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