Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
control-point-selection.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
6/* Authors:
7 * Krzysztof KosiƄski <tweenk.pl@gmail.com>
8 *
9 * Copyright (C) 2009 Authors
10 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
11 */
12
13#ifndef INKSCAPE_UI_TOOL_CONTROL_POINT_SELECTION_H
14#define INKSCAPE_UI_TOOL_CONTROL_POINT_SELECTION_H
15
16#include <list>
17#include <memory>
18#include <unordered_map>
19#include <unordered_set>
20#include <optional>
21#include <cstddef>
22#include <sigc++/sigc++.h>
23#include <2geom/forward.h>
24#include <2geom/point.h>
25#include <2geom/rect.h>
27#include "ui/tool/manipulator.h"
28#include "ui/tool/node-types.h"
29#include "snap-candidate.h"
30
31class SPDesktop;
32
33namespace Inkscape {
34class CanvasItemGroup;
35struct KeyPressEvent;
36struct ButtonReleaseEvent;
37
38namespace UI {
39class TransformHandleSet;
40class SelectableControlPoint;
41
43 : public Manipulator
44 , public sigc::trackable
45{
46public:
48 ~ControlPointSelection() override;
49 using set_type = std::unordered_set<SelectableControlPoint*>;
50 using Set = set_type; // convenience alias
51
52 using iterator = set_type::iterator;
53 using const_iterator = set_type::const_iterator;
54 using size_type = set_type::size_type;
57
58 // size
59 bool empty() const { return _points.empty(); }
60 size_type size() const { return _points.size(); }
61
62 // iterators
63 iterator begin() { return _points.begin(); }
64 const_iterator begin() const { return _points.begin(); }
65 iterator end() { return _points.end(); }
66 const_iterator end() const { return _points.end(); }
67
68 // insert
69 std::pair<iterator, bool> insert(const value_type& x, bool notify = true, bool to_update = true);
70 template <class InputIterator>
71 void insert(InputIterator first, InputIterator last) {
72 for (; first != last; ++first) {
73 insert(*first, false, false);
74 }
75 _update();
76 signal_selection_changed.emit(std::vector<key_type>(first, last), true);
77 }
78
79 // erase
80 void clear();
81 void erase(iterator pos, bool to_update = true);
82 size_type erase(const key_type& k, bool notify = true);
83 void erase(iterator first, iterator last);
84
85 // find
87 return _points.find(k);
88 }
89
90 // Sometimes it is very useful to keep a list of all selectable points.
91 set_type const &allPoints() const { return _all_points; }
93 // ...for example in these methods. Another useful case is snapping.
94 void selectAll();
95 void selectArea(Geom::Path const &, bool invert = false);
96 void invertSelection();
98
99 bool event(Inkscape::UI::Tools::ToolBase *tool, CanvasEvent const &event) override;
100
101 void transform(Geom::Affine const &m);
103 void distribute(Geom::Dim2 d);
104
107 std::optional<Geom::Point> firstSelectedPoint() const;
108
110 void showTransformHandles(bool v, bool one_node);
111 // the two methods below do not modify the state; they are for use in manipulators
112 // that need to temporarily hide the handles, for example when moving a node
116
117 sigc::signal<void ()> signal_update;
118 // It turns out that emitting a signal after every point is selected or deselected is not too efficient,
119 // so this can be done in a massive group once the selection is finally changed.
120 sigc::signal<void (std::vector<SelectableControlPoint *>, bool)> signal_selection_changed;
121 sigc::signal<void (CommitEvent)> signal_commit;
122
123 void getOriginalPoints(std::vector<Inkscape::SnapCandidatePoint> &pts);
124 void getUnselectedPoints(std::vector<Inkscape::SnapCandidatePoint> &pts);
125 void setOriginalPoints();
126 //the purpose of this list is to keep track of first and last selected
127 std::list<SelectableControlPoint *> _points_list;
128
129private:
130 // The functions below are invoked from SelectableControlPoint.
131 // Previously they were connected to handlers when selecting, but this
132 // creates problems when dragging a point that was not selected.
134 void _pointDragged(Geom::Point &, MotionEvent const &);
135 void _pointUngrabbed();
137 void _mouseoverChanged();
138
139 void _update();
140 void _updateTransformHandles(bool preserve_center);
141 void _updateBounds();
142 bool _keyboardMove(KeyPressEvent const &, Geom::Point const &);
143 bool _keyboardRotate(KeyPressEvent const &, int);
144 bool _keyboardScale(KeyPressEvent const &, int);
148 double _rotationRadius(Geom::Point const &);
149
151
153 std::unordered_map<SelectableControlPoint *, Geom::Point> _original_positions;
154 std::unordered_map<SelectableControlPoint *, Geom::Affine> _last_trans;
155 std::optional<double> _rot_radius;
156 std::optional<double> _mouseover_rot_radius;
157 std::optional<Geom::Point> _first_point;
161 unsigned _dragging : 1;
162 unsigned _handles_visible : 1;
163 unsigned _one_node_handles : 1;
164
166};
167
168} // namespace UI
169} // namespace Inkscape
170
171#endif // INKSCAPE_UI_TOOL_CONTROL_POINT_SELECTION_H
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:fileencoding=utf-8 :
Cartesian point / 2D vector and related operations.
Point origin
Definition aa.cpp:227
3x3 matrix representing an affine transformation.
Definition affine.h:70
Axis-aligned rectangle that can be empty.
Definition rect.h:203
Sequence of contiguous curves, aka spline.
Definition path.h:353
Two-dimensional point that doubles as a vector.
Definition point.h:66
Group of selected control points.
std::pair< iterator, bool > insert(const value_type &x, bool notify=true, bool to_update=true)
Add a control point to the selection.
std::optional< Geom::Point > firstSelectedPoint() const
The first selected point is the first selection a user makes, but only if they selected exactly one p...
std::list< SelectableControlPoint * > _points_list
void _updateTransformHandles(bool preserve_center)
sigc::signal< void()> signal_update
Fires when the display needs to be updated to reflect changes.
void getUnselectedPoints(std::vector< Inkscape::SnapCandidatePoint > &pts)
void selectArea(Geom::Path const &, bool invert=false)
Select all points inside the given rectangle (in desktop coordinates).
sigc::signal< void(std::vector< SelectableControlPoint * >, bool)> signal_selection_changed
void _pointDragged(Geom::Point &, MotionEvent const &)
bool _keyboardRotate(KeyPressEvent const &, int)
Rotates the selected points in the given direction according to the modifier state from the supplied ...
void align(Geom::Dim2 d, AlignTargetNode target=AlignTargetNode::MID_NODE)
Align control points on the specified axis.
std::unordered_map< SelectableControlPoint *, Geom::Point > _original_positions
void erase(iterator pos, bool to_update=true)
Remove a point from the selection.
bool _keyboardMove(KeyPressEvent const &, Geom::Point const &)
Moves the selected points along the supplied unit vector according to the modifier state of the suppl...
std::unordered_set< SelectableControlPoint * > set_type
void _keyboardTransform(Geom::Affine const &)
Geom::OptRect pointwiseBounds()
Get the bounds of the selection.
std::optional< Geom::Point > _first_point
bool _keyboardScale(KeyPressEvent const &, int)
std::unordered_map< SelectableControlPoint *, Geom::Affine > _last_trans
void invertSelection()
Unselect all selected points and select all unselected points.
void getOriginalPoints(std::vector< Inkscape::SnapCandidatePoint > &pts)
void insert(InputIterator first, InputIterator last)
bool event(Inkscape::UI::Tools::ToolBase *tool, CanvasEvent const &event) override
Handle input event. Returns true if handled.
double _rotationRadius(Geom::Point const &)
Computes the distance to the farthest corner of the bounding box.
bool _pointClicked(SelectableControlPoint *, ButtonReleaseEvent const &)
void _pointGrabbed(SelectableControlPoint *)
void showTransformHandles(bool v, bool one_node)
void transform(Geom::Affine const &m)
Transform all selected control points by the given affine transformation.
sigc::signal< void(CommitEvent)> signal_commit
Fires when a change that needs to be committed to XML happens.
void clear()
Remove all points from the selection, making it empty.
void spatialGrow(SelectableControlPoint *origin, int dir)
void selectAll()
Select all points that this selection can contain.
void distribute(Geom::Dim2 d)
Equdistantly distribute control points by moving them in the specified dimension.
Tool component that processes events and does something in response to them.
Definition manipulator.h:34
Desktop-bound selectable control object.
Base class for Event processors.
Definition tool-base.h:95
To do: update description of desktop.
Definition desktop.h:149
Commit events.
Contains forward declarations of 2geom types.
Dim2
2D axis enumeration (X or Y).
Definition coord.h:48
Manipulator - edits something on-canvas.
CommitEvent
This is used to provide sensible messages on the undo stack.
Helper class to stream background task notifications as a series of messages.
Node types and other small enums.
Axis-aligned rectangle.
Some utility classes to store various kinds of snap candidates.
void invert(const double v[16], double alpha[16])
A mouse button (left/right/middle) is released.
Abstract base class for events.
A key has been pressed.
Movement of the mouse pointer.