UNPKG

@itwin/frontend-devtools

Version:

Debug menu and supporting UI widgets

253 lines • 10.2 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. *--------------------------------------------------------------------------------------------*/ Object.defineProperty(exports, "__esModule", { value: true }); exports.TestClipStyleTool = exports.ToggleSectionCutTool = exports.ClipIntersectionTool = exports.ClipColorTool = void 0; /** @packageDocumentation * @module Tools */ const core_common_1 = require("@itwin/core-common"); const core_frontend_1 = require("@itwin/core-frontend"); const parseToggle_1 = require("./parseToggle"); const parseBoolean_1 = require("./parseBoolean"); const DisplayStyleTools_1 = require("./DisplayStyleTools"); /** This tool specifies or un-specifies a clip color to use for pixels inside or outside the clip region. * Arguments can be: * - clear * - inside <color string> | clear * - outside <color string> | clear * <color string> must be in one of the following forms: * "rgb(255,0,0)" * "rgba(255,0,0,255)" * "rgb(100%,0%,0%)" * "hsl(120,50%,50%)" * "#rrbbgg" * "blanchedAlmond" (see possible values from [[ColorByName]]). Case insensitive. * @see [ColorDef] * @beta */ class ClipColorTool extends core_frontend_1.Tool { static toolId = "ClipColorTool"; static get minArgs() { return 1; } static get maxArgs() { return 2; } _clearClipColors() { const vp = core_frontend_1.IModelApp.viewManager.selectedView; if (undefined !== vp) { const props = vp.displayStyle.settings.clipStyle.toJSON() ?? {}; props.insideColor = props.outsideColor = undefined; vp.displayStyle.settings.clipStyle = core_common_1.ClipStyle.fromJSON(props); } } setClipColor(colStr, which) { const vp = core_frontend_1.IModelApp.viewManager.selectedView; if (vp) { const props = vp.displayStyle.settings.clipStyle.toJSON() ?? {}; props[which] = colStr === "clear" ? undefined : core_common_1.RgbColor.fromColorDef(core_common_1.ColorDef.fromString(colStr)); vp.displayStyle.settings.clipStyle = core_common_1.ClipStyle.fromJSON(props); } } /** This runs the tool using the given arguments, specifying or unspecifying a clip color to use for pixels inside or outside the clip region. * Arguments can be: * - clear * - inside <color string> | clear * - outside <color string> | clear * <color string> must be in one of the following forms: * "rgb(255,0,0)" * "rgba(255,0,0,255)" * "rgb(100%,0%,0%)" * "hsl(120,50%,50%)" * "#rrbbgg" * "blanchedAlmond" (see possible values from [[ColorByName]]). Case insensitive. * @beta */ async parseAndRun(...args) { if (1 === args.length) { if (args[0] === "clear") this._clearClipColors(); return true; } const which = args[0]; if (which === "inside" || which === "outside") this.setClipColor(args[1], "inside" === which ? "insideColor" : "outsideColor"); return true; } } exports.ClipColorTool = ClipColorTool; /** This tool specifies or un-specifies a color and width to use for pixels within the specified width of a clip plane. * Arguments can be: * - off * - default * - color <color string> * - width <number> * <color string> must be in one of the following forms: * "rgb(255,0,0)" * "rgba(255,0,0,255)" * "rgb(100%,0%,0%)" * "hsl(120,50%,50%)" * "#rrbbgg" * "blanchedAlmond" (see possible values from [[ColorByName]]). Case insensitive. * @see [ColorDef] * @beta */ class ClipIntersectionTool extends core_frontend_1.Tool { static toolId = "ClipIntersectionTool"; static get minArgs() { return 0; } static get maxArgs() { return 4; } _toggleIntersectionStyle(toggle) { const vp = core_frontend_1.IModelApp.viewManager.selectedView; if (undefined !== vp) { const props = vp.displayStyle.settings.clipStyle.toJSON() ?? {}; props.colorizeIntersection = toggle; vp.displayStyle.settings.clipStyle = core_common_1.ClipStyle.fromJSON(props); } } _defaultClipIntersection() { const vp = core_frontend_1.IModelApp.viewManager.selectedView; if (undefined !== vp) { const props = vp.displayStyle.settings.clipStyle.toJSON() ?? {}; if (!props.intersectionStyle) { props.intersectionStyle = core_common_1.ClipIntersectionStyle.defaults; } else { props.intersectionStyle.color = core_common_1.RgbColor.fromColorDef(core_common_1.ColorDef.white); props.intersectionStyle.width = 1; } vp.displayStyle.settings.clipStyle = core_common_1.ClipStyle.fromJSON(props); } } setClipIntersection(colStr, width) { const vp = core_frontend_1.IModelApp.viewManager.selectedView; if (vp) { const props = vp.displayStyle.settings.clipStyle.toJSON() ?? {}; if (!props.intersectionStyle) { props.intersectionStyle = core_common_1.ClipIntersectionStyle.defaults; } if (colStr) { props.intersectionStyle.color = core_common_1.RgbColor.fromColorDef(core_common_1.ColorDef.fromString(colStr)); } if (width) { props.intersectionStyle.width = width; } vp.displayStyle.settings.clipStyle = core_common_1.ClipStyle.fromJSON(props); } } /** This runs the tool using the given arguments, specifying or unspecifying a color and width to use for pixels within the specified width of a clip plane. * Arguments can be: * - off * - default * - color <color string> * - width <number> * <color string> must be in one of the following forms: * "rgb(255,0,0)" * "rgba(255,0,0,255)" * "rgb(100%,0%,0%)" * "hsl(120,50%,50%)" * "#rrbbgg" * "blanchedAlmond" (see possible values from [[ColorByName]]). Case insensitive. * @beta */ async parseAndRun(...args) { if (args[0] === "off") { this._toggleIntersectionStyle(false); return true; } this._toggleIntersectionStyle(true); if (args[0] === "default") { this._defaultClipIntersection(); return true; } args[0] === "color" ? this.setClipIntersection(args[1], +args[3]) : this.setClipIntersection(args[3], +args[1]); return true; } } exports.ClipIntersectionTool = ClipIntersectionTool; /** Controls a view state's view details' flag for producing cut geometry for a clip style. * @beta */ class ToggleSectionCutTool extends core_frontend_1.Tool { static toolId = "ToggleSectionCut"; static get minArgs() { return 0; } static get maxArgs() { return 1; } /** This method runs the tool, controlling a view state's view details' flag for producing cut geometry for a clip style. * @param produceCutGeometry whether to produce cut geometry */ async run(produceCutGeometry) { const vp = core_frontend_1.IModelApp.viewManager.selectedView; if (vp) { const style = vp.view.displayStyle.settings.clipStyle; produceCutGeometry = produceCutGeometry ?? !style.produceCutGeometry; if (produceCutGeometry !== style.produceCutGeometry) { const json = { ...vp.view.displayStyle.settings.clipStyle.toJSON(), produceCutGeometry, }; vp.view.displayStyle.settings.clipStyle = core_common_1.ClipStyle.fromJSON(json); vp.invalidateScene(); } } return true; } /** Executes this tool's run method with args[0] containing `produceCutGeometry`. * @see [[run]] */ async parseAndRun(...args) { const enable = (0, parseToggle_1.parseToggle)(args[0]); if (typeof enable !== "string") await this.run(enable); return true; } } exports.ToggleSectionCutTool = ToggleSectionCutTool; /** Simple tool that toggles a hard-coded clip style overriding various aspects of the cut geometry appearance. * @beta */ class TestClipStyleTool extends DisplayStyleTools_1.DisplayStyleTool { static toolId = "TestClipStyle"; static get maxArgs() { return 2; } static get minArgs() { return 1; } _useStyle = false; _style; get require3d() { return true; } async parse(args) { this._useStyle = (0, parseBoolean_1.parseBoolean)(args[0]) ?? false; if (this._useStyle && args.length > 1) this._style = JSON.parse(args[1]); return true; } async execute(vp) { const props = { produceCutGeometry: true }; if (this._useStyle) { if (this._style) props.cutStyle = this._style; else props.cutStyle = { viewflags: { renderMode: core_common_1.RenderMode.SmoothShade, visibleEdges: true, hiddenEdges: false, }, appearance: { rgb: { r: 0xff, g: 0x7f, b: 0 }, transparency: 0.5, nonLocatable: true, }, hiddenLine: { visible: { ovrColor: true, color: core_common_1.ColorByName.blue, pattern: core_common_1.LinePixels.Solid, width: 3, }, }, }; } vp.displayStyle.settings.clipStyle = core_common_1.ClipStyle.fromJSON(props); vp.invalidateRenderPlan(); vp.setFeatureOverrideProviderChanged(); return true; } } exports.TestClipStyleTool = TestClipStyleTool; //# sourceMappingURL=ClipTools.js.map