Creating Composite ShapesCognex VisionPro

VisionPro provides many basic shapes, such as CogCircle, CogRectangle, and CogEllipse. The CogCompositeShape interface lets you group the basic VisionPro shapes and treat them as a single graphic entity.

This example shows you how to create a composite shape, how to add basic shapes to a composite shape, and how to display the composite shape.

Before You Begin

Choose Project -> Add Reference and add a reference to the Cognex.VisionPro.Core assembly to use composite shapes.

This example displays images in a Cognex Display Control named cdDisp.

Create the Child Shapes

The shapes that make up the composite shape are called child shapes. You create these shapes as you normally do with the exception that the SelectedSpaceName of the graphic must be "$". This coordinate space name specifies that the shape is a child of a composite shape.

' Valid for COM, .NET is similar
Dim cgRect As New CogRectangle
Dim cgCirc As New CogCircle
cgCirc.CenterX = 220
cgCirc.CenterY = 220
cgCirc.SelectedSpaceName = "$"

cgRect.X = 220
cgRect.Y = 220
cgRect.SelectedSpaceName = "$"
Create the Composite Shape and Add the Child Shapes to It

A composite shape maintains a collection of child shapes. You can access this collection with its Shapes method.

' Valid for COM, .NET is similar
Dim cgShape As New CogCompositeShape
cgShape.Shapes.Add cgRect
cgShape.Shapes.Add cgCirc
Set the Composite Shape Attributes

In most respects the composite shape behaves like any of the basic VisionPro shapes, and you set its attributes the same way.

' Valid for COM, .NET is similar
cgShape.Interactive = True
cgShape.GraphicDOFEnable = cogCompositeShapeDOFAll
cgShape.Visible = True

The composite shape's CompositionMode property determines whether each shape keeps its own graphic properties such as line width, line style, and color, or whether the composite shape's properties are propagated to each of the child shapes. The default composition mode is CogCompositeShapeCompositionModeConstants. The SelectedSpaceName and GraphicDOFEnableBase properties are never propagated from the composite shape to the child shapes.

Add the Composite Shape to the Display

To make the shape appear in a display, you add it to the display's graphics collection. Since the composite shape in this example is interactive, you add it to the InteractiveGraphics collection.

' Valid for COM, .NET is similar
cdDisp.InteractiveGraphics.Add cgShape