UNPKG

@itwin/measure-tools-react

Version:
99 lines 5.87 kB
/*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ import * as React from "react"; import { ConditionalBooleanValue } from "@itwin/appui-abstract"; import { StagePanelLocation, StagePanelSection, StageUsage, SyncUiEventId, ToolbarHelper, ToolbarItemUtilities, ToolbarOrientation, ToolbarUsage, WidgetState, } from "@itwin/appui-react"; import { MeasurementSyncUiEventId } from "../api/MeasurementEnums.js"; import { MeasurementUIEvents } from "../api/MeasurementUIEvents.js"; import { MeasureTools } from "../MeasureTools.js"; import { MeasureToolDefinitions } from "../tools/MeasureToolDefinitions.js"; import { MeasurementPropertyWidget, MeasurementPropertyWidgetId } from "./MeasurementPropertyWidget.js"; import { IModelApp } from "@itwin/core-frontend"; export class MeasureToolsUiItemsProvider { constructor(props) { this.id = "MeasureToolsUiItemsProvider"; this._props = { itemPriority: props?.itemPriority ?? 20, groupPriority: props?.groupPriority ?? 10, widgetPlacement: { location: props?.widgetPlacement?.location ?? StagePanelLocation.Right, section: props?.widgetPlacement?.section ?? StagePanelSection.Start, }, enableSheetMeasurement: props?.enableSheetMeasurement ?? false, stageUsageList: props?.stageUsageList ?? [StageUsage.General], allowedViewportCallback: props?.allowedViewportCallback ?? ((_vp) => { return true; }), additionalToolbarItems: props?.additionalToolbarItems, isHiddenCallback: props?.isHiddenCallback ?? ((_activeViewport) => false), }; } provideToolbarItems(_stageId, stageUsage, toolbarUsage, toolbarOrientation) { if (this._props.stageUsageList.includes(stageUsage) && toolbarUsage === ToolbarUsage.ContentManipulation) { const featureFlags = MeasureTools.featureFlags; const tools = []; const callback = this._props.allowedViewportCallback; const isHiddenCallbackFunc = this._props.isHiddenCallback; if (!featureFlags?.hideDistanceTool) { tools.push(MeasureToolDefinitions.getMeasureDistanceToolCommand(callback, this._props.enableSheetMeasurement)); } if (!featureFlags?.hideAreaTool) { tools.push(MeasureToolDefinitions.getMeasureAreaToolCommand(callback, this._props.enableSheetMeasurement)); } if (!featureFlags?.hideLocationTool) { tools.push(MeasureToolDefinitions.getMeasureLocationToolCommand(callback, this._props.enableSheetMeasurement)); } if (!featureFlags?.hideRadiusTool) { tools.push(MeasureToolDefinitions.getMeasureRadiusToolCommand(callback)); } if (!featureFlags?.hideAngleTool) { tools.push(MeasureToolDefinitions.getMeasureAngleToolCommand(callback)); } if (!featureFlags?.hidePerpendicularTool) { tools.push(MeasureToolDefinitions.getMeasurePerpendicularToolCommand(callback)); } if (this._props.additionalToolbarItems) { tools.push(...this._props.additionalToolbarItems); } if (toolbarOrientation === ToolbarOrientation.Vertical) { return [ ToolbarItemUtilities.createGroupItem("measure-tools-toolbar", this._props.itemPriority, "icon-measure", MeasureTools.localization.getLocalizedString("MeasureTools:MeasurementGroupButton.tooltip"), ToolbarHelper.constructChildToolbarItems(tools), { groupPriority: this._props.groupPriority, isHidden: new ConditionalBooleanValue(() => isHiddenCallbackFunc(IModelApp.viewManager.selectedView), [SyncUiEventId.ActiveViewportChanged, SyncUiEventId.ViewStateChanged]), }), ]; } if (tools.length > 0 && toolbarOrientation === ToolbarOrientation.Horizontal) { return [ ToolbarHelper.createToolbarItemFromItemDef(100, MeasureToolDefinitions.clearMeasurementsToolCommand, { isHidden: new ConditionalBooleanValue(() => !MeasurementUIEvents.isClearMeasurementButtonVisible, [ SyncUiEventId.ActiveViewportChanged, SyncUiEventId.ViewStateChanged, MeasurementSyncUiEventId.MeasurementSelectionSetChanged, MeasurementSyncUiEventId.DynamicMeasurementChanged, ]), }), ]; } } return []; } provideWidgets(_stageId, stageUsage, location, section) { const widgets = []; const preferredLocation = this._props.widgetPlacement.location; const preferredSection = this._props.widgetPlacement.section; if (this._props.stageUsageList.includes(stageUsage) && location === preferredLocation && section === preferredSection) { { widgets.push({ id: MeasurementPropertyWidgetId, label: MeasureTools.localization.getLocalizedString("MeasureTools:Generic.measurements"), content: React.createElement(MeasurementPropertyWidget, null), defaultState: WidgetState.Hidden, icon: "icon-measure", }); } } return widgets; } } //# sourceMappingURL=MeasureToolsUiProvider.js.map