TraceLogViewModel.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. 
  2. using NPOI.SS.Formula.Functions;
  3. namespace MinicsUI.ViewModels.Dialogs;
  4. public partial class TraceLogViewModel(Hardwares hardwares, DialogService dialogService) : ObservableObject, IDialogAwareTitle
  5. {
  6. public DialogCloseListener RequestClose { get; set; }
  7. public string Title { get; set; } = "";
  8. [ObservableProperty]
  9. private string? _Hint;
  10. [ObservableProperty]
  11. private Visibility _HintVis = Visibility.Collapsed;
  12. [ObservableProperty]
  13. private ObservableCollection<Selector> _Selecters = [];
  14. [ObservableProperty]
  15. private ObservableDictionary<byte, Channel> _Channels = [];
  16. [ObservableProperty]
  17. private ObservableDictionary<string, RealtimeDataPlotHelper> _PlotHelpers = [];
  18. public bool CanCloseDialog()
  19. {
  20. return true;
  21. }
  22. public void OnDialogClosed()
  23. {
  24. foreach (var item in this.PlotHelpers.Values)
  25. item.Dispose();
  26. }
  27. public void OnDialogOpened(IDialogParameters parameters)
  28. {
  29. if (!parameters.TryGetValue("Mini8Info", out Mini8Info? mini8) || mini8 is null)
  30. return;
  31. if (!hardwares.Mini8Channels.TryGetValue(mini8.Index, out ObservableDictionary<byte, Channel>? channels) || channels is null)
  32. return;
  33. this.Channels = channels;
  34. this.Selecters ??= [];
  35. this.PlotHelpers ??= [];
  36. foreach (var channel in channels.Values)
  37. {
  38. this.Selecters.Add(new(channel));
  39. if (channel.Inhibit == Inhibit.Disable)
  40. continue;
  41. RealtimeDataPlotHelper helper = new();
  42. helper.InitPlot(channel);
  43. this.PlotHelpers[channel.Name!] = helper;
  44. }
  45. }
  46. [RelayCommand]
  47. private void EditChannel(Channel channel)
  48. {
  49. DialogParameters para = new()
  50. {
  51. { "Channel", channel },
  52. };
  53. dialogService.Show("Channel", para, null);
  54. }
  55. [RelayCommand]
  56. private void Exit()
  57. {
  58. this.RequestClose.Invoke();
  59. }
  60. }