Friday, January 12, 2007

Exercise2 - Step4

Creating a Custom Entity – Exercise 2 – Step 4

Now you will learn how to add OSNAP points to your custom entity. If you run the application before this step you will see that our custom entity already shows some Object Snap points by default (ENDPOINT and MIDPOINT). In this example we want to add a CENTER object snap to our polyline that will allow users to select the exact center point. To provide this, we need to change the standard behavior of getOsnapPoints() method. This method has 4 signatures and 2 of them, containing the AcGeFastTransform parameter, are for future use. We will use the first signature and will handle the CENTER object snap responding with our center point:

Acad::ErrorStatus AuPolyline::getOsnapPoints (
AcDb::OsnapMode osnapMode,
int gsSelectionMark,
const AcGePoint3d &pickPoint,
const AcGePoint3d &lastPoint,
const AcGeMatrix3d &viewXform,
AcGePoint3dArray &snapPoints,
AcDbIntArray &geomIds) const
{
assertReadEnabled () ;
switch(osnapMode)
{
case AcDb::kOsModeCen:
snapPoints.append(GetPolylineCenter());
break;
}
return (AcDbPolyline::getOsnapPoints (osnapMode, gsSelectionMark, pickPoint, lastPoint, viewXform, snapPoints, geomIds)) ;
}
This method receives an Array of points where we need to add the center point whenever the OSNAP CENTER is requested. On line 13 we handle the CENTER object snap by adding our center point to the snapPoints array (Figure 17). Even handling this particular object snap this method needs to call the polyline class level. The polyline will handle all other possible object snaps for us.


Figure 17 – CENTER object snap.

Note: This OSNAP solution handles only simple OSNAP types like CENTER, MIDPOINT and ENDPOINT. Complex OSNAP modes like INTERSECTION require other methods implementations and some additional procedures.

No comments :