Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
path-manipulator.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
5/* Authors:
6 * Krzysztof KosiƄski <tweenk.pl@gmail.com>
7 *
8 * Copyright (C) 2009 Authors
9 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
10 */
11
12#ifndef INKSCAPE_UI_TOOL_PATH_MANIPULATOR_H
13#define INKSCAPE_UI_TOOL_PATH_MANIPULATOR_H
14
15#include <string>
16#include <memory>
17#include <2geom/pathvector.h>
18#include <2geom/path-sink.h>
19#include <2geom/affine.h>
20#include "ui/tool/node.h"
21#include "ui/tool/manipulator.h"
22
23class SPPath;
24
25namespace Inkscape {
26
27class CanvasItemBpath;
28
29namespace XML { class Node; }
30
31namespace UI {
32
33class PathManipulator;
34class ControlPointSelection;
35class PathManipulatorObserver;
36class CurveDragPoint;
37class PathCanvasGroups;
38class MultiPathManipulator;
39class Node;
40class Handle;
41
48
50{
51 automatic, // try to preserve shape if deleted nodes do not form sharp corners
52 inverse_auto, // opposite of what automatic mode would do
53 curve_fit, // preserve shape
54 line_segment, // do not preserve shape; delete nodes and connect subpaths with a line segment
55 gap_nodes, // Remove the connection between the selected nodes, leaving a gap
56 gap_lines // Remove the connection between the selected lines, leaving a gap
57};
58
65{
66public:
67 using ItemType = SPPath*;
68
70 uint32_t outline_color, Glib::ustring lpe_key);
71 ~PathManipulator() override;
72 bool event(Inkscape::UI::Tools::ToolBase *tool, CanvasEvent const &event) override;
73
74 bool empty();
75 void writeXML();
76 void update(bool alert_LPE = false); // update display, but don't commit
77 void clear(); // remove all nodes from manipulator
78
79 SPObject const *item() const { return _path; }
80 SPObject *item() { return _path; }
81
82 void selectSubpaths();
84
86 void insertNodes();
88 void insertNode(NodeList::iterator first, double t, bool take_selection);
89 void duplicateNodes();
91 void weldNodes(NodeList::iterator preserve_pos = NodeList::iterator());
92 void weldSegments();
93 void breakNodes() { breakNodes(true); }
94 void breakNodes(bool new_nodes);
96 void deleteSegments();
97 void reverseSubpaths(bool selected_only);
99
100 void scaleHandle(Node *n, int which, int dir, bool pixel);
101 void rotateHandle(Node *n, int which, int dir, bool pixel);
102
103 void showOutline(bool show);
104 void showHandles(bool show);
105 void showPathDirection(bool show);
106 void setLiveOutline(bool set);
107 void setLiveObjects(bool set);
108 void updateHandles();
109 void updatePath();
111 void hideDragPoint();
113
116 bool search_unselected, bool closest);
117
118 int _bsplineGetSteps() const;
119 // this is necessary for Tab-selection in MultiPathManipulator
121
122 static bool is_item_type(void *item);
123
124private:
126 using SubpathPtr = std::shared_ptr<NodeList>;
127
129 void _deleteSegments(bool delete_singles);
130
132 bool _isBSpline() const;
133 double _bsplineHandlePosition(Handle *h, bool check_other = true);
134 Geom::Point _bsplineHandleReposition(Handle *h, bool check_other = true);
136 void _createGeometryFromControlPoints(bool alert_LPE = false);
138 std::string _createTypeString();
139 void _updateOutline();
140 //void _setOutline(Geom::PathVector const &);
141 void _getGeometry();
142 void _setGeometry();
143 Glib::ustring _nodetypesKey();
146
147 void _selectionChangedM(std::vector<SelectableControlPoint *> pvec, bool selected);
148 void _selectionChanged(SelectableControlPoint * p, bool selected);
149 bool _nodeClicked(Node *, ButtonReleaseEvent const &);
150 void _handleGrabbed();
152 void _handleUngrabbed();
153
154 void _externalChange(unsigned type);
156 void _commit(Glib::ustring const &annotation);
157 void _commit(Glib::ustring const &annotation, gchar const *key);
160 double _getStrokeTolerance();
161 Handle *_chooseHandle(Node *n, int which);
162
166 Geom::PathVector _spcurve; // in item coordinates
168 CurveDragPoint *_dragpoint; // an invisible control point hovering over curve
173 bool _show_handles = true;
174 bool _show_outline = false;
176 bool _live_outline = true;
177 bool _live_objects = true;
178 bool _is_bspline = false;
179 Glib::ustring _lpe_key;
180
182 friend class CurveDragPoint;
183 friend class Node;
184 friend class Handle;
185};
186
187} // namespace UI
188} // namespace Inkscape
189
190#endif // INKSCAPE_UI_TOOL_PATH_MANIPULATOR_H
191
192/*
193 Local Variables:
194 mode:c++
195 c-file-style:"stroustrup"
196 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
197 indent-tabs-mode:nil
198 fill-column:99
199 End:
200*/
201// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
Point origin
Definition aa.cpp:227
3x3 affine transformation matrix.
std::unique_ptr< T, CanvasItemUnlinkDeleter > CanvasItemPtr
Smart pointer used to hold CanvasItems, like std::unique_ptr.
3x3 matrix representing an affine transformation.
Definition affine.h:70
Store paths to a PathVector.
Definition path-sink.h:226
Sequence of subpaths.
Definition pathvector.h:122
Two-dimensional point that doubles as a vector.
Definition point.h:66
An invisible point used to drag curves.
Manipulator that manages multiple path manipulators active at the same time.
Manipulator that edits a single path using nodes with handles.
void _updateOutline()
Update the path outline.
CanvasItemPtr< Inkscape::CanvasItemBpath > _outline
void update(bool alert_LPE=false)
Update the display and the outline of the path.
Inkscape::XML::Node * _getXMLNode()
Return the XML node we are editing.
std::string _createTypeString()
Construct a node type string to store in the sodipodi:nodetypes attribute.
void _createGeometryFromControlPoints(bool alert_LPE=false)
Construct the geometric representation of nodes and handles, update the outline and display.
Glib::ustring _nodetypesKey()
Figure out in what attribute to store the nodetype string.
void setSegmentType(SegmentType)
Make selected segments curves / lines.
void hideDragPoint()
Hide the curve drag point until the next motion event.
void _selectionChanged(SelectableControlPoint *p, bool selected)
void insertNodeAtExtremum(ExtremumType extremum)
Insert a new node at the extremum of the selected segments.
Geom::Coord _updateDragPoint(Geom::Point const &)
Update the position of the curve drag point such that it is over the nearest point of the path.
std::shared_ptr< NodeList > SubpathPtr
void _commit(Glib::ustring const &annotation)
Update the XML representation and put the specified annotation on the undo stack.
Geom::Point _bsplineHandleReposition(Handle *h, bool check_other=true)
void rotateHandle(Node *n, int which, int dir, bool pixel)
void _externalChange(unsigned type)
Called by the XML observer when something else than us modifies the path.
void reverseSubpaths(bool selected_only)
Reverse subpaths of the path.
void _removeNodesFromSelection()
Removes all nodes belonging to this manipulator from the control point selection.
void _getGeometry()
Retrieve the geometry of the edited object from the object tree.
bool _nodeClicked(Node *, ButtonReleaseEvent const &)
void _updateOutlineOnZoomChange()
This is called on zoom change to update the direction arrows.
void _deleteSegments(bool delete_singles)
Removes selected segments.
bool _handleClicked(Handle *, ButtonReleaseEvent const &)
void showHandles(bool show)
Set the visibility of handles.
double _getStrokeTolerance()
Compute the radius from the edge of the path where clicks should initiate a curve drag or segment sel...
void weldNodes(NodeList::iterator preserve_pos=NodeList::iterator())
Replace contiguous selections of nodes in each subpath with one node.
void selectSubpaths()
Select all nodes in subpaths that have something selected.
MultiPathManipulator & mpm()
void setControlsTransform(Geom::Affine const &)
SPObject const * item() const
bool empty()
Check whether the manipulator has any nodes.
void showOutline(bool show)
Set the visibility of outline.
static bool is_item_type(void *item)
void invertSelectionInSubpaths()
Invert selection in the selected subpaths.
unsigned _deleteStretch(NodeList::iterator first, NodeList::iterator last, NodeDeleteMode mode)
Delete nodes between the two iterators.
void duplicateNodes()
Insert new nodes exactly at the positions of selected nodes while preserving shape.
void clear()
Remove all nodes from the path.
void _setGeometry()
Set the geometry of the edited object in the object tree, but do not commit to XML.
Geom::Affine _i2d_transform
item-to-desktop transform, inverse of _d2i_transform
Geom::Affine _edit_transform
additional transform to apply to editing controls
bool event(Inkscape::UI::Tools::ToolBase *tool, CanvasEvent const &event) override
Handle motion events to update the position of the curve drag point.
Geom::Affine _d2i_transform
desktop-to-item transform
PathManipulatorObserver * _observer
void deleteNodes(NodeDeleteMode mode)
Delete selected nodes in the path, optionally substituting deleted segments with bezier curves in a w...
void insertNodes()
Insert a new node in the middle of each selected segment.
void scaleHandle(Node *n, int which, int dir, bool pixel)
void weldSegments()
Remove nodes in the middle of selected segments.
Handle * _chooseHandle(Node *n, int which)
NodeList::iterator extremeNode(NodeList::iterator origin, bool search_selected, bool search_unselected, bool closest)
Find the node that is closest/farthest from the origin.
MultiPathManipulator & _multi_path_manipulator
void writeXML()
Store the changes to the path in XML.
void _selectionChangedM(std::vector< SelectableControlPoint * > pvec, bool selected)
NodeList::iterator subdivideSegment(NodeList::iterator after, double t)
Insert a node in the segment beginning with the supplied iterator, at the given time value.
void _createControlPointsFromGeometry()
Create nodes and handles based on the XML of the edited path.
void copySelectedPath(Geom::PathBuilder *builder)
Copy the selected nodes using the PathBuilder.
SPObject * _path
can be an SPPath or an Inkscape::LivePathEffect::Effect !!!
double _bsplineHandlePosition(Handle *h, bool check_other=true)
Tool component that edits something on the canvas using selectable control points.
Definition manipulator.h:53
ExtremumType
Type of extremum points to add in PathManipulator::insertNodeAtExtremum.
Definition manipulator.h:62
Desktop-bound selectable control object.
List of node lists.
Definition node.h:442
Base class for Event processors.
Definition tool-base.h:95
Interface for refcounted XML nodes.
Definition node.h:80
SPObject is an abstract base class of all of the document nodes at the SVG document level.
Definition sp-object.h:160
SVG <path> implementation.
Definition sp-path.h:27
double Coord
Floating point type used to store coordinates.
Definition coord.h:76
Manipulator - edits something on-canvas.
SegmentType
Types of segments supported in the node tool.
Definition node-types.h:30
Helper class to stream background task notifications as a series of messages.
static cairo_user_data_key_t key
int mode
callback interface for SVG path data
PathVector - a sequence of subpaths.
A mouse button (left/right/middle) is released.
Abstract base class for events.
Inkscape::CanvasItemGroup * outline_group
Inkscape::CanvasItemGroup * dragpoint_group
Glib::RefPtr< Gtk::Builder > builder
Editable node and associated data structures.