8dd1354e2adb2ffb1bab29789769cd5b75108e28
1 #ifndef INKSCAPE_LIVEPATHEFFECT_H
2 #define INKSCAPE_LIVEPATHEFFECT_H
4 /*
5 * Inkscape::LivePathEffect
6 *
7 * Copyright (C) Johan Engelen 2007-2008 <j.b.c.engelen@utwente.nl>
8 *
9 * Released under GNU GPL, read the file 'COPYING' for more information
10 */
13 #include "display/display-forward.h"
14 #include <map>
15 #include <glibmm/ustring.h>
16 #include <2geom/path.h>
17 #include <2geom/forward.h>
18 #include "ui/widget/registry.h"
19 #include "util/enums.h"
20 #include "sp-lpe-item.h"
21 #include "knotholder.h"
22 #include "parameter/bool.h"
24 #define LPE_CONVERSION_TOLERANCE 0.01 // FIXME: find good solution for this.
26 #define LPE_ENABLE_TEST_EFFECTS
28 struct SPDocument;
29 struct SPDesktop;
30 struct SPItem;
31 class SPNodeContext;
32 struct LivePathEffectObject;
34 namespace Gtk {
35 class Widget;
36 class VBox;
37 class Tooltips;
38 }
40 namespace Inkscape {
42 namespace XML {
43 class Node;
44 }
46 namespace NodePath {
47 class Path ;
48 }
50 namespace LivePathEffect {
52 enum EffectType {
53 BEND_PATH = 0,
54 PATTERN_ALONG_PATH,
55 FREEHAND_SHAPE,
56 SKETCH,
57 VONKOCH,
58 KNOT,
59 #ifdef LPE_ENABLE_TEST_EFFECTS
60 DOEFFECTSTACK_TEST,
61 #endif
62 GEARS,
63 CURVE_STITCH,
64 CIRCLE_WITH_RADIUS,
65 PERSPECTIVE_PATH,
66 SPIRO,
67 LATTICE,
68 ENVELOPE,
69 CONSTRUCT_GRID,
70 PERP_BISECTOR,
71 TANGENT_TO_CURVE,
72 MIRROR_SYMMETRY,
73 CIRCLE_3PTS,
74 ANGLE_BISECTOR,
75 PARALLEL,
76 COPY_ROTATE,
77 OFFSET,
78 RULER,
79 BOOLOPS,
80 INTERPOLATE,
81 TEXT_LABEL,
82 PATH_LENGTH,
83 LINE_SEGMENT,
84 INVALID_LPE // This must be last
85 };
87 extern const Util::EnumData<EffectType> LPETypeData[];
88 extern const Util::EnumDataConverter<EffectType> LPETypeConverter;
90 enum LPEPathFlashType {
91 SUPPRESS_FLASH,
92 // PERMANENT_FLASH,
93 DEFAULT
94 };
96 class Effect {
97 public:
98 static Effect* New(EffectType lpenr, LivePathEffectObject *lpeobj);
99 static void createAndApply(const char* name, SPDocument *doc, SPItem *item);
100 static void createAndApply(EffectType type, SPDocument *doc, SPItem *item);
102 virtual ~Effect();
104 EffectType effectType ();
106 virtual void doOnApply (SPLPEItem *lpeitem);
107 virtual void doBeforeEffect (SPLPEItem *lpeitem);
109 void writeParamsToSVG();
111 virtual void acceptParamPath (SPPath *param_path);
112 static int acceptsNumClicks(EffectType type);
113 int acceptsNumClicks() { return acceptsNumClicks(effectType()); }
114 void doAcceptPathPreparations(SPLPEItem *lpeitem);
116 /*
117 * isReady() indicates whether all preparations which are necessary to apply the LPE are done,
118 * e.g., waiting for a parameter path either before the effect is created or when it needs a
119 * path as argument. This is set in sp_lpe_item_add_path_effect().
120 */
121 inline bool isReady() { return is_ready; }
122 inline void setReady(bool ready = true) { is_ready = ready; }
124 virtual void doEffect (SPCurve * curve);
126 virtual Gtk::Widget * newWidget(Gtk::Tooltips * tooltips);
128 virtual void resetDefaults(SPItem * item);
130 virtual void setup_nodepath(Inkscape::NodePath::Path *np);
132 /// /todo: is this method really necessary? it causes UI inconsistensies... (johan)
133 virtual void transform_multiply(Geom::Matrix const& postmul, bool set);
135 // /TODO: providesKnotholder() is currently used as an indicator of whether a nodepath is
136 // created for an item or not. When we allow both at the same time, this needs rethinking!
137 bool providesKnotholder();
138 // /TODO: in view of providesOwnFlashPaths() below, this is somewhat redundant
139 // (but spiro lpe still needs it!)
140 virtual LPEPathFlashType pathFlashType() { return DEFAULT; }
141 void addHandles(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item);
142 std::vector<Geom::PathVector> getHelperPaths(SPLPEItem *lpeitem);
144 inline bool providesOwnFlashPaths() {
145 return provides_own_flash_paths || show_orig_path;
146 }
147 inline bool showOrigPath() { return show_orig_path; }
149 Glib::ustring getName();
150 Inkscape::XML::Node * getRepr();
151 SPDocument * getSPDoc();
152 LivePathEffectObject * getLPEObj() {return lpeobj;};
153 Parameter * getParameter(const char * key);
155 void readallParameters(Inkscape::XML::Node * repr);
156 void setParameter(const gchar * key, const gchar * new_value);
158 inline bool isVisible() { return is_visible; }
160 void editNextParamOncanvas(SPItem * item, SPDesktop * desktop);
162 protected:
163 Effect(LivePathEffectObject *lpeobject);
165 // provide a set of doEffect functions so the developer has a choice
166 // of what kind of input/output parameters he desires.
167 // the order in which they appear is the order in which they are
168 // called by this base class. (i.e. doEffect(SPCurve * curve) defaults to calling
169 // doEffect(std::vector<Geom::Path> )
170 virtual std::vector<Geom::Path>
171 doEffect_path (std::vector<Geom::Path> const & path_in);
172 virtual Geom::Piecewise<Geom::D2<Geom::SBasis> >
173 doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in);
175 void registerParameter(Parameter * param);
176 void registerKnotHolderHandle(KnotHolderEntity* entity, const char* descr);
177 Parameter * getNextOncanvasEditableParam();
179 void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item);
181 //virtual std::vector<Geom::PathVector> getCanvasIndicators(SPLPEItem *lpeitem);
182 virtual void addCanvasIndicators(SPLPEItem *lpeitem, std::vector<Geom::PathVector> &hp_vec);
185 std::vector<Parameter *> param_vector;
186 std::vector<std::pair<KnotHolderEntity*, const char*> > kh_entity_vector;
187 int oncanvasedit_it;
188 BoolParam is_visible;
189 BoolParam deactivate_knotholder; // the user can use this to deactivate knotholders (for
190 // convenience, because they may interfere with node handles
191 // during editing); this is probably only temporary
193 bool show_orig_path; // set this to true in derived effects to automatically have the original
194 // path displayed as helperpath
196 Inkscape::UI::Widget::Registry wr;
198 LivePathEffectObject *lpeobj;
200 // this boolean defaults to false, it concatenates the input path to one pwd2,
201 // instead of normally 'splitting' the path into continuous pwd2 paths.
202 bool concatenate_before_pwd2;
204 private:
205 bool provides_own_flash_paths; // if true, the standard flash path is suppressed
207 bool is_ready;
209 Effect(const Effect&);
210 Effect& operator=(const Effect&);
211 };
213 } //namespace LivePathEffect
214 } //namespace Inkscape
216 #endif
218 /*
219 Local Variables:
220 mode:c++
221 c-file-style:"stroustrup"
222 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
223 indent-tabs-mode:nil
224 fill-column:99
225 End:
226 */
227 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :