connector-context.cpp revision 60d3de07a6473dd321c1d0016f49d13eb06c0884
/*
* Connector creation tool
*
* Authors:
* Michael Wybrow <mjwybrow@users.sourceforge.net>
*
* Copyright (C) 2005 Michael Wybrow
*
* Released under GNU GPL, read the file 'COPYING' for more information
*
* TODO:
* o Have shapes avoid convex hulls of objects, rather than their
* bounding box. Possibly implement the unfinished ConvexHull
* class in libnr.
* (HOWEVER, using the convex hull C of a shape S does the wrong thing if a
* connector starts outside of S but inside C, or if the best route around
* an object involves going inside C but without entering S.)
* o Draw connectors to shape edges rather than bounding box.
* o Show a visual indicator for objects with the 'avoid' property set.
* o Allow user to change a object between a path and connector through
* the interface.
* o Create an interface for setting markers (arrow heads).
* o Better distinguish between paths and connectors to prevent problems
* in the node tool and paths accidently being turned into connectors
* in the connector tool. Perhaps have a way to convert between.
* o Only call libavoid's updateEndPoint as required. Currently we do it
* for both endpoints, even if only one is moving.
* o Allow user-placeable connection points.
* o Deal sanely with connectors with both endpoints attached to the
* same connection point, and drawing of connectors attaching
* overlaping shapes (currently tries to adjust connector to be
* outside both bounding boxes).
* o Fix many special cases related to connectors updating,
* e.g., copying a couple of shapes and a connector that are
* attached to each other.
* e.g., detach connector when it is moved or transformed in
* one of the other contexts.
* o Cope with shapes whose ids change when they have attached
* connectors.
* o gobble_motion_events(GDK_BUTTON1_MASK)?;
*
*/
#include <gdk/gdkkeysyms.h>
#include "connector-context.h"
#include "pixmaps/cursor-connector.xpm"
#include "xml/node-event-vector.h"
#include "desktop.h"
#include "desktop-style.h"
#include "desktop-affine.h"
#include "desktop-handles.h"
#include "document.h"
#include "message-context.h"
#include "message-stack.h"
#include "selection.h"
#include "inkscape.h"
#include "prefs-utils.h"
#include "sp-path.h"
#include "display/canvas-bpath.h"
#include "display/sodipodi-ctrl.h"
#include "snap.h"
#include "knot.h"
#include "sp-conn-end.h"
#include "conn-avoid-ref.h"
#include "libavoid/vertices.h"
#include "context-fns.h"
#include "sp-namedview.h"
#include "sp-text.h"
#include "sp-flowtext.h"
static gint sp_connector_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event);
// Stuff borrowed from DrawContext
// Context event handlers
static gint connector_handle_button_press(SPConnectorContext *const cc, GdkEventButton const &bevent);
static gint connector_handle_motion_notify(SPConnectorContext *const cc, GdkEventMotion const &mevent);
static gint connector_handle_button_release(SPConnectorContext *const cc, GdkEventButton const &revent);
static bool connector_within_tolerance = false;
static SPEventContextClass *parent_class;
NULL, /* child_added */
NULL, /* child_added */
NULL, /* content_changed */
NULL /* order_changed */
};
NULL, /* child_added */
NULL, /* child_added */
NULL, /* content_changed */
NULL /* order_changed */
};
{
if (!type) {
sizeof(SPConnectorContextClass),
sizeof(SPConnectorContext),
4,
NULL, /* value_table */
};
}
return type;
}
static void
{
}
static void
{
for (int i = 0; i < 2; ++i) {
cc->endpt_handler_id[i] = 0;
}
}
static void
{
if (cc->connpthandle) {
}
for (int i = 0; i < 2; ++i) {
}
}
}
}
}
static void
{
}
/* Create red bpath */
/* Create red curve */
/* Create green curve */
// Notice the initial selection.
ec->enableSelectionCue();
}
// Make sure we see all enter events for canvas items,
// even if a mouse button is depressed.
}
static void
{
}
}
// Restore the default event generating behaviour.
}
//-----------------------------------------------------------------------------
static void
{
return;
}
if (cc->active_shape_repr) {
}
// Hide the center connection point if it exists.
if (cc->connpthandle) {
}
}
static void
{
return;
}
if (cc->active_conn_repr) {
}
// Hide the endpoint handles.
for (int i = 0; i < 2; ++i) {
if (cc->endpt_handle[i]) {
}
}
}
static gchar *
{
// TODO: this will need to change when there are more connection
// points available for each shape.
{
}
return NULL;
}
static gint
{
case GDK_BUTTON_RELEASE:
{
}
// Doing simething else like rerouting.
break;
}
// find out clicked item, disregarding groups, honoring Alt
} else {
}
}
break;
case GDK_ENTER_NOTIFY:
{
if (cc_item_is_shape(item)) {
// This is a shape, so show connection point(s).
if (!(cc->active_shape) ||
// Don't show handle for another handle.
}
}
break;
}
default:
break;
}
return ret;
}
{
case GDK_BUTTON_PRESS:
break;
case GDK_MOTION_NOTIFY:
break;
case GDK_BUTTON_RELEASE:
break;
case GDK_KEY_PRESS:
break;
default:
break;
}
if (!ret) {
if (parent_root_handler) {
}
}
return ret;
}
static gint
{
/* Find desktop coordinates */
return TRUE;
}
bevent.y);
connector_within_tolerance = true;
/* This is allowed, if we just cancelled curve */
{
/* Set start anchor */
SP_EVENT_CONTEXT_DESKTOP(cc)->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Creating new connector"));
/* Create green anchor */
p = event_dt;
// Test whether we clicked on a connection point
// This is the first point, so just snap it to the grid
// as there's no other points to go off.
}
}
break;
}
{
// This is the second click of a connector creation.
// Test whether we clicked on a connection point
}
break;
}
{
g_warning("Button down in CLOSE state");
break;
}
default:
break;
}
// A context menu is going to be triggered here,
// so end the rerouting operation.
// Don't set ret to TRUE, so we drop through to the
// parent handler which will open the context menu.
}
}
}
return ret;
}
static gint
{
if (event_context->space_panning || mevent.state & GDK_BUTTON2_MASK || mevent.state & GDK_BUTTON3_MASK) {
// allow middle-button scrolling
return FALSE;
}
if (connector_within_tolerance) {
"value", 0, 0, 100);
return FALSE; // Do not drag if we're within tolerance from origin.
}
}
// Once the user has moved farther than tolerance from the original location
// (indicating they intend to move the object, not click), then always process
// the motion notify coordinates as given (no snapping back to origin)
connector_within_tolerance = false;
/* Find desktop coordinates */
{
// This is movement during a connector creation.
}
break;
}
{
// Update the hidden path
}
else {
}
// Copy this to the temporary visible path
break;
}
/* This is perfectly valid */
break;
default:
break;
}
return ret;
}
static gint
{
/* Find desktop coordinates */
//case SP_CONNECTOR_CONTEXT_POINT:
{
{
return TRUE;
}
// Connector has been created via a drag, end it now.
// Test whether we clicked on a connection point
}
break;
}
{
return TRUE;
break;
}
/* This is allowed, if we just cancelled curve */
break;
default:
break;
}
}
return ret;
}
static gint
{
/* fixme: */
switch (keyval) {
case GDK_Return:
case GDK_KP_Enter:
}
break;
case GDK_Escape:
_("Connector endpoint drag cancelled."));
}
// if drawing, cancel, otherwise pass it up for deselecting
}
break;
default:
break;
}
return ret;
}
static void
{
// Clear the temporary path:
if (p != NULL)
{
// Test whether we clicked on a connection point
if (shape_label) {
"inkscape:connection-start",shape_label, false);
}
else {
"inkscape:connection-end",shape_label, false);
}
}
}
_("Reroute connector"));
}
static void
{
/* Red */
}
static void
{
cc->p[0] = p;
cc->p[1] = p;
}
static void
{
if (!cc->newConnRef) {
}
}
}
/**
* Concats red, blue and green.
* If any anchors are defined, process these, optionally removing curves from white list
* Invoke _flush_white to write result back to object.
*/
static void
{
if (sp_curve_empty(c)) {
sp_curve_unref(c);
return;
}
spcc_flush_white(cc, c);
sp_curve_unref(c);
}
/*
* Flushes white curve(s) and additional curve into object
*
* No cleaning of colored curves - this has to be done by caller
* No rereading of white data, so if you cannot rely on ::modified, do it in caller
*
*/
static void
{
SPCurve *c;
if (gc) {
c = gc;
sp_curve_ref(c);
} else {
return;
}
/* Now we have to go back to item coordinates at last */
if ( c && !sp_curve_empty(c) ) {
/* We actually have something to write */
/* Set style */
/* Attach repr */
bool connection = false;
"polyline", false);
{
connection = true;
}
{
connection = true;
}
if (connection) {
// Adjust endpoints to shape edge.
}
}
sp_curve_unref(c);
/* Flush pending updates */
}
static void
{
}
}
static void
{
if (cc->newConnRef) {
delete cc->newConnRef;
}
}
static gboolean
{
case GDK_ENTER_NOTIFY:
{
}
break;
case GDK_LEAVE_NOTIFY:
}
break;
default:
break;
}
return consumed;
}
static gboolean
{
case GDK_BUTTON_PRESS:
// Disconnect from attached shape
}
else {
}
// Show the red path for dragging.
// The rest of the interaction rerouting the connector is
// handled by the context root handler.
}
break;
default:
break;
}
return consumed;
}
{
// Remove existing active shape listeners
if (cc->active_shape_repr) {
}
// Listen in case the active shape changes
if (cc->active_shape_repr) {
}
// Set center connection point.
_("<b>Connection point</b>: click or drag to create a new connector"));
// We don't want to use the standard knot handler,
//since we don't want this knot to be draggable.
knot->_event_handler_id = 0;
}
if (bbox) {
} else {
}
}
static void
{
{
// Just adjust handle positions.
return;
}
// Remove existing active conn listeners
if (cc->active_conn_repr) {
}
// Listen in case the active conn changes
if (cc->active_conn_repr) {
}
for (int i = 0; i < 2; ++i) {
// Create the handle if it doesn't exist
_("<b>Connector endpoint</b>: drag to reroute or connect to new shapes"));
// We don't want to use the standard knot handler,
//since we don't want this knot to be draggable.
knot->_event_handler_id = 0;
}
// Remove any existing handlers
if (cc->endpt_handler_id[i]) {
cc->endpt_handler_id[i] = 0;
}
// Setup handlers for connector endpoints, this is
// is as 'after' so that cc_generic_knot_handler is
// triggered first for any endpoint.
}
}
{
if (SP_IS_PATH(item)) {
// Open paths are connectors.
return false;
}
}
// Don't count text as a shape we can connect connector to.
return false;
}
}
return true;
}
{
if (SP_IS_PATH(item)) {
return true;
}
}
return false;
}
void cc_selection_set_avoid(bool const set_avoid)
{
return;
}
int changes = 0;
while (l) {
if (cc_item_is_shape(item)) {
value, false);
changes++;
}
l = l->next;
}
if (changes == 0) {
_("Select <b>at least one non-connector object</b>."));
return;
}
char *event_desc = (set_avoid) ?
_("Make connectors avoid selected objects") :
_("Make connectors ignore selected objects");
}
static void
{
//SPEventContext *ec = SP_EVENT_CONTEXT(cc);
{
// Nothing to change.
return;
}
{
return;
}
if (cc_item_is_connector(item)) {
}
}
static void
{
// The active shape has been deleted. Clear active shape.
}
}
static void
{
// Look for changes than result in onscreen movement.
{
// Active shape has moved. Clear active shape.
}
// The active conn has been moved.
// Set it again, which just sets new handle positions.
}
}
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :