Skip to content

Commit

Permalink
Version compare change summary bounding box options (backport #6826) …
Browse files Browse the repository at this point in the history
…[release/4.7.x] (#6886)

Co-authored-by: Diego Pinate <[email protected]>
Co-authored-by: Diego Pinate <[email protected]>
Co-authored-by: Nam Le <[email protected]>
Co-authored-by: imodeljs-admin <[email protected]>
  • Loading branch information
5 people authored Jun 22, 2024
1 parent 2f7a2ea commit bab7dca
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 9 deletions.
2 changes: 2 additions & 0 deletions common/api/core-backend.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -4420,6 +4420,8 @@ export interface ProcessChangesetOptions {
// (undocumented)
tempDir?: string;
// (undocumented)
wantBoundingBoxes?: boolean;
// (undocumented)
wantChunkTraversal?: boolean;
// (undocumented)
wantParents?: boolean;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@itwin/core-backend",
"comment": "Update changed elements process options for bounding box calculations",
"type": "none"
}
],
"packageName": "@itwin/core-backend"
}
8 changes: 4 additions & 4 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
"webpack": "^5.76.0"
},
"dependencies": {
"@bentley/imodeljs-native": "4.7.27",
"@bentley/imodeljs-native": "4.7.29",
"@itwin/cloud-agnostic-core": "^2.1.0",
"@itwin/core-telemetry": "workspace:*",
"@itwin/object-storage-azure": "^2.2.2",
Expand Down
2 changes: 2 additions & 0 deletions core/backend/src/ChangedElementsDb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface ProcessChangesetOptions {
wantRelationshipCaching?: boolean;
relationshipCacheSize?: number;
wantChunkTraversal?: boolean;
wantBoundingBoxes?: boolean;
}

/** An ChangedElementsDb file
Expand Down Expand Up @@ -155,6 +156,7 @@ export class ChangedElementsDb implements IDisposable {
options.wantRelationshipCaching,
options.relationshipCacheSize,
options.wantChunkTraversal,
options.wantBoundingBoxes,
);
if (status !== DbResult.BE_SQLITE_OK)
throw new IModelError(status, "Failed to process changesets");
Expand Down
89 changes: 88 additions & 1 deletion full-stack-tests/backend/src/integration/ChangedElements.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@

import { AccessToken, DbResult, GuidString, OpenMode } from "@itwin/core-bentley";
import { IModelError, IModelVersion } from "@itwin/core-common";
import { Range3d } from "@itwin/core-geometry";
import { TestUsers, TestUtility } from "@itwin/oidc-signin-tool";
import { assert } from "chai";
import { BriefcaseManager, ChangedElementsDb, IModelHost, IModelJsFs, ProcessChangesetOptions, SnapshotDb } from "@itwin/core-backend";
import { BriefcaseManager, ChangedElementsDb, IModelDb, IModelHost, IModelJsFs, ProcessChangesetOptions, SnapshotDb } from "@itwin/core-backend";
import { ChangedElementsManager } from "@itwin/core-backend/lib/cjs/ChangedElementsManager";
import { HubWrappers } from "@itwin/core-backend/lib/cjs/test/IModelTestUtils";
import { HubUtility } from "../HubUtility";
Expand Down Expand Up @@ -191,6 +192,7 @@ describe("ChangedElements", () => {
wantParents: true,
wantPropertyChecksums: true,
wantRelationshipCaching: true,
wantBoundingBoxes: true,
};
// Get file path before processing and rolling since it requires closing the iModelDb
const iModelFilepath = iModel.pathName;
Expand Down Expand Up @@ -260,6 +262,7 @@ describe("ChangedElements", () => {
wantParents: true,
wantPropertyChecksums: true,
wantRelationshipCaching: false,
wantBoundingBoxes: true,
};
// Get file path before processing and rolling since it requires closing the iModelDb
const iModelFilepath = iModel.pathName;
Expand Down Expand Up @@ -297,4 +300,88 @@ describe("ChangedElements", () => {

newIModel.closeFile();
});

it("Test processing with and without bounding boxes", async () => {
const cacheFilePath: string = BriefcaseManager.getChangeCachePathName(testIModelId);
if (IModelJsFs.existsSync(cacheFilePath))
IModelJsFs.removeSync(cacheFilePath);

let iModel: IModelDb = await HubWrappers.downloadAndOpenCheckpoint({ accessToken, iTwinId: testITwinId, iModelId: testIModelId, asOf: IModelVersion.first().toJSON() });
const changesets = await IModelHost.hubAccess.queryChangesets({ accessToken, iModelId: testIModelId });
const startChangesetId = changesets[0].id;
const endChangesetId = changesets[changesets.length - 1].id;
assert.exists(iModel);

const filePath = ChangedElementsManager.getChangedElementsPathName(iModel.iModelId);
if (IModelJsFs.existsSync(filePath))
IModelJsFs.removeSync(filePath);

let cache = ChangedElementsDb.createDb(iModel, filePath);
assert.isDefined(cache);
// Check that the changesets have not been processed yet
assert.isFalse(cache.isProcessed(startChangesetId));
assert.isFalse(cache.isProcessed(endChangesetId));

// Try getting changed elements, should fail because we haven't processed the changesets
assert.throws(() => cache.getChangedElements(startChangesetId, endChangesetId), IModelError);

// Test processing with wantBoundingBoxes = true
const options: ProcessChangesetOptions = {
rulesetId: "Items",
startChangesetId,
endChangesetId,
wantParents: true,
wantPropertyChecksums: true,
wantRelationshipCaching: true,
wantBoundingBoxes: true,
};
// Keep path name for re-opening later
const iModelPathName = iModel.pathName;
// When processing multiple changesets, native side creates a clone to do the rolling on
let result = await cache.processChangesetsAndRoll(accessToken, iModel, options);

assert.equal(result, DbResult.BE_SQLITE_OK);
// Check that the changesets should have been processed now
assert.isTrue(cache.isProcessed(startChangesetId));
assert.isTrue(cache.isProcessed(endChangesetId));
// Try getting changed models
let models = cache.getChangedModels(startChangesetId, endChangesetId);
assert.isTrue(models !== undefined);
assert.isTrue(models!.modelIds.length !== 0);
assert.isTrue(models!.modelIds.length === models!.bboxes.length);
// We should be able to find some bounding boxes for geometric models that are not [0,0,0] due to wantBoundingBoxes = true
assert.isTrue(models!.bboxes.filter((bbox) => {
const range = Range3d.fromJSON(bbox);
return !range.isAlmostZeroX || !range.isAlmostZeroY || !range.isAlmostZeroZ;
}).length > 0);

// Re-open iModel
iModel = SnapshotDb.openFile(iModelPathName);
// Delete processed changed elements db and re-create fresh
cache.closeDb();
IModelJsFs.removeSync(filePath);
cache = ChangedElementsDb.createDb(iModel, filePath);

// Test processing with wantBoundingBoxes = false
// When processing multiple changesets, native side creates a clone to do the rolling on
result = await cache.processChangesetsAndRoll(accessToken, iModel, { ...options, wantBoundingBoxes: false });
// Check that the changesets are processed
assert.isTrue(cache.isProcessed(startChangesetId));
assert.isTrue(cache.isProcessed(endChangesetId));
// Try getting changed models
models = cache.getChangedModels(startChangesetId, endChangesetId);
assert.isTrue(models !== undefined);
assert.isTrue(models!.modelIds.length !== 0);
assert.isTrue(models!.modelIds.length === models!.bboxes.length);
// Bounding boxes should be [0,0,0] for all elements when processing with wantBoundingBoxes = false
assert.isTrue(models!.bboxes.every((bbox) => {
const range = Range3d.fromJSON(bbox);
return range.isAlmostZeroX && range.isAlmostZeroY && range.isAlmostZeroZ;
}));

// Destroy the cache
cache.closeDb();
cache.cleanCaches();
ChangedElementsManager.cleanUp();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ dependencies {
implementation 'com.google.android.material:material:1.7.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.navigation:navigation-ui:2.5.3'
implementation 'com.github.itwin:mobile-native-android:4.7.27'
implementation 'com.github.itwin:mobile-native-android:4.7.29'
implementation 'androidx.webkit:webkit:1.5.0'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@
repositoryURL = "https://github.com/iTwin/mobile-native-ios";
requirement = {
kind = exactVersion;
version = 4.7.27;
version = 4.7.29;
};
};
/* End XCRemoteSwiftPackageReference section */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@
repositoryURL = "https://github.com/iTwin/mobile-native-ios";
requirement = {
kind = exactVersion;
version = 4.7.27;
version = 4.7.29;
};
};
/* End XCRemoteSwiftPackageReference section */
Expand Down

0 comments on commit bab7dca

Please sign in to comment.