Interface AnnotationGetterInterface

The AnnotationGetterInterface interface is used to fetch annotations views in the DMU.

Please see Annotations for more explanations about annotations.

The AnnotationGetterInterface interfaces are created through the createAnnotationGetter method.

The list of signals the AnnotationGetterInterface may trigger is available in the AnnotationGetterInterfaceSignal enumeration.

The annotation retrieval request is triggered through the fetchAnnotationViews method. The result is not available right away, but the event AnnotationFetchReady is triggered when the result of the AnnotationGetterInterface is available. The result is available through the getAnnotationViewsResult function.
As said in Annotations, the annotation views result consists in opaque annotation view(s) that must be included in an AnnotationRendererInterface to be usable. Each annotation view is itself composed of multiple annotations.

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

An AnnotationGetterInterface may be interrupted (cancelled) when the AnnotationGetterInterface is running and cancelFetch is called. In such cases, the AnnotationFetchCancelled signal is fired, and shortly after, AnnotationFetchReady signal is fired, but getAnnotationViewsResult will return undefined. Just call fetchAnnotationViews with another (or the same) AnnotationViewInfoInterface to trigger a new fetch request.

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

The process is as follows :

/** 
* Sample to illustrate the use of an AnnotationGetterInterface to retrieve multiple annotation views.
*/
import {
DataSessionInterface, IdCardGetterInterface, IdCardGetterInterfaceSignal,
InfiniteEvent, PartInstanceInfoInterface, AnnotationViewInfoInterface, AnnotationGetterInterface, AnnotationGetterInterfaceSignal, AnnotationResultInterface, VisibilityContextInterface,
} from 'generated/documentation/appinfiniteapi';

// the DataSessionInterface has been created previously and is connected
let lDataSession : DataSessionInterface;
// created previously
let lIdCardGetterInterface : IdCardGetterInterface;
// created previously, the visibility context to use for the id card query
let lVisibilityContext : VisibilityContextInterface;
// the part instance id to fetch
let lPartInstanceId : number;

// to retrieve the annotations
const lAnnotationViewGetter : AnnotationGetterInterface = lDataSession.createAnnotationGetter();

// what to do when we have retrieved id card information ?
let onIdCardReady : (_pEvent: InfiniteEvent, _pCallbackData: Object | undefined) => void;

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

// what to do when id card is ready ?
lIdCardGetterInterface.addEventListener(IdCardGetterInterfaceSignal.IdCardReady, onIdCardReady);
// what to do when the download of the annotation view is ready ?
lAnnotationViewGetter.addEventListener(AnnotationGetterInterfaceSignal.AnnotationFetchReady, onAnnotationViewDownloaded);

// onIdCardReady will be called when idcard data is available
onIdCardReady = (_pEvent: InfiniteEvent, _pCallbackData: Object | undefined) : void =>
{
if (lIdCardGetterInterface.getLastError().length !== 0) {
// 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;
}
// get the first the instantiation chain
const lCurrentChain : PartInstanceInfoInterface = lPartInstanceInfos[0];
// the annotation views that will be fetched
const lAnnotationsToFetch : Array<AnnotationViewInfoInterface> = [];
// iterate over the annotation views to retrieve all views at once
const lAllAnnotationViews : Array<Array<AnnotationViewInfoInterface>> = lCurrentChain.getAnnotationViews();
// loops
let i : number;
let j : number;
// number of annotation views for this instance
let lNbAnnotationViews : number;
// number of ancestors
const lNbAncestors : number = lAllAnnotationViews.length;
let lAnnotationViewsOfPartInstance :Array<AnnotationViewInfoInterface>;
let lCurAnnotationView : AnnotationViewInfoInterface;
for (i = 0; i < lNbAncestors; ++i)
{
lAnnotationViewsOfPartInstance = lAllAnnotationViews[i];
lNbAnnotationViews = lAnnotationViewsOfPartInstance.length;
for (j = 0; j < lNbAnnotationViews; ++j)
{
lCurAnnotationView = lAnnotationViewsOfPartInstance[j];
// some fancy log
console.log('Will fetch annotation view ' + lCurAnnotationView.getAnnotationViewName() + ' of type ' + lCurAnnotationView.getAnnotationViewTypeName()
+ ' with ' + lCurAnnotationView.getAnnotationViewAnnotationCount() + ' annotations');
// add the annotation view to be fetched
lAnnotationsToFetch.push(lCurAnnotationView);
}
}
// and download
lAnnotationViewGetter.fetchAnnotationViews(lAnnotationsToFetch);
}

// what to do when annotation data has been downloaded ?
onAnnotationViewDownloaded = (_pEvent: InfiniteEvent, _pCallbackData: Object | undefined) : void =>
{
// annotation are ready
const lAnnotationViewsContent : Array<AnnotationResultInterface> | undefined = lAnnotationViewGetter.getAnnotationViewsResult();
if ((!lAnnotationViewsContent) || (lAnnotationViewsContent.length === 0))
{
console.log('error while fetching annotation content');
return;
}
// now annotation content is there, just need to display them
// use only the first view
const lCurAnnotationViewResult : AnnotationResultInterface = lAnnotationViewsContent[0];
console.log('display annotation view ' + lCurAnnotationViewResult.getAnnotationViewName() + ' (of type ' + lCurAnnotationViewResult.getAnnotationViewTypeName() + ')');
}

lIdCardGetterInterface.retrieveIdCard(lPartInstanceId, lVisibilityContext);

Or with async calls :
/** 
* Sample to illustrate the asynchronous use of an AnnotationGetterInterface to retrieve multiple annotation views.
*/
import {
DataSessionInterface, IdCardGetterInterface, VisibilityContextInterface, AsyncResultReason, AsyncPartInstanceInfoResult,
PartInstanceInfoInterface, AnnotationViewInfoInterface, AnnotationGetterInterface, AnnotationResultInterface, AsyncAnnotationResult
} from 'generated/documentation/appinfiniteapi';

// the DataSessionInterface has been created previously and is connected
let lDataSession : DataSessionInterface;
// created previously
let lIdCardGetterInterface : IdCardGetterInterface;
// created previously, the visibility context to use for the id card query
let lVisibilityContext : VisibilityContextInterface;
// the part instance id to fetch
let lPartInstanceId : number;

// to retrieve the annotations
const lAnnotationViewGetter : AnnotationGetterInterface = lDataSession.createAnnotationGetter();

const fetchAnnotation = async () : Promise<any> =>
{
const lIdCardRes : AsyncPartInstanceInfoResult = await lIdCardGetterInterface.asyncRetrieveIdCard(lPartInstanceId, lVisibilityContext);
if (!lIdCardRes.value || !lIdCardRes.value.length)
{
// display some fancy error message
return;
}
console.assert(lIdCardRes.reason === AsyncResultReason.ARR_Success);

// get the first the instantiation chain
const lCurrentChain : PartInstanceInfoInterface = lIdCardRes.value[0];
// the annotation views that will be fetched
const lAnnotationsToFetch : Array<AnnotationViewInfoInterface> = [];
// iterate over the annotation views to retrieve all views at once
const lAllAnnotationViews : Array<Array<AnnotationViewInfoInterface>> = lCurrentChain.getAnnotationViews();
// loops
let i : number;
let j : number;
// number of annotation views for this instance
let lNbAnnotationViews : number;
// number of ancestors
const lNbAncestors : number = lAllAnnotationViews.length;
let lAnnotationViewsOfPartInstance :Array<AnnotationViewInfoInterface>;
let lCurAnnotationView : AnnotationViewInfoInterface;
for (i = 0; i < lNbAncestors; ++i)
{
lAnnotationViewsOfPartInstance = lAllAnnotationViews[i];
lNbAnnotationViews = lAnnotationViewsOfPartInstance.length;
for (j = 0; j < lNbAnnotationViews; ++j)
{
lCurAnnotationView = lAnnotationViewsOfPartInstance[j];
// some fancy log
console.log('Will fetch annotation view ' + lCurAnnotationView.getAnnotationViewName() + ' of type ' + lCurAnnotationView.getAnnotationViewTypeName()
+ ' with ' + lCurAnnotationView.getAnnotationViewAnnotationCount() + ' annotations');
// add the annotation view to be fetched
lAnnotationsToFetch.push(lCurAnnotationView);
}
}
// and download
const lAnnotationContentResult : AsyncAnnotationResult = await lAnnotationViewGetter.asyncFetchAnnotationViews(lAnnotationsToFetch);
// annotation are ready
// const lAnnotationViewsContent : Array<AnnotationResultInterface> | undefined = lAnnotationViewGetter.getAnnotationViewsResult();
if ((!lAnnotationContentResult.value) || (lAnnotationContentResult.value.length === 0))
{
console.log('error while fetching annotation content');
return;
}
// now annotation content is there, just need to display them
// use only the first view
const lCurAnnotationViewResult : AnnotationResultInterface = lAnnotationContentResult.value[0];
console.log('display annotation view ' + lCurAnnotationViewResult.getAnnotationViewName() + ' (of type ' + lCurAnnotationViewResult.getAnnotationViewTypeName() + ')');
}

fetchAnnotation();

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

See

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

  • Cancels the computation of the fetch retrieval (if any).

    A AnnotationFetchCancelled signal is emitted if the AnnotationGetterInterface is retrieving data.

    Returns

    true if the AnnotationGetterInterface was running, else false.

    See

    AnnotationFetchCancelled

    Returns boolean

  • Gets the last error message returned by the annotation retrieval procedure.

    Returns

    The last error message.

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

    This is generally the case after calling cancelFetch when the AnnotationGetterInterface is preforming an annotation retrieval procedure.

    Returns

    true if the annotation retrieval procedure is cancelled.

    Returns boolean

  • Tells if a annotation retrieval procedure is running.

    This is the case after calling fetchAnnotationViews.

    Returns

    true if an annotation retrieval procedure request is running.

    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](AnnotationGetterInterface.html#addEventListener) that you want to remove.

    Returns boolean