@itwin/core-backend
Version:
iTwin.js backend components
94 lines • 4.38 kB
JavaScript
;
/*---------------------------------------------------------------------------------------------
* 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
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.TextAnnotation3d = exports.TextAnnotation2d = void 0;
const core_common_1 = require("@itwin/core-common");
const Element_1 = require("./Element");
const TextAnnotationGeometry_1 = require("./TextAnnotationGeometry");
function updateAnnotation(element, annotation, subCategory) {
const builder = new core_common_1.GeometryStreamBuilder();
const params = new core_common_1.GeometryParams(element.category, subCategory);
if (!builder.appendGeometryParamsChange(params)) {
return false;
}
const props = (0, TextAnnotationGeometry_1.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
*/
class TextAnnotation2d extends Element_1.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 ? core_common_1.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);
}
}
exports.TextAnnotation2d = TextAnnotation2d;
/** 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
*/
class TextAnnotation3d extends Element_1.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 ? core_common_1.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);
}
}
exports.TextAnnotation3d = TextAnnotation3d;
//# sourceMappingURL=TextAnnotationElement.js.map