From fa668afcbd7dc12ef748e0d0b4fd62fb9441c13e Mon Sep 17 00:00:00 2001 From: mjwybrow Date: Tue, 14 Feb 2006 00:36:28 +0000 Subject: * src/graphlayout/graphlayout.cpp, src/conn-avoid-ref.cpp, src/conn-avoid-ref.h, src/libavoid/connector.cpp, src/libavoid/connector.h: Change the behaviour and naming of some connector querying code after feedback from Tim Dwyer in implementing graph drawing functionality. (bzr r136) --- src/libavoid/connector.cpp | 33 ++++++++++++++++++++++++++++++++- src/libavoid/connector.h | 8 ++++++-- 2 files changed, 38 insertions(+), 3 deletions(-) (limited to 'src/libavoid') diff --git a/src/libavoid/connector.cpp b/src/libavoid/connector.cpp index 06a0cd4aa..4d5821741 100644 --- a/src/libavoid/connector.cpp +++ b/src/libavoid/connector.cpp @@ -421,8 +421,14 @@ const unsigned int ConnRef::runningFrom = 2; const unsigned int ConnRef::runningToAndFrom = ConnRef::runningTo | ConnRef::runningFrom; +// XXX: attachedShapes and attachedConns both need to be rewritten +// for constant time lookup of attached objects once this info +// is stored better within libavoid. -void attachedToShape(IntList &conns, const unsigned int shapeId, + + // Returns a list of connector Ids of all the connectors of type + // 'type' attached to the shape with the ID 'shapeId'. +void attachedConns(IntList &conns, const unsigned int shapeId, const unsigned int type) { ConnRefList::iterator fin = connRefs.end(); @@ -437,6 +443,31 @@ void attachedToShape(IntList &conns, const unsigned int shapeId, } + // Returns a list of shape Ids of all the shapes attached to the + // shape with the ID 'shapeId' with connection type 'type'. +void attachedShapes(IntList &shapes, 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)) { + if ((*i)->_srcId != 0) + { + // Only if there is a shape attached to the other end. + shapes.push_back((*i)->_srcId); + } + } + else if ((type & ConnRef::runningFrom) && ((*i)->_srcId == shapeId)) { + if ((*i)->_dstId != 0) + { + // Only if there is a shape attached to the other end. + shapes.push_back((*i)->_dstId); + } + } + } +} + + // It's intended this function is called after shape movement has // happened to alert connectors that they need to be rerouted. void callbackAllInvalidConnectors(void) diff --git a/src/libavoid/connector.h b/src/libavoid/connector.h index 1fd4255a8..a08b9ab8a 100644 --- a/src/libavoid/connector.h +++ b/src/libavoid/connector.h @@ -64,7 +64,9 @@ class ConnRef void makePathInvalid(void); friend void markConnectors(ShapeRef *shape); - friend void attachedToShape(IntList &conns, + friend void attachedShapes(IntList &shapes, + const unsigned int shapeId, const unsigned int type); + friend void attachedConns(IntList &conns, const unsigned int shapeId, const unsigned int type); static const unsigned int runningTo; @@ -91,7 +93,9 @@ class ConnRef extern ConnRefList connRefs; extern void callbackAllInvalidConnectors(void); -extern void attachedToShape(IntList &conns, const unsigned int shapeId, +extern void attachedConns(IntList &conns, const unsigned int shapeId, + const unsigned int type); +extern void attachedShapes(IntList &shapes, const unsigned int shapeId, const unsigned int type); } -- cgit v1.2.3