@itwin/frontend-devtools
Version:
Debug menu and supporting UI widgets
86 lines • 3.47 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.DumpSelectionSetTool = exports.SelectElementsByIdTool = void 0;
/** @packageDocumentation
* @module Tools
*/
const core_bentley_1 = require("@itwin/core-bentley");
const core_frontend_1 = require("@itwin/core-frontend");
const ClipboardUtilities_1 = require("../ClipboardUtilities");
const parseArgs_1 = require("./parseArgs");
/** Replaces the contents of the selection set with the set of element Ids specified.
* Element Ids are separated by whitespace.
* @beta
*/
class SelectElementsByIdTool extends core_frontend_1.Tool {
static toolId = "SelectElementsById";
static get minArgs() { return 1; }
static get maxArgs() { return undefined; }
async run(ids) {
const vp = core_frontend_1.IModelApp.viewManager.selectedView;
if (undefined !== vp && undefined !== ids)
vp.iModel.selectionSet.replace(ids);
return true;
}
async parseAndRun(...args) {
return this.run(args);
}
}
exports.SelectElementsByIdTool = SelectElementsByIdTool;
/** A tool that outputs the Ids of the elements in the [SelectionSet]($frontend) of the [IModelConnection]($frontend) associated with the selected [Viewport]($frontend).
* @beta
*/
class DumpSelectionSetTool extends core_frontend_1.Tool {
static toolId = "DumpSelectionSet";
static get minArgs() { return 0; }
static get maxArgs() { return 2; }
_format = "list";
_copy;
async run() {
const vp = core_frontend_1.IModelApp.viewManager.selectedView;
if (!vp)
return false;
const elems = Array.from(vp.iModel.selectionSet.elements);
core_bentley_1.OrderedId64Iterable.sortArray(elems);
let output;
switch (this._format) {
case "compressed":
output = core_bentley_1.CompressedId64Set.compressArray(elems);
break;
case "json":
output = JSON.stringify(elems);
break;
default:
output = elems.join(" ");
break;
}
if (this._copy)
(0, ClipboardUtilities_1.copyStringToClipboard)(output);
const brief = `Selection set dumped${this._copy ? " to clipboard" : ""}.`;
const details = new core_frontend_1.NotifyMessageDetails(core_frontend_1.OutputMessagePriority.Info, brief, output);
core_frontend_1.IModelApp.notifications.outputMessage(details);
return true;
}
async parseAndRun(...input) {
const args = (0, parseArgs_1.parseArgs)(input);
this._copy = args.getBoolean("c");
const formatArg = args.get("f");
if (formatArg) {
switch (formatArg[0].toLowerCase()) {
case "j":
this._format = "json";
break;
case "c":
this._format = "compressed";
break;
}
}
return this.run();
}
}
exports.DumpSelectionSetTool = DumpSelectionSetTool;
//# sourceMappingURL=SelectionTools.js.map