@itwin/core-backend 5.4.0-dev.3 → 5.4.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.
Files changed (39) hide show
  1. package/lib/cjs/annotations/ElementDrivesTextAnnotation.d.ts +14 -0
  2. package/lib/cjs/annotations/ElementDrivesTextAnnotation.d.ts.map +1 -1
  3. package/lib/cjs/annotations/ElementDrivesTextAnnotation.js +32 -19
  4. package/lib/cjs/annotations/ElementDrivesTextAnnotation.js.map +1 -1
  5. package/lib/cjs/annotations/LeaderGeometry.d.ts.map +1 -1
  6. package/lib/cjs/annotations/LeaderGeometry.js +7 -9
  7. package/lib/cjs/annotations/LeaderGeometry.js.map +1 -1
  8. package/lib/cjs/annotations/TextAnnotationElement.d.ts.map +1 -1
  9. package/lib/cjs/annotations/TextAnnotationElement.js +3 -4
  10. package/lib/cjs/annotations/TextAnnotationElement.js.map +1 -1
  11. package/lib/cjs/annotations/TextBlockLayout.d.ts.map +1 -1
  12. package/lib/cjs/annotations/TextBlockLayout.js +2 -1
  13. package/lib/cjs/annotations/TextBlockLayout.js.map +1 -1
  14. package/lib/cjs/internal/annotations/fields.d.ts +3 -2
  15. package/lib/cjs/internal/annotations/fields.d.ts.map +1 -1
  16. package/lib/cjs/internal/annotations/fields.js +12 -5
  17. package/lib/cjs/internal/annotations/fields.js.map +1 -1
  18. package/lib/esm/annotations/ElementDrivesTextAnnotation.d.ts +14 -0
  19. package/lib/esm/annotations/ElementDrivesTextAnnotation.d.ts.map +1 -1
  20. package/lib/esm/annotations/ElementDrivesTextAnnotation.js +33 -20
  21. package/lib/esm/annotations/ElementDrivesTextAnnotation.js.map +1 -1
  22. package/lib/esm/annotations/LeaderGeometry.d.ts.map +1 -1
  23. package/lib/esm/annotations/LeaderGeometry.js +7 -9
  24. package/lib/esm/annotations/LeaderGeometry.js.map +1 -1
  25. package/lib/esm/annotations/TextAnnotationElement.d.ts.map +1 -1
  26. package/lib/esm/annotations/TextAnnotationElement.js +3 -4
  27. package/lib/esm/annotations/TextAnnotationElement.js.map +1 -1
  28. package/lib/esm/annotations/TextBlockLayout.d.ts.map +1 -1
  29. package/lib/esm/annotations/TextBlockLayout.js +2 -1
  30. package/lib/esm/annotations/TextBlockLayout.js.map +1 -1
  31. package/lib/esm/internal/annotations/fields.d.ts +3 -2
  32. package/lib/esm/internal/annotations/fields.d.ts.map +1 -1
  33. package/lib/esm/internal/annotations/fields.js +11 -5
  34. package/lib/esm/internal/annotations/fields.js.map +1 -1
  35. package/lib/esm/test/annotations/LeaderGeometry.test.js +0 -1
  36. package/lib/esm/test/annotations/LeaderGeometry.test.js.map +1 -1
  37. package/lib/esm/test/annotations/TextAnnotation.test.js +49 -6
  38. package/lib/esm/test/annotations/TextAnnotation.test.js.map +1 -1
  39. package/package.json +12 -12
@@ -2,11 +2,12 @@ import { FieldRun, FieldValue, RelationshipProps, TextBlock } from "@itwin/core-
2
2
  import { IModelDb } from "../../IModelDb";
3
3
  import { Id64String } from "@itwin/core-bentley";
4
4
  export interface UpdateFieldsContext {
5
- readonly hostElementId: Id64String;
5
+ readonly hostElementId: Id64String | undefined;
6
6
  getProperty(field: FieldRun): FieldValue | undefined;
7
7
  }
8
- export declare function createUpdateContext(hostElementId: string, iModel: IModelDb, deleted: boolean): UpdateFieldsContext;
8
+ export declare function createUpdateContext(hostElementId: string | undefined, iModel: IModelDb, deleted: boolean): UpdateFieldsContext;
9
9
  export declare function updateField(field: FieldRun, context: UpdateFieldsContext): boolean;
10
10
  export declare function updateFields(textBlock: TextBlock, context: UpdateFieldsContext): number;
11
11
  export declare function updateElementFields(props: RelationshipProps, iModel: IModelDb, deleted: boolean): void;
12
+ export declare function updateAllFields(annotationElementId: Id64String, iModel: IModelDb): void;
12
13
  //# sourceMappingURL=fields.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../../../../src/internal/annotations/fields.ts"],"names":[],"mappings":"AAKA,OAAO,EAA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MAAM,GAAG,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,GAAG,mBAAmB,CAK9H;AAGD,wBAAgB,WAAW,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAsBlF;AAID,wBAAgB,YAAY,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,mBAAmB,GAAG,MAAM,CASvF;AAyBD,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,iBAAiB,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CAEtG;AAED,wBAAgB,eAAe,CAAC,mBAAmB,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,GAAG,IAAI,CAEvF"}
@@ -8,6 +8,7 @@ exports.createUpdateContext = createUpdateContext;
8
8
  exports.updateField = updateField;
9
9
  exports.updateFields = updateFields;
10
10
  exports.updateElementFields = updateElementFields;
11
+ exports.updateAllFields = updateAllFields;
11
12
  const core_common_1 = require("@itwin/core-common");
12
13
  const core_bentley_1 = require("@itwin/core-bentley");
13
14
  const BackendLoggerCategory_1 = require("../../BackendLoggerCategory");
@@ -187,7 +188,7 @@ function createUpdateContext(hostElementId, iModel, deleted) {
187
188
  }
188
189
  // Recompute the display value of a single field, return false if it couldn't be evaluated.
189
190
  function updateField(field, context) {
190
- if (context.hostElementId !== field.propertyHost.elementId) {
191
+ if (context.hostElementId && context.hostElementId !== field.propertyHost.elementId) {
191
192
  return false;
192
193
  }
193
194
  let newContent;
@@ -218,12 +219,11 @@ function updateFields(textBlock, context) {
218
219
  }
219
220
  return numUpdated;
220
221
  }
221
- // Invoked by ElementDrivesTextAnnotation to update fields in target element when source element changes or is deleted.
222
- function updateElementFields(props, iModel, deleted) {
222
+ function doUpdateFields(annotationId, sourceId, iModel, deleted) {
223
223
  try {
224
- const target = iModel.elements.getElement(props.targetId);
224
+ const target = iModel.elements.getElement(annotationId);
225
225
  if ((0, ElementDrivesTextAnnotation_1.isITextAnnotation)(target)) {
226
- const context = createUpdateContext(props.sourceId, iModel, deleted);
226
+ const context = createUpdateContext(sourceId, iModel, deleted);
227
227
  const updatedBlocks = [];
228
228
  for (const block of target.getTextBlocks()) {
229
229
  if (updateFields(block.textBlock, context)) {
@@ -240,4 +240,11 @@ function updateElementFields(props, iModel, deleted) {
240
240
  core_bentley_1.Logger.logException(BackendLoggerCategory_1.BackendLoggerCategory.IModelDb, err);
241
241
  }
242
242
  }
243
+ // Invoked by ElementDrivesTextAnnotation to update fields in target element when source element changes or is deleted.
244
+ function updateElementFields(props, iModel, deleted) {
245
+ doUpdateFields(props.targetId, props.sourceId, iModel, deleted);
246
+ }
247
+ function updateAllFields(annotationElementId, iModel) {
248
+ doUpdateFields(annotationElementId, undefined, iModel, false);
249
+ }
243
250
  //# sourceMappingURL=fields.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"fields.js","sourceRoot":"","sources":["../../../../src/internal/annotations/fields.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;AA4N/F,kDAKC;AAGD,kCAsBC;AAID,oCASC;AAGD,kDAoBC;AA5RD,oDAA8L;AAE9L,sDAA0F;AAC1F,uEAAoE;AACpE,+FAAkF;AAClF,gEAA6H;AAiC7H,0EAA0E;AAC1E,SAAS,qBAAqB,CAAC,KAAe,EAAE,MAAgB;IAC9D,MAAM,IAAI,GAAG,KAAK,CAAC,YAAY,CAAC;IAChC,MAAM,UAAU,GAAG,MAAM,CAAC,aAAa,CAAC,iBAAiB,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;IAC3F,IAAI,CAAC,+BAAW,CAAC,aAAa,CAAC,UAAU,CAAC,EAAE,CAAC;QAC3C,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,OAAO,GAAa,UAAU,CAAC;IACnC,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,GAAG,KAAK,CAAC,YAAY,CAAC;IACvD,IAAI,MAAM,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AI,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,SAAgB,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,IAAA,+CAAiB,EAAC,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;gBACvC,MAAM,CAAC,MAAM,EAAE,CAAC;YAClB,CAAC;QACH,CAAC;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,qBAAM,CAAC,YAAY,CAAC,6CAAqB,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"]}
1
+ {"version":3,"file":"fields.js","sourceRoot":"","sources":["../../../../src/internal/annotations/fields.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;AA4N/F,kDAKC;AAGD,kCAsBC;AAID,oCASC;AAyBD,kDAEC;AAED,0CAEC;AApSD,oDAA8L;AAE9L,sDAA0F;AAC1F,uEAAoE;AACpE,+FAAkF;AAClF,gEAA6H;AAiC7H,0EAA0E;AAC1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gB,CAAC,aAAa,CAAC,CAAC;gBACvC,MAAM,CAAC,MAAM,EAAE,CAAC;YAClB,CAAC;QACH,CAAC;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,qBAAM,CAAC,YAAY,CAAC,6CAAqB,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;IAC3D,CAAC;AACH,CAAC;AAED,uHAAuH;AACvH,SAAgB,mBAAmB,CAAC,KAAwB,EAAE,MAAgB,EAAE,OAAgB;IAC9F,cAAc,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AAClE,CAAC;AAED,SAAgB,eAAe,CAAC,mBAA+B,EAAE,MAAgB;IAC/E,cAAc,CAAC,mBAAmB,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;AAChE,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 | undefined;\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 | undefined, 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 && 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\nfunction doUpdateFields(annotationId: Id64String, sourceId: Id64String | undefined, iModel: IModelDb, deleted: boolean): void {\n try {\n const target = iModel.elements.getElement(annotationId);\n if (isITextAnnotation(target)) {\n const context = createUpdateContext(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// 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 doUpdateFields(props.targetId, props.sourceId, iModel, deleted);\n}\n\nexport function updateAllFields(annotationElementId: Id64String, iModel: IModelDb): void {\n doUpdateFields(annotationElementId, undefined, iModel, false);\n}\n\n"]}
@@ -36,6 +36,15 @@ export interface ITextAnnotation {
36
36
  * @beta
37
37
  */
38
38
  export declare function isITextAnnotation(element: Element): element is ITextAnnotation & Element;
39
+ /** Arguments supplied to [[ElementDrivesTextAnnotation.evaluateFields]].
40
+ * @beta
41
+ */
42
+ export interface EvaluateFieldsArgs {
43
+ /** The text block whose fields are to be evaluated. */
44
+ block: TextBlock;
45
+ /** The iModel containing the elements supplying the display strings for the fields in [[block]]. */
46
+ iModel: IModelDb;
47
+ }
39
48
  /** A relationship in which the source element hosts one or more properties that are displayed by a target [[ITextAnnotation]] element.
40
49
  * This relationship is used to automatically update the [FieldRun]($common)s contained in the target element when the source element is modified.
41
50
  * An [[ITextAnnotation]] element should invoke [[updateFieldDependencies]] from its [[Element.onInserted]] and [[Element.onUpdated]] functions to
@@ -60,6 +69,11 @@ export declare class ElementDrivesTextAnnotation extends ElementDrivesElement {
60
69
  * It also deletes any stale relationships left over from fields that were deleted or whose source elements changed.
61
70
  */
62
71
  static updateFieldDependencies(annotationElementId: Id64String, iModel: IModelDb): void;
72
+ /** Recompute the display strings of all [FieldRun]($common)s in a [TextBlock]($common).
73
+ * @returns the number of fields whose display strings were modified.
74
+ * @throws Error if evaluation of any field fails.
75
+ */
76
+ static evaluateFields(args: EvaluateFieldsArgs): number;
63
77
  /** When copying an [[ITextAnnotation]] from one iModel into another, remaps the element Ids in any [FieldPropertyHost]($common) within the cloned element
64
78
  * so that they refer to elements in the `context`'s target iModel, and sets any Ids that cannot be remapped to [Id64.invalid]($bentley).
65
79
  * Implementations of `ITextAnnotation` should invoke this function from their implementations of [[Element.onCloned]].
@@ -1 +1 @@
1
- {"version":3,"file":"ElementDrivesTextAnnotation.d.ts","sourceRoot":"","sources":["../../../src/annotations/ElementDrivesTextAnnotation.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,SAAS,EAA8B,MAAM,oBAAoB,CAAC;AAC9G,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC,OAAO,EAAkB,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjE,OAAO,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AAEzE;;;;;GAKG;AACH,MAAM,WAAW,cAAc;IAC7B,sBAAsB;IACtB,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAC9B,gIAAgI;IAChI,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAC;CACtB;AAKD;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B,uEAAuE;IACvE,gBAAgB,CAAC,EAAE,oCAAoC,CAAC;IACxD,sFAAsF;IACtF,aAAa,IAAI,QAAQ,CA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AI9D;;;OAGG;WACW,WAAW,CAAC,KAAK,EAAE,eAAe,EAAE,OAAO,EAAE,yBAAyB,GAAG,IAAI;CAwB5F;AAED;;GAEG;AACH,qBAAa,oCAAqC,SAAQ,cAAc;IACtE,OAAc,aAAa,SAAkD;gBAC1D,qBAAqB,EAAE,UAAU,EAAE,YAAY,GAAE,MAA2D;CAGhI"}
@@ -7,7 +7,7 @@
7
7
  */
8
8
  import { RelatedElement, traverseTextBlockComponent } from "@itwin/core-common";
9
9
  import { ElementDrivesElement } from "../Relationship";
10
- import { updateElementFields } from "../internal/annotations/fields";
10
+ import { createUpdateContext, updateAllFields, updateElementFields, updateFields } from "../internal/annotations/fields";
11
11
  import { DbResult, Id64 } from "@itwin/core-bentley";
12
12
  import { ECVersion } from "@itwin/ecschema-metadata";
13
13
  // ElementDrivesTextAnnotation was introduced in this version of BisCore - iModels with earlier versions cannot support field dependencies.
@@ -41,17 +41,13 @@ export class ElementDrivesTextAnnotation extends ElementDrivesElement {
41
41
  * update when the source element changes.
42
42
  */
43
43
  static isSupportedForIModel(iModel) {
44
- const bisCoreVersion = iModel.querySchemaVersionNumbers("BisCore");
45
- return undefined !== bisCoreVersion && bisCoreVersion.compare(minBisCoreVersion) >= 0;
44
+ return iModel.meetsMinimumSchemaVersion("BisCore", minBisCoreVersion);
46
45
  }
47
46
  /** Examines all of the [FieldRun]($common)s within the specified [[ITextAnnotation]] and ensures that the appropriate
48
47
  * `ElementDrivesTextAnnotation` relationships exist between the fields' source elements and this target element.
49
48
  * It also deletes any stale relationships left over from fields that were deleted or whose source elements changed.
50
49
  */
51
50
  static updateFieldDependencies(annotationElementId, iModel) {
52
- if (!ElementDrivesTextAnnotation.isSupportedForIModel(iModel)) {
53
- return;
54
- }
55
51
  const annotationElement = iModel.elements.tryGetElement(annotationElementId);
56
52
  if (!annotationElement || !isITextAnnotation(annotationElement)) {
57
53
  return;
@@ -69,27 +65,37 @@ export class ElementDrivesTextAnnotation extends ElementDrivesElement {
69
65
  }
70
66
  const sourceToRelationship = new Map();
71
67
  const blocks = annotationElement.getTextBlocks();
68
+ let haveFields = false;
72
69
  for (const block of blocks) {
73
70
  for (const { child } of traverseTextBlockComponent(block.textBlock)) {
74
- if (child.type === "field" && isValidSourceId(child.propertyHost.elementId)) {
75
- sourceToRelationship.set(child.propertyHost.elementId, null);
71
+ if (child.type === "field") {
72
+ haveFields = true;
73
+ if (isValidSourceId(child.propertyHost.elementId)) {
74
+ sourceToRelationship.set(child.propertyHost.elementId, null);
75
+ }
76
76
  }
77
77
  }
78
78
  }
79
+ if (haveFields) {
80
+ iModel.requireMinimumSchemaVersion("BisCore", minBisCoreVersion, "Text fields");
81
+ updateAllFields(annotationElementId, iModel);
82
+ }
79
83
  const staleRelationships = new Set();
80
- // eslint-disable-next-line @typescript-eslint/no-deprecated
81
- annotationElement.iModel.withPreparedStatement(`SELECT ECInstanceId, SourceECInstanceId FROM BisCore.ElementDrivesTextAnnotation WHERE TargetECInstanceId=${annotationElement.id}`, (stmt) => {
82
- while (DbResult.BE_SQLITE_ROW === stmt.step()) {
83
- const relationshipId = stmt.getValue(0).getId();
84
- const sourceId = stmt.getValue(1).getId();
85
- if (sourceToRelationship.has(sourceId)) {
86
- sourceToRelationship.set(sourceId, relationshipId);
87
- }
88
- else {
89
- staleRelationships.add(relationshipId);
84
+ if (this.isSupportedForIModel(iModel)) {
85
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
86
+ annotationElement.iModel.withPreparedStatement(`SELECT ECInstanceId, SourceECInstanceId FROM BisCore.ElementDrivesTextAnnotation WHERE TargetECInstanceId=${annotationElement.id}`, (stmt) => {
87
+ while (DbResult.BE_SQLITE_ROW === stmt.step()) {
88
+ const relationshipId = stmt.getValue(0).getId();
89
+ const sourceId = stmt.getValue(1).getId();
90
+ if (sourceToRelationship.has(sourceId)) {
91
+ sourceToRelationship.set(sourceId, relationshipId);
92
+ }
93
+ else {
94
+ staleRelationships.add(relationshipId);
95
+ }
90
96
  }
91
- }
92
- });
97
+ });
98
+ }
93
99
  for (const [sourceId, relationshipId] of sourceToRelationship) {
94
100
  if (relationshipId === null) {
95
101
  ElementDrivesTextAnnotation.create(annotationElement.iModel, sourceId, annotationElement.id).insert();
@@ -100,6 +106,13 @@ export class ElementDrivesTextAnnotation extends ElementDrivesElement {
100
106
  annotationElement.iModel.relationships.deleteInstances(staleRelationshipProps);
101
107
  }
102
108
  }
109
+ /** Recompute the display strings of all [FieldRun]($common)s in a [TextBlock]($common).
110
+ * @returns the number of fields whose display strings were modified.
111
+ * @throws Error if evaluation of any field fails.
112
+ */
113
+ static evaluateFields(args) {
114
+ return updateFields(args.block, createUpdateContext(undefined, args.iModel, false));
115
+ }
103
116
  /** When copying an [[ITextAnnotation]] from one iModel into another, remaps the element Ids in any [FieldPropertyHost]($common) within the cloned element
104
117
  * so that they refer to elements in the `context`'s target iModel, and sets any Ids that cannot be remapped to [Id64.invalid]($bentley).
105
118
  * Implementations of `ITextAnnotation` should invoke this function from their implementations of [[Element.onCloned]].
@@ -1 +1 @@
1
- {"version":3,"file":"ElementDrivesTextAnnotation.js","sourceRoot":"","sources":["../../../src/annotations/ElementDrivesTextAnnotation.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,cAAc,EAAgC,0BAA0B,EAAE,MAAM,oBAAoB,CAAC;AAC9G,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAGvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAc,MAAM,qBAAqB,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAgBrD,2IAA2I;AAC3I,MAAM,iBAAiB,GAAG,IAAI,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;AAgBlD;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAgB;IAChD,OAAO,CAA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E,CAAC;gBACpE,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;oBAC3B,KAAK,CAAC,YAAY,CAAC,SAAS,GAAG,OAAO,CAAC,mBAAmB,CAAC,KAAK,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;oBACzF,UAAU,GAAG,IAAI,CAAC;gBACpB,CAAC;YACH,CAAC;YAED,IAAI,UAAU,EAAE,CAAC;gBACf,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAC5B,CAAC;QACH,CAAC;QAED,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC7B,KAAK,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAC;QACxC,CAAC;IACH,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,oCAAqC,SAAQ,cAAc;IAC/D,MAAM,CAAC,aAAa,GAAG,8CAA8C,CAAC;IAC7E,YAAmB,qBAAiC,EAAE,eAAuB,oCAAoC,CAAC,aAAa;QAC7H,KAAK,CAAC,EAAE,EAAE,EAAE,qBAAqB,EAAE,YAAY,EAAE,CAAC,CAAC;IACrD,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 { RelatedElement, RelationshipProps, TextBlock, traverseTextBlockComponent } from \"@itwin/core-common\";\nimport { ElementDrivesElement } from \"../Relationship\";\nimport { IModelDb } from \"../IModelDb\";\nimport { Element } from \"../Element\";\nimport { updateElementFields } from \"../internal/annotations/fields\";\nimport { DbResult, Id64, Id64String } from \"@itwin/core-bentley\";\nimport { ECVersion } from \"@itwin/ecschema-metadata\";\nimport { IModelElementCloneContext } from \"../IModelElementCloneContext\";\n\n/** Describes one of potentially many [TextBlock]($common)s hosted by an [[ITextAnnotation]].\n * For example, a [[TextAnnotation2d]] hosts only a single text block, but an element representing a table may\n * host one text block for each cell in the table, in which case it might use the combination of row and column\n * as the [[id]] for each text block.\n * @beta\n */\nexport interface TextBlockAndId {\n /** The text block. */\n readonly textBlock: TextBlock;\n /** An opaque identifier that allows the [[ITextAnnotation]] to discern which of its hosted text blocks is being referred to. */\n readonly id: unknown;\n}\n\n// ElementDrivesTextAnnotation was introduced in this version of BisCore - iModels with earlier versions cannot support field dependencies.\nconst minBisCoreVersion = new ECVersion(1, 0, 22);\n\n/** Interface implemented by [[GeometricElement]] subclasses whose schemas declare them to implement the mix-in `BisCore:ITextAnnotation`.\n * Such elements may host any number of [TextBlock]($common)s. `ITextAnnotation` provides a uniform way to interact with text regardless of\n * the type of element to which it belongs.\n * @beta\n */\nexport interface ITextAnnotation {\n /** The default [[AnnotationTextStyle]] used by the text annotation. */\n defaultTextStyle?: TextAnnotationUsesTextStyleByDefault;\n /** Obtain a collection of all of the [TextBlock]($common)s hosted by this element. */\n getTextBlocks(): Iterable<TextBlockAndId>;\n /** Update the element in-memory to replace the contents of the specified [TextBlock]($common)s. */\n updateTextBlocks(textBlocks: TextBlockAndId[]): void;\n}\n\n/** Returns `true` if the specified `element` implements [[ITextAnnotation]].\n * @beta\n */\nexport function isITextAnnotation(element: Element): element is ITextAnnotation & Element {\n return [\"getTextBlocks\", \"updateTextBlocks\"].every((x) => x in element && typeof (element as any)[x] === \"function\");\n}\n\n/** A relationship in which the source element hosts one or more properties that are displayed by a target [[ITextAnnotation]] element.\n * This relationship is used to automatically update the [FieldRun]($common)s contained in the target element when the source element is modified.\n * An [[ITextAnnotation]] element should invoke [[updateFieldDependencies]] from its [[Element.onInserted]] and [[Element.onUpdated]] functions to\n * establish or update the relationships required for the [FieldRun]($common)s it contains.\n * @note This relationship was introduced in version 01.00.22 of the BisCore schema. [FieldRun]($common)s created in iModels that have not been upgraded to\n * that version or newer will not automatically update. Use [[isSupportedForIModel]] to check.\n * @beta\n */\nexport class ElementDrivesTextAnnotation extends ElementDrivesElement {\n public static override get className(): string { return \"ElementDrivesTextAnnotation\"; }\n\n /** @internal */\n public static override onRootChanged(props: RelationshipProps, iModel: IModelDb): void {\n updateElementFields(props, iModel, false);\n }\n\n /** @internal */\n public static override onDeletedDependency(props: RelationshipProps, iModel: IModelDb): void {\n updateElementFields(props, iModel, true);\n }\n\n /** Returns true if `iModel` contains a version of the BisCore schema new enough to support this relationship.\n * If not, the schema should be updated before inserting any [FieldRun]($common)s, or those runs will not\n * update when the source element changes.\n */\n public static isSupportedForIModel(iModel: IModelDb): boolean {\n const bisCoreVersion = iModel.querySchemaVersionNumbers(\"BisCore\");\n return undefined !== bisCoreVersion && bisCoreVersion.compare(minBisCoreVersion) >= 0;\n }\n\n /** Examines all of the [FieldRun]($common)s within the specified [[ITextAnnotation]] and ensures that the appropriate\n * `ElementDrivesTextAnnotation` relationships exist between the fields' source elements and this target element.\n * It also deletes any stale relationships left over from fields that were deleted or whose source elements changed.\n */\n public static updateFieldDependencies(annotationElementId: Id64String, iModel: IModelDb): void {\n if (!ElementDrivesTextAnnotation.isSupportedForIModel(iModel)) {\n return;\n }\n\n const annotationElement = iModel.elements.tryGetElement<Element>(annotationElementId);\n if (!annotationElement || !isITextAnnotation(annotationElement)) {\n return;\n }\n\n // The native layer will allow us to insert relationships to invalid or non-existent source elements...errors will arise later. Prevent it.\n function isValidSourceId(id: Id64String): boolean {\n if (!Id64.isValidId64(id)) {\n return false;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n return iModel.withPreparedStatement(\"SELECT CodeValue FROM BisCore.Element WHERE ECInstanceId=?\", (stmt) => {\n stmt.bindId(1, id);\n return DbResult.BE_SQLITE_ROW === stmt.step();\n });\n }\n\n const sourceToRelationship = new Map<Id64String, Id64String | null>();\n const blocks = annotationElement.getTextBlocks();\n\n for (const block of blocks) {\n for (const { child } of traverseTextBlockComponent(block.textBlock)) {\n if (child.type === \"field\" && isValidSourceId(child.propertyHost.elementId)) {\n sourceToRelationship.set(child.propertyHost.elementId, null);\n }\n }\n }\n\n const staleRelationships = new Set<Id64String>();\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n annotationElement.iModel.withPreparedStatement(`SELECT ECInstanceId, SourceECInstanceId FROM BisCore.ElementDrivesTextAnnotation WHERE TargetECInstanceId=${annotationElement.id}`, (stmt) => {\n while (DbResult.BE_SQLITE_ROW === stmt.step()) {\n const relationshipId = stmt.getValue(0).getId();\n const sourceId = stmt.getValue(1).getId();\n if (sourceToRelationship.has(sourceId)) {\n sourceToRelationship.set(sourceId, relationshipId);\n } else {\n staleRelationships.add(relationshipId);\n }\n }\n });\n\n for (const [sourceId, relationshipId] of sourceToRelationship) {\n if (relationshipId === null) {\n ElementDrivesTextAnnotation.create(annotationElement.iModel, sourceId, annotationElement.id).insert();\n }\n }\n\n if (staleRelationships.size > 0) {\n const staleRelationshipProps = Array.from(staleRelationships).map(relationshipId =>\n annotationElement.iModel.relationships.getInstanceProps(\"BisCore.ElementDrivesTextAnnotation\", relationshipId)\n );\n annotationElement.iModel.relationships.deleteInstances(staleRelationshipProps);\n }\n }\n\n /** When copying an [[ITextAnnotation]] from one iModel into another, remaps the element Ids in any [FieldPropertyHost]($common) within the cloned element\n * so that they refer to elements in the `context`'s target iModel, and sets any Ids that cannot be remapped to [Id64.invalid]($bentley).\n * Implementations of `ITextAnnotation` should invoke this function from their implementations of [[Element.onCloned]].\n */\n public static remapFields(clone: ITextAnnotation, context: IModelElementCloneContext): void {\n if (!context.isBetweenIModels) {\n return;\n }\n\n const updatedBlocks = [];\n for (const block of clone.getTextBlocks()) {\n let anyUpdated = false;\n for (const { child } of traverseTextBlockComponent(block.textBlock)) {\n if (child.type === \"field\") {\n child.propertyHost.elementId = context.findTargetElementId(child.propertyHost.elementId);\n anyUpdated = true;\n }\n }\n\n if (anyUpdated) {\n updatedBlocks.push(block);\n }\n }\n\n if (updatedBlocks.length > 0) {\n clone.updateTextBlocks(updatedBlocks);\n }\n }\n}\n\n/** Relationship indicating that the [[AnnotationTextStyle]] is being used as the default style for the [[ITextAnnotation]].\n * @beta\n */\nexport class TextAnnotationUsesTextStyleByDefault extends RelatedElement {\n public static classFullName = \"BisCore:TextAnnotationUsesTextStyleByDefault\";\n public constructor(annotationTextStyleId: Id64String, relClassName: string = TextAnnotationUsesTextStyleByDefault.classFullName) {\n super({ id: annotationTextStyleId, relClassName });\n }\n}\n"]}
1
+ {"version":3,"file":"ElementDrivesTextAnnotation.js","sourceRoot":"","sources":["../../../src/annotations/ElementDrivesTextAnnotation.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,cAAc,EAAgC,0BAA0B,EAAE,MAAM,oBAAoB,CAAC;AAC9G,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAGvD,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AACzH,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAc,MAAM,qBAAqB,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAgBrD,2IAA2I;AAC3I,MAAM,iBAAiB,GAAG,IAAI,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;AAgBlD;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAgB;IAChD,OAAO,CAAC,eAAe,EAAE,kBAAkB,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,OAAO,IAAI,OAAQ,OAAe,CAAC,CAAC,CAAC,KAAK,UAAU,CAAC,CAAC;AACvH,CAAC;AAYD;;;;;;;GAOG;AACH,MAAM,OAAO,2BAA4B,SAAQ,oBAAoB;IAC5D,MAAM,KAAc,SAAS,KAAa,OAAO,6BAA6B,CAAC,CAAC,CAAC;IAExF,gBAAgB;IACT,MAAM,CAAU,aAAa,CAAC,KAAwB,EAAE,MAAgB;QAC7E,mBAAmB,CAAC,KA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I,KAAK,OAAO,EAAE,CAAC;oBAC3B,KAAK,CAAC,YAAY,CAAC,SAAS,GAAG,OAAO,CAAC,mBAAmB,CAAC,KAAK,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;oBACzF,UAAU,GAAG,IAAI,CAAC;gBACpB,CAAC;YACH,CAAC;YAED,IAAI,UAAU,EAAE,CAAC;gBACf,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAC5B,CAAC;QACH,CAAC;QAED,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC7B,KAAK,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAC;QACxC,CAAC;IACH,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,oCAAqC,SAAQ,cAAc;IAC/D,MAAM,CAAC,aAAa,GAAG,8CAA8C,CAAC;IAC7E,YAAmB,qBAAiC,EAAE,eAAuB,oCAAoC,CAAC,aAAa;QAC7H,KAAK,CAAC,EAAE,EAAE,EAAE,qBAAqB,EAAE,YAAY,EAAE,CAAC,CAAC;IACrD,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 { RelatedElement, RelationshipProps, TextBlock, traverseTextBlockComponent } from \"@itwin/core-common\";\nimport { ElementDrivesElement } from \"../Relationship\";\nimport { IModelDb } from \"../IModelDb\";\nimport { Element } from \"../Element\";\nimport { createUpdateContext, updateAllFields, updateElementFields, updateFields } from \"../internal/annotations/fields\";\nimport { DbResult, Id64, Id64String } from \"@itwin/core-bentley\";\nimport { ECVersion } from \"@itwin/ecschema-metadata\";\nimport { IModelElementCloneContext } from \"../IModelElementCloneContext\";\n\n/** Describes one of potentially many [TextBlock]($common)s hosted by an [[ITextAnnotation]].\n * For example, a [[TextAnnotation2d]] hosts only a single text block, but an element representing a table may\n * host one text block for each cell in the table, in which case it might use the combination of row and column\n * as the [[id]] for each text block.\n * @beta\n */\nexport interface TextBlockAndId {\n /** The text block. */\n readonly textBlock: TextBlock;\n /** An opaque identifier that allows the [[ITextAnnotation]] to discern which of its hosted text blocks is being referred to. */\n readonly id: unknown;\n}\n\n// ElementDrivesTextAnnotation was introduced in this version of BisCore - iModels with earlier versions cannot support field dependencies.\nconst minBisCoreVersion = new ECVersion(1, 0, 22);\n\n/** Interface implemented by [[GeometricElement]] subclasses whose schemas declare them to implement the mix-in `BisCore:ITextAnnotation`.\n * Such elements may host any number of [TextBlock]($common)s. `ITextAnnotation` provides a uniform way to interact with text regardless of\n * the type of element to which it belongs.\n * @beta\n */\nexport interface ITextAnnotation {\n /** The default [[AnnotationTextStyle]] used by the text annotation. */\n defaultTextStyle?: TextAnnotationUsesTextStyleByDefault;\n /** Obtain a collection of all of the [TextBlock]($common)s hosted by this element. */\n getTextBlocks(): Iterable<TextBlockAndId>;\n /** Update the element in-memory to replace the contents of the specified [TextBlock]($common)s. */\n updateTextBlocks(textBlocks: TextBlockAndId[]): void;\n}\n\n/** Returns `true` if the specified `element` implements [[ITextAnnotation]].\n * @beta\n */\nexport function isITextAnnotation(element: Element): element is ITextAnnotation & Element {\n return [\"getTextBlocks\", \"updateTextBlocks\"].every((x) => x in element && typeof (element as any)[x] === \"function\");\n}\n\n/** Arguments supplied to [[ElementDrivesTextAnnotation.evaluateFields]].\n * @beta\n */\nexport interface EvaluateFieldsArgs {\n /** The text block whose fields are to be evaluated. */\n block: TextBlock;\n /** The iModel containing the elements supplying the display strings for the fields in [[block]]. */\n iModel: IModelDb;\n}\n\n/** A relationship in which the source element hosts one or more properties that are displayed by a target [[ITextAnnotation]] element.\n * This relationship is used to automatically update the [FieldRun]($common)s contained in the target element when the source element is modified.\n * An [[ITextAnnotation]] element should invoke [[updateFieldDependencies]] from its [[Element.onInserted]] and [[Element.onUpdated]] functions to\n * establish or update the relationships required for the [FieldRun]($common)s it contains.\n * @note This relationship was introduced in version 01.00.22 of the BisCore schema. [FieldRun]($common)s created in iModels that have not been upgraded to\n * that version or newer will not automatically update. Use [[isSupportedForIModel]] to check.\n * @beta\n */\nexport class ElementDrivesTextAnnotation extends ElementDrivesElement {\n public static override get className(): string { return \"ElementDrivesTextAnnotation\"; }\n\n /** @internal */\n public static override onRootChanged(props: RelationshipProps, iModel: IModelDb): void {\n updateElementFields(props, iModel, false);\n }\n\n /** @internal */\n public static override onDeletedDependency(props: RelationshipProps, iModel: IModelDb): void {\n updateElementFields(props, iModel, true);\n }\n\n /** Returns true if `iModel` contains a version of the BisCore schema new enough to support this relationship.\n * If not, the schema should be updated before inserting any [FieldRun]($common)s, or those runs will not\n * update when the source element changes.\n */\n public static isSupportedForIModel(iModel: IModelDb): boolean {\n return iModel.meetsMinimumSchemaVersion(\"BisCore\", minBisCoreVersion);\n }\n\n /** Examines all of the [FieldRun]($common)s within the specified [[ITextAnnotation]] and ensures that the appropriate\n * `ElementDrivesTextAnnotation` relationships exist between the fields' source elements and this target element.\n * It also deletes any stale relationships left over from fields that were deleted or whose source elements changed.\n */\n public static updateFieldDependencies(annotationElementId: Id64String, iModel: IModelDb): void {\n const annotationElement = iModel.elements.tryGetElement<Element>(annotationElementId);\n if (!annotationElement || !isITextAnnotation(annotationElement)) {\n return;\n }\n\n // The native layer will allow us to insert relationships to invalid or non-existent source elements...errors will arise later. Prevent it.\n function isValidSourceId(id: Id64String): boolean {\n if (!Id64.isValidId64(id)) {\n return false;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n return iModel.withPreparedStatement(\"SELECT CodeValue FROM BisCore.Element WHERE ECInstanceId=?\", (stmt) => {\n stmt.bindId(1, id);\n return DbResult.BE_SQLITE_ROW === stmt.step();\n });\n }\n\n const sourceToRelationship = new Map<Id64String, Id64String | null>();\n const blocks = annotationElement.getTextBlocks();\n\n let haveFields = false;\n for (const block of blocks) {\n for (const { child } of traverseTextBlockComponent(block.textBlock)) {\n if (child.type === \"field\") {\n haveFields = true;\n if (isValidSourceId(child.propertyHost.elementId)) {\n sourceToRelationship.set(child.propertyHost.elementId, null);\n }\n }\n }\n }\n\n if (haveFields) {\n iModel.requireMinimumSchemaVersion(\"BisCore\", minBisCoreVersion, \"Text fields\");\n updateAllFields(annotationElementId, iModel)\n }\n\n const staleRelationships = new Set<Id64String>();\n if (this.isSupportedForIModel(iModel)) {\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n annotationElement.iModel.withPreparedStatement(`SELECT ECInstanceId, SourceECInstanceId FROM BisCore.ElementDrivesTextAnnotation WHERE TargetECInstanceId=${annotationElement.id}`, (stmt) => {\n while (DbResult.BE_SQLITE_ROW === stmt.step()) {\n const relationshipId = stmt.getValue(0).getId();\n const sourceId = stmt.getValue(1).getId();\n if (sourceToRelationship.has(sourceId)) {\n sourceToRelationship.set(sourceId, relationshipId);\n } else {\n staleRelationships.add(relationshipId);\n }\n }\n });\n }\n\n for (const [sourceId, relationshipId] of sourceToRelationship) {\n if (relationshipId === null) {\n ElementDrivesTextAnnotation.create(annotationElement.iModel, sourceId, annotationElement.id).insert();\n }\n }\n\n if (staleRelationships.size > 0) {\n const staleRelationshipProps = Array.from(staleRelationships).map(relationshipId =>\n annotationElement.iModel.relationships.getInstanceProps(\"BisCore.ElementDrivesTextAnnotation\", relationshipId)\n );\n annotationElement.iModel.relationships.deleteInstances(staleRelationshipProps);\n }\n }\n\n /** Recompute the display strings of all [FieldRun]($common)s in a [TextBlock]($common).\n * @returns the number of fields whose display strings were modified.\n * @throws Error if evaluation of any field fails.\n */\n public static evaluateFields(args: EvaluateFieldsArgs): number {\n return updateFields(args.block, createUpdateContext(undefined, args.iModel, false))\n }\n\n /** When copying an [[ITextAnnotation]] from one iModel into another, remaps the element Ids in any [FieldPropertyHost]($common) within the cloned element\n * so that they refer to elements in the `context`'s target iModel, and sets any Ids that cannot be remapped to [Id64.invalid]($bentley).\n * Implementations of `ITextAnnotation` should invoke this function from their implementations of [[Element.onCloned]].\n */\n public static remapFields(clone: ITextAnnotation, context: IModelElementCloneContext): void {\n if (!context.isBetweenIModels) {\n return;\n }\n\n const updatedBlocks = [];\n for (const block of clone.getTextBlocks()) {\n let anyUpdated = false;\n for (const { child } of traverseTextBlockComponent(block.textBlock)) {\n if (child.type === \"field\") {\n child.propertyHost.elementId = context.findTargetElementId(child.propertyHost.elementId);\n anyUpdated = true;\n }\n }\n\n if (anyUpdated) {\n updatedBlocks.push(block);\n }\n }\n\n if (updatedBlocks.length > 0) {\n clone.updateTextBlocks(updatedBlocks);\n }\n }\n}\n\n/** Relationship indicating that the [[AnnotationTextStyle]] is being used as the default style for the [[ITextAnnotation]].\n * @beta\n */\nexport class TextAnnotationUsesTextStyleByDefault extends RelatedElement {\n public static classFullName = \"BisCore:TextAnnotationUsesTextStyleByDefault\";\n public constructor(annotationTextStyleId: Id64String, relClassName: string = TextAnnotationUsesTextStyleByDefault.classFullName) {\n super({ id: annotationTextStyleId, relClassName });\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"LeaderGeometry.d.ts","sourceRoot":"","sources":["../../../src/annotations/LeaderGeometry.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAY,eAAe,EAAe,cAAc,EAAE,oBAAoB,EAAuC,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC1K,OAAO,EAAyE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEvJ,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAEvE;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,eAAe,CAAC,OAAO,EAAE,OAAO,EAAE,oBAAoB,EAAE,EAAE,MAAM,EAAE,eAAe,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,cAAc,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAA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O,CAsEnP;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,eAAe,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,cAAc,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAwEnM;AAGD;;;;;;;;;;GAUG;AACH,wBAAgB,qBAAqB,CAAC,eAAe,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,GAAG,IAAI,EAAE,WAAW,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS,CA4BlI;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,4BAA4B,CAC1C,MAAM,EAAE,oBAAoB,EAC5B,UAAU,EAAE,IAAI,GAAG,IAAI,EACvB,UAAU,EAAE,eAAe,EAC3B,SAAS,EAAE,SAAS,GACnB,OAAO,GAAG,SAAS,CAyCrB"}
@@ -101,10 +101,10 @@ export function createTerminatorGeometry(builder, point, dir, params, textStyleS
101
101
  return false; // If dir is parallel to Z, we can't create a terminator
102
102
  const terminatorHeight = textStyleSettings.leader.terminatorHeightFactor * textHeight;
103
103
  const terminatorWidth = textStyleSettings.leader.terminatorWidthFactor * textHeight;
104
+ const terminatorHalfHeight = terminatorHeight / 2;
104
105
  const basePoint = point.plusScaled(dir, terminatorWidth);
105
- const point1 = basePoint.plusScaled(termY, terminatorHeight / 2);
106
- const point2 = basePoint.plusScaled(termY.negate(), terminatorHeight / 2);
107
- const radius = terminatorHeight / 2;
106
+ const point1 = basePoint.plusScaled(termY, terminatorHalfHeight);
107
+ const point2 = basePoint.plusScaled(termY.negate(), terminatorHalfHeight);
108
108
  // Helper function to add fill parameters
109
109
  const addFillParams = () => {
110
110
  params.fillDisplay = FillDisplay.Always;
@@ -133,13 +133,13 @@ export function createTerminatorGeometry(builder, point, dir, params, textStyleS
133
133
  break;
134
134
  }
135
135
  case "circle": {
136
- const circle = Arc3d.createXY(point, radius);
136
+ const circle = Arc3d.createXY(point, terminatorHalfHeight);
137
137
  addGeometry(circle);
138
138
  break;
139
139
  }
140
140
  case "circleFilled": {
141
141
  addFillParams();
142
- const circle = Arc3d.createXY(point, radius);
142
+ const circle = Arc3d.createXY(point, terminatorHalfHeight);
143
143
  addGeometry(circle, true);
144
144
  break;
145
145
  }
@@ -148,14 +148,12 @@ export function createTerminatorGeometry(builder, point, dir, params, textStyleS
148
148
  if (!normalizedVector)
149
149
  throw new Error("Invalid reference vector for slash terminator.");
150
150
  const rotatedVector = normalizedVector.rotateXY(Angle.createDegrees(45));
151
- const startPoint = point.plusScaled(rotatedVector, -radius);
152
- const endPoint = point.plusScaled(rotatedVector, radius);
151
+ const startPoint = point.plusScaled(rotatedVector, -terminatorHalfHeight);
152
+ const endPoint = point.plusScaled(rotatedVector, terminatorHalfHeight);
153
153
  const slashLine = LineSegment3d.create(startPoint, endPoint);
154
154
  addGeometry(slashLine);
155
155
  break;
156
156
  }
157
- default:
158
- throw new Error(`Unknown terminator shape: ${textStyleSettings.leader.terminatorShape}`);
159
157
  }
160
158
  return result;
161
159
  }
@@ -1 +1 @@
1
- {"version":3,"file":"LeaderGeometry.js","sourceRoot":"","sources":["../../../src/annotations/LeaderGeometry.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAmB,WAAW,EAAgG,MAAM,oBAAoB,CAAC;AAC1K,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU,EAAkB,aAAa,EAAE,YAAY,EAAE,IAAI,EAAQ,OAAO,EAAa,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACvJ,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAG/C;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,sBAAsB,CAAC,OAAgC,EAAE,OAA+B,EAAE,MAAuB,EAAE,SAAoB,EAAE,MAAsB,EAAE,iBAAoC,EAAE,W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,CAAC;QACvG,eAAe,GAAG,kBAAkB,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC;IACzD,CAAC;IACD,OAAO,eAAe,CAAC;AACzB,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 ElementGeometry\n */\n\nimport { ColorDef, ElementGeometry, FillDisplay, GeometryParams, TextAnnotationLeader, TextFrameStyleProps, TextStyleColor, TextStyleSettings } from \"@itwin/core-common\";\nimport { Angle, Arc3d, CurveCurve, CurvePrimitive, LineSegment3d, LineString3d, Loop, Path, Point3d, Transform, Vector3d } from \"@itwin/core-geometry\";\nimport { computeFrame } from \"./FrameGeometry\";\nimport { TextBlockLayout, TextStyleResolver } from \"./TextBlockLayout\";\n\n/**\n * Constructs and appends leader lines and their terminators to the provided geometry builder for a text annotation.\n *\n * This function processes an array of `TextAnnotationLeader` objects, computes their attachment points\n * relative to a text frame (or a default rectangular frame if none is provided), and appends the leader\n * line and terminator geometry to the builder. It also applies color overrides if specified\n * in the leader's style overrides.\n *\n * @param builder - The geometry builder to which the leader geometries will be appended.\n * @param leaders - An array of leader properties.\n * @param layout - The layout information for the text block, including its range.\n * @param transform - The transform to apply to the frame and leader geometry.\n * @param params - The geometry parameters, such as color, to use for the leader lines.\n * @param textStyleResolver - Resolver for text styles, used to obtain leader styles.\n * @param scaleFactor - The scale factor to apply to leader dimensions, usually comes from the `scaleFactor` of a [[Drawing]] element.\n * @returns `true` if at least one leader with a terminator was successfully appended; otherwise, `false`.\n * @beta\n */\nexport function appendLeadersToBuilder(builder: ElementGeometry.Builder, leaders: TextAnnotationLeader[], layout: TextBlockLayout, transform: Transform, params: GeometryParams, textStyleResolver: TextStyleResolver, scaleFactor: number): boolean {\n let result = true;\n const scaledBlockTextHeight = textStyleResolver.blockSettings.textHeight * scaleFactor;\n let frame: TextFrameStyleProps | undefined = textStyleResolver.blockSettings.frame;\n\n // If there is no frame, use a rectangular frame to compute the attachmentPoints for leaders.\n if (frame === undefined || frame.shape === \"none\") {\n frame = { shape: \"rectangle\" }\n }\n if (frame.shape === undefined || frame.shape === \"none\") return false;\n const frameCurve = computeFrame({ frame: frame.shape, range: layout.range, transform });\n\n for (const leader of leaders) {\n const leaderStyle = textStyleResolver.resolveSettings(leader.styleOverrides ?? {}, true);\n\n let effectiveColor: TextStyleColor = \"subcategory\";\n\n if (leaderStyle.leader.color === \"inherit\") {\n effectiveColor = leaderStyle.color;\n } else if (leaderStyle.leader.color !== \"subcategory\") {\n effectiveColor = leaderStyle.leader.color;\n }\n\n if (effectiveColor !== \"subcategory\") {\n params.lineColor = ColorDef.fromJSON(effectiveColor);\n result = result && builder.appendGeometryParamsChange(params);\n }\n\n const attachmentPoint = computeLeaderAttachmentPoint(leader, frameCurve, layout, transform);\n if (!attachmentPoint) return false;\n\n // Leader line geometry\n const leaderLinePoints: Point3d[] = [];\n\n leaderLinePoints.push(leader.startPoint)\n\n leader.intermediatePoints?.forEach((point) => {\n leaderLinePoints.push(point);\n });\n\n if (leaderStyle.leader.wantElbow) {\n const elbowLength = leaderStyle.leader.elbowLength * scaledBlockTextHeight;\n const elbowDirection = computeElbowDirection(attachmentPoint, frameCurve, elbowLength);\n if (elbowDirection)\n leaderLinePoints.push(attachmentPoint.plusScaled(elbowDirection, elbowLength))\n }\n\n leaderLinePoints.push(attachmentPoint)\n\n const terminatorDirection = Vector3d.createStartEnd(\n leaderLinePoints[0], leaderLinePoints[1]\n ).normalize();\n const terminatorWidth = leaderStyle.leader.terminatorWidthFactor * scaledBlockTextHeight;\n // Truncate the first segment of the leader lines to account for the arrowhead size when closedArrow (hollow triangle) terminatorShape is used.\n if (leaderStyle.leader.terminatorShape === \"closedArrow\") {\n if (terminatorDirection)\n leaderLinePoints[0] = leaderLinePoints[0].plusScaled(terminatorDirection, terminatorWidth);\n }\n\n result = result && builder.appendGeometryQuery(LineString3d.create(leaderLinePoints));\n\n if (leaderStyle.leader.terminatorShape !== \"none\") {\n // Terminator geometry\n if (!terminatorDirection) continue; // Assuming leaders without terminators is a valid case.\n result = result && createTerminatorGeometry(builder, leader.startPoint, terminatorDirection, params, leaderStyle, scaledBlockTextHeight);\n\n }\n\n }\n return result;\n}\n\n/**\n * Creates the geometry for a terminator at the end of a leader line.\n * @param builder The geometry builder to append the terminator geometry to.\n * @param point The starting point of the leader line.\n * @param dir The direction vector of the leader line.\n * @param params The geometry parameters to use for the terminator.\n * @param textStyleSettings The text style settings to use for the terminator.\n * @param textHeight The height of the text block.\n * @returns True if the geometry was successfully created, false otherwise.\n * @beta\n */\nexport function createTerminatorGeometry(builder: ElementGeometry.Builder, point: Point3d, dir: Vector3d, params: GeometryParams, textStyleSettings: TextStyleSettings, textHeight: number): boolean {\n\n let result = true;\n const termY = dir.unitCrossProduct(Vector3d.unitZ());\n if (!termY) return false; // If dir is parallel to Z, we can't create a terminator\n const terminatorHeight = textStyleSettings.leader.terminatorHeightFactor * textHeight;\n const terminatorWidth = textStyleSettings.leader.terminatorWidthFactor * textHeight;\n const basePoint = point.plusScaled(dir, terminatorWidth);\n const point1 = basePoint.plusScaled(termY, terminatorHeight / 2);\n const point2 = basePoint.plusScaled(termY.negate(), terminatorHeight / 2);\n const radius = terminatorHeight / 2;\n\n // Helper function to add fill parameters\n const addFillParams = () => {\n params.fillDisplay = FillDisplay.Always;\n result = result && builder.appendGeometryParamsChange(params);\n };\n\n // Helper function to create geometry entry\n const addGeometry = (content: CurvePrimitive, useLoop = false) => {\n const finalContent = useLoop ? Loop.create(content) : content;\n result = result && builder.appendGeometryQuery(finalContent);\n };\n\n switch (textStyleSettings.leader.terminatorShape) {\n case \"openArrow\": {\n const lineString = LineString3d.create([point1, point, point2]);\n addGeometry(lineString);\n break;\n }\n\n case \"closedArrow\": {\n const lineString = LineString3d.create([point1, point, point2, point1]);\n addGeometry(lineString);\n break;\n }\n\n case \"closedArrowFilled\": {\n addFillParams();\n const lineString = LineString3d.create([point1, point, point2, point1]);\n addGeometry(lineString, true);\n break;\n }\n\n case \"circle\": {\n const circle = Arc3d.createXY(point, radius);\n addGeometry(circle);\n break;\n }\n\n case \"circleFilled\": {\n addFillParams();\n const circle = Arc3d.createXY(point, radius);\n addGeometry(circle, true);\n break;\n }\n\n case \"slash\": {\n const normalizedVector = dir.normalize();\n if (!normalizedVector) throw new Error(\"Invalid reference vector for slash terminator.\");\n\n const rotatedVector = normalizedVector.rotateXY(Angle.createDegrees(45));\n const startPoint = point.plusScaled(rotatedVector, -radius);\n const endPoint = point.plusScaled(rotatedVector, radius);\n\n const slashLine = LineSegment3d.create(startPoint, endPoint);\n addGeometry(slashLine);\n break;\n }\n\n default:\n throw new Error(`Unknown terminator shape: ${textStyleSettings.leader.terminatorShape}`);\n }\n\n return result;\n};\n\n\n/**\n * Computes the direction vector for an \"elbow\" for leader based on the attachment point and a frame curve.\n * The elbow direction is determined by whether the attachment point is closer to the left or right side of the frame.\n * If the computed elbow would be tangent to the frame at the intersection, no elbow direction is returned.\n *\n * @param attachmentPoint - The point where the leader attaches.\n * @param frameCurve - The frame curve (either a Loop or Path) to which the leader is attached.\n * @param elbowLength - The length of the elbow segment to be created.\n * @returns The direction vector for the elbow, or `undefined` if the elbow would be tangent to the frame.\n * @beta\n */\nexport function computeElbowDirection(attachmentPoint: Point3d, frameCurve: Loop | Path, elbowLength: number): Vector3d | undefined {\n\n let elbowDirection: Vector3d | undefined;\n // Determine the direction based on the closest point's position relative to the frame\n const isCloserToLeft = Math.abs(attachmentPoint.x - frameCurve.range().low.x) < Math.abs(attachmentPoint.x - frameCurve.range().high.x);\n\n // Decide the direction: left (-X) or right (+X)\n elbowDirection = isCloserToLeft ? Vector3d.unitX().negate() : Vector3d.unitX();\n\n // Verify if the elbow is a tangent to the frame, if yes, do not create an elbow\n const elbowPoint = attachmentPoint.plusScaled(elbowDirection, elbowLength);\n const elbowLine = LineSegment3d.create(attachmentPoint, elbowPoint);\n // Find intersection points between the elbow and the frame\n const intersections = CurveCurve.intersectionXYZPairs(elbowLine, false, frameCurve, false);\n // As the elbow will intersect the frame only at one point, we can safely use the first intersection\n const intersection = intersections[0];\n const curveFraction = intersection.detailB.fraction;\n const derivative = intersection.detailB.curve?.fractionToPointAndDerivative(curveFraction);\n const tangent = derivative?.direction.normalize();\n const lineDirection = Vector3d.createStartEnd(elbowLine.point0Ref, elbowLine.point1Ref).normalize();\n if (tangent && lineDirection) {\n const dot = tangent.dotProduct(lineDirection);\n // If the tangent and line direction are aligned (dot product close to 1 or -1), it's tangent\n if (Math.abs(dot) > 0.999) {\n elbowDirection = undefined;\n }\n }\n return elbowDirection;\n}\n\n/**\n * Computes the attachment point for a leader line on a text annotation frame.\n *\n * The attachment point is determined based on the leader's attachment mode:\n * - `\"Nearest\"`: Finds the closest point on the frame curve to the leader's start point.\n * - `\"KeyPoint\"`: Uses a specific curve segment and fraction along that segment to determine the point.\n * - `\"TextPoint\"`: Calculates a point on the text layout (top/bottom, left/right) and projects it onto the frame curve.\n *\n * @param leader - The leader props.\n * @param frameCurve - The curve (Loop or Path) representing the annotation frame.\n * @param textLayout - The layout information for the text block.\n * @param transform - The transform applied to the text layout.\n * @returns The computed attachment point as a `Point3d`, or `undefined` if it cannot be determined.\n * @beta\n */\nexport function computeLeaderAttachmentPoint(\n leader: TextAnnotationLeader,\n frameCurve: Loop | Path,\n textLayout: TextBlockLayout,\n transform: Transform\n): Point3d | undefined {\n let attachmentPoint: Point3d | undefined;\n\n if (leader.attachment.mode === \"Nearest\") {\n attachmentPoint = frameCurve.closestPoint(leader.startPoint)?.point;\n } else if (leader.attachment.mode === \"KeyPoint\") {\n const curves = frameCurve.collectCurvePrimitives(undefined, false, true);\n const curveIndex = leader.attachment.curveIndex;\n const fraction = leader.attachment.fraction;\n if (curveIndex >= curves.length) {\n // If the curveIndex is invalid, use the last curve\n // This is a fallback to avoid out-of-bounds access\n attachmentPoint = curves[curves.length - 1].fractionToPoint(fraction);\n } else {\n attachmentPoint = curves[curveIndex].fractionToPoint(fraction);\n }\n } else { // attachment.mode=\"TextPoint\"\n let scaleDirection = transform.matrix.getColumn(0).negate(); // direction to draw a scaled line from text attachment point to find intersection point on frame\n let lineIndex: number;\n if (leader.attachment.position.includes(\"Top\")) {\n lineIndex = 0\n } else {\n lineIndex = textLayout.lines.length - 1\n }\n const lineRange = textLayout.lines[lineIndex].range;\n const lineOffset = textLayout.lines[lineIndex].offsetFromDocument;\n const origin = transform.multiplyPoint3d(Point3d.fromJSON(lineOffset));\n let attachmentPointOnText = origin.plusScaled(transform.matrix.getColumn(1), ((lineRange.yLength()) / 2));\n\n if (leader.attachment.position.includes(\"Right\")) {\n attachmentPointOnText = attachmentPointOnText.plusScaled(transform.matrix.getColumn(0), lineRange.xLength());\n scaleDirection = scaleDirection.negate();\n }\n // Find the nearest intersection point on the frame to get the correct attachment point\n // Extend the direction vector to create a target point far along the direction\n const targetPoint = attachmentPointOnText.plusScaled(scaleDirection, 1e6); // Scale the direction vector to a large value\n const intersectionLine = LineSegment3d.create(attachmentPointOnText, targetPoint);\n const closestPointDetail = CurveCurve.intersectionXYZPairs(intersectionLine, false, frameCurve, false);\n attachmentPoint = closestPointDetail[0]?.detailA.point;\n }\n return attachmentPoint;\n}"]}
1
+ {"version":3,"file":"LeaderGeometry.js","sourceRoot":"","sources":["../../../src/annotations/LeaderGeometry.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAmB,WAAW,EAAgG,MAAM,oBAAoB,CAAC;AAC1K,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU,EAAkB,aAAa,EAAE,YAAY,EAAE,IAAI,EAAQ,OAAO,EAAa,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACvJ,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAG/C;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU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G,eAAe,GAAG,kBAAkB,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC;IACzD,CAAC;IACD,OAAO,eAAe,CAAC;AACzB,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 ElementGeometry\n */\n\nimport { ColorDef, ElementGeometry, FillDisplay, GeometryParams, TextAnnotationLeader, TextFrameStyleProps, TextStyleColor, TextStyleSettings } from \"@itwin/core-common\";\nimport { Angle, Arc3d, CurveCurve, CurvePrimitive, LineSegment3d, LineString3d, Loop, Path, Point3d, Transform, Vector3d } from \"@itwin/core-geometry\";\nimport { computeFrame } from \"./FrameGeometry\";\nimport { TextBlockLayout, TextStyleResolver } from \"./TextBlockLayout\";\n\n/**\n * Constructs and appends leader lines and their terminators to the provided geometry builder for a text annotation.\n *\n * This function processes an array of `TextAnnotationLeader` objects, computes their attachment points\n * relative to a text frame (or a default rectangular frame if none is provided), and appends the leader\n * line and terminator geometry to the builder. It also applies color overrides if specified\n * in the leader's style overrides.\n *\n * @param builder - The geometry builder to which the leader geometries will be appended.\n * @param leaders - An array of leader properties.\n * @param layout - The layout information for the text block, including its range.\n * @param transform - The transform to apply to the frame and leader geometry.\n * @param params - The geometry parameters, such as color, to use for the leader lines.\n * @param textStyleResolver - Resolver for text styles, used to obtain leader styles.\n * @param scaleFactor - The scale factor to apply to leader dimensions, usually comes from the `scaleFactor` of a [[Drawing]] element.\n * @returns `true` if at least one leader with a terminator was successfully appended; otherwise, `false`.\n * @beta\n */\nexport function appendLeadersToBuilder(builder: ElementGeometry.Builder, leaders: TextAnnotationLeader[], layout: TextBlockLayout, transform: Transform, params: GeometryParams, textStyleResolver: TextStyleResolver, scaleFactor: number): boolean {\n let result = true;\n const scaledBlockTextHeight = textStyleResolver.blockSettings.textHeight * scaleFactor;\n let frame: TextFrameStyleProps | undefined = textStyleResolver.blockSettings.frame;\n\n // If there is no frame, use a rectangular frame to compute the attachmentPoints for leaders.\n if (frame === undefined || frame.shape === \"none\") {\n frame = { shape: \"rectangle\" }\n }\n if (frame.shape === undefined || frame.shape === \"none\") return false;\n const frameCurve = computeFrame({ frame: frame.shape, range: layout.range, transform });\n\n for (const leader of leaders) {\n const leaderStyle = textStyleResolver.resolveSettings(leader.styleOverrides ?? {}, true);\n\n let effectiveColor: TextStyleColor = \"subcategory\";\n\n if (leaderStyle.leader.color === \"inherit\") {\n effectiveColor = leaderStyle.color;\n } else if (leaderStyle.leader.color !== \"subcategory\") {\n effectiveColor = leaderStyle.leader.color;\n }\n\n if (effectiveColor !== \"subcategory\") {\n params.lineColor = ColorDef.fromJSON(effectiveColor);\n result = result && builder.appendGeometryParamsChange(params);\n }\n\n const attachmentPoint = computeLeaderAttachmentPoint(leader, frameCurve, layout, transform);\n if (!attachmentPoint) return false;\n\n // Leader line geometry\n const leaderLinePoints: Point3d[] = [];\n\n leaderLinePoints.push(leader.startPoint)\n\n leader.intermediatePoints?.forEach((point) => {\n leaderLinePoints.push(point);\n });\n\n if (leaderStyle.leader.wantElbow) {\n const elbowLength = leaderStyle.leader.elbowLength * scaledBlockTextHeight;\n const elbowDirection = computeElbowDirection(attachmentPoint, frameCurve, elbowLength);\n if (elbowDirection)\n leaderLinePoints.push(attachmentPoint.plusScaled(elbowDirection, elbowLength))\n }\n\n leaderLinePoints.push(attachmentPoint)\n\n const terminatorDirection = Vector3d.createStartEnd(\n leaderLinePoints[0], leaderLinePoints[1]\n ).normalize();\n const terminatorWidth = leaderStyle.leader.terminatorWidthFactor * scaledBlockTextHeight;\n // Truncate the first segment of the leader lines to account for the arrowhead size when closedArrow (hollow triangle) terminatorShape is used.\n if (leaderStyle.leader.terminatorShape === \"closedArrow\") {\n if (terminatorDirection)\n leaderLinePoints[0] = leaderLinePoints[0].plusScaled(terminatorDirection, terminatorWidth);\n }\n\n result = result && builder.appendGeometryQuery(LineString3d.create(leaderLinePoints));\n\n if (leaderStyle.leader.terminatorShape !== \"none\") {\n // Terminator geometry\n if (!terminatorDirection) continue; // Assuming leaders without terminators is a valid case.\n result = result && createTerminatorGeometry(builder, leader.startPoint, terminatorDirection, params, leaderStyle, scaledBlockTextHeight);\n\n }\n\n }\n return result;\n}\n\n/**\n * Creates the geometry for a terminator at the end of a leader line.\n * @param builder The geometry builder to append the terminator geometry to.\n * @param point The starting point of the leader line.\n * @param dir The direction vector of the leader line.\n * @param params The geometry parameters to use for the terminator.\n * @param textStyleSettings The text style settings to use for the terminator.\n * @param textHeight The height of the text block.\n * @returns True if the geometry was successfully created, false otherwise.\n * @beta\n */\nexport function createTerminatorGeometry(builder: ElementGeometry.Builder, point: Point3d, dir: Vector3d, params: GeometryParams, textStyleSettings: TextStyleSettings, textHeight: number): boolean {\n\n let result = true;\n const termY = dir.unitCrossProduct(Vector3d.unitZ());\n if (!termY) return false; // If dir is parallel to Z, we can't create a terminator\n const terminatorHeight = textStyleSettings.leader.terminatorHeightFactor * textHeight;\n const terminatorWidth = textStyleSettings.leader.terminatorWidthFactor * textHeight;\n const terminatorHalfHeight = terminatorHeight / 2;\n const basePoint = point.plusScaled(dir, terminatorWidth);\n const point1 = basePoint.plusScaled(termY, terminatorHalfHeight);\n const point2 = basePoint.plusScaled(termY.negate(), terminatorHalfHeight);\n\n // Helper function to add fill parameters\n const addFillParams = () => {\n params.fillDisplay = FillDisplay.Always;\n result = result && builder.appendGeometryParamsChange(params);\n };\n\n // Helper function to create geometry entry\n const addGeometry = (content: CurvePrimitive, useLoop = false) => {\n const finalContent = useLoop ? Loop.create(content) : content;\n result = result && builder.appendGeometryQuery(finalContent);\n };\n\n switch (textStyleSettings.leader.terminatorShape) {\n case \"openArrow\": {\n const lineString = LineString3d.create([point1, point, point2]);\n addGeometry(lineString);\n break;\n }\n\n case \"closedArrow\": {\n const lineString = LineString3d.create([point1, point, point2, point1]);\n addGeometry(lineString);\n break;\n }\n\n case \"closedArrowFilled\": {\n addFillParams();\n const lineString = LineString3d.create([point1, point, point2, point1]);\n addGeometry(lineString, true);\n break;\n }\n\n case \"circle\": {\n const circle = Arc3d.createXY(point, terminatorHalfHeight);\n addGeometry(circle);\n break;\n }\n\n case \"circleFilled\": {\n addFillParams();\n const circle = Arc3d.createXY(point, terminatorHalfHeight);\n addGeometry(circle, true);\n break;\n }\n\n case \"slash\": {\n const normalizedVector = dir.normalize();\n if (!normalizedVector) throw new Error(\"Invalid reference vector for slash terminator.\");\n\n const rotatedVector = normalizedVector.rotateXY(Angle.createDegrees(45));\n const startPoint = point.plusScaled(rotatedVector, -terminatorHalfHeight);\n const endPoint = point.plusScaled(rotatedVector, terminatorHalfHeight);\n\n const slashLine = LineSegment3d.create(startPoint, endPoint);\n addGeometry(slashLine);\n break;\n }\n }\n\n return result;\n};\n\n\n/**\n * Computes the direction vector for an \"elbow\" for leader based on the attachment point and a frame curve.\n * The elbow direction is determined by whether the attachment point is closer to the left or right side of the frame.\n * If the computed elbow would be tangent to the frame at the intersection, no elbow direction is returned.\n *\n * @param attachmentPoint - The point where the leader attaches.\n * @param frameCurve - The frame curve (either a Loop or Path) to which the leader is attached.\n * @param elbowLength - The length of the elbow segment to be created.\n * @returns The direction vector for the elbow, or `undefined` if the elbow would be tangent to the frame.\n * @beta\n */\nexport function computeElbowDirection(attachmentPoint: Point3d, frameCurve: Loop | Path, elbowLength: number): Vector3d | undefined {\n\n let elbowDirection: Vector3d | undefined;\n // Determine the direction based on the closest point's position relative to the frame\n const isCloserToLeft = Math.abs(attachmentPoint.x - frameCurve.range().low.x) < Math.abs(attachmentPoint.x - frameCurve.range().high.x);\n\n // Decide the direction: left (-X) or right (+X)\n elbowDirection = isCloserToLeft ? Vector3d.unitX().negate() : Vector3d.unitX();\n\n // Verify if the elbow is a tangent to the frame, if yes, do not create an elbow\n const elbowPoint = attachmentPoint.plusScaled(elbowDirection, elbowLength);\n const elbowLine = LineSegment3d.create(attachmentPoint, elbowPoint);\n // Find intersection points between the elbow and the frame\n const intersections = CurveCurve.intersectionXYZPairs(elbowLine, false, frameCurve, false);\n // As the elbow will intersect the frame only at one point, we can safely use the first intersection\n const intersection = intersections[0];\n const curveFraction = intersection.detailB.fraction;\n const derivative = intersection.detailB.curve?.fractionToPointAndDerivative(curveFraction);\n const tangent = derivative?.direction.normalize();\n const lineDirection = Vector3d.createStartEnd(elbowLine.point0Ref, elbowLine.point1Ref).normalize();\n if (tangent && lineDirection) {\n const dot = tangent.dotProduct(lineDirection);\n // If the tangent and line direction are aligned (dot product close to 1 or -1), it's tangent\n if (Math.abs(dot) > 0.999) {\n elbowDirection = undefined;\n }\n }\n return elbowDirection;\n}\n\n/**\n * Computes the attachment point for a leader line on a text annotation frame.\n *\n * The attachment point is determined based on the leader's attachment mode:\n * - `\"Nearest\"`: Finds the closest point on the frame curve to the leader's start point.\n * - `\"KeyPoint\"`: Uses a specific curve segment and fraction along that segment to determine the point.\n * - `\"TextPoint\"`: Calculates a point on the text layout (top/bottom, left/right) and projects it onto the frame curve.\n *\n * @param leader - The leader props.\n * @param frameCurve - The curve (Loop or Path) representing the annotation frame.\n * @param textLayout - The layout information for the text block.\n * @param transform - The transform applied to the text layout.\n * @returns The computed attachment point as a `Point3d`, or `undefined` if it cannot be determined.\n * @beta\n */\nexport function computeLeaderAttachmentPoint(\n leader: TextAnnotationLeader,\n frameCurve: Loop | Path,\n textLayout: TextBlockLayout,\n transform: Transform\n): Point3d | undefined {\n let attachmentPoint: Point3d | undefined;\n\n if (leader.attachment.mode === \"Nearest\") {\n attachmentPoint = frameCurve.closestPoint(leader.startPoint)?.point;\n } else if (leader.attachment.mode === \"KeyPoint\") {\n const curves = frameCurve.collectCurvePrimitives(undefined, false, true);\n const curveIndex = leader.attachment.curveIndex;\n const fraction = leader.attachment.fraction;\n if (curveIndex >= curves.length) {\n // If the curveIndex is invalid, use the last curve\n // This is a fallback to avoid out-of-bounds access\n attachmentPoint = curves[curves.length - 1].fractionToPoint(fraction);\n } else {\n attachmentPoint = curves[curveIndex].fractionToPoint(fraction);\n }\n } else { // attachment.mode=\"TextPoint\"\n let scaleDirection = transform.matrix.getColumn(0).negate(); // direction to draw a scaled line from text attachment point to find intersection point on frame\n let lineIndex: number;\n if (leader.attachment.position.includes(\"Top\")) {\n lineIndex = 0\n } else {\n lineIndex = textLayout.lines.length - 1\n }\n const lineRange = textLayout.lines[lineIndex].range;\n const lineOffset = textLayout.lines[lineIndex].offsetFromDocument;\n const origin = transform.multiplyPoint3d(Point3d.fromJSON(lineOffset));\n let attachmentPointOnText = origin.plusScaled(transform.matrix.getColumn(1), ((lineRange.yLength()) / 2));\n\n if (leader.attachment.position.includes(\"Right\")) {\n attachmentPointOnText = attachmentPointOnText.plusScaled(transform.matrix.getColumn(0), lineRange.xLength());\n scaleDirection = scaleDirection.negate();\n }\n // Find the nearest intersection point on the frame to get the correct attachment point\n // Extend the direction vector to create a target point far along the direction\n const targetPoint = attachmentPointOnText.plusScaled(scaleDirection, 1e6); // Scale the direction vector to a large value\n const intersectionLine = LineSegment3d.create(attachmentPointOnText, targetPoint);\n const closestPointDetail = CurveCurve.intersectionXYZPairs(intersectionLine, false, frameCurve, false);\n attachmentPoint = closestPointDetail[0]?.detailA.point;\n }\n return attachmentPoint;\n}"]}
@@ -1 +1 @@
1
- {"version":3,"file":"TextAnnotationElement.d.ts","sourceRoot":"","sources":["../../../src/annotations/TextAnnotationElement.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,wBAAwB,EAAe,IAAI,EAAE,SAAS,EAAE,cAAc,EAA4E,kBAAkB,EAAe,gBAAgB,EAAe,gBAAgB,EAAkB,cAAc,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,sBAAsB,EAA8B,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACjc,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EA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_VERSION)
444
444
  return oldData.data;
445
- if (oldData.data.leader) {
446
- oldData.data.leader.terminatorShape = oldData.data.leader.terminatorShape ?? TextStyleSettings.defaultProps.leader.terminatorShape;
445
+ // Migrate from 1.0.0 to 1.0.1
446
+ if (oldData.data.leader && !oldData.data.leader.terminatorShape) {
447
+ oldData.data.leader.terminatorShape = TextStyleSettings.defaultProps.leader.terminatorShape;
447
448
  }
448
449
  return oldData.data;
449
- // Only if something goes wrong, throw an error.
450
- // throw new Error(`Migration for settings from version ${oldData.version} to ${TEXT_STYLE_SETTINGS_JSON_VERSION} failed.`);
451
450
  }
452
451
  /**
453
452
  * The definition element that holds text style information.