connectionpin.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) 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 
27 
28 
29 #ifndef AVOID_CONNECTIONPIN_H
30 #define AVOID_CONNECTIONPIN_H
31 
32 #include <cstdio>
33 #include <set>
34 #include <climits>
35 
36 #include "libavoid/connend.h"
37 #include "libavoid/geomtypes.h"
38 
39 namespace Avoid {
40 
41 
42 static const unsigned int CONNECTIONPIN_UNSET = INT_MAX;
43 static const unsigned int CONNECTIONPIN_CENTRE = INT_MAX - 1;
44 
45 class Router;
46 class ShapeRef;
47 class JunctionRef;
48 class ConnEnd;
49 class VertInf;
50 
69 {
70  public:
129  ShapeConnectionPin(ShapeRef *shape, const unsigned int classId,
130  const double xPortionOffset, const double yPortionOffset,
131  const double insideOffset = 0.0,
132  const ConnDirFlags visDirs = ConnDirNone);
151  ShapeConnectionPin(JunctionRef *junction, const unsigned int classId,
152  const ConnDirFlags visDirs = ConnDirNone);
153 
155 
162  void setConnectionCost(const double cost);
163 
168  const Point position(const Polygon& newPoly = Polygon()) const;
169 
175  ConnDirFlags directions(void) const;
176 
183  void setExclusive(const bool exclusive);
184 
185  bool operator==(const ShapeConnectionPin& rhs) const;
186  bool operator<(const ShapeConnectionPin& rhs) const;
187  private:
188  friend class ShapeRef;
189  friend class JunctionRef;
190  friend class Obstacle;
191  friend class ConnEnd;
192  friend class Router;
193 
194  void updatePosition(const Point& newPosition);
195  void updatePosition(const Polygon& newPoly);
196  void updatePositionAndVisibility(void);
197  void updateVisibility(void);
198  void outputCode(FILE *fp) const;
199  unsigned int containingObjectId(void) const;
200 
201  // Unique properties
202  Router *m_router;
203  ShapeRef *m_shape;
204  JunctionRef *m_junction;
205  unsigned int m_class_id;
206  double m_x_portion_offset;
207  double m_y_portion_offset;
208  double m_inside_offset;
209  ConnDirFlags m_visibility_directions;
210 
211  // Some extra properties.
212  bool m_exclusive;
213  double m_connection_cost;
214  // The set of connends using this pin.
215  std::set<ConnEnd *> m_connend_users;
216  VertInf *m_vertex;
217 };
218 
219 class CmpConnPinPtr
220 {
221  public:
222  CmpConnPinPtr()
223  {
224  }
225  bool operator()(const ShapeConnectionPin *lhs,
226  const ShapeConnectionPin *rhs) const
227  {
228  return (*lhs) < (*rhs);
229  }
230 };
231 
232 typedef std::set<ShapeConnectionPin *, CmpConnPinPtr> ShapeConnectionPinSet;
233 
234 }
235 
236 
237 #endif
238 
239