index cde387c5b5be6443193aa6c2516b8acc8461df13..3526b3f1594b3b37e8ca52c53416ffe706d104dd 100644 (file)
* vim: ts=4 sw=4 et tw=0 wm=0
*
* libavoid - Fast, Incremental, Object-avoiding Line Router
* vim: ts=4 sw=4 et tw=0 wm=0
*
* libavoid - Fast, Incremental, Object-avoiding Line Router
- * Copyright (C) 2004-2005 Michael Wybrow <mjwybrow@users.sourceforge.net>
+ * Copyright (C) 2004-2006 Michael Wybrow <mjwybrow@users.sourceforge.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
*/
#include "libavoid/graph.h"
*/
#include "libavoid/graph.h"
+#include "libavoid/connector.h"
#include "libavoid/makepath.h"
#include "libavoid/visibility.h"
#include "libavoid/debug.h"
#include "libavoid/makepath.h"
#include "libavoid/visibility.h"
#include "libavoid/debug.h"
+#include "libavoid/router.h"
namespace Avoid {
namespace Avoid {
-ConnRefList connRefs;
-
-
-ConnRef::ConnRef(const uint id)
- : _id(id)
+ConnRef::ConnRef(Router *router, const unsigned int id)
+ : _router(router)
+ , _id(id)
+ , _type(ConnType_PolyLine)
+ , _srcId(0)
+ , _dstId(0)
, _needs_reroute_flag(true)
, _false_path(false)
, _active(false)
, _needs_reroute_flag(true)
, _false_path(false)
, _active(false)
, _initialised(false)
, _callback(NULL)
, _connector(NULL)
, _initialised(false)
, _callback(NULL)
, _connector(NULL)
+ , _hateCrossings(false)
{
// TODO: Store endpoints and details.
_route.pn = 0;
{
// TODO: Store endpoints and details.
_route.pn = 0;
}
}
-ConnRef::ConnRef(const uint id, const Point& src, const Point& dst)
- : _id(id)
+ConnRef::ConnRef(Router *router, const unsigned int id,
+ const Point& src, const Point& dst)
+ : _router(router)
+ , _id(id)
+ , _type(ConnType_PolyLine)
+ , _srcId(0)
+ , _dstId(0)
, _needs_reroute_flag(true)
, _false_path(false)
, _active(false)
, _needs_reroute_flag(true)
, _false_path(false)
, _active(false)
, _initialised(false)
, _callback(NULL)
, _connector(NULL)
, _initialised(false)
, _callback(NULL)
, _connector(NULL)
+ , _hateCrossings(false)
{
_route.pn = 0;
_route.ps = NULL;
{
_route.pn = 0;
_route.ps = NULL;
- if (IncludeEndpoints)
+ if (_router->IncludeEndpoints)
{
bool isShape = false;
{
bool isShape = false;
- _srcVert = new VertInf(VertID(id, isShape, 1), src);
- _dstVert = new VertInf(VertID(id, isShape, 2), dst);
- vertices.addVertex(_srcVert);
- vertices.addVertex(_dstVert);
+ _srcVert = new VertInf(_router, VertID(id, isShape, 1), src);
+ _dstVert = new VertInf(_router, VertID(id, isShape, 2), dst);
+ _router->vertices.addVertex(_srcVert);
+ _router->vertices.addVertex(_dstVert);
makeActive();
_initialised = true;
}
makeActive();
_initialised = true;
}
if (_srcVert)
{
if (_srcVert)
{
- vertices.removeVertex(_srcVert);
+ _router->vertices.removeVertex(_srcVert);
delete _srcVert;
_srcVert = NULL;
}
if (_dstVert)
{
delete _srcVert;
_srcVert = NULL;
}
if (_dstVert)
{
- vertices.removeVertex(_dstVert);
+ _router->vertices.removeVertex(_dstVert);
delete _dstVert;
_dstVert = NULL;
}
delete _dstVert;
_dstVert = NULL;
}
}
}
}
}
-void ConnRef::updateEndPoint(const uint type, const Point& point)
+
+void ConnRef::setType(unsigned int type)
+{
+ _type = type;
+}
+
+
+void ConnRef::updateEndPoint(const unsigned int type, const Point& point)
{
{
- assert((type == (uint) VertID::src) || (type == (uint) VertID::tar));
- //assert(IncludeEndpoints);
+ assert((type == (unsigned int) VertID::src) ||
+ (type == (unsigned int) VertID::tar));
+
+ // XXX: This was commented out. Is there a case where it isn't true?
+ assert(_router->IncludeEndpoints);
+ if (!_initialised)
+ {
+ makeActive();
+ _initialised = true;
+ }
+
VertInf *altered = NULL;
VertInf *partner = NULL;
bool isShape = false;
VertInf *altered = NULL;
VertInf *partner = NULL;
bool isShape = false;
- if (type == (uint) VertID::src)
+ if (type == (unsigned int) VertID::src)
{
if (_srcVert)
{
{
if (_srcVert)
{
}
else
{
}
else
{
- _srcVert = new VertInf(VertID(_id, isShape, type), point);
- vertices.addVertex(_srcVert);
+ _srcVert = new VertInf(_router, VertID(_id, isShape, type), point);
+ _router->vertices.addVertex(_srcVert);
}
altered = _srcVert;
partner = _dstVert;
}
}
altered = _srcVert;
partner = _dstVert;
}
- else // if (type == (uint) VertID::dst)
+ else // if (type == (unsigned int) VertID::dst)
{
if (_dstVert)
{
{
if (_dstVert)
{
}
else
{
}
else
{
- _dstVert = new VertInf(VertID(_id, isShape, type), point);
- vertices.addVertex(_dstVert);
+ _dstVert = new VertInf(_router, VertID(_id, isShape, type), point);
+ _router->vertices.addVertex(_dstVert);
}
altered = _dstVert;
partner = _srcVert;
}
}
altered = _dstVert;
partner = _srcVert;
}
-
- bool knownNew = false;
+
+ // XXX: Seems to be faster to just remove the edges and recreate
+ bool isConn = true;
+ altered->removeFromGraph(isConn);
+ bool knownNew = true;
vertexVisibility(altered, partner, knownNew, true);
}
vertexVisibility(altered, partner, knownNew, true);
}
+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;
+ }
+}
+
+
+unsigned int ConnRef::getSrcShapeId(void)
+{
+ return _srcId;
+}
+
+
+unsigned int ConnRef::getDstShapeId(void)
+{
+ return _dstId;
+}
+
+
void ConnRef::makeActive(void)
{
assert(!_active);
// Add to connRefs list.
void ConnRef::makeActive(void)
{
assert(!_active);
// Add to connRefs list.
- _pos = connRefs.insert(connRefs.begin(), this);
+ _pos = _router->connRefs.insert(_router->connRefs.begin(), this);
_active = true;
}
_active = true;
}
assert(_active);
// Remove from connRefs list.
assert(_active);
// Remove from connRefs list.
- connRefs.erase(_pos);
+ _router->connRefs.erase(_pos);
_active = false;
}
_active = false;
}
}
}
-void ConnRef::moveRoute(const int& diff_x, const int& diff_y)
-{
- for (int i = 0; i < _route.pn; i++)
- {
- _route.ps[i].x += diff_x;
- _route.ps[i].y += diff_y;
- }
-}
-
-
void ConnRef::lateSetup(const Point& src, const Point& dst)
{
assert(!_initialised);
bool isShape = false;
void ConnRef::lateSetup(const Point& src, const Point& dst)
{
assert(!_initialised);
bool isShape = false;
- _srcVert = new VertInf(VertID(_id, isShape, 1), src);
- _dstVert = new VertInf(VertID(_id, isShape, 2), dst);
- vertices.addVertex(_srcVert);
- vertices.addVertex(_dstVert);
+ _srcVert = new VertInf(_router, VertID(_id, isShape, 1), src);
+ _dstVert = new VertInf(_router, VertID(_id, isShape, 2), dst);
+ _router->vertices.addVertex(_srcVert);
+ _router->vertices.addVertex(_dstVert);
makeActive();
_initialised = true;
}
makeActive();
_initialised = true;
}
+unsigned int ConnRef::id(void)
+{
+ return _id;
+}
+
+
VertInf *ConnRef::src(void)
{
return _srcVert;
VertInf *ConnRef::src(void)
{
return _srcVert;
void ConnRef::unInitialise(void)
{
void ConnRef::unInitialise(void)
{
- vertices.removeVertex(_srcVert);
- vertices.removeVertex(_dstVert);
+ _router->vertices.removeVertex(_srcVert);
+ _router->vertices.removeVertex(_dstVert);
makeInactive();
_initialised = false;
}
makeInactive();
_initialised = false;
}
}
}
+Router *ConnRef::router(void)
+{
+ return _router;
+}
+
+
int ConnRef::generatePath(Point p0, Point p1)
{
if (!_false_path && !_needs_reroute_flag) {
int ConnRef::generatePath(Point p0, Point p1)
{
if (!_false_path && !_needs_reroute_flag) {
_false_path = false;
_needs_reroute_flag = false;
_false_path = false;
_needs_reroute_flag = false;
-
+
VertInf *src = _srcVert;
VertInf *tar = _dstVert;
VertInf *src = _srcVert;
VertInf *tar = _dstVert;
-
- if (!IncludeEndpoints)
+
+ if ( !(_router->IncludeEndpoints) )
{
lateSetup(p0, p1);
{
lateSetup(p0, p1);
tar = _dstVert;
bool knownNew = true;
tar = _dstVert;
bool knownNew = true;
- vertexVisibility(src, tar, knownNew);
- vertexVisibility(tar, src, knownNew);
+ bool genContains = true;
+ vertexVisibility(src, tar, knownNew, genContains);
+ vertexVisibility(tar, src, knownNew, genContains);
}
bool *flag = &(_needs_reroute_flag);
}
bool *flag = &(_needs_reroute_flag);
db_printf("Warning: Path not found...\n");
pathlen = 2;
tar->pathNext = src;
db_printf("Warning: Path not found...\n");
pathlen = 2;
tar->pathNext = src;
- if (InvisibilityGrph)
+ if (_router->InvisibilityGrph)
{
// TODO: Could we know this edge already?
EdgeInf *edge = EdgeInf::existingEdge(src, tar);
{
// TODO: Could we know this edge already?
EdgeInf *edge = EdgeInf::existingEdge(src, tar);
int j = pathlen - 1;
for (VertInf *i = tar; i != src; i = i->pathNext)
{
int j = pathlen - 1;
for (VertInf *i = tar; i != src; i = i->pathNext)
{
- if (InvisibilityGrph)
+ if (_router->InvisibilityGrph)
{
// TODO: Again, we could know this edge without searching.
EdgeInf *edge = EdgeInf::existingEdge(i, i->pathNext);
{
// TODO: Again, we could know this edge without searching.
EdgeInf *edge = EdgeInf::existingEdge(i, i->pathNext);
{
_false_path = true;
}
{
_false_path = true;
}
- path[j--] = i->point;
+ path[j] = i->point;
+ path[j].id = i->id.objID;
+ j--;
}
path[0] = src->point;
}
path[0] = src->point;
PolyLine& output_route = route();
output_route.pn = pathlen;
output_route.ps = path;
PolyLine& output_route = route();
output_route.pn = pathlen;
output_route.ps = path;
+
+ if ( !(_router->IncludeEndpoints) )
+ {
+ assert(_initialised);
+ unInitialise();
+ }
return (int) result;
}
return (int) result;
}
-//============================================================================
+void ConnRef::setHateCrossings(bool value)
+{
+ _hateCrossings = value;
+}
- // It's intended this function is called after shape movement has
- // happened to alert connectors that they need to be rerouted.
-void callbackAllInvalidConnectors(void)
+bool ConnRef::doesHateCrossings(void)
{
{
- ConnRefList::iterator fin = connRefs.end();
- for (ConnRefList::iterator i = connRefs.begin(); i != fin; ++i) {
- (*i)->handleInvalid();
- }
+ return _hateCrossings;
}
}
+//============================================================================
+
}
}