@itwin/core-backend 5.3.0-dev.7 → 5.3.0-dev.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -1
- package/lib/cjs/IModelHost.d.ts +1 -2
- package/lib/cjs/IModelHost.d.ts.map +1 -1
- package/lib/cjs/IModelHost.js +9 -17
- package/lib/cjs/IModelHost.js.map +1 -1
- package/lib/cjs/TileStorage.d.ts +1 -1
- package/lib/cjs/TileStorage.d.ts.map +1 -1
- package/lib/cjs/TileStorage.js.map +1 -1
- package/lib/cjs/annotations/ElementDrivesTextAnnotation.d.ts +7 -1
- package/lib/cjs/annotations/ElementDrivesTextAnnotation.d.ts.map +1 -1
- package/lib/cjs/annotations/ElementDrivesTextAnnotation.js +25 -0
- package/lib/cjs/annotations/ElementDrivesTextAnnotation.js.map +1 -1
- package/lib/cjs/annotations/TextAnnotationElement.d.ts +20 -1
- package/lib/cjs/annotations/TextAnnotationElement.d.ts.map +1 -1
- package/lib/cjs/annotations/TextAnnotationElement.js +84 -2
- package/lib/cjs/annotations/TextAnnotationElement.js.map +1 -1
- package/lib/cjs/internal/annotations/fields.d.ts.map +1 -1
- package/lib/cjs/internal/annotations/fields.js +1 -0
- package/lib/cjs/internal/annotations/fields.js.map +1 -1
- package/lib/esm/IModelHost.d.ts +1 -2
- package/lib/esm/IModelHost.d.ts.map +1 -1
- package/lib/esm/IModelHost.js +10 -18
- package/lib/esm/IModelHost.js.map +1 -1
- package/lib/esm/TileStorage.d.ts +1 -1
- package/lib/esm/TileStorage.d.ts.map +1 -1
- package/lib/esm/TileStorage.js.map +1 -1
- package/lib/esm/annotations/ElementDrivesTextAnnotation.d.ts +7 -1
- package/lib/esm/annotations/ElementDrivesTextAnnotation.d.ts.map +1 -1
- package/lib/esm/annotations/ElementDrivesTextAnnotation.js +25 -0
- package/lib/esm/annotations/ElementDrivesTextAnnotation.js.map +1 -1
- package/lib/esm/annotations/TextAnnotationElement.d.ts +20 -1
- package/lib/esm/annotations/TextAnnotationElement.d.ts.map +1 -1
- package/lib/esm/annotations/TextAnnotationElement.js +86 -5
- package/lib/esm/annotations/TextAnnotationElement.js.map +1 -1
- package/lib/esm/internal/annotations/fields.d.ts.map +1 -1
- package/lib/esm/internal/annotations/fields.js +1 -0
- package/lib/esm/internal/annotations/fields.js.map +1 -1
- package/lib/esm/test/IModelHost.test.js +17 -11
- package/lib/esm/test/IModelHost.test.js.map +1 -1
- package/lib/esm/test/annotations/Fields.test.js +146 -51
- package/lib/esm/test/annotations/Fields.test.js.map +1 -1
- package/lib/esm/test/annotations/TextAnnotation.test.js +227 -2
- package/lib/esm/test/annotations/TextAnnotation.test.js.map +1 -1
- package/package.json +17 -19
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
/** @packageDocumentation
|
|
6
6
|
* @module Elements
|
|
7
7
|
*/
|
|
8
|
-
import { BisCodeSpec, Code, ElementGeometry, Placement2d, Placement3d, TextAnnotation, TextStyleSettings } from "@itwin/core-common";
|
|
8
|
+
import { BisCodeSpec, Code, ElementGeometry, Placement2d, Placement3d, TextAnnotation, TextStyleSettings, traverseTextBlockComponent } from "@itwin/core-common";
|
|
9
9
|
import { AnnotationElement2d, DefinitionElement, Drawing, GraphicalElement3d } from "../Element";
|
|
10
|
-
import { assert } from "@itwin/core-bentley";
|
|
10
|
+
import { assert, Id64 } from "@itwin/core-bentley";
|
|
11
11
|
import { layoutTextBlock, TextStyleResolver } from "./TextBlockLayout";
|
|
12
12
|
import { appendTextAnnotationGeometry } from "./TextAnnotationGeometry";
|
|
13
13
|
import { ElementDrivesTextAnnotation, TextAnnotationUsesTextStyleByDefault } from "./ElementDrivesTextAnnotation";
|
|
@@ -46,8 +46,10 @@ function migrateTextAnnotationData(oldData) {
|
|
|
46
46
|
// Place migration logic here.
|
|
47
47
|
throw new Error(`Migration for textAnnotationData from version ${oldData.version} to ${TEXT_ANNOTATION_JSON_VERSION} failed.`);
|
|
48
48
|
}
|
|
49
|
-
/** Parses, validates, and potentially migrates the text annotation data from a JSON string.
|
|
50
|
-
|
|
49
|
+
/** Parses, validates, and potentially migrates the text annotation data from a JSON string.
|
|
50
|
+
* @internal
|
|
51
|
+
*/
|
|
52
|
+
export function parseTextAnnotationData(json) {
|
|
51
53
|
if (!json)
|
|
52
54
|
return undefined;
|
|
53
55
|
return validateAndMigrateVersionedJSON(json, TEXT_ANNOTATION_JSON_VERSION, migrateTextAnnotationData);
|
|
@@ -215,6 +217,19 @@ export class TextAnnotation2d extends AnnotationElement2d /* implements ITextAnn
|
|
|
215
217
|
super.onUpdated(arg);
|
|
216
218
|
ElementDrivesTextAnnotation.updateFieldDependencies(arg.id, arg.iModel);
|
|
217
219
|
}
|
|
220
|
+
collectReferenceIds(referenceIds) {
|
|
221
|
+
super.collectReferenceIds(referenceIds);
|
|
222
|
+
collectReferenceIds(this, referenceIds);
|
|
223
|
+
}
|
|
224
|
+
/** @internal */
|
|
225
|
+
static onCloned(context, srcProps, dstProps) {
|
|
226
|
+
super.onCloned(context, srcProps, dstProps);
|
|
227
|
+
const srcElem = TextAnnotation2d.fromJSON(srcProps, context.sourceDb);
|
|
228
|
+
ElementDrivesTextAnnotation.remapFields(srcElem, context);
|
|
229
|
+
const anno = srcElem.getAnnotation();
|
|
230
|
+
dstProps.textAnnotationData = anno ? JSON.stringify({ version: TEXT_ANNOTATION_JSON_VERSION, data: anno.toJSON() }) : undefined;
|
|
231
|
+
remapTextStyle(context, srcElem, dstProps);
|
|
232
|
+
}
|
|
218
233
|
}
|
|
219
234
|
/** An element that displays textual content within a 3d model.
|
|
220
235
|
* The text is stored as a [TextAnnotation]($common) from which the element's [geometry]($docs/learning/common/GeometryStream.md) and [Placement]($common) are computed.
|
|
@@ -367,6 +382,40 @@ export class TextAnnotation3d extends GraphicalElement3d /* implements ITextAnno
|
|
|
367
382
|
super.onUpdated(arg);
|
|
368
383
|
ElementDrivesTextAnnotation.updateFieldDependencies(arg.id, arg.iModel);
|
|
369
384
|
}
|
|
385
|
+
collectReferenceIds(referenceIds) {
|
|
386
|
+
super.collectReferenceIds(referenceIds);
|
|
387
|
+
collectReferenceIds(this, referenceIds);
|
|
388
|
+
}
|
|
389
|
+
/** @internal */
|
|
390
|
+
static onCloned(context, srcProps, dstProps) {
|
|
391
|
+
super.onCloned(context, srcProps, dstProps);
|
|
392
|
+
const srcElem = TextAnnotation3d.fromJSON(srcProps, context.sourceDb);
|
|
393
|
+
ElementDrivesTextAnnotation.remapFields(srcElem, context);
|
|
394
|
+
const anno = srcElem.getAnnotation();
|
|
395
|
+
dstProps.textAnnotationData = anno ? JSON.stringify({ version: TEXT_ANNOTATION_JSON_VERSION, data: anno.toJSON() }) : undefined;
|
|
396
|
+
remapTextStyle(context, srcElem, dstProps);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
function remapTextStyle(context, srcElem, dstProps) {
|
|
400
|
+
const dstStyleId = AnnotationTextStyle.remapTextStyleId(srcElem.defaultTextStyle?.id ?? Id64.invalid, context);
|
|
401
|
+
dstProps.defaultTextStyle = Id64.isValid(dstStyleId) ? new TextAnnotationUsesTextStyleByDefault(dstStyleId).toJSON() : undefined;
|
|
402
|
+
}
|
|
403
|
+
function collectReferenceIds(elem, referenceIds) {
|
|
404
|
+
const style = elem.defaultTextStyle?.id;
|
|
405
|
+
if (style && Id64.isValidId64(style)) {
|
|
406
|
+
referenceIds.addElement(style);
|
|
407
|
+
}
|
|
408
|
+
const block = elem.getAnnotation()?.textBlock;
|
|
409
|
+
if (block) {
|
|
410
|
+
for (const { child } of traverseTextBlockComponent(block)) {
|
|
411
|
+
if (child.type === "field") {
|
|
412
|
+
const hostId = child.propertyHost.elementId;
|
|
413
|
+
if (Id64.isValidId64(hostId)) {
|
|
414
|
+
referenceIds.addElement(hostId);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
}
|
|
370
419
|
}
|
|
371
420
|
function getTextBlocks(elem) {
|
|
372
421
|
const annotation = elem.getAnnotation();
|
|
@@ -383,7 +432,6 @@ function updateTextBlocks(elem, textBlocks) {
|
|
|
383
432
|
}
|
|
384
433
|
annotation.textBlock = textBlocks[0].textBlock;
|
|
385
434
|
elem.setAnnotation(annotation);
|
|
386
|
-
elem.update();
|
|
387
435
|
}
|
|
388
436
|
/** The version of the JSON stored in `AnnotationTextStyleProps.settings` used by the code.
|
|
389
437
|
* Uses the same semantics as [ECVersion]($ecschema-metadata).
|
|
@@ -529,5 +577,38 @@ export class AnnotationTextStyle extends DefinitionElement {
|
|
|
529
577
|
return undefined;
|
|
530
578
|
return validateAndMigrateVersionedJSON(json, TEXT_STYLE_SETTINGS_JSON_VERSION, migrateTextStyleSettings);
|
|
531
579
|
}
|
|
580
|
+
/** When copying an element from one iModel to another, returns the Id of the AnnotationTextStyle in the `context`'s target iModel
|
|
581
|
+
* corresponding to `sourceTextStyleId`, or [Id64.invalid]($bentley) if no corresponding text style exists.
|
|
582
|
+
* If a text style with the same [Code]($common) exists in the target iModel, the style Id will be remapped to refer to that style.
|
|
583
|
+
* Otherwise, a copy of the style will be imported into the target iModel and its element Id returned.
|
|
584
|
+
* Implementations of [[ITextAnnotation]] should invoke this function when implementing their [[Element._onCloned]] method.
|
|
585
|
+
* @throws Error if an attempt to import the text style failed.
|
|
586
|
+
*/
|
|
587
|
+
static remapTextStyleId(sourceTextStyleId, context) {
|
|
588
|
+
// No remapping necessary if there's no text style or we're not copying to a different iModel.
|
|
589
|
+
if (!Id64.isValid(sourceTextStyleId) || !context.isBetweenIModels) {
|
|
590
|
+
return sourceTextStyleId;
|
|
591
|
+
}
|
|
592
|
+
// If the style's already been remapped, we're finished.
|
|
593
|
+
let dstStyleId = context.findTargetElementId(sourceTextStyleId);
|
|
594
|
+
if (Id64.isValid(dstStyleId)) {
|
|
595
|
+
return dstStyleId;
|
|
596
|
+
}
|
|
597
|
+
// Look up the style. It really ought to exist.
|
|
598
|
+
const srcStyle = context.sourceDb.elements.tryGetElement(sourceTextStyleId);
|
|
599
|
+
if (!srcStyle) {
|
|
600
|
+
return Id64.invalid;
|
|
601
|
+
}
|
|
602
|
+
// If a style with the same code exists in the target iModel, remap to that one.
|
|
603
|
+
dstStyleId = context.targetDb.elements.queryElementIdByCode(srcStyle.code);
|
|
604
|
+
if (undefined !== dstStyleId) {
|
|
605
|
+
return dstStyleId;
|
|
606
|
+
}
|
|
607
|
+
// Copy the style into the target iModel and remap its Id.
|
|
608
|
+
const dstStyleProps = context.cloneElement(srcStyle);
|
|
609
|
+
dstStyleId = context.targetDb.elements.insertElement(dstStyleProps);
|
|
610
|
+
context.remapElement(sourceTextStyleId, dstStyleId);
|
|
611
|
+
return dstStyleId;
|
|
612
|
+
}
|
|
532
613
|
}
|
|
533
614
|
//# sourceMappingURL=TextAnnotationElement.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextAnnotationElement.js","sourceRoot":"","sources":["../../../src/annotations/TextAnnotationElement.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAA4B,WAAW,EAAE,IAAI,EAAwD,eAAe,EAAgC,WAAW,EAAoB,WAAW,EAAoC,cAAc,EAAqE,iBAAiB,EAAyC,MAAM,oBAAoB,CAAC;AAEjZ,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,OAAO,EAAE,kBAAkB,EAAqC,MAAM,YAAY,CAAC;AACpI,OAAO,EAAE,MAAM,EAAc,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAE,4BAA4B,EAAE,MAAM,0BAA0B,CAAC;AACxE,OAAO,EAAE,2BAA2B,EAAE,oCAAoC,EAAkB,MAAM,+BAA+B,CAAC;AAElI,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AAEjC;;;EAGE;AACF,MAAM,CAAC,MAAM,4BAA4B,GAAG,OAAO,CAAC;AAEpD,SAAS,+BAA+B,CAC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AAC,sBAAsB,CAAC,IAAwB;QAC5D,IAAI,CAAC,IAAI;YAAE,OAAO,SAAS,CAAC;QAC5B,OAAO,+BAA+B,CAAyB,IAAI,EAAE,gCAAgC,EAAE,wBAAwB,CAAC,CAAC;IACnI,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Elements\n */\n\nimport { AnnotationTextStyleProps, BisCodeSpec, Code, CodeProps, CodeScopeProps, CodeSpec, ECVersionString, ElementGeometry, ElementGeometryBuilderParams, Placement2d, Placement2dProps, Placement3d, Placement3dProps, PlacementProps, TextAnnotation, TextAnnotation2dProps, TextAnnotation3dProps, TextAnnotationProps, TextStyleSettings, TextStyleSettingsProps, VersionedJSON } from \"@itwin/core-common\";\nimport { IModelDb } from \"../IModelDb\";\nimport { AnnotationElement2d, DefinitionElement, Drawing, GraphicalElement3d, OnElementIdArg, OnElementPropsArg } from \"../Element\";\nimport { assert, Id64String } from \"@itwin/core-bentley\";\nimport { layoutTextBlock, TextStyleResolver } from \"./TextBlockLayout\";\nimport { appendTextAnnotationGeometry } from \"./TextAnnotationGeometry\";\nimport { ElementDrivesTextAnnotation, TextAnnotationUsesTextStyleByDefault, TextBlockAndId } from \"./ElementDrivesTextAnnotation\";\nimport { CustomHandledProperty, DeserializeEntityArgs, ECSqlRow } from \"../Entity\";\nimport * as semver from \"semver\";\n\n/** The version of the JSON stored in `TextAnnotation2d/3dProps.textAnnotationData` used by the code.\n * Uses the same semantics as [ECVersion]($ecschema-metadata).\n * @internal\n*/\nexport const TEXT_ANNOTATION_JSON_VERSION = \"1.0.0\";\n\nfunction validateAndMigrateVersionedJSON<T>(\n json: string,\n currentVersion: ECVersionString,\n migrate: (old: VersionedJSON<T>) => T\n): VersionedJSON<T> | undefined {\n let parsed;\n try {\n parsed = JSON.parse(json) as VersionedJSON<T>;\n } catch {\n return undefined;\n }\n\n const version = parsed.version;\n if (typeof version !== \"string\" || !semver.valid(version))\n throw new Error(\"JSON version is missing or invalid.\");\n\n if (typeof parsed.data !== \"object\" || parsed.data === null)\n throw new Error(\"JSON data is missing or invalid.\");\n\n // Newer\n if (semver.gt(version, currentVersion))\n throw new Error(`JSON version ${parsed.version} is newer than supported version ${currentVersion}. Application update required to understand data.`);\n\n // Older\n if (semver.lt(version, currentVersion)) {\n parsed.data = migrate(parsed);\n parsed.version = currentVersion;\n }\n\n return parsed;\n}\n\nfunction migrateTextAnnotationData(oldData: VersionedJSON<TextAnnotationProps>): TextAnnotationProps {\n if (oldData.version === TEXT_ANNOTATION_JSON_VERSION) return oldData.data;\n\n // Place migration logic here.\n\n throw new Error(`Migration for textAnnotationData from version ${oldData.version} to ${TEXT_ANNOTATION_JSON_VERSION} failed.`);\n}\n\n/** Parses, validates, and potentially migrates the text annotation data from a JSON string. */\nfunction parseTextAnnotationData(json: string | undefined): VersionedJSON<TextAnnotationProps> | undefined {\n if (!json) return undefined;\n\n return validateAndMigrateVersionedJSON<TextAnnotationProps>(json, TEXT_ANNOTATION_JSON_VERSION, migrateTextAnnotationData);\n}\n\nfunction getElementGeometryBuilderParams(iModel: IModelDb, modelId: Id64String, categoryId: Id64String, _placementProps: PlacementProps, annotationProps?: TextAnnotationProps, textStyleId?: Id64String, _subCategory?: Id64String): ElementGeometryBuilderParams {\n const textBlock = TextAnnotation.fromJSON(annotationProps).textBlock;\n const textStyleResolver = new TextStyleResolver({textBlock, textStyleId: textStyleId ?? \"\", iModel});\n const layout = layoutTextBlock({ iModel, textBlock, textStyleResolver });\n const builder = new ElementGeometry.Builder();\n let scaleFactor = 1;\n const element = iModel.elements.getElement(modelId);\n if (element instanceof Drawing)\n scaleFactor = element.scaleFactor;\n appendTextAnnotationGeometry({ layout, textStyleResolver, scaleFactor, annotationProps: annotationProps ?? {}, builder, categoryId });\n\n return { entryArray: builder.entries };\n}\n\n/** Arguments supplied when creating a [[TextAnnotation2d]].\n * @beta\n */\nexport interface TextAnnotation2dCreateArgs {\n /** The category ID for the annotation. */\n category: Id64String;\n /** The model ID where the annotation will be placed. */\n model: Id64String;\n /** The placement properties for the annotation. */\n placement: Placement2dProps;\n /** The default text style ID for the annotation. */\n defaultTextStyleId?: Id64String;\n /** Optional [[TextAnnotation]] JSON representation used to create the `TextAnnotation2d`. Essentially an empty element if not provided. */\n textAnnotationProps?: TextAnnotationProps;\n /** Optional code for the element. */\n code?: CodeProps;\n}\n\n/** Arguments supplied when creating a [[TextAnnotation3d]].\n * @beta\n */\nexport interface TextAnnotation3dCreateArgs {\n /** The category ID for the annotation. */\n category: Id64String;\n /** The model ID where the annotation will be placed. */\n model: Id64String;\n /** The placement properties for the annotation. */\n placement: Placement3dProps;\n /** The default text style ID for the annotation. */\n defaultTextStyleId?: Id64String;\n /** Optional [[TextAnnotation]] JSON representation used to create the `TextAnnotation3d`. Essentially an empty element if not provided. */\n textAnnotationProps?: TextAnnotationProps;\n /** Optional code for the element. */\n code?: CodeProps;\n}\n\n/** An element that displays textual content within a 2d model.\n * The text is stored as a [TextAnnotation]($common) from which the element's [geometry]($docs/learning/common/GeometryStream.md) and [Placement]($common) are computed.\n * @see [[setAnnotation]] to change the textual content.\n * @public @preview\n */\nexport class TextAnnotation2d extends AnnotationElement2d /* implements ITextAnnotation */ {\n /** @internal */\n public static override get className(): string { return \"TextAnnotation2d\"; }\n /**\n * The default [[AnnotationTextStyle]] used by the TextAnnotation2d.\n * @beta\n */\n public defaultTextStyle?: TextAnnotationUsesTextStyleByDefault;\n /** The data associated with the text annotation. */\n private _textAnnotationProps?: TextAnnotationProps;\n\n /** Extract the textual content, if present.\n * @see [[setAnnotation]] to change it.\n */\n public getAnnotation(): TextAnnotation | undefined {\n return this._textAnnotationProps ? TextAnnotation.fromJSON(this._textAnnotationProps) : undefined;\n }\n\n /** Change the textual content of the `TextAnnotation2d`.\n * @see [[getAnnotation]] to extract the current annotation.\n * @param annotation The new annotation\n */\n public setAnnotation(annotation: TextAnnotation) {\n this._textAnnotationProps = annotation.toJSON();\n }\n\n protected constructor(props: TextAnnotation2dProps, iModel: IModelDb) {\n super(props, iModel);\n if (props.defaultTextStyle) {\n this.defaultTextStyle = new TextAnnotationUsesTextStyleByDefault(props.defaultTextStyle.id);\n }\n this._textAnnotationProps = parseTextAnnotationData(props.textAnnotationData)?.data;\n }\n\n /** Creates a new instance of `TextAnnotation2d` from its JSON representation. */\n public static fromJSON(props: TextAnnotation2dProps, iModel: IModelDb): TextAnnotation2d {\n return new TextAnnotation2d(props, iModel);\n }\n\n /**\n * Converts the current `TextAnnotation2d` instance to its JSON representation.\n * It also computes the `elementGeometryBuilderParams` property used to create the GeometryStream.\n * @inheritdoc\n */\n public override toJSON(): TextAnnotation2dProps {\n const props = super.toJSON() as TextAnnotation2dProps;\n props.textAnnotationData = this._textAnnotationProps ? JSON.stringify({ version: TEXT_ANNOTATION_JSON_VERSION, data: this._textAnnotationProps }) : undefined;\n if (this._textAnnotationProps) {\n props.elementGeometryBuilderParams = getElementGeometryBuilderParams(this.iModel, this.model, this.category, this.placement, this._textAnnotationProps, this.defaultTextStyle ? this.defaultTextStyle.id : undefined);\n }\n\n return props;\n }\n\n /** Creates a new `TextAnnotation2d` instance with the specified properties.\n * @param iModelDb The iModel.\n * @param arg The arguments for creating the TextAnnotation2d.\n * @beta\n */\n public static create(iModelDb: IModelDb, arg: TextAnnotation2dCreateArgs): TextAnnotation2d {\n const elementProps: TextAnnotation2dProps = {\n classFullName: this.classFullName,\n textAnnotationData: arg.textAnnotationProps ? JSON.stringify({ version: TEXT_ANNOTATION_JSON_VERSION, data: arg.textAnnotationProps }) : undefined,\n defaultTextStyle: arg.defaultTextStyleId ? new TextAnnotationUsesTextStyleByDefault(arg.defaultTextStyleId).toJSON() : undefined,\n placement: arg.placement,\n model: arg.model,\n category: arg.category,\n code: arg.code ?? Code.createEmpty(),\n };\n return new this(elementProps, iModelDb);\n }\n\n /**\n * Updates the geometry of the TextAnnotation2d on insert and validates version.\n * @inheritdoc\n * @beta\n */\n protected static override onInsert(arg: OnElementPropsArg): void {\n super.onInsert(arg);\n this.validateVersionAndUpdateGeometry(arg);\n }\n\n /**\n * Updates the geometry of the TextAnnotation2d on update and validates version.\n * @inheritdoc\n * @beta\n */\n protected static override onUpdate(arg: OnElementPropsArg): void {\n super.onUpdate(arg);\n this.validateVersionAndUpdateGeometry(arg);\n }\n\n /**\n * Populates the `elementGeometryBuilderParams` property in the [TextAnnotation2dProps]($common).\n * Only does this if the `elementGeometryBuilderParams` is not already set and if there is actually a text annotation to produce geometry for.\n * Also, validates the version of the text annotation data and migrates it if necessary.\n * @beta\n */\n protected static validateVersionAndUpdateGeometry(arg: OnElementPropsArg): void {\n const props = arg.props as TextAnnotation2dProps;\n const textAnnotationData = parseTextAnnotationData(props.textAnnotationData);\n if (!props.elementGeometryBuilderParams && textAnnotationData) {\n props.elementGeometryBuilderParams = getElementGeometryBuilderParams(arg.iModel, props.model, props.category, props.placement ?? Placement2d.fromJSON(), textAnnotationData.data, props.defaultTextStyle?.id);\n }\n }\n\n /**\n * TextAnnotation2d custom HandledProps include 'textAnnotationData'.\n * @inheritdoc\n * @internal\n */\n protected static override readonly _customHandledProps: CustomHandledProperty[] = [\n { propertyName: \"textAnnotationData\", source: \"Class\" },\n ];\n\n /**\n * TextAnnotation2d deserializes 'textAnnotationData'.\n * @inheritdoc\n * @beta\n */\n public static override deserialize(props: DeserializeEntityArgs): TextAnnotation2dProps {\n const elProps = super.deserialize(props) as TextAnnotation2dProps;\n const textAnnotationData = parseTextAnnotationData(props.row.textAnnotationData);\n if (textAnnotationData) {\n elProps.textAnnotationData = JSON.stringify(textAnnotationData);\n }\n return elProps;\n }\n\n /**\n * TextAnnotation2d serializes 'textAnnotationData'.\n * @inheritdoc\n * @beta\n */\n public static override serialize(props: TextAnnotation2dProps, iModel: IModelDb): ECSqlRow {\n const inst = super.serialize(props, iModel);\n if (props.textAnnotationData !== undefined) {\n inst.textAnnotationData = props.textAnnotationData;\n }\n return inst;\n }\n\n /** @internal */\n public getTextBlocks(): Iterable<TextBlockAndId> {\n return getTextBlocks(this);\n }\n\n /** @internal */\n public updateTextBlocks(textBlocks: TextBlockAndId[]): void {\n return updateTextBlocks(this, textBlocks);\n }\n\n /** @internal */\n public static override onInserted(arg: OnElementIdArg): void {\n super.onInserted(arg);\n ElementDrivesTextAnnotation.updateFieldDependencies(arg.id, arg.iModel);\n }\n\n /** @internal */\n public static override onUpdated(arg: OnElementIdArg): void {\n super.onUpdated(arg);\n ElementDrivesTextAnnotation.updateFieldDependencies(arg.id, arg.iModel);\n }\n}\n\n/** An element that displays textual content within a 3d model.\n * The text is stored as a [TextAnnotation]($common) from which the element's [geometry]($docs/learning/common/GeometryStream.md) and [Placement]($common) are computed.\n * @see [[setAnnotation]] to change the textual content.\n * @public @preview\n */\nexport class TextAnnotation3d extends GraphicalElement3d /* implements ITextAnnotation */ {\n /** @internal */\n public static override get className(): string { return \"TextAnnotation3d\"; }\n /**\n * The default [[AnnotationTextStyle]] used by the TextAnnotation3d.\n * @beta\n */\n public defaultTextStyle?: TextAnnotationUsesTextStyleByDefault;\n /** The data associated with the text annotation. */\n private _textAnnotationProps?: TextAnnotationProps;\n\n /** Extract the textual content, if present.\n * @see [[setAnnotation]] to change it.\n */\n public getAnnotation(): TextAnnotation | undefined {\n return this._textAnnotationProps ? TextAnnotation.fromJSON(this._textAnnotationProps) : undefined;\n }\n\n /** Change the textual content of the `TextAnnotation3d`.\n * @see [[getAnnotation]] to extract the current annotation.\n * @param annotation The new annotation\n */\n public setAnnotation(annotation: TextAnnotation) {\n this._textAnnotationProps = annotation.toJSON();\n }\n\n protected constructor(props: TextAnnotation3dProps, iModel: IModelDb) {\n super(props, iModel);\n if (props.defaultTextStyle) {\n this.defaultTextStyle = new TextAnnotationUsesTextStyleByDefault(props.defaultTextStyle.id);\n }\n this._textAnnotationProps = parseTextAnnotationData(props.textAnnotationData)?.data;\n }\n\n /** Creates a new instance of `TextAnnotation3d` from its JSON representation. */\n public static fromJSON(props: TextAnnotation3dProps, iModel: IModelDb): TextAnnotation3d {\n return new TextAnnotation3d(props, iModel);\n }\n\n /**\n * Converts the current `TextAnnotation3d` instance to its JSON representation.\n * It also computes the `elementGeometryBuilderParams` property used to create the GeometryStream.\n * @inheritdoc\n */\n public override toJSON(): TextAnnotation3dProps {\n const props = super.toJSON() as TextAnnotation3dProps;\n props.textAnnotationData = this._textAnnotationProps ? JSON.stringify({ version: TEXT_ANNOTATION_JSON_VERSION, data: this._textAnnotationProps }) : undefined;\n if (this._textAnnotationProps) {\n props.elementGeometryBuilderParams = getElementGeometryBuilderParams(this.iModel, this.model, this.category, this.placement, this._textAnnotationProps, this.defaultTextStyle ? this.defaultTextStyle.id : undefined);\n }\n\n return props;\n }\n\n /** Creates a new `TextAnnotation3d` instance with the specified properties.\n * @param iModelDb The iModel.\n * @param arg The arguments for creating the TextAnnotation3d.\n * @beta\n */\n public static create(iModelDb: IModelDb, arg: TextAnnotation3dCreateArgs): TextAnnotation3d {\n const elementProps: TextAnnotation3dProps = {\n classFullName: this.classFullName,\n textAnnotationData: arg.textAnnotationProps ? JSON.stringify({ version: TEXT_ANNOTATION_JSON_VERSION, data: arg.textAnnotationProps }) : undefined,\n defaultTextStyle: arg.defaultTextStyleId ? new TextAnnotationUsesTextStyleByDefault(arg.defaultTextStyleId).toJSON() : undefined,\n placement: arg.placement,\n model: arg.model,\n category: arg.category,\n code: arg.code ?? Code.createEmpty(),\n };\n return new this(elementProps, iModelDb);\n }\n\n /**\n * Updates the geometry of the TextAnnotation3d on insert and validates version..\n * @inheritdoc\n * @beta\n */\n protected static override onInsert(arg: OnElementPropsArg): void {\n super.onInsert(arg);\n this.validateVersionAndUpdateGeometry(arg);\n }\n\n /**\n * Updates the geometry of the TextAnnotation3d on update and validates version..\n * @inheritdoc\n * @beta\n */\n protected static override onUpdate(arg: OnElementPropsArg): void {\n super.onUpdate(arg);\n this.validateVersionAndUpdateGeometry(arg);\n }\n\n /**\n * Populates the `elementGeometryBuilderParams` property in the [TextAnnotation3dProps]($common).\n * Only does this if the `elementGeometryBuilderParams` is not already set and if there is actually a text annotation to produce geometry for.\n * Also, validates the version of the text annotation data and migrates it if necessary.\n * @beta\n */\n protected static validateVersionAndUpdateGeometry(arg: OnElementPropsArg): void {\n const props = arg.props as TextAnnotation3dProps;\n const textAnnotationData = parseTextAnnotationData(props.textAnnotationData);\n if (!props.elementGeometryBuilderParams && textAnnotationData) {\n props.elementGeometryBuilderParams = getElementGeometryBuilderParams(arg.iModel, props.model, props.category, props.placement ?? Placement3d.fromJSON(), textAnnotationData.data, props.defaultTextStyle?.id);\n }\n }\n\n /**\n * TextAnnotation3d custom HandledProps include 'textAnnotationData'.\n * @inheritdoc\n * @internal\n */\n protected static override readonly _customHandledProps: CustomHandledProperty[] = [\n { propertyName: \"textAnnotationData\", source: \"Class\" },\n ];\n\n /**\n * TextAnnotation3d deserializes 'textAnnotationData'.\n * @inheritdoc\n * @beta\n */\n public static override deserialize(props: DeserializeEntityArgs): TextAnnotation3dProps {\n const elProps = super.deserialize(props) as TextAnnotation3dProps;\n const textAnnotationData = parseTextAnnotationData(props.row.textAnnotationData);\n if (textAnnotationData) {\n elProps.textAnnotationData = JSON.stringify(textAnnotationData);\n }\n return elProps;\n }\n\n /**\n * TextAnnotation3d serializes 'textAnnotationData'.\n * @inheritdoc\n * @beta\n */\n public static override serialize(props: TextAnnotation3dProps, iModel: IModelDb): ECSqlRow {\n const inst = super.serialize(props, iModel);\n if (props.textAnnotationData !== undefined) {\n inst.textAnnotationData = props.textAnnotationData;\n }\n return inst;\n }\n\n /** @internal */\n public getTextBlocks(): Iterable<TextBlockAndId> {\n return getTextBlocks(this);\n }\n\n /** @internal */\n public updateTextBlocks(textBlocks: TextBlockAndId[]): void {\n return updateTextBlocks(this, textBlocks);\n }\n\n /** @internal */\n public static override onInserted(arg: OnElementIdArg): void {\n super.onInserted(arg);\n ElementDrivesTextAnnotation.updateFieldDependencies(arg.id, arg.iModel);\n }\n\n /** @internal */\n public static override onUpdated(arg: OnElementIdArg): void {\n super.onUpdated(arg);\n ElementDrivesTextAnnotation.updateFieldDependencies(arg.id, arg.iModel);\n }\n}\n\nfunction getTextBlocks(elem: TextAnnotation2d | TextAnnotation3d): Iterable<TextBlockAndId> {\n const annotation = elem.getAnnotation();\n return annotation ? [{ textBlock: annotation.textBlock, id: undefined }] : [];\n}\n\nfunction updateTextBlocks(elem: TextAnnotation2d | TextAnnotation3d, textBlocks: TextBlockAndId[]): void {\n assert(textBlocks.length === 1);\n assert(textBlocks[0].id === undefined);\n\n const annotation = elem.getAnnotation();\n if (!annotation) {\n // We must obtain the TextBlockAndId from the element in the first place, so the only way we could end up here is if\n // somebody removed the text annotation after we called getTextBlocks. That's gotta be a mistake.\n throw new Error(\"Text annotation element has no text\");\n }\n\n annotation.textBlock = textBlocks[0].textBlock;\n\n elem.setAnnotation(annotation);\n elem.update();\n}\n\n/** The version of the JSON stored in `AnnotationTextStyleProps.settings` used by the code.\n * Uses the same semantics as [ECVersion]($ecschema-metadata).\n * @internal\n*/\nexport const TEXT_STYLE_SETTINGS_JSON_VERSION = \"1.0.0\";\n\nfunction migrateTextStyleSettings(oldData: VersionedJSON<TextStyleSettingsProps>): TextStyleSettingsProps {\n if (oldData.version === TEXT_STYLE_SETTINGS_JSON_VERSION) return oldData.data;\n\n // Place migration logic here.\n\n throw new Error(`Migration for settings from version ${oldData.version} to ${TEXT_STYLE_SETTINGS_JSON_VERSION} failed.`);\n}\n\n/** Arguments supplied when creating an [[AnnotationTextStyle]].\n * @beta\n */\nexport interface TextStyleCreateArgs {\n /** The ID of the [[DefinitionModel]]. */\n definitionModelId: Id64String;\n /** The name to assign to the [[AnnotationTextStyle]]. */\n name: string;\n /** Optional text style settings used to create the [[AnnotationTextStyle]]. Default settings will be used if not provided. */\n settings?: TextStyleSettingsProps;\n /** Optional description for the [[AnnotationTextStyle]]. */\n description?: string;\n}\n\n/**\n * The definition element that holds text style information.\n * The style is stored as a [TextStyleSettings]($common).\n * @beta\n */\nexport class AnnotationTextStyle extends DefinitionElement {\n /** @internal */\n public static override get className(): string { return \"AnnotationTextStyle\"; }\n /**\n * Optional text describing the `AnnotationTextStyle`.\n */\n public description?: string;\n /**\n * The text style settings for the `AnnotationTextStyle`.\n * @see [[TextStyleSettings]] for more information.\n */\n public settings: TextStyleSettings;\n\n protected constructor(props: AnnotationTextStyleProps, iModel: IModelDb) {\n super(props, iModel);\n this.description = props.description;\n const settingsProps = AnnotationTextStyle.parseTextStyleSettings(props.settings);\n this.settings = TextStyleSettings.fromJSON(settingsProps?.data);\n }\n\n /**\n * Creates a Code for an `AnnotationTextStyle` given a name that is meant to be unique within the scope of the specified DefinitionModel.\n *\n * @param iModel - The IModelDb.\n * @param definitionModelId - The ID of the DefinitionModel that contains the AnnotationTextStyle and provides the scope for its name.\n * @param name - The AnnotationTextStyle name.\n * @beta\n */\n public static createCode(iModel: IModelDb, definitionModelId: CodeScopeProps, name: string): Code {\n const codeSpec: CodeSpec = iModel.codeSpecs.getByName(BisCodeSpec.annotationTextStyle);\n return new Code({ spec: codeSpec.id, scope: definitionModelId, value: name });\n }\n\n /**\n * Creates a new instance of `AnnotationTextStyle` with the specified properties.\n *\n * @param iModelDb - The iModelDb.\n * @param arg - The arguments for creating the AnnotationTextStyle.\n * @beta\n */\n public static create(iModelDb: IModelDb, arg: TextStyleCreateArgs): AnnotationTextStyle {\n const props: AnnotationTextStyleProps = {\n classFullName: this.classFullName,\n model: arg.definitionModelId,\n code: this.createCode(iModelDb, arg.definitionModelId, arg.name).toJSON(),\n description: arg.description,\n settings: arg.settings ? JSON.stringify({version: TEXT_STYLE_SETTINGS_JSON_VERSION, data: arg.settings}) : undefined,\n }\n return new this(props, iModelDb);\n }\n\n /**\n * Converts the current `AnnotationTextStyle` instance to its JSON representation.\n * @inheritdoc\n */\n public override toJSON(): AnnotationTextStyleProps {\n const props = super.toJSON() as AnnotationTextStyleProps;\n props.description = this.description;\n props.settings = JSON.stringify({version: TEXT_STYLE_SETTINGS_JSON_VERSION, data: this.settings.toJSON()});\n return props;\n }\n\n /** Creates a new instance of `AnnotationTextStyle` from its JSON representation. */\n public static fromJSON(props: AnnotationTextStyleProps, iModel: IModelDb): AnnotationTextStyle {\n return new AnnotationTextStyle(props, iModel);\n }\n\n /**\n * Validates that the AnnotationTextStyle's settings are valid before insert.\n * @inheritdoc\n * @beta\n */\n protected static override onInsert(arg: OnElementPropsArg): void {\n super.onInsert(arg);\n this.validateSettings(arg.props as AnnotationTextStyleProps);\n }\n\n /**\n * Validates that the AnnotationTextStyle's settings are valid before update.\n * @inheritdoc\n * @beta\n */\n protected static override onUpdate(arg: OnElementPropsArg): void {\n super.onUpdate(arg);\n this.validateSettings(arg.props as AnnotationTextStyleProps);\n }\n\n private static validateSettings(props: AnnotationTextStyleProps): void {\n const settingProps = AnnotationTextStyle.parseTextStyleSettings(props.settings);\n if (!settingProps) return;\n const settings = TextStyleSettings.fromJSON(settingProps.data);\n const errors = settings.getValidationErrors();\n if (errors.length > 0) {\n throw new Error(`Invalid AnnotationTextStyle settings: ${errors.join(\", \")}`);\n }\n }\n\n /**\n * AnnotationTextStyle custom HandledProps include 'settings'.\n * @inheritdoc\n * @beta\n */\n protected static override readonly _customHandledProps: CustomHandledProperty[] = [\n { propertyName: \"settings\", source: \"Class\" },\n ];\n\n /**\n * AnnotationTextStyle deserializes 'settings'.\n * @inheritdoc\n * @beta\n */\n public static override deserialize(props: DeserializeEntityArgs): AnnotationTextStyleProps {\n const elProps = super.deserialize(props) as AnnotationTextStyleProps;\n const settings = this.parseTextStyleSettings(props.row.settings);\n if (settings) {\n elProps.settings = JSON.stringify(settings);\n }\n return elProps;\n }\n\n /**\n * AnnotationTextStyle serializes 'settings'.\n * @inheritdoc\n * @beta\n */\n public static override serialize(props: AnnotationTextStyleProps, iModel: IModelDb): ECSqlRow {\n const inst = super.serialize(props, iModel);\n if (props.settings !== undefined) {\n inst.settings = props.settings;\n }\n return inst;\n }\n\n /** Parses, validates, and potentially migrates the text style settings data from a JSON string. */\n private static parseTextStyleSettings(json: string | undefined): VersionedJSON<TextStyleSettingsProps> | undefined {\n if (!json) return undefined;\n return validateAndMigrateVersionedJSON<TextStyleSettingsProps>(json, TEXT_STYLE_SETTINGS_JSON_VERSION, migrateTextStyleSettings);\n }\n}"]}
|
|
1
|
+
{"version":3,"file":"TextAnnotationElement.js","sourceRoot":"","sources":["../../../src/annotations/TextAnnotationElement.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAA4B,WAAW,EAAE,IAAI,EAAwD,eAAe,EAAoD,WAAW,EAAoB,WAAW,EAAoC,cAAc,EAAqE,iBAAiB,EAA0B,0BAA0B,EAAiB,MAAM,oBAAoB,CAAC;AAEjc,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,OAAO,EAAE,kBAAkB,EAAqC,MAAM,YAAY,CAAC;AACpI,OAAO,EAAE,MAAM,EAAE,IAAI,EAAc,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAE,4BAA4B,EAAE,MAAM,0BAA0B,CAAC;AACxE,OAAO,EAAE,2BAA2B,EAAE,oCAAoC,EAAkB,MAAM,+BAA+B,CAAC;AAGlI,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AAEjC;;;EAGE;AACF,MAAM,CAAC,MAAM,4BAA4B,GAAG,OAAO,CAAC;AAEpD,SAAS,+BAA+B,CACtC,IAAY,EACZ,cAA+B,EAC/B,OAAqC;IAErC,IAAI,MAAM,CAAC;IACX,IAAI,CAAC;QACH,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAqB,CAAC;IAChD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC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,EAAE,gCAAgC,EAAE,wBAAwB,CAAC,CAAC;IACnI,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,gBAAgB,CAAC,iBAA6B,EAAE,OAAkC;QAC9F,8FAA8F;QAC9F,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE,CAAC;YAClE,OAAO,iBAAiB,CAAC;QAC3B,CAAC;QAED,wDAAwD;QACxD,IAAI,UAAU,GAA2B,OAAO,CAAC,mBAAmB,CAAC,iBAAiB,CAAC,CAAC;QACxF,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;YAC7B,OAAO,UAAU,CAAC;QACpB,CAAC;QAED,+CAA+C;QAC/C,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,aAAa,CAAsB,iBAAiB,CAAC,CAAC;QACjG,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,OAAO,IAAI,CAAC,OAAO,CAAC;QACtB,CAAC;QAED,gFAAgF;QAChF,UAAU,GAAG,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,oBAAoB,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC3E,IAAI,SAAS,KAAK,UAAU,EAAE,CAAC;YAC7B,OAAO,UAAU,CAAC;QACpB,CAAC;QAED,0DAA0D;QAC1D,MAAM,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;QACrD,UAAU,GAAG,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,aAAa,CAAC,aAAa,CAAC,CAAC;QACpE,OAAO,CAAC,YAAY,CAAC,iBAAiB,EAAE,UAAU,CAAC,CAAC;QACpD,OAAO,UAAU,CAAC;IACpB,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Elements\n */\n\nimport { AnnotationTextStyleProps, BisCodeSpec, Code, CodeProps, CodeScopeProps, CodeSpec, ECVersionString, ElementGeometry, ElementGeometryBuilderParams, EntityReferenceSet, Placement2d, Placement2dProps, Placement3d, Placement3dProps, PlacementProps, TextAnnotation, TextAnnotation2dProps, TextAnnotation3dProps, TextAnnotationProps, TextStyleSettings, TextStyleSettingsProps, traverseTextBlockComponent, VersionedJSON } from \"@itwin/core-common\";\nimport { IModelDb } from \"../IModelDb\";\nimport { AnnotationElement2d, DefinitionElement, Drawing, GraphicalElement3d, OnElementIdArg, OnElementPropsArg } from \"../Element\";\nimport { assert, Id64, Id64String } from \"@itwin/core-bentley\";\nimport { layoutTextBlock, TextStyleResolver } from \"./TextBlockLayout\";\nimport { appendTextAnnotationGeometry } from \"./TextAnnotationGeometry\";\nimport { ElementDrivesTextAnnotation, TextAnnotationUsesTextStyleByDefault, TextBlockAndId } from \"./ElementDrivesTextAnnotation\";\nimport { IModelElementCloneContext } from \"../IModelElementCloneContext\";\nimport { CustomHandledProperty, DeserializeEntityArgs, ECSqlRow } from \"../Entity\";\nimport * as semver from \"semver\";\n\n/** The version of the JSON stored in `TextAnnotation2d/3dProps.textAnnotationData` used by the code.\n * Uses the same semantics as [ECVersion]($ecschema-metadata).\n * @internal\n*/\nexport const TEXT_ANNOTATION_JSON_VERSION = \"1.0.0\";\n\nfunction validateAndMigrateVersionedJSON<T>(\n json: string,\n currentVersion: ECVersionString,\n migrate: (old: VersionedJSON<T>) => T\n): VersionedJSON<T> | undefined {\n let parsed;\n try {\n parsed = JSON.parse(json) as VersionedJSON<T>;\n } catch {\n return undefined;\n }\n\n const version = parsed.version;\n if (typeof version !== \"string\" || !semver.valid(version))\n throw new Error(\"JSON version is missing or invalid.\");\n\n if (typeof parsed.data !== \"object\" || parsed.data === null)\n throw new Error(\"JSON data is missing or invalid.\");\n\n // Newer\n if (semver.gt(version, currentVersion))\n throw new Error(`JSON version ${parsed.version} is newer than supported version ${currentVersion}. Application update required to understand data.`);\n\n // Older\n if (semver.lt(version, currentVersion)) {\n parsed.data = migrate(parsed);\n parsed.version = currentVersion;\n }\n\n return parsed;\n}\n\nfunction migrateTextAnnotationData(oldData: VersionedJSON<TextAnnotationProps>): TextAnnotationProps {\n if (oldData.version === TEXT_ANNOTATION_JSON_VERSION) return oldData.data;\n\n // Place migration logic here.\n\n throw new Error(`Migration for textAnnotationData from version ${oldData.version} to ${TEXT_ANNOTATION_JSON_VERSION} failed.`);\n}\n\n/** Parses, validates, and potentially migrates the text annotation data from a JSON string.\n * @internal\n */\nexport function parseTextAnnotationData(json: string | undefined): VersionedJSON<TextAnnotationProps> | undefined {\n if (!json) return undefined;\n\n return validateAndMigrateVersionedJSON<TextAnnotationProps>(json, TEXT_ANNOTATION_JSON_VERSION, migrateTextAnnotationData);\n}\n\nfunction getElementGeometryBuilderParams(iModel: IModelDb, modelId: Id64String, categoryId: Id64String, _placementProps: PlacementProps, annotationProps?: TextAnnotationProps, textStyleId?: Id64String, _subCategory?: Id64String): ElementGeometryBuilderParams {\n const textBlock = TextAnnotation.fromJSON(annotationProps).textBlock;\n const textStyleResolver = new TextStyleResolver({textBlock, textStyleId: textStyleId ?? \"\", iModel});\n const layout = layoutTextBlock({ iModel, textBlock, textStyleResolver });\n const builder = new ElementGeometry.Builder();\n let scaleFactor = 1;\n const element = iModel.elements.getElement(modelId);\n if (element instanceof Drawing)\n scaleFactor = element.scaleFactor;\n appendTextAnnotationGeometry({ layout, textStyleResolver, scaleFactor, annotationProps: annotationProps ?? {}, builder, categoryId });\n\n return { entryArray: builder.entries };\n}\n\n/** Arguments supplied when creating a [[TextAnnotation2d]].\n * @beta\n */\nexport interface TextAnnotation2dCreateArgs {\n /** The category ID for the annotation. */\n category: Id64String;\n /** The model ID where the annotation will be placed. */\n model: Id64String;\n /** The placement properties for the annotation. */\n placement: Placement2dProps;\n /** The default text style ID for the annotation. */\n defaultTextStyleId?: Id64String;\n /** Optional [[TextAnnotation]] JSON representation used to create the `TextAnnotation2d`. Essentially an empty element if not provided. */\n textAnnotationProps?: TextAnnotationProps;\n /** Optional code for the element. */\n code?: CodeProps;\n}\n\n/** Arguments supplied when creating a [[TextAnnotation3d]].\n * @beta\n */\nexport interface TextAnnotation3dCreateArgs {\n /** The category ID for the annotation. */\n category: Id64String;\n /** The model ID where the annotation will be placed. */\n model: Id64String;\n /** The placement properties for the annotation. */\n placement: Placement3dProps;\n /** The default text style ID for the annotation. */\n defaultTextStyleId?: Id64String;\n /** Optional [[TextAnnotation]] JSON representation used to create the `TextAnnotation3d`. Essentially an empty element if not provided. */\n textAnnotationProps?: TextAnnotationProps;\n /** Optional code for the element. */\n code?: CodeProps;\n}\n\n/** An element that displays textual content within a 2d model.\n * The text is stored as a [TextAnnotation]($common) from which the element's [geometry]($docs/learning/common/GeometryStream.md) and [Placement]($common) are computed.\n * @see [[setAnnotation]] to change the textual content.\n * @public @preview\n */\nexport class TextAnnotation2d extends AnnotationElement2d /* implements ITextAnnotation */ {\n /** @internal */\n public static override get className(): string { return \"TextAnnotation2d\"; }\n /**\n * The default [[AnnotationTextStyle]] used by the TextAnnotation2d.\n * @beta\n */\n public defaultTextStyle?: TextAnnotationUsesTextStyleByDefault;\n /** The data associated with the text annotation. */\n private _textAnnotationProps?: TextAnnotationProps;\n\n /** Extract the textual content, if present.\n * @see [[setAnnotation]] to change it.\n */\n public getAnnotation(): TextAnnotation | undefined {\n return this._textAnnotationProps ? TextAnnotation.fromJSON(this._textAnnotationProps) : undefined;\n }\n\n /** Change the textual content of the `TextAnnotation2d`.\n * @see [[getAnnotation]] to extract the current annotation.\n * @param annotation The new annotation\n */\n public setAnnotation(annotation: TextAnnotation) {\n this._textAnnotationProps = annotation.toJSON();\n }\n\n protected constructor(props: TextAnnotation2dProps, iModel: IModelDb) {\n super(props, iModel);\n if (props.defaultTextStyle) {\n this.defaultTextStyle = new TextAnnotationUsesTextStyleByDefault(props.defaultTextStyle.id);\n }\n this._textAnnotationProps = parseTextAnnotationData(props.textAnnotationData)?.data;\n }\n\n /** Creates a new instance of `TextAnnotation2d` from its JSON representation. */\n public static fromJSON(props: TextAnnotation2dProps, iModel: IModelDb): TextAnnotation2d {\n return new TextAnnotation2d(props, iModel);\n }\n\n /**\n * Converts the current `TextAnnotation2d` instance to its JSON representation.\n * It also computes the `elementGeometryBuilderParams` property used to create the GeometryStream.\n * @inheritdoc\n */\n public override toJSON(): TextAnnotation2dProps {\n const props = super.toJSON() as TextAnnotation2dProps;\n props.textAnnotationData = this._textAnnotationProps ? JSON.stringify({ version: TEXT_ANNOTATION_JSON_VERSION, data: this._textAnnotationProps }) : undefined;\n if (this._textAnnotationProps) {\n props.elementGeometryBuilderParams = getElementGeometryBuilderParams(this.iModel, this.model, this.category, this.placement, this._textAnnotationProps, this.defaultTextStyle ? this.defaultTextStyle.id : undefined);\n }\n\n return props;\n }\n\n /** Creates a new `TextAnnotation2d` instance with the specified properties.\n * @param iModelDb The iModel.\n * @param arg The arguments for creating the TextAnnotation2d.\n * @beta\n */\n public static create(iModelDb: IModelDb, arg: TextAnnotation2dCreateArgs): TextAnnotation2d {\n const elementProps: TextAnnotation2dProps = {\n classFullName: this.classFullName,\n textAnnotationData: arg.textAnnotationProps ? JSON.stringify({ version: TEXT_ANNOTATION_JSON_VERSION, data: arg.textAnnotationProps }) : undefined,\n defaultTextStyle: arg.defaultTextStyleId ? new TextAnnotationUsesTextStyleByDefault(arg.defaultTextStyleId).toJSON() : undefined,\n placement: arg.placement,\n model: arg.model,\n category: arg.category,\n code: arg.code ?? Code.createEmpty(),\n };\n return new this(elementProps, iModelDb);\n }\n\n /**\n * Updates the geometry of the TextAnnotation2d on insert and validates version.\n * @inheritdoc\n * @beta\n */\n protected static override onInsert(arg: OnElementPropsArg): void {\n super.onInsert(arg);\n this.validateVersionAndUpdateGeometry(arg);\n }\n\n /**\n * Updates the geometry of the TextAnnotation2d on update and validates version.\n * @inheritdoc\n * @beta\n */\n protected static override onUpdate(arg: OnElementPropsArg): void {\n super.onUpdate(arg);\n this.validateVersionAndUpdateGeometry(arg);\n }\n\n /**\n * Populates the `elementGeometryBuilderParams` property in the [TextAnnotation2dProps]($common).\n * Only does this if the `elementGeometryBuilderParams` is not already set and if there is actually a text annotation to produce geometry for.\n * Also, validates the version of the text annotation data and migrates it if necessary.\n * @beta\n */\n protected static validateVersionAndUpdateGeometry(arg: OnElementPropsArg): void {\n const props = arg.props as TextAnnotation2dProps;\n const textAnnotationData = parseTextAnnotationData(props.textAnnotationData);\n if (!props.elementGeometryBuilderParams && textAnnotationData) {\n props.elementGeometryBuilderParams = getElementGeometryBuilderParams(arg.iModel, props.model, props.category, props.placement ?? Placement2d.fromJSON(), textAnnotationData.data, props.defaultTextStyle?.id);\n }\n }\n\n /**\n * TextAnnotation2d custom HandledProps include 'textAnnotationData'.\n * @inheritdoc\n * @internal\n */\n protected static override readonly _customHandledProps: CustomHandledProperty[] = [\n { propertyName: \"textAnnotationData\", source: \"Class\" },\n ];\n\n /**\n * TextAnnotation2d deserializes 'textAnnotationData'.\n * @inheritdoc\n * @beta\n */\n public static override deserialize(props: DeserializeEntityArgs): TextAnnotation2dProps {\n const elProps = super.deserialize(props) as TextAnnotation2dProps;\n const textAnnotationData = parseTextAnnotationData(props.row.textAnnotationData);\n if (textAnnotationData) {\n elProps.textAnnotationData = JSON.stringify(textAnnotationData);\n }\n return elProps;\n }\n\n /**\n * TextAnnotation2d serializes 'textAnnotationData'.\n * @inheritdoc\n * @beta\n */\n public static override serialize(props: TextAnnotation2dProps, iModel: IModelDb): ECSqlRow {\n const inst = super.serialize(props, iModel);\n if (props.textAnnotationData !== undefined) {\n inst.textAnnotationData = props.textAnnotationData;\n }\n return inst;\n }\n\n /** @internal */\n public getTextBlocks(): Iterable<TextBlockAndId> {\n return getTextBlocks(this);\n }\n\n /** @internal */\n public updateTextBlocks(textBlocks: TextBlockAndId[]): void {\n return updateTextBlocks(this, textBlocks);\n }\n\n /** @internal */\n public static override onInserted(arg: OnElementIdArg): void {\n super.onInserted(arg);\n ElementDrivesTextAnnotation.updateFieldDependencies(arg.id, arg.iModel);\n }\n\n /** @internal */\n public static override onUpdated(arg: OnElementIdArg): void {\n super.onUpdated(arg);\n ElementDrivesTextAnnotation.updateFieldDependencies(arg.id, arg.iModel);\n }\n\n protected override collectReferenceIds(referenceIds: EntityReferenceSet): void {\n super.collectReferenceIds(referenceIds);\n collectReferenceIds(this, referenceIds);\n }\n\n /** @internal */\n protected static override onCloned(context: IModelElementCloneContext, srcProps: TextAnnotation2dProps, dstProps: TextAnnotation2dProps): void {\n super.onCloned(context, srcProps, dstProps);\n\n const srcElem = TextAnnotation2d.fromJSON(srcProps, context.sourceDb);\n ElementDrivesTextAnnotation.remapFields(srcElem, context);\n const anno = srcElem.getAnnotation();\ndstProps.textAnnotationData = anno ? JSON.stringify({ version: TEXT_ANNOTATION_JSON_VERSION, data: anno.toJSON() }) : undefined;\n\n remapTextStyle(context, srcElem, dstProps);\n }\n}\n\n/** An element that displays textual content within a 3d model.\n * The text is stored as a [TextAnnotation]($common) from which the element's [geometry]($docs/learning/common/GeometryStream.md) and [Placement]($common) are computed.\n * @see [[setAnnotation]] to change the textual content.\n * @public @preview\n */\nexport class TextAnnotation3d extends GraphicalElement3d /* implements ITextAnnotation */ {\n /** @internal */\n public static override get className(): string { return \"TextAnnotation3d\"; }\n /**\n * The default [[AnnotationTextStyle]] used by the TextAnnotation3d.\n * @beta\n */\n public defaultTextStyle?: TextAnnotationUsesTextStyleByDefault;\n /** The data associated with the text annotation. */\n private _textAnnotationProps?: TextAnnotationProps;\n\n /** Extract the textual content, if present.\n * @see [[setAnnotation]] to change it.\n */\n public getAnnotation(): TextAnnotation | undefined {\n return this._textAnnotationProps ? TextAnnotation.fromJSON(this._textAnnotationProps) : undefined;\n }\n\n /** Change the textual content of the `TextAnnotation3d`.\n * @see [[getAnnotation]] to extract the current annotation.\n * @param annotation The new annotation\n */\n public setAnnotation(annotation: TextAnnotation) {\n this._textAnnotationProps = annotation.toJSON();\n }\n\n protected constructor(props: TextAnnotation3dProps, iModel: IModelDb) {\n super(props, iModel);\n if (props.defaultTextStyle) {\n this.defaultTextStyle = new TextAnnotationUsesTextStyleByDefault(props.defaultTextStyle.id);\n }\n this._textAnnotationProps = parseTextAnnotationData(props.textAnnotationData)?.data;\n }\n\n /** Creates a new instance of `TextAnnotation3d` from its JSON representation. */\n public static fromJSON(props: TextAnnotation3dProps, iModel: IModelDb): TextAnnotation3d {\n return new TextAnnotation3d(props, iModel);\n }\n\n /**\n * Converts the current `TextAnnotation3d` instance to its JSON representation.\n * It also computes the `elementGeometryBuilderParams` property used to create the GeometryStream.\n * @inheritdoc\n */\n public override toJSON(): TextAnnotation3dProps {\n const props = super.toJSON() as TextAnnotation3dProps;\n props.textAnnotationData = this._textAnnotationProps ? JSON.stringify({ version: TEXT_ANNOTATION_JSON_VERSION, data: this._textAnnotationProps }) : undefined;\n if (this._textAnnotationProps) {\n props.elementGeometryBuilderParams = getElementGeometryBuilderParams(this.iModel, this.model, this.category, this.placement, this._textAnnotationProps, this.defaultTextStyle ? this.defaultTextStyle.id : undefined);\n }\n\n return props;\n }\n\n /** Creates a new `TextAnnotation3d` instance with the specified properties.\n * @param iModelDb The iModel.\n * @param arg The arguments for creating the TextAnnotation3d.\n * @beta\n */\n public static create(iModelDb: IModelDb, arg: TextAnnotation3dCreateArgs): TextAnnotation3d {\n const elementProps: TextAnnotation3dProps = {\n classFullName: this.classFullName,\n textAnnotationData: arg.textAnnotationProps ? JSON.stringify({ version: TEXT_ANNOTATION_JSON_VERSION, data: arg.textAnnotationProps }) : undefined,\n defaultTextStyle: arg.defaultTextStyleId ? new TextAnnotationUsesTextStyleByDefault(arg.defaultTextStyleId).toJSON() : undefined,\n placement: arg.placement,\n model: arg.model,\n category: arg.category,\n code: arg.code ?? Code.createEmpty(),\n };\n return new this(elementProps, iModelDb);\n }\n\n /**\n * Updates the geometry of the TextAnnotation3d on insert and validates version..\n * @inheritdoc\n * @beta\n */\n protected static override onInsert(arg: OnElementPropsArg): void {\n super.onInsert(arg);\n this.validateVersionAndUpdateGeometry(arg);\n }\n\n /**\n * Updates the geometry of the TextAnnotation3d on update and validates version..\n * @inheritdoc\n * @beta\n */\n protected static override onUpdate(arg: OnElementPropsArg): void {\n super.onUpdate(arg);\n this.validateVersionAndUpdateGeometry(arg);\n }\n\n /**\n * Populates the `elementGeometryBuilderParams` property in the [TextAnnotation3dProps]($common).\n * Only does this if the `elementGeometryBuilderParams` is not already set and if there is actually a text annotation to produce geometry for.\n * Also, validates the version of the text annotation data and migrates it if necessary.\n * @beta\n */\n protected static validateVersionAndUpdateGeometry(arg: OnElementPropsArg): void {\n const props = arg.props as TextAnnotation3dProps;\n const textAnnotationData = parseTextAnnotationData(props.textAnnotationData);\n if (!props.elementGeometryBuilderParams && textAnnotationData) {\n props.elementGeometryBuilderParams = getElementGeometryBuilderParams(arg.iModel, props.model, props.category, props.placement ?? Placement3d.fromJSON(), textAnnotationData.data, props.defaultTextStyle?.id);\n }\n }\n\n /**\n * TextAnnotation3d custom HandledProps include 'textAnnotationData'.\n * @inheritdoc\n * @internal\n */\n protected static override readonly _customHandledProps: CustomHandledProperty[] = [\n { propertyName: \"textAnnotationData\", source: \"Class\" },\n ];\n\n /**\n * TextAnnotation3d deserializes 'textAnnotationData'.\n * @inheritdoc\n * @beta\n */\n public static override deserialize(props: DeserializeEntityArgs): TextAnnotation3dProps {\n const elProps = super.deserialize(props) as TextAnnotation3dProps;\n const textAnnotationData = parseTextAnnotationData(props.row.textAnnotationData);\n if (textAnnotationData) {\n elProps.textAnnotationData = JSON.stringify(textAnnotationData);\n }\n return elProps;\n }\n\n /**\n * TextAnnotation3d serializes 'textAnnotationData'.\n * @inheritdoc\n * @beta\n */\n public static override serialize(props: TextAnnotation3dProps, iModel: IModelDb): ECSqlRow {\n const inst = super.serialize(props, iModel);\n if (props.textAnnotationData !== undefined) {\n inst.textAnnotationData = props.textAnnotationData;\n }\n return inst;\n }\n\n /** @internal */\n public getTextBlocks(): Iterable<TextBlockAndId> {\n return getTextBlocks(this);\n }\n\n /** @internal */\n public updateTextBlocks(textBlocks: TextBlockAndId[]): void {\n return updateTextBlocks(this, textBlocks);\n }\n\n /** @internal */\n public static override onInserted(arg: OnElementIdArg): void {\n super.onInserted(arg);\n ElementDrivesTextAnnotation.updateFieldDependencies(arg.id, arg.iModel);\n }\n\n /** @internal */\n public static override onUpdated(arg: OnElementIdArg): void {\n super.onUpdated(arg);\n ElementDrivesTextAnnotation.updateFieldDependencies(arg.id, arg.iModel);\n }\n\n protected override collectReferenceIds(referenceIds: EntityReferenceSet): void {\n super.collectReferenceIds(referenceIds);\n collectReferenceIds(this, referenceIds);\n }\n\n /** @internal */\n protected static override onCloned(context: IModelElementCloneContext, srcProps: TextAnnotation3dProps, dstProps: TextAnnotation3dProps): void {\n super.onCloned(context, srcProps, dstProps);\n\n const srcElem = TextAnnotation3d.fromJSON(srcProps, context.sourceDb);\n ElementDrivesTextAnnotation.remapFields(srcElem, context);\n const anno = srcElem.getAnnotation();\n dstProps.textAnnotationData = anno ? JSON.stringify({ version: TEXT_ANNOTATION_JSON_VERSION, data: anno.toJSON() }) : undefined;\n\n remapTextStyle(context, srcElem, dstProps);\n }\n}\n\nfunction remapTextStyle(\n context: IModelElementCloneContext,\n srcElem: TextAnnotation2d | TextAnnotation3d,\n dstProps: TextAnnotation2dProps | TextAnnotation3dProps\n): void {\n const dstStyleId = AnnotationTextStyle.remapTextStyleId(srcElem.defaultTextStyle?.id ?? Id64.invalid, context);\n dstProps.defaultTextStyle = Id64.isValid(dstStyleId) ? new TextAnnotationUsesTextStyleByDefault(dstStyleId).toJSON() : undefined;\n}\n\nfunction collectReferenceIds(elem: TextAnnotation2d | TextAnnotation3d, referenceIds: EntityReferenceSet): void {\n const style = elem.defaultTextStyle?.id;\n if (style && Id64.isValidId64(style)) {\n referenceIds.addElement(style);\n }\n\n const block = elem.getAnnotation()?.textBlock;\n if (block) {\n for (const { child } of traverseTextBlockComponent(block)) {\n if (child.type === \"field\") {\n const hostId = child.propertyHost.elementId;\n if (Id64.isValidId64(hostId)) {\n referenceIds.addElement(hostId);\n }\n }\n }\n }\n}\n\nfunction getTextBlocks(elem: TextAnnotation2d | TextAnnotation3d): Iterable<TextBlockAndId> {\n const annotation = elem.getAnnotation();\n return annotation ? [{ textBlock: annotation.textBlock, id: undefined }] : [];\n}\n\nfunction updateTextBlocks(elem: TextAnnotation2d | TextAnnotation3d, textBlocks: TextBlockAndId[]): void {\n assert(textBlocks.length === 1);\n assert(textBlocks[0].id === undefined);\n\n const annotation = elem.getAnnotation();\n if (!annotation) {\n // We must obtain the TextBlockAndId from the element in the first place, so the only way we could end up here is if\n // somebody removed the text annotation after we called getTextBlocks. That's gotta be a mistake.\n throw new Error(\"Text annotation element has no text\");\n }\n\n annotation.textBlock = textBlocks[0].textBlock;\n\n elem.setAnnotation(annotation);\n}\n\n/** The version of the JSON stored in `AnnotationTextStyleProps.settings` used by the code.\n * Uses the same semantics as [ECVersion]($ecschema-metadata).\n * @internal\n*/\nexport const TEXT_STYLE_SETTINGS_JSON_VERSION = \"1.0.0\";\n\nfunction migrateTextStyleSettings(oldData: VersionedJSON<TextStyleSettingsProps>): TextStyleSettingsProps {\n if (oldData.version === TEXT_STYLE_SETTINGS_JSON_VERSION) return oldData.data;\n\n // Place migration logic here.\n\n throw new Error(`Migration for settings from version ${oldData.version} to ${TEXT_STYLE_SETTINGS_JSON_VERSION} failed.`);\n}\n\n/** Arguments supplied when creating an [[AnnotationTextStyle]].\n * @beta\n */\nexport interface TextStyleCreateArgs {\n /** The ID of the [[DefinitionModel]]. */\n definitionModelId: Id64String;\n /** The name to assign to the [[AnnotationTextStyle]]. */\n name: string;\n /** Optional text style settings used to create the [[AnnotationTextStyle]]. Default settings will be used if not provided. */\n settings?: TextStyleSettingsProps;\n /** Optional description for the [[AnnotationTextStyle]]. */\n description?: string;\n}\n\n/**\n * The definition element that holds text style information.\n * The style is stored as a [TextStyleSettings]($common).\n * @beta\n */\nexport class AnnotationTextStyle extends DefinitionElement {\n /** @internal */\n public static override get className(): string { return \"AnnotationTextStyle\"; }\n /**\n * Optional text describing the `AnnotationTextStyle`.\n */\n public description?: string;\n /**\n * The text style settings for the `AnnotationTextStyle`.\n * @see [[TextStyleSettings]] for more information.\n */\n public settings: TextStyleSettings;\n\n protected constructor(props: AnnotationTextStyleProps, iModel: IModelDb) {\n super(props, iModel);\n this.description = props.description;\n const settingsProps = AnnotationTextStyle.parseTextStyleSettings(props.settings);\n this.settings = TextStyleSettings.fromJSON(settingsProps?.data);\n }\n\n /**\n * Creates a Code for an `AnnotationTextStyle` given a name that is meant to be unique within the scope of the specified DefinitionModel.\n *\n * @param iModel - The IModelDb.\n * @param definitionModelId - The ID of the DefinitionModel that contains the AnnotationTextStyle and provides the scope for its name.\n * @param name - The AnnotationTextStyle name.\n * @beta\n */\n public static createCode(iModel: IModelDb, definitionModelId: CodeScopeProps, name: string): Code {\n const codeSpec: CodeSpec = iModel.codeSpecs.getByName(BisCodeSpec.annotationTextStyle);\n return new Code({ spec: codeSpec.id, scope: definitionModelId, value: name });\n }\n\n /**\n * Creates a new instance of `AnnotationTextStyle` with the specified properties.\n *\n * @param iModelDb - The iModelDb.\n * @param arg - The arguments for creating the AnnotationTextStyle.\n * @beta\n */\n public static create(iModelDb: IModelDb, arg: TextStyleCreateArgs): AnnotationTextStyle {\n const props: AnnotationTextStyleProps = {\n classFullName: this.classFullName,\n model: arg.definitionModelId,\n code: this.createCode(iModelDb, arg.definitionModelId, arg.name).toJSON(),\n description: arg.description,\n settings: arg.settings ? JSON.stringify({version: TEXT_STYLE_SETTINGS_JSON_VERSION, data: arg.settings}) : undefined,\n }\n return new this(props, iModelDb);\n }\n\n /**\n * Converts the current `AnnotationTextStyle` instance to its JSON representation.\n * @inheritdoc\n */\n public override toJSON(): AnnotationTextStyleProps {\n const props = super.toJSON() as AnnotationTextStyleProps;\n props.description = this.description;\n props.settings = JSON.stringify({version: TEXT_STYLE_SETTINGS_JSON_VERSION, data: this.settings.toJSON()});\n return props;\n }\n\n /** Creates a new instance of `AnnotationTextStyle` from its JSON representation. */\n public static fromJSON(props: AnnotationTextStyleProps, iModel: IModelDb): AnnotationTextStyle {\n return new AnnotationTextStyle(props, iModel);\n }\n\n /**\n * Validates that the AnnotationTextStyle's settings are valid before insert.\n * @inheritdoc\n * @beta\n */\n protected static override onInsert(arg: OnElementPropsArg): void {\n super.onInsert(arg);\n this.validateSettings(arg.props as AnnotationTextStyleProps);\n }\n\n /**\n * Validates that the AnnotationTextStyle's settings are valid before update.\n * @inheritdoc\n * @beta\n */\n protected static override onUpdate(arg: OnElementPropsArg): void {\n super.onUpdate(arg);\n this.validateSettings(arg.props as AnnotationTextStyleProps);\n }\n\n private static validateSettings(props: AnnotationTextStyleProps): void {\n const settingProps = AnnotationTextStyle.parseTextStyleSettings(props.settings);\n if (!settingProps) return;\n const settings = TextStyleSettings.fromJSON(settingProps.data);\n const errors = settings.getValidationErrors();\n if (errors.length > 0) {\n throw new Error(`Invalid AnnotationTextStyle settings: ${errors.join(\", \")}`);\n }\n }\n\n /**\n * AnnotationTextStyle custom HandledProps include 'settings'.\n * @inheritdoc\n * @beta\n */\n protected static override readonly _customHandledProps: CustomHandledProperty[] = [\n { propertyName: \"settings\", source: \"Class\" },\n ];\n\n /**\n * AnnotationTextStyle deserializes 'settings'.\n * @inheritdoc\n * @beta\n */\n public static override deserialize(props: DeserializeEntityArgs): AnnotationTextStyleProps {\n const elProps = super.deserialize(props) as AnnotationTextStyleProps;\n const settings = this.parseTextStyleSettings(props.row.settings);\n if (settings) {\n elProps.settings = JSON.stringify(settings);\n }\n return elProps;\n }\n\n /**\n * AnnotationTextStyle serializes 'settings'.\n * @inheritdoc\n * @beta\n */\n public static override serialize(props: AnnotationTextStyleProps, iModel: IModelDb): ECSqlRow {\n const inst = super.serialize(props, iModel);\n if (props.settings !== undefined) {\n inst.settings = props.settings;\n }\n return inst;\n }\n\n /** Parses, validates, and potentially migrates the text style settings data from a JSON string. */\n private static parseTextStyleSettings(json: string | undefined): VersionedJSON<TextStyleSettingsProps> | undefined {\n if (!json) return undefined;\n return validateAndMigrateVersionedJSON<TextStyleSettingsProps>(json, TEXT_STYLE_SETTINGS_JSON_VERSION, migrateTextStyleSettings);\n }\n\n /** When copying an element from one iModel to another, returns the Id of the AnnotationTextStyle in the `context`'s target iModel\n * corresponding to `sourceTextStyleId`, or [Id64.invalid]($bentley) if no corresponding text style exists.\n * If a text style with the same [Code]($common) exists in the target iModel, the style Id will be remapped to refer to that style.\n * Otherwise, a copy of the style will be imported into the target iModel and its element Id returned.\n * Implementations of [[ITextAnnotation]] should invoke this function when implementing their [[Element._onCloned]] method.\n * @throws Error if an attempt to import the text style failed.\n */\n public static remapTextStyleId(sourceTextStyleId: Id64String, context: IModelElementCloneContext): Id64String {\n // No remapping necessary if there's no text style or we're not copying to a different iModel.\n if (!Id64.isValid(sourceTextStyleId) || !context.isBetweenIModels) {\n return sourceTextStyleId;\n }\n\n // If the style's already been remapped, we're finished.\n let dstStyleId: Id64String | undefined = context.findTargetElementId(sourceTextStyleId);\n if (Id64.isValid(dstStyleId)) {\n return dstStyleId;\n }\n\n // Look up the style. It really ought to exist.\n const srcStyle = context.sourceDb.elements.tryGetElement<AnnotationTextStyle>(sourceTextStyleId);\n if (!srcStyle) {\n return Id64.invalid;\n }\n\n // If a style with the same code exists in the target iModel, remap to that one.\n dstStyleId = context.targetDb.elements.queryElementIdByCode(srcStyle.code);\n if (undefined !== dstStyleId) {\n return dstStyleId;\n }\n\n // Copy the style into the target iModel and remap its Id.\n const dstStyleProps = context.cloneElement(srcStyle);\n dstStyleId = context.targetDb.elements.insertElement(dstStyleProps);\n context.remapElement(sourceTextStyleId, dstStyleId);\n return dstStyleId;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../../../../src/internal/annotations/fields.ts"],"names":[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,EAAE,CAAC;QAC9D,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,IAAI,WAAW,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,CAAC;YAC1D,EAAE,UAAU,CAAC;QACf,CAAC;IACH,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,uHAAuH;AACvH,MAAM,UAAU,mBAAmB,CAAC,KAAwB,EAAE,MAAgB,EAAE,OAAgB;IAC9F,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAC1D,IAAI,iBAAiB,CAAC,MAAM,CAAC,EAAE,CAAC;YAC9B,MAAM,OAAO,GAAG,mBAAmB,CAAC,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;YACrE,MAAM,aAAa,GAAG,EAAE,CAAC;YACzB,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,aAAa,EAAE,EAAE,CAAC;gBAC3C,IAAI,YAAY,CAAC,KAAK,CAAC,SAAS,EAAE,OAAO,CAAC,EAAE,CAAC;oBAC3C,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gBAC5B,CAAC;YACH,CAAC;YAED,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC7B,MAAM,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAC;YACzC,CAAC;QACH,CAAC;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,CAAC,YAAY,CAAC,qBAAqB,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;IAC3D,CAAC;AACH,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n\nimport { ECSqlValueType, FieldPrimitiveValue, FieldPropertyType, FieldRun, FieldValue, formatFieldValue, RelationshipProps, TextBlock, traverseTextBlockComponent } from \"@itwin/core-common\";\nimport { IModelDb } from \"../../IModelDb\";\nimport { assert, DbResult, expectDefined, Id64String, Logger } from \"@itwin/core-bentley\";\nimport { BackendLoggerCategory } from \"../../BackendLoggerCategory\";\nimport { isITextAnnotation } from \"../../annotations/ElementDrivesTextAnnotation\";\nimport { AnyClass, EntityClass, PrimitiveType, Property, PropertyType, StructArrayProperty } from \"@itwin/ecschema-metadata\";\n\ninterface FieldStructValue { [key: string]: any }\n\n// An intermediate value obtained while evaluating a FieldPropertyPath.\ntype FieldValueType = {\n primitive: FieldPrimitiveValue;\n struct?: never;\n primitiveArray?: never;\n structArray?: never;\n} | {\n primitive?: never;\n struct: FieldStructValue;\n primitiveArray?: never;\n structArray?: never;\n} | {\n primitive?: never;\n struct?: never;\n primitiveArray: FieldPrimitiveValue[];\n structArray?: never;\n} | {\n primitive?: never;\n struct?: never;\n primitiveArray?: never;\n structArray: FieldStructValue[];\n}\n\nexport interface UpdateFieldsContext {\n readonly hostElementId: Id64String;\n\n getProperty(field: FieldRun): FieldValue | undefined\n}\n\n// Resolve the raw primitive value of the property that a field points to.\nfunction getFieldPropertyValue(field: FieldRun, iModel: IModelDb): FieldValue | undefined {\n const host = field.propertyHost;\n const schemaItem = iModel.schemaContext.getSchemaItemSync(host.schemaName, host.className);\n if (!EntityClass.isEntityClass(schemaItem)) {\n return undefined;\n }\n\n let ecClass: AnyClass = schemaItem;\n const { propertyName, accessors } = field.propertyPath;\n let ecProp = ecClass.getPropertySync(propertyName);\n if (!ecProp) {\n return undefined;\n }\n\n const isAspect = ecClass.isSync(\"ElementAspect\", \"BisCore\");\n const where = ` WHERE ${isAspect ? \"Element.Id\" : \"ECInstanceId\"}=${host.elementId}`;\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n let curValue: FieldValueType | undefined = iModel.withPreparedStatement(`SELECT ${propertyName} FROM ${host.schemaName}.${host.className} ${where}`, (stmt) => {\n if (stmt.step() !== DbResult.BE_SQLITE_ROW) {\n return undefined;\n }\n\n const rootValue = stmt.getValue(0);\n if (undefined === rootValue || rootValue.isNull) {\n return undefined;\n }\n\n switch (rootValue.columnInfo.getType()) {\n case ECSqlValueType.Blob:\n return { primitive: rootValue.getBlob() };\n case ECSqlValueType.Boolean:\n return { primitive: rootValue.getBoolean() };\n case ECSqlValueType.DateTime:\n return { primitive: new Date(rootValue.getDateTime()) };\n case ECSqlValueType.Double:\n return { primitive: rootValue.getDouble() };\n case ECSqlValueType.Guid:\n return { primitive: rootValue.getGuid() };\n case ECSqlValueType.Int:\n case ECSqlValueType.Int64:\n return { primitive: rootValue.getInteger() };\n case ECSqlValueType.Point2d:\n return { primitive: rootValue.getXAndY() };\n case ECSqlValueType.Point3d:\n return { primitive: rootValue.getXYAndZ() };\n case ECSqlValueType.String:\n return { primitive: rootValue.getString() };\n case ECSqlValueType.Struct: {\n ecProp = expectDefined(ecProp);\n assert(ecProp.isStruct());\n ecClass = ecProp.structClass;\n return { struct: rootValue.getStruct() };\n }\n case ECSqlValueType.PrimitiveArray: {\n return { primitiveArray: rootValue.getArray() };\n }\n case ECSqlValueType.StructArray: {\n return { structArray: rootValue.getArray() };\n }\n // Unsupported:\n // case ECSqlValueType.Geometry:\n // case ECSqlValueType.Navigation:\n // case ECSqlValueType.Id:\n }\n\n return undefined;\n });\n\n if (undefined === curValue) {\n return undefined;\n }\n\n if (accessors) {\n for (const accessor of accessors) {\n if (undefined !== curValue.primitive) {\n // Can't index into a primitive.\n return undefined;\n }\n\n if (typeof accessor === \"number\") {\n const array: FieldPrimitiveValue[] | FieldStructValue[] | undefined = curValue.primitiveArray ?? curValue.structArray;\n if (!array) {\n return undefined;\n }\n\n const index: number = accessor < 0 ? (array.length + accessor) : accessor;\n const item: FieldPrimitiveValue | FieldStructValue = array[index];\n if (undefined === item) {\n return undefined;\n } else if (curValue.primitiveArray) {\n curValue = { primitive: curValue.primitiveArray[index] };\n } else {\n assert(undefined !== curValue.structArray);\n assert(ecProp instanceof StructArrayProperty);\n\n ecClass = ecProp.structClass;\n curValue = { struct: curValue.structArray[index] };\n }\n } else {\n if (undefined === curValue.struct) {\n return undefined;\n }\n\n const item: any = curValue.struct[accessor];\n if (undefined === item) {\n return undefined;\n }\n\n ecProp = ecClass.getPropertySync(accessor);\n if (!ecProp) {\n return undefined;\n }\n\n if (ecProp.isArray()) {\n curValue = ecProp.isStruct() ? { structArray: item } : { primitiveArray: item };\n } else if (ecProp.isStruct()) {\n ecClass = ecProp.structClass;\n curValue = { struct: item };\n } else if (ecProp.isPrimitive()) {\n curValue = { primitive: item };\n } else {\n return undefined;\n }\n }\n }\n }\n\n const propertyType = determineFieldPropertyType(ecProp);\n if(!propertyType) {\n return undefined;\n }\n\n // The ultimate result must be a primitive value.\n if (undefined === curValue.primitive) {\n return undefined;\n }\n\n return { value: curValue.primitive, type: propertyType };\n}\n\nfunction determineFieldPropertyType(prop: Property): FieldPropertyType | undefined {\n if (prop.isEnumeration()) {\n switch (prop.propertyType) {\n case PropertyType.Integer_Enumeration:\n return \"int-enum\";\n case PropertyType.String_Enumeration:\n return \"string-enum\";\n default:\n return undefined;\n }\n }\n\n if (prop.isPrimitive()) {\n switch (prop.primitiveType) {\n case PrimitiveType.Boolean:\n return \"boolean\";\n case PrimitiveType.String:\n return prop.extendedTypeName === \"DateTime\" ? \"datetime\" : \"string\";\n case PrimitiveType.DateTime:\n return \"datetime\";\n case PrimitiveType.Double:\n case PrimitiveType.Long:\n return \"quantity\";\n case PrimitiveType.Point2d:\n case PrimitiveType.Point3d:\n return \"coordinate\";\n case PrimitiveType.Binary:\n return prop.extendedTypeName === \"BeGuid\" ? \"string\" : undefined;\n case PrimitiveType.Integer:\n case PrimitiveType.Long:\n return \"string\";\n default:\n return undefined;\n }\n }\n\n return undefined;\n}\n\nexport function createUpdateContext(hostElementId: string, iModel: IModelDb, deleted: boolean): UpdateFieldsContext {\n return {\n hostElementId,\n getProperty: deleted ? () => undefined : (field) => getFieldPropertyValue(field, iModel),\n };\n}\n\n// Recompute the display value of a single field, return false if it couldn't be evaluated.\nexport function updateField(field: FieldRun, context: UpdateFieldsContext): boolean {\n if (context.hostElementId !== field.propertyHost.elementId) {\n return false;\n }\n\n let newContent: string | undefined;\n try {\n const propValue = context.getProperty(field);\n if (undefined !== propValue) {\n newContent = formatFieldValue(propValue, field.formatOptions);\n }\n } catch (err) {\n Logger.logException(BackendLoggerCategory.IModelDb, err);\n }\n\n newContent = newContent ?? FieldRun.invalidContentIndicator;\n if (newContent === field.cachedContent) {\n return false;\n }\n\n field.setCachedContent(newContent);\n return true;\n}\n\n// Re-evaluates the display strings for all fields that target the element specified by `context` and returns the number\n// of fields whose display strings changed as a result.\nexport function updateFields(textBlock: TextBlock, context: UpdateFieldsContext): number {\n let numUpdated = 0;\n for (const { child } of traverseTextBlockComponent(textBlock)) {\n if (child.type === \"field\" && updateField(child, context)) {\n ++numUpdated;\n }\n }\n\n return numUpdated;\n}\n\n// Invoked by ElementDrivesTextAnnotation to update fields in target element when source element changes or is deleted.\nexport function updateElementFields(props: RelationshipProps, iModel: IModelDb, deleted: boolean): void {\n try {\n const target = iModel.elements.getElement(props.targetId);\n if (isITextAnnotation(target)) {\n const context = createUpdateContext(props.sourceId, iModel, deleted);\n const updatedBlocks = [];\n for (const block of target.getTextBlocks()) {\n if (updateFields(block.textBlock, context)) {\n updatedBlocks.push(block);\n }\n }\n\n if (updatedBlocks.length > 0) {\n target.updateTextBlocks(updatedBlocks);\n }\n }\n } catch (err) {\n Logger.logException(BackendLoggerCategory.IModelDb, err);\n }\n}\n\n"]}
|
|
1
|
+
{"version":3,"file":"fields.js","sourceRoot":"","sources":["../../../../src/internal/annotations/fields.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F,OAAO,EAAE,cAAc,EAA0C,QAAQ,EAAc,gBAAgB,EAAgC,0BAA0B,EAAE,MAAM,oBAAoB,CAAC;AAE9L,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa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C,KAAK,CAAC,SAAS,EAAE,OAAO,CAAC,EAAE,CAAC;oBAC3C,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gBAC5B,CAAC;YACH,CAAC;YAED,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC7B,MAAM,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAC;gBACvC,MAAM,CAAC,MAAM,EAAE,CAAC;YAClB,CAAC;QACH,CAAC;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,CAAC,YAAY,CAAC,qBAAqB,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;IAC3D,CAAC;AACH,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n\nimport { ECSqlValueType, FieldPrimitiveValue, FieldPropertyType, FieldRun, FieldValue, formatFieldValue, RelationshipProps, TextBlock, traverseTextBlockComponent } from \"@itwin/core-common\";\nimport { IModelDb } from \"../../IModelDb\";\nimport { assert, DbResult, expectDefined, Id64String, Logger } from \"@itwin/core-bentley\";\nimport { BackendLoggerCategory } from \"../../BackendLoggerCategory\";\nimport { isITextAnnotation } from \"../../annotations/ElementDrivesTextAnnotation\";\nimport { AnyClass, EntityClass, PrimitiveType, Property, PropertyType, StructArrayProperty } from \"@itwin/ecschema-metadata\";\n\ninterface FieldStructValue { [key: string]: any }\n\n// An intermediate value obtained while evaluating a FieldPropertyPath.\ntype FieldValueType = {\n primitive: FieldPrimitiveValue;\n struct?: never;\n primitiveArray?: never;\n structArray?: never;\n} | {\n primitive?: never;\n struct: FieldStructValue;\n primitiveArray?: never;\n structArray?: never;\n} | {\n primitive?: never;\n struct?: never;\n primitiveArray: FieldPrimitiveValue[];\n structArray?: never;\n} | {\n primitive?: never;\n struct?: never;\n primitiveArray?: never;\n structArray: FieldStructValue[];\n}\n\nexport interface UpdateFieldsContext {\n readonly hostElementId: Id64String;\n\n getProperty(field: FieldRun): FieldValue | undefined\n}\n\n// Resolve the raw primitive value of the property that a field points to.\nfunction getFieldPropertyValue(field: FieldRun, iModel: IModelDb): FieldValue | undefined {\n const host = field.propertyHost;\n const schemaItem = iModel.schemaContext.getSchemaItemSync(host.schemaName, host.className);\n if (!EntityClass.isEntityClass(schemaItem)) {\n return undefined;\n }\n\n let ecClass: AnyClass = schemaItem;\n const { propertyName, accessors } = field.propertyPath;\n let ecProp = ecClass.getPropertySync(propertyName);\n if (!ecProp) {\n return undefined;\n }\n\n const isAspect = ecClass.isSync(\"ElementAspect\", \"BisCore\");\n const where = ` WHERE ${isAspect ? \"Element.Id\" : \"ECInstanceId\"}=${host.elementId}`;\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n let curValue: FieldValueType | undefined = iModel.withPreparedStatement(`SELECT ${propertyName} FROM ${host.schemaName}.${host.className} ${where}`, (stmt) => {\n if (stmt.step() !== DbResult.BE_SQLITE_ROW) {\n return undefined;\n }\n\n const rootValue = stmt.getValue(0);\n if (undefined === rootValue || rootValue.isNull) {\n return undefined;\n }\n\n switch (rootValue.columnInfo.getType()) {\n case ECSqlValueType.Blob:\n return { primitive: rootValue.getBlob() };\n case ECSqlValueType.Boolean:\n return { primitive: rootValue.getBoolean() };\n case ECSqlValueType.DateTime:\n return { primitive: new Date(rootValue.getDateTime()) };\n case ECSqlValueType.Double:\n return { primitive: rootValue.getDouble() };\n case ECSqlValueType.Guid:\n return { primitive: rootValue.getGuid() };\n case ECSqlValueType.Int:\n case ECSqlValueType.Int64:\n return { primitive: rootValue.getInteger() };\n case ECSqlValueType.Point2d:\n return { primitive: rootValue.getXAndY() };\n case ECSqlValueType.Point3d:\n return { primitive: rootValue.getXYAndZ() };\n case ECSqlValueType.String:\n return { primitive: rootValue.getString() };\n case ECSqlValueType.Struct: {\n ecProp = expectDefined(ecProp);\n assert(ecProp.isStruct());\n ecClass = ecProp.structClass;\n return { struct: rootValue.getStruct() };\n }\n case ECSqlValueType.PrimitiveArray: {\n return { primitiveArray: rootValue.getArray() };\n }\n case ECSqlValueType.StructArray: {\n return { structArray: rootValue.getArray() };\n }\n // Unsupported:\n // case ECSqlValueType.Geometry:\n // case ECSqlValueType.Navigation:\n // case ECSqlValueType.Id:\n }\n\n return undefined;\n });\n\n if (undefined === curValue) {\n return undefined;\n }\n\n if (accessors) {\n for (const accessor of accessors) {\n if (undefined !== curValue.primitive) {\n // Can't index into a primitive.\n return undefined;\n }\n\n if (typeof accessor === \"number\") {\n const array: FieldPrimitiveValue[] | FieldStructValue[] | undefined = curValue.primitiveArray ?? curValue.structArray;\n if (!array) {\n return undefined;\n }\n\n const index: number = accessor < 0 ? (array.length + accessor) : accessor;\n const item: FieldPrimitiveValue | FieldStructValue = array[index];\n if (undefined === item) {\n return undefined;\n } else if (curValue.primitiveArray) {\n curValue = { primitive: curValue.primitiveArray[index] };\n } else {\n assert(undefined !== curValue.structArray);\n assert(ecProp instanceof StructArrayProperty);\n\n ecClass = ecProp.structClass;\n curValue = { struct: curValue.structArray[index] };\n }\n } else {\n if (undefined === curValue.struct) {\n return undefined;\n }\n\n const item: any = curValue.struct[accessor];\n if (undefined === item) {\n return undefined;\n }\n\n ecProp = ecClass.getPropertySync(accessor);\n if (!ecProp) {\n return undefined;\n }\n\n if (ecProp.isArray()) {\n curValue = ecProp.isStruct() ? { structArray: item } : { primitiveArray: item };\n } else if (ecProp.isStruct()) {\n ecClass = ecProp.structClass;\n curValue = { struct: item };\n } else if (ecProp.isPrimitive()) {\n curValue = { primitive: item };\n } else {\n return undefined;\n }\n }\n }\n }\n\n const propertyType = determineFieldPropertyType(ecProp);\n if(!propertyType) {\n return undefined;\n }\n\n // The ultimate result must be a primitive value.\n if (undefined === curValue.primitive) {\n return undefined;\n }\n\n return { value: curValue.primitive, type: propertyType };\n}\n\nfunction determineFieldPropertyType(prop: Property): FieldPropertyType | undefined {\n if (prop.isEnumeration()) {\n switch (prop.propertyType) {\n case PropertyType.Integer_Enumeration:\n return \"int-enum\";\n case PropertyType.String_Enumeration:\n return \"string-enum\";\n default:\n return undefined;\n }\n }\n\n if (prop.isPrimitive()) {\n switch (prop.primitiveType) {\n case PrimitiveType.Boolean:\n return \"boolean\";\n case PrimitiveType.String:\n return prop.extendedTypeName === \"DateTime\" ? \"datetime\" : \"string\";\n case PrimitiveType.DateTime:\n return \"datetime\";\n case PrimitiveType.Double:\n case PrimitiveType.Long:\n return \"quantity\";\n case PrimitiveType.Point2d:\n case PrimitiveType.Point3d:\n return \"coordinate\";\n case PrimitiveType.Binary:\n return prop.extendedTypeName === \"BeGuid\" ? \"string\" : undefined;\n case PrimitiveType.Integer:\n case PrimitiveType.Long:\n return \"string\";\n default:\n return undefined;\n }\n }\n\n return undefined;\n}\n\nexport function createUpdateContext(hostElementId: string, iModel: IModelDb, deleted: boolean): UpdateFieldsContext {\n return {\n hostElementId,\n getProperty: deleted ? () => undefined : (field) => getFieldPropertyValue(field, iModel),\n };\n}\n\n// Recompute the display value of a single field, return false if it couldn't be evaluated.\nexport function updateField(field: FieldRun, context: UpdateFieldsContext): boolean {\n if (context.hostElementId !== field.propertyHost.elementId) {\n return false;\n }\n\n let newContent: string | undefined;\n try {\n const propValue = context.getProperty(field);\n if (undefined !== propValue) {\n newContent = formatFieldValue(propValue, field.formatOptions);\n }\n } catch (err) {\n Logger.logException(BackendLoggerCategory.IModelDb, err);\n }\n\n newContent = newContent ?? FieldRun.invalidContentIndicator;\n if (newContent === field.cachedContent) {\n return false;\n }\n\n field.setCachedContent(newContent);\n return true;\n}\n\n// Re-evaluates the display strings for all fields that target the element specified by `context` and returns the number\n// of fields whose display strings changed as a result.\nexport function updateFields(textBlock: TextBlock, context: UpdateFieldsContext): number {\n let numUpdated = 0;\n for (const { child } of traverseTextBlockComponent(textBlock)) {\n if (child.type === \"field\" && updateField(child, context)) {\n ++numUpdated;\n }\n }\n\n return numUpdated;\n}\n\n// Invoked by ElementDrivesTextAnnotation to update fields in target element when source element changes or is deleted.\nexport function updateElementFields(props: RelationshipProps, iModel: IModelDb, deleted: boolean): void {\n try {\n const target = iModel.elements.getElement(props.targetId);\n if (isITextAnnotation(target)) {\n const context = createUpdateContext(props.sourceId, iModel, deleted);\n const updatedBlocks = [];\n for (const block of target.getTextBlocks()) {\n if (updateFields(block.textBlock, context)) {\n updatedBlocks.push(block);\n }\n }\n\n if (updatedBlocks.length > 0) {\n target.updateTextBlocks(updatedBlocks);\n target.update();\n }\n }\n } catch (err) {\n Logger.logException(BackendLoggerCategory.IModelDb, err);\n }\n}\n\n"]}
|
|
@@ -11,8 +11,7 @@ import { SnapshotDb } from "../IModelDb";
|
|
|
11
11
|
import { IModelHost, KnownLocations } from "../IModelHost";
|
|
12
12
|
import { Schemas } from "../Schema";
|
|
13
13
|
import { KnownTestLocations } from "./KnownTestLocations";
|
|
14
|
-
import { AzureServerStorage
|
|
15
|
-
import { ServerStorage } from "@itwin/object-storage-core";
|
|
14
|
+
import { AzureServerStorage } from "@itwin/object-storage-azure";
|
|
16
15
|
import { TestUtils } from "./TestUtils";
|
|
17
16
|
import { IModelTestUtils } from "./IModelTestUtils";
|
|
18
17
|
import { Logger, LogLevel } from "@itwin/core-bentley";
|
|
@@ -127,17 +126,24 @@ describe("IModelHost", () => {
|
|
|
127
126
|
account: "testAccount",
|
|
128
127
|
accessKey: "testAccessKey",
|
|
129
128
|
};
|
|
130
|
-
const storageStub = sinon.createStubInstance(AzureServerStorage); // I guess Sinon type definitions don't work well with overloads
|
|
131
|
-
const registerStub = sinon.stub(AzureServerStorageBindings.prototype, "register").callsFake((container) => {
|
|
132
|
-
container.bind(ServerStorage).toConstantValue(storageStub);
|
|
133
|
-
});
|
|
134
129
|
await IModelHost.startup(config);
|
|
135
130
|
assert.isDefined(IModelHost.tileStorage);
|
|
136
|
-
assert.
|
|
137
|
-
assert.
|
|
138
|
-
assert.equal(
|
|
139
|
-
|
|
140
|
-
|
|
131
|
+
assert.isDefined(IModelHost.tileStorage.storage);
|
|
132
|
+
assert.instanceOf(IModelHost.tileStorage.storage, AzureServerStorage);
|
|
133
|
+
assert.equal((IModelHost.tileStorage?.storage)._config.baseUrl, `https://${config.tileCacheAzureCredentials.account}.blob.core.windows.net`);
|
|
134
|
+
});
|
|
135
|
+
it("should set Azure cloud storage provider for tile cache with custom baseUrl", async () => {
|
|
136
|
+
const config = {};
|
|
137
|
+
config.tileCacheAzureCredentials = {
|
|
138
|
+
account: "testAccount",
|
|
139
|
+
accessKey: "testAccessKey",
|
|
140
|
+
baseUrl: "https://custom.blob.core.windows.net",
|
|
141
|
+
};
|
|
142
|
+
await IModelHost.startup(config);
|
|
143
|
+
assert.isDefined(IModelHost.tileStorage);
|
|
144
|
+
assert.isDefined(IModelHost.tileStorage.storage);
|
|
145
|
+
assert.instanceOf(IModelHost.tileStorage.storage, AzureServerStorage);
|
|
146
|
+
assert.equal((IModelHost.tileStorage?.storage)._config.baseUrl, config.tileCacheAzureCredentials.baseUrl);
|
|
141
147
|
});
|
|
142
148
|
it("should set custom cloud storage provider for tile cache", async () => {
|
|
143
149
|
const config = {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IModelHost.test.js","sourceRoot":"","sources":["../../../src/test/IModelHost.test.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACtC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAqB,cAAc,EAAE,MAAM,eAAe,CAAC;AAC9E,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACp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C;QACzE,MAAM,aAAa,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,sBAAsB,CAAC,CAAC;QACnE,IAAI,cAAc,GAAG,CAAC,SAAS,CAAC,CAAC;QACjC,IAAI,IAAI,GAAG,UAAU,CAAC,qBAAqB,CAAC,EAAE,aAAa,EAAE,cAAc,EAAE,CAAC,CAAC;QAC/E,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,0CAA0C,CAAC,CAAC;QAE/D,MAAM,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,qBAAqB,CAAC,EAAE,aAAa,EAAE,cAAc,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,wCAAwC,CAAC,CAAC;QAErJ,cAAc,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC,CAAC;QACvD,IAAI,GAAG,UAAU,CAAC,qBAAqB,CAAC,EAAE,aAAa,EAAE,cAAc,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC;QAC7F,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,0CAA0C,CAAC,CAAC;IACjE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nimport { assert, expect } from \"chai\";\nimport * as path from \"path\";\nimport * as sinon from \"sinon\";\nimport { RpcRegistry } from \"@itwin/core-common\";\nimport { BriefcaseManager } from \"../BriefcaseManager\";\nimport { SnapshotDb } from \"../IModelDb\";\nimport { IModelHost, IModelHostOptions, KnownLocations } from \"../IModelHost\";\nimport { Schemas } from \"../Schema\";\nimport { KnownTestLocations } from \"./KnownTestLocations\";\nimport { AzureServerStorage, AzureServerStorageBindings, AzureServerStorageBindingsConfig } from \"@itwin/object-storage-azure\";\nimport { ServerStorage } from \"@itwin/object-storage-core\";\nimport { TestUtils } from \"./TestUtils\";\nimport { IModelTestUtils } from \"./IModelTestUtils\";\nimport { Logger, LogLevel } from \"@itwin/core-bentley\";\nimport { overrideSyncNativeLogLevels } from \"../internal/NativePlatform\";\nimport { _getHubAccess, _hubAccess } from \"../internal/Symbols\";\n\ndescribe(\"IModelHost\", () => {\n const opts = { cacheDir: TestUtils.getCacheDir() };\n beforeEach(async () => {\n await TestUtils.shutdownBackend();\n });\n\n afterEach(async () => {\n sinon.restore();\n });\n\n after(async () => {\n await TestUtils.startBackend();\n });\n\n it(\"valid default configuration\", async () => {\n await IModelHost.startup(opts);\n\n // Valid registered implemented RPCs\n expect(RpcRegistry.instance.implementationClasses.size).to.equal(4);\n expect(RpcRegistry.instance.implementationClasses.get(\"IModelReadRpcInterface\")).to.exist;\n expect(RpcRegistry.instance.implementationClasses.get(\"IModelTileRpcInterface\")).to.exist;\n expect(RpcRegistry.instance.implementationClasses.get(\"SnapshotIModelRpcInterface\")).to.exist;\n expect(RpcRegistry.instance.implementationClasses.get(\"DevToolsRpcInterface\")).to.exist;\n\n expect(Schemas.getRegisteredSchema(\"BisCore\")).to.exist;\n expect(Schemas.getRegisteredSchema(\"Generic\")).to.exist;\n expect(Schemas.getRegisteredSchema(\"Functional\")).to.exist;\n });\n\n it(\"should properly cleanup beforeExit event listeners on shutdown\", async () => {\n const beforeCount = process.listenerCount(\"beforeExit\");\n for (let i = 0; i <= 15; i++) {\n await IModelHost.startup();\n await IModelHost.shutdown();\n\n }\n const afterCount = process.listenerCount(\"beforeExit\");\n expect(beforeCount).to.be.equal(afterCount);\n });\n\n it(\"should call logger sync function\", async () => {\n let nSyncCalls = 0;\n overrideSyncNativeLogLevels(() => ++nSyncCalls);\n await IModelHost.startup(opts);\n expect(nSyncCalls).to.equal(0);\n Logger.setLevel(\"test-cat\", LogLevel.Warning);\n expect(nSyncCalls).to.equal(1);\n overrideSyncNativeLogLevels(undefined);\n });\n\n it(\"should raise onAfterStartup events\", async () => {\n const eventHandler = sinon.spy();\n IModelHost.onAfterStartup.addOnce(eventHandler);\n await IModelHost.startup(opts);\n expect(eventHandler.calledOnce).to.be.true;\n });\n\n it(\"should raise onBeforeShutdown events\", async () => {\n await TestUtils.startBackend();\n const eventHandler = sinon.spy();\n IModelHost.onBeforeShutdown.addOnce(eventHandler);\n const filename = IModelTestUtils.resolveAssetFile(\"GetSetAutoHandledStructProperties.bim\");\n\n const workspaceClose = sinon.spy((IModelHost.appWorkspace as any), \"close\");\n const saveSettings = IModelHost.appWorkspace.settings as any;\n const settingClose = sinon.spy(saveSettings, \"close\");\n expect(workspaceClose.callCount).eq(0);\n expect(settingClose.callCount).eq(0);\n expect(saveSettings._remove).to.not.be.undefined;\n\n // shutdown should close any opened iModels. Make sure that happens\n const imodel1 = SnapshotDb.openFile(filename, { key: \"imodel1\" });\n const imodel2 = SnapshotDb.openFile(filename, { key: \"imodel2\" });\n const imodel3 = SnapshotDb.openFile(filename, { key: \"imodel3\" });\n const imodel4 = SnapshotDb.openFile(filename, { key: \"imodel4\" });\n assert.notEqual(imodel1, imodel2);\n assert.notEqual(imodel2, imodel3);\n expect(imodel1.isOpen).to.be.true;\n expect(imodel2.isOpen).to.be.true;\n expect(imodel3.isOpen).to.be.true;\n imodel4.close(); // make sure it gets removed so we don't try to close it again on shutdown\n await TestUtils.shutdownBackend();\n expect(eventHandler.calledOnce).to.be.true;\n assert.isFalse(imodel1.isOpen, \"shutdown should close iModel1\");\n assert.isFalse(imodel2.isOpen, \"shutdown should close iModel2\");\n assert.isFalse(imodel3.isOpen, \"shutdown should close iModel3\");\n expect(workspaceClose.callCount).eq(1);\n expect(settingClose.callCount).eq(1);\n expect(saveSettings._remove).to.be.undefined;\n });\n\n it(\"should auto-shutdown on process beforeExit event\", async () => {\n await TestUtils.startBackend();\n expect(IModelHost.isValid).to.be.true;\n const eventHandler = sinon.spy();\n IModelHost.onBeforeShutdown.addOnce(eventHandler);\n process.emit(\"beforeExit\", 0);\n await new Promise((resolve) => setImmediate(resolve));\n expect(eventHandler.calledOnce).to.be.true;\n expect(IModelHost.isValid).to.be.false;\n });\n\n it(\"should set the briefcase cache directory to expected locations\", async () => {\n const config: IModelHostOptions = {};\n const cacheSubDir = \"imodels\";\n\n // Test cache default location\n await IModelHost.shutdown();\n await IModelHost.startup(config);\n let expectedDir = path.join(IModelHost.cacheDir, cacheSubDir);\n assert.strictEqual(expectedDir, BriefcaseManager.cacheDir);\n\n // Test custom cache location\n await IModelHost.shutdown();\n config.cacheDir = KnownLocations.tmpdir;\n await IModelHost.startup(config);\n expectedDir = path.join(KnownLocations.tmpdir, cacheSubDir);\n assert.strictEqual(expectedDir, BriefcaseManager.cacheDir);\n });\n\n it(\"should set Azure cloud storage provider for tile cache given credentials\", async () => {\n const config: IModelHostOptions = {};\n config.tileCacheAzureCredentials = {\n account: \"testAccount\",\n accessKey: \"testAccessKey\",\n };\n\n const storageStub = sinon.createStubInstance(AzureServerStorage) as sinon.SinonStubbedInstance<AzureServerStorage> & AzureServerStorage; // I guess Sinon type definitions don't work well with overloads\n const registerStub = sinon.stub(AzureServerStorageBindings.prototype, \"register\").callsFake((container) => {\n container.bind(ServerStorage).toConstantValue(storageStub);\n });\n\n await IModelHost.startup(config);\n\n assert.isDefined(IModelHost.tileStorage);\n assert.equal(IModelHost.tileStorage!.storage, storageStub);\n assert.isTrue(registerStub.calledOnce);\n assert.equal((registerStub.firstCall.lastArg as AzureServerStorageBindingsConfig).accountName, config.tileCacheAzureCredentials.account);\n assert.equal((registerStub.firstCall.lastArg as AzureServerStorageBindingsConfig).accountKey, config.tileCacheAzureCredentials.accessKey);\n assert.equal((registerStub.firstCall.lastArg as AzureServerStorageBindingsConfig).baseUrl, `https://${config.tileCacheAzureCredentials.account}.blob.core.windows.net`);\n });\n\n it(\"should set custom cloud storage provider for tile cache\", async () => {\n const config: IModelHostOptions = {};\n config.tileCacheStorage = {} as ServerStorage;\n\n await IModelHost.startup(config);\n\n assert.isDefined(IModelHost.tileStorage);\n assert.equal(IModelHost.tileStorage!.storage, config.tileCacheStorage);\n });\n\n it(\"should throw if both tileCacheStorage and tileCacheAzureCredentials are set\", async () => {\n const config: IModelHostOptions = {};\n config.tileCacheAzureCredentials = {\n account: \"testAccount\",\n accessKey: \"testAccessKey\",\n };\n config.tileCacheStorage = {} as ServerStorage;\n\n await expect(IModelHost.startup(config)).to.be.rejectedWith(\"Cannot use both Azure and custom cloud storage providers for tile cache.\");\n });\n\n it(\"should use local cache if cloud storage provider for tile cache is not set\", async () => {\n await IModelHost.startup(opts);\n\n assert.isUndefined(IModelHost.tileStorage);\n });\n\n it(\"should cleanup tileStorage on shutdown\", async () => {\n const config: IModelHostOptions = {};\n config.tileCacheStorage = {} as ServerStorage;\n\n await IModelHost.startup(config);\n\n assert.equal(IModelHost.tileStorage?.storage, config.tileCacheStorage);\n\n await IModelHost.shutdown();\n\n assert.isUndefined(IModelHost.tileStorage);\n });\n\n it(\"should throw if hubAccess is undefined and getter is called\", async () => {\n await IModelHost.startup(opts);\n expect(IModelHost[_getHubAccess]()).undefined;\n expect(() => IModelHost[_hubAccess]).throws();\n });\n\n it(\"computeSchemaChecksum\", () => {\n const assetsDir = path.join(KnownTestLocations.assetsDir, \"ECSchemaOps\");\n const schemaXmlPath = path.join(assetsDir, \"SchemaA.ecschema.xml\");\n let referencePaths = [assetsDir];\n let sha1 = IModelHost.computeSchemaChecksum({ schemaXmlPath, referencePaths });\n expect(sha1).equal(\"3ac6578060902aa0b8426b61d62045fdf7fa0b2b\");\n\n expect(() => IModelHost.computeSchemaChecksum({ schemaXmlPath, referencePaths, exactMatch: true })).throws(\"Failed to read schema SchemaA.ecschema\");\n\n referencePaths = [path.join(assetsDir, \"exact-match\")];\n sha1 = IModelHost.computeSchemaChecksum({ schemaXmlPath, referencePaths, exactMatch: true });\n expect(sha1).equal(\"2a618664fbba1df7c05f27d7c0e8f58de250003b\");\n });\n});\n"]}
|
|
1
|
+
{"version":3,"file":"IModelHost.test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AAC,KAAK,CAAC,0CAA0C,CAAC,CAAC;IACjE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nimport { assert, expect } from \"chai\";\nimport * as path from \"path\";\nimport * as sinon from \"sinon\";\nimport { RpcRegistry } from \"@itwin/core-common\";\nimport { BriefcaseManager } from \"../BriefcaseManager\";\nimport { SnapshotDb } from \"../IModelDb\";\nimport { IModelHost, IModelHostOptions, KnownLocations } from \"../IModelHost\";\nimport { Schemas } from \"../Schema\";\nimport { KnownTestLocations } from \"./KnownTestLocations\";\nimport { AzureServerStorage } from \"@itwin/object-storage-azure\";\nimport type { ServerStorage } from \"@itwin/object-storage-core\";\nimport { TestUtils } from \"./TestUtils\";\nimport { IModelTestUtils } from \"./IModelTestUtils\";\nimport { Logger, LogLevel } from \"@itwin/core-bentley\";\nimport { overrideSyncNativeLogLevels } from \"../internal/NativePlatform\";\nimport { _getHubAccess, _hubAccess } from \"../internal/Symbols\";\n\ndescribe(\"IModelHost\", () => {\n const opts = { cacheDir: TestUtils.getCacheDir() };\n beforeEach(async () => {\n await TestUtils.shutdownBackend();\n });\n\n afterEach(async () => {\n sinon.restore();\n });\n\n after(async () => {\n await TestUtils.startBackend();\n });\n\n it(\"valid default configuration\", async () => {\n await IModelHost.startup(opts);\n\n // Valid registered implemented RPCs\n expect(RpcRegistry.instance.implementationClasses.size).to.equal(4);\n expect(RpcRegistry.instance.implementationClasses.get(\"IModelReadRpcInterface\")).to.exist;\n expect(RpcRegistry.instance.implementationClasses.get(\"IModelTileRpcInterface\")).to.exist;\n expect(RpcRegistry.instance.implementationClasses.get(\"SnapshotIModelRpcInterface\")).to.exist;\n expect(RpcRegistry.instance.implementationClasses.get(\"DevToolsRpcInterface\")).to.exist;\n\n expect(Schemas.getRegisteredSchema(\"BisCore\")).to.exist;\n expect(Schemas.getRegisteredSchema(\"Generic\")).to.exist;\n expect(Schemas.getRegisteredSchema(\"Functional\")).to.exist;\n });\n\n it(\"should properly cleanup beforeExit event listeners on shutdown\", async () => {\n const beforeCount = process.listenerCount(\"beforeExit\");\n for (let i = 0; i <= 15; i++) {\n await IModelHost.startup();\n await IModelHost.shutdown();\n\n }\n const afterCount = process.listenerCount(\"beforeExit\");\n expect(beforeCount).to.be.equal(afterCount);\n });\n\n it(\"should call logger sync function\", async () => {\n let nSyncCalls = 0;\n overrideSyncNativeLogLevels(() => ++nSyncCalls);\n await IModelHost.startup(opts);\n expect(nSyncCalls).to.equal(0);\n Logger.setLevel(\"test-cat\", LogLevel.Warning);\n expect(nSyncCalls).to.equal(1);\n overrideSyncNativeLogLevels(undefined);\n });\n\n it(\"should raise onAfterStartup events\", async () => {\n const eventHandler = sinon.spy();\n IModelHost.onAfterStartup.addOnce(eventHandler);\n await IModelHost.startup(opts);\n expect(eventHandler.calledOnce).to.be.true;\n });\n\n it(\"should raise onBeforeShutdown events\", async () => {\n await TestUtils.startBackend();\n const eventHandler = sinon.spy();\n IModelHost.onBeforeShutdown.addOnce(eventHandler);\n const filename = IModelTestUtils.resolveAssetFile(\"GetSetAutoHandledStructProperties.bim\");\n\n const workspaceClose = sinon.spy((IModelHost.appWorkspace as any), \"close\");\n const saveSettings = IModelHost.appWorkspace.settings as any;\n const settingClose = sinon.spy(saveSettings, \"close\");\n expect(workspaceClose.callCount).eq(0);\n expect(settingClose.callCount).eq(0);\n expect(saveSettings._remove).to.not.be.undefined;\n\n // shutdown should close any opened iModels. Make sure that happens\n const imodel1 = SnapshotDb.openFile(filename, { key: \"imodel1\" });\n const imodel2 = SnapshotDb.openFile(filename, { key: \"imodel2\" });\n const imodel3 = SnapshotDb.openFile(filename, { key: \"imodel3\" });\n const imodel4 = SnapshotDb.openFile(filename, { key: \"imodel4\" });\n assert.notEqual(imodel1, imodel2);\n assert.notEqual(imodel2, imodel3);\n expect(imodel1.isOpen).to.be.true;\n expect(imodel2.isOpen).to.be.true;\n expect(imodel3.isOpen).to.be.true;\n imodel4.close(); // make sure it gets removed so we don't try to close it again on shutdown\n await TestUtils.shutdownBackend();\n expect(eventHandler.calledOnce).to.be.true;\n assert.isFalse(imodel1.isOpen, \"shutdown should close iModel1\");\n assert.isFalse(imodel2.isOpen, \"shutdown should close iModel2\");\n assert.isFalse(imodel3.isOpen, \"shutdown should close iModel3\");\n expect(workspaceClose.callCount).eq(1);\n expect(settingClose.callCount).eq(1);\n expect(saveSettings._remove).to.be.undefined;\n });\n\n it(\"should auto-shutdown on process beforeExit event\", async () => {\n await TestUtils.startBackend();\n expect(IModelHost.isValid).to.be.true;\n const eventHandler = sinon.spy();\n IModelHost.onBeforeShutdown.addOnce(eventHandler);\n process.emit(\"beforeExit\", 0);\n await new Promise((resolve) => setImmediate(resolve));\n expect(eventHandler.calledOnce).to.be.true;\n expect(IModelHost.isValid).to.be.false;\n });\n\n it(\"should set the briefcase cache directory to expected locations\", async () => {\n const config: IModelHostOptions = {};\n const cacheSubDir = \"imodels\";\n\n // Test cache default location\n await IModelHost.shutdown();\n await IModelHost.startup(config);\n let expectedDir = path.join(IModelHost.cacheDir, cacheSubDir);\n assert.strictEqual(expectedDir, BriefcaseManager.cacheDir);\n\n // Test custom cache location\n await IModelHost.shutdown();\n config.cacheDir = KnownLocations.tmpdir;\n await IModelHost.startup(config);\n expectedDir = path.join(KnownLocations.tmpdir, cacheSubDir);\n assert.strictEqual(expectedDir, BriefcaseManager.cacheDir);\n });\n\n it(\"should set Azure cloud storage provider for tile cache given credentials\", async () => {\n const config: IModelHostOptions = {};\n config.tileCacheAzureCredentials = {\n account: \"testAccount\",\n accessKey: \"testAccessKey\",\n };\n\n await IModelHost.startup(config);\n\n assert.isDefined(IModelHost.tileStorage);\n assert.isDefined(IModelHost.tileStorage!.storage);\n assert.instanceOf(IModelHost.tileStorage!.storage, AzureServerStorage);\n assert.equal((IModelHost.tileStorage?.storage as any)._config.baseUrl, `https://${config.tileCacheAzureCredentials.account}.blob.core.windows.net`)\n });\n\n it(\"should set Azure cloud storage provider for tile cache with custom baseUrl\", async () => {\n const config: IModelHostOptions = {};\n config.tileCacheAzureCredentials = {\n account: \"testAccount\",\n accessKey: \"testAccessKey\",\n baseUrl: \"https://custom.blob.core.windows.net\",\n };\n\n await IModelHost.startup(config);\n\n assert.isDefined(IModelHost.tileStorage);\n assert.isDefined(IModelHost.tileStorage!.storage);\n assert.instanceOf(IModelHost.tileStorage!.storage, AzureServerStorage);\n assert.equal((IModelHost.tileStorage?.storage as any)._config.baseUrl, config.tileCacheAzureCredentials.baseUrl)\n });\n\n it(\"should set custom cloud storage provider for tile cache\", async () => {\n const config: IModelHostOptions = {};\n config.tileCacheStorage = {} as ServerStorage;\n\n await IModelHost.startup(config);\n\n assert.isDefined(IModelHost.tileStorage);\n assert.equal(IModelHost.tileStorage!.storage, config.tileCacheStorage);\n });\n\n it(\"should throw if both tileCacheStorage and tileCacheAzureCredentials are set\", async () => {\n const config: IModelHostOptions = {};\n config.tileCacheAzureCredentials = {\n account: \"testAccount\",\n accessKey: \"testAccessKey\",\n };\n config.tileCacheStorage = {} as ServerStorage;\n\n await expect(IModelHost.startup(config)).to.be.rejectedWith(\"Cannot use both Azure and custom cloud storage providers for tile cache.\");\n });\n\n it(\"should use local cache if cloud storage provider for tile cache is not set\", async () => {\n await IModelHost.startup(opts);\n\n assert.isUndefined(IModelHost.tileStorage);\n });\n\n it(\"should cleanup tileStorage on shutdown\", async () => {\n const config: IModelHostOptions = {};\n config.tileCacheStorage = {} as ServerStorage;\n\n await IModelHost.startup(config);\n\n assert.equal(IModelHost.tileStorage?.storage, config.tileCacheStorage);\n\n await IModelHost.shutdown();\n\n assert.isUndefined(IModelHost.tileStorage);\n });\n\n it(\"should throw if hubAccess is undefined and getter is called\", async () => {\n await IModelHost.startup(opts);\n expect(IModelHost[_getHubAccess]()).undefined;\n expect(() => IModelHost[_hubAccess]).throws();\n });\n\n it(\"computeSchemaChecksum\", () => {\n const assetsDir = path.join(KnownTestLocations.assetsDir, \"ECSchemaOps\");\n const schemaXmlPath = path.join(assetsDir, \"SchemaA.ecschema.xml\");\n let referencePaths = [assetsDir];\n let sha1 = IModelHost.computeSchemaChecksum({ schemaXmlPath, referencePaths });\n expect(sha1).equal(\"3ac6578060902aa0b8426b61d62045fdf7fa0b2b\");\n\n expect(() => IModelHost.computeSchemaChecksum({ schemaXmlPath, referencePaths, exactMatch: true })).throws(\"Failed to read schema SchemaA.ecschema\");\n\n referencePaths = [path.join(assetsDir, \"exact-match\")];\n sha1 = IModelHost.computeSchemaChecksum({ schemaXmlPath, referencePaths, exactMatch: true });\n expect(sha1).equal(\"2a618664fbba1df7c05f27d7c0e8f58de250003b\");\n });\n});\n"]}
|