Public Member Functions | List of all members
Avoid::ShapeConnectionPin Class Reference

The ShapeConnectionPin class represents a fixed point or "pin" on a shape that can be connected to. More...

#include <connectionpin.h>

Public Member Functions

 ShapeConnectionPin (ShapeRef *shape, const unsigned int classId, const double xPortionOffset, const double yPortionOffset, const double insideOffset=0.0, const ConnDirFlags visDirs=ConnDirNone)
 Constructs a ShapeConnectionPin at a specified position on a parent shape. More...
 
 ShapeConnectionPin (JunctionRef *junction, const unsigned int classId, const ConnDirFlags visDirs=ConnDirNone)
 Constructs a ShapeConnectionPin on a JunctionRef. More...
 
void setConnectionCost (const double cost)
 sets a cost used when selecting whether connectors should be be attached to this connection pin. More...
 
const Point position (const Polygon &newPoly=Polygon()) const
 Returns the position of this connection pin. More...
 
ConnDirFlags directions (void) const
 Returns the directions in which this connection pin has visibility. More...
 
void setExclusive (const bool exclusive)
 Sets whether the pin is exclusive, i.e., only one connector can attach to it. More...
 

Detailed Description

The ShapeConnectionPin class represents a fixed point or "pin" on a shape that can be connected to.

Pins have a visibility direction and numeric class ID (e.g., to specify types of pins such as "input" or "output"). They may optionally have a priority which means when routing connectors to a particular class ID then one pin will be selected over another.

Pins have a position that is specified relative to its parent shape. Then the shape is moved or resized, The pin will be automatically moved accordingly.

Pins with a specified direction are exclusive by default, those with visibility in all directions are non-exclusive by default. This behaviour can be changed by calling the ShapeConnectionPin::setExclusive() method.

Constructor & Destructor Documentation

Avoid::ShapeConnectionPin::ShapeConnectionPin ( ShapeRef shape,
const unsigned int  classId,
const double  xPortionOffset,
const double  yPortionOffset,
const double  insideOffset = 0.0,
const ConnDirFlags  visDirs = ConnDirNone 
)

Constructs a ShapeConnectionPin at a specified position on a parent shape.

Ownership of this ShapeConnectionPin is passed to the parent shape.

The connection point position should be specified as proportion of the shape's total width and height using a floating point value between 0 and 1.

There are some predefined values for specifying the xPortionOffset and yPortionOffset arguments:

  • ATTACH_POS_TOP = 0
  • ATTACH_POS_LEFT = 0
  • ATTACH_POS_CENTRE = 0.5
  • ATTACH_POS_BOTTOM = 1
  • ATTACH_POS_RIGHT = 1

Importantly, shape connection pins will be moved automatically when the parent shapes are moved or resized. Attachment for connectors will be chosen based on the classId specified to ConnEnd and these connectors will be subsequently rerouted.

If no value is given for the visDirs argument, then visibility is automatically determined based on the position of the connection point. Points on the shape boundary will have visibility from the shape out of that edge while points in the interior will have visibility in all directions.

The insideOffset argument can be used to set a distance to automatically offset the point within the shape. This is useful for orthogonal routing, where you usually want the connection point to lie inside the shape rather than exactly on its boundary. While you could specify an exact position with xPortionOffset and yPortionOffset, it is usually much easier and more readable to not have to specify the visibility directions manually and to write something like

  ShapeConnectionPin(shapeRef, pinClassId, ATTACH_POS_RIGHT, ATTACH_POS_CENTRE, 5);

rather than

  ShapeConnectionPin(shapeRef, pinClassId, 1 - 5/shapeWidth, ATTACH_POS_CENTRE, 0, ConnDirRight);
Parameters
[in]shapeA pointer to the containing parent shape's ShapeRef.
[in]classIdAn integer used to mark the class or group of this connection point, used for specifying attachment to ConnEnd.
[in]xPortionOffsetThe X position within the shape, specified as a proportion of the width between 0 (left) and 1 (right).
[in]yPortionOffsetThe Y position within the shape, specified as a proportion of the height between 0 (top) and 1 (bottom).
[in]insideOffsetA distance to offset the connection point inside the shape if it lies on the boundary.
[in]visDirsOne or more Avoid::ConnDirFlag options specifying the directions that this connection point has visibility.
Avoid::ShapeConnectionPin::ShapeConnectionPin ( JunctionRef junction,
const unsigned int  classId,
const ConnDirFlags  visDirs = ConnDirNone 
)

Constructs a ShapeConnectionPin on a JunctionRef.

Ownership of this ShapeConnectionPin is passed to the parent junction.

This will usually be automatically called by the JunctionRef constructor to give the Junction four ShapeConnectionPins, facing up, down, left and right.

Parameters
[in]junctionA pointer to the containing parent junction's JunctionRef.
[in]classIdAn integer used to mark the class or group of this connection point, used for specifying attachment to ConnEnd.
[in]visDirsOne or more Avoid::ConnDirFlag options specifying the directions that this connection point has visibility.

Member Function Documentation

ConnDirFlags Avoid::ShapeConnectionPin::directions ( void  ) const

Returns the directions in which this connection pin has visibility.

Returns
The visibility directions for this connection pin.
const Point Avoid::ShapeConnectionPin::position ( const Polygon newPoly = Polygon()) const

Returns the position of this connection pin.

Returns
The position of this connection pin.
void Avoid::ShapeConnectionPin::setConnectionCost ( const double  cost)

sets a cost used when selecting whether connectors should be be attached to this connection pin.

Parameters
[in]costA routing cost applied to a route when selecting this connection pin.
void Avoid::ShapeConnectionPin::setExclusive ( const bool  exclusive)

Sets whether the pin is exclusive, i.e., only one connector can attach to it.

Parameters
[in]exclusiveA bool representing whether this pin should be exclusive.

The documentation for this class was generated from the following files: