Code

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