Close

Relief for ODA Team in Ukraine

Learn more
ODA PRC SDK
ODA PRC SDK Sample Applications Reusable Files

Summary

ODA Product: ODA PRC SDK
Sample Name: Common
Categories: C++ / Beginner, Advanced / Working with .prc files / Android, iOS, macOS, Linux, Windows
Source Code Location: Prc/Examples/Common

Description

Common files used by ODA PRC SDK sample applications include:

These files contain custom service class definitions and functions for custom assertions, local time freezing, and console printing.

The custom service class combines platform-dependent functionality of the OdRxSystemServices and OdPrcHostAppServices classes and allows custom applications based on ODA PRC SDK to interact with core ODA Platform functionality.

The functionality implemented in PrcExamplesCommon.h and PrcWithTDExamplesCommon.h is described below.

PrcExamplesCommon.h

The PrcExamplesCommon.h file contains definitions and declarations for the following elements:

  • getLocalTime() function — Freezes local time when working with a drawing database. There is a global variable g_pLocalTimeFunc in ODA Platform, which contains a pointer to a function returning the current local time. The default ODA Platform local time function can be replaced with a custom function by assigning a new value to this variable:

extern FIRSTDLL_EXPORT_STATIC PgetLocalTime g_pLocalTimeFunc;

static void getLocalTime(OdTimeStamp &localTime)
{
  localTime.setDate(12, 22, 2009);
  localTime.setTime(18, 0, 0, 0);
}
        
Then in a custom application, set a new value for the g_pLocalTimeFunc variable:

g_pLocalTimeFunc = getLocalTime;
          
The function accepts a reference to an OdTimeStamp object to return a custom date and time value.
  • odPrintConsoleString() function — Implements cross-platform console output. This is similar to a printf() function: it accepts one mandatory parameter with a formatting string (fmt) and can accept one or several values to be inserted into a formatting string instead of placeholders.
  • MyAssert() function — Implements a reaction for an assertion event. This custom function provides a way to avoid an application crash when an assertion fires. The MyAssert function accepts three parameters:
    • expression — Contains an assert expression.
    • fileName — Passes the source file name where an assertion has been fired.
    • nLineNo — Contains a line number.
  • MyServices class — Implements a combination of platform-dependent functionality from the OdRxSystemServices and OdDbBaseHostAppServices classes. Inheritance from OdDbBaseHostAppServices is implemented through inheritance from two intermediate classes:
    • OdExPrcHostAppServices — Its declaration and definition can be found in the /Prc/Extensions/ExServices/ExPrcHostAppServices.h file.
    • OdPrcHostAppServices — Its declaration and definition can be found in the /Prc/Include/AppServices/PrcHostAppServices.h file.
Most of the methods in the MyService class contain only a default implementation and therefore are available for custom implementation in derived classes.

PrcWithTDExamplesCommon.h

The PrcWithTDExamplesCommon.h file contains definitions and declarations that are useful for creating custom applications based on both ODA Platform and ODA PRC SDK products.

  • MyServicesBase template class — Encapsulates default objects of the following classes:
    • OdExPrcHostAppServicesclass — Implements platform-dependent and progress metering operations for .prc contents: getting a bitmap device for rendering, creating a drawing database related to a .prc file, file searching, font handling operations, etc. OdExPrcHostAppServicesclass is derived from OdPrcHostAppServices, which is derived from OdDbBaseHostAppServices. Declaration and definition is located in the /Prc/Extensions/ExServices/ExPrcHostAppServices.h file.
    • ExHostAppServices class — Contains platform-dependent operations and progress metering to enhance ODA Platform functionality for custom applications. Class declaration and definition are located in the /Core/Extensions/ExServicesExHostAppServices.h file.
    • ExSystemServices class — Includes the default implementation for ODA Platform platform-dependent services available for custom applications:
      • Creating files
      • Opening files
      • Getting file attributes (creation time, modification time, size)
      Declaration and default implementation of the ExSystemServices class methods are located in the /Core/Extensions/ExServices/ExSystemServices.h file.
The MyServicesBase class combines platform dependent, progress metering and system operation functionality for ODA Platform and ODA PRC SDK by providing the ability to create a derived class with custom implementation.
  • MyServices class — Inherits the MyServiceBase class with default template classes (OdExPrcHostAppServices, ExHostAppServices, ExSystemServices).
  • MyAssert() function — Implements a custom reaction for an assertion event. See detailed description above.

Typical Console Sample Application Structure

All ODA PRC SDK console sample applications have a similar structure, and in most cases differ only with the source code used to implement specific functionality.

First, sample application source code is allocated in one .cpp file. This file contains a platform-dependent definition of the main() function. The name of the .cpp file usually matches the sample application name. For example, OdPrcToXml.cpp is the main file of the OdPrcToXml sample application. The main() function contains a set of actions that are run before and after a code fragment that illustrates a feature. Below is the common structure of a ODA PRC SDK console sample application:

  1. Override the global function that returns the current local time with an internal implementation.
  2. Set a customized assert function (call the global odSetAssertFunc() function with a pointer to a custom assert function).
  3. Create an instance of the MyServices class for implementing ODA Software platform-dependent functionality.
  4. Parse input arguments passed from the operating system.
  5. Initialize ODA Platform functionality (call the odrxInitialize() global function).
  6. Run the code that illustrates the functionality or feature.
  7. Uninitialize ODA Platform functionality (call the odrxUninitialize() global function).
  8. Return the result of the dumping operation.

See Also:

ODA PRC SDK Sample Applications

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