"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 Symbology
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.GeometryParams = exports.GeometryClass = exports.BackgroundFill = exports.FillDisplay = void 0;
const core_bentley_1 = require("@itwin/core-bentley");
const IModel_1 = require("./IModel");
/** Whether a closed region should be drawn for wireframe display with its internal area filled or not.
 * @public
 * @extensions
 */
var FillDisplay;
(function (FillDisplay) {
    /** don't fill, even if fill attribute is on for the viewport */
    FillDisplay[FillDisplay["Never"] = 0] = "Never";
    /** fill if the fill attribute is on for the viewport */
    FillDisplay[FillDisplay["ByView"] = 1] = "ByView";
    /** always fill, even if the fill attribute is off for the viewport */
    FillDisplay[FillDisplay["Always"] = 2] = "Always";
    /** always fill, fill will always be behind other geometry belonging to the same element.
     * @note Edge geometry is not produced for shapes with this fill type. If you want an outline, add it as separate geometry.
     */
    FillDisplay[FillDisplay["Blanking"] = 3] = "Blanking";
})(FillDisplay || (exports.FillDisplay = FillDisplay = {}));
/** Describes how a view's background color affects the interior area of a closed region.
 * @public
 * @extensions
 */
var BackgroundFill;
(function (BackgroundFill) {
    /** single color fill uses the fill color and line color to draw either a solid or outline fill */
    BackgroundFill[BackgroundFill["None"] = 0] = "None";
    /** single color fill uses the view's background color to draw a solid fill */
    BackgroundFill[BackgroundFill["Solid"] = 1] = "Solid";
    /** single color fill uses the view's background color and line color to draw an outline fill */
    BackgroundFill[BackgroundFill["Outline"] = 2] = "Outline";
})(BackgroundFill || (exports.BackgroundFill = BackgroundFill = {}));
/** Categorizes a piece of geometry within a GeometryStream. Visibility of classes of geometry can be toggled
 * within a view using [[ViewFlags]].
 * @see [[GeometryStreamProps]].
 * @see [[Feature]].
 * @public
 * @extensions
 */
var GeometryClass;
(function (GeometryClass) {
    /** Used to classify the "real" geometry within a model. Most geometry falls within this class. */
    GeometryClass[GeometryClass["Primary"] = 0] = "Primary";
    /** Used to classify geometry used as a drawing aid in constructing the Primary geometry. For example, grid lines. */
    GeometryClass[GeometryClass["Construction"] = 1] = "Construction";
    /** Used to classify annotations which dimension (measure) the Primary geometry. */
    GeometryClass[GeometryClass["Dimension"] = 2] = "Dimension";
    /** Used to classify geometry used to fill planar regions with a 2d pattern (e.g., hatch lines). */
    GeometryClass[GeometryClass["Pattern"] = 3] = "Pattern";
})(GeometryClass || (exports.GeometryClass = GeometryClass = {}));
/** Describes the display properties of graphics in a persistent element's GeometryStream that aren't inherited from [[SubCategoryAppearance]].
 * @see [[GeometryStreamProps]].
 * @public
 */
class GeometryParams {
    categoryId;
    subCategoryId;
    /** Optional render material to override [[SubCategoryAppearance.materialId]].
     * Specify an invalid [[Id64]] to override [[SubCategoryAppearance.materialId]] with no material.
     */
    materialId;
    /** Optional display priority added to [[SubCategoryAppearance.priority]].
     * The net display priority value is used to control z ordering when drawing to 2d views.
     */
    elmPriority;
    /** Optional line weight to override [[SubCategoryAppearance.weight]].
     * The weight is an integer in the range of [0,31] that by default corresponds to a pixel width of weight+1.
     */
    weight;
    /** Optional line color to override [[SubCategoryAppearance.color]].
     * The transparency component is ignored and should instead be specified using [[elmTransparency]].
     */
    lineColor;
    /** Optional fill color for region interiors. Set the same as [[lineColor]] for an opaque fill.
     * Valid when [[fillDisplay]] is not [[FillDisplay.Never]], [[gradient]] is undefined, and [[backgroundFill]] is [[BackgroundFill.None]].
     * The transparency component is ignored and should instead be specified using [[fillTransparency]].
     */
    fillColor;
    /** Optional fill using the current view background color for region interiors.
     * Valid when [[fillDisplay]] is not [[FillDisplay.Never]] and [[gradient]] is undefined. Default is [[BackgroundFill.None]].
     */
    backgroundFill;
    /** Optional fill specification that determines when and if a region interior will display using [[gradient]], [[backgroundFill]], or [[fillColor]] in that order of preference.
     * Fill only applies to [[RenderMode.Wireframe]] views. In a [[RenderMode.SmoothShade]] or [[RenderMode.SolidFill]] view, regions will always display as surfaces preferring [[fillColor]] when present over [[lineColor]].
     * Default is [[FillDisplay.Never]].
     */
    fillDisplay;
    /** Optional line color transparency to combine with [[SubCategoryAppearance.transparency]].
     * Transparency values are combined by multiplying the opaqueness. A 50% transparent element on a 50% transparent sub-category creates a 75% transparent result (1 - ((1 - .5) * (1 - .5)) = 0.75).
     * Value range is [0.0,1.0]. Pass 0.0 for completely opaque and 1.0 for completely transparent.
     */
    elmTransparency;
    /** Optional fill color transparency to combine with [[SubCategoryAppearance.transparency]].
     * Transparency values are combined by multiplying the opaqueness. A 50% transparent fill on a 50% transparent sub-category creates a 75% transparent result (1 - ((1 - .5) * (1 - .5)) = 0.75).
     * Value range is [0.0,1.0]. Pass 0.0 for completely opaque, 1.0 for completely transparent, or leave undefined to use [[elmTransparency]].
     */
    fillTransparency;
    /** Optional geometry classification that can be toggled off with a [[ViewFlags]] independent of [[SubCategoryAppearance.invisible]].
     * Default is [[GeometryClass.Primary]].
     */
    geometryClass;
    /** Optional line style to override [[SubCategoryAppearance.styleId]] plus modifiers to override the line style definition.
     * Specify an invalid [[Id64]] to override [[SubCategoryAppearance.styleId]] with a solid line.
     */
    styleInfo;
    /** Optional gradient fill settings for region interiors.
     * Valid when [[fillDisplay]] is not [[FillDisplay.Never]].
     */
    gradient;
    /** Optional area pattern settings for region interiors.
     * Independent of fill, a region can have both fill and pattern.
     */
    pattern;
    /** Create a GeometryParams given a [[Category]] Id for a [[GeometricElement]] and optional [[SubCategory]] Id. The [[SubCategory.appearance]] establishes the non-overriden display properties of
     * graphics in a GeometricElement's [[GeometryStreamProps]]. A GeometricElement refers to a single Category through [[GeometricElement.category]], while it's graphics can appear on multiple SubCategories
     * by adding a [[GeometryAppearanceProps]] with a SubCategory change to the GeometryStream.
     * @note If a valid SubCategory Id is not supplied, the default SubCategory for the parent Category is used. To be considered valid, [[SubCategory.getCategoryId]] must refer to the specified Category Id.
     */
    constructor(categoryId, subCategoryId = core_bentley_1.Id64.invalid) {
        this.categoryId = categoryId;
        this.subCategoryId = subCategoryId;
        if (!core_bentley_1.Id64.isValid(subCategoryId))
            this.subCategoryId = IModel_1.IModel.getDefaultSubCategoryId(categoryId);
    }
    clone() {
        const retVal = new GeometryParams(this.categoryId, this.subCategoryId);
        retVal.materialId = this.materialId;
        retVal.elmPriority = this.elmPriority;
        retVal.weight = this.weight;
        retVal.lineColor = this.lineColor;
        retVal.fillColor = this.fillColor;
        retVal.backgroundFill = this.backgroundFill;
        retVal.fillDisplay = this.fillDisplay;
        retVal.elmTransparency = this.elmTransparency;
        retVal.fillTransparency = this.fillTransparency;
        retVal.geometryClass = this.geometryClass;
        retVal.styleInfo = this.styleInfo ? this.styleInfo.clone() : undefined;
        retVal.gradient = this.gradient ? this.gradient.clone() : undefined;
        retVal.pattern = this.pattern ? this.pattern.clone() : undefined;
        return retVal;
    }
    /** Clears [[SubCategoryAppearance]] overrides while preserving [[categoryId]] and [[subCategoryId]]. */
    resetAppearance() {
        this.materialId = undefined;
        this.elmPriority = undefined;
        this.weight = undefined;
        this.lineColor = undefined;
        this.fillColor = undefined;
        this.backgroundFill = undefined;
        this.fillDisplay = undefined;
        this.elmTransparency = undefined;
        this.fillTransparency = undefined;
        this.geometryClass = undefined;
        this.styleInfo = undefined;
        this.gradient = undefined;
        this.pattern = undefined;
    }
    /** Compare two [[GeometryParams]] for equivalence, i.e. both values are undefined and inherited from [[SubCategoryAppearance]] or have the same override. */
    isEquivalent(other) {
        if (this === other)
            return true; // Same pointer
        if (this.categoryId !== other.categoryId)
            return false;
        if (this.subCategoryId !== other.subCategoryId)
            return false;
        if (this.geometryClass !== other.geometryClass)
            return false;
        if (this.elmPriority !== other.elmPriority)
            return false;
        if (this.elmTransparency !== other.elmTransparency)
            return false;
        if (this.fillTransparency !== other.fillTransparency)
            return false;
        if ((this.lineColor === undefined) !== (other.lineColor === undefined))
            return false;
        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
        if (this.lineColor && !this.lineColor.equals(other.lineColor))
            return false;
        if (this.weight !== other.weight)
            return false;
        if ((this.materialId === undefined) !== (other.materialId === undefined))
            return false;
        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
        if (this.materialId && this.materialId !== other.materialId)
            return false;
        if ((this.styleInfo === undefined) !== (other.styleInfo === undefined))
            return false;
        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
        if (this.styleInfo && !this.styleInfo.equals(other.styleInfo))
            return false;
        if (this.fillDisplay !== other.fillDisplay)
            return false;
        if (this.fillDisplay !== undefined && this.fillDisplay !== FillDisplay.Never) {
            if ((this.gradient === undefined) !== (other.gradient === undefined))
                return false;
            // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
            if (this.gradient && !this.gradient.equals(other.gradient))
                return false;
            if (this.backgroundFill !== other.backgroundFill)
                return false;
            if (this.backgroundFill === undefined || this.backgroundFill === BackgroundFill.None) {
                if ((this.fillColor === undefined) !== (other.fillColor === undefined))
                    return false;
                // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
                if (this.fillColor && !this.fillColor.equals(other.fillColor))
                    return false;
            }
        }
        if ((this.pattern === undefined) !== (other.pattern === undefined))
            return false;
        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
        if (this.pattern && !this.pattern.equals(other.pattern))
            return false;
        return true;
    }
    /** Change [[categoryId]] to the supplied id, [[subCategoryId]] to the supplied category's the default subCategory, and optionally clear any [[SubCategoryAppearance]] overrides. */
    setCategoryId(categoryId, clearAppearanceOverrides = true) {
        this.categoryId = categoryId;
        this.subCategoryId = IModel_1.IModel.getDefaultSubCategoryId(categoryId);
        if (clearAppearanceOverrides)
            this.resetAppearance();
    }
    /** Change [[subCategoryId]] to the supplied id and optionally clear any [[SubCategoryAppearance]] overrides. */
    setSubCategoryId(subCategoryId, clearAppearanceOverrides = true) {
        this.subCategoryId = subCategoryId;
        if (clearAppearanceOverrides)
            this.resetAppearance();
    }
}
exports.GeometryParams = GeometryParams;
//# sourceMappingURL=GeometryParams.js.map