Drawings SDK Developer Guide > Working with .dwg Files > Working with Entities > Creating a Custom Entity > Implementing Snap Point Functions
Implementing Snap Point Functions

To support the snap mode in a custom entity, override the getOsnapPoints() function. The custom entity invokes this function to acquire the relevant snap points for the current mode. If you do not want an entity to support snap points for a particular mode, you can filter out the snap modes that you do want to support and return eOk for the others. If multiple object snap modes are active, this function is called once for each object snap mode.


virtual OdResult OdDbEntity::getOsnapPoints( OdDb::OsnapMode osnapMode, int gsSelectionMark,
                                             const OdGePoint3d& pickPoint, const OdGePoint3d& lastPoint,
                                             const OdGeMatrix3d& xfm, const OdGeMatrix3d& ucs, OdGePoint3dArray& snapPoints ) const;

The getOsnapPoints() function must fill in the OdGePoint3dArray array of snap points that have been defined for the custom entity. Additional points in the array are realized using the append() function on the array object. In the function is usually a switch operator, which checks the snap mode and fills in the array of snap points.

For example, the smiley entity implements the following:


OdResult AsdkSmiley::getOsnapPoints( OdDb::OsnapMode osnapMode,
                                     int gsSelectionMark,
                                     const OdGePoint3d& pickPoint,
                                     const OdGePoint3d& lastPoint,
                                     const OdGeMatrix3d& xfm,
                                     const OdGeMatrix3d& ucs,
                                     OdGePoint3dArray& snapPoints ) const
{
   assertReadEnabled();

   switch( osnapMode )
   {
      case OdDb::kOsModeCen:                        // Osnap center point
           snapPoints.append( center() );
           snapPoints.append( leftEyeCenter() );
           snapPoints.append( rightEyeCenter() );
           return eOk;

      case OdDb::kOsModeNear:
      case OdDb::kOsModeQuad:                       // Osnap quad points
         {
           OdGeVector3d xoff(radius(),0,0),
                        yoff(0,radius(),0);
           OdGePoint3d center( center() );
            
           snapPoints.append( center + xoff );
           snapPoints.append( center + yoff );
           snapPoints.append( center - xoff );
           snapPoints.append( center - yoff );
         }
           return eOk;
                                                    // Osnap middle points
      case OdDb::kOsModeMid:
           snapPoints.append( OdGeLineSeg3d( mouthLeft(), mouthRight() ).midPoint() );
           return eOk;

      case OdDb::kOsModeEnd:                        // Other osnap mode is ignored
      case OdDb::kOsModeNode:
      case OdDb::kOsModeIns:
      case OdDb::kOsModePerp:
      case OdDb::kOsModeTan:
      
      default: break;
   }
   return eInvalidInput;
}

See Also

Creating a Custom Entity

Implementing Grip Point Functions

Copyright © 2002 – 2020. Open Design Alliance. All rights reserved.