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 "util/set-types.h"
18 #include <sigc++/sigc++.h>
19 #include <2geom/forward.h>
20 #include <2geom/point.h>
21 #include <2geom/rect.h>
22 #include "display/display-forward.h"
23 #include "util/accumulators.h"
24 #include "ui/tool/commit-events.h"
25 #include "ui/tool/manipulator.h"
27 class SPDesktop;
29 namespace Inkscape {
30 namespace UI {
31 class TransformHandleSet;
32 class SelectableControlPoint;
33 }
34 }
36 #ifdef USE_GNU_HASHES
37 namespace __gnu_cxx {
38 template<>
39 struct hash<Inkscape::UI::SelectableControlPoint*> {
40 size_t operator()(Inkscape::UI::SelectableControlPoint *p) const {
41 return reinterpret_cast<size_t>(p);
42 }
43 };
44 } // namespace __gnu_cxx
45 #endif // USE_GNU_HASHES
47 namespace Inkscape {
48 namespace UI {
50 class ControlPointSelection : public Manipulator, public sigc::trackable {
51 public:
52 ControlPointSelection(SPDesktop *d, SPCanvasGroup *th_group);
53 ~ControlPointSelection();
54 typedef optim_set< SelectableControlPoint * > set_type;
55 typedef set_type Set; // convenience alias
57 typedef set_type::iterator iterator;
58 typedef set_type::const_iterator const_iterator;
59 typedef set_type::size_type size_type;
60 typedef SelectableControlPoint *value_type;
61 typedef SelectableControlPoint *key_type;
63 // size
64 bool empty() { return _points.empty(); }
65 size_type size() { return _points.size(); }
67 // iterators
68 iterator begin() { return _points.begin(); }
69 const_iterator begin() const { return _points.begin(); }
70 iterator end() { return _points.end(); }
71 const_iterator end() const { return _points.end(); }
73 // insert
74 std::pair<iterator, bool> insert(const value_type& x);
75 template <class InputIterator>
76 void insert(InputIterator first, InputIterator last) {
77 for (; first != last; ++first) {
78 insert(*first);
79 }
80 }
82 // erase
83 void clear();
84 void erase(iterator pos);
85 size_type erase(const key_type& k);
86 void erase(iterator first, iterator last);
88 // find
89 iterator find(const key_type &k) {
90 return _points.find(k);
91 }
93 // Sometimes it is very useful to keep a list of all selectable points.
94 set_type const &allPoints() const { return _all_points; }
95 set_type &allPoints() { return _all_points; }
96 // ...for example in these methods. Another useful case is snapping.
97 void selectAll();
98 void selectArea(Geom::Rect const &);
99 void invertSelection();
100 void spatialGrow(SelectableControlPoint *origin, int dir);
102 virtual bool event(GdkEvent *);
104 void transform(Geom::Matrix const &m);
105 void align(Geom::Dim2 d);
106 void distribute(Geom::Dim2 d);
108 Geom::OptRect pointwiseBounds();
109 Geom::OptRect bounds();
111 bool transformHandlesEnabled() { return _handles_visible; }
112 void showTransformHandles(bool v, bool one_node);
113 // the two methods below do not modify the state; they are for use in manipulators
114 // that need to temporarily hide the handles, for example when moving a node
115 void hideTransformHandles();
116 void restoreTransformHandles();
117 void toggleTransformHandlesMode();
119 sigc::signal<void> signal_update;
120 sigc::signal<void, SelectableControlPoint *, bool> signal_point_changed;
121 sigc::signal<void, CommitEvent> signal_commit;
122 private:
123 // The functions below are invoked from SelectableControlPoint.
124 // Previously they were connected to handlers when selecting, but this
125 // creates problems when dragging a point that was not selected.
126 void _pointGrabbed(SelectableControlPoint *);
127 void _pointDragged(Geom::Point &, GdkEventMotion *);
128 void _pointUngrabbed();
129 bool _pointClicked(SelectableControlPoint *, GdkEventButton *);
130 void _pointChanged(SelectableControlPoint *, bool);
131 void _mouseoverChanged();
133 void _updateTransformHandles(bool preserve_center);
134 void _updateBounds();
135 bool _keyboardMove(GdkEventKey const &, Geom::Point const &);
136 bool _keyboardRotate(GdkEventKey const &, int);
137 bool _keyboardScale(GdkEventKey const &, int);
138 bool _keyboardFlip(Geom::Dim2);
139 void _keyboardTransform(Geom::Matrix const &);
140 void _commitHandlesTransform(CommitEvent ce);
141 double _rotationRadius(Geom::Point const &);
143 set_type _points;
144 set_type _all_points;
145 optim_map<SelectableControlPoint *, Geom::Point> _original_positions;
146 boost::optional<double> _rot_radius;
147 boost::optional<double> _mouseover_rot_radius;
148 Geom::OptRect _bounds;
149 TransformHandleSet *_handles;
150 SelectableControlPoint *_grabbed_point, *_farthest_point;
151 unsigned _dragging : 1;
152 unsigned _handles_visible : 1;
153 unsigned _one_node_handles : 1;
155 friend class SelectableControlPoint;
156 };
158 } // namespace UI
159 } // namespace Inkscape
161 #endif
163 /*
164 Local Variables:
165 mode:c++
166 c-file-style:"stroustrup"
167 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
168 indent-tabs-mode:nil
169 fill-column:99
170 End:
171 */
172 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :