Drawings SDK Developer Guide > Working with .dgn Files > Building an Example Project > Protocol Extension Usage Example
Protocol Extension Usage Example

OdRxObject is the base class by which the functionality of drawable elements and other OdRxObjects can be extended. ExDgnDump example demonstrates it.

A new class is created as the virtual base class of the extension:

 class OdDgObject_Dumper : public OdRxObject
   {
 ODRX_DECLARE_MEMBERS( OdDgObject_Dumper );
   public:
 OdDgObject_Dumper();
 //OdRxObject overridden
   virtual void addRef();
   virtual void release();
   virtual long numRefs() const;
   …

Its own specialized (non-OdRxObject) base functionality:

 virtual void dump( OdRxObjectPtr object ) = 0; //each object class has to    describe itself via that method
   virtual OdString getClassName() = 0; //each object class has to define its own    name
   …

The macro is provided as an implementation helper, which is critical in this process, since this macro contains the registration methods for this extension:

 ODRX_NO_CONS_DEFINE_MEMBERS( OdDgObject_Dumper, OdRxObject )

 

Next, the object is specialized to each type:

 class OdDgLine2d_Dumper : public OdDgObject_Dumper
   {
public:
 virtual void dump( OdRxObjectPtr object );
   virtual OdString getClassName();
};

Then, the protocol extension is created for the OdRxClass during base class construction. The object’s OdRxClass is retrieved using the ::desc() method, as follows:

 OdDgDumper::OdDgDumper()
   {
   …
   OdDgLine2d::desc()->addX( OdDgObject_Dumper::desc(), &m_line2dDumper    );
   …

During base class destruction, this extension’s existence is revoked:

 OdDgDumper::~OdDgDumper()
   {
   …
   OdDgLine2d::desc()->delX( OdDgObject_Dumper::desc() );
   …

The macro ODRX_NO_CONS_DEFINE_MEMBERS gives the method for registration of this protocol extension object. After loading a database, call the following to initialize the dumper protocol extension into the database:

 //register our dumper
   OdDgObject_Dumper::rxInit();

Call the following to uninitialize the extension:

 OdDgObject_Dumper::rxUninit();

 

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