Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
selection.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Authors:
4 * Lauris Kaplinski <lauris@kaplinski.com>
5 * MenTaLguY <mental@rydia.net>
6 * bulia byak <buliabyak@users.sf.net>
7 * Adrian Boguszewski
8 *
9 * Copyright (C) 2016 Adrian Boguszewski
10 * Copyright (C) 2004-2005 MenTaLguY
11 * Copyright (C) 1999-2002 Lauris Kaplinski
12 * Copyright (C) 2001-2002 Ximian, Inc.
13 *
14 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
15 */
16
17#ifndef SEEN_INKSCAPE_SELECTION_H
18#define SEEN_INKSCAPE_SELECTION_H
19
20#include <cstddef>
21#include <list>
22#include <unordered_map>
23#include <utility>
24#include <vector>
25#include <sigc++/signal.h>
26#include <sigc++/slot.h>
27
28#include <sigc++/scoped_connection.h>
29#include "object/object-set.h"
30
31namespace Inkscape {
32
33namespace XML {
34class Node;
35} // namespace XML
36
41{
42 std::string path_id; // ID of the path containing the node
43 int subpath_index; // Index of the subpath
44 int node_index; // Index of the node within the subpath
45
46 PathNodeState(std::string id, int sp, int n)
47 : path_id(std::move(id))
48 , subpath_index(sp)
49 , node_index(n)
50 {}
51};
52
57{
58 std::vector<std::string> selected_ids; // IDs of selected objects
59 std::vector<PathNodeState> selected_nodes; // Selected path nodes (when node tool is active)
60};
61
79class Selection : public ObjectSet
80{
81public:
91 ~Selection() override;
92
99
100 using ObjectSet::add;
101
107 void add(XML::Node *repr) {
108 add(_objectForXMLNode(repr));
109 }
110
111 using ObjectSet::set;
112
118 void set(XML::Node *repr) {
119 set(_objectForXMLNode(repr));
120 }
121
122 using ObjectSet::remove;
123
131 void remove(XML::Node *repr) {
133 }
134
136
140 bool includes(XML::Node *repr, bool anyAncestor = false) {
141 return includes(_objectForXMLNode(repr), anyAncestor);
142 }
143
145
152
154 size_t numberOfLayers();
155
157 size_t numberOfParents();
158
164 std::vector<Inkscape::SnapCandidatePoint> getSnapPoints(SnapPreferences const *snapprefs) const;
165
166 // Fixme: Hack should not exist, but used by live_effects.
168
179 sigc::connection connectChanged(sigc::slot<void (Selection *)> slot) {
180 return _changed_signal.connect(std::move(slot));
181 }
182
188 sigc::connection connectChangedFirst(sigc::slot<void (Selection *)> slot) {
189 return _changed_signal.connect_first(std::move(slot));
190 }
191
198 void setAnchor(double x, double y, bool set = true);
199 // Allow the selection to specify a facus anchor (helps with transforming against this point)
200 bool has_anchor = false;
202
210 void scaleAnchored(double amount, bool fixed = true);
211
218 void rotateAnchored(double angle_degrees, double zoom = 1.0);
219
232 sigc::connection connectModified(sigc::slot<void (Selection *, unsigned)> slot) {
233 return _modified_signal.connect(std::move(slot));
234 }
235
239 sigc::connection connectModifiedFirst(sigc::slot<void (Selection *, unsigned)> slot) {
240 return _modified_signal.connect_first(std::move(slot));
241 }
242
247
251 void setState(SelectionState const &state);
252
258
259protected:
260 void _connectSignals(SPObject* object) override;
261 void _releaseSignals(SPObject* object) override;
262
263private:
265 static int _emit_modified(Selection *selection);
267 void _schedule_modified(SPObject *obj, unsigned int flags);
268
270 void _emitModified(unsigned int flags);
272 void _emitChanged(bool persist_selection_context = false) override;
276 void _releaseContext(SPObject *obj);
277
279 unsigned _flags = 0;
280 unsigned _idle = 0;
281 bool _change_layer = true;
282 bool _change_page = true;
283 std::unordered_map<SPObject *, sigc::scoped_connection> _modified_connections;
284 sigc::scoped_connection _context_release_connection;
285
286 sigc::signal<void (Selection *)> _changed_signal;
287 sigc::signal<void (Selection *, unsigned)> _modified_signal;
288
290};
291
292} // namespace Inkscape
293
294#endif // SEEN_INKSCAPE_SELECTION_H
295
296/*
297 Local Variables:
298 mode:c++
299 c-file-style:"stroustrup"
300 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
301 indent-tabs-mode:nil
302 fill-column:99
303 End:
304*/
305// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
SimpleSnap option
Two-dimensional point that doubles as a vector.
Definition point.h:66
SPObject * includesAncestor(SPObject *object)
Returns ancestor if the given object has ancestor selected.
SPDesktop * desktop()
Returns the desktop the selection is bound to.
Definition object-set.h:390
bool remove(SPObject *object)
Removes an item from the set of selected objects.
bool add(SPObject *object, bool nosignal=false)
Add an SPObject to the set of selected objects.
void set(SPObject *object, bool persist_selection_context=false)
Set the selection to a single specific object.
SPDocument * document()
Returns the document the selection is bound to.
Definition object-set.h:397
bool includes(SPObject *object, bool anyAncestor=false)
Returns true if the given object is selected.
The set of selected SPObjects for a given document and layer model.
Definition selection.h:80
SPObject * _selection_context
Definition selection.h:278
void _releaseSignals(SPObject *object) override
sigc::scoped_connection _context_release_connection
Definition selection.h:284
void add(XML::Node *repr)
Add an XML node's SPObject to the set of selected objects.
Definition selection.h:107
sigc::signal< void(Selection *, unsigned)> _modified_signal
Definition selection.h:287
std::vector< Inkscape::SnapCandidatePoint > getSnapPoints(SnapPreferences const *snapprefs) const
Compute the list of points in the selection that are to be considered for snapping from.
void _releaseContext(SPObject *obj)
Releases an active layer object that is being removed.
void setAnchor(double x, double y, bool set=true)
Set the anchor point of the selection, used for telling it how transforms should be anchored against.
std::unordered_map< SPObject *, sigc::scoped_connection > _modified_connections
Definition selection.h:283
SPObject * activeContext()
Returns active layer for selection (currentLayer or its parent).
void set(XML::Node *repr)
Set the selection to an XML node's SPObject.
Definition selection.h:118
void remove(XML::Node *repr)
Removes an item from the set of selected objects.
Definition selection.h:131
void _connectSignals(SPObject *object) override
size_t numberOfLayers()
Returns the number of layers in which there are selected objects.
void setChangePage(bool option)
Definition selection.h:257
Geom::Point _previous_rotate_anchor
Definition selection.h:289
void _emitChanged(bool persist_selection_context=false) override
Issues changed selection signal.
static int _emit_modified(Selection *selection)
Issues modification notification signals.
Definition selection.cpp:73
void rotateAnchored(double angle_degrees, double zoom=1.0)
Rotate the selection, anchoring it against the center, or a selected anchor.
SelectionState getState()
Returns the current selection state including selected objects and nodes.
sigc::connection connectModifiedFirst(sigc::slot< void(Selection *, unsigned)> slot)
Similar to connectModified, but will be run first.
Definition selection.h:239
SPObject * includesAncestor(XML::Node *repr)
Returns ancestor if the given object has ancestor selected.
Definition selection.h:149
bool includes(XML::Node *repr, bool anyAncestor=false)
Returns true if the given item is selected.
Definition selection.h:140
void setChangeLayer(bool option)
Decide if the selection changing should change the layer and page selection too.
Definition selection.h:256
void scaleAnchored(double amount, bool fixed=true)
Scale the selection, anchoring it against the center, or a selected anchor.
void _emitModified(unsigned int flags)
Issues modified selection signal.
Definition selection.cpp:86
void setState(SelectionState const &state)
Restores a selection state previously obtained from getState()
size_t numberOfParents()
Returns the number of parents to which the selected objects belong.
sigc::connection connectChangedFirst(sigc::slot< void(Selection *)> slot)
Similar to connectChanged, but will be run first.
Definition selection.h:188
void _schedule_modified(SPObject *obj, unsigned int flags)
Schedules an item modification signal to be sent.
Definition selection.cpp:63
sigc::connection connectChanged(sigc::slot< void(Selection *)> slot)
Connects a slot to be notified of selection changes.
Definition selection.h:179
sigc::signal< void(Selection *)> _changed_signal
Definition selection.h:286
~Selection() override
Definition selection.cpp:54
SPObject * _objectForXMLNode(XML::Node *repr) const
returns the SPObject corresponding to an xml node (if any).
sigc::connection connectModified(sigc::slot< void(Selection *, unsigned)> slot)
Connects a slot to be notified of selected object modifications.
Definition selection.h:232
Geom::Point anchor
Definition selection.h:201
Storing of snapping preferences.
Interface for refcounted XML nodes.
Definition node.h:80
To do: update description of desktop.
Definition desktop.h:149
Typed SVG document implementation.
Definition document.h:103
SPObject is an abstract base class of all of the document nodes at the SVG document level.
Definition sp-object.h:160
Helper class to stream background task notifications as a series of messages.
STL namespace.
Represents a selected node in a path.
Definition selection.h:41
PathNodeState(std::string id, int sp, int n)
Definition selection.h:46
Complete state of a selection, including selected objects and nodes.
Definition selection.h:57
std::vector< std::string > selected_ids
Definition selection.h:58
std::vector< PathNodeState > selected_nodes
Definition selection.h:59