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/forward.h>
17 #include "ui/widget/registry.h"
18 #include "sp-lpe-item.h"
19 //#include "knotholder.h"
20 #include "parameter/bool.h"
21 #include "effect-enum.h"
23 #define LPE_CONVERSION_TOLERANCE 0.01 // FIXME: find good solution for this.
25 struct SPDocument;
26 struct SPDesktop;
27 struct SPItem;
28 class SPNodeContext;
29 struct LivePathEffectObject;
30 class SPLPEItem;
31 class KnotHolder;
32 class KnotHolderEntity;
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 LPEPathFlashType {
53 SUPPRESS_FLASH,
54 // PERMANENT_FLASH,
55 DEFAULT
56 };
58 class Effect {
59 public:
60 static Effect* New(EffectType lpenr, LivePathEffectObject *lpeobj);
61 static void createAndApply(const char* name, SPDocument *doc, SPItem *item);
62 static void createAndApply(EffectType type, SPDocument *doc, SPItem *item);
64 virtual ~Effect();
66 EffectType effectType ();
68 virtual void doOnApply (SPLPEItem *lpeitem);
69 virtual void doBeforeEffect (SPLPEItem *lpeitem);
71 void writeParamsToSVG();
73 virtual void acceptParamPath (SPPath *param_path);
74 static int acceptsNumClicks(EffectType type);
75 int acceptsNumClicks() { return acceptsNumClicks(effectType()); }
76 void doAcceptPathPreparations(SPLPEItem *lpeitem);
78 /*
79 * isReady() indicates whether all preparations which are necessary to apply the LPE are done,
80 * e.g., waiting for a parameter path either before the effect is created or when it needs a
81 * path as argument. This is set in sp_lpe_item_add_path_effect().
82 */
83 inline bool isReady() { return is_ready; }
84 inline void setReady(bool ready = true) { is_ready = ready; }
86 virtual void doEffect (SPCurve * curve);
88 virtual Gtk::Widget * newWidget(Gtk::Tooltips * tooltips);
90 /**
91 * Sets all parameters to their default values and writes them to SVG.
92 */
93 virtual void resetDefaults(SPItem * item);
95 /// /todo: is this method really necessary? it causes UI inconsistensies... (johan)
96 virtual void transform_multiply(Geom::Matrix const& postmul, bool set);
98 // /TODO: providesKnotholder() is currently used as an indicator of whether a nodepath is
99 // created for an item or not. When we allow both at the same time, this needs rethinking!
100 bool providesKnotholder();
101 // /TODO: in view of providesOwnFlashPaths() below, this is somewhat redundant
102 // (but spiro lpe still needs it!)
103 virtual LPEPathFlashType pathFlashType() { return DEFAULT; }
104 void addHandles(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item);
105 std::vector<Geom::PathVector> getHelperPaths(SPLPEItem *lpeitem);
107 inline bool providesOwnFlashPaths() {
108 return provides_own_flash_paths || show_orig_path;
109 }
110 inline bool showOrigPath() { return show_orig_path; }
112 Glib::ustring getName();
113 Inkscape::XML::Node * getRepr();
114 SPDocument * getSPDoc();
115 LivePathEffectObject * getLPEObj() {return lpeobj;};
116 Parameter * getParameter(const char * key);
118 void readallParameters(Inkscape::XML::Node * repr);
119 void setParameter(const gchar * key, const gchar * new_value);
121 inline bool isVisible() { return is_visible; }
123 void editNextParamOncanvas(SPItem * item, SPDesktop * desktop);
125 protected:
126 Effect(LivePathEffectObject *lpeobject);
128 // provide a set of doEffect functions so the developer has a choice
129 // of what kind of input/output parameters he desires.
130 // the order in which they appear is the order in which they are
131 // called by this base class. (i.e. doEffect(SPCurve * curve) defaults to calling
132 // doEffect(std::vector<Geom::Path> )
133 virtual std::vector<Geom::Path>
134 doEffect_path (std::vector<Geom::Path> const & path_in);
135 virtual Geom::Piecewise<Geom::D2<Geom::SBasis> >
136 doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in);
138 void registerParameter(Parameter * param);
139 void registerKnotHolderHandle(KnotHolderEntity* entity, const char* descr);
140 Parameter * getNextOncanvasEditableParam();
142 void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item);
144 //virtual std::vector<Geom::PathVector> getCanvasIndicators(SPLPEItem *lpeitem);
145 virtual void addCanvasIndicators(SPLPEItem *lpeitem, std::vector<Geom::PathVector> &hp_vec);
148 std::vector<Parameter *> param_vector;
149 std::vector<std::pair<KnotHolderEntity*, const char*> > kh_entity_vector;
150 int oncanvasedit_it;
151 BoolParam is_visible;
153 bool show_orig_path; // set this to true in derived effects to automatically have the original
154 // path displayed as helperpath
156 Inkscape::UI::Widget::Registry wr;
158 LivePathEffectObject *lpeobj;
160 // this boolean defaults to false, it concatenates the input path to one pwd2,
161 // instead of normally 'splitting' the path into continuous pwd2 paths.
162 bool concatenate_before_pwd2;
164 private:
165 bool provides_own_flash_paths; // if true, the standard flash path is suppressed
167 bool is_ready;
169 Effect(const Effect&);
170 Effect& operator=(const Effect&);
171 };
173 } //namespace LivePathEffect
174 } //namespace Inkscape
176 #endif
178 /*
179 Local Variables:
180 mode:c++
181 c-file-style:"stroustrup"
182 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
183 indent-tabs-mode:nil
184 fill-column:99
185 End:
186 */
187 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :