Code

use touchpath selection when rubberbanding with Alt; do move-selected with Alt only...
[inkscape.git] / src / trace / trace.h
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-2006 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 <gtkmm.h>
29 #include <vector>
30 #include <sp-shape.h>
32 struct SPImage;
33 struct SPItem;
35 namespace Inkscape {
37 namespace Trace {
41 /**
42  *
43  */
44 class TracingEngineResult
45 {
47 public:
49     /**
50      *
51      */
52     TracingEngineResult(const std::string &theStyle,
53                         const std::string &thePathData,
54                         long theNodeCount)
55         {
56         style     = theStyle;
57         pathData  = thePathData;
58         nodeCount = theNodeCount;
59         }
61     TracingEngineResult(const TracingEngineResult &other)
62         { assign(other); }
64     virtual TracingEngineResult &operator=(const TracingEngineResult &other)
65         { assign(other); return *this; }
68     /**
69      *
70      */
71     virtual ~TracingEngineResult()
72         { }
75     /**
76      *
77      */
78     std::string getStyle()
79         { return style; }
81     /**
82      *
83      */
84     std::string getPathData()
85         { return pathData; }
87     /**
88      *
89      */
90     long getNodeCount()
91         { return nodeCount; }
93 private:
95     void assign(const TracingEngineResult &other)
96         {
97         style = other.style;
98         pathData = other.pathData;
99         nodeCount = other.nodeCount;
100         }
102     std::string style;
104     std::string pathData;
106     long nodeCount;
108 };
112 /**
113  *
114  */
115 class TracingEngine
118     public:
120     /**
121      *
122      */
123     TracingEngine()
124         {}
126     /**
127      *
128      */
129     virtual ~TracingEngine()
130         {}
132     /**
133      *  This is the working method of this interface, and all
134      *  implementing classes.  Take a GdkPixbuf, trace it, and
135      *  return a style attribute and the path data that is
136      *  compatible with the d="" attribute
137      *  of an SVG <path> element.
138      */
139     virtual  std::vector<TracingEngineResult> trace(
140                            Glib::RefPtr<Gdk::Pixbuf> pixbuf)
141         { std::vector<TracingEngineResult> dummy;  return dummy; }
144     /**
145      *  Abort the thread that is executing getPathDataFromPixbuf()
146      */
147     virtual void abort()
148         {}
152 };//class TracingEngine
162 /**
163  *  This simple class allows a generic wrapper around a given
164  *  TracingEngine object.  Its purpose is to provide a gateway
165  *  to a variety of tracing engines, while maintaining a
166  *  consistent interface.
167  */
168 class Tracer
171 public:
174     /**
175      *
176      */
177     Tracer()
178         {
179         engine       = NULL;
180         sioxEnabled  = false;
181         }
185     /**
186      *
187      */
188     ~Tracer()
189         {}
192     /**
193      *  A convenience method to allow other software to 'see' the
194      *  same image that this class sees.
195      */
196     Glib::RefPtr<Gdk::Pixbuf> getSelectedImage();
198     /**
199      * This is the main working method.  Trace the selected image, if
200      * any, and create a <path> element from it, inserting it into
201      * the current document.
202      */
203     void trace(TracingEngine *engine);
206     /**
207      *  Abort the thread that is executing convertImageToPath()
208      */
209     void abort();
211     /**
212      *  Whether we want to enable SIOX subimage selection
213      */
214     void enableSiox(bool enable);
217 private:
219     /**
220      * This is the single path code that is called by its counterpart above.
221      */
222     void traceThread();
224     /**
225      * This is true during execution. Setting it to false (like abort()
226      * does) should inform the threaded code that it needs to stop
227      */
228     bool keepGoing;
230     /**
231      *  During tracing, this is Non-null, and refers to the
232      *  engine that is currently doing the tracing.
233      */
234     TracingEngine *engine;
236     SPImage *getSelectedSPImage();
238     std::vector<SPShape *> sioxShapes;
240     bool sioxEnabled;
242     Glib::RefPtr<Gdk::Pixbuf> sioxProcessImage(
243            SPImage *img, Glib::RefPtr<Gdk::Pixbuf> origPixbuf);
245     Glib::RefPtr<Gdk::Pixbuf> lastSioxPixbuf;
246     Glib::RefPtr<Gdk::Pixbuf> lastOrigPixbuf;
248 };//class Tracer
253 } // namespace Trace
255 } // namespace Inkscape
259 #endif //__TRACE_H__
261 //#########################################################################
262 //# E N D   O F   F I L E
263 //#########################################################################