UNPKG

@itwin/frontend-devtools

Version:

Debug menu and supporting UI widgets

137 lines 5.61 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 { PlanProjectionSettings, SubCategoryOverride } from "@itwin/core-common"; import { IModelApp, NotifyMessageDetails, OutputMessagePriority } from "@itwin/core-frontend"; import { copyStringToClipboard } from "../ClipboardUtilities"; import { DisplayStyleTool } from "./DisplayStyleTools"; import { parseArgs } from "./parseArgs"; /** Dumps a JSON representation of the plan projection settings for the current viewport. * @beta */ export class DumpPlanProjectionSettingsTool extends DisplayStyleTool { static toolId = "DumpLayerSettings"; static get minArgs() { return 0; } static get maxArgs() { return 1; } _copyToClipboard = false; get require3d() { return true; } async parse(args) { if (1 === args.length) this._copyToClipboard = "c" === args[0].toLowerCase(); return true; } async execute(vp) { const settings = vp.displayStyle.settings.planProjectionSettings; if (undefined === settings) { IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Info, "No plan projection settings defined")); return false; } const props = []; for (const [modelId, value] of settings) props.push({ modelId, settings: value.toJSON() }); const json = JSON.stringify(props); if (this._copyToClipboard) copyStringToClipboard(json); const messageDetails = new NotifyMessageDetails(OutputMessagePriority.Info, "Dumped plan projection settings", json); IModelApp.notifications.outputMessage(messageDetails); return false; } } /** Changes subcategory display priority. * @beta */ export class OverrideSubCategoryPriorityTool extends DisplayStyleTool { static toolId = "OverrideSubCategoryPriority"; static get minArgs() { return 1; } static get maxArgs() { return 2; } _subcatIds = new Set(); _priority; async execute(vp) { const style = vp.displayStyle; for (const id of this._subcatIds) { const ovr = style.getSubCategoryOverride(id); if (undefined === ovr) { if (undefined !== this._priority) style.overrideSubCategory(id, SubCategoryOverride.fromJSON({ priority: this._priority })); } else { const props = ovr.toJSON(); props.priority = this._priority; style.overrideSubCategory(id, SubCategoryOverride.fromJSON(props)); } } return true; } async parse(args) { for (const id of args[0].split(",")) this._subcatIds.add(id); const priority = parseInt(args[1], 10); if (!Number.isNaN(priority)) this._priority = priority; return true; } } /** Changes plan projection settings for one or more models. * @beta */ export class ChangePlanProjectionSettingsTool extends DisplayStyleTool { static toolId = "ChangeLayerSettings"; static get minArgs() { return 1; } static get maxArgs() { return 5; } _modelIds = new Set(); _settings; get require3d() { return true; } async execute(vp) { const settings = vp.displayStyle.settings; for (const modelId of this._modelIds) settings.setPlanProjectionSettings(modelId, this._settings); return true; } async parse(inputArgs) { if (!this.parseModels(inputArgs[0])) return false; const args = parseArgs(inputArgs.slice(1)); const props = {}; props.transparency = args.getFloat("t"); props.overlay = args.getBoolean("o"); props.enforceDisplayPriority = args.getBoolean("p"); props.elevation = args.getFloat("e"); this._settings = PlanProjectionSettings.fromJSON(props); return true; } parseModels(models) { const vp = IModelApp.viewManager.selectedView; // already validated by super.parseAndRun models = models.toLowerCase(); const isPlanProjection = (modelId) => { const model = vp.iModel.models.getLoaded(modelId); return undefined !== model && isPlanProjectionModel(model); }; const isPlanProjectionModel = (model) => { const model3d = model.asGeometricModel3d; return undefined !== model3d && model3d.isPlanProjection; }; switch (models[0]) { case "a": // all models in selector vp.view.forEachModel((model) => { if (isPlanProjectionModel(model)) this._modelIds.add(model.id); }); break; case "0": // comma-separated list of Ids for (const modelId of models.split(",")) if (isPlanProjection(modelId)) this._modelIds.add(modelId); break; } if (this._modelIds.size === 0) { IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, "No plan projection models")); return false; } return true; } } //# sourceMappingURL=PlanProjectionTools.js.map