Close

Relief for ODA Team in Ukraine

Learn more
ODA PRC SDK
Sample of Export a .dgn File to a .pdf File with PRC Support

Summary

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

Description

Sample console application that illustrates .dgn to .pdf export functionality with enabled PRC format support.

The example creates a simple .dgn file and exports its content to a specified .pdf file as a PRC mesh.

Run Sample Application

To run the OdDgn2PdfExportWithPrc 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 parameters:
    
                OdDgn2PdfExportWithPrc <export case> <target file>
              
    export case Name of an export case to execute. The export case determines the export parameters and options.

    Currently only one export case is available:

    • Dgn2PdfCreateAndExport — Creates a .dgn file with four 3D entities and exports it to a .pdf file. Four PRC views are added (one for each entity) to the .pdf file's page. Entities are exported as meshes.
    target file Full path to the output .pdf file that will contain all exported content.

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:

The sample application creates a new PDF file with specified name that can be open with any available PDF viewer with support of PRC format.

Sample Application Structure

The entry point (the main() function) is located in the OdDgn2PdfExportWithPrc.cpp file. This file also contains a declaration of the MyServicesForTestDGN class, which implements a combination of the platform-dependent functionality (platform-dependent operations and progress metering) for .dgn and .prc files.

The main() function checks input arguments, creates a custom services instance (a MyServiceForTestDGN object) and then calls the OdDgn2PdfExportWithPrcStart() function.

Below is the functions call schema:

main()
|
|->OdDgn2PdfExportWithPrcStart()
    |
    |-->OdDgn2PdfSimpleExample(OdDgHostAppServices&, OdString)
        |
        |-->OdDgn2PdfSimpleExample(OdDgHostAppServices, OdString, PDFExportParams, bool, void (*fillerfunc)(OdDgDatabasePtr&))
            |
            |-->fillDatabase()
            |    |
            |    |-->addSphere()
            |    |
            |    |-->addBox()
            |    |
            |    |-->addCylinder()
            |    |
            |    |-->addSmartSolid()
            |
            |-->fillLayoutList()

OdDgn2PdfExportWithPrcStart() function

Input parameters:
  • OdDgHostAppServices& svcs — Reference to a custom services instance.
  • OdString pdfPath — Full path to the exported .pdf file.
  • ExportMode emode — Export mode, which corresponds to the export case input argument.

This function runs the OdDgn2PdfSimpleExample(OdDgHostAppServices&, OdString) function.

OdDgn2PdfSimpleExample functions

The sample application contains two overrides of the OdDgn2PdfSimpleExample functions:
  • OdDgn2PdfSimpleExample(OdDgHostAppServices&, OdString) — Calls the second OdDgn2PdfSimpleExample function with specified default values for mismatched parameters. Input parameters:
    • OdDgHostAppServices& svcs — Reference to a custom services instance.
    • OdString pdfPath — Full path to the exported .pdf file.
  • OdDgn2PdfSimpleExample(OdDbHostAppServices, OdString, PDFExportParams::PRCSupport, bool, void (*fillerfunc)(OdDgDatabasePtr&)) — Input parameters:
    • OdDgHostAppServices& svcs — Reference to a custom services instance.
    • OdString pdfPath — Full path to the exported .pdf file.
    • PDFExportParams::PRCSupport flags — Flag that determines what kind of PRC support should be used during the export process.
    • bool shouldUseSingleViewMode — Flag that shows whether the export should use only single view mode.
    • void (*fillerfunc)(OdDgDatabasePtr &pDb) — Pointer to a function that fills the DGN database with entities.
This function does the following:
    1. Creates a PDF export module.
    2. Creates and fills a database with entities (fillDatabase() function).
    3. Sets export parameters.
    4. Runs the export method of the exporter object.
    5. Checks the result returned by the export method.

fillDatabase() function

Gets the active DGN model and creates several entities for it.

Input parameter:

  • OdDgDatabasePtr& pDb — Reference to the DGN database where the entities should be created.

This function does the following:

  1. Creates a red solid sphere (calls the addSphere() function).
  2. Creates a green mesh box (calls the addBox() function).
  3. Creates a blue cone cylinder (calls the addCylinder() function).
  4. Creates a yellow smart solid (calls the addSmartSolid() function).
  5. Transforms the created 3D objects.
  6. Zooms the drawing to extents.

fillLayoutList() function

Extracts layouts from the specified DGN database and fills the specified string array with their names.

Input parameters:

  • OdArray <OdString>& layouts — Reference to a string array where the layout names should be stored.
  • OdDgDatabasePtr& pDb — Reference to a DGN database from which the layout names should be extracted.

addSphere() function

Adds a solid sphere to the DGN database.

Input parameters:

  • const OdGePoint3d& ptCenter — Center point of the sphere.
  • double dSize — Sphere's diameter value.
  • OdUInt32 uColorIndex — Index of the sphere's color.
  • OdDgModelPtr& pModel — Reference to a DGN model to which the sphere should be added.

addBox() function

Adds a solid sphere to the DGN database.

Input parameters:

  • const OdGePoint3d& ptCenter — Center point of the box.
  • double dSize — Size of box sides.
  • OdUInt32 uColorIndex — Index of the box color.
  • OdDgModelPtr& pModel — Reference to a DGN model to which the box should be added.

addCylinder() function

Adds a solid cylinder to the DGN database.

Input parameters:

  • const OdGePoint3d& ptCenter — Center point of the cylinder.
  • double dSize — Cylinder's diameter.
  • OdUInt32 uColorIndex — Iindex of the cylinder's color.
  • OdDgModelPtr& pModel — Reference to a DGN model to which the cylinder should be added.

addSmartSolid() function

Adds a smart solid object to the DGN database.

Input parameters:

  • const OdGePoint3d& ptCenter — Origin of the smart solid.
  • double dSize: — Value that determines the scale factor.
  • OdUInt32 uColorIndex — Index of the solid's color.
  • OdDgModelPtr& pModel — Reference to a DGN model to which the smart solid should be added.

See Also:

Export a Drawing to a .prc File

ODA PRC SDK Sample Applications

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