Code

Fix path reverse action (Shift+R) in the node tool.
[inkscape.git] / src / ui / tool / path-manipulator.h
1 /** @file
2  * Path manipulator - a component that edits a single path on-canvas
3  */
4 /* Authors:
5  *   Krzysztof KosiƄski <tweenk.pl@gmail.com>
6  *
7  * Copyright (C) 2009 Authors
8  * Released under GNU GPL, read the file 'COPYING' for more information
9  */
11 #ifndef SEEN_UI_TOOL_PATH_MANIPULATOR_H
12 #define SEEN_UI_TOOL_PATH_MANIPULATOR_H
14 #include <string>
15 #include <memory>
16 #include <2geom/pathvector.h>
17 #include <2geom/matrix.h>
18 #include <boost/shared_ptr.hpp>
19 #include <boost/weak_ptr.hpp>
20 #include "display/display-forward.h"
21 #include "forward.h"
22 #include "ui/tool/node.h"
23 #include "ui/tool/manipulator.h"
25 struct SPCanvasItem;
27 namespace Inkscape {
28 namespace XML { class Node; }
30 namespace UI {
32 class PathManipulator;
33 class ControlPointSelection;
34 class PathManipulatorObserver;
35 class CurveDragPoint;
36 class PathCanvasGroups;
37 class MultiPathManipulator;
38 class Node;
40 struct PathSharedData {
41     NodeSharedData node_data;
42     SPCanvasGroup *outline_group;
43     SPCanvasGroup *dragpoint_group;
44 };
46 /**
47  * Manipulator that edits a single path using nodes with handles.
48  * Currently only cubic bezier and linear segments are supported, but this might change
49  * some time in the future.
50  */
51 class PathManipulator : public PointManipulator {
52 public:
53     typedef SPPath *ItemType;
55     PathManipulator(MultiPathManipulator &mpm, SPPath *path, Geom::Matrix const &edit_trans,
56         guint32 outline_color, Glib::ustring lpe_key);
57     ~PathManipulator();
58     virtual bool event(GdkEvent *);
60     bool empty();
61     void writeXML();
62     void update(); // update display, but don't commit
63     void clear(); // remove all nodes from manipulator
64     SPPath *item() { return _path; }
66     void selectSubpaths();
67     void shiftSelection(int dir);
68     void invertSelectionInSubpaths();
70     void insertNodes();
71     void weldNodes(NodeList::iterator preserve_pos = NodeList::iterator());
72     void weldSegments();
73     void breakNodes();
74     void deleteNodes(bool keep_shape = true);
75     void deleteSegments();
76     void reverseSubpaths(bool selected_only);
77     void setSegmentType(SegmentType);
79     void showOutline(bool show);
80     void showHandles(bool show);
81     void showPathDirection(bool show);
82     void setControlsTransform(Geom::Matrix const &);
83     void hideDragPoint();
85     NodeList::iterator subdivideSegment(NodeList::iterator after, double t);
86     NodeList::iterator extremeNode(NodeList::iterator origin, bool search_selected,
87         bool search_unselected, bool closest);
89     static bool is_item_type(void *item);
90 private:
91     typedef NodeList Subpath;
92     typedef boost::shared_ptr<NodeList> SubpathPtr;
94     void _createControlPointsFromGeometry();
95     void _createGeometryFromControlPoints();
96     std::string _createTypeString();
97     void _updateOutline();
98     //void _setOutline(Geom::PathVector const &);
99     void _getGeometry();
100     void _setGeometry();
101     Glib::ustring _nodetypesKey();
102     Inkscape::XML::Node *_getXMLNode();
104     void _attachNodeHandlers(Node *n);
105     void _removeNodeHandlers(Node *n);
107     void _selectionChanged(SelectableControlPoint *p, bool selected);
108     bool _nodeClicked(Node *, GdkEventButton *);
109     void _handleGrabbed();
110     bool _handleClicked(Handle *, GdkEventButton *);
111     void _handleUngrabbed();
112     void _externalChange(unsigned type);
113     void _removeNodesFromSelection();
114     void _commit(Glib::ustring const &annotation);
115     void _updateDragPoint(Geom::Point const &);
116     void _updateOutlineOnZoomChange();
117     double _getStrokeTolerance();
119     SubpathList _subpaths;
120     MultiPathManipulator &_multi_path_manipulator;
121     SPPath *_path;
122     SPCurve *_spcurve; // in item coordinates
123     SPCanvasItem *_outline;
124     CurveDragPoint *_dragpoint; // an invisible control point hoverng over curve
125     PathManipulatorObserver *_observer;
126     Geom::Matrix _d2i_transform; ///< desktop-to-item transform
127     Geom::Matrix _i2d_transform; ///< item-to-desktop transform, inverse of _d2i_transform
128     Geom::Matrix _edit_transform; ///< additional transform to apply to editing controls
129     unsigned _num_selected; ///< number of selected nodes
130     bool _show_handles;
131     bool _show_outline;
132     bool _show_path_direction;
133     Glib::ustring _lpe_key;
135     friend class PathManipulatorObserver;
136     friend class CurveDragPoint;
137     friend class Node;
138 };
140 } // namespace UI
141 } // namespace Inkscape
143 #endif
145 /*
146   Local Variables:
147   mode:c++
148   c-file-style:"stroustrup"
149   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
150   indent-tabs-mode:nil
151   fill-column:99
152   End:
153 */
154 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :