123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- using Avalonia.Collections;
- using Avalonia.Controls;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ShakerApp.ViewModels
- {
- internal class ShakerChannelViewModel:DisplayViewModelBase<Shaker.Models.ShakerChannelModel>
- {
- public override bool CanResize => false;
- public override double Height => 420;
- public override double Width => 560;
- public AvaloniaList<int> Channels { get; } = new AvaloniaList<int>();
- [PropertyAssociation(nameof(Shaker.Models.ShakerChannelModel.DisplacementChannel))]
- public int DisplacementChannel { get => Model.DisplacementChannel; set => SetProperty(ref Model.DisplacementChannel, value); }
- [PropertyAssociation(nameof(Shaker.Models.ShakerChannelModel.AccelerationChannel0))]
- public int AccelerationChannel0 { get => Model.AccelerationChannel0; set => SetProperty(ref Model.AccelerationChannel0, value); }
- [PropertyAssociation(nameof(Shaker.Models.ShakerChannelModel.AccelerationChannel1))]
- public int AccelerationChannel1 { get => Model.AccelerationChannel1; set => SetProperty(ref Model.AccelerationChannel1, value); }
- [PropertyAssociation(nameof(Shaker.Models.ShakerChannelModel.OutSignalChannel))]
- public int OutSignalChannel { get => Model.OutSignalChannel; set => SetProperty(ref Model.OutSignalChannel, value); }
- protected override bool SkipProperty(string? propertyName)
- {
- cansave = true;
- return base.SkipProperty(propertyName);
- }
- private ShakerChannelViewModel()
- {
- Content = typeof(Views.ShakerChannelView);
- Channels.Clear();
- Channels.AddRange(Enumerable.Range(0, Shaker.Models.ShakerChannelModel.MaxChannel));
- GetEvent<Shaker.Models.AllConfig>().Subscrip((sender,args) =>
- {
- UpDateModel(args.Data.ShakerChannel);
- CommunicationViewModel.Instance.LocalCommunication?.GetEvent<Shaker.Models.ShakerChannelModel>()?.Subscrip((sender, args) =>
- {
- UpDateModel(args.Data);
- CommunicationViewModel.Instance.ServiceCommunication?.GetEvent<Shaker.Models.ShakerChannelModel>()?.Publish(this, Model);
- });
- });
- }
- static ShakerChannelViewModel()
- {
- }
- protected override void Save()
- {
- List<int> channels = new List<int>() { DisplacementChannel, AccelerationChannel0, AccelerationChannel1, OutSignalChannel };
- int oldch = channels.Count;
- if(channels.Distinct().Count()!=oldch)
- {
- SaveClose = false;
- this.ShowError(App.Current?.FindResource("ChannelRepeatError")+"");
- return;
- }
- base.Save();
- }
- public static ShakerChannelViewModel Instance { get; } = new ShakerChannelViewModel();
- }
- }
|