Introduction
DWG Concepts
Teigha Class Categories
Teigha consists of several categories of C++ classes, which you can identify by the prefix of the class name:
OdRx - Classes pertaining to run time class registration and identitification
OdDb - Database classes
OdGi - Classes used for vectorization of database objects
OdGe - General purpose geometric classes, such as point, vector, etc.
OdBr - Classes used for B-Rep traversal
OdGs - Graphical System classes, providing a client interface for vectorization
OdRxObject and Run Time Type Identification
The OdRxObject class is the base class for all classes that require registration and run-time type identification. Each subclass of OdRxObject has an associated OdRxClass object (obtained using the OdRxObject::desc() function) that provides run-time type identification. The OdRxObject::isA() function determines whether an object is an instance of a particular class or a derived class.
Object IDs
Teigha uses Object ID objects (instances of OdDbObjectId) to reference database objects. An Object ID is a memory resident placeholder for a database object. An actual database object pointer can always be obtained from a valid Object ID object. Usually, a user gets a database object pointer by explicitly opening the object via the Object ID. The associated smart pointer object closes the open database object pointer when the smart pointer goes out of scope. Alternatively, you can explicitly close it by calling the smart pointer release() function.
As an effect of this mechanism, database objects do not reside in memory unless a user explicitly opens them. This mechanism allows Teigha to support a transparent partial loading of a database: a few key objects are loaded, but the remaining database objects need not be loaded untill they are accessed. This greatly improves the speed for applications that access only some parts of a drawing.
Smart Pointers and Reference Counting
Teigha uses reference counting to manage most of the heap objects. A set of smart pointer classes facilitate the use of heap objects. The main Teigha smart pointer template is OdSmartPtr. You can find it in SmartPtr.h, in the top level include folder. Most database classes have smart pointer classes, which are defined as the class name with the suffix "Ptr". For example, the OdDbCircle smart pointer is OdDbCirclePtr.
DWG Database Structure
A drawing file is represented in memory by an instance of the OdDbDatabase class. This document refers to an OdDbDatabase instance as database. A database serves as container object for all data loaded from the file.
The following diagram shows the database content:
Additionally, a database contains functions for setting and retrieving the values of system variables in a file.
Entities and Blocks
All entities are accessed from the list of entities from the OdDbBlockTableRecord to which the entities are attached. There are two special blocks, *Model_Space and *Paper_Space, which hold the model space and paper space entities respectively. Several entities may also serve as containers for other entities. For example, an OdDb3dPolyline entity serves as the container or owner for its vertices, while an OdDbBlockReference owns its attributes. This differs from the C Toolkit, where all entities for a block are stored in a flat list.
Tables
The following tables are available in DWG and DXF files:
Layers
Contains all layers in the drawing. Each layer has attributes, such as ON/OFF, FROZEN/THAWED, color, and linetype. The corresponding Teigha class is OdDbLayerTableRecord.
Linetypes
Contains all linetypes in the drawing. Each linetype has a name, a string describing its appearance, and an array containing the control parameters which determine the linetype appearance. The corresponding Teigha class is OdDbLinetypeTableRecord.
TextStyles
Contains all text style definitions from the drawing. Each text style has a name, an indication of the font in use, a height, an oblique angle, and other parameters. The corresponding Teigha class is OdDbTextStyleTableRecord.
Views
Contains all named view definitions of the drawing. Each view definition specifies a 3D view. The corresponding Teigha class is OdDbViewTableRecord.
Viewports
Contains all viewport definitions of the drawing. Viewport definitions are distinct from paper space viewport entities, which are rather model space viewports that display model space data. A named viewport group consists of a set of viewports, all having the same name. The current viewport has the name "*ACTIVE". The corresponding Teigha class is OdDbViewportTableRecord.
DimStyles
Contains all dimension styles definitions in the drawing. Dimension styles are collections of variables that specify how dimensions are created. The corresponding Teigha class is OdDbDimStyleTableRecord.
UCSs
(User Coordinate Systems)
Contains all named user coordinate system definitions in the drawing. A UCS is a specification of a local coordinate system to use instead of the world coordinate system. The corresponding Teigha class is OdDbUCSTableRecord.
Registered Applications
Contains all registered applications in the drawing. These are applications that have registered themselves with the CAD system. The corresponding Teigha class is OdDbRegAppTableRecord.
Object Dictionary
The Object Dictionary stores a number of types of AutoCAD objects, such as dictionary entries, multi-line styles, groups, and application defined custom objects. The Object Dictionary is an object of type OdDbDictionary.
Memory Management
All heap memory allocations in Teigha are made through calls to the following functions defined in OdAlloc.h:
extern ALLOCDLL_EXPORT void* odrxAlloc (size_t nBytes);
extern ALLOCDLL_EXPORT void* odrxRealloc (void* pMemBlock, size_t newSize, size_t oldSize);
extern ALLOCDLL_EXPORT void odrxFree (void* pMemBlock);
Additionally, Teigha calls the global "new" and "delete" C++ operators. The TD_Alloc module provides default implementations of the odrx* functions, and "new" and "delete".