ShakerConfigViewModel.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. using Avalonia.Collections;
  2. using Shaker.Models;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace ShakerApp.ViewModels
  9. {
  10. internal class ShakerConfigViewModel : ViewModelBase<Shaker.Models.ShakerConfigModel>
  11. {
  12. [PropertyAssociation(nameof(ShakerConfigModel.SynthesisType))]
  13. public AccelerationSynthesisType SynthesisType { get => Model.SynthesisType; set => SetProperty(ref Model.SynthesisType, value); }
  14. [PropertyAssociation(nameof(ShakerConfigModel.OutSignalGain))]
  15. public double OutSignalGain { get => Model.OutSignalGain; set => SetProperty(ref Model.OutSignalGain, value); }
  16. public override bool CanResize => false;
  17. public override double Width => 960;
  18. public override double Height => 560;
  19. [PropertyAssociation(nameof(ShakerConfigModel.MaxRiseCount))]
  20. public uint MaxRiseCount => Model.MaxRiseCount;
  21. [PropertyAssociation(nameof(ShakerConfigModel.MaxZeroChangedCount))]
  22. public uint MaxZeroChangedCount => Model.MaxZeroChangedCount;
  23. [PropertyAssociation(nameof(ShakerConfigModel.MaxSignalCount))]
  24. public uint MaxSignalCount => Model.MaxSignalCount;
  25. [PropertyAssociation(nameof(ShakerConfigModel.MaxEmergencyStopCount))]
  26. public uint MaxEmergencyStopCount => Model.MaxEmergencyStopCount;
  27. [PropertyAssociation(nameof(ShakerConfigModel.MaxStopWindowCount))]
  28. public uint MaxStopWindowCount => MaxStopWindowCount;
  29. [PropertyAssociation(nameof(ShakerConfigModel.MaxAdjustCount))]
  30. public uint MaxAdjustCount => Model.MaxAdjustCount;
  31. [PropertyAssociation(nameof(ShakerConfigModel.MaxFallCount))]
  32. public uint MaxFallCount => Model.MaxFallCount;
  33. [PropertyAssociation(nameof(ShakerConfigModel.StartCount))]
  34. public uint StartCount => Model.StartCount;
  35. [PropertyAssociation(nameof(ShakerConfigModel.InitialLocation))]
  36. public double InitialLocation { get => Model.InitialLocation; set => SetProperty(ref Model.InitialLocation, value); }
  37. [PropertyAssociation(nameof(ShakerConfigModel.SampleRate))]
  38. public uint SampleRate => Model.SampleRate;
  39. [PropertyAssociation(nameof(ShakerConfigModel.FPGAClock))]
  40. public uint FPGAClock => Model.FPGAClock;
  41. [PropertyAssociation(nameof(ShakerConfigModel.AnalogSignalConfigs))]
  42. public int ChannelCount => Model.AnalogSignalConfigs.Count;
  43. [PropertyAssociation(nameof(ShakerConfigModel.MaxFrequency))]
  44. public double MaxFrequency { get => Model.MaxFrequency; set => SetProperty(ref Model.MaxFrequency, value); }
  45. [PropertyAssociation(nameof(ShakerConfigModel.MinFrequency))]
  46. public double MinFrequency { get => Model.MinFrequency; set => SetProperty(ref Model.MinFrequency, value); }
  47. [PropertyAssociation(nameof(ShakerConfigModel.MaxOutInput))]
  48. public double MaxOutInput { get => Model.MaxOutInput; set => SetProperty(ref Model.MaxOutInput, value); }
  49. [PropertyAssociation(nameof(ShakerConfigModel.MaxAcceleration))]
  50. public double MaxAcceleration { get => Model.MaxAcceleration; set => SetProperty(ref Model.MaxAcceleration, value); }
  51. [PropertyAssociation(nameof(ShakerConfigModel.MaxDisplacement))]
  52. public double MaxDisplacement { get => Model.MaxDisplacement; set => SetProperty(ref Model.MaxDisplacement, value); }
  53. [PropertyAssociation(nameof(ShakerConfigModel.MaxDriver))]
  54. public double MaxDriver { get => Model.MaxDriver; set => SetProperty(ref Model.MaxDriver, value); }
  55. [PropertyAssociation(nameof(ShakerConfigModel.MaxJitterAcceleration))]
  56. public double MaxJitterAcceleration { get => Model.MaxJitterAcceleration; set => SetProperty(ref Model.MaxJitterAcceleration, value); }
  57. [PropertyAssociation(nameof(ShakerConfigModel.MaxJitterDisplacement))]
  58. public double MaxJitterDisplacement { get => Model.MaxJitterDisplacement; set => SetProperty(ref Model.MaxJitterDisplacement, value); }
  59. [PropertyAssociation(nameof(ShakerConfigModel.MaxVelocity))]
  60. public double MaxVelocity { get => Model.MaxVelocity; set => SetProperty(ref Model.MaxVelocity, value); }
  61. [PropertyAssociation(nameof(ShakerConfigModel.AccelerationConfigs))]
  62. public int AccelerationSensorCount => Model.AccelerationConfigs.Count;
  63. public AvaloniaList<IndexValueItemViewModel<AnalogSignalConfigViewModel>> AnalogSignals { get; } = new AvaloniaList<IndexValueItemViewModel<AnalogSignalConfigViewModel>>();
  64. public AvaloniaList<IndexValueItemViewModel<AccelerationConfigViewModel>> Accelerations { get; } = new AvaloniaList<IndexValueItemViewModel<AccelerationConfigViewModel>>();
  65. [PropertyAssociation(nameof(ShakerConfigModel.DisplacementSensitivity))]
  66. public double DisplacementSensitivity { get => Model.DisplacementSensitivity; set => SetProperty(ref Model.DisplacementSensitivity, value); }
  67. private ShakerConfigViewModel()
  68. {
  69. Content = typeof(Views.ShakerConfigView);
  70. for(int i=0;i<Model.AccelerationConfigs.Count;i++)
  71. {
  72. Accelerations.Add(new IndexValueItemViewModel<AccelerationConfigViewModel>(i + 1,new AccelerationConfigViewModel(Model.AccelerationConfigs[i])));
  73. Accelerations[^1].Value.PropertyChanged += (sender, args) =>
  74. {
  75. SaveIsEnabled = true;
  76. };
  77. }
  78. for(int i=0;i<Model.AnalogSignalConfigs.Count;i++)
  79. {
  80. AnalogSignals.Add(new IndexValueItemViewModel<AnalogSignalConfigViewModel>(i + 1, new AnalogSignalConfigViewModel(Model.AnalogSignalConfigs[i])));
  81. }
  82. GetEvent<AllConfig>().Subscrip((sender, args) =>
  83. {
  84. UpDateModel(args.Data.ShakerConfig);
  85. if(CommunicationViewModel.Intance.ServiceIsStart)
  86. {
  87. CommunicationViewModel.Intance.ServiceCommunication.GetEvent<Shaker.Models.ShakerConfigModel>().Publish(this, args.Data.ShakerConfig);
  88. }
  89. CommunicationViewModel.Intance.LocalCommunication?.GetEvent<Shaker.Models.ShakerConfigModel>()?.Subscrip((sender, args) =>
  90. {
  91. if (args.Data == null) return;
  92. UpDateModel(args.Data);
  93. CommunicationViewModel.Intance.ServiceCommunication?.GetEvent<Shaker.Models.ShakerConfigModel>()?.Publish(this, args.Data);
  94. });
  95. GetEvent(Models.Topic.InitSeries).Publish(this, null);
  96. });
  97. }
  98. static ShakerConfigViewModel()
  99. {
  100. }
  101. public override void UpDateModel(Shaker.Models.ShakerConfigModel model)
  102. {
  103. base.UpDateModel(model);
  104. Accelerations.Clear();
  105. for(int i=0;i<model.AccelerationConfigs.Count;i++)
  106. {
  107. Accelerations.Add(new IndexValueItemViewModel<AccelerationConfigViewModel>(i + 1, new AccelerationConfigViewModel(model.AccelerationConfigs[i])));
  108. Accelerations[^1].Value.PropertyChanged += (sender, args) =>
  109. {
  110. SaveIsEnabled = true;
  111. };
  112. }
  113. AnalogSignals.Clear();
  114. for(int i=0;i<model.AnalogSignalConfigs.Count;i++)
  115. {
  116. AnalogSignals.Add(new IndexValueItemViewModel<AnalogSignalConfigViewModel>(i + 1, new AnalogSignalConfigViewModel(model.AnalogSignalConfigs[i])));
  117. }
  118. }
  119. public static ShakerConfigViewModel Instance { get; } = new ShakerConfigViewModel();
  120. protected override void Save()
  121. {
  122. base.Save();
  123. CommunicationViewModel.Intance.LocalCommunication?.GetEvent<Shaker.Models.ShakerConfigModel>()?.Publish(this, Model);
  124. CommunicationViewModel.Intance.ServiceCommunication?.GetEvent<Shaker.Models.ShakerConfigModel>()?.Publish(this, Model);
  125. }
  126. }
  127. }