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 shiftSelection(int dir);
69 void invertSelectionInSubpaths();
71 void insertNodes();
72 void duplicateNodes();
73 void weldNodes(NodeList::iterator preserve_pos = NodeList::iterator());
74 void weldSegments();
75 void breakNodes();
76 void deleteNodes(bool keep_shape = true);
77 void deleteSegments();
78 void reverseSubpaths(bool selected_only);
79 void setSegmentType(SegmentType);
81 void scaleHandle(Node *n, int which, int dir, bool pixel);
82 void rotateHandle(Node *n, int which, int dir, bool pixel);
84 void showOutline(bool show);
85 void showHandles(bool show);
86 void showPathDirection(bool show);
87 void setLiveOutline(bool set);
88 void setLiveObjects(bool set);
89 void setControlsTransform(Geom::Matrix const &);
90 void hideDragPoint();
91 MultiPathManipulator &mpm() { return _multi_path_manipulator; }
93 NodeList::iterator subdivideSegment(NodeList::iterator after, double t);
94 NodeList::iterator extremeNode(NodeList::iterator origin, bool search_selected,
95 bool search_unselected, bool closest);
97 static bool is_item_type(void *item);
98 private:
99 typedef NodeList Subpath;
100 typedef boost::shared_ptr<NodeList> SubpathPtr;
102 void _createControlPointsFromGeometry();
103 void _createGeometryFromControlPoints();
104 unsigned _deleteStretch(NodeList::iterator first, NodeList::iterator last, bool keep_shape);
105 std::string _createTypeString();
106 void _updateOutline();
107 //void _setOutline(Geom::PathVector const &);
108 void _getGeometry();
109 void _setGeometry();
110 Glib::ustring _nodetypesKey();
111 Inkscape::XML::Node *_getXMLNode();
113 void _selectionChanged(SelectableControlPoint *p, bool selected);
114 bool _nodeClicked(Node *, GdkEventButton *);
115 void _handleGrabbed();
116 bool _handleClicked(Handle *, GdkEventButton *);
117 void _handleUngrabbed();
119 void _externalChange(unsigned type);
120 void _removeNodesFromSelection();
121 void _commit(Glib::ustring const &annotation);
122 void _commit(Glib::ustring const &annotation, gchar const *key);
123 void _updateDragPoint(Geom::Point const &);
124 void _updateOutlineOnZoomChange();
125 double _getStrokeTolerance();
126 Handle *_chooseHandle(Node *n, int which);
128 SubpathList _subpaths;
129 MultiPathManipulator &_multi_path_manipulator;
130 SPPath *_path;
131 SPCurve *_spcurve; // in item coordinates
132 SPCanvasItem *_outline;
133 CurveDragPoint *_dragpoint; // an invisible control point hoverng over curve
134 PathManipulatorObserver *_observer;
135 Geom::Matrix _d2i_transform; ///< desktop-to-item transform
136 Geom::Matrix _i2d_transform; ///< item-to-desktop transform, inverse of _d2i_transform
137 Geom::Matrix _edit_transform; ///< additional transform to apply to editing controls
138 unsigned _num_selected; ///< number of selected nodes
139 bool _show_handles;
140 bool _show_outline;
141 bool _show_path_direction;
142 bool _live_outline;
143 bool _live_objects;
144 Glib::ustring _lpe_key;
146 friend class PathManipulatorObserver;
147 friend class CurveDragPoint;
148 friend class Node;
149 friend class Handle;
150 };
152 } // namespace UI
153 } // namespace Inkscape
155 #endif
157 /*
158 Local Variables:
159 mode:c++
160 c-file-style:"stroustrup"
161 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
162 indent-tabs-mode:nil
163 fill-column:99
164 End:
165 */
166 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :