UNPKG

@itwin/core-backend

Version:
89 lines 4.14 kB
/*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ /** @packageDocumentation * @module Elements */ import { GeometryParams, GeometryStreamBuilder, TextAnnotation } from "@itwin/core-common"; import { AnnotationElement2d, GraphicalElement3d } from "./Element"; import { produceTextAnnotationGeometry } from "./TextAnnotationGeometry"; function updateAnnotation(element, annotation, subCategory) { const builder = new GeometryStreamBuilder(); const params = new GeometryParams(element.category, subCategory); if (!builder.appendGeometryParamsChange(params)) { return false; } const props = produceTextAnnotationGeometry({ iModel: element.iModel, annotation }); if (!builder.appendTextBlock(props)) { return false; } element.geom = builder.geometryStream; element.jsonProperties.annotation = annotation.toJSON(); return true; } /** An element that displays textual content within a 2d model. * The text is stored as a [TextAnnotation]($common) from which the element's [geometry]($docs/learning/common/GeometryStream.md) and [Placement]($common) are computed. * @see [[setAnnotation]] to change the textual content. * @public @preview */ export class TextAnnotation2d extends AnnotationElement2d { /** @internal */ static get className() { return "TextAnnotation2d"; } constructor(props, iModel) { super(props, iModel); } static fromJSON(props, iModel) { return new TextAnnotation2d(props, iModel); } toJSON() { return super.toJSON(); } /** Extract the textual content, if present. * @see [[setAnnotation]] to change it. */ getAnnotation() { const json = this.jsonProperties.annotation; return json ? TextAnnotation.fromJSON(json) : undefined; } /** Change the textual content, updating the element's geometry and placement accordingly. * @see [[getAnnotation]] to extract the current annotation. * @param annotation The new annotation * @param subCategory If specified, the subcategory on which to define the geometry; otherwise, the default subcategory of the element's category is used. * @returns true if the annotation was successfully updated. */ setAnnotation(annotation, subCategory) { return updateAnnotation(this, annotation, subCategory); } } /** An element that displays textual content within a 3d model. * The text is stored as a [TextAnnotation]($common) from which the element's [geometry]($docs/learning/common/GeometryStream.md) and [Placement]($common) are computed. * @see [[setAnnotation]] to change the textual content. * @public @preview */ export class TextAnnotation3d extends GraphicalElement3d { /** @internal */ static get className() { return "TextAnnotation3d"; } constructor(props, iModel) { super(props, iModel); } static fromJSON(props, iModel) { return new TextAnnotation3d(props, iModel); } toJSON() { return super.toJSON(); } /** Extract the textual content, if present. * @see [[setAnnotation]] to change it. */ getAnnotation() { const json = this.jsonProperties.annotation; return json ? TextAnnotation.fromJSON(json) : undefined; } /** Change the textual content, updating the element's geometry and placement accordingly. * @see [[getAnnotation]] to extract the current annotation. * @param annotation The new annotation * @param subCategory If specified, the subcategory on which to define the geometry; otherwise, the default subcategory of the element's category is used. * @returns true if the annotation was successfully updated. */ setAnnotation(annotation, subCategory) { return updateAnnotation(this, annotation, subCategory); } } //# sourceMappingURL=TextAnnotationElement.js.map