0fc9de9d0384ee0e99d98e0366012ed7851aa2ce
1 /*
2 * Connector creation tool
3 *
4 * Authors:
5 * Michael Wybrow <mjwybrow@users.sourceforge.net>
6 *
7 * Copyright (C) 2005-2008 Michael Wybrow
8 * Copyright (C) 2009 Monash University
9 *
10 * Released under GNU GPL, read the file 'COPYING' for more information
11 *
12 * TODO:
13 * o Show a visual indicator for objects with the 'avoid' property set.
14 * o Allow user to change a object between a path and connector through
15 * the interface.
16 * o Create an interface for setting markers (arrow heads).
17 * o Better distinguish between paths and connectors to prevent problems
18 * in the node tool and paths accidentally being turned into connectors
19 * in the connector tool. Perhaps have a way to convert between.
20 * o Only call libavoid's updateEndPoint as required. Currently we do it
21 * for both endpoints, even if only one is moving.
22 * o Allow user-placeable connection points.
23 * o Deal sanely with connectors with both endpoints attached to the
24 * same connection point, and drawing of connectors attaching
25 * overlapping shapes (currently tries to adjust connector to be
26 * outside both bounding boxes).
27 * o Fix many special cases related to connectors updating,
28 * e.g., copying a couple of shapes and a connector that are
29 * attached to each other.
30 * e.g., detach connector when it is moved or transformed in
31 * one of the other contexts.
32 * o Cope with shapes whose ids change when they have attached
33 * connectors.
34 * o During dragging motion, gobble up to and use the final motion event.
35 * Gobbling away all duplicates after the current can occasionally result
36 * in the path lagging behind the mouse cursor if it is no longer being
37 * dragged.
38 * o Fix up libavoid's representation after undo actions. It doesn't see
39 * any transform signals and hence doesn't know shapes have moved back to
40 * there earlier positions.
41 * o Decide whether drawing/editing mode should be an Inkscape preference
42 * or the connector tool should always start in drawing mode.
43 * o Correct the problem with switching to the select tool when pressing
44 * space bar (there are moments when it refuses to do so).
45 *
46 * ----------------------------------------------------------------------------
47 *
48 * mjwybrow's observations on acracan's Summer of Code connector work:
49 *
50 * - GUI comments:
51 *
52 * - Buttons for adding and removing user-specified connection
53 * points should probably have "+" and "-" symbols on them so they
54 * are consistent with the similar buttons for the node tool.
55 * - Controls on the connector tool be should be reordered logically,
56 * possibly as follows:
57 *
58 * *Connector*: [Polyline-radio-button] [Orthgonal-radio-button]
59 * [Curvature-control] | *Shape*: [Avoid-button] [Dont-avoid-button]
60 * [Spacing-control] | *Connection pts*: [Edit-mode] [Add-pt] [Rm-pt]
61 *
62 * I think that the network layout controls be moved to the
63 * Align and Distribute dialog (there is already the layout button
64 * there, but no options are exposed).
65 *
66 * I think that the style change between polyline and orthogonal
67 * would be much clearer with two buttons (radio behaviour -- just
68 * one is true).
69 *
70 * The other tools show a label change from "New:" to "Change:"
71 * depending on whether an object is selected. We could consider
72 * this but there may not be space.
73 *
74 * The Add-pt and Rm-pt buttons should be greyed out (inactive) if
75 * we are not in connection point editing mode. And probably also
76 * if there is no shape selected, i.e. at the times they have no
77 * effect when clicked.
78 *
79 * Likewise for the avoid/ignore shapes buttons. These should be
80 * inactive when a shape is not selected in the connector context.
81 *
82 * - When creating/editing connection points:
83 *
84 * - Strange things can happen if you have connectors selected, or
85 * try rerouting connectors by dragging their endpoints when in
86 * connection point editing mode.
87 *
88 * - Possibly the selected shape's connection points should always
89 * be shown (i.e., have knots) when in editing mode.
90 *
91 * - It is a little strange to be able to place connection points
92 * competely outside shapes. Especially when you later can't draw
93 * connectors to them since the knots are only visible when you
94 * are over the shape. I think that you should only be able to
95 * place connection points inside or on the boundary of the shape
96 * itself.
97 *
98 * - The intended ability to place a new point at the current cursor
99 * position by pressing RETURN does not seem to work.
100 *
101 * - The Status bar tooltip should change to reflect editing mode
102 * and tell the user about RETURN and how to use the tool.
103 *
104 * - Connection points general:
105 *
106 * - Connection points that were inside the shape can end up outside
107 * after a rotation is applied to the shape in the select tool.
108 * It doesn't seem like the correct transform is being applied to
109 * these, or it is being applied at the wrong time. I'd expect
110 * connection points to rotate with the shape, and stay at the
111 * same position "on the shape"
112 *
113 * - I was able to make the connectors attached to a shape fall off
114 * the shape after scaling it. Not sure the exact cause, but may
115 * require more investigation/debugging.
116 *
117 * - The user-defined connection points should be either absolute
118 * (as the current ones are) or defined as a percentage of the
119 * shape. These would be based on a toggle setting on the
120 * toolbar, and they would be placed in exactly the same way by
121 * the user. The only difference would be that they would be
122 * store as percentage positions in the SVG connection-points
123 * property and that they would update/move automatically if the
124 * object was resized or scaled.
125 *
126 * - Thinking more, I think you always want to store and think about
127 * the positions of connection points to be pre-transform, but
128 * obviously the shape transform is applied to them. That way,
129 * they will rotate and scale automatically with the shape, when
130 * the shape transform is altered. The Percentage version would
131 * compute their position from the pre-transform dimensions and
132 * then have the transform applied to them, for example.
133 *
134 * - The connection points in the test_connection_points.svg file
135 * seem to follow the shape when it is moved, but connection
136 * points I add to new shapes, do not follow the shape, either
137 * when the shape is just moved or transformed. There is
138 * something wrong here. What exactly should the behaviour be
139 * currently?
140 *
141 * - I see that connection points are specified at absolute canvas
142 * positions. I really think that they should be specified in
143 * shape coordinated relative to the shapes. There may be
144 * transforms applied to layers and the canvas which would make
145 * specifying them quite difficult. I'd expect a position of 0, 0
146 * to be on the shape in question or very close to it, for example.
147 *
148 */
152 #include <gdk/gdkkeysyms.h>
153 #include <string>
154 #include <cstring>
156 #include "connector-context.h"
157 #include "pixmaps/cursor-connector.xpm"
158 #include "pixmaps/cursor-node.xpm"
159 //#include "pixmaps/cursor-node-m.xpm"
160 //#include "pixmaps/cursor-node-d.xpm"
161 #include "xml/node-event-vector.h"
162 #include "xml/repr.h"
163 #include "svg/svg.h"
164 #include "desktop.h"
165 #include "desktop-style.h"
166 #include "desktop-handles.h"
167 #include "document.h"
168 #include "message-context.h"
169 #include "message-stack.h"
170 #include "selection.h"
171 #include "inkscape.h"
172 #include "preferences.h"
173 #include "sp-path.h"
174 #include "display/canvas-bpath.h"
175 #include "display/sodipodi-ctrl.h"
176 #include <glibmm/i18n.h>
177 #include <glibmm/stringutils.h>
178 #include "snap.h"
179 #include "knot.h"
180 #include "sp-conn-end.h"
181 #include "sp-conn-end-pair.h"
182 #include "conn-avoid-ref.h"
183 #include "libavoid/vertices.h"
184 #include "libavoid/router.h"
185 #include "context-fns.h"
186 #include "sp-namedview.h"
187 #include "sp-text.h"
188 #include "sp-flowtext.h"
189 #include "display/curve.h"
191 static void sp_connector_context_class_init(SPConnectorContextClass *klass);
192 static void sp_connector_context_init(SPConnectorContext *conn_context);
193 static void sp_connector_context_dispose(GObject *object);
195 static void sp_connector_context_setup(SPEventContext *ec);
196 static void sp_connector_context_set(SPEventContext *ec, Inkscape::Preferences::Entry *val);
197 static void sp_connector_context_finish(SPEventContext *ec);
198 static gint sp_connector_context_root_handler(SPEventContext *ec, GdkEvent *event);
199 static gint sp_connector_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event);
201 // Stuff borrowed from DrawContext
202 static void spcc_connector_set_initial_point(SPConnectorContext *cc, Geom::Point const p);
203 static void spcc_connector_set_subsequent_point(SPConnectorContext *cc, Geom::Point const p);
204 static void spcc_connector_finish_segment(SPConnectorContext *cc, Geom::Point p);
205 static void spcc_reset_colors(SPConnectorContext *cc);
206 static void spcc_connector_finish(SPConnectorContext *cc);
207 static void spcc_concat_colors_and_flush(SPConnectorContext *cc);
208 static void spcc_flush_white(SPConnectorContext *cc, SPCurve *gc);
210 // Context event handlers
211 static gint connector_handle_button_press(SPConnectorContext *const cc, GdkEventButton const &bevent);
212 static gint connector_handle_motion_notify(SPConnectorContext *const cc, GdkEventMotion const &mevent);
213 static gint connector_handle_button_release(SPConnectorContext *const cc, GdkEventButton const &revent);
214 static gint connector_handle_key_press(SPConnectorContext *const cc, guint const keyval);
216 static void cc_active_shape_add_knot(SPDesktop* desktop, SPItem* item, ConnectionPointMap &cphandles, ConnectionPoint& cp);
217 static void cc_set_active_shape(SPConnectorContext *cc, SPItem *item);
218 static void cc_clear_active_shape(SPConnectorContext *cc);
219 static void cc_set_active_conn(SPConnectorContext *cc, SPItem *item);
220 static void cc_clear_active_conn(SPConnectorContext *cc);
221 static gchar *conn_pt_handle_test(SPConnectorContext *cc, Geom::Point& w);
222 static void cc_select_handle(SPKnot* knot);
223 static void cc_deselect_handle(SPKnot* knot);
224 static bool cc_item_is_shape(SPItem *item);
225 static void cc_selection_changed(Inkscape::Selection *selection, gpointer data);
226 static void cc_connector_rerouting_finish(SPConnectorContext *const cc,
227 Geom::Point *const p);
229 static void shape_event_attr_deleted(Inkscape::XML::Node *repr,
230 Inkscape::XML::Node *child, Inkscape::XML::Node *ref, gpointer data);
231 static void shape_event_attr_changed(Inkscape::XML::Node *repr, gchar const *name,
232 gchar const *old_value, gchar const *new_value, bool is_interactive,
233 gpointer data);
236 /*static Geom::Point connector_drag_origin_w(0, 0);
237 static bool connector_within_tolerance = false;*/
238 static SPEventContextClass *parent_class;
241 static Inkscape::XML::NodeEventVector shape_repr_events = {
242 NULL, /* child_added */
243 NULL, /* child_added */
244 shape_event_attr_changed,
245 NULL, /* content_changed */
246 NULL /* order_changed */
247 };
249 static Inkscape::XML::NodeEventVector layer_repr_events = {
250 NULL, /* child_added */
251 shape_event_attr_deleted,
252 NULL, /* child_added */
253 NULL, /* content_changed */
254 NULL /* order_changed */
255 };
258 GType
259 sp_connector_context_get_type(void)
260 {
261 static GType type = 0;
262 if (!type) {
263 GTypeInfo info = {
264 sizeof(SPConnectorContextClass),
265 NULL, NULL,
266 (GClassInitFunc) sp_connector_context_class_init,
267 NULL, NULL,
268 sizeof(SPConnectorContext),
269 4,
270 (GInstanceInitFunc) sp_connector_context_init,
271 NULL, /* value_table */
272 };
273 type = g_type_register_static(SP_TYPE_EVENT_CONTEXT, "SPConnectorContext", &info, (GTypeFlags)0);
274 }
275 return type;
276 }
278 static void
279 sp_connector_context_class_init(SPConnectorContextClass *klass)
280 {
281 GObjectClass *object_class;
282 SPEventContextClass *event_context_class;
284 object_class = (GObjectClass *) klass;
285 event_context_class = (SPEventContextClass *) klass;
287 parent_class = (SPEventContextClass*)g_type_class_peek_parent(klass);
289 object_class->dispose = sp_connector_context_dispose;
291 event_context_class->setup = sp_connector_context_setup;
292 event_context_class->set = sp_connector_context_set;
293 event_context_class->finish = sp_connector_context_finish;
294 event_context_class->root_handler = sp_connector_context_root_handler;
295 event_context_class->item_handler = sp_connector_context_item_handler;
296 }
299 static void
300 sp_connector_context_init(SPConnectorContext *cc)
301 {
302 SPEventContext *ec = SP_EVENT_CONTEXT(cc);
304 ec->cursor_shape = cursor_connector_xpm;
305 ec->hot_x = 1;
306 ec->hot_y = 1;
307 ec->xp = 0;
308 ec->yp = 0;
310 cc->mode = SP_CONNECTOR_CONTEXT_DRAWING_MODE;
311 cc->knot_tip = 0;
313 cc->red_color = 0xff00007f;
315 cc->newconn = NULL;
316 cc->newConnRef = NULL;
317 cc->curvature = 0.0;
319 cc->sel_changed_connection = sigc::connection();
321 cc->active_shape = NULL;
322 cc->active_shape_repr = NULL;
323 cc->active_shape_layer_repr = NULL;
325 cc->active_conn = NULL;
326 cc->active_conn_repr = NULL;
328 cc->active_handle = NULL;
330 cc->selected_handle = NULL;
332 cc->clickeditem = NULL;
333 cc->clickedhandle = NULL;
335 new (&cc->connpthandles) ConnectionPointMap();
337 for (int i = 0; i < 2; ++i) {
338 cc->endpt_handle[i] = NULL;
339 cc->endpt_handler_id[i] = 0;
340 }
341 cc->sid = NULL;
342 cc->eid = NULL;
343 cc->npoints = 0;
344 cc->state = SP_CONNECTOR_CONTEXT_IDLE;
345 }
348 static void
349 sp_connector_context_dispose(GObject *object)
350 {
351 SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(object);
353 cc->sel_changed_connection.disconnect();
355 if (!cc->connpthandles.empty()) {
356 for (ConnectionPointMap::iterator it = cc->connpthandles.begin();
357 it != cc->connpthandles.end(); ++it) {
358 g_object_unref(it->first);
359 }
360 cc->connpthandles.clear();
361 }
362 cc->connpthandles.~ConnectionPointMap();
363 for (int i = 0; i < 2; ++i) {
364 if (cc->endpt_handle[1]) {
365 g_object_unref(cc->endpt_handle[i]);
366 cc->endpt_handle[i] = NULL;
367 }
368 }
369 if (cc->sid) {
370 g_free(cc->sid);
371 cc->sid = NULL;
372 }
373 if (cc->eid) {
374 g_free(cc->eid);
375 cc->eid = NULL;
376 }
377 g_assert( cc->newConnRef == NULL );
379 G_OBJECT_CLASS(parent_class)->dispose(object);
380 }
383 static void
384 sp_connector_context_setup(SPEventContext *ec)
385 {
386 SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(ec);
387 SPDesktop *dt = ec->desktop;
389 if (((SPEventContextClass *) parent_class)->setup) {
390 ((SPEventContextClass *) parent_class)->setup(ec);
391 }
393 cc->selection = sp_desktop_selection(dt);
395 cc->sel_changed_connection.disconnect();
396 cc->sel_changed_connection = cc->selection->connectChanged(
397 sigc::bind(sigc::ptr_fun(&cc_selection_changed),
398 (gpointer) cc));
400 /* Create red bpath */
401 cc->red_bpath = sp_canvas_bpath_new(sp_desktop_sketch(ec->desktop), NULL);
402 sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(cc->red_bpath), cc->red_color,
403 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
404 sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(cc->red_bpath), 0x00000000,
405 SP_WIND_RULE_NONZERO);
406 /* Create red curve */
407 cc->red_curve = new SPCurve();
409 /* Create green curve */
410 cc->green_curve = new SPCurve();
412 // Notice the initial selection.
413 cc_selection_changed(cc->selection, (gpointer) cc);
415 cc->within_tolerance = false;
417 sp_event_context_read(ec, "curvature");
418 sp_event_context_read(ec, "orthogonal");
419 sp_event_context_read(ec, "mode");
420 cc->knot_tip = cc->mode == SP_CONNECTOR_CONTEXT_DRAWING_MODE ? cc_knot_tips[0] : cc_knot_tips[1];
421 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
422 if (prefs->getBool("/tools/connector/selcue", 0)) {
423 ec->enableSelectionCue();
424 }
426 // Make sure we see all enter events for canvas items,
427 // even if a mouse button is depressed.
428 dt->canvas->gen_all_enter_events = true;
429 }
432 static void
433 sp_connector_context_set(SPEventContext *ec, Inkscape::Preferences::Entry *val)
434 {
435 SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(ec);
437 /* fixme: Proper error handling for non-numeric data. Use a locale-independent function like
438 * g_ascii_strtod (or a thin wrapper that does the right thing for invalid values inf/nan). */
439 Glib::ustring name = val->getEntryName();
440 if ( name == "curvature" ) {
441 cc->curvature = val->getDoubleLimited(); // prevents NaN and +/-Inf from messing up
442 }
443 else if ( name == "orthogonal" ) {
444 cc->isOrthogonal = val->getBool();
445 }
446 else if ( name == "mode")
447 {
448 sp_connector_context_switch_mode(ec, val->getBool() ? SP_CONNECTOR_CONTEXT_EDITING_MODE : SP_CONNECTOR_CONTEXT_DRAWING_MODE);
449 }
450 }
452 void sp_connector_context_switch_mode(SPEventContext* ec, unsigned int newMode)
453 {
454 SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(ec);
456 cc->mode = newMode;
457 if ( cc->mode == SP_CONNECTOR_CONTEXT_DRAWING_MODE )
458 {
459 ec->cursor_shape = cursor_connector_xpm;
460 cc->knot_tip = cc_knot_tips[0];
461 if (cc->selected_handle)
462 cc_deselect_handle( cc->selected_handle );
463 cc->selected_handle = NULL;
464 // Show all default connection points
466 }
467 else if ( cc->mode == SP_CONNECTOR_CONTEXT_EDITING_MODE )
468 {
469 ec->cursor_shape = cursor_node_xpm;
470 cc->knot_tip = cc_knot_tips[1];
471 /* if (cc->active_shape)
472 {
473 cc->selection->set( SP_OBJECT( cc->active_shape ) );
474 }
475 else
476 {
477 SPItem* item = cc->selection->singleItem();
478 if ( item )
479 {
480 cc_set_active_shape(cc, item);
481 cc->selection->set( SP_OBJECT( item ) );
482 }
483 }*/
484 }
485 sp_event_context_update_cursor(ec);
487 }
490 static void
491 sp_connector_context_finish(SPEventContext *ec)
492 {
493 SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(ec);
495 spcc_connector_finish(cc);
496 cc->state = SP_CONNECTOR_CONTEXT_IDLE;
498 if (((SPEventContextClass *) parent_class)->finish) {
499 ((SPEventContextClass *) parent_class)->finish(ec);
500 }
502 if (cc->selection) {
503 cc->selection = NULL;
504 }
505 cc_clear_active_shape(cc);
506 cc_clear_active_conn(cc);
508 // Restore the default event generating behaviour.
509 SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(ec);
510 desktop->canvas->gen_all_enter_events = false;
511 }
514 //-----------------------------------------------------------------------------
517 static void
518 cc_clear_active_shape(SPConnectorContext *cc)
519 {
520 if (cc->active_shape == NULL) {
521 return;
522 }
523 g_assert( cc->active_shape_repr );
524 g_assert( cc->active_shape_layer_repr );
526 cc->active_shape = NULL;
528 if (cc->active_shape_repr) {
529 sp_repr_remove_listener_by_data(cc->active_shape_repr, cc);
530 Inkscape::GC::release(cc->active_shape_repr);
531 cc->active_shape_repr = NULL;
533 sp_repr_remove_listener_by_data(cc->active_shape_layer_repr, cc);
534 Inkscape::GC::release(cc->active_shape_layer_repr);
535 cc->active_shape_layer_repr = NULL;
536 }
538 // Hide the connection points if they exist.
539 if (cc->connpthandles.size()) {
540 for (ConnectionPointMap::iterator it = cc->connpthandles.begin();
541 it != cc->connpthandles.end(); ++it) {
542 sp_knot_hide(it->first);
543 }
544 }
545 }
548 static void
549 cc_clear_active_conn(SPConnectorContext *cc)
550 {
551 if (cc->active_conn == NULL) {
552 return;
553 }
554 g_assert( cc->active_conn_repr );
556 cc->active_conn = NULL;
558 if (cc->active_conn_repr) {
559 sp_repr_remove_listener_by_data(cc->active_conn_repr, cc);
560 Inkscape::GC::release(cc->active_conn_repr);
561 cc->active_conn_repr = NULL;
562 }
564 // Hide the endpoint handles.
565 for (int i = 0; i < 2; ++i) {
566 if (cc->endpt_handle[i]) {
567 sp_knot_hide(cc->endpt_handle[i]);
568 }
569 }
570 }
573 static gchar *
574 conn_pt_handle_test(SPConnectorContext *cc, Geom::Point& p)
575 {
576 // TODO: this will need to change when there are more connection
577 // points available for each shape.
579 if (cc->active_handle && (cc->connpthandles.find(cc->active_handle) != cc->connpthandles.end()))
580 {
581 p = cc->active_handle->pos;
582 const ConnectionPoint& cp = cc->connpthandles[cc->active_handle];
583 return g_strdup_printf("#%s_%c_%d", SP_OBJECT_ID(cc->active_shape),
584 cp.type == ConnPointDefault ? 'd' : 'u' , cp.id);
585 }
586 return NULL;
587 }
589 static void
590 cc_select_handle(SPKnot* knot)
591 {
592 knot->setShape(SP_KNOT_SHAPE_SQUARE);
593 knot->setSize(10);
594 knot->setAnchor(GTK_ANCHOR_CENTER);
595 knot->setFill(0x0000ffff, 0x0000ffff, 0x0000ffff);
596 sp_knot_update_ctrl(knot);
597 }
599 static void
600 cc_deselect_handle(SPKnot* knot)
601 {
602 knot->setShape(SP_KNOT_SHAPE_SQUARE);
603 knot->setSize(8);
604 knot->setAnchor(GTK_ANCHOR_CENTER);
605 knot->setFill(0xffffff00, 0xff0000ff, 0xff0000ff);
606 sp_knot_update_ctrl(knot);
607 }
609 static gint
610 sp_connector_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event)
611 {
612 gint ret = FALSE;
614 SPDesktop *desktop = event_context->desktop;
616 SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(event_context);
618 Geom::Point p(event->button.x, event->button.y);
620 switch (event->type) {
621 case GDK_BUTTON_RELEASE:
622 if (event->button.button == 1 && !event_context->space_panning) {
623 if ((cc->state == SP_CONNECTOR_CONTEXT_DRAGGING) &&
624 (event_context->within_tolerance))
625 {
626 spcc_reset_colors(cc);
627 cc->state = SP_CONNECTOR_CONTEXT_IDLE;
628 }
629 if (cc->state != SP_CONNECTOR_CONTEXT_IDLE) {
630 // Doing something else like rerouting.
631 break;
632 }
633 // find out clicked item, honoring Alt
634 SPItem *item = sp_event_context_find_item(desktop,
635 p, event->button.state & GDK_MOD1_MASK, FALSE);
637 if (event->button.state & GDK_SHIFT_MASK) {
638 cc->selection->toggle(item);
639 } else {
640 cc->selection->set(item);
641 if ( cc->mode == SP_CONNECTOR_CONTEXT_EDITING_MODE && cc->selected_handle )
642 {
643 cc_deselect_handle( cc->selected_handle );
644 cc->selected_handle = NULL;
645 }
646 /* When selecting a new item,
647 do not allow showing connection points
648 on connectors. (yet?)
649 */
650 if ( item != cc->active_shape && !cc_item_is_connector( item ) )
651 cc_set_active_shape( cc, item );
652 }
653 ret = TRUE;
655 }
656 break;
657 case GDK_ENTER_NOTIFY:
658 {
659 if (cc->mode == SP_CONNECTOR_CONTEXT_DRAWING_MODE || (cc->mode == SP_CONNECTOR_CONTEXT_EDITING_MODE && !cc->selected_handle))
660 {
661 if (cc_item_is_shape(item)) {
663 // I don't really understand what the above does,
664 // so I commented it.
665 // This is a shape, so show connection point(s).
666 /* if (!(cc->active_shape)
667 // Don't show handle for another handle.
668 // || (cc->connpthandles.find((SPKnot*) item) != cc->connpthandles.end())
669 )
670 {
671 cc_set_active_shape(cc, item);
672 }*/
673 cc_set_active_shape(cc, item);
674 }
675 ret = TRUE;
676 }
677 break;
678 }
679 default:
680 break;
681 }
683 return ret;
684 }
687 gint
688 sp_connector_context_root_handler(SPEventContext *ec, GdkEvent *event)
689 {
690 SPConnectorContext *const cc = SP_CONNECTOR_CONTEXT(ec);
692 gint ret = FALSE;
694 switch (event->type) {
695 case GDK_BUTTON_PRESS:
696 ret = connector_handle_button_press(cc, event->button);
697 break;
699 case GDK_MOTION_NOTIFY:
700 ret = connector_handle_motion_notify(cc, event->motion);
701 break;
703 case GDK_BUTTON_RELEASE:
704 ret = connector_handle_button_release(cc, event->button);
705 break;
706 case GDK_KEY_PRESS:
707 ret = connector_handle_key_press(cc, get_group0_keyval (&event->key));
708 break;
710 default:
711 break;
712 }
714 if (!ret) {
715 gint (*const parent_root_handler)(SPEventContext *, GdkEvent *)
716 = ((SPEventContextClass *) parent_class)->root_handler;
717 if (parent_root_handler) {
718 ret = parent_root_handler(ec, event);
719 }
720 }
722 return ret;
723 }
726 static gint
727 connector_handle_button_press(SPConnectorContext *const cc, GdkEventButton const &bevent)
728 {
729 Geom::Point const event_w(bevent.x, bevent.y);
730 /* Find desktop coordinates */
731 Geom::Point p = cc->desktop->w2d(event_w);
732 SPEventContext *event_context = SP_EVENT_CONTEXT(cc);
734 gint ret = FALSE;
735 if ( cc->mode == SP_CONNECTOR_CONTEXT_DRAWING_MODE )
736 {
737 if ( bevent.button == 1 && !event_context->space_panning ) {
739 SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(cc);
741 if (Inkscape::have_viable_layer(desktop, cc->_message_context) == false) {
742 return TRUE;
743 }
745 Geom::Point const event_w(bevent.x,
746 bevent.y);
747 // connector_drag_origin_w = event_w;
748 cc->xp = bevent.x;
749 cc->yp = bevent.y;
750 cc->within_tolerance = true;
752 Geom::Point const event_dt = cc->desktop->w2d(event_w);
754 SnapManager &m = cc->desktop->namedview->snap_manager;
755 m.setup(cc->desktop);
757 switch (cc->state) {
758 case SP_CONNECTOR_CONTEXT_STOP:
759 /* This is allowed, if we just canceled curve */
760 case SP_CONNECTOR_CONTEXT_IDLE:
761 {
762 if ( cc->npoints == 0 ) {
763 cc_clear_active_conn(cc);
765 SP_EVENT_CONTEXT_DESKTOP(cc)->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Creating new connector"));
767 /* Set start anchor */
768 /* Create green anchor */
769 Geom::Point p = event_dt;
771 // Test whether we clicked on a connection point
772 cc->sid = conn_pt_handle_test(cc, p);
774 if (!cc->sid) {
775 // This is the first point, so just snap it to the grid
776 // as there's no other points to go off.
777 m.freeSnapReturnByRef(Inkscape::SnapPreferences::SNAPPOINT_NODE, p, Inkscape::SNAPSOURCE_HANDLE);
778 }
779 spcc_connector_set_initial_point(cc, p);
781 }
782 cc->state = SP_CONNECTOR_CONTEXT_DRAGGING;
783 ret = TRUE;
784 break;
785 }
786 case SP_CONNECTOR_CONTEXT_DRAGGING:
787 {
788 // This is the second click of a connector creation.
789 m.freeSnapReturnByRef(Inkscape::SnapPreferences::SNAPPOINT_NODE, p, Inkscape::SNAPSOURCE_HANDLE);
791 spcc_connector_set_subsequent_point(cc, p);
792 spcc_connector_finish_segment(cc, p);
793 // Test whether we clicked on a connection point
794 cc->eid = conn_pt_handle_test(cc, p);
795 if (cc->npoints != 0) {
796 spcc_connector_finish(cc);
797 }
798 cc_set_active_conn(cc, cc->newconn);
799 cc->state = SP_CONNECTOR_CONTEXT_IDLE;
800 ret = TRUE;
801 break;
802 }
803 case SP_CONNECTOR_CONTEXT_CLOSE:
804 {
805 g_warning("Button down in CLOSE state");
806 break;
807 }
808 default:
809 break;
810 }
811 } else if (bevent.button == 3) {
812 if (cc->state == SP_CONNECTOR_CONTEXT_REROUTING) {
813 // A context menu is going to be triggered here,
814 // so end the rerouting operation.
815 cc_connector_rerouting_finish(cc, &p);
817 cc->state = SP_CONNECTOR_CONTEXT_IDLE;
819 // Don't set ret to TRUE, so we drop through to the
820 // parent handler which will open the context menu.
821 }
822 else if (cc->npoints != 0) {
823 spcc_connector_finish(cc);
824 cc->state = SP_CONNECTOR_CONTEXT_IDLE;
825 ret = TRUE;
826 }
827 }
828 }
829 else if ( cc->mode == SP_CONNECTOR_CONTEXT_EDITING_MODE )
830 {
831 if ( bevent.button == 1 && !event_context->space_panning )
832 {
833 // Initialize variables in case of dragging
835 SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(cc);
837 if (Inkscape::have_viable_layer(desktop, cc->_message_context) == false) {
838 return TRUE;
839 }
841 cc->xp = bevent.x;
842 cc->yp = bevent.y;
843 cc->within_tolerance = true;
845 ConnectionPointMap::iterator const& active_knot_it = cc->connpthandles.find( cc->active_handle );
847 switch (cc->state)
848 {
849 case SP_CONNECTOR_CONTEXT_IDLE:
850 if ( active_knot_it != cc->connpthandles.end() )
851 {
852 // We do not allow selecting and, thereby, moving default knots
853 if ( active_knot_it->second.type != ConnPointDefault)
854 {
855 if (cc->selected_handle != cc->active_handle)
856 {
857 if ( cc->selected_handle )
858 cc_deselect_handle( cc->selected_handle );
859 cc->selected_handle = cc->active_handle;
860 cc_select_handle( cc->selected_handle );
861 }
862 }
863 else
864 // Just ignore the default connection point
865 return FALSE;
866 }
867 else
868 if ( cc->selected_handle )
869 {
870 cc_deselect_handle( cc->selected_handle );
871 cc->selected_handle = NULL;
872 }
874 if ( cc->selected_handle )
875 {
876 cc->state = SP_CONNECTOR_CONTEXT_DRAGGING;
877 cc->selection->set( SP_OBJECT( cc->active_shape ) );
878 }
880 ret = TRUE;
881 break;
882 // Dragging valid because of the way we create
883 // new connection points.
884 case SP_CONNECTOR_CONTEXT_DRAGGING:
885 // Do nothing.
886 ret = TRUE;
887 break;
888 }
889 }
890 }
891 return ret;
892 }
895 static gint
896 connector_handle_motion_notify(SPConnectorContext *const cc, GdkEventMotion const &mevent)
897 {
898 gint ret = FALSE;
899 SPEventContext *event_context = SP_EVENT_CONTEXT(cc);
900 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
902 if (event_context->space_panning || mevent.state & GDK_BUTTON2_MASK || mevent.state & GDK_BUTTON3_MASK) {
903 // allow middle-button scrolling
904 return FALSE;
905 }
907 Geom::Point const event_w(mevent.x, mevent.y);
909 if (cc->within_tolerance) {
910 cc->tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100);
911 if ( ( abs( (gint) mevent.x - cc->xp ) < cc->tolerance ) &&
912 ( abs( (gint) mevent.y - cc->yp ) < cc->tolerance ) ) {
913 return FALSE; // Do not drag if we're within tolerance from origin.
914 }
915 }
916 // Once the user has moved farther than tolerance from the original location
917 // (indicating they intend to move the object, not click), then always process
918 // the motion notify coordinates as given (no snapping back to origin)
919 cc->within_tolerance = false;
921 SPDesktop *const dt = cc->desktop;
923 /* Find desktop coordinates */
924 Geom::Point p = dt->w2d(event_w);
926 if ( cc->mode == SP_CONNECTOR_CONTEXT_DRAWING_MODE )
927 {
928 SnapManager &m = dt->namedview->snap_manager;
929 m.setup(dt);
931 switch (cc->state) {
932 case SP_CONNECTOR_CONTEXT_DRAGGING:
933 {
934 gobble_motion_events(mevent.state);
935 // This is movement during a connector creation.
936 if ( cc->npoints > 0 ) {
937 m.freeSnapReturnByRef(Inkscape::SnapPreferences::SNAPPOINT_NODE, p,
938 Inkscape::SNAPSOURCE_HANDLE);
939 cc->selection->clear();
940 spcc_connector_set_subsequent_point(cc, p);
941 ret = TRUE;
942 }
943 break;
944 }
945 case SP_CONNECTOR_CONTEXT_REROUTING:
946 {
947 gobble_motion_events(GDK_BUTTON1_MASK);
948 g_assert( SP_IS_PATH(cc->clickeditem));
950 m.freeSnapReturnByRef(Inkscape::SnapPreferences::SNAPPOINT_NODE, p,
951 Inkscape::SNAPSOURCE_HANDLE);
953 // Update the hidden path
954 Geom::Matrix i2d = sp_item_i2d_affine(cc->clickeditem);
955 Geom::Matrix d2i = i2d.inverse();
956 SPPath *path = SP_PATH(cc->clickeditem);
957 SPCurve *curve = path->original_curve ? path->original_curve : path->curve;
958 if (cc->clickedhandle == cc->endpt_handle[0]) {
959 Geom::Point o = cc->endpt_handle[1]->pos;
960 curve->stretch_endpoints(p * d2i, o * d2i);
961 }
962 else {
963 Geom::Point o = cc->endpt_handle[0]->pos;
964 curve->stretch_endpoints(o * d2i, p * d2i);
965 }
966 sp_conn_reroute_path_immediate(path);
968 // Copy this to the temporary visible path
969 cc->red_curve = path->original_curve ?
970 path->original_curve->copy() : path->curve->copy();
971 cc->red_curve->transform(i2d);
973 sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(cc->red_bpath), cc->red_curve);
974 ret = TRUE;
975 break;
976 }
977 case SP_CONNECTOR_CONTEXT_STOP:
978 /* This is perfectly valid */
979 break;
980 default:
981 break;
982 }
983 }
984 else if ( cc->mode == SP_CONNECTOR_CONTEXT_EDITING_MODE )
985 {
986 switch ( cc->state )
987 {
988 case SP_CONNECTOR_CONTEXT_DRAGGING:
989 sp_knot_set_position(cc->selected_handle, p, 0);
990 ret = TRUE;
991 break;
992 case SP_CONNECTOR_CONTEXT_NEWCONNPOINT:
993 sp_knot_set_position(cc->selected_handle, p, 0);
994 ret = TRUE;
995 break;
996 }
997 }
999 return ret;
1000 }
1003 static gint
1004 connector_handle_button_release(SPConnectorContext *const cc, GdkEventButton const &revent)
1005 {
1006 gint ret = FALSE;
1007 SPEventContext *event_context = SP_EVENT_CONTEXT(cc);
1008 if ( revent.button == 1 && !event_context->space_panning ) {
1010 SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(cc);
1011 SPDocument *doc = sp_desktop_document(desktop);
1013 SnapManager &m = desktop->namedview->snap_manager;
1014 m.setup(desktop);
1016 Geom::Point const event_w(revent.x, revent.y);
1018 /* Find desktop coordinates */
1019 Geom::Point p = cc->desktop->w2d(event_w);
1020 if ( cc->mode == SP_CONNECTOR_CONTEXT_DRAWING_MODE )
1021 {
1022 switch (cc->state) {
1023 //case SP_CONNECTOR_CONTEXT_POINT:
1024 case SP_CONNECTOR_CONTEXT_DRAGGING:
1025 {
1026 m.freeSnapReturnByRef(Inkscape::SnapPreferences::SNAPPOINT_NODE, p, Inkscape::SNAPSOURCE_HANDLE);
1028 if (cc->within_tolerance)
1029 {
1030 spcc_connector_finish_segment(cc, p);
1031 return TRUE;
1032 }
1033 // Connector has been created via a drag, end it now.
1034 spcc_connector_set_subsequent_point(cc, p);
1035 spcc_connector_finish_segment(cc, p);
1036 // Test whether we clicked on a connection point
1037 cc->eid = conn_pt_handle_test(cc, p);
1038 if (cc->npoints != 0) {
1039 spcc_connector_finish(cc);
1040 }
1041 cc_set_active_conn(cc, cc->newconn);
1042 cc->state = SP_CONNECTOR_CONTEXT_IDLE;
1043 break;
1044 }
1045 case SP_CONNECTOR_CONTEXT_REROUTING:
1046 {
1047 m.freeSnapReturnByRef(Inkscape::SnapPreferences::SNAPPOINT_NODE, p, Inkscape::SNAPSOURCE_HANDLE);
1048 cc_connector_rerouting_finish(cc, &p);
1050 sp_document_ensure_up_to_date(doc);
1051 cc->state = SP_CONNECTOR_CONTEXT_IDLE;
1052 return TRUE;
1053 break;
1054 }
1055 case SP_CONNECTOR_CONTEXT_STOP:
1056 /* This is allowed, if we just cancelled curve */
1057 break;
1058 default:
1059 break;
1060 }
1061 ret = TRUE;
1062 }
1063 else if ( cc->mode == SP_CONNECTOR_CONTEXT_EDITING_MODE )
1064 {
1065 switch ( cc->state )
1066 {
1067 case SP_CONNECTOR_CONTEXT_DRAGGING:
1069 if (!cc->within_tolerance)
1070 {
1071 m.freeSnapReturnByRef(Inkscape::SnapPreferences::SNAPPOINT_NODE, p, Inkscape::SNAPSOURCE_HANDLE);
1072 sp_knot_set_position(cc->selected_handle, p, 0);
1073 ConnectionPoint& cp = cc->connpthandles[cc->selected_handle];
1074 cp.pos = p * sp_item_dt2i_affine(cc->active_shape);
1075 cc->active_shape->avoidRef->updateConnectionPoint(cp);
1076 }
1078 cc->state = SP_CONNECTOR_CONTEXT_IDLE;
1079 ret = TRUE;
1080 break;
1083 case SP_CONNECTOR_CONTEXT_NEWCONNPOINT:
1084 m.freeSnapReturnByRef(Inkscape::SnapPreferences::SNAPPOINT_NODE, p, Inkscape::SNAPSOURCE_HANDLE);
1086 sp_knot_set_position(cc->selected_handle, p, 0);
1088 ConnectionPoint cp;
1089 cp.type = ConnPointUserDefined;
1090 cp.pos = p * sp_item_dt2i_affine(cc->active_shape);
1091 cp.dir = Avoid::ConnDirAll;
1092 g_object_unref(cc->selected_handle);
1093 cc->active_shape->avoidRef->addConnectionPoint(cp);
1094 sp_document_ensure_up_to_date(doc);
1095 for (ConnectionPointMap::iterator it = cc->connpthandles.begin(); it != cc->connpthandles.end(); ++it)
1096 if (it->second.type == ConnPointUserDefined && it->second.id == cp.id)
1097 {
1098 cc->selected_handle = it->first;
1099 break;
1100 }
1101 cc_select_handle( cc->selected_handle );
1102 cc->state = SP_CONNECTOR_CONTEXT_IDLE;
1103 ret = TRUE;
1104 break;
1105 }
1106 }
1107 }
1110 return ret;
1111 }
1114 static gint
1115 connector_handle_key_press(SPConnectorContext *const cc, guint const keyval)
1116 {
1117 gint ret = FALSE;
1118 /* fixme: */
1119 if ( cc->mode == SP_CONNECTOR_CONTEXT_DRAWING_MODE )
1120 {
1121 switch (keyval) {
1122 case GDK_Return:
1123 case GDK_KP_Enter:
1124 if (cc->npoints != 0) {
1125 spcc_connector_finish(cc);
1126 cc->state = SP_CONNECTOR_CONTEXT_IDLE;
1127 ret = TRUE;
1128 }
1129 break;
1130 case GDK_Escape:
1131 if (cc->state == SP_CONNECTOR_CONTEXT_REROUTING) {
1133 SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(cc);
1134 SPDocument *doc = sp_desktop_document(desktop);
1136 cc_connector_rerouting_finish(cc, NULL);
1138 sp_document_undo(doc);
1140 cc->state = SP_CONNECTOR_CONTEXT_IDLE;
1141 desktop->messageStack()->flash( Inkscape::NORMAL_MESSAGE,
1142 _("Connector endpoint drag cancelled."));
1143 ret = TRUE;
1144 }
1145 else if (cc->npoints != 0) {
1146 // if drawing, cancel, otherwise pass it up for deselecting
1147 cc->state = SP_CONNECTOR_CONTEXT_STOP;
1148 spcc_reset_colors(cc);
1149 ret = TRUE;
1150 }
1151 break;
1152 default:
1153 break;
1154 }
1155 }
1156 else if ( cc->mode == SP_CONNECTOR_CONTEXT_EDITING_MODE )
1157 {
1158 switch ( cc->state )
1159 {
1160 case SP_CONNECTOR_CONTEXT_DRAGGING:
1161 if ( keyval == GDK_Escape )
1162 {
1163 // Cancel connection point dragging
1165 // Obtain original position
1166 ConnectionPoint const& cp = cc->connpthandles[cc->selected_handle];
1167 SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(cc);
1168 const Geom::Matrix& i2doc = sp_item_i2doc_affine(cc->active_shape);
1169 sp_knot_set_position(cc->selected_handle, cp.pos * i2doc * desktop->doc2dt(), 0);
1170 cc->state = SP_CONNECTOR_CONTEXT_IDLE;
1171 desktop->messageStack()->flash( Inkscape::NORMAL_MESSAGE,
1172 _("Connection point drag cancelled."));
1173 ret = TRUE;
1174 }
1175 else if ( keyval == GDK_Return || keyval == GDK_KP_Enter )
1176 {
1177 // Put connection point at current position
1179 SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(cc);
1180 SnapManager &m = desktop->namedview->snap_manager;
1181 m.setup(desktop);
1182 Geom::Point p = cc->selected_handle->pos;
1183 // SPEventContext* event_context = SP_EVENT_CONTEXT( cc );
1185 if (!cc->within_tolerance)
1186 {
1187 m.freeSnapReturnByRef(Inkscape::SnapPreferences::SNAPPOINT_NODE, p, Inkscape::SNAPSOURCE_HANDLE);
1188 sp_knot_set_position(cc->selected_handle, p, 0);
1189 ConnectionPoint& cp = cc->connpthandles[cc->selected_handle];
1190 cp.pos = p * sp_item_dt2i_affine(cc->active_shape);
1191 cc->active_shape->avoidRef->updateConnectionPoint(cp);
1192 }
1194 cc->state = SP_CONNECTOR_CONTEXT_IDLE;
1195 ret = TRUE;
1196 }
1197 break;
1198 case SP_CONNECTOR_CONTEXT_NEWCONNPOINT:
1199 if ( keyval == GDK_Escape )
1200 {
1201 // Just destroy the knot
1202 g_object_unref( cc->selected_handle );
1203 cc->selected_handle = NULL;
1204 cc->state = SP_CONNECTOR_CONTEXT_IDLE;
1205 ret = TRUE;
1206 }
1207 else if ( keyval == GDK_Return || keyval == GDK_KP_Enter )
1208 {
1209 SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(cc);
1210 SPDocument *doc = sp_desktop_document(desktop);
1211 SnapManager &m = desktop->namedview->snap_manager;
1212 m.setup(desktop);
1213 Geom::Point p = cc->selected_handle->pos;
1215 m.freeSnapReturnByRef(Inkscape::SnapPreferences::SNAPPOINT_NODE, p, Inkscape::SNAPSOURCE_HANDLE);
1217 sp_knot_set_position(cc->selected_handle, p, 0);
1219 ConnectionPoint cp;
1220 cp.type = ConnPointUserDefined;
1221 cp.pos = p * sp_item_dt2i_affine(cc->active_shape);
1222 cp.dir = Avoid::ConnDirAll;
1223 g_object_unref(cc->selected_handle);
1224 cc->active_shape->avoidRef->addConnectionPoint(cp);
1225 sp_document_ensure_up_to_date(doc);
1226 for (ConnectionPointMap::iterator it = cc->connpthandles.begin(); it != cc->connpthandles.end(); ++it)
1227 if (it->second.type == ConnPointUserDefined && it->second.id == cp.id)
1228 {
1229 cc->selected_handle = it->first;
1230 break;
1231 }
1232 cc_select_handle( cc->selected_handle );
1233 cc->state = SP_CONNECTOR_CONTEXT_IDLE;
1234 ret = TRUE;
1235 }
1237 break;
1238 case SP_CONNECTOR_CONTEXT_IDLE:
1239 if ( keyval == GDK_Delete && cc->selected_handle )
1240 {
1241 cc->active_shape->avoidRef->deleteConnectionPoint(cc->connpthandles[cc->selected_handle]);
1242 cc->selected_handle = NULL;
1243 ret = TRUE;
1244 }
1246 break;
1247 }
1248 }
1250 return ret;
1251 }
1254 static void
1255 cc_connector_rerouting_finish(SPConnectorContext *const cc, Geom::Point *const p)
1256 {
1257 SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(cc);
1258 SPDocument *doc = sp_desktop_document(desktop);
1260 // Clear the temporary path:
1261 cc->red_curve->reset();
1262 sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(cc->red_bpath), NULL);
1264 if (p != NULL)
1265 {
1266 // Test whether we clicked on a connection point
1267 gchar *shape_label = conn_pt_handle_test(cc, *p);
1269 if (shape_label) {
1270 if (cc->clickedhandle == cc->endpt_handle[0]) {
1271 sp_object_setAttribute(cc->clickeditem,
1272 "inkscape:connection-start",shape_label, false);
1273 }
1274 else {
1275 sp_object_setAttribute(cc->clickeditem,
1276 "inkscape:connection-end",shape_label, false);
1277 }
1278 g_free(shape_label);
1279 }
1280 }
1281 cc->clickeditem->setHidden(false);
1282 sp_conn_reroute_path_immediate(SP_PATH(cc->clickeditem));
1283 cc->clickeditem->updateRepr();
1284 sp_document_done(doc, SP_VERB_CONTEXT_CONNECTOR,
1285 _("Reroute connector"));
1286 cc_set_active_conn(cc, cc->clickeditem);
1287 }
1290 static void
1291 spcc_reset_colors(SPConnectorContext *cc)
1292 {
1293 /* Red */
1294 cc->red_curve->reset();
1295 sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(cc->red_bpath), NULL);
1297 cc->green_curve->reset();
1298 cc->npoints = 0;
1299 }
1302 static void
1303 spcc_connector_set_initial_point(SPConnectorContext *const cc, Geom::Point const p)
1304 {
1305 g_assert( cc->npoints == 0 );
1307 cc->p[0] = p;
1308 cc->p[1] = p;
1309 cc->npoints = 2;
1310 sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(cc->red_bpath), NULL);
1311 }
1314 static void
1315 spcc_connector_set_subsequent_point(SPConnectorContext *const cc, Geom::Point const p)
1316 {
1317 g_assert( cc->npoints != 0 );
1319 SPDesktop *dt = cc->desktop;
1320 Geom::Point o = dt->dt2doc(cc->p[0]);
1321 Geom::Point d = dt->dt2doc(p);
1322 Avoid::Point src(o[Geom::X], o[Geom::Y]);
1323 Avoid::Point dst(d[Geom::X], d[Geom::Y]);
1325 if (!cc->newConnRef) {
1326 Avoid::Router *router = sp_desktop_document(dt)->router;
1327 cc->newConnRef = new Avoid::ConnRef(router);
1328 cc->newConnRef->setEndpoint(Avoid::VertID::src, src);
1329 if (cc->isOrthogonal)
1330 cc->newConnRef->setRoutingType(Avoid::ConnType_Orthogonal);
1331 else
1332 cc->newConnRef->setRoutingType(Avoid::ConnType_PolyLine);
1333 }
1334 // Set new endpoint.
1335 cc->newConnRef->setEndpoint(Avoid::VertID::tar, dst);
1336 // Immediately generate new routes for connector.
1337 cc->newConnRef->makePathInvalid();
1338 cc->newConnRef->router()->processTransaction();
1339 // Recreate curve from libavoid route.
1340 recreateCurve( cc->red_curve, cc->newConnRef, cc->curvature );
1341 cc->red_curve->transform(dt->doc2dt());
1342 sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(cc->red_bpath), cc->red_curve);
1343 }
1346 /**
1347 * Concats red, blue and green.
1348 * If any anchors are defined, process these, optionally removing curves from white list
1349 * Invoke _flush_white to write result back to object.
1350 */
1351 static void
1352 spcc_concat_colors_and_flush(SPConnectorContext *cc)
1353 {
1354 SPCurve *c = cc->green_curve;
1355 cc->green_curve = new SPCurve();
1357 cc->red_curve->reset();
1358 sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(cc->red_bpath), NULL);
1360 if (c->is_empty()) {
1361 c->unref();
1362 return;
1363 }
1365 spcc_flush_white(cc, c);
1367 c->unref();
1368 }
1371 /*
1372 * Flushes white curve(s) and additional curve into object
1373 *
1374 * No cleaning of colored curves - this has to be done by caller
1375 * No rereading of white data, so if you cannot rely on ::modified, do it in caller
1376 *
1377 */
1379 static void
1380 spcc_flush_white(SPConnectorContext *cc, SPCurve *gc)
1381 {
1382 SPCurve *c;
1384 if (gc) {
1385 c = gc;
1386 c->ref();
1387 } else {
1388 return;
1389 }
1391 /* Now we have to go back to item coordinates at last */
1392 c->transform(SP_EVENT_CONTEXT_DESKTOP(cc)->dt2doc());
1394 SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(cc);
1395 SPDocument *doc = sp_desktop_document(desktop);
1396 Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc);
1398 if ( c && !c->is_empty() ) {
1399 /* We actually have something to write */
1401 Inkscape::XML::Node *repr = xml_doc->createElement("svg:path");
1402 /* Set style */
1403 sp_desktop_apply_style_tool(desktop, repr, "/tools/connector", false);
1405 gchar *str = sp_svg_write_path( c->get_pathvector() );
1406 g_assert( str != NULL );
1407 repr->setAttribute("d", str);
1408 g_free(str);
1410 /* Attach repr */
1411 cc->newconn = SP_ITEM(desktop->currentLayer()->appendChildRepr(repr));
1412 cc->newconn->transform = sp_item_i2doc_affine(SP_ITEM(desktop->currentLayer())).inverse();
1414 bool connection = false;
1415 sp_object_setAttribute(cc->newconn, "inkscape:connector-type",
1416 cc->isOrthogonal ? "orthogonal" : "polyline", false);
1417 sp_object_setAttribute(cc->newconn, "inkscape:connector-curvature",
1418 Glib::Ascii::dtostr(cc->curvature).c_str(), false);
1419 if (cc->sid)
1420 {
1421 sp_object_setAttribute(cc->newconn, "inkscape:connection-start",
1422 cc->sid, false);
1423 connection = true;
1424 }
1426 if (cc->eid)
1427 {
1428 sp_object_setAttribute(cc->newconn, "inkscape:connection-end",
1429 cc->eid, false);
1430 connection = true;
1431 }
1432 // Process pending updates.
1433 cc->newconn->updateRepr();
1434 sp_document_ensure_up_to_date(doc);
1436 if (connection) {
1437 // Adjust endpoints to shape edge.
1438 sp_conn_reroute_path_immediate(SP_PATH(cc->newconn));
1439 cc->newconn->updateRepr();
1440 }
1442 // Only set the selection after we are finished with creating the attributes of
1443 // the connector. Otherwise, the selection change may alter the defaults for
1444 // values like curvature in the connector context, preventing subsequent lookup
1445 // of their original values.
1446 cc->selection->set(repr);
1447 Inkscape::GC::release(repr);
1448 }
1450 c->unref();
1452 sp_document_done(doc, SP_VERB_CONTEXT_CONNECTOR, _("Create connector"));
1453 }
1456 static void
1457 spcc_connector_finish_segment(SPConnectorContext *const cc, Geom::Point const /*p*/)
1458 {
1459 if (!cc->red_curve->is_empty()) {
1460 cc->green_curve->append_continuous(cc->red_curve, 0.0625);
1462 cc->p[0] = cc->p[3];
1463 cc->p[1] = cc->p[4];
1464 cc->npoints = 2;
1466 cc->red_curve->reset();
1467 }
1468 }
1471 static void
1472 spcc_connector_finish(SPConnectorContext *const cc)
1473 {
1474 SPDesktop *const desktop = cc->desktop;
1475 desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Finishing connector"));
1477 cc->red_curve->reset();
1478 spcc_concat_colors_and_flush(cc);
1480 cc->npoints = 0;
1482 if (cc->newConnRef) {
1483 cc->newConnRef->removeFromGraph();
1484 delete cc->newConnRef;
1485 cc->newConnRef = NULL;
1486 }
1487 }
1490 static gboolean
1491 cc_generic_knot_handler(SPCanvasItem *, GdkEvent *event, SPKnot *knot)
1492 {
1493 g_assert (knot != NULL);
1495 g_object_ref(knot);
1497 SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(
1498 knot->desktop->event_context);
1500 gboolean consumed = FALSE;
1502 gchar* knot_tip = knot->tip ? knot->tip : cc->knot_tip;
1503 switch (event->type) {
1504 case GDK_ENTER_NOTIFY:
1505 sp_knot_set_flag(knot, SP_KNOT_MOUSEOVER, TRUE);
1507 cc->active_handle = knot;
1508 if (knot_tip)
1509 {
1510 knot->desktop->event_context->defaultMessageContext()->set(
1511 Inkscape::NORMAL_MESSAGE, knot_tip);
1512 }
1514 consumed = TRUE;
1515 break;
1516 case GDK_LEAVE_NOTIFY:
1517 sp_knot_set_flag(knot, SP_KNOT_MOUSEOVER, FALSE);
1519 cc->active_handle = NULL;
1521 if (knot_tip) {
1522 knot->desktop->event_context->defaultMessageContext()->clear();
1523 }
1525 consumed = TRUE;
1526 break;
1527 default:
1528 break;
1529 }
1531 g_object_unref(knot);
1533 return consumed;
1534 }
1537 static gboolean
1538 endpt_handler(SPKnot */*knot*/, GdkEvent *event, SPConnectorContext *cc)
1539 {
1540 g_assert( SP_IS_CONNECTOR_CONTEXT(cc) );
1542 gboolean consumed = FALSE;
1544 switch (event->type) {
1545 case GDK_BUTTON_PRESS:
1546 g_assert( (cc->active_handle == cc->endpt_handle[0]) ||
1547 (cc->active_handle == cc->endpt_handle[1]) );
1548 if (cc->state == SP_CONNECTOR_CONTEXT_IDLE) {
1549 cc->clickeditem = cc->active_conn;
1550 cc->clickedhandle = cc->active_handle;
1551 cc_clear_active_conn(cc);
1552 cc->state = SP_CONNECTOR_CONTEXT_REROUTING;
1554 // Disconnect from attached shape
1555 unsigned ind = (cc->active_handle == cc->endpt_handle[0]) ? 0 : 1;
1556 sp_conn_end_detach(cc->clickeditem, ind);
1558 Geom::Point origin;
1559 if (cc->clickedhandle == cc->endpt_handle[0]) {
1560 origin = cc->endpt_handle[1]->pos;
1561 }
1562 else {
1563 origin = cc->endpt_handle[0]->pos;
1564 }
1566 // Show the red path for dragging.
1567 cc->red_curve = SP_PATH(cc->clickeditem)->original_curve ? SP_PATH(cc->clickeditem)->original_curve->copy() : SP_PATH(cc->clickeditem)->curve->copy();
1568 Geom::Matrix i2d = sp_item_i2d_affine(cc->clickeditem);
1569 cc->red_curve->transform(i2d);
1570 sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(cc->red_bpath), cc->red_curve);
1572 cc->clickeditem->setHidden(true);
1574 // The rest of the interaction rerouting the connector is
1575 // handled by the context root handler.
1576 consumed = TRUE;
1577 }
1578 break;
1579 default:
1580 break;
1581 }
1583 return consumed;
1584 }
1586 static void cc_active_shape_add_knot(SPDesktop* desktop, SPItem* item, ConnectionPointMap &cphandles, ConnectionPoint& cp)
1587 {
1588 SPKnot *knot = sp_knot_new(desktop, 0);
1590 knot->setShape(SP_KNOT_SHAPE_SQUARE);
1591 knot->setSize(8);
1592 knot->setAnchor(GTK_ANCHOR_CENTER);
1593 knot->setFill(0xffffff00, 0xff0000ff, 0xff0000ff);
1594 sp_knot_update_ctrl(knot);
1596 // We don't want to use the standard knot handler.
1597 g_signal_handler_disconnect(G_OBJECT(knot->item),
1598 knot->_event_handler_id);
1599 knot->_event_handler_id = 0;
1601 gtk_signal_connect(GTK_OBJECT(knot->item), "event",
1602 GTK_SIGNAL_FUNC(cc_generic_knot_handler), knot);
1603 sp_knot_set_position(knot, item->avoidRef->getConnectionPointPos(cp.type, cp.id) * desktop->doc2dt(), 0);
1604 sp_knot_show(knot);
1605 cphandles[knot] = cp;
1606 }
1608 static void cc_set_active_shape(SPConnectorContext *cc, SPItem *item)
1609 {
1610 g_assert(item != NULL );
1612 std::map<int, ConnectionPoint>* connpts = &item->avoidRef->connection_points;
1614 if (cc->active_shape != item)
1615 {
1616 // The active shape has changed
1617 // Rebuild everything
1618 cc->active_shape = item;
1619 // Remove existing active shape listeners
1620 if (cc->active_shape_repr) {
1621 sp_repr_remove_listener_by_data(cc->active_shape_repr, cc);
1622 Inkscape::GC::release(cc->active_shape_repr);
1624 sp_repr_remove_listener_by_data(cc->active_shape_layer_repr, cc);
1625 Inkscape::GC::release(cc->active_shape_layer_repr);
1626 }
1628 // Listen in case the active shape changes
1629 cc->active_shape_repr = SP_OBJECT_REPR(item);
1630 if (cc->active_shape_repr) {
1631 Inkscape::GC::anchor(cc->active_shape_repr);
1632 sp_repr_add_listener(cc->active_shape_repr, &shape_repr_events, cc);
1634 cc->active_shape_layer_repr = cc->active_shape_repr->parent();
1635 Inkscape::GC::anchor(cc->active_shape_layer_repr);
1636 sp_repr_add_listener(cc->active_shape_layer_repr, &layer_repr_events, cc);
1637 }
1640 // Set the connection points.
1641 if ( cc->connpthandles.size() )
1642 // destroy the old list
1643 while (! cc->connpthandles.empty() )
1644 {
1645 g_object_unref(cc->connpthandles.begin()->first);
1646 cc->connpthandles.erase(cc->connpthandles.begin());
1647 }
1648 // build the new one
1649 if ( connpts->size() )
1650 for (std::map<int, ConnectionPoint>::iterator it = connpts->begin(); it != connpts->end(); ++it)
1651 cc_active_shape_add_knot(cc->desktop, item, cc->connpthandles, it->second);
1653 // Also add default connection points
1654 // For now, only centre default connection point will
1655 // be available
1656 ConnectionPoint centre;
1657 centre.type = ConnPointDefault;
1658 centre.id = ConnPointPosCC;
1659 cc_active_shape_add_knot(cc->desktop, item, cc->connpthandles, centre);
1660 }
1661 else
1662 {
1663 // The active shape didn't change
1664 // Update only the connection point knots
1666 // Ensure the item's connection_points map
1667 // has been updated
1668 sp_document_ensure_up_to_date(SP_OBJECT_DOCUMENT(item));
1670 std::set<int> seen;
1671 for ( ConnectionPointMap::iterator it = cc->connpthandles.begin(); it != cc->connpthandles.end() ;)
1672 {
1673 bool removed = false;
1674 if ( it->second.type == ConnPointUserDefined )
1675 {
1676 std::map<int, ConnectionPoint>::iterator p = connpts->find(it->second.id);
1677 if (p != connpts->end())
1678 {
1679 if ( it->second != p->second )
1680 // Connection point position has changed
1681 // Update knot position
1682 sp_knot_set_position(it->first,
1683 item->avoidRef->getConnectionPointPos(it->second.type, it->second.id) * cc->desktop->doc2dt(), 0);
1684 seen.insert(it->second.id);
1685 sp_knot_show(it->first);
1686 }
1687 else
1688 {
1689 // This connection point does no longer exist,
1690 // remove the knot
1691 ConnectionPointMap::iterator curr = it;
1692 ++it;
1693 g_object_unref( curr->first );
1694 cc->connpthandles.erase(curr);
1695 removed = true;
1696 }
1697 }
1698 else
1699 {
1700 // It's a default connection point
1701 // Just make sure it's position is correct
1702 sp_knot_set_position(it->first,
1703 item->avoidRef->getConnectionPointPos(it->second.type, it->second.id) * cc->desktop->doc2dt(), 0);
1704 sp_knot_show(it->first);
1706 }
1707 if ( !removed )
1708 ++it;
1709 }
1710 // Add knots for new connection points.
1711 if (connpts->size())
1712 for ( std::map<int, ConnectionPoint>::iterator it = connpts->begin(); it != connpts->end(); ++it )
1713 if ( seen.find(it->first) == seen.end() )
1714 // A new connection point has been added
1715 // to the shape. Add a knot for it.
1716 cc_active_shape_add_knot(cc->desktop, item, cc->connpthandles, it->second);
1717 }
1718 }
1721 static void
1722 cc_set_active_conn(SPConnectorContext *cc, SPItem *item)
1723 {
1724 g_assert( SP_IS_PATH(item) );
1726 SPCurve *curve = SP_PATH(item)->original_curve ? SP_PATH(item)->original_curve : SP_PATH(item)->curve;
1727 Geom::Matrix i2d = sp_item_i2d_affine(item);
1729 if (cc->active_conn == item)
1730 {
1731 // Just adjust handle positions.
1732 Geom::Point startpt = *(curve->first_point()) * i2d;
1733 sp_knot_set_position(cc->endpt_handle[0], startpt, 0);
1735 Geom::Point endpt = *(curve->last_point()) * i2d;
1736 sp_knot_set_position(cc->endpt_handle[1], endpt, 0);
1738 return;
1739 }
1741 cc->active_conn = item;
1743 // Remove existing active conn listeners
1744 if (cc->active_conn_repr) {
1745 sp_repr_remove_listener_by_data(cc->active_conn_repr, cc);
1746 Inkscape::GC::release(cc->active_conn_repr);
1747 cc->active_conn_repr = NULL;
1748 }
1750 // Listen in case the active conn changes
1751 cc->active_conn_repr = SP_OBJECT_REPR(item);
1752 if (cc->active_conn_repr) {
1753 Inkscape::GC::anchor(cc->active_conn_repr);
1754 sp_repr_add_listener(cc->active_conn_repr, &shape_repr_events, cc);
1755 }
1757 for (int i = 0; i < 2; ++i) {
1759 // Create the handle if it doesn't exist
1760 if ( cc->endpt_handle[i] == NULL ) {
1761 SPKnot *knot = sp_knot_new(cc->desktop,
1762 _("<b>Connector endpoint</b>: drag to reroute or connect to new shapes"));
1764 knot->setShape(SP_KNOT_SHAPE_SQUARE);
1765 knot->setSize(7);
1766 knot->setAnchor(GTK_ANCHOR_CENTER);
1767 knot->setFill(0xffffff00, 0xff0000ff, 0xff0000ff);
1768 knot->setStroke(0x000000ff, 0x000000ff, 0x000000ff);
1769 sp_knot_update_ctrl(knot);
1771 // We don't want to use the standard knot handler,
1772 // since we don't want this knot to be draggable.
1773 g_signal_handler_disconnect(G_OBJECT(knot->item),
1774 knot->_event_handler_id);
1775 knot->_event_handler_id = 0;
1777 gtk_signal_connect(GTK_OBJECT(knot->item), "event",
1778 GTK_SIGNAL_FUNC(cc_generic_knot_handler), knot);
1780 cc->endpt_handle[i] = knot;
1781 }
1783 // Remove any existing handlers
1784 if (cc->endpt_handler_id[i]) {
1785 g_signal_handlers_disconnect_by_func(
1786 G_OBJECT(cc->endpt_handle[i]->item),
1787 (void*)G_CALLBACK(endpt_handler), (gpointer) cc );
1788 cc->endpt_handler_id[i] = 0;
1789 }
1791 // Setup handlers for connector endpoints, this is
1792 // is as 'after' so that cc_generic_knot_handler is
1793 // triggered first for any endpoint.
1794 cc->endpt_handler_id[i] = g_signal_connect_after(
1795 G_OBJECT(cc->endpt_handle[i]->item), "event",
1796 G_CALLBACK(endpt_handler), cc);
1797 }
1799 Geom::Point startpt = *(curve->first_point()) * i2d;
1800 sp_knot_set_position(cc->endpt_handle[0], startpt, 0);
1802 Geom::Point endpt = *(curve->last_point()) * i2d;
1803 sp_knot_set_position(cc->endpt_handle[1], endpt, 0);
1805 sp_knot_show(cc->endpt_handle[0]);
1806 sp_knot_show(cc->endpt_handle[1]);
1807 }
1809 void cc_create_connection_point(SPConnectorContext* cc)
1810 {
1811 if (cc->active_shape && cc->state == SP_CONNECTOR_CONTEXT_IDLE)
1812 {
1813 if (cc->selected_handle)
1814 {
1815 cc_deselect_handle( cc->selected_handle );
1816 }
1817 SPKnot *knot = sp_knot_new(cc->desktop, 0);
1818 // We do not process events on this knot.
1819 g_signal_handler_disconnect(G_OBJECT(knot->item),
1820 knot->_event_handler_id);
1821 knot->_event_handler_id = 0;
1823 cc_select_handle( knot );
1824 cc->selected_handle = knot;
1825 sp_knot_show(cc->selected_handle);
1826 cc->state = SP_CONNECTOR_CONTEXT_NEWCONNPOINT;
1827 }
1828 }
1830 void cc_remove_connection_point(SPConnectorContext* cc)
1831 {
1832 if (cc->selected_handle && cc->state == SP_CONNECTOR_CONTEXT_IDLE )
1833 {
1834 cc->active_shape->avoidRef->deleteConnectionPoint(cc->connpthandles[cc->selected_handle]);
1835 cc->selected_handle = NULL;
1836 }
1837 }
1839 static bool cc_item_is_shape(SPItem *item)
1840 {
1841 if (SP_IS_PATH(item)) {
1842 SPCurve *curve = (SP_SHAPE(item))->curve;
1843 if ( curve && !(curve->is_closed()) ) {
1844 // Open paths are connectors.
1845 return false;
1846 }
1847 }
1848 else if (SP_IS_TEXT(item) || SP_IS_FLOWTEXT(item)) {
1849 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1850 if (prefs->getBool("/tools/connector/ignoretext", true)) {
1851 // Don't count text as a shape we can connect connector to.
1852 return false;
1853 }
1854 }
1855 return true;
1856 }
1859 bool cc_item_is_connector(SPItem *item)
1860 {
1861 if (SP_IS_PATH(item)) {
1862 if (SP_PATH(item)->connEndPair.isAutoRoutingConn()) {
1863 g_assert( SP_PATH(item)->original_curve ? !(SP_PATH(item)->original_curve->is_closed()) : !(SP_PATH(item)->curve->is_closed()) );
1864 return true;
1865 }
1866 }
1867 return false;
1868 }
1871 void cc_selection_set_avoid(bool const set_avoid)
1872 {
1873 SPDesktop *desktop = inkscape_active_desktop();
1874 if (desktop == NULL) {
1875 return;
1876 }
1878 SPDocument *document = sp_desktop_document(desktop);
1880 Inkscape::Selection *selection = sp_desktop_selection(desktop);
1882 GSList *l = (GSList *) selection->itemList();
1884 int changes = 0;
1886 while (l) {
1887 SPItem *item = (SPItem *) l->data;
1889 char const *value = (set_avoid) ? "true" : NULL;
1891 if (cc_item_is_shape(item)) {
1892 sp_object_setAttribute(item, "inkscape:connector-avoid",
1893 value, false);
1894 item->avoidRef->handleSettingChange();
1895 changes++;
1896 }
1898 l = l->next;
1899 }
1901 if (changes == 0) {
1902 desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE,
1903 _("Select <b>at least one non-connector object</b>."));
1904 return;
1905 }
1907 char *event_desc = (set_avoid) ?
1908 _("Make connectors avoid selected objects") :
1909 _("Make connectors ignore selected objects");
1910 sp_document_done(document, SP_VERB_CONTEXT_CONNECTOR, event_desc);
1911 }
1914 static void
1915 cc_selection_changed(Inkscape::Selection *selection, gpointer data)
1916 {
1917 SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(data);
1918 //SPEventContext *ec = SP_EVENT_CONTEXT(cc);
1920 SPItem *item = selection->singleItem();
1922 if (cc->active_conn == item)
1923 {
1924 // Nothing to change.
1925 return;
1926 }
1927 if (item == NULL)
1928 {
1929 cc_clear_active_conn(cc);
1930 return;
1931 }
1933 if (cc_item_is_connector(item)) {
1934 cc_set_active_conn(cc, item);
1935 }
1936 }
1939 static void
1940 shape_event_attr_deleted(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node *child,
1941 Inkscape::XML::Node */*ref*/, gpointer data)
1942 {
1943 g_assert(data);
1944 SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(data);
1946 if (child == cc->active_shape_repr) {
1947 // The active shape has been deleted. Clear active shape.
1948 cc_clear_active_shape(cc);
1949 }
1950 }
1953 static void
1954 shape_event_attr_changed(Inkscape::XML::Node *repr, gchar const *name,
1955 gchar const */*old_value*/, gchar const */*new_value*/,
1956 bool /*is_interactive*/, gpointer data)
1957 {
1958 g_assert(data);
1959 SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(data);
1961 // Look for changes that result in onscreen movement.
1962 if (!strcmp(name, "d") || !strcmp(name, "x") || !strcmp(name, "y") ||
1963 !strcmp(name, "width") || !strcmp(name, "height") ||
1964 !strcmp(name, "transform"))
1965 {
1966 if (repr == cc->active_shape_repr) {
1967 // Active shape has moved. Clear active shape.
1968 cc_clear_active_shape(cc);
1969 }
1970 else if (repr == cc->active_conn_repr) {
1971 // The active conn has been moved.
1972 // Set it again, which just sets new handle positions.
1973 cc_set_active_conn(cc, cc->active_conn);
1974 }
1975 }
1976 else
1977 if ( !strcmp(name, "inkscape:connection-points") )
1978 if (repr == cc->active_shape_repr)
1979 // The connection points of the active shape
1980 // have changed. Update them.
1981 cc_set_active_shape(cc, cc->active_shape);
1982 }
1985 /*
1986 Local Variables:
1987 mode:c++
1988 c-file-style:"stroustrup"
1989 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
1990 indent-tabs-mode:nil
1991 fill-column:99
1992 End:
1993 */
1994 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :