Code

b675863d50d24d9903c0978fd454b8f23d44e3ab
[inkscape.git] / src / nodepath.h
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"
21 #include <list>
23 class SPDesktop;
24 class SPPath;
25 class SPKnot;
27 namespace Inkscape {
28 namespace XML {
29 class Node;
30 }
31 }
34 /**
35  * Radial objects are represented by an angle and a distance from
36  * 0,0.  0,0 is represented by a == big_num.
37  */
38 class Radial{
39  public:
40 /**  Radius */
41         double r;
42 /**  Amplitude */
43         double a;
44         Radial() {}
45         //      Radial(NR::Point const &p); // Convert a point to radial coordinates
46         Radial(Radial &p) : r(p.r),a(p.a) {}
47         //      operator NR::Point() const;
49 /**
50  * Construct Radial from NR::Point.
51  */
52 Radial(NR::Point const &p)
53 {
54         r = NR::L2(p);
55         if (r > 0) {
56                 a = NR::atan2 (p);
57         } else {
58                 a = HUGE_VAL; //undefined
59         }
60 }
62 /**
63  * Cast Radial to cartesian NR::Point.
64  */
65 operator NR::Point() const
66 {
67         if (a == HUGE_VAL) {
68                 return NR::Point(0,0);
69         } else {
70                 return r*NR::Point(cos(a), sin(a));
71         }
72 }
74 };
76 /** defined in node-context.h */
77 class SPNodeContext;
79 namespace Inkscape {
80 namespace NodePath {
82 /**
83  * This is a node on a subpath
84  */
85 class Path;
87 /**
88  * This is a subdivision of a NodePath
89  */
90 class SubPath;
92 class NodeSide;
94 /**
95  * This is a node (point) along a subpath
96  */
97 class Node;
100 /**
101  *  This is a collection of subpaths which contain nodes
102  *
103  * In the following data model.   Nodepaths are made up of subpaths which
104  * are comprised of nodes.
105  *
106  * Nodes are linked thus:
107  * \verbatim
108            n              other
109     node -----> nodeside ------> node            \endverbatim
110  */
111 class Path {
112  public:
113 /**  Pointer to the current desktop, for reporting purposes */
114         SPDesktop * desktop;
115 /**  The parent path of this nodepath */
116         SPPath * path;
117 /**  The context which created this nodepath.  Important if this nodepath is deleted */
118         SPNodeContext * nodeContext;
119 /**  The subpaths which comprise this NodePath */
120         GList * subpaths;
121 /**  A list of nodes which are currently selected */
122         GList * selected;
123 /**  Transforms (userspace <---> virtual space?   someone please describe )
124          njh: I'd be guessing that these are item <-> desktop transforms.*/
125         NR::Matrix i2d, d2i;
126 /**  The DOM node which describes this NodePath */
127         Inkscape::XML::Node *repr;
128         //STL compliant method to get the selected nodes
129         void selection(std::list<Node *> &l);
131       /// livarot library is used for "point on path" and "nearest position on path", so we need to maintain its path representation as well
132         ::Path *livarot_path;
134       /// true if we changed repr, to tell this change from an external one such as from undo, simplify, or another desktop
135         unsigned int local_change;
137         /// true if we're showing selected nodes' handles
138         bool show_handles;
139 };
142 /**
143  *  This is the lowest list item, a simple list of nodes.
144  */
145 class SubPath {
146  public:
147 /**  The parent of this subpath */
148         Path * nodepath;
149 /**  Is this path closed (no endpoints) or not?*/
150         gboolean closed;
151 /**  The nodes in this subpath. */
152         GList * nodes;
153 /**  The first node of the subpath (does not imply open/closed)*/
154         Node * first;
155 /**  The last node of the subpath */
156         Node * last;
157 };
161 /**
162  *  What kind of node is this?  This is the value for the node->type
163  *  field.  NodeType indicates the degree of continuity required for
164  *  the node.  I think that the corresponding integer indicates which
165  *  derivate is connected. (Thus 2 means that the node is continuous
166  *  to the second derivative, i.e. has matching endpoints and tangents)
167  */
168 typedef enum {
169 /**  A normal node */
170         NODE_NONE,
171 /**  This node non-continuously joins two segments.*/
172         NODE_CUSP,
173 /**  This node continuously joins two segments. */
174         NODE_SMOOTH,
175 /**  This node is symmetric. */
176         NODE_SYMM
177 } NodeType;
181 /**
182  * A NodeSide is a datarecord which may be on either side (n or p) of a node,
183  * which describes the segment going to the next node.
184  */
185 class NodeSide{
186  public:
187 /**  Pointer to the next node, */
188         Node * other;
189 /**  Position */
190         NR::Point pos;
191 /**  Origin (while dragging) in radial notation */
192         Radial origin_radial;
193 /**  Origin (while dragging) in x/y notation */
194         NR::Point origin;
195 /**  Knots are Inkscape's way of providing draggable points.  This
196  *  Knot is the point on the curve representing the control point in a
197  *  bezier curve.*/
198         SPKnot * knot;
199 /**  What kind of rendering? */
200         SPCanvasItem * line;
201 };
203 /**
204  * A node along a NodePath
205  */
206 class Node {
207  public:
208 /**  The parent subpath of this node */
209         SubPath * subpath;
210 /**  Type is selected from NodeType.*/
211         guint type : 4;
212 /**  Code refers to which ArtCode is used to represent the segment
213  *  (which segment?).*/
214         guint code : 4;
215 /**  Boolean.  Am I currently selected or not? */
216         guint selected : 1;
217 /**  */
218         NR::Point pos;
219 /**  */
220         NR::Point origin;
221 /**  Knots are Inkscape's way of providing draggable points.  This
222  *  Knot is the point on the curve representing the endpoint.*/
223         SPKnot * knot;
224 /**  The NodeSide in the 'next' direction */
225         NodeSide n;
226 /**  The NodeSide in the 'previous' direction */
227         NodeSide p;
229         /** The pointer to the nodeside which we are dragging out with Shift */
230         NodeSide *dragging_out;
231   
232   /** Boolean.  Am I being dragged? */
233   guint is_dragging : 1;
234 };
236 }  // namespace NodePath
237 }  // namespace Inkscape
239 enum {
240   SCULPT_PROFILE_LINEAR,
241   SCULPT_PROFILE_BELL,
242   SCULPT_PROFILE_ELLIPTIC
243 };
245 // Do function documentation in nodepath.cpp
246 Inkscape::NodePath::Path * sp_nodepath_new (SPDesktop * desktop, SPItem * item, bool show_handles);
247 void sp_nodepath_destroy (Inkscape::NodePath::Path * nodepath);
248 void sp_nodepath_ensure_livarot_path(Inkscape::NodePath::Path *np);
249 void sp_nodepath_deselect (Inkscape::NodePath::Path *nodepath);
250 void sp_nodepath_select_all (Inkscape::NodePath::Path *nodepath, bool invert);
251 void sp_nodepath_select_all_from_subpath(Inkscape::NodePath::Path *nodepath, bool invert);
252 void sp_nodepath_select_next (Inkscape::NodePath::Path *nodepath);
253 void sp_nodepath_select_prev (Inkscape::NodePath::Path *nodepath);
254 void sp_nodepath_select_rect (Inkscape::NodePath::Path * nodepath, NR::Rect const &b, gboolean incremental);
255 GList *save_nodepath_selection (Inkscape::NodePath::Path *nodepath);
256 void restore_nodepath_selection (Inkscape::NodePath::Path *nodepath, GList *r);
257 gboolean nodepath_repr_d_changed (Inkscape::NodePath::Path * np, const char *newd);
258 gboolean nodepath_repr_typestr_changed (Inkscape::NodePath::Path * np, const char *newtypestr);
259 gboolean node_key (GdkEvent * event);
260 void sp_nodepath_update_repr(Inkscape::NodePath::Path *np, const gchar *annotation);
261 void sp_nodepath_update_statusbar (Inkscape::NodePath::Path *nodepath);
262 void sp_nodepath_selected_align(Inkscape::NodePath::Path *nodepath, NR::Dim2 axis);
263 void sp_nodepath_selected_distribute(Inkscape::NodePath::Path *nodepath, NR::Dim2 axis);
264 void sp_nodepath_select_segment_near_point(Inkscape::NodePath::Path *nodepath, NR::Point p, bool toggle);
265 void sp_nodepath_add_node_near_point(Inkscape::NodePath::Path *nodepath, NR::Point p);
266 void sp_nodepath_curve_drag(int node, double t, NR::Point delta);
267 Inkscape::NodePath::Node * sp_nodepath_get_node_by_index(int index);
268 /* possibly private functions */
270 void sp_node_selected_add_node (void);
271 void sp_node_selected_break (void);
272 void sp_node_selected_duplicate (void);
273 void sp_node_selected_join (void);
274 void sp_node_selected_join_segment (void);
275 void sp_node_delete_preserve (GList *nodes_to_delete);
276 void sp_node_selected_delete (void);
277 void sp_node_selected_delete_segment (void);
278 void sp_node_selected_set_type (Inkscape::NodePath::NodeType type);
279 void sp_node_selected_set_line_type (NRPathcode code);
280 void sp_node_selected_move (gdouble dx, gdouble dy);
281 void sp_node_selected_move_screen (gdouble dx, gdouble dy);
283 void sp_nodepath_show_handles(bool show);
285 void sp_nodepath_selected_nodes_rotate (Inkscape::NodePath::Path * nodepath, gdouble angle, int which, bool screen);
287 void sp_nodepath_selected_nodes_scale (Inkscape::NodePath::Path * nodepath, gdouble grow, int which);
288 void sp_nodepath_selected_nodes_scale_screen (Inkscape::NodePath::Path * nodepath, gdouble grow, int which);
290 void sp_nodepath_flip (Inkscape::NodePath::Path *nodepath, NR::Dim2 axis);
292 #endif