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

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 DataSessionInterface.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 PartInstanceConverterInterfaceSignal.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 PartInstanceConverterInterfaceSignal.PartInstanceConverterCancelled signal is fired, and shortly after, PartInstanceConverterInterfaceSignal.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 PartInstanceConverterInterfaceSignal.PartInstanceConverterReady, only one PartInstanceConverterInterfaceSignal.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_files/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_files/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<void> =>
{
// 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

interface PartInstanceConverterInterface {
    addEventListener(pType, pListener, pObject): string;
    addEventListener(pType, pListener): string;
    areSignalsBlocked(): boolean;
    asyncConvert(pPartInstanceIds, pWorkingSetContext?): Promise<AsyncUInt32ArrayResult>;
    blockSignals(pBlock): void;
    cancel(): boolean;
    convert(pPartInstanceIds, pWorkingSetContext?): boolean;
    dispose(): void;
    getGeometricInstanceIds(): Uint32Array;
    getInfiniteObjectType(): InfiniteObjectType;
    getLastError(): InfiniteError;
    getLastRequestId(): string;
    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 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.

    An optional WorkingSetInterface may be used to restrict the final result.

    Parameters

    • pPartInstanceIds: number[] | Uint32Array
      in
      the part instance ids to perform the conversion with.
    • Optional pWorkingSetContext: WorkingSetInterface
      in
      The WorkingSetInterface to use when "converting" to a list of part instance ids.

    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

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

    An optional WorkingSetInterface may be used to restrict the final result.

    Parameters

    • pPartInstanceIds: number[] | Uint32Array
      in
      The part instance ids to perform the conversion with.
    • Optional pWorkingSetContext: WorkingSetInterface
      in
      The WorkingSetInterface to use when "converting" to a list of part instance ids.

    Returns boolean

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

  • 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 PartInstanceConverterInterfaceSignal.PartInstanceConverterReady to know when the PartInstanceConverterInterface is ready.

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

    Returns Uint32Array

    const
    The list of geometric instance ids, result of the conversion, or undefined if the converter had an error, or is still computing.
  • Gets the last error returned by the convert call of the PartInstanceConverterInterface.

    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.

  • 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 PartInstanceConverterInterface has been cancelled.

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

    Returns boolean

    true if the PartInstanceConverterInterface is cancelled.

  • Tells if the PartInstanceConverterInterface is converting data.

    This is the case after calling convert.

    Returns boolean

    true if the PartInstanceConverterInterface 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.