TraceLogViewModel.cs 1.9 KB

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