672b90b87cb71bcdacaf3d2b9198be920041e06a
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 "ui/widget/registry.h"
18 #include "util/enums.h"
19 #include "sp-lpe-item.h"
20 #include "knotholder.h"
21 #include "parameter/bool.h"
23 #define LPE_CONVERSION_TOLERANCE 0.01 // FIXME: find good solution for this.
25 #define LPE_ENABLE_TEST_EFFECTS
27 struct SPDocument;
28 struct SPDesktop;
29 struct SPItem;
30 class SPNodeContext;
31 class NArtBpath;
32 struct LivePathEffectObject;
34 namespace Gtk {
35 class Widget;
36 class VBox;
37 class Tooltips;
38 }
40 namespace Geom {
41 class Matrix;
42 }
44 namespace Inkscape {
46 namespace XML {
47 class Node;
48 }
50 namespace NodePath {
51 class Path ;
52 }
54 namespace LivePathEffect {
56 enum EffectType {
57 BEND_PATH = 0,
58 PATTERN_ALONG_PATH,
59 SKETCH,
60 VONKOCH,
61 KNOT,
62 #ifdef LPE_ENABLE_TEST_EFFECTS
63 DOEFFECTSTACK_TEST,
64 #endif
65 GEARS,
66 CURVE_STITCH,
67 CIRCLE_WITH_RADIUS,
68 PERSPECTIVE_PATH,
69 SPIRO,
70 LATTICE,
71 ENVELOPE,
72 CONSTRUCT_GRID,
73 PERP_BISECTOR,
74 TANGENT_TO_CURVE,
75 MIRROR_REFLECT,
76 CIRCLE_3PTS,
77 ANGLE_BISECTOR,
78 PARALLEL,
79 COPY_ROTATE,
80 INVALID_LPE // This must be last
81 };
83 extern const Util::EnumData<EffectType> LPETypeData[INVALID_LPE];
84 extern const Util::EnumDataConverter<EffectType> LPETypeConverter;
86 enum LPEPathFlashType {
87 SUPPRESS_FLASH,
88 // PERMANENT_FLASH,
89 DEFAULT
90 };
92 class Effect {
93 public:
94 static Effect* New(EffectType lpenr, LivePathEffectObject *lpeobj);
95 static void createAndApply(const char* name, SPDocument *doc, SPItem *item);
96 static void createAndApply(EffectType type, SPDocument *doc, SPItem *item);
98 virtual ~Effect();
100 EffectType effectType ();
102 virtual void doOnApply (SPLPEItem *lpeitem);
103 virtual void doBeforeEffect (SPLPEItem *lpeitem);
105 void writeParamsToSVG();
107 virtual void acceptParamPath (SPPath *param_path);
108 virtual int acceptsNumParams() { return 0; }
109 void doAcceptPathPreparations(SPLPEItem *lpeitem);
111 inline bool pathParamAccepted() { return done_pathparam_set; }
113 virtual void doEffect (SPCurve * curve);
115 virtual Gtk::Widget * newWidget(Gtk::Tooltips * tooltips);
117 virtual void resetDefaults(SPItem * item);
119 virtual void setup_nodepath(Inkscape::NodePath::Path *np);
121 virtual void transform_multiply(Geom::Matrix const& postmul, bool set);
123 // TODO: providesKnotholder() is currently used as an indicator of whether a nodepath is
124 // created for an item or not. When we allow both at the same time, this needs rethinking!
125 bool providesKnotholder();
126 // TODO: in view of providesOwnFlashPaths() below, this is somewhat redundant
127 // (but spiro lpe still needs it!)
128 virtual LPEPathFlashType pathFlashType() { return DEFAULT; }
129 void addHandles(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item);
130 void addPointParamHandles(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item);
132 void addHelperPaths(SPLPEItem *lpeitem, SPDesktop *desktop);
133 inline bool providesOwnFlashPaths() {
134 return provides_own_flash_paths || show_orig_path;
135 }
136 inline bool showOrigPath() { return show_orig_path; }
138 Glib::ustring getName();
139 Inkscape::XML::Node * getRepr();
140 SPDocument * getSPDoc();
141 LivePathEffectObject * getLPEObj() {return lpeobj;};
142 Parameter * getParameter(const char * key);
144 void readallParameters(Inkscape::XML::Node * repr);
145 void setParameter(const gchar * key, const gchar * new_value);
147 inline bool isVisible() { return is_visible; }
149 void editNextParamOncanvas(SPItem * item, SPDesktop * desktop);
151 protected:
152 Effect(LivePathEffectObject *lpeobject);
154 // provide a set of doEffect functions so the developer has a choice
155 // of what kind of input/output parameters he desires.
156 // the order in which they appear is the order in which they are
157 // called by this base class. (i.e. doEffect(SPCurve * curve) defaults to calling
158 // doEffect(std::vector<Geom::Path> )
159 virtual std::vector<Geom::Path>
160 doEffect_path (std::vector<Geom::Path> const & path_in);
161 virtual Geom::Piecewise<Geom::D2<Geom::SBasis> >
162 doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in);
164 void registerParameter(Parameter * param);
165 void registerKnotHolderHandle(KnotHolderEntity* entity, const char* descr);
166 Parameter * getNextOncanvasEditableParam();
168 virtual void addHelperPathsImpl(SPLPEItem *lpeitem, SPDesktop *desktop);
170 std::vector<Parameter *> param_vector;
171 std::vector<std::pair<KnotHolderEntity*, const char*> > kh_entity_vector;
172 int oncanvasedit_it;
173 BoolParam is_visible;
174 bool done_pathparam_set;
176 bool show_orig_path; // set this to true in derived effects to automatically have the original
177 // path displayed as helperpath
179 Inkscape::UI::Widget::Registry wr;
181 LivePathEffectObject *lpeobj;
183 // this boolean defaults to false, it concatenates the input path to one pwd2,
184 // instead of normally 'splitting' the path into continuous pwd2 paths.
185 bool concatenate_before_pwd2;
187 private:
188 bool provides_own_flash_paths; // if true, the standard flash path is suppressed
190 Effect(const Effect&);
191 Effect& operator=(const Effect&);
192 };
195 } //namespace LivePathEffect
196 } //namespace Inkscape
198 #endif
200 /*
201 Local Variables:
202 mode:c++
203 c-file-style:"stroustrup"
204 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
205 indent-tabs-mode:nil
206 fill-column:99
207 End:
208 */
209 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :