@itwin/frontend-devtools
Version:
Debug menu and supporting UI widgets
87 lines • 3.68 kB
JavaScript
;
/*---------------------------------------------------------------------------------------------
* 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.ToggleTileRequestDecorationTool = 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 TileRequestDecoration {
static _instance;
_removeDecorator;
_targetVp;
constructor(vp) {
this._targetVp = vp;
this._removeDecorator = core_frontend_1.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 = core_frontend_1.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(core_frontend_1.GraphicType.WorldDecoration, tile.tree.iModelTransform);
map.set(tile.tree, builder);
}
let color = core_common_1.ColorDef.white;
if (undefined !== tile.request)
color = tile.request.isQueued ? core_common_1.ColorDef.green : core_common_1.ColorDef.red;
builder.setSymbology(color, color, 1, core_common_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
*/
class ToggleTileRequestDecorationTool extends core_frontend_1.Tool {
static toolId = "ToggleTileRequestDecoration";
static get minArgs() { return 0; }
static get maxArgs() { return 1; }
async run(enable) {
const vp = core_frontend_1.IModelApp.viewManager.selectedView;
if (undefined !== vp)
TileRequestDecoration.toggle(vp, 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.ToggleTileRequestDecorationTool = ToggleTileRequestDecorationTool;
//# sourceMappingURL=TileRequestDecoration.js.map