@itwin/editor-backend 5.0.0-dev.9 → 5.0.0-dev.92
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 +51 -1
- package/lib/cjs/EditBuiltInCommand.js +2 -1
- package/lib/cjs/EditBuiltInCommand.js.map +1 -1
- package/lib/cjs/EditCommand.js +8 -5
- package/lib/cjs/EditCommand.js.map +1 -1
- package/lib/cjs/editor-backend.js.map +1 -1
- package/lib/esm/EditBuiltInCommand.d.ts +30 -0
- package/lib/esm/EditBuiltInCommand.d.ts.map +1 -0
- package/lib/esm/EditBuiltInCommand.js +176 -0
- package/lib/esm/EditBuiltInCommand.js.map +1 -0
- package/lib/esm/EditCommand.d.ts +93 -0
- package/lib/esm/EditCommand.d.ts.map +1 -0
- package/lib/esm/EditCommand.js +157 -0
- package/lib/esm/EditCommand.js.map +1 -0
- package/lib/esm/editor-backend.d.ts +10 -0
- package/lib/esm/editor-backend.d.ts.map +1 -0
- package/lib/esm/editor-backend.js +14 -0
- package/lib/esm/editor-backend.js.map +1 -0
- package/package.json +16 -14
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,56 @@
|
|
|
1
1
|
# Change Log - @itwin/editor-backend
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Wed, 19 Mar 2025 15:33:24 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 4.10.11
|
|
6
|
+
Wed, 19 Mar 2025 15:30:39 GMT
|
|
7
|
+
|
|
8
|
+
_Version update only_
|
|
9
|
+
|
|
10
|
+
## 4.10.10
|
|
11
|
+
Tue, 11 Mar 2025 15:25:11 GMT
|
|
12
|
+
|
|
13
|
+
_Version update only_
|
|
14
|
+
|
|
15
|
+
## 4.10.9
|
|
16
|
+
Tue, 11 Mar 2025 05:17:33 GMT
|
|
17
|
+
|
|
18
|
+
_Version update only_
|
|
19
|
+
|
|
20
|
+
## 4.10.8
|
|
21
|
+
Thu, 06 Mar 2025 14:13:37 GMT
|
|
22
|
+
|
|
23
|
+
_Version update only_
|
|
24
|
+
|
|
25
|
+
## 4.10.7
|
|
26
|
+
Tue, 18 Feb 2025 17:27:03 GMT
|
|
27
|
+
|
|
28
|
+
_Version update only_
|
|
29
|
+
|
|
30
|
+
## 4.10.6
|
|
31
|
+
Fri, 24 Jan 2025 08:02:40 GMT
|
|
32
|
+
|
|
33
|
+
_Version update only_
|
|
34
|
+
|
|
35
|
+
## 4.10.5
|
|
36
|
+
Tue, 21 Jan 2025 21:56:45 GMT
|
|
37
|
+
|
|
38
|
+
_Version update only_
|
|
39
|
+
|
|
40
|
+
## 4.10.4
|
|
41
|
+
Mon, 13 Jan 2025 14:06:43 GMT
|
|
42
|
+
|
|
43
|
+
_Version update only_
|
|
44
|
+
|
|
45
|
+
## 4.10.3
|
|
46
|
+
Mon, 06 Jan 2025 14:00:13 GMT
|
|
47
|
+
|
|
48
|
+
_Version update only_
|
|
49
|
+
|
|
50
|
+
## 4.10.2
|
|
51
|
+
Thu, 21 Nov 2024 15:22:20 GMT
|
|
52
|
+
|
|
53
|
+
_Version update only_
|
|
4
54
|
|
|
5
55
|
## 4.10.1
|
|
6
56
|
Thu, 14 Nov 2024 18:11:00 GMT
|
|
@@ -17,6 +17,8 @@ const EditCommand_1 = require("./EditCommand");
|
|
|
17
17
|
* @beta
|
|
18
18
|
*/
|
|
19
19
|
class BasicManipulationCommand extends EditCommand_1.EditCommand {
|
|
20
|
+
_str;
|
|
21
|
+
static commandId = editor_common_1.editorBuiltInCmdIds.cmdBasicManipulation;
|
|
20
22
|
constructor(iModel, _str) {
|
|
21
23
|
super(iModel);
|
|
22
24
|
this._str = _str;
|
|
@@ -175,5 +177,4 @@ class BasicManipulationCommand extends EditCommand_1.EditCommand {
|
|
|
175
177
|
}
|
|
176
178
|
}
|
|
177
179
|
exports.BasicManipulationCommand = BasicManipulationCommand;
|
|
178
|
-
BasicManipulationCommand.commandId = editor_common_1.editorBuiltInCmdIds.cmdBasicManipulation;
|
|
179
180
|
//# sourceMappingURL=EditBuiltInCommand.js.map
|
|
@@ -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;IAGvD,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,gCAAiB,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;QACnD,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC;QAE3D,KAAK,MAAM,EAAE,IAAI,KAAK;YACpB,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;QAEzC,OAAO,2BAAY,CAAC,OAAO,CAAC;IAC9B,CAAC;IAEM,KAAK,CAAC,kBAAkB,CAAC,GAAsB,EAAE,UAA0B;QAChF,MAAM,KAAK,GAA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AAC;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;AA9MwB,kCAAS,GAAG,mCAAmB,CAAC,oBAAoB,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
|
+
{"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,cAAc,CAAC,GAAsB;QAChD,MAAM,KAAK,GAAG,gCAAiB,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;QACnD,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,YAAY,CA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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"]}
|
package/lib/cjs/EditCommand.js
CHANGED
|
@@ -35,6 +35,11 @@ const editor_common_1 = require("@itwin/editor-common");
|
|
|
35
35
|
* @beta
|
|
36
36
|
*/
|
|
37
37
|
class EditCommand {
|
|
38
|
+
/** The unique string that identifies this EditCommand class. This must be overridden in every subclass. */
|
|
39
|
+
static commandId = "";
|
|
40
|
+
static version = "1.0.0";
|
|
41
|
+
/** The iModel this EditCommand may modify. */
|
|
42
|
+
iModel;
|
|
38
43
|
constructor(iModel, ..._args) {
|
|
39
44
|
this.iModel = iModel;
|
|
40
45
|
}
|
|
@@ -59,9 +64,6 @@ class EditCommand {
|
|
|
59
64
|
}
|
|
60
65
|
}
|
|
61
66
|
exports.EditCommand = EditCommand;
|
|
62
|
-
/** The unique string that identifies this EditCommand class. This must be overridden in every subclass. */
|
|
63
|
-
EditCommand.commandId = "";
|
|
64
|
-
EditCommand.version = "1.0.0";
|
|
65
67
|
class EditorAppHandler extends core_backend_1.IpcHandler {
|
|
66
68
|
get channelName() { return editor_common_1.editorIpcStrings.channel; }
|
|
67
69
|
async startCommand(commandId, iModelKey, ...args) {
|
|
@@ -91,6 +93,9 @@ class EditorAppHandler extends core_backend_1.IpcHandler {
|
|
|
91
93
|
* @beta
|
|
92
94
|
*/
|
|
93
95
|
class EditCommandAdmin {
|
|
96
|
+
static commands = new Map();
|
|
97
|
+
static _activeCommand;
|
|
98
|
+
static _isInitialized = false;
|
|
94
99
|
static get activeCommand() { return this._activeCommand; }
|
|
95
100
|
/** If any command is currently active, wait for it to finish.
|
|
96
101
|
* Afterward, no command will be active.
|
|
@@ -154,6 +159,4 @@ class EditCommandAdmin {
|
|
|
154
159
|
}
|
|
155
160
|
}
|
|
156
161
|
exports.EditCommandAdmin = EditCommandAdmin;
|
|
157
|
-
EditCommandAdmin.commands = new Map();
|
|
158
|
-
EditCommandAdmin._isInitialized = false;
|
|
159
162
|
//# sourceMappingURL=EditCommand.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"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I,GAAG,EAA2B,CAAC;AAGtD,+BAAc,GAAG,KAAK,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
|
+
{"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,KAAK,CAAC,OAAO,KAAmB,CAAC;IAEjC,KAAK,CAAC,IAAI;QACf,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,SAAS,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;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,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 +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":["/*---------------------------------------------------------------------------------------------\
|
|
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"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module Editing
|
|
3
|
+
*/
|
|
4
|
+
import { CompressedId64Set, Id64String, IModelStatus } from "@itwin/core-bentley";
|
|
5
|
+
import { Matrix3dProps, Range3dProps, TransformProps } from "@itwin/core-geometry";
|
|
6
|
+
import { IModelDb } from "@itwin/core-backend";
|
|
7
|
+
import { EcefLocationProps, ElementGeometryBuilderParams, ElementGeometryInfo, GeometricElementProps, GeometryPartProps } from "@itwin/core-common";
|
|
8
|
+
import { BasicManipulationCommandIpc, FlatBufferGeometryFilter } from "@itwin/editor-common";
|
|
9
|
+
import { EditCommand } from "./EditCommand";
|
|
10
|
+
/** Implementation for a EditCommand command that provides basic creation and modification operations.
|
|
11
|
+
* @beta
|
|
12
|
+
*/
|
|
13
|
+
export declare class BasicManipulationCommand extends EditCommand implements BasicManipulationCommandIpc {
|
|
14
|
+
protected _str: string;
|
|
15
|
+
static commandId: string;
|
|
16
|
+
constructor(iModel: IModelDb, _str: string);
|
|
17
|
+
onStart(): Promise<string>;
|
|
18
|
+
addAllowedChannel(channelKey: string): Promise<void>;
|
|
19
|
+
removeAllowedChannel(channelKey: string): Promise<void>;
|
|
20
|
+
deleteElements(ids: CompressedId64Set): Promise<IModelStatus>;
|
|
21
|
+
transformPlacement(ids: CompressedId64Set, transProps: TransformProps): Promise<IModelStatus>;
|
|
22
|
+
rotatePlacement(ids: CompressedId64Set, matrixProps: Matrix3dProps, aboutCenter: boolean): Promise<IModelStatus>;
|
|
23
|
+
insertGeometricElement(props: GeometricElementProps): Promise<Id64String>;
|
|
24
|
+
insertGeometryPart(props: GeometryPartProps): Promise<Id64String>;
|
|
25
|
+
updateGeometricElement(propsOrId: GeometricElementProps | Id64String, data?: ElementGeometryBuilderParams): Promise<void>;
|
|
26
|
+
requestElementGeometry(elementId: Id64String, filter?: FlatBufferGeometryFilter): Promise<ElementGeometryInfo | undefined>;
|
|
27
|
+
updateProjectExtents(extents: Range3dProps): Promise<void>;
|
|
28
|
+
updateEcefLocation(ecefLocation: EcefLocationProps): Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=EditBuiltInCommand.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EditBuiltInCommand.d.ts","sourceRoot":"","sources":["../../src/EditBuiltInCommand.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,iBAAiB,EAAY,UAAU,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC5F,OAAO,EAAY,aAAa,EAAoB,YAAY,EAAa,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC1H,OAAO,EAAoB,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,EAA4B,iBAAiB,EAAmB,4BAA4B,EAA2B,mBAAmB,EAA6C,qBAAqB,EAAE,iBAAiB,EAAe,MAAM,oBAAoB,CAAC;AAChR,OAAO,EAAE,2BAA2B,EAAuB,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AAClH,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C;;GAEG;AACH,qBAAa,wBAAyB,SAAQ,WAAY,YAAW,2BAA2B;IAGzD,SAAS,CAAC,IAAI,EAAE,MAAM;IAF3D,OAAuB,SAAS,SAA4C;gBAEzD,MAAM,EAAE,QAAQ,EAAY,IAAI,EAAE,MAAM;IAErC,OAAO;IAEhB,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIpD,oBAAoB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIvD,cAAc,CAAC,GAAG,EAAE,iBAAiB,GAAG,OAAO,CAAC,YAAY,CAAC;IAU7D,kBAAkB,CAAC,GAAG,EAAE,iBAAiB,EAAE,UAAU,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,CAAC;IAmB7F,eAAe,CAAC,GAAG,EAAE,iBAAiB,EAAE,WAAW,EAAE,aAAa,EAAE,WAAW,EAAE,OAAO,GAAG,OAAO,CAAC,YAAY,CAAC;IAsBhH,sBAAsB,CAAC,KAAK,EAAE,qBAAqB,GAAG,OAAO,CAAC,UAAU,CAAC;IAMzE,kBAAkB,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,UAAU,CAAC;IAMjE,sBAAsB,CAAC,SAAS,EAAE,qBAAqB,GAAG,UAAU,EAAE,IAAI,CAAC,EAAE,4BAA4B,GAAG,OAAO,CAAC,IAAI,CAAC;IAqBzH,sBAAsB,CAAC,SAAS,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,wBAAwB,GAAG,OAAO,CAAC,mBAAmB,GAAG,SAAS,CAAC;IAyE1H,oBAAoB,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IA0B1D,kBAAkB,CAAC,YAAY,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;CAShF"}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
/** @packageDocumentation
|
|
6
|
+
* @module Editing
|
|
7
|
+
*/
|
|
8
|
+
import { CompressedId64Set, DbResult, IModelStatus } from "@itwin/core-bentley";
|
|
9
|
+
import { Matrix3d, Point3d, Range3d, Transform } from "@itwin/core-geometry";
|
|
10
|
+
import { BRepEntity, EcefLocation, ElementGeometry, IModelError } from "@itwin/core-common";
|
|
11
|
+
import { editorBuiltInCmdIds } from "@itwin/editor-common";
|
|
12
|
+
import { EditCommand } from "./EditCommand";
|
|
13
|
+
/** Implementation for a EditCommand command that provides basic creation and modification operations.
|
|
14
|
+
* @beta
|
|
15
|
+
*/
|
|
16
|
+
export class BasicManipulationCommand extends EditCommand {
|
|
17
|
+
_str;
|
|
18
|
+
static commandId = editorBuiltInCmdIds.cmdBasicManipulation;
|
|
19
|
+
constructor(iModel, _str) {
|
|
20
|
+
super(iModel);
|
|
21
|
+
this._str = _str;
|
|
22
|
+
}
|
|
23
|
+
async onStart() { return BasicManipulationCommand.commandId; }
|
|
24
|
+
async addAllowedChannel(channelKey) {
|
|
25
|
+
this.iModel.channels.addAllowedChannel(channelKey);
|
|
26
|
+
}
|
|
27
|
+
async removeAllowedChannel(channelKey) {
|
|
28
|
+
this.iModel.channels.removeAllowedChannel(channelKey);
|
|
29
|
+
}
|
|
30
|
+
async deleteElements(ids) {
|
|
31
|
+
const idSet = CompressedId64Set.decompressSet(ids);
|
|
32
|
+
await this.iModel.locks.acquireLocks({ exclusive: idSet });
|
|
33
|
+
for (const id of idSet)
|
|
34
|
+
this.iModel.elements.deleteElement(id);
|
|
35
|
+
return IModelStatus.Success;
|
|
36
|
+
}
|
|
37
|
+
async transformPlacement(ids, transProps) {
|
|
38
|
+
const idSet = CompressedId64Set.decompressSet(ids);
|
|
39
|
+
await this.iModel.locks.acquireLocks({ exclusive: idSet });
|
|
40
|
+
const transform = Transform.fromJSON(transProps);
|
|
41
|
+
for (const id of idSet) {
|
|
42
|
+
const element = this.iModel.elements.getElement(id);
|
|
43
|
+
if (!element.placement.isValid)
|
|
44
|
+
continue; // Ignore assembly parents w/o geometry, etc...
|
|
45
|
+
element.placement.multiplyTransform(transform);
|
|
46
|
+
this.iModel.elements.updateElement(element.toJSON());
|
|
47
|
+
}
|
|
48
|
+
return IModelStatus.Success;
|
|
49
|
+
}
|
|
50
|
+
async rotatePlacement(ids, matrixProps, aboutCenter) {
|
|
51
|
+
const idSet = CompressedId64Set.decompressSet(ids);
|
|
52
|
+
await this.iModel.locks.acquireLocks({ exclusive: idSet });
|
|
53
|
+
const matrix = Matrix3d.fromJSON(matrixProps);
|
|
54
|
+
for (const id of idSet) {
|
|
55
|
+
const element = this.iModel.elements.getElement(id);
|
|
56
|
+
if (!element.placement.isValid)
|
|
57
|
+
continue; // Ignore assembly parents w/o geometry, etc...
|
|
58
|
+
const fixedPoint = aboutCenter ? element.placement.calculateRange().center : Point3d.createFrom(element.placement.origin);
|
|
59
|
+
const transform = Transform.createFixedPointAndMatrix(fixedPoint, matrix);
|
|
60
|
+
element.placement.multiplyTransform(transform);
|
|
61
|
+
this.iModel.elements.updateElement(element.toJSON());
|
|
62
|
+
}
|
|
63
|
+
return IModelStatus.Success;
|
|
64
|
+
}
|
|
65
|
+
async insertGeometricElement(props) {
|
|
66
|
+
await this.iModel.locks.acquireLocks({ shared: props.model });
|
|
67
|
+
return this.iModel.elements.insertElement(props);
|
|
68
|
+
}
|
|
69
|
+
async insertGeometryPart(props) {
|
|
70
|
+
await this.iModel.locks.acquireLocks({ shared: props.model });
|
|
71
|
+
return this.iModel.elements.insertElement(props);
|
|
72
|
+
}
|
|
73
|
+
async updateGeometricElement(propsOrId, data) {
|
|
74
|
+
let props;
|
|
75
|
+
if (typeof propsOrId === "string") {
|
|
76
|
+
if (undefined === data)
|
|
77
|
+
throw new IModelError(DbResult.BE_SQLITE_ERROR, "Flatbuffer data required for update by id");
|
|
78
|
+
props = this.iModel.elements.getElementProps(propsOrId);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
props = propsOrId;
|
|
82
|
+
}
|
|
83
|
+
if (undefined === props.id)
|
|
84
|
+
throw new IModelError(DbResult.BE_SQLITE_ERROR, "Element id required for update");
|
|
85
|
+
await this.iModel.locks.acquireLocks({ exclusive: props.id });
|
|
86
|
+
if (undefined !== data)
|
|
87
|
+
props.elementGeometryBuilderParams = { entryArray: data.entryArray, viewIndependent: data.viewIndependent };
|
|
88
|
+
this.iModel.elements.updateElement(props);
|
|
89
|
+
}
|
|
90
|
+
async requestElementGeometry(elementId, filter) {
|
|
91
|
+
let accepted;
|
|
92
|
+
const onGeometry = (info) => {
|
|
93
|
+
accepted = info;
|
|
94
|
+
if (undefined !== filter) {
|
|
95
|
+
let numDisplayable = 0;
|
|
96
|
+
for (const entry of info.entryArray) {
|
|
97
|
+
if (!ElementGeometry.isDisplayableEntry(entry))
|
|
98
|
+
continue;
|
|
99
|
+
numDisplayable++;
|
|
100
|
+
if (filter.maxDisplayable && numDisplayable > filter.maxDisplayable) {
|
|
101
|
+
accepted = undefined;
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
if (filter.reject && filter.reject.some((opcode) => entry.opcode === opcode)) {
|
|
105
|
+
accepted = undefined;
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
if (filter.accept && !filter.accept.some((opcode) => entry.opcode === opcode)) {
|
|
109
|
+
accepted = undefined;
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
if (undefined === filter.geometry)
|
|
113
|
+
continue;
|
|
114
|
+
let entityType;
|
|
115
|
+
if (filter.geometry.curves && !(filter.geometry.surfaces || filter.geometry.solids))
|
|
116
|
+
entityType = ElementGeometry.isCurve(entry) ? BRepEntity.Type.Wire : undefined; // skip surface/solid opcodes...
|
|
117
|
+
else
|
|
118
|
+
entityType = ElementGeometry.getBRepEntityType(entry);
|
|
119
|
+
switch (entityType) {
|
|
120
|
+
case BRepEntity.Type.Wire:
|
|
121
|
+
if (!filter.geometry.curves)
|
|
122
|
+
accepted = undefined;
|
|
123
|
+
break;
|
|
124
|
+
case BRepEntity.Type.Sheet:
|
|
125
|
+
if (!filter.geometry.surfaces)
|
|
126
|
+
accepted = undefined;
|
|
127
|
+
break;
|
|
128
|
+
case BRepEntity.Type.Solid:
|
|
129
|
+
if (!filter.geometry.solids)
|
|
130
|
+
accepted = undefined;
|
|
131
|
+
break;
|
|
132
|
+
default:
|
|
133
|
+
accepted = undefined;
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
if (undefined === accepted)
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
const requestProps = {
|
|
142
|
+
onGeometry,
|
|
143
|
+
elementId,
|
|
144
|
+
};
|
|
145
|
+
if (IModelStatus.Success !== this.iModel.elementGeometryRequest(requestProps))
|
|
146
|
+
return undefined;
|
|
147
|
+
return accepted;
|
|
148
|
+
}
|
|
149
|
+
async updateProjectExtents(extents) {
|
|
150
|
+
const newExtents = new Range3d();
|
|
151
|
+
newExtents.setFromJSON(extents);
|
|
152
|
+
if (newExtents.isNull)
|
|
153
|
+
throw new IModelError(DbResult.BE_SQLITE_ERROR, "Invalid project extents");
|
|
154
|
+
await this.iModel.acquireSchemaLock();
|
|
155
|
+
this.iModel.updateProjectExtents(newExtents);
|
|
156
|
+
// Set source from calculated to user so connectors preserve the change.
|
|
157
|
+
const unitsProps = { name: "Units", namespace: "dgn_Db" };
|
|
158
|
+
const unitsStr = this.iModel.queryFilePropertyString(unitsProps);
|
|
159
|
+
if (undefined !== unitsStr) {
|
|
160
|
+
const unitsVal = JSON.parse(unitsStr);
|
|
161
|
+
const calculated = 1;
|
|
162
|
+
if (calculated !== unitsVal.extentsSource) {
|
|
163
|
+
unitsVal.extentsSource = calculated;
|
|
164
|
+
this.iModel.saveFileProperty(unitsProps, JSON.stringify(unitsVal));
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
async updateEcefLocation(ecefLocation) {
|
|
169
|
+
await this.iModel.acquireSchemaLock();
|
|
170
|
+
// Clear GCS that caller already determined was invalid...
|
|
171
|
+
this.iModel.deleteFileProperty({ name: "DgnGCS", namespace: "dgn_Db" });
|
|
172
|
+
const newEcefLocation = new EcefLocation(ecefLocation);
|
|
173
|
+
this.iModel.updateEcefLocation(newEcefLocation);
|
|
174
|
+
}
|
|
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AC3B,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.updateEcefLocation(newEcefLocation);\n }\n}\n"]}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module Editing
|
|
3
|
+
*/
|
|
4
|
+
import { IModelDb } from "@itwin/core-backend";
|
|
5
|
+
import { EditCommandIpc } from "@itwin/editor-common";
|
|
6
|
+
/** @beta */
|
|
7
|
+
export type EditCommandType = typeof EditCommand;
|
|
8
|
+
/**
|
|
9
|
+
* An EditCommand performs an editing action on the backend.
|
|
10
|
+
* Any writes to the iModel in an editing session should be done from an EditCommand:
|
|
11
|
+
* - All changes to an iModel are made within a transaction (Txn).
|
|
12
|
+
* - Calling SaveChanges ends the current Txn and starts a new one.
|
|
13
|
+
* - 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.
|
|
14
|
+
* - Because there is currently no way to enforce this, it is important that all applications follow this rule.
|
|
15
|
+
* EditCommands are usually paired with and driven by EditTools on the frontend that can either be interactive tools or immediate tools.
|
|
16
|
+
* Interactive EditTools:
|
|
17
|
+
* - Can be a [PrimitiveTool]($frontend).
|
|
18
|
+
* - Can be an [InputCollector]($frontend) in special cases such as [EditManipulator.HandleTool]($frontend).
|
|
19
|
+
* - Should not be a [ViewTool]($frontend), these should never write changes to the iModel.
|
|
20
|
+
* Immediate EditTools:
|
|
21
|
+
* - As direct subclasses of [Tool]($frontend) that perform their function without further input or becoming the active tool,
|
|
22
|
+
* they potentially leave the current [PrimitiveTool]($frontend) in an invalid state.
|
|
23
|
+
* - To avoid issues, immediate tools that start an EditCommand must call [ToolAdmin.restartPrimitiveTool]($frontend) when they complete.
|
|
24
|
+
* EditCommands have a *commandId* that uniquely identifies them, so they can be found via a lookup in the [[EditCommandAdmin]].
|
|
25
|
+
* Each EditCommand must be registered in the [[EditCommandAdmin]] with [[EditCommandAdmin.register]] or [[EditCommandAdmin.registerModule]].
|
|
26
|
+
* Every time an EditCommand runs, a new instance of (a subclass of) this class is created.
|
|
27
|
+
* @see [[BasicManipulationCommand]] for an example EditCommand.
|
|
28
|
+
* @beta
|
|
29
|
+
*/
|
|
30
|
+
export declare class EditCommand implements EditCommandIpc {
|
|
31
|
+
/** The unique string that identifies this EditCommand class. This must be overridden in every subclass. */
|
|
32
|
+
static commandId: string;
|
|
33
|
+
static version: string;
|
|
34
|
+
/** The iModel this EditCommand may modify. */
|
|
35
|
+
readonly iModel: IModelDb;
|
|
36
|
+
constructor(iModel: IModelDb, ..._args: any[]);
|
|
37
|
+
get ctor(): EditCommandType;
|
|
38
|
+
onStart(): Promise<any>;
|
|
39
|
+
ping(): Promise<{
|
|
40
|
+
commandId: string;
|
|
41
|
+
version: string;
|
|
42
|
+
[propName: string]: any;
|
|
43
|
+
}>;
|
|
44
|
+
private onFinish;
|
|
45
|
+
/**
|
|
46
|
+
* Called when another EditCommand wishes to become the active EditCommand.
|
|
47
|
+
* Subclasses should complete and save their work as soon as possible and then return "done".
|
|
48
|
+
* If it is not currently possible to finish, return any string other than "done" and the other EditCommand will have to wait and retry,
|
|
49
|
+
* potentially showing the returned string to the user.
|
|
50
|
+
*/
|
|
51
|
+
requestFinish(): Promise<"done" | string>;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* EditCommandAdmin holds a mapping between commandIds and their corresponding [[EditCommand]] class. This provides the mechanism to
|
|
55
|
+
* run EditCommands by commandId.
|
|
56
|
+
* It also keeps track of the currently active EditCommand. When a new EditCommand attempts to start, the active EditCommand
|
|
57
|
+
* is requested to finish, and the new EditCommand cannot start until it does.
|
|
58
|
+
* @beta
|
|
59
|
+
*/
|
|
60
|
+
export declare class EditCommandAdmin {
|
|
61
|
+
static readonly commands: Map<string, typeof EditCommand>;
|
|
62
|
+
private static _activeCommand?;
|
|
63
|
+
private static _isInitialized;
|
|
64
|
+
static get activeCommand(): EditCommand | undefined;
|
|
65
|
+
/** If any command is currently active, wait for it to finish.
|
|
66
|
+
* Afterward, no command will be active.
|
|
67
|
+
* This method is invoked by [[runCommand]] before starting a new command.
|
|
68
|
+
* @throws BackendError if the command fails to finish.
|
|
69
|
+
*/
|
|
70
|
+
static finishCommand(): Promise<void>;
|
|
71
|
+
/** Start running the specified command.
|
|
72
|
+
* The new command will not begin running until the currently-active command (if any) finishes.
|
|
73
|
+
* Afterward, the new command becomes the active command.
|
|
74
|
+
* @throws BackendError if the currently-active command fails to finish.
|
|
75
|
+
*/
|
|
76
|
+
static runCommand(cmd: EditCommand): Promise<any>;
|
|
77
|
+
/**
|
|
78
|
+
* Un-register a previously registered EditCommand class.
|
|
79
|
+
* @param commandId the commandId of a previously registered EditCommand to unRegister.
|
|
80
|
+
*/
|
|
81
|
+
static unRegister(commandId: string): void;
|
|
82
|
+
/**
|
|
83
|
+
* Register an EditCommand class. This establishes a connection between the commandId of the class and the class itself.
|
|
84
|
+
* @param commandType the subclass of Tool to register.
|
|
85
|
+
*/
|
|
86
|
+
static register(commandType: EditCommandType): void;
|
|
87
|
+
/**
|
|
88
|
+
* Register all the EditCommand classes found in a module.
|
|
89
|
+
* @param modelObj the module to search for subclasses of EditCommand.
|
|
90
|
+
*/
|
|
91
|
+
static registerModule(moduleObj: any): void;
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=EditCommand.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EditCommand.d.ts","sourceRoot":"","sources":["../../src/EditCommand.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,EAAE,QAAQ,EAAuB,MAAM,qBAAqB,CAAC;AAEpE,OAAO,EAAE,cAAc,EAA+B,MAAM,sBAAsB,CAAC;AAEnF,YAAY;AACZ,MAAM,MAAM,eAAe,GAAG,OAAO,WAAW,CAAC;AAEjD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,WAAY,YAAW,cAAc;IAChD,2GAA2G;IAC3G,OAAc,SAAS,SAAM;IAC7B,OAAc,OAAO,SAAW;IAEhC,8CAA8C;IAC9C,SAAgB,MAAM,EAAE,QAAQ,CAAC;gBAEd,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,GAAG,EAAE;IAGpD,IAAW,IAAI,IAAI,eAAe,CAEjC;IAEY,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC;IAEvB,IAAI,IAAI,OAAO,CAAC;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,CAAC;IAK7F,OAAO,CAAC,QAAQ;IAEhB;;;;;OAKG;IACU,aAAa,IAAI,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC;CAIvD;AA8BD;;;;;;GAMG;AACH,qBAAa,gBAAgB;IAC3B,gBAAuB,QAAQ,kCAAsC;IAErE,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC,CAAc;IAC5C,OAAO,CAAC,MAAM,CAAC,cAAc,CAAS;IACtC,WAAkB,aAAa,4BAAkC;IAEjE;;;;OAIG;WACiB,aAAa;IASjC;;;;OAIG;WACiB,UAAU,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC;IAM9D;;;OAGG;WACW,UAAU,CAAC,SAAS,EAAE,MAAM;IAI1C;;;OAGG;WACW,QAAQ,CAAC,WAAW,EAAE,eAAe;IAWnD;;;OAGG;WACW,cAAc,CAAC,SAAS,EAAE,GAAG;CAY5C"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
/** @packageDocumentation
|
|
6
|
+
* @module Editing
|
|
7
|
+
*/
|
|
8
|
+
import { IModelStatus } from "@itwin/core-bentley";
|
|
9
|
+
import { IModelDb, IpcHandler, IpcHost } from "@itwin/core-backend";
|
|
10
|
+
import { BackendError, IModelError } from "@itwin/core-common";
|
|
11
|
+
import { editorIpcStrings } from "@itwin/editor-common";
|
|
12
|
+
/**
|
|
13
|
+
* An EditCommand performs an editing action on the backend.
|
|
14
|
+
* Any writes to the iModel in an editing session should be done from an EditCommand:
|
|
15
|
+
* - All changes to an iModel are made within a transaction (Txn).
|
|
16
|
+
* - Calling SaveChanges ends the current Txn and starts a new one.
|
|
17
|
+
* - 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.
|
|
18
|
+
* - Because there is currently no way to enforce this, it is important that all applications follow this rule.
|
|
19
|
+
* EditCommands are usually paired with and driven by EditTools on the frontend that can either be interactive tools or immediate tools.
|
|
20
|
+
* Interactive EditTools:
|
|
21
|
+
* - Can be a [PrimitiveTool]($frontend).
|
|
22
|
+
* - Can be an [InputCollector]($frontend) in special cases such as [EditManipulator.HandleTool]($frontend).
|
|
23
|
+
* - Should not be a [ViewTool]($frontend), these should never write changes to the iModel.
|
|
24
|
+
* Immediate EditTools:
|
|
25
|
+
* - As direct subclasses of [Tool]($frontend) that perform their function without further input or becoming the active tool,
|
|
26
|
+
* they potentially leave the current [PrimitiveTool]($frontend) in an invalid state.
|
|
27
|
+
* - To avoid issues, immediate tools that start an EditCommand must call [ToolAdmin.restartPrimitiveTool]($frontend) when they complete.
|
|
28
|
+
* EditCommands have a *commandId* that uniquely identifies them, so they can be found via a lookup in the [[EditCommandAdmin]].
|
|
29
|
+
* Each EditCommand must be registered in the [[EditCommandAdmin]] with [[EditCommandAdmin.register]] or [[EditCommandAdmin.registerModule]].
|
|
30
|
+
* Every time an EditCommand runs, a new instance of (a subclass of) this class is created.
|
|
31
|
+
* @see [[BasicManipulationCommand]] for an example EditCommand.
|
|
32
|
+
* @beta
|
|
33
|
+
*/
|
|
34
|
+
export class EditCommand {
|
|
35
|
+
/** The unique string that identifies this EditCommand class. This must be overridden in every subclass. */
|
|
36
|
+
static commandId = "";
|
|
37
|
+
static version = "1.0.0";
|
|
38
|
+
/** The iModel this EditCommand may modify. */
|
|
39
|
+
iModel;
|
|
40
|
+
constructor(iModel, ..._args) {
|
|
41
|
+
this.iModel = iModel;
|
|
42
|
+
}
|
|
43
|
+
get ctor() {
|
|
44
|
+
return this.constructor;
|
|
45
|
+
}
|
|
46
|
+
async onStart() { }
|
|
47
|
+
async ping() {
|
|
48
|
+
return { version: this.ctor.version, commandId: this.ctor.commandId };
|
|
49
|
+
}
|
|
50
|
+
// This is only temporary to find subclasses that used to implement this method. It was made async and renamed `requestFinish`.
|
|
51
|
+
onFinish() { }
|
|
52
|
+
/**
|
|
53
|
+
* Called when another EditCommand wishes to become the active EditCommand.
|
|
54
|
+
* Subclasses should complete and save their work as soon as possible and then return "done".
|
|
55
|
+
* If it is not currently possible to finish, return any string other than "done" and the other EditCommand will have to wait and retry,
|
|
56
|
+
* potentially showing the returned string to the user.
|
|
57
|
+
*/
|
|
58
|
+
async requestFinish() {
|
|
59
|
+
this.onFinish(); // TODO: temporary, remove
|
|
60
|
+
return "done";
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
class EditorAppHandler extends IpcHandler {
|
|
64
|
+
get channelName() { return editorIpcStrings.channel; }
|
|
65
|
+
async startCommand(commandId, iModelKey, ...args) {
|
|
66
|
+
await EditCommandAdmin.finishCommand();
|
|
67
|
+
if (commandId === "") // just kill active command, don't start another
|
|
68
|
+
return;
|
|
69
|
+
const commandClass = EditCommandAdmin.commands.get(commandId);
|
|
70
|
+
if (undefined === commandClass)
|
|
71
|
+
throw new IModelError(IModelStatus.NotRegistered, `Command not registered [${commandId}]`);
|
|
72
|
+
return EditCommandAdmin.runCommand(new commandClass(IModelDb.findByKey(iModelKey), ...args));
|
|
73
|
+
}
|
|
74
|
+
async callMethod(methodName, ...args) {
|
|
75
|
+
const cmd = EditCommandAdmin.activeCommand;
|
|
76
|
+
if (!cmd)
|
|
77
|
+
throw new IModelError(IModelStatus.NoActiveCommand, `No active command`);
|
|
78
|
+
const func = cmd[methodName];
|
|
79
|
+
if (typeof func !== "function")
|
|
80
|
+
throw new IModelError(IModelStatus.FunctionNotFound, `Method ${methodName} not found on ${cmd.ctor.commandId}`);
|
|
81
|
+
return func.call(cmd, ...args);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* EditCommandAdmin holds a mapping between commandIds and their corresponding [[EditCommand]] class. This provides the mechanism to
|
|
86
|
+
* run EditCommands by commandId.
|
|
87
|
+
* It also keeps track of the currently active EditCommand. When a new EditCommand attempts to start, the active EditCommand
|
|
88
|
+
* is requested to finish, and the new EditCommand cannot start until it does.
|
|
89
|
+
* @beta
|
|
90
|
+
*/
|
|
91
|
+
export class EditCommandAdmin {
|
|
92
|
+
static commands = new Map();
|
|
93
|
+
static _activeCommand;
|
|
94
|
+
static _isInitialized = false;
|
|
95
|
+
static get activeCommand() { return this._activeCommand; }
|
|
96
|
+
/** If any command is currently active, wait for it to finish.
|
|
97
|
+
* Afterward, no command will be active.
|
|
98
|
+
* This method is invoked by [[runCommand]] before starting a new command.
|
|
99
|
+
* @throws BackendError if the command fails to finish.
|
|
100
|
+
*/
|
|
101
|
+
static async finishCommand() {
|
|
102
|
+
if (this._activeCommand) {
|
|
103
|
+
const finished = await this._activeCommand.requestFinish();
|
|
104
|
+
if ("done" !== finished)
|
|
105
|
+
throw new BackendError(IModelStatus.ServerTimeout, editorIpcStrings.commandBusy, finished);
|
|
106
|
+
}
|
|
107
|
+
this._activeCommand = undefined;
|
|
108
|
+
}
|
|
109
|
+
/** Start running the specified command.
|
|
110
|
+
* The new command will not begin running until the currently-active command (if any) finishes.
|
|
111
|
+
* Afterward, the new command becomes the active command.
|
|
112
|
+
* @throws BackendError if the currently-active command fails to finish.
|
|
113
|
+
*/
|
|
114
|
+
static async runCommand(cmd) {
|
|
115
|
+
await this.finishCommand();
|
|
116
|
+
this._activeCommand = cmd;
|
|
117
|
+
return cmd.onStart();
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Un-register a previously registered EditCommand class.
|
|
121
|
+
* @param commandId the commandId of a previously registered EditCommand to unRegister.
|
|
122
|
+
*/
|
|
123
|
+
static unRegister(commandId) {
|
|
124
|
+
this.commands.delete(commandId);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Register an EditCommand class. This establishes a connection between the commandId of the class and the class itself.
|
|
128
|
+
* @param commandType the subclass of Tool to register.
|
|
129
|
+
*/
|
|
130
|
+
static register(commandType) {
|
|
131
|
+
if (!this._isInitialized) {
|
|
132
|
+
this._isInitialized = true;
|
|
133
|
+
if (!IpcHost.isValid)
|
|
134
|
+
throw new Error("Edit Commands require IpcHost");
|
|
135
|
+
EditorAppHandler.register();
|
|
136
|
+
}
|
|
137
|
+
if (commandType.commandId.length !== 0)
|
|
138
|
+
this.commands.set(commandType.commandId, commandType);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Register all the EditCommand classes found in a module.
|
|
142
|
+
* @param modelObj the module to search for subclasses of EditCommand.
|
|
143
|
+
*/
|
|
144
|
+
static registerModule(moduleObj) {
|
|
145
|
+
let foundOne = false;
|
|
146
|
+
for (const thisMember in moduleObj) { // eslint-disable-line guard-for-in
|
|
147
|
+
const thisCmd = moduleObj[thisMember];
|
|
148
|
+
if (thisCmd.prototype instanceof EditCommand) {
|
|
149
|
+
foundOne = true;
|
|
150
|
+
this.register(thisCmd);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (!foundOne)
|
|
154
|
+
throw new Error(`no EditCommands found - are you sure this is a module? Maybe you meant to call "register"?`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
//# sourceMappingURL=EditCommand.js.map
|
|
@@ -0,0 +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,E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AAC,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"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from "./EditCommand";
|
|
2
|
+
export * from "./EditBuiltInCommand";
|
|
3
|
+
/** @docs-package-description
|
|
4
|
+
* The editor-backend package contains backend functionality for editing iModels.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* @docs-group-description Editing
|
|
8
|
+
* Classes containing functionality for editing iModels on the backend.
|
|
9
|
+
*/
|
|
10
|
+
//# sourceMappingURL=editor-backend.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"editor-backend.d.ts","sourceRoot":"","sources":["../../src/editor-backend.ts"],"names":[],"mappings":"AAIA,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC;AAErC;;GAEG;AAEH;;;GAGG"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
export * from "./EditCommand";
|
|
6
|
+
export * from "./EditBuiltInCommand";
|
|
7
|
+
/** @docs-package-description
|
|
8
|
+
* The editor-backend package contains backend functionality for editing iModels.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* @docs-group-description Editing
|
|
12
|
+
* Classes containing functionality for editing iModels on the backend.
|
|
13
|
+
*/
|
|
14
|
+
//# sourceMappingURL=editor-backend.js.map
|
|
@@ -0,0 +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"]}
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/editor-backend",
|
|
3
|
-
"version": "5.0.0-dev.
|
|
3
|
+
"version": "5.0.0-dev.92",
|
|
4
4
|
"description": "iTwin.js editor backend",
|
|
5
5
|
"main": "lib/cjs/editor-backend.js",
|
|
6
|
+
"module": "lib/esm/editor-backend.js",
|
|
6
7
|
"typings": "lib/cjs/editor-backend",
|
|
7
8
|
"license": "MIT",
|
|
8
9
|
"engines": {
|
|
@@ -25,10 +26,10 @@
|
|
|
25
26
|
"url": "http://www.bentley.com"
|
|
26
27
|
},
|
|
27
28
|
"peerDependencies": {
|
|
28
|
-
"@itwin/core-backend": "
|
|
29
|
-
"@itwin/core-
|
|
30
|
-
"@itwin/core-
|
|
31
|
-
"@itwin/core-geometry": "
|
|
29
|
+
"@itwin/core-backend": "5.0.0-dev.92",
|
|
30
|
+
"@itwin/core-common": "5.0.0-dev.92",
|
|
31
|
+
"@itwin/core-bentley": "5.0.0-dev.92",
|
|
32
|
+
"@itwin/core-geometry": "5.0.0-dev.92"
|
|
32
33
|
},
|
|
33
34
|
"//devDependencies": [
|
|
34
35
|
"NOTE: All peerDependencies should also be listed as devDependencies since peerDependencies are not considered by npm install",
|
|
@@ -37,21 +38,22 @@
|
|
|
37
38
|
"devDependencies": {
|
|
38
39
|
"@itwin/eslint-plugin": "5.0.0-dev.1",
|
|
39
40
|
"eslint": "^9.13.0",
|
|
40
|
-
"rimraf": "^
|
|
41
|
+
"rimraf": "^6.0.1",
|
|
41
42
|
"typescript": "~5.6.2",
|
|
42
|
-
"@itwin/build-tools": "5.0.0-dev.
|
|
43
|
-
"@itwin/core-
|
|
44
|
-
"@itwin/core-bentley": "5.0.0-dev.
|
|
45
|
-
"@itwin/core-common": "5.0.0-dev.
|
|
46
|
-
"@itwin/core-
|
|
43
|
+
"@itwin/build-tools": "5.0.0-dev.92",
|
|
44
|
+
"@itwin/core-geometry": "5.0.0-dev.92",
|
|
45
|
+
"@itwin/core-bentley": "5.0.0-dev.92",
|
|
46
|
+
"@itwin/core-common": "5.0.0-dev.92",
|
|
47
|
+
"@itwin/core-backend": "5.0.0-dev.92"
|
|
47
48
|
},
|
|
48
49
|
"dependencies": {
|
|
49
|
-
"@itwin/editor-common": "5.0.0-dev.
|
|
50
|
+
"@itwin/editor-common": "5.0.0-dev.92"
|
|
50
51
|
},
|
|
51
52
|
"scripts": {
|
|
52
|
-
"build": "npm run -s build:cjs",
|
|
53
|
+
"build": "npm run -s build:cjs && npm run -s build:esm",
|
|
53
54
|
"build:cjs": "tsc 1>&2 --outDir lib/cjs",
|
|
54
|
-
"
|
|
55
|
+
"build:esm": "tsc 1>&2 --module ES2022 --outDir lib/esm",
|
|
56
|
+
"clean": "rimraf -g lib .rush/temp/package-deps*.json",
|
|
55
57
|
"docs": "betools docs --json=../../generated-docs/editor/editor-backend/file.json --tsIndexFile=./editor-backend.ts --onlyJson",
|
|
56
58
|
"extract-api": "betools extract-api --entry=editor-backend",
|
|
57
59
|
"lint": "eslint --max-warnings 0 ./src/**/*.ts 1>&2",
|