Adaptagrams
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-2014 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
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 #include <utility>
36 
37 #include "libavoid/dllexport.h"
38 #include "libavoid/connend.h"
39 #include "libavoid/geomtypes.h"
40 
41 namespace Avoid {
42 
43 
44 static const unsigned int CONNECTIONPIN_UNSET = INT_MAX;
45 static const unsigned int CONNECTIONPIN_CENTRE = INT_MAX - 1;
46 
47 class Router;
48 class ShapeRef;
49 class JunctionRef;
50 class ConnEnd;
51 class VertInf;
52 
53 typedef std::pair<unsigned int, unsigned int> ConnectionPinIds;
54 
55 // Used to specify position on shape when constructing a shape-attached ConnEnd.
56 //
57 static const double ATTACH_POS_TOP = 0;
58 static const double ATTACH_POS_CENTRE = 0.5;
59 static const double ATTACH_POS_BOTTOM = 1;
60 static const double ATTACH_POS_LEFT = ATTACH_POS_TOP;
61 static const double ATTACH_POS_RIGHT = ATTACH_POS_BOTTOM;
62 
63 static const double ATTACH_POS_MIN_OFFSET = 0;
64 static const double ATTACH_POS_MAX_OFFSET = -1;
65 
66 
96 class AVOID_EXPORT ShapeConnectionPin
97 {
98  public:
169  ShapeConnectionPin(ShapeRef *shape, const unsigned int classId,
170  const double xOffset, const double yOffset,
171  const bool proportional, const double insideOffset,
172  const ConnDirFlags visDirs);
173 
174  // Old constructor. Provided for compatibility with old debug files.
175  ShapeConnectionPin(ShapeRef *shape, const unsigned int classId,
176  const double xOffset, const double yOffset,
177  const double insideOffset, const ConnDirFlags visDirs);
178 
197  ShapeConnectionPin(JunctionRef *junction, const unsigned int classId,
198  const ConnDirFlags visDirs = ConnDirNone);
199 
200 // To prevent C++ objects from being destroyed in garbage collected languages
201 // when the libraries are called from SWIG, we hide the declarations of the
202 // destructors and prevent generation of default destructors.
203 #ifndef SWIG
205 #endif
206 
213  void setConnectionCost(const double cost);
214 
219  const Point position(const Polygon& newPoly = Polygon()) const;
220 
226  ConnDirFlags directions(void) const;
227 
236  void setExclusive(const bool exclusive);
237 
243  bool isExclusive(void) const;
244 
245  ConnectionPinIds ids(void) const;
246 
247  bool operator==(const ShapeConnectionPin& rhs) const;
248  bool operator<(const ShapeConnectionPin& rhs) const;
249  private:
250  friend class ShapeRef;
251  friend class JunctionRef;
252  friend class Obstacle;
253  friend class ConnEnd;
254  friend class Router;
255 
256  void commonInitForShapeConnection(void);
257  void updatePosition(const Point& newPosition);
258  void updatePosition(const Polygon& newPoly);
259  void updatePositionAndVisibility(void);
260  void updateVisibility(void);
261  void outputCode(FILE *fp) const;
262  unsigned int containingObjectId(void) const;
263 
264  // Unique properties
265  Router *m_router;
266  ShapeRef *m_shape;
267  JunctionRef *m_junction;
268  unsigned int m_class_id;
269  double m_x_offset;
270  double m_y_offset;
271  double m_inside_offset;
272  ConnDirFlags m_visibility_directions;
273 
274  // Some extra properties.
275  bool m_exclusive;
276  double m_connection_cost;
277  // The set of connends using this pin.
278  std::set<ConnEnd *> m_connend_users;
279  VertInf *m_vertex;
280  bool m_using_proportional_offsets;
281 };
282 
283 class CmpConnPinPtr
284 {
285  public:
286  CmpConnPinPtr()
287  {
288  }
289  bool operator()(const ShapeConnectionPin *lhs,
290  const ShapeConnectionPin *rhs) const
291  {
292  return (*lhs) < (*rhs);
293  }
294 };
295 
296 typedef std::set<ShapeConnectionPin *, CmpConnPinPtr> ShapeConnectionPinSet;
297 
298 }
299 
300 
301 #endif
302 
303 
The ConnEnd class represents different possible endpoints for connectors.
Definition: connend.h:110
unsigned int ConnDirFlags
One or more Avoid::ConnDirFlag options.
Definition: connend.h:83
A dynamic Polygon, to which points can be easily added and removed.
Definition: geomtypes.h:207
The ShapeConnectionPin class represents a fixed point or "pin" on a shape that can be connected to...
Definition: connectionpin.h:96
Contains the interface for various geometry types and classes.
Contains the interface for the ConnEnd class.
The Point class defines a point in the plane.
Definition: geomtypes.h:52
libavoid: Object-avoiding orthogonal and polyline connector routing library.
Definition: actioninfo.cpp:33
The Router class represents a libavoid router instance.
Definition: router.h:386
The ShapeRef class represents a shape object.
Definition: shape.h:81
The JunctionRef class represents a fixed or free-floating point that connectors can be attached to...
Definition: junction.h:57