UNPKG

@itwin/frontend-devtools

Version:

Debug menu and supporting UI widgets

184 lines • 9.27 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.ClearModelAppearanceOverrides = exports.SetModelColorTool = exports.SetModelIgnoresMaterialsTool = exports.SetModelEmphasizedTool = exports.SetModelLocateTool = exports.SetModelLineCodeTool = exports.SetModelLineWeightTool = exports.SetModelTransparencyTool = void 0; /** @packageDocumentation * @module Tools */ const core_common_1 = require("@itwin/core-common"); const core_frontend_1 = require("@itwin/core-frontend"); const parseBoolean_1 = require("./parseBoolean"); function changeModelAppearanceOverrides(vp, overrides, name) { let changed = false; if (vp !== undefined && vp.view instanceof core_frontend_1.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) : core_common_1.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 */ class SetModelTransparencyTool extends core_frontend_1.Tool { static toolId = "SetModelTransparencyTool"; static get minArgs() { return 1; } static get maxArgs() { return 2; } async run(transparency, name) { const changed = changeModelAppearanceOverrides(core_frontend_1.IModelApp.viewManager.selectedView, { transparency }, name); if (changed) core_frontend_1.IModelApp.notifications.outputMessage(new core_frontend_1.NotifyMessageDetails(core_frontend_1.OutputMessagePriority.Info, `${modelChangedString(name)} set to transparency: ${transparency}`)); return changed; } async parseAndRun(...args) { return this.run(parseFloat(args[0]), args[1]); } } exports.SetModelTransparencyTool = SetModelTransparencyTool; /** Set model appearance override for line weight in display style. * @beta */ class SetModelLineWeightTool extends core_frontend_1.Tool { static toolId = "SetModelLineWeightTool"; static get minArgs() { return 1; } static get maxArgs() { return 2; } async run(weight, name) { const changed = changeModelAppearanceOverrides(core_frontend_1.IModelApp.viewManager.selectedView, { weight }, name); if (changed) core_frontend_1.IModelApp.notifications.outputMessage(new core_frontend_1.NotifyMessageDetails(core_frontend_1.OutputMessagePriority.Info, `${modelChangedString(name)} set to line weight: ${weight}`)); return changed; } async parseAndRun(...args) { return this.run(parseFloat(args[0]), args[1]); } } exports.SetModelLineWeightTool = SetModelLineWeightTool; /** Set model appearance override for line code in display style. * @beta */ class SetModelLineCodeTool extends core_frontend_1.Tool { static toolId = "SetModelLineCodeTool"; static get minArgs() { return 1; } static get maxArgs() { return 2; } static linePixels = [core_common_1.LinePixels.Code0, core_common_1.LinePixels.Code1, core_common_1.LinePixels.Code2, core_common_1.LinePixels.Code3, core_common_1.LinePixels.Code4, core_common_1.LinePixels.Code5, core_common_1.LinePixels.Code6, core_common_1.LinePixels.Code7]; async run(lineCode, name) { if (lineCode < 0 || lineCode >= SetModelLineCodeTool.linePixels.length) return false; const changed = changeModelAppearanceOverrides(core_frontend_1.IModelApp.viewManager.selectedView, { linePixels: SetModelLineCodeTool.linePixels[lineCode] }, name); if (changed) core_frontend_1.IModelApp.notifications.outputMessage(new core_frontend_1.NotifyMessageDetails(core_frontend_1.OutputMessagePriority.Info, `${modelChangedString(name)} set to line code: ${lineCode}`)); return changed; } async parseAndRun(...args) { return this.run(parseFloat(args[0]), args[1]); } } exports.SetModelLineCodeTool = SetModelLineCodeTool; /** Set model appearance override for nonLocatable in display style. * @beta */ class SetModelLocateTool extends core_frontend_1.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(core_frontend_1.IModelApp.viewManager.selectedView, { nonLocatable }, name); if (changed) core_frontend_1.IModelApp.notifications.outputMessage(new core_frontend_1.NotifyMessageDetails(core_frontend_1.OutputMessagePriority.Info, `${modelChangedString(name)} set to locate: ${locate}`)); return changed; } async parseAndRun(...args) { const locate = (0, parseBoolean_1.parseBoolean)(args[0]); return locate === undefined ? false : this.run(locate, args[1]); } } exports.SetModelLocateTool = SetModelLocateTool; /** Set model appearance override for emphasized in display style. * @beta */ class SetModelEmphasizedTool extends core_frontend_1.Tool { static toolId = "SetModelEmphasizedTool"; static get minArgs() { return 1; } static get maxArgs() { return 2; } async run(emphasized, name) { const changed = changeModelAppearanceOverrides(core_frontend_1.IModelApp.viewManager.selectedView, { emphasized }, name); if (changed) core_frontend_1.IModelApp.notifications.outputMessage(new core_frontend_1.NotifyMessageDetails(core_frontend_1.OutputMessagePriority.Info, `Mode: ${name} set to emphasized: ${emphasized}`)); return changed; } async parseAndRun(...args) { const emphasized = (0, parseBoolean_1.parseBoolean)(args[0]); return emphasized === undefined ? false : this.run(emphasized ? true : undefined, args[1]); } } exports.SetModelEmphasizedTool = SetModelEmphasizedTool; /** Set model appearance override for ignoreMaterials in display style. * @beta */ class SetModelIgnoresMaterialsTool extends core_frontend_1.Tool { static toolId = "SetModelIgnoresMaterialsTool"; static get minArgs() { return 1; } static get maxArgs() { return 2; } async run(ignoresMaterial, name) { const changed = changeModelAppearanceOverrides(core_frontend_1.IModelApp.viewManager.selectedView, { ignoresMaterial }, name); if (changed) core_frontend_1.IModelApp.notifications.outputMessage(new core_frontend_1.NotifyMessageDetails(core_frontend_1.OutputMessagePriority.Info, `Mode: ${name} set to ignore Materials: ${ignoresMaterial}`)); return changed; } async parseAndRun(...args) { const ignoresMaterial = (0, parseBoolean_1.parseBoolean)(args[0]); return ignoresMaterial === undefined ? false : this.run(ignoresMaterial ? true : undefined, args[1]); } } exports.SetModelIgnoresMaterialsTool = SetModelIgnoresMaterialsTool; /** Set model appearance override for color in display style. * @beta */ class SetModelColorTool extends core_frontend_1.Tool { static toolId = "SetModelColorTool"; static get minArgs() { return 3; } static get maxArgs() { return 4; } async run(rgb, name) { const changed = changeModelAppearanceOverrides(core_frontend_1.IModelApp.viewManager.selectedView, { rgb }, name); if (changed) core_frontend_1.IModelApp.notifications.outputMessage(new core_frontend_1.NotifyMessageDetails(core_frontend_1.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]); } } exports.SetModelColorTool = SetModelColorTool; /** clear model appearance overrides in display style. * @beta */ class ClearModelAppearanceOverrides extends core_frontend_1.Tool { static toolId = "ClearModelAppearanceOverrides"; static get minArgs() { return 0; } static get maxArgs() { return 1; } async run(name) { const vp = core_frontend_1.IModelApp.viewManager.selectedView; if (vp !== undefined && vp.view instanceof core_frontend_1.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]); } } exports.ClearModelAppearanceOverrides = ClearModelAppearanceOverrides; //# sourceMappingURL=ModelAppearanceTools.js.map