Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
lpe-fill-between-strokes.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Copyright (C) Theodore Janeczko 2012 <flutterguy317@gmail.com>
4 *
5 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
6 */
8
9#include <glibmm/i18n.h>
10
11#include "inkscape.h"
12#include "selection.h"
13
14#include "display/curve.h"
15#include "object/sp-root.h"
16
17
18namespace Inkscape {
19namespace LivePathEffect {
20
22 Effect(lpeobject),
23 linked_path(_("Linked path:"), _("Path from which to take the original path data"), "linkedpath", &wr, this),
24 second_path(_("Second path:"), _("Second path from which to take the original path data"), "secondpath", &wr, this),
25 reverse_second(_("Reverse Second"), _("Reverses the second path order"), "reversesecond", &wr, this),
26 join(_("Join subpaths"), _("Join subpaths"), "join", &wr, this, true),
27 close(_("Close"), _("Close path"), "close", &wr, this, true)
28{
36}
37
39
40void
45
46bool
48{
49 if (!is_load || is_applied) {
50 return false;
51 }
58 std::vector<SPLPEItem *> lpeitems = getCurrrentLPEItems();
59 if (lpeitems.size() == 1) {
60 sp_lpe_item = lpeitems[0];
62 }
63 if (auto item = linked_path.getObject()) {
64 item->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
65 }
66 if (auto item = second_path.getObject()) {
67 item->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
68 }
69 return false;
70}
71
72void
74{
75 legacytest = false;
76 std::vector<SPLPEItem *> lpeitems = getCurrrentLPEItems();
77 if (lpeitems.size() == 1) {
78 sp_lpe_item = lpeitems[0];
79 }
80 if (!is_load) {
83 } else {
90 if (auto item = linked_path.getObject()) {
91 item->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
92 }
93 if (auto item = second_path.getObject()) {
94 item->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
95 }
96 }
97 Glib::ustring version = lpeversion.param_getSVGValue();
98 if (version < "1.2") {
99 legacytest = true;
100 }
101}
102void
104{
105 if (is_visible && sp_lpe_item->pathEffectsEnabled() && !isOnClipboard() && !postmul.isIdentity()) {
106 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
107 Inkscape::Selection *selection = nullptr;
108 if (desktop) {
109 selection = desktop->getSelection();
110 }
111 std::vector<SPLPEItem *> lpeitems = getCurrrentLPEItems();
112 if (lpeitems.size() == 1) {
113 sp_lpe_item = lpeitems[0];
114 }
115 if (auto item = linked_path.getObject()) {
116 if (item->document->isSensitive() && selection && !selection->includes(item, true) && selection->includes(sp_lpe_item, true)) {
118 item->transform *= postmul.inverse();
120 item->doWriteTransform(item->transform, nullptr, false);
121 item->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
122 }
123 }
124 if (auto item2 = second_path.getObject()) {
125 if (item2->document->isSensitive() && selection && !selection->includes(item2, true) && selection->includes(sp_lpe_item, true)) {
126 item2->transform *= i2anc_affine(item2->parent, item2->document->getRoot());
127 item2->transform *= postmul.inverse();
128 item2->transform *= i2anc_affine(item2->parent, item2->document->getRoot()).inverse();
129 item2->doWriteTransform(item2->transform, nullptr, false);
130 item2->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
131 }
132 }
133
134 }
135}
136
138{
139 if (curve) {
141 SPItem * linked1 = linked_path.getObject();
142 if (is_load) {
143 linked1->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
144 }
146 SPItem * linked2 = second_path.getObject();
147 if (is_load) {
148 linked2->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
149 }
151 Geom::PathVector result_linked_pathv;
152 Geom::PathVector result_second_pathv;
153 linked_pathv *= linked1->getRelativeTransform(sp_lpe_item);
154 second_pathv *= linked2->getRelativeTransform(sp_lpe_item);
155 for (auto & iter : linked_pathv)
156 {
157 result_linked_pathv.push_back(iter);
158 }
159
160 for (auto & iter : second_pathv)
161 {
162 result_second_pathv.push_back(iter);
163 }
164
165 if ( !result_linked_pathv.empty() && !result_second_pathv.empty() && !result_linked_pathv.front().closed() ) {
167 result_second_pathv.front() = result_second_pathv.front().reversed();
168 }
169 if (join) {
170 if (!are_near(result_linked_pathv.front().finalPoint(), result_second_pathv.front().initialPoint(),0.1)) {
171 result_linked_pathv.front().appendNew<Geom::LineSegment>(result_second_pathv.front().initialPoint());
172 } else {
173 result_second_pathv.front().setInitial(result_linked_pathv.front().finalPoint());
174 }
175 result_linked_pathv.front().append(result_second_pathv.front());
176 if (close) {
177 result_linked_pathv.front().close();
178 }
179 } else {
180 if (close) {
181 result_linked_pathv.front().close();
182 result_second_pathv.front().close();
183 }
184 result_linked_pathv.push_back(result_second_pathv.front());
185 }
186 curve->set_pathvector(result_linked_pathv);
187 } else if ( !result_linked_pathv.empty() ) {
188 curve->set_pathvector(result_linked_pathv);
189 } else if ( !result_second_pathv.empty() ) {
190 curve->set_pathvector(result_second_pathv);
191 }
192 }
193 else if ( linked_path.linksToPath() && linked_path.getObject() ) {
194 SPItem *linked1 = linked_path.getObject();
195 if (is_load) {
196 linked1->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
197 }
199 linked_pathv *= linked1->getRelativeTransform(sp_lpe_item);
200 Geom::PathVector result_pathv;
201 for (auto & iter : linked_pathv)
202 {
203 result_pathv.push_back(iter);
204 }
205 if ( !result_pathv.empty() ) {
206 if (close) {
207 result_pathv.front().close();
208 }
209 curve->set_pathvector(result_pathv);
210 }
211 }
212 else if ( second_path.linksToPath() && second_path.getObject() ) {
213 SPItem *linked2 = second_path.getObject();
214 if (is_load) {
215 linked2->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
216 }
218 second_pathv *= linked2->getRelativeTransform(sp_lpe_item);
219 Geom::PathVector result_pathv;
220 for (auto & iter : second_pathv)
221 {
222 result_pathv.push_back(iter);
223 }
224 if ( !result_pathv.empty() ) {
225 if (close) {
226 result_pathv.front().close();
227 result_pathv.front().snapEnds(0.1);
228 }
229 curve->set_pathvector(result_pathv);
230 }
231 }
232 }
233}
234
235} // namespace LivePathEffect
236} /* namespace Inkscape */
237
238/*
239 Local Variables:
240 mode:c++
241 c-file-style:"stroustrup"
242 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
243 indent-tabs-mode:nil
244 fill-column:99
245 End:
246*/
247// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
3x3 matrix representing an affine transformation.
Definition affine.h:70
bool isIdentity(Coord eps=EPSILON) const
Check whether this matrix is an identity matrix.
Definition affine.cpp:109
Affine inverse() const
Compute the inverse matrix.
Definition affine.cpp:388
Sequence of subpaths.
Definition pathvector.h:122
void push_back(Path const &path)
Append a path at the end.
Definition pathvector.h:172
bool empty() const
Check whether the vector contains any paths.
Definition pathvector.h:145
bool closed() const
Check whether the path is closed.
Definition path.h:503
Point finalPoint() const
Get the last point in the path.
Definition path.h:709
void close(bool closed=true)
Set whether the path is closed.
Definition path.cpp:322
void append(Curve *curve)
Add a new curve to the end of the path.
Definition path.h:750
Point initialPoint() const
Get the first point in the path.
Definition path.h:705
Path reversed() const
Obtain a reversed version of the current path.
Definition path.cpp:866
void snapEnds(Coord precision=EPSILON)
Reduce the closing segment to a point if it's shorter than precision.
Definition path.cpp:969
void setInitial(Point const &p)
Definition path.h:734
void appendNew(Args &&... args)
Append a new curve to the path.
Definition path.h:804
void registerParameter(Parameter *param)
Definition effect.cpp:1710
bool isOnClipboard()
The lpe is on clipboard.
Definition effect.cpp:1248
std::vector< SPLPEItem * > getCurrrentLPEItems() const
Definition effect.cpp:1187
void param_setValue(Glib::ustring newvalue, bool write=false)
Definition hidden.cpp:71
Glib::ustring param_getSVGValue() const override
Definition hidden.cpp:53
bool doOnOpen(SPLPEItem const *lpeitem) override
Is performed on load document or revert If the item is fixed legacy return true.
void doOnApply(SPLPEItem const *lpeitem) override
Is performed a single time when the effect is freshly applied to a path.
void doBeforeEffect(SPLPEItem const *lpeitem) override
Is performed each time before the effect is updated.
void setUpdating(bool updating)
Definition parameter.h:73
Geom::PathVector const & get_pathvector() const
Definition path.cpp:99
void start_listening(SPObject *to)
Definition path.cpp:409
The set of selected SPObjects for a given document and layer model.
Definition selection.h:80
bool includes(XML::Node *repr, bool anyAncestor=false)
Returns true if the given item is selected.
Definition selection.h:140
Wrapper around a Geom::PathVector object.
Definition curve.h:26
To do: update description of desktop.
Definition desktop.h:149
Inkscape::Selection * getSelection() const
Definition desktop.h:188
SPRoot * getRoot()
Returns our SPRoot.
Definition document.h:202
bool isSensitive() const
Definition document.h:365
Base class for visual SVG elements.
Definition sp-item.h:109
Geom::Affine transform
Definition sp-item.h:138
Geom::Affine getRelativeTransform(SPObject const *obj) const
Definition sp-item.cpp:1812
void doWriteTransform(Geom::Affine const &transform, Geom::Affine const *adv=nullptr, bool compensate=true)
Set a new transform on an object.
Definition sp-item.cpp:1658
bool pathEffectsEnabled() const
SPDocument * document
Definition sp-object.h:188
SPObject * parent
Definition sp-object.h:189
void requestDisplayUpdate(unsigned int flags)
Queues an deferred update of this object's display.
SPItem * item
bool are_near(Affine const &a1, Affine const &a2, Coord eps=EPSILON)
Helper class to stream background task notifications as a series of messages.
static Glib::ustring join(std::vector< Glib::ustring > const &accels, char const separator)
Geom::Affine i2anc_affine(SPObject const *object, SPObject const *ancestor)
Definition sp-item.cpp:1787
SPRoot: SVG <svg> implementation.
Definition curve.h:24
SPDesktop * desktop