Code

Merging in the changes from the 0.47 release branch. Also updating version numbers...
[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/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     virtual void setup_nodepath(Inkscape::NodePath::Path *np);
97     /// /todo: is this method really necessary? it causes UI inconsistensies... (johan)
98     virtual void transform_multiply(Geom::Matrix const& postmul, bool set);
100     // /TODO: providesKnotholder() is currently used as an indicator of whether a nodepath is
101     // created for an item or not. When we allow both at the same time, this needs rethinking!
102     bool providesKnotholder();
103     // /TODO: in view of providesOwnFlashPaths() below, this is somewhat redundant
104     //       (but spiro lpe still needs it!)
105     virtual LPEPathFlashType pathFlashType() { return DEFAULT; }
106     void addHandles(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item);
107     std::vector<Geom::PathVector> getHelperPaths(SPLPEItem *lpeitem);
109     inline bool providesOwnFlashPaths() {
110         return provides_own_flash_paths || show_orig_path;
111     }
112     inline bool showOrigPath() { return show_orig_path; }
114     Glib::ustring          getName();
115     Inkscape::XML::Node *  getRepr();
116     SPDocument *           getSPDoc();
117     LivePathEffectObject * getLPEObj() {return lpeobj;};
118     Parameter *            getParameter(const char * key);
120     void readallParameters(Inkscape::XML::Node * repr);
121     void setParameter(const gchar * key, const gchar * new_value);
123     inline bool isVisible() { return is_visible; }
125     void editNextParamOncanvas(SPItem * item, SPDesktop * desktop);
127 protected:
128     Effect(LivePathEffectObject *lpeobject);
130     // provide a set of doEffect functions so the developer has a choice
131     // of what kind of input/output parameters he desires.
132     // the order in which they appear is the order in which they are
133     // called by this base class. (i.e. doEffect(SPCurve * curve) defaults to calling
134     // doEffect(std::vector<Geom::Path> )
135     virtual std::vector<Geom::Path>
136             doEffect_path (std::vector<Geom::Path> const & path_in);
137     virtual Geom::Piecewise<Geom::D2<Geom::SBasis> >
138             doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in);
140     void registerParameter(Parameter * param);
141     void registerKnotHolderHandle(KnotHolderEntity* entity, const char* descr);
142     Parameter * getNextOncanvasEditableParam();
144     void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item);
146     //virtual std::vector<Geom::PathVector> getCanvasIndicators(SPLPEItem *lpeitem);
147     virtual void addCanvasIndicators(SPLPEItem *lpeitem, std::vector<Geom::PathVector> &hp_vec);
150     std::vector<Parameter *> param_vector;
151     std::vector<std::pair<KnotHolderEntity*, const char*> > kh_entity_vector;
152     int oncanvasedit_it;
153     BoolParam is_visible;
155     bool show_orig_path; // set this to true in derived effects to automatically have the original
156                          // path displayed as helperpath
158     Inkscape::UI::Widget::Registry wr;
160     LivePathEffectObject *lpeobj;
162     // this boolean defaults to false, it concatenates the input path to one pwd2,
163     // instead of normally 'splitting' the path into continuous pwd2 paths.
164     bool concatenate_before_pwd2;
166 private:
167     bool provides_own_flash_paths; // if true, the standard flash path is suppressed
169     bool is_ready;
171     Effect(const Effect&);
172     Effect& operator=(const Effect&);
173 };
175 } //namespace LivePathEffect
176 } //namespace Inkscape
178 #endif
180 /*
181   Local Variables:
182   mode:c++
183   c-file-style:"stroustrup"
184   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
185   indent-tabs-mode:nil
186   fill-column:99
187   End:
188 */
189 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :