@itwin/core-common
Version:
iTwin.js components common to frontend and backend
127 lines • 5.88 kB
JavaScript
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module Symbology
*/
import { Id64, JsonUtils } from "@itwin/core-bentley";
import { ColorDef } from "./ColorDef";
/** Parameters that define the way geometry on a [[SubCategory]] appears.
* SubCategoryAppearance describes the intrinsic appearance of geometry belonging to that SubCategory, independent of a particular [[ViewState]].
* Aspects of a SubCategory's appearance can be overridden in the context of a particular [[ViewState]] through the use of [[SubCategoryOverride]]s.
* @public
*/
export class SubCategoryAppearance {
/** The color of the geometry.
* @note The transparency component of the color is ignored.
* @see [[SubCategoryAppearance.transparency]].
*/
color;
/** The line width, in pixels.
* @note The renderer will clamp values to the integer range [1, 32].
*/
weight;
/** The display priority used to control which geometry draws in front of other geometry within a 2D view.
* The priority is a number in the range [-8388576,8388576].
* Where two pieces of geometry overlap, the one with the larger priority value draws on top of the one with the smaller priority.
* If they have equal priorities, the order in which they draw is undefined, and z-fighting may result.
* @note This property has no effect in 3D views unless [[PlanProjectionSettings]] are in effect.
*/
priority;
/** A value in the range [0, 1] indicating the transparency of the geometry where 0.0 means "fully opaque" and 1.0 means "fully transparent". */
transparency;
/** If true, geometry belonging to this SubCategory is not drawn. */
invisible;
/** @internal */
dontPlot;
/** @internal */
dontSnap;
/** @internal */
dontLocate;
/** The element ID of the line style used to draw curves, or an invalid ID if no line style is specified. */
styleId;
/** The element ID of the material applied to surfaces, or an invalid ID if no material is specified. */
materialId;
/** @internal */
_fillColor;
/** @internal */
_fillTransparency;
/** The fill color of geometry marked as being filled.
* @note The transparency component of the fill color is ignored.
* @see [[SubCategoryAppearance.fillTransparency]].
*/
get fillColor() { return (undefined !== this._fillColor ? this._fillColor : this.color); }
/** A value in the range [0, 1] indicating the fill transparency of the geometry where 0.0 means "fully opaque" and 1.0 means "fully transparent". */
get fillTransparency() { return (undefined !== this._fillTransparency ? this._fillTransparency : this.transparency); }
constructor(props) {
if (!props) {
this.color = ColorDef.black;
this.weight = 0;
this.priority = 0;
this.transparency = 0;
this.invisible = this.dontPlot = this.dontSnap = this.dontLocate = false;
this.styleId = Id64.invalid;
this.materialId = Id64.invalid;
return;
}
this.invisible = JsonUtils.asBool(props.invisible);
this.dontSnap = JsonUtils.asBool(props.dontSnap);
this.dontLocate = JsonUtils.asBool(props.dontLocate);
this.dontPlot = JsonUtils.asBool(props.dontPlot);
this.color = ColorDef.fromJSON(props.color);
this.weight = JsonUtils.asInt(props.weight);
this.styleId = Id64.fromJSON(props.style);
this.priority = JsonUtils.asInt(props.priority);
this.materialId = Id64.fromJSON(props.material);
this.transparency = JsonUtils.asDouble(props.transp);
if (props.fill)
this._fillColor = ColorDef.fromJSON(props.fill);
if (props.transpFill)
this._fillTransparency = JsonUtils.asDouble(props.transpFill);
}
equals(other) {
return this.invisible === other.invisible &&
this.dontPlot === other.dontPlot &&
this.dontSnap === other.dontSnap &&
this.dontLocate === other.dontLocate &&
this.color.equals(other.color) &&
this.weight === other.weight &&
this.priority === other.priority &&
this.styleId === other.styleId &&
this.materialId === other.materialId &&
this.transparency === other.transparency &&
this.fillColor.equals(other.fillColor) &&
this.fillTransparency === other.fillTransparency;
}
/** @internal */
toJSON() {
const val = { color: this.color.toJSON() };
if (this.invisible)
val.invisible = true;
if (this.dontPlot)
val.dontPlot = true;
if (this.dontSnap)
val.dontSnap = true;
if (this.dontLocate)
val.dontLocate = true;
if (0 !== this.weight)
val.weight = this.weight;
if (0 !== this.priority)
val.priority = this.priority;
if (Id64.isValid(this.styleId))
val.style = this.styleId;
if (Id64.isValid(this.materialId))
val.material = this.materialId;
if (0.0 !== this.transparency)
val.transp = this.transparency;
if (this._fillColor)
val.fill = this._fillColor.toJSON();
if (this._fillTransparency)
val.transpFill = this._fillTransparency;
return val;
}
clone() { return new SubCategoryAppearance(this.toJSON()); }
static defaults = new SubCategoryAppearance();
}
//# sourceMappingURL=SubCategoryAppearance.js.map