2.1 Simple load and export
HOOPS Exchange can be used within your application in two different ways - as a direct or indirect integration.
A direct integration means you are accessing the assembly tree structure, parsing entities, and using that information to inspect the model data or otherwise provide a feature-rich experience to the end user. For information on how you would do this, see section 4, Reading model geometry.
An indirect integration means you are simply reading a model file and using HOOPS Exchange to write it in a different format without reading the assembly tree.
Start HOOPS Exchange by initializing the libraries and setting the license key. That process is described in the initialization section.
Once HOOPS Exchange is initialized, you can use it to load a CAD model into memory. CAD files can be imported with a minimal amount of code:
If you're doing an indirect integration, you're done. You can export the file as another format by using the code in the next subsection.
For direct integrations, you'll need access to the model file pointer. This pointer gives you a reference to the root of the assembly tree:
Loading a CAD file with custom options
Many file formats contain extraneous data that is not necessary for all situations. Therefore, before loading the file, you should set the file import parameters to load only the specific data required by your application. Doing so decreases the memory footprint, CPU load, and load time. These parameters are set using the A3DRWParamsLoadData structure:
The end result of successful file load is a model file pointer. This structure represents the root entity for a model file. Through it, you can access the assembly tree. There is only one model file per model.
Once in memory, the model is represented by a PRC assembly tree that is equivalent to its native structure. Note that pModelFile points to a model file node. Nodes always have data associated with them, but this data is not populated by default. The following code sample fills the node's data structure so that you can access the information within:
At this point, the model file is loaded into memory and you can use the modelFileData structure to access the assembly tree. As noted above, this is the route you would take to perform a direct integration. For information on how you would do this, see section 7, Reading model geometry.
A PRC assembly tree can contain any number of nodes, and in many cases, they will be nested several levels deep. In order to gather all the information from the PRC, your traversal algorithm must visit every node. Typically, this is done through recursion.
With incremental load, it's possible to load specific parts into memory without loading extraneous parts. More precisely, Exchange will load the full assembly structure but only the geometry and tessellation of the specified parts, thereby reducing the overhead of the application and boosting relative performance. This is especially useful for large CAD models.
Incremental load is only available for certain file formats, including SolidWorks, NX (Unigraphics), Creo (Pro/E), and CATIA V5. Incremental load support is specified on the information pages for most formats, linked from this table. A full code example of incremental load is available in the downloadable package, and a working demo of incremental mode can be evaluated by opening a supported CAD model in the HOOPS Demo Viewer or the Parasolid Demo Viewer. Instructions for loading a model in the HDV in incremental mode are available in the HDV docs.
The following code example demonstrates a simple example of an incremental load of a single part:
In this example, pMyProductOccurrence is a pointer to a leaf node containing geometry and/or tessellation. The variable pRoot is the Product Occurrence containing the leaf node pMyProductOccurrence.
After these variables are initialized, the options for the incremental load are set via the m_sLoadData member, which is an object of type A3DRWParamsIncrementalLoadData. Although we're only loading one leaf node in our example above, it is also possible to load more than one leaf node at a single time.
Once a part has been loaded, it can subsequently be unloaded with a call to the function A3DAsmModelFileUnloadParts().
Please note, CAD views are not supported in incremental mode.
Loading a PDF model
A PDF file can potentially contain multiple 3D data streams. Therefore, simply using A3DAsmModelFileLoadFromFile or A3DAsmModelFileGet will not work because those functions can only handle a single data stream. To load a PDF, you need to use A3DGet3DPDFStreams.
PDF data can be either in PRC or U3D format. If the data is PRC, you can load it from memory. If U3D, you must write the data to a temporary file before reading it using A3DPDF3DStreamCreateFromFile.
Exporting your model is similar to importing - simply reverse the procedure. You need only three things: the model file pointer, the export parameters structure, and the target filename. The supported export formats can be found here.
Indirect integration with the HOOPSExchangeLoader
Exporting a file with the HOOPSExchangeLoader is the preferred method when you are doing an indirect integration. Simply specify the filename of the import file and the export file. The export file type is determined by the file extension, so you should use a known file extension for the file format.
Export options vary widely between file types. However, all export data structures have the following name:
...where * is substituted with the file type. Suppose you are exporting a STEP file. Configure a A3DRWParamsExportStepData data structure to suit your needs. Then, to export your model, you would do something like this: