AcGi Overview

The AcGi library defines a set of interfaces with which objects can render themselves to an underlying graphics system. This section discusses how AcGi works in the AutoCAD environment. However, it works in a similar way for other systems that implement the AcGi interfaces.

The AcGi library enables entities to query for information about the regeneration process, and to detail a set of primitives using the geometry classes. Access to AcGi occurs within the following three member functions of the AcGiDrawable base class:

ACDB_PORT ADESK_SEALED_VIRTUAL Adesk::Boolean
worldDraw(
    AcGiWorldDraw * wd);
 
ACDB_PORT ADESK_SEALED_VIRTUAL void 
viewportDraw(
    AcGiViewportDraw * vd);
 
ACDB_PORT ADESK_SEALED_VIRTUAL Adesk::UInt32   
setAttributes(
    AcGiDrawableTraits * traits);

AcDbEntity inherits these functions from AcGiDrawable.

Each of the these functions, worldDraw(), viewportDraw() and setAttributes(), has a nonsealed counterpart, subWorldDraw, subViewportDraw and subSetAttributes(), respectively.

virtual Adesk::Boolean
subWorldDraw(
    AcGiWorldDraw * wd) = 0;
 
virtual void 
subViewportDraw(
    AcGiViewportDraw * vd) = 0;
 
virtual Adesk::UInt32   
subSetAttributes(
    AcGiDrawableTraits * traits) = 0;

AutoCAD realies on the sealed versions to provide the basic common functionality, which then call into the nonsealed versions for subtype-specific functionality. Typically, when implementing a custom entity, you will override these nonsealed functions and provide your own implementation.

When AutoCAD needs to regenerate the graphics to display an entity, it calls the sealed functions in the following manner:

AcGiDrawable *pDrawable;
pDrawable->setAttributes(pDt);
if (!pDrawable->worldDraw(pWd))
{
    for each viewport
        pDrawable->viewportDraw(pVd);
}

For custom entities, if you have overridden the nonsealed functions, AutoCAD passes in the appropriate AcGi objects. This enables AutoCAD to display your custom entity just as if it were a built-in entity.

The subSetAttributes() function initializes attributes for the entity, such as color, layer, and linetype. The subWorldDraw() function builds the portion of the entity's graphical representation that can be specified independent of any particular model-space view or paper-space viewport contexts. The subViewportDraw() function then builds the view-dependent portion of the entity's graphics. If any of the entity's graphics are view-dependent, suWorldDraw() must return kFalse and suViewportDraw() must be implemented. Conversely, if the entity has no view-dependent graphics, then subWorldDraw() must return kTrue and the custom entity does not implement subViewportDraw().

The following illustration shows the sequence in which an AutoCAD drawing with two viewports gets regenerated. In this example the drawing contains two blocks, Block 1 and Block 2. Block 1 is broken down into its component parts, a line and a circle. Block 2 consists of a custom entity. The custom entity is broken down to show the order in which functions are called as the drawing is generated:

The AcGiContext object provides a common context that can be accessed during all parts of the regeneration process. It provides information about the current state of the regen. For example, you can get the current database from the AcGiContext object at any time during the regen process.

The class hierarchy for AcGi is as follows:

The AcGiCommonDraw base class encapsulates the common functionality of AcGiViewportDraw and AcGiWorldDraw. The AcGiGeometry base class encapsulates the common functionality of AcGiViewportGeometry and AcGiWorldGeometry. These base classes allow you to write more general code that can handle both cases, if desired.