Controlling the Behavior of Groups

If you're designing shapes for a custom solution, you can precisely control numerous aspects of a group's behavior. For example, you might want to prevent users from subselecting items in a group, or you might want to prevent shapes contained in a group from being resized.

When you work with formulas in grouped shapes, you can use local coordinates, parent coordinates, or page coordinates, as the following illustration shows. Defining different resize behavior for a grouped shape can involve converting coordinates from one system to another.

A shape in a group in the Visio coordinate system

A shape in a group in the Visio coordinate system

  1. Page coordinates
  1. Parent coordinates
  1. Local coordinates

In this section…

Controlling How Groups are Selected

Defining the Resizing Behavior of Grouped Shapes

Resizing Shapes in Only One Direction

Creating a 3-D Box: an Example

Controlling How Groups are Selected

Microsoft® Visio® supports three types of behavior for selecting groups:

  • Group selection only (group members cannot be selected)
  • Group selection first (second click selects group member)
  • Group member first (second click selects entire group)

In addition, you can prevent the immediate children of a group from being moved by setting the DontMoveChildren cell in the Group Properties section to TRUE.

You can determine the selection behavior of the grouped shapes you create by modifying the SelectMode cell in the Group Properties section of the group's sheet. When groups are nested, the group selection behavior of the currently selected group is respected.

Settings for the SelectMode cell (Group Properties section)

Value

Description

0

Click selects the group only. Subsequent click deselects the group. Corresponds to Group only in the Selection list in the Behavior dialog box.

1

Click selects the group first. Subsequent clicks select group members. To reselect the group, you must first deselect it. (This is the default.) Corresponds to Group first in the Selection list in the Behavior dialog box.

2

Click selects a group member first. Subsequent click selects the group. If the group contains stacked component shapes, subsequent clicks select the next shape in the stacking order, and then the group. Corresponds to Members first in the Selection list in the Behavior dialog box.

Note Clicking in quick succession can be interpreted as a double-click and might open the group's text box rather than select the next shape in the selection order. To prevent this, pause briefly between clicks.

TOP

Defining the Resizing Behavior of Grouped Shapes

When you are defining the resizing behavior of a group, you need to consider how the size and position of the group members should change within the group. As a group is resized, its component shapes are typically stretched and repositioned to maintain their proportions in the group coordinate system. However, some shapes represent objects with fixed physical dimensions. When the group changes size, you can define these shapes to change position, but not change their size or proportions. In some cases, that will mean when a group is resized, some component shapes will be resized and others will not. The ResizeMode cells in the Shape Transform sections for member shapes control their resizing behavior.

For example, in the following figure, the kitchen island group contains a countertop, range, and sink. The range and sink represent physical objects of industry-standard size that should not resize with the island. A countertop, however, can be constructed to any size and should resize with the island.

Resizing shapes in a group

Resizing shapes in a group

  1. Original group
  1. By default, component shapes resize when the group is resized. For shapes with fixed dimensions such as the sink and range, this results in undesirable behavior.
  1. To reposition the sink and stove rather than resize them, enter the value 1 in the ResizeMode cell in the sheets for those shapes.

You can control a component shape's or group's resizing behavior with its ResizeMode cell (Shape Transform section). To control how a component shape behaves when the group that contains it is resized, set the value of the ResizeMode cell for the component shape. To control how a group is resized when it is nested within another group, set the value of the ResizeMode cell for the group. Using the preceding example, you would set ResizeMode to 1 for the sink, and then group the sink with the countertop. The following table shows the resizing options you can use.

Settings for the ResizeMode cell (Shape Transform section)

Value

Description

0

Shape resizes according to the group's ResizeMode setting. Corresponds to Use group's setting under Resize behavior in the Behavior dialog box. (This is the default.)

1

Shape keeps its size when the group is stretched; only its location within the group changes. Corresponds to Reposition only under Resize behavior in the Behavior dialog box.

2

Shape resizes proportionally when the group is stretched. Corresponds to Scale with group under Resize behavior in the Behavior dialog box.

When you set a different resizing behavior, do it for the highest-level shape possible—for example, set the resize behavior for the stove rather than each burner. To keep users from accidentally resizing a shape in a group, either by resizing the group or by subselecting the shape and resizing it individually, set the ResizeMode cell to 1, and also set the LockWidth and LockHeight cells to 1 in the Protection section of the ShapeSheet. If you set locks for a shape's width, height, or aspect ratio and then add the shape to a group, the shape's resizing behavior takes precedence over any locks you've specified for the group.

TOP

Resizing Shapes in Only One Direction

When you want to control how shapes in a group resize, you can customize the component shapes' resizing behavior with formulas. For example, the three-dimensional (3-D) box shape in the following figure is a group made up of three shapes: one for the face of the box, one for the top, and one for the side, each of which resizes differently. When you resize the face, it stretches proportionately in width and height, but the top stretches only in width, and the side stretches only in height. This way, the shape maintains its 3-D look as it is stretched.

The top and side of the 3-D box stretch in only one direction when the box is resized.

The top and side of the 3-D box stretch in only one direction when the box is resized.

You use two key techniques to get this kind of resizing behavior in a group:

  • Define the dimension of the component shape that doesn't resize as a constant value and the dimension of the shape that does resize in terms of the corresponding group dimension.
  • Move the pin of the component shape to the origin in its local coordinate system (the lower-left corner of the local x- and y-axis). Then define the shape's parent pin in terms of the group's width or height, so that the location of the component shape is always fixed with respect to the group. Otherwise, the component shape moves with respect to the parent coordinate system when the group is resized.

In the 3-D box shape, the top's height and the side's width are both constant values, because they shouldn't resize when the group is resized. The top's width is defined in terms of the group width, so the top can resize in the direction of width. Similarly, the side's height is defined in terms of the group height, so the side resizes in the direction of height.

The face shape defines the alignment box for the group, because its size and position determine the size and position of the top and side. The parent pin defines each component shape's position at the appropriate edge of the group alignment box. For the top, the x-coordinate of the parent pin is 0 in., and its y-coordinate is the same as the group's height. For the side, the x-coordinate of the parent pin is equal to the group's width, and its y-coordinate is 0 in.

It's easiest to see the relationship between the component shapes' width and height and the group's width and height if you draw the shape without angled vertices, as shown in the following figure.

Exploded view of the 3-D box shape

Exploded view of the 3-D box shape

  1. Pin
  1. <group sheet id>!Height
  1. <group sheet id>!Width

TOP

Creating a 3-D Box: an Example

Using the techniques described in the previous topic, you can create a shape with resizing behavior similar to the three-dimensional (3-D) box. One shape defines the alignment box for the group, and the component shapes are fixed in position with relation to the alignment box. In addition, the component shapes resize in only one direction as the group is resized.

To draw the actual 3-D box group, do the following:

  • Define the group's custom alignment box by drawing the face of the 3-D box first, grouping it, and then locking the alignment box.
  • Roughly draw the top and side shapes as simple rectangles, and then add them to the group.
  • Modify the vertices of the top and side to give them a 3-D look.
  • Customize the formulas in the Width cell, Height cell, and PinX and PinY cells of the top and side shapes to control their resizing behavior.

As the following figure shows, vertex 2 of the top and vertex 3 of the side are skewed. The y-position of the top's vertex 2 is equal to that shape's height. The x-position of the side's vertex 3 is equal to that shape's width. Top height and side widths are a constant value, 0.125 in. By adding this constant to the appropriate vertex formulas, the shapes are skewed.

Local coordinates for the component shapes of the 3-D box

Local coordinates for the component shapes of the 3-D box

  1. Local coordinates of the group
  1. Height = 0.125 in.
  1. Width + 0.125 in.
  1. Height + 0.125 in.
  1. Width = 0.125 in.

To draw the 3-D box as a group

  1. Use the Rectangle tool to draw rectangular boxes representing the face, top, and side in approximately the right position. Don't worry about making the top and side look 3-D for now.
  1. Select just the face, and group it.
  1. Select the group. On the Window menu, click Show ShapeSheet, and then set the formula for the LockCalcWH cell (Protection section) to 1.
  1. With the group still selected, on the Edit menu, click Open Group to open the group window. Then select the top and the side shapes on the drawing page and drag them into the group window to add them to the group. Close the group window.
  1. Right-click in the group's ShapeSheet® window. On the shortcut menu, click Insert Section, and then click Scratch to add a Scratch section. In the Scratch section, enter the following formulas:
  • Scratch.X1     = .5 in.
  • Scratch.Y1     = .5 in.
  1. Set the top and side shapes to reference the constants you defined in the group's ShapeSheet window.
  • To do this, in the drawing window, select the top shape. On the
  • Window
  • menu, click
  • Show ShapeSheet
  • , and add a Scratch section (as described in step 5). Do the same for the side shape. In the top's and side's Scratch sections, enter these formulas:
  • Scratch.X1     = <group sheet id>!Scratch.X1
  • Scratch.Y1     = <group sheet id>!Scratch.Y1
  • You must supply the group's ID in these formulas. For example, if the group's ID is Sheet.4, the formula for the X1 cell would be
  • Sheet.4!Scratch.X1
  • .
  1. Define the skew for the vertices in the top and side shapes.

Row (Name)

X

Y

1 (MoveTo)

= 0 in.

= 0 in.

2 (LineTo)

= Scratch.X1

= Height

3 (LineTo)

= Width + Scratch.X1

= Height

4 (LineTo)

= Width

= 0 in.

5 (LineTo)

= Geometry1.X1

= Geometry1.Y1

Row (Name)

X

Y

1 (MoveTo)

= 0 in.

= 0 in.

2 (LineTo)

= 0 in.

= Height

3 (LineTo)

= Width

= Height + Scratch.Y1

4 (LineTo)

= Width

= Scratch.Y1

5 (LineTo)

= Geometry1.X1

= Geometry1.Y1

  1. Define the resizing behavior for the top and side shapes.

Width
Height
PinX
PinY
LocPinX
LocPinY

= <group sheet id>!Width
= Scratch.Y1
= 0 in.
= <group sheet id>!Height
= GUARD(0 in.)
= GUARD(0 in.)

Width
Height
PinX
PinY
LocPinX
LocPinY

= Scratch.X1
= <group sheet id>!Height
= <group sheet id>!Width
= 0 in.
= GUARD(0 in.)
= GUARD(0 in.)

  1. Prevent users from selecting the component shapes by entering 0 (group only) in the SelectMode cell (Group Properties section) of the group's sheet.