Code

ae42e358c2ef3e03bb1fc5d7e48d8d2ef89fdb70
[inkscape.git] / src / live_effects / effect.h
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 "sp-lpe-item.h"
20 #include "knotholder.h"
21 #include "parameter/bool.h"
22 #include "effect-enum.h"
24 #define  LPE_CONVERSION_TOLERANCE 0.01    // FIXME: find good solution for this.
26 struct SPDocument;
27 struct SPDesktop;
28 struct SPItem;
29 class SPNodeContext;
30 struct LivePathEffectObject;
32 namespace Gtk {
33     class Widget;
34     class VBox;
35     class Tooltips;
36 }
38 namespace Inkscape {
40 namespace XML {
41     class Node;
42 }
44 namespace NodePath {
45     class Path ;
46 }
48 namespace LivePathEffect {
50 enum LPEPathFlashType {
51     SUPPRESS_FLASH,
52 //    PERMANENT_FLASH,
53     DEFAULT
54 };
56 class Effect {
57 public:
58     static Effect* New(EffectType lpenr, LivePathEffectObject *lpeobj);
59     static void createAndApply(const char* name, SPDocument *doc, SPItem *item);
60     static void createAndApply(EffectType type, SPDocument *doc, SPItem *item);
62     virtual ~Effect();
64     EffectType effectType ();
66     virtual void doOnApply (SPLPEItem *lpeitem);
67     virtual void doBeforeEffect (SPLPEItem *lpeitem);
69     void writeParamsToSVG();
71     virtual void acceptParamPath (SPPath *param_path);
72     static int acceptsNumClicks(EffectType type);
73     int acceptsNumClicks() { return acceptsNumClicks(effectType()); }
74     void doAcceptPathPreparations(SPLPEItem *lpeitem);
76     /*
77      * isReady() indicates whether all preparations which are necessary to apply the LPE are done,
78      * e.g., waiting for a parameter path either before the effect is created or when it needs a
79      * path as argument. This is set in sp_lpe_item_add_path_effect().
80      */
81     inline bool isReady() { return is_ready; }
82     inline void setReady(bool ready = true) { is_ready = ready; }
84     virtual void doEffect (SPCurve * curve);
86     virtual Gtk::Widget * newWidget(Gtk::Tooltips * tooltips);
88     virtual void resetDefaults(SPItem * item);
90     virtual void setup_nodepath(Inkscape::NodePath::Path *np);
92     /// /todo: is this method really necessary? it causes UI inconsistensies... (johan)
93     virtual void transform_multiply(Geom::Matrix const& postmul, bool set);
95     // /TODO: providesKnotholder() is currently used as an indicator of whether a nodepath is
96     // created for an item or not. When we allow both at the same time, this needs rethinking!
97     bool providesKnotholder();
98     // /TODO: in view of providesOwnFlashPaths() below, this is somewhat redundant
99     //       (but spiro lpe still needs it!)
100     virtual LPEPathFlashType pathFlashType() { return DEFAULT; }
101     void addHandles(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item);
102     std::vector<Geom::PathVector> getHelperPaths(SPLPEItem *lpeitem);
104     inline bool providesOwnFlashPaths() {
105         return provides_own_flash_paths || show_orig_path;
106     }
107     inline bool showOrigPath() { return show_orig_path; }
109     Glib::ustring          getName();
110     Inkscape::XML::Node *  getRepr();
111     SPDocument *           getSPDoc();
112     LivePathEffectObject * getLPEObj() {return lpeobj;};
113     Parameter *            getParameter(const char * key);
115     void readallParameters(Inkscape::XML::Node * repr);
116     void setParameter(const gchar * key, const gchar * new_value);
118     inline bool isVisible() { return is_visible; }
120     void editNextParamOncanvas(SPItem * item, SPDesktop * desktop);
122 protected:
123     Effect(LivePathEffectObject *lpeobject);
125     // provide a set of doEffect functions so the developer has a choice
126     // of what kind of input/output parameters he desires.
127     // the order in which they appear is the order in which they are
128     // called by this base class. (i.e. doEffect(SPCurve * curve) defaults to calling
129     // doEffect(std::vector<Geom::Path> )
130     virtual std::vector<Geom::Path>
131             doEffect_path (std::vector<Geom::Path> const & path_in);
132     virtual Geom::Piecewise<Geom::D2<Geom::SBasis> >
133             doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in);
135     void registerParameter(Parameter * param);
136     void registerKnotHolderHandle(KnotHolderEntity* entity, const char* descr);
137     Parameter * getNextOncanvasEditableParam();
139     void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item);
141     //virtual std::vector<Geom::PathVector> getCanvasIndicators(SPLPEItem *lpeitem);
142     virtual void addCanvasIndicators(SPLPEItem *lpeitem, std::vector<Geom::PathVector> &hp_vec);
145     std::vector<Parameter *> param_vector;
146     std::vector<std::pair<KnotHolderEntity*, const char*> > kh_entity_vector;
147     int oncanvasedit_it;
148     BoolParam is_visible;
149     BoolParam deactivate_knotholder; // the user can use this to deactivate knotholders (for
150                                      // convenience, because they may interfere with node handles
151                                      // during editing); this is probably only temporary
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 :