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 <tr1/unordered_map>
17 #include <tr1/unordered_set>
18 #include <boost/optional.hpp>
19 #include <sigc++/sigc++.h>
20 #include <2geom/forward.h>
21 #include <2geom/point.h>
22 #include "display/display-forward.h"
23 #include "util/accumulators.h"
24 #include "util/hash.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 {
41 public:
42 ControlPointSelection(SPDesktop *d, SPCanvasGroup *th_group);
43 ~ControlPointSelection();
44 typedef std::tr1::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 void showTransformHandles(bool v, bool one_node);
100 // the two methods below do not modify the state; they are for use in manipulators
101 // that need to temporarily hide the handles, for example when moving a node
102 void hideTransformHandles();
103 void restoreTransformHandles();
104 void toggleTransformHandlesMode();
106 sigc::signal<void> signal_update;
107 sigc::signal<void, SelectableControlPoint *, bool> signal_point_changed;
108 sigc::signal<void, CommitEvent> signal_commit;
109 private:
110 // The functions below are invoked from SelectableControlPoint.
111 // Previously they were connected to handlers when selecting, but this
112 // creates problems when dragging a point that was not selected.
113 void _pointGrabbed();
114 void _pointDragged(Geom::Point const &, Geom::Point &, GdkEventMotion *);
115 void _pointUngrabbed();
116 bool _pointClicked(SelectableControlPoint *, GdkEventButton *);
118 void _updateTransformHandles(bool preserve_center);
119 bool _keyboardMove(GdkEventKey const &, Geom::Point const &);
120 bool _keyboardRotate(GdkEventKey const &, int);
121 bool _keyboardScale(GdkEventKey const &, int);
122 bool _keyboardFlip(Geom::Dim2);
123 void _keyboardTransform(Geom::Matrix const &);
124 void _commitTransform(CommitEvent ce);
125 set_type _points;
126 set_type _all_points;
127 boost::optional<double> _rot_radius;
128 TransformHandleSet *_handles;
129 SelectableControlPoint *_grabbed_point;
130 unsigned _dragging : 1;
131 unsigned _handles_visible : 1;
132 unsigned _one_node_handles : 1;
134 friend class SelectableControlPoint;
135 };
137 } // namespace UI
138 } // namespace Inkscape
140 #endif
142 /*
143 Local Variables:
144 mode:c++
145 c-file-style:"stroustrup"
146 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
147 indent-tabs-mode:nil
148 fill-column:99
149 End:
150 */
151 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :