Drawings SDK Developer Guide > Working with .dwg Files > Working with Entities > Creating a Custom Entity > Smiley Object Example
Smiley Object Example

This sample demonstrates the implementation of a custom object. The AsdkSmiley class has the following definition:


#define kPi 3.14159265358979323846

class AsdkSmiley : public OdDbEntity
{
 private:
   OdGeVector3d   mnormal;                                   // smiley normal vector
   OdGeCircArc3d  mfacecircle;                               // smiley face
   OdGeCircArc3d  mmoutharc;                                 // smiley mouth arc (not written out)

   double  meyesapart;                                       // smiley eyes apart
   double  meyesheight;                                      // smiley eyes height
   double  meyesize;                                         // smiley eyes size

   OdCmEntityColor mbackcolor;                               // smiley color

 protected:
   void ensureRadiusMouth();
   void ensureRadiusEyes();

 public:
   ODDB_DECLARE_MEMBERS(AsdkSmiley);                         // Declare database methods

   AsdkSmiley();                                             // Constructor
   virtual ~AsdkSmiley();                                    // Destructor

   // Step 1
   bool worldDraw(OdGiWorldDraw* mode) const;                // for drawing
   OdResult dwgInFields(OdDbDwgFiler* pFiler);               // for loading from .dwg file
   void dwgOutFields(OdDbDwgFiler* pFiler) const;            // for saving in .dwg file

   // Step 2
   OdResult dxfInFields(OdDbDxfFiler *filer);                // for loading from .dxf file
   void dxfOutFields(OdDbDxfFiler *filer) const;             // for saving in .dxf file

   // Step 3
   OdResult transformBy(const OdGeMatrix3d& xform);          // for moving and rotating
   void scaleRadius(const double r);                         // for scaling
   
   // Step 4
   OdResult getGripPoints(OdGePoint3dArray& gripPoints) const;
   OdResult moveGripPointsAt(const OdGePoint3dArray& gripPoints, const OdIntArray& indices);

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

   // Step 6
   OdResult explode(OdRxObjectPtrArray& entitySet) const;    // to destroy the smiley object

   //
   // Smiley property functions
   //

   virtual OdCmEntityColor backColor() const;                // smiley back color
   virtual void setBackColor(const OdCmEntityColor& color);
   virtual OdGeVector3d normal() const;                      // smiley normal
   virtual void setNormal(const OdGeVector3d v);
   virtual OdGePoint3d center() const;                       // smiley center
   virtual void setCenter(const OdGePoint3d c);
   virtual double radius() const;                            // smiley radius
   virtual void setRadius(const double r);
   virtual double eyesApart() const;                         // eyes apart
   virtual void setEyesApart(const double a);
   virtual double eyesHeight() const;                        // eyes height
   virtual void setEyesHeight(const double h);
   virtual double eyeSize() const;                           // eyes size
   virtual void setEyeSize(const double s);
   
   virtual OdGePoint3d leftEyeCenter() const;                // center of left eye
   virtual OdGePoint3d rightEyeCenter() const;               // center of right eye
   virtual double mouthRadius() const;                       // radius of mouth arc
   virtual OdGePoint3d mouthCenter() const;                  // center of mouth arc
   virtual OdGePoint3d mouthLeft() const;                    // left point of mouth arc
   virtual OdGePoint3d mouthRight() const;                   // right point of mouth arc
   virtual OdGePoint3d mouthBottom() const;                  // bottom point of mouth arc

                                                             // whole mouth
   virtual void setMouth(const OdGePoint3d& left, const OdGePoint3d& bottom, const OdGePoint3d& right);
   void moveMouthToPoint(const OdGePoint3d point);
};

See Also

Creating a Custom Entity

Creating Custom Entities Sample Application

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