Creating a Polyline

A Polyline is defined by a list of points, followed by an equal length list of radius. Polylines can be used to define a variety of complex shapes. The procedure for creating a Polyline is oultlined below.

1. Create a CATGeoFactory object. This will be used to create our other geometry.

CATGeoFactory* piGeomFactory = ::CATCreateCGMContainer() ;
if (NULL==piGeomFactory) return (1);

2. Create required variables needed to create different objects. Two CATICkeParm_var objects must be created to act as placeholders for the x and y coordinates of each point. This must be done since the Polyline method requires CATICkeParm type variables for the inputs. spMag is an object that tells our value parameter what units to use. nameX and nameY are are just variables containing the name of the x and y parameters.

CATICkeParm_var spX = NULL_var;
CATICkeParm_var spY = NULL_var;
CATICkeMagnitude_var spMag = spParamDictionary->FindMagnitude("LENGTH");
CATUnicodeString nameX("X-Value");
CATUnicodeString nameY("Y-Value");

3. Next we must create some list objects to hold our radius and point objects. This list will be fed into the Polyline function to create our polyline. The points are the points on the polyline, and the radii are the corresponding round radius to each point.

CATLISTV(CATISpecObject_var) spPlist; CATLISTV(CATISpecObject_var) spRlist; CATLISTV(CATISpecObject_var) spPlaneList;

4. Now we need to create three points and add them to our spPlaneList object. These first three will be used to create a plane on which we will draw our polyline.

double ipt[2];
ipt[0] = 0.0;
ipt[1] = 0.0;
ipt[2] = 0.0;

CATIGSMPoint_var spPta = spGSMFactory->CreatePoint(ipt);
spPlaneList.Append(spPta);

ipt[0] = 10.0;
ipt[1] = 0.0;
ipt[2] = 0.0; 

CATIGSMPoint_var spPtb = spGSMFactory->CreatePoint(ipt);
spPlaneList.Append(spPtb);

ipt[0] = 0.0;
ipt[1] = 10.0;
ipt[2] = 0.0;

CATIGSMPoint_var spPtc = spGSMFactory->CreatePoint(ipt);
spPlaneList.Append(spPtc);

CATIGSMPlaneMean_var ipPlane = spGSMFactory->CreatePlane(spPlaneList);
CATISpecObject_var iPlane = ipPlane;

iPlane->Update();
CATIGSMProceduralView_var spCurObj = iPlane;
spCurObj->InsertInProceduralView();

5. Next we create our points on the plane and add them to our spPlist object which contains our points. Repeat this step for as many points as you want in your Polyline.

spX = spParmFactory->CreateDimension(spMag,nameX,0.0);
spY = spParmFactory->CreateDimension(spMag,nameY,0.0);

CATIGSMPoint_var spPt0 = spGSMFactory->CreatePoint(iPlane, iPoint, spX, spY);
spPlist.Append(spPt0);

spX = spParmFactory->CreateDimension(spMag,nameX,0.1);
spY = spParmFactory->CreateDimension(spMag,nameY,0.0);

CATIGSMPoint_var spPt1 = spGSMFactory->CreatePoint(iPlane, iPoint, spX, spY);
spPlist.Append(spPt1);

etc...

6. Now we need to create our list of radii. The radii need two objects, a name and a value.

CATISpecObject_var spRd0 = spParmFactory->CreateLength("Radius.1", 0.03);
spRlist.Append(spRd0)

CATISpecObject_var spRd1 = spParmFactory->CreateLength("Radius.2", 0.03);
spRlist.Append(spRd1);

etc...

Do this for as many points as you have, number of radii needs to be the same as number of points.

6. Last step is to create the Polyline. SetClosure tells the polyline to close itself.

CATIGSMPolyline_var spPoly = spGSMFactory->CreatePolyline(spPlist, spRlist);
spPoly->SetClosure(true);
CATISpecObject_var spPLine = spPoly;

spPLine->Update();
spCurObj = spPLine;
spCurObj->InsertInProceduralView();
spPLine->Update();

I'm not sure why, but you have to update the Polyline at the beginning and end of the insert section.