Interface AnnotationViewParsingResultInterface

The AnnotationViewParsingResultInterface is the attachment of the AnnotationViewParsed signal sent by the AnnotationRendererInterface when new annotations are available. The AnnotationRendererInterfaceSignal is sent after a call to addAnnotationView.

This object stores information about the annotation view that was parsed : i.e. the annotations that were included inside it.

Each annotations is assigned an id (tAnnotationId), from annotationIdStart to annotationIdStart + nbAnnotations - 1 inclusive, and the added AnnotationViewInterface that was included in the AnnotationRendererInterface is also assigned an id (annotationViewId). A valid id (annotation or view id) is a strictly positive number (0 is invalid). The requestId is the value that was returned by the successful call to addAnnotationView.

In case of error, annotationIdStart, annotationViewId and nbAnnotations are negative (-1 actually), errorMessage is set with the reason for the error.

The warnings field tells if some values were not handled correctly, but the AnnotationViewInterface can still be displayed.

/** 
* Sample to illustrate the displaying of annotations.
*/
import {
AnnotationGetterInterface, AnnotationGetterInterfaceSignal, InfiniteEvent,
AnnotationResultInterface, Matrix4, InfiniteEngineInterface, AnnotationRendererInterface, AnnotationRendererInterfaceSignal,
tAnnotationViewId, AnnotationInstanceState, AnnotationViewParsingResultInterface,
} from 'generated/documentation/appinfiniteapi';

// created previously
let lAnnotationViewGetter : AnnotationGetterInterface;
// created previously
let lInfiniteEngine : InfiniteEngineInterface;
// retrieve the annotation renderer
const lAnnotationRenderer : AnnotationRendererInterface = lInfiniteEngine.getAnnotationRenderer();

// the annotation view id that has just been parsed
let lAnnotationViewId : tAnnotationViewId = -1;

// what to do when an annotation has been downloaded ?
let onAnnotationRetrieved : (pEvent: InfiniteEvent, pCallbackData: Object | undefined) => void;

// what to do when an annotation is ready to be displayed ?
let onAnnotationReady : (pEvent: InfiniteEvent, pCallbackData: Object | undefined) => void;

// connect to signals
lAnnotationViewGetter.addEventListener(AnnotationGetterInterfaceSignal.AnnotationFetchReady, onAnnotationRetrieved);
lAnnotationRenderer.addEventListener(AnnotationRendererInterfaceSignal.AnnotationViewParsed, onAnnotationReady);

// what to do when an annotation has been downloaded ?
onAnnotationRetrieved = (_pEvent: InfiniteEvent, _pCallbackData: Object | undefined) : void =>
{
// the result of the download
const lAnnotationViewsContent : Array<AnnotationResultInterface> | undefined = lAnnotationViewGetter.getAnnotationViewsResult();
if (!lAnnotationViewsContent || (lAnnotationViewsContent.length === 0))
{
console.log('Weird, annotation is downloaded but no content');
return;
}
if (lAnnotationViewsContent.length > 1)
{
console.log('Only displaying one annotation view at the moment, other annotation views will be discarded');
return;
}
// take the first annotation result, discarding others
const lAnnotationResult : AnnotationResultInterface = lAnnotationViewsContent[0];

// and add the annotation view to be displayed with standard depth
// we want to set the depth and visible state of the annotation
// mask is AnnotationInstanceState.AIS_DepthPriorityMask | AnnotationInstanceState.AIS_Visible
// but we want to be depth std and invisible
// state is AnnotationInstanceState.AIS_DepthPriorityStd | 0 = AnnotationInstanceState.AIS_DepthPriorityStd

const lMask : number = AnnotationInstanceState.AIS_DepthPriorityMask | AnnotationInstanceState.AIS_Visible;
const lState : number = AnnotationInstanceState.AIS_DepthPriorityStd;
const lRequestId : number = lAnnotationRenderer.addAnnotationView(lAnnotationResult.getAnnotationView(), lAnnotationResult.getAnnotationViewMatrix(), lMask, lState);
if (lRequestId < 0)
{
// weird error
console.log('The parsing procedure could not be started');
}
}

// what to do when an annotation is ready to be displayed ?
onAnnotationReady = (pEvent: InfiniteEvent, _pCallbackData: Object | undefined) : void =>
{
// fancy log
console.log('annotation view has finished parsing');

// take the parsing result
const lParsingResult : AnnotationViewParsingResultInterface = pEvent.attachments;
if (lParsingResult.annotationViewId < 0)
{
// this is an error
console.log('annotation view parsing has failed ' + lParsingResult.errorMessage);
return;
}

// store the annotation view id
lAnnotationViewId = lParsingResult.annotationViewId;

// create the list of annotation ids from lParsingResult.annotationIdStart to lParsingResult.annotationIdStart + lParsingResult.nbAnnotations - 1
const lAnnotationIds : number [] = [];
lAnnotationIds.length = lParsingResult.nbAnnotations;
let i : number;
for (i = 0; i < lParsingResult.nbAnnotations; ++i)
{
lAnnotationIds[i] = lParsingResult.annotationIdStart + i;
}
// mask for all rendering flags (except priority)
const lMask : number = AnnotationInstanceState.AIS_AppearThroughGeometry | AnnotationInstanceState.AIS_Highlight
| AnnotationInstanceState.AIS_Overprint | AnnotationInstanceState.AIS_Visible;
// state is visible (but we may add AnnotationInstanceState.AIS_AppearThroughGeometry just for fun)
const lState : number = AnnotationInstanceState.AIS_Visible; // | AnnotationInstanceState.AIS_AppearThroughGeometry

lAnnotationRenderer.setAnnotationRenderingState(lAnnotationIds, lMask, lState);
// you should now see the annotation on the next rendering
}

Please see Annotations for more explanations about annotations.
Events

Hierarchy

  • AnnotationViewParsingResultInterface

Properties

annotationIdStart: number

The starting id (-1 if the parsing was not successful) of the annotation contained in the given AnnotationViewInterface.

Annotations are identified by annotationIdStart, annotationIdStart + 1, ..., annotationIdStart + nbAnnotations -1.

annotationViewId: number

The annotation view id (-1 if the parsing was not successful) of the annotation view contained in the given AnnotationViewInterface.

errorMessage: string

An error message if relevant (or empty if no error).

nbAnnotations: number

The number of annotations (-1 if the parsing was not successful) inside the annotation view.

requestId: number

The request id that was returned by the call to addAnnotationView.

warnings: string[]

Warning messages. If some content was not handled, warnings are there.