OutSignalMainPageViewModel.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using Avalonia.Collections;
  2. using Avalonia.Controls;
  3. using Shaker.Model;
  4. using Shaker.Models;
  5. using ShakerApp.Models;
  6. using ShakerApp.Tools;
  7. using ShakerApp.Views;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.ComponentModel.DataAnnotations;
  11. using System.Diagnostics.CodeAnalysis;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. namespace ShakerApp.ViewModels
  16. {
  17. internal class OutSignalMainPageViewModel:ViewModelBase<IModel>,IMainPageViewModel
  18. {
  19. public MainPageType PageType => MainPageType.OutSignal;
  20. [AllowNull]
  21. private TimeDomainMenuViewModel selectedType;
  22. private OutSignalMainPageViewModel()
  23. {
  24. Enum.GetValues<TimeDomainType>().ToList()
  25. .ForEach(x =>
  26. {
  27. Menu.Add(new TimeDomainMenuViewModel()
  28. {
  29. TimeDomainType = x,
  30. IsEnabled = true,
  31. Unit = x.GetUnit(),
  32. });
  33. });
  34. if(Menu.Count>0)
  35. {
  36. SelectedType = Menu.First();
  37. }
  38. PlotModel.Axes.Add(new OxyPlot.Axes.TimeSpanAxis()
  39. {
  40. Title = App.Current?.FindResource("Time") + "",
  41. Unit = "s",
  42. Position = OxyPlot.Axes.AxisPosition.Bottom,
  43. MaximumPadding =0,
  44. MinimumPadding =0,
  45. MajorGridlineStyle = OxyPlot.LineStyle.Solid,
  46. });
  47. PlotModel.Axes.Add(new OxyPlot.Axes.LinearAxis()
  48. {
  49. Title=App.Current?.FindResource("Ampt")+ "",
  50. Unit=SelectedType.Unit,
  51. Position = OxyPlot.Axes.AxisPosition.Left,
  52. MajorGridlineStyle = OxyPlot.LineStyle.Solid,
  53. });
  54. PlotModel.Title = $"{App.Current?.FindResource(MainPageType.OutSignal.Description())}-{App.Current?.FindResource(SelectedType.Key)}";
  55. GetEvent(ShakerSettingViewModel.LANGUAGECHANGEDEVENT).Subscrip((_, _) =>
  56. {
  57. PlotModel.InvalidatePlot(false);
  58. PlotModel.Title = $"{App.Current?.FindResource(MainPageType.OutSignal.Description())}-{App.Current?.FindResource(SelectedType.Key)}";
  59. PlotModel.Axes[0].Title = App.Current?.FindResource("Time") + "";
  60. PlotModel.Axes[1].Title = Title = App.Current?.FindResource("Ampt") + "";
  61. PlotModel.InvalidatePlot(true);
  62. });
  63. }
  64. static OutSignalMainPageViewModel()
  65. {
  66. }
  67. public void Start()
  68. {
  69. }
  70. public void Stop()
  71. {
  72. }
  73. public void UpdateData(IResultDataModel model)
  74. {
  75. }
  76. public AvaloniaList<TimeDomainMenuViewModel> Menu { get; } = new AvaloniaList<TimeDomainMenuViewModel>();
  77. public TimeDomainMenuViewModel SelectedType
  78. {
  79. get => selectedType;
  80. set
  81. {
  82. SetProperty(ref selectedType, value);
  83. foreach(var val in Menu)
  84. {
  85. val.IsChecked = val.TimeDomainType == value.TimeDomainType;
  86. }
  87. PlotModel.Title = $"{App.Current?.FindResource(MainPageType.OutSignal.Description())}-{App.Current?.FindResource(value.Key)}";
  88. if (PlotModel.Axes.Count < 2) return;
  89. PlotModel.InvalidatePlot(false);
  90. PlotModel.Axes[1].Unit = value.Unit;
  91. PlotModel.InvalidatePlot(true);
  92. }
  93. }
  94. public OxyPlot.PlotController Controller { get; private set; } = new OxyPlot.PlotController();
  95. public OxyPlot.PlotModel PlotModel { get; private set; } = new OxyPlot.PlotModel();
  96. public static OutSignalMainPageViewModel Instance { get; } = new OutSignalMainPageViewModel();
  97. }
  98. }