@itwin/frontend-devtools
Version:
Debug menu and supporting UI widgets
282 lines • 13.7 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.ToggleOSMBuildingDisplay = exports.AttachCesiumAssetTool = exports.ClearRealityModelAppearanceOverrides = exports.SetRealityModelColorTool = exports.DetachRealityModelTool = exports.SetRealityModelEmphasizedTool = exports.SetRealityModelLocateTool = exports.SetRealityModelTransparencyTool = exports.SaveRealityModelTool = exports.AttachRealityModelTool = 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 parseBoolean_1 = require("./parseBoolean");
const parseToggle_1 = require("./parseToggle");
/** This tool attaches a specified reality model.
* @beta
*/
class AttachRealityModelTool extends core_frontend_1.Tool {
static toolId = "AttachRealityModelTool";
static get minArgs() { return 1; }
static get maxArgs() { return 1; }
/** This method runs the tool, attaching a specified reality model.
* @param data a [[ContextRealityModelProps]] JSON representation
*/
async run(data) {
const props = JSON.parse(data);
const vp = core_frontend_1.IModelApp.viewManager.selectedView;
if (vp === undefined)
return false;
if (props === undefined || props.tilesetUrl === undefined) {
core_frontend_1.IModelApp.notifications.outputMessage(new core_frontend_1.NotifyMessageDetails(core_frontend_1.OutputMessagePriority.Error, `Properties ${props} are not valid`));
}
vp.displayStyle.attachRealityModel(props);
core_frontend_1.IModelApp.notifications.outputMessage(new core_frontend_1.NotifyMessageDetails(core_frontend_1.OutputMessagePriority.Info, `Reality Model ${props.tilesetUrl} attached`));
return true;
}
/** Executes this tool's run method with args[0] containing `data`.
* @see [[run]]
*/
async parseAndRun(...args) {
return this.run(args[0]);
}
}
exports.AttachRealityModelTool = AttachRealityModelTool;
/** This tool saves a reality model's JSON representation to the system clipboard.
* @beta */
class SaveRealityModelTool extends core_frontend_1.Tool {
static toolId = "SaveRealityModelTool";
static get minArgs() { return 0; }
static get maxArgs() { return 1; }
/** This method runs the tool, saving a reality model's JSON representation to the system clipboard.
* @param name the name of the reality model to copy; if undefined, copy the last found reality model
*/
async run(name) {
const vp = core_frontend_1.IModelApp.viewManager.selectedView;
if (vp === undefined)
return false;
vp.displayStyle.forEachRealityModel((realityModel) => {
if (name === undefined || realityModel.name === name) {
(0, ClipboardUtilities_1.copyStringToClipboard)(JSON.stringify(realityModel.toJSON()));
core_frontend_1.IModelApp.notifications.outputMessage(new core_frontend_1.NotifyMessageDetails(core_frontend_1.OutputMessagePriority.Info, `Reality Model ${realityModel.name} copied to clipboard`));
}
});
return true;
}
/** Executes this tool's run method with args[0] containing `name`.
* @see [[run]]
*/
async parseAndRun(...args) {
return this.run(args.length > 0 ? args[0] : undefined);
}
}
exports.SaveRealityModelTool = SaveRealityModelTool;
function changeRealityModelAppearanceOverrides(vp, overrides, index) {
if (index < 0) {
for (const model of vp.displayStyle.settings.contextRealityModels.models)
model.appearanceOverrides = model.appearanceOverrides ? model.appearanceOverrides.clone(overrides) : core_common_1.FeatureAppearance.fromJSON(overrides);
return vp.displayStyle.settings.contextRealityModels.models.length > 0;
}
else {
const model = vp.displayStyle.settings.contextRealityModels.models[index];
if (!model)
return false;
model.appearanceOverrides = model.appearanceOverrides ? model.appearanceOverrides.clone(overrides) : core_common_1.FeatureAppearance.fromJSON(overrides);
return true;
}
}
function appearanceChangedString(index) {
return index < 0 ? `All Reality Models` : `Reality Model at Index: ${index}`;
}
/** Set reality model appearance override for transparency in display style.
* @beta
*/
class SetRealityModelTransparencyTool extends core_frontend_1.Tool {
static toolId = "SetRealityModelTransparencyTool";
static get minArgs() { return 1; }
static get maxArgs() { return 2; }
async run(transparency, index) {
const vp = core_frontend_1.IModelApp.viewManager.selectedView;
if (vp === undefined)
return false;
const changed = changeRealityModelAppearanceOverrides(vp, { transparency }, index);
if (changed)
core_frontend_1.IModelApp.notifications.outputMessage(new core_frontend_1.NotifyMessageDetails(core_frontend_1.OutputMessagePriority.Info, `${appearanceChangedString(index)} set to transparency: ${transparency}`));
return true;
}
async parseAndRun(...args) {
return this.run(parseFloat(args[0]), args.length > 1 ? parseInt(args[1], 10) : -1);
}
}
exports.SetRealityModelTransparencyTool = SetRealityModelTransparencyTool;
/** Set reality model appearance override for locatable in display style.
* @beta
*/
class SetRealityModelLocateTool extends core_frontend_1.Tool {
static toolId = "SetRealityModelLocateTool";
static get minArgs() { return 1; }
static get maxArgs() { return 2; }
async run(locate, index) {
const vp = core_frontend_1.IModelApp.viewManager.selectedView;
if (vp === undefined)
return false;
const nonLocatable = locate ? undefined : true;
const changed = changeRealityModelAppearanceOverrides(vp, { nonLocatable }, index);
if (changed)
core_frontend_1.IModelApp.notifications.outputMessage(new core_frontend_1.NotifyMessageDetails(core_frontend_1.OutputMessagePriority.Info, `${appearanceChangedString(index)} set to locate: ${locate}`));
return true;
}
async parseAndRun(...args) {
const locate = (0, parseBoolean_1.parseBoolean)(args[0]);
return locate === undefined ? false : this.run(locate, args.length > 1 ? parseInt(args[1], 10) : -1);
}
}
exports.SetRealityModelLocateTool = SetRealityModelLocateTool;
/** Set reality model appearance override for emphasized in display style.
* @beta
*/
class SetRealityModelEmphasizedTool extends core_frontend_1.Tool {
static toolId = "SetRealityModelEmphasizedTool";
static get minArgs() { return 1; }
static get maxArgs() { return 2; }
async run(emphasized, index) {
const vp = core_frontend_1.IModelApp.viewManager.selectedView;
if (vp === undefined)
return false;
const changed = changeRealityModelAppearanceOverrides(vp, { emphasized }, index);
if (changed)
core_frontend_1.IModelApp.notifications.outputMessage(new core_frontend_1.NotifyMessageDetails(core_frontend_1.OutputMessagePriority.Info, `${appearanceChangedString(index)} set to emphasized: ${emphasized}`));
return true;
}
async parseAndRun(...args) {
const emphasized = (0, parseBoolean_1.parseBoolean)(args[0]);
return emphasized === undefined ? false : this.run(emphasized ? true : undefined, args.length > 1 ? parseInt(args[1], 10) : -1);
}
}
exports.SetRealityModelEmphasizedTool = SetRealityModelEmphasizedTool;
/** Detach reality model from display style.
* @beta
*/
class DetachRealityModelTool extends core_frontend_1.Tool {
static toolId = "ViewportDetachRealityModel";
static get minArgs() { return 0; }
static get maxArgs() { return 1; }
async run(index) {
const vp = core_frontend_1.IModelApp.viewManager.selectedView;
if (vp === undefined)
return false;
if (index < 0) {
vp.displayStyle.settings.contextRealityModels.models.forEach((model) => vp.displayStyle.settings.contextRealityModels.delete(model));
return true;
}
else {
const model = vp.displayStyle.settings.contextRealityModels.models[index];
if (!model)
return false;
vp.displayStyle.settings.contextRealityModels.delete(model);
return true;
}
}
async parseAndRun(...args) {
return this.run(args.length > 0 ? parseInt(args[0], 10) : -1);
}
}
exports.DetachRealityModelTool = DetachRealityModelTool;
/** Set reality model appearance override for color in display style.
* @beta
*/
class SetRealityModelColorTool extends core_frontend_1.Tool {
static toolId = "SetRealityModelColorTool";
static get minArgs() { return 3; }
static get maxArgs() { return 4; }
async run(rgb, index) {
const vp = core_frontend_1.IModelApp.viewManager.selectedView;
if (vp === undefined)
return false;
const changed = changeRealityModelAppearanceOverrides(vp, { rgb }, index);
if (changed)
core_frontend_1.IModelApp.notifications.outputMessage(new core_frontend_1.NotifyMessageDetails(core_frontend_1.OutputMessagePriority.Info, `${appearanceChangedString(index)} 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.length > 3 ? parseInt(args[3], 10) : -1);
}
}
exports.SetRealityModelColorTool = SetRealityModelColorTool;
/** Clear reality model appearance override in display style.
* @beta
*/
class ClearRealityModelAppearanceOverrides extends core_frontend_1.Tool {
static toolId = "ClearRealityModelAppearanceOverrides";
static get minArgs() { return 0; }
static get maxArgs() { return 1; }
async run(index) {
const vp = core_frontend_1.IModelApp.viewManager.selectedView;
if (!vp)
return false;
const model = vp.displayStyle.settings.contextRealityModels.models[index];
if (!model)
return false;
model.appearanceOverrides = undefined;
return true;
}
async parseAndRun(...args) {
return this.run(args[0] === undefined ? -1 : parseInt(args[0], 10));
}
}
exports.ClearRealityModelAppearanceOverrides = ClearRealityModelAppearanceOverrides;
/** Attach a cesium asset from the Ion ID and key.
* @beta
*/
class AttachCesiumAssetTool extends core_frontend_1.Tool {
static toolId = "AttachCesiumAssetTool";
static get minArgs() { return 1; }
static get maxArgs() { return 2; }
async run(assetId, requestKey) {
const vp = core_frontend_1.IModelApp.viewManager.selectedView;
if (vp === undefined)
return false;
// attach using getCesiumAssetUrl
const accessKey = requestKey ? requestKey : core_frontend_1.IModelApp.tileAdmin.cesiumIonKey ? core_frontend_1.IModelApp.tileAdmin.cesiumIonKey : "";
const props = {
tilesetUrl: (0, core_frontend_1.getCesiumAssetUrl)(assetId, accessKey),
};
// Alternative new way to attach using rdSourceKey
// const rdSourceKey = RealityDataSource.createCesiumIonAssetKey(assetId, accessKey);
// const props: ContextRealityModelProps = { rdSourceKey, tilesetUrl: getCesiumAssetUrl(assetId, accessKey) };
vp.displayStyle.attachRealityModel(props);
core_frontend_1.IModelApp.notifications.outputMessage(new core_frontend_1.NotifyMessageDetails(core_frontend_1.OutputMessagePriority.Info, `Cesium Asset #${assetId} attached`));
return true;
}
async parseAndRun(...args) {
const assetId = parseInt(args[0], 10);
return Number.isNaN(assetId) ? false : this.run(assetId, args[1]);
}
}
exports.AttachCesiumAssetTool = AttachCesiumAssetTool;
/** Turn on/off display of OpenStreetMap buildings
* @beta
*/
class ToggleOSMBuildingDisplay extends core_frontend_1.Tool {
static toolId = "SetBuildingDisplay";
static get minArgs() { return 0; }
static get maxArgs() { return 2; }
async run(onOff, transparency) {
const vp = core_frontend_1.IModelApp.viewManager.selectedView;
if (vp === undefined)
return false;
if (onOff === undefined)
onOff = undefined === vp.displayStyle.getOSMBuildingRealityModel(); // Toggle current state.
const appearanceOverrides = (transparency !== undefined && transparency > 0 && transparency < 1) ? core_common_1.FeatureAppearance.fromJSON({ transparency }) : undefined;
vp.displayStyle.setOSMBuildingDisplay({ onOff, appearanceOverrides });
return true;
}
async parseAndRun(...args) {
const toggle = (0, parseToggle_1.parseToggle)(args[0]);
const transparency = args.length > 0 ? parseFloat(args[1]) : undefined;
return typeof toggle === "string" ? false : this.run(toggle, transparency);
}
}
exports.ToggleOSMBuildingDisplay = ToggleOSMBuildingDisplay;
//# sourceMappingURL=RealityModelTools.js.map