Code

* src/conn-avoid-ref.cpp, src/libavoid/connector.h,
authormjwybrow <mjwybrow@users.sourceforge.net>
Wed, 1 Mar 2006 01:48:07 +0000 (01:48 +0000)
committermjwybrow <mjwybrow@users.sourceforge.net>
Wed, 1 Mar 2006 01:48:07 +0000 (01:48 +0000)
      src/libavoid/shape.cpp, src/libavoid/graph.cpp, src/libavoid/shape.h,
      src/libavoid/graph.h, src/libavoid/router.cpp, src/libavoid/router.h,
      src/libavoid/connector.cpp, src/libavoid/debug.h:

      Some speed improvements and interface cleanups to libavoid.

ChangeLog
src/conn-avoid-ref.cpp
src/libavoid/connector.cpp
src/libavoid/connector.h
src/libavoid/debug.h
src/libavoid/graph.cpp
src/libavoid/graph.h
src/libavoid/router.cpp
src/libavoid/router.h
src/libavoid/shape.cpp
src/libavoid/shape.h

index 2c35fb7ba6e48ca210e619db5a9917a43cb2afb6..69abdd7c87e4ffdb2d8a4726758c0f1ac7412ce5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2006-03-01  Michael Wybrow  <mjwybrow@users.sourceforge.net>
+
+       * src/conn-avoid-ref.cpp, src/libavoid/connector.h,
+         src/libavoid/shape.cpp, src/libavoid/graph.cpp, src/libavoid/shape.h,
+         src/libavoid/graph.h, src/libavoid/router.cpp, src/libavoid/router.h,
+         src/libavoid/connector.cpp, src/libavoid/debug.h:
+
+         Some speed improvements and interface cleanups to libavoid.
+
 2006-02-28  Jon A. Cruz  <jon@joncruz.org>
        * src/dialogs/swatches.cpp:
 
index df885d44c61717d425bbe5e3c54aeaa153512718..5de222adef48e3f4945536e02d63c6f67d88655f 100644 (file)
@@ -253,8 +253,7 @@ void avoid_item_move(NR::Matrix const *mp, SPItem *moved_item)
     Router *router = moved_item->document->router;
     Avoid::Polygn poly = avoid_item_poly(moved_item);
     if (poly.pn > 0) {
-        // moveShape actually destroys the old shapeRef and returns a new one.
-        moved_item->avoidRef->shapeRef = router->moveShape(shapeRef, &poly);
+        router->moveShape(shapeRef, &poly);
         Avoid::freePoly(poly);
     }
 }
index d8c299ba0aab1e07b733ab4b0f7fac0fda00799e..a9f1446889cc4eff3335fa4218de2509265c6815 100644 (file)
@@ -235,16 +235,6 @@ bool ConnRef::needsReroute(void)
 }
 
 
-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);
index 81f79641fade8cddabfe16d6eec4eb8e8d78c924..0ec5890a1f2a89d5b3bb4d0d0d9debb919baa916 100644 (file)
@@ -47,7 +47,6 @@ class ConnRef
         void setType(unsigned int type);
         PolyLine& route(void);
         bool needsReroute(void);
-        void moveRoute(const int& diff_x, const int& diff_y);
         void freeRoute(void);
         void calcRouteDist(void);
         void updateEndPoint(const unsigned int type, const Point& point);
index 1a6879e85a979d085325cc04578f1be30ec20b07..1312c54586ae513bf9a1b403ea284a5c671e6a4c 100644 (file)
 #define AVOID_DEBUG_H
 
 
-
-#ifndef NDEBUG
-  //#define DBPRINTF_DEBUG
-#endif
-
-
-#ifdef DBPRINTF_DEBUG
+#ifdef LIBAVOID_DEBUG
 
 #include <stdarg.h>
 #include <iostream>
@@ -39,7 +33,7 @@
 
 namespace Avoid {
 
-#ifdef DBPRINTF_DEBUG
+#ifdef LIBAVOID_DEBUG
 inline void db_printf(const char *fmt, ...)
 {
     va_list ap;
index 5e41f79f548ba5702a079423681f059e69a105fc..c8f061f6a56b2ae08e03bbff8dfa5a8faad95fee 100644 (file)
@@ -37,6 +37,7 @@ namespace Avoid {
 EdgeInf::EdgeInf(VertInf *v1, VertInf *v2)
     : lstPrev(NULL)
     , lstNext(NULL)
+    , _blocker(0)
     , _router(NULL)
     , _added(false)
     , _visible(false)
@@ -51,7 +52,6 @@ EdgeInf::EdgeInf(VertInf *v1, VertInf *v2)
     assert(_v1->_router == _v2->_router);
     _router = _v1->_router;
 
-    _blockers.clear();
     _conns.clear();
 }
 
@@ -109,18 +109,12 @@ void EdgeInf::makeInactive(void)
         _v2->invisList.erase(_pos2);
         _v2->invisListSize--;
     }
-    _blockers.clear();
+    _blocker = 0;
     _conns.clear();
     _added = false;
 }
 
 
-double EdgeInf::getDist(void)
-{
-    return _dist;
-}
-
-
 void EdgeInf::setDist(double dist)
 {
     //assert(dist != 0);
@@ -135,13 +129,14 @@ void EdgeInf::setDist(double dist)
         makeActive();
     }
     _dist = dist;
-    _blockers.clear();
+    _blocker = 0;
 }
 
 
 void EdgeInf::alertConns(void)
 {
-    for (FlagList::iterator i = _conns.begin(); i != _conns.end(); ++i)
+    FlagList::iterator finish = _conns.end();
+    for (FlagList::iterator i = _conns.begin(); i != finish; ++i)
     {
         *(*i) = true;
     }
@@ -176,29 +171,7 @@ void EdgeInf::addBlocker(int b)
         makeActive();
     }
     _dist = 0;
-    _blockers.clear();
-    _blockers.push_back(b);
-}
-
-
-bool EdgeInf::hasBlocker(int b)
-{
-    assert(_router->InvisibilityGrph);
-
-    ShapeList::iterator finish = _blockers.end();
-    for (ShapeList::iterator it = _blockers.begin(); it != finish; ++it)
-    {
-        if ((*it) == -1)
-        {
-            alertConns();
-            return true;
-        }
-        else if ((*it) == b)
-        {
-            return true;
-        }
-    }
-    return false;
+    _blocker = b;
 }
 
 
index 080309d5271e779ef9f1eefa4ea70da60d67574b..92451f2054d2916ef1f8bf6c3bfeedcd7595e38f 100644 (file)
@@ -45,13 +45,16 @@ class EdgeInf
     public:
         EdgeInf(VertInf *v1, VertInf *v2);
         ~EdgeInf();
-        double getDist(void);
+        inline double getDist(void)
+        {
+            return _dist;
+        }
         void setDist(double dist);
         void alertConns(void);
         void addConn(bool *flag);
         void addCycleBlocker(void);
         void addBlocker(int b);
-        bool hasBlocker(int b);
+
         pair<VertID, VertID> ids(void);
         pair<Point, Point> points(void);
         void db_print(void);
@@ -63,6 +66,7 @@ class EdgeInf
 
         EdgeInf *lstPrev;
         EdgeInf *lstNext;
+        int _blocker;
     private:
         Router *_router;
         bool _added;
@@ -71,7 +75,6 @@ class EdgeInf
         VertInf *_v2;
         EdgeInfList::iterator _pos1;
         EdgeInfList::iterator _pos2;
-        ShapeList _blockers;
         FlagList  _conns;
         double  _dist;
 
index 78bfa33db1bd5c33be07db3b8ffed01ec159f20e..c4dc8961f5fb714c9ff032ff20141a3e949a13b9 100644 (file)
@@ -28,6 +28,7 @@
 #include "libavoid/debug.h"
 #include "math.h"
 
+//#define ORTHOGONAL_ROUTING
 
 namespace Avoid {
 
@@ -41,6 +42,7 @@ Router::Router()
     , IncludeEndpoints(true)
     , UseLeesAlgorithm(false)
     , InvisibilityGrph(true)
+    , ConsolidateMoves(false)
     , PartialFeedback(false)
     // Instrumentation:
     , st_checked_edges(0)
@@ -63,6 +65,10 @@ void Router::addShape(ShapeRef *shape)
     //    blocks them.
     newBlockingShape(&poly, pid);
 
+#ifdef ORTHOGONAL_ROUTING
+    Region::addShape(shape);
+#endif
+
     // o  Calculate visibility for the new vertices.
     if (UseLeesAlgorithm)
     {
@@ -90,6 +96,10 @@ void Router::delShape(ShapeRef *shape)
 
     adjustContainsWithDel(pid);
     
+#ifdef ORTHOGONAL_ROUTING
+    Region::removeShape(shape);
+#endif
+
     delete shape;
     
     // o  Check all edges that were blocked by this shape.
@@ -106,22 +116,26 @@ void Router::delShape(ShapeRef *shape)
 }
 
 
-ShapeRef *Router::moveShape(ShapeRef *oldShape, Polygn *newPoly, const bool first_move)
+void Router::moveShape(ShapeRef *shape, Polygn *newPoly, const bool first_move)
 {
-    unsigned int pid = oldShape->id();
-    
+    unsigned int pid = shape->id();
+    bool notPartialTime = !(PartialFeedback && PartialTime);
+
     // o  Remove entries related to this shape's vertices
-    oldShape->removeFromGraph();
+    shape->removeFromGraph();
     
-    if (SelectiveReroute && (!(PartialFeedback && PartialTime) || first_move))
+    if (SelectiveReroute && (notPartialTime || first_move))
     {
-        markConnectors(oldShape);
+        markConnectors(shape);
     }
 
     adjustContainsWithDel(pid);
     
-    delete oldShape;
-    oldShape = NULL;
+#ifdef ORTHOGONAL_ROUTING
+    Region::removeShape(shape);
+#endif
+
+    shape->setNewPoly(*newPoly);
 
     adjustContainsWithAdd(*newPoly, pid);
     
@@ -135,12 +149,14 @@ ShapeRef *Router::moveShape(ShapeRef *oldShape, Polygn *newPoly, const bool firs
         // check all edges not in graph
         checkAllMissingEdges();
     }
-    
-    ShapeRef *newShape = new ShapeRef(this, pid, *newPoly);
+
+#ifdef ORTHOGONAL_ROUTING
+    Region::addShape(shape);
+#endif
 
     // o  Check all visibility edges to see if this one shape
     //    blocks them.
-    if (!(PartialFeedback && PartialTime))
+    if (notPartialTime)
     {
         newBlockingShape(newPoly, pid);
     }
@@ -148,15 +164,13 @@ ShapeRef *Router::moveShape(ShapeRef *oldShape, Polygn *newPoly, const bool firs
     // o  Calculate visibility for the new vertices.
     if (UseLeesAlgorithm)
     {
-        shapeVisSweep(newShape);
+        shapeVisSweep(shape);
     }
     else
     {
-        shapeVis(newShape);
+        shapeVis(shape);
     }
     callbackAllInvalidConnectors();
-
-    return newShape;
 }
 
 
@@ -289,7 +303,12 @@ void Router::checkAllBlockedEdges(int pid)
         EdgeInf *tmp = iter;
         iter = iter->lstNext;
 
-        if (tmp->hasBlocker(pid))
+        if (tmp->_blocker == -1)
+        {
+            tmp->alertConns();
+            tmp->checkVis();
+        }
+        else if (tmp->_blocker == pid)
         {
             tmp->checkVis();
         }
index bcb4ea67c496c5bc90dcd31cfc1050d76b2502e2..4d25b53d4a0da11bb852a5fabc3ff4a551505370 100644 (file)
@@ -29,6 +29,8 @@
 #include "libavoid/shape.h"
 #include "libavoid/graph.h"
 #include "libavoid/timer.h"
+#include <list>
+#include <utility>
 #ifdef LINEDEBUG       
     #include <SDL.h>
 #endif
@@ -39,6 +41,7 @@ namespace Avoid {
 class ConnRef;
 typedef std::list<ConnRef *> ConnRefList;
 typedef std::list<unsigned int> IntList;
+typedef std::pair<ShapeRef *, Polygn *> MoveInfo;
 
 
 static const unsigned int runningTo = 1;
@@ -67,6 +70,7 @@ class Router {
         bool IncludeEndpoints;
         bool UseLeesAlgorithm;
         bool InvisibilityGrph;
+        bool ConsolidateMoves;
         bool PartialFeedback;
 
         // Instrumentation:
@@ -78,7 +82,7 @@ class Router {
 
         void addShape(ShapeRef *shape);
         void delShape(ShapeRef *shape);
-        ShapeRef *moveShape(ShapeRef *oldShape, Polygn *newPoly,
+        void moveShape(ShapeRef *shape, Polygn *newPoly,
                 const bool first_move = false);
         
         void attachedConns(IntList &conns, const unsigned int shapeId,
index f2fd6d6b30138e3e47a7545841671f55f1d565da..84f0312ee1d56550bcb656215871839c87bbe95e 100644 (file)
@@ -100,6 +100,31 @@ ShapeRef::~ShapeRef()
 }
 
 
+void ShapeRef::setNewPoly(Polygn& poly)
+{
+    assert(_firstVert != NULL);
+    assert(_poly.pn == poly.pn);
+    
+    VertInf *curr = _firstVert;
+    for (int pt_i = 0; pt_i < _poly.pn; pt_i++)
+    {
+        assert(curr->visListSize == 0);
+        assert(curr->invisListSize == 0);
+
+        // Reset with the new polygon point.
+        curr->Reset(poly.ps[pt_i]);
+        curr->pathNext = NULL;
+        curr->pathDist = 0;
+        
+        curr = curr->shNext;
+    }
+    assert(curr == _firstVert);
+        
+    freePoly(_poly);
+    _poly = copyPoly(poly);
+}
+
+
 void ShapeRef::makeActive(void)
 {
     assert(!_active);
index 8989cf37532f11910ef0f6a66b9fb278c22f8248..cdcbe7839ddce3ea66aa105a83b949c8f683645c 100644 (file)
@@ -40,6 +40,7 @@ class ShapeRef
     public:
         ShapeRef(Router *router, unsigned int id, Polygn& poly);
         ~ShapeRef();
+        void setNewPoly(Polygn& poly);
         VertInf *firstVert(void);
         VertInf *lastVert(void);
         unsigned int id(void);