UNPKG

@itwin/frontend-devtools

Version:

Debug menu and supporting UI widgets

71 lines 2.92 kB
/*--------------------------------------------------------------------------------------------- * 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 { ColorDef, LinePixels } from "@itwin/core-common"; import { GraphicType, IModelApp, Tool } from "@itwin/core-frontend"; import { parseToggle } from "./parseToggle"; class TreeDecoration { constructor() { /** This will allow the render system to cache and reuse the decorations created by this decorator's decorate() method. */ this.useCachedDecorations = true; this._removeMe = IModelApp.viewManager.addDecorator(this); } stop() { if (this._removeMe) { this._removeMe(); this._removeMe = undefined; } } decorate(context) { context.viewport.forEachTileTreeRef((ref) => 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(GraphicType.WorldDecoration, location); builder.setSymbology(ColorDef.green, ColorDef.green, 1, LinePixels.Solid); builder.addRangeBox(tree.range); if (undefined !== tree.contentRange) { builder.setSymbology(ColorDef.red, ColorDef.red, 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 */ export class ToggleTileTreeBoundsDecorationTool extends Tool { static get minArgs() { return 0; } static get maxArgs() { return 1; } async run(enable) { TreeDecoration.toggle(enable); return true; } async parseAndRun(...args) { const enable = parseToggle(args[0]); if (typeof enable !== "string") await this.run(enable); return true; } } ToggleTileTreeBoundsDecorationTool.toolId = "ToggleTileTreeBoundsDecoration"; //# sourceMappingURL=TileTreeBoundsDecoration.js.map