diff options
| -rw-r--r-- | ChangeLog | 18 | ||||
| -rw-r--r-- | src/conn-avoid-ref.cpp | 20 | ||||
| -rw-r--r-- | src/conn-avoid-ref.h | 7 | ||||
| -rw-r--r-- | src/libavoid/connector.cpp | 38 | ||||
| -rw-r--r-- | src/libavoid/connector.h | 11 | ||||
| -rw-r--r-- | src/libavoid/visibility.cpp | 10 | ||||
| -rw-r--r-- | src/sp-conn-end-pair.cpp | 23 | ||||
| -rw-r--r-- | src/sp-conn-end-pair.h | 2 |
8 files changed, 123 insertions, 6 deletions
@@ -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 diff --git a/src/conn-avoid-ref.cpp b/src/conn-avoid-ref.cpp index 657560902..8fbdfb673 100644 --- a/src/conn-avoid-ref.cpp +++ b/src/conn-avoid-ref.cpp @@ -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(); diff --git a/src/conn-avoid-ref.h b/src/conn-avoid-ref.h index ac9295cf9..28d5de28a 100644 --- a/src/conn-avoid-ref.h +++ b/src/conn-avoid-ref.h @@ -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; diff --git a/src/libavoid/connector.cpp b/src/libavoid/connector.cpp index 870095415..04bf7aaad 100644 --- a/src/libavoid/connector.cpp +++ b/src/libavoid/connector.cpp @@ -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. diff --git a/src/libavoid/connector.h b/src/libavoid/connector.h index 71713ae41..1fd4255a8 100644 --- a/src/libavoid/connector.h +++ b/src/libavoid/connector.h @@ -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); } diff --git a/src/libavoid/visibility.cpp b/src/libavoid/visibility.cpp index 84e38037d..6154bd396 100644 --- a/src/libavoid/visibility.cpp +++ b/src/libavoid/visibility.cpp @@ -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); diff --git a/src/sp-conn-end-pair.cpp b/src/sp-conn-end-pair.cpp index ff1005a16..bb5d89107 100644 --- a/src/sp-conn-end-pair.cpp +++ b/src/sp-conn-end-pair.cpp @@ -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) diff --git a/src/sp-conn-end-pair.h b/src/sp-conn-end-pair.h index 9807b4f14..3f130da32 100644 --- a/src/sp-conn-end-pair.h +++ b/src/sp-conn-end-pair.h @@ -64,6 +64,8 @@ private: // A sigc connection for transformed signal. sigc::connection _transformed_connection; + + void storeIds(void); }; |
