Code

First GSoC node tool commit to Bazaar
[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 <boost/shared_ptr.hpp>
18 #include <boost/weak_ptr.hpp>
19 #include <boost/optional.hpp>
20 #include <sigc++/sigc++.h>
21 #include <2geom/forward.h>
22 #include <2geom/point.h>
23 #include "display/display-forward.h"
24 #include "util/accumulators.h"
25 #include "util/hash.h"
26 #include "ui/tool/commit-events.h"
27 #include "ui/tool/manipulator.h"
29 namespace std { using namespace tr1; }
31 class SPDesktop;
33 namespace Inkscape {
34 namespace UI {
36 class TransformHandleSet;
37 class SelectableControlPoint;
39 class ControlPointSelection : public Manipulator {
40 public:
41     ControlPointSelection(SPDesktop *d, SPCanvasGroup *th_group);
42     ~ControlPointSelection();
43     typedef std::list<sigc::connection> connlist_type;
44     typedef std::unordered_map< SelectableControlPoint *,
45         boost::shared_ptr<connlist_type> > map_type;
47     // boilerplate typedefs
48     typedef map_type::iterator iterator;
49     typedef map_type::const_iterator const_iterator;
50     typedef map_type::size_type size_type;
52     typedef SelectableControlPoint *value_type;
53     typedef SelectableControlPoint *key_type;
55     // size
56     bool empty() { return _points.empty(); }
57     size_type size() { return _points.size(); }
59     // iterators
60     iterator begin() { return _points.begin(); }
61     const_iterator begin() const { return _points.begin(); }
62     iterator end() { return _points.end(); }
63     const_iterator end() const { return _points.end(); }
65     // insert
66     std::pair<iterator, bool> insert(const value_type& x);
67     template <class InputIterator>
68     void insert(InputIterator first, InputIterator last) {
69         for (; first != last; ++first) {
70             insert(*first);
71         }
72     }
74     // erase
75     void clear();
76     void erase(iterator pos);
77     size_type erase(const key_type& k);
78     void erase(iterator first, iterator last);
80     // find
81     iterator find(const key_type &k) { return _points.find(k); }
83     virtual bool event(GdkEvent *);
85     void transform(Geom::Matrix const &m);
86     void align(Geom::Dim2 d);
87     void distribute(Geom::Dim2 d);
89     Geom::OptRect pointwiseBounds();
90     Geom::OptRect bounds();
92     void showTransformHandles(bool v, bool one_node);
93     // the two methods below do not modify the state; they are for use in manipulators
94     // that need to temporarily hide the handles
95     void hideTransformHandles();
96     void restoreTransformHandles();
97     
98     // TODO this is really only applicable to nodes... maybe derive a NodeSelection?
99     void setSculpting(bool v) { _sculpt_enabled = v; }
101     sigc::signal<void> signal_update;
102     sigc::signal<void, SelectableControlPoint *, bool> signal_point_changed;
103     sigc::signal<void, CommitEvent> signal_commit;
104 private:
105     void _selectionGrabbed(SelectableControlPoint *, GdkEventMotion *);
106     void _selectionDragged(Geom::Point const &, Geom::Point &, GdkEventMotion *);
107     void _selectionUngrabbed();
108     void _updateTransformHandles(bool preserve_center);
109     bool _keyboardMove(GdkEventKey const &, Geom::Point const &);
110     bool _keyboardRotate(GdkEventKey const &, int);
111     bool _keyboardScale(GdkEventKey const &, int);
112     bool _keyboardFlip(Geom::Dim2);
113     void _keyboardTransform(Geom::Matrix const &);
114     void _commitTransform(CommitEvent ce);
115     map_type _points;
116     boost::optional<double> _rot_radius;
117     TransformHandleSet *_handles;
118     SelectableControlPoint *_grabbed_point;
119     unsigned _dragging         : 1;
120     unsigned _handles_visible  : 1;
121     unsigned _one_node_handles : 1;
122     unsigned _sculpt_enabled   : 1;
123     unsigned _sculpting        : 1;
124 };
126 } // namespace UI
127 } // namespace Inkscape
129 #endif
131 /*
132   Local Variables:
133   mode:c++
134   c-file-style:"stroustrup"
135   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
136   indent-tabs-mode:nil
137   fill-column:99
138   End:
139 */
140 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :