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 virtual void transform_multiply(Geom::Matrix const& postmul, bool set);
134 // TODO: providesKnotholder() is currently used as an indicator of whether a nodepath is
135 // created for an item or not. When we allow both at the same time, this needs rethinking!
136 bool providesKnotholder();
137 // TODO: in view of providesOwnFlashPaths() below, this is somewhat redundant
138 // (but spiro lpe still needs it!)
139 virtual LPEPathFlashType pathFlashType() { return DEFAULT; }
140 void addHandles(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item);
141 std::vector<Geom::PathVector> getHelperPaths(SPLPEItem *lpeitem);
143 inline bool providesOwnFlashPaths() {
144 return provides_own_flash_paths || show_orig_path;
145 }
146 inline bool showOrigPath() { return show_orig_path; }
148 Glib::ustring getName();
149 Inkscape::XML::Node * getRepr();
150 SPDocument * getSPDoc();
151 LivePathEffectObject * getLPEObj() {return lpeobj;};
152 Parameter * getParameter(const char * key);
154 void readallParameters(Inkscape::XML::Node * repr);
155 void setParameter(const gchar * key, const gchar * new_value);
157 inline bool isVisible() { return is_visible; }
159 void editNextParamOncanvas(SPItem * item, SPDesktop * desktop);
161 protected:
162 Effect(LivePathEffectObject *lpeobject);
164 // provide a set of doEffect functions so the developer has a choice
165 // of what kind of input/output parameters he desires.
166 // the order in which they appear is the order in which they are
167 // called by this base class. (i.e. doEffect(SPCurve * curve) defaults to calling
168 // doEffect(std::vector<Geom::Path> )
169 virtual std::vector<Geom::Path>
170 doEffect_path (std::vector<Geom::Path> const & path_in);
171 virtual Geom::Piecewise<Geom::D2<Geom::SBasis> >
172 doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in);
174 void registerParameter(Parameter * param);
175 void registerKnotHolderHandle(KnotHolderEntity* entity, const char* descr);
176 Parameter * getNextOncanvasEditableParam();
178 void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item);
180 //virtual std::vector<Geom::PathVector> getCanvasIndicators(SPLPEItem *lpeitem);
181 virtual void addCanvasIndicators(SPLPEItem *lpeitem, std::vector<Geom::PathVector> &hp_vec);
184 std::vector<Parameter *> param_vector;
185 std::vector<std::pair<KnotHolderEntity*, const char*> > kh_entity_vector;
186 int oncanvasedit_it;
187 BoolParam is_visible;
188 BoolParam deactivate_knotholder; // the user can use this to deactivate knotholders (for
189 // convenience, because they may interfere with node handles
190 // during editing); this is probably only temporary
192 bool show_orig_path; // set this to true in derived effects to automatically have the original
193 // path displayed as helperpath
195 Inkscape::UI::Widget::Registry wr;
197 LivePathEffectObject *lpeobj;
199 // this boolean defaults to false, it concatenates the input path to one pwd2,
200 // instead of normally 'splitting' the path into continuous pwd2 paths.
201 bool concatenate_before_pwd2;
203 private:
204 bool provides_own_flash_paths; // if true, the standard flash path is suppressed
206 bool is_ready;
208 Effect(const Effect&);
209 Effect& operator=(const Effect&);
210 };
212 } //namespace LivePathEffect
213 } //namespace Inkscape
215 #endif
217 /*
218 Local Variables:
219 mode:c++
220 c-file-style:"stroustrup"
221 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
222 indent-tabs-mode:nil
223 fill-column:99
224 End:
225 */
226 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :