-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow Users to Pass Function to Measure-Tools Feature Tracking #1029
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ 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 | ||
|
@@ -32,11 +33,15 @@ export interface MeasureToolsUiProviderOptions { | |
// 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: RecursiveRequired<MeasureToolsUiProviderOptions>; | ||
private _props: Omit<RecursiveRequired<MeasureToolsUiProviderOptions>, 'onFeatureUsed'> & { | ||
onFeatureUsed?: (feature: Feature) => void; | ||
}; | ||
|
||
constructor(props?: MeasureToolsUiProviderOptions) { | ||
this._props = { | ||
|
@@ -48,7 +53,10 @@ export class MeasureToolsUiItemsProvider implements UiItemsProvider { | |
}, | ||
enableSheetMeasurement: props?.enableSheetMeasurement ?? false, | ||
stageUsageList: props?.stageUsageList ?? [StageUsage.General], | ||
onFeatureUsed: props?.onFeatureUsed, | ||
}; | ||
if (!FeatureTracking.onFeature.numberOfListeners && this._props.onFeatureUsed) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd nix the condition checking the number of listeners. @aruniverse Do UI providers ever get cleaned up? Or only ever created once per app lifetime? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reason for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With FeatureTracking.onFeature being public, I don't think it's appropriate to assume that nobody else is listening for that event. It doesn't seem acceptable to have this not work because the event is already being listened to by somebody else. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like the interface has a cleanup mechanism: https://www.itwinjs.org/reference/appui-react/uiprovider/uiitemsprovider/onunregister/ TBH something like this belongs better in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, I can implement it as a startup option instead. However, its usage will be different from tree-widget package (where you can provide onFeatureUsed callback function to UI Provider). If you are fine with that, I will do it right away. Thank you! |
||
FeatureTracking.onFeature.addListener(this._props.onFeatureUsed); | ||
} | ||
|
||
public provideToolbarItems( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is getting a bit confusing, especially since it doesn't seem like
this._props.onFeatureUsed
is used outside of the constructor: why should it be added tothis._props
at all? One idea is to each of the_props
members into its own private member. Then we wouldn't have this unnecessary coupling between internal state and arguments.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, onFeatureUsed is indeed used in constructor only. I will remove
& { onFeatureUsed?: (feature: Feature) => void; };
part and directly useprops?.onFeatureUsed
instead. This is also reasonable as it does not make a lot of sense to initialize onFeatureUsed with any default value if it is a member ofthis._props
About the idea to each of the
_props
members into its own private member, I think we can do that in another PR where we can replace_props
usage with those private properties. But does that mean we do not needRecursiveRequired
introduced in this commit (to make sure all_props
members initialized with at least some value) anymore?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I was just thinking that perhaps someone would come along and do something similar for another arg that wasn't used outside of the constructor, but whichever you feel more comfortable doing. Just an observation. This repo/file isn't my code so don't want to impose.