@itwin/frontend-devtools
Version:
Debug menu and supporting UI widgets
80 lines • 4.41 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 { BentleyError } from "@itwin/core-bentley";
import { QueryRowFormat } from "@itwin/core-common";
import { IModelApp, NotifyMessageDetails, OutputMessagePriority, Tool } from "@itwin/core-frontend";
import { copyStringToClipboard } from "../ClipboardUtilities";
import { parseArgs } from "./parseArgs";
/** Base class for a tool that can convert between source aspect Ids and element Ids.
* A "source aspect Id" is a string that identifies an object (such as an element) in the source document from which the iModel originated.
* For example, if the iModel was produced by the MicroStation bridge, the source aspect Id is usually a V8 element Id.
* @beta
*/
export class SourceAspectIdTool extends Tool {
static get minArgs() { return 1; }
static get maxArgs() { return 2; }
async run(idToQuery, copyToClipboard) {
if (typeof idToQuery === "string")
await this.doQuery(idToQuery, true === copyToClipboard);
return true;
}
async parseAndRun(...keyinArgs) {
const args = parseArgs(keyinArgs);
return this.run(args.get("i"), args.getBoolean("c"));
}
async doQuery(queryId, copyToClipboard) {
const imodel = IModelApp.viewManager.selectedView?.iModel;
if (undefined === imodel)
return;
let resultId;
try {
for await (const row of imodel.createQueryReader(this.getECSql(queryId), undefined, { rowFormat: QueryRowFormat.UseJsPropertyNames, limit: { count: 1 } }))
resultId = row.resultId;
}
catch (ex) {
resultId = BentleyError.getErrorMessage(ex);
}
if (typeof resultId !== "string")
resultId = "NOT FOUND";
if (copyToClipboard)
copyStringToClipboard(resultId);
const message = `${queryId} => ${resultId}`;
IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Info, message));
}
}
/** Given a source aspect Id, output the Id of the corresponding element in the iModel.
* A "source aspect Id" is a string that identifies an object (such as an element) in the source document from which the iModel originated.
* For example, if the iModel was produced by the MicroStation bridge, the source aspect Id is usually a V8 element Id.
* Arguments:
* - `id=elementId` where `elementId` is the numeric Id of the element of interest (e.g., `0x13a6c`; decimal notation is also permitted).
* - `copy=0|1` where `1` indicates the source aspect Id should be copied to the clipboard.
* The command outputs to the IModelApp.notifications the corresponding source aspect Id, or "NOT FOUND".
* @beta
*/
export class SourceAspectIdFromElementIdTool extends SourceAspectIdTool {
static toolId = "SourceAspectIdFromElementId";
getECSql(queryId) {
return `SELECT Identifier as resultId FROM BisCore.ExternalSourceAspect WHERE Element.Id=${queryId} AND [Kind]='Element'`;
}
}
/** Given the Id of an element in the iModel, output the source aspect Id of the object in the source document from which the element originated.
* A "source aspect Id" is a string that identifies an object (such as an element) in the source document from which the iModel originated.
* For example, if the iModel was produced by the MicroStation bridge, the source aspect Id is usually a V8 element Id.
* Arguments:
* - `id=sourceAspectId` where `sourceAspectId` is the string identifier of the object of interest.
* - `copy=0|1` where `1` indicates the element Id should be copied to the clipboard.
* The command outputs to the IModelApp.notifications the corresponding element Id, or "NOT FOUND".
* @beta
*/
export class ElementIdFromSourceAspectIdTool extends SourceAspectIdTool {
static toolId = "ElementIdFromSourceAspectId";
getECSql(queryId) {
return `SELECT Element.Id as resultId FROM BisCore.ExternalSourceAspect WHERE Identifier='${queryId}' AND [Kind]='Element'`;
}
}
//# sourceMappingURL=SourceAspectIdTools.js.map