Prototype Aware Getters

If you’re familiar with HOOPS Exchange, you’ve likely encountered the prototype concept. Using the prototype correctly is simpler than many developers realize, but it still represents a bit of a hurdle. Because of this, we’re proposing an improvement to the Exchange API to make the use of prototypes easier. We want to share the proposed change with you and ask that you share any thoughts or feedback with us.

Once you’ve loaded a file using HOOPS Exchange, the result is provided as an A3DAsmModelFile object. This is the top-level object that provides access all the loaded data. Usually, the data you care about is embedded somewhere within the product structure (assembly structure) of the loaded data.

The assembly structure is obtained from an A3DAsmModelFile object by recursively traversing the A3DAsmProductOccurrence objects it contains, ignoring prototypes. The objects inside the grey box in Figure 1 illustrate this. The challenge of using prototypes enters the equation when you must examine the properties of each node in this assembly structure.


(Figure 1. Assembly structure with Prototypes)

Each node in the assembly structure may be an instance of some shared definition. Applying this concept, a designer can create a part or assembly once and add many instances of the shared definition in the assembly hierarchy. In this scenario, the m_pPrototype pointer in the assembly nodes for each instance will be a non-null pointer referencing the shared definition. The pink box titled “Prototypes (shared)” in Figure 1 shows these shared parts and assemblies.

An instance of a shared definition often will override some of the shared definition’s properties. While some properties may be overridden, others may not be. The effective properties of an assembly node instance ( A3DAsmProductOccurrence ) are correctly determined by taking the shared definition’s properties into account when they’re not overridden by the instance.

As a concrete example, we’ll consider the location. While traversing the product structure, you may want to know the local transformation of each node. To determine this, you must examine the property A3DAsmProductOccurrence::m_pLocation . This pointer may be null, but that is not the complete story. When you encounter a null pointer in the A3DAsmProductOccurrence , you must recursively search the prototypes until you encounter an m_pLocation pointer that is set. Once you’ve done this, you are correctly determining the location while taking prototypes into account.

This is just one of many properties where you must take prototypes into account to determine the instance’s overall state. As a result, developers have been required to write prototype-aware recursive functions to retrieve assembly node properties, even for properties as simple as the node name.

To make life a bit simpler for our partners, we are proposing the addition a new API to HOOPS Exchange. The new API would contain the recursion needed to extract the effective set of properties for an assembly node. All the properties will be returned in a single struct.

struct A3DAsmProductOccurrenceWithPrototypeData {
    A3DRootBaseData m_sRootBaseData;
    A3DRootBaseWithGraphicsData m_sRootBaseWithGraphicsData;
    A3DAsmProductOccurrenceData m_sProductOccurrenceData;
};

A3DAsmProductOccurrenceGetWithPrototype( A3DAsmProductOccurrence *po, A3DAsmProductOccurrenceWithPrototypeData *d );`

Using this new function, our partners will no longer have to write the code to traverse prototype pointers to extract the properties they care about. Of course, we won’t be removing any data or functionality, so your existing codebase will be unaffected by this change. However, for any new code, if you don’t care about the details of how an assembly node is defined, using this function will save time and effort.

2 Likes

Interesting! Thanks for sharing @brad