@itwin/frontend-devtools
Version:
Debug menu and supporting UI widgets
114 lines • 5.06 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.ToggleProjectExtentsTool = exports.ProjectExtentsDecoration = void 0;
exports.toggleProjectExtents = toggleProjectExtents;
/** @packageDocumentation
* @module Tools
*/
const core_common_1 = require("@itwin/core-common");
const core_frontend_1 = require("@itwin/core-frontend");
const parseToggle_1 = require("./parseToggle");
/** @beta */
class ProjectExtentsDecoration {
static _decorator;
_removeDecorationListener;
_extents;
constructor(iModel) {
this._extents = iModel.projectExtents;
this.updateDecorationListener(true);
}
stop() { this.updateDecorationListener(false); }
updateDecorationListener(add) {
if (this._removeDecorationListener) {
if (!add) {
this._removeDecorationListener();
this._removeDecorationListener = undefined;
}
}
else if (add) {
if (!this._removeDecorationListener)
this._removeDecorationListener = core_frontend_1.IModelApp.viewManager.addDecorator(this);
}
}
static get isActive() {
return undefined !== ProjectExtentsDecoration._decorator;
}
/** This will allow the render system to cache and reuse the decorations created by this decorator's decorate() method. */
useCachedDecorations = true;
decorate(context) {
const vp = context.viewport;
if (!vp.view.isSpatialView())
return;
const builderAccVis = context.createGraphicBuilder(core_frontend_1.GraphicType.WorldDecoration);
const builderAccHid = context.createGraphicBuilder(core_frontend_1.GraphicType.WorldOverlay);
const colorAccVis = core_common_1.ColorDef.white.adjustedForContrast(context.viewport.view.backgroundColor);
const colorAccHid = colorAccVis.withAlpha(100);
builderAccVis.setSymbology(colorAccVis, core_common_1.ColorDef.black, 3);
builderAccHid.setSymbology(colorAccHid, core_common_1.ColorDef.black, 1, core_common_1.LinePixels.Code2);
builderAccVis.addRangeBox(this._extents);
builderAccHid.addRangeBox(this._extents);
context.addDecorationFromBuilder(builderAccVis);
context.addDecorationFromBuilder(builderAccHid);
}
// Returns true if extents become enabled.
static toggle(imodel, enabled) {
if (undefined !== enabled) {
const alreadyEnabled = undefined !== ProjectExtentsDecoration._decorator;
if (enabled === alreadyEnabled)
return alreadyEnabled;
}
if (undefined === ProjectExtentsDecoration._decorator) {
ProjectExtentsDecoration._decorator = new ProjectExtentsDecoration(imodel);
return true;
}
else {
ProjectExtentsDecoration._decorator.stop();
ProjectExtentsDecoration._decorator = undefined;
return false;
}
}
}
exports.ProjectExtentsDecoration = ProjectExtentsDecoration;
/** Enable or disable the project extents decoration. This decoration draws a box coinciding with the iModel's project extents.
* @param imodel The iModel from which to obtain the extents.
* @param enable If undefined, the current enabled state of the decoration will be inverted; otherwise it will be enabled if true, or disabled if false.
* @returns true if the extents are now ON, false if they are now OFF.
* @beta
*/
function toggleProjectExtents(imodel, enabled) {
return ProjectExtentsDecoration.toggle(imodel, enabled);
}
/** Enable or disable project extents decoration.
* The key-in takes at most 1 argument (case-insensitive):
* - "ON" => enable project extents
* - "OFF" => disable project extents
* - "TOGGLE" or omitted => toggle project extents
* @see [toggleProjectExtents]
* @beta
*/
class ToggleProjectExtentsTool extends core_frontend_1.Tool {
static toolId = "ToggleProjectExtents";
static get minArgs() { return 0; }
static get maxArgs() { return 1; }
async run(enable) {
const vp = core_frontend_1.IModelApp.viewManager.selectedView;
if (undefined !== vp && vp.view.isSpatialView()) {
const iModel = vp.iModel;
if (toggleProjectExtents(iModel, enable))
vp.onChangeView.addOnce(() => toggleProjectExtents(iModel, false));
}
return true;
}
async parseAndRun(...args) {
const enable = (0, parseToggle_1.parseToggle)(args[0]);
if (typeof enable !== "string")
await this.run(enable);
return true;
}
}
exports.ToggleProjectExtentsTool = ToggleProjectExtentsTool;
//# sourceMappingURL=ProjectExtents.js.map