Code

Filters. Custom predefined filters update and new ABC filters.
[inkscape.git] / src / sp-conn-end-pair.cpp
index 98b2aec26dc23eaf1125a5c04f601746ea35da9f..5bce1a4f80d7a4378848e0e0c66229b73c239c08 100644 (file)
@@ -4,6 +4,7 @@
  * Authors:
  *   Peter Moulder <pmoulder@mail.csse.monash.edu.au>
  *   Michael Wybrow <mjwybrow@users.sourceforge.net>
+ *   Abhishek Sharma
  *
  *    * Copyright (C) 2004-2005 Monash University
  *
@@ -63,7 +64,7 @@ SPConnEndPair::release()
         this->_connEnd[handle_ix]->ref.detach();
     }
 
-    // If the document is being destroyed then the router instance 
+    // If the document is being destroyed then the router instance
     // and the ConnRefs will have been destroyed with it.
     const bool routerInstanceExists = (_path->document->router != NULL);
 
@@ -79,10 +80,12 @@ SPConnEndPair::release()
 void
 sp_conn_end_pair_build(SPObject *object)
 {
-    sp_object_read_attr(object, "inkscape:connector-type");
-    sp_object_read_attr(object, "inkscape:connection-start");
-    sp_object_read_attr(object, "inkscape:connection-end");
-    sp_object_read_attr(object, "inkscape:connector-curvature");
+    object->readAttr( "inkscape:connector-type" );
+    object->readAttr( "inkscape:connection-start" );
+    object->readAttr( "inkscape:connection-start-point" );
+    object->readAttr( "inkscape:connection-end" );
+    object->readAttr( "inkscape:connection-end-point" );
+    object->readAttr( "inkscape:connector-curvature" );
 }
 
 
@@ -99,31 +102,18 @@ avoid_conn_transformed(Geom::Matrix const */*mp*/, SPItem *moved_item)
 void
 SPConnEndPair::setAttr(unsigned const key, gchar const *const value)
 {
-    if (key == SP_ATTR_CONNECTOR_TYPE) {
-        if (value && (strcmp(value, "polyline") == 0 || strcmp(value, "orthogonal") == 0)) {
-            int newconnType = strcmp(value, "polyline") ? SP_CONNECTOR_ORTHOGONAL : SP_CONNECTOR_POLYLINE;
-            
-            if (!_connRef)
-            {
-                _connType = newconnType;
-                Avoid::Router *router = _path->document->router;
-                GQuark itemID = g_quark_from_string(SP_OBJECT(_path)->id);
-                _connRef = new Avoid::ConnRef(router, itemID);
-                switch (newconnType)
-                {
-                    case SP_CONNECTOR_POLYLINE:
-                        _connRef->setRoutingType(Avoid::ConnType_PolyLine);
-                        break;
-                    case SP_CONNECTOR_ORTHOGONAL:
-                        _connRef->setRoutingType(Avoid::ConnType_Orthogonal);
-                }
-                _transformed_connection = _path->connectTransformed(
-                        sigc::ptr_fun(&avoid_conn_transformed));
-            }
-            else
-                if (newconnType != _connType)
+    switch (key)
+    {
+        case SP_ATTR_CONNECTOR_TYPE:
+            if (value && (strcmp(value, "polyline") == 0 || strcmp(value, "orthogonal") == 0)) {
+                int newconnType = strcmp(value, "polyline") ? SP_CONNECTOR_ORTHOGONAL : SP_CONNECTOR_POLYLINE;
+
+                if (!_connRef)
                 {
                     _connType = newconnType;
+                    Avoid::Router *router = _path->document->router;
+                    GQuark itemID = g_quark_from_string(_path->getId());
+                    _connRef = new Avoid::ConnRef(router, itemID);
                     switch (newconnType)
                     {
                         case SP_CONNECTOR_POLYLINE:
@@ -132,51 +122,68 @@ SPConnEndPair::setAttr(unsigned const key, gchar const *const value)
                         case SP_CONNECTOR_ORTHOGONAL:
                             _connRef->setRoutingType(Avoid::ConnType_Orthogonal);
                     }
-                    sp_conn_reroute_path(_path);
+                    _transformed_connection = _path->connectTransformed(
+                            sigc::ptr_fun(&avoid_conn_transformed));
                 }
-        }
-        else {
-            _connType = SP_CONNECTOR_NOAVOID;
+                else
+                    if (newconnType != _connType)
+                    {
+                        _connType = newconnType;
+                        switch (newconnType)
+                        {
+                            case SP_CONNECTOR_POLYLINE:
+                                _connRef->setRoutingType(Avoid::ConnType_PolyLine);
+                                break;
+                            case SP_CONNECTOR_ORTHOGONAL:
+                                _connRef->setRoutingType(Avoid::ConnType_Orthogonal);
+                        }
+                        sp_conn_reroute_path(_path);
+                    }
+            }
+            else {
+                _connType = SP_CONNECTOR_NOAVOID;
 
-            if (_connRef) {
-                _connRef->removeFromGraph();
-                delete _connRef;
-                _connRef = NULL;
-                _transformed_connection.disconnect();
+                if (_connRef) {
+                    _connRef->removeFromGraph();
+                    delete _connRef;
+                    _connRef = NULL;
+                    _transformed_connection.disconnect();
+                }
             }
-        }
-        return;
-    }
-    else if (key == SP_ATTR_CONNECTOR_CURVATURE) {
-        if (value) {
-            _connCurvature = g_strtod(value, NULL);
-            if (_connRef && _connRef->isInitialised()) {
-                // Redraw the connector, but only if it has been initialised.
-                sp_conn_reroute_path(_path);
+            break;
+        case SP_ATTR_CONNECTOR_CURVATURE:
+            if (value) {
+                _connCurvature = g_strtod(value, NULL);
+                if (_connRef && _connRef->isInitialised()) {
+                    // Redraw the connector, but only if it has been initialised.
+                    sp_conn_reroute_path(_path);
+                }
             }
-        }
-        return;
+            break;
+        case SP_ATTR_CONNECTION_START:
+        case SP_ATTR_CONNECTION_END:
+            this->_connEnd[(key == SP_ATTR_CONNECTION_START ? 0 : 1)]->setAttacherHref(value, _path);
+            break;
+        case SP_ATTR_CONNECTION_START_POINT:
+        case SP_ATTR_CONNECTION_END_POINT:
+            this->_connEnd[(key == SP_ATTR_CONNECTION_START_POINT ? 0 : 1)]->setAttacherEndpoint(value, _path);
+            break;
     }
 
-    unsigned const handle_ix = key - SP_ATTR_CONNECTION_START;
-    g_assert( handle_ix <= 1 );
-    this->_connEnd[handle_ix]->setAttacherHref(value, _path);
 }
 
 void
 SPConnEndPair::writeRepr(Inkscape::XML::Node *const repr) const
 {
+    char const * const attr_strs[] = {"inkscape:connection-start", "inkscape:connection-start-point",
+                                      "inkscape:connection-end", "inkscape:connection-end-point"};
     for (unsigned handle_ix = 0; handle_ix < 2; ++handle_ix) {
         if (this->_connEnd[handle_ix]->ref.getURI()) {
-            char const * const attr_strs[] = {"inkscape:connection-start",
-                                              "inkscape:connection-end"};
+            repr->setAttribute(attr_strs[2*handle_ix], this->_connEnd[handle_ix]->ref.getURI()->toString());
             std::ostringstream ostr;
-            ostr<<this->_connEnd[handle_ix]->ref.getURI()->toString()<<"_"<<
-                  (this->_connEnd[handle_ix]->type == ConnPointDefault ? "d":"u") <<
-                  "_" << this->_connEnd[handle_ix]->id;
-            
-            
-            repr->setAttribute(attr_strs[handle_ix], ostr.str().c_str());
+            ostr<<(this->_connEnd[handle_ix]->type == ConnPointDefault ? "d":"u") <<
+                  this->_connEnd[handle_ix]->id;
+            repr->setAttribute(attr_strs[2*handle_ix+1], ostr.str().c_str());
         }
     }
     repr->setAttribute("inkscape:connector-curvature", Glib::Ascii::dtostr(_connCurvature).c_str());
@@ -210,6 +217,7 @@ SPConnEndPair::getEndpoints(Geom::Point endPts[]) const {
     SPCurve *curve = _path->original_curve ? _path->original_curve : _path->curve;
     SPItem *h2attItem[2];
     getAttachedItems(h2attItem);
+    Geom::Matrix i2d = SP_ITEM(_path)->i2doc_affine();
 
     for (unsigned h = 0; h < 2; ++h) {
         if ( h2attItem[h] ) {
@@ -219,10 +227,10 @@ SPConnEndPair::getEndpoints(Geom::Point endPts[]) const {
         else
         {
             if (h == 0) {
-                endPts[h] = *(curve->first_point());
+                endPts[h] = *(curve->first_point())*i2d;
             }
             else {
-                endPts[h] = *(curve->last_point());
+                endPts[h] = *(curve->last_point())*i2d;
             }
         }
     }
@@ -287,25 +295,19 @@ SPConnEndPair::update(void)
 void SPConnEndPair::storeIds(void)
 {
     if (_connEnd[0]->href) {
-        gchar ** href_strarray = NULL;
-        href_strarray = g_strsplit(_connEnd[0]->href, "_", 0);
         // href begins with a '#' which we don't want.
-        const char *startId = href_strarray[0] + 1;
+        const char *startId = _connEnd[0]->href + 1;
         GQuark itemId = g_quark_from_string(startId);
         _connRef->setEndPointId(Avoid::VertID::src, itemId);
-        g_strfreev(href_strarray);
     }
     else {
         _connRef->setEndPointId(Avoid::VertID::src, 0);
     }
     if (_connEnd[1]->href) {
-        gchar ** href_strarray = NULL;
-        href_strarray = g_strsplit(_connEnd[1]->href, "_", 0);
         // href begins with a '#' which we don't want.
-        const char *endId = href_strarray[0] + 1;
+        const char *endId = _connEnd[1]->href + 1;
         GQuark itemId = g_quark_from_string(endId);
         _connRef->setEndPointId(Avoid::VertID::tar, itemId);
-        g_strfreev(href_strarray);
     }
     else {
         _connRef->setEndPointId(Avoid::VertID::tar, 0);
@@ -339,7 +341,7 @@ void recreateCurve(SPCurve *curve, Avoid::ConnRef *connRef, const gdouble curvat
     if (!straight)
         route = route.curvedPolyline(curvature);
     connRef->calcRouteDist();
-    
+
     curve->reset();
 
     curve->moveto( Geom::Point(route.ps[0].x, route.ps[0].y) );
@@ -359,7 +361,7 @@ void recreateCurve(SPCurve *curve, Avoid::ConnRef *connRef, const gdouble curvat
                     break;
                 case 'C':
                     g_assert( i+2<pn );
-                    curve->curveto( p, Geom::Point(route.ps[i+1].x, route.ps[i+1].y), 
+                    curve->curveto( p, Geom::Point(route.ps[i+1].x, route.ps[i+1].y),
                             Geom::Point(route.ps[i+2].x, route.ps[i+2].y) );
                     i+=2;
                     break;
@@ -404,10 +406,10 @@ SPConnEndPair::reroutePathFromLibavoid(void)
     SPCurve *curve = _path->original_curve ?_path->original_curve : _path->curve;
 
     recreateCurve( curve, _connRef, _connCurvature );
-    
-    Geom::Matrix doc2item = sp_item_i2doc_affine(SP_ITEM(_path)).inverse();
-    curve->transform(doc2item); 
-    
+
+    Geom::Matrix doc2item = SP_ITEM(_path)->i2doc_affine().inverse();
+    curve->transform(doc2item);
+
     return true;
 }