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/shared_ptr.hpp>
19 #include <boost/weak_ptr.hpp>
20 #include <boost/optional.hpp>
21 #include <sigc++/sigc++.h>
22 #include <2geom/forward.h>
23 #include <2geom/point.h>
24 #include "display/display-forward.h"
25 #include "util/accumulators.h"
26 #include "util/hash.h"
27 #include "ui/tool/commit-events.h"
28 #include "ui/tool/manipulator.h"
30 namespace std { using namespace tr1; }
32 class SPDesktop;
34 namespace Inkscape {
35 namespace UI {
37 class TransformHandleSet;
38 class SelectableControlPoint;
40 class ControlPointSelection : public Manipulator {
41 public:
42 ControlPointSelection(SPDesktop *d, SPCanvasGroup *th_group);
43 ~ControlPointSelection();
44 typedef std::list<sigc::connection> connlist_type;
45 typedef std::unordered_map< SelectableControlPoint *,
46 boost::shared_ptr<connlist_type> > map_type;
47 typedef std::unordered_set< SelectableControlPoint * > set_type;
48 typedef set_type Set; // convenience alias
50 typedef map_type::iterator iterator;
51 typedef map_type::const_iterator const_iterator;
52 typedef map_type::size_type size_type;
53 typedef SelectableControlPoint *value_type;
54 typedef SelectableControlPoint *key_type;
56 // size
57 bool empty() { return _points.empty(); }
58 size_type size() { return _points.size(); }
60 // iterators
61 iterator begin() { return _points.begin(); }
62 const_iterator begin() const { return _points.begin(); }
63 iterator end() { return _points.end(); }
64 const_iterator end() const { return _points.end(); }
66 // insert
67 std::pair<iterator, bool> insert(const value_type& x);
68 template <class InputIterator>
69 void insert(InputIterator first, InputIterator last) {
70 for (; first != last; ++first) {
71 insert(*first);
72 }
73 }
75 // erase
76 void clear();
77 void erase(iterator pos);
78 size_type erase(const key_type& k);
79 void erase(iterator first, iterator last);
81 // find
82 iterator find(const key_type &k) { return _points.find(k); }
84 // Sometimes it is very useful to keep a list of all selectable points.
85 set_type const &allPoints() const { return _all_points; }
86 set_type &allPoints() { return _all_points; }
87 // ...for example in these methods. Another useful case is snapping.
88 void selectAll();
89 void selectArea(Geom::Rect const &);
90 void invertSelection();
91 void spatialGrow(SelectableControlPoint *origin, int dir);
93 virtual bool event(GdkEvent *);
95 void transform(Geom::Matrix const &m);
96 void align(Geom::Dim2 d);
97 void distribute(Geom::Dim2 d);
99 Geom::OptRect pointwiseBounds();
100 Geom::OptRect bounds();
102 void showTransformHandles(bool v, bool one_node);
103 // the two methods below do not modify the state; they are for use in manipulators
104 // that need to temporarily hide the handles
105 void hideTransformHandles();
106 void restoreTransformHandles();
108 // TODO this is really only applicable to nodes... maybe derive a NodeSelection?
109 void setSculpting(bool v) { _sculpt_enabled = v; }
111 sigc::signal<void> signal_update;
112 sigc::signal<void, SelectableControlPoint *, bool> signal_point_changed;
113 sigc::signal<void, CommitEvent> signal_commit;
114 private:
115 void _selectionGrabbed(SelectableControlPoint *, GdkEventMotion *);
116 void _selectionDragged(Geom::Point const &, Geom::Point &, GdkEventMotion *);
117 void _selectionUngrabbed();
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 map_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;
133 unsigned _sculpt_enabled : 1;
134 unsigned _sculpting : 1;
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 :