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; }
29 namespace UI {
31 class PathManipulator;
32 class ControlPointSelection;
33 class PathManipulatorObserver;
34 class CurveDragPoint;
35 class PathCanvasGroups;
37 struct PathSharedData {
38 NodeSharedData node_data;
39 SPCanvasGroup *outline_group;
40 SPCanvasGroup *dragpoint_group;
41 };
43 /**
44 * Manipulator that edits a single path using nodes with handles.
45 * Currently only cubic bezier and linear segments are supported, but this might change
46 * some time in the future.
47 */
48 class PathManipulator : public PointManipulator {
49 public:
50 typedef SPPath *ItemType;
52 PathManipulator(PathSharedData const &data, SPPath *path, Geom::Matrix const &edit_trans,
53 guint32 outline_color, Glib::ustring lpe_key);
54 ~PathManipulator();
55 virtual bool event(GdkEvent *);
57 bool empty();
58 void writeXML();
59 void update(); // update display, but don't commit
60 void clear(); // remove all nodes from manipulator
61 SPPath *item() { return _path; }
63 void selectSubpaths();
64 void selectAll();
65 void selectArea(Geom::Rect const &);
66 void shiftSelection(int dir);
67 void linearGrow(int dir);
68 void spatialGrow(int dir);
69 void invertSelection();
70 void invertSelectionInSubpaths();
72 void insertNodes();
73 void weldNodes(NodeList::iterator const &preserve_pos = NodeList::iterator());
74 void weldSegments();
75 void breakNodes();
76 void deleteNodes(bool keep_shape = true);
77 void deleteSegments();
78 void reverseSubpaths();
79 void setSegmentType(SegmentType);
81 void showOutline(bool show);
82 void showHandles(bool show);
83 void showPathDirection(bool show);
84 void setControlsTransform(Geom::Matrix const &);
85 void hideDragPoint();
87 NodeList::iterator subdivideSegment(NodeList::iterator after, double t);
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 PathSharedData const &_path_data;
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 };
139 } // namespace UI
140 } // namespace Inkscape
142 #endif
144 /*
145 Local Variables:
146 mode:c++
147 c-file-style:"stroustrup"
148 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
149 indent-tabs-mode:nil
150 fill-column:99
151 End:
152 */
153 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :