HOOPS Exchange is Tech Soft 3D's CAD data integration library and is the recommended way to get model data from a CAD file into Visualize. Through Exchange, you can access assembly information, visualization data, and PMI annotations for inspection or manipulation within the context of a Visualize scene graph. A detailed introduction to HOOPS Exchange can be found here.
Any file that can be loaded by the HOOPS Exchange libraries can be loaded into HOOPS Visualize. The interface described in this section is the way to connect Visualize with HOOPS Exchange, and is supported on Windows, Linux, and OS X.
The Exchange integration has a few limitations when using C#. Functions which expect C++ pointers cannot be called directly from C#. Instead, an intermediate step using CLI (Common Language Infrastructure) is required. The Visualize solution provides the cc_exchange_lib_vc11 project which demonstrates how the C++/CLI interface is set up, allowing the C# programmer to access specific Exchange functionality that is otherwise only available in C++.
The project can be found at Applications > Demo > cc_exchange_lib_vc11, and when compiled, generates the CLI interface in the form of a DLL. The DLL needs to be added as a reference to the C# project that invokes it. You will also find a sister project called Applications > Demo > cc_exchange_vc11. This project is a demonstration on how you would invoke the CLI to call from your C# application through to C++ using the interface generated by cc_exchange_lib_vc11.
Steps for integrating HOOPS Visualize with Exchange are delineated below:
Exchange can be downloaded from the Tech Soft 3D Developer Zone. If you don't already have Exchange installed, install it now. You do not have to generate a separate key to use the Exchange component. The key will be embedded with your Visualize license key. Note the Exchange installation directory.
The Exchange DLLs must be in the system path so that they can be located when your program is executing. For example, assuming your platform is 64-bit Windows, and the installation is at C:\Program Files\HOOPS_ExchangePublish, the path should be set as C:\Program Files\HOOPS_ExchangePublish\bin\win64;.
The Visualize-Exchange integration library must be included as a dependency. C++ users will need to link to hps_sprk_exchange.lib. C# users need to reference the hps_cs_sprk_exchange_vc11 assembly. Alternatively, you may specify the library directory by calling HPS::World::SetExchangeLibraryDirectory.
Your source files that use the Visualize-Exchange integration must include sprk_exchange.h.
This step is only necessary if you need to call the HOOPS Exchange API directly in order to access functionality not provided by the Visualize-Exchange integration. If this is your intention, you must make an explicit call to A3DSDKLoadLibrary. See Runtime initializations of the HOOPS Exchange Programming Guide. You should not call any other HOOPS Exchange initialization functions.
At this point, HOOPS Exchange is ready to use in your application.
The view hierarchy that was introduced in section 3.1 is utilized when loading Exchange models. Specifically, Visualize encapsualtes Exchange models HPS::Model objects as part of the loading process. It can also create a HPS::View using the Exchange model's camera (where supported by the file format). In any case, the end goal is to create a view hierarchy. There are multiple ways to do this, as demonstrated in the code snippet, below:
This snippet demonstrates the importance of calling Wait() on your notifier object. Because all notifier classes do their I/O in a separate thread, the potential exists to use the object before it is done loading, especially if you try to interact with it immediately after you call Import(). Calling Wait() ensures the I/O operation is complete before continuing. If you do not use Wait(), you could end up with unexpected behavior.
In addition to waiting, the HPS::Exchange::ImportNotifier also can provide you with useful information about the status of the import. You can even use the notifier to cancel the import, if needed. All of the possible return values for the status are listed in the HPS::IOResult reference manual page.
After the model is loaded using Exchange, it can be manipulated like any other Visualize model. The components of the model are translated from their native format into the Visualize entities as discussed in the data mapping section.
When loading a file, you can choose beforehand whether certain elements will be loaded. Default import options will be used for any import settings that are not set on the HPS::Stream::ImportOptionsKit passed to the HPS::Exchange::File::Import function. These defaults can be seen via HPS::ImportOptionsKit::GetDefault(). The options specified during import will determine how long the import takes, the amount of memory used, and the size of exported files. Additionally, if data is not loaded during import, it will not be available afterwards without reimporting the data. It is important to keep these things in mind when selecting the import options. For example, if you have a file that contains PMI data, but know you will not be needing it, you can disable PMI as an import option:
Additional options that can be controlled during import are B-rep data, solids, surfaces, and others.
Multiple CAD models may be imported into the same scene graph. To do this, set the destination of the model using HPS::Exchange::ImportOptionsKit::SetLocation or HPS::Exchange::ModelFileImportOptionsKit::SetLocation functions. These functions allow you to provide a HPS::ComponentPath with an optional HPS::MatrixKit. HPS::ComponentPath describes the path within the component hierarchy where the new data should be inserted, scaled by the provided matrix.
If a location is not set, HOOPS Visualize will simply create a new HPS::CADModel. If the location is set, Visualize will create new HPS::Components and add them to the existing component hierarchy.
Configurations are an important option that can be utilized for certain file formats. A configuration is a sub-model within a larger model - sometimes these files are also referred to as "multi-model" or "multi-entry" files. Only CATIAV4, SolidWorks, and IDEAS files support configurations. Some files can contain multiple configurations. If you do not specify a configuration to load, the default configuration will be loaded, if possible. Multi-model CATIA V4 files do not have a default configuration, so attempting to load such a file without specifying a configuration will cause the import to fail.
In code snippet 9.5.2.a, notice that ActivateDefaultCapture returns a HPS::View object. This is the same HPS::View discussed in section 3.1. Some model formats include a view of a particular state of the model, and ActivateDefaultCapture will load that view. The view may include a camera, toggle visibility for cutting planes, PMI, and geometry with the scene. Additionally, it may apply transformations to some geometry, for example, create an exploded view of an assembly.
Certain model formats allow multiple views to be pre-defined, and you may be interested in loading some view other than the default. The code below demonstrates how to do this.
Metadata is additional non-geometric information that is associated with an HPS::Exchange::Component. Each piece of metadata is a name-value pair, and the values can be strings, integers, unsigned integers, doubles, Booleans, or times. Any HPS::Exchange::Component can have metadata associated with it. During the import process, metadata is generally only imported if the HPS::Exchange::ImportOptionsKit::SetAttributes is set to true. However, some metadata, such as faces, certain IDs, layers, and materials, are always imported even if HPS::ImportOptionsKit::SetAttributes is set to false. A list of that metadata is as follows:
Metadata name | Type | Description |
---|---|---|
"Name" | String | Name of this component. |
"PersistentID" | non-zero unsigned int | |
"NonPersistentID" | non-zero unsigned int | |
"Layer" | unsigned int | Layer number where this component is located. |
"Filename" | String | File name of this model. |
"FileFormat" | String | File format for this model. |
"IsAnnotationCapture" | Boolean | Only available for components of type capture. Value is true if the capture is an annotation capture, false otherwise. |
"Units" | String | The units of the model. Only available from the HPS::Exchange::CADModel. |
"IsDefaultSheet" | Boolean | Whether the sheet is the default sheet for a drawing. Only available for components of type HPS::Component::ComponentType::ExchangeDrawingSheet. |
Metadata can be embedded with a HPS::Exchange::Component in many different forms. The following example demonstrates how to get metadata associated with a HPS::Exchange::Component:
Filters are found in some CAD files and provide the capability to show or hide certain pieces of geometry or objects that lie in certain layers. Filters can be toggled once a CAD file has been imported via the Visualize-Exchange API. Filters may also be toggled when captures are activated. Note that a filter can be attached to any component of the model. You may use HPS::CADModel::GetAllFilters to get a list of all HPS::Filter objects in the HPS::CADModel. The following code example shows how to activate a filter on a view:
More than one filter may be active at a particular time. To activate or deactivate a filter, you first need to get a reference to it. You can get a list of all the active filters on a HPS::View by using this logic:
All file formats that Exchange can export are supported via the Visualize-Exchange API (ExportACIS, ExportIGES, ExportJT, ExportParasolid, ExportPRC, ExportSTEP, ExportSTL, ExportU3D, and ExportVRML). All export formats have their own Export*OptionsKit (except for VRML which has no options).
Writing a file through Exchange is an operation similar to reading:
Exchange can import many more file types than it can export. A list of supported file formats is located here (authentication required).
HOOPS Visualize does not use B-rep (boundary representation) calculations when rendering. All models are tessellated. However, models will be exported with B-rep if the original Exchange model was loaded with B-rep. If your application adds Visualize scene graph data to the scene, and you have a need to export that data along with the Exchange data, the export process is more complex.
Exporting Visualize data with Exchange data is possible using the ExportPRC function. As the name implies, PRC is the only format in which this operation is permitted. The general sequence is explained below:
There exist overloads of the ExportPRC function which do not accept a HPS::CADModel. These overloads will export everything which is pointed to by the key paths you pass to them, but in those cases you will only get tessellation - B-rep is not included.
If you need to export Exchange and Visualize data to a non-PRC file format, we recommend you first export to PRC, then use Exchange to translate the file to the format of your choice.
During the import process, Exchange will trigger events when it detects a problem or has information to give you. For example, if Exchange couldn't find a referenced subcomponent in an assembly, or if there was some sort of import failure, a warning or error could be triggered. It is the responsibility of your application to catch these events and respond appropriately.
The Visualize-Exchange integration will capture all events and wrap them into one of three types: HPS::InformationEvent, HPS::ErrorEvent, or HPS::WarningEvent. Each of these types derive from HPS::Event, thus, handling them is identical to handling any other type of Visualize event (event handling is discussed here).
WarningEvent and InformationEvent contain both a code and a message field that help to determine what caused the event.
It is important for developers to be able to map objects within their Visualize database to the corresponding entities as loaded by HOOPS Exchange. Exchange first maps all incoming CAD data to the industry standard 'PRC' format, which in turn is then mapped to the Visualize scene graph. Visualize interfaces to each Exchange entity through an HPS::Exchange::Component object. Using a HPS::Exchange::Component, you can query the underlying PRC data for model information. Exchange objects are called entities and Visualize objects are components. Here is an example of some basic Exchange interactions:
At the end of code snippet 9.5.6.a, Exchange is integrated, and you can use then use the entity references to manipulate model data using the Exchange API.
Commonly, it is necessary to determine whether a component contains a certain type of entity. If you are only looking for a specific type, you can use HPS::Component::GetComponentType to test against the returned type. But some generalized entities can take many forms. For example, PMI can exist as plain text, rich text, or GD&T, among other things. Rather than checking against all types of PMI, you can use a PMI mask with the HasComponentType function. This operation will tell you whether the component contains any type of PMI.
Type masks also exist for topology and representation items. A usage example is as follows:
When you make changes to a Visualize scene graph which represents a HOOPS Exchange model, those changes affect the Visualize scene graph only. Likewise, if you modify a model's PRC data using the HOOPS Exchange API, the corresponding Visualize scene graph is unchanged. To ensure the PRC data and the Visualize scene graph are synchronized, further action is necessary.
If your changes are relatively simple, such as a deleting a PRC entity, you can call HPS::Component::Delete on the corresponding HPS::Component to update the Visualize scene graph. However, if you have a need to make more substantive changes, first make the modification using the Exchange API. Next, call HPS::Component::Reload to bring the scene graph and component hierarchy up to date. The reload should be invoked at or above the level where the changes were made, thus ensuring Visualize doesn’t try to access potentially deleted PRC entities. You can also use a notifier to determine when the reload is complete:
HOOPS Visualize takes care of all of the import logic for supported file formats, including HOOPS Exchange. In doing so, it creates an in-memory model structure which consists of the HPS::Component objects mentioned in the previous section. If you have a need to write your own importer, you will need a way to create these components as you parse the input file. HOOPS Visualize allows you to do this using its component creation API functions.
The first step in this process is to create the root component, which is the HPS::Exchange::CADModel. This is the only object in the Exchange structure that has no owner. From this point, you can build the model structure as you parse it, using the HPS::Exchange::Factory static class to create each component.
Additionally, see the reference manual entries for HPS::Component::AddKey, HPS::Component::AddOwner, and HPS::Component::AddReference, which aid with component creation in certain situations. For example, to associate a geometry key will a component, use AddKey.
As Exchange itself is only implemented for Windows and Linux, the Visualize-Exchange integration is not applicable to other operating systems.
It is also important to note that the Visualize-Exchange integration ignores B-rep data and asks HOOPS Exchange to provide all data in tessellated form.
A further discourse on the inner workings of Exchange is beyond the scope of this manual, however, the main source for Exchange documentation can be viewed here (authentication required).