SequenceSet.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.ComponentModel;
  5. using System.Runtime.CompilerServices;
  6. using Newtonsoft.Json;
  7. using TeamAAS.Feeder.Enums;
  8. namespace TeamAAS.Feeder.Models
  9. {
  10. public enum SequenceStepType
  11. {
  12. [Description("方向振动")]
  13. Direction,
  14. [Description("延时等待")]
  15. Delay,
  16. }
  17. public class SequenceStep : INotifyPropertyChanged
  18. {
  19. private int _index;
  20. private SequenceStepType _stepType = SequenceStepType.Direction;
  21. private FeederAction _direction = FeederAction.Right;
  22. private int _timeMs = 500;
  23. private string _note = "";
  24. private bool _enabled = true;
  25. [JsonIgnore]
  26. public int Index
  27. {
  28. get { return _index; }
  29. set { SetProperty(ref _index, value); }
  30. }
  31. public SequenceStepType StepType
  32. {
  33. get { return _stepType; }
  34. set { SetProperty(ref _stepType, value); }
  35. }
  36. public FeederAction Direction
  37. {
  38. get { return _direction; }
  39. set { SetProperty(ref _direction, value); }
  40. }
  41. /// <summary>
  42. /// 统一时间字段:方向振动时=振动时长(ms),延时等待时=延时时长(ms)
  43. /// </summary>
  44. public int TimeMs
  45. {
  46. get { return _timeMs; }
  47. set { SetProperty(ref _timeMs, value); }
  48. }
  49. public string Note
  50. {
  51. get { return _note; }
  52. set { SetProperty(ref _note, value); }
  53. }
  54. public bool Enabled
  55. {
  56. get { return _enabled; }
  57. set { SetProperty(ref _enabled, value); }
  58. }
  59. public event PropertyChangedEventHandler PropertyChanged;
  60. protected virtual bool SetProperty<T>(ref T storage, T value, [CallerMemberName] string propertyName = null)
  61. {
  62. if (EqualityComparer<T>.Default.Equals(storage, value)) return false;
  63. storage = value;
  64. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  65. return true;
  66. }
  67. }
  68. public class SequenceSet : INotifyPropertyChanged
  69. {
  70. private string _name = "";
  71. private string _description = "";
  72. public string Name
  73. {
  74. get { return _name; }
  75. set { SetProperty(ref _name, value); }
  76. }
  77. public string Description
  78. {
  79. get { return _description; }
  80. set { SetProperty(ref _description, value); }
  81. }
  82. public ObservableCollection<SequenceStep> Steps { get; set; }
  83. = new ObservableCollection<SequenceStep>();
  84. public SequenceSet Clone()
  85. {
  86. var json = JsonConvert.SerializeObject(this);
  87. return JsonConvert.DeserializeObject<SequenceSet>(json);
  88. }
  89. public event PropertyChangedEventHandler PropertyChanged;
  90. protected virtual bool SetProperty<T>(ref T storage, T value, [CallerMemberName] string propertyName = null)
  91. {
  92. if (EqualityComparer<T>.Default.Equals(storage, value)) return false;
  93. storage = value;
  94. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  95. return true;
  96. }
  97. }
  98. }