ShakerChannelViewModel.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using Avalonia.Collections;
  2. using Avalonia.Controls;
  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 ShakerChannelViewModel:DisplayViewModelBase<Shaker.Models.ShakerChannelModel>
  11. {
  12. public override bool CanResize => false;
  13. public override double Height => 420;
  14. public override double Width => 560;
  15. public AvaloniaList<int> Channels { get; } = new AvaloniaList<int>();
  16. [PropertyAssociation(nameof(Shaker.Models.ShakerChannelModel.DisplacementChannel))]
  17. public int DisplacementChannel { get => Model.DisplacementChannel; set => SetProperty(ref Model.DisplacementChannel, value); }
  18. [PropertyAssociation(nameof(Shaker.Models.ShakerChannelModel.AccelerationChannel0))]
  19. public int AccelerationChannel0 { get => Model.AccelerationChannel0; set => SetProperty(ref Model.AccelerationChannel0, value); }
  20. [PropertyAssociation(nameof(Shaker.Models.ShakerChannelModel.AccelerationChannel1))]
  21. public int AccelerationChannel1 { get => Model.AccelerationChannel1; set => SetProperty(ref Model.AccelerationChannel1, value); }
  22. [PropertyAssociation(nameof(Shaker.Models.ShakerChannelModel.OutSignalChannel))]
  23. public int OutSignalChannel { get => Model.OutSignalChannel; set => SetProperty(ref Model.OutSignalChannel, value); }
  24. protected override bool SkipProperty(string? propertyName)
  25. {
  26. cansave = true;
  27. return base.SkipProperty(propertyName);
  28. }
  29. private ShakerChannelViewModel()
  30. {
  31. Content = typeof(Views.ShakerChannelView);
  32. Channels.Clear();
  33. Channels.AddRange(Enumerable.Range(0, Shaker.Models.ShakerChannelModel.MaxChannel));
  34. GetEvent<Shaker.Models.AllConfig>().Subscrip((sender,args) =>
  35. {
  36. UpDateModel(args.Data.ShakerChannel);
  37. CommunicationViewModel.Instance.LocalCommunication?.GetEvent<Shaker.Models.ShakerChannelModel>()?.Subscrip((sender, args) =>
  38. {
  39. UpDateModel(args.Data);
  40. CommunicationViewModel.Instance.ServiceCommunication?.GetEvent<Shaker.Models.ShakerChannelModel>()?.Publish(this, Model);
  41. });
  42. });
  43. }
  44. static ShakerChannelViewModel()
  45. {
  46. }
  47. protected override void Save()
  48. {
  49. List<int> channels = new List<int>() { DisplacementChannel, AccelerationChannel0, AccelerationChannel1, OutSignalChannel };
  50. int oldch = channels.Count;
  51. if(channels.Distinct().Count()!=oldch)
  52. {
  53. SaveClose = false;
  54. this.ShowError(App.Current?.FindResource("ChannelRepeatError")+"");
  55. return;
  56. }
  57. base.Save();
  58. }
  59. public static ShakerChannelViewModel Instance { get; } = new ShakerChannelViewModel();
  60. }
  61. }