123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- using Avalonia.Collections;
- using Avalonia.Controls;
- using Shaker.Models;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ShakerApp.ViewModels
- {
- internal class ShakerConfigViewModel : ViewModelBase<Shaker.Models.ShakerConfigModel>
- {
- [PropertyAssociation(nameof(ShakerConfigModel.DisplacementBias))]
- public float DisplacementBias { get => Model.DisplacementBias; set => SetProperty(ref Model.DisplacementBias, value); }
- [PropertyAssociation(nameof(ShakerConfigModel.SynthesisType))]
- public AccelerationSynthesisType SynthesisType { get => Model.SynthesisType; set => SetProperty(ref Model.SynthesisType, value); }
- [PropertyAssociation(nameof(ShakerConfigModel.OutSignalGain))]
- public double OutSignalGain { get => Model.OutSignalGain; set => SetProperty(ref Model.OutSignalGain, value); }
- public override bool CanResize => false;
- public override double Width => 960;
- public override double Height => 560;
- [PropertyAssociation(nameof(ShakerConfigModel.BitstreamMD5))]
- public string BitstreamMD5 => Model.BitstreamMD5;
- [PropertyAssociation(nameof(ShakerConfigModel.BitstreamVersion))]
- public string BitfileVersion =>Model.BitstreamVersion;
- [PropertyAssociation(nameof(ShakerConfigModel.SignatureRegister))]
- public string SignatureRegister =>Model.SignatureRegister;
- [PropertyAssociation(nameof(ShakerConfigModel.BitstreamVersion))]
- public string BitstreamVersion =>Model.BitstreamVersion;
- [PropertyAssociation(nameof(ShakerConfigModel.BitstreamVersion))]
- public string SignatureNames => Model.BitstreamVersion;
- [PropertyAssociation(nameof(ShakerConfigModel.CreateTime))]
- public DateTime CreateTime =>Model.CreateTime;
- [PropertyAssociation(nameof(ShakerConfigModel.MaxRiseCount))]
- public uint MaxRiseCount => Model.MaxRiseCount;
- [PropertyAssociation(nameof(ShakerConfigModel.MaxZeroChangedCount))]
- public uint MaxZeroChangedCount => Model.MaxZeroChangedCount;
- [PropertyAssociation(nameof(ShakerConfigModel.MaxSignalCount))]
- public uint MaxSignalCount => Model.MaxSignalCount;
- [PropertyAssociation(nameof(ShakerConfigModel.MaxEmergencyStopCount))]
- public uint MaxEmergencyStopCount => Model.MaxEmergencyStopCount;
- [PropertyAssociation(nameof(ShakerConfigModel.MaxStopWindowCount))]
- public uint MaxStopWindowCount => MaxStopWindowCount;
- [PropertyAssociation(nameof(ShakerConfigModel.MaxAdjustCount))]
- public uint MaxAdjustCount => Model.MaxAdjustCount;
- [PropertyAssociation(nameof(ShakerConfigModel.MaxFallCount))]
- public uint MaxFallCount => Model.MaxFallCount;
- [PropertyAssociation(nameof(ShakerConfigModel.StartCount))]
- public uint StartCount => Model.StartCount;
- [PropertyAssociation(nameof(ShakerConfigModel.InitialLocation))]
- public double InitialLocation { get => Model.InitialLocation; set => SetProperty(ref Model.InitialLocation, value); }
- [PropertyAssociation(nameof(ShakerConfigModel.SampleRate))]
- public uint SampleRate => Model.SampleRate;
- [PropertyAssociation(nameof(ShakerConfigModel.FPGAClock))]
- public uint FPGAClock => Model.FPGAClock;
- [PropertyAssociation(nameof(ShakerConfigModel.AnalogSignalConfigs))]
- public int ChannelCount => Model.AnalogSignalConfigs.Count;
- [PropertyAssociation(nameof(ShakerConfigModel.MaxFrequency))]
- public double MaxFrequency { get => Model.MaxFrequency; set => SetProperty(ref Model.MaxFrequency, value); }
- [PropertyAssociation(nameof(ShakerConfigModel.MinFrequency))]
- public double MinFrequency { get => Model.MinFrequency; set => SetProperty(ref Model.MinFrequency, value); }
- [PropertyAssociation(nameof(ShakerConfigModel.MaxOutInput))]
- public double MaxOutInput { get => Model.MaxOutInput; set => SetProperty(ref Model.MaxOutInput, value); }
- [PropertyAssociation(nameof(ShakerConfigModel.MaxAcceleration))]
- public double MaxAcceleration { get => Model.MaxAcceleration; set => SetProperty(ref Model.MaxAcceleration, value); }
- [PropertyAssociation(nameof(ShakerConfigModel.MaxDisplacement))]
- public double MaxDisplacement { get => Model.MaxDisplacement; set => SetProperty(ref Model.MaxDisplacement, value); }
- [PropertyAssociation(nameof(ShakerConfigModel.MaxDriver))]
- public double MaxDriver { get => Model.MaxDriver; set => SetProperty(ref Model.MaxDriver, value); }
- [PropertyAssociation(nameof(ShakerConfigModel.MaxJitterAcceleration))]
- public double MaxJitterAcceleration { get => Model.MaxJitterAcceleration; set => SetProperty(ref Model.MaxJitterAcceleration, value); }
- [PropertyAssociation(nameof(ShakerConfigModel.MaxJitterDisplacement))]
- public double MaxJitterDisplacement { get => Model.MaxJitterDisplacement; set => SetProperty(ref Model.MaxJitterDisplacement, value); }
- [PropertyAssociation(nameof(ShakerConfigModel.MaxVelocity))]
- public double MaxVelocity { get => Model.MaxVelocity; set => SetProperty(ref Model.MaxVelocity, value); }
- [PropertyAssociation(nameof(ShakerConfigModel.AccelerationConfigs))]
- public int AccelerationSensorCount => Model.AccelerationConfigs.Count;
- public AvaloniaList<IndexValueItemViewModel<AnalogSignalConfigViewModel>> AnalogSignals { get; } = new AvaloniaList<IndexValueItemViewModel<AnalogSignalConfigViewModel>>();
- public AvaloniaList<IndexValueItemViewModel<AccelerationConfigViewModel>> Accelerations { get; } = new AvaloniaList<IndexValueItemViewModel<AccelerationConfigViewModel>>();
- [PropertyAssociation(nameof(ShakerConfigModel.DisplacementSensitivity))]
- public double DisplacementSensitivity { get => Model.DisplacementSensitivity; set => SetProperty(ref Model.DisplacementSensitivity, value); }
- public double AccelerationSensitivity => Accelerations.First().Value.Model.Sensitivity;
- private ShakerConfigViewModel()
- {
- Content = typeof(Views.ShakerConfigView);
- for(int i=0;i<Model.AccelerationConfigs.Count;i++)
- {
- Accelerations.Add(new IndexValueItemViewModel<AccelerationConfigViewModel>(i + 1,new AccelerationConfigViewModel(Model.AccelerationConfigs[i])));
- Accelerations[^1].Value.PropertyChanged += (sender, args) =>
- {
- SaveIsEnabled = true;
- switch(args.PropertyName)
- {
- case nameof(AccelerationConfigViewModel.Weight):
- if (AccelerationSensorCount <= 1) return;
- Accelerations[^1].Value.Weight = 1 - Accelerations.Take(AccelerationSensorCount - 1).Sum(x => x.Value.Weight);
- break;
- }
- };
- }
- for(int i=0;i<Model.AnalogSignalConfigs.Count;i++)
- {
- AnalogSignals.Add(new IndexValueItemViewModel<AnalogSignalConfigViewModel>(i + 1, new AnalogSignalConfigViewModel(Model.AnalogSignalConfigs[i])));
- }
- GetEvent<AllConfig>().Subscrip((sender, args) =>
- {
- UpDateModel(args.Data.ShakerConfig);
- OnPropertyChanged(nameof(AccelerationSensorCount));
- CommunicationViewModel.Instance.LocalCommunication?.GetEvent<Shaker.Models.ShakerConfigModel>()?.Subscrip((sender, args) =>
- {
- if (args.Data == null) return;
- UpDateModel(args.Data);
- OnPropertyChanged(nameof(AccelerationSensorCount));
- CommunicationViewModel.Instance.ServiceCommunication?.GetEvent<Shaker.Models.ShakerConfigModel>()?.Publish(this, args.Data);
- });
- GetEvent(Models.Topic.InitSeries).Publish(this, null);
- });
- }
- static ShakerConfigViewModel()
- {
- }
- public override void UpDateModel(Shaker.Models.ShakerConfigModel model)
- {
- base.UpDateModel(model);
- Accelerations.Clear();
- for(int i=0;i<model.AccelerationConfigs.Count;i++)
- {
- Accelerations.Add(new IndexValueItemViewModel<AccelerationConfigViewModel>(i + 1, new AccelerationConfigViewModel(model.AccelerationConfigs[i])));
- Accelerations[^1].Value.PropertyChanged += (sender, args) =>
- {
- SaveIsEnabled = true;
- };
- }
- AnalogSignals.Clear();
- for(int i=0;i<model.AnalogSignalConfigs.Count;i++)
- {
- AnalogSignals.Add(new IndexValueItemViewModel<AnalogSignalConfigViewModel>(i + 1, new AnalogSignalConfigViewModel(model.AnalogSignalConfigs[i])));
- }
- }
- public static ShakerConfigViewModel Instance { get; } = new ShakerConfigViewModel();
- protected override void Save()
- {
- if(SynthesisType == AccelerationSynthesisType.Synthesis && MathF.Abs(Accelerations.Sum(x=>x.Value.Weight) -1f)>0.0001f)
- {
- ShowError(string.Format(App.Current?.FindResource("AccelerationWeightSumError") + "", 1));
- return;
- }
- base.Save();
- CommunicationViewModel.Instance.LocalCommunication?.GetEvent<Shaker.Models.ShakerConfigModel>()?.Publish(this, Model);
- CommunicationViewModel.Instance.ServiceCommunication?.GetEvent<Shaker.Models.ShakerConfigModel>()?.Publish(this, Model);
- }
- public override void ReceiveServiceModel(ShakerConfigModel model)
- {
- base.ReceiveServiceModel(model);
- CommunicationViewModel.Instance.LocalCommunication?.GetEvent<Shaker.Models.ShakerConfigModel>()?.Publish(this, Model);
- }
- }
- }
|