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 class NArtBpath;
33 struct LivePathEffectObject;
35 namespace Gtk {
36 class Widget;
37 class VBox;
38 class Tooltips;
39 }
41 namespace Inkscape {
43 namespace XML {
44 class Node;
45 }
47 namespace NodePath {
48 class Path ;
49 }
51 namespace LivePathEffect {
53 enum EffectType {
54 BEND_PATH = 0,
55 PATTERN_ALONG_PATH,
56 FREEHAND_SHAPE,
57 SKETCH,
58 VONKOCH,
59 KNOT,
60 #ifdef LPE_ENABLE_TEST_EFFECTS
61 DOEFFECTSTACK_TEST,
62 #endif
63 GEARS,
64 CURVE_STITCH,
65 CIRCLE_WITH_RADIUS,
66 PERSPECTIVE_PATH,
67 SPIRO,
68 LATTICE,
69 ENVELOPE,
70 CONSTRUCT_GRID,
71 PERP_BISECTOR,
72 TANGENT_TO_CURVE,
73 MIRROR_SYMMETRY,
74 CIRCLE_3PTS,
75 ANGLE_BISECTOR,
76 PARALLEL,
77 COPY_ROTATE,
78 OFFSET,
79 RULER,
80 BOOLOPS,
81 INTERPOLATE,
82 TEXT_LABEL,
83 PATH_LENGTH,
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 virtual int acceptsNumParams() { return 0; }
113 void doAcceptPathPreparations(SPLPEItem *lpeitem);
115 inline bool pathParamAccepted() { return done_pathparam_set; }
117 virtual void doEffect (SPCurve * curve);
119 virtual Gtk::Widget * newWidget(Gtk::Tooltips * tooltips);
121 virtual void resetDefaults(SPItem * item);
123 virtual void setup_nodepath(Inkscape::NodePath::Path *np);
125 virtual void transform_multiply(Geom::Matrix const& postmul, bool set);
127 // TODO: providesKnotholder() is currently used as an indicator of whether a nodepath is
128 // created for an item or not. When we allow both at the same time, this needs rethinking!
129 bool providesKnotholder();
130 // TODO: in view of providesOwnFlashPaths() below, this is somewhat redundant
131 // (but spiro lpe still needs it!)
132 virtual LPEPathFlashType pathFlashType() { return DEFAULT; }
133 void addHandles(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item);
134 std::vector<Geom::PathVector> getHelperPaths(SPLPEItem *lpeitem);
136 inline bool providesOwnFlashPaths() {
137 return provides_own_flash_paths || show_orig_path;
138 }
139 inline bool showOrigPath() { return show_orig_path; }
141 Glib::ustring getName();
142 Inkscape::XML::Node * getRepr();
143 SPDocument * getSPDoc();
144 LivePathEffectObject * getLPEObj() {return lpeobj;};
145 Parameter * getParameter(const char * key);
147 void readallParameters(Inkscape::XML::Node * repr);
148 void setParameter(const gchar * key, const gchar * new_value);
150 inline bool isVisible() { return is_visible; }
152 void editNextParamOncanvas(SPItem * item, SPDesktop * desktop);
154 protected:
155 Effect(LivePathEffectObject *lpeobject);
157 // provide a set of doEffect functions so the developer has a choice
158 // of what kind of input/output parameters he desires.
159 // the order in which they appear is the order in which they are
160 // called by this base class. (i.e. doEffect(SPCurve * curve) defaults to calling
161 // doEffect(std::vector<Geom::Path> )
162 virtual std::vector<Geom::Path>
163 doEffect_path (std::vector<Geom::Path> const & path_in);
164 virtual Geom::Piecewise<Geom::D2<Geom::SBasis> >
165 doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in);
167 void registerParameter(Parameter * param);
168 void registerKnotHolderHandle(KnotHolderEntity* entity, const char* descr);
169 Parameter * getNextOncanvasEditableParam();
171 void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item);
173 //virtual std::vector<Geom::PathVector> getCanvasIndicators(SPLPEItem *lpeitem);
174 virtual void addCanvasIndicators(SPLPEItem *lpeitem, std::vector<Geom::PathVector> &hp_vec);
177 std::vector<Parameter *> param_vector;
178 std::vector<std::pair<KnotHolderEntity*, const char*> > kh_entity_vector;
179 int oncanvasedit_it;
180 BoolParam is_visible;
181 bool done_pathparam_set;
183 bool show_orig_path; // set this to true in derived effects to automatically have the original
184 // path displayed as helperpath
186 Inkscape::UI::Widget::Registry wr;
188 LivePathEffectObject *lpeobj;
190 // this boolean defaults to false, it concatenates the input path to one pwd2,
191 // instead of normally 'splitting' the path into continuous pwd2 paths.
192 bool concatenate_before_pwd2;
194 private:
195 bool provides_own_flash_paths; // if true, the standard flash path is suppressed
197 Effect(const Effect&);
198 Effect& operator=(const Effect&);
199 };
201 } //namespace LivePathEffect
202 } //namespace Inkscape
204 #endif
206 /*
207 Local Variables:
208 mode:c++
209 c-file-style:"stroustrup"
210 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
211 indent-tabs-mode:nil
212 fill-column:99
213 End:
214 */
215 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :