ee828f4aca4d245a4a955c6b45e77c607b1f1de6
1 #ifndef __SP_NODEPATH_H__
2 #define __SP_NODEPATH_H__
4 /** \file
5 * Path handler in node edit mode
6 */
8 /*
9 * Authors:
10 * Lauris Kaplinski <lauris@kaplinski.com>
11 *
12 * This code is in public domain
13 */
15 //#include "knot.h"
16 //#include "sp-path.h"
17 //#include "desktop-handles.h"
18 #include "libnr/nr-path-code.h"
19 #include "livarot/Path.h"
20 #include <glibmm/ustring.h>
22 #include <list>
24 class SPObject;
25 class SPDesktop;
26 class SPPath;
27 class SPKnot;
28 class LivePathEffectObject;
30 namespace Inkscape {
31 namespace XML {
32 class Node;
33 }
34 }
37 /**
38 * Radial objects are represented by an angle and a distance from
39 * 0,0. 0,0 is represented by a == big_num.
40 */
41 class Radial{
42 public:
43 /** Radius */
44 double r;
45 /** Amplitude */
46 double a;
47 Radial() {}
48 // Radial(NR::Point const &p); // Convert a point to radial coordinates
49 Radial(Radial &p) : r(p.r),a(p.a) {}
50 // operator NR::Point() const;
52 /**
53 * Construct Radial from NR::Point.
54 */
55 Radial(NR::Point const &p)
56 {
57 r = NR::L2(p);
58 if (r > 0) {
59 a = NR::atan2 (p);
60 } else {
61 a = HUGE_VAL; //undefined
62 }
63 }
65 /**
66 * Cast Radial to cartesian NR::Point.
67 */
68 operator NR::Point() const
69 {
70 if (a == HUGE_VAL) {
71 return NR::Point(0,0);
72 } else {
73 return r*NR::Point(cos(a), sin(a));
74 }
75 }
77 };
79 class ShapeEditor;
81 namespace Inkscape {
82 namespace NodePath {
84 /**
85 * This is a node on a subpath
86 */
87 class Path;
89 /**
90 * This is a subdivision of a NodePath
91 */
92 class SubPath;
94 class NodeSide;
96 /**
97 * This is a node (point) along a subpath
98 */
99 class Node;
102 /**
103 * This is the lowest list item, a simple list of nodes.
104 */
105 class SubPath {
106 public:
107 /** The parent of this subpath */
108 Path * nodepath;
109 /** Is this path closed (no endpoints) or not?*/
110 gboolean closed;
111 /** The nodes in this subpath. */
112 GList * nodes;
113 /** The first node of the subpath (does not imply open/closed)*/
114 Node * first;
115 /** The last node of the subpath */
116 Node * last;
117 };
121 /**
122 * What kind of node is this? This is the value for the node->type
123 * field. NodeType indicates the degree of continuity required for
124 * the node. I think that the corresponding integer indicates which
125 * derivate is connected. (Thus 2 means that the node is continuous
126 * to the second derivative, i.e. has matching endpoints and tangents)
127 */
128 typedef enum {
129 /** A normal node */
130 NODE_NONE,
131 /** This node non-continuously joins two segments.*/
132 NODE_CUSP,
133 /** This node continuously joins two segments. */
134 NODE_SMOOTH,
135 /** This node is symmetric. */
136 NODE_SYMM
137 } NodeType;
141 /**
142 * A NodeSide is a datarecord which may be on either side (n or p) of a node,
143 * which describes the segment going to the next node.
144 */
145 class NodeSide{
146 public:
147 /** Pointer to the next node, */
148 Node * other;
149 /** Position */
150 NR::Point pos;
151 /** Origin (while dragging) in radial notation */
152 Radial origin_radial;
153 /** Origin (while dragging) in x/y notation */
154 NR::Point origin;
155 /** Knots are Inkscape's way of providing draggable points. This
156 * Knot is the point on the curve representing the control point in a
157 * bezier curve.*/
158 SPKnot * knot;
159 /** What kind of rendering? */
160 SPCanvasItem * line;
161 };
163 /**
164 * A node along a NodePath
165 */
166 class Node {
167 public:
168 /** The parent subpath of this node */
169 SubPath * subpath;
170 /** Type is selected from NodeType.*/
171 guint type : 4;
172 /** Code refers to which ArtCode is used to represent the segment
173 * (which segment?).*/
174 guint code : 4;
175 /** Boolean. Am I currently selected or not? */
176 guint selected : 1;
177 /** */
178 NR::Point pos;
179 /** */
180 NR::Point origin;
181 /** Knots are Inkscape's way of providing draggable points. This
182 * Knot is the point on the curve representing the endpoint.*/
183 SPKnot * knot;
184 /** The NodeSide in the 'next' direction */
185 NodeSide n;
186 /** The NodeSide in the 'previous' direction */
187 NodeSide p;
189 /** The pointer to the nodeside which we are dragging out with Shift */
190 NodeSide *dragging_out;
192 /** Boolean. Am I being dragged? */
193 guint is_dragging : 1;
194 };
196 /**
197 * This is a collection of subpaths which contain nodes
198 *
199 * In the following data model. Nodepaths are made up of subpaths which
200 * are comprised of nodes.
201 *
202 * Nodes are linked thus:
203 * \verbatim
204 n other
205 node -----> nodeside ------> node \endverbatim
206 */
207 class Path {
208 public:
209 /** Pointer to the current desktop, for reporting purposes */
210 SPDesktop * desktop;
211 /** The parent path of this nodepath */
212 SPObject * object;
213 /** The parent livepatheffect of this nodepath, if applicable */
214 SPItem * item;
215 /** The context which created this nodepath. Important if this nodepath is deleted */
216 ShapeEditor *shape_editor;
217 /** The subpaths which comprise this NodePath */
218 GList * subpaths;
219 /** A list of nodes which are currently selected */
220 GList * selected;
221 /** Transforms (userspace <---> virtual space? someone please describe )
222 njh: I'd be guessing that these are item <-> desktop transforms.*/
223 NR::Matrix i2d, d2i;
224 /** The DOM node which describes this NodePath */
225 Inkscape::XML::Node *repr;
226 gchar *repr_key;
227 gchar *repr_nodetypes_key;
228 //STL compliant method to get the selected nodes
229 void selection(std::list<Node *> &l);
231 guint numSelected() {return (selected? g_list_length(selected) : 0);}
232 NR::Point& singleSelectedCoords() {return (((Node *) selected->data)->pos);}
234 /// livarot library is used for "point on path" and "nearest position on path", so we need to maintain its path representation as well
235 ::Path *livarot_path;
237 /// draw a "sketch" of the path by using these variables
238 SPCanvasItem *helper_path;
239 SPCurve *curve;
240 bool show_helperpath;
241 guint32 helperpath_rgba;
242 gdouble helperpath_width;
244 /// true if we changed repr, to tell this change from an external one such as from undo, simplify, or another desktop
245 unsigned int local_change;
247 /// true if we're showing selected nodes' handles
248 bool show_handles;
250 /// true if the path cannot contain curves, just straight lines
251 bool straight_path;
253 /// active_node points to the node that is currently mouseovered (= NULL if
254 /// there isn't any); we also consider the node mouseovered if it is covered
255 /// by one of its handles and the latter is mouseovered
256 static Node *active_node;
257 };
259 } // namespace NodePath
260 } // namespace Inkscape
262 enum {
263 SCULPT_PROFILE_LINEAR,
264 SCULPT_PROFILE_BELL,
265 SCULPT_PROFILE_ELLIPTIC
266 };
268 // Do function documentation in nodepath.cpp
269 Inkscape::NodePath::Path * sp_nodepath_new (SPDesktop * desktop, SPObject *object, bool show_handles, const char * repr_key = NULL, SPItem *item = NULL);
270 void sp_nodepath_destroy (Inkscape::NodePath::Path * nodepath);
271 void sp_nodepath_ensure_livarot_path(Inkscape::NodePath::Path *np);
272 void sp_nodepath_deselect (Inkscape::NodePath::Path *nodepath);
273 void sp_nodepath_select_all (Inkscape::NodePath::Path *nodepath, bool invert);
274 void sp_nodepath_select_all_from_subpath(Inkscape::NodePath::Path *nodepath, bool invert);
275 void sp_nodepath_select_next (Inkscape::NodePath::Path *nodepath);
276 void sp_nodepath_select_prev (Inkscape::NodePath::Path *nodepath);
277 void sp_nodepath_select_rect (Inkscape::NodePath::Path * nodepath, NR::Rect const &b, gboolean incremental);
278 GList *save_nodepath_selection (Inkscape::NodePath::Path *nodepath);
279 void restore_nodepath_selection (Inkscape::NodePath::Path *nodepath, GList *r);
280 gboolean nodepath_repr_d_changed (Inkscape::NodePath::Path * np, const char *newd);
281 gboolean nodepath_repr_typestr_changed (Inkscape::NodePath::Path * np, const char *newtypestr);
282 gboolean node_key (GdkEvent * event);
283 void sp_nodepath_update_repr(Inkscape::NodePath::Path *np, const gchar *annotation);
284 void sp_nodepath_update_statusbar (Inkscape::NodePath::Path *nodepath);
285 void sp_nodepath_selected_align(Inkscape::NodePath::Path *nodepath, NR::Dim2 axis);
286 void sp_nodepath_selected_distribute(Inkscape::NodePath::Path *nodepath, NR::Dim2 axis);
287 void sp_nodepath_select_segment_near_point(Inkscape::NodePath::Path *nodepath, NR::Point p, bool toggle);
288 void sp_nodepath_add_node_near_point(Inkscape::NodePath::Path *nodepath, NR::Point p);
289 void sp_nodepath_curve_drag(int node, double t, NR::Point delta);
290 Inkscape::NodePath::Node * sp_nodepath_get_node_by_index(int index);
291 /* possibly private functions */
293 void sp_node_selected_add_node (Inkscape::NodePath::Path *nodepath);
294 void sp_node_selected_break (Inkscape::NodePath::Path *nodepath);
295 void sp_node_selected_duplicate (Inkscape::NodePath::Path *nodepath);
296 void sp_node_selected_join (Inkscape::NodePath::Path *nodepath);
297 void sp_node_selected_join_segment (Inkscape::NodePath::Path *nodepath);
298 void sp_node_delete_preserve (GList *nodes_to_delete);
299 void sp_node_selected_delete (Inkscape::NodePath::Path *nodepath);
300 void sp_node_selected_delete_segment (Inkscape::NodePath::Path *nodepath);
301 void sp_node_selected_set_type (Inkscape::NodePath::Path *nodepath, Inkscape::NodePath::NodeType type);
302 void sp_node_selected_set_line_type (Inkscape::NodePath::Path *nodepath, NRPathcode code);
303 void sp_node_selected_move (Inkscape::NodePath::Path *nodepath, gdouble dx, gdouble dy);
304 void sp_node_selected_move_screen (Inkscape::NodePath::Path *nodepath, gdouble dx, gdouble dy);
306 void sp_nodepath_show_handles(Inkscape::NodePath::Path *nodepath, bool show);
308 void sp_nodepath_selected_nodes_rotate (Inkscape::NodePath::Path * nodepath, gdouble angle, int which, bool screen);
310 void sp_nodepath_selected_nodes_scale (Inkscape::NodePath::Path * nodepath, gdouble grow, int which);
311 void sp_nodepath_selected_nodes_scale_screen (Inkscape::NodePath::Path * nodepath, gdouble grow, int which);
313 void sp_nodepath_flip (Inkscape::NodePath::Path *nodepath, NR::Dim2 axis, NR::Maybe<NR::Point> center);
315 #endif