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