Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
effect.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2
3/*
4 * Copyright (C) Johan Engelen 2007-2012 <j.b.c.engelen@alumnus.utwente.nl>
5 *
6 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
7 */
8
9#ifndef INKSCAPE_LIVEPATHEFFECT_H
10#define INKSCAPE_LIVEPATHEFFECT_H
11
12#include "effect-enum.h"
13#include "parameter/bool.h"
14#include "parameter/hidden.h"
15#include "ui/widget/registry.h"
16#include <2geom/forward.h>
17#include <glibmm/ustring.h>
18#include <iostream>
19
20#define LPE_CONVERSION_TOLERANCE 0.01 // FIXME: find good solution for this.
21
22class SPDocument;
23class SPDesktop;
24class SPItem;
26class SPLPEItem;
27class KnotHolder;
29class SPPath;
30class SPCurve;
31
32namespace Gtk {
33 class Widget;
34}
35
36namespace Inkscape {
37
38namespace XML {
39 class Node;
40}
41
42namespace LivePathEffect {
43
46// PERMANENT_FLASH,
48};
49
58
59// maybe can grow in the future with more SPItemData
61 size_t nchildshapes = 0;
62 size_t nsubpaths = 0;
63 size_t ncurves = 0;
64 inline bool operator==(LPEItemShapesNumbers const &other) const = default;
65 inline bool operator!=(LPEItemShapesNumbers other) const
66 {
67 return !(*this == other);
68 }
69};
70inline std::ostream &operator<<(std::ostream &os, LPEItemShapesNumbers const &lpeitemnumbers) {
71 os << "Number of child shapes:" << lpeitemnumbers.nchildshapes << std::endl;
72 os << "Number of subpaths:" << lpeitemnumbers.nsubpaths << std::endl;
73 os << "Number of curves:" << lpeitemnumbers.ncurves;
74 return os;
75}
76class Effect {
77public:
79 static void createAndApply(const char* name, SPDocument *doc, SPItem *item);
80 static void createAndApply(EffectType type, SPDocument *doc, SPItem *item);
81
82 virtual ~Effect();
83 Effect(const Effect&) = delete;
84 Effect& operator=(const Effect&) = delete;
85
86 EffectType effectType() const;
87
88 //basically, to get this method called before the derived classes, a bit
89 //of indirection is needed. We first call these methods, then the below.
90 void doAfterEffect_impl(SPLPEItem const *lpeitem, SPCurve *curve);
91 void doOnApply_impl(SPLPEItem const* lpeitem);
92 void doBeforeEffect_impl(SPLPEItem const* lpeitem);
93 void doOnOpen_impl();
94 void doOnRemove_impl(SPLPEItem const* lpeitem);
95 void transform_multiply_impl(Geom::Affine const &postmul, SPLPEItem *);
96 void doOnBeforeCommit();
97 void read_from_SVG();
98 void setCurrentZoom(double cZ);
99 void setSelectedNodePoints(std::vector<Geom::Point> sNP);
100 bool isNodePointSelected(Geom::Point const &nodePoint) const;
101 bool isOnClipboard();
102 std::vector<SPLPEItem *> getCurrrentLPEItems() const;
103 void update_satellites();
104 virtual void doOnException(SPLPEItem const *lpeitem);
105 virtual void doOnVisibilityToggled(SPLPEItem const* lpeitem);
106 virtual void adjustForNewPath();
107 void writeParamsToSVG();
108 std::vector<SPObject *> effect_get_satellites(bool force = true);
109 virtual void acceptParamPath (SPPath const* param_path);
110 static int acceptsNumClicks(EffectType type);
112 SPShape * getCurrentShape() const { return current_shape; };
113 void setCurrentShape(SPShape * shape) { current_shape = shape; }
114 virtual void processObjects(LPEAction lpe_action);
115 void makeUndoDone(Glib::ustring message);
116 /*
117 * isReady() indicates whether all preparations which are necessary to apply the LPE are done,
118 * e.g., waiting for a parameter path either before the effect is created or when it needs a
119 * path as argument. This is set in SPLPEItem::addPathEffect().
120 */
121 inline bool isReady() const { return is_ready; }
122 inline void setReady(bool ready = true) { is_ready = ready; }
123
124 virtual void doEffect (SPCurve * curve);
125
126 virtual Gtk::Widget * newWidget();
130 virtual void resetDefaults(SPItem const* item);
131
132 // /TODO: providesKnotholder() is currently used as an indicator of whether a nodepath is
133 // created for an item or not. When we allow both at the same time, this needs rethinking!
134 bool providesKnotholder() const;
135 // /TODO: in view of providesOwnFlashPaths() below, this is somewhat redundant
136 // (but spiro lpe still needs it!)
137 virtual LPEPathFlashType pathFlashType() const { return DEFAULT; }
138 void addHandles(KnotHolder *knotholder, SPItem *item);
139 std::vector<Geom::PathVector> getCanvasIndicators(SPLPEItem const* lpeitem);
140 void update_helperpath();
142
143 inline bool providesOwnFlashPaths() const {
145 }
146 inline bool showOrigPath() const { return show_orig_path; }
147
148 Glib::ustring getName() const;
152 LivePathEffectObject const * getLPEObj() const {return lpeobj;};
153 Parameter * getParameter(const char * key);
154
155 void readallParameters(Inkscape::XML::Node const* repr);
156 void setParameter(const gchar * key, const gchar * new_value);
157
158 inline bool isVisible() const { return is_visible; }
159
162 bool keep_paths; // set this to false allow retain extra generated objects, see measure line LPE
167 bool finishiddle = false;
171 void setLPEAction(LPEAction lpe_action) { _lpe_action = lpe_action; }
176 SPLPEItem *sp_lpe_item = nullptr; // these get stored in doBeforeEffect_impl, and derived classes may do as they please with
177 // them.
178 SPShape *current_shape; // these get stored in performPathEffects.
179 std::vector<Parameter *> param_vector;
183 virtual bool getHolderRemove() { return false; }
184protected:
185 Effect(LivePathEffectObject *lpeobject);
187 friend class LPEMeasureSegments;
188 // adjust path study make public if grow
189 bool _adjust_path = false;
190 // provide a set of doEffect functions so the developer has a choice
191 // of what kind of input/output parameters he desires.
192 // the order in which they appear is the order in which they are
193 // called by this base class. (i.e. doEffect(SPCurve * curve) defaults to calling
194 // doEffect(Geom::PathVector )
195 virtual Geom::PathVector
196 doEffect_path (Geom::PathVector const & path_in);
199
200 void registerParameter(Parameter * param);
202
203 virtual void addKnotHolderEntities(KnotHolder * /*knotholder*/, SPItem * /*item*/) {};
204
205 virtual void addCanvasIndicators(SPLPEItem const* lpeitem, std::vector<Geom::PathVector> &hp_vec);
206
211 bool show_orig_path; // set this to true in derived effects to automatically have the original
212 // path displayed as helperpath
213 // this boolean defaults to false, it concatenates the input path to one pwd2,
214 // instead of normally 'splitting' the path into continuous pwd2 paths and calling doEffect_pwd2 for each.
217 std::vector<Geom::Point> selectedNodesPoints;
219private:
221 virtual void transform_multiply(Geom::Affine const &postmul, bool set);
222 virtual bool doOnOpen(SPLPEItem const *lpeitem);
223 virtual void doAfterEffect (SPLPEItem const* lpeitem, SPCurve *curve);
224 // we want to call always to overrided methods not effect ones
225 virtual void doOnRemove(SPLPEItem const* /*lpeitem*/);
226 virtual void doOnApply (SPLPEItem const* lpeitem);
227 virtual void doBeforeEffect (SPLPEItem const* lpeitem);
228
229 void setDefaultParam(Glib::ustring pref_path, Parameter *param);
230 void unsetDefaultParam(Glib::ustring pref_path, Parameter *param);
231 bool provides_own_flash_paths; // if true, the standard flash path is suppressed
236};
237
238} //namespace LivePathEffect
239} //namespace Inkscape
240
241#endif // INKSCAPE_LIVEPATHEFFECT_H
242
243/*
244 Local Variables:
245 mode:c++
246 c-file-style:"stroustrup"
247 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
248 indent-tabs-mode:nil
249 fill-column:99
250 End:
251*/
252// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
3x3 matrix representing an affine transformation.
Definition affine.h:70
Adaptor that creates 2D functions from 1D ones.
Definition d2.h:55
Sequence of subpaths.
Definition pathvector.h:122
Function defined as discrete pieces.
Definition piecewise.h:71
Two-dimensional point that doubles as a vector.
Definition point.h:66
void doBeforeEffect_impl(SPLPEItem const *lpeitem)
Definition effect.cpp:1550
virtual void doOnVisibilityToggled(SPLPEItem const *lpeitem)
Definition effect.cpp:1473
std::vector< Parameter * > param_vector
Definition effect.h:179
void registerParameter(Parameter *param)
Definition effect.cpp:1710
virtual void addCanvasIndicators(SPLPEItem const *lpeitem, std::vector< Geom::PathVector > &hp_vec)
Add possible canvas indicators (i.e., helperpaths other than the original path) to hp_vec This functi...
Definition effect.cpp:1768
virtual void resetDefaults(SPItem const *item)
Sets all parameters to their default values and writes them to SVG.
Definition effect.cpp:2014
virtual Gtk::Widget * newWidget()
This creates a managed widget.
Definition effect.cpp:1790
LivePathEffectObject const * getLPEObj() const
Definition effect.h:152
void setReady(bool ready=true)
Definition effect.h:122
static void createAndApply(const char *name, SPDocument *doc, SPItem *item)
Definition effect.cpp:1118
virtual void doOnRemove(SPLPEItem const *)
Definition effect.cpp:1470
bool providesOwnFlashPaths() const
Definition effect.h:143
void setParameter(const gchar *key, const gchar *new_value)
Definition effect.cpp:1693
bool hasDefaultParameters()
Get LPE has defaults.
Definition effect.cpp:1860
void transform_multiply_impl(Geom::Affine const &postmul, SPLPEItem *)
Definition effect.cpp:1227
void editNextParamOncanvas(SPItem *item, SPDesktop *desktop)
Definition effect.cpp:1994
std::vector< Geom::PathVector > getCanvasIndicators(SPLPEItem const *lpeitem)
Return a vector of PathVectors which contain all canvas indicators for this effect.
Definition effect.cpp:1745
virtual void doOnApply(SPLPEItem const *lpeitem)
Is performed a single time when the effect is freshly applied to a path.
Definition effect.cpp:1204
static Effect * New(EffectType lpenr, LivePathEffectObject *lpeobj)
Definition effect.cpp:930
Parameter * getParameter(const char *key)
Definition effect.cpp:1948
LivePathEffectObject * lpeobj
Definition effect.h:220
void setLPEAction(LPEAction lpe_action)
Definition effect.h:171
void setDefaultParam(Glib::ustring pref_path, Parameter *param)
Definition effect.cpp:1916
Effect(const Effect &)=delete
virtual void processObjects(LPEAction lpe_action)
Definition effect.cpp:1416
std::vector< SPObject * > effect_get_satellites(bool force=true)
Definition effect.cpp:1588
sigc::connection _before_commit_connection
Definition effect.h:232
Inkscape::XML::Node * getRepr()
Definition effect.cpp:1934
void addHandles(KnotHolder *knotholder, SPItem *item)
Add all registered LPE knotholder handles to the knotholder.
Definition effect.cpp:1720
SPShape * getCurrentShape() const
Definition effect.h:112
Effect & operator=(const Effect &)=delete
bool isOnClipboard()
The lpe is on clipboard.
Definition effect.cpp:1248
virtual bool getHolderRemove()
Definition effect.h:183
Parameter * getNextOncanvasEditableParam()
Definition effect.cpp:1967
void doAfterEffect_impl(SPLPEItem const *lpeitem, SPCurve *curve)
Definition effect.cpp:1483
void unsetDefaultParam(Glib::ustring pref_path, Parameter *param)
Definition effect.cpp:1924
bool isNodePointSelected(Geom::Point const &nodePoint) const
Definition effect.cpp:1258
std::vector< SPLPEItem * > getCurrrentLPEItems() const
Definition effect.cpp:1187
virtual void doOnException(SPLPEItem const *lpeitem)
Definition effect.cpp:1463
void setDefaultParameters()
Set this LPE defaults.
Definition effect.cpp:1829
Geom::PathVector pathvector_before_effect
Definition effect.h:174
Glib::ustring getName() const
Definition effect.cpp:1173
void doOnOpen_impl()
Is performed on document open allow things like fix legacy LPE in a undo insensitive way.
Definition effect.cpp:1510
void setSelectedNodePoints(std::vector< Geom::Point > sNP)
Definition effect.cpp:1240
EffectType effectType() const
Definition effect.cpp:1182
void makeUndoDone(Glib::ustring message)
Definition effect.cpp:1521
virtual void doBeforeEffect(SPLPEItem const *lpeitem)
Is performed each time before the effect is updated.
Definition effect.cpp:1444
LPEItemShapesNumbers _lpenumbers
Definition effect.h:233
void update_helperpath()
Call to a method on nodetool to update the helper path from the effect.
Definition effect.cpp:1776
Geom::PathVector pathvector_after_effect
Definition effect.h:175
virtual void doEffect(SPCurve *curve)
Definition effect.cpp:1616
void doOnRemove_impl(SPLPEItem const *lpeitem)
Definition effect.cpp:1491
virtual void transform_multiply(Geom::Affine const &postmul, bool set)
Overridden function to apply transforms for example to powerstroke, jointtype or tapperstroke.
Definition effect.cpp:1217
virtual void doAfterEffect(SPLPEItem const *lpeitem, SPCurve *curve)
Is performed at the end of the LPE only one time per "lpeitem" in paths/shapes is called in middle of...
Definition effect.cpp:1457
std::vector< Geom::Point > selectedNodesPoints
Definition effect.h:217
void readallParameters(Inkscape::XML::Node const *repr)
Definition effect.cpp:1662
void doOnApply_impl(SPLPEItem const *lpeitem)
Definition effect.cpp:1532
void setCurrentShape(SPShape *shape)
Definition effect.h:113
void resetDefaultParameters()
Reset this LPE defaults.
Definition effect.cpp:1889
LivePathEffectObject * getLPEObj()
Definition effect.h:151
virtual LPEPathFlashType pathFlashType() const
Definition effect.h:137
virtual Geom::PathVector doEffect_path(Geom::PathVector const &path_in)
Definition effect.cpp:1626
virtual bool doOnOpen(SPLPEItem const *lpeitem)
Is performed on load document or revert If the item is fixed legacy return true.
Definition effect.cpp:1424
virtual void acceptParamPath(SPPath const *param_path)
If the effect expects a path parameter (specified by a number of mouse clicks) before it is applied,...
Definition effect.cpp:1608
virtual Geom::Piecewise< Geom::D2< Geom::SBasis > > doEffect_pwd2(Geom::Piecewise< Geom::D2< Geom::SBasis > > const &pwd2_in)
Definition effect.cpp:1655
Inkscape::UI::Widget::Registry wr
Definition effect.h:218
virtual void addKnotHolderEntities(KnotHolder *, SPItem *)
Definition effect.h:203
Interface for refcounted XML nodes.
Definition node.h:80
KnotHolderEntity definition.
Wrapper around a Geom::PathVector object.
Definition curve.h:28
To do: update description of desktop.
Definition desktop.h:149
Typed SVG document implementation.
Definition document.h:101
Base class for visual SVG elements.
Definition sp-item.h:109
SVG <path> implementation.
Definition sp-path.h:29
Base class for shapes, including <path> element.
Definition sp-shape.h:38
Contains forward declarations of 2geom types.
SPItem * item
std::ostream & operator<<(std::ostream &os, const Bezier &b)
Definition bezier.h:372
Definition desktop.h:50
Helper class to stream background task notifications as a series of messages.
static cairo_user_data_key_t key
bool ready
bool operator==(LPEItemShapesNumbers const &other) const =default
bool operator!=(LPEItemShapesNumbers other) const
Definition effect.h:65
Definition curve.h:24
SPDesktop * desktop
Glib::ustring name
Definition toolbars.cpp:55