eced0a1941b22aaf915514379f7a41b5a23c2517
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 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 INVALID_LPE // This must be last
80 };
82 extern const Util::EnumData<EffectType> LPETypeData[INVALID_LPE];
83 extern const Util::EnumDataConverter<EffectType> LPETypeConverter;
85 enum LPEPathFlashType {
86 SUPPRESS_FLASH,
87 // PERMANENT_FLASH,
88 DEFAULT
89 };
91 class Effect {
92 public:
93 static Effect* New(EffectType lpenr, LivePathEffectObject *lpeobj);
94 static void createAndApply(const char* name, SPDocument *doc, SPItem *item);
95 static void createAndApply(EffectType type, SPDocument *doc, SPItem *item);
97 virtual ~Effect();
99 EffectType effectType ();
101 virtual void doOnApply (SPLPEItem *lpeitem);
102 virtual void doBeforeEffect (SPLPEItem *lpeitem);
104 void writeParamsToSVG();
106 virtual void acceptParamPath (SPPath *param_path);
107 virtual int acceptsNumParams() { return 0; }
108 void doAcceptPathPreparations(SPLPEItem *lpeitem);
110 inline bool pathParamAccepted() { return done_pathparam_set; }
112 virtual void doEffect (SPCurve * curve);
114 virtual Gtk::Widget * newWidget(Gtk::Tooltips * tooltips);
116 virtual void resetDefaults(SPItem * item);
118 virtual void setup_nodepath(Inkscape::NodePath::Path *np);
120 virtual void transform_multiply(Geom::Matrix const& postmul, bool set);
122 // TODO: providesKnotholder() is currently used as an indicator of whether a nodepath is
123 // created for an item or not. When we allow both at the same time, this needs rethinking!
124 bool providesKnotholder();
125 // TODO: in view of providesOwnFlashPaths() below, this is somewhat redundant
126 // (but spiro lpe still needs it!)
127 virtual LPEPathFlashType pathFlashType() { return DEFAULT; }
128 void addHandles(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item);
129 void addPointParamHandles(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item);
131 void addHelperPaths(SPLPEItem *lpeitem, SPDesktop *desktop);
132 inline bool providesOwnFlashPaths() {
133 return provides_own_flash_paths || show_orig_path;
134 }
135 inline bool showOrigPath() { return show_orig_path; }
137 Glib::ustring getName();
138 Inkscape::XML::Node * getRepr();
139 SPDocument * getSPDoc();
140 LivePathEffectObject * getLPEObj() {return lpeobj;};
141 Parameter * getParameter(const char * key);
143 void readallParameters(Inkscape::XML::Node * repr);
144 void setParameter(const gchar * key, const gchar * new_value);
146 inline bool isVisible() { return is_visible; }
148 void editNextParamOncanvas(SPItem * item, SPDesktop * desktop);
150 protected:
151 Effect(LivePathEffectObject *lpeobject);
153 // provide a set of doEffect functions so the developer has a choice
154 // of what kind of input/output parameters he desires.
155 // the order in which they appear is the order in which they are
156 // called by this base class. (i.e. doEffect(SPCurve * curve) defaults to calling
157 // doEffect(std::vector<Geom::Path> )
158 virtual std::vector<Geom::Path>
159 doEffect_path (std::vector<Geom::Path> const & path_in);
160 virtual Geom::Piecewise<Geom::D2<Geom::SBasis> >
161 doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in);
163 void registerParameter(Parameter * param);
164 void registerKnotHolderHandle(KnotHolderEntity* entity, const char* descr);
165 Parameter * getNextOncanvasEditableParam();
167 virtual void addHelperPathsImpl(SPLPEItem *lpeitem, SPDesktop *desktop);
169 std::vector<Parameter *> param_vector;
170 std::vector<std::pair<KnotHolderEntity*, const char*> > kh_entity_vector;
171 int oncanvasedit_it;
172 BoolParam is_visible;
173 bool done_pathparam_set;
175 bool show_orig_path; // set this to true in derived effects to automatically have the original
176 // path displayed as helperpath
178 Inkscape::UI::Widget::Registry wr;
180 LivePathEffectObject *lpeobj;
182 // this boolean defaults to false, it concatenates the input path to one pwd2,
183 // instead of normally 'splitting' the path into continuous pwd2 paths.
184 bool concatenate_before_pwd2;
186 private:
187 bool provides_own_flash_paths; // if true, the standard flash path is suppressed
189 Effect(const Effect&);
190 Effect& operator=(const Effect&);
191 };
194 } //namespace LivePathEffect
195 } //namespace Inkscape
197 #endif
199 /*
200 Local Variables:
201 mode:c++
202 c-file-style:"stroustrup"
203 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
204 indent-tabs-mode:nil
205 fill-column:99
206 End:
207 */
208 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :