UNPKG

@itwin/frontend-devtools

Version:

Debug menu and supporting UI widgets

86 lines 4.9 kB
"use strict"; /*--------------------------------------------------------------------------------------------- * 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.ElementIdFromSourceAspectIdTool = exports.SourceAspectIdFromElementIdTool = exports.SourceAspectIdTool = void 0; /** @packageDocumentation * @module Tools */ const core_bentley_1 = require("@itwin/core-bentley"); const core_common_1 = require("@itwin/core-common"); const core_frontend_1 = require("@itwin/core-frontend"); const ClipboardUtilities_1 = require("../ClipboardUtilities"); const parseArgs_1 = require("./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 */ class SourceAspectIdTool extends core_frontend_1.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 = (0, parseArgs_1.parseArgs)(keyinArgs); return this.run(args.get("i"), args.getBoolean("c")); } async doQuery(queryId, copyToClipboard) { const imodel = core_frontend_1.IModelApp.viewManager.selectedView?.iModel; if (undefined === imodel) return; let resultId; try { for await (const row of imodel.createQueryReader(this.getECSql(queryId), undefined, { rowFormat: core_common_1.QueryRowFormat.UseJsPropertyNames, limit: { count: 1 } })) resultId = row.resultId; } catch (ex) { resultId = core_bentley_1.BentleyError.getErrorMessage(ex); } if (typeof resultId !== "string") resultId = "NOT FOUND"; if (copyToClipboard) (0, ClipboardUtilities_1.copyStringToClipboard)(resultId); const message = `${queryId} => ${resultId}`; core_frontend_1.IModelApp.notifications.outputMessage(new core_frontend_1.NotifyMessageDetails(core_frontend_1.OutputMessagePriority.Info, message)); } } exports.SourceAspectIdTool = SourceAspectIdTool; /** 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 */ class SourceAspectIdFromElementIdTool extends SourceAspectIdTool { static toolId = "SourceAspectIdFromElementId"; getECSql(queryId) { return `SELECT Identifier as resultId FROM BisCore.ExternalSourceAspect WHERE Element.Id=${queryId} AND [Kind]='Element'`; } } exports.SourceAspectIdFromElementIdTool = SourceAspectIdFromElementIdTool; /** 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 */ class ElementIdFromSourceAspectIdTool extends SourceAspectIdTool { static toolId = "ElementIdFromSourceAspectId"; getECSql(queryId) { return `SELECT Element.Id as resultId FROM BisCore.ExternalSourceAspect WHERE Identifier='${queryId}' AND [Kind]='Element'`; } } exports.ElementIdFromSourceAspectIdTool = ElementIdFromSourceAspectIdTool; //# sourceMappingURL=SourceAspectIdTools.js.map