@itwin/frontend-devtools
Version:
Debug menu and supporting UI widgets
143 lines • 6.26 kB
JavaScript
;
/*---------------------------------------------------------------------------------------------
* 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.ChangePlanProjectionSettingsTool = exports.OverrideSubCategoryPriorityTool = exports.DumpPlanProjectionSettingsTool = void 0;
/** @packageDocumentation
* @module Tools
*/
const core_common_1 = require("@itwin/core-common");
const core_frontend_1 = require("@itwin/core-frontend");
const ClipboardUtilities_1 = require("../ClipboardUtilities");
const DisplayStyleTools_1 = require("./DisplayStyleTools");
const parseArgs_1 = require("./parseArgs");
/** Dumps a JSON representation of the plan projection settings for the current viewport.
* @beta
*/
class DumpPlanProjectionSettingsTool extends DisplayStyleTools_1.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) {
core_frontend_1.IModelApp.notifications.outputMessage(new core_frontend_1.NotifyMessageDetails(core_frontend_1.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)
(0, ClipboardUtilities_1.copyStringToClipboard)(json);
const messageDetails = new core_frontend_1.NotifyMessageDetails(core_frontend_1.OutputMessagePriority.Info, "Dumped plan projection settings", json);
core_frontend_1.IModelApp.notifications.outputMessage(messageDetails);
return false;
}
}
exports.DumpPlanProjectionSettingsTool = DumpPlanProjectionSettingsTool;
/** Changes subcategory display priority.
* @beta
*/
class OverrideSubCategoryPriorityTool extends DisplayStyleTools_1.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, core_common_1.SubCategoryOverride.fromJSON({ priority: this._priority }));
}
else {
const props = ovr.toJSON();
props.priority = this._priority;
style.overrideSubCategory(id, core_common_1.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;
}
}
exports.OverrideSubCategoryPriorityTool = OverrideSubCategoryPriorityTool;
/** Changes plan projection settings for one or more models.
* @beta
*/
class ChangePlanProjectionSettingsTool extends DisplayStyleTools_1.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 = (0, parseArgs_1.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 = core_common_1.PlanProjectionSettings.fromJSON(props);
return true;
}
parseModels(models) {
const vp = core_frontend_1.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) {
core_frontend_1.IModelApp.notifications.outputMessage(new core_frontend_1.NotifyMessageDetails(core_frontend_1.OutputMessagePriority.Error, "No plan projection models"));
return false;
}
return true;
}
}
exports.ChangePlanProjectionSettingsTool = ChangePlanProjectionSettingsTool;
//# sourceMappingURL=PlanProjectionTools.js.map