UNPKG

@itwin/frontend-devtools

Version:

Debug menu and supporting UI widgets

173 lines • 7.77 kB
/*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ /** @packageDocumentation * @module Tools */ import { FeatureAppearance, LinePixels } from "@itwin/core-common"; import { IModelApp, NotifyMessageDetails, OutputMessagePriority, SpatialViewState, Tool } from "@itwin/core-frontend"; import { parseBoolean } from "./parseBoolean"; function changeModelAppearanceOverrides(vp, overrides, name) { let changed = false; if (vp !== undefined && vp.view instanceof SpatialViewState) vp.view.forEachModel((model) => { if (name === undefined || model.name === name) { changed = true; const existingOverrides = vp.displayStyle.settings.getModelAppearanceOverride(model.id); vp.overrideModelAppearance(model.id, existingOverrides ? existingOverrides.clone(overrides) : FeatureAppearance.fromJSON(overrides)); } }); return changed; } function modelChangedString(name) { return name === undefined ? `All Models` : `Model: ${name}`; } /** Set model appearance override for transparency in display style. * @beta */ export class SetModelTransparencyTool extends Tool { static toolId = "SetModelTransparencyTool"; static get minArgs() { return 1; } static get maxArgs() { return 2; } async run(transparency, name) { const changed = changeModelAppearanceOverrides(IModelApp.viewManager.selectedView, { transparency }, name); if (changed) IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Info, `${modelChangedString(name)} set to transparency: ${transparency}`)); return changed; } async parseAndRun(...args) { return this.run(parseFloat(args[0]), args[1]); } } /** Set model appearance override for line weight in display style. * @beta */ export class SetModelLineWeightTool extends Tool { static toolId = "SetModelLineWeightTool"; static get minArgs() { return 1; } static get maxArgs() { return 2; } async run(weight, name) { const changed = changeModelAppearanceOverrides(IModelApp.viewManager.selectedView, { weight }, name); if (changed) IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Info, `${modelChangedString(name)} set to line weight: ${weight}`)); return changed; } async parseAndRun(...args) { return this.run(parseFloat(args[0]), args[1]); } } /** Set model appearance override for line code in display style. * @beta */ export class SetModelLineCodeTool extends Tool { static toolId = "SetModelLineCodeTool"; static get minArgs() { return 1; } static get maxArgs() { return 2; } static linePixels = [LinePixels.Code0, LinePixels.Code1, LinePixels.Code2, LinePixels.Code3, LinePixels.Code4, LinePixels.Code5, LinePixels.Code6, LinePixels.Code7]; async run(lineCode, name) { if (lineCode < 0 || lineCode >= SetModelLineCodeTool.linePixels.length) return false; const changed = changeModelAppearanceOverrides(IModelApp.viewManager.selectedView, { linePixels: SetModelLineCodeTool.linePixels[lineCode] }, name); if (changed) IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Info, `${modelChangedString(name)} set to line code: ${lineCode}`)); return changed; } async parseAndRun(...args) { return this.run(parseFloat(args[0]), args[1]); } } /** Set model appearance override for nonLocatable in display style. * @beta */ export class SetModelLocateTool extends Tool { static toolId = "SetModelLocateTool"; static get minArgs() { return 1; } static get maxArgs() { return 2; } async run(locate, name) { const nonLocatable = locate ? undefined : true; const changed = changeModelAppearanceOverrides(IModelApp.viewManager.selectedView, { nonLocatable }, name); if (changed) IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Info, `${modelChangedString(name)} set to locate: ${locate}`)); return changed; } async parseAndRun(...args) { const locate = parseBoolean(args[0]); return locate === undefined ? false : this.run(locate, args[1]); } } /** Set model appearance override for emphasized in display style. * @beta */ export class SetModelEmphasizedTool extends Tool { static toolId = "SetModelEmphasizedTool"; static get minArgs() { return 1; } static get maxArgs() { return 2; } async run(emphasized, name) { const changed = changeModelAppearanceOverrides(IModelApp.viewManager.selectedView, { emphasized }, name); if (changed) IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Info, `Mode: ${name} set to emphasized: ${emphasized}`)); return changed; } async parseAndRun(...args) { const emphasized = parseBoolean(args[0]); return emphasized === undefined ? false : this.run(emphasized ? true : undefined, args[1]); } } /** Set model appearance override for ignoreMaterials in display style. * @beta */ export class SetModelIgnoresMaterialsTool extends Tool { static toolId = "SetModelIgnoresMaterialsTool"; static get minArgs() { return 1; } static get maxArgs() { return 2; } async run(ignoresMaterial, name) { const changed = changeModelAppearanceOverrides(IModelApp.viewManager.selectedView, { ignoresMaterial }, name); if (changed) IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Info, `Mode: ${name} set to ignore Materials: ${ignoresMaterial}`)); return changed; } async parseAndRun(...args) { const ignoresMaterial = parseBoolean(args[0]); return ignoresMaterial === undefined ? false : this.run(ignoresMaterial ? true : undefined, args[1]); } } /** Set model appearance override for color in display style. * @beta */ export class SetModelColorTool extends Tool { static toolId = "SetModelColorTool"; static get minArgs() { return 3; } static get maxArgs() { return 4; } async run(rgb, name) { const changed = changeModelAppearanceOverrides(IModelApp.viewManager.selectedView, { rgb }, name); if (changed) IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Info, `${modelChangedString(name)} set to RGB color: (${rgb.r}, ${rgb.g}, ${rgb.b})`)); return true; } async parseAndRun(...args) { return this.run({ r: parseFloat(args[0]), g: parseFloat(args[1]), b: parseFloat(args[2]) }, args[3]); } } /** clear model appearance overrides in display style. * @beta */ export class ClearModelAppearanceOverrides extends Tool { static toolId = "ClearModelAppearanceOverrides"; static get minArgs() { return 0; } static get maxArgs() { return 1; } async run(name) { const vp = IModelApp.viewManager.selectedView; if (vp !== undefined && vp.view instanceof SpatialViewState) { vp.view.forEachModel((model) => { if (name === undefined || model.name === name) vp.dropModelAppearanceOverride(model.id); }); } return true; } async parseAndRun(...args) { return this.run(args[0]); } } //# sourceMappingURL=ModelAppearanceTools.js.map