@itwin/frontend-devtools
Version:
Debug menu and supporting UI widgets
38 lines • 1.65 kB
JavaScript
/*---------------------------------------------------------------------------------------------
* 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 { IModelApp, Tool } from "@itwin/core-frontend";
import { parseToggle } from "./parseToggle";
// CSpell: ignore fmtr
/** Controls whether quantities are formatted using imperial or metric units.
* Such formatting is used in many places; one example is the output of the MeasureTool.
* @beta
*/
export class ChangeUnitsTool extends Tool {
static toolId = "ChangeUnits";
static get minArgs() { return 0; }
static get maxArgs() { return 1; }
// support boolean for backwards compatibility
async run(useMetric) {
const fmtr = IModelApp.quantityFormatter;
// if no arg then toggle to metric from any non-metric unit system
const useImperial = undefined !== useMetric ? !useMetric : fmtr.activeUnitSystem === "metric";
const unitSystem = useImperial ? "imperial" : "metric";
if (unitSystem !== fmtr.activeUnitSystem) {
await fmtr.setActiveUnitSystem(unitSystem);
await IModelApp.toolAdmin.startDefaultTool();
}
return true;
}
async parseAndRun(...args) {
const enable = parseToggle(args[0]);
if (typeof enable !== "string")
await this.run(enable);
return true;
}
}
//# sourceMappingURL=ChangeUnitsTool.js.map