Code

fixed fixme's in shapeeditor and changed verbs for node editting. helps with multiple...
[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 class ShapeEditor;
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;
98 /**
99  *  This is a collection of subpaths which contain nodes
100  *
101  * In the following data model.   Nodepaths are made up of subpaths which
102  * are comprised of nodes.
103  *
104  * Nodes are linked thus:
105  * \verbatim
106            n              other
107     node -----> nodeside ------> node            \endverbatim
108  */
109 class Path {
110  public:
111 /**  Pointer to the current desktop, for reporting purposes */
112         SPDesktop * desktop;
113 /**  The parent path of this nodepath */
114         SPPath * path;
115 /**  The context which created this nodepath.  Important if this nodepath is deleted */
116         ShapeEditor *shape_editor;
117 /**  The subpaths which comprise this NodePath */
118         GList * subpaths;
119 /**  A list of nodes which are currently selected */
120         GList * selected;
121 /**  Transforms (userspace <---> virtual space?   someone please describe )
122          njh: I'd be guessing that these are item <-> desktop transforms.*/
123         NR::Matrix i2d, d2i;
124 /**  The DOM node which describes this NodePath */
125         Inkscape::XML::Node *repr;
126         //STL compliant method to get the selected nodes
127         void selection(std::list<Node *> &l);
129       /// livarot library is used for "point on path" and "nearest position on path", so we need to maintain its path representation as well
130         ::Path *livarot_path;
132       /// true if we changed repr, to tell this change from an external one such as from undo, simplify, or another desktop
133         unsigned int local_change;
135         /// true if we're showing selected nodes' handles
136         bool show_handles;
138         /// active_node points to the node that is currently mouseovered (= NULL if
139         /// there isn't any); we also consider the node mouseovered if it is covered
140         /// by one of its handles and the latter is mouseovered
141         static Node *active_node;
142 };
145 /**
146  *  This is the lowest list item, a simple list of nodes.
147  */
148 class SubPath {
149  public:
150 /**  The parent of this subpath */
151         Path * nodepath;
152 /**  Is this path closed (no endpoints) or not?*/
153         gboolean closed;
154 /**  The nodes in this subpath. */
155         GList * nodes;
156 /**  The first node of the subpath (does not imply open/closed)*/
157         Node * first;
158 /**  The last node of the subpath */
159         Node * last;
160 };
164 /**
165  *  What kind of node is this?  This is the value for the node->type
166  *  field.  NodeType indicates the degree of continuity required for
167  *  the node.  I think that the corresponding integer indicates which
168  *  derivate is connected. (Thus 2 means that the node is continuous
169  *  to the second derivative, i.e. has matching endpoints and tangents)
170  */
171 typedef enum {
172 /**  A normal node */
173         NODE_NONE,
174 /**  This node non-continuously joins two segments.*/
175         NODE_CUSP,
176 /**  This node continuously joins two segments. */
177         NODE_SMOOTH,
178 /**  This node is symmetric. */
179         NODE_SYMM
180 } NodeType;
184 /**
185  * A NodeSide is a datarecord which may be on either side (n or p) of a node,
186  * which describes the segment going to the next node.
187  */
188 class NodeSide{
189  public:
190 /**  Pointer to the next node, */
191         Node * other;
192 /**  Position */
193         NR::Point pos;
194 /**  Origin (while dragging) in radial notation */
195         Radial origin_radial;
196 /**  Origin (while dragging) in x/y notation */
197         NR::Point origin;
198 /**  Knots are Inkscape's way of providing draggable points.  This
199  *  Knot is the point on the curve representing the control point in a
200  *  bezier curve.*/
201         SPKnot * knot;
202 /**  What kind of rendering? */
203         SPCanvasItem * line;
204 };
206 /**
207  * A node along a NodePath
208  */
209 class Node {
210  public:
211 /**  The parent subpath of this node */
212         SubPath * subpath;
213 /**  Type is selected from NodeType.*/
214         guint type : 4;
215 /**  Code refers to which ArtCode is used to represent the segment
216  *  (which segment?).*/
217         guint code : 4;
218 /**  Boolean.  Am I currently selected or not? */
219         guint selected : 1;
220 /**  */
221         NR::Point pos;
222 /**  */
223         NR::Point origin;
224 /**  Knots are Inkscape's way of providing draggable points.  This
225  *  Knot is the point on the curve representing the endpoint.*/
226         SPKnot * knot;
227 /**  The NodeSide in the 'next' direction */
228         NodeSide n;
229 /**  The NodeSide in the 'previous' direction */
230         NodeSide p;
232         /** The pointer to the nodeside which we are dragging out with Shift */
233         NodeSide *dragging_out;
234   
235   /** Boolean.  Am I being dragged? */
236   guint is_dragging : 1;
237 };
239 }  // namespace NodePath
240 }  // namespace Inkscape
242 enum {
243   SCULPT_PROFILE_LINEAR,
244   SCULPT_PROFILE_BELL,
245   SCULPT_PROFILE_ELLIPTIC
246 };
248 // Do function documentation in nodepath.cpp
249 Inkscape::NodePath::Path * sp_nodepath_new (SPDesktop * desktop, SPItem * item, bool show_handles);
250 void sp_nodepath_destroy (Inkscape::NodePath::Path * nodepath);
251 void sp_nodepath_ensure_livarot_path(Inkscape::NodePath::Path *np);
252 void sp_nodepath_deselect (Inkscape::NodePath::Path *nodepath);
253 void sp_nodepath_select_all (Inkscape::NodePath::Path *nodepath, bool invert);
254 void sp_nodepath_select_all_from_subpath(Inkscape::NodePath::Path *nodepath, bool invert);
255 void sp_nodepath_select_next (Inkscape::NodePath::Path *nodepath);
256 void sp_nodepath_select_prev (Inkscape::NodePath::Path *nodepath);
257 void sp_nodepath_select_rect (Inkscape::NodePath::Path * nodepath, NR::Rect const &b, gboolean incremental);
258 GList *save_nodepath_selection (Inkscape::NodePath::Path *nodepath);
259 void restore_nodepath_selection (Inkscape::NodePath::Path *nodepath, GList *r);
260 gboolean nodepath_repr_d_changed (Inkscape::NodePath::Path * np, const char *newd);
261 gboolean nodepath_repr_typestr_changed (Inkscape::NodePath::Path * np, const char *newtypestr);
262 gboolean node_key (GdkEvent * event);
263 void sp_nodepath_update_repr(Inkscape::NodePath::Path *np, const gchar *annotation);
264 void sp_nodepath_update_statusbar (Inkscape::NodePath::Path *nodepath);
265 void sp_nodepath_selected_align(Inkscape::NodePath::Path *nodepath, NR::Dim2 axis);
266 void sp_nodepath_selected_distribute(Inkscape::NodePath::Path *nodepath, NR::Dim2 axis);
267 void sp_nodepath_select_segment_near_point(Inkscape::NodePath::Path *nodepath, NR::Point p, bool toggle);
268 void sp_nodepath_add_node_near_point(Inkscape::NodePath::Path *nodepath, NR::Point p);
269 void sp_nodepath_curve_drag(int node, double t, NR::Point delta);
270 Inkscape::NodePath::Node * sp_nodepath_get_node_by_index(int index);
271 /* possibly private functions */
273 void sp_node_selected_add_node (Inkscape::NodePath::Path *nodepath);
274 void sp_node_selected_break (Inkscape::NodePath::Path *nodepath);
275 void sp_node_selected_duplicate (Inkscape::NodePath::Path *nodepath);
276 void sp_node_selected_join (Inkscape::NodePath::Path *nodepath);
277 void sp_node_selected_join_segment (Inkscape::NodePath::Path *nodepath);
278 void sp_node_delete_preserve (GList *nodes_to_delete);
279 void sp_node_selected_delete (Inkscape::NodePath::Path *nodepath);
280 void sp_node_selected_delete_segment (Inkscape::NodePath::Path *nodepath);
281 void sp_node_selected_set_type (Inkscape::NodePath::Path *nodepath, Inkscape::NodePath::NodeType type);
282 void sp_node_selected_set_line_type (Inkscape::NodePath::Path *nodepath, NRPathcode code);
283 void sp_node_selected_move (Inkscape::NodePath::Path *nodepath, gdouble dx, gdouble dy);
284 void sp_node_selected_move_screen (Inkscape::NodePath::Path *nodepath, gdouble dx, gdouble dy);
286 void sp_nodepath_show_handles(Inkscape::NodePath::Path *nodepath, bool show);
288 void sp_nodepath_selected_nodes_rotate (Inkscape::NodePath::Path * nodepath, gdouble angle, int which, bool screen);
290 void sp_nodepath_selected_nodes_scale (Inkscape::NodePath::Path * nodepath, gdouble grow, int which);
291 void sp_nodepath_selected_nodes_scale_screen (Inkscape::NodePath::Path * nodepath, gdouble grow, int which);
293 void sp_nodepath_flip (Inkscape::NodePath::Path *nodepath, NR::Dim2 axis, NR::Maybe<NR::Point> center);
295 #endif