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