From dbf12acd1f7fb726c0fffb305a250d6739c85a2f Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Thu, 18 Jul 2024 18:56:56 +0000 Subject: [PATCH] Fix Viewport's never-drawn elements overriding display style's excluded elements (backport #6988) [release/4.7.x] (#6989) Co-authored-by: Paul Connelly <22944042+pmconne@users.noreply.github.com> --- ...ever-drawn-overwrite_2024-07-18-17-56.json | 10 +++++ core/frontend/src/render/FeatureSymbology.ts | 8 ++-- .../test/FeatureSymbologyOverrides.test.ts | 45 +++++++++++++++++++ 3 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 common/changes/@itwin/core-frontend/pmc-never-drawn-overwrite_2024-07-18-17-56.json create mode 100644 core/frontend/src/test/FeatureSymbologyOverrides.test.ts diff --git a/common/changes/@itwin/core-frontend/pmc-never-drawn-overwrite_2024-07-18-17-56.json b/common/changes/@itwin/core-frontend/pmc-never-drawn-overwrite_2024-07-18-17-56.json new file mode 100644 index 000000000000..50cf97e20f3b --- /dev/null +++ b/common/changes/@itwin/core-frontend/pmc-never-drawn-overwrite_2024-07-18-17-56.json @@ -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" +} \ No newline at end of file diff --git a/core/frontend/src/render/FeatureSymbology.ts b/core/frontend/src/render/FeatureSymbology.ts index 89fc51e3bda3..102d5ead9ae3 100644 --- a/core/frontend/src/render/FeatureSymbology.ts +++ b/core/frontend/src/render/FeatureSymbology.ts @@ -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 { diff --git a/core/frontend/src/test/FeatureSymbologyOverrides.test.ts b/core/frontend/src/test/FeatureSymbologyOverrides.test.ts new file mode 100644 index 000000000000..f6ad7f8e2fda --- /dev/null +++ b/core/frontend/src/test/FeatureSymbologyOverrides.test.ts @@ -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, []); + }); + }); +});