b3c2f422bd5a12256a4e7d6ebef0ef19fb926538
1 /** @file
2 * Node selection - stores a set of nodes and applies transformations
3 * to them
4 */
5 /* Authors:
6 * Krzysztof KosiĆski <tweenk.pl@gmail.com>
7 *
8 * Copyright (C) 2009 Authors
9 * Released under GNU GPL, read the file 'COPYING' for more information
10 */
12 #ifndef SEEN_UI_TOOL_NODE_SELECTION_H
13 #define SEEN_UI_TOOL_NODE_SELECTION_H
15 #include <memory>
16 #include <boost/optional.hpp>
17 #include <boost/unordered_set.hpp>
18 #include <boost/unordered_map.hpp>
19 #include <sigc++/sigc++.h>
20 #include <2geom/forward.h>
21 #include <2geom/point.h>
22 #include <2geom/rect.h>
23 #include "display/display-forward.h"
24 #include "util/accumulators.h"
25 #include "ui/tool/commit-events.h"
26 #include "ui/tool/manipulator.h"
28 class SPDesktop;
30 namespace Inkscape {
31 namespace UI {
32 class TransformHandleSet;
33 class SelectableControlPoint;
34 }
35 }
37 namespace Inkscape {
38 namespace UI {
40 class ControlPointSelection : public Manipulator, public sigc::trackable {
41 public:
42 ControlPointSelection(SPDesktop *d, SPCanvasGroup *th_group);
43 ~ControlPointSelection();
44 typedef boost::unordered_set< SelectableControlPoint * > set_type;
45 typedef set_type Set; // convenience alias
47 typedef set_type::iterator iterator;
48 typedef set_type::const_iterator const_iterator;
49 typedef set_type::size_type size_type;
50 typedef SelectableControlPoint *value_type;
51 typedef SelectableControlPoint *key_type;
53 // size
54 bool empty() { return _points.empty(); }
55 size_type size() { return _points.size(); }
57 // iterators
58 iterator begin() { return _points.begin(); }
59 const_iterator begin() const { return _points.begin(); }
60 iterator end() { return _points.end(); }
61 const_iterator end() const { return _points.end(); }
63 // insert
64 std::pair<iterator, bool> insert(const value_type& x);
65 template <class InputIterator>
66 void insert(InputIterator first, InputIterator last) {
67 for (; first != last; ++first) {
68 insert(*first);
69 }
70 }
72 // erase
73 void clear();
74 void erase(iterator pos);
75 size_type erase(const key_type& k);
76 void erase(iterator first, iterator last);
78 // find
79 iterator find(const key_type &k) { return _points.find(k); }
81 // Sometimes it is very useful to keep a list of all selectable points.
82 set_type const &allPoints() const { return _all_points; }
83 set_type &allPoints() { return _all_points; }
84 // ...for example in these methods. Another useful case is snapping.
85 void selectAll();
86 void selectArea(Geom::Rect const &);
87 void invertSelection();
88 void spatialGrow(SelectableControlPoint *origin, int dir);
90 virtual bool event(GdkEvent *);
92 void transform(Geom::Matrix const &m);
93 void align(Geom::Dim2 d);
94 void distribute(Geom::Dim2 d);
96 Geom::OptRect pointwiseBounds();
97 Geom::OptRect bounds();
99 bool transformHandlesEnabled() { return _handles_visible; }
100 void showTransformHandles(bool v, bool one_node);
101 // the two methods below do not modify the state; they are for use in manipulators
102 // that need to temporarily hide the handles, for example when moving a node
103 void hideTransformHandles();
104 void restoreTransformHandles();
105 void toggleTransformHandlesMode();
107 sigc::signal<void> signal_update;
108 sigc::signal<void, SelectableControlPoint *, bool> signal_point_changed;
109 sigc::signal<void, CommitEvent> signal_commit;
110 private:
111 // The functions below are invoked from SelectableControlPoint.
112 // Previously they were connected to handlers when selecting, but this
113 // creates problems when dragging a point that was not selected.
114 void _pointGrabbed(SelectableControlPoint *);
115 void _pointDragged(Geom::Point &, GdkEventMotion *);
116 void _pointUngrabbed();
117 bool _pointClicked(SelectableControlPoint *, GdkEventButton *);
118 void _pointChanged(SelectableControlPoint *, bool);
119 void _mouseoverChanged();
121 void _updateTransformHandles(bool preserve_center);
122 void _updateBounds();
123 bool _keyboardMove(GdkEventKey const &, Geom::Point const &);
124 bool _keyboardRotate(GdkEventKey const &, int);
125 bool _keyboardScale(GdkEventKey const &, int);
126 bool _keyboardFlip(Geom::Dim2);
127 void _keyboardTransform(Geom::Matrix const &);
128 void _commitHandlesTransform(CommitEvent ce);
129 double _rotationRadius(Geom::Point const &);
131 set_type _points;
132 set_type _all_points;
133 boost::unordered_map<SelectableControlPoint *, Geom::Point> _original_positions;
134 boost::optional<double> _rot_radius;
135 boost::optional<double> _mouseover_rot_radius;
136 Geom::OptRect _bounds;
137 TransformHandleSet *_handles;
138 SelectableControlPoint *_grabbed_point, *_farthest_point;
139 unsigned _dragging : 1;
140 unsigned _handles_visible : 1;
141 unsigned _one_node_handles : 1;
143 friend class SelectableControlPoint;
144 };
146 } // namespace UI
147 } // namespace Inkscape
149 #endif
151 /*
152 Local Variables:
153 mode:c++
154 c-file-style:"stroustrup"
155 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
156 indent-tabs-mode:nil
157 fill-column:99
158 End:
159 */
160 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :