Skip to content

Commit

Permalink
Fix Viewport's never-drawn elements overriding display style's exclud…
Browse files Browse the repository at this point in the history
…ed elements (backport #6988) [release/4.7.x] (#6989)

Co-authored-by: Paul Connelly <[email protected]>
  • Loading branch information
mergify[bot] and pmconne authored Jul 18, 2024
1 parent c6399d1 commit dbf12ac
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@itwin/core-frontend",
"comment": "Fix Viewport's never-drawn elements overriding the display style's excluded elements.",
"type": "none"
}
],
"packageName": "@itwin/core-frontend"
}
8 changes: 4 additions & 4 deletions core/frontend/src/render/FeatureSymbology.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,20 @@ export namespace FeatureSymbology {
* @internal
*/
public initFromViewport(viewport: Viewport): void {
const view = viewport.view;
this._initFromView(view);

// Set the initial always/never-drawn sets. Later, initFromView can add more elements to them.
if (undefined !== viewport.neverDrawn)
this.setNeverDrawnSet(viewport.neverDrawn);

if (undefined !== viewport.alwaysDrawn)
this.setAlwaysDrawnSet(viewport.alwaysDrawn, viewport.isAlwaysDrawnExclusive);

this._initFromView(viewport.view);

viewport.addFeatureOverrides(this);
viewport.addModelSubCategoryVisibilityOverrides(this, this._modelSubCategoryOverrides);

// This will include any per-model subcategory visibility overrides added above.
this._initSubCategoryOverrides(view);
this._initSubCategoryOverrides(viewport.view);
}

private _initFromView(view: ViewState): void {
Expand Down
45 changes: 45 additions & 0 deletions core/frontend/src/test/FeatureSymbologyOverrides.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/

import { expect } from "chai";
import { testBlankViewport } from "./openBlankViewport";
import { FeatureSymbology, IModelApp, Viewport, ViewState } from "../core-frontend";
import { EmptyLocalization } from "@itwin/core-common";

describe("FeatureSymbology.Overrides", () => {
before(async () => IModelApp.startup({ localization: new EmptyLocalization() }));
after(async () => IModelApp.shutdown());

it("combines viewport's never-drawn elements with display style's excluded elements", () => {
function expectNeverDrawn(view: Viewport | ViewState, ids: string[]): void {
const ovrs = new FeatureSymbology.Overrides(view);
expect(ovrs.neverDrawn.size).to.equal(ids.length);
for (const id of ids) {
expect(ovrs.neverDrawn.hasId(id)).to.be.true;
}
}

testBlankViewport((vp) => {
expectNeverDrawn(vp.view, []);
expectNeverDrawn(vp, []);

vp.view.displayStyle.settings.addExcludedElements("0x1");
expectNeverDrawn(vp.view, ["0x1"]);
expectNeverDrawn(vp, ["0x1"]);

vp.setNeverDrawn(new Set(["0x2"]));
expectNeverDrawn(vp.view, ["0x1"]);
expectNeverDrawn(vp, ["0x1", "0x2"]);

vp.view.displayStyle.settings.dropExcludedElement("0x1");
expectNeverDrawn(vp.view, []);
expectNeverDrawn(vp, ["0x2"]);

vp.clearNeverDrawn();
expectNeverDrawn(vp.view, []);
expectNeverDrawn(vp, []);
});
});
});

0 comments on commit dbf12ac

Please sign in to comment.