SignalPreviewViewModel.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. using Avalonia.Collections;
  2. using CommunityToolkit.Mvvm.Input;
  3. using Shaker.Models;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Diagnostics;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Input;
  11. namespace ShakerApp.ViewModels
  12. {
  13. internal class SignalPreviewViewModel:ViewModelBase<IModel>, IDataPreview
  14. {
  15. public AvaloniaList<AnalogSignalPreviewViewModel> SignalPreviews { get; } = new AvaloniaList<AnalogSignalPreviewViewModel>();
  16. private bool upSignalData;
  17. private int rowCount = 2;
  18. private int columnCount = 2;
  19. private bool showLayout = false;
  20. private SignalPreviewViewModel()
  21. {
  22. this.ButtonVisibily = false;
  23. Content = typeof(Views.SignalPreviewView);
  24. SignalPreviews.Add(new AnalogSignalPreviewViewModel(AnalogType.Displacement));
  25. SignalPreviews.Add(new AnalogSignalPreviewViewModel(AnalogType.Acceleration));
  26. SignalPreviews.Add(new AnalogSignalPreviewViewModel(AnalogType.OutSignal));
  27. SignalPreviews.Add(new AnalogSignalPreviewViewModel(AnalogType.Driver));
  28. timer.AutoReset = false;
  29. timer.Elapsed += (_, _) =>
  30. {
  31. ShowLayout = true;
  32. };
  33. timer.Enabled = false;
  34. timer.Stop();
  35. }
  36. static SignalPreviewViewModel()
  37. {
  38. }
  39. public ICommand OneCommnad => new RelayCommand(One);
  40. private void One()
  41. {
  42. RowCount = 1;
  43. ColumnCount = 1;
  44. ShowLayout = false;
  45. }
  46. public ICommand OneTwoCommand=>new RelayCommand(OneTwo);
  47. private void OneTwo()
  48. {
  49. RowCount = 1;
  50. ColumnCount = 2;
  51. ShowLayout = false;
  52. }
  53. public ICommand TwoOneCommand=>new RelayCommand(TwoOne);
  54. private void TwoOne()
  55. {
  56. RowCount = 2;
  57. ColumnCount = 1;
  58. ShowLayout = false;
  59. }
  60. public ICommand TwoTwoCommand=>new RelayCommand(TwoTwo);
  61. private void TwoTwo()
  62. {
  63. RowCount = 2;
  64. ColumnCount = 2;
  65. ShowLayout = false;
  66. }
  67. public bool ShowLayout { get => showLayout; set =>SetProperty(ref showLayout , value); }
  68. private bool lastShowLayout = false;
  69. private System.Timers.Timer timer = new System.Timers.Timer(1000);
  70. private bool buttonPointerOver;
  71. private bool panelPointerOver;
  72. public ICommand PointerExitedCommand=>new RelayCommand(PointerExited);
  73. private void PointerExited()
  74. {
  75. ButtonPointerOver = false;
  76. timer.Stop();
  77. }
  78. public bool ButtonPointerOver
  79. {
  80. get => buttonPointerOver;
  81. set
  82. {
  83. SetProperty(ref buttonPointerOver, value);
  84. ShowLayout = ShowLayout ? PanelPointerOver : (ButtonPointerOver || PanelPointerOver);
  85. }
  86. }
  87. public bool PanelPointerOver
  88. {
  89. get => panelPointerOver;
  90. set
  91. {
  92. SetProperty(ref panelPointerOver, value);
  93. ShowLayout = ShowLayout ? PanelPointerOver : (ButtonPointerOver || PanelPointerOver);
  94. }
  95. }
  96. public ICommand ControlPointerEnteredCommand=>new RelayCommand(ControlPointerEntered);
  97. private void ControlPointerEntered()
  98. {
  99. PanelPointerOver = true;
  100. }
  101. public ICommand ControlPointerExitedCommand => new RelayCommand(ControlPointerExited);
  102. private void ControlPointerExited()
  103. {
  104. PanelPointerOver = false;
  105. }
  106. public ICommand PointerEnteredCommand=>new RelayCommand(PointerEntered);
  107. private void PointerEntered()
  108. {
  109. ButtonPointerOver = true;
  110. ShowLayout = false;
  111. timer.Start();
  112. }
  113. public int RowCount { get => rowCount; set =>SetProperty(ref rowCount , value); }
  114. public int ColumnCount { get => columnCount; set =>SetProperty(ref columnCount , value); }
  115. public static SignalPreviewViewModel Instance { get; } = new SignalPreviewViewModel();
  116. public bool UpSignalData
  117. {
  118. get => upSignalData;
  119. set
  120. {
  121. upSignalData = value;
  122. foreach (var item in SignalPreviews)
  123. {
  124. item.UpSignalData = value;
  125. }
  126. }
  127. }
  128. }
  129. }