Code

fix guide dragging
[inkscape.git] / src / sp-conn-end-pair.cpp
index a1c4697e55007eecbd85d90faa8ee94354303e5a..d13ef9e86a00f022f0f3c31df91e484928adec2d 100644 (file)
@@ -19,6 +19,7 @@
 #include "libavoid/vertices.h"
 #include "libavoid/router.h"
 #include "document.h"
+#include "sp-item-group.h"
 
 
 SPConnEndPair::SPConnEndPair(SPPath *const owner)
@@ -76,7 +77,7 @@ sp_conn_end_pair_build(SPObject *object)
 
 
 static void
-avoid_conn_move(NR::Matrix const *mp, SPItem *moved_item)
+avoid_conn_move(NR::Matrix const */*mp*/, SPItem *moved_item)
 {
     // Reroute connector
     SPPath *path = SP_PATH(moved_item);
@@ -138,6 +139,20 @@ void
 SPConnEndPair::getAttachedItems(SPItem *h2attItem[2]) const {
     for (unsigned h = 0; h < 2; ++h) {
         h2attItem[h] = this->_connEnd[h]->ref.getObject();
+
+        // Deal with the case of the attached object being an empty group.
+        // A group containing no items does not have a valid bbox, so
+        // causes problems for the auto-routing code.  Also, since such a
+        // group no longer has an onscreen representation and can only be
+        // selected through the XML editor, it makes sense just to detach
+        // connectors from them.
+        if (SP_IS_GROUP(h2attItem[h])) {
+            if (SP_GROUP(h2attItem[h])->group->getItemCount() == 0) {
+                // This group is empty, so detach.
+                sp_conn_end_detach(_path, h);
+                h2attItem[h] = NULL;
+            }
+        }
     }
 }
 
@@ -149,8 +164,13 @@ SPConnEndPair::getEndpoints(NR::Point endPts[]) const {
 
     for (unsigned h = 0; h < 2; ++h) {
         if ( h2attItem[h] ) {
-            NR::Rect const bbox = h2attItem[h]->invokeBbox(sp_item_i2doc_affine(h2attItem[h]));
-            endPts[h] = bbox.midpoint();
+            NR::Maybe<NR::Rect> bbox = h2attItem[h]->getBounds(sp_item_i2doc_affine(h2attItem[h]));
+            if (bbox) {
+                endPts[h] = bbox->midpoint();
+            } else {
+                // FIXME
+                endPts[h] = NR::Point(0, 0);
+            }
         }
         else
         {
@@ -205,8 +225,8 @@ SPConnEndPair::update(void)
             NR::Point endPt[2];
             getEndpoints(endPt);
 
-            Avoid::Point src = { endPt[0][NR::X], endPt[0][NR::Y] };
-            Avoid::Point dst = { endPt[1][NR::X], endPt[1][NR::Y] };
+            Avoid::Point src(endPt[0][NR::X], endPt[0][NR::Y]);
+            Avoid::Point dst(endPt[1][NR::X], endPt[1][NR::Y]);
 
             _connRef->lateSetup(src, dst);
             _connRef->setCallback(&emitPathInvalidationNotification, _path);
@@ -268,8 +288,8 @@ SPConnEndPair::reroutePath(void)
     NR::Point endPt[2];
     getEndpoints(endPt);
 
-    Avoid::Point src = { endPt[0][NR::X], endPt[0][NR::Y] };
-    Avoid::Point dst = { endPt[1][NR::X], endPt[1][NR::Y] };
+    Avoid::Point src(endPt[0][NR::X], endPt[0][NR::Y]);
+    Avoid::Point dst(endPt[1][NR::X], endPt[1][NR::Y]);
 
     _connRef->updateEndPoint(Avoid::VertID::src, src);
     _connRef->updateEndPoint(Avoid::VertID::tar, dst);