Code

make win32 compile using libxslt
[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"
20 #include <glibmm/ustring.h>
22 #include <list>
24 class SPDesktop;
25 class SPPath;
26 class SPKnot;
28 namespace Inkscape {
29 namespace XML {
30 class Node;
31 }
32 }
35 /**
36  * Radial objects are represented by an angle and a distance from
37  * 0,0.  0,0 is represented by a == big_num.
38  */
39 class Radial{
40  public:
41 /**  Radius */
42         double r;
43 /**  Amplitude */
44         double a;
45         Radial() {}
46         //      Radial(NR::Point const &p); // Convert a point to radial coordinates
47         Radial(Radial &p) : r(p.r),a(p.a) {}
48         //      operator NR::Point() const;
50 /**
51  * Construct Radial from NR::Point.
52  */
53 Radial(NR::Point const &p)
54 {
55         r = NR::L2(p);
56         if (r > 0) {
57                 a = NR::atan2 (p);
58         } else {
59                 a = HUGE_VAL; //undefined
60         }
61 }
63 /**
64  * Cast Radial to cartesian NR::Point.
65  */
66 operator NR::Point() const
67 {
68         if (a == HUGE_VAL) {
69                 return NR::Point(0,0);
70         } else {
71                 return r*NR::Point(cos(a), sin(a));
72         }
73 }
75 };
77 class ShapeEditor;
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;
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         SPObject * object;
116 /**  The context which created this nodepath.  Important if this nodepath is deleted */
117         ShapeEditor *shape_editor;
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     gchar *repr_key;
128     gchar *repr_nodetypes_key;
129         //STL compliant method to get the selected nodes
130         void selection(std::list<Node *> &l);
132       /// livarot library is used for "point on path" and "nearest position on path", so we need to maintain its path representation as well
133         ::Path *livarot_path;
134     
135     /// draw a "sketch" of the path by using these variables
136     SPCanvasItem *helper_path;
137     SPCurve *curve;
138     bool show_helperpath;
140       /// true if we changed repr, to tell this change from an external one such as from undo, simplify, or another desktop
141         unsigned int local_change;
143         /// true if we're showing selected nodes' handles
144         bool show_handles;
146     /// true if the path cannot contain curves, just straight lines
147     bool straight_path;
149         /// active_node points to the node that is currently mouseovered (= NULL if
150         /// there isn't any); we also consider the node mouseovered if it is covered
151         /// by one of its handles and the latter is mouseovered
152         static Node *active_node;
153 };
156 /**
157  *  This is the lowest list item, a simple list of nodes.
158  */
159 class SubPath {
160  public:
161 /**  The parent of this subpath */
162         Path * nodepath;
163 /**  Is this path closed (no endpoints) or not?*/
164         gboolean closed;
165 /**  The nodes in this subpath. */
166         GList * nodes;
167 /**  The first node of the subpath (does not imply open/closed)*/
168         Node * first;
169 /**  The last node of the subpath */
170         Node * last;
171 };
175 /**
176  *  What kind of node is this?  This is the value for the node->type
177  *  field.  NodeType indicates the degree of continuity required for
178  *  the node.  I think that the corresponding integer indicates which
179  *  derivate is connected. (Thus 2 means that the node is continuous
180  *  to the second derivative, i.e. has matching endpoints and tangents)
181  */
182 typedef enum {
183 /**  A normal node */
184         NODE_NONE,
185 /**  This node non-continuously joins two segments.*/
186         NODE_CUSP,
187 /**  This node continuously joins two segments. */
188         NODE_SMOOTH,
189 /**  This node is symmetric. */
190         NODE_SYMM
191 } NodeType;
195 /**
196  * A NodeSide is a datarecord which may be on either side (n or p) of a node,
197  * which describes the segment going to the next node.
198  */
199 class NodeSide{
200  public:
201 /**  Pointer to the next node, */
202         Node * other;
203 /**  Position */
204         NR::Point pos;
205 /**  Origin (while dragging) in radial notation */
206         Radial origin_radial;
207 /**  Origin (while dragging) in x/y notation */
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 control point in a
211  *  bezier curve.*/
212         SPKnot * knot;
213 /**  What kind of rendering? */
214         SPCanvasItem * line;
215 };
217 /**
218  * A node along a NodePath
219  */
220 class Node {
221  public:
222 /**  The parent subpath of this node */
223         SubPath * subpath;
224 /**  Type is selected from NodeType.*/
225         guint type : 4;
226 /**  Code refers to which ArtCode is used to represent the segment
227  *  (which segment?).*/
228         guint code : 4;
229 /**  Boolean.  Am I currently selected or not? */
230         guint selected : 1;
231 /**  */
232         NR::Point pos;
233 /**  */
234         NR::Point origin;
235 /**  Knots are Inkscape's way of providing draggable points.  This
236  *  Knot is the point on the curve representing the endpoint.*/
237         SPKnot * knot;
238 /**  The NodeSide in the 'next' direction */
239         NodeSide n;
240 /**  The NodeSide in the 'previous' direction */
241         NodeSide p;
243         /** The pointer to the nodeside which we are dragging out with Shift */
244         NodeSide *dragging_out;
245   
246   /** Boolean.  Am I being dragged? */
247   guint is_dragging : 1;
248 };
250 }  // namespace NodePath
251 }  // namespace Inkscape
253 enum {
254   SCULPT_PROFILE_LINEAR,
255   SCULPT_PROFILE_BELL,
256   SCULPT_PROFILE_ELLIPTIC
257 };
259 // Do function documentation in nodepath.cpp
260 Inkscape::NodePath::Path * sp_nodepath_new (SPDesktop * desktop, SPObject *object, bool show_handles, const char * repr_key = NULL);
261 void sp_nodepath_destroy (Inkscape::NodePath::Path * nodepath);
262 void sp_nodepath_ensure_livarot_path(Inkscape::NodePath::Path *np);
263 void sp_nodepath_deselect (Inkscape::NodePath::Path *nodepath);
264 void sp_nodepath_select_all (Inkscape::NodePath::Path *nodepath, bool invert);
265 void sp_nodepath_select_all_from_subpath(Inkscape::NodePath::Path *nodepath, bool invert);
266 void sp_nodepath_select_next (Inkscape::NodePath::Path *nodepath);
267 void sp_nodepath_select_prev (Inkscape::NodePath::Path *nodepath);
268 void sp_nodepath_select_rect (Inkscape::NodePath::Path * nodepath, NR::Rect const &b, gboolean incremental);
269 GList *save_nodepath_selection (Inkscape::NodePath::Path *nodepath);
270 void restore_nodepath_selection (Inkscape::NodePath::Path *nodepath, GList *r);
271 gboolean nodepath_repr_d_changed (Inkscape::NodePath::Path * np, const char *newd);
272 gboolean nodepath_repr_typestr_changed (Inkscape::NodePath::Path * np, const char *newtypestr);
273 gboolean node_key (GdkEvent * event);
274 void sp_nodepath_update_repr(Inkscape::NodePath::Path *np, const gchar *annotation);
275 void sp_nodepath_update_statusbar (Inkscape::NodePath::Path *nodepath);
276 void sp_nodepath_selected_align(Inkscape::NodePath::Path *nodepath, NR::Dim2 axis);
277 void sp_nodepath_selected_distribute(Inkscape::NodePath::Path *nodepath, NR::Dim2 axis);
278 void sp_nodepath_select_segment_near_point(Inkscape::NodePath::Path *nodepath, NR::Point p, bool toggle);
279 void sp_nodepath_add_node_near_point(Inkscape::NodePath::Path *nodepath, NR::Point p);
280 void sp_nodepath_curve_drag(int node, double t, NR::Point delta);
281 Inkscape::NodePath::Node * sp_nodepath_get_node_by_index(int index);
282 /* possibly private functions */
284 void sp_node_selected_add_node (Inkscape::NodePath::Path *nodepath);
285 void sp_node_selected_break (Inkscape::NodePath::Path *nodepath);
286 void sp_node_selected_duplicate (Inkscape::NodePath::Path *nodepath);
287 void sp_node_selected_join (Inkscape::NodePath::Path *nodepath);
288 void sp_node_selected_join_segment (Inkscape::NodePath::Path *nodepath);
289 void sp_node_delete_preserve (GList *nodes_to_delete);
290 void sp_node_selected_delete (Inkscape::NodePath::Path *nodepath);
291 void sp_node_selected_delete_segment (Inkscape::NodePath::Path *nodepath);
292 void sp_node_selected_set_type (Inkscape::NodePath::Path *nodepath, Inkscape::NodePath::NodeType type);
293 void sp_node_selected_set_line_type (Inkscape::NodePath::Path *nodepath, NRPathcode code);
294 void sp_node_selected_move (Inkscape::NodePath::Path *nodepath, gdouble dx, gdouble dy);
295 void sp_node_selected_move_screen (Inkscape::NodePath::Path *nodepath, gdouble dx, gdouble dy);
297 void sp_nodepath_show_handles(Inkscape::NodePath::Path *nodepath, bool show);
299 void sp_nodepath_selected_nodes_rotate (Inkscape::NodePath::Path * nodepath, gdouble angle, int which, bool screen);
301 void sp_nodepath_selected_nodes_scale (Inkscape::NodePath::Path * nodepath, gdouble grow, int which);
302 void sp_nodepath_selected_nodes_scale_screen (Inkscape::NodePath::Path * nodepath, gdouble grow, int which);
304 void sp_nodepath_flip (Inkscape::NodePath::Path *nodepath, NR::Dim2 axis, NR::Maybe<NR::Point> center);
306 #endif