Files
DP44/enriched-qwen3-coder-next/DTS Viewer/DTS.Viewer.Reports/DTS.Viewer.PSDReportSettings/ViewModel.md

104 lines
4.9 KiB
Markdown
Raw Normal View History

2026-04-17 14:55:32 -04:00
---
source_files:
- DTS Viewer/DTS.Viewer.Reports/DTS.Viewer.PSDReportSettings/ViewModel/PSDReportSettingsViewModel.cs
generated_at: "2026-04-16T13:37:48.788166+00:00"
model: "zai-org/GLM-5-FP8"
schema_version: 1
sha256: "9dcac2937b5c346b"
---
# Documentation: PSDReportSettingsViewModel
## 1. Purpose
`PSDReportSettingsViewModel` is a Prism-based ViewModel responsible for managing Power Spectral Density (PSD) report settings within the DTS Viewer application. It serves as a mediator between graph visualization components and report settings, responding to user interactions such as channel selection and axis changes, and publishing those changes to other system components via the event aggregator. The class extends `BaseViewModel<IPSDReportSettingsModel>` and implements `IPSDReportSettingsViewModel`.
---
## 2. Public Interface
### Properties
| Property | Type | Description |
|----------|------|-------------|
| `View` | `IBaseView` | Gets or sets the associated view instance. |
| `Parent` | `IBaseViewModel` | Gets or sets the parent ViewModel reference. |
| `Model` | `IPSDReportSettingsModel` | Gets or sets the model instance. Uses `new` keyword to hide base class property. Raises `OnPropertyChanged("Model")` on set. |
| `NotificationRequest` | `InteractionRequest<Notification>` | Interaction request for displaying notifications to the user. |
| `ConfirmationRequest` | `InteractionRequest<Confirmation>` | Interaction request for displaying confirmation dialogs. Uses `new` keyword to hide base class property. |
### Constructor
```csharp
public PSDReportSettingsViewModel(
IPSDReportSettingsView view,
IRegionManager regionManager,
IEventAggregator eventAggregator,
IUnityContainer unityContainer)
```
Creates a new instance, initializes the view's DataContext, and creates interaction request objects.
### Methods
```csharp
public override void Initialize()
```
Empty override. No initialization logic performed.
```csharp
public override void Initialize(object parameter)
```
Initializes the ViewModel with a parent reference (cast to `IBaseViewModel`), subscribes to events, resolves the `IPSDReportSettingsModel` from the Unity container, and sets the model's `Parent` property.
```csharp
public void PublishChanges()
```
Publishes a `PSDReportSettingsChangedEvent` with a `PSDReportSettingsChangedEventArg` containing the current `Model` and `ParentVM` reference.
---
## 3. Invariants
- **Parent Filtering**: Event handlers (`OnChartAxisChanged`, `OnGraphSelectedChannelsChanged`) ignore events where `arg.ParentVM` does not match `Parent`.
- **Publish Guard**: When handling X-axis changes, `Model.CanPublishChanges` is set to `false` before modifying `DataStart`/`DataEnd`, then restored to `true` before calling `PublishChanges()`. This prevents potential recursive event propagation.
- **Model Resolution**: The `Model` is resolved from the Unity container during `Initialize(object parameter)`, not in the constructor.
---
## 4. Dependencies
### This Module Depends On
| Namespace/Module | Usage |
|------------------|-------|
| `DTS.Common.Base` | `BaseViewModel<T>` base class |
| `DTS.Common.Events` | Event types: `GraphSelectedChannelsNotification`, `GraphClearNotification`, `ChartAxisChangedEvent`, `PSDReportSettingsChangedEvent` and their argument types |
| `DTS.Common.Interactivity` | `InteractionRequest<T>`, `Notification`, `Confirmation` |
| `DTS.Common.Interface` | `IBaseView`, `IBaseViewModel`, `IPSDReportSettingsModel`, `IPSDReportSettingsView`, `IPSDReportSettingsViewModel` |
| `Prism.Events` | `IEventAggregator` |
| `Prism.Regions` | `IRegionManager` |
| `Unity` | `IUnityContainer` for dependency resolution |
### What Depends On This Module
- **Unclear from source alone**: The module publishes `PSDReportSettingsChangedEvent`, indicating subscribers elsewhere in the system consume this ViewModel's output, but specific consumers are not visible in this file.
---
## 5. Gotchas
1. **Property Hiding**: Both `Model` and `ConfirmationRequest` use the `new` keyword to hide base class members. This can lead to unexpected behavior if the ViewModel is accessed via a base class reference.
2. **Commented-Out Code**: Several features appear incomplete or disabled:
- `Standalone` property is commented out
- Y-axis handling in `OnChartAxisChanged` is commented out
- `PublishChanges()` call in `OnGraphSelectedChannelsChanged` is commented out
- `CursorsAlailableChangedEvent` subscription is commented out
- `View.DataContext = Model` assignment in `Initialize(object parameter)` is commented out
3. **Empty `Initialize()` Override**: The parameterless `Initialize()` method is empty. All initialization logic resides in the overloaded version.
4. **Unused `OnRaiseNotification` Method**: This private method exists but is never called within the visible source. It may be wired via event subscription not shown in this file.
5. **Async Pattern Absent**: Despite importing `System.Threading.Tasks`, no async operations are performed in this class.