1 /*
2 * A generic interface for plugging different
3 * autotracers into Inkscape.
4 *
5 * Authors:
6 * Bob Jamison <rjamison@titan.com>
7 *
8 * Copyright (C) 2004 Bob Jamison
9 *
10 * Released under GNU GPL, read the file 'COPYING' for more information
11 */
12 #ifndef __TRACE_H__
13 #define __TRACE_H__
15 #ifdef HAVE_CONFIG_H
16 # include "config.h"
17 #endif
19 #ifdef HAVE_STDLIB_H
20 # include <stdlib.h>
21 #endif
23 #ifdef HAVE_STRING_H
24 # include <string.h>
25 #endif
27 #include <gdk/gdkpixbuf.h>
30 struct SPImage;
31 struct SPItem;
33 namespace Inkscape {
35 namespace Trace {
39 /**
40 *
41 */
42 class TracingEngineResult
43 {
45 public:
47 /**
48 *
49 */
50 TracingEngineResult(char *theStyle, char *thePathData, long theNodeCount)
51 {
52 next = NULL;
53 style = strdup(theStyle);
54 pathData = strdup(thePathData);
55 nodeCount = theNodeCount;
56 }
58 /**
59 *
60 */
61 virtual ~TracingEngineResult()
62 {
63 if (next)
64 delete next;
65 if (style)
66 free(style);
67 if (pathData)
68 free(pathData);
69 }
72 /**
73 *
74 */
75 char *getStyle()
76 { return style; }
78 /**
79 *
80 */
81 char *getPathData()
82 { return pathData; }
84 /**
85 *
86 */
87 long getNodeCount()
88 { return nodeCount; }
90 /**
91 *
92 */
93 TracingEngineResult *next;
95 private:
97 char *style;
99 char *pathData;
101 long nodeCount;
103 };
107 /**
108 *
109 */
110 class TracingEngine
111 {
113 public:
115 /**
116 *
117 */
118 TracingEngine()
119 {}
121 /**
122 *
123 */
124 virtual ~TracingEngine()
125 {}
127 /**
128 * This is the working method of this interface, and all
129 * implementing classes. Take a GdkPixbuf, trace it, and
130 * return a style attribute and the path data that is
131 * compatible with the d="" attribute
132 * of an SVG <path> element.
133 */
134 virtual TracingEngineResult *trace(GdkPixbuf *pixbuf, int *nrPaths)
135 { return NULL; }
138 /**
139 * Abort the thread that is executing getPathDataFromPixbuf()
140 */
141 virtual void abort()
142 {}
146 };//class TracingEngine
156 /**
157 * This simple class allows a generic wrapper around a given
158 * TracingEngine object. Its purpose is to provide a gateway
159 * to a variety of tracing engines, while maintaining a
160 * consistent interface.
161 */
162 class Tracer
163 {
165 public:
168 /**
169 *
170 */
171 Tracer()
172 {
173 engine = NULL;
174 selectedItem = NULL;
175 }
179 /**
180 *
181 */
182 ~Tracer()
183 {}
186 /**
187 * A convenience method to allow other software to 'see' the
188 * same image that this class sees.
189 */
190 GdkPixbuf *getSelectedImage();
192 /**
193 * This is the main working method. Trace the selected image, if
194 * any, and create a <path> element from it, inserting it into
195 * the current document.
196 */
197 void trace(TracingEngine *engine);
200 /**
201 * Abort the thread that is executing convertImageToPath()
202 */
203 void abort();
206 private:
208 /**
209 * This is the single path code that is called by its counterpart above.
210 */
211 void traceThread();
213 /**
214 * This is true during execution. Setting it to false (like abort()
215 * does) should inform the threaded code that it needs to stop
216 */
217 bool keepGoing;
219 /**
220 * During tracing, this is Non-null, and refers to the
221 * engine that is currently doing the tracing.
222 */
223 TracingEngine *engine;
225 SPImage *getSelectedSPImage();
227 SPItem *selectedItem;
230 };//class Tracer
235 } // namespace Trace
237 } // namespace Inkscape
241 #endif //__TRACE_H__
243 //#########################################################################
244 //# E N D O F F I L E
245 //#########################################################################