obstacle.h
Go to the documentation of this file.
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-2010 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 */
24 
28 
29 
30 #ifndef AVOID_OBSTACLE_H
31 #define AVOID_OBSTACLE_H
32 
33 #include <list>
34 #include <set>
35 
36 #include <cstdio>
37 
38 #include "libavoid/geometry.h"
39 #include "libavoid/connectionpin.h"
40 
41 
42 namespace Avoid {
43 
44 class VertInf;
45 class Router;
46 class Obstacle;
47 class ConnEnd;
48 typedef std::list<Obstacle *> ObstacleList;
49 
50 
51 // @brief The Obstacle class represents an obstacle that must be
52 // routed around..
53 //
54 class Obstacle
55 {
56  public:
80  Obstacle(Router *router, Polygon poly, const unsigned int id = 0);
85  virtual ~Obstacle();
86 
89  unsigned int id(void) const;
92  const Polygon& polygon(void) const;
95  Router *router(void) const;
98  virtual Point position(void) const = 0;
99 
100  void setNewPoly(const Polygon& poly);
101  VertInf *firstVert(void);
102  VertInf *lastVert(void);
103  void boundingBox(BBox& bbox);
104 
105  private:
106  friend class Router;
107  friend class ConnEnd;
108  friend class ShapeConnectionPin;
109 
110  // Defined in visibility.cpp:
111  void computeVisibilityNaive(void);
112  void computeVisibilitySweep(void);
113 
114  virtual void outputCode(FILE *fp) const = 0;
115  void makeActive(void);
116  void makeInactive(void);
117  bool isActive(void) const;
118  void updatePinPolyLineVisibility(void);
119 
120  void removeFromGraph(void);
121  void markForMove(void);
122  void clearMoveMark(void);
123  Point shapeCentre(void);
124 
125  VertInf *getPointVertex(const Point& point);
126 
127  void addFollowingConnEnd(ConnEnd *connEnd);
128  void removeFollowingConnEnd(ConnEnd *connEnd);
129  unsigned int addConnectionPin(ShapeConnectionPin *pin);
130  void removeConnectionPin(ShapeConnectionPin *pin);
131  void assignPinVisibilityTo(const unsigned int pinClassId,
132  VertInf *dummyConnectionVert);
133  std::vector<Point> possiblePinPoints(unsigned int pinClassId) const;
134 
135  protected:
136  Router *m_router;
137  unsigned int m_id;
138  Polygon m_polygon;
139  bool m_active;
140  bool m_in_move_list;
141  ObstacleList::iterator m_router_obstacles_pos;
142  VertInf *m_first_vert;
143  VertInf *m_last_vert;
144  std::set<ConnEnd *> m_following_conns;
145  ShapeConnectionPinSet m_connection_pins;
146 };
147 
148 
149 }
150 
151 
152 #endif
153 
154