Code

Go back to using TR1 unordered containers to fix warnings. Add configure
[inkscape.git] / src / ui / tool / control-point-selection.h
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 class SPDesktop;
32 namespace Inkscape {
33 namespace UI {
34 class TransformHandleSet;
35 class SelectableControlPoint;
36 }
37 }
39 namespace Inkscape {
40 namespace UI {
42 class ControlPointSelection : public Manipulator {
43 public:
44     ControlPointSelection(SPDesktop *d, SPCanvasGroup *th_group);
45     ~ControlPointSelection();
46     typedef std::list<sigc::connection> connlist_type;
47     typedef std::tr1::unordered_map< SelectableControlPoint *,
48         boost::shared_ptr<connlist_type> > map_type;
49     typedef std::tr1::unordered_set< SelectableControlPoint * > set_type;
50     typedef set_type Set; // convenience alias
52     typedef map_type::iterator iterator;
53     typedef map_type::const_iterator const_iterator;
54     typedef map_type::size_type size_type;
55     typedef SelectableControlPoint *value_type;
56     typedef SelectableControlPoint *key_type;
58     // size
59     bool empty() { return _points.empty(); }
60     size_type size() { return _points.size(); }
62     // iterators
63     iterator begin() { return _points.begin(); }
64     const_iterator begin() const { return _points.begin(); }
65     iterator end() { return _points.end(); }
66     const_iterator end() const { return _points.end(); }
68     // insert
69     std::pair<iterator, bool> insert(const value_type& x);
70     template <class InputIterator>
71     void insert(InputIterator first, InputIterator last) {
72         for (; first != last; ++first) {
73             insert(*first);
74         }
75     }
77     // erase
78     void clear();
79     void erase(iterator pos);
80     size_type erase(const key_type& k);
81     void erase(iterator first, iterator last);
83     // find
84     iterator find(const key_type &k) { return _points.find(k); }
86     // Sometimes it is very useful to keep a list of all selectable points.
87     set_type const &allPoints() const { return _all_points; }
88     set_type &allPoints() { return _all_points; }
89     // ...for example in these methods. Another useful case is snapping.
90     void selectAll();
91     void selectArea(Geom::Rect const &);
92     void invertSelection();
93     void spatialGrow(SelectableControlPoint *origin, int dir);
95     virtual bool event(GdkEvent *);
97     void transform(Geom::Matrix const &m);
98     void align(Geom::Dim2 d);
99     void distribute(Geom::Dim2 d);
101     Geom::OptRect pointwiseBounds();
102     Geom::OptRect bounds();
104     void showTransformHandles(bool v, bool one_node);
105     // the two methods below do not modify the state; they are for use in manipulators
106     // that need to temporarily hide the handles, for example when moving a node
107     void hideTransformHandles();
108     void restoreTransformHandles();
109     void toggleTransformHandlesMode();
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     // The functions below are invoked from SelectableControlPoint.
116     // Previously they were connected to handlers when selecting, but this
117     // creates problems when dragging a point that was not selected.
118     void _pointGrabbed();
119     void _pointDragged(Geom::Point const &, Geom::Point &, GdkEventMotion *);
120     void _pointUngrabbed();
121     bool _pointClicked(SelectableControlPoint *, GdkEventButton *);
123     void _updateTransformHandles(bool preserve_center);
124     bool _keyboardMove(GdkEventKey const &, Geom::Point const &);
125     bool _keyboardRotate(GdkEventKey const &, int);
126     bool _keyboardScale(GdkEventKey const &, int);
127     bool _keyboardFlip(Geom::Dim2);
128     void _keyboardTransform(Geom::Matrix const &);
129     void _commitTransform(CommitEvent ce);
130     map_type _points;
131     set_type _all_points;
132     boost::optional<double> _rot_radius;
133     TransformHandleSet *_handles;
134     SelectableControlPoint *_grabbed_point;
135     unsigned _dragging         : 1;
136     unsigned _handles_visible  : 1;
137     unsigned _one_node_handles : 1;
139     friend class SelectableControlPoint;
140 };
142 } // namespace UI
143 } // namespace Inkscape
145 #endif
147 /*
148   Local Variables:
149   mode:c++
150   c-file-style:"stroustrup"
151   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
152   indent-tabs-mode:nil
153   fill-column:99
154   End:
155 */
156 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :