UNPKG

@itwin/frontend-devtools

Version:

Debug menu and supporting UI widgets

79 lines 3.3 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.ToggleTileTreeBoundsDecorationTool = void 0; /** @packageDocumentation * @module Tools */ const core_common_1 = require("@itwin/core-common"); const core_frontend_1 = require("@itwin/core-frontend"); const parseToggle_1 = require("./parseToggle"); class TreeDecoration { static _instance; _removeMe; constructor() { this._removeMe = core_frontend_1.IModelApp.viewManager.addDecorator(this); } stop() { if (this._removeMe) { this._removeMe(); this._removeMe = undefined; } } /** This will allow the render system to cache and reuse the decorations created by this decorator's decorate() method. */ useCachedDecorations = true; decorate(context) { for (const ref of context.viewport.getTileTreeRefs()) { this.drawBoundingBox(ref, context); } } drawBoundingBox(ref, context) { const tree = ref.treeOwner.tileTree; const location = ref.getLocation(); if (undefined === location || undefined === tree || tree.isContentUnbounded || tree.range.isNull) return; const builder = context.createGraphicBuilder(core_frontend_1.GraphicType.WorldDecoration, location); builder.setSymbology(core_common_1.ColorDef.green, core_common_1.ColorDef.green, 1, core_common_1.LinePixels.Solid); builder.addRangeBox(tree.range); if (undefined !== tree.contentRange) { builder.setSymbology(core_common_1.ColorDef.red, core_common_1.ColorDef.red, 1, core_common_1.LinePixels.Solid); builder.addRangeBox(tree.contentRange); } context.addDecorationFromBuilder(builder); } static toggle(enabled) { const instance = TreeDecoration._instance; if (undefined !== enabled && (undefined !== instance) === enabled) return; if (undefined === instance) { TreeDecoration._instance = new TreeDecoration(); } else { instance.stop(); TreeDecoration._instance = undefined; } } } /** Display in every viewport a green range graphic for each displayed tile tree, plus a red range graphic for each tile tree's content range if defined. * @beta */ class ToggleTileTreeBoundsDecorationTool extends core_frontend_1.Tool { static toolId = "ToggleTileTreeBoundsDecoration"; static get minArgs() { return 0; } static get maxArgs() { return 1; } async run(enable) { TreeDecoration.toggle(enable); return true; } async parseAndRun(...args) { const enable = (0, parseToggle_1.parseToggle)(args[0]); if (typeof enable !== "string") await this.run(enable); return true; } } exports.ToggleTileTreeBoundsDecorationTool = ToggleTileTreeBoundsDecorationTool; //# sourceMappingURL=TileTreeBoundsDecoration.js.map