UNPKG

@itwin/core-common

Version:

iTwin.js components common to frontend and backend

119 lines 5.84 kB
"use strict"; /*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ /** @packageDocumentation * @module DisplayStyles */ Object.defineProperty(exports, "__esModule", { value: true }); exports.SubCategoryOverride = void 0; const core_bentley_1 = require("@itwin/core-bentley"); const ColorDef_1 = require("./ColorDef"); const SubCategoryAppearance_1 = require("./SubCategoryAppearance"); /** Overrides selected aspects of a [[SubCategoryAppearance]] in the context of a [[DisplayStyleState]]. * When determining how geometry belonging to a [[SubCategory]] will appear when drawn within a view: * 1. The base [[SubCategoryAppearance]] associated with that subcategory is obtained. * 2. The [[SubCategoryOverride]] associated with that subcategory in the [[DisplayStyleState]] is obtained. * 3. Any aspects of the appearance overridden by the SubCategoryOverride are replaced with the values from the SubCategoryOverride. * An aspect is overridden by virtue of not being set to "undefined" in the SubCategoryOverride. * @see [[DisplayStyleState.overrideSubCategory]] * @public */ class SubCategoryOverride { /** See [[SubCategoryAppearance.color]] */ color; /** See [[SubCategoryAppearance.invisible]] */ invisible; /** See [[SubCategoryAppearance.weight]] */ weight; /** @internal Overriding with arbitrary custom line style is not supported - overriding with LinePixels enum could be. */ style; /** See [[SubCategoryAppearance.priority]] */ priority; /** See [[SubCategoryAppearance.materialId]] */ material; /** See [[SubCategoryAppearance.transparency]] */ transparency; /** Returns true if any aspect of the appearance is overridden (i.e., if any member is not undefined). */ get anyOverridden() { return undefined !== this.invisible || undefined !== this.color || undefined !== this.weight || undefined !== this.style || undefined !== this.priority || undefined !== this.material || undefined !== this.transparency; } /** Returns a SubCategoryAppearance overridden to match the properties defined by this SubCategoryOverride. */ override(appearance) { if (!this.anyOverridden) return appearance; const props = appearance.toJSON(); const ovrProps = this.toJSON(); if (undefined !== ovrProps.invisible) props.invisible = ovrProps.invisible; if (undefined !== ovrProps.weight) props.weight = ovrProps.weight; if (undefined !== ovrProps.style) props.style = ovrProps.style; if (undefined !== ovrProps.material) props.material = ovrProps.material; if (undefined !== ovrProps.priority) props.priority = ovrProps.priority; if (undefined !== ovrProps.transp) props.transp = ovrProps.transp; if (undefined !== ovrProps.color) props.color = ovrProps.color; return new SubCategoryAppearance_1.SubCategoryAppearance(props); } /** Convert this SubCategoryOverride to a JSON object * @internal */ toJSON() { const props = {}; if (undefined !== this.invisible) props.invisible = this.invisible; if (undefined !== this.weight) props.weight = this.weight; if (undefined !== this.style) props.style = this.style; if (undefined !== this.material) props.material = this.material; if (undefined !== this.priority) props.priority = this.priority; if (undefined !== this.transparency) props.transp = this.transparency; if (undefined !== this.color) props.color = this.color.toJSON(); return props; } /** Perform equality comparison against another SubCategoryOverride. */ equals(other) { if (this.invisible !== other.invisible || this.weight !== other.weight || this.style !== other.style || this.priority !== other.priority || this.material !== other.material || this.transparency !== other.transparency) return false; if (undefined !== this.color && undefined !== other.color) return this.color.tbgr === other.color.tbgr; else return undefined === this.color && undefined === other.color; } /** Create a new SubCategoryOverride from a JSON object */ static fromJSON(json) { return undefined !== json ? new SubCategoryOverride(json) : this.defaults; } constructor(props) { if (undefined !== props.invisible) this.invisible = core_bentley_1.JsonUtils.asBool(props.invisible); if (undefined !== props.color) this.color = ColorDef_1.ColorDef.fromJSON(props.color); if (undefined !== props.weight) this.weight = core_bentley_1.JsonUtils.asInt(props.weight); if (undefined !== props.style) this.style = core_bentley_1.Id64.fromJSON(props.style); if (undefined !== props.material) this.material = core_bentley_1.Id64.fromJSON(props.material); if (undefined !== props.priority) this.priority = core_bentley_1.JsonUtils.asInt(props.priority); if (undefined !== props.transp) this.transparency = core_bentley_1.JsonUtils.asDouble(props.transp); } /** A default SubCategoryOverride which overrides nothing. */ static defaults = new SubCategoryOverride({}); } exports.SubCategoryOverride = SubCategoryOverride; //# sourceMappingURL=SubCategoryOverride.js.map