Code

* src/sp-conn-end-pair.cpp, src/sp-conn-end-pair.h,
authormjwybrow <mjwybrow@users.sourceforge.net>
Fri, 10 Feb 2006 04:23:35 +0000 (04:23 +0000)
committermjwybrow <mjwybrow@users.sourceforge.net>
Fri, 10 Feb 2006 04:23:35 +0000 (04:23 +0000)
  src/conn-avoid-ref.cpp, src/conn-avoid-ref.h,
  src/libavoid/connector.cpp, src/libavoid/connector.h,
  src/libavoid/visibility.cpp:

Add some code to allow querying of items and connectors to find
out what is attached to them.  This will allow graph layout
algorithms (currently being work on by Tim Dwyer) to determine
a graph structure from the diagram.

ChangeLog
src/conn-avoid-ref.cpp
src/conn-avoid-ref.h
src/libavoid/connector.cpp
src/libavoid/connector.h
src/libavoid/visibility.cpp
src/sp-conn-end-pair.cpp
src/sp-conn-end-pair.h

index 79e1f51f1cf66e394e1dfde934bedcce5e216606..12d7681955fd552e74222c0d849d4d4968d68e51 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,12 +1,24 @@
+2006-02-10  Michael Wybrow  <mjwybrow@users.sourceforge.net>
+
+       * src/sp-conn-end-pair.cpp, src/sp-conn-end-pair.h,
+         src/conn-avoid-ref.cpp, src/conn-avoid-ref.h,
+         src/libavoid/connector.cpp, src/libavoid/connector.h,
+         src/libavoid/visibility.cpp:
+
+       Add some code to allow querying of items and connectors to find
+       out what is attached to them.  This will allow graph layout
+       algorithms (currently being work on by Tim Dwyer) to determine 
+       a graph structure from the diagram.
+
 2006-02-07  MenTaLguY  <mental@rydia.net>
 
        * src/widgets/icon.cpp: get rid of icon prerender time messages
 
 2006-02-07  MenTaLguY  <mental@rydia.net>
 
-    * src/debug/gc-heap.h, src/debug/logger.cpp, src/debug/sysv-heap.h,
-      src/jabber_whiteboard/deserializer.cpp, src/sp-object.cpp,
-      src/util/share.h, src/xml/simple-node.cpp:
+       * src/debug/gc-heap.h, src/debug/logger.cpp, src/debug/sysv-heap.h,
+         src/jabber_whiteboard/deserializer.cpp, src/sp-object.cpp,
+         src/util/share.h, src/xml/simple-node.cpp:
 
       share_static -> share_static_string
 
index 6575609022ba557f48479756250e90ed29b299af..8fbdfb6739a97e491fbd77f27f7cdcddaa098566 100644 (file)
@@ -16,6 +16,7 @@
 #include "libnr/nr-rect-ops.h"
 #include "libavoid/polyutil.h"
 #include "libavoid/incremental.h"
+#include "libavoid/connector.h"
 #include "xml/simple-node.cpp"
 #include "document.h"
 #include "prefs-utils.h"
@@ -108,6 +109,25 @@ void SPAvoidRef::handleSettingChange(void)
 }
 
 
+GSList *SPAvoidRef::getAttachedConnectors(const unsigned int type)
+{
+    GSList *list = NULL;
+
+    Avoid::IntList conns;
+    GQuark shapeId = g_quark_from_string(item->id);
+    Avoid::attachedToShape(conns, shapeId, type);
+    
+    Avoid::IntList::iterator finish = conns.end();
+    for (Avoid::IntList::iterator i = conns.begin(); i != finish; ++i) {
+        const gchar *connId = g_quark_to_string(*i);
+        SPItem *item = SP_ITEM(item->document->getObjectById(connId));
+        g_assert(item != NULL);
+        list = g_slist_prepend(list, item);
+    }
+    return list;
+}
+
+
 static Avoid::Polygn avoid_item_poly(SPItem const *item)
 {
     SPDesktop *desktop = inkscape_active_desktop();
index ac9295cf917450307ab3a3c23834d15ce04b6757..28d5de28a2fcc69747502620c01a19607efe5607 100644 (file)
@@ -30,6 +30,13 @@ public:
 
     void setAvoid(char const *value);
     void handleSettingChange(void);
+    
+    // Returns a list of SPItems of all connectors attached to this
+    // object.  Pass one of the following for 'type':
+    //     Avoid::ConnRef::runningTo
+    //     Avoid::ConnRef::runningFrom
+    //     Avoid::ConnRef::runningToAndFrom
+    GSList *getAttachedConnectors(const unsigned int type);
 
 private:
     SPItem *item;
index 87009541593c4b8a65be7071e0fd8ad84d05d027..04bf7aaada6b573ad8479174a4f263d343b934f0 100644 (file)
@@ -20,6 +20,7 @@
  * 
 */
 
+#include "libavoid/connector.h"
 #include "libavoid/graph.h"
 #include "libavoid/makepath.h"
 #include "libavoid/visibility.h"
@@ -34,6 +35,8 @@ ConnRefList connRefs;
 
 ConnRef::ConnRef(const unsigned int id)
     : _id(id)
+    , _srcId(0)
+    , _dstId(0)
     , _needs_reroute_flag(true)
     , _false_path(false)
     , _active(false)
@@ -52,6 +55,8 @@ ConnRef::ConnRef(const unsigned int id)
 
 ConnRef::ConnRef(const unsigned int id, const Point& src, const Point& dst)
     : _id(id)
+    , _srcId(0)
+    , _dstId(0)
     , _needs_reroute_flag(true)
     , _false_path(false)
     , _active(false)
@@ -154,6 +159,19 @@ void ConnRef::updateEndPoint(const unsigned int type, const Point& point)
 }
 
 
+void ConnRef::setEndPointId(const unsigned int type, const unsigned int id)
+{
+    if (type == (unsigned int) VertID::src)
+    {
+        _srcId = id;
+    }
+    else  // if (type == (unsigned int) VertID::dst)
+    {
+        _dstId = id;
+    }
+}
+
+
 void ConnRef::makeActive(void)
 {
     assert(!_active);
@@ -398,6 +416,26 @@ int ConnRef::generatePath(Point p0, Point p1)
 
 //============================================================================
 
+const unsigned int ConnRef::runningTo = 1;
+const unsigned int ConnRef::runningFrom = 2;
+const unsigned int ConnRef::runningToAndFrom =
+        ConnRef::runningTo | ConnRef::runningFrom;
+
+
+void attachedToShape(IntList &conns, const unsigned int shapeId,
+        const unsigned int type)
+{
+    ConnRefList::iterator fin = connRefs.end();
+    for (ConnRefList::iterator i = connRefs.begin(); i != fin; ++i) {
+        if ((type & ConnRef::runningTo) && ((*i)->_dstId == shapeId)) {
+            conns.push_back((*i)->_id);
+        }
+        else if ((type & ConnRef::runningFrom) && ((*i)->_srcId == shapeId)) {
+            conns.push_back((*i)->_id);
+        }
+    }
+}
+
 
     // It's intended this function is called after shape movement has 
     // happened to alert connectors that they need to be rerouted.
index 71713ae414ac61552d5d0b7012b2c1269160eaa5..1fd4255a8a6726550bd99aee289bf190d78fd4e1 100644 (file)
@@ -33,6 +33,7 @@ namespace Avoid {
 class ConnRef;
 
 typedef std::list<ConnRef *> ConnRefList;
+typedef std::list<unsigned int> IntList;
 
 
 class ConnRef
@@ -48,6 +49,7 @@ class ConnRef
         void freeRoute(void);
         void calcRouteDist(void);
         void updateEndPoint(const unsigned int type, const Point& point);
+        void setEndPointId(const unsigned int type, const unsigned int id);
         void makeActive(void);
         void makeInactive(void);
         void lateSetup(const Point& src, const Point& dst);
@@ -62,9 +64,16 @@ class ConnRef
         void makePathInvalid(void);
         
         friend void markConnectors(ShapeRef *shape);
+        friend void attachedToShape(IntList &conns,
+                const unsigned int shapeId, const unsigned int type);
 
+        static const unsigned int runningTo;
+        static const unsigned int runningFrom;
+        static const unsigned int runningToAndFrom;
+        
     private:
         unsigned int _id;
+        unsigned int _srcId, _dstId;
         bool _needs_reroute_flag;
         bool _false_path;
         bool _active;
@@ -82,6 +91,8 @@ class ConnRef
 extern ConnRefList connRefs;
 
 extern void callbackAllInvalidConnectors(void);
+extern void attachedToShape(IntList &conns, const unsigned int shapeId,
+        const unsigned int type);
 
 }
 
index 84e38037d2531f8a8fa3b13931ac622d2b841e58..6154bd39678fd30adbd098b7eb210bb522e2b6bd 100644 (file)
@@ -26,7 +26,9 @@
 #include "libavoid/shape.h"
 #include "libavoid/debug.h"
 #include "libavoid/visibility.h"
+#include "libavoid/vertices.h"
 #include "libavoid/graph.h"
+#include "libavoid/geometry.h"
 
 #include <math.h>
 
@@ -602,7 +604,9 @@ void vertexSweep(VertInf *vert)
             EdgeSet::iterator ePtr;
             if (prevDir == BEHIND)
             {
-                ePtr = e.find(prevPair);
+                // XXX: Strangely e.find does not return the correct results.
+                // ePtr = e.find(prevPair);
+                ePtr = std::find(e.begin(), e.end(), prevPair);
                 if (ePtr != e.end())
                 {
                     e.erase(ePtr);
@@ -625,7 +629,9 @@ void vertexSweep(VertInf *vert)
 
             if (nextDir == BEHIND)
             {
-                ePtr = e.find(nextPair);
+                // XXX: Strangely e.find does not return the correct results.
+                // ePtr = e.find(nextPair);
+                ePtr = std::find(e.begin(), e.end(), nextPair);
                 if (ePtr != e.end())
                 {
                     e.erase(ePtr);
index ff1005a1636e474c130a08289008ef803c731cb0..bb5d89107f521b617b9f4034e093b450a2dede71 100644 (file)
@@ -211,9 +211,30 @@ SPConnEndPair::update(void)
             _connRef->lateSetup(src, dst);
             _connRef->setCallback(&emitPathInvalidationNotification, _path);
         }
+        // Store the ID of the objects attached to the connector.
+        storeIds();
     }
 }
-    
+
+
+void SPConnEndPair::storeIds(void)
+{
+    if (_connEnd[0]->href) {
+        GQuark itemId = g_quark_from_string(_connEnd[0]->href);
+        _connRef->setEndPointId(Avoid::VertID::src, itemId);
+    }
+    else {
+        _connRef->setEndPointId(Avoid::VertID::src, 0);
+    }
+    if (_connEnd[1]->href) {
+        GQuark itemId = g_quark_from_string(_connEnd[1]->href);
+        _connRef->setEndPointId(Avoid::VertID::tar, itemId);
+    }
+    else {
+        _connRef->setEndPointId(Avoid::VertID::tar, 0);
+    }
+}
+
 
 bool
 SPConnEndPair::isAutoRoutingConn(void)
index 9807b4f149093bc5ad9835b44539251306e9d573..3f130da32661058a37e0c22e9e20c2e93a2282bf 100644 (file)
@@ -64,6 +64,8 @@ private:
     
     // A sigc connection for transformed signal.
     sigc::connection _transformed_connection;
+    
+    void storeIds(void);
 };