Interface PartInstanceConverterInterface

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

Contrary to the GeometricInstanceConverterInterface, this operation is not dependant on a filtering context.

This conversion may be useful to change the display on some part instances, from a search query for example , since the InfiniteEngineInterface works on geometric instance ids.

The PartInstanceConverterInterface interfaces are created through the createPartInstanceConverter method.

The list of signals the PartInstanceConverterInterface may trigger is available in the PartInstanceConverterInterfaceSignal enumeration.

The conversion mechanism is triggered through the convert method. The result is not available right away, but the event PartInstanceConverterReady is triggered when the result of the PartInstanceConverterInterfaceSignal is available. The result is available through the getGeometricInstanceIds function.

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

A PartInstanceConverterInterface may be interrupted (cancelled) when the PartInstanceConverterInterface is fetching data and cancel is called. In such cases, the PartInstanceConverterCancelled signal is fired, and shortly after, PartInstanceConverterReady signal is fired, but getGeometricInstanceIds will return undefined. Just call convert with another (or the same) part instance ids to trigger a new retrieval.

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

This interface performs the opposite operation of the GeometricInstanceConverterInterface interface.

/** 
* Sample to explain how to convert part instance ids to geometric instance ids using a PartInstanceConverterInterface.
*/
import {
PartInstanceConverterInterface, PartInstanceConverterInterfaceSignal,
InfiniteEngineInterface, VisualStates, DataSessionInterface,
} from 'generated/documentation/appinfiniteapi';

// the DataSessionInterface has been created previously and is connected
let lDataSession : DataSessionInterface;
// lInfiniteEngine has been created previously
let lInfiniteEngine : InfiniteEngineInterface;
// the `part instance id` to get information from
let lPartInstanceId : number;
// what to do when the conversion from picking is ready
let onGeometricInstanceReady : (pEvent, _pCallbackData) => void;

// the `part instance ids` to convert
const lPartInstanceIds: Uint32Array = new Uint32Array(1);
lPartInstanceIds[0] = lPartInstanceId;

// create a partInstanceConverter to convert `part instances` to `geometric instance ids`
const lPartInstanceConverter : PartInstanceConverterInterface = lDataSession.createPartInstanceConverter();
// connect the PartInstanceConverterReady signal to the set ghost procedure
lPartInstanceConverter.addEventListener(PartInstanceConverterInterfaceSignal.PartInstanceConverterReady, onGeometricInstanceReady);

onGeometricInstanceReady = (_pEvent, _pCallbackData) : void =>
{
// triggered when we have all the `geometric instances` of the given `part instance`
const lGeometricInstanceIds : Uint32Array| undefined = lPartInstanceConverter.getGeometricInstanceIds();
if (lGeometricInstanceIds && (lGeometricInstanceIds.length > 0))
{
// display the given `geometric instances` ghosted
lInfiniteEngine.updateGeometricState(lGeometricInstanceIds, VisualStates.S_Ghost, VisualStates.S_Ghost);
}
}

// trigger the conversion
lPartInstanceConverter.convert(lPartInstanceIds);

or asynchronously :
/** 
* Sample to explain how to asynchronously convert part instance ids to geometric instance ids using a PartInstanceConverterInterface.
*/
import {
PartInstanceConverterInterface, DataSessionInterface,
InfiniteEngineInterface, VisualStates, AsyncUInt32ArrayResult, AsyncResultReason
} from 'generated/documentation/appinfiniteapi';

// the DataSessionInterface has been created previously and is connected
let lDataSession : DataSessionInterface;
// lInfiniteEngine has been created previously
let lInfiniteEngine : InfiniteEngineInterface;
// the `part instance id` to get information from
let lPartInstanceId : number;

// the `part instance ids` to convert
const lPartInstanceIds: Uint32Array = new Uint32Array(1);
lPartInstanceIds[0] = lPartInstanceId;

// create a partInstanceConverter to convert `part instances` to `geometric instance ids`
const lPartInstanceConverter : PartInstanceConverterInterface = lDataSession.createPartInstanceConverter();

const convertPartInstances = async () : Promise<any> =>
{
// trigger the conversion
const lResult : AsyncUInt32ArrayResult = await lPartInstanceConverter.asyncConvert(lPartInstanceIds);
if (lResult.reason !== AsyncResultReason.ARR_Success || lResult.value === undefined || lResult.value.length <= 0)
{
// perhaps some fancy GUI message ?
console.log('Error while converting part instances')
return;
}
// display the given `geometric instances` ghosted
lInfiniteEngine.updateGeometricState(lResult.value, VisualStates.S_Ghost, VisualStates.S_Ghost);
}

convertPartInstances();

Please make sure the destination browser supports promises before using async calls.
Converters

See

PartInstanceConverterInterfaceSignal

Hierarchy

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.

    Returns

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

    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: undefined | Object
      in
      The optional object the callback will be called with when the given event fires.

    Returns string

  • 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.

    Returns

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

    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

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

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

    Returns a promise.

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

    Returns

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

    Parameters

    • pPartInstanceIds: number[] | Uint32Array
      in
      the part instance ids to perform the conversion with.

    Returns Promise<AsyncUInt32ArrayResult>

  • Cancels the computation of the conversion process (if any).

    A PartInstanceConverterCancelled signal is emitted if the PartInstanceConverterInterface is retrieving data.

    Returns

    true if the PartInstanceConverterInterface was running, else false.

    See

    PartInstanceConverterCancelled

    Returns boolean

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

    The server will try to find all geometric instances that are linked to the given part instance ids. An event PartInstanceConverterReady is fired when the translation is finished, use getLastError() to check if it was correctly performed.

    Returns true if the "conversion" is started. If not, just call getLastError to get the reason why the procedure failed. All values of the input list should be between 0 and 231-1, if not, returns false.

    Returns

    true if the conversion process has started, just wait for PartInstanceConverterReady.

    Parameters

    • pPartInstanceIds: number[] | Uint32Array
      in
      The part instance ids to perform the conversion with.

    Returns boolean

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

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

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

    Returns

    const
    The list of geometric instance ids, result of the conversion, or undefined if the converter had an error, or is still computing.

    See

    Returns undefined | Uint32Array

  • Gets the last error returned by the convert call of the PartInstanceConverterInterface.

    Returns

    The last error message (if any, or an empty string if no error occurred).

    Returns string

  • Each call to convert is assigned a request id.

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

    Returns

    The id of the last call to convert.

    Returns string

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

    Returns

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

    Parameters

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

    Returns boolean

  • Tells if the PartInstanceConverterInterface has been cancelled.

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

    Returns

    true if the PartInstanceConverterInterface is cancelled.

    Returns boolean

  • Tells if the PartInstanceConverterInterface is converting data.

    This is the case after calling convert.

    Returns

    true if the PartInstanceConverterInterface is converting.

    Returns boolean

  • 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.

    Returns

    true if the callback was removed else false.

    Parameters

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

      The listener function that gets removed.

    • pObject: undefined | Object

      The listener object that was used when addEventListener was called.

    Returns boolean

  • 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.

    Returns

    true if the callback was removed else false.

    Parameters

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

      The listener function that gets removed.

    Returns boolean

  • 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.

    Returns

    true if the callback was removed else false.

    Parameters

    • pId: string
      in
      The id returned by the call to [addEventListener](PartInstanceConverterInterface.html#addEventListener) that you want to remove.

    Returns boolean