1 /*
2 * vim: ts=4 sw=4 et tw=0 wm=0
3 *
4 * libavoid - Fast, Incremental, Object-avoiding Line Router
5 *
6 * Copyright (C) 2004-2009 Monash University
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 * See the file LICENSE.LGPL distributed with the library.
13 *
14 * Licensees holding a valid commercial license may use this file in
15 * accordance with the commercial license agreement provided with the
16 * library.
17 *
18 * This library is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21 *
22 * Author(s): Michael Wybrow <mjwybrow@users.sourceforge.net>
23 */
26 #ifndef AVOID_VERTICES_H
27 #define AVOID_VERTICES_H
29 #include <list>
30 #include <set>
31 #include <map>
32 #include <iostream>
33 #include <cstdio>
35 #include "libavoid/geomtypes.h"
37 namespace Avoid {
39 class EdgeInf;
40 class Router;
42 typedef std::list<EdgeInf *> EdgeInfList;
44 typedef unsigned int ConnDirFlags;
47 class VertID
48 {
49 public:
50 unsigned int objID;
51 bool isShape;
52 unsigned short vn;
54 static const unsigned short src;
55 static const unsigned short tar;
57 VertID();
58 VertID(unsigned int id, bool s, int n);
59 VertID(const VertID& other);
60 VertID& operator= (const VertID& rhs);
61 bool operator==(const VertID& rhs) const;
62 bool operator!=(const VertID& rhs) const;
63 bool operator<(const VertID& rhs) const;
64 VertID operator+(const int& rhs) const;
65 VertID operator-(const int& rhs) const;
66 VertID& operator++(int);
67 void print(FILE *file = stdout) const;
68 void db_print(void) const;
69 friend std::ostream& operator<<(std::ostream& os, const VertID& vID);
70 };
73 // An ID given to all dummy vertices inserted to allow creation of the
74 // orthogonal visibility graph since the vertices in the orthogonal graph
75 // mostly do not correspond to shape corners or connector endpoints.
76 //
77 static const VertID dummyOrthogID(0, true, 0);
80 class VertInf
81 {
82 public:
83 VertInf(Router *router, const VertID& vid, const Point& vpoint,
84 const bool addToRouter = true);
85 ~VertInf();
86 void Reset(const VertID& vid, const Point& vpoint);
87 void Reset(const Point& vpoint);
88 void removeFromGraph(const bool isConnVert = true);
89 bool orphaned(void);
91 Router *_router;
92 VertID id;
93 Point point;
94 VertInf *lstPrev;
95 VertInf *lstNext;
96 VertInf *shPrev;
97 VertInf *shNext;
98 EdgeInfList visList;
99 unsigned int visListSize;
100 EdgeInfList orthogVisList;
101 unsigned int orthogVisListSize;
102 EdgeInfList invisList;
103 unsigned int invisListSize;
104 VertInf *pathNext;
105 ConnDirFlags visDirections;
106 };
109 bool directVis(VertInf *src, VertInf *dst);
112 // A linked list of all the vertices in the router instance. All the
113 // connector endpoints are listed first, then all the shape vertices.
114 // Dunnny vertices inserted for orthogonal routing are classed as shape
115 // vertices but have VertID(0, 0).
116 //
117 class VertInfList
118 {
119 public:
120 VertInfList();
121 void addVertex(VertInf *vert);
122 VertInf *removeVertex(VertInf *vert);
123 VertInf *getVertexByID(const VertID& id);
124 VertInf *getVertexByPos(const Point& p);
125 VertInf *shapesBegin(void);
126 VertInf *connsBegin(void);
127 VertInf *end(void);
128 unsigned int connsSize(void) const;
129 unsigned int shapesSize(void) const;
130 void stats(FILE *fp = stderr)
131 {
132 fprintf(fp, "Conns %d, shapes %d\n", _connVertices,
133 _shapeVertices);
134 }
135 private:
136 VertInf *_firstShapeVert;
137 VertInf *_firstConnVert;
138 VertInf *_lastShapeVert;
139 VertInf *_lastConnVert;
140 unsigned int _shapeVertices;
141 unsigned int _connVertices;
142 };
145 typedef std::set<unsigned int> ShapeSet;
146 typedef std::map<VertID, ShapeSet> ContainsMap;
149 }
152 #endif