Close

Relief for ODA Team in Ukraine

Learn more
ODA Drawings SDK
Host Application Services

Drawings SDK allows a client application to provide an implementation for certain services, including status notification (for file loading, saving, etc.), font file locating, etc. These services are defined by the OdDbHostAppServices class. A default implementation of OdDbHostAppServices is provided with the Drawings SDK.

Each database instance has an associated OdDbHostAppServices object (which allows notifications to be sent to different OdDbHostAppServices instances during simultaneous file loads or saves). This association can be formed in the following ways:

  • An empty database is created by an instance of OdDbHostAppServices (using the OdDbHostAppServices::createDatabase() function), and its associated services object will be the one that created it.
  • A client calls OdDbHostAppServices::readFile() or OdDbHostAppServices::recoverFile() which as expected will associate the returned database with the OdDbHostAppServices instance for which the function was called.

Database Loading Example

Objects of the OdDbDatabase class represent the contents of a .dwg or .dxf file in memory, and an OdDbDatabase object is the initial access point for all data in a drawing. The following code segment demonstrates how to load a drawing into memory:



// Define a Custom Services class that has functionality of ExSystemServices and ExHostAppServices.
class MyServices : public ExSystemServices, public ExHostAppServices
{
protected:
  ODRX_USING_HEAP_OPERATORS(ExSystemServices);
}

OdRxObjectImpl<MyServices> svcs;           // Services

odInitialize(&svcs);                       // Initialization

OdDbDatabasePtr pDb;                       // A smart pointer to a database

pDb = svcs.readFile("drawing1.dwg");       // Create a database and load the drawing into it

// Do something with the database.

pDb.release();                             // Delete the database before uninitialization

odUninitialize();                          // Termination

As part of the MyServices instance, the OdDbHostAppServices instance that is created the database (using OdDbHostAppServices::readFile(), OdDbHostAppServices::createDatabase(), etc.) will be associated with that database instance. So in the above example, the MyServices instance, svcs, will be associated with the newly created database, and will receive a call to newProgressMeter prior to the loading of "drawing1.dwg". The returned OdDbHostAppProgressMeter will receive the notification calls for the file load.

If you want use do multi-threading, create an OdDbHostAppServices instance for each thread. Otherwise, progress notifications from multiple threads will be sent to the same services object.

Note: When the OdDbHostAppServices object calls the readFile() method, it can throw the "File is not found" OdError exception. The OdError::description() method returns OdString containing the file name. If this exception occurs for the RecomputeDimBlock.tx module, use the setRecomputeDimBlocksRequired() method of the host object to control the situation. The OdDbHostAppServices object is introduced to handle loading of the RecomputeDimBlock.tx module in static configurations and has a True value by default. If the RecomputeDimBlock module is absent, the readFile() method throws the "File is not found" exception to prevent creating files where dimensions are not displayed in Autodesk® AutoCAD® 2010 and 2011. If the client application does not use the recompute dimension block functionality intentionally (not recommended), call OdDbHostAppServices::setRecomputeDimBlocksRequired(false) and pass a False value to it as an argument before creating a database or loading a drawing file. If the client application uses this functionality, pass a True value to it as an argument, but the RecomputeDimBlock.tx module must exist.

Monitoring File Loading and Saving

Load and save monitoring is done by providing a custom implementation of the OdDbHostAppProgressMeter class. The client should override the OdDbHostAppServices::newProgressMeter() function to return a custom implementation of an OdDbHostAppProgressMeter. The C++ library will call OdDbHostAppServices::newProgressMeter() when a new progress meter is required for a load or save operation. The progress meter will receive a call to OdDbHostAppProgressMeter::start(), which initializes the meter, then it will receive a call to OdDbHostAppProgressMeter::setLimit(), which sets the total number of times this meter will be called, call it n. After that, the meter will receive the followed by n calls to OdDbHostAppProgressMeter::meterProgress(). When the meter attains the specified number of calls, it will receive a call to OdDbHostAppProgressMeter::stop().

Canceling a Load or Save Operation

A client application can terminate a load or save operation by providing a custom implementation of OdDbHostAppServices and OdDbHostAppProgressMeter, and then throwing an exception from OdDbHostAppProgressMeter::meterProgress(). If a file load operation is canceled, the returned database smart pointer will be null.

Controlling Curve Emulation During R12 Writing

Drawings SDK API contains two functions, OdDbHostAppServices::setR12SaveDeviation and OdDbHostAppServices::setR12SaveAccuracy, which can be called by a client to control how ellipses and splines are converted to simpler entities, during a save to R12 and earlier versions. These functions are defined in SysVarDefs.h by REG_VAR_DEF macro calls. Specifically:

  • Curve "Accuracy" is the number of segments on one fourth of a full ellipse, or the number of segments between spline control points.
  • If the "Deviation" is zero (default), the Accuracy value is used (default Accuracy is 8).
  • If the Deviation is non-zero, then the Deviation value is used for curve tessellation. If the number of resulting points is less than the number required by the Accuracy value, then the curve is tessellated again to ensure that the final number of points is at least the number required by the Accuracy value.
Copyright © 2002 – 2022. Open Design Alliance. All rights reserved.