Home > User Guide > Bookkeeping in ACIS Assembly Modeling
Handles in Assembly Modeling
Handle objects are proxies in the assembly domain which allow assembly mode code to refer to objects for which a pointer to the object is not a "good" identifier in assembly mode. (Refer to the sections Assembly Modeling vs Part Modeling and Assembly Modeling Tutorial for a discussion of assembly mode.) Handle objects are always owned by an asm_model object, and are only exposed to client code as pointers. (Refer to the section Use Counting and Holding Objects in Assembly Modeling for a discussion of handle ownership.) The ACIS Assembly Modeling interface uses handle object pointers in the same way that ACIS Part Modeling uses ENTITY pointers; interface functions take handle pointers or handle lists as parameters, with the handle list classes supporting the same operations as ENTITY_LIST. (Refer to the section List Objects in Assembly Modeling for a discussion of handle lists.)
Topics include:
- Handle Types
- Need for Handles
- Entity Handle as a Fundamental Type
- Handle Data
- Handle Holding
- Component Entity Handle as the Assembly Modeling Analogue of ENTITY
- Handle Validity
Handle Types
The types of handle objects in ACIS Assembly Modeling include:
- entity_handle: a proxy for an ENTITY within a model.
- component_handle: a proxy for a component of an assembly.
- component_entity_handle: a proxy for a component entity within an assembly. (Refer to the sections Basic Concepts in Assembly Modeling and Assembly Modeling Tutorial for a discussion components and component entities.)
Need for Handles
For each of these handle object types, using a pointer to the underlying object as an identifier would be unsafe. In each case, this is related to the requirement that asm_model objects can be bound to different history streams; that is, the contents of models can roll independently. (Refer to the section History and Roll in Assembly Modeling.) In essence, the underlying objects can become invalid due to history operations. In the case of entity handles, if the underlying ENTITY is lost or destructed, then any pointers to that ENTITY become invalid without any notification being given to the object holding the pointer. A pointer to the ENTITY’s entity_handle object, however, remains valid because the entity_handle does not participate in history. The entity handle can be queried for a pointer to its underlying ENTITY; if the ENTITY has been lost or destructed, then the query will return a NULL value. If a lost entity is revived by rolling its history stream, then querying its entity handle for its ENTITY's pointer value will again return a non-NULL value.
The impact of independent history streams on components and component entities is more subtle because they are not ENTITYs. Instead, they correspond to a sequence of model references (in the case of components) or a sequence of model references terminated by an entity (in the case of component entities). Because these model references live in different models, the validity of a particular component (or component entity) can be affected by deletions or roll operations in any of those models. This, in turn, means that an identifier is needed for each component or component entity which is unaffected by the state of its underlying entities.
Note: Although this section discusses "component" and "component_entity" as abstract concepts class types representing these concepts are not a part of ACIS. All of the services that such class types would provide are instead provided by the corresponding handle types and the ASMI interface routines which act upon them. If such class types are introduced in a future version of ACIS, however, they will not be derived from ENTITY.
Entity Handle as a Fundamental Type
Note that, to a large extent, entity_handle is the fundamental data object in assembly modeling (in the same way that ENTITY is the fundamental data type in part modeling). The other two handle types can be thought of as referring to aggregations of entity handles:
- A component is specified by a root model (asm_model) pointer and a list of entity handle to ASM_MODEL_REF handles which represent the path through the assembly's model-ref tree.
- A component entity is represented by a pointer to a component handle (specifying the component) and an entity handle (specifying the entity).
Handle Data
Each of the three handle types has underlying data associated with it, which can be queried by client code:
- An entity handle has a pointer to its associated entity
- A component handle has a list of entity handles bound to the ASM_MODEL_REF entities representing the component. Note that, by construction, each of these ASM_MODEL_REF entities lives in a different model, and so might be associated with a different history stream. Also note that this list may be empty, which indicates that the component represents the root component of the component handle's owning model.
- A component entity has a component handle for its component and an entity handle that is bound to its ENTITY
In addition, all handles are owned/managed by an asm_model object, and can be queried for their owning model with a get_owning_model() method:
- entity_handle objects are owned by the model which contains the underlying entity.
- component objects are owned by the component's root model; for example, the left-front wheel component of a car assembly would be owned by the car assembly's model; the left wheel component of an axle assembly would be owned by the axle assembly's model.
- component entity objects are owned by the model which owns their component. Note that this will usually be a different model than the owner of the component entity's entity_handle. The owner of the component entity’s entity_handle must be the end model of the compenent entity’s component; only for a zero length model-ref path will this be the same as the owning model of the component.
Component Entity Handle as the Assembly Modeling Analogue of ENTITY
In ACIS Part Modeling, the unique identifier for elements of the model is ENTITY*. In ACIS Assembly Modeling, ENTITY* is not the case. For example, the pointer to a FACE within a wheel part is not a unique identifier in a car assembly because the face appears four times within the assembly. The unique identifier in ACIS Assembly Modeling is component_entity_handle*; each of the four appearances of the wheel’s face corresponds to a unique component entity handle.
Handle Validity
Because handles are designed to manage interaction with objects which might be invalid (either temporarily or permanently), additional care must be taken by client code which uses handles. A handle object is invalid whenever either it or one of the handle objects it contains returns NULL when queried for its associated ENTITY pointer:
- entity_handle objects are invalid if they return NULL when queried for their underlying ENTITY pointer
- component_handle objects are invalid if any of their entity_handles are invalid
- component_ entity_handle objects are invalid if either of their component_handle or entity_handle objects are invalid
Client code must written to be robust against invalid handles; that is, a handle's validity should be explicitly checked before it is used. Generally speaking, invalid handles should simply be ignored when iterating through a list of handles in order to perform some operation(s) on each handle. Note that an invalid handle can become valid again if the operation which made the handle invalid is rolled away. Each of the handle types has an is_valid() method which will indicate if the handle being queried is currently valid.
Handle Holding
It is extremely important that any handle object which will be used by client code outside the scope of the routine (or after an explicit call to cleanup) where it is obtained be "held" (have its use-count incremented by placing it in a holding object or list). Refer to Use Counting and Holding Objects in Assembly Modeling for a discussion of handle ownership.
Related topics:
Use Counting and Holding Objects in Assembly Modeling
List Objects in Assembly Modeling[Top]
© 1989-2007 Spatial Corp., a Dassault Systèmes company. All rights reserved.