Code

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