b61c00df6a9a15968c82be0f0ee46f745f35ddee
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(p, Inkscape::SNAPSOURCE_OTHER_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(p, Inkscape::SNAPSOURCE_OTHER_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(p, Inkscape::SNAPSOURCE_OTHER_HANDLE);
938 cc->selection->clear();
939 spcc_connector_set_subsequent_point(cc, p);
940 ret = TRUE;
941 }
942 break;
943 }
944 case SP_CONNECTOR_CONTEXT_REROUTING:
945 {
946 gobble_motion_events(GDK_BUTTON1_MASK);
947 g_assert( SP_IS_PATH(cc->clickeditem));
949 m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_OTHER_HANDLE);
951 // Update the hidden path
952 Geom::Matrix i2d = sp_item_i2d_affine(cc->clickeditem);
953 Geom::Matrix d2i = i2d.inverse();
954 SPPath *path = SP_PATH(cc->clickeditem);
955 SPCurve *curve = path->original_curve ? path->original_curve : path->curve;
956 if (cc->clickedhandle == cc->endpt_handle[0]) {
957 Geom::Point o = cc->endpt_handle[1]->pos;
958 curve->stretch_endpoints(p * d2i, o * d2i);
959 }
960 else {
961 Geom::Point o = cc->endpt_handle[0]->pos;
962 curve->stretch_endpoints(o * d2i, p * d2i);
963 }
964 sp_conn_reroute_path_immediate(path);
966 // Copy this to the temporary visible path
967 cc->red_curve = path->original_curve ?
968 path->original_curve->copy() : path->curve->copy();
969 cc->red_curve->transform(i2d);
971 sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(cc->red_bpath), cc->red_curve);
972 ret = TRUE;
973 break;
974 }
975 case SP_CONNECTOR_CONTEXT_STOP:
976 /* This is perfectly valid */
977 break;
978 default:
979 if (!sp_event_context_knot_mouseover(cc)) {
980 m.preSnap(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_OTHER_HANDLE));
981 }
982 break;
983 }
984 }
985 else if ( cc->mode == SP_CONNECTOR_CONTEXT_EDITING_MODE )
986 {
987 switch ( cc->state )
988 {
989 case SP_CONNECTOR_CONTEXT_DRAGGING:
990 sp_knot_set_position(cc->selected_handle, p, 0);
991 ret = TRUE;
992 break;
993 case SP_CONNECTOR_CONTEXT_NEWCONNPOINT:
994 sp_knot_set_position(cc->selected_handle, p, 0);
995 ret = TRUE;
996 break;
997 }
998 }
1000 return ret;
1001 }
1004 static gint
1005 connector_handle_button_release(SPConnectorContext *const cc, GdkEventButton const &revent)
1006 {
1007 gint ret = FALSE;
1008 SPEventContext *event_context = SP_EVENT_CONTEXT(cc);
1009 if ( revent.button == 1 && !event_context->space_panning ) {
1011 SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(cc);
1012 SPDocument *doc = sp_desktop_document(desktop);
1014 SnapManager &m = desktop->namedview->snap_manager;
1015 m.setup(desktop);
1017 Geom::Point const event_w(revent.x, revent.y);
1019 /* Find desktop coordinates */
1020 Geom::Point p = cc->desktop->w2d(event_w);
1021 if ( cc->mode == SP_CONNECTOR_CONTEXT_DRAWING_MODE )
1022 {
1023 switch (cc->state) {
1024 //case SP_CONNECTOR_CONTEXT_POINT:
1025 case SP_CONNECTOR_CONTEXT_DRAGGING:
1026 {
1027 m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_OTHER_HANDLE);
1029 if (cc->within_tolerance)
1030 {
1031 spcc_connector_finish_segment(cc, p);
1032 return TRUE;
1033 }
1034 // Connector has been created via a drag, end it now.
1035 spcc_connector_set_subsequent_point(cc, p);
1036 spcc_connector_finish_segment(cc, p);
1037 // Test whether we clicked on a connection point
1038 cc->eid = conn_pt_handle_test(cc, p);
1039 if (cc->npoints != 0) {
1040 spcc_connector_finish(cc);
1041 }
1042 cc_set_active_conn(cc, cc->newconn);
1043 cc->state = SP_CONNECTOR_CONTEXT_IDLE;
1044 break;
1045 }
1046 case SP_CONNECTOR_CONTEXT_REROUTING:
1047 {
1048 m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_OTHER_HANDLE);
1049 cc_connector_rerouting_finish(cc, &p);
1051 sp_document_ensure_up_to_date(doc);
1052 cc->state = SP_CONNECTOR_CONTEXT_IDLE;
1053 return TRUE;
1054 break;
1055 }
1056 case SP_CONNECTOR_CONTEXT_STOP:
1057 /* This is allowed, if we just cancelled curve */
1058 break;
1059 default:
1060 break;
1061 }
1062 ret = TRUE;
1063 }
1064 else if ( cc->mode == SP_CONNECTOR_CONTEXT_EDITING_MODE )
1065 {
1066 switch ( cc->state )
1067 {
1068 case SP_CONNECTOR_CONTEXT_DRAGGING:
1070 if (!cc->within_tolerance)
1071 {
1072 m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_OTHER_HANDLE);
1073 sp_knot_set_position(cc->selected_handle, p, 0);
1074 ConnectionPoint& cp = cc->connpthandles[cc->selected_handle];
1075 cp.pos = p * sp_item_dt2i_affine(cc->active_shape);
1076 cc->active_shape->avoidRef->updateConnectionPoint(cp);
1077 }
1079 cc->state = SP_CONNECTOR_CONTEXT_IDLE;
1080 ret = TRUE;
1081 break;
1084 case SP_CONNECTOR_CONTEXT_NEWCONNPOINT:
1085 m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_OTHER_HANDLE);
1087 sp_knot_set_position(cc->selected_handle, p, 0);
1089 ConnectionPoint cp;
1090 cp.type = ConnPointUserDefined;
1091 cp.pos = p * sp_item_dt2i_affine(cc->active_shape);
1092 cp.dir = Avoid::ConnDirAll;
1093 g_object_unref(cc->selected_handle);
1094 cc->active_shape->avoidRef->addConnectionPoint(cp);
1095 sp_document_ensure_up_to_date(doc);
1096 for (ConnectionPointMap::iterator it = cc->connpthandles.begin(); it != cc->connpthandles.end(); ++it)
1097 if (it->second.type == ConnPointUserDefined && it->second.id == cp.id)
1098 {
1099 cc->selected_handle = it->first;
1100 break;
1101 }
1102 cc_select_handle( cc->selected_handle );
1103 cc->state = SP_CONNECTOR_CONTEXT_IDLE;
1104 ret = TRUE;
1105 break;
1106 }
1107 }
1108 }
1111 return ret;
1112 }
1115 static gint
1116 connector_handle_key_press(SPConnectorContext *const cc, guint const keyval)
1117 {
1118 gint ret = FALSE;
1119 /* fixme: */
1120 if ( cc->mode == SP_CONNECTOR_CONTEXT_DRAWING_MODE )
1121 {
1122 switch (keyval) {
1123 case GDK_Return:
1124 case GDK_KP_Enter:
1125 if (cc->npoints != 0) {
1126 spcc_connector_finish(cc);
1127 cc->state = SP_CONNECTOR_CONTEXT_IDLE;
1128 ret = TRUE;
1129 }
1130 break;
1131 case GDK_Escape:
1132 if (cc->state == SP_CONNECTOR_CONTEXT_REROUTING) {
1134 SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(cc);
1135 SPDocument *doc = sp_desktop_document(desktop);
1137 cc_connector_rerouting_finish(cc, NULL);
1139 sp_document_undo(doc);
1141 cc->state = SP_CONNECTOR_CONTEXT_IDLE;
1142 desktop->messageStack()->flash( Inkscape::NORMAL_MESSAGE,
1143 _("Connector endpoint drag cancelled."));
1144 ret = TRUE;
1145 }
1146 else if (cc->npoints != 0) {
1147 // if drawing, cancel, otherwise pass it up for deselecting
1148 cc->state = SP_CONNECTOR_CONTEXT_STOP;
1149 spcc_reset_colors(cc);
1150 ret = TRUE;
1151 }
1152 break;
1153 default:
1154 break;
1155 }
1156 }
1157 else if ( cc->mode == SP_CONNECTOR_CONTEXT_EDITING_MODE )
1158 {
1159 switch ( cc->state )
1160 {
1161 case SP_CONNECTOR_CONTEXT_DRAGGING:
1162 if ( keyval == GDK_Escape )
1163 {
1164 // Cancel connection point dragging
1166 // Obtain original position
1167 ConnectionPoint const& cp = cc->connpthandles[cc->selected_handle];
1168 SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(cc);
1169 const Geom::Matrix& i2doc = sp_item_i2doc_affine(cc->active_shape);
1170 sp_knot_set_position(cc->selected_handle, cp.pos * i2doc * desktop->doc2dt(), 0);
1171 cc->state = SP_CONNECTOR_CONTEXT_IDLE;
1172 desktop->messageStack()->flash( Inkscape::NORMAL_MESSAGE,
1173 _("Connection point drag cancelled."));
1174 ret = TRUE;
1175 }
1176 else if ( keyval == GDK_Return || keyval == GDK_KP_Enter )
1177 {
1178 // Put connection point at current position
1180 SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(cc);
1181 SnapManager &m = desktop->namedview->snap_manager;
1182 m.setup(desktop);
1183 Geom::Point p = cc->selected_handle->pos;
1184 // SPEventContext* event_context = SP_EVENT_CONTEXT( cc );
1186 if (!cc->within_tolerance)
1187 {
1188 m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_OTHER_HANDLE);
1189 sp_knot_set_position(cc->selected_handle, p, 0);
1190 ConnectionPoint& cp = cc->connpthandles[cc->selected_handle];
1191 cp.pos = p * sp_item_dt2i_affine(cc->active_shape);
1192 cc->active_shape->avoidRef->updateConnectionPoint(cp);
1193 }
1195 cc->state = SP_CONNECTOR_CONTEXT_IDLE;
1196 ret = TRUE;
1197 }
1198 break;
1199 case SP_CONNECTOR_CONTEXT_NEWCONNPOINT:
1200 if ( keyval == GDK_Escape )
1201 {
1202 // Just destroy the knot
1203 g_object_unref( cc->selected_handle );
1204 cc->selected_handle = NULL;
1205 cc->state = SP_CONNECTOR_CONTEXT_IDLE;
1206 ret = TRUE;
1207 }
1208 else if ( keyval == GDK_Return || keyval == GDK_KP_Enter )
1209 {
1210 SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(cc);
1211 SPDocument *doc = sp_desktop_document(desktop);
1212 SnapManager &m = desktop->namedview->snap_manager;
1213 m.setup(desktop);
1214 Geom::Point p = cc->selected_handle->pos;
1216 m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_OTHER_HANDLE);
1218 sp_knot_set_position(cc->selected_handle, p, 0);
1220 ConnectionPoint cp;
1221 cp.type = ConnPointUserDefined;
1222 cp.pos = p * sp_item_dt2i_affine(cc->active_shape);
1223 cp.dir = Avoid::ConnDirAll;
1224 g_object_unref(cc->selected_handle);
1225 cc->active_shape->avoidRef->addConnectionPoint(cp);
1226 sp_document_ensure_up_to_date(doc);
1227 for (ConnectionPointMap::iterator it = cc->connpthandles.begin(); it != cc->connpthandles.end(); ++it)
1228 if (it->second.type == ConnPointUserDefined && it->second.id == cp.id)
1229 {
1230 cc->selected_handle = it->first;
1231 break;
1232 }
1233 cc_select_handle( cc->selected_handle );
1234 cc->state = SP_CONNECTOR_CONTEXT_IDLE;
1235 ret = TRUE;
1236 }
1238 break;
1239 case SP_CONNECTOR_CONTEXT_IDLE:
1240 if ( keyval == GDK_Delete && cc->selected_handle )
1241 {
1242 cc->active_shape->avoidRef->deleteConnectionPoint(cc->connpthandles[cc->selected_handle]);
1243 cc->selected_handle = NULL;
1244 ret = TRUE;
1245 }
1247 break;
1248 }
1249 }
1251 return ret;
1252 }
1255 static void
1256 cc_connector_rerouting_finish(SPConnectorContext *const cc, Geom::Point *const p)
1257 {
1258 SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(cc);
1259 SPDocument *doc = sp_desktop_document(desktop);
1261 // Clear the temporary path:
1262 cc->red_curve->reset();
1263 sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(cc->red_bpath), NULL);
1265 if (p != NULL)
1266 {
1267 // Test whether we clicked on a connection point
1268 gchar *shape_label = conn_pt_handle_test(cc, *p);
1270 if (shape_label) {
1271 if (cc->clickedhandle == cc->endpt_handle[0]) {
1272 sp_object_setAttribute(cc->clickeditem,
1273 "inkscape:connection-start",shape_label, false);
1274 }
1275 else {
1276 sp_object_setAttribute(cc->clickeditem,
1277 "inkscape:connection-end",shape_label, false);
1278 }
1279 g_free(shape_label);
1280 }
1281 }
1282 cc->clickeditem->setHidden(false);
1283 sp_conn_reroute_path_immediate(SP_PATH(cc->clickeditem));
1284 cc->clickeditem->updateRepr();
1285 sp_document_done(doc, SP_VERB_CONTEXT_CONNECTOR,
1286 _("Reroute connector"));
1287 cc_set_active_conn(cc, cc->clickeditem);
1288 }
1291 static void
1292 spcc_reset_colors(SPConnectorContext *cc)
1293 {
1294 /* Red */
1295 cc->red_curve->reset();
1296 sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(cc->red_bpath), NULL);
1298 cc->green_curve->reset();
1299 cc->npoints = 0;
1300 }
1303 static void
1304 spcc_connector_set_initial_point(SPConnectorContext *const cc, Geom::Point const p)
1305 {
1306 g_assert( cc->npoints == 0 );
1308 cc->p[0] = p;
1309 cc->p[1] = p;
1310 cc->npoints = 2;
1311 sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(cc->red_bpath), NULL);
1312 }
1315 static void
1316 spcc_connector_set_subsequent_point(SPConnectorContext *const cc, Geom::Point const p)
1317 {
1318 g_assert( cc->npoints != 0 );
1320 SPDesktop *dt = cc->desktop;
1321 Geom::Point o = dt->dt2doc(cc->p[0]);
1322 Geom::Point d = dt->dt2doc(p);
1323 Avoid::Point src(o[Geom::X], o[Geom::Y]);
1324 Avoid::Point dst(d[Geom::X], d[Geom::Y]);
1326 if (!cc->newConnRef) {
1327 Avoid::Router *router = sp_desktop_document(dt)->router;
1328 cc->newConnRef = new Avoid::ConnRef(router);
1329 cc->newConnRef->setEndpoint(Avoid::VertID::src, src);
1330 if (cc->isOrthogonal)
1331 cc->newConnRef->setRoutingType(Avoid::ConnType_Orthogonal);
1332 else
1333 cc->newConnRef->setRoutingType(Avoid::ConnType_PolyLine);
1334 }
1335 // Set new endpoint.
1336 cc->newConnRef->setEndpoint(Avoid::VertID::tar, dst);
1337 // Immediately generate new routes for connector.
1338 cc->newConnRef->makePathInvalid();
1339 cc->newConnRef->router()->processTransaction();
1340 // Recreate curve from libavoid route.
1341 recreateCurve( cc->red_curve, cc->newConnRef, cc->curvature );
1342 cc->red_curve->transform(dt->doc2dt());
1343 sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(cc->red_bpath), cc->red_curve);
1344 }
1347 /**
1348 * Concats red, blue and green.
1349 * If any anchors are defined, process these, optionally removing curves from white list
1350 * Invoke _flush_white to write result back to object.
1351 */
1352 static void
1353 spcc_concat_colors_and_flush(SPConnectorContext *cc)
1354 {
1355 SPCurve *c = cc->green_curve;
1356 cc->green_curve = new SPCurve();
1358 cc->red_curve->reset();
1359 sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(cc->red_bpath), NULL);
1361 if (c->is_empty()) {
1362 c->unref();
1363 return;
1364 }
1366 spcc_flush_white(cc, c);
1368 c->unref();
1369 }
1372 /*
1373 * Flushes white curve(s) and additional curve into object
1374 *
1375 * No cleaning of colored curves - this has to be done by caller
1376 * No rereading of white data, so if you cannot rely on ::modified, do it in caller
1377 *
1378 */
1380 static void
1381 spcc_flush_white(SPConnectorContext *cc, SPCurve *gc)
1382 {
1383 SPCurve *c;
1385 if (gc) {
1386 c = gc;
1387 c->ref();
1388 } else {
1389 return;
1390 }
1392 /* Now we have to go back to item coordinates at last */
1393 c->transform(SP_EVENT_CONTEXT_DESKTOP(cc)->dt2doc());
1395 SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(cc);
1396 SPDocument *doc = sp_desktop_document(desktop);
1397 Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc);
1399 if ( c && !c->is_empty() ) {
1400 /* We actually have something to write */
1402 Inkscape::XML::Node *repr = xml_doc->createElement("svg:path");
1403 /* Set style */
1404 sp_desktop_apply_style_tool(desktop, repr, "/tools/connector", false);
1406 gchar *str = sp_svg_write_path( c->get_pathvector() );
1407 g_assert( str != NULL );
1408 repr->setAttribute("d", str);
1409 g_free(str);
1411 /* Attach repr */
1412 cc->newconn = SP_ITEM(desktop->currentLayer()->appendChildRepr(repr));
1413 cc->newconn->transform = sp_item_i2doc_affine(SP_ITEM(desktop->currentLayer())).inverse();
1415 bool connection = false;
1416 sp_object_setAttribute(cc->newconn, "inkscape:connector-type",
1417 cc->isOrthogonal ? "orthogonal" : "polyline", false);
1418 sp_object_setAttribute(cc->newconn, "inkscape:connector-curvature",
1419 Glib::Ascii::dtostr(cc->curvature).c_str(), false);
1420 if (cc->sid)
1421 {
1422 sp_object_setAttribute(cc->newconn, "inkscape:connection-start",
1423 cc->sid, false);
1424 connection = true;
1425 }
1427 if (cc->eid)
1428 {
1429 sp_object_setAttribute(cc->newconn, "inkscape:connection-end",
1430 cc->eid, false);
1431 connection = true;
1432 }
1433 // Process pending updates.
1434 cc->newconn->updateRepr();
1435 sp_document_ensure_up_to_date(doc);
1437 if (connection) {
1438 // Adjust endpoints to shape edge.
1439 sp_conn_reroute_path_immediate(SP_PATH(cc->newconn));
1440 cc->newconn->updateRepr();
1441 }
1443 // Only set the selection after we are finished with creating the attributes of
1444 // the connector. Otherwise, the selection change may alter the defaults for
1445 // values like curvature in the connector context, preventing subsequent lookup
1446 // of their original values.
1447 cc->selection->set(repr);
1448 Inkscape::GC::release(repr);
1449 }
1451 c->unref();
1453 sp_document_done(doc, SP_VERB_CONTEXT_CONNECTOR, _("Create connector"));
1454 }
1457 static void
1458 spcc_connector_finish_segment(SPConnectorContext *const cc, Geom::Point const /*p*/)
1459 {
1460 if (!cc->red_curve->is_empty()) {
1461 cc->green_curve->append_continuous(cc->red_curve, 0.0625);
1463 cc->p[0] = cc->p[3];
1464 cc->p[1] = cc->p[4];
1465 cc->npoints = 2;
1467 cc->red_curve->reset();
1468 }
1469 }
1472 static void
1473 spcc_connector_finish(SPConnectorContext *const cc)
1474 {
1475 SPDesktop *const desktop = cc->desktop;
1476 desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Finishing connector"));
1478 cc->red_curve->reset();
1479 spcc_concat_colors_and_flush(cc);
1481 cc->npoints = 0;
1483 if (cc->newConnRef) {
1484 cc->newConnRef->removeFromGraph();
1485 delete cc->newConnRef;
1486 cc->newConnRef = NULL;
1487 }
1488 }
1491 static gboolean
1492 cc_generic_knot_handler(SPCanvasItem *, GdkEvent *event, SPKnot *knot)
1493 {
1494 g_assert (knot != NULL);
1496 g_object_ref(knot);
1498 SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(
1499 knot->desktop->event_context);
1501 gboolean consumed = FALSE;
1503 gchar* knot_tip = knot->tip ? knot->tip : cc->knot_tip;
1504 switch (event->type) {
1505 case GDK_ENTER_NOTIFY:
1506 sp_knot_set_flag(knot, SP_KNOT_MOUSEOVER, TRUE);
1508 cc->active_handle = knot;
1509 if (knot_tip)
1510 {
1511 knot->desktop->event_context->defaultMessageContext()->set(
1512 Inkscape::NORMAL_MESSAGE, knot_tip);
1513 }
1515 consumed = TRUE;
1516 break;
1517 case GDK_LEAVE_NOTIFY:
1518 sp_knot_set_flag(knot, SP_KNOT_MOUSEOVER, FALSE);
1520 cc->active_handle = NULL;
1522 if (knot_tip) {
1523 knot->desktop->event_context->defaultMessageContext()->clear();
1524 }
1526 consumed = TRUE;
1527 break;
1528 default:
1529 break;
1530 }
1532 g_object_unref(knot);
1534 return consumed;
1535 }
1538 static gboolean
1539 endpt_handler(SPKnot */*knot*/, GdkEvent *event, SPConnectorContext *cc)
1540 {
1541 g_assert( SP_IS_CONNECTOR_CONTEXT(cc) );
1543 gboolean consumed = FALSE;
1545 switch (event->type) {
1546 case GDK_BUTTON_PRESS:
1547 g_assert( (cc->active_handle == cc->endpt_handle[0]) ||
1548 (cc->active_handle == cc->endpt_handle[1]) );
1549 if (cc->state == SP_CONNECTOR_CONTEXT_IDLE) {
1550 cc->clickeditem = cc->active_conn;
1551 cc->clickedhandle = cc->active_handle;
1552 cc_clear_active_conn(cc);
1553 cc->state = SP_CONNECTOR_CONTEXT_REROUTING;
1555 // Disconnect from attached shape
1556 unsigned ind = (cc->active_handle == cc->endpt_handle[0]) ? 0 : 1;
1557 sp_conn_end_detach(cc->clickeditem, ind);
1559 Geom::Point origin;
1560 if (cc->clickedhandle == cc->endpt_handle[0]) {
1561 origin = cc->endpt_handle[1]->pos;
1562 }
1563 else {
1564 origin = cc->endpt_handle[0]->pos;
1565 }
1567 // Show the red path for dragging.
1568 cc->red_curve = SP_PATH(cc->clickeditem)->original_curve ? SP_PATH(cc->clickeditem)->original_curve->copy() : SP_PATH(cc->clickeditem)->curve->copy();
1569 Geom::Matrix i2d = sp_item_i2d_affine(cc->clickeditem);
1570 cc->red_curve->transform(i2d);
1571 sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(cc->red_bpath), cc->red_curve);
1573 cc->clickeditem->setHidden(true);
1575 // The rest of the interaction rerouting the connector is
1576 // handled by the context root handler.
1577 consumed = TRUE;
1578 }
1579 break;
1580 default:
1581 break;
1582 }
1584 return consumed;
1585 }
1587 static void cc_active_shape_add_knot(SPDesktop* desktop, SPItem* item, ConnectionPointMap &cphandles, ConnectionPoint& cp)
1588 {
1589 SPKnot *knot = sp_knot_new(desktop, 0);
1591 knot->setShape(SP_KNOT_SHAPE_SQUARE);
1592 knot->setSize(8);
1593 knot->setAnchor(GTK_ANCHOR_CENTER);
1594 knot->setFill(0xffffff00, 0xff0000ff, 0xff0000ff);
1595 sp_knot_update_ctrl(knot);
1597 // We don't want to use the standard knot handler.
1598 g_signal_handler_disconnect(G_OBJECT(knot->item),
1599 knot->_event_handler_id);
1600 knot->_event_handler_id = 0;
1602 gtk_signal_connect(GTK_OBJECT(knot->item), "event",
1603 GTK_SIGNAL_FUNC(cc_generic_knot_handler), knot);
1604 sp_knot_set_position(knot, item->avoidRef->getConnectionPointPos(cp.type, cp.id) * desktop->doc2dt(), 0);
1605 sp_knot_show(knot);
1606 cphandles[knot] = cp;
1607 }
1609 static void cc_set_active_shape(SPConnectorContext *cc, SPItem *item)
1610 {
1611 g_assert(item != NULL );
1613 std::map<int, ConnectionPoint>* connpts = &item->avoidRef->connection_points;
1615 if (cc->active_shape != item)
1616 {
1617 // The active shape has changed
1618 // Rebuild everything
1619 cc->active_shape = item;
1620 // Remove existing active shape listeners
1621 if (cc->active_shape_repr) {
1622 sp_repr_remove_listener_by_data(cc->active_shape_repr, cc);
1623 Inkscape::GC::release(cc->active_shape_repr);
1625 sp_repr_remove_listener_by_data(cc->active_shape_layer_repr, cc);
1626 Inkscape::GC::release(cc->active_shape_layer_repr);
1627 }
1629 // Listen in case the active shape changes
1630 cc->active_shape_repr = SP_OBJECT_REPR(item);
1631 if (cc->active_shape_repr) {
1632 Inkscape::GC::anchor(cc->active_shape_repr);
1633 sp_repr_add_listener(cc->active_shape_repr, &shape_repr_events, cc);
1635 cc->active_shape_layer_repr = cc->active_shape_repr->parent();
1636 Inkscape::GC::anchor(cc->active_shape_layer_repr);
1637 sp_repr_add_listener(cc->active_shape_layer_repr, &layer_repr_events, cc);
1638 }
1641 // Set the connection points.
1642 if ( cc->connpthandles.size() )
1643 // destroy the old list
1644 while (! cc->connpthandles.empty() )
1645 {
1646 g_object_unref(cc->connpthandles.begin()->first);
1647 cc->connpthandles.erase(cc->connpthandles.begin());
1648 }
1649 // build the new one
1650 if ( connpts->size() )
1651 for (std::map<int, ConnectionPoint>::iterator it = connpts->begin(); it != connpts->end(); ++it)
1652 cc_active_shape_add_knot(cc->desktop, item, cc->connpthandles, it->second);
1654 // Also add default connection points
1655 // For now, only centre default connection point will
1656 // be available
1657 ConnectionPoint centre;
1658 centre.type = ConnPointDefault;
1659 centre.id = ConnPointPosCC;
1660 cc_active_shape_add_knot(cc->desktop, item, cc->connpthandles, centre);
1661 }
1662 else
1663 {
1664 // The active shape didn't change
1665 // Update only the connection point knots
1667 // Ensure the item's connection_points map
1668 // has been updated
1669 sp_document_ensure_up_to_date(SP_OBJECT_DOCUMENT(item));
1671 std::set<int> seen;
1672 for ( ConnectionPointMap::iterator it = cc->connpthandles.begin(); it != cc->connpthandles.end() ;)
1673 {
1674 bool removed = false;
1675 if ( it->second.type == ConnPointUserDefined )
1676 {
1677 std::map<int, ConnectionPoint>::iterator p = connpts->find(it->second.id);
1678 if (p != connpts->end())
1679 {
1680 if ( it->second != p->second )
1681 // Connection point position has changed
1682 // Update knot position
1683 sp_knot_set_position(it->first,
1684 item->avoidRef->getConnectionPointPos(it->second.type, it->second.id) * cc->desktop->doc2dt(), 0);
1685 seen.insert(it->second.id);
1686 sp_knot_show(it->first);
1687 }
1688 else
1689 {
1690 // This connection point does no longer exist,
1691 // remove the knot
1692 ConnectionPointMap::iterator curr = it;
1693 ++it;
1694 g_object_unref( curr->first );
1695 cc->connpthandles.erase(curr);
1696 removed = true;
1697 }
1698 }
1699 else
1700 {
1701 // It's a default connection point
1702 // Just make sure it's position is correct
1703 sp_knot_set_position(it->first,
1704 item->avoidRef->getConnectionPointPos(it->second.type, it->second.id) * cc->desktop->doc2dt(), 0);
1705 sp_knot_show(it->first);
1707 }
1708 if ( !removed )
1709 ++it;
1710 }
1711 // Add knots for new connection points.
1712 if (connpts->size())
1713 for ( std::map<int, ConnectionPoint>::iterator it = connpts->begin(); it != connpts->end(); ++it )
1714 if ( seen.find(it->first) == seen.end() )
1715 // A new connection point has been added
1716 // to the shape. Add a knot for it.
1717 cc_active_shape_add_knot(cc->desktop, item, cc->connpthandles, it->second);
1718 }
1719 }
1722 static void
1723 cc_set_active_conn(SPConnectorContext *cc, SPItem *item)
1724 {
1725 g_assert( SP_IS_PATH(item) );
1727 SPCurve *curve = SP_PATH(item)->original_curve ? SP_PATH(item)->original_curve : SP_PATH(item)->curve;
1728 Geom::Matrix i2d = sp_item_i2d_affine(item);
1730 if (cc->active_conn == item)
1731 {
1732 // Just adjust handle positions.
1733 Geom::Point startpt = *(curve->first_point()) * i2d;
1734 sp_knot_set_position(cc->endpt_handle[0], startpt, 0);
1736 Geom::Point endpt = *(curve->last_point()) * i2d;
1737 sp_knot_set_position(cc->endpt_handle[1], endpt, 0);
1739 return;
1740 }
1742 cc->active_conn = item;
1744 // Remove existing active conn listeners
1745 if (cc->active_conn_repr) {
1746 sp_repr_remove_listener_by_data(cc->active_conn_repr, cc);
1747 Inkscape::GC::release(cc->active_conn_repr);
1748 cc->active_conn_repr = NULL;
1749 }
1751 // Listen in case the active conn changes
1752 cc->active_conn_repr = SP_OBJECT_REPR(item);
1753 if (cc->active_conn_repr) {
1754 Inkscape::GC::anchor(cc->active_conn_repr);
1755 sp_repr_add_listener(cc->active_conn_repr, &shape_repr_events, cc);
1756 }
1758 for (int i = 0; i < 2; ++i) {
1760 // Create the handle if it doesn't exist
1761 if ( cc->endpt_handle[i] == NULL ) {
1762 SPKnot *knot = sp_knot_new(cc->desktop,
1763 _("<b>Connector endpoint</b>: drag to reroute or connect to new shapes"));
1765 knot->setShape(SP_KNOT_SHAPE_SQUARE);
1766 knot->setSize(7);
1767 knot->setAnchor(GTK_ANCHOR_CENTER);
1768 knot->setFill(0xffffff00, 0xff0000ff, 0xff0000ff);
1769 knot->setStroke(0x000000ff, 0x000000ff, 0x000000ff);
1770 sp_knot_update_ctrl(knot);
1772 // We don't want to use the standard knot handler,
1773 // since we don't want this knot to be draggable.
1774 g_signal_handler_disconnect(G_OBJECT(knot->item),
1775 knot->_event_handler_id);
1776 knot->_event_handler_id = 0;
1778 gtk_signal_connect(GTK_OBJECT(knot->item), "event",
1779 GTK_SIGNAL_FUNC(cc_generic_knot_handler), knot);
1781 cc->endpt_handle[i] = knot;
1782 }
1784 // Remove any existing handlers
1785 if (cc->endpt_handler_id[i]) {
1786 g_signal_handlers_disconnect_by_func(
1787 G_OBJECT(cc->endpt_handle[i]->item),
1788 (void*)G_CALLBACK(endpt_handler), (gpointer) cc );
1789 cc->endpt_handler_id[i] = 0;
1790 }
1792 // Setup handlers for connector endpoints, this is
1793 // is as 'after' so that cc_generic_knot_handler is
1794 // triggered first for any endpoint.
1795 cc->endpt_handler_id[i] = g_signal_connect_after(
1796 G_OBJECT(cc->endpt_handle[i]->item), "event",
1797 G_CALLBACK(endpt_handler), cc);
1798 }
1800 Geom::Point startpt = *(curve->first_point()) * i2d;
1801 sp_knot_set_position(cc->endpt_handle[0], startpt, 0);
1803 Geom::Point endpt = *(curve->last_point()) * i2d;
1804 sp_knot_set_position(cc->endpt_handle[1], endpt, 0);
1806 sp_knot_show(cc->endpt_handle[0]);
1807 sp_knot_show(cc->endpt_handle[1]);
1808 }
1810 void cc_create_connection_point(SPConnectorContext* cc)
1811 {
1812 if (cc->active_shape && cc->state == SP_CONNECTOR_CONTEXT_IDLE)
1813 {
1814 if (cc->selected_handle)
1815 {
1816 cc_deselect_handle( cc->selected_handle );
1817 }
1818 SPKnot *knot = sp_knot_new(cc->desktop, 0);
1819 // We do not process events on this knot.
1820 g_signal_handler_disconnect(G_OBJECT(knot->item),
1821 knot->_event_handler_id);
1822 knot->_event_handler_id = 0;
1824 cc_select_handle( knot );
1825 cc->selected_handle = knot;
1826 sp_knot_show(cc->selected_handle);
1827 cc->state = SP_CONNECTOR_CONTEXT_NEWCONNPOINT;
1828 }
1829 }
1831 void cc_remove_connection_point(SPConnectorContext* cc)
1832 {
1833 if (cc->selected_handle && cc->state == SP_CONNECTOR_CONTEXT_IDLE )
1834 {
1835 cc->active_shape->avoidRef->deleteConnectionPoint(cc->connpthandles[cc->selected_handle]);
1836 cc->selected_handle = NULL;
1837 }
1838 }
1840 static bool cc_item_is_shape(SPItem *item)
1841 {
1842 if (SP_IS_PATH(item)) {
1843 SPCurve *curve = (SP_SHAPE(item))->curve;
1844 if ( curve && !(curve->is_closed()) ) {
1845 // Open paths are connectors.
1846 return false;
1847 }
1848 }
1849 else if (SP_IS_TEXT(item) || SP_IS_FLOWTEXT(item)) {
1850 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1851 if (prefs->getBool("/tools/connector/ignoretext", true)) {
1852 // Don't count text as a shape we can connect connector to.
1853 return false;
1854 }
1855 }
1856 return true;
1857 }
1860 bool cc_item_is_connector(SPItem *item)
1861 {
1862 if (SP_IS_PATH(item)) {
1863 if (SP_PATH(item)->connEndPair.isAutoRoutingConn()) {
1864 g_assert( SP_PATH(item)->original_curve ? !(SP_PATH(item)->original_curve->is_closed()) : !(SP_PATH(item)->curve->is_closed()) );
1865 return true;
1866 }
1867 }
1868 return false;
1869 }
1872 void cc_selection_set_avoid(bool const set_avoid)
1873 {
1874 SPDesktop *desktop = inkscape_active_desktop();
1875 if (desktop == NULL) {
1876 return;
1877 }
1879 SPDocument *document = sp_desktop_document(desktop);
1881 Inkscape::Selection *selection = sp_desktop_selection(desktop);
1883 GSList *l = (GSList *) selection->itemList();
1885 int changes = 0;
1887 while (l) {
1888 SPItem *item = (SPItem *) l->data;
1890 char const *value = (set_avoid) ? "true" : NULL;
1892 if (cc_item_is_shape(item)) {
1893 sp_object_setAttribute(item, "inkscape:connector-avoid",
1894 value, false);
1895 item->avoidRef->handleSettingChange();
1896 changes++;
1897 }
1899 l = l->next;
1900 }
1902 if (changes == 0) {
1903 desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE,
1904 _("Select <b>at least one non-connector object</b>."));
1905 return;
1906 }
1908 char *event_desc = (set_avoid) ?
1909 _("Make connectors avoid selected objects") :
1910 _("Make connectors ignore selected objects");
1911 sp_document_done(document, SP_VERB_CONTEXT_CONNECTOR, event_desc);
1912 }
1915 static void
1916 cc_selection_changed(Inkscape::Selection *selection, gpointer data)
1917 {
1918 SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(data);
1919 //SPEventContext *ec = SP_EVENT_CONTEXT(cc);
1921 SPItem *item = selection->singleItem();
1923 if (cc->active_conn == item)
1924 {
1925 // Nothing to change.
1926 return;
1927 }
1928 if (item == NULL)
1929 {
1930 cc_clear_active_conn(cc);
1931 return;
1932 }
1934 if (cc_item_is_connector(item)) {
1935 cc_set_active_conn(cc, item);
1936 }
1937 }
1940 static void
1941 shape_event_attr_deleted(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node *child,
1942 Inkscape::XML::Node */*ref*/, gpointer data)
1943 {
1944 g_assert(data);
1945 SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(data);
1947 if (child == cc->active_shape_repr) {
1948 // The active shape has been deleted. Clear active shape.
1949 cc_clear_active_shape(cc);
1950 }
1951 }
1954 static void
1955 shape_event_attr_changed(Inkscape::XML::Node *repr, gchar const *name,
1956 gchar const */*old_value*/, gchar const */*new_value*/,
1957 bool /*is_interactive*/, gpointer data)
1958 {
1959 g_assert(data);
1960 SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(data);
1962 // Look for changes that result in onscreen movement.
1963 if (!strcmp(name, "d") || !strcmp(name, "x") || !strcmp(name, "y") ||
1964 !strcmp(name, "width") || !strcmp(name, "height") ||
1965 !strcmp(name, "transform"))
1966 {
1967 if (repr == cc->active_shape_repr) {
1968 // Active shape has moved. Clear active shape.
1969 cc_clear_active_shape(cc);
1970 }
1971 else if (repr == cc->active_conn_repr) {
1972 // The active conn has been moved.
1973 // Set it again, which just sets new handle positions.
1974 cc_set_active_conn(cc, cc->active_conn);
1975 }
1976 }
1977 else
1978 if ( !strcmp(name, "inkscape:connection-points") )
1979 if (repr == cc->active_shape_repr)
1980 // The connection points of the active shape
1981 // have changed. Update them.
1982 cc_set_active_shape(cc, cc->active_shape);
1983 }
1986 /*
1987 Local Variables:
1988 mode:c++
1989 c-file-style:"stroustrup"
1990 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
1991 indent-tabs-mode:nil
1992 fill-column:99
1993 End:
1994 */
1995 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :