Code

Split SPCanvasItem and SPCanvasGroup to individual .h files. Removed forward header.
[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 <map>
14 #include <glibmm/ustring.h>
15 #include <2geom/forward.h>
16 #include "ui/widget/registry.h"
17 #include "parameter/bool.h"
18 #include "effect-enum.h"
20 #define  LPE_CONVERSION_TOLERANCE 0.01    // FIXME: find good solution for this.
22 struct SPDocument;
23 struct SPDesktop;
24 struct SPItem;
25 class SPNodeContext;
26 struct LivePathEffectObject;
27 class SPLPEItem;
28 class KnotHolder;
29 class KnotHolderEntity;
30 class SPPath;
31 struct SPCurve;
33 namespace Gtk {
34     class Widget;
35     class VBox;
36     class Tooltips;
37 }
39 namespace Inkscape {
41 namespace XML {
42     class Node;
43 }
45 namespace NodePath {
46     class Path ;
47 }
49 namespace LivePathEffect {
51 enum LPEPathFlashType {
52     SUPPRESS_FLASH,
53 //    PERMANENT_FLASH,
54     DEFAULT
55 };
57 class Effect {
58 public:
59     static Effect* New(EffectType lpenr, LivePathEffectObject *lpeobj);
60     static void createAndApply(const char* name, SPDocument *doc, SPItem *item);
61     static void createAndApply(EffectType type, SPDocument *doc, SPItem *item);
63     virtual ~Effect();
65     EffectType effectType ();
67     virtual void doOnApply (SPLPEItem *lpeitem);
68     virtual void doBeforeEffect (SPLPEItem *lpeitem);
70     void writeParamsToSVG();
72     virtual void acceptParamPath (SPPath *param_path);
73     static int acceptsNumClicks(EffectType type);
74     int acceptsNumClicks() { return acceptsNumClicks(effectType()); }
75     void doAcceptPathPreparations(SPLPEItem *lpeitem);
77     /*
78      * isReady() indicates whether all preparations which are necessary to apply the LPE are done,
79      * e.g., waiting for a parameter path either before the effect is created or when it needs a
80      * path as argument. This is set in sp_lpe_item_add_path_effect().
81      */
82     inline bool isReady() { return is_ready; }
83     inline void setReady(bool ready = true) { is_ready = ready; }
85     virtual void doEffect (SPCurve * curve);
87     virtual Gtk::Widget * newWidget(Gtk::Tooltips * tooltips);
89     /**
90      * Sets all parameters to their default values and writes them to SVG.
91      */
92     virtual void resetDefaults(SPItem * item);
94     /// /todo: is this method really necessary? it causes UI inconsistensies... (johan)
95     virtual void transform_multiply(Geom::Matrix const& postmul, bool set);
97     // /TODO: providesKnotholder() is currently used as an indicator of whether a nodepath is
98     // created for an item or not. When we allow both at the same time, this needs rethinking!
99     bool providesKnotholder();
100     // /TODO: in view of providesOwnFlashPaths() below, this is somewhat redundant
101     //       (but spiro lpe still needs it!)
102     virtual LPEPathFlashType pathFlashType() { return DEFAULT; }
103     void addHandles(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item);
104     std::vector<Geom::PathVector> getHelperPaths(SPLPEItem *lpeitem);
106     inline bool providesOwnFlashPaths() {
107         return provides_own_flash_paths || show_orig_path;
108     }
109     inline bool showOrigPath() { return show_orig_path; }
111     Glib::ustring          getName();
112     Inkscape::XML::Node *  getRepr();
113     SPDocument *           getSPDoc();
114     LivePathEffectObject * getLPEObj() {return lpeobj;};
115     Parameter *            getParameter(const char * key);
117     void readallParameters(Inkscape::XML::Node * repr);
118     void setParameter(const gchar * key, const gchar * new_value);
120     inline bool isVisible() { return is_visible; }
122     void editNextParamOncanvas(SPItem * item, SPDesktop * desktop);
124 protected:
125     Effect(LivePathEffectObject *lpeobject);
127     // provide a set of doEffect functions so the developer has a choice
128     // of what kind of input/output parameters he desires.
129     // the order in which they appear is the order in which they are
130     // called by this base class. (i.e. doEffect(SPCurve * curve) defaults to calling
131     // doEffect(std::vector<Geom::Path> )
132     virtual std::vector<Geom::Path>
133             doEffect_path (std::vector<Geom::Path> const & path_in);
134     virtual Geom::Piecewise<Geom::D2<Geom::SBasis> >
135             doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in);
137     void registerParameter(Parameter * param);
138     void registerKnotHolderHandle(KnotHolderEntity* entity, const char* descr);
139     Parameter * getNextOncanvasEditableParam();
141     void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item);
143     //virtual std::vector<Geom::PathVector> getCanvasIndicators(SPLPEItem *lpeitem);
144     virtual void addCanvasIndicators(SPLPEItem *lpeitem, std::vector<Geom::PathVector> &hp_vec);
147     std::vector<Parameter *> param_vector;
148     std::vector<std::pair<KnotHolderEntity*, const char*> > kh_entity_vector;
149     int oncanvasedit_it;
150     BoolParam is_visible;
152     bool show_orig_path; // set this to true in derived effects to automatically have the original
153                          // path displayed as helperpath
155     Inkscape::UI::Widget::Registry wr;
157     LivePathEffectObject *lpeobj;
159     // this boolean defaults to false, it concatenates the input path to one pwd2,
160     // instead of normally 'splitting' the path into continuous pwd2 paths.
161     bool concatenate_before_pwd2;
163 private:
164     bool provides_own_flash_paths; // if true, the standard flash path is suppressed
166     bool is_ready;
168     Effect(const Effect&);
169     Effect& operator=(const Effect&);
170 };
172 } //namespace LivePathEffect
173 } //namespace Inkscape
175 #endif
177 /*
178   Local Variables:
179   mode:c++
180   c-file-style:"stroustrup"
181   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
182   indent-tabs-mode:nil
183   fill-column:99
184   End:
185 */
186 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :