@itwin/core-backend 5.13.0-dev.12 → 5.13.0-dev.14

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.
@@ -3,11 +3,11 @@
3
3
  * See LICENSE.md in the project root for license terms and full copyright notice.
4
4
  *--------------------------------------------------------------------------------------------*/
5
5
  import { assert, expect } from "chai";
6
- import { DbResult, Id64 } from "@itwin/core-bentley";
6
+ import { DbResult, Id64, OpenMode } from "@itwin/core-bentley";
7
7
  import { EditTxn, withEditTxn } from "../../EditTxn";
8
8
  import { BriefcaseIdValue, Code, ColorDef, ElementGeometry, IModel, QueryRowFormat, SubCategoryAppearance, } from "@itwin/core-common";
9
9
  import { Angle, Arc3d, Cone, IModelJson as GeomJson, LineSegment3d, Point2d, Point3d, Range2d, Range3d } from "@itwin/core-geometry";
10
- import { _nativeDb, CategorySelector, DefinitionModel, DisplayStyle2d, DisplayStyle3d, DrawingCategory, DrawingViewDefinition, IModelDb, IModelJsFs, ModelSelector, OrthographicViewDefinition, PhysicalModel, PhysicalObject, SnapshotDb, SpatialCategory, SpatialViewDefinition } from "../../core-backend";
10
+ import { _nativeDb, CategorySelector, ChannelControl, DefinitionModel, DisplayStyle2d, DisplayStyle3d, DrawingCategory, DrawingViewDefinition, GeometricElement3d, IModelDb, IModelJsFs, ModelSelector, OrthographicViewDefinition, PhysicalModel, PhysicalObject, SnapshotDb, SpatialCategory, SpatialViewDefinition, StandaloneDb } from "../../core-backend";
11
11
  import { IModelTestUtils } from "../IModelTestUtils";
12
12
  import { EntityClass, RelationshipClass } from "@itwin/ecschema-metadata";
13
13
  function verifyPrimitiveBase(actualValue, expectedValue) {
@@ -878,6 +878,84 @@ describe("Element and ElementAspect roundtrip test for all type of properties",
878
878
  testBox({ baseOriginX: 5 }, 5);
879
879
  testBox({ originX: 2, baseOriginX: 4 }, 2);
880
880
  });
881
+ it("Does not deserialize an absent placement, but preserves an origin without a bbox", async () => {
882
+ const imodelPath = IModelTestUtils.prepareOutputFile(subDirName, "roundtrip_placement_without_bbox.bim");
883
+ let imodel = IModelTestUtils.createSnapshotFromSeed(imodelPath, iModelPath);
884
+ const { noPlacementId, originOnlyId } = withEditTxn(imodel, (txn) => {
885
+ const modelId = PhysicalModel.insert(txn, IModelDb.rootSubjectId, "model");
886
+ const categoryId = SpatialCategory.insert(txn, IModelDb.dictionaryId, "model", {});
887
+ const baseProps = {
888
+ classFullName: PhysicalObject.classFullName,
889
+ code: Code.createEmpty(),
890
+ model: modelId,
891
+ category: categoryId,
892
+ };
893
+ const originOnlyProps = {
894
+ ...baseProps,
895
+ placement: {
896
+ origin: { x: 10, y: 20, z: 30 },
897
+ angles: { yaw: 0, pitch: 0, roll: 0 },
898
+ },
899
+ };
900
+ return {
901
+ noPlacementId: txn.insertElement(baseProps),
902
+ originOnlyId: txn.insertElement(originOnlyProps),
903
+ };
904
+ });
905
+ imodel.close();
906
+ imodel = SnapshotDb.openFile(imodelPath);
907
+ const noPlacement = imodel.elements.getElementProps({ id: noPlacementId });
908
+ assert.isUndefined(noPlacement.placement);
909
+ const noPlacementElement = imodel.elements.getElement(noPlacementId, PhysicalObject);
910
+ assert.isUndefined(noPlacementElement.toJSON().placement);
911
+ const writableImodel = StandaloneDb.openFile(imodelPath, OpenMode.ReadWrite);
912
+ writableImodel.channels.addAllowedChannel(ChannelControl.sharedChannelName);
913
+ withEditTxn(writableImodel, (txn) => txn.updateElement(noPlacementElement.toJSON()));
914
+ writableImodel.close();
915
+ imodel.close();
916
+ imodel = SnapshotDb.openFile(imodelPath);
917
+ const reloadedNoPlacement = imodel.elements.getElement(noPlacementId, PhysicalObject);
918
+ assert.isUndefined(reloadedNoPlacement.toJSON().placement);
919
+ reloadedNoPlacement.placement.origin.x = 10;
920
+ assert.deepEqual(reloadedNoPlacement.toJSON().placement?.origin, { x: 10, y: 0, z: 0 });
921
+ assert.isUndefined(imodel.elements.getElementProps({ id: noPlacementId }).placement);
922
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
923
+ const spatialIndexCount = imodel.withPreparedStatement("SELECT COUNT(*) FROM bis.SpatialIndex WHERE ECInstanceId=?", (stmt) => {
924
+ stmt.bindId(1, noPlacementId);
925
+ assert.equal(stmt.step(), DbResult.BE_SQLITE_ROW);
926
+ return stmt.getValue(0).getInteger();
927
+ });
928
+ assert.equal(spatialIndexCount, 0);
929
+ const originOnly = imodel.elements.getElementProps({ id: originOnlyId });
930
+ assert.deepEqual(originOnly.placement?.origin, [10, 20, 30]);
931
+ assert.isDefined(originOnly.placement);
932
+ const originOnlyElement = imodel.elements.getElement(originOnlyId, PhysicalObject);
933
+ assert.deepEqual(originOnlyElement.toJSON().placement?.origin, { x: 10, y: 20, z: 30 });
934
+ imodel.close();
935
+ });
936
+ it("Preserves a placement returned by 3d geometry deserialization", () => {
937
+ const placement = {
938
+ origin: [10, 20, 30],
939
+ angles: { yaw: 0, pitch: 0, roll: 0 },
940
+ bbox: { low: [-1, -2, -3], high: [1, 2, 3] },
941
+ };
942
+ const nativeDb = {
943
+ patchJsonProperties: (json) => json,
944
+ convertOrUpdateGeometrySource: () => ({ geom: [], placement }),
945
+ };
946
+ const row = {
947
+ classFullName: GeometricElement3d.classFullName,
948
+ id: "0x1",
949
+ model: { id: "0x1" },
950
+ codeValue: "",
951
+ codeSpec: { id: "0x0" },
952
+ codeScope: { id: "0x0" },
953
+ category: { id: "0x2" },
954
+ geometryStream: new Uint8Array([1]),
955
+ };
956
+ const props = GeometricElement3d.deserialize({ row, iModel: { [_nativeDb]: nativeDb } });
957
+ assert.deepEqual(props.placement, placement);
958
+ });
881
959
  it("Roundtrip updating properties to null", async () => {
882
960
  const testFileName = IModelTestUtils.prepareOutputFile(subDirName, "roundtrip_properties_null_update.bim");
883
961
  const imodel = IModelTestUtils.createSnapshotFromSeed(testFileName, iModelPath);