Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
shape-editor.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
/*
7 * Authors: see git history
8 * bulia byak <buliabyak@users.sf.net>
9 * Krzysztof KosiƄski <tweenk.pl@gmail.com>
10 *
11 * Copyright (C) 2018 Authors
12 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
13 */
14
15#include "shape-editor.h"
16
17#include "desktop.h"
18#include "document.h"
19#include "live_effects/effect.h"
20#include "object/sp-lpe-item.h"
22#include "ui/knot/knot-holder.h"
23
24namespace Inkscape {
25namespace UI {
26
28
29ShapeEditor::ShapeEditor(SPDesktop *dt, Geom::Affine edit_transform, double edit_rotation, int edit_marker_mode)
30 : desktop(dt)
31 , _edit_transform(edit_transform)
32 , _edit_rotation(edit_rotation)
33 , _edit_marker_mode(edit_marker_mode)
34{
35}
36
40
41void ShapeEditor::unset_item(bool keep_knotholder) {
42 if (knotholder) {
43 Inkscape::XML::Node *old_repr = knotholder->repr;
44 if (old_repr && old_repr == knotholder_listener_attached_for) {
45 old_repr->removeObserver(*this);
46 Inkscape::GC::release(old_repr);
48 }
49
50 if (!keep_knotholder) {
51 knotholder.reset();
52 }
53 }
54 if (lpeknotholder) {
55 Inkscape::XML::Node *old_repr = lpeknotholder->repr;
56 bool remove = false;
57 if (old_repr && old_repr == lpeknotholder_listener_attached_for) {
58 old_repr->removeObserver(*this);
59 Inkscape::GC::release(old_repr);
60 remove = true;
61 }
62
63 if (!keep_knotholder) {
64 lpeknotholder.reset();
65 }
66 if (remove) {
68 }
69 }
70}
71
73 if (knotholder) {
74 knotholder->update_knots();
75 }
76 if (lpeknotholder) {
77 lpeknotholder->update_knots();
78 }
79}
80
82{
83 return (knotholder && knotholder->local_change) || (lpeknotholder && lpeknotholder->local_change);
84}
85
87 if (knotholder) {
88 knotholder->local_change = false;
89 }
90 if (lpeknotholder) {
91 lpeknotholder->local_change = false;
92 }
93}
94
98{
99 bool changed_kh = false;
100
101 if (has_knotholder()) {
102 changed_kh = !has_local_change();
104 if (changed_kh) {
105 reset_item();
106 }
107 }
108}
109
110
112 if (_blockSetItem) {
113 return;
114 }
115 // this happens (and should only happen) when for an LPEItem having both knotholder and
116 // nodepath the knotholder is adapted; in this case we don't want to delete the knotholder
117 // since this freezes the handles
118 unset_item(true);
119
120 if (item) {
122 if (!knotholder) {
123 // only recreate knotholder if none is present
125 }
126 auto lpe = cast<SPLPEItem>(item);
127 if (!(lpe &&
128 lpe->getCurrentLPE() &&
129 lpe->getCurrentLPE()->isVisible() &&
130 lpe->getCurrentLPE()->providesKnotholder()))
131 {
132 lpeknotholder.reset();
133 }
134 if (!lpeknotholder) {
135 // only recreate knotholder if none is present
137 }
138 if (knotholder) {
139 knotholder->install_modification_watch(); // let knotholder know item's attribute may have changed
140 knotholder->setEditTransform(_edit_transform);
141 knotholder->update_knots();
142 // setting new listener
143 repr = knotholder->repr;
146 repr->addObserver(*this);
148 }
149 }
150 if (this->lpeknotholder) {
151 this->lpeknotholder->setEditTransform(_edit_transform);
152 this->lpeknotholder->update_knots();
153 // setting new listener
154 repr = this->lpeknotholder->repr;
157 repr->addObserver(*this);
159 }
160 }
161 }
162}
163
164
168{
169 if (knotholder) {
171 set_item(cast<SPItem>(obj));
172 } else if (lpeknotholder) {
174 set_item(cast<SPItem>(obj));
175 }
176}
177
182 if (this->knotholder) {
183 return knotholder->knot_mouseover();
184 }
185 if (this->lpeknotholder) {
186 return lpeknotholder->knot_mouseover();
187 }
188
189 return false;
190}
191
192} // namespace UI
193} // namespace Inkscape
194
195/*
196 Local Variables:
197 mode:c++
198 c-file-style:"stroustrup"
199 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
200 indent-tabs-mode:nil
201 fill-column:99
202 End:
203*/
204// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
3x3 matrix representing an affine transformation.
Definition affine.h:70
void reset_item()
FIXME: This thing is only called when the item needs to be updated in response to repr change.
void notifyAttributeChanged(Inkscape::XML::Node &node, GQuark key, Inkscape::Util::ptr_shared oldvalue, Inkscape::Util::ptr_shared newval) final
Attribute change callback.
Inkscape::XML::Node * lpeknotholder_listener_attached_for
bool knot_mouseover() const
Returns true if this ShapeEditor has a knot above which the mouse currently hovers.
void set_item(SPItem *item)
void unset_item(bool keep_knotholder=false)
std::unique_ptr< KnotHolder > knotholder
ShapeEditor(SPDesktop *desktop, Geom::Affine edit_transform=Geom::identity(), double edit_rotation=0.0, int edit_marker_mode=-1)
std::unique_ptr< KnotHolder > lpeknotholder
Inkscape::XML::Node * knotholder_listener_attached_for
Interface for refcounted XML nodes.
Definition node.h:80
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.
To do: update description of desktop.
Definition desktop.h:149
SPDocument * getDocument() const
Definition desktop.h:189
SPObject * getObjectByRepr(Inkscape::XML::Node *repr) const
Base class for visual SVG elements.
Definition sp-item.h:109
SPObject is an abstract base class of all of the document nodes at the SVG document level.
Definition sp-object.h:160
Editable view implementation.
SPItem * item
static R & anchor(R &r)
Increments the reference count of a anchored object.
Definition gc-anchored.h:92
static R & release(R &r)
Decrements the reference count of a anchored object.
std::unique_ptr< KnotHolder > create_LPE_knot_holder(SPItem *item, SPDesktop *desktop)
std::unique_ptr< KnotHolder > create_knot_holder(SPItem *item, SPDesktop *desktop, double edit_rotation, int edit_marker_mode)
Helper class to stream background task notifications as a series of messages.
void remove(std::vector< T > &vec, T const &val)
Definition sanitize.cpp:94
Inkscape::ShapeEditor This is a container class which contains a knotholder for shapes.
Base class for live path effect items.
guint32 GQuark
SPDesktop * desktop