Interface GeometricInstanceConverterInterface

The GeometricInstanceConverterInterface interface is used to get, from a list of geometric instance ids, the corresponding part instance ids.

Such a conversion is dependant on a WorkingSetInterface. Indeed, the list of current part instances is dependant on the chosen configuration (at least) and may be dependant on the list of visible part instances for example. For this reason, converting geometric instance ids (from a picking request for example) needs a WorkingSetInterface (see WorkingSetInterface).

This conversion is particularly useful to make id-card requests, since metadata documents are retrieved from part instances and not geometric instances.

The GeometricInstanceConverterInterface interfaces are created through the DataSessionInterface.createGeometricInstanceConverter method.

The list of signals the GeometricInstanceConverterInterface may trigger is available in the GeometricInstanceConverterInterfaceSignal enumeration.

The conversion mechanism is triggered through the convert method. The result is not available right away, but the event GeometricInstanceConverterInterfaceSignal.GeometricInstanceConverterReady is triggered when the result of the GeometricInstanceConverterInterfaceSignal is available. The result is available through the getPartInstanceIds function.

Warning : there may be cases when the getPartInstanceIds is not available such as when the GeometricInstanceConverterInterface is fetching data, i.e. when isRunning returns true, or when the GeometricInstanceConverterInterface has been cancelled, i.e. when isCancelled returns true.

A GeometricInstanceConverterInterface may be interrupted (cancelled) when the GeometricInstanceConverterInterface is fetching data and cancel is called. In such cases, the GeometricInstanceConverterInterfaceSignal.GeometricInstanceConverterCancelled signal is fired, and shortly after, GeometricInstanceConverterInterfaceSignal.GeometricInstanceConverterReady signal is fired, but getPartInstanceIds will return undefined. Just call convert with another (or the same) geometric instance ids to trigger a new retrieval.

If you call multiple times convert before receiving the GeometricInstanceConverterInterfaceSignal.GeometricInstanceConverterReady, only one GeometricInstanceConverterInterfaceSignal.GeometricInstanceConverterReady will be sent with the content of the last call to convert.

This interface performs the opposite operation of the PartInstanceConverterInterface interface.

/** 
* Sample to illustrate the use of a GeometricInstanceConverterInterface from a `geometric instance id`.
*/
import {
WorkingSetInterface, GeometricInstanceConverterInterface, GeometricInstanceConverterInterfaceSignal,
DataSessionInterface,
} from 'generated_files/documentation/appinfiniteapi';

// the `geometric instances` are retrieved by a picking for example

// the DataSessionInterface has been created previously and is connected
let lDataSession : DataSessionInterface;
// the `geometric instance id` to get information from
let lGeometricInstanceId : number;
// create a `geometric instance id` converter
const lGeometricConverter : GeometricInstanceConverterInterface = lDataSession.createGeometricInstanceConverter();
// the current Working set has been created previously
let lVisibilityContext : WorkingSetInterface;

// the `geometric instance` to get
const lGeometricInstanceIds: Uint32Array = new Uint32Array(1);
lGeometricInstanceIds[0] = lGeometricInstanceId;

const onPartInstanceReady = (_pEvent, _pCallbackData) : void =>
{
// triggered when we have all the `part instances` of the given geometry
const lPartInstanceIds : Uint32Array| undefined = lGeometricConverter.getPartInstanceIds();
if (lPartInstanceIds && (lPartInstanceIds.length > 0))
{
// only work if result is valid
console.log('result found');
console.log(lPartInstanceIds.join(','));
}
};

// connect the GeometricInstanceConverterReady signal to the id card retrieval
lGeometricConverter.addEventListener(GeometricInstanceConverterInterfaceSignal.GeometricInstanceConverterReady, onPartInstanceReady);

// trigger the conversion
lGeometricConverter.convert(lGeometricInstanceIds, lVisibilityContext);

Or with async calls :
/** 
* Sample to illustrate the asynchronous use of a GeometricInstanceConverterInterface from a `geometric instance id`.
*/
import {
WorkingSetInterface, GeometricInstanceConverterInterface, AsyncUInt32ArrayResult, AsyncResultReason,
DataSessionInterface,
} from 'generated_files/documentation/appinfiniteapi';

// the `geometric instances` are retrieved by a picking for example

// the DataSessionInterface has been created previously and is connected
let lDataSession : DataSessionInterface;
// the `geometric instance id` to get information from
let lGeometricInstanceId : number;
// create a `geometric instance id` converter
const lGeometricConverter : GeometricInstanceConverterInterface = lDataSession.createGeometricInstanceConverter();
// the current Working set has been created previously
let lVisibilityContext : WorkingSetInterface;

// the `geometric instance` to get
const lGeometricInstanceIds: Uint32Array = new Uint32Array(1);
lGeometricInstanceIds[0] = lGeometricInstanceId;

const convertInstance = async () : Promise<void> =>
{
// trigger the conversion
const lResult : AsyncUInt32ArrayResult = await lGeometricConverter.asyncConvert(lGeometricInstanceIds, lVisibilityContext);

// triggered when we have all the `part instances` of the given geometry
const lPartInstanceIds : Uint32Array| undefined = lGeometricConverter.getPartInstanceIds();
console.assert(lResult.value === lPartInstanceIds);
if (lPartInstanceIds && (lPartInstanceIds.length > 0))
{
console.assert(lResult.reason === AsyncResultReason.ARR_Success);
// only work if result is valid
console.log('result found');
console.log(lPartInstanceIds.join(','));
}
};

convertInstance();

An example with an id-card request :
/** 
* Sample to illustrate the use of an IdCardGetterInterface from a `geometric instance id`.
*/
import {
WorkingSetInterface, IdCardGetterInterface, GeometricInstanceConverterInterface,
IdCardGetterInterfaceSignal, GeometricInstanceConverterInterfaceSignal, DataSessionInterface,
} from 'generated_files/documentation/appinfiniteapi';
// the `part instances` are retrieved by a picking for example

// the DataSessionInterface has been created previously and is connected
let lDataSession : DataSessionInterface;
// the `geometric instance id` to get information from
let lGeometricInstanceId : number;
// create a `geometric instance id` converter
const lGeometricConverter : GeometricInstanceConverterInterface = lDataSession.createGeometricInstanceConverter();
// the current Working set has been created previously
let lVisibilityContext : WorkingSetInterface;
// what to do when the conversion from picking is ready
let onPartInstanceReady : (pEvent, _pCallbackData) => void;
// what to do when the id card retrieval is over
let onIdCardReady : (pEvent, _pCallbackData) => void;

// id card getter interface creation
const lIdCardGetterInterface : IdCardGetterInterface = lDataSession.createIdCardGetter();
// connect the IDCardReady signal to the handling of the metadata of the `part instance` and its genealogy
lIdCardGetterInterface.addEventListener(IdCardGetterInterfaceSignal.IdCardReady, onIdCardReady);

// the `geometric instance` to get
const lGeometricInstanceIds: Uint32Array = new Uint32Array(1);
lGeometricInstanceIds[0] = lGeometricInstanceId;
// connect the GeometricInstanceConverterReady signal to the id card retrieval
lGeometricConverter.addEventListener(GeometricInstanceConverterInterfaceSignal.GeometricInstanceConverterReady, onPartInstanceReady);

onPartInstanceReady = (_pEvent, _pCallbackData) : void =>
{
// triggered when we have all the `part instances` of the given geometry
const lPartInstanceIds : Uint32Array| undefined = lGeometricConverter.getPartInstanceIds();
if (lPartInstanceIds && (lPartInstanceIds.length > 0))
{
// only get the id-card of the first `part instance` (we may do other things if multiple id-cards to retrieve)
// onIdCardReady will be called shortly after
lIdCardGetterInterface.retrieveIdCard(lPartInstanceIds[0], lVisibilityContext);
}
};

// trigger the conversion
lGeometricConverter.convert(lGeometricInstanceIds, lVisibilityContext);

Please refer to IdCardGetterInterface for more information about id-card requests.
Converters

interface GeometricInstanceConverterInterface {
    addEventListener(pType, pListener, pObject): string;
    addEventListener(pType, pListener): string;
    areSignalsBlocked(): boolean;
    asyncConvert(pGeometricInstanceIds, pWorkingSetContext, pComputeGeometricInstanceIdMapping?): Promise<AsyncUInt32ArrayResult>;
    blockSignals(pBlock): void;
    cancel(): boolean;
    convert(pGeometricInstanceIds, pWorkingSetContext, pComputeGeometricInstanceIdMapping?): boolean;
    dispose(): void;
    getGeometricInstanceIdsMapping(): Uint32Array;
    getInfiniteObjectType(): InfiniteObjectType;
    getLastError(): InfiniteError;
    getLastRequestId(): string;
    getPartInstanceIds(): Uint32Array;
    hasEventListener(pType, pListener): boolean;
    hasEventListenerById(pId): boolean;
    isCancelled(): boolean;
    isDisposed(): boolean;
    isRunning(): boolean;
    removeAllEventListeners(): boolean;
    removeEventListener(pType, pListener, pObject): boolean;
    removeEventListener(pType, pListener): boolean;
    removeEventListenerById(pId): boolean;
}

Hierarchy (view full)

Methods

  • Adds a listener to an event type.

    When an event of the type pType fires, the callback pListener will be called. This function returns a unique string id that may be used in removeEventListenerById to allow simple listener removal. It is possible to add an object that will be included in the callback to avoid creating too many closures. Calling twice addEventListener with the same parameters results in the second call to be ignored, only unique pairs callback / object are allowed, in order to avoid calling multiple times the same thing.

    Parameters

    • pType: string
      in
      The type of the event pListener will be called upon.
    • pListener: tListenerCallback
      in
      The listener function that fires when the given event type occurs.
    • pObject: Object
      in
      The optional object the callback will be called with when the given event fires.

    Returns string

    The id of the inserted callback (actually an UUID).

  • Adds a listener to an event type.

    When an event of the type pType fires, the callback pListener will be called. This function returns a unique string id that may be used in removeEventListenerById to allow simple listener removal.

    Parameters

    • pType: string
      in
      The type of the event pListener will be called upon.
    • pListener: tListenerCallback
      in
      The listener function that fires when the given event type occurs.

    Returns string

    The id of the inserted callback (actually an UUID).

  • Tells if signals sent by the object are blocked or not.

    If signals are blocked, no signal will be emitted nor buffered, such signal will be lost.

    Returns boolean

    true if signals are blocked.

  • Asynchronously triggers a request to "translate" the given geometric instance ids to the corresponding part instance ids.

    The server will try to find all part instances that are linked to the given geometric instance ids in the given WorkingSetInterface.

    If pComputeGeometricInstanceIdMapping is set to true, then getGeometricInstanceIdsMapping will return an Uint32Array of the same size as getPartInstanceIds and getGeometricInstanceIdsMapping()[offset] will return the geometric instance id of getPartInstanceIds()[offset].

    pComputeGeometricInstanceIdMapping defaults to false.

    Returns a promise.

    Please note that in case of multiple promises running at the same time on the same GeometricInstanceConverterInterface, the first promises will be signalled as cancelled, the last as ok, but all calls to getPartInstanceIds after awaiting will return the same value.

    If pWorkingSetContext is modified during the execution, then the call is cancelled (see cancel).

    Parameters

    Returns Promise<AsyncUInt32ArrayResult>

    A promise. The promise is resolved with the reason (success, cancelled, disposed, bad input). In case of success, the promise contains the requested Uint32Array.

  • Blocks / Unblocks all signals sent by the object.

    If signals are blocked, no signal will be emitted nor buffered, such signal will be lost.

    Parameters

    • pBlock: boolean
      in
      If set to true, all further signals will be silently discarded.

    Returns void

  • Gets the mapping result of the last convert call of the geometric instance ids conversion, with pComputeGeometricInstanceIdMapping set to true.

    getGeometricInstanceIdsMapping will be of the same size as getPartInstanceIds, and getGeometricInstanceIdsMapping(offset) corresponds to the geometric instance id of the part instance leaf getPartInstanceIds(offset).

    An Uint32Array representing the geometric instance ids is returned if the GeometricInstanceConverterInterface has finished computing. Use addEventListener on the event GeometricInstanceConverterInterfaceSignal.GeometricInstanceConverterReady to know when the GeometricInstanceConverterInterface is ready.

    DO NOT modify this data in place, this results in undefined behavior.

    Returns Uint32Array

    const
    The list of geometric instance ids correspondence result of the conversion, or undefined if the converter had an error, is still computing, or called with pComputeGeometricInstanceIdMapping set to false.
  • Gets the last error returned by the convert call of the GeometricInstanceConverterInterface.

    Returns InfiniteError

    The last error (if any, or undefined if no error occurred).

  • Each call to convert is assigned a request id.

    This call tels the id of the last call to convert.

    Returns string

    The id of the last call to convert.

  • Gets the result of the last convert call of the geometric instance ids conversion.

    An Uint32Array representing the part instance ids is returned if the GeometricInstanceConverterInterface has finished computing. Use addEventListener on the event GeometricInstanceConverterInterfaceSignal.GeometricInstanceConverterReady to know when the GeometricInstanceConverterInterface is ready.

    DO NOT modify this data in place, this results in undefined behavior.

    Returns Uint32Array

    const
    The list of part instance ids, result of the conversion, or undefined if the converter had an error, or is still computing.
  • Tells if the EventDispatcher has such a callback registered for the given event type.

    Parameters

    • pType: string
      in
      The type of the event to test.
    • pListener: tListenerCallback
      in
      The listener function that gets tested.

    Returns boolean

    true if such a listener is installed for the given type of event.

  • Tells if the EventDispatcher has such a callback registered for the given callback id.

    Parameters

    • pId: string
      in
      The id of the callback to test.

    Returns boolean

    true if such a listener is installed for the given callback id.

  • Tells if the GeometricInstanceConverterInterface has been cancelled.

    This is generally the case after calling cancel when the GeometricInstanceConverterInterface is retrieving data.

    Returns boolean

    true if the GeometricInstanceConverterInterface is cancelled.

  • Tells if the GeometricInstanceConverterInterface is converting data.

    This is the case after calling convert.

    Returns boolean

    true if the GeometricInstanceConverterInterface is converting.

  • Removes a listener from an event type.

    If no such listener is found, then the function returns false and does nothing. You must use the exact parameters that were used in addEventListener to actually remove the listener.

    Parameters

    • pType: string
      in
      The type of the listener that gets removed.
    • pListener: tListenerCallback

      The listener function that gets removed.

    • pObject: Object

      The listener object that was used when addEventListener was called.

    Returns boolean

    true if the callback was removed else false.

  • Removes a listener from an event type.

    If no such listener is found, then the function returns false and does nothing. You must use the exact parameters that were used in addEventListener to actually remove the listener.

    Parameters

    • pType: string
      in
      The type of the listener that gets removed.
    • pListener: tListenerCallback

      The listener function that gets removed.

    Returns boolean

    true if the callback was removed else false.

  • Removes a listener by its id.

    If no such listener is found, then the function returns false and does nothing. You must use the return value of addEventListener to actually remove the listener.

    Parameters

    • pId: string
      in
      The id returned by the call to addEventListener that you want to remove.

    Returns boolean

    true if the callback was removed else false.