Creating Protocol Extension Classes

To create a custom object snap mode you must create protocol extension classes to handle the per-entity input point processing. The class AcDbCustomOsnapInfo defines the protocol that every custom object snap mode must implement for relevant entities. This base class contains the function getOsnapInfo(), which performs the input point processing on an entity:

class AcDbCustomOsnapInfo : public AcRxObject {
public:
ACRX_DECLARE_MEMBERS(AcDbCustomOsnapInfo);
virtual Acad::ErrorStatus
getOsnapInfo(
    AcDbEntity* pickedObject,
    int gsSelectionMark,
    const AcGePoint3d& pickPoint,
    const AcGePoint3d& lastPoint,
    const AcGeMatrix3d& viewXform,
    AcArray<AcGePoint3d>& snapPoints,
    AcArray<int>& geomIdsForPts,
    AcArray<AcGeLine3d>& snapLines,
    AcArray<int>& geomIdsForLines);
};

To create protocol extension classes for custom object snap modes

  1. Define an abstract base protocol extension class derived from AcDbCustomOsnapInfo.

    For example, if your custom class is called AcmeSocketInfo, define it as follows:

class AcmeSocketInfo : public AcDbCustomOsnapInfo{
public:
ACRX_DECLARE_MEMBERS(AcDbSocketInfo);
virtual Acad::ErrorStatus
getOsnapInfo(
    AcDbEntity* pickedObject,
    int gsSelectionMark,
    const AcGePoint3d& pickPoint,
    const AcGePoint3d& lastPoint,
    const AcGeMatrix3d& viewXform,
    AcArray<AcGePoint3d>& snapPoints,
    AcArray<int>& geomIdsForPts,
    AcArray<AcGeLine3d>& snapLines,
    AcArray<int>& geomIdsForLines);
};
ACRX_NO_CONS_DEFINE_MEMBERS(AcmeSocketInfo, AcDbCustomOsnapInfo);

Initialize the base protocol extension class and add it to the runtime class hierarchy.

For example, add the following lines to your acrxEntryPoint() function:

AcmeSocketInfo::rxInit();
acrxBuildClassHierarchy();

For every relevant entity class, derive a protocol extension class from the base class.

For example, you might derive a class called AcmeSocketForLines that implements getOsnapInfo() to handle the input point processing for lines.

Note: A default implementation should be associated with AcDbEntity for each registered class derived from AcDbCustomOsnapInfo.

Create an instance of each protocol extension object and add the objects to the appropriate AcRxClass descriptor objects using the addX() function.

For example:

pSocketForLine = new AcmeSocketForLine;
AcDbLine::desc()->addX(AcmeSocketInfo::desc(), pSocketForLine);