@itwin/editor-backend 5.5.0-dev.2 → 5.5.0-dev.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -1
- package/lib/cjs/EditBuiltInCommand.js.map +1 -1
- package/lib/cjs/EditCommand.js.map +1 -1
- package/lib/cjs/editor-backend.js.map +1 -1
- package/lib/esm/EditBuiltInCommand.js.map +1 -1
- package/lib/esm/EditCommand.js.map +1 -1
- package/lib/esm/editor-backend.js.map +1 -1
- package/package.json +11 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
# Change Log - @itwin/editor-backend
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Tue, 02 Dec 2025 23:11:57 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 5.4.0
|
|
6
|
+
Tue, 02 Dec 2025 21:22:25 GMT
|
|
7
|
+
|
|
8
|
+
### Updates
|
|
9
|
+
|
|
10
|
+
- Add support for Node.js 24
|
|
4
11
|
|
|
5
12
|
## 5.3.3
|
|
6
13
|
Thu, 20 Nov 2025 22:30:37 GMT
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditBuiltInCommand.js","sourceRoot":"","sources":["../../src/EditBuiltInCommand.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA4F;AAC5F,wDAA0H;AAE1H,oDAAgR;AAChR,wDAAkH;AAClH,+CAA4C;AAE5C;;GAEG;AACH,MAAa,wBAAyB,SAAQ,yBAAW;IAGR;IAFxC,MAAM,CAAU,SAAS,GAAG,mCAAmB,CAAC,oBAAoB,CAAC;IAE5E,YAAmB,MAAgB,EAAY,IAAY;QAAI,KAAK,CAAC,MAAM,CAAC,CAAC;QAA9B,SAAI,GAAJ,IAAI,CAAQ;IAAmB,CAAC;IAE/D,KAAK,CAAC,OAAO,KAAK,OAAO,wB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IAAI,yBAAW,CAAC,uBAAQ,CAAC,eAAe,EAAE,yBAAyB,CAAC,CAAC;QAE7E,MAAM,IAAI,CAAC,MAAM,CAAC,iBAAiB,EAAE,CAAC;QAEtC,IAAI,CAAC,MAAM,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAAC;QAE7C,wEAAwE;QACxE,MAAM,UAAU,GAAsB,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC;QAC7E,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,uBAAuB,CAAC,UAAU,CAAC,CAAC;QAEjE,IAAI,SAAS,KAAK,QAAQ,EAAE,CAAC;YAC3B,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;YACtC,MAAM,UAAU,GAAG,CAAC,CAAC;YAErB,IAAI,UAAU,KAAK,QAAQ,CAAC,aAAa,EAAE,CAAC;gBAC1C,QAAQ,CAAC,aAAa,GAAG,UAAU,CAAC;gBACpC,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC;YACrE,CAAC;QACH,CAAC;IACH,CAAC;IAEM,KAAK,CAAC,kBAAkB,CAAC,YAA+B;QAC7D,MAAM,IAAI,CAAC,MAAM,CAAC,iBAAiB,EAAE,CAAC;QAEtC,0DAA0D;QAC1D,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,CAAC;QAExE,MAAM,eAAe,GAAG,IAAI,0BAAY,CAAC,YAAY,CAAC,CAAC;QACvD,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC,eAAe,CAAC,CAAC;IAClD,CAAC;;AA9MH,4DA+MC","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 Editing\n */\n\nimport { CompressedId64Set, DbResult, Id64String, IModelStatus } from \"@itwin/core-bentley\";\nimport { Matrix3d, Matrix3dProps, Point3d, Range3d, Range3dProps, Transform, TransformProps } from \"@itwin/core-geometry\";\nimport { GeometricElement, IModelDb } from \"@itwin/core-backend\";\nimport { BRepEntity, EcefLocation, EcefLocationProps, ElementGeometry, ElementGeometryBuilderParams, ElementGeometryFunction, ElementGeometryInfo, ElementGeometryRequest, FilePropertyProps, GeometricElementProps, GeometryPartProps, IModelError } from \"@itwin/core-common\";\nimport { BasicManipulationCommandIpc, editorBuiltInCmdIds, FlatBufferGeometryFilter } from \"@itwin/editor-common\";\nimport { EditCommand } from \"./EditCommand\";\n\n/** Implementation for a EditCommand command that provides basic creation and modification operations.\n * @beta\n */\nexport class BasicManipulationCommand extends EditCommand implements BasicManipulationCommandIpc {\n public static override commandId = editorBuiltInCmdIds.cmdBasicManipulation;\n\n public constructor(iModel: IModelDb, protected _str: string) { super(iModel); }\n\n public override async onStart() { return BasicManipulationCommand.commandId; }\n\n public async addAllowedChannel(channelKey: string): Promise<void> {\n this.iModel.channels.addAllowedChannel(channelKey);\n }\n\n public async removeAllowedChannel(channelKey: string): Promise<void> {\n this.iModel.channels.removeAllowedChannel(channelKey);\n }\n\n public async deleteElements(ids: CompressedId64Set): Promise<IModelStatus> {\n const idSet = CompressedId64Set.decompressSet(ids);\n await this.iModel.locks.acquireLocks({ exclusive: idSet });\n\n for (const id of idSet)\n this.iModel.elements.deleteElement(id);\n\n return IModelStatus.Success;\n }\n\n public async transformPlacement(ids: CompressedId64Set, transProps: TransformProps): Promise<IModelStatus> {\n const idSet = CompressedId64Set.decompressSet(ids);\n await this.iModel.locks.acquireLocks({ exclusive: idSet });\n\n const transform = Transform.fromJSON(transProps);\n\n for (const id of idSet) {\n const element = this.iModel.elements.getElement<GeometricElement>(id);\n\n if (!element.placement.isValid)\n continue; // Ignore assembly parents w/o geometry, etc...\n\n element.placement.multiplyTransform(transform);\n this.iModel.elements.updateElement(element.toJSON());\n }\n\n return IModelStatus.Success;\n }\n\n public async rotatePlacement(ids: CompressedId64Set, matrixProps: Matrix3dProps, aboutCenter: boolean): Promise<IModelStatus> {\n const idSet = CompressedId64Set.decompressSet(ids);\n await this.iModel.locks.acquireLocks({ exclusive: idSet });\n\n const matrix = Matrix3d.fromJSON(matrixProps);\n\n for (const id of idSet) {\n const element = this.iModel.elements.getElement<GeometricElement>(id);\n\n if (!element.placement.isValid)\n continue; // Ignore assembly parents w/o geometry, etc...\n\n const fixedPoint = aboutCenter ? element.placement.calculateRange().center : Point3d.createFrom(element.placement.origin);\n const transform = Transform.createFixedPointAndMatrix(fixedPoint, matrix);\n\n element.placement.multiplyTransform(transform);\n this.iModel.elements.updateElement(element.toJSON());\n }\n\n return IModelStatus.Success;\n }\n\n public async insertGeometricElement(props: GeometricElementProps): Promise<Id64String> {\n await this.iModel.locks.acquireLocks({ shared: props.model });\n\n return this.iModel.elements.insertElement(props);\n }\n\n public async insertGeometryPart(props: GeometryPartProps): Promise<Id64String> {\n await this.iModel.locks.acquireLocks({ shared: props.model });\n\n return this.iModel.elements.insertElement(props);\n }\n\n public async updateGeometricElement(propsOrId: GeometricElementProps | Id64String, data?: ElementGeometryBuilderParams): Promise<void> {\n let props: GeometricElementProps;\n if (typeof propsOrId === \"string\") {\n if (undefined === data)\n throw new IModelError(DbResult.BE_SQLITE_ERROR, \"Flatbuffer data required for update by id\");\n props = this.iModel.elements.getElementProps<GeometricElementProps>(propsOrId);\n } else {\n props = propsOrId;\n }\n\n if (undefined === props.id)\n throw new IModelError(DbResult.BE_SQLITE_ERROR, \"Element id required for update\");\n\n await this.iModel.locks.acquireLocks({ exclusive: props.id });\n\n if (undefined !== data)\n props.elementGeometryBuilderParams = { entryArray: data.entryArray, viewIndependent: data.viewIndependent };\n\n this.iModel.elements.updateElement(props);\n }\n\n public async requestElementGeometry(elementId: Id64String, filter?: FlatBufferGeometryFilter): Promise<ElementGeometryInfo | undefined> {\n let accepted: ElementGeometryInfo | undefined;\n\n const onGeometry: ElementGeometryFunction = (info: ElementGeometryInfo): void => {\n accepted = info;\n\n if (undefined !== filter) {\n let numDisplayable = 0;\n\n for (const entry of info.entryArray) {\n if (!ElementGeometry.isDisplayableEntry(entry))\n continue;\n\n numDisplayable++;\n if (filter.maxDisplayable && numDisplayable > filter.maxDisplayable) {\n accepted = undefined;\n break;\n }\n\n if (filter.reject && filter.reject.some((opcode) => entry.opcode === opcode)) {\n accepted = undefined;\n break;\n }\n\n if (filter.accept && !filter.accept.some((opcode) => entry.opcode === opcode)) {\n accepted = undefined;\n break;\n }\n\n if (undefined === filter.geometry)\n continue;\n\n let entityType;\n if (filter.geometry.curves && !(filter.geometry.surfaces || filter.geometry.solids))\n entityType = ElementGeometry.isCurve(entry) ? BRepEntity.Type.Wire : undefined; // skip surface/solid opcodes...\n else\n entityType = ElementGeometry.getBRepEntityType(entry);\n\n switch (entityType) {\n case BRepEntity.Type.Wire:\n if (!filter.geometry.curves)\n accepted = undefined;\n break;\n case BRepEntity.Type.Sheet:\n if (!filter.geometry.surfaces)\n accepted = undefined;\n break;\n case BRepEntity.Type.Solid:\n if (!filter.geometry.solids)\n accepted = undefined;\n break;\n default:\n accepted = undefined;\n break;\n }\n\n if (undefined === accepted)\n break;\n }\n }\n };\n\n const requestProps: ElementGeometryRequest = {\n onGeometry,\n elementId,\n };\n\n if (IModelStatus.Success !== this.iModel.elementGeometryRequest(requestProps))\n return undefined;\n\n return accepted;\n }\n\n public async updateProjectExtents(extents: Range3dProps): Promise<void> {\n const newExtents = new Range3d();\n newExtents.setFromJSON(extents);\n\n if (newExtents.isNull)\n throw new IModelError(DbResult.BE_SQLITE_ERROR, \"Invalid project extents\");\n\n await this.iModel.acquireSchemaLock();\n\n this.iModel.updateProjectExtents(newExtents);\n\n // Set source from calculated to user so connectors preserve the change.\n const unitsProps: FilePropertyProps = { name: \"Units\", namespace: \"dgn_Db\" };\n const unitsStr = this.iModel.queryFilePropertyString(unitsProps);\n\n if (undefined !== unitsStr) {\n const unitsVal = JSON.parse(unitsStr);\n const calculated = 1;\n\n if (calculated !== unitsVal.extentsSource) {\n unitsVal.extentsSource = calculated;\n this.iModel.saveFileProperty(unitsProps, JSON.stringify(unitsVal));\n }\n }\n }\n\n public async updateEcefLocation(ecefLocation: EcefLocationProps): Promise<void> {\n await this.iModel.acquireSchemaLock();\n\n // Clear GCS that caller already determined was invalid...\n this.iModel.deleteFileProperty({ name: \"DgnGCS\", namespace: \"dgn_Db\" });\n\n const newEcefLocation = new EcefLocation(ecefLocation);\n this.iModel.updateEcefLocation(newEcefLocation);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"EditBuiltInCommand.js","sourceRoot":"","sources":["../../src/EditBuiltInCommand.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA4F;AAC5F,wDAA0H;AAE1H,oDAAgR;AAChR,wDAAkH;AAClH,+CAA4C;AAE5C;;GAEG;AACH,MAAa,wBAAyB,SAAQ,yBAAW;IAGR;IAFxC,MAAM,CAAU,SAAS,GAAG,mCAAmB,CAAC,oBAAoB,CAAC;IAE5E,YAAmB,MAAgB,EAAY,IAAY;QAAI,KAAK,CAAC,MAAM,CAAC,CAAC;QAA9B,SAAI,GAAJ,IAAI,CAAQ;IAAmB,CAAC;IAE/D,KAAK,CAAC,OAAO,KAAK,OAAO,wBAAwB,CAAC,SAAS,CAAC,CAAC,CAAC;IAEvE,KAAK,CAAC,iBAAiB,CAAC,UAAkB;QAC/C,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC;IACrD,CAAC;IAEM,KAAK,CAAC,oBAAoB,CAAC,UAAkB;QAClD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAAC;IACxD,CAAC;IAEM,KAAK,CAAC,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AAG,IAAI,CAAC,MAAM,CAAC,uBAAuB,CAAC,UAAU,CAAC,CAAC;QAEjE,IAAI,SAAS,KAAK,QAAQ,EAAE,CAAC;YAC3B,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;YACtC,MAAM,UAAU,GAAG,CAAC,CAAC;YAErB,IAAI,UAAU,KAAK,QAAQ,CAAC,aAAa,EAAE,CAAC;gBAC1C,QAAQ,CAAC,aAAa,GAAG,UAAU,CAAC;gBACpC,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC;YACrE,CAAC;QACH,CAAC;IACH,CAAC;IAEM,KAAK,CAAC,kBAAkB,CAAC,YAA+B;QAC7D,MAAM,IAAI,CAAC,MAAM,CAAC,iBAAiB,EAAE,CAAC;QAEtC,0DAA0D;QAC1D,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,CAAC;QAExE,MAAM,eAAe,GAAG,IAAI,0BAAY,CAAC,YAAY,CAAC,CAAC;QACvD,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC,eAAe,CAAC,CAAC;IAClD,CAAC;;AA9MH,4DA+MC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Editing\r\n */\r\n\r\nimport { CompressedId64Set, DbResult, Id64String, IModelStatus } from \"@itwin/core-bentley\";\r\nimport { Matrix3d, Matrix3dProps, Point3d, Range3d, Range3dProps, Transform, TransformProps } from \"@itwin/core-geometry\";\r\nimport { GeometricElement, IModelDb } from \"@itwin/core-backend\";\r\nimport { BRepEntity, EcefLocation, EcefLocationProps, ElementGeometry, ElementGeometryBuilderParams, ElementGeometryFunction, ElementGeometryInfo, ElementGeometryRequest, FilePropertyProps, GeometricElementProps, GeometryPartProps, IModelError } from \"@itwin/core-common\";\r\nimport { BasicManipulationCommandIpc, editorBuiltInCmdIds, FlatBufferGeometryFilter } from \"@itwin/editor-common\";\r\nimport { EditCommand } from \"./EditCommand\";\r\n\r\n/** Implementation for a EditCommand command that provides basic creation and modification operations.\r\n * @beta\r\n */\r\nexport class BasicManipulationCommand extends EditCommand implements BasicManipulationCommandIpc {\r\n public static override commandId = editorBuiltInCmdIds.cmdBasicManipulation;\r\n\r\n public constructor(iModel: IModelDb, protected _str: string) { super(iModel); }\r\n\r\n public override async onStart() { return BasicManipulationCommand.commandId; }\r\n\r\n public async addAllowedChannel(channelKey: string): Promise<void> {\r\n this.iModel.channels.addAllowedChannel(channelKey);\r\n }\r\n\r\n public async removeAllowedChannel(channelKey: string): Promise<void> {\r\n this.iModel.channels.removeAllowedChannel(channelKey);\r\n }\r\n\r\n public async deleteElements(ids: CompressedId64Set): Promise<IModelStatus> {\r\n const idSet = CompressedId64Set.decompressSet(ids);\r\n await this.iModel.locks.acquireLocks({ exclusive: idSet });\r\n\r\n for (const id of idSet)\r\n this.iModel.elements.deleteElement(id);\r\n\r\n return IModelStatus.Success;\r\n }\r\n\r\n public async transformPlacement(ids: CompressedId64Set, transProps: TransformProps): Promise<IModelStatus> {\r\n const idSet = CompressedId64Set.decompressSet(ids);\r\n await this.iModel.locks.acquireLocks({ exclusive: idSet });\r\n\r\n const transform = Transform.fromJSON(transProps);\r\n\r\n for (const id of idSet) {\r\n const element = this.iModel.elements.getElement<GeometricElement>(id);\r\n\r\n if (!element.placement.isValid)\r\n continue; // Ignore assembly parents w/o geometry, etc...\r\n\r\n element.placement.multiplyTransform(transform);\r\n this.iModel.elements.updateElement(element.toJSON());\r\n }\r\n\r\n return IModelStatus.Success;\r\n }\r\n\r\n public async rotatePlacement(ids: CompressedId64Set, matrixProps: Matrix3dProps, aboutCenter: boolean): Promise<IModelStatus> {\r\n const idSet = CompressedId64Set.decompressSet(ids);\r\n await this.iModel.locks.acquireLocks({ exclusive: idSet });\r\n\r\n const matrix = Matrix3d.fromJSON(matrixProps);\r\n\r\n for (const id of idSet) {\r\n const element = this.iModel.elements.getElement<GeometricElement>(id);\r\n\r\n if (!element.placement.isValid)\r\n continue; // Ignore assembly parents w/o geometry, etc...\r\n\r\n const fixedPoint = aboutCenter ? element.placement.calculateRange().center : Point3d.createFrom(element.placement.origin);\r\n const transform = Transform.createFixedPointAndMatrix(fixedPoint, matrix);\r\n\r\n element.placement.multiplyTransform(transform);\r\n this.iModel.elements.updateElement(element.toJSON());\r\n }\r\n\r\n return IModelStatus.Success;\r\n }\r\n\r\n public async insertGeometricElement(props: GeometricElementProps): Promise<Id64String> {\r\n await this.iModel.locks.acquireLocks({ shared: props.model });\r\n\r\n return this.iModel.elements.insertElement(props);\r\n }\r\n\r\n public async insertGeometryPart(props: GeometryPartProps): Promise<Id64String> {\r\n await this.iModel.locks.acquireLocks({ shared: props.model });\r\n\r\n return this.iModel.elements.insertElement(props);\r\n }\r\n\r\n public async updateGeometricElement(propsOrId: GeometricElementProps | Id64String, data?: ElementGeometryBuilderParams): Promise<void> {\r\n let props: GeometricElementProps;\r\n if (typeof propsOrId === \"string\") {\r\n if (undefined === data)\r\n throw new IModelError(DbResult.BE_SQLITE_ERROR, \"Flatbuffer data required for update by id\");\r\n props = this.iModel.elements.getElementProps<GeometricElementProps>(propsOrId);\r\n } else {\r\n props = propsOrId;\r\n }\r\n\r\n if (undefined === props.id)\r\n throw new IModelError(DbResult.BE_SQLITE_ERROR, \"Element id required for update\");\r\n\r\n await this.iModel.locks.acquireLocks({ exclusive: props.id });\r\n\r\n if (undefined !== data)\r\n props.elementGeometryBuilderParams = { entryArray: data.entryArray, viewIndependent: data.viewIndependent };\r\n\r\n this.iModel.elements.updateElement(props);\r\n }\r\n\r\n public async requestElementGeometry(elementId: Id64String, filter?: FlatBufferGeometryFilter): Promise<ElementGeometryInfo | undefined> {\r\n let accepted: ElementGeometryInfo | undefined;\r\n\r\n const onGeometry: ElementGeometryFunction = (info: ElementGeometryInfo): void => {\r\n accepted = info;\r\n\r\n if (undefined !== filter) {\r\n let numDisplayable = 0;\r\n\r\n for (const entry of info.entryArray) {\r\n if (!ElementGeometry.isDisplayableEntry(entry))\r\n continue;\r\n\r\n numDisplayable++;\r\n if (filter.maxDisplayable && numDisplayable > filter.maxDisplayable) {\r\n accepted = undefined;\r\n break;\r\n }\r\n\r\n if (filter.reject && filter.reject.some((opcode) => entry.opcode === opcode)) {\r\n accepted = undefined;\r\n break;\r\n }\r\n\r\n if (filter.accept && !filter.accept.some((opcode) => entry.opcode === opcode)) {\r\n accepted = undefined;\r\n break;\r\n }\r\n\r\n if (undefined === filter.geometry)\r\n continue;\r\n\r\n let entityType;\r\n if (filter.geometry.curves && !(filter.geometry.surfaces || filter.geometry.solids))\r\n entityType = ElementGeometry.isCurve(entry) ? BRepEntity.Type.Wire : undefined; // skip surface/solid opcodes...\r\n else\r\n entityType = ElementGeometry.getBRepEntityType(entry);\r\n\r\n switch (entityType) {\r\n case BRepEntity.Type.Wire:\r\n if (!filter.geometry.curves)\r\n accepted = undefined;\r\n break;\r\n case BRepEntity.Type.Sheet:\r\n if (!filter.geometry.surfaces)\r\n accepted = undefined;\r\n break;\r\n case BRepEntity.Type.Solid:\r\n if (!filter.geometry.solids)\r\n accepted = undefined;\r\n break;\r\n default:\r\n accepted = undefined;\r\n break;\r\n }\r\n\r\n if (undefined === accepted)\r\n break;\r\n }\r\n }\r\n };\r\n\r\n const requestProps: ElementGeometryRequest = {\r\n onGeometry,\r\n elementId,\r\n };\r\n\r\n if (IModelStatus.Success !== this.iModel.elementGeometryRequest(requestProps))\r\n return undefined;\r\n\r\n return accepted;\r\n }\r\n\r\n public async updateProjectExtents(extents: Range3dProps): Promise<void> {\r\n const newExtents = new Range3d();\r\n newExtents.setFromJSON(extents);\r\n\r\n if (newExtents.isNull)\r\n throw new IModelError(DbResult.BE_SQLITE_ERROR, \"Invalid project extents\");\r\n\r\n await this.iModel.acquireSchemaLock();\r\n\r\n this.iModel.updateProjectExtents(newExtents);\r\n\r\n // Set source from calculated to user so connectors preserve the change.\r\n const unitsProps: FilePropertyProps = { name: \"Units\", namespace: \"dgn_Db\" };\r\n const unitsStr = this.iModel.queryFilePropertyString(unitsProps);\r\n\r\n if (undefined !== unitsStr) {\r\n const unitsVal = JSON.parse(unitsStr);\r\n const calculated = 1;\r\n\r\n if (calculated !== unitsVal.extentsSource) {\r\n unitsVal.extentsSource = calculated;\r\n this.iModel.saveFileProperty(unitsProps, JSON.stringify(unitsVal));\r\n }\r\n }\r\n }\r\n\r\n public async updateEcefLocation(ecefLocation: EcefLocationProps): Promise<void> {\r\n await this.iModel.acquireSchemaLock();\r\n\r\n // Clear GCS that caller already determined was invalid...\r\n this.iModel.deleteFileProperty({ name: \"DgnGCS\", namespace: \"dgn_Db\" });\r\n\r\n const newEcefLocation = new EcefLocation(ecefLocation);\r\n this.iModel.updateEcefLocation(newEcefLocation);\r\n }\r\n}\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditCommand.js","sourceRoot":"","sources":["../../src/EditCommand.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAAmD;AACnD,sDAAoE;AACpE,oDAA+D;AAC/D,wDAAmF;AAKnF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAa,WAAW;IACtB,2GAA2G;IACpG,MAAM,CAAC,SAAS,GAAG,EAAE,CAAC;IACtB,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC;IAEhC,8CAA8C;IAC9B,MAAM,CAAW;IAEjC,YAAmB,MAAgB,EAAE,GAAG,KAAY;QAClD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IACD,IAAW,IAAI;QACb,OAAO,IAAI,CAAC,WAA8B,CAAC;IAC7C,CAAC;IAEM,K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,MAAM,CAAC,QAAQ,CAAC,WAA4B;QACjD,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC;YACzB,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;YAC3B,IAAI,CAAC,sBAAO,CAAC,OAAO;gBAClB,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;YACnD,gBAAgB,CAAC,QAAQ,EAAE,CAAC;QAC9B,CAAC;QACD,IAAI,WAAW,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC;YACpC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;IAC1D,CAAC;IAED;;;OAGG;IACI,MAAM,CAAC,cAAc,CAAC,SAAc;QACzC,IAAI,QAAQ,GAAG,KAAK,CAAC;QACrB,KAAK,MAAM,UAAU,IAAI,SAAS,EAAE,CAAC,CAAE,mCAAmC;YACxE,MAAM,OAAO,GAAG,SAAS,CAAC,UAAU,CAAC,CAAC;YACtC,IAAI,OAAO,CAAC,SAAS,YAAY,WAAW,EAAE,CAAC;gBAC7C,QAAQ,GAAG,IAAI,CAAC;gBAChB,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;YACzB,CAAC;QACH,CAAC;QACD,IAAI,CAAC,QAAQ;YACX,MAAM,IAAI,KAAK,CAAC,4FAA4F,CAAC,CAAC;IAClH,CAAC;;AAtEH,4CAuEC","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 Editing\n */\n\nimport { IModelStatus } from \"@itwin/core-bentley\";\nimport { IModelDb, IpcHandler, IpcHost } from \"@itwin/core-backend\";\nimport { BackendError, IModelError } from \"@itwin/core-common\";\nimport { EditCommandIpc, EditorIpc, editorIpcStrings } from \"@itwin/editor-common\";\n\n/** @beta */\nexport type EditCommandType = typeof EditCommand;\n\n/**\n * An EditCommand performs an editing action on the backend.\n * Any writes to the iModel in an editing session should be done from an EditCommand:\n * - All changes to an iModel are made within a transaction (Txn).\n * - Calling SaveChanges ends the current Txn and starts a new one.\n * - Using EditCommand ensures all of the changes in a Txn are from the same source, as only one EditCommand may be active at a time.\n * - Because there is currently no way to enforce this, it is important that all applications follow this rule.\n * EditCommands are usually paired with and driven by EditTools on the frontend that can either be interactive tools or immediate tools.\n * Interactive EditTools:\n * - Can be a [PrimitiveTool]($frontend).\n * - Can be an [InputCollector]($frontend) in special cases such as [EditManipulator.HandleTool]($frontend).\n * - Should not be a [ViewTool]($frontend), these should never write changes to the iModel.\n * Immediate EditTools:\n * - As direct subclasses of [Tool]($frontend) that perform their function without further input or becoming the active tool,\n * they potentially leave the current [PrimitiveTool]($frontend) in an invalid state.\n * - To avoid issues, immediate tools that start an EditCommand must call [ToolAdmin.restartPrimitiveTool]($frontend) when they complete.\n * EditCommands have a *commandId* that uniquely identifies them, so they can be found via a lookup in the [[EditCommandAdmin]].\n * Each EditCommand must be registered in the [[EditCommandAdmin]] with [[EditCommandAdmin.register]] or [[EditCommandAdmin.registerModule]].\n * Every time an EditCommand runs, a new instance of (a subclass of) this class is created.\n * @see [[BasicManipulationCommand]] for an example EditCommand.\n * @beta\n */\nexport class EditCommand implements EditCommandIpc {\n /** The unique string that identifies this EditCommand class. This must be overridden in every subclass. */\n public static commandId = \"\";\n public static version = \"1.0.0\";\n\n /** The iModel this EditCommand may modify. */\n public readonly iModel: IModelDb;\n\n public constructor(iModel: IModelDb, ..._args: any[]) {\n this.iModel = iModel;\n }\n public get ctor(): EditCommandType {\n return this.constructor as EditCommandType;\n }\n\n public async onStart(): Promise<any> { }\n\n public async ping(): Promise<{ commandId: string, version: string, [propName: string]: any }> {\n return { version: this.ctor.version, commandId: this.ctor.commandId };\n }\n\n // This is only temporary to find subclasses that used to implement this method. It was made async and renamed `requestFinish`.\n private onFinish() { }\n\n /**\n * Called when another EditCommand wishes to become the active EditCommand.\n * Subclasses should complete and save their work as soon as possible and then return \"done\".\n * If it is not currently possible to finish, return any string other than \"done\" and the other EditCommand will have to wait and retry,\n * potentially showing the returned string to the user.\n */\n public async requestFinish(): Promise<\"done\" | string> { // eslint-disable-line @typescript-eslint/no-redundant-type-constituents\n this.onFinish(); // TODO: temporary, remove\n return \"done\";\n }\n}\n\nclass EditorAppHandler extends IpcHandler implements EditorIpc {\n public get channelName() { return editorIpcStrings.channel; }\n\n public async startCommand(commandId: string, iModelKey: string, ...args: any[]) {\n await EditCommandAdmin.finishCommand();\n if (commandId === \"\") // just kill active command, don't start another\n return;\n\n const commandClass = EditCommandAdmin.commands.get(commandId);\n if (undefined === commandClass)\n throw new IModelError(IModelStatus.NotRegistered, `Command not registered [${commandId}]`);\n\n return EditCommandAdmin.runCommand(new commandClass(IModelDb.findByKey(iModelKey), ...args));\n }\n\n public async callMethod(methodName: string, ...args: any[]) {\n const cmd = EditCommandAdmin.activeCommand;\n if (!cmd)\n throw new IModelError(IModelStatus.NoActiveCommand, `No active command`);\n\n const func = (cmd as any)[methodName];\n if (typeof func !== \"function\")\n throw new IModelError(IModelStatus.FunctionNotFound, `Method ${methodName} not found on ${cmd.ctor.commandId}`);\n\n return func.call(cmd, ...args);\n }\n}\n\n/**\n * EditCommandAdmin holds a mapping between commandIds and their corresponding [[EditCommand]] class. This provides the mechanism to\n * run EditCommands by commandId.\n * It also keeps track of the currently active EditCommand. When a new EditCommand attempts to start, the active EditCommand\n * is requested to finish, and the new EditCommand cannot start until it does.\n * @beta\n */\nexport class EditCommandAdmin {\n public static readonly commands = new Map<string, EditCommandType>();\n\n private static _activeCommand?: EditCommand;\n private static _isInitialized = false;\n public static get activeCommand() { return this._activeCommand; }\n\n /** If any command is currently active, wait for it to finish.\n * Afterward, no command will be active.\n * This method is invoked by [[runCommand]] before starting a new command.\n * @throws BackendError if the command fails to finish.\n */\n public static async finishCommand() {\n if (this._activeCommand) {\n const finished = await this._activeCommand.requestFinish();\n if (\"done\" !== finished)\n throw new BackendError(IModelStatus.ServerTimeout, editorIpcStrings.commandBusy, finished);\n }\n this._activeCommand = undefined;\n }\n\n /** Start running the specified command.\n * The new command will not begin running until the currently-active command (if any) finishes.\n * Afterward, the new command becomes the active command.\n * @throws BackendError if the currently-active command fails to finish.\n */\n public static async runCommand(cmd: EditCommand): Promise<any> {\n await this.finishCommand();\n this._activeCommand = cmd;\n return cmd.onStart();\n }\n\n /**\n * Un-register a previously registered EditCommand class.\n * @param commandId the commandId of a previously registered EditCommand to unRegister.\n */\n public static unRegister(commandId: string) {\n this.commands.delete(commandId);\n }\n\n /**\n * Register an EditCommand class. This establishes a connection between the commandId of the class and the class itself.\n * @param commandType the subclass of Tool to register.\n */\n public static register(commandType: EditCommandType) {\n if (!this._isInitialized) {\n this._isInitialized = true;\n if (!IpcHost.isValid)\n throw new Error(\"Edit Commands require IpcHost\");\n EditorAppHandler.register();\n }\n if (commandType.commandId.length !== 0)\n this.commands.set(commandType.commandId, commandType);\n }\n\n /**\n * Register all the EditCommand classes found in a module.\n * @param modelObj the module to search for subclasses of EditCommand.\n */\n public static registerModule(moduleObj: any) {\n let foundOne = false;\n for (const thisMember in moduleObj) { // eslint-disable-line guard-for-in\n const thisCmd = moduleObj[thisMember];\n if (thisCmd.prototype instanceof EditCommand) {\n foundOne = true;\n this.register(thisCmd);\n }\n }\n if (!foundOne)\n throw new Error(`no EditCommands found - are you sure this is a module? Maybe you meant to call \"register\"?`);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"EditCommand.js","sourceRoot":"","sources":["../../src/EditCommand.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAAmD;AACnD,sDAAoE;AACpE,oDAA+D;AAC/D,wDAAmF;AAKnF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAa,WAAW;IACtB,2GAA2G;IACpG,MAAM,CAAC,SAAS,GAAG,EAAE,CAAC;IACtB,MAAM,CAAC,OAAO,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,cAAc,GAAG,GAAG,CAAC;QAC1B,OAAO,GAAG,CAAC,OAAO,EAAE,CAAC;IACvB,CAAC;IAED;;;OAGG;IACI,MAAM,CAAC,UAAU,CAAC,SAAiB;QACxC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IAClC,CAAC;IAED;;;OAGG;IACI,MAAM,CAAC,QAAQ,CAAC,WAA4B;QACjD,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC;YACzB,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;YAC3B,IAAI,CAAC,sBAAO,CAAC,OAAO;gBAClB,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;YACnD,gBAAgB,CAAC,QAAQ,EAAE,CAAC;QAC9B,CAAC;QACD,IAAI,WAAW,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC;YACpC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;IAC1D,CAAC;IAED;;;OAGG;IACI,MAAM,CAAC,cAAc,CAAC,SAAc;QACzC,IAAI,QAAQ,GAAG,KAAK,CAAC;QACrB,KAAK,MAAM,UAAU,IAAI,SAAS,EAAE,CAAC,CAAE,mCAAmC;YACxE,MAAM,OAAO,GAAG,SAAS,CAAC,UAAU,CAAC,CAAC;YACtC,IAAI,OAAO,CAAC,SAAS,YAAY,WAAW,EAAE,CAAC;gBAC7C,QAAQ,GAAG,IAAI,CAAC;gBAChB,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;YACzB,CAAC;QACH,CAAC;QACD,IAAI,CAAC,QAAQ;YACX,MAAM,IAAI,KAAK,CAAC,4FAA4F,CAAC,CAAC;IAClH,CAAC;;AAtEH,4CAuEC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Editing\r\n */\r\n\r\nimport { IModelStatus } from \"@itwin/core-bentley\";\r\nimport { IModelDb, IpcHandler, IpcHost } from \"@itwin/core-backend\";\r\nimport { BackendError, IModelError } from \"@itwin/core-common\";\r\nimport { EditCommandIpc, EditorIpc, editorIpcStrings } from \"@itwin/editor-common\";\r\n\r\n/** @beta */\r\nexport type EditCommandType = typeof EditCommand;\r\n\r\n/**\r\n * An EditCommand performs an editing action on the backend.\r\n * Any writes to the iModel in an editing session should be done from an EditCommand:\r\n * - All changes to an iModel are made within a transaction (Txn).\r\n * - Calling SaveChanges ends the current Txn and starts a new one.\r\n * - Using EditCommand ensures all of the changes in a Txn are from the same source, as only one EditCommand may be active at a time.\r\n * - Because there is currently no way to enforce this, it is important that all applications follow this rule.\r\n * EditCommands are usually paired with and driven by EditTools on the frontend that can either be interactive tools or immediate tools.\r\n * Interactive EditTools:\r\n * - Can be a [PrimitiveTool]($frontend).\r\n * - Can be an [InputCollector]($frontend) in special cases such as [EditManipulator.HandleTool]($frontend).\r\n * - Should not be a [ViewTool]($frontend), these should never write changes to the iModel.\r\n * Immediate EditTools:\r\n * - As direct subclasses of [Tool]($frontend) that perform their function without further input or becoming the active tool,\r\n * they potentially leave the current [PrimitiveTool]($frontend) in an invalid state.\r\n * - To avoid issues, immediate tools that start an EditCommand must call [ToolAdmin.restartPrimitiveTool]($frontend) when they complete.\r\n * EditCommands have a *commandId* that uniquely identifies them, so they can be found via a lookup in the [[EditCommandAdmin]].\r\n * Each EditCommand must be registered in the [[EditCommandAdmin]] with [[EditCommandAdmin.register]] or [[EditCommandAdmin.registerModule]].\r\n * Every time an EditCommand runs, a new instance of (a subclass of) this class is created.\r\n * @see [[BasicManipulationCommand]] for an example EditCommand.\r\n * @beta\r\n */\r\nexport class EditCommand implements EditCommandIpc {\r\n /** The unique string that identifies this EditCommand class. This must be overridden in every subclass. */\r\n public static commandId = \"\";\r\n public static version = \"1.0.0\";\r\n\r\n /** The iModel this EditCommand may modify. */\r\n public readonly iModel: IModelDb;\r\n\r\n public constructor(iModel: IModelDb, ..._args: any[]) {\r\n this.iModel = iModel;\r\n }\r\n public get ctor(): EditCommandType {\r\n return this.constructor as EditCommandType;\r\n }\r\n\r\n public async onStart(): Promise<any> { }\r\n\r\n public async ping(): Promise<{ commandId: string, version: string, [propName: string]: any }> {\r\n return { version: this.ctor.version, commandId: this.ctor.commandId };\r\n }\r\n\r\n // This is only temporary to find subclasses that used to implement this method. It was made async and renamed `requestFinish`.\r\n private onFinish() { }\r\n\r\n /**\r\n * Called when another EditCommand wishes to become the active EditCommand.\r\n * Subclasses should complete and save their work as soon as possible and then return \"done\".\r\n * If it is not currently possible to finish, return any string other than \"done\" and the other EditCommand will have to wait and retry,\r\n * potentially showing the returned string to the user.\r\n */\r\n public async requestFinish(): Promise<\"done\" | string> { // eslint-disable-line @typescript-eslint/no-redundant-type-constituents\r\n this.onFinish(); // TODO: temporary, remove\r\n return \"done\";\r\n }\r\n}\r\n\r\nclass EditorAppHandler extends IpcHandler implements EditorIpc {\r\n public get channelName() { return editorIpcStrings.channel; }\r\n\r\n public async startCommand(commandId: string, iModelKey: string, ...args: any[]) {\r\n await EditCommandAdmin.finishCommand();\r\n if (commandId === \"\") // just kill active command, don't start another\r\n return;\r\n\r\n const commandClass = EditCommandAdmin.commands.get(commandId);\r\n if (undefined === commandClass)\r\n throw new IModelError(IModelStatus.NotRegistered, `Command not registered [${commandId}]`);\r\n\r\n return EditCommandAdmin.runCommand(new commandClass(IModelDb.findByKey(iModelKey), ...args));\r\n }\r\n\r\n public async callMethod(methodName: string, ...args: any[]) {\r\n const cmd = EditCommandAdmin.activeCommand;\r\n if (!cmd)\r\n throw new IModelError(IModelStatus.NoActiveCommand, `No active command`);\r\n\r\n const func = (cmd as any)[methodName];\r\n if (typeof func !== \"function\")\r\n throw new IModelError(IModelStatus.FunctionNotFound, `Method ${methodName} not found on ${cmd.ctor.commandId}`);\r\n\r\n return func.call(cmd, ...args);\r\n }\r\n}\r\n\r\n/**\r\n * EditCommandAdmin holds a mapping between commandIds and their corresponding [[EditCommand]] class. This provides the mechanism to\r\n * run EditCommands by commandId.\r\n * It also keeps track of the currently active EditCommand. When a new EditCommand attempts to start, the active EditCommand\r\n * is requested to finish, and the new EditCommand cannot start until it does.\r\n * @beta\r\n */\r\nexport class EditCommandAdmin {\r\n public static readonly commands = new Map<string, EditCommandType>();\r\n\r\n private static _activeCommand?: EditCommand;\r\n private static _isInitialized = false;\r\n public static get activeCommand() { return this._activeCommand; }\r\n\r\n /** If any command is currently active, wait for it to finish.\r\n * Afterward, no command will be active.\r\n * This method is invoked by [[runCommand]] before starting a new command.\r\n * @throws BackendError if the command fails to finish.\r\n */\r\n public static async finishCommand() {\r\n if (this._activeCommand) {\r\n const finished = await this._activeCommand.requestFinish();\r\n if (\"done\" !== finished)\r\n throw new BackendError(IModelStatus.ServerTimeout, editorIpcStrings.commandBusy, finished);\r\n }\r\n this._activeCommand = undefined;\r\n }\r\n\r\n /** Start running the specified command.\r\n * The new command will not begin running until the currently-active command (if any) finishes.\r\n * Afterward, the new command becomes the active command.\r\n * @throws BackendError if the currently-active command fails to finish.\r\n */\r\n public static async runCommand(cmd: EditCommand): Promise<any> {\r\n await this.finishCommand();\r\n this._activeCommand = cmd;\r\n return cmd.onStart();\r\n }\r\n\r\n /**\r\n * Un-register a previously registered EditCommand class.\r\n * @param commandId the commandId of a previously registered EditCommand to unRegister.\r\n */\r\n public static unRegister(commandId: string) {\r\n this.commands.delete(commandId);\r\n }\r\n\r\n /**\r\n * Register an EditCommand class. This establishes a connection between the commandId of the class and the class itself.\r\n * @param commandType the subclass of Tool to register.\r\n */\r\n public static register(commandType: EditCommandType) {\r\n if (!this._isInitialized) {\r\n this._isInitialized = true;\r\n if (!IpcHost.isValid)\r\n throw new Error(\"Edit Commands require IpcHost\");\r\n EditorAppHandler.register();\r\n }\r\n if (commandType.commandId.length !== 0)\r\n this.commands.set(commandType.commandId, commandType);\r\n }\r\n\r\n /**\r\n * Register all the EditCommand classes found in a module.\r\n * @param modelObj the module to search for subclasses of EditCommand.\r\n */\r\n public static registerModule(moduleObj: any) {\r\n let foundOne = false;\r\n for (const thisMember in moduleObj) { // eslint-disable-line guard-for-in\r\n const thisCmd = moduleObj[thisMember];\r\n if (thisCmd.prototype instanceof EditCommand) {\r\n foundOne = true;\r\n this.register(thisCmd);\r\n }\r\n }\r\n if (!foundOne)\r\n throw new Error(`no EditCommands found - are you sure this is a module? Maybe you meant to call \"register\"?`);\r\n }\r\n}\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editor-backend.js","sourceRoot":"","sources":["../../src/editor-backend.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;;+FAG+F;AAC/F,gDAA8B;AAC9B,uDAAqC;AAErC;;GAEG;AAEH;;;GAGG","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*--------------------------------------------------------------------------------------------*/\nexport * from \"./EditCommand\";\nexport * from \"./EditBuiltInCommand\";\n\n/** @docs-package-description\n * The editor-backend package contains backend functionality for editing iModels.\n */\n\n/**\n * @docs-group-description Editing\n * Classes containing functionality for editing iModels on the backend.\n */\n"]}
|
|
1
|
+
{"version":3,"file":"editor-backend.js","sourceRoot":"","sources":["../../src/editor-backend.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;;+FAG+F;AAC/F,gDAA8B;AAC9B,uDAAqC;AAErC;;GAEG;AAEH;;;GAGG","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\nexport * from \"./EditCommand\";\r\nexport * from \"./EditBuiltInCommand\";\r\n\r\n/** @docs-package-description\r\n * The editor-backend package contains backend functionality for editing iModels.\r\n */\r\n\r\n/**\r\n * @docs-group-description Editing\r\n * Classes containing functionality for editing iModels on the backend.\r\n */\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditBuiltInCommand.js","sourceRoot":"","sources":["../../src/EditBuiltInCommand.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAc,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC5F,OAAO,EAAE,QAAQ,EAAiB,OAAO,EAAE,OAAO,EAAgB,SAAS,EAAkB,MAAM,sBAAsB,CAAC;AAE1H,OAAO,EAAE,UAAU,EAAE,YAAY,EAAqB,eAAe,EAAmK,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAChR,OAAO,EAA+B,mBAAmB,EAA4B,MAAM,sBAAsB,CAAC;AAClH,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C;;GAEG;AACH,MAAM,OAAO,wBAAyB,SAAQ,WAAW;IAGR;IAFxC,MAAM,CAAU,SAAS,GAAG,mBAAmB,CAAC,oBAAoB,CAAC;IAE5E,YAAmB,MAAgB,EAAY,IAAY;QAAI,KAAK,CAAC,MAAM,CAAC,CAAC;QAA9B,SAAI,GAAJ,IAAI,CAAQ;IAAmB,CAAC;IAE/D,KAAK,CAAC,OAAO,KAAK,OAAO,wBAAwB,CAAC,SAAS,CAAC,CAAC,CAAC;IAEvE,KAAK,CAAC,iBAAiB,CAAC,UAAkB;QAC/C,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC;IACrD,CAAC;IAEM,KAAK,CAAC,oBAAoB,CAAC,UAAkB;QAClD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAAC;IACxD,CAAC;IAEM,KAAK,CAAC,cAAc,CAAC,GAAsB;QAChD,MAAM,KAAK,GAAG,iBAAiB,CAAC,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K,QAAQ,EAAE,CAAC;YAC3B,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;YACtC,MAAM,UAAU,GAAG,CAAC,CAAC;YAErB,IAAI,UAAU,KAAK,QAAQ,CAAC,aAAa,EAAE,CAAC;gBAC1C,QAAQ,CAAC,aAAa,GAAG,UAAU,CAAC;gBACpC,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC;YACrE,CAAC;QACH,CAAC;IACH,CAAC;IAEM,KAAK,CAAC,kBAAkB,CAAC,YAA+B;QAC7D,MAAM,IAAI,CAAC,MAAM,CAAC,iBAAiB,EAAE,CAAC;QAEtC,0DAA0D;QAC1D,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,CAAC;QAExE,MAAM,eAAe,GAAG,IAAI,YAAY,CAAC,YAAY,CAAC,CAAC;QACvD,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC,eAAe,CAAC,CAAC;IAClD,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 Editing\n */\n\nimport { CompressedId64Set, DbResult, Id64String, IModelStatus } from \"@itwin/core-bentley\";\nimport { Matrix3d, Matrix3dProps, Point3d, Range3d, Range3dProps, Transform, TransformProps } from \"@itwin/core-geometry\";\nimport { GeometricElement, IModelDb } from \"@itwin/core-backend\";\nimport { BRepEntity, EcefLocation, EcefLocationProps, ElementGeometry, ElementGeometryBuilderParams, ElementGeometryFunction, ElementGeometryInfo, ElementGeometryRequest, FilePropertyProps, GeometricElementProps, GeometryPartProps, IModelError } from \"@itwin/core-common\";\nimport { BasicManipulationCommandIpc, editorBuiltInCmdIds, FlatBufferGeometryFilter } from \"@itwin/editor-common\";\nimport { EditCommand } from \"./EditCommand\";\n\n/** Implementation for a EditCommand command that provides basic creation and modification operations.\n * @beta\n */\nexport class BasicManipulationCommand extends EditCommand implements BasicManipulationCommandIpc {\n public static override commandId = editorBuiltInCmdIds.cmdBasicManipulation;\n\n public constructor(iModel: IModelDb, protected _str: string) { super(iModel); }\n\n public override async onStart() { return BasicManipulationCommand.commandId; }\n\n public async addAllowedChannel(channelKey: string): Promise<void> {\n this.iModel.channels.addAllowedChannel(channelKey);\n }\n\n public async removeAllowedChannel(channelKey: string): Promise<void> {\n this.iModel.channels.removeAllowedChannel(channelKey);\n }\n\n public async deleteElements(ids: CompressedId64Set): Promise<IModelStatus> {\n const idSet = CompressedId64Set.decompressSet(ids);\n await this.iModel.locks.acquireLocks({ exclusive: idSet });\n\n for (const id of idSet)\n this.iModel.elements.deleteElement(id);\n\n return IModelStatus.Success;\n }\n\n public async transformPlacement(ids: CompressedId64Set, transProps: TransformProps): Promise<IModelStatus> {\n const idSet = CompressedId64Set.decompressSet(ids);\n await this.iModel.locks.acquireLocks({ exclusive: idSet });\n\n const transform = Transform.fromJSON(transProps);\n\n for (const id of idSet) {\n const element = this.iModel.elements.getElement<GeometricElement>(id);\n\n if (!element.placement.isValid)\n continue; // Ignore assembly parents w/o geometry, etc...\n\n element.placement.multiplyTransform(transform);\n this.iModel.elements.updateElement(element.toJSON());\n }\n\n return IModelStatus.Success;\n }\n\n public async rotatePlacement(ids: CompressedId64Set, matrixProps: Matrix3dProps, aboutCenter: boolean): Promise<IModelStatus> {\n const idSet = CompressedId64Set.decompressSet(ids);\n await this.iModel.locks.acquireLocks({ exclusive: idSet });\n\n const matrix = Matrix3d.fromJSON(matrixProps);\n\n for (const id of idSet) {\n const element = this.iModel.elements.getElement<GeometricElement>(id);\n\n if (!element.placement.isValid)\n continue; // Ignore assembly parents w/o geometry, etc...\n\n const fixedPoint = aboutCenter ? element.placement.calculateRange().center : Point3d.createFrom(element.placement.origin);\n const transform = Transform.createFixedPointAndMatrix(fixedPoint, matrix);\n\n element.placement.multiplyTransform(transform);\n this.iModel.elements.updateElement(element.toJSON());\n }\n\n return IModelStatus.Success;\n }\n\n public async insertGeometricElement(props: GeometricElementProps): Promise<Id64String> {\n await this.iModel.locks.acquireLocks({ shared: props.model });\n\n return this.iModel.elements.insertElement(props);\n }\n\n public async insertGeometryPart(props: GeometryPartProps): Promise<Id64String> {\n await this.iModel.locks.acquireLocks({ shared: props.model });\n\n return this.iModel.elements.insertElement(props);\n }\n\n public async updateGeometricElement(propsOrId: GeometricElementProps | Id64String, data?: ElementGeometryBuilderParams): Promise<void> {\n let props: GeometricElementProps;\n if (typeof propsOrId === \"string\") {\n if (undefined === data)\n throw new IModelError(DbResult.BE_SQLITE_ERROR, \"Flatbuffer data required for update by id\");\n props = this.iModel.elements.getElementProps<GeometricElementProps>(propsOrId);\n } else {\n props = propsOrId;\n }\n\n if (undefined === props.id)\n throw new IModelError(DbResult.BE_SQLITE_ERROR, \"Element id required for update\");\n\n await this.iModel.locks.acquireLocks({ exclusive: props.id });\n\n if (undefined !== data)\n props.elementGeometryBuilderParams = { entryArray: data.entryArray, viewIndependent: data.viewIndependent };\n\n this.iModel.elements.updateElement(props);\n }\n\n public async requestElementGeometry(elementId: Id64String, filter?: FlatBufferGeometryFilter): Promise<ElementGeometryInfo | undefined> {\n let accepted: ElementGeometryInfo | undefined;\n\n const onGeometry: ElementGeometryFunction = (info: ElementGeometryInfo): void => {\n accepted = info;\n\n if (undefined !== filter) {\n let numDisplayable = 0;\n\n for (const entry of info.entryArray) {\n if (!ElementGeometry.isDisplayableEntry(entry))\n continue;\n\n numDisplayable++;\n if (filter.maxDisplayable && numDisplayable > filter.maxDisplayable) {\n accepted = undefined;\n break;\n }\n\n if (filter.reject && filter.reject.some((opcode) => entry.opcode === opcode)) {\n accepted = undefined;\n break;\n }\n\n if (filter.accept && !filter.accept.some((opcode) => entry.opcode === opcode)) {\n accepted = undefined;\n break;\n }\n\n if (undefined === filter.geometry)\n continue;\n\n let entityType;\n if (filter.geometry.curves && !(filter.geometry.surfaces || filter.geometry.solids))\n entityType = ElementGeometry.isCurve(entry) ? BRepEntity.Type.Wire : undefined; // skip surface/solid opcodes...\n else\n entityType = ElementGeometry.getBRepEntityType(entry);\n\n switch (entityType) {\n case BRepEntity.Type.Wire:\n if (!filter.geometry.curves)\n accepted = undefined;\n break;\n case BRepEntity.Type.Sheet:\n if (!filter.geometry.surfaces)\n accepted = undefined;\n break;\n case BRepEntity.Type.Solid:\n if (!filter.geometry.solids)\n accepted = undefined;\n break;\n default:\n accepted = undefined;\n break;\n }\n\n if (undefined === accepted)\n break;\n }\n }\n };\n\n const requestProps: ElementGeometryRequest = {\n onGeometry,\n elementId,\n };\n\n if (IModelStatus.Success !== this.iModel.elementGeometryRequest(requestProps))\n return undefined;\n\n return accepted;\n }\n\n public async updateProjectExtents(extents: Range3dProps): Promise<void> {\n const newExtents = new Range3d();\n newExtents.setFromJSON(extents);\n\n if (newExtents.isNull)\n throw new IModelError(DbResult.BE_SQLITE_ERROR, \"Invalid project extents\");\n\n await this.iModel.acquireSchemaLock();\n\n this.iModel.updateProjectExtents(newExtents);\n\n // Set source from calculated to user so connectors preserve the change.\n const unitsProps: FilePropertyProps = { name: \"Units\", namespace: \"dgn_Db\" };\n const unitsStr = this.iModel.queryFilePropertyString(unitsProps);\n\n if (undefined !== unitsStr) {\n const unitsVal = JSON.parse(unitsStr);\n const calculated = 1;\n\n if (calculated !== unitsVal.extentsSource) {\n unitsVal.extentsSource = calculated;\n this.iModel.saveFileProperty(unitsProps, JSON.stringify(unitsVal));\n }\n }\n }\n\n public async updateEcefLocation(ecefLocation: EcefLocationProps): Promise<void> {\n await this.iModel.acquireSchemaLock();\n\n // Clear GCS that caller already determined was invalid...\n this.iModel.deleteFileProperty({ name: \"DgnGCS\", namespace: \"dgn_Db\" });\n\n const newEcefLocation = new EcefLocation(ecefLocation);\n this.iModel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K,CAAC,QAAQ,CAAC,CAAC;YACtC,MAAM,UAAU,GAAG,CAAC,CAAC;YAErB,IAAI,UAAU,KAAK,QAAQ,CAAC,aAAa,EAAE,CAAC;gBAC1C,QAAQ,CAAC,aAAa,GAAG,UAAU,CAAC;gBACpC,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC;YACrE,CAAC;QACH,CAAC;IACH,CAAC;IAEM,KAAK,CAAC,kBAAkB,CAAC,YAA+B;QAC7D,MAAM,IAAI,CAAC,MAAM,CAAC,iBAAiB,EAAE,CAAC;QAEtC,0DAA0D;QAC1D,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,CAAC;QAExE,MAAM,eAAe,GAAG,IAAI,YAAY,CAAC,YAAY,CAAC,CAAC;QACvD,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC,eAAe,CAAC,CAAC;IAClD,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Editing\r\n */\r\n\r\nimport { CompressedId64Set, DbResult, Id64String, IModelStatus } from \"@itwin/core-bentley\";\r\nimport { Matrix3d, Matrix3dProps, Point3d, Range3d, Range3dProps, Transform, TransformProps } from \"@itwin/core-geometry\";\r\nimport { GeometricElement, IModelDb } from \"@itwin/core-backend\";\r\nimport { BRepEntity, EcefLocation, EcefLocationProps, ElementGeometry, ElementGeometryBuilderParams, ElementGeometryFunction, ElementGeometryInfo, ElementGeometryRequest, FilePropertyProps, GeometricElementProps, GeometryPartProps, IModelError } from \"@itwin/core-common\";\r\nimport { BasicManipulationCommandIpc, editorBuiltInCmdIds, FlatBufferGeometryFilter } from \"@itwin/editor-common\";\r\nimport { EditCommand } from \"./EditCommand\";\r\n\r\n/** Implementation for a EditCommand command that provides basic creation and modification operations.\r\n * @beta\r\n */\r\nexport class BasicManipulationCommand extends EditCommand implements BasicManipulationCommandIpc {\r\n public static override commandId = editorBuiltInCmdIds.cmdBasicManipulation;\r\n\r\n public constructor(iModel: IModelDb, protected _str: string) { super(iModel); }\r\n\r\n public override async onStart() { return BasicManipulationCommand.commandId; }\r\n\r\n public async addAllowedChannel(channelKey: string): Promise<void> {\r\n this.iModel.channels.addAllowedChannel(channelKey);\r\n }\r\n\r\n public async removeAllowedChannel(channelKey: string): Promise<void> {\r\n this.iModel.channels.removeAllowedChannel(channelKey);\r\n }\r\n\r\n public async deleteElements(ids: CompressedId64Set): Promise<IModelStatus> {\r\n const idSet = CompressedId64Set.decompressSet(ids);\r\n await this.iModel.locks.acquireLocks({ exclusive: idSet });\r\n\r\n for (const id of idSet)\r\n this.iModel.elements.deleteElement(id);\r\n\r\n return IModelStatus.Success;\r\n }\r\n\r\n public async transformPlacement(ids: CompressedId64Set, transProps: TransformProps): Promise<IModelStatus> {\r\n const idSet = CompressedId64Set.decompressSet(ids);\r\n await this.iModel.locks.acquireLocks({ exclusive: idSet });\r\n\r\n const transform = Transform.fromJSON(transProps);\r\n\r\n for (const id of idSet) {\r\n const element = this.iModel.elements.getElement<GeometricElement>(id);\r\n\r\n if (!element.placement.isValid)\r\n continue; // Ignore assembly parents w/o geometry, etc...\r\n\r\n element.placement.multiplyTransform(transform);\r\n this.iModel.elements.updateElement(element.toJSON());\r\n }\r\n\r\n return IModelStatus.Success;\r\n }\r\n\r\n public async rotatePlacement(ids: CompressedId64Set, matrixProps: Matrix3dProps, aboutCenter: boolean): Promise<IModelStatus> {\r\n const idSet = CompressedId64Set.decompressSet(ids);\r\n await this.iModel.locks.acquireLocks({ exclusive: idSet });\r\n\r\n const matrix = Matrix3d.fromJSON(matrixProps);\r\n\r\n for (const id of idSet) {\r\n const element = this.iModel.elements.getElement<GeometricElement>(id);\r\n\r\n if (!element.placement.isValid)\r\n continue; // Ignore assembly parents w/o geometry, etc...\r\n\r\n const fixedPoint = aboutCenter ? element.placement.calculateRange().center : Point3d.createFrom(element.placement.origin);\r\n const transform = Transform.createFixedPointAndMatrix(fixedPoint, matrix);\r\n\r\n element.placement.multiplyTransform(transform);\r\n this.iModel.elements.updateElement(element.toJSON());\r\n }\r\n\r\n return IModelStatus.Success;\r\n }\r\n\r\n public async insertGeometricElement(props: GeometricElementProps): Promise<Id64String> {\r\n await this.iModel.locks.acquireLocks({ shared: props.model });\r\n\r\n return this.iModel.elements.insertElement(props);\r\n }\r\n\r\n public async insertGeometryPart(props: GeometryPartProps): Promise<Id64String> {\r\n await this.iModel.locks.acquireLocks({ shared: props.model });\r\n\r\n return this.iModel.elements.insertElement(props);\r\n }\r\n\r\n public async updateGeometricElement(propsOrId: GeometricElementProps | Id64String, data?: ElementGeometryBuilderParams): Promise<void> {\r\n let props: GeometricElementProps;\r\n if (typeof propsOrId === \"string\") {\r\n if (undefined === data)\r\n throw new IModelError(DbResult.BE_SQLITE_ERROR, \"Flatbuffer data required for update by id\");\r\n props = this.iModel.elements.getElementProps<GeometricElementProps>(propsOrId);\r\n } else {\r\n props = propsOrId;\r\n }\r\n\r\n if (undefined === props.id)\r\n throw new IModelError(DbResult.BE_SQLITE_ERROR, \"Element id required for update\");\r\n\r\n await this.iModel.locks.acquireLocks({ exclusive: props.id });\r\n\r\n if (undefined !== data)\r\n props.elementGeometryBuilderParams = { entryArray: data.entryArray, viewIndependent: data.viewIndependent };\r\n\r\n this.iModel.elements.updateElement(props);\r\n }\r\n\r\n public async requestElementGeometry(elementId: Id64String, filter?: FlatBufferGeometryFilter): Promise<ElementGeometryInfo | undefined> {\r\n let accepted: ElementGeometryInfo | undefined;\r\n\r\n const onGeometry: ElementGeometryFunction = (info: ElementGeometryInfo): void => {\r\n accepted = info;\r\n\r\n if (undefined !== filter) {\r\n let numDisplayable = 0;\r\n\r\n for (const entry of info.entryArray) {\r\n if (!ElementGeometry.isDisplayableEntry(entry))\r\n continue;\r\n\r\n numDisplayable++;\r\n if (filter.maxDisplayable && numDisplayable > filter.maxDisplayable) {\r\n accepted = undefined;\r\n break;\r\n }\r\n\r\n if (filter.reject && filter.reject.some((opcode) => entry.opcode === opcode)) {\r\n accepted = undefined;\r\n break;\r\n }\r\n\r\n if (filter.accept && !filter.accept.some((opcode) => entry.opcode === opcode)) {\r\n accepted = undefined;\r\n break;\r\n }\r\n\r\n if (undefined === filter.geometry)\r\n continue;\r\n\r\n let entityType;\r\n if (filter.geometry.curves && !(filter.geometry.surfaces || filter.geometry.solids))\r\n entityType = ElementGeometry.isCurve(entry) ? BRepEntity.Type.Wire : undefined; // skip surface/solid opcodes...\r\n else\r\n entityType = ElementGeometry.getBRepEntityType(entry);\r\n\r\n switch (entityType) {\r\n case BRepEntity.Type.Wire:\r\n if (!filter.geometry.curves)\r\n accepted = undefined;\r\n break;\r\n case BRepEntity.Type.Sheet:\r\n if (!filter.geometry.surfaces)\r\n accepted = undefined;\r\n break;\r\n case BRepEntity.Type.Solid:\r\n if (!filter.geometry.solids)\r\n accepted = undefined;\r\n break;\r\n default:\r\n accepted = undefined;\r\n break;\r\n }\r\n\r\n if (undefined === accepted)\r\n break;\r\n }\r\n }\r\n };\r\n\r\n const requestProps: ElementGeometryRequest = {\r\n onGeometry,\r\n elementId,\r\n };\r\n\r\n if (IModelStatus.Success !== this.iModel.elementGeometryRequest(requestProps))\r\n return undefined;\r\n\r\n return accepted;\r\n }\r\n\r\n public async updateProjectExtents(extents: Range3dProps): Promise<void> {\r\n const newExtents = new Range3d();\r\n newExtents.setFromJSON(extents);\r\n\r\n if (newExtents.isNull)\r\n throw new IModelError(DbResult.BE_SQLITE_ERROR, \"Invalid project extents\");\r\n\r\n await this.iModel.acquireSchemaLock();\r\n\r\n this.iModel.updateProjectExtents(newExtents);\r\n\r\n // Set source from calculated to user so connectors preserve the change.\r\n const unitsProps: FilePropertyProps = { name: \"Units\", namespace: \"dgn_Db\" };\r\n const unitsStr = this.iModel.queryFilePropertyString(unitsProps);\r\n\r\n if (undefined !== unitsStr) {\r\n const unitsVal = JSON.parse(unitsStr);\r\n const calculated = 1;\r\n\r\n if (calculated !== unitsVal.extentsSource) {\r\n unitsVal.extentsSource = calculated;\r\n this.iModel.saveFileProperty(unitsProps, JSON.stringify(unitsVal));\r\n }\r\n }\r\n }\r\n\r\n public async updateEcefLocation(ecefLocation: EcefLocationProps): Promise<void> {\r\n await this.iModel.acquireSchemaLock();\r\n\r\n // Clear GCS that caller already determined was invalid...\r\n this.iModel.deleteFileProperty({ name: \"DgnGCS\", namespace: \"dgn_Db\" });\r\n\r\n const newEcefLocation = new EcefLocation(ecefLocation);\r\n this.iModel.updateEcefLocation(newEcefLocation);\r\n }\r\n}\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditCommand.js","sourceRoot":"","sources":["../../src/EditCommand.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAA6B,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAKnF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,OAAO,WAAW;IACtB,2GAA2G;IACpG,MAAM,CAAC,SAAS,GAAG,EAAE,CAAC;IACtB,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC;IAEhC,8CAA8C;IAC9B,MAAM,CAAW;IAEjC,YAAmB,MAAgB,EAAE,GAAG,KAAY;QAClD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IACD,IAAW,IAAI;QACb,OAAO,IAAI,CAAC,WAA8B,CAA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ACI,MAAM,CAAC,QAAQ,CAAC,WAA4B;QACjD,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC;YACzB,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;YAC3B,IAAI,CAAC,OAAO,CAAC,OAAO;gBAClB,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;YACnD,gBAAgB,CAAC,QAAQ,EAAE,CAAC;QAC9B,CAAC;QACD,IAAI,WAAW,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC;YACpC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;IAC1D,CAAC;IAED;;;OAGG;IACI,MAAM,CAAC,cAAc,CAAC,SAAc;QACzC,IAAI,QAAQ,GAAG,KAAK,CAAC;QACrB,KAAK,MAAM,UAAU,IAAI,SAAS,EAAE,CAAC,CAAE,mCAAmC;YACxE,MAAM,OAAO,GAAG,SAAS,CAAC,UAAU,CAAC,CAAC;YACtC,IAAI,OAAO,CAAC,SAAS,YAAY,WAAW,EAAE,CAAC;gBAC7C,QAAQ,GAAG,IAAI,CAAC;gBAChB,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;YACzB,CAAC;QACH,CAAC;QACD,IAAI,CAAC,QAAQ;YACX,MAAM,IAAI,KAAK,CAAC,4FAA4F,CAAC,CAAC;IAClH,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 Editing\n */\n\nimport { IModelStatus } from \"@itwin/core-bentley\";\nimport { IModelDb, IpcHandler, IpcHost } from \"@itwin/core-backend\";\nimport { BackendError, IModelError } from \"@itwin/core-common\";\nimport { EditCommandIpc, EditorIpc, editorIpcStrings } from \"@itwin/editor-common\";\n\n/** @beta */\nexport type EditCommandType = typeof EditCommand;\n\n/**\n * An EditCommand performs an editing action on the backend.\n * Any writes to the iModel in an editing session should be done from an EditCommand:\n * - All changes to an iModel are made within a transaction (Txn).\n * - Calling SaveChanges ends the current Txn and starts a new one.\n * - Using EditCommand ensures all of the changes in a Txn are from the same source, as only one EditCommand may be active at a time.\n * - Because there is currently no way to enforce this, it is important that all applications follow this rule.\n * EditCommands are usually paired with and driven by EditTools on the frontend that can either be interactive tools or immediate tools.\n * Interactive EditTools:\n * - Can be a [PrimitiveTool]($frontend).\n * - Can be an [InputCollector]($frontend) in special cases such as [EditManipulator.HandleTool]($frontend).\n * - Should not be a [ViewTool]($frontend), these should never write changes to the iModel.\n * Immediate EditTools:\n * - As direct subclasses of [Tool]($frontend) that perform their function without further input or becoming the active tool,\n * they potentially leave the current [PrimitiveTool]($frontend) in an invalid state.\n * - To avoid issues, immediate tools that start an EditCommand must call [ToolAdmin.restartPrimitiveTool]($frontend) when they complete.\n * EditCommands have a *commandId* that uniquely identifies them, so they can be found via a lookup in the [[EditCommandAdmin]].\n * Each EditCommand must be registered in the [[EditCommandAdmin]] with [[EditCommandAdmin.register]] or [[EditCommandAdmin.registerModule]].\n * Every time an EditCommand runs, a new instance of (a subclass of) this class is created.\n * @see [[BasicManipulationCommand]] for an example EditCommand.\n * @beta\n */\nexport class EditCommand implements EditCommandIpc {\n /** The unique string that identifies this EditCommand class. This must be overridden in every subclass. */\n public static commandId = \"\";\n public static version = \"1.0.0\";\n\n /** The iModel this EditCommand may modify. */\n public readonly iModel: IModelDb;\n\n public constructor(iModel: IModelDb, ..._args: any[]) {\n this.iModel = iModel;\n }\n public get ctor(): EditCommandType {\n return this.constructor as EditCommandType;\n }\n\n public async onStart(): Promise<any> { }\n\n public async ping(): Promise<{ commandId: string, version: string, [propName: string]: any }> {\n return { version: this.ctor.version, commandId: this.ctor.commandId };\n }\n\n // This is only temporary to find subclasses that used to implement this method. It was made async and renamed `requestFinish`.\n private onFinish() { }\n\n /**\n * Called when another EditCommand wishes to become the active EditCommand.\n * Subclasses should complete and save their work as soon as possible and then return \"done\".\n * If it is not currently possible to finish, return any string other than \"done\" and the other EditCommand will have to wait and retry,\n * potentially showing the returned string to the user.\n */\n public async requestFinish(): Promise<\"done\" | string> { // eslint-disable-line @typescript-eslint/no-redundant-type-constituents\n this.onFinish(); // TODO: temporary, remove\n return \"done\";\n }\n}\n\nclass EditorAppHandler extends IpcHandler implements EditorIpc {\n public get channelName() { return editorIpcStrings.channel; }\n\n public async startCommand(commandId: string, iModelKey: string, ...args: any[]) {\n await EditCommandAdmin.finishCommand();\n if (commandId === \"\") // just kill active command, don't start another\n return;\n\n const commandClass = EditCommandAdmin.commands.get(commandId);\n if (undefined === commandClass)\n throw new IModelError(IModelStatus.NotRegistered, `Command not registered [${commandId}]`);\n\n return EditCommandAdmin.runCommand(new commandClass(IModelDb.findByKey(iModelKey), ...args));\n }\n\n public async callMethod(methodName: string, ...args: any[]) {\n const cmd = EditCommandAdmin.activeCommand;\n if (!cmd)\n throw new IModelError(IModelStatus.NoActiveCommand, `No active command`);\n\n const func = (cmd as any)[methodName];\n if (typeof func !== \"function\")\n throw new IModelError(IModelStatus.FunctionNotFound, `Method ${methodName} not found on ${cmd.ctor.commandId}`);\n\n return func.call(cmd, ...args);\n }\n}\n\n/**\n * EditCommandAdmin holds a mapping between commandIds and their corresponding [[EditCommand]] class. This provides the mechanism to\n * run EditCommands by commandId.\n * It also keeps track of the currently active EditCommand. When a new EditCommand attempts to start, the active EditCommand\n * is requested to finish, and the new EditCommand cannot start until it does.\n * @beta\n */\nexport class EditCommandAdmin {\n public static readonly commands = new Map<string, EditCommandType>();\n\n private static _activeCommand?: EditCommand;\n private static _isInitialized = false;\n public static get activeCommand() { return this._activeCommand; }\n\n /** If any command is currently active, wait for it to finish.\n * Afterward, no command will be active.\n * This method is invoked by [[runCommand]] before starting a new command.\n * @throws BackendError if the command fails to finish.\n */\n public static async finishCommand() {\n if (this._activeCommand) {\n const finished = await this._activeCommand.requestFinish();\n if (\"done\" !== finished)\n throw new BackendError(IModelStatus.ServerTimeout, editorIpcStrings.commandBusy, finished);\n }\n this._activeCommand = undefined;\n }\n\n /** Start running the specified command.\n * The new command will not begin running until the currently-active command (if any) finishes.\n * Afterward, the new command becomes the active command.\n * @throws BackendError if the currently-active command fails to finish.\n */\n public static async runCommand(cmd: EditCommand): Promise<any> {\n await this.finishCommand();\n this._activeCommand = cmd;\n return cmd.onStart();\n }\n\n /**\n * Un-register a previously registered EditCommand class.\n * @param commandId the commandId of a previously registered EditCommand to unRegister.\n */\n public static unRegister(commandId: string) {\n this.commands.delete(commandId);\n }\n\n /**\n * Register an EditCommand class. This establishes a connection between the commandId of the class and the class itself.\n * @param commandType the subclass of Tool to register.\n */\n public static register(commandType: EditCommandType) {\n if (!this._isInitialized) {\n this._isInitialized = true;\n if (!IpcHost.isValid)\n throw new Error(\"Edit Commands require IpcHost\");\n EditorAppHandler.register();\n }\n if (commandType.commandId.length !== 0)\n this.commands.set(commandType.commandId, commandType);\n }\n\n /**\n * Register all the EditCommand classes found in a module.\n * @param modelObj the module to search for subclasses of EditCommand.\n */\n public static registerModule(moduleObj: any) {\n let foundOne = false;\n for (const thisMember in moduleObj) { // eslint-disable-line guard-for-in\n const thisCmd = moduleObj[thisMember];\n if (thisCmd.prototype instanceof EditCommand) {\n foundOne = true;\n this.register(thisCmd);\n }\n }\n if (!foundOne)\n throw new Error(`no EditCommands found - are you sure this is a module? Maybe you meant to call \"register\"?`);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"EditCommand.js","sourceRoot":"","sources":["../../src/EditCommand.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAA6B,gBA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,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Editing\r\n */\r\n\r\nimport { IModelStatus } from \"@itwin/core-bentley\";\r\nimport { IModelDb, IpcHandler, IpcHost } from \"@itwin/core-backend\";\r\nimport { BackendError, IModelError } from \"@itwin/core-common\";\r\nimport { EditCommandIpc, EditorIpc, editorIpcStrings } from \"@itwin/editor-common\";\r\n\r\n/** @beta */\r\nexport type EditCommandType = typeof EditCommand;\r\n\r\n/**\r\n * An EditCommand performs an editing action on the backend.\r\n * Any writes to the iModel in an editing session should be done from an EditCommand:\r\n * - All changes to an iModel are made within a transaction (Txn).\r\n * - Calling SaveChanges ends the current Txn and starts a new one.\r\n * - Using EditCommand ensures all of the changes in a Txn are from the same source, as only one EditCommand may be active at a time.\r\n * - Because there is currently no way to enforce this, it is important that all applications follow this rule.\r\n * EditCommands are usually paired with and driven by EditTools on the frontend that can either be interactive tools or immediate tools.\r\n * Interactive EditTools:\r\n * - Can be a [PrimitiveTool]($frontend).\r\n * - Can be an [InputCollector]($frontend) in special cases such as [EditManipulator.HandleTool]($frontend).\r\n * - Should not be a [ViewTool]($frontend), these should never write changes to the iModel.\r\n * Immediate EditTools:\r\n * - As direct subclasses of [Tool]($frontend) that perform their function without further input or becoming the active tool,\r\n * they potentially leave the current [PrimitiveTool]($frontend) in an invalid state.\r\n * - To avoid issues, immediate tools that start an EditCommand must call [ToolAdmin.restartPrimitiveTool]($frontend) when they complete.\r\n * EditCommands have a *commandId* that uniquely identifies them, so they can be found via a lookup in the [[EditCommandAdmin]].\r\n * Each EditCommand must be registered in the [[EditCommandAdmin]] with [[EditCommandAdmin.register]] or [[EditCommandAdmin.registerModule]].\r\n * Every time an EditCommand runs, a new instance of (a subclass of) this class is created.\r\n * @see [[BasicManipulationCommand]] for an example EditCommand.\r\n * @beta\r\n */\r\nexport class EditCommand implements EditCommandIpc {\r\n /** The unique string that identifies this EditCommand class. This must be overridden in every subclass. */\r\n public static commandId = \"\";\r\n public static version = \"1.0.0\";\r\n\r\n /** The iModel this EditCommand may modify. */\r\n public readonly iModel: IModelDb;\r\n\r\n public constructor(iModel: IModelDb, ..._args: any[]) {\r\n this.iModel = iModel;\r\n }\r\n public get ctor(): EditCommandType {\r\n return this.constructor as EditCommandType;\r\n }\r\n\r\n public async onStart(): Promise<any> { }\r\n\r\n public async ping(): Promise<{ commandId: string, version: string, [propName: string]: any }> {\r\n return { version: this.ctor.version, commandId: this.ctor.commandId };\r\n }\r\n\r\n // This is only temporary to find subclasses that used to implement this method. It was made async and renamed `requestFinish`.\r\n private onFinish() { }\r\n\r\n /**\r\n * Called when another EditCommand wishes to become the active EditCommand.\r\n * Subclasses should complete and save their work as soon as possible and then return \"done\".\r\n * If it is not currently possible to finish, return any string other than \"done\" and the other EditCommand will have to wait and retry,\r\n * potentially showing the returned string to the user.\r\n */\r\n public async requestFinish(): Promise<\"done\" | string> { // eslint-disable-line @typescript-eslint/no-redundant-type-constituents\r\n this.onFinish(); // TODO: temporary, remove\r\n return \"done\";\r\n }\r\n}\r\n\r\nclass EditorAppHandler extends IpcHandler implements EditorIpc {\r\n public get channelName() { return editorIpcStrings.channel; }\r\n\r\n public async startCommand(commandId: string, iModelKey: string, ...args: any[]) {\r\n await EditCommandAdmin.finishCommand();\r\n if (commandId === \"\") // just kill active command, don't start another\r\n return;\r\n\r\n const commandClass = EditCommandAdmin.commands.get(commandId);\r\n if (undefined === commandClass)\r\n throw new IModelError(IModelStatus.NotRegistered, `Command not registered [${commandId}]`);\r\n\r\n return EditCommandAdmin.runCommand(new commandClass(IModelDb.findByKey(iModelKey), ...args));\r\n }\r\n\r\n public async callMethod(methodName: string, ...args: any[]) {\r\n const cmd = EditCommandAdmin.activeCommand;\r\n if (!cmd)\r\n throw new IModelError(IModelStatus.NoActiveCommand, `No active command`);\r\n\r\n const func = (cmd as any)[methodName];\r\n if (typeof func !== \"function\")\r\n throw new IModelError(IModelStatus.FunctionNotFound, `Method ${methodName} not found on ${cmd.ctor.commandId}`);\r\n\r\n return func.call(cmd, ...args);\r\n }\r\n}\r\n\r\n/**\r\n * EditCommandAdmin holds a mapping between commandIds and their corresponding [[EditCommand]] class. This provides the mechanism to\r\n * run EditCommands by commandId.\r\n * It also keeps track of the currently active EditCommand. When a new EditCommand attempts to start, the active EditCommand\r\n * is requested to finish, and the new EditCommand cannot start until it does.\r\n * @beta\r\n */\r\nexport class EditCommandAdmin {\r\n public static readonly commands = new Map<string, EditCommandType>();\r\n\r\n private static _activeCommand?: EditCommand;\r\n private static _isInitialized = false;\r\n public static get activeCommand() { return this._activeCommand; }\r\n\r\n /** If any command is currently active, wait for it to finish.\r\n * Afterward, no command will be active.\r\n * This method is invoked by [[runCommand]] before starting a new command.\r\n * @throws BackendError if the command fails to finish.\r\n */\r\n public static async finishCommand() {\r\n if (this._activeCommand) {\r\n const finished = await this._activeCommand.requestFinish();\r\n if (\"done\" !== finished)\r\n throw new BackendError(IModelStatus.ServerTimeout, editorIpcStrings.commandBusy, finished);\r\n }\r\n this._activeCommand = undefined;\r\n }\r\n\r\n /** Start running the specified command.\r\n * The new command will not begin running until the currently-active command (if any) finishes.\r\n * Afterward, the new command becomes the active command.\r\n * @throws BackendError if the currently-active command fails to finish.\r\n */\r\n public static async runCommand(cmd: EditCommand): Promise<any> {\r\n await this.finishCommand();\r\n this._activeCommand = cmd;\r\n return cmd.onStart();\r\n }\r\n\r\n /**\r\n * Un-register a previously registered EditCommand class.\r\n * @param commandId the commandId of a previously registered EditCommand to unRegister.\r\n */\r\n public static unRegister(commandId: string) {\r\n this.commands.delete(commandId);\r\n }\r\n\r\n /**\r\n * Register an EditCommand class. This establishes a connection between the commandId of the class and the class itself.\r\n * @param commandType the subclass of Tool to register.\r\n */\r\n public static register(commandType: EditCommandType) {\r\n if (!this._isInitialized) {\r\n this._isInitialized = true;\r\n if (!IpcHost.isValid)\r\n throw new Error(\"Edit Commands require IpcHost\");\r\n EditorAppHandler.register();\r\n }\r\n if (commandType.commandId.length !== 0)\r\n this.commands.set(commandType.commandId, commandType);\r\n }\r\n\r\n /**\r\n * Register all the EditCommand classes found in a module.\r\n * @param modelObj the module to search for subclasses of EditCommand.\r\n */\r\n public static registerModule(moduleObj: any) {\r\n let foundOne = false;\r\n for (const thisMember in moduleObj) { // eslint-disable-line guard-for-in\r\n const thisCmd = moduleObj[thisMember];\r\n if (thisCmd.prototype instanceof EditCommand) {\r\n foundOne = true;\r\n this.register(thisCmd);\r\n }\r\n }\r\n if (!foundOne)\r\n throw new Error(`no EditCommands found - are you sure this is a module? Maybe you meant to call \"register\"?`);\r\n }\r\n}\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editor-backend.js","sourceRoot":"","sources":["../../src/editor-backend.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC;AAErC;;GAEG;AAEH;;;GAGG","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*--------------------------------------------------------------------------------------------*/\nexport * from \"./EditCommand\";\nexport * from \"./EditBuiltInCommand\";\n\n/** @docs-package-description\n * The editor-backend package contains backend functionality for editing iModels.\n */\n\n/**\n * @docs-group-description Editing\n * Classes containing functionality for editing iModels on the backend.\n */\n"]}
|
|
1
|
+
{"version":3,"file":"editor-backend.js","sourceRoot":"","sources":["../../src/editor-backend.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC;AAErC;;GAEG;AAEH;;;GAGG","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\nexport * from \"./EditCommand\";\r\nexport * from \"./EditBuiltInCommand\";\r\n\r\n/** @docs-package-description\r\n * The editor-backend package contains backend functionality for editing iModels.\r\n */\r\n\r\n/**\r\n * @docs-group-description Editing\r\n * Classes containing functionality for editing iModels on the backend.\r\n */\r\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/editor-backend",
|
|
3
|
-
"version": "5.5.0-dev.
|
|
3
|
+
"version": "5.5.0-dev.5",
|
|
4
4
|
"description": "iTwin.js editor backend",
|
|
5
5
|
"main": "lib/cjs/editor-backend.js",
|
|
6
6
|
"module": "lib/esm/editor-backend.js",
|
|
@@ -26,10 +26,10 @@
|
|
|
26
26
|
"url": "http://www.bentley.com"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
|
-
"@itwin/core-backend": "5.5.0-dev.
|
|
30
|
-
"@itwin/core-
|
|
31
|
-
"@itwin/core-
|
|
32
|
-
"@itwin/core-common": "5.5.0-dev.
|
|
29
|
+
"@itwin/core-backend": "5.5.0-dev.5",
|
|
30
|
+
"@itwin/core-bentley": "5.5.0-dev.5",
|
|
31
|
+
"@itwin/core-geometry": "5.5.0-dev.5",
|
|
32
|
+
"@itwin/core-common": "5.5.0-dev.5"
|
|
33
33
|
},
|
|
34
34
|
"//devDependencies": [
|
|
35
35
|
"NOTE: All peerDependencies should also be listed as devDependencies since peerDependencies are not considered by npm install",
|
|
@@ -40,14 +40,14 @@
|
|
|
40
40
|
"eslint": "^9.31.0",
|
|
41
41
|
"rimraf": "^6.0.1",
|
|
42
42
|
"typescript": "~5.6.2",
|
|
43
|
-
"@itwin/
|
|
44
|
-
"@itwin/core-
|
|
45
|
-
"@itwin/core-
|
|
46
|
-
"@itwin/
|
|
47
|
-
"@itwin/core-
|
|
43
|
+
"@itwin/core-common": "5.5.0-dev.5",
|
|
44
|
+
"@itwin/core-geometry": "5.5.0-dev.5",
|
|
45
|
+
"@itwin/core-backend": "5.5.0-dev.5",
|
|
46
|
+
"@itwin/build-tools": "5.5.0-dev.5",
|
|
47
|
+
"@itwin/core-bentley": "5.5.0-dev.5"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@itwin/editor-common": "5.5.0-dev.
|
|
50
|
+
"@itwin/editor-common": "5.5.0-dev.5"
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|
|
53
53
|
"build": "npm run -s build:cjs && npm run -s build:esm",
|