Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
lpeobject.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Copyright (C) Johan Engelen 2007-2008 <j.b.c.engelen@utwente.nl>
4 * Abhishek Sharma
5 *
6 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
7 */
8
10
11#include "attributes.h"
12#include "document.h"
13#include "live_effects/effect.h"
14#include "object/sp-defs.h"
15
16//#define LIVEPATHEFFECT_VERBOSE
17
19{
20#ifdef LIVEPATHEFFECT_VERBOSE
21 g_message("Init livepatheffectobject");
22#endif
23}
24
26
31{
33
35
36 if (repr) {
38 }
40 /* Register ourselves, is this necessary? */
41 // document->addResource("path-effect", object);
42}
43
48{
50 if (this->lpe) {
51 delete this->lpe;
52 this->lpe = nullptr;
53 }
54
56
58}
59
63void LivePathEffectObject::set(SPAttr key, gchar const *value) {
64#ifdef LIVEPATHEFFECT_VERBOSE
65 g_print("Set livepatheffect");
66#endif
67
68 switch (key) {
70 if (this->lpe) {
71 delete this->lpe;
72 this->lpe = nullptr;
73 }
74 if ( value && Inkscape::LivePathEffect::LPETypeConverter.is_valid_key(value) ) {
75 this->effecttype = Inkscape::LivePathEffect::LPETypeConverter.get_id_from_key(value);
77 this->effecttype_set = true;
78 this->deleted = false;
79 } else {
81 this->lpe = nullptr;
82 this->effecttype_set = false;
83 }
84
85 this->requestModified(SP_OBJECT_MODIFIED_FLAG);
86 break;
87 }
88
89 SPObject::set(key, value);
90}
91
96 if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) {
97 repr = xml_doc->createElement("inkscape:path-effect");
98 }
99
100 if ((flags & SP_OBJECT_WRITE_ALL) || this->lpe) {
102
103 this->lpe->writeParamsToSVG();
104 }
105
106 SPObject::write(xml_doc, repr, flags);
107
108 return repr;
109}
110
111// Caution using this function, just compare id and same type of
112// effect, we use on clipboard to do not fork in same doc on pastepatheffect
114{
115 if (that) {
116 const char *thisid = this->getId();
117 const char *thatid = that->getId();
118 if (!thisid || !thatid || strcmp(thisid, thatid) != 0) {
119 return false;
120 }
121 Inkscape::LivePathEffect::Effect *thislpe = this->get_lpe();
122 Inkscape::LivePathEffect::Effect *thatlpe = that->get_lpe();
123 if (thatlpe && thislpe && thislpe->getName() != thatlpe->getName()) {
124 return false;
125 }
126 }
127 return true;
128}
129
134{
135 // when no document we are intermedite state between clipboard
136 if (!document) {
137 _isOnClipboard = true;
138 return;
139 }
140
142 Inkscape::XML::Node *clipnode = sp_repr_lookup_name(root, "inkscape:clipboard", 1);
143 _isOnClipboard = clipnode != nullptr;
144}
145
152{
153 if (hrefcount > nr_of_allowed_users) {
154 SPDocument *doc = this->document;
155 Inkscape::XML::Document *xml_doc = doc->getReprDoc();
156 Inkscape::XML::Node *dup_repr = this->getRepr()->duplicate(xml_doc);
157
158 doc->getDefs()->getRepr()->addChild(dup_repr, nullptr);
159 auto lpeobj_new = cast<LivePathEffectObject>(doc->getObjectByRepr(dup_repr));
160 Inkscape::GC::release(dup_repr);
161 // To regenerate ID
162 sp_object_ref(lpeobj_new, nullptr);
163 auto id = generate_unique_id();
164 lpeobj_new->setAttribute("id", id);
165 // Load all volatile vars of forked item
166 sp_object_unref(lpeobj_new, nullptr);
167 return lpeobj_new;
168 }
169 return this;
170}
171
174{
175#ifdef LIVEPATHEFFECT_VERBOSE
176 g_print("LPENodeObserver::notifyAttributeChanged()\n");
177#endif
178 auto lpeobj = static_cast<LivePathEffectObject *>(this);
179 auto const key = g_quark_to_string(key_);
180 if (!lpeobj->get_lpe()) {
181 return;
182 }
183 lpeobj->get_lpe()->setParameter(key, newval);
184 lpeobj->requestModified(SP_OBJECT_MODIFIED_FLAG);
185}
186
187/*
188 Local Variables:
189 mode:c++
190 c-file-style:"stroustrup"
191 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
192 indent-tabs-mode:nil
193 fill-column:99
194 End:
195*/
196// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
Lookup dictionary for attributes/properties.
SPAttr
Definition attributes.h:27
@ PATH_EFFECT
static Effect * New(EffectType lpenr, LivePathEffectObject *lpeobj)
Definition effect.cpp:930
Glib::ustring getName() const
Definition effect.cpp:1173
Interface for refcounted XML nodes.
Definition node.h:80
virtual void addChild(Node *child, Node *after)=0
Insert another node as a child of this node.
void setAttributeOrRemoveIfEmpty(Inkscape::Util::const_char_ptr key, Inkscape::Util::const_char_ptr value)
Change an attribute of this node.
Definition node.cpp:167
virtual Node * duplicate(Document *doc) const =0
Create a duplicate of this node.
virtual void addObserver(NodeObserver &observer)=0
Add an object that will be notified of the changes to this node.
virtual void removeObserver(NodeObserver &observer)=0
Remove an object from the list of observers.
void notifyAttributeChanged(Inkscape::XML::Node &node, GQuark key, Inkscape::Util::ptr_shared oldval, Inkscape::Util::ptr_shared newval) final
Attribute change callback.
void build(SPDocument *doc, Inkscape::XML::Node *repr) override
Virtual build: set livepatheffect attributes from its associated XML node.
Definition lpeobject.cpp:30
Inkscape::LivePathEffect::Effect * get_lpe()
Definition lpeobject.h:51
~LivePathEffectObject() override
void set(SPAttr key, char const *value) override
Virtual set: set attribute to value.
Definition lpeobject.cpp:63
void setOnClipboard()
Set lpeobject is on clipboard.
Inkscape::XML::Node * write(Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, unsigned int flags) override
Virtual write: write object attributes to repr.
Definition lpeobject.cpp:95
Inkscape::LivePathEffect::Effect * lpe
Definition lpeobject.h:54
LPENodeObserver & nodeObserver()
Definition lpeobject.h:68
bool is_similar(LivePathEffectObject *that)
Inkscape::LivePathEffect::EffectType effecttype
Definition lpeobject.h:39
LivePathEffectObject * fork_private_if_necessary(unsigned int nr_of_allowed_users=1)
If this has other users, create a new private duplicate and return it returns 'this' when no forking ...
void release() override
Virtual release of livepatheffect members before destruction.
Definition lpeobject.cpp:47
Typed SVG document implementation.
Definition document.h:101
Inkscape::XML::Node * getReprRoot()
Definition document.h:206
SPDefs * getDefs()
Return the main defs object for the document.
Definition document.cpp:247
Inkscape::XML::Document * getReprDoc()
Our Inkscape::XML::Document.
Definition document.h:211
SPObject * getObjectByRepr(Inkscape::XML::Node *repr) const
Inkscape::XML::Node * repr
Definition sp-object.h:193
void requestModified(unsigned int flags)
Requests that a modification notification signal be emitted later (e.g.
SPDocument * document
Definition sp-object.h:188
virtual void set(SPAttr key, const char *value)
char const * getId() const
Returns the objects current ID string.
virtual Inkscape::XML::Node * write(Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, unsigned int flags)
virtual void release()
void readAttr(char const *key)
Read value of key attribute from XML node into object.
std::string generate_unique_id(char const *default_id=nullptr) const
Generate a document-wide unique id for this object.
Inkscape::XML::Node * getRepr()
Returns the XML representation of tree.
virtual void build(SPDocument *doc, Inkscape::XML::Node *repr)
unsigned int hrefcount
Definition sp-object.h:186
RootCluster root
static R & release(R &r)
Decrements the reference count of a anchored object.
const EnumEffectDataConverter< EffectType > LPETypeConverter
defined in effect.cpp
static cairo_user_data_key_t key
Inkscape::XML::Node const * sp_repr_lookup_name(Inkscape::XML::Node const *repr, gchar const *name, gint maxdepth)
guint32 GQuark
SPObject * sp_object_unref(SPObject *object, SPObject *owner)
Decrease reference count of object, with possible debugging and finalization.
SPObject * sp_object_ref(SPObject *object, SPObject *owner)
Increase reference count of object, with possible debugging.
Interface for XML documents.
Definition document.h:43
virtual Node * createElement(char const *name)=0