Code

ad2d5126f3d6addb4b5ae882942822f70b338cb1
[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 "ui/widget/registry.h"
18 #include "util/enums.h"
19 #include "sp-lpe-item.h"
20 #include "knotholder.h"
22 #define  LPE_CONVERSION_TOLERANCE 0.01    // FIXME: find good solution for this.
24 #define LPE_ENABLE_TEST_EFFECTS
26 struct SPDocument;
27 struct SPDesktop;
28 struct SPItem;
29 class NArtBpath;
30 struct LivePathEffectObject;
32 namespace Gtk {
33     class Widget;
34     class VBox;
35     class Tooltips;
36 }
38 namespace Geom {
39     class Matrix;
40 }
42 namespace Inkscape {
44 namespace XML {
45     class Node;
46 }
48 namespace NodePath {
49     class Path ;
50 }
52 namespace LivePathEffect {
54 enum EffectType {
55     BEND_PATH = 0,
56     PATTERN_ALONG_PATH,
57     SKETCH,
58     VONKOCH,
59     KNOT,
60 #ifdef LPE_ENABLE_TEST_EFFECTS
61     DOEFFECTSTACK_TEST,
62 #endif
63     GEARS,
64     CURVE_STITCH,
65     CIRCLE_WITH_RADIUS,
66     PERSPECTIVE_PATH,
67     SPIRO,
68     CONSTRUCT_GRID,
69     ENVELOPE,
70     PERP_BISECTOR,
71     TANGENT_TO_CURVE,
72     INVALID_LPE // This must be last
73 };
75 extern const Util::EnumData<EffectType> LPETypeData[INVALID_LPE];
76 extern const Util::EnumDataConverter<EffectType> LPETypeConverter;
78 class Parameter;
80 class Effect {
81 public:
82     static Effect* New(EffectType lpenr, LivePathEffectObject *lpeobj);
84     virtual ~Effect();
86     EffectType effectType ();
88     virtual void doOnApply (SPLPEItem *lpeitem);
90     virtual void doBeforeEffect (SPLPEItem *lpeitem);
92     virtual void doEffect (SPCurve * curve);
94     virtual Gtk::Widget * newWidget(Gtk::Tooltips * tooltips);
96     virtual void resetDefaults(SPItem * item);
98     virtual void setup_nodepath(Inkscape::NodePath::Path *np);
100     virtual void transform_multiply(Geom::Matrix const& postmul, bool set);
102     bool providesKnotholder() { return knotholder_func_vector.size() > 0; }
103     void addHandles(SPKnotHolder *knotholder);
105     Glib::ustring          getName();
106     Inkscape::XML::Node *  getRepr();
107     SPDocument *           getSPDoc();
108     LivePathEffectObject * getLPEObj() {return lpeobj;};
109     Parameter *            getParameter(const char * key);
111     void readallParameters(Inkscape::XML::Node * repr);
112     void setParameter(const gchar * key, const gchar * new_value);
114     void editNextParamOncanvas(SPItem * item, SPDesktop * desktop);
116 protected:
117     Effect(LivePathEffectObject *lpeobject);
119     // provide a set of doEffect functions so the developer has a choice
120     // of what kind of input/output parameters he desires.
121     // the order in which they appear is the order in which they are
122     // called by this base class. (i.e. doEffect(SPCurve * curve) defaults to calling
123     // doEffect(std::vector<Geom::Path> )
124     virtual NArtBpath *
125             doEffect_nartbpath (NArtBpath const * path_in) __attribute__ ((deprecated));
126     virtual std::vector<Geom::Path>
127             doEffect_path (std::vector<Geom::Path> const & path_in);
128     virtual Geom::Piecewise<Geom::D2<Geom::SBasis> >
129             doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in);
131     void registerParameter(Parameter * param);
132     void registerKnotHolderHandle(SPKnotHolderSetFunc set_func, SPKnotHolderGetFunc get_func);
133     Parameter * getNextOncanvasEditableParam();
135     std::vector<Parameter *> param_vector;
136     std::vector<std::pair<SPKnotHolderSetFunc, SPKnotHolderGetFunc> > knotholder_func_vector;
137     int oncanvasedit_it;
138     Inkscape::UI::Widget::Registry wr;
140     LivePathEffectObject *lpeobj;
142     // this boolean defaults to false, it concatenates the input path to one pwd2,
143     // instead of normally 'splitting' the path into continuous pwd2 paths.
144     bool concatenate_before_pwd2;
146 private:
147     Effect(const Effect&);
148     Effect& operator=(const Effect&);
149 };
152 } //namespace LivePathEffect
153 } //namespace Inkscape
155 #endif