--- source_files: - DTS Viewer/DTS.Viewer.Reports/DTS.Viewer.PSDReportSettings/ViewModel/PSDReportSettingsViewModel.cs generated_at: "2026-04-16T11:00:01.546105+00:00" model: "zai-org/GLM-5-FP8" schema_version: 1 sha256: "9dcac2937b5c346b" --- # Documentation: PSDReportSettingsViewModel.cs ## 1. Purpose This module provides a ViewModel for configuring PSD (Power Spectral Density) report settings within the DTS Viewer application. It acts as a mediator between the view layer and the data model, responding to graph-related events (channel selection, axis changes, graph clearing) and publishing setting changes to other system components via an event aggregator. The class follows the MVVM pattern using Prism framework conventions. --- ## 2. Public Interface ### Class: `PSDReportSettingsViewModel` **Namespace:** `DTS.Viewer.PSDReportSettings` **Inherits from:** `BaseViewModel` **Implements:** `IPSDReportSettingsViewModel` #### Properties | Property | Type | Access | Description | |----------|------|--------|-------------| | `View` | `IBaseView` | get/set | Reference to the associated view; DataContext is set to `this` in constructor. | | `Parent` | `IBaseViewModel` | get/set | Parent ViewModel reference, passed during initialization. | | `Model` | `IPSDReportSettingsModel` | get/set | Hides base `Model` property. Backed by private `_model` field; raises `OnPropertyChanged("Model")` on set. | | `NotificationRequest` | `InteractionRequest` | get | Used to raise notification dialogs. | | `ConfirmationRequest` | `InteractionRequest` | get | Hides base property. Used to raise confirmation dialogs. | #### Constructor ```csharp public PSDReportSettingsViewModel( IPSDReportSettingsView view, IRegionManager regionManager, IEventAggregator eventAggregator, IUnityContainer unityContainer) ``` Initializes the ViewModel, sets the View's DataContext, creates interaction requests, and stores references to the event aggregator and Unity container. #### Methods | Method | Signature | Description | |--------|-----------|-------------| | `Initialize` | `override void Initialize()` | Empty override. No initialization logic. | | `Initialize` | `override void Initialize(object parameter)` | Sets `Parent` from parameter, calls `Subscribe()`, resolves `IPSDReportSettingsModel` from container, and sets `Model.Parent = this`. | | `PublishChanges` | `void PublishChanges()` | Publishes a `PSDReportSettingsChangedEvent` with a `PSDReportSettingsChangedEventArg` containing the current `Model` and `Parent`. | --- ## 3. Invariants 1. **Parent-Child Relationship:** The `Parent` property must be an `IBaseViewModel` type; it is cast directly from the `object parameter` in `Initialize(object parameter)` without null checking. 2. **Event Filtering:** Event handlers (`OnChartAxisChanged`, `OnGraphSelectedChannelsChanged`) filter events by checking `arg?.ParentVM != Parent`. Events not matching the parent are ignored. 3. **Model Resolution:** The `Model` is resolved from the Unity container during `Initialize(object parameter)`, not injected via constructor. 4. **Publish Control:** During X-axis changes in `OnChartAxisChanged`, `Model.CanPublishChanges` is set to `false` before modifying `DataStart`/`DataEnd`, then restored to `true` before calling `PublishChanges()`. 5. **DataContext Assignment:** The View's DataContext is assigned to `this` (the ViewModel) in the constructor, not to the Model (a commented line suggests this was previously different). --- ## 4. Dependencies ### Imports (this module depends on): - `DTS.Common.Base` - Provides `BaseViewModel` - `DTS.Common.Events` - Provides event args: `ChartAxisChangedEventArg`, `GraphClearNotificationArg`, `GraphSelectedChannelsNotificationArg`, `PSDReportSettingsChangedEvent`, `PSDReportSettingsChangedEventArg` - `DTS.Common.Interactivity` - Provides `InteractionRequest`, `Notification`, `Confirmation` - `DTS.Common.Interface` - Provides interfaces: `IBaseView`, `IBaseViewModel`, `IPSDReportSettingsModel`, `IPSDReportSettingsView`, `IPSDReportSettingsViewModel` - `Prism.Events` - Provides `IEventAggregator` - `Prism.Regions` - Provides `IRegionManager` - `Unity` - Provides `IUnityContainer` ### Consumers (what depends on this module): - Not determinable from this source file alone. Likely consumed by View classes and/or registered in a module initialization or DI container configuration. --- ## 5. Gotchas 1. **Member Hiding:** Both `Model` and `ConfirmationRequest` properties use the `new` keyword, hiding inherited members from `BaseViewModel`. This could lead to unexpected behavior if the base class is accessed polymorphically. 2. **Commented-Out Code:** Several code blocks are commented out, including: - A `Standalone` property - Y-axis handling in `OnChartAxisChanged` (lines setting `MinFixedY`/`MaxFixedY`) - `PublishChanges()` call in `OnGraphSelectedChannelsChanged` - A subscription to `CursorsAlailableChangedEvent` in `Subscribe()` This suggests incomplete features or work-in-progress that may cause confusion. 3. **Empty `Initialize()` Override:** The parameterless `Initialize()` method is empty. If base class calls this method, no initialization occurs. 4. **Direct Cast Without Validation:** In `Initialize(object parameter)`, the parameter is cast directly to `IBaseViewModel` without null or type checking, which could throw `InvalidCastException` or result in null. 5. **Unused `OnRaiseNotification` Method:** The `OnRaiseNotification` method is private with no apparent callers within this class. It may be dead code or intended for future use.