summaryrefslogtreecommitdiffstats
path: root/src/sp-conn-end.cpp
diff options
context:
space:
mode:
authorArcadie M. Cracan <acracan@gmail.com>2010-02-21 10:40:13 +0000
committerArcadie M. Cracan <acracan@gmail.com>2010-02-21 10:40:13 +0000
commita78a295c3c2df3ee1ff480302a2c2bbb4d39c4b4 (patch)
treeb547269d763a0516219d65c9e73feb9caaa616e6 /src/sp-conn-end.cpp
parentMake sure that guides always snap correctly when dropping them, and improve p... (diff)
downloadinkscape-a78a295c3c2df3ee1ff480302a2c2bbb4d39c4b4.tar.gz
inkscape-a78a295c3c2df3ee1ff480302a2c2bbb4d39c4b4.zip
Disabled unfinished connection point edit mode. Added inkscape:connection-start-point, inkscape:connection-end-point attributes for connector endpoints. This corrects the previous approach making drawings created in 0.48 version compatible with earlier versions (new attributes are silently ignored).
(bzr r9103.1.1)
Diffstat (limited to 'src/sp-conn-end.cpp')
-rw-r--r--src/sp-conn-end.cpp206
1 files changed, 89 insertions, 117 deletions
diff --git a/src/sp-conn-end.cpp b/src/sp-conn-end.cpp
index 224442eb8..3ad6954a2 100644
--- a/src/sp-conn-end.cpp
+++ b/src/sp-conn-end.cpp
@@ -21,6 +21,9 @@ static void change_endpts(SPCurve *const curve, double const endPos[2]);
SPConnEnd::SPConnEnd(SPObject *const owner) :
ref(owner),
href(NULL),
+ // Default to center connection endpoint
+ type(ConnPointDefault),
+ id(4),
_changed_connection(),
_delete_connection(),
_transformed_connection()
@@ -228,9 +231,10 @@ sp_conn_end_deleted(SPObject *, SPObject *const owner, unsigned const handle_ix)
// todo: The first argument is the deleted object, or just NULL if
// called by sp_conn_end_detach.
g_return_if_fail(handle_ix < 2);
- char const *const attr_str[] = {"inkscape:connection-start",
- "inkscape:connection-end"};
- SP_OBJECT_REPR(owner)->setAttribute(attr_str[handle_ix], NULL);
+ char const * const attr_strs[] = {"inkscape:connection-start", "inkscape:connection-start-point",
+ "inkscape:connection-end", "inkscape:connection-end-point"};
+ SP_OBJECT_REPR(owner)->setAttribute(attr_strs[2*handle_ix], NULL);
+ SP_OBJECT_REPR(owner)->setAttribute(attr_strs[2*handle_ix+1], NULL);
/* I believe this will trigger sp_conn_end_href_changed. */
}
@@ -245,7 +249,9 @@ SPConnEnd::setAttacherHref(gchar const *value, SPPath* /*path*/)
{
if ( value && href && ( strcmp(value, href) == 0 ) ) {
/* No change, do nothing. */
- } else {
+ }
+ else
+ {
if (!value)
{
ref.detach();
@@ -254,138 +260,104 @@ SPConnEnd::setAttacherHref(gchar const *value, SPPath* /*path*/)
}
else
{
-
- /* References to the connection points have the following format
- #svguri_t_id, where #svguri is the id of the item the
- connector is attached to, t is the type of the point, which
- can be either "d" for default or "u" for user-defined, and
- id is the local (inside the item) id of the connection point.
- In the case of default points id represents the position on the
- item (i.e. Top-Left, Centre-Centre, etc.).
- */
-
- gchar ** href_strarray = NULL;
- if (href)
- href_strarray = g_strsplit(href, "_", 0);
- gchar ** value_strarray = g_strsplit(value, "_", 0);
-
- g_free(href);
- href = NULL;
-
- bool changed = false;
bool validRef = true;
+ href = g_strdup(value);
+ // Now do the attaching, which emits the changed signal.
+ try {
+ ref.attach(Inkscape::URI(value));
+ } catch (Inkscape::BadURIException &e) {
+ /* TODO: Proper error handling as per
+ * http://www.w3.org/TR/SVG11/implnote.html#ErrorProcessing. (Also needed for
+ * sp-use.) */
+ g_warning("%s", e.what());
+ validRef = false;
+ }
- if ( !href_strarray || g_strcmp0(href_strarray[0], value_strarray[0]) != 0 )
+ if ( !validRef )
{
- // The href has changed, so update it.
- changed = true;
- // Set the href field, because sp_conn_end_href_changed will need it.
- href = g_strdup(value);
- // Now do the attaching, which emits the changed signal.
- try {
- ref.attach(Inkscape::URI(value_strarray[0]));
- } catch (Inkscape::BadURIException &e) {
- /* TODO: Proper error handling as per
- * http://www.w3.org/TR/SVG11/implnote.html#ErrorProcessing. (Also needed for
- * sp-use.) */
- g_warning("%s", e.what());
- validRef = false;
- }
+ ref.detach();
+ g_free(href);
+ href = NULL;
}
- // Check to see if the connection point changed and update it.
- //
+ }
+ }
+}
- if ( !value_strarray[1] )
- {
- /* Treat the old references to connection points
- as default points that connect to the centre
- of the item.
- */
- if ( type != ConnPointDefault )
+void
+SPConnEnd::setAttacherEndpoint(gchar const *value, SPPath* /*path*/)
+{
+
+ /* References to the connection points have the following format
+ <t><id>, where t is the type of the point, which
+ can be either "d" for default or "u" for user-defined, and
+ id is the local (inside the item) id of the connection point.
+ In the case of default points id represents the position on the
+ item (i.e. Top-Left, Center-Center, etc.).
+ */
+
+ bool changed = false;
+ ConnPointType newtype = type;
+
+ if (!value)
+ {
+ // Default to center endpoint
+ type = ConnPointDefault;
+ id = 4;
+ }
+ else
+ {
+ switch (value[0])
+ {
+ case 'd':
+ if ( newtype != ConnPointDefault )
{
- type = ConnPointDefault;
+ newtype = ConnPointDefault;
changed = true;
}
- if ( id != ConnPointPosCC )
+ break;
+ case 'u':
+ if ( newtype != ConnPointUserDefined)
{
- id = ConnPointPosCC;
+ newtype = ConnPointUserDefined;
changed = true;
}
- }
- else
+ break;
+ default:
+ g_warning("Bad reference to a connection point.");
+ }
+
+ int newid = (int) g_ascii_strtod( value+1, 0 );
+ if ( id != newid )
+ {
+ id = newid;
+ changed = true;
+ }
+
+ // We have to verify that the reference to the
+ // connection point is a valid one.
+
+ if ( changed )
+ {
+
+ // Get the item the connector is attached to
+ SPItem* item = ref.getObject();
+ if ( item )
{
- switch (value_strarray[1][0])
- {
- case 'd':
- if ( type != ConnPointDefault )
- {
- type = ConnPointDefault;
- changed = true;
- }
- break;
- case 'u':
- if ( type != ConnPointUserDefined)
- {
- type = ConnPointUserDefined;
- changed = true;
- }
- break;
- default:
- g_warning("Bad reference to a connection point.");
- validRef = false;
- }
- if ( value_strarray[2] )
+ if (!item->avoidRef->isValidConnPointId( newtype, newid ) )
{
- int newId = (int) g_ascii_strtod( value_strarray[2], 0 );
- if ( id != newId )
- {
- id = newId;
- changed = true;
- }
-
+ g_warning("Bad reference to a connection point.");
}
else
{
- // We have a malformed reference to a connection point,
- // emit a warning, clear href and detach ref.
- changed = true;
- g_warning("Bad reference to a connection point.");\
- validRef = false;
+ type = newtype;
+ id = newid;
}
- }
-
- if ( changed )
- {
- // We still have to verify that the reference to the
- // connection point is a valid one.
-
- // Get the item the connector is attached to
- SPItem* item = ref.getObject();
- if ( item && !item->avoidRef->isValidConnPointId( type, id ) )
- {
- g_warning("Bad reference to a connection point.");
- validRef = false;
+ /* // Update the connector
+ if (path->connEndPair.isAutoRoutingConn()) {
+ path->connEndPair.tellLibavoidNewEndpoints();
}
-/* else
- // Update the connector
- if (path->connEndPair.isAutoRoutingConn()) {
- path->connEndPair.tellLibavoidNewEndpoints();
- }
-*/
- }
-
- if ( !validRef )
- {
- ref.detach();
- g_free(href);
- href = NULL;
+ */
}
- else
- if (!href)
- href = g_strdup(value);
-
- g_strfreev(href_strarray);
- g_strfreev(value_strarray);
}
}
}