VisionSolutionViewModel.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. using Prism.Commands;
  2. using Prism.Ioc;
  3. using Prism.Mvvm;
  4. using Prism.Regions;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Windows.Media;
  9. using Team.FFFeederService;
  10. using Team.FFFeederService.Interfaces;
  11. using TeamAAS_VP.Controls;
  12. using TeamAAS_VP.Core;
  13. using TeamAAS_VP.Interfaces;
  14. namespace TeamAAS_VP.ViewModels.DebugMod
  15. {
  16. public class VisionSolutionViewModel : BindableBase, IConfirmNavigationRequest
  17. {
  18. IContainerProvider _container;
  19. ISystemDatabaseService _systemDatabaseService;
  20. private ImageSource _CurrentImage;
  21. public ImageSource CurrentImage
  22. {
  23. get { return _CurrentImage; }
  24. set { SetProperty(ref _CurrentImage, value); }
  25. }
  26. private FocusAnalyzerViewModel _FocusAnalyzerViewModel;
  27. public FocusAnalyzerViewModel FocusAnalyzerViewModel
  28. {
  29. get { return _FocusAnalyzerViewModel; }
  30. set { SetProperty(ref _FocusAnalyzerViewModel, value); }
  31. }
  32. //选择图片
  33. private DelegateCommand _SelectImageCommand;
  34. public DelegateCommand SelectImageCommand =>
  35. _SelectImageCommand ?? (_SelectImageCommand = new DelegateCommand(ExecuteSelectImageCommand));
  36. private DelegateCommand _LoadedCommand;
  37. public DelegateCommand LoadedCommand =>
  38. _LoadedCommand ?? (_LoadedCommand = new DelegateCommand(ExecuteLoadedCommand));
  39. public VisionSolutionViewModel(IContainerProvider container, ISystemDatabaseService systemDatabaseService)
  40. {
  41. _container = container;
  42. _systemDatabaseService = systemDatabaseService;
  43. }
  44. void ExecuteLoadedCommand()
  45. {
  46. try
  47. {
  48. if (_systemDatabaseService.GetCurrentUser().userPart == Enums.UserPart.Operator)
  49. {
  50. IsAllowEdit = false;
  51. }
  52. else
  53. {
  54. IsAllowEdit = true;
  55. }
  56. }
  57. catch (Exception)
  58. {
  59. }
  60. }
  61. /// <summary>
  62. /// 选择一张图像
  63. /// </summary>
  64. void ExecuteSelectImageCommand()
  65. {
  66. //打开文件对话框,选择一张图片
  67. Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog();
  68. openFileDialog.Filter = "Image files (*.png;*.jpg;*.jpeg;*.bmp)|*.png;*.jpg;*.jpeg;*.bmp|All files (*.*)|*.*";
  69. openFileDialog.Multiselect = true;
  70. bool? result = openFileDialog.ShowDialog();
  71. if (result.HasValue)
  72. {
  73. if (openFileDialog.FileNames.Length > 0)
  74. {
  75. //加载第一张图片
  76. string filePath = openFileDialog.FileNames[0];
  77. try
  78. {
  79. System.Windows.Media.Imaging.BitmapImage bitmap = new System.Windows.Media.Imaging.BitmapImage();
  80. bitmap.BeginInit();
  81. bitmap.UriSource = new Uri(filePath, UriKind.Absolute);
  82. bitmap.CacheOption = System.Windows.Media.Imaging.BitmapCacheOption.OnLoad;
  83. bitmap.EndInit();
  84. FocusAnalyzerViewModel.CurrentImage = bitmap;
  85. }
  86. catch (Exception ex)
  87. {
  88. //显示错误信息
  89. System.Windows.MessageBox.Show("加载图片失败:" + ex.Message);
  90. }
  91. }
  92. }
  93. }
  94. #region 继承
  95. /// <summary>
  96. /// 确认导航请求时调用。此方法允许您在导航之前执行一些操作。
  97. /// </summary>
  98. /// <param name="navigationContext"></param>
  99. /// <param name="continuationCallback"></param>
  100. public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)
  101. {
  102. continuationCallback(true);
  103. }
  104. /// <summary>
  105. /// 接收导航请求时调用。传入导航参数,包含有关导航目标的信息。
  106. /// </summary>
  107. /// <param name="navigationContext"></param>
  108. /// <exception cref="NotImplementedException"></exception>
  109. public async void OnNavigatedTo(NavigationContext navigationContext)
  110. {
  111. if (FocusAnalyzerViewModel==null)
  112. {
  113. FocusAnalyzerViewModel = new FocusAnalyzerViewModel();
  114. }
  115. }
  116. /// <summary>
  117. /// 是否允许导航到此视图模型。
  118. /// </summary>
  119. /// <param name="navigationContext"></param>
  120. /// <returns></returns>
  121. public bool IsNavigationTarget(NavigationContext navigationContext)
  122. {
  123. return true;
  124. }
  125. /// <summary>
  126. /// 导航离开此视图模型时调用。您可以在此处执行清理操作或保存状态。
  127. /// </summary>
  128. /// <param name="navigationContext"></param>
  129. public void OnNavigatedFrom(NavigationContext navigationContext)
  130. {
  131. }
  132. #endregion
  133. private bool _IsAllowEdit = false;
  134. public bool IsAllowEdit
  135. {
  136. get { return _IsAllowEdit; }
  137. set { SetProperty(ref _IsAllowEdit, value); }
  138. }
  139. private void LoginChange(Models.User user)
  140. {
  141. if (user.userPart == Enums.UserPart.Operator)
  142. {
  143. IsAllowEdit = false;
  144. }
  145. else
  146. {
  147. IsAllowEdit = true;
  148. }
  149. }
  150. }
  151. }