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-2008 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 */
25 //! @file shape.h
26 //! @brief Contains the interface for the ShapeRef class.
29 #ifndef AVOID_SHAPE_H
30 #define AVOID_SHAPE_H
32 #include "libavoid/geometry.h"
33 #include <list>
36 namespace Avoid {
38 class VertInf;
39 class Router;
40 class ShapeRef;
41 typedef std::list<ShapeRef *> ShapeRefList;
44 //! @brief The ShapeRef class represents a shape object.
45 //!
46 //! Shapes are obstacles that connectors must be routed around. They can be
47 //! placed into a Router scene and can be repositioned or resized (via
48 //! Router::moveShape()).
49 //!
50 //! Usually, it is expected that you would create a ShapeRef for each shape
51 //! in your diagram and keep that reference in your own shape class.
52 //!
53 class ShapeRef
54 {
55 public:
56 //! @brief Shape reference constructor.
57 //!
58 //! Creates a shape obect reference, but does not yet place it into the
59 //! Router scene.
60 //!
61 //! The poly argument will usually be the boundary of the shape in your
62 //! application with additional buffer of several pixels on each side.
63 //! Specifying such a buffer results in connectors leaving a small
64 //! amount of space around shapes, rather than touching them on the
65 //! corners or edges.
66 //!
67 //! If an ID is not specified, then one will be assigned to the shape.
68 //! If assigning an ID yourself, note that it should be a unique
69 //! positive integer. Also, IDs are given to all objects in a scene,
70 //! so the same ID cannot be given to a shape and a connector for
71 //! example.
72 //!
73 //! @param[in] router The router scene to place the shape into.
74 //! @param[in] poly A Polygon representing the boundary of the
75 //! shape.
76 //! @param[in] id A unique positive integer ID for the shape.
77 ShapeRef(Router *router, Polygon& poly, const unsigned int id = 0);
78 //! @brief Shape reference destructor.
79 //!
80 //! This will call Router::removeShape() for this shape, if this has
81 //! not already be called.
82 ~ShapeRef();
84 //! @brief Returns the ID of this shape.
85 //! @returns The ID of the shape.
86 unsigned int id(void) const;
87 //! @brief Returns a reference to the polygon boundary of this shape.
88 //! @returns A reference to the polygon boundary of the shape.
89 const Polygon& polygon(void) const;
90 //! @brief Returns a pointer to the router scene this shape is in.
91 //! @returns A pointer to the router scene for this shape.
92 Router *router(void) const;
94 void setNewPoly(const Polygon& poly);
95 VertInf *firstVert(void);
96 VertInf *lastVert(void);
97 void boundingBox(BBox& bbox);
99 void makeActive(void);
100 void makeInactive(void);
101 bool isActive(void) const;
103 void removeFromGraph(void);
104 void markForMove(void);
105 void clearMoveMark(void);
107 VertInf *getPointVertex(const Point& point);
109 private:
110 Router *_router;
111 unsigned int _id;
112 Polygon _poly;
113 bool _active;
114 bool _inMoveList;
115 ShapeRefList::iterator _pos;
116 VertInf *_firstVert;
117 VertInf *_lastVert;
118 };
121 }
124 #endif