﻿ Groups
Nevron Open Vision Documentation
Diagram / Diagram DOM / Drawings / Shapes / Groups
In This Topic
Groups
In This Topic

Groups are shapes, which aggregate other shapes. Groups are represented by the NGroup class, which derives from NShape class. You can construct a group from any types of shapes - including other groups. Groups are by default treated as 2D shapes. Groups support drill down selection, which means that you can select the shapes contained in a group.
Creating Groups

The following example creates a group, which contains three shapes:

Creating Groups
Copy Code
```// create all shapes
NBasicShapesFactory basicShapes = new NBasicShapesFactory();
NConnectorShapesFactory connectorShapes = new NConnectorShapesFactory();
// create the group
NGroup group = new NGroup();
// create a rectangle that is scaled and repositioned
NShape rect1 = basicShapes.CreateShape(ENBasicShapes.Rectangle);
rect1.ResizeInGroup = ENResizeInGroup.ScaleAndReposition;
rect1.SetBounds(new NRectangle(10, 10, 100, 100));
// create a rectangle that is only repositioned
NShape rect2 = basicShapes.CreateShape(ENBasicShapes.Rectangle);
rect2.ResizeInGroup = ENResizeInGroup.RepositionOnly;
rect2.SetBounds(new NRectangle(120, 120, 100, 100));
// create a 1D shape
NShape arrow = connectorShapes.CreateShape(ENConnectorShapes.SingleArrow);
arrow.SetBeginPoint(new NPoint(10, 250));
arrow.SetEndPoint(new NPoint(220, 290));
```
Resize Of Shapes in Groups

When 2D shapes that reside in a group are resized by the user, NOV diagram takes into account the ResizeInGroup property of the shape that accepts values from the ENResizeInGroup enumeration:

• ScaleAndReposition - the shape width and height and pin point are expressed as factors of the group width and height. In this way when the group is resized the shape will change its size and position.
• RepositionOnly - only the shape pin point is expressed as factors of the group width and height. In this way when the group is resized, the shape will maintain its original size, but it will be repositioned.
• UseGroupSettings - in this case the resize behavior of shape is determined by the group ResizeShapes property, which accepts only two values - ScaleAndReposition and RepositionOnly.

When the user changes the end-points of 1D shapes that reside in a group, NOV Diagram expresses the respective end-point as factors of the group width and height. In this way when the group is resized the 1D shape is proportionally "stretched" by its end-points.

Group Selection Mode

By default groups allow the drill-down selection of the shapes which they contain. The user performs drill down selection of the shapes contained inside a group by clicking on a grouped shapes multiple times. Each group can control the way in which drill-down selection is performed for that group vis the SelectionMode property that accepts values from the ENGroupSelectionMode enumeration:

• GroupOnly - specifies that when you click a group, only the group is selected. You cannot select the individual shapes within a group.
• GroupFirst - specifies that when you click a group, the group is selected first. If you click again, you can select an individual shape. Group first is the default behavior for most groups.
• ShapesFirst - specifies that when you click a group, you select the individual shape that you're pointing to. You must click the bounding box around the group to select the group itself.

When creating custom shapes by grouping other shapes it is often required to disable the selection of the shapes contained inside the group. The following code example disables the selection of the shapes contained inside a group:

Change group selection mode
Copy Code
```group.SelectionMode = ENGroupSelectionMode.GroupOnly;
```
Group Snapping

By default group allow the snapping to the shapes contained inside them. When creating custom shapes by grouping other shapes, it is often required to prevent the user from gluing connectors to the shapes contained inside the group. Because an end-point must be first snapped to a shape before it is glued to it, you can prevent the snapping to the group shapes by setting the SnapToShapes property to false:

Disabling Snapping to Shapes
Copy Code
```group.SnapToShapes = false;
```
Group Elements Z-Order

By default the elements of a group (geometry, text-block, widget etc.) are displayed behind the content of the shapes contained in the group. You can however change that and display the group elements above the shapes, by setting the group ElementsZOrder to AboveShapes:

Displaying the group elements above the shapes
Copy Code
```group.ElementsZOrder = ENGroupElementsZOrder.AboveShapes;
```