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;
39 class Handle;
41 struct PathSharedData {
42 NodeSharedData node_data;
43 SPCanvasGroup *outline_group;
44 SPCanvasGroup *dragpoint_group;
45 };
47 /**
48 * Manipulator that edits a single path using nodes with handles.
49 * Currently only cubic bezier and linear segments are supported, but this might change
50 * some time in the future.
51 */
52 class PathManipulator : public PointManipulator {
53 public:
54 typedef SPPath *ItemType;
56 PathManipulator(MultiPathManipulator &mpm, SPPath *path, Geom::Matrix const &edit_trans,
57 guint32 outline_color, Glib::ustring lpe_key);
58 ~PathManipulator();
59 virtual bool event(GdkEvent *);
61 bool empty();
62 void writeXML();
63 void update(); // update display, but don't commit
64 void clear(); // remove all nodes from manipulator
65 SPPath *item() { return _path; }
67 void selectSubpaths();
68 void invertSelectionInSubpaths();
70 void insertNodes();
71 void duplicateNodes();
72 void weldNodes(NodeList::iterator preserve_pos = NodeList::iterator());
73 void weldSegments();
74 void breakNodes();
75 void deleteNodes(bool keep_shape = true);
76 void deleteSegments();
77 void reverseSubpaths(bool selected_only);
78 void setSegmentType(SegmentType);
80 void scaleHandle(Node *n, int which, int dir, bool pixel);
81 void rotateHandle(Node *n, int which, int dir, bool pixel);
83 void showOutline(bool show);
84 void showHandles(bool show);
85 void showPathDirection(bool show);
86 void setLiveOutline(bool set);
87 void setLiveObjects(bool set);
88 void setControlsTransform(Geom::Matrix const &);
89 void hideDragPoint();
90 MultiPathManipulator &mpm() { return _multi_path_manipulator; }
92 NodeList::iterator subdivideSegment(NodeList::iterator after, double t);
93 NodeList::iterator extremeNode(NodeList::iterator origin, bool search_selected,
94 bool search_unselected, bool closest);
96 // this is necessary for Tab-selection in MultiPathManipulator
97 SubpathList &subpathList() { return _subpaths; }
99 static bool is_item_type(void *item);
100 private:
101 typedef NodeList Subpath;
102 typedef boost::shared_ptr<NodeList> SubpathPtr;
104 void _createControlPointsFromGeometry();
105 void _createGeometryFromControlPoints();
106 unsigned _deleteStretch(NodeList::iterator first, NodeList::iterator last, bool keep_shape);
107 std::string _createTypeString();
108 void _updateOutline();
109 //void _setOutline(Geom::PathVector const &);
110 void _getGeometry();
111 void _setGeometry();
112 Glib::ustring _nodetypesKey();
113 Inkscape::XML::Node *_getXMLNode();
115 void _selectionChanged(SelectableControlPoint *p, bool selected);
116 bool _nodeClicked(Node *, GdkEventButton *);
117 void _handleGrabbed();
118 bool _handleClicked(Handle *, GdkEventButton *);
119 void _handleUngrabbed();
121 void _externalChange(unsigned type);
122 void _removeNodesFromSelection();
123 void _commit(Glib::ustring const &annotation);
124 void _commit(Glib::ustring const &annotation, gchar const *key);
125 void _updateDragPoint(Geom::Point const &);
126 void _updateOutlineOnZoomChange();
127 double _getStrokeTolerance();
128 Handle *_chooseHandle(Node *n, int which);
130 SubpathList _subpaths;
131 MultiPathManipulator &_multi_path_manipulator;
132 SPPath *_path;
133 SPCurve *_spcurve; // in item coordinates
134 SPCanvasItem *_outline;
135 CurveDragPoint *_dragpoint; // an invisible control point hoverng over curve
136 PathManipulatorObserver *_observer;
137 Geom::Matrix _d2i_transform; ///< desktop-to-item transform
138 Geom::Matrix _i2d_transform; ///< item-to-desktop transform, inverse of _d2i_transform
139 Geom::Matrix _edit_transform; ///< additional transform to apply to editing controls
140 unsigned _num_selected; ///< number of selected nodes
141 bool _show_handles;
142 bool _show_outline;
143 bool _show_path_direction;
144 bool _live_outline;
145 bool _live_objects;
146 Glib::ustring _lpe_key;
148 friend class PathManipulatorObserver;
149 friend class CurveDragPoint;
150 friend class Node;
151 friend class Handle;
152 };
154 } // namespace UI
155 } // namespace Inkscape
157 #endif
159 /*
160 Local Variables:
161 mode:c++
162 c-file-style:"stroustrup"
163 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
164 indent-tabs-mode:nil
165 fill-column:99
166 End:
167 */
168 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :