Interface IdCardGetterInterface

The IdCardGetterInterface interface is used to retrieve information about a part instance (and not a geometric instance id), such as the metadata of the part, link, the list of part instance ancestors, attached document, ....

The metadata documents and general information can be retrieved by knowing the part instance to retrieve. If such a document is requested after a picking, then the given geometric instance id must be converted to a part instance id.

The IdCardGetterInterface interfaces are created through the DataSessionInterface.createIdCardGetter method.

/** 
* 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);

The list of signals the IdCardGetterInterface may trigger is available in the IdCardGetterInterfaceSignal enumeration.

The metadata retrieval procedure is triggered through the retrieveIdCard methods. The result is not available right away, but the event IdCardGetterInterfaceSignal.IdCardReady is triggered when the result of the IdCardGetterInterface is available. The result is available through the getPartInstanceInfos function.

Warning : there may be cases when the getPartInstanceInfos is not available such as when the IdCardGetterInterface is updating, i.e. when isRunning returns true, or when the IdCardGetterInterface has been cancelled, i.e. when isCancelled returns true.

An IdCardGetterInterface may be interrupted (cancelled) when the IdCardGetterInterface is updating and cancel is called. In such cases, the IdCardGetterInterfaceSignal.IdCardCancelled signal is fired, and shortly after, IdCardGetterInterfaceSignal.IdCardReady signal is fired, but getPartInstanceInfos will return undefined. Just call retrieveIdCard with another (or the same) part instance ids to trigger a new retrieval.

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

The developer may process the results of an id card retrieval with the following code :

/** 
* Sample to illustrate the use of an IdCardGetterInterface with the parsing of
* PartInstanceInfoInterface to display some information about a part instance.
*/
import {
WorkingSetInterface, IdCardGetterInterface, IdCardGetterInterfaceSignal,
InfiniteEvent, PartInstanceInfoInterface, DataSessionInterface, AncestryInstanceMetadataInterface, DocumentContentInterface
} from 'generated_files/documentation/appinfiniteapi';

// the DataSessionInterface has been created previously and is connected
let lDataSession : DataSessionInterface;
// created previously
let lVisibilityContext : WorkingSetInterface;
// the `part instance id` to get
let lPartInstanceId : number;
// what to do when we have retrieved id card information ?
let onIdCardReady : (_pEvent: InfiniteEvent, _pCallbackData: Object | undefined) => void;

// create an idCardGetter
const lIdCardGetterInterface : IdCardGetterInterface = lDataSession.createIdCardGetter();
// what to do when result is ready ?
lIdCardGetterInterface.addEventListener(IdCardGetterInterfaceSignal.IdCardReady, onIdCardReady);

// onIdCardReady will be called when data is available
onIdCardReady = (_pEvent: InfiniteEvent, _pCallbackData: Object | undefined) : void =>
{
if (lIdCardGetterInterface.getLastError() !== undefined) {
// do nothing in case of error
// perhaps some GUI code ?
}
const lPartInstanceInfos : Array<PartInstanceInfoInterface> | undefined = lIdCardGetterInterface.getPartInstanceInfos();
if (!lPartInstanceInfos || lPartInstanceInfos.length !== 1)
{
// no data (isCancelled ?)
return;
}
// we required only one `part instance`, as such, only one result should be retrieved
// iterate over the instantiation chain, but take the first chain since one `part instance` retrieved
const lCurrentChain : PartInstanceInfoInterface = lPartInstanceInfos[0];

// iterate over the metadata infos
const lAllInstanceMetadata : Array<AncestryInstanceMetadataInterface> = lCurrentChain.getAncestorInstanceInfos();

// number of items
const lNbAncestors : number = lAllInstanceMetadata.length;
const lOffsetToPartInstance : number = lNbAncestors - 1;
// we get the `part` metadata of the given `part instance` (and not their parents - grand parents) => lNbAncestors-1
const lCurrentInstanceInfos : AncestryInstanceMetadataInterface = lAllInstanceMetadata[lOffsetToPartInstance];
const lPartMetadataDocuments : Array<DocumentContentInterface> = lCurrentInstanceInfos.getPartMetadataDocuments();
if (lPartMetadataDocuments.length === 0)
{
console.log('this part instance has no part metadata documents');
return;
}
// and we only care with the first document, but many documents may be attached
const lPartMetadata : Object = lPartMetadataDocuments[0].getDocumentContent();
// some fancy output
console.log(JSON.stringify(lPartMetadata));

// get the visibility info in order to get information about the `part instance`
if (lCurrentInstanceInfos.isDisplayable())
{
console.log('this part instance is displayable');
}
};

// trigger the retrieval
lIdCardGetterInterface.retrieveIdCard(lPartInstanceId, lVisibilityContext);

or with async calls :
/** 
* Sample to illustrate the asynchronous use of an IdCardGetterInterface with the parsing of
* PartInstanceInfoInterface to display some information about a part instance.
*/
import {
WorkingSetInterface, IdCardGetterInterface, AsyncPartInstanceInfoResult,
AsyncResultReason, PartInstanceInfoInterface, DataSessionInterface, AncestryInstanceMetadataInterface, DocumentContentInterface
} from 'generated_files/documentation/appinfiniteapi';

// the DataSessionInterface has been created previously and is connected
let lDataSession : DataSessionInterface;
// created previously
let lVisibilityContext : WorkingSetInterface;
// the `part instance id` to get
let lPartInstanceId : number;
// what to do when we have retrieved id card information ?

// create an idCardGetter
const lIdCardGetterInterface : IdCardGetterInterface = lDataSession.createIdCardGetter();

const fetchIdCard = async () : Promise<void> =>
{
// trigger the retrieval
const lResult : AsyncPartInstanceInfoResult = await lIdCardGetterInterface.asyncRetrieveIdCard(lPartInstanceId, lVisibilityContext);
if (lResult.reason !== AsyncResultReason.ARR_Success) {
// do nothing in case of error
// perhaps some GUI code ?
}

const lPartInstanceInfos : Array<PartInstanceInfoInterface> | undefined = lIdCardGetterInterface.getPartInstanceInfos();
console.assert(lPartInstanceInfos === lResult.value);
if (!lPartInstanceInfos || lPartInstanceInfos.length !== 1)
{
// no data (isCancelled ?)
return;
}
// we required only one `part instance`, as such, only one result should be retrieved
// iterate over the instantiation chain, but take the first chain since one `part instance` retrieved
const lCurrentChain : PartInstanceInfoInterface = lPartInstanceInfos[0];

// get all metadata hierarchy
const lAllInstanceMetadata : Array<AncestryInstanceMetadataInterface> = lCurrentChain.getAncestorInstanceInfos();

// number of items
const lNbAncestors : number = lAllInstanceMetadata.length;
const lOffsetToPartInstance : number = lNbAncestors - 1;

// we get the `part` metadata of the given `part instance` (and not their parents - grand parents) => lNbAncestors-1
const lCurrentInstanceInfos : AncestryInstanceMetadataInterface = lAllInstanceMetadata[lOffsetToPartInstance];
const lPartMetadataDocuments : Array<DocumentContentInterface> = lCurrentInstanceInfos.getPartMetadataDocuments();
if (lPartMetadataDocuments.length === 0)
{
console.log('this part instance has no part metadata documents');
return;
}
// and we only care with the first document, but many documents may be attached
const lPartMetadata : Object = lPartMetadataDocuments[0].getDocumentContent();
// some fancy output
console.log(JSON.stringify(lPartMetadata));

// get the visibility info in order to get information about the `part instance`
if (lCurrentInstanceInfos.isDisplayable())
{
console.log('the last child of the part instance is displayable');
}
};

fetchIdCard();

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

interface IdCardGetterInterface {
    addEventListener(pType, pListener, pObject): string;
    addEventListener(pType, pListener): string;
    areSignalsBlocked(): boolean;
    asyncRetrieveIdCard(pPartInstanceIds, pWorkingSet): Promise<AsyncPartInstanceInfoResult>;
    asyncRetrieveRootIdCard(pWorkingSet): Promise<AsyncPartInstanceInfoResult>;
    blockSignals(pBlock): void;
    cancel(): boolean;
    dispose(): void;
    getInfiniteObjectType(): InfiniteObjectType;
    getLastError(): InfiniteError;
    getLastRequestId(): string;
    getPartInstanceInfos(): PartInstanceInfoInterface[];
    getResultForIdCardCustomization(pMultiMetadataHierarchies, pDocPool): boolean;
    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;
    retrieveIdCard(pPartInstanceIds, pWorkingSet): boolean;
    retrieveIdCard(pPartInstanceId, pWorkingSet): boolean;
    retrieveRootIdCard(pWorkingSet): 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 the information about the specified part instance ids and their genealogy.

    Returns a promise.

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

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

    Parameters

    • pPartInstanceIds: number | number[] | Uint32Array
      in
      The list of part instance ids to fetch metadata from.
    • pWorkingSet: WorkingSetInterface
      in
      The current working set for configured metadata.

    Returns Promise<AsyncPartInstanceInfoResult>

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

  • Asynchronously gets the information about the specified part instance id and its genealogy.

    Returns a promise.

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

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

    Parameters

    Returns Promise<AsyncPartInstanceInfoResult>

    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

  • Gets the last error returned by the update of the IdCardGetterInterface.

    Returns InfiniteError

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

  • Gets the result for the id-card customization script.

    As the customization script may change, the customization script types are not exposed to the Infinite api. You can get them from the @3djuump.com/client-script-3djuump-infinite package.

    • 
      

    /**

    • Sample to illustrate the use of an IdCardGetterInterface with the usage of the customization script. */ import { IdCardGetterInterface, tScriptDocPool } from 'generated_files/documentation/appinfiniteapi';

    // created previously let lIdCardGetterInterface : IdCardGetterInterface; // ... // ... const lMultiHierarchy : Array = []; const lDocPool : tScriptDocPool = {}; // now retrieve the result if(!lIdCardGetterInterface.getResultForIdCardCustomization(lMultiHierarchy, lDocPool)) { console.log('Error while transforming data'); throw new Error('customization failed'); } // now we can use the customization script since data is ready to be used.

    <br>
    The detailed usage of the customization script is beyond the scope of this documentation.

    Parameters

    • pMultiMetadataHierarchies: any[]
      out
      The multi id card hierarchy result.
    • pDocPool: tScriptDocPool
      out
      The map of docs.

    Returns boolean

    true if the conversion went right.

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

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

    Returns boolean

    true if the IdCardGetterInterface is cancelled.

  • Tells if the IdCardGetterInterface is updating.

    This is the case after calling retrieveIdCard.

    Returns boolean

    true if the IdCardGetterInterface is updating.

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

  • Gets the information about the specified part instance ids and their genealogy.

    The IdCardGetterInterfaceSignal.IdCardReady signal is fired when the part instance ids metadata result is ready.

    Returns true if the metadata procedure retrieval is started. If not, just call getLastError to get the reason why the procedure failed. For instance, pPartInstanceIds is considered as invalid input if it is empty or at least one element is out of range [1 : 2^31-1].

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

    Parameters

    Returns boolean

    true if the retrieval procedure has begun.

  • Gets the information about the specified part instance id and its genealogy.

    The event IdCardGetterInterfaceSignal.IdCardReady is fired when the part instance id metadata result is ready.

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

    Returns true if the metadata procedure retrieval is started. If not, just call getLastError to get the reason why the procedure failed. For instance, pPartInstanceIds is considered as invalid input if it is empty or at least one element is out of range [1 - 2^31-1].

    Parameters

    • pPartInstanceId: number
      in
      The part instance id to fetch metadata from.
    • pWorkingSet: WorkingSetInterface
      in
      The current working set for configured metadata.

    Returns boolean

    true if the retrieval procedure has begun.

  • Gets the information about the specified part instance id and its genealogy.

    The event IdCardGetterInterfaceSignal.IdCardReady is fired when the part instance id metadata result is ready.

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

    Returns true if the metadata procedure retrieval is started. If not, just call getLastError to get the reason why the procedure failed. For instance, pPartInstanceIds is considered as invalid input if it is empty or at least one element is out of range [1 - 2^31-1].

    Parameters

    Returns boolean

    true if the retrieval procedure has begun.