Cloning a Vector Group
A group of vector objects can be cloned and added to a vector handle as a clone object. The steps used to accomplish this are as follows:
1. |
Create and add a new group in the current vector handle. |
2. |
Create and add any new objects of the desired type into the group. |
3. |
Create an empty layer. |
4. |
Create a clone of the group. |
5. |
Add the clone object to the layer in the vector handle. |
The following is an example that shows this process:
void CreateClone( pVECTORHANDLE pVector )
{
L_INT nRet;
VECTORPOINT Min, Max;
VECTORGROUPDESC GroupDesc;
VECTORGROUP Group;
VECTORLINE Line;
VECTORLAYERDESC LayerDesc;
VECTORLAYER Layer;
VECTORCLONE Clone;
// setup the vector
Min.x = 0.0;
Min.y = 0.0;
Min.z = 0.0;
Max.x = 5.0;
Max.y = 5.0;
Max.z = 0.0;
L_VecSetParallelogram( pVector, &Min, &Max );
L_VecSetOrigin( pVector, NULL );
L_VecSetCamera( pVector, NULL );
ZeroMemory( &GroupDesc, sizeof( GroupDesc ) );
GroupDesc.nSize = sizeof( GroupDesc );
lstrcpy( GroupDesc.szName, TEXT("My Group"));
GroupDesc.dwTag = 0L;
nRet = L_VecAddGroup( pVector, &GroupDesc, &Group, 0L );
if( nRet != SUCCESS )
{
MessageBox( NULL, TEXT("Can't Add Group!"), NULL, 0 );
return;
}
// add a new object
ZeroMemory( &Line, sizeof( Line ) );
L_VecInitObject( &Line.Object );
Line.Object.nSize = sizeof( Line );
Line.Object.nType = VECTOR_LINE;
Line.Point[ 0 ].x = 0.0;
Line.Point[ 0 ].y = 0.0;
Line.Point[ 0 ].z = 0.0;
Line.Point[ 1 ].x = 1.0;
Line.Point[ 1 ].y = 1.0;
Line.Point[ 1 ].z = 0.0;
Line.Pen.nSize = sizeof( Line.Pen );
Line.Pen.bExtPen = FALSE;
Line.Pen.NewPen.LogPen.lopnColor = RGB( 255, 0, 0 );
Line.Pen.NewPen.LogPen.lopnWidth.x = 1;
Line.Pen.NewPen.LogPen.lopnWidth.y = 0;
Line.Pen.NewPen.LogPen.lopnStyle = PS_SOLID;
nRet = L_VecAddObjectToGroup( pVector, &Group, VECTOR_LINE, &Line,
NULL );
if( nRet != SUCCESS )
{
MessageBox( NULL, TEXT("Can't Insert Object!"), NULL, 0 );
return;
}
Line.Point[ 0 ].x = 1.0;
Line.Point[ 0 ].y = 0.0;
Line.Point[ 0 ].z = 0.0;
Line.Point[ 1 ].x = 0.0;
Line.Point[ 1 ].y = 1.0;
Line.Point[ 1 ].z = 0.0;
nRet = L_VecAddObjectToGroup( pVector, &Group, VECTOR_LINE, &Line,
NULL );
if( nRet != SUCCESS )
{
MessageBox( NULL, TEXT("Can't Insert Object!"), NULL, 0 );
return;
}
// create an empty layer
ZeroMemory( &LayerDesc, sizeof( LayerDesc ) );
LayerDesc.nSize = sizeof( LayerDesc );
lstrcpy( LayerDesc.szName, TEXT("My Layer"));
LayerDesc.bVisible = TRUE;
LayerDesc.bLocked = FALSE;
LayerDesc.dwTag = 0L;
nRet = L_VecAddLayer( pVector, &LayerDesc, &Layer, 0L );
if( nRet != SUCCESS )
{
MessageBox( NULL, TEXT("Can't Add Layer!"), NULL, 0 );
return;
}
// now, clone the group
ZeroMemory( &Clone, sizeof( Clone ) );
L_VecInitObject( &Clone.Object );
Clone.Object.nSize = sizeof( Clone );
Clone.Object.nType = VECTOR_CLONE;
memcpy( &Clone.Group, &Group, sizeof( Group ) );
Clone.Point.x = 2.0;
Clone.Point.y = 2.0;
Clone.Point.z = 0.0;
Clone.Scale.x = 2.0;
Clone.Scale.y = 2.0;
Clone.Scale.z = 2.0;
Clone.Rotation.x = 0.0;
Clone.Rotation.y = 0.0;
Clone.Rotation.z = 0.0;
Clone.Pen.nSize = sizeof( Clone.Pen );
Clone.Pen.bExtPen = FALSE;
Clone.Pen.NewPen.LogPen.lopnColor = RGB( 255, 0, 0 );
Clone.Pen.NewPen.LogPen.lopnWidth.x = 1;
Clone.Pen.NewPen.LogPen.lopnWidth.y = 0;
Clone.Pen.NewPen.LogPen.lopnStyle = PS_SOLID;
Clone.Brush.nSize = sizeof( Clone.Brush );
Clone.Brush.VectorBrushStyle = VECTORBRUSH_STANDARD;
Clone.Brush.BrushType.StandardBrush.LogBrush.lbColor = RGB( 255, 0, 0 );
Clone.Brush.BrushType.StandardBrush.LogBrush.lbStyle = BS_SOLID;
Clone.Brush.BrushType.StandardBrush.LogBrush.lbHatch = 0;
Clone.dwFlags = 0L; // use original settings
nRet = L_VecAddObject( pVector, &Layer, VECTOR_CLONE, &Clone, NULL );
if( nRet != SUCCESS )
{
MessageBox( NULL, TEXT("Can't Insert Object!"), NULL, 0 );
return;
}
// now, clone the group again
Clone.Point.x = 4.0;
Clone.Point.y = 1.0;
Clone.Point.z = 0.0;
Clone.Scale.x = 1.0;
Clone.Scale.y = 1.0;
Clone.Scale.z = 1.0;
Clone.Rotation.x = 0.0;
Clone.Rotation.y = 0.0;
Clone.Rotation.z = 45.0;
Clone.dwFlags = VECTOR_CLONE_USE_PEN;
Clone.Pen.NewPen.LogPen.lopnColor = RGB( 0, 0, 255 ); // this clone will be blue
nRet = L_VecAddObject( pVector, &Layer, VECTOR_CLONE, &Clone, NULL );
if( nRet != SUCCESS )
{
MessageBox( NULL, TEXT("Can't Insert Object!"), NULL, 0 );
return;
}
}