connend.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-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 */
24 
27 
28 
29 #ifndef AVOID_CONNEND_H
30 #define AVOID_CONNEND_H
31 
32 
33 #include <cstdio>
34 #include <list>
35 #include <vector>
36 
37 #include "libavoid/geometry.h"
38 
39 
40 namespace Avoid {
41 
42 class Obstacle;
43 class ShapeRef;
44 class JunctionRef;
45 class Router;
46 class ConnRef;
47 class ShapeConnectionPin;
48 typedef std::list<ConnRef *> ConnRefList;
49 class VertInf;
50 
51 
61  ConnDirNone = 0,
64  ConnDirUp = 1,
78 };
81 typedef unsigned int ConnDirFlags;
82 
83 
84 // Used to specify position on shape when constructing a shape-attached ConnEnd.
85 //
86 static const double ATTACH_POS_TOP = 0;
87 static const double ATTACH_POS_CENTRE = 0.5;
88 static const double ATTACH_POS_BOTTOM = 1;
89 static const double ATTACH_POS_LEFT = ATTACH_POS_TOP;
90 static const double ATTACH_POS_RIGHT = ATTACH_POS_BOTTOM;
91 
92 
99 class ConnEnd
100 {
101  public:
106  ConnEnd(const Point& point);
107 
121  ConnEnd(ShapeRef *shapeRef, const unsigned int connectionPinClassID);
122 
133  ConnEnd(JunctionRef *junctionRef);
134 
146  ConnEnd(const Point& point, const ConnDirFlags visDirs);
147 
152  const Point position(void) const;
153 
159  ConnDirFlags directions(void) const;
160 
161  ~ConnEnd();
162  private:
163  friend class Obstacle;
164  friend class JunctionRef;
165  friend class ShapeRef;
166  friend class ConnRef;
167  friend class Router;
168  friend class ShapeConnectionPin;
169 
170  void connect(ConnRef *conn);
171  void disconnect(const bool shapeDeleted = false);
172  void usePin(ShapeConnectionPin *pin);
173  void usePinVertex(VertInf *pinVert);
174  void freeActivePin(void);
175  ShapeRef *containingShape(void) const;
176  unsigned int type(void) const;
177  bool isPinConnection(void) const;
178  std::vector<Point> possiblePinPoints(void) const;
179  void assignPinVisibilityTo(VertInf *dummyConnectionVert,
180  VertInf *targetVert);
181  void outputCode(FILE *fp, const char *srcDst);
182 
183  Point m_point;
184  ConnDirFlags m_directions;
185  unsigned int m_connection_pin_class_id;
186 
187  // For referencing ConnEnds
188  Obstacle *m_anchor_obj; // The shape/junction this is attached to.
189  ConnRef *m_conn_ref; // The parent connector.
190 
191  // The pin to which the ConnEnd is attached.
192  ShapeConnectionPin *m_active_pin;
193 };
194 
195 
196 }
197 
198 
199 #endif
200 
201