Close

Relief for ODA Team in Ukraine

Learn more
ODA PRC SDK
Sample Application that Illustrate Read and Dump of a .prc File

Summary

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

Description

Console application that reads a specified .prc file and dumps its content to a console window. Output can be redirected to a file.

Run Sample Application

To run the OdPrcReadEx sample application, please do the following:

  1. Open the terminal window and go to the directory where the sample binary file is allocated:
    • For Windows® platforms: <PRC_DIR>\exe\<version>
    • For Non-Windows platforms: <PRC_DIR>/bin/<version>

    <PRC_DIR> is a directory where you unpacked the PRC SDK archive.

    To determine your <version> parameter, please see the appropriate section in the Download ODA PRC SDK topic.

  2. Run the sample with appropriate arguments:
    
                OdPrcReadEx <filename>
              
    filename Full path to the input .prc file to be dumped.

If the application executed properly, you will see the following console window:

If an error occurs during the application execution, you will see an appropriate error message in the console window. For example, the following picture illustrates the program output in the case when it was called with wrong arguments:

Sample Application Structure

The entry point (the main() function) is located in the OdPrcReadEx.cpp file, which contains:

The main() function also contains common sections before and after the source code section that illustrate how to dump a .prc file's content to the console window. The main() function does the following:

  1. Loads the OdPrcModule. This module contains the implementation for working with .prc data functionality.
  2. Loads the OdPrcDumpModule. This module contains the implementation for dumping a .prc file's content.
  3. Reads the contents of the .prc file specified in the application arguments.
  4. Dumps the contents of the specified .prc file by calling the dump() function.
  5. Implements exception handling for the operations listed above.

Below is the functions call and class instances schema:

main()
|
|-->dump()
    |
    |-->addChilds()
         |
         |-->OdPrcListenerImpl class instance
         |
         |-->getObjectId()

OdPrcListenerImpl Class

Module: OdPrcReadEx.cpp

The OdPrcListenerImpl class implements dumping values of different data types to the console window using the odPrintConsoleString() function.

Class methods:

  • A set of dumping methods that print values of different types to the console window. Each method accepts two parameters:
    • pName — Name of the attribute.
    • value — Attribute's value. When dumping a string attribute (AnsiString, String or CharArray), the parameter name is str. When dumping bit data, the parameter name is data.
    The dumping methods print a pair of attribute names and values to the console window:
    • dumpInt8()
    • dumpInt32()
    • dumpUInt8()
    • dumpUInt16()
    • dumpUInt32()
    • dumpUInt32Hex()
    • dumpUniqueId()
    • dumpObjectId()
    • dumpUncompressedBlock()
    • dumpBoolean()
    • dumpDouble()
    • dumpFloat()
    • dumpBits()
    • dumpAnsiString()
    • dumpString()
    • dumpCharArray()
  • The childs() method returns a set of IDs for the PRC entities that are children of the current object.

dump() function

Module: OdPrcReadEx.cpp

Calls the addChilds() function with a pointer to an OdPrcFile object as a root of the .prc object hierarchy.

Input parameters:

  • pFile — Pointer to an OdPrcFile object containing .prc file contents.

addChilds() function

Module: OdPrcReadEx.cpp

Dumps information about a specified object and its children. Currently only the names of objects are dumped.

Input parameters:

  • pObj — Pointer to a parent object evaluated for the OdRxObject object.
  • childLevelCounter — Level of hierarchy in the .prc file contents to be dumped.

Common dumping process does the following:

  1. Creates an instance of the OdPrcListenerImpl class.
  2. Casts the specified pointer of a dumped object to an OdPrcEntity_Dumper pointer.
  3. Prints the parent object name (if cast operation is successful).
  4. Calls the dump() method of the OdPrcEntity_Dumper object.
    Note: The current implementation of this method does nothing.
  5. Gets the parent object identifier (by calling the getObjectId() function).
  6. Gets the IDs of the current object's children (OdPrcListenerImple has the childs() method for this purpose).
  7. Opens each child for reading (if it has an ID and its ID is not equal to the parent object's ID) and dumps it through a recursive call of the addChilds() function.
    If the child entity has no ID, children entities are searched through by calling the hasSubElements() method. The names of entities without IDs are not printed in the console window.

getObjectId() function

Module: OdPrcReadEx.cpp

Returns the ID of the specified object. Used for getting identifiers of dumped objects.

Input parameter:

  • pObj — Pointer to an object evaluated for the OdRxObject object.

The ID is returned if the specified object can be cast to an instance of the OdPrcReferencedBase, OdPrcBody, or OdPrcFileStructure class. If the object cannot be cast to an instance of one of these classes, an empty ID is returned.

See Also:

ODA PRC SDK Sample Applications

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