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); };
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.
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);