RandomConfigViewModel.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. using Avalonia.Collections;
  2. using Avalonia.Controls;
  3. using Avalonia.Utilities;
  4. using CommunityToolkit.Mvvm.Input;
  5. using OxyPlot;
  6. using OxyPlot.Series;
  7. using Shaker.Models;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Numerics;
  12. using System.Runtime.CompilerServices;
  13. using System.Runtime.InteropServices;
  14. using System.Text;
  15. using System.Threading.Tasks;
  16. using System.Windows.Input;
  17. namespace ShakerApp.ViewModels
  18. {
  19. internal class RandomConfigViewModel : DisplayViewModelBase<Shaker.Models.RandomConfigModel>
  20. {
  21. public List<RandomData> RefSpectrum => datas;
  22. private RandomConfigViewModel()
  23. {
  24. Content = typeof(Views.RandomConfigView);
  25. #region 加速度谱曲线
  26. AccelerationModel.Axes.Add(new OxyPlot.Axes.LogarithmicAxis()
  27. {
  28. MaximumPadding = 0,
  29. MinimumPadding = 0,
  30. Title = App.Current?.FindResource(Shaker.Models.ShakerConstant.FrequencyKey) + "",
  31. Unit = "Hz",
  32. MajorGridlineStyle = LineStyle.Solid,
  33. Position = OxyPlot.Axes.AxisPosition.Bottom,
  34. Key = "Freq"
  35. });
  36. AccelerationModel.Axes.Add(new OxyPlot.Axes.LogarithmicAxis()
  37. {
  38. Key = "Ampt",
  39. Title = App.Current?.FindResource(ShakerConstant.AmptAxisTitleKey) + "",
  40. Unit = "g",
  41. MajorGridlineStyle = LineStyle.Solid,
  42. Position = OxyPlot.Axes.AxisPosition.Left,
  43. });
  44. AccelerationModel.Title = App.Current?.FindResource(ShakerConstant.AccelerationSpectrumKey) + "";
  45. for (int i = 0; i < oxyColors.Count; i++)
  46. {
  47. LineSeries line = new LineSeries();
  48. line.Title = App.Current?.FindResource(ShakerConstant.SweepAccelerationSpectrumNames[i]) + "";
  49. line.Color = oxyColors[i];
  50. line.StrokeThickness = 1;
  51. line.DataFieldX = nameof(SweepData.Frequency);
  52. line.DataFieldY = properties[i];
  53. line.LineStyle = lineStyles[i];
  54. line.XAxisKey = "Freq";
  55. line.YAxisKey = "Ampt";
  56. line.Tag = "g";
  57. lineSeries.Add(line);
  58. AccelerationModel.Series.Add(line);
  59. }
  60. AccelerationModel.Legends.Add(new OxyPlot.Legends.Legend()
  61. {
  62. ShowInvisibleSeries = true,
  63. });
  64. #endregion
  65. #region 速度
  66. VelocityModel.Axes.Add(new OxyPlot.Axes.LogarithmicAxis()
  67. {
  68. MaximumPadding = 0,
  69. MinimumPadding = 0,
  70. Title = App.Current?.FindResource(Shaker.Models.ShakerConstant.FrequencyKey) + "",
  71. Unit = "Hz",
  72. MajorGridlineStyle = LineStyle.Solid,
  73. Position = OxyPlot.Axes.AxisPosition.Bottom,
  74. Key = "Freq"
  75. });
  76. VelocityModel.Title = App.Current?.FindResource(ShakerConstant.VelocityKey) + "";
  77. VelocityModel.Axes.Add(new OxyPlot.Axes.LogarithmicAxis()
  78. {
  79. Key = "Ampt",
  80. Title = App.Current?.FindResource(ShakerConstant.AmptAxisTitleKey) + "",
  81. Unit = "m/s",
  82. MajorGridlineStyle = LineStyle.Solid,
  83. Position = OxyPlot.Axes.AxisPosition.Left,
  84. });
  85. velocity = new LineSeries();
  86. velocity.Title = App.Current?.FindResource(ShakerConstant.VelocityKey) + "";
  87. velocity.Color = oxyColors[0];
  88. velocity.StrokeThickness = 1;
  89. velocity.DataFieldX = nameof(DataPoint.X);
  90. velocity.DataFieldY = nameof(DataPoint.Y);
  91. velocity.LineStyle = lineStyles[0];
  92. velocity.XAxisKey = "Freq";
  93. velocity.YAxisKey = "Ampt";
  94. velocity.Tag = "m/s";
  95. VelocityModel.Series.Add(velocity);
  96. #endregion
  97. #region 位移
  98. DisplacementModel.Axes.Add(new OxyPlot.Axes.LogarithmicAxis()
  99. {
  100. MaximumPadding = 0,
  101. MinimumPadding = 0,
  102. Title = App.Current?.FindResource(Shaker.Models.ShakerConstant.FrequencyKey) + "",
  103. Unit = "Hz",
  104. MajorGridlineStyle = LineStyle.Solid,
  105. Position = OxyPlot.Axes.AxisPosition.Bottom,
  106. Key = "Freq"
  107. });
  108. DisplacementModel.Title = App.Current?.FindResource(ShakerConstant.DisplacementKey) + "";
  109. DisplacementModel.Axes.Add(new OxyPlot.Axes.LogarithmicAxis()
  110. {
  111. Key = "Ampt",
  112. Title = App.Current?.FindResource(ShakerConstant.AmptAxisTitleKey) + "",
  113. Unit = "mm",
  114. MajorGridlineStyle = LineStyle.Solid,
  115. Position = OxyPlot.Axes.AxisPosition.Left,
  116. });
  117. displacement = new LineSeries();
  118. displacement.Title = App.Current?.FindResource(ShakerConstant.DisplacementKey) + "";
  119. displacement.Color = oxyColors[0];
  120. displacement.StrokeThickness = 1;
  121. displacement.DataFieldX = nameof(DataPoint.X);
  122. displacement.DataFieldY = nameof(DataPoint.Y);
  123. displacement.LineStyle = lineStyles[0];
  124. displacement.XAxisKey = "Freq";
  125. displacement.YAxisKey = "Ampt";
  126. displacement.Tag = "mm";
  127. DisplacementModel.Series.Add(displacement);
  128. #endregion
  129. GetEvent(ShakerSettingViewModel.LANGUAGECHANGEDEVENT).Subscrip((_, _) =>
  130. {
  131. AccelerationModel.InvalidatePlot(false);
  132. AccelerationModel.Axes[0].Title = App.Current?.FindResource(ShakerConstant.FrequencyKey) + "";
  133. AccelerationModel.Axes[1].Title = App.Current?.FindResource(ShakerConstant.AmptAxisTitleKey) + "";
  134. AccelerationModel.Title = App.Current?.FindResource(ShakerConstant.AccelerationSpectrumKey) + "";
  135. for (int i = 0; i < lineSeries.Count; i++)
  136. {
  137. lineSeries[i].Title = App.Current?.FindResource(ShakerConstant.SweepAccelerationSpectrumNames[i]) + "";
  138. }
  139. AccelerationModel.InvalidatePlot(true);
  140. VelocityModel.InvalidatePlot(false);
  141. VelocityModel.Axes[0].Title = App.Current?.FindResource(ShakerConstant.FrequencyKey) + "";
  142. VelocityModel.Axes[1].Title = App.Current?.FindResource(ShakerConstant.AmptAxisTitleKey) + "";
  143. VelocityModel.Title = App.Current?.FindResource(ShakerConstant.VelocityKey) + "";
  144. velocity.Title = App.Current?.FindResource(ShakerConstant.VelocityKey) + "";
  145. VelocityModel.InvalidatePlot(true);
  146. DisplacementModel.InvalidatePlot(false);
  147. DisplacementModel.Axes[0].Title = App.Current?.FindResource(ShakerConstant.FrequencyKey) + "";
  148. DisplacementModel.Axes[1].Title = App.Current?.FindResource(ShakerConstant.AmptAxisTitleKey) + "";
  149. DisplacementModel.Title = App.Current?.FindResource(ShakerConstant.DisplacementKey) + "";
  150. displacement.Title = App.Current?.FindResource(ShakerConstant.DisplacementKey) + "";
  151. DisplacementModel.InvalidatePlot(true);
  152. });
  153. GetEvent<AllConfig>().Subscrip((sender, args) =>
  154. {
  155. UpDateModel(args.Data.RandomConfig);
  156. CommunicationViewModel.Instance.LocalCommunication?.GetEvent<RandomConfigModel>()?.Subscrip((sender, args) =>
  157. {
  158. UpDateModel(args.Data);
  159. Refresh();
  160. RandomMainPageViewModel.Instance.SetRefSpectrum(datas);
  161. CommunicationViewModel.Instance.ServiceCommunication?.GetEvent<RandomConfigModel>()?.Publish(this, Model);
  162. });
  163. });
  164. Identify.PropertyChanged += (_, _) => SaveIsEnabled = true;
  165. }
  166. static RandomConfigViewModel()
  167. {
  168. }
  169. [PropertyAssociation(nameof(RandomConfigModel.SpectrumItemsCount))]
  170. public uint SpectrumItemsCount => Model.SpectrumItemsCount;
  171. [PropertyAssociation(nameof(RandomConfigModel.HanningWindowCompensationCoefficient))]
  172. public double HanningWindowCompensationCoefficient { get => Model.HanningWindowCompensationCoefficient; set => SetProperty(ref Model.HanningWindowCompensationCoefficient, value); }
  173. [PropertyAssociation(nameof(RandomConfigModel.LinearAverage))]
  174. public uint LinearAverage { get => Model.LinearAverage; set => SetProperty(ref Model.LinearAverage, value); }
  175. [PropertyAssociation(nameof(RandomConfigModel.ExponentialAverage))]
  176. public uint ExponentialAverage { get => Model.ExponentialAverage; set => SetProperty(ref Model.ExponentialAverage, value); }
  177. [PropertyAssociation(nameof(RandomConfigModel.LinearAverage),nameof(RandomConfigModel.ExponentialAverage))]
  178. public uint DOF => (LinearAverage << 1) * ((ExponentialAverage << 1) - 1);
  179. [PropertyAssociation(nameof(RandomConfigModel.MaxFrequency),nameof(SpectrumLines))]
  180. public double FrequencyResolution => (double)MaxFrequency / (double)SpectrumLines;
  181. [PropertyAssociation(nameof(RandomConfigModel.RandomSampleRate))]
  182. public uint RandomSampleRate => Model.RandomSampleRate;
  183. List<OxyPlot.Series.LineSeries> lineSeries = new List<OxyPlot.Series.LineSeries>();
  184. List<DataPoint> velocitydata = new List<DataPoint>();
  185. LineSeries velocity = new LineSeries();
  186. LineSeries displacement = new LineSeries();
  187. List<DataPoint> displacementdata = new List<DataPoint>();
  188. List<OxyColor> oxyColors = new List<OxyColor>() { OxyColors.Green, OxyColors.Red, OxyColors.Red, OxyColors.Yellow, OxyColors.Yellow };
  189. List<LineStyle> lineStyles = new List<LineStyle>() { LineStyle.Solid, LineStyle.Solid, LineStyle.Solid, LineStyle.LongDashDotDot, LineStyle.LongDashDotDot };
  190. List<string> properties = new List<string>() { nameof(RandomData.TargetAcceleration), nameof(RandomData.UpStopAcceleration), nameof(RandomData.DownStopAcceleration), nameof(RandomData.UpWarnAcceleration), nameof(RandomData.DownWarnAcceleration) };
  191. List<RandomData> datas = new List<RandomData>();
  192. private double maxDisplacement;
  193. private double maxVelocity;
  194. private bool canResetRMS = false;
  195. private double resetRMS;
  196. [PropertyAssociation(nameof(RandomConfigModel.MaxFrequency))]
  197. public RandomMaxFrequency MaxFrequency
  198. {
  199. get => Model.MaxFrequency;
  200. set
  201. {
  202. SetProperty(ref Model.MaxFrequency, value);
  203. OnPropertyChanged(nameof(FFTLength));
  204. }
  205. }
  206. public bool CanResetRMS { get => canResetRMS; set =>SetProperty(ref canResetRMS, value); }
  207. public double ResetRMS { get => resetRMS; set =>SetProperty(ref resetRMS , value); }
  208. [PropertyAssociation(nameof(RandomConfigModel.SynthesisType))]
  209. public AccelerationSynthesisType SynthesisType { get => Model.SynthesisType; set => SetProperty(ref Model.SynthesisType, value); }
  210. [PropertyAssociation(nameof(RandomConfigModel.MinFrequency))]
  211. public double MinFrequency { get => Model.MinFrequency; set => SetProperty(ref Model.MinFrequency, value); }
  212. [PropertyAssociation(nameof(RandomConfigModel.SpectrumLines))]
  213. public SpectrumLines SpectrumLines
  214. {
  215. get => Model.SpectrumLines;
  216. set
  217. {
  218. SetProperty(ref Model.SpectrumLines, value);
  219. OnPropertyChanged(nameof(FFTLength));
  220. }
  221. }
  222. [PropertyAssociation(nameof(RandomConfigModel.Sigma))]
  223. public double Sigma { get => Model.Sigma; set => SetProperty(ref Model.Sigma, value); }
  224. [PropertyAssociation(nameof(RandomConfigModel.RandomSampleRate),nameof(RandomConfigModel.MaxFrequency),nameof(RandomConfigModel.SpectrumLines))]
  225. public uint FFTLength => (uint)(Model.RandomSampleRate / (float)MaxFrequency * (uint)SpectrumLines);
  226. [PropertyAssociation(nameof(RandomConfigModel.RandomSampleRate), nameof(RandomConfigModel.MaxFrequency), nameof(RandomConfigModel.SpectrumLines))]
  227. public uint FFTHalfLength => FFTLength >> 1;
  228. public RandomIdentifyViewModel Identify { get; } = new RandomIdentifyViewModel();
  229. public AvaloniaList<IndexValueItemViewModel<RandomSpectrumItemViewModel>> SpectrumItems { get; }= new AvaloniaList<IndexValueItemViewModel<RandomSpectrumItemViewModel>>();
  230. public AvaloniaList<IndexValueItemViewModel<RandomPlanItemViewModel>> PlanItems { get; } = new AvaloniaList<IndexValueItemViewModel<RandomPlanItemViewModel>>();
  231. [PropertyAssociation(nameof(RandomConfigModel.StopLins))]
  232. public uint StopLins { get => Model.StopLins; set => SetProperty(ref Model.StopLins, value); }
  233. [PropertyAssociation(nameof(RandomConfigModel.WarnLines))]
  234. public uint WarnLines { get => Model.WarnLines; set => SetProperty(ref Model.WarnLines, value); }
  235. [PropertyAssociation(nameof(RandomConfigModel.StopRMS))]
  236. public double StopRMS { get => Model.StopRMS; set => SetProperty(ref Model.StopRMS, value); }
  237. public OxyPlot.PlotModel AccelerationModel { get; } = new OxyPlot.PlotModel();
  238. public PlotModel DisplacementModel { get; } = new PlotModel();
  239. public PlotModel VelocityModel { get; } = new PlotModel();
  240. public static RandomConfigViewModel Instance { get; } = new RandomConfigViewModel();
  241. [PropertyAssociation(nameof(RandomConfigModel.Sigma))]
  242. public double MaxAcceleration => RMSAcceleration * Sigma;
  243. public double MaxDisplacement { get => maxDisplacement; set =>SetProperty(ref maxDisplacement , value); }
  244. public double MaxVelocity { get => maxVelocity; set =>SetProperty(ref maxVelocity , value); }
  245. public bool AccelerationOverLimit => MaxAcceleration >= ShakerConfigViewModel.Instance.MaxAcceleration;
  246. public bool DisplacementOverLimit => MaxDisplacement > ShakerConfigViewModel.Instance.MaxDisplacement;
  247. public bool VelocityOverLimit => MaxVelocity > ShakerConfigViewModel.Instance.MaxVelocity;
  248. public double AccelerationLoad => Math.Round(MaxAcceleration / ShakerConfigViewModel.Instance.MaxAcceleration * 100f, 2);
  249. public double DisplacementLoad => Math.Round((double)MaxDisplacement / ShakerConfigViewModel.Instance.MaxDisplacement * 100f, 2);
  250. public double VelocityLoad => Math.Round((double)MaxVelocity / ShakerConfigViewModel.Instance.MaxVelocity * 100f, 2);
  251. public double RMSAcceleration { get => Model.RMSAcceleration; set =>SetProperty(ref Model.RMSAcceleration , value); }
  252. public ICommand AddCommand => new RelayCommand(Add);
  253. public override void UpDateModel(RandomConfigModel model)
  254. {
  255. SpectrumItems.Clear();
  256. PlanItems.Clear();
  257. for(int i=0;i<model.SpectrumItems.Count;i++)
  258. {
  259. SpectrumItems.Add(new IndexValueItemViewModel<RandomSpectrumItemViewModel>(i + 1, new RandomSpectrumItemViewModel(model.SpectrumItems[i])));
  260. }
  261. for(int i=0;i<model.PlanItems.Count;i++)
  262. {
  263. PlanItems.Add(new IndexValueItemViewModel<RandomPlanItemViewModel>(i + 1, new RandomPlanItemViewModel(model.PlanItems[i])));
  264. }
  265. Identify.UpDateModel(model.Identify);
  266. base.UpDateModel(model);
  267. }
  268. private void Add()
  269. {
  270. if (SpectrumItems.Count >= SpectrumItemsCount) return;
  271. if (Model.SpectrumItems.Count == 0) Model.SpectrumItems.Add(new RandomSpectrumItemModel());
  272. else Model.SpectrumItems.Add(Model.SpectrumItems[^1].CloneBase());
  273. SpectrumItems.Add(new IndexValueItemViewModel<RandomSpectrumItemViewModel>(SpectrumItems.Count + 1, new RandomSpectrumItemViewModel(Model.SpectrumItems[^1])));
  274. }
  275. public ICommand DeleteCommand => new RelayCommand(Delete);
  276. private void Delete()
  277. {
  278. if (SpectrumItems.Count == 0) return;
  279. if(Model.SpectrumItems.Count>0)
  280. {
  281. Model.SpectrumItems.RemoveAt(Model.SpectrumItems.Count - 1);
  282. }
  283. SpectrumItems.RemoveAt(SpectrumItems.Count - 1);
  284. }
  285. public ICommand ResetRMSCommand=>new RelayCommand(ResetRMSExecute);
  286. private void ResetRMSExecute()
  287. {
  288. if (!CanResetRMS) return;
  289. if (ResetRMS <= 0) return;
  290. for(int i=0;i<SpectrumItems.Count;i++)
  291. {
  292. SpectrumItems[i].Value.Value *= (ResetRMS*ResetRMS)/(RMSAcceleration * RMSAcceleration);
  293. Model.SpectrumItems[i].Value = SpectrumItems[i].Value.Value;
  294. }
  295. CanResetRMS = false;
  296. RefreshCommand?.CanExecute(null);
  297. }
  298. public ICommand AddPlanCommand => new RelayCommand(AddPlan);
  299. private void AddPlan()
  300. {
  301. if (PlanItems.Count >= 10 || Model.PlanItems.Count>=10) return;
  302. if (Model.PlanItems.Count == 0) Model.PlanItems.Add(new RandomPlanItemModel());
  303. else Model.PlanItems.Add(Model.PlanItems[^1].CloneBase());
  304. PlanItems.Add(new IndexValueItemViewModel<RandomPlanItemViewModel>(PlanItems.Count + 1, new RandomPlanItemViewModel(Model.PlanItems[^1])));
  305. }
  306. public ICommand DeletePlanCommand => new RelayCommand(DeletePlan);
  307. private void DeletePlan()
  308. {
  309. if (PlanItems.Count == 0) return;
  310. if(Model.PlanItems.Count==0)
  311. {
  312. Model.PlanItems.RemoveAt(Model.PlanItems.Count - 1);
  313. }
  314. PlanItems.RemoveAt(PlanItems.Count - 1);
  315. }
  316. public ICommand RefreshPlanCommand => new RelayCommand(RefreshPlan);
  317. private void RefreshPlan()
  318. {
  319. if (PlanItems.Count < 1) return;
  320. }
  321. public ICommand RefreshCommand => new RelayCommand(Refresh);
  322. private unsafe void Refresh()
  323. {
  324. if (SpectrumItems.Count < 3) return;
  325. var items = SpectrumItems.Select(x => x.Value.Model.CloneBase()).DistinctBy(x => x.Frequency).OrderBy(x => x.Frequency).ToList();
  326. SpectrumItems.Clear();
  327. for(int i=0;i<items.Count;i++)
  328. {
  329. SpectrumItems.Add(new IndexValueItemViewModel<RandomSpectrumItemViewModel>(i + 1, new RandomSpectrumItemViewModel(items[i])));
  330. }
  331. if (items.Count < 3) return;
  332. Shaker.Models.Tools.Tools.CalcRefSpectrum(items.Select(x => x.Frequency).ToArray(), items.Select(x => x.Value).ToArray(), items.Select(x => x.ValueType).ToArray(), FrequencyResolution,out var fy_array,out var f,out var turningfreq);
  333. if (fy_array.Length == 0) return;
  334. this.Model.SpectralTables.Clear();
  335. for(int i=0;i<turningfreq.Length;i++)
  336. {
  337. this.Model.SpectralTables.Add(new RandomSpectralTableModel()
  338. {
  339. TurningFrequency = turningfreq[i],
  340. TurningValue = fy_array[(int)((turningfreq[i]-SpectrumItems[0].Value.Frequency)/FrequencyResolution)],
  341. });
  342. }
  343. RMSAcceleration = Math.Sqrt(Shaker.Models.Tools.Tools.Calc.Sum.Sum(ref fy_array[0], (uint)fy_array.Length) * FrequencyResolution);
  344. ResetRMS = RMSAcceleration;
  345. double[] f2 = new double[f.Length];
  346. double[] fv = new double[f.Length];
  347. Shaker.Models.Tools.Tools.Calc.Multiply.Multiply(ref f[0], ref f[0], (uint)f.Length,ref f2[0]);
  348. Shaker.Models.Tools.Tools.Calc.Division.Division(ref fy_array[0],ref f2[0], (uint)f.Length,ref fv[0]);
  349. double sum = Shaker.Models.Tools.Tools.Calc.Sum.Sum(ref fv[0], (uint)fv.Length);
  350. MaxVelocity = Math.Sqrt((sum - (fv[0] + fv[^1] / 2) / 2) * FrequencyResolution) / (2 * Math.PI) * Sigma * 9.8f;
  351. Shaker.Models.Tools.Tools.Calc.Division.Division(ref fv[0], ref f2[0], (uint)f.Length, ref fv[0]);
  352. sum = Shaker.Models.Tools.Tools.Calc.Sum.Sum(ref fv[0], (uint)fv.Length);
  353. MaxDisplacement = Math.Sqrt((sum - (fv[0] + fv[^1] / 2) / 2) * FrequencyResolution) / (2 * Math.PI*2*Math.PI) * Sigma * 9800f;
  354. OnPropertyChanged(nameof(MaxAcceleration));
  355. double[,] spectrumdata = new double[5, f.Length];
  356. Unsafe.CopyBlock(ref Unsafe.As<double, byte>(ref spectrumdata[0, 0]), ref Unsafe.As<double, byte>(ref fy_array[0]), (uint)(Unsafe.SizeOf<double>() * fy_array.Length));
  357. CalcSpectrum(items, f, fy_array, FrequencyResolution, turningfreq, ref spectrumdata);
  358. datas.Clear();
  359. velocitydata.Clear();
  360. displacementdata.Clear();
  361. for (int i=0;i<f.Length;i++)
  362. {
  363. datas.Add(new RandomData(f[i],double.NaN, double.NaN, spectrumdata[0, i], spectrumdata[1, i], spectrumdata[3, i], spectrumdata[2, i], spectrumdata[4,i]));
  364. velocitydata.Add(new DataPoint(f[i], Shaker.Models.Tools.Tools.AccelerationToVelocity(spectrumdata[0, i], f[i])));
  365. displacementdata.Add(new DataPoint(f[i], Shaker.Models.Tools.Tools.AccelerationToDisplacement(spectrumdata[0, i], f[i])));
  366. }
  367. AccelerationModel.InvalidatePlot(false);
  368. VelocityModel.InvalidatePlot(false);
  369. DisplacementModel.InvalidatePlot(false);
  370. for (int i = 0; i < lineSeries.Count; i++)
  371. {
  372. lineSeries[i].ItemsSource = datas;
  373. }
  374. velocity.ItemsSource = velocitydata;
  375. displacement.ItemsSource = displacementdata;
  376. AccelerationModel.InvalidatePlot(true);
  377. VelocityModel.InvalidatePlot(true);
  378. DisplacementModel.InvalidatePlot(true);
  379. CanResetRMS = true;
  380. }
  381. private void CalcSpectrum(List<RandomSpectrumItemModel> models, [In] double[] f, [In] double[] fy_array, [In] double deltaf, [In] double[] turn_freq,ref double[,] spectrumdata)
  382. {
  383. Shaker.Models.Tools.Tools.CalcItemSpectrum(models.Select(x => x.UpStop).ToArray(), f, fy_array, deltaf, turn_freq, ref spectrumdata[1, 0]);
  384. Shaker.Models.Tools.Tools.CalcItemSpectrum(models.Select(x => x.UpWarn).ToArray(), f, fy_array, deltaf, turn_freq, ref spectrumdata[2, 0]);
  385. Shaker.Models.Tools.Tools.CalcItemSpectrum(models.Select(x => x.DownStop).ToArray(), f, fy_array, deltaf, turn_freq, ref spectrumdata[3, 0]);
  386. Shaker.Models.Tools.Tools.CalcItemSpectrum(models.Select(x => x.DownWarn).ToArray(), f, fy_array, deltaf, turn_freq, ref spectrumdata[4, 0]);
  387. }
  388. protected override void Save()
  389. {
  390. base.Save();
  391. CommunicationViewModel.Instance.LocalCommunication?.GetEvent<RandomConfigModel>()?.Publish(this, Model);
  392. CommunicationViewModel.Instance.ServiceCommunication?.GetEvent<RandomConfigModel>()?.Publish(this, Model);
  393. RandomMainPageViewModel.Instance.SetRefSpectrum(datas);
  394. }
  395. }
  396. }