-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathMeasureToolsUiProvider.tsx
More file actions
153 lines (143 loc) · 6.18 KB
/
MeasureToolsUiProvider.tsx
File metadata and controls
153 lines (143 loc) · 6.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*---------------------------------------------------------------------------------------------
* 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 type { ToolbarItem, ToolItemDef, UiItemsProvider, Widget } from "@itwin/appui-react";
import {
StagePanelLocation, StagePanelSection, StageUsage, SyncUiEventId, ToolbarHelper, ToolbarItemUtilities,
ToolbarOrientation, ToolbarUsage, WidgetState,
} from "@itwin/appui-react";
import { MeasurementSyncUiEventId } from "../api/MeasurementEnums";
import { MeasurementUIEvents } from "../api/MeasurementUIEvents";
import { MeasureTools } from "../MeasureTools";
import { MeasureToolDefinitions } from "../tools/MeasureToolDefinitions";
import type { RecursiveRequired } from "../utils/types";
import { MeasurementPropertyWidget, MeasurementPropertyWidgetId } from "./MeasurementPropertyWidget";
import { IModelApp } from "@itwin/core-frontend";
import { Feature, FeatureTracking } from "../measure-tools-react";
// Note: measure tools cannot pick geometry when a sheet view is active to snap to and therefore must be hidden
// to avoid giving the user the impression they should work
const isSheetViewActive = () => !!IModelApp.viewManager.selectedView?.view?.isSheetView();
export interface MeasureToolsUiProviderOptions {
itemPriority?: number;
groupPriority?: number;
widgetPlacement?: {
location: StagePanelLocation;
section?: StagePanelSection;
};
// If we check for sheet to 3d transformation when measuring in sheets
enableSheetMeasurement?: boolean;
stageUsageList?: string[];
// Callback that is invoked when a tracked feature is used.
onFeatureUsed?: (feature: Feature) => void;
}
export class MeasureToolsUiItemsProvider implements UiItemsProvider {
public readonly id = "MeasureToolsUiItemsProvider";
private _props: Omit<RecursiveRequired<MeasureToolsUiProviderOptions>, 'onFeatureUsed'>;
constructor(props?: MeasureToolsUiProviderOptions) {
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],
};
if (!FeatureTracking.onFeature.numberOfListeners && props?.onFeatureUsed)
FeatureTracking.onFeature.addListener(props?.onFeatureUsed);
}
public provideToolbarItems(
_stageId: string,
stageUsage: string,
toolbarUsage: ToolbarUsage,
toolbarOrientation: ToolbarOrientation,
): ToolbarItem[] {
if (this._props.stageUsageList.includes(stageUsage) && toolbarUsage === ToolbarUsage.ContentManipulation) {
const featureFlags = MeasureTools.featureFlags;
const tools: ToolItemDef[] = [];
if (!featureFlags?.hideDistanceTool) {
tools.push(MeasureToolDefinitions.getMeasureDistanceToolCommand(this._props.enableSheetMeasurement));
}
if (!featureFlags?.hideAreaTool) {
tools.push(MeasureToolDefinitions.getMeasureAreaToolCommand(this._props.enableSheetMeasurement));
}
if (!featureFlags?.hideLocationTool) {
tools.push(MeasureToolDefinitions.getMeasureLocationToolCommand(this._props.enableSheetMeasurement));
}
if (!featureFlags?.hideRadiusTool) {
tools.push(MeasureToolDefinitions.measureRadiusToolCommand);
}
if (!featureFlags?.hideAngleTool) {
tools.push(MeasureToolDefinitions.measureAngleToolCommand);
}
if (!featureFlags?.hidePerpendicularTool) {
tools.push(MeasureToolDefinitions.measurePerpendicularToolCommand);
}
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(
isSheetViewActive,
[SyncUiEventId.ViewStateChanged],
),
},
),
];
}
if (tools.length > 0 && toolbarOrientation === ToolbarOrientation.Horizontal) {
return [
ToolbarHelper.createToolbarItemFromItemDef(
100,
MeasureToolDefinitions.clearMeasurementsToolCommand,
{
isHidden: new ConditionalBooleanValue(
() => isSheetViewActive() || !MeasurementUIEvents.isClearMeasurementButtonVisible,
[
SyncUiEventId.ViewStateChanged,
MeasurementSyncUiEventId.MeasurementSelectionSetChanged,
MeasurementSyncUiEventId.DynamicMeasurementChanged,
],
),
},
),
];
}
}
return [];
}
public provideWidgets(
_stageId: string,
stageUsage: string,
location: StagePanelLocation,
section?: StagePanelSection | undefined,
): ReadonlyArray<Widget> {
const widgets: Widget[] = [];
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: <MeasurementPropertyWidget />,
defaultState: WidgetState.Hidden,
icon: "icon-measure",
});
}
}
return widgets;
}
}