Code

Infrastructure in class LivePathEffect::Effect to put Inkscape into 'wait for paramet...
[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"
21 #include "parameter/bool.h"
23 #define  LPE_CONVERSION_TOLERANCE 0.01    // FIXME: find good solution for this.
25 #define LPE_ENABLE_TEST_EFFECTS
27 struct SPDocument;
28 struct SPDesktop;
29 struct SPItem;
30 class NArtBpath;
31 struct LivePathEffectObject;
33 namespace Gtk {
34     class Widget;
35     class VBox;
36     class Tooltips;
37 }
39 namespace Geom {
40     class Matrix;
41 }
43 namespace Inkscape {
45 namespace XML {
46     class Node;
47 }
49 namespace NodePath {
50     class Path ;
51 }
53 namespace LivePathEffect {
55 enum EffectType {
56     BEND_PATH = 0,
57     PATTERN_ALONG_PATH,
58     SKETCH,
59     VONKOCH,
60     KNOT,
61 #ifdef LPE_ENABLE_TEST_EFFECTS
62     DOEFFECTSTACK_TEST,
63 #endif
64     GEARS,
65     CURVE_STITCH,
66     CIRCLE_WITH_RADIUS,
67     PERSPECTIVE_PATH,
68     SPIRO,
69     LATTICE,
70     ENVELOPE,
71     CONSTRUCT_GRID,
72     PERP_BISECTOR,
73     TANGENT_TO_CURVE,
74     MIRROR_REFLECT,
75     INVALID_LPE // This must be last
76 };
78 extern const Util::EnumData<EffectType> LPETypeData[INVALID_LPE];
79 extern const Util::EnumDataConverter<EffectType> LPETypeConverter;
81 enum LPEPathFlashType {
82     SUPPRESS_FLASH,
83     PERMANENT_FLASH,
84     DEFAULT
85 };
87 class Effect {
88 public:
89     static Effect* New(EffectType lpenr, LivePathEffectObject *lpeobj);
90     static void createAndApply(const char* name, SPDocument *doc, SPItem *item);
91     static void createAndApply(EffectType type, SPDocument *doc, SPItem *item);
93     virtual ~Effect();
95     EffectType effectType ();
97     virtual void doOnApply (SPLPEItem *lpeitem);
98     virtual void doBeforeEffect (SPLPEItem *lpeitem);
100     void writeParamsToSVG();
102     virtual void acceptParamPath (SPPath *param_path);
103     virtual int acceptsNumParams() { return 0; }
104     void doAcceptPathPreparations(SPLPEItem *lpeitem);
106     inline bool pathParamAccepted() { return done_pathparam_set; }
108     virtual void doEffect (SPCurve * curve);
110     virtual Gtk::Widget * newWidget(Gtk::Tooltips * tooltips);
112     virtual void resetDefaults(SPItem * item);
114     virtual void setup_nodepath(Inkscape::NodePath::Path *np);
116     virtual void transform_multiply(Geom::Matrix const& postmul, bool set);
118     bool providesKnotholder() { return (kh_entity_vector.size() > 0); }
119     virtual LPEPathFlashType pathFlashType() { return DEFAULT; }
120     void addHandles(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item);
122     Glib::ustring          getName();
123     Inkscape::XML::Node *  getRepr();
124     SPDocument *           getSPDoc();
125     LivePathEffectObject * getLPEObj() {return lpeobj;};
126     Parameter *            getParameter(const char * key);
128     void readallParameters(Inkscape::XML::Node * repr);
129     void setParameter(const gchar * key, const gchar * new_value);
131     inline bool isVisible() { return is_visible; }
133     void editNextParamOncanvas(SPItem * item, SPDesktop * desktop);
135 protected:
136     Effect(LivePathEffectObject *lpeobject);
138     // provide a set of doEffect functions so the developer has a choice
139     // of what kind of input/output parameters he desires.
140     // the order in which they appear is the order in which they are
141     // called by this base class. (i.e. doEffect(SPCurve * curve) defaults to calling
142     // doEffect(std::vector<Geom::Path> )
143     virtual std::vector<Geom::Path>
144             doEffect_path (std::vector<Geom::Path> const & path_in);
145     virtual Geom::Piecewise<Geom::D2<Geom::SBasis> >
146             doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in);
148     void registerParameter(Parameter * param);
149     void registerKnotHolderHandle(KnotHolderEntity* entity, const char* descr);
150     void addPointParamHandles(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item);
151     Parameter * getNextOncanvasEditableParam();
153     std::vector<Parameter *> param_vector;
154     std::vector<std::pair<KnotHolderEntity*, const char*> > kh_entity_vector;
155     int oncanvasedit_it;
156     BoolParam is_visible;
157     bool done_pathparam_set;
159     Inkscape::UI::Widget::Registry wr;
161     LivePathEffectObject *lpeobj;
163     // this boolean defaults to false, it concatenates the input path to one pwd2,
164     // instead of normally 'splitting' the path into continuous pwd2 paths.
165     bool concatenate_before_pwd2;
167 private:
168     Effect(const Effect&);
169     Effect& operator=(const Effect&);
170 };
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 :