1 #ifndef SEEN_CONNECTOR_CONTEXT_H
2 #define SEEN_CONNECTOR_CONTEXT_H
4 /*
5 * Connector creation tool
6 *
7 * Authors:
8 * Michael Wybrow <mjwybrow@users.sourceforge.net>
9 *
10 * Copyright (C) 2005 Michael Wybrow
11 *
12 * Released under GNU GPL, read the file 'COPYING' for more information
13 */
15 #include <sigc++/sigc++.h>
16 #include <sigc++/connection.h>
17 #include "event-context.h"
18 #include <forward.h>
19 #include <display/display-forward.h>
20 #include <2geom/point.h>
21 #include "libavoid/connector.h"
22 #include "connection-points.h"
23 #include <glibmm/i18n.h>
25 #define SP_TYPE_CONNECTOR_CONTEXT (sp_connector_context_get_type())
26 #define SP_CONNECTOR_CONTEXT(o) (G_TYPE_CHECK_INSTANCE_CAST((o), SP_TYPE_CONNECTOR_CONTEXT, SPConnectorContext))
27 #define SP_CONNECTOR_CONTEXT_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), SP_TYPE_CONNECTOR_CONTEXT, SPConnectorContextClass))
28 #define SP_IS_CONNECTOR_CONTEXT(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), SP_TYPE_CONNECTOR_CONTEXT))
29 #define SP_IS_CONNECTOR_CONTEXT_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE((k), SP_TYPE_CONNECTOR_CONTEXT))
31 struct SPKnot;
32 namespace Inkscape
33 {
34 class Selection;
35 }
37 enum {
38 SP_CONNECTOR_CONTEXT_IDLE,
39 SP_CONNECTOR_CONTEXT_DRAGGING,
40 SP_CONNECTOR_CONTEXT_CLOSE,
41 SP_CONNECTOR_CONTEXT_STOP,
42 SP_CONNECTOR_CONTEXT_REROUTING,
43 SP_CONNECTOR_CONTEXT_NEWCONNPOINT
44 };
46 enum {
47 SP_CONNECTOR_CONTEXT_DRAWING_MODE,
48 SP_CONNECTOR_CONTEXT_EDITING_MODE
49 };
50 static char* cc_knot_tips[] = { _("<b>Connection point</b>: click or drag to create a new connector"),
51 _("<b>Connection point</b>: click to select, drag to move") };
53 typedef std::map<SPKnot *, ConnectionPoint> ConnectionPointMap;
55 struct SPConnectorContext : public SPEventContext {
56 Inkscape::Selection *selection;
57 Geom::Point p[5];
59 /** \invar npoints in {0, 2}. */
60 gint npoints;
61 /* The tool mode can be connector drawing or
62 connection points editing.
63 */
64 unsigned int mode : 1;
65 unsigned int state : 4;
67 gchar* knot_tip;
69 // Red curve
70 SPCanvasItem *red_bpath;
71 SPCurve *red_curve;
72 guint32 red_color;
74 // Green curve
75 SPCurve *green_curve;
77 // The new connector
78 SPItem *newconn;
79 Avoid::ConnRef *newConnRef;
80 gdouble curvature;
81 bool isOrthogonal;
83 // The active shape
84 SPItem *active_shape;
85 Inkscape::XML::Node *active_shape_repr;
86 Inkscape::XML::Node *active_shape_layer_repr;
88 // Same as above, but for the active connector
89 SPItem *active_conn;
90 Inkscape::XML::Node *active_conn_repr;
91 sigc::connection sel_changed_connection;
94 // The activehandle
95 SPKnot *active_handle;
97 // The selected handle, used in editing mode
98 SPKnot *selected_handle;
100 SPItem *clickeditem;
101 SPKnot *clickedhandle;
103 ConnectionPointMap connpthandles;
104 SPKnot *endpt_handle[2];
105 guint endpt_handler_id[2];
106 gchar *sid;
107 gchar *eid;
108 SPCanvasItem *c0, *c1, *cl0, *cl1;
109 };
111 struct SPConnectorContextClass : public SPEventContextClass { };
113 GType sp_connector_context_get_type();
115 void sp_connector_context_switch_mode(SPEventContext* ec, unsigned int newMode);
116 void cc_selection_set_avoid(bool const set_ignore);
117 void cc_create_connection_point(SPConnectorContext* cc);
118 void cc_remove_connection_point(SPConnectorContext* cc);
119 bool cc_item_is_connector(SPItem *item);
122 #endif /* !SEEN_CONNECTOR_CONTEXT_H */
124 /*
125 Local Variables:
126 mode:c++
127 c-file-style:"stroustrup"
128 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
129 indent-tabs-mode:nil
130 fill-column:99
131 End:
132 */
133 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :