Code

SPDocument->Document
[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 Document;
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, Document *doc, SPItem *item);
60     static void createAndApply(EffectType type, Document *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     /**
89      * Sets all parameters to their default values and writes them to SVG.
90      */
91     virtual void resetDefaults(SPItem * item);
93     virtual void setup_nodepath(Inkscape::NodePath::Path *np);
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     Document *           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 :