Interface PartInstanceMatrixGetterInterface

The PartInstanceMatrixGetterInterface interface is used to fetch matrices of part instances.

The PartInstanceMatrixGetterInterface interfaces are created through the DataSessionInterface.createPartInstanceMatrixGetter method.

The list of signals the PartInstanceMatrixGetterInterface may trigger is available in the PartInstanceMatrixGetterInterfaceSignal enumeration.

The matrix retrieval request is triggered through the fetchMatrices method. The result is not available right away, but the event PartInstanceMatrixGetterInterfaceSignal.MatrixFetchReady is triggered when the result of the PartInstanceMatrixGetterInterface is available. The result is available through the getMatricesResult function.

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

An PartInstanceMatrixGetterInterface may be interrupted (cancelled) when the PartInstanceMatrixGetterInterface is running and cancelFetch is called. In such cases, the PartInstanceMatrixGetterInterfaceSignal.MatrixFetchCancelled signal is fired, and shortly after, PartInstanceMatrixGetterInterfaceSignal.MatrixFetchReady signal is fired, but getMatricesResult will return undefined. Just call fetchMatrices with another (or the same) array of part instances to trigger a new fetch request.

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

/** 
* Sample to illustrate the use of an PartInstanceMatrixGetterInterface to retrieve multiple matrices.
*/
import {
DataSessionInterface, PartInstanceMatrixGetterInterfaceSignal,
InfiniteEvent, PartInstanceMatrixResultInterface, PartInstanceMatrixGetterInterface
} from 'generated_files/documentation/appinfiniteapi';

// the DataSessionInterface has been created previously and is connected
let lDataSession : DataSessionInterface;
// the part instance ids to fetch
let lPartInstanceIds: Array<number>;

// to retrieve the matrices
const lPartInstanceMatrixGetter : PartInstanceMatrixGetterInterface = lDataSession.createPartInstanceMatrixGetter();

// what to do when matrix data has been downloaded ?
let onMatricesReady : (_pEvent: InfiniteEvent, _pCallbackData: Object | undefined) => void;

// what to do when the download of the matrices is ready ?
lPartInstanceMatrixGetter.addEventListener(PartInstanceMatrixGetterInterfaceSignal.MatrixFetchReady, onMatricesReady);

// what to do when matrix data has been downloaded ?
onMatricesReady = (_pEvent: InfiniteEvent, _pCallbackData: Object | undefined) : void =>
{
// matrices are ready
const lMatricesContent : Array<PartInstanceMatrixResultInterface> | undefined = lPartInstanceMatrixGetter.getMatricesResult();
if ((!lMatricesContent) || (lMatricesContent.length === 0))
{
console.log('error while fetching matrices content');
return;
}
// now matrix content is there, just need to display them
// use only the first part instance
const lCurMatrixResult : PartInstanceMatrixResultInterface = lMatricesContent[0];
console.log('Matrices info : instance:', lCurMatrixResult.getInstanceId(), 'local matrix:', lCurMatrixResult.getLocalMatrix(), 'world matrix:', lCurMatrixResult.getWorldMatrix(), ')');
};

lPartInstanceMatrixGetter.fetchMatrices(lPartInstanceIds);

Or with async calls :
/** 
* Sample to illustrate the asynchronous use of an PartInstanceMatrixGetterInterface to retrieve multiple matrices.
*/
import {
DataSessionInterface, PartInstanceMatrixGetterInterface, AsyncResultReason, AsyncPartInstanceMatrixResult,
PartInstanceMatrixResultInterface
} from 'generated_files/documentation/appinfiniteapi';
// the DataSessionInterface has been created previously and is connected
let lDataSession : DataSessionInterface;
// the part instance ids to fetch
let lPartInstanceIds: Array<number>;

// to retrieve the matrices
const lPartInstanceMatrixGetter : PartInstanceMatrixGetterInterface = lDataSession.createPartInstanceMatrixGetter();

const fetchMatrices = async () : Promise<void> =>
{
const lMatrixRes : AsyncPartInstanceMatrixResult = await lPartInstanceMatrixGetter.asyncFetchMatrices(lPartInstanceIds);
if (!lMatrixRes.value || !lMatrixRes.value.length)
{
// display some fancy error message
return;
}
console.assert(lMatrixRes.reason === AsyncResultReason.ARR_Success);
// now matrix content is there, just need to display them
// use only the first view
const lCurMatrixResult : PartInstanceMatrixResultInterface = lMatrixRes.value[0];
console.log('Matrices info : instance:', lCurMatrixResult.getInstanceId(), 'local matrix:', lCurMatrixResult.getLocalMatrix(), 'world matrix:', lCurMatrixResult.getWorldMatrix(), ')');
};

fetchMatrices();

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

interface PartInstanceMatrixGetterInterface {
    addEventListener(pType, pListener, pObject): string;
    addEventListener(pType, pListener): string;
    areSignalsBlocked(): boolean;
    asyncFetchMatrices(pPartInstanceList): Promise<AsyncPartInstanceMatrixResult>;
    blockSignals(pBlock): void;
    cancelFetch(): boolean;
    dispose(): void;
    fetchMatrices(pPartInstanceList): boolean;
    getInfiniteObjectType(): InfiniteObjectType;
    getLastError(): InfiniteError;
    getLastRequestId(): string;
    getMatricesResult(): PartInstanceMatrixResultInterface[];
    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 gets matrices.

    Returns a promise that will be resolved with the reason, and the eventual result when the fetch request is finished or cancelled.

    Parameters

    • pPartInstanceList: number | number[] | Uint32Array
      in
      The part instance ids of the matrices to fetch.

    Returns Promise<AsyncPartInstanceMatrixResult>

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

  • 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 (an) matrices retrieval request(s).

    An event PartInstanceMatrixGetterInterfaceSignal.MatrixFetchReady is fired when the fetch procedure is finished, then getLastError() tells if the retrieval was correctly performed.

    Returns true if the matrices fetch procedure is started. If not, just call getLastError to get the reason why the procedure failed.

    Parameters

    • pPartInstanceList: number | number[] | Uint32Array
      in
      The part instance ids of the matrices to fetch.

    Returns boolean

    true if the PartInstanceMatrixGetterInterface has begun running.

  • Gets the last error returned by the matrix retrieval procedure.

    Returns InfiniteError

    The last error.

  • 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 a matrix retrieval procedure has been cancelled.

    This is generally the case after calling cancelFetch when the PartInstanceMatrixGetterInterface is performing a matrix retrieval procedure.

    Returns boolean

    true if the matrix retrieval procedure is cancelled.

  • Tells if a matrix retrieval procedure is running.

    This is the case after calling fetchMatrices.

    Returns boolean

    true if an matrix retrieval procedure request is running.

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