Files
2026-04-17 14:55:32 -04:00

7.8 KiB

source_files, generated_at, model, schema_version, sha256
source_files generated_at model schema_version sha256
DTS Viewer/DTS.Viewer.Reports/DTS.Viewer.PSDReport/ViewModel/PSDReportMainViewModel.cs
2026-04-16T13:41:19.428606+00:00 zai-org/GLM-5-FP8 1 280cd655454826b4

Documentation: PSDReportMainViewModel.cs

1. Purpose

The PSDReportMainViewModel class serves as the primary view model (controller) for the PSD (Power Spectral Density) Report module within the DTS Viewer application. It orchestrates the layout and lifecycle of multiple child views (graphs, tests, settings, navigation) by managing navigation regions and mediating communication via an event aggregator. This class is responsible for handling user interactions such as file selection, calibration settings, and zoom controls, while maintaining the state of the busy indicator and UI titles based on data loading events.

2. Public Interface

Constructor

  • PSDReportMainViewModel(IRegionManager regionManager, IEventAggregator eventAggregator, IUnityContainer unityContainer)
    • Initializes the view model, creates interaction requests (NotificationRequest, ConfirmationRequest), resolves the main view (IPSDReportMainViewGrid) via the Unity container, and sets the DataContext.

Properties

  • IBaseView View { get; set; }: Gets or sets the associated view.
  • InteractionRequest<Notification> NotificationRequest { get; }: Request object for triggering notifications.
  • InteractionRequest<Confirmation> ConfirmationRequest { get; }: Request object for triggering confirmation dialogs.
  • Region Context Properties (Manage content of specific regions on the View):
    • object ContextNavigationRegion: Maps to NavigationRegion.
    • object ContextGraphsRegion: Maps to GraphListRegion.
    • object ContextGraphListRegion: Maps to GraphListRegion.
    • object ContextTestsRegion: Maps to TestsRegion.
    • object ContextLegendRegion: Maps to LegendRegion.
    • object ContextPropertyRegion: Standalone property (logic not fully visible).
    • object ContextChartOptionsRegion: Maps to ChartOptionsRegion.
    • object ContextViewerSettingsRegion: Maps to SettingsRegion.
    • object ContextReportDataSelectRegion: Maps to DataSelectRegion.
    • object ContextGraphRegion: Maps to GraphRegion.
    • object ContextReportChartOptionsRegion: Maps to ReportChartOptionsRegion.
    • object ContextReportResultsRegion: Maps to ReportResultsRegion.
  • string ConfigPath { get; set; }: Throws NotImplementedException.
  • string TitleTests { get; set; }: Title for the Tests section.
  • int TotalSelectedTests { get; set; }: Count of selected tests; updates TitleTests.
  • int TotalLoadedTests { get; set; }: Count of loaded tests; updates TitleTests.
  • string TitleGraphs { get; set; }: Title for the Graphs section.
  • int TotalSelectedGraphs { get; set; }: Count of selected graphs; updates TitleGraphs.
  • int TotalLoadedGraphs { get; set; }: Count of loaded graphs; updates TitleGraphs.
  • string SelectedDataFolder { get; set; }: Sets the data folder and publishes DataFolderChangedEvent.
  • string SelectedDataFile { get; set; }: Sets the data file and publishes DataFolderChangedEvent.
  • IsoViewMode ChannelCodeViewMode { get; set; }: Gets/sets channel code view mode; publishes ChannelCodesViewChangedEvent.
  • CalibrationBehaviors CalibrationBehaviorSetting { get; set; }: Gets/sets calibration behavior; publishes CalibrationBehaviorSettingChangedEvent.
  • bool CalibrationBehaviorSettableInViewer { get; set; }: Determines if calibration is settable; publishes event and forces tab selection logic.
  • Visibility SettingsVisibility { get; }: Controls visibility of settings.
  • bool IsBusy { get; set; }: Controls busy indicator visibility.
  • string IsBusyMessage { get; set; }: Text displayed when busy.
  • bool IsMenuIncluded { get; set; }: Inherited behavior flag.
  • bool IsNavigationIncluded { get; set; }: Inherited behavior flag.
  • bool IsDirty { get; }: Throws NotImplementedException.

Methods

  • List<FrameworkElement> GetRegions(): Retrieves child elements named "Region" from the MainShell.
  • void Initialize(): Calls Subscribe() to register event listeners.
  • void Initialize(object parameter): Sets the Parent window model and calls Subscribe().
  • void LeftKeyPress(): Throws NotImplementedException.
  • void RightKeyPress(): Throws NotImplementedException.
  • void ZoomReset(): Publishes ResetZoomChangedEvent to reset zoom levels.
  • void SelectAndIncludeDataFile(string value): Sets the selected data file and publishes a DataFolderChangedEvent with SetSelected flag.

3. Invariants

  • View Type Constraint: The View property must resolve to a PSDReportMainViewGrid type (or compatible type) because the region properties explicitly cast View to PSDReportMainViewGrid to access named UI elements (e.g., NavigationRegion, GraphListRegion).
  • Parent Type: The Initialize(object parameter) method expects parameter to be castable to IBaseWindowModel.
  • Event Aggregator Presence: The class relies heavily on IEventAggregator being injected; it will fail to function (specifically in property setters) if _eventAggregator is null.
  • Setter Guards: Properties SelectedDataFolder and SelectedDataFile will return without action if the value is null or empty.

4. Dependencies

Internal Dependencies (Inferred from imports)

  • DTS.Common.Base: BaseViewModel, IBaseView, IBaseViewModel, IBaseWindowModel.
  • DTS.Common.Enums: IsoViewMode, CalibrationBehaviors.
  • DTS.Common.Events: DataFolderChangedEvent, LoadViewModulEvent, ChannelCodesViewChangedEvent, CalibrationBehaviorSettingChangedEvent, ResetZoomChangedEvent, etc.
  • DTS.Common.Interface: IPSDReportMainViewModel, IGraphView, IChartOptionsView, etc.
  • DTS.Common.Utils: Utils class (used for GetChildrenByName).
  • DTS.Common.Interactivity: InteractionRequest, Notification, Confirmation.
  • DTS.Viewer.PSDReport.Resources: StringResources.

External Dependencies

  • Prism: IEventAggregator, IRegionManager (Event driving and navigation).
  • Unity: IUnityContainer (Dependency injection and view resolution).
  • System.Windows: WPF UI components (FrameworkElement, Visibility).

5. Gotchas

  • MVVM Violation in Properties: The region properties (e.g., ContextNavigationRegion) directly access and cast the View to PSDReportMainViewGrid to manipulate UI elements (Content properties). This creates a tight coupling between the ViewModel and the specific View implementation, violating standard MVVM principles.
  • Duplicate Region Logic: ContextGraphsRegion and ContextGraphListRegion both access ((PSDReportMainViewGrid)View).GraphListRegion.Content. This appears to be a copy-paste error where ContextGraphsRegion should likely target a different region.
  • Member Hiding: The class uses the new keyword to hide base members (e.g., IsBusy, IsBusyMessage, ConfirmationRequest, OnPropertyChanged). This can lead to unexpected behavior if the object is accessed via a base class reference, as the base implementation will be called instead of the derived one.
  • Not Implemented Features: Several public members throw NotImplementedException (ConfigPath, IsDirty, LeftKeyPress, RightKeyPress). These should not be relied upon in production code.
  • Direct Tab Manipulation: The setter for CalibrationBehaviorSettableInViewer directly manipulates the IsSelected and Focusable properties of UI tabs (graphsTab, testsTab, chartResultsTab) found on the View. This logic references bug fix IDs (FB13946, FB14797) and implies fragile UI logic embedded in the ViewModel.