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"
20 #include <list>
22 class SPDesktop;
23 class SPPath;
24 class SPKnot;
26 namespace Inkscape {
27 namespace XML {
28 class Node;
29 }
30 }
33 /**
34 * Radial objects are represented by an angle and a distance from
35 * 0,0. 0,0 is represented by a == big_num.
36 */
37 class Radial{
38 public:
39 /** Radius */
40 double r;
41 /** Amplitude */
42 double a;
43 Radial() {}
44 // Radial(NR::Point const &p); // Convert a point to radial coordinates
45 Radial(Radial &p) : r(p.r),a(p.a) {}
46 // operator NR::Point() const;
48 /**
49 * Construct Radial from NR::Point.
50 */
51 Radial(NR::Point const &p)
52 {
53 r = NR::L2(p);
54 if (r > 0) {
55 a = NR::atan2 (p);
56 } else {
57 a = HUGE_VAL; //undefined
58 }
59 }
61 /**
62 * Cast Radial to cartesian NR::Point.
63 */
64 operator NR::Point() const
65 {
66 if (a == HUGE_VAL) {
67 return NR::Point(0,0);
68 } else {
69 return r*NR::Point(cos(a), sin(a));
70 }
71 }
73 };
75 /** defined in node-context.h */
76 class SPNodeContext;
78 namespace Inkscape {
79 namespace NodePath {
81 /**
82 * This is a node on a subpath
83 */
84 class Path;
86 /**
87 * This is a subdivision of a NodePath
88 */
89 class SubPath;
91 class NodeSide;
93 /**
94 * This is a node (point) along a subpath
95 */
96 class Node;
99 /**
100 * This is a collection of subpaths which contain nodes
101 *
102 * In the following data model. Nodepaths are made up of subpaths which
103 * are comprised of nodes.
104 *
105 * Nodes are linked thus:
106 * \verbatim
107 n other
108 node -----> nodeside ------> node \endverbatim
109 */
110 class Path {
111 public:
112 /** Pointer to the current desktop, for reporting purposes */
113 SPDesktop * desktop;
114 /** The parent path of this nodepath */
115 SPPath * path;
116 /** The context which created this nodepath. Important if this nodepath is deleted */
117 SPNodeContext * nodeContext;
118 /** The subpaths which comprise this NodePath */
119 GList * subpaths;
120 /** A list of nodes which are currently selected */
121 GList * selected;
122 /** Transforms (userspace <---> virtual space? someone please describe )
123 njh: I'd be guessing that these are item <-> desktop transforms.*/
124 NR::Matrix i2d, d2i;
125 /** The DOM node which describes this NodePath */
126 Inkscape::XML::Node *repr;
127 //STL compliant method to get the selected nodes
128 void selection(std::list<Node *> &l);
129 };
132 /**
133 * This is the lowest list item, a simple list of nodes.
134 */
135 class SubPath {
136 public:
137 /** The parent of this subpath */
138 Path * nodepath;
139 /** Is this path closed (no endpoints) or not?*/
140 gboolean closed;
141 /** The nodes in this subpath. */
142 GList * nodes;
143 /** The first node of the subpath (does not imply open/closed)*/
144 Node * first;
145 /** The last node of the subpath */
146 Node * last;
147 };
151 /**
152 * What kind of node is this? This is the value for the node->type
153 * field. NodeType indicates the degree of continuity required for
154 * the node. I think that the corresponding integer indicates which
155 * derivate is connected. (Thus 2 means that the node is continuous
156 * to the second derivative, i.e. has matching endpoints and tangents)
157 */
158 typedef enum {
159 /** A normal node */
160 NODE_NONE,
161 /** This node non-continuously joins two segments.*/
162 NODE_CUSP,
163 /** This node continuously joins two segments. */
164 NODE_SMOOTH,
165 /** This node is symmetric. */
166 NODE_SYMM
167 } NodeType;
171 /**
172 * A NodeSide is a datarecord which may be on either side (n or p) of a node,
173 * which describes the segment going to the next node.
174 */
175 class NodeSide{
176 public:
177 /** Pointer to the next node, */
178 Node * other;
179 /** Position */
180 NR::Point pos;
181 /** Knots are Inkscape's way of providing draggable points. This
182 * Knot is the point on the curve representing the control point in a
183 * bezier curve.*/
184 SPKnot * knot;
185 /** What kind of rendering? */
186 SPCanvasItem * line;
187 /** */
188 Radial origin;
189 };
191 /**
192 * A node along a NodePath
193 */
194 class Node {
195 public:
196 /** The parent subpath of this node */
197 SubPath * subpath;
198 /** Type is selected from NodeType.*/
199 guint type : 4;
200 /** Code refers to which ArtCode is used to represent the segment
201 * (which segment?).*/
202 guint code : 4;
203 /** Boolean. Am I currently selected or not? */
204 guint selected : 1;
205 /** */
206 NR::Point pos;
207 /** */
208 NR::Point origin;
209 /** Knots are Inkscape's way of providing draggable points. This
210 * Knot is the point on the curve representing the endpoint.*/
211 SPKnot * knot;
212 /** The NodeSide in the 'next' direction */
213 NodeSide n;
214 /** The NodeSide in the 'previous' direction */
215 NodeSide p;
217 /** The pointer to the nodeside which we are dragging out with Shift */
218 NodeSide *dragging_out;
219 };
221 } // namespace NodePath
222 } // namespace Inkscape
224 // Do function documentation in nodepath.cpp
225 Inkscape::NodePath::Path * sp_nodepath_new (SPDesktop * desktop, SPItem * item);
226 void sp_nodepath_destroy (Inkscape::NodePath::Path * nodepath);
227 void sp_nodepath_deselect (Inkscape::NodePath::Path *nodepath);
228 void sp_nodepath_select_all (Inkscape::NodePath::Path *nodepath, bool invert);
229 void sp_nodepath_select_all_from_subpath(Inkscape::NodePath::Path *nodepath, bool invert);
230 void sp_nodepath_select_next (Inkscape::NodePath::Path *nodepath);
231 void sp_nodepath_select_prev (Inkscape::NodePath::Path *nodepath);
232 void sp_nodepath_select_rect (Inkscape::NodePath::Path * nodepath, NR::Rect const &b, gboolean incremental);
233 GList *save_nodepath_selection (Inkscape::NodePath::Path *nodepath);
234 void restore_nodepath_selection (Inkscape::NodePath::Path *nodepath, GList *r);
235 gboolean nodepath_repr_d_changed (Inkscape::NodePath::Path * np, const char *newd);
236 gboolean nodepath_repr_typestr_changed (Inkscape::NodePath::Path * np, const char *newtypestr);
237 gboolean node_key (GdkEvent * event);
238 void sp_nodepath_update_statusbar (Inkscape::NodePath::Path *nodepath);
239 void sp_nodepath_selected_align(Inkscape::NodePath::Path *nodepath, NR::Dim2 axis);
240 void sp_nodepath_selected_distribute(Inkscape::NodePath::Path *nodepath, NR::Dim2 axis);
241 void sp_nodepath_select_segment_near_point(SPItem * item, NR::Point p, bool toggle);
242 void sp_nodepath_add_node_near_point(SPItem * item, NR::Point p);
243 void sp_nodepath_curve_drag(Inkscape::NodePath::Node * e, double t, NR::Point delta, char * key);
244 Inkscape::NodePath::Node * sp_nodepath_get_node_by_index(int index);
245 /* possibly private functions */
247 void sp_node_selected_add_node (void);
248 void sp_node_selected_break (void);
249 void sp_node_selected_duplicate (void);
250 void sp_node_selected_join (void);
251 void sp_node_selected_join_segment (void);
252 void sp_node_selected_delete (void);
253 void sp_node_selected_delete_segment (void);
254 void sp_node_selected_set_type (Inkscape::NodePath::NodeType type);
255 void sp_node_selected_set_line_type (NRPathcode code);
256 void sp_node_selected_move (gdouble dx, gdouble dy);
257 void sp_node_selected_move_screen (gdouble dx, gdouble dy);
259 void sp_nodepath_selected_nodes_rotate (Inkscape::NodePath::Path * nodepath, gdouble angle, int which, bool screen);
261 void sp_nodepath_selected_nodes_scale (Inkscape::NodePath::Path * nodepath, gdouble grow, int which);
262 void sp_nodepath_selected_nodes_scale_screen (Inkscape::NodePath::Path * nodepath, gdouble grow, int which);
264 void sp_nodepath_flip (Inkscape::NodePath::Path *nodepath, NR::Dim2 axis);
266 #endif