Code

Remove warnings
[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;
136 };
139 /**
140  *  This is the lowest list item, a simple list of nodes.
141  */
142 class SubPath {
143  public:
144 /**  The parent of this subpath */
145         Path * nodepath;
146 /**  Is this path closed (no endpoints) or not?*/
147         gboolean closed;
148 /**  The nodes in this subpath. */
149         GList * nodes;
150 /**  The first node of the subpath (does not imply open/closed)*/
151         Node * first;
152 /**  The last node of the subpath */
153         Node * last;
154 };
158 /**
159  *  What kind of node is this?  This is the value for the node->type
160  *  field.  NodeType indicates the degree of continuity required for
161  *  the node.  I think that the corresponding integer indicates which
162  *  derivate is connected. (Thus 2 means that the node is continuous
163  *  to the second derivative, i.e. has matching endpoints and tangents)
164  */
165 typedef enum {
166 /**  A normal node */
167         NODE_NONE,
168 /**  This node non-continuously joins two segments.*/
169         NODE_CUSP,
170 /**  This node continuously joins two segments. */
171         NODE_SMOOTH,
172 /**  This node is symmetric. */
173         NODE_SYMM
174 } NodeType;
178 /**
179  * A NodeSide is a datarecord which may be on either side (n or p) of a node,
180  * which describes the segment going to the next node.
181  */
182 class NodeSide{
183  public:
184 /**  Pointer to the next node, */
185         Node * other;
186 /**  Position */
187         NR::Point pos;
188 /**  Knots are Inkscape's way of providing draggable points.  This
189  *  Knot is the point on the curve representing the control point in a
190  *  bezier curve.*/
191         SPKnot * knot;
192 /**  What kind of rendering? */
193         SPCanvasItem * line;
194 /**  */
195         Radial origin;
196 };
198 /**
199  * A node along a NodePath
200  */
201 class Node {
202  public:
203 /**  The parent subpath of this node */
204         SubPath * subpath;
205 /**  Type is selected from NodeType.*/
206         guint type : 4;
207 /**  Code refers to which ArtCode is used to represent the segment
208  *  (which segment?).*/
209         guint code : 4;
210 /**  Boolean.  Am I currently selected or not? */
211         guint selected : 1;
212 /**  */
213         NR::Point pos;
214 /**  */
215         NR::Point origin;
216 /**  Knots are Inkscape's way of providing draggable points.  This
217  *  Knot is the point on the curve representing the endpoint.*/
218         SPKnot * knot;
219 /**  The NodeSide in the 'next' direction */
220         NodeSide n;
221 /**  The NodeSide in the 'previous' direction */
222         NodeSide p;
224         /** The pointer to the nodeside which we are dragging out with Shift */
225         NodeSide *dragging_out;
226 };
228 }  // namespace NodePath
229 }  // namespace Inkscape
231 // Do function documentation in nodepath.cpp
232 Inkscape::NodePath::Path * sp_nodepath_new (SPDesktop * desktop, SPItem * item);
233 void sp_nodepath_destroy (Inkscape::NodePath::Path * nodepath);
234 void sp_nodepath_deselect (Inkscape::NodePath::Path *nodepath);
235 void sp_nodepath_select_all (Inkscape::NodePath::Path *nodepath, bool invert);
236 void sp_nodepath_select_all_from_subpath(Inkscape::NodePath::Path *nodepath, bool invert);
237 void sp_nodepath_select_next (Inkscape::NodePath::Path *nodepath);
238 void sp_nodepath_select_prev (Inkscape::NodePath::Path *nodepath);
239 void sp_nodepath_select_rect (Inkscape::NodePath::Path * nodepath, NR::Rect const &b, gboolean incremental);
240 GList *save_nodepath_selection (Inkscape::NodePath::Path *nodepath);
241 void restore_nodepath_selection (Inkscape::NodePath::Path *nodepath, GList *r);
242 gboolean nodepath_repr_d_changed (Inkscape::NodePath::Path * np, const char *newd);
243 gboolean nodepath_repr_typestr_changed (Inkscape::NodePath::Path * np, const char *newtypestr);
244 gboolean node_key (GdkEvent * event);
245 void sp_nodepath_update_repr(Inkscape::NodePath::Path *np);
246 void sp_nodepath_update_statusbar (Inkscape::NodePath::Path *nodepath);
247 void sp_nodepath_selected_align(Inkscape::NodePath::Path *nodepath, NR::Dim2 axis);
248 void sp_nodepath_selected_distribute(Inkscape::NodePath::Path *nodepath, NR::Dim2 axis);
249 void sp_nodepath_select_segment_near_point(Inkscape::NodePath::Path *nodepath, NR::Point p, bool toggle);
250 void sp_nodepath_add_node_near_point(Inkscape::NodePath::Path *nodepath, NR::Point p);
251 void sp_nodepath_curve_drag(Inkscape::NodePath::Node * e, double t, NR::Point delta);
252 Inkscape::NodePath::Node * sp_nodepath_get_node_by_index(int index);
253 /* possibly private functions */
255 void sp_node_selected_add_node (void);
256 void sp_node_selected_break (void);
257 void sp_node_selected_duplicate (void);
258 void sp_node_selected_join (void);
259 void sp_node_selected_join_segment (void);
260 void sp_node_selected_delete (void);
261 void sp_node_selected_delete_segment (void);
262 void sp_node_selected_set_type (Inkscape::NodePath::NodeType type);
263 void sp_node_selected_set_line_type (NRPathcode code);
264 void sp_node_selected_move (gdouble dx, gdouble dy);
265 void sp_node_selected_move_screen (gdouble dx, gdouble dy);
267 void sp_nodepath_selected_nodes_rotate (Inkscape::NodePath::Path * nodepath, gdouble angle, int which, bool screen);
269 void sp_nodepath_selected_nodes_scale (Inkscape::NodePath::Path * nodepath, gdouble grow, int which);
270 void sp_nodepath_selected_nodes_scale_screen (Inkscape::NodePath::Path * nodepath, gdouble grow, int which);
272 void sp_nodepath_flip (Inkscape::NodePath::Path *nodepath, NR::Dim2 axis);
274 #endif