Drawings SDK Developer Guide > Working with .dwg Files > Working with Databases > Advanced Data Extraction
Advanced Data Extraction

This section describes advanced functionality and techniques for extracting data from a .dwg or .dxf file.

Dispatching on entity type

Applications that process entity data from a database require a way to identify each entity by its type and perform type-specific processing on the entity. ODA Platform uses a mechanism called protocol extension to provide this functionality. Protocol extension allows a client application to create a new class and associate an instance of this class with a particular class of database objects. Then this new class instance may be retrieved from a generalization of the class with which it was registered, providing an effective means of dispatching by type.

As an example, consider the protocol extension classes defined in ExProtocolExtension.h and ExProtocolExtension.cpp. The purpose of these classes is to dump the contents of the entities in a database, based on entity type. The implementation can be broken up into the following steps.

Create the parent dispatching class

The following is the parent class for our entity dumpers:




class OdDbEntity_Dumper : public OdRxObject
{
public:
  ODRX_DECLARE_MEMBERS(OdDbEntity_Dumper);

  virtual void dump(OdDbEntity* pEnt, int indent) const;
};

class Dumpers;
  
/************************************************************************/
/* This class is the protocol extension class for all entity dumpers    */
/************************************************************************/
class ExProtocolExtension  
{
  Dumpers* m_pDumpers;
public:
	ExProtocolExtension();
	virtual ~ExProtocolExtension();
  void initialize();
  void uninitialize();
};

#endif // !defined(AFX_EXPROTOCOLEXTENSION_H__A6B44366_0CE0_408A_BFDF_BAE98BD49250__INCLUDED_)

This class MUST be derived from OdRxObject.

Create one or more child dispatching classes

See the OdDb2dPolyline_Dumper class defined in Drawing\Examples\OdReadEx\ExProtocolExtension.cpp for an example of dumping OdDb2dPolyline entities by overriding the OdDbEntity_Dumper::dump() function in order to dump the data specific to this entity. This method can be used to extract the geometry data from any OdDbEntity type.

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