NShape Concepts
Shape Connections

<< Click to Display Table of Contents >>

Navigation:  Concepts >

NShape Concepts
Shape Connections

Previous pageReturn to chapter overviewNext page

Connection Types

Shapes can be connected to each other in two ways.

A point-to-point connection is a connection where a glue point of one shape is connected to a connection point of another shape. In most cases the glue point is a control point of a line and the connection point is a control point of a planar shape, but that is not absolutely required. The essential aspect about point-to-point connections is that it connects to a specific point of a shape, which is necessary whenever the shapes presentation includes locations with a special meaning.
If for example the shape represents a flowchart condition symbol, two of the corners might have the meaning yes and no. In this case, the connection goes specifically to one of them and therefore a connected line must be fixed at the respective corner.
A point-to-shape connection however connects a glue point to a shape as a whole. For this type of connection it does not matter to which specific point of the shape the line is tied to. The endpoint of the line may move if the other end of the line is moved.
An example is an UML class symbol. An aggregation arrow that starts from that symbol does not have to be fixed at a certain point but might and even should find its endpoint where it looks best.

NShape supports both kinds of connections. It is possible to connect a glue point either to a specific connection point or to the shape as a whole. As a consequence the glue point will either stay exactly at the position of the associated connection point or move around the shape as the connected line moves.

Glue and Connection Points

As might already have become clear, NShape attaches the behavior of connected shapes not to shapes but to the connected control points. A connectable control point can either be an active glue point or a passive connection point. A connection is always between a glue point and a connection point (point-to-point) or between a glue point and a shape (point-to-shape).

The typical example of a glue point are the end points of most lines. A glue point can be attached to either one connection point or one shape. In order to perform this, the user drags the glue point over the connection point or shape and drops it there. After that, if the connection point or the shape move, the glue point moves along modifying the guise of its shape. An actively connected shape cannot be moved; it is glued to its connection partner. When storing a connection in the repository, it is always stored at the active side, i.e. where the glue point is.

 

While a point-to-shape connection (left) refers to the whole shape, the point-to-point connection (right) is specificially targeted towards a connection point of the shape.

While a point-to-shape connection (left) refers to the whole shape, the point-to-point connection (right) is specificially targeted towards a connection point of the shape.

The connection point behaves the opposite way in many aspects. First, a connection point can accept any number of connections, not only one. The number can be constrained by settings in the shape or its model object, but generally spoken it is unlimited. Second, a shape with connected connection points can be moved and will move connected shapes (lines) along.

If the connection is between a glue point and a shape, it behaves very much as if it was between the glue point and a connection point in the center of the shape. Lines will however not draw up to that central point but terminate at the border of the shape.

Glue points and connection points are identified by their control point id. You can get the control point id by...

opening the shape's template editor in NShape designer and switch to the connection points tab.
calling the GetControlPointIds method of the shape passing ControlPointCapabilities.Connect as filter:

foreach (ControlPointId id in shape.GetControlPointIds(ControlPointCapabilities.Connect)) {
 ...
}

accessing the constants defined in the nested ControlPointIds class of the shape's type (only NShape 2.1.0 or newer)

lineShape.Connect(ControlPointId.FirstVertex, rectangleShape, RectangleBase.ControlPointIds.TopCenterControlPoint)

 

 

The "Connection Points" tab of the template editor shows all connection points including their ControlPointId.

The "Connection Points" tab of the template editor shows all connection points including their ControlPointId.