1 #ifndef __SHAPE_EDITOR_H__
2 #define __SHAPE_EDITOR_H__
4 /*
5 * Inkscape::ShapeEditor
6 *
7 * This is a container class which contains either knotholder (for shapes) or nodepath (for
8 * paths). It is attached to a single item so only one of these is active at a time.
9 *
10 * Authors:
11 * bulia byak <buliabyak@users.sf.net>
12 *
13 */
15 #include <forward.h>
16 #include <libnr/nr-forward.h>
18 namespace Inkscape { namespace NodePath { class Path; } }
19 namespace Inkscape { namespace XML { class Node; } }
21 #include "libnr/nr-path-code.h"
22 #include "libnr/nr-point.h"
23 #include <boost/optional.hpp>
24 #include <vector>
26 class KnotHolder;
27 class SPDesktop;
28 class SPNodeContext;
29 class ShapeEditorsCollective;
31 enum SubType{
32 SH_NODEPATH,
33 SH_KNOTHOLDER
34 };
36 class ShapeEditor {
37 public:
39 ShapeEditor(SPDesktop *desktop);
40 ~ShapeEditor();
42 void set_item (SPItem *item, SubType type, bool keep_knotholder = false);
43 void set_item_lpe_path_parameter(SPItem *item, SPObject *lpeobject, const char * key);
44 void set_knotholder(KnotHolder * knot_holder);
45 void reset_item (SubType type, bool keep_knotholder = true);
46 void unset_item (SubType type, bool keep_knotholder = false);
48 const SPItem *get_item (SubType type);
50 bool has_nodepath ();
51 bool has_knotholder ();
52 void update_knotholder ();
54 bool has_local_change (SubType type);
55 void decrement_local_change (SubType type);
57 GList *save_nodepath_selection ();
58 void restore_nodepath_selection (GList *saved);
60 void nodepath_destroyed ();
62 void update_statusbar ();
64 bool is_over_stroke (NR::Point event_p, bool remember);
66 void add_node_near_point(); // uses the shapeeditor's remembered point, if any
68 void select_segment_near_point(bool toggle); // uses the shapeeditor's remembered point, if any
70 void cancel_hit ();
72 bool hits_curve ();
74 void curve_drag (gdouble eventx, gdouble eventy);
76 void finish_drag ();
78 void select_rect (NR::Rect const &rect, bool add);
80 bool has_selection ();
81 void deselect ();
83 Inkscape::NodePath::Path *get_nodepath() {return nodepath;} //((deprecated))
84 ShapeEditorsCollective *get_container() {return container;}
86 void add_node();
88 void delete_nodes();
89 void delete_nodes_preserving_shape();
90 void delete_segment();
92 void set_node_type(int type);
94 void break_at_nodes();
95 void join_nodes();
96 void join_segments();
98 void duplicate_nodes();
100 void set_type_of_segments(NRPathcode code);
102 void move_nodes(gdouble dx, gdouble dy);
103 void move_nodes_screen(SPDesktop *desktop, gdouble dx, gdouble dy);
105 void rotate_nodes(gdouble angle, int which, bool screen);
107 void scale_nodes(gdouble const grow, int const which);
108 void scale_nodes_screen(gdouble const grow, int const which);
110 void select_all (bool invert);
111 void select_all_from_subpath (bool invert);
112 void select_next ();
113 void select_prev ();
115 void show_handles (bool show);
116 void show_helperpath (bool show);
118 void flip (NR::Dim2 axis, boost::optional<NR::Point> center = boost::optional<NR::Point>());
120 void distribute (NR::Dim2 axis);
121 void align (NR::Dim2 axis);
123 bool nodepath_edits_repr_key(gchar const *name);
125 private:
126 SPDesktop *desktop;
128 Inkscape::NodePath::Path *nodepath;
129 KnotHolder *knotholder;
131 ShapeEditorsCollective *container;
133 //Inkscape::XML::Node *lidtened_repr;
135 double grab_t;
136 int grab_node; // number of node grabbed by sp_node_context_is_over_stroke
137 bool hit;
138 NR::Point curvepoint_event; // int coords from event
139 NR::Point curvepoint_doc; // same, in doc coords
141 Inkscape::XML::Node *listener_attached_for;
142 };
145 /* As the next stage, this will be a collection of multiple ShapeEditors,
146 with the same interface as the single ShapeEditor, passing the actions to all its
147 contained ShapeEditors. Thus it should be easy to switch node context from
148 using a single ShapeEditor to using a ShapeEditorsCollective. */
150 class ShapeEditorsCollective {
151 public:
153 ShapeEditorsCollective(SPDesktop *desktop);
154 ~ShapeEditorsCollective();
156 void update_statusbar();
158 private:
159 std::vector<ShapeEditor> editors;
161 SPNodeContext *nc; // who holds us
162 };
164 #endif
167 /*
168 Local Variables:
169 mode:c++
170 c-file-style:"stroustrup"
171 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
172 indent-tabs-mode:nil
173 fill-column:99
174 End:
175 */
176 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :