FoupTopView.xaml.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. using System.ComponentModel;
  2. using System.Runtime.CompilerServices;
  3. using System.Windows;
  4. using System.Windows.Controls;
  5. using System.Windows.Media;
  6. using MECF.Framework.Common.CommonData;
  7. using MECF.Framework.Common.OperationCenter;
  8. namespace VirgoUI.Client.Controls.Parts
  9. {
  10. /// <summary>
  11. /// Door.xaml 的交互逻辑
  12. /// </summary>
  13. public partial class FoupTopView : UserControl, INotifyPropertyChanged
  14. {
  15. public double CanvasYPosition { get; set; }
  16. public bool _isFoupLoaded;
  17. public bool IsFoupLoaded
  18. {
  19. get { return (bool)GetValue(IsFoupLoadedProperty); }
  20. set
  21. {
  22. SetValue(IsFoupLoadedProperty, value);
  23. CanvasYPosition = value ? -20 : 10;
  24. OnPropertyChanged(nameof(CanvasYPosition));
  25. }
  26. }
  27. public static readonly DependencyProperty IsFoupLoadedProperty =
  28. DependencyProperty.Register("IsFoupLoaded", typeof(bool), typeof(FoupTopView),
  29. new PropertyMetadata(false, PropertyChangedCallback));
  30. public string ModuleName
  31. {
  32. get { return (string)GetValue(ModuleNameProperty); }
  33. set { SetValue(ModuleNameProperty, value); }
  34. }
  35. public static readonly DependencyProperty ModuleNameProperty =
  36. DependencyProperty.Register("ModuleName", typeof(string), typeof(FoupTopView),
  37. new PropertyMetadata("LP1", PropertyChangedCallback));
  38. public Visibility MenuVisibility
  39. {
  40. get { return (Visibility)this.GetValue(MenuVisibilityProperty); }
  41. set { this.SetValue(MenuVisibilityProperty, value); }
  42. }
  43. public static readonly DependencyProperty MenuVisibilityProperty =
  44. DependencyProperty.Register("MenuVisibility", typeof(Visibility), typeof(FoupTopView),
  45. new FrameworkPropertyMetadata(Visibility.Visible, FrameworkPropertyMetadataOptions.AffectsRender));
  46. public LPMenuEnable DeviceData
  47. {
  48. get
  49. {
  50. return (LPMenuEnable)this.GetValue(DeviceDataProperty);
  51. }
  52. set
  53. {
  54. this.SetValue(DeviceDataProperty, value);
  55. }
  56. }
  57. public static readonly DependencyProperty DeviceDataProperty = DependencyProperty.Register(
  58. "DeviceData", typeof(LPMenuEnable), typeof(FoupTopView),
  59. new FrameworkPropertyMetadata(new LPMenuEnable(), FrameworkPropertyMetadataOptions.AffectsRender));
  60. public FoupTopView()
  61. {
  62. InitializeComponent();
  63. }
  64. public event PropertyChangedEventHandler PropertyChanged;
  65. //[NotifyPropertyChangedInvocator]
  66. protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
  67. {
  68. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  69. }
  70. static void PropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
  71. {
  72. var self = (FoupTopView)d;
  73. switch (e.Property.Name)
  74. {
  75. case "IsFoupLoaded":
  76. self.CanvasYPosition = (bool)e.NewValue ? -30 : 0;
  77. self.OnPropertyChanged(nameof(CanvasYPosition));
  78. break;
  79. default:
  80. self.OnPropertyChanged(nameof(e.Property.Name));
  81. break;
  82. }
  83. }
  84. protected override void OnRender(DrawingContext drawingContext)
  85. {
  86. base.OnRender(drawingContext);
  87. canvas.ContextMenu.Visibility = MenuVisibility;
  88. if (DeviceData == null)
  89. return;
  90. if (MenuVisibility == Visibility.Visible && canvas.ContextMenu.Items != null && canvas.ContextMenu.Items.Count == 13)
  91. {
  92. ((MenuItem)canvas.ContextMenu.Items[1]).IsEnabled = DeviceData.IsResetEnable;
  93. ((MenuItem)canvas.ContextMenu.Items[2]).IsEnabled = DeviceData.IsAbortEnable;
  94. ((MenuItem)canvas.ContextMenu.Items[3]).IsEnabled = DeviceData.IsLoadEnable;
  95. ((MenuItem)canvas.ContextMenu.Items[4]).IsEnabled = DeviceData.IsUnloadEnable;
  96. ((MenuItem)canvas.ContextMenu.Items[5]).IsEnabled = DeviceData.IsReadCarrierIDEnable;
  97. ((MenuItem)canvas.ContextMenu.Items[6]).IsEnabled = DeviceData.IsClampEnable;
  98. ((MenuItem)canvas.ContextMenu.Items[7]).IsEnabled = DeviceData.IsUnclampEnable;
  99. ((MenuItem)canvas.ContextMenu.Items[8]).IsEnabled = DeviceData.IsDockEnable;
  100. ((MenuItem)canvas.ContextMenu.Items[9]).IsEnabled = DeviceData.IsUndockEnable;
  101. ((MenuItem)canvas.ContextMenu.Items[10]).IsEnabled = DeviceData.IsOpenEnable;
  102. ((MenuItem)canvas.ContextMenu.Items[11]).IsEnabled = DeviceData.IsCloseEnable;
  103. ((MenuItem)canvas.ContextMenu.Items[12]).IsEnabled = DeviceData.IsMapEnable;
  104. }
  105. }
  106. private void Home(object sender, RoutedEventArgs e)
  107. {
  108. InvokeClient.Instance.Service.DoOperation($"{ModuleName}.Home");
  109. }
  110. private void Reset(object sender, RoutedEventArgs e)
  111. {
  112. InvokeClient.Instance.Service.DoOperation($"{ModuleName}.Reset");
  113. }
  114. private void Abort(object sender, RoutedEventArgs e)
  115. {
  116. InvokeClient.Instance.Service.DoOperation($"{ModuleName}.Abort");
  117. }
  118. private void ReadCarrierID(object sender, RoutedEventArgs e)
  119. {
  120. InvokeClient.Instance.Service.DoOperation($"{ModuleName}.ReadCarrierId");
  121. }
  122. private void Load(object sender, RoutedEventArgs e)
  123. {
  124. InvokeClient.Instance.Service.DoOperation($"{ModuleName}.Load");
  125. }
  126. private void Unload(object sender, RoutedEventArgs e)
  127. {
  128. InvokeClient.Instance.Service.DoOperation($"{ModuleName}.Unload");
  129. }
  130. private void Clamp(object sender, RoutedEventArgs e)
  131. {
  132. InvokeClient.Instance.Service.DoOperation($"{ModuleName}.Clamp");
  133. }
  134. private void Unclamp(object sender, RoutedEventArgs e)
  135. {
  136. InvokeClient.Instance.Service.DoOperation($"{ModuleName}.Unclamp");
  137. }
  138. private void Dock(object sender, RoutedEventArgs e)
  139. {
  140. InvokeClient.Instance.Service.DoOperation($"{ModuleName}.Dock");
  141. }
  142. private void Undock(object sender, RoutedEventArgs e)
  143. {
  144. InvokeClient.Instance.Service.DoOperation($"{ModuleName}.Undock");
  145. }
  146. private void OpenDoor(object sender, RoutedEventArgs e)
  147. {
  148. InvokeClient.Instance.Service.DoOperation($"{ModuleName}.OpenDoor");
  149. }
  150. private void CloseDoor(object sender, RoutedEventArgs e)
  151. {
  152. InvokeClient.Instance.Service.DoOperation($"{ModuleName}.CloseDoor");
  153. }
  154. private void Map(object sender, RoutedEventArgs e)
  155. {
  156. InvokeClient.Instance.Service.DoOperation($"{ModuleName}.Map");
  157. }
  158. }
  159. public class LPMenuEnable : NotifiableItem
  160. {
  161. public bool IsResetEnable { get; set; }
  162. public bool IsAbortEnable { get; set; }
  163. public bool IsReadCarrierIDEnable { get; set; }
  164. public bool IsLoadEnable { get; set; }
  165. public bool IsUnloadEnable { get; set; }
  166. public bool IsClampEnable { get; set; }
  167. public bool IsUnclampEnable { get; set; }
  168. public bool IsDockEnable { get; set; }
  169. public bool IsUndockEnable { get; set; }
  170. public bool IsOpenEnable { get; set; }
  171. public bool IsCloseEnable { get; set; }
  172. public bool IsMapEnable { get; set; }
  173. }
  174. }