In This Topic
Shapes are aggregate models, which are used to represent objects from the real world, concepts or abstractions. Shapes can be connected with each other and form complex relationships. Shapes are the primary building blocks of diagrams.
In the DOM all types of shapes derive from the base NShape class. Currently there are three distinct NShape class derivates:
- Primitive Shapes - these are shapes, which aggregate a single primitive model. See Primitive Shapes for more information.
- Composite Shapes - these are shapes, which aggregate one or more primitive models. See Composite Shapes for more information.
- Groups - these are shapes, which aggregate other shapes. See Groups for more information.
All shapes share the following set of common features:
Shape Type
The shape type is controlled from the ShapeType property (gets/sets a value from the ShapeType enumeration). There are only two types of shapes:
-
1D Shapes - these are shapes, which are treated as lines and are usually used to connect 2D shapes. 1D shapes have start and end plugs, which can be connected to the inward ports of other shapes. The start and end plugs are anchored to the shape start and end points. In the context of graphs, 1D Shapes are treated as graph edges (if the
GraphPart property is set to true). In the context of routing, 1D Shapes are not treated as obstacles. Only the bridgeable paths of bridgeable 1D shapes can display bridges.
-
2D Shapes - these are shapes, which are treated as boxes. 2D shapes do not have plugs. In the context of graphs, 2D Shapes are treated as graph vertices (if the
GraphPart property is set to true). In the context of routing, 2D Shapes are treated as obstacles (the
RouteObstacleType property is taken into account). Bridgeable paths inside 2D shapes do not display bridges.
Besides the different way in which the diagram treats 1D and 2D shapes, the value of the ShapeType property influences the default values of several shape properties.
Plugs
Plugs are only available for 1D shapes. In fact the shape will by design automatically create and destroy the shape plugs when you change the shape type. Each shape has two plugs - one start and one end plug.
The star plug is represented by an instance of the NStartPlug class and is accessible from the StartPlug property. The start plug position is anchored to the start point of the shape. When you move the start plug it actually moves the start point of the shape.
The end plug is represented by an instance of the NEndPlug class and is accessible from the EndPlug property. The end plug position is anchored to the end point of the shape. When you move the end plug it actually moves the end point of the shape.
Each plug can be connected to a single inward port of another shape. There are two ways of connecting a plug to a port:
-
Explicit connection - this type of connection is performed by the plug Connect method. In explicit connections you specify the plug and the port, which must be connected - that is why this connection is sometimes called
point to point connection. For example:
C# |
Copy Code
|
// explicitly connect the start plug of a 1D shape to the first port of another shape
shape1D.StartPlug.Connect(shape.Ports.GetChildAt(0) as NPort);
|
Visual Basic |
Copy Code
|
' explicitly connect the start plug of a 1D shape to the first port of another shape
shape1D.StartPlug.Connect(shape.Ports.GetChildAt(0) As NPort)
|
-
Implicit connection - this type of connection is performed by the the
ConnectToShape method of the
NPlug class. In implicit connections the plug gets connected to the default inward port of the specified shape - that is why this connection is sometimes called
shape to shape connection. For example:
C# |
Copy Code
|
// implicitly connect the start plug of a 1D shape to the default inward port of another shape
shape1D.StartPlug.ConnectToShape(shape);
|
Visual Basic |
Copy Code
|
' implicitly connect the start plug of a 1D shape to the default inward port of another shape
shape1D.StartPlug.ConnectToShape(shape)
|
In a plug-port connection the port is considered as master and the plug is considered as slave. This means that the plug will follow the movement of the port to which it is connected.
It is important to understand that physically not shapes, but their plugs and ports get connected. However it is more useful to logically threat these connections as if shapes are connected to other shapes. See Shape Navigation for more information.
You can disconnect a plug with the help of it's Disconnect method.
You can obtain the shapes to which the start and end plugs are connected via the FromShape and ToShape properties. Setting these properties will perform implicit connection of the respective plug.
Optional Shape Elements
Optionally, each shape can have the following set of additional shape elements:
-
Labels - labels are texts, whose location, size and/or orientation can be anchored to different aspects of the shape or the models it aggregates. The shape labels are accessible from the
Labels property. See
Labels for more information.
-
Ports - ports are connection points to which multiple plugs can be connected. The shape ports are accessible from the
Ports property. See
Ports for more information.
-
Control Points - control points are used for the interactive modification of the shape geometry. The shape control points are accessible from the
ControlPoints property. See
Control Points for more information.
-
Decorators - decorators are elements, which "decorate" a shape in a certain manner. See the
Decorators for more information.
By design a shape will only create the elements it needs (e.g. some shapes may not have labels, control points and/or ports). You can programmatically create and destroy the optional shape elements with the help of the CreateShapeElements and DestroyShapeElements methods, which both accept a combination of the ShapeElementsMask enumeration.
The following code will create the shape ports element, if the shape does not already has ports:
C# |
Copy Code
|
if (shape.Ports == null)
{
shape.CreateShapeElements(ShapeElementsMask.Ports);
}
|
Visual Basic |
Copy Code
|
If shape.Ports Is Nothing Then
shape.CreateShapeElements(ShapeElementsMask.Ports)
End If
|
Currently all instancable shapes in the DOM have a single label, which is at the same time the default label. The only exception is the NTextShape (see Primitive Shapes for more information).
Expand and Collapse
Each shape can be either in expanded or collapsed state. By default all shapes are expanded. To collapse/expand a shape set its Collapsed property to true/false respectively.
When a shape is collapsed it will automatically reset its model size to be the size specified by the CollapsedSize property. Changing the model size of the shape, when the shape is collapsed will automatically update the CollapsedSize property of the shape.
When a shape is expanded it will automatically reset its model size to be the size specified by the ExpandedSize property. The ExpandedSize property is automatically updated when the shape is resized in expanded state.
A shape will expand/collapse relative to a pin point, the alignment of which is specified by the ExpandCollapsePinAlignment property.
All models that a shape aggregates are considered collapsed, when the shape is collapsed. A collapsed model is invisible and cannot be hit tested. Besides the aggregated models, the labels of a collapsed shape will also automatically become invisible and not hit testable. The only content that will remain visible are the shape decorators. That is why decorators are usually used in combination with collapsible shapes.
It is also worth mentioning that the diagram will automatically change the anchor positioning of plugs connected to ports, which reside in collapsed shapes (e.g. collapsed ports). By default ports, which are collapsed glue the connected plugs to the rim of the last collapsed shape in their ancestor path.
Interaction Style
In drawing views shapes are interactively edited with the help of trackers (interactive editors with handles, which the user can drag). There is a single tracker, for each type of shape aspect, which must be edited.
The trackers are automatically created by the drawing view when the shape is selected. You can however specify what types of trackers must be displayed for each shape through the InteractionStyle property. It gets/sets a NInteractionStyle structure, which exposes an easy way to raise/drop the flags in the InteractionStyleMask enumeration.
The following example will instruct the drawing view not to create a rotated bounds tracker for the shape, when it is selected:
C# |
Copy Code
|
NInteractionStyle interactionStyle = shape.InteractionStyle;
interactionStyle.RotatedBounds = false;
shape.InteractionStyle = interactionStyle;
|
Visual Basic |
Copy Code
|
Dim interactionStyle As NInteractionStyle = shape.InteractionStyle
interactionStyle.RotatedBounds = False
shape.InteractionStyle = interactionStyle
|
Translation Slaves
It is in many cases necessary to implement rigid connected shapes structures. This is achieved with the help of shape translation slaves. The translation slaves of a shape are such shapes, which are translated with the shape when it is translated.
The translation shapes are specified through the TranslationSlaves property. It gets/sets a NTranslationSlaves structure, which exposes an easy way to raise/drop the flags in the TranslationSlavesMask enumeration.
The following example will instruct the shape to be translated together with it's destination shapes:
C# |
Copy Code
|
NTranslationSlaves translationSlaves = shape.TranslationSlaves;
translationSlaves.DestinationShapes = true;
shape.TranslationSlaves = translationSlaves;
|
Visual Basic |
Copy Code
|
Dim translationSlaves As NTranslationSlaves = shape.TranslationSlaves
translationSlaves.DestinationShapes = True
shape.TranslationSlaves = translationSlaves
|
The accumulation of the shape translation slaves is recursive. For example: if a shape has to be translated, because it is a translation slave, then its translation slaves will also be translated.
Related Examples
Windows Forms: Document Object Model - Shapes folder
See Also