UNPKG

@itwin/frontend-devtools

Version:

Debug menu and supporting UI widgets

83 lines 3.35 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 TileRequestDecoration { static _instance; _removeDecorator; _targetVp; constructor(vp) { this._targetVp = vp; this._removeDecorator = IModelApp.viewManager.addDecorator(this); } stop() { if (this._removeDecorator) { this._removeDecorator(); this._removeDecorator = undefined; } } /** This will allow the render system to cache and reuse the decorations created by this decorator's decorate() method. */ useCachedDecorations = true; decorate(context) { const tiles = IModelApp.tileAdmin.getRequestsForUser(this._targetVp); if (undefined === tiles) return; const map = new Map(); for (const tile of tiles) { let builder = map.get(tile.tree); if (undefined === builder) { builder = context.createGraphicBuilder(GraphicType.WorldDecoration, tile.tree.iModelTransform); map.set(tile.tree, builder); } let color = ColorDef.white; if (undefined !== tile.request) color = tile.request.isQueued ? ColorDef.green : ColorDef.red; builder.setSymbology(color, color, 1, LinePixels.Solid); builder.addRangeBox(tile.range); } for (const builder of map.values()) context.addDecorationFromBuilder(builder); } static toggle(vp, enabled) { const instance = TileRequestDecoration._instance; if (undefined !== enabled) { if ((undefined !== instance) === enabled) return; } if (undefined === instance) { TileRequestDecoration._instance = new TileRequestDecoration(vp); } else { instance.stop(); TileRequestDecoration._instance = undefined; } } } /** Display in every viewport a range graphic for every tile currently being requested for the viewport that was initially selected when the decorator was installed. * Green indicates queued (http request not yet sent), red indicates active (http request sent). White indicates unexpected state. * @beta */ export class ToggleTileRequestDecorationTool extends Tool { static toolId = "ToggleTileRequestDecoration"; static get minArgs() { return 0; } static get maxArgs() { return 1; } async run(enable) { const vp = IModelApp.viewManager.selectedView; if (undefined !== vp) TileRequestDecoration.toggle(vp, enable); return true; } async parseAndRun(...args) { const enable = parseToggle(args[0]); if (typeof enable !== "string") await this.run(enable); return true; } } //# sourceMappingURL=TileRequestDecoration.js.map