@itwin/core-backend 5.3.0-dev.3 → 5.3.0-dev.5
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/lib/cjs/annotations/TextAnnotationElement.d.ts +101 -20
- package/lib/cjs/annotations/TextAnnotationElement.d.ts.map +1 -1
- package/lib/cjs/annotations/TextAnnotationElement.js +202 -64
- package/lib/cjs/annotations/TextAnnotationElement.js.map +1 -1
- package/lib/esm/annotations/TextAnnotationElement.d.ts +101 -20
- package/lib/esm/annotations/TextAnnotationElement.d.ts.map +1 -1
- package/lib/esm/annotations/TextAnnotationElement.js +201 -63
- package/lib/esm/annotations/TextAnnotationElement.js.map +1 -1
- package/lib/esm/test/annotations/TextAnnotation.test.js +110 -13
- package/lib/esm/test/annotations/TextAnnotation.test.js.map +1 -1
- package/package.json +13 -13
|
@@ -11,18 +11,48 @@ import { assert } from "@itwin/core-bentley";
|
|
|
11
11
|
import { layoutTextBlock, TextStyleResolver } from "./TextBlockLayout";
|
|
12
12
|
import { appendTextAnnotationGeometry } from "./TextAnnotationGeometry";
|
|
13
13
|
import { ElementDrivesTextAnnotation, TextAnnotationUsesTextStyleByDefault } from "./ElementDrivesTextAnnotation";
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
import * as semver from "semver";
|
|
15
|
+
/** The version of the JSON stored in `TextAnnotation2d/3dProps.textAnnotationData` used by the code.
|
|
16
|
+
* Uses the same semantics as [ECVersion]($ecschema-metadata).
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
export const TEXT_ANNOTATION_JSON_VERSION = "1.0.0";
|
|
20
|
+
function validateAndMigrateVersionedJSON(json, currentVersion, migrate) {
|
|
21
|
+
let parsed;
|
|
17
22
|
try {
|
|
18
|
-
|
|
23
|
+
parsed = JSON.parse(json);
|
|
19
24
|
}
|
|
20
25
|
catch {
|
|
21
26
|
return undefined;
|
|
22
27
|
}
|
|
28
|
+
const version = parsed.version;
|
|
29
|
+
if (typeof version !== "string" || !semver.valid(version))
|
|
30
|
+
throw new Error("JSON version is missing or invalid.");
|
|
31
|
+
if (typeof parsed.data !== "object" || parsed.data === null)
|
|
32
|
+
throw new Error("JSON data is missing or invalid.");
|
|
33
|
+
// Newer
|
|
34
|
+
if (semver.gt(version, currentVersion))
|
|
35
|
+
throw new Error(`JSON version ${parsed.version} is newer than supported version ${currentVersion}. Application update required to understand data.`);
|
|
36
|
+
// Older
|
|
37
|
+
if (semver.lt(version, currentVersion)) {
|
|
38
|
+
parsed.data = migrate(parsed);
|
|
39
|
+
parsed.version = currentVersion;
|
|
40
|
+
}
|
|
41
|
+
return parsed;
|
|
23
42
|
}
|
|
24
|
-
function
|
|
25
|
-
|
|
43
|
+
function migrateTextAnnotationData(oldData) {
|
|
44
|
+
if (oldData.version === TEXT_ANNOTATION_JSON_VERSION)
|
|
45
|
+
return oldData.data;
|
|
46
|
+
// Place migration logic here.
|
|
47
|
+
throw new Error(`Migration for textAnnotationData from version ${oldData.version} to ${TEXT_ANNOTATION_JSON_VERSION} failed.`);
|
|
48
|
+
}
|
|
49
|
+
/** Parses, validates, and potentially migrates the text annotation data from a JSON string. */
|
|
50
|
+
function parseTextAnnotationData(json) {
|
|
51
|
+
if (!json)
|
|
52
|
+
return undefined;
|
|
53
|
+
return validateAndMigrateVersionedJSON(json, TEXT_ANNOTATION_JSON_VERSION, migrateTextAnnotationData);
|
|
54
|
+
}
|
|
55
|
+
function getElementGeometryBuilderParams(iModel, modelId, categoryId, _placementProps, annotationProps, textStyleId, _subCategory) {
|
|
26
56
|
const textBlock = TextAnnotation.fromJSON(annotationProps).textBlock;
|
|
27
57
|
const textStyleResolver = new TextStyleResolver({ textBlock, textStyleId: textStyleId ?? "", iModel });
|
|
28
58
|
const layout = layoutTextBlock({ iModel, textBlock, textStyleResolver });
|
|
@@ -47,28 +77,27 @@ export class TextAnnotation2d extends AnnotationElement2d /* implements ITextAnn
|
|
|
47
77
|
* @beta
|
|
48
78
|
*/
|
|
49
79
|
defaultTextStyle;
|
|
50
|
-
/**
|
|
51
|
-
|
|
80
|
+
/** The data associated with the text annotation. */
|
|
81
|
+
_textAnnotationProps;
|
|
52
82
|
/** Extract the textual content, if present.
|
|
53
83
|
* @see [[setAnnotation]] to change it.
|
|
54
84
|
*/
|
|
55
85
|
getAnnotation() {
|
|
56
|
-
|
|
57
|
-
return textAnnotationProps ? TextAnnotation.fromJSON(textAnnotationProps) : undefined;
|
|
86
|
+
return this._textAnnotationProps ? TextAnnotation.fromJSON(this._textAnnotationProps) : undefined;
|
|
58
87
|
}
|
|
59
88
|
/** Change the textual content of the `TextAnnotation2d`.
|
|
60
89
|
* @see [[getAnnotation]] to extract the current annotation.
|
|
61
90
|
* @param annotation The new annotation
|
|
62
91
|
*/
|
|
63
92
|
setAnnotation(annotation) {
|
|
64
|
-
this.
|
|
93
|
+
this._textAnnotationProps = annotation.toJSON();
|
|
65
94
|
}
|
|
66
95
|
constructor(props, iModel) {
|
|
67
96
|
super(props, iModel);
|
|
68
97
|
if (props.defaultTextStyle) {
|
|
69
98
|
this.defaultTextStyle = new TextAnnotationUsesTextStyleByDefault(props.defaultTextStyle.id);
|
|
70
99
|
}
|
|
71
|
-
this.
|
|
100
|
+
this._textAnnotationProps = parseTextAnnotationData(props.textAnnotationData)?.data;
|
|
72
101
|
}
|
|
73
102
|
/** Creates a new instance of `TextAnnotation2d` from its JSON representation. */
|
|
74
103
|
static fromJSON(props, iModel) {
|
|
@@ -77,14 +106,13 @@ export class TextAnnotation2d extends AnnotationElement2d /* implements ITextAnn
|
|
|
77
106
|
/**
|
|
78
107
|
* Converts the current `TextAnnotation2d` instance to its JSON representation.
|
|
79
108
|
* It also computes the `elementGeometryBuilderParams` property used to create the GeometryStream.
|
|
80
|
-
|
|
81
109
|
* @inheritdoc
|
|
82
110
|
*/
|
|
83
111
|
toJSON() {
|
|
84
112
|
const props = super.toJSON();
|
|
85
|
-
props.textAnnotationData = this.
|
|
86
|
-
if (this.
|
|
87
|
-
props.elementGeometryBuilderParams = getElementGeometryBuilderParams(this.iModel, this.model, this.
|
|
113
|
+
props.textAnnotationData = this._textAnnotationProps ? JSON.stringify({ version: TEXT_ANNOTATION_JSON_VERSION, data: this._textAnnotationProps }) : undefined;
|
|
114
|
+
if (this._textAnnotationProps) {
|
|
115
|
+
props.elementGeometryBuilderParams = getElementGeometryBuilderParams(this.iModel, this.model, this.category, this.placement, this._textAnnotationProps, this.defaultTextStyle ? this.defaultTextStyle.id : undefined);
|
|
88
116
|
}
|
|
89
117
|
return props;
|
|
90
118
|
}
|
|
@@ -96,7 +124,7 @@ export class TextAnnotation2d extends AnnotationElement2d /* implements ITextAnn
|
|
|
96
124
|
static create(iModelDb, arg) {
|
|
97
125
|
const elementProps = {
|
|
98
126
|
classFullName: this.classFullName,
|
|
99
|
-
textAnnotationData: JSON.stringify(arg.
|
|
127
|
+
textAnnotationData: arg.textAnnotationProps ? JSON.stringify({ version: TEXT_ANNOTATION_JSON_VERSION, data: arg.textAnnotationProps }) : undefined,
|
|
100
128
|
defaultTextStyle: arg.defaultTextStyleId ? new TextAnnotationUsesTextStyleByDefault(arg.defaultTextStyleId).toJSON() : undefined,
|
|
101
129
|
placement: arg.placement,
|
|
102
130
|
model: arg.model,
|
|
@@ -106,32 +134,68 @@ export class TextAnnotation2d extends AnnotationElement2d /* implements ITextAnn
|
|
|
106
134
|
return new this(elementProps, iModelDb);
|
|
107
135
|
}
|
|
108
136
|
/**
|
|
109
|
-
* Updates the geometry of the TextAnnotation2d on insert.
|
|
137
|
+
* Updates the geometry of the TextAnnotation2d on insert and validates version.
|
|
110
138
|
* @inheritdoc
|
|
111
139
|
* @beta
|
|
112
140
|
*/
|
|
113
141
|
static onInsert(arg) {
|
|
114
142
|
super.onInsert(arg);
|
|
115
|
-
this.
|
|
143
|
+
this.validateVersionAndUpdateGeometry(arg);
|
|
116
144
|
}
|
|
117
145
|
/**
|
|
118
|
-
* Updates the geometry of the TextAnnotation2d on update.
|
|
146
|
+
* Updates the geometry of the TextAnnotation2d on update and validates version.
|
|
119
147
|
* @inheritdoc
|
|
120
148
|
* @beta
|
|
121
149
|
*/
|
|
122
150
|
static onUpdate(arg) {
|
|
123
151
|
super.onUpdate(arg);
|
|
124
|
-
this.
|
|
152
|
+
this.validateVersionAndUpdateGeometry(arg);
|
|
125
153
|
}
|
|
126
154
|
/**
|
|
127
155
|
* Populates the `elementGeometryBuilderParams` property in the [TextAnnotation2dProps]($common).
|
|
128
|
-
*
|
|
156
|
+
* Only does this if the `elementGeometryBuilderParams` is not already set and if there is actually a text annotation to produce geometry for.
|
|
157
|
+
* Also, validates the version of the text annotation data and migrates it if necessary.
|
|
158
|
+
* @beta
|
|
129
159
|
*/
|
|
130
|
-
static
|
|
131
|
-
|
|
132
|
-
|
|
160
|
+
static validateVersionAndUpdateGeometry(arg) {
|
|
161
|
+
const props = arg.props;
|
|
162
|
+
const textAnnotationData = parseTextAnnotationData(props.textAnnotationData);
|
|
163
|
+
if (!props.elementGeometryBuilderParams && textAnnotationData) {
|
|
164
|
+
props.elementGeometryBuilderParams = getElementGeometryBuilderParams(arg.iModel, props.model, props.category, props.placement ?? Placement2d.fromJSON(), textAnnotationData.data, props.defaultTextStyle?.id);
|
|
133
165
|
}
|
|
134
|
-
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* TextAnnotation2d custom HandledProps include 'textAnnotationData'.
|
|
169
|
+
* @inheritdoc
|
|
170
|
+
* @internal
|
|
171
|
+
*/
|
|
172
|
+
static _customHandledProps = [
|
|
173
|
+
{ propertyName: "textAnnotationData", source: "Class" },
|
|
174
|
+
];
|
|
175
|
+
/**
|
|
176
|
+
* TextAnnotation2d deserializes 'textAnnotationData'.
|
|
177
|
+
* @inheritdoc
|
|
178
|
+
* @beta
|
|
179
|
+
*/
|
|
180
|
+
static deserialize(props) {
|
|
181
|
+
const elProps = super.deserialize(props);
|
|
182
|
+
const textAnnotationData = parseTextAnnotationData(props.row.textAnnotationData);
|
|
183
|
+
if (textAnnotationData) {
|
|
184
|
+
elProps.textAnnotationData = JSON.stringify(textAnnotationData);
|
|
185
|
+
}
|
|
186
|
+
return elProps;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* TextAnnotation2d serializes 'textAnnotationData'.
|
|
190
|
+
* @inheritdoc
|
|
191
|
+
* @beta
|
|
192
|
+
*/
|
|
193
|
+
static serialize(props, iModel) {
|
|
194
|
+
const inst = super.serialize(props, iModel);
|
|
195
|
+
if (props.textAnnotationData !== undefined) {
|
|
196
|
+
inst.textAnnotationData = props.textAnnotationData;
|
|
197
|
+
}
|
|
198
|
+
return inst;
|
|
135
199
|
}
|
|
136
200
|
/** @internal */
|
|
137
201
|
getTextBlocks() {
|
|
@@ -165,28 +229,27 @@ export class TextAnnotation3d extends GraphicalElement3d /* implements ITextAnno
|
|
|
165
229
|
* @beta
|
|
166
230
|
*/
|
|
167
231
|
defaultTextStyle;
|
|
168
|
-
/**
|
|
169
|
-
|
|
232
|
+
/** The data associated with the text annotation. */
|
|
233
|
+
_textAnnotationProps;
|
|
170
234
|
/** Extract the textual content, if present.
|
|
171
235
|
* @see [[setAnnotation]] to change it.
|
|
172
236
|
*/
|
|
173
237
|
getAnnotation() {
|
|
174
|
-
|
|
175
|
-
return textAnnotationProps ? TextAnnotation.fromJSON(textAnnotationProps) : undefined;
|
|
238
|
+
return this._textAnnotationProps ? TextAnnotation.fromJSON(this._textAnnotationProps) : undefined;
|
|
176
239
|
}
|
|
177
240
|
/** Change the textual content of the `TextAnnotation3d`.
|
|
178
241
|
* @see [[getAnnotation]] to extract the current annotation.
|
|
179
242
|
* @param annotation The new annotation
|
|
180
243
|
*/
|
|
181
244
|
setAnnotation(annotation) {
|
|
182
|
-
this.
|
|
245
|
+
this._textAnnotationProps = annotation.toJSON();
|
|
183
246
|
}
|
|
184
247
|
constructor(props, iModel) {
|
|
185
248
|
super(props, iModel);
|
|
186
249
|
if (props.defaultTextStyle) {
|
|
187
250
|
this.defaultTextStyle = new TextAnnotationUsesTextStyleByDefault(props.defaultTextStyle.id);
|
|
188
251
|
}
|
|
189
|
-
this.
|
|
252
|
+
this._textAnnotationProps = parseTextAnnotationData(props.textAnnotationData)?.data;
|
|
190
253
|
}
|
|
191
254
|
/** Creates a new instance of `TextAnnotation3d` from its JSON representation. */
|
|
192
255
|
static fromJSON(props, iModel) {
|
|
@@ -199,9 +262,9 @@ export class TextAnnotation3d extends GraphicalElement3d /* implements ITextAnno
|
|
|
199
262
|
*/
|
|
200
263
|
toJSON() {
|
|
201
264
|
const props = super.toJSON();
|
|
202
|
-
props.textAnnotationData = this.
|
|
203
|
-
if (this.
|
|
204
|
-
props.elementGeometryBuilderParams = getElementGeometryBuilderParams(this.iModel, this.model, this.
|
|
265
|
+
props.textAnnotationData = this._textAnnotationProps ? JSON.stringify({ version: TEXT_ANNOTATION_JSON_VERSION, data: this._textAnnotationProps }) : undefined;
|
|
266
|
+
if (this._textAnnotationProps) {
|
|
267
|
+
props.elementGeometryBuilderParams = getElementGeometryBuilderParams(this.iModel, this.model, this.category, this.placement, this._textAnnotationProps, this.defaultTextStyle ? this.defaultTextStyle.id : undefined);
|
|
205
268
|
}
|
|
206
269
|
return props;
|
|
207
270
|
}
|
|
@@ -213,7 +276,7 @@ export class TextAnnotation3d extends GraphicalElement3d /* implements ITextAnno
|
|
|
213
276
|
static create(iModelDb, arg) {
|
|
214
277
|
const elementProps = {
|
|
215
278
|
classFullName: this.classFullName,
|
|
216
|
-
textAnnotationData: JSON.stringify(arg.
|
|
279
|
+
textAnnotationData: arg.textAnnotationProps ? JSON.stringify({ version: TEXT_ANNOTATION_JSON_VERSION, data: arg.textAnnotationProps }) : undefined,
|
|
217
280
|
defaultTextStyle: arg.defaultTextStyleId ? new TextAnnotationUsesTextStyleByDefault(arg.defaultTextStyleId).toJSON() : undefined,
|
|
218
281
|
placement: arg.placement,
|
|
219
282
|
model: arg.model,
|
|
@@ -223,32 +286,68 @@ export class TextAnnotation3d extends GraphicalElement3d /* implements ITextAnno
|
|
|
223
286
|
return new this(elementProps, iModelDb);
|
|
224
287
|
}
|
|
225
288
|
/**
|
|
226
|
-
* Updates the geometry of the TextAnnotation3d on insert
|
|
289
|
+
* Updates the geometry of the TextAnnotation3d on insert and validates version..
|
|
227
290
|
* @inheritdoc
|
|
228
291
|
* @beta
|
|
229
292
|
*/
|
|
230
293
|
static onInsert(arg) {
|
|
231
294
|
super.onInsert(arg);
|
|
232
|
-
this.
|
|
295
|
+
this.validateVersionAndUpdateGeometry(arg);
|
|
233
296
|
}
|
|
234
297
|
/**
|
|
235
|
-
* Updates the geometry of the TextAnnotation3d on update
|
|
298
|
+
* Updates the geometry of the TextAnnotation3d on update and validates version..
|
|
236
299
|
* @inheritdoc
|
|
237
300
|
* @beta
|
|
238
301
|
*/
|
|
239
302
|
static onUpdate(arg) {
|
|
240
303
|
super.onUpdate(arg);
|
|
241
|
-
this.
|
|
304
|
+
this.validateVersionAndUpdateGeometry(arg);
|
|
242
305
|
}
|
|
243
306
|
/**
|
|
244
307
|
* Populates the `elementGeometryBuilderParams` property in the [TextAnnotation3dProps]($common).
|
|
245
|
-
*
|
|
308
|
+
* Only does this if the `elementGeometryBuilderParams` is not already set and if there is actually a text annotation to produce geometry for.
|
|
309
|
+
* Also, validates the version of the text annotation data and migrates it if necessary.
|
|
310
|
+
* @beta
|
|
246
311
|
*/
|
|
247
|
-
static
|
|
248
|
-
|
|
249
|
-
|
|
312
|
+
static validateVersionAndUpdateGeometry(arg) {
|
|
313
|
+
const props = arg.props;
|
|
314
|
+
const textAnnotationData = parseTextAnnotationData(props.textAnnotationData);
|
|
315
|
+
if (!props.elementGeometryBuilderParams && textAnnotationData) {
|
|
316
|
+
props.elementGeometryBuilderParams = getElementGeometryBuilderParams(arg.iModel, props.model, props.category, props.placement ?? Placement3d.fromJSON(), textAnnotationData.data, props.defaultTextStyle?.id);
|
|
250
317
|
}
|
|
251
|
-
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* TextAnnotation3d custom HandledProps include 'textAnnotationData'.
|
|
321
|
+
* @inheritdoc
|
|
322
|
+
* @internal
|
|
323
|
+
*/
|
|
324
|
+
static _customHandledProps = [
|
|
325
|
+
{ propertyName: "textAnnotationData", source: "Class" },
|
|
326
|
+
];
|
|
327
|
+
/**
|
|
328
|
+
* TextAnnotation3d deserializes 'textAnnotationData'.
|
|
329
|
+
* @inheritdoc
|
|
330
|
+
* @beta
|
|
331
|
+
*/
|
|
332
|
+
static deserialize(props) {
|
|
333
|
+
const elProps = super.deserialize(props);
|
|
334
|
+
const textAnnotationData = parseTextAnnotationData(props.row.textAnnotationData);
|
|
335
|
+
if (textAnnotationData) {
|
|
336
|
+
elProps.textAnnotationData = JSON.stringify(textAnnotationData);
|
|
337
|
+
}
|
|
338
|
+
return elProps;
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* TextAnnotation3d serializes 'textAnnotationData'.
|
|
342
|
+
* @inheritdoc
|
|
343
|
+
* @beta
|
|
344
|
+
*/
|
|
345
|
+
static serialize(props, iModel) {
|
|
346
|
+
const inst = super.serialize(props, iModel);
|
|
347
|
+
if (props.textAnnotationData !== undefined) {
|
|
348
|
+
inst.textAnnotationData = props.textAnnotationData;
|
|
349
|
+
}
|
|
350
|
+
return inst;
|
|
252
351
|
}
|
|
253
352
|
/** @internal */
|
|
254
353
|
getTextBlocks() {
|
|
@@ -286,6 +385,17 @@ function updateTextBlocks(elem, textBlocks) {
|
|
|
286
385
|
elem.setAnnotation(annotation);
|
|
287
386
|
elem.update();
|
|
288
387
|
}
|
|
388
|
+
/** The version of the JSON stored in `AnnotationTextStyleProps.settings` used by the code.
|
|
389
|
+
* Uses the same semantics as [ECVersion]($ecschema-metadata).
|
|
390
|
+
* @internal
|
|
391
|
+
*/
|
|
392
|
+
export const TEXT_STYLE_SETTINGS_JSON_VERSION = "1.0.0";
|
|
393
|
+
function migrateTextStyleSettings(oldData) {
|
|
394
|
+
if (oldData.version === TEXT_STYLE_SETTINGS_JSON_VERSION)
|
|
395
|
+
return oldData.data;
|
|
396
|
+
// Place migration logic here.
|
|
397
|
+
throw new Error(`Migration for settings from version ${oldData.version} to ${TEXT_STYLE_SETTINGS_JSON_VERSION} failed.`);
|
|
398
|
+
}
|
|
289
399
|
/**
|
|
290
400
|
* The definition element that holds text style information.
|
|
291
401
|
* The style is stored as a [TextStyleSettings]($common).
|
|
@@ -307,7 +417,7 @@ export class AnnotationTextStyle extends DefinitionElement {
|
|
|
307
417
|
super(props, iModel);
|
|
308
418
|
this.description = props.description;
|
|
309
419
|
const settingsProps = AnnotationTextStyle.parseTextStyleSettings(props.settings);
|
|
310
|
-
this.settings = TextStyleSettings.fromJSON(settingsProps);
|
|
420
|
+
this.settings = TextStyleSettings.fromJSON(settingsProps?.data);
|
|
311
421
|
}
|
|
312
422
|
/**
|
|
313
423
|
* Creates a Code for an `AnnotationTextStyle` given a name that is meant to be unique within the scope of the specified DefinitionModel.
|
|
@@ -315,6 +425,7 @@ export class AnnotationTextStyle extends DefinitionElement {
|
|
|
315
425
|
* @param iModel - The IModelDb.
|
|
316
426
|
* @param definitionModelId - The ID of the DefinitionModel that contains the AnnotationTextStyle and provides the scope for its name.
|
|
317
427
|
* @param name - The AnnotationTextStyle name.
|
|
428
|
+
* @beta
|
|
318
429
|
*/
|
|
319
430
|
static createCode(iModel, definitionModelId, name) {
|
|
320
431
|
const codeSpec = iModel.codeSpecs.getByName(BisCodeSpec.annotationTextStyle);
|
|
@@ -324,18 +435,16 @@ export class AnnotationTextStyle extends DefinitionElement {
|
|
|
324
435
|
* Creates a new instance of `AnnotationTextStyle` with the specified properties.
|
|
325
436
|
*
|
|
326
437
|
* @param iModelDb - The iModelDb.
|
|
327
|
-
* @param
|
|
328
|
-
* @
|
|
329
|
-
* @param settings - Optional text style settings used to create the `AnnotationTextStyle`. Default settings will be used if not provided.
|
|
330
|
-
* @param description - Optional description for the `AnnotationTextStyle`.
|
|
438
|
+
* @param arg - The arguments for creating the AnnotationTextStyle.
|
|
439
|
+
* @beta
|
|
331
440
|
*/
|
|
332
|
-
static create(iModelDb,
|
|
441
|
+
static create(iModelDb, arg) {
|
|
333
442
|
const props = {
|
|
334
443
|
classFullName: this.classFullName,
|
|
335
|
-
model: definitionModelId,
|
|
336
|
-
code: this.createCode(iModelDb, definitionModelId, name).toJSON(),
|
|
337
|
-
description,
|
|
338
|
-
settings: JSON.stringify(settings),
|
|
444
|
+
model: arg.definitionModelId,
|
|
445
|
+
code: this.createCode(iModelDb, arg.definitionModelId, arg.name).toJSON(),
|
|
446
|
+
description: arg.description,
|
|
447
|
+
settings: arg.settings ? JSON.stringify({ version: TEXT_STYLE_SETTINGS_JSON_VERSION, data: arg.settings }) : undefined,
|
|
339
448
|
};
|
|
340
449
|
return new this(props, iModelDb);
|
|
341
450
|
}
|
|
@@ -346,7 +455,7 @@ export class AnnotationTextStyle extends DefinitionElement {
|
|
|
346
455
|
toJSON() {
|
|
347
456
|
const props = super.toJSON();
|
|
348
457
|
props.description = this.description;
|
|
349
|
-
props.settings = JSON.stringify(this.settings.toJSON());
|
|
458
|
+
props.settings = JSON.stringify({ version: TEXT_STYLE_SETTINGS_JSON_VERSION, data: this.settings.toJSON() });
|
|
350
459
|
return props;
|
|
351
460
|
}
|
|
352
461
|
/** Creates a new instance of `AnnotationTextStyle` from its JSON representation. */
|
|
@@ -375,21 +484,50 @@ export class AnnotationTextStyle extends DefinitionElement {
|
|
|
375
484
|
const settingProps = AnnotationTextStyle.parseTextStyleSettings(props.settings);
|
|
376
485
|
if (!settingProps)
|
|
377
486
|
return;
|
|
378
|
-
const settings = TextStyleSettings.fromJSON(settingProps);
|
|
487
|
+
const settings = TextStyleSettings.fromJSON(settingProps.data);
|
|
379
488
|
const errors = settings.getValidationErrors();
|
|
380
489
|
if (errors.length > 0) {
|
|
381
490
|
throw new Error(`Invalid AnnotationTextStyle settings: ${errors.join(", ")}`);
|
|
382
491
|
}
|
|
383
492
|
}
|
|
493
|
+
/**
|
|
494
|
+
* AnnotationTextStyle custom HandledProps include 'settings'.
|
|
495
|
+
* @inheritdoc
|
|
496
|
+
* @beta
|
|
497
|
+
*/
|
|
498
|
+
static _customHandledProps = [
|
|
499
|
+
{ propertyName: "settings", source: "Class" },
|
|
500
|
+
];
|
|
501
|
+
/**
|
|
502
|
+
* AnnotationTextStyle deserializes 'settings'.
|
|
503
|
+
* @inheritdoc
|
|
504
|
+
* @beta
|
|
505
|
+
*/
|
|
506
|
+
static deserialize(props) {
|
|
507
|
+
const elProps = super.deserialize(props);
|
|
508
|
+
const settings = this.parseTextStyleSettings(props.row.settings);
|
|
509
|
+
if (settings) {
|
|
510
|
+
elProps.settings = JSON.stringify(settings);
|
|
511
|
+
}
|
|
512
|
+
return elProps;
|
|
513
|
+
}
|
|
514
|
+
/**
|
|
515
|
+
* AnnotationTextStyle serializes 'settings'.
|
|
516
|
+
* @inheritdoc
|
|
517
|
+
* @beta
|
|
518
|
+
*/
|
|
519
|
+
static serialize(props, iModel) {
|
|
520
|
+
const inst = super.serialize(props, iModel);
|
|
521
|
+
if (props.settings !== undefined) {
|
|
522
|
+
inst.settings = props.settings;
|
|
523
|
+
}
|
|
524
|
+
return inst;
|
|
525
|
+
}
|
|
526
|
+
/** Parses, validates, and potentially migrates the text style settings data from a JSON string. */
|
|
384
527
|
static parseTextStyleSettings(json) {
|
|
385
528
|
if (!json)
|
|
386
529
|
return undefined;
|
|
387
|
-
|
|
388
|
-
return JSON.parse(json);
|
|
389
|
-
}
|
|
390
|
-
catch {
|
|
391
|
-
return undefined;
|
|
392
|
-
}
|
|
530
|
+
return validateAndMigrateVersionedJSON(json, TEXT_STYLE_SETTINGS_JSON_VERSION, migrateTextStyleSettings);
|
|
393
531
|
}
|
|
394
532
|
}
|
|
395
533
|
//# sourceMappingURL=TextAnnotationElement.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextAnnotationElement.js","sourceRoot":"","sources":["../../../src/annotations/TextAnnotationElement.ts"],"names":[],"mappings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IAAI,CAAC,IAAI;YAAE,OAAO,SAAS,CAAC;QAC5B,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC1B,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,SAAS,CAAC;QACnB,CAAC;IACH,CAAC;CACF","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, ElementGeometry, ElementGeometryBuilderParams, Placement2d, Placement2dProps, Placement3d, Placement3dProps, PlacementProps, TextAnnotation, TextAnnotation2dProps, TextAnnotation3dProps, TextAnnotationProps, TextStyleSettings, TextStyleSettingsProps } 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\";\n\nfunction parseTextAnnotationData(json: string | undefined): TextAnnotationProps | undefined {\n if (!json) return undefined;\n try {\n return JSON.parse(json);\n } catch {\n return undefined;\n }\n}\n\nfunction getElementGeometryBuilderParams(iModel: IModelDb, modelId: Id64String, _placementProps: PlacementProps, stringifiedAnnotationProps: string, categoryId: Id64String, textStyleId?: Id64String, _subCategory?: Id64String): ElementGeometryBuilderParams {\n const annotationProps = parseTextAnnotationData(stringifiedAnnotationProps);\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 textAnnotationData?: 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 textAnnotationData?: 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 /** Optional string containing the data associated with the text annotation. */\n private _textAnnotationData?: string;\n\n /** Extract the textual content, if present.\n * @see [[setAnnotation]] to change it.\n */\n public getAnnotation(): TextAnnotation | undefined {\n const textAnnotationProps = parseTextAnnotationData(this._textAnnotationData);\n return textAnnotationProps ? TextAnnotation.fromJSON(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._textAnnotationData = annotation ? JSON.stringify(annotation.toJSON()) : undefined;\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._textAnnotationData = props.textAnnotationData;\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\n * @inheritdoc\n */\n public override toJSON(): TextAnnotation2dProps {\n const props = super.toJSON() as TextAnnotation2dProps;\n props.textAnnotationData = this._textAnnotationData;\n if (this._textAnnotationData) {\n props.elementGeometryBuilderParams = getElementGeometryBuilderParams(this.iModel, this.model, this.placement, this._textAnnotationData, this.category, 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: JSON.stringify(arg.textAnnotationData),\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.\n * @inheritdoc\n * @beta\n */\n protected static override onInsert(arg: OnElementPropsArg): void {\n super.onInsert(arg);\n this.updateGeometry(arg.iModel, arg.props as TextAnnotation2dProps);\n }\n\n /**\n * Updates the geometry of the TextAnnotation2d on update.\n * @inheritdoc\n * @beta\n */\n protected static override onUpdate(arg: OnElementPropsArg): void {\n super.onUpdate(arg);\n this.updateGeometry(arg.iModel, arg.props as TextAnnotation2dProps);\n }\n\n /**\n * Populates the `elementGeometryBuilderParams` property in the [TextAnnotation2dProps]($common).\n * It only does this if the `elementGeometryBuilderParams` is not already set and if there is actually a text annotation to produce geometry for.\n */\n protected static updateGeometry(iModelDb: IModelDb, props: TextAnnotation2dProps): void {\n if (props.elementGeometryBuilderParams || !props.textAnnotationData) {\n return;\n }\n\n props.elementGeometryBuilderParams = getElementGeometryBuilderParams(iModelDb, props.model, props.placement ?? Placement2d.fromJSON(), props.textAnnotationData, props.category, props.defaultTextStyle ? props.defaultTextStyle.id : undefined);\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 /** Optional string containing the data associated with the text annotation. */\n private _textAnnotationData?: string;\n\n /** Extract the textual content, if present.\n * @see [[setAnnotation]] to change it.\n */\n public getAnnotation(): TextAnnotation | undefined {\n const textAnnotationProps = parseTextAnnotationData(this._textAnnotationData);\n return textAnnotationProps ? TextAnnotation.fromJSON(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._textAnnotationData = annotation ? JSON.stringify(annotation.toJSON()) : undefined;\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._textAnnotationData = props.textAnnotationData;\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._textAnnotationData;\n if (this._textAnnotationData) {\n props.elementGeometryBuilderParams = getElementGeometryBuilderParams(this.iModel, this.model, this.placement, this._textAnnotationData, this.category, 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: JSON.stringify(arg.textAnnotationData),\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.\n * @inheritdoc\n * @beta\n */\n protected static override onInsert(arg: OnElementPropsArg): void {\n super.onInsert(arg);\n this.updateGeometry(arg.iModel, arg.props as TextAnnotation3dProps);\n }\n\n /**\n * Updates the geometry of the TextAnnotation3d on update.\n * @inheritdoc\n * @beta\n */\n protected static override onUpdate(arg: OnElementPropsArg): void {\n super.onUpdate(arg);\n this.updateGeometry(arg.iModel, arg.props as TextAnnotation3dProps);\n }\n\n /**\n * Populates the `elementGeometryBuilderParams` property in the [TextAnnotation3dProps]($common).\n * It only does this if the `elementGeometryBuilderParams` is not already set and if there is actually a text annotation to produce geometry for.\n */\n protected static updateGeometry(iModelDb: IModelDb, props: TextAnnotation3dProps): void {\n if (props.elementGeometryBuilderParams || !props.textAnnotationData) {\n return;\n }\n\n props.elementGeometryBuilderParams = getElementGeometryBuilderParams(iModelDb, props.model, props.placement ?? Placement3d.fromJSON(), props.textAnnotationData, props.category, props.defaultTextStyle ? props.defaultTextStyle.id : undefined);\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/**\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);\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 */\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 definitionModelId - The ID of the [[DefinitionModel]].\n * @param name - The name to assign to the `AnnotationTextStyle`.\n * @param settings - Optional text style settings used to create the `AnnotationTextStyle`. Default settings will be used if not provided.\n * @param description - Optional description for the `AnnotationTextStyle`.\n */\n public static create(iModelDb: IModelDb, definitionModelId: Id64String, name: string, settings?: TextStyleSettingsProps, description?: string) {\n const props: AnnotationTextStyleProps = {\n classFullName: this.classFullName,\n model: definitionModelId,\n code: this.createCode(iModelDb, definitionModelId, name).toJSON(),\n description,\n settings: JSON.stringify(settings),\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(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);\n const errors = settings.getValidationErrors();\n if (errors.length > 0) {\n throw new Error(`Invalid AnnotationTextStyle settings: ${errors.join(\", \")}`);\n }\n }\n\n private static parseTextStyleSettings(json: string | undefined): TextStyleSettingsProps | undefined {\n if (!json) return undefined;\n try {\n return JSON.parse(json);\n } catch {\n return undefined;\n }\n }\n}\n\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,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,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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EAAE,CAAC;QAC9C,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CAAC,yCAAyC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAChF,CAAC;IACH,CAAC;IAED;;;;OAIG;IACO,MAAM,CAAmB,mBAAmB,GAA4B;QAChF,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE;KAC9C,CAAC;IAEF;;;;OAIG;IACI,MAAM,CAAU,WAAW,CAAC,KAA4B;QAC7D,MAAM,OAAO,GAAG,KAAK,CAAC,WAAW,CAAC,KAAK,CAA6B,CAAC;QACrE,MAAM,QAAQ,GAAG,IAAI,CAAC,sBAAsB,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACjE,IAAI,QAAQ,EAAE,CAAC;YACb,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;QAC9C,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAU,SAAS,CAAC,KAA+B,EAAE,MAAgB;QAChF,MAAM,IAAI,GAAG,KAAK,CAAC,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAC5C,IAAI,KAAK,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;YACjC,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;QACjC,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,mGAAmG;IAC3F,MAAM,CAAC,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}"]}
|