init
This commit is contained in:
@@ -0,0 +1,120 @@
|
||||
---
|
||||
source_files:
|
||||
- DTS Viewer/DTS.Viewer.Modules/DTS.Viewer.ViewerSettings/ViewModel/ViewerSettingsViewModel.cs
|
||||
generated_at: "2026-04-16T13:49:48.286150+00:00"
|
||||
model: "zai-org/GLM-5-FP8"
|
||||
schema_version: 1
|
||||
sha256: "f93455d3d5a535ba"
|
||||
---
|
||||
|
||||
# Documentation: ViewerSettingsViewModel
|
||||
|
||||
## 1. Purpose
|
||||
|
||||
`ViewerSettingsViewModel` is a Prism-based view model for the Viewer Settings module within the DTS Viewer application. It manages user-configurable settings related to calibration behaviors, handles visibility states for settings UI elements, and coordinates with parent view models via event aggregation. The class serves as the binding context for `IViewerSettingsView` and participates in the application's region-based navigation system.
|
||||
|
||||
---
|
||||
|
||||
## 2. Public Interface
|
||||
|
||||
### Constructor
|
||||
|
||||
```csharp
|
||||
public ViewerSettingsViewModel(
|
||||
IViewerSettingsView view,
|
||||
IRegionManager regionManager,
|
||||
IEventAggregator eventAggregator,
|
||||
IUnityContainer unityContainer)
|
||||
```
|
||||
Initializes the view model, sets the view's DataContext to itself, and creates `NotificationRequest` and `ConfirmationRequest` interaction requests.
|
||||
|
||||
### Methods
|
||||
|
||||
```csharp
|
||||
public override void Initialize()
|
||||
```
|
||||
Empty override. No initialization logic performed.
|
||||
|
||||
```csharp
|
||||
public override void Initialize(object parameter)
|
||||
```
|
||||
Sets `Parent` property from the provided parameter (cast to `IBaseViewModel`) and calls `Subscribe()` to register event handlers.
|
||||
|
||||
```csharp
|
||||
public void PublishChanges()
|
||||
```
|
||||
Empty implementation. No behavior defined in source.
|
||||
|
||||
### Properties
|
||||
|
||||
| Property | Type | Description |
|
||||
|----------|------|-------------|
|
||||
| `View` | `IViewerSettingsView` | Gets/sets the associated view interface. |
|
||||
| `Parent` | `IBaseViewModel` | Gets/sets the parent view model reference. |
|
||||
| `NotificationRequest` | `InteractionRequest<Notification>` | Interaction request for notifications. |
|
||||
| `ConfirmationRequest` | `InteractionRequest<Confirmation>` | Interaction request for confirmations (hides base member with `new`). |
|
||||
| `HeaderInfo` | `string` | Returns constant string `"SettingsRegion"`. |
|
||||
| `IsBusy` | `bool` | Gets/sets busy state (hides base member with `new`). |
|
||||
| `IsDirty` | `bool` | Gets/sets dirty state (hides base member with `new`). |
|
||||
| `IsNavigationIncluded` | `bool` | Gets/sets navigation inclusion flag (hides base member with `new`). |
|
||||
| `CalibrationBehaviorSettingVisibility` | `Visibility` | Controls visibility of calibration behavior setting UI. Publishes `ViewerSettingsVisibilityChangedEvent` when changed. |
|
||||
| `OverallSettingsVisibility` | `Visibility` | Computed property; returns `Visibility.Visible` if `CalibrationBehaviorSettingVisibility` is visible, otherwise `Visibility.Collapsed`. |
|
||||
| `AvailableCalibrationBehaviors` | `DisplayedCalibrationBehavior[]` | Lazily-initialized, thread-safe array of three calibration behavior options: `_linearIfAvail`, `_nonLinearIfAvail`, `_useBothIfAvail`. |
|
||||
| `CalibrationBehaviorSetting` | `DisplayedCalibrationBehavior` | Gets/sets the selected calibration behavior. Defaults to `CalibrationBehaviors.NonLinearIfAvailable`. Publishes `CalibrationBehaviorSettingChangedEvent` when changed. |
|
||||
|
||||
### Events
|
||||
|
||||
```csharp
|
||||
public new event PropertyChangedEventHandler PropertyChanged
|
||||
```
|
||||
Hides base class event. Raised via `OnPropertyChanged(string)`.
|
||||
|
||||
---
|
||||
|
||||
## 3. Invariants
|
||||
|
||||
- **Default Calibration Behavior**: `_calibrationBehaviorSetting` is always initialized to `CalibrationBehaviors.NonLinearIfAvailable`.
|
||||
- **OverallSettingsVisibility Dependency**: `OverallSettingsVisibility` is always `Visibility.Collapsed` when `CalibrationBehaviorSettingVisibility` is `Visibility.Collapsed`. It cannot be visible independently.
|
||||
- **Thread Safety**: `AvailableCalibrationBehaviors` getter uses a lock (`MyLock`) to ensure thread-safe lazy initialization.
|
||||
- **CalibrationBehaviorSetting Getter**: Always returns a matching `DisplayedCalibrationBehavior` from `AvailableCalibrationBehaviors` array, or `null` if no match found.
|
||||
- **Event Subscription Timing**: Subscriptions occur only after `Initialize(object parameter)` is called, not in the constructor.
|
||||
|
||||
---
|
||||
|
||||
## 4. Dependencies
|
||||
|
||||
### External Dependencies (from imports)
|
||||
- **Prism.Events** - `IEventAggregator` for pub/sub messaging
|
||||
- **Prism.Regions** - `IRegionManager` for region-based navigation
|
||||
- **Unity** - `IUnityContainer` for dependency injection
|
||||
- **DTS.Common.Base** - `BaseViewModel<T>`, `IBaseViewModel`
|
||||
- **DTS.Common.Classes.Sensors** - `DisplayedCalibrationBehavior`
|
||||
- **DTS.Common.Enums.Sensors** - `CalibrationBehaviors` enum
|
||||
- **DTS.Common.Events** - `CalibrationBehaviorSettingChangedEvent`, `CalibrationBehaviorSettableInViewerChangedEvent`, `ViewerSettingsVisibilityChangedEvent`
|
||||
- **DTS.Common.Interactivity** - `InteractionRequest<T>`, `Notification`, `Confirmation`
|
||||
- **DTS.Common.Interface** - `IViewerSettingsViewModel`
|
||||
- **System.Windows** - `Visibility` enum
|
||||
|
||||
### Consumed Events
|
||||
- `CalibrationBehaviorSettingChangedEvent` - payload: `CalibrationBehaviors`
|
||||
- `CalibrationBehaviorSettableInViewerChangedEvent` - payload: `bool`
|
||||
|
||||
### Published Events
|
||||
- `CalibrationBehaviorSettingChangedEvent` - published when `CalibrationBehaviorSetting` setter is invoked with a different value
|
||||
- `ViewerSettingsVisibilityChangedEvent` - published when `CalibrationBehaviorSettingVisibility` is set
|
||||
|
||||
---
|
||||
|
||||
## 5. Gotchas
|
||||
|
||||
1. **Misleading XML Documentation**: The constructor's XML comment references `TestSummaryViewListModel`, which appears to be a copy-paste error from another class.
|
||||
|
||||
2. **Member Hiding with `new` Keyword**: Multiple members (`PropertyChanged`, `OnPropertyChanged`, `IsBusy`, `IsDirty`, `IsNavigationIncluded`, `ConfirmationRequest`) hide base class members using `new`. This breaks polymorphism—consumers casting to the base type will invoke base implementations, not these overrides.
|
||||
|
||||
3. **Empty `PublishChanges()` Method**: The method has no implementation. Its intended purpose is unclear from source alone.
|
||||
|
||||
4. **Cascading Visibility Notifications**: `OnPropertyChanged` has special logic—any property name ending with `"Visibility"` (except `"OverallSettingsVisibility"`) triggers an additional `OnPropertyChanged("OverallSettingsVisibility")` call. This side effect is not obvious from property setters alone.
|
||||
|
||||
5. **Potential Null Return**: `CalibrationBehaviorSetting` getter returns `null` if `_calibrationBehaviorSetting` does not match any item in `AvailableCalibrationBehaviors`. Callers should handle this possibility.
|
||||
|
||||
6. **No Unsubscribe Logic**: The class subscribes to events in `Subscribe()` but does not appear to unsubscribe. Potential memory leak if view model lifecycle is shorter than the event aggregator's.
|
||||
Reference in New Issue
Block a user