Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
lpe-perp_bisector.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
5/*
6 * Authors:
7 * Maximilian Albert
8 * Johan Engelen
9 *
10 * Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl>
11 * Copyright (C) Maximilin Albert 2008 <maximilian.albert@gmail.com>
12 *
13 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
14 */
16#include "display/curve.h"
17#include "line-geometry.h"
18
19#include "object/sp-path.h"
20
21#include "ui/knot/knot-holder.h"
23
24// TODO due to internal breakage in glibmm headers, this must be last:
25#include <glibmm/i18n.h>
26
27namespace Inkscape {
28namespace LivePathEffect {
29namespace PB {
30
31class KnotHolderEntityEnd : public LPEKnotHolderEntity {
32public:
33 KnotHolderEntityEnd(LPEPerpBisector *effect) : LPEKnotHolderEntity(effect) {};
34 void bisector_end_set(Geom::Point const &p, guint state, bool left = true);
35};
36
37class KnotHolderEntityLeftEnd : public KnotHolderEntityEnd {
38public:
39 KnotHolderEntityLeftEnd(LPEPerpBisector *effect) : KnotHolderEntityEnd(effect) {};
40 void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state) override;
41 Geom::Point knot_get() const override;
42};
43
44class KnotHolderEntityRightEnd : public KnotHolderEntityEnd {
45public:
46 KnotHolderEntityRightEnd(LPEPerpBisector *effect) : KnotHolderEntityEnd(effect) {};
47 void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state) override;
48 Geom::Point knot_get() const override;
49};
50
52KnotHolderEntityLeftEnd::knot_get() const {
53 LPEPerpBisector const* lpe = dynamic_cast<LPEPerpBisector const*>(_effect);
54 return Geom::Point(lpe->C);
55}
56
58KnotHolderEntityRightEnd::knot_get() const {
59 LPEPerpBisector const* lpe = dynamic_cast<LPEPerpBisector const*>(_effect);
60 return Geom::Point(lpe->D);
61}
62
63void
64KnotHolderEntityEnd::bisector_end_set(Geom::Point const &p, guint state, bool left) {
65 LPEPerpBisector *lpe = dynamic_cast<LPEPerpBisector *>(_effect);
66 if (!lpe) return;
67
68 Geom::Point const s = snap_knot_position(p, state);
69
70 double lambda = Geom::nearest_time(s, lpe->M, lpe->perp_dir);
71 if (left) {
72 lpe->C = lpe->M + lpe->perp_dir * lambda;
73 lpe->length_left.param_set_value(lambda);
74 } else {
75 lpe->D = lpe->M + lpe->perp_dir * lambda;
76 lpe->length_right.param_set_value(-lambda);
77 }
78
79 // FIXME: this should not directly ask for updating the item. It should write to SVG, which triggers updating.
80 sp_lpe_item_update_patheffect (cast<SPLPEItem>(item), true, true);
81}
82
83void
84KnotHolderEntityLeftEnd::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint state) {
85 bisector_end_set(p, state);
86}
87
88void
89KnotHolderEntityRightEnd::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint state) {
90 bisector_end_set(p, state, false);
91}
92
93} //namescape PB
94
96 Effect(lpeobject),
97 length_left(_("Length left:"), _("Specifies the left end of the bisector"), "length-left", &wr, this, 200),
98 length_right(_("Length right:"), _("Specifies the right end of the bisector"), "length-right", &wr, this, 200),
99 A(0,0), B(0,0), M(0,0), C(0,0), D(0,0), perp_dir(0,0)
100{
101 show_orig_path = true;
103
104 // register all your parameters here, so Inkscape knows which parameters this effect has:
107}
108
110
111void
113{
114 /* make the path a straight line */
128}
129
130
133{
134 using namespace Geom;
135
136 Piecewise<D2<SBasis> > output;
137
138 A = pwd2_in.firstValue();
139 B = pwd2_in.lastValue();
140 M = (A + B)/2;
141
142 perp_dir = unit_vector((B - A).ccw());
143
144 C = M + perp_dir * length_left;
145 D = M - perp_dir * length_right;
146
147 output = Piecewise<D2<SBasis> >(D2<SBasis>(SBasis(C[X], D[X]), SBasis(C[Y], D[Y])));
148
149 return output;
150}
151
152void
154 {
156 e->create(desktop, item, knotholder, Inkscape::CANVAS_ITEM_CTRL_TYPE_LPE, "LPE:PerpBisectorLeftEnd",
157 _("Adjust the \"left\" end of the bisector"));
158knotholder->add(e);
159 }
160 {
162 e->create(desktop, item, knotholder, Inkscape::CANVAS_ITEM_CTRL_TYPE_LPE, "LPE:PerpBisectorRightEnd",
163 _("Adjust the \"right\" end of the bisector"));
164 knotholder->add(e);
165 }
166};
167
168/* ######################## */
169
170} //namespace LivePathEffect
171} /* namespace Inkscape */
172
173/*
174 Local Variables:
175 mode:c++
176 c-file-style:"stroustrup"
177 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
178 indent-tabs-mode:nil
179 fill-column:99
180 End:
181*/
182// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
Point origin
Definition aa.cpp:227
Adaptor that creates 2D functions from 1D ones.
Definition d2.h:55
Function defined as discrete pieces.
Definition piecewise.h:71
Two-dimensional point that doubles as a vector.
Definition point.h:66
Polynomial in symmetric power basis.
Definition sbasis.h:70
void registerParameter(Parameter *param)
Definition effect.cpp:1704
LPEPerpBisector(LivePathEffectObject *lpeobject)
void doOnApply(SPLPEItem const *lpeitem) override
Is performed a single time when the effect is freshly applied to a path.
Geom::Piecewise< Geom::D2< Geom::SBasis > > doEffect_pwd2(Geom::Piecewise< Geom::D2< Geom::SBasis > > const &pwd2_in) override
void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item)
KnotHolderEntity definition.
void create(SPDesktop *desktop, SPItem *item, KnotHolder *parent, Inkscape::CanvasItemCtrlType type=Inkscape::CANVAS_ITEM_CTRL_TYPE_DEFAULT, Glib::ustring const &name="unknown", char const *tip="", uint32_t color=0xffffff00)
void add(KnotHolderEntity *e)
To do: update description of desktop.
Definition desktop.h:149
Base class for visual SVG elements.
Definition sp-item.h:109
@ Y
Definition coord.h:48
@ X
Definition coord.h:48
SPItem * item
LPE <perp_bisector> implementation, see lpe-perp_bisector.cpp.
Various utility functions.
Definition affine.h:22
Coord nearest_time(Point const &p, Curve const &c)
Definition curve.h:354
Point unit_vector(Point const &a)
void bisector_end_set(SPItem *item, Geom::Point const &p, guint state, bool left=true)
Helper class to stream background task notifications as a series of messages.
@ CANVAS_ITEM_CTRL_TYPE_LPE
void sp_lpe_item_update_patheffect(SPLPEItem *lpeitem, bool wholetree, bool write, bool with_satellites)
Calls any registered handlers for the update_patheffect action.
SPDesktop * desktop