@itwin/core-backend 5.3.0-dev.7 → 5.3.0-dev.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -1
- package/lib/cjs/annotations/ElementDrivesTextAnnotation.d.ts +7 -1
- package/lib/cjs/annotations/ElementDrivesTextAnnotation.d.ts.map +1 -1
- package/lib/cjs/annotations/ElementDrivesTextAnnotation.js +25 -0
- package/lib/cjs/annotations/ElementDrivesTextAnnotation.js.map +1 -1
- package/lib/cjs/annotations/TextAnnotationElement.d.ts +20 -1
- package/lib/cjs/annotations/TextAnnotationElement.d.ts.map +1 -1
- package/lib/cjs/annotations/TextAnnotationElement.js +84 -2
- package/lib/cjs/annotations/TextAnnotationElement.js.map +1 -1
- package/lib/cjs/internal/annotations/fields.d.ts.map +1 -1
- package/lib/cjs/internal/annotations/fields.js +1 -0
- package/lib/cjs/internal/annotations/fields.js.map +1 -1
- package/lib/esm/annotations/ElementDrivesTextAnnotation.d.ts +7 -1
- package/lib/esm/annotations/ElementDrivesTextAnnotation.d.ts.map +1 -1
- package/lib/esm/annotations/ElementDrivesTextAnnotation.js +25 -0
- package/lib/esm/annotations/ElementDrivesTextAnnotation.js.map +1 -1
- package/lib/esm/annotations/TextAnnotationElement.d.ts +20 -1
- package/lib/esm/annotations/TextAnnotationElement.d.ts.map +1 -1
- package/lib/esm/annotations/TextAnnotationElement.js +86 -5
- package/lib/esm/annotations/TextAnnotationElement.js.map +1 -1
- package/lib/esm/internal/annotations/fields.d.ts.map +1 -1
- package/lib/esm/internal/annotations/fields.js +1 -0
- package/lib/esm/internal/annotations/fields.js.map +1 -1
- package/lib/esm/test/annotations/Fields.test.js +146 -51
- package/lib/esm/test/annotations/Fields.test.js.map +1 -1
- package/lib/esm/test/annotations/TextAnnotation.test.js +227 -2
- package/lib/esm/test/annotations/TextAnnotation.test.js.map +1 -1
- package/package.json +13 -13
|
@@ -1 +1 @@
|
|
|
1
|
-
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AAa,EAAE,EAAE,CAAC;gBAC3C,IAAI,YAAY,CAAC,KAAK,CAAC,SAAS,EAAE,OAAO,CAAC,EAAE,CAAC;oBAC3C,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gBAC5B,CAAC;YACH,CAAC;YAED,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC7B,MAAM,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAC;YACzC,CAAC;QACH,CAAC;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,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 }\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;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,GAAG,OAAO,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC;IACnD,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,QAAQ,GAAG,OAAO,CAAC,MAA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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"]}
|
|
@@ -6,6 +6,7 @@ import { ElementDrivesElement } from "../Relationship";
|
|
|
6
6
|
import { IModelDb } from "../IModelDb";
|
|
7
7
|
import { Element } from "../Element";
|
|
8
8
|
import { Id64String } from "@itwin/core-bentley";
|
|
9
|
+
import { IModelElementCloneContext } from "../IModelElementCloneContext";
|
|
9
10
|
/** Describes one of potentially many [TextBlock]($common)s hosted by an [[ITextAnnotation]].
|
|
10
11
|
* For example, a [[TextAnnotation2d]] hosts only a single text block, but an element representing a table may
|
|
11
12
|
* host one text block for each cell in the table, in which case it might use the combination of row and column
|
|
@@ -28,7 +29,7 @@ export interface ITextAnnotation {
|
|
|
28
29
|
defaultTextStyle?: TextAnnotationUsesTextStyleByDefault;
|
|
29
30
|
/** Obtain a collection of all of the [TextBlock]($common)s hosted by this element. */
|
|
30
31
|
getTextBlocks(): Iterable<TextBlockAndId>;
|
|
31
|
-
/** Update the element to replace the contents of the specified [TextBlock]($common)s. */
|
|
32
|
+
/** Update the element in-memory to replace the contents of the specified [TextBlock]($common)s. */
|
|
32
33
|
updateTextBlocks(textBlocks: TextBlockAndId[]): void;
|
|
33
34
|
}
|
|
34
35
|
/** Returns `true` if the specified `element` implements [[ITextAnnotation]].
|
|
@@ -59,6 +60,11 @@ export declare class ElementDrivesTextAnnotation extends ElementDrivesElement {
|
|
|
59
60
|
* It also deletes any stale relationships left over from fields that were deleted or whose source elements changed.
|
|
60
61
|
*/
|
|
61
62
|
static updateFieldDependencies(annotationElementId: Id64String, iModel: IModelDb): void;
|
|
63
|
+
/** When copying an [[ITextAnnotation]] from one iModel into another, remaps the element Ids in any [FieldPropertyHost]($common) within the cloned element
|
|
64
|
+
* 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
|
+
* Implementations of `ITextAnnotation` should invoke this function from their implementations of [[Element._onCloned]].
|
|
66
|
+
*/
|
|
67
|
+
static remapFields(clone: ITextAnnotation, context: IModelElementCloneContext): void;
|
|
62
68
|
}
|
|
63
69
|
/** Relationship indicating that the [[AnnotationTextStyle]] is being used as the default style for the [[ITextAnnotation]].
|
|
64
70
|
* @beta
|
|
@@ -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;A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AQ,GAAG,IAAI;IAItF,gBAAgB;WACO,mBAAmB,CAAC,KAAK,EAAE,iBAAiB,EAAE,MAAM,EAAE,QAAQ,GAAG,IAAI;IAI5F;;;OAGG;WACW,oBAAoB,CAAC,MAAM,EAAE,QAAQ,GAAG,OAAO;IAK7D;;;OAGG;WACW,uBAAuB,CAAC,mBAAmB,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,GAAG,IAAI;IA4D9F;;;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"}
|
|
@@ -100,6 +100,31 @@ export class ElementDrivesTextAnnotation extends ElementDrivesElement {
|
|
|
100
100
|
annotationElement.iModel.relationships.deleteInstance(props);
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
|
+
/** When copying an [[ITextAnnotation]] from one iModel into another, remaps the element Ids in any [FieldPropertyHost]($common) within the cloned element
|
|
104
|
+
* 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
|
+
* Implementations of `ITextAnnotation` should invoke this function from their implementations of [[Element._onCloned]].
|
|
106
|
+
*/
|
|
107
|
+
static remapFields(clone, context) {
|
|
108
|
+
if (!context.isBetweenIModels) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const updatedBlocks = [];
|
|
112
|
+
for (const block of clone.getTextBlocks()) {
|
|
113
|
+
let anyUpdated = false;
|
|
114
|
+
for (const { child } of traverseTextBlockComponent(block.textBlock)) {
|
|
115
|
+
if (child.type === "field") {
|
|
116
|
+
child.propertyHost.elementId = context.findTargetElementId(child.propertyHost.elementId);
|
|
117
|
+
anyUpdated = true;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (anyUpdated) {
|
|
121
|
+
updatedBlocks.push(block);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (updatedBlocks.length > 0) {
|
|
125
|
+
clone.updateTextBlocks(updatedBlocks);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
103
128
|
}
|
|
104
129
|
/** Relationship indicating that the [[AnnotationTextStyle]] is being used as the default style for the [[ITextAnnotation]].
|
|
105
130
|
* @beta
|
|
@@ -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;AAerD,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;AAED;;;;;;;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,EA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c,KAAK,IAAI,EAAE,CAAC;gBAC5B,2BAA2B,CAAC,MAAM,CAAC,iBAAiB,CAAC,MAAM,EAAE,QAAQ,EAAE,iBAAiB,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC;YACxG,CAAC;QACH,CAAC;QAED,KAAK,MAAM,cAAc,IAAI,kBAAkB,EAAE,CAAC;YAChD,MAAM,KAAK,GAAG,iBAAiB,CAAC,MAAM,CAAC,aAAa,CAAC,gBAAgB,CAAC,qCAAqC,EAAE,cAAc,CAAC,CAAC;YAC7H,iBAAiB,CAAC,MAAM,CAAC,aAAa,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;QAC/D,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\";\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 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 for (const relationshipId of staleRelationships) {\n const props = annotationElement.iModel.relationships.getInstanceProps(\"BisCore.ElementDrivesTextAnnotation\", relationshipId);\n annotationElement.iModel.relationships.deleteInstance(props);\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}"]}
|
|
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,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AAM,EAAE,KAAK,EAAE,IAAI,0BAA0B,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,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 for (const relationshipId of staleRelationships) {\n const props = annotationElement.iModel.relationships.getInstanceProps(\"BisCore.ElementDrivesTextAnnotation\", relationshipId);\n annotationElement.iModel.relationships.deleteInstance(props);\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,17 +1,22 @@
|
|
|
1
1
|
/** @packageDocumentation
|
|
2
2
|
* @module Elements
|
|
3
3
|
*/
|
|
4
|
-
import { AnnotationTextStyleProps, Code, CodeProps, CodeScopeProps, Placement2dProps, Placement3dProps, TextAnnotation, TextAnnotation2dProps, TextAnnotation3dProps, TextAnnotationProps, TextStyleSettings, TextStyleSettingsProps } from "@itwin/core-common";
|
|
4
|
+
import { AnnotationTextStyleProps, Code, CodeProps, CodeScopeProps, EntityReferenceSet, Placement2dProps, Placement3dProps, TextAnnotation, TextAnnotation2dProps, TextAnnotation3dProps, TextAnnotationProps, TextStyleSettings, TextStyleSettingsProps, VersionedJSON } from "@itwin/core-common";
|
|
5
5
|
import { IModelDb } from "../IModelDb";
|
|
6
6
|
import { AnnotationElement2d, DefinitionElement, GraphicalElement3d, OnElementIdArg, OnElementPropsArg } from "../Element";
|
|
7
7
|
import { Id64String } from "@itwin/core-bentley";
|
|
8
8
|
import { TextAnnotationUsesTextStyleByDefault, TextBlockAndId } from "./ElementDrivesTextAnnotation";
|
|
9
|
+
import { IModelElementCloneContext } from "../IModelElementCloneContext";
|
|
9
10
|
import { CustomHandledProperty, DeserializeEntityArgs, ECSqlRow } from "../Entity";
|
|
10
11
|
/** The version of the JSON stored in `TextAnnotation2d/3dProps.textAnnotationData` used by the code.
|
|
11
12
|
* Uses the same semantics as [ECVersion]($ecschema-metadata).
|
|
12
13
|
* @internal
|
|
13
14
|
*/
|
|
14
15
|
export declare const TEXT_ANNOTATION_JSON_VERSION = "1.0.0";
|
|
16
|
+
/** Parses, validates, and potentially migrates the text annotation data from a JSON string.
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
export declare function parseTextAnnotationData(json: string | undefined): VersionedJSON<TextAnnotationProps> | undefined;
|
|
15
20
|
/** Arguments supplied when creating a [[TextAnnotation2d]].
|
|
16
21
|
* @beta
|
|
17
22
|
*/
|
|
@@ -130,6 +135,9 @@ export declare class TextAnnotation2d extends AnnotationElement2d {
|
|
|
130
135
|
static onInserted(arg: OnElementIdArg): void;
|
|
131
136
|
/** @internal */
|
|
132
137
|
static onUpdated(arg: OnElementIdArg): void;
|
|
138
|
+
protected collectReferenceIds(referenceIds: EntityReferenceSet): void;
|
|
139
|
+
/** @internal */
|
|
140
|
+
protected static onCloned(context: IModelElementCloneContext, srcProps: TextAnnotation2dProps, dstProps: TextAnnotation2dProps): void;
|
|
133
141
|
}
|
|
134
142
|
/** An element that displays textual content within a 3d model.
|
|
135
143
|
* The text is stored as a [TextAnnotation]($common) from which the element's [geometry]($docs/learning/common/GeometryStream.md) and [Placement]($common) are computed.
|
|
@@ -215,6 +223,9 @@ export declare class TextAnnotation3d extends GraphicalElement3d {
|
|
|
215
223
|
static onInserted(arg: OnElementIdArg): void;
|
|
216
224
|
/** @internal */
|
|
217
225
|
static onUpdated(arg: OnElementIdArg): void;
|
|
226
|
+
protected collectReferenceIds(referenceIds: EntityReferenceSet): void;
|
|
227
|
+
/** @internal */
|
|
228
|
+
protected static onCloned(context: IModelElementCloneContext, srcProps: TextAnnotation3dProps, dstProps: TextAnnotation3dProps): void;
|
|
218
229
|
}
|
|
219
230
|
/** The version of the JSON stored in `AnnotationTextStyleProps.settings` used by the code.
|
|
220
231
|
* Uses the same semantics as [ECVersion]($ecschema-metadata).
|
|
@@ -309,5 +320,13 @@ export declare class AnnotationTextStyle extends DefinitionElement {
|
|
|
309
320
|
static serialize(props: AnnotationTextStyleProps, iModel: IModelDb): ECSqlRow;
|
|
310
321
|
/** Parses, validates, and potentially migrates the text style settings data from a JSON string. */
|
|
311
322
|
private static parseTextStyleSettings;
|
|
323
|
+
/** When copying an element from one iModel to another, returns the Id of the AnnotationTextStyle in the `context`'s target iModel
|
|
324
|
+
* corresponding to `sourceTextStyleId`, or [Id64.invalid]($bentley) if no corresponding text style exists.
|
|
325
|
+
* If a text style with the same [Code]($common) exists in the target iModel, the style Id will be remapped to refer to that style.
|
|
326
|
+
* Otherwise, a copy of the style will be imported into the target iModel and its element Id returned.
|
|
327
|
+
* Implementations of [[ITextAnnotation]] should invoke this function when implementing their [[Element._onCloned]] method.
|
|
328
|
+
* @throws Error if an attempt to import the text style failed.
|
|
329
|
+
*/
|
|
330
|
+
static remapTextStyleId(sourceTextStyleId: Id64String, context: IModelElementCloneContext): Id64String;
|
|
312
331
|
}
|
|
313
332
|
//# sourceMappingURL=TextAnnotationElement.d.ts.map
|
|
@@ -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,
|
|
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,EAAW,kBAAkB,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACpI,OAAO,EAAgB,UAAU,EAAE,MAAM,q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lD,oFAAoF;WACtE,QAAQ,CAAC,KAAK,EAAE,wBAAwB,EAAE,MAAM,EAAE,QAAQ,GAAG,mBAAmB;IAI9F;;;;OAIG;qBACuB,QAAQ,CAAC,GAAG,EAAE,iBAAiB,GAAG,IAAI;IAKhE;;;;OAIG;qBACuB,QAAQ,CAAC,GAAG,EAAE,iBAAiB,GAAG,IAAI;IAKhE,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAU/B;;;;OAIG;IACH,0BAAmC,mBAAmB,EAAE,qBAAqB,EAAE,CAE7E;IAEF;;;;OAIG;WACoB,WAAW,CAAC,KAAK,EAAE,qBAAqB,GAAG,wBAAwB;IAS1F;;;;OAIG;WACoB,SAAS,CAAC,KAAK,EAAE,wBAAwB,EAAE,MAAM,EAAE,QAAQ,GAAG,QAAQ;IAQ7F,mGAAmG;IACnG,OAAO,CAAC,MAAM,CAAC,sBAAsB;IAKrC;;;;;;OAMG;WACW,gBAAgB,CAAC,iBAAiB,EAAE,UAAU,EAAE,OAAO,EAAE,yBAAyB,GAAG,UAAU;CA8B9G"}
|
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
/** @packageDocumentation
|
|
6
6
|
* @module Elements
|
|
7
7
|
*/
|
|
8
|
-
import { BisCodeSpec, Code, ElementGeometry, Placement2d, Placement3d, TextAnnotation, TextStyleSettings } from "@itwin/core-common";
|
|
8
|
+
import { BisCodeSpec, Code, ElementGeometry, Placement2d, Placement3d, TextAnnotation, TextStyleSettings, traverseTextBlockComponent } from "@itwin/core-common";
|
|
9
9
|
import { AnnotationElement2d, DefinitionElement, Drawing, GraphicalElement3d } from "../Element";
|
|
10
|
-
import { assert } from "@itwin/core-bentley";
|
|
10
|
+
import { assert, Id64 } from "@itwin/core-bentley";
|
|
11
11
|
import { layoutTextBlock, TextStyleResolver } from "./TextBlockLayout";
|
|
12
12
|
import { appendTextAnnotationGeometry } from "./TextAnnotationGeometry";
|
|
13
13
|
import { ElementDrivesTextAnnotation, TextAnnotationUsesTextStyleByDefault } from "./ElementDrivesTextAnnotation";
|
|
@@ -46,8 +46,10 @@ function migrateTextAnnotationData(oldData) {
|
|
|
46
46
|
// Place migration logic here.
|
|
47
47
|
throw new Error(`Migration for textAnnotationData from version ${oldData.version} to ${TEXT_ANNOTATION_JSON_VERSION} failed.`);
|
|
48
48
|
}
|
|
49
|
-
/** Parses, validates, and potentially migrates the text annotation data from a JSON string.
|
|
50
|
-
|
|
49
|
+
/** Parses, validates, and potentially migrates the text annotation data from a JSON string.
|
|
50
|
+
* @internal
|
|
51
|
+
*/
|
|
52
|
+
export function parseTextAnnotationData(json) {
|
|
51
53
|
if (!json)
|
|
52
54
|
return undefined;
|
|
53
55
|
return validateAndMigrateVersionedJSON(json, TEXT_ANNOTATION_JSON_VERSION, migrateTextAnnotationData);
|
|
@@ -215,6 +217,19 @@ export class TextAnnotation2d extends AnnotationElement2d /* implements ITextAnn
|
|
|
215
217
|
super.onUpdated(arg);
|
|
216
218
|
ElementDrivesTextAnnotation.updateFieldDependencies(arg.id, arg.iModel);
|
|
217
219
|
}
|
|
220
|
+
collectReferenceIds(referenceIds) {
|
|
221
|
+
super.collectReferenceIds(referenceIds);
|
|
222
|
+
collectReferenceIds(this, referenceIds);
|
|
223
|
+
}
|
|
224
|
+
/** @internal */
|
|
225
|
+
static onCloned(context, srcProps, dstProps) {
|
|
226
|
+
super.onCloned(context, srcProps, dstProps);
|
|
227
|
+
const srcElem = TextAnnotation2d.fromJSON(srcProps, context.sourceDb);
|
|
228
|
+
ElementDrivesTextAnnotation.remapFields(srcElem, context);
|
|
229
|
+
const anno = srcElem.getAnnotation();
|
|
230
|
+
dstProps.textAnnotationData = anno ? JSON.stringify({ version: TEXT_ANNOTATION_JSON_VERSION, data: anno.toJSON() }) : undefined;
|
|
231
|
+
remapTextStyle(context, srcElem, dstProps);
|
|
232
|
+
}
|
|
218
233
|
}
|
|
219
234
|
/** An element that displays textual content within a 3d model.
|
|
220
235
|
* The text is stored as a [TextAnnotation]($common) from which the element's [geometry]($docs/learning/common/GeometryStream.md) and [Placement]($common) are computed.
|
|
@@ -367,6 +382,40 @@ export class TextAnnotation3d extends GraphicalElement3d /* implements ITextAnno
|
|
|
367
382
|
super.onUpdated(arg);
|
|
368
383
|
ElementDrivesTextAnnotation.updateFieldDependencies(arg.id, arg.iModel);
|
|
369
384
|
}
|
|
385
|
+
collectReferenceIds(referenceIds) {
|
|
386
|
+
super.collectReferenceIds(referenceIds);
|
|
387
|
+
collectReferenceIds(this, referenceIds);
|
|
388
|
+
}
|
|
389
|
+
/** @internal */
|
|
390
|
+
static onCloned(context, srcProps, dstProps) {
|
|
391
|
+
super.onCloned(context, srcProps, dstProps);
|
|
392
|
+
const srcElem = TextAnnotation3d.fromJSON(srcProps, context.sourceDb);
|
|
393
|
+
ElementDrivesTextAnnotation.remapFields(srcElem, context);
|
|
394
|
+
const anno = srcElem.getAnnotation();
|
|
395
|
+
dstProps.textAnnotationData = anno ? JSON.stringify({ version: TEXT_ANNOTATION_JSON_VERSION, data: anno.toJSON() }) : undefined;
|
|
396
|
+
remapTextStyle(context, srcElem, dstProps);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
function remapTextStyle(context, srcElem, dstProps) {
|
|
400
|
+
const dstStyleId = AnnotationTextStyle.remapTextStyleId(srcElem.defaultTextStyle?.id ?? Id64.invalid, context);
|
|
401
|
+
dstProps.defaultTextStyle = Id64.isValid(dstStyleId) ? new TextAnnotationUsesTextStyleByDefault(dstStyleId).toJSON() : undefined;
|
|
402
|
+
}
|
|
403
|
+
function collectReferenceIds(elem, referenceIds) {
|
|
404
|
+
const style = elem.defaultTextStyle?.id;
|
|
405
|
+
if (style && Id64.isValidId64(style)) {
|
|
406
|
+
referenceIds.addElement(style);
|
|
407
|
+
}
|
|
408
|
+
const block = elem.getAnnotation()?.textBlock;
|
|
409
|
+
if (block) {
|
|
410
|
+
for (const { child } of traverseTextBlockComponent(block)) {
|
|
411
|
+
if (child.type === "field") {
|
|
412
|
+
const hostId = child.propertyHost.elementId;
|
|
413
|
+
if (Id64.isValidId64(hostId)) {
|
|
414
|
+
referenceIds.addElement(hostId);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
}
|
|
370
419
|
}
|
|
371
420
|
function getTextBlocks(elem) {
|
|
372
421
|
const annotation = elem.getAnnotation();
|
|
@@ -383,7 +432,6 @@ function updateTextBlocks(elem, textBlocks) {
|
|
|
383
432
|
}
|
|
384
433
|
annotation.textBlock = textBlocks[0].textBlock;
|
|
385
434
|
elem.setAnnotation(annotation);
|
|
386
|
-
elem.update();
|
|
387
435
|
}
|
|
388
436
|
/** The version of the JSON stored in `AnnotationTextStyleProps.settings` used by the code.
|
|
389
437
|
* Uses the same semantics as [ECVersion]($ecschema-metadata).
|
|
@@ -529,5 +577,38 @@ export class AnnotationTextStyle extends DefinitionElement {
|
|
|
529
577
|
return undefined;
|
|
530
578
|
return validateAndMigrateVersionedJSON(json, TEXT_STYLE_SETTINGS_JSON_VERSION, migrateTextStyleSettings);
|
|
531
579
|
}
|
|
580
|
+
/** When copying an element from one iModel to another, returns the Id of the AnnotationTextStyle in the `context`'s target iModel
|
|
581
|
+
* corresponding to `sourceTextStyleId`, or [Id64.invalid]($bentley) if no corresponding text style exists.
|
|
582
|
+
* If a text style with the same [Code]($common) exists in the target iModel, the style Id will be remapped to refer to that style.
|
|
583
|
+
* Otherwise, a copy of the style will be imported into the target iModel and its element Id returned.
|
|
584
|
+
* Implementations of [[ITextAnnotation]] should invoke this function when implementing their [[Element._onCloned]] method.
|
|
585
|
+
* @throws Error if an attempt to import the text style failed.
|
|
586
|
+
*/
|
|
587
|
+
static remapTextStyleId(sourceTextStyleId, context) {
|
|
588
|
+
// No remapping necessary if there's no text style or we're not copying to a different iModel.
|
|
589
|
+
if (!Id64.isValid(sourceTextStyleId) || !context.isBetweenIModels) {
|
|
590
|
+
return sourceTextStyleId;
|
|
591
|
+
}
|
|
592
|
+
// If the style's already been remapped, we're finished.
|
|
593
|
+
let dstStyleId = context.findTargetElementId(sourceTextStyleId);
|
|
594
|
+
if (Id64.isValid(dstStyleId)) {
|
|
595
|
+
return dstStyleId;
|
|
596
|
+
}
|
|
597
|
+
// Look up the style. It really ought to exist.
|
|
598
|
+
const srcStyle = context.sourceDb.elements.tryGetElement(sourceTextStyleId);
|
|
599
|
+
if (!srcStyle) {
|
|
600
|
+
return Id64.invalid;
|
|
601
|
+
}
|
|
602
|
+
// If a style with the same code exists in the target iModel, remap to that one.
|
|
603
|
+
dstStyleId = context.targetDb.elements.queryElementIdByCode(srcStyle.code);
|
|
604
|
+
if (undefined !== dstStyleId) {
|
|
605
|
+
return dstStyleId;
|
|
606
|
+
}
|
|
607
|
+
// Copy the style into the target iModel and remap its Id.
|
|
608
|
+
const dstStyleProps = context.cloneElement(srcStyle);
|
|
609
|
+
dstStyleId = context.targetDb.elements.insertElement(dstStyleProps);
|
|
610
|
+
context.remapElement(sourceTextStyleId, dstStyleId);
|
|
611
|
+
return dstStyleId;
|
|
612
|
+
}
|
|
532
613
|
}
|
|
533
614
|
//# sourceMappingURL=TextAnnotationElement.js.map
|