Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
multi-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_MULTI_PATH_MANIPULATOR_H
13#define INKSCAPE_UI_TOOL_MULTI_PATH_MANIPULATOR_H
14
15#include <cstddef>
16#include <sigc++/connection.h>
17#include <2geom/path-sink.h>
18#include "commit-events.h"
19#include "manipulator.h"
20#include "modifier-tracker.h"
21#include "node-types.h"
22#include "shape-record.h"
24
25namespace Inkscape {
26namespace UI {
27
28class PathManipulator;
29class MultiPathManipulator;
30struct PathSharedData;
31
36{
37public:
39 ~MultiPathManipulator() override;
40
41 bool event(Inkscape::UI::Tools::ToolBase *tool, CanvasEvent const &event) override;
42
43 bool empty() const { return _mmap.empty(); }
44 size_t size() const { return _mmap.size(); }
45 void setItems(std::set<ShapeRecord> const &);
46 void clear() { _mmap.clear(); }
47 void cleanup();
48
49 void selectSubpaths();
50 void shiftSelection(int dir);
52
53 void setNodeType(NodeType t);
55
57 void insertNodes();
58 void insertNode(Geom::Point pt);
59 void alertLPE();
60 void duplicateNodes();
62 void joinNodes();
63 void breakNodes();
64 void deleteNodes();
66 void joinSegments();
67 void deleteSegments();
70 void reverseSubpaths();
71 void move(Geom::Point const &delta);
72 void scale(Geom::Point const &center, Geom::Point const &scale);
73
74 void showOutline(bool show);
75 void showHandles(bool show);
76 void showPathDirection(bool show);
77 void setLiveOutline(bool set);
78 void setLiveObjects(bool set);
80 void updateHandles();
81 void updatePaths();
82
84 sigc::signal<void ()> signal_coords_changed;
85
86private:
87 using MapPair = std::pair<ShapeRecord, std::shared_ptr<PathManipulator>>;
88 using MapType = std::map<ShapeRecord, std::shared_ptr<PathManipulator>>;
89
90 template <typename R>
91 void invokeForAll(R (PathManipulator::*method)()) {
92 for (MapType::iterator i = _mmap.begin(); i != _mmap.end(); ) {
93 // Sometimes the PathManipulator got freed at loop end, thus
94 // invalidating the iterator so make sure that next_i will
95 // be a valid iterator and then assign i to it.
96 MapType::iterator next_i = i;
97 ++next_i;
98 // i->second is a std::shared_ptr so try to hold on to it so
99 // it won't get freed prematurely by the WriteXML() method or
100 // whatever. See https://bugs.launchpad.net/inkscape/+bug/1617615
101 // Applicable to empty paths.
102 std::shared_ptr<PathManipulator> hold(i->second);
103 ((hold.get())->*method)();
104 i = next_i;
105 }
106 }
107 template <typename R, typename A>
108 void invokeForAll(R (PathManipulator::*method)(A), A a) {
109 for (auto & i : _mmap) {
110 ((i.second.get())->*method)(a);
111 }
112 }
113 template <typename R, typename A>
114 void invokeForAll(R (PathManipulator::*method)(A const &), A const &a) {
115 for (auto & i : _mmap) {
116 ((i.second.get())->*method)(a);
117 }
118 }
119 template <typename R, typename A, typename B>
120 void invokeForAll(R (PathManipulator::*method)(A,B), A a, B b) {
121 for (auto & i : _mmap) {
122 ((i.second.get())->*method)(a, b);
123 }
124 }
125
126 void _commit(CommitEvent cps);
127 void _done(gchar const *reason, bool alert_LPE = true);
128 void _doneWithCleanup(gchar const *reason, bool alert_LPE = false);
130
132
133public:
135
136private:
143
144 friend class PathManipulator;
145};
146
147} // namespace UI
148} // namespace Inkscape
149
150#endif // INKSCAPE_UI_TOOL_MULTI_PATH_MANIPULATOR_H
151
152/*
153 Local Variables:
154 mode:c++
155 c-file-style:"stroustrup"
156 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
157 indent-tabs-mode:nil
158 fill-column:99
159 End:
160*/
161// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
Store paths to a PathVector.
Definition path-sink.h:226
Two-dimensional point that doubles as a vector.
Definition point.h:66
Manipulator that manages multiple path manipulators active at the same time.
void copySelectedPath(Geom::PathBuilder *builder)
void setItems(std::set< ShapeRecord > const &)
Change the set of items to edit.
std::map< ShapeRecord, std::shared_ptr< PathManipulator > > MapType
void invokeForAll(R(PathManipulator::*method)(A const &), A const &a)
void _done(gchar const *reason, bool alert_LPE=true)
Commits changes to XML and adds undo stack entry.
sigc::signal< void()> signal_coords_changed
Emitted whenever the coordinates shown in the status bar need updating.
void setLiveObjects(bool set)
Set live object update status.
std::pair< ShapeRecord, std::shared_ptr< PathManipulator > > MapPair
void invokeForAll(R(PathManipulator::*method)(A), A a)
void joinSegments()
Join selected endpoints to create segments.
void setLiveOutline(bool set)
Set live outline update status.
void invokeForAll(R(PathManipulator::*method)())
void invokeForAll(R(PathManipulator::*method)(A, B), A a, B b)
void alignNodes(Geom::Dim2 d, AlignTargetNode target=AlignTargetNode::MID_NODE)
void cleanup()
Remove empty manipulators.
void insertNodesAtExtrema(ExtremumType extremum)
Colors::Color _getOutlineColor(ShapeRole role, SPObject *object)
Get an outline color based on the shape's role (normal, mask, LPE parameter, etc.).
bool event(Inkscape::UI::Tools::ToolBase *tool, CanvasEvent const &event) override
Handle input event. Returns true if handled.
void _doneWithCleanup(gchar const *reason, bool alert_LPE=false)
Commits changes to XML, adds undo stack entry and removes empty manipulators.
void scale(Geom::Point const &center, Geom::Point const &scale)
void _commit(CommitEvent cps)
Commit changes to XML and add undo stack entry based on the action that was done.
void deleteNodes()
Delete nodes, use the preference to decide which mode to use.
Manipulator that edits a single path using nodes with handles.
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
Base class for Event processors.
Definition tool-base.h:95
SPObject is an abstract base class of all of the document nodes at the SVG document level.
Definition sp-object.h:160
Commit events.
Dim2
2D axis enumeration (X or Y).
Definition coord.h:48
Manipulator - edits something on-canvas.
Fine-grained modifier tracker for event handling.
ShapeRole
Role of the shape in the drawing - affects outline display and color.
NodeType
Types of nodes supported in the node tool.
Definition node-types.h:20
CommitEvent
This is used to provide sensible messages on the undo stack.
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.
Node types and other small enums.
int mode
Path manipulator - a component that edits a single path on-canvas.
callback interface for SVG path data
Structures that store data needed for shape editing which are not contained directly in the XML node.
static const Point data[]
Abstract base class for events.
int delta
Glib::RefPtr< Gtk::Builder > builder