summaryrefslogtreecommitdiffstats
path: root/src/libavoid/shape.h
diff options
context:
space:
mode:
authorSylvain Chiron <chironsylvain@orange.fr>2017-07-01 11:36:41 +0000
committerSylvain Chiron <chironsylvain@orange.fr>2017-07-01 11:36:41 +0000
commitfd733201b82f39655488a286c89142f321ef9dc9 (patch)
treea12c70f213414f69467f666619b1552103f6370e /src/libavoid/shape.h
parentHackfest icon work: restore selected menu icons and make theming easier (diff)
downloadinkscape-fd733201b82f39655488a286c89142f321ef9dc9.tar.gz
inkscape-fd733201b82f39655488a286c89142f321ef9dc9.zip
Updated libs from the Adaptagrams project: libavoid, libcola and libvspc; changed the code to match the new API
Signed-off-by: Sylvain Chiron <chironsylvain@orange.fr>
Diffstat (limited to 'src/libavoid/shape.h')
-rw-r--r--src/libavoid/shape.h129
1 files changed, 84 insertions, 45 deletions
diff --git a/src/libavoid/shape.h b/src/libavoid/shape.h
index df4c98df1..f6d70763a 100644
--- a/src/libavoid/shape.h
+++ b/src/libavoid/shape.h
@@ -3,7 +3,7 @@
*
* libavoid - Fast, Incremental, Object-avoiding Line Router
*
- * Copyright (C) 2004-2008 Monash University
+ * Copyright (C) 2004-2011 Monash University
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -19,7 +19,7 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
- * Author(s): Michael Wybrow <mjwybrow@users.sourceforge.net>
+ * Author(s): Michael Wybrow
*/
//! @file shape.h
@@ -29,17 +29,45 @@
#ifndef AVOID_SHAPE_H
#define AVOID_SHAPE_H
-#include "libavoid/geometry.h"
#include <list>
+#include <set>
+
+#include <cstdio>
+#include "libavoid/dllexport.h"
+#include "libavoid/geometry.h"
+#include "libavoid/obstacle.h"
+
+namespace topology {
+ class LayoutObstacle;
+}
namespace Avoid {
class VertInf;
class Router;
class ShapeRef;
+class ConnEnd;
+class ShapeConnectionPin;
+class ConnRef;
typedef std::list<ShapeRef *> ShapeRefList;
+//! @brief Describes the type of transformation that has been applied to a
+//! shape having its transformConnectionPinPositions() method called.
+enum ShapeTransformationType
+{
+ //! @brief The shape has been rotated clockwise by 90 degrees.
+ TransformationType_CW90 = 0,
+ //! @brief The shape has been rotated clockwise by 180 degrees.
+ TransformationType_CW180 = 1,
+ //! @brief The shape has been rotated clockwise by 270 degrees.
+ TransformationType_CW270 = 2,
+ //! @brief The shape has been flipped horizontally in the X-dimension.
+ TransformationType_FlipX = 3,
+ //! @brief The shape has been flipped vertically in the Y-dimension.
+ TransformationType_FlipY = 4
+};
+
//! @brief The ShapeRef class represents a shape object.
//!
@@ -50,13 +78,22 @@ typedef std::list<ShapeRef *> ShapeRefList;
//! Usually, it is expected that you would create a ShapeRef for each shape
//! in your diagram and keep that reference in your own shape class.
//!
-class ShapeRef
+class AVOID_EXPORT ShapeRef : public Obstacle
{
public:
//! @brief Shape reference constructor.
//!
- //! Creates a shape obect reference, but does not yet place it into the
- //! Router scene.
+ //! Creates a shape object reference, and adds it to the router
+ //! scene. This shape will be considered to be an obstacle.
+ //! This will cause connectors intersecting the newly added shape
+ //! to be marked as needing to be rerouted.
+ //!
+ //! If the router is using transactions, then changes will occur
+ //! the next time Router::processTransaction() is called. See
+ //! Router::setTransactionUse() for more information.
+ //!
+ //! The shape can be moved with Router::moveShape() and removed
+ //! from the scene and freed with Router::deleteShape().
//!
//! The poly argument will usually be the boundary of the shape in your
//! application with additional buffer of several pixels on each side.
@@ -64,57 +101,59 @@ class ShapeRef
//! amount of space around shapes, rather than touching them on the
//! corners or edges.
//!
- //! If an ID is not specified, then one will be assigned to the shape.
- //! If assigning an ID yourself, note that it should be a unique
- //! positive integer. Also, IDs are given to all objects in a scene,
- //! so the same ID cannot be given to a shape and a connector for
- //! example.
+ //! @note Regarding IDs:
+ //! You can let libavoid manually handle IDs by not specifying
+ //! them. Alternatively, you can specify all IDs yourself, but
+ //! you must be careful to makes sure that each object in the
+ //! scene (shape, connector, cluster, etc) is given a unique,
+ //! positive ID. This uniqueness is checked if assertions are
+ //! enabled, but if not and there are clashes then strange
+ //! things can happen.
//!
//! @param[in] router The router scene to place the shape into.
//! @param[in] poly A Polygon representing the boundary of the
//! shape.
- //! @param[in] id A unique positive integer ID for the shape.
+ //! @param[in] id Optionally, a positive integer ID unique
+ //! among all objects.
+ //!
ShapeRef(Router *router, Polygon& poly, const unsigned int id = 0);
+
+// To prevent C++ objects from being destroyed in garbage collected languages
+// when the libraries are called from SWIG, we hide the declarations of the
+// destructors and prevent generation of default destructors.
+#ifndef SWIG
//! @brief Shape reference destructor.
//!
- //! This will call Router::removeShape() for this shape, if this has
- //! not already be called.
- ~ShapeRef();
-
- //! @brief Returns the ID of this shape.
- //! @returns The ID of the shape.
- unsigned int id(void) const;
+ //! Do not call this yourself, instead call Router::deleteShape().
+ //! Ownership of this object belongs to the router scene.
+ virtual ~ShapeRef();
+#endif
+
//! @brief Returns a reference to the polygon boundary of this shape.
//! @returns A reference to the polygon boundary of the shape.
const Polygon& polygon(void) const;
- //! @brief Returns a pointer to the router scene this shape is in.
- //! @returns A pointer to the router scene for this shape.
- Router *router(void) const;
- void setNewPoly(const Polygon& poly);
- VertInf *firstVert(void);
- VertInf *lastVert(void);
- void boundingBox(BBox& bbox);
-
- void makeActive(void);
- void makeInactive(void);
- bool isActive(void) const;
-
- void removeFromGraph(void);
- void markForMove(void);
- void clearMoveMark(void);
-
- VertInf *getPointVertex(const Point& point);
-
+ //! @brief Adjusts all of the shape's connection pin positions and
+ //! visibility directions for a given transformation type.
+ //!
+ //! @param[in] transform A ShapeTransformationType specifying the
+ //! type of transform to be applied to all
+ //! connection pins for the shape.
+ //!
+ void transformConnectionPinPositions(ShapeTransformationType transform);
+
+ Point position(void) const;
private:
- Router *_router;
- unsigned int _id;
- Polygon _poly;
- bool _active;
- bool _inMoveList;
- ShapeRefList::iterator _pos;
- VertInf *_firstVert;
- VertInf *_lastVert;
+ friend class Router;
+ friend class ConnEnd;
+ friend class ShapeConnectionPin;
+ friend class topology::LayoutObstacle;
+
+ void outputCode(FILE *fp) const;
+ void moveAttachedConns(const Polygon& newPoly);
+ void assignPinVisibilityTo(const unsigned int pinClassId,
+ VertInf *dummyConnectionVert);
+ void setCentrePos(const Point& newCentre);
};