245 lines
9.7 KiB
C#
245 lines
9.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using DTS.Common.Base;
|
|
using Unity;
|
|
using DTS.Common.Enums.Viewer;
|
|
using DTS.Common.Events;
|
|
using DTS.Common.Interface;
|
|
using Prism.Events;
|
|
using Prism.Regions;
|
|
using DTS.Common.Interactivity;
|
|
using Prism.Commands;
|
|
// ReSharper disable UnassignedGetOnlyAutoProperty
|
|
// ReSharper disable InconsistentNaming
|
|
// ReSharper disable NotAccessedField.Local
|
|
// ReSharper disable UnusedAutoPropertyAccessor.Local
|
|
// ReSharper disable CheckNamespace
|
|
// ReSharper disable AutoPropertyCanBeMadeGetOnly.Local
|
|
// ReSharper disable RedundantDefaultMemberInitializer
|
|
|
|
namespace DTS.Viewer.ChartOptions
|
|
{
|
|
public class ChartOptionsViewModel : BaseViewModel<IChartOptionsViewModel>, IChartOptionsViewModel
|
|
{
|
|
public IBaseViewModel Parent { get; set; }
|
|
private IEventAggregator _eventAggregator { get; set; }
|
|
private IUnityContainer _unityContainer { get; set; }
|
|
public InteractionRequest<Notification> NotificationRequest { get; private set; }
|
|
public new InteractionRequest<Confirmation> ConfirmationRequest { get; private set; }
|
|
public IBaseView View { get; set; }
|
|
|
|
private IChartOptionsModel _model;
|
|
public new IChartOptionsModel Model { get => _model; set { _model = value; OnPropertyChanged("Model"); } }
|
|
|
|
/// <summary>
|
|
/// Creates a new instance of the TestSummaryViewModel.
|
|
/// </summary>
|
|
/// <param name="view">The TestListView interface.</param>
|
|
/// <param name="regionManager">The logical placeholder defined within the application's UI (in the shell or within views) into which views are displayed.</param>
|
|
/// <param name="eventAggregator">The EventAggregator which allows different components to publish/subscribe to events without being coupled to each other.</param>
|
|
/// <param name="unityContainer">The unityContainer.</param>
|
|
public ChartOptionsViewModel(IChartOptionsView view, IRegionManager regionManager, IEventAggregator eventAggregator, IUnityContainer unityContainer)
|
|
: base(regionManager, eventAggregator, unityContainer)
|
|
{
|
|
View = view;
|
|
View.DataContext = this;
|
|
NotificationRequest = new InteractionRequest<Notification>();
|
|
ConfirmationRequest = new InteractionRequest<Confirmation>();
|
|
|
|
_eventAggregator = eventAggregator;
|
|
_unityContainer = unityContainer;
|
|
_eventAggregator.GetEvent<ChartAxisChangedEvent>().Subscribe(OnChartAxisChangedEvent);
|
|
|
|
//Model = _unityContainer.Resolve<IChartOptionsModel>();
|
|
//Model.Parent = this;
|
|
//View.DataContext = Model;
|
|
}
|
|
public override void Initialize()
|
|
{
|
|
|
|
}
|
|
|
|
private string chartType = string.Empty;
|
|
public override void Initialize(object parameter)
|
|
{
|
|
Subscribe();
|
|
Model = _unityContainer.Resolve<IChartOptionsModel>();
|
|
Model.Parent = this;
|
|
View.DataContext = Model;
|
|
if (parameter is IViewerMainViewModel)
|
|
{
|
|
Parent = (IBaseViewModel)parameter;
|
|
Model.DecimateData = true;
|
|
}
|
|
else if (parameter is Tuple<IBaseViewModel, string> tuParam && tuParam.Item1 is IPSDReportMainViewModel)
|
|
{
|
|
Parent = tuParam.Item1;
|
|
chartType = tuParam.Item2;
|
|
Model.CanPublishChanges = false;
|
|
if ("Graph" == chartType)
|
|
{
|
|
Model.UnitType = ChartUnitTypeEnum.PSD;
|
|
Model.YRange = YRangeScaleEnum.Fixed;
|
|
Model.MaxFixedY = 1;
|
|
Model.MinFixedY = 1e-12; //log scale, can't be 0
|
|
Model.DecimateData = false;
|
|
}
|
|
else
|
|
{
|
|
Model.DecimateData = true;
|
|
Model.Filter = FilterOptionEnum.Unfiltered;
|
|
}
|
|
Model.CanPublishChanges = true;
|
|
}
|
|
}
|
|
|
|
private void Subscribe()
|
|
{
|
|
_eventAggregator.GetEvent<CursorsAlailableChangedEvent>().Subscribe(OnCursorsAlailableChanged);
|
|
_eventAggregator.GetEvent<GraphSelectedChannelsNotification>().Subscribe(OnGraphSelectedChannelsChanged);
|
|
}
|
|
|
|
private string Directory { get; set; }
|
|
|
|
private void OnGraphSelectedChannelsChanged(GraphSelectedChannelsNotificationArg arg)
|
|
{
|
|
if (Parent != arg?.ParentVM) return;
|
|
var channels = arg.SelectedChannels;
|
|
Model.Parent = this;
|
|
Directory = channels.Count > 0 ? channels[0].BinaryFilePath : string.Empty;
|
|
ChartOptionsVisability = (channels.Count > 0);
|
|
//whenever channels change, check the status of mV/ADC buttons
|
|
//18256 Implement StackChannelScaleFactorsEUPerADC Arm/Event Command
|
|
if (AllChannelsSupportADC(channels))
|
|
{
|
|
Model.SupportsADC = true;
|
|
}
|
|
else
|
|
{
|
|
Model.SupportsADC = false;
|
|
if (Model.UnitType == ChartUnitTypeEnum.ADC)
|
|
{
|
|
Model.UnitType = ChartUnitTypeEnum.EU;
|
|
}
|
|
}
|
|
if (AllChannelsSupportmV(channels))
|
|
{
|
|
Model.SupportsMV = true;
|
|
}
|
|
else
|
|
{
|
|
Model.SupportsMV = false;
|
|
if (Model.UnitType == ChartUnitTypeEnum.mV)
|
|
{
|
|
Model.UnitType = ChartUnitTypeEnum.EU;
|
|
}
|
|
}
|
|
|
|
PublishChanges();
|
|
}
|
|
/// <summary>
|
|
/// returns true if all channels support ADC
|
|
/// for now this is determined by looking at the sensor serial number, but we
|
|
/// can be more sophisticated in the future, as there are other channels that won't support ADC meaningfully as well
|
|
/// (like calculated channels)
|
|
/// </summary>
|
|
private bool AllChannelsSupportADC(List<ITestChannel> channels)
|
|
{
|
|
return !channels.Exists(x => Common.Enums.Hardware.HardwareConstants.IsTSRAIRSerialNumber(x.ParentModule.BaseSerialNumber));
|
|
}
|
|
/// <summary>
|
|
/// returns true if all channels support mV
|
|
/// </summary>
|
|
private bool AllChannelsSupportmV(List<ITestChannel> channels)
|
|
{
|
|
return !channels.Exists(x => Common.Enums.Hardware.HardwareConstants.IsTSRAIRSerialNumber(x.ParentModule.BaseSerialNumber));
|
|
}
|
|
|
|
private void OnCursorsAlailableChanged(bool value)
|
|
{
|
|
Model.IsCursorsAvailable = value;
|
|
}
|
|
|
|
private void OnChartAxisChangedEvent(ChartAxisChangedEventArg args)
|
|
{
|
|
if (args?.ParentVM != Parent) return;
|
|
Model.CanPublishChanges = false;
|
|
switch (args.Axis)
|
|
{
|
|
case "Y":
|
|
Model.MinFixedY = args.MinValue;
|
|
Model.MaxFixedY = args.MaxValue;
|
|
break;
|
|
case "X":
|
|
Model.MinFixedT = args.MinValue;
|
|
Model.MaxFixedT = args.MaxValue;
|
|
break;
|
|
}
|
|
Model.CanPublishChanges = true;
|
|
}
|
|
|
|
#region Properties
|
|
|
|
public object ContextSearchRegion { get; set; }
|
|
public new bool IsMenuIncluded { get; set; }
|
|
public new bool IsNavigationIncluded { get; set; }
|
|
public new bool IsBusy { get; set; }
|
|
public new bool IsDirty { get; }
|
|
|
|
private bool _chartOptionsVisability = false;
|
|
public bool ChartOptionsVisability { get => _chartOptionsVisability; set { _chartOptionsVisability = value; OnPropertyChanged("ChartOptionsVisability"); } }
|
|
|
|
public new event PropertyChangedEventHandler PropertyChanged;
|
|
|
|
public new void OnPropertyChanged(string propertyName)
|
|
{
|
|
var handler = PropertyChanged;
|
|
handler?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
}
|
|
#endregion Properties
|
|
|
|
#region Methods
|
|
public void ShowMinMaxCursor(bool value)
|
|
{
|
|
_eventAggregator.GetEvent<CursorShowMinMaxChangedEvent>().Publish(value);
|
|
}
|
|
public void ResetZoomMethod()
|
|
{
|
|
Model.YRange = YRangeScaleEnum.AutoRange;
|
|
_eventAggregator.GetEvent<ResetZoomChangedEvent>().Publish(true);
|
|
}
|
|
public void ResetTMethod()
|
|
{
|
|
_eventAggregator.GetEvent<ResetZoomChangedEvent>().Publish(false);
|
|
}
|
|
public void SaveToPDFMethod()
|
|
{
|
|
_eventAggregator.GetEvent<SaveToPDFRequestedEvent>().Publish(Directory);
|
|
}
|
|
public void PublishChanges()
|
|
{
|
|
_eventAggregator.GetEvent<ChartOptionsChangedEvent>().Publish(new ChartOptionsChangedEventArg() { ParentVM = Parent, Model = Model, ChartType = chartType });
|
|
}
|
|
public void ShowCusor(bool value)
|
|
{
|
|
_eventAggregator.GetEvent<CursorShowChangedEvent>().Publish(value);
|
|
}
|
|
|
|
#endregion Methods
|
|
|
|
#region Commands
|
|
|
|
private DelegateCommand _clearMarkersCommand;
|
|
public DelegateCommand ClearMarkersCommand => _clearMarkersCommand ?? (_clearMarkersCommand = new DelegateCommand(ClearMarkersMethod));
|
|
private void ClearMarkersMethod()
|
|
{
|
|
_eventAggregator.GetEvent<CursorsClearChangedEvent>().Publish(true);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|