MicroscopeControlPanel.xaml.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. namespace OINA.Extender.WPF.Testharness
  2. {
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Globalization;
  7. using System.Windows;
  8. using OINA.Extender;
  9. using OINA.Extender.MicroscopeControl;
  10. /// <summary>
  11. /// Interaction logic for MicroscopeControlPanel.xaml
  12. /// </summary>
  13. public partial class MicroscopeControlPanel : Window
  14. {
  15. /// <summary>
  16. /// IMicroscopeController object
  17. /// </summary>
  18. private IMicroscopeController microscopeController = null;
  19. /// <summary>
  20. /// Interaction logic for MicroscopeControlPanel.xaml
  21. /// </summary>
  22. public MicroscopeControlPanel()
  23. {
  24. this.InitializeComponent();
  25. this.microscopeController = AcquireFactory.CreateMicroscopeControl();
  26. this.microscopeController.ColumnChange += this.MicroscopeController_ColumnChange;
  27. this.microscopeController.StageChange += this.MicroscopeController_StageChange;
  28. this.UpdateMicroscopeColumnText();
  29. this.UpdateMicroscopeStageText();
  30. }
  31. #region Event handlers
  32. /// <summary>
  33. /// OnMicroscopeColumnChange
  34. /// </summary>
  35. /// <param name="sender">sender object</param>
  36. /// <param name="e">EventArgs</param>
  37. private void MicroscopeController_ColumnChange(object sender, EventArgs e)
  38. {
  39. this.Dispatcher.BeginInvoke((Action)this.UpdateMicroscopeColumnText);
  40. }
  41. /// <summary>
  42. /// OnMicroscopeStageChange
  43. /// </summary>
  44. /// <param name="sender">sender object</param>
  45. /// <param name="e">EventArgs</param>
  46. private void MicroscopeController_StageChange(object sender, EventArgs e)
  47. {
  48. this.Dispatcher.BeginInvoke((Action)this.UpdateMicroscopeStageText);
  49. }
  50. #endregion
  51. #region Update UI content
  52. /// <summary>
  53. /// UpdateMicroscopeStageText Method
  54. /// </summary>
  55. private void UpdateMicroscopeStageText()
  56. {
  57. this.gbStage.Header = @"Stage " + this.microscopeController.StageConnectionStatus.Name;
  58. if (this.microscopeController.StageCapabilities.StageX.CanRead)
  59. {
  60. this.lbX.Content = this.microscopeController.StageConditions.StageX.ToString(@"F2", CultureInfo.CurrentCulture);
  61. this.tbXvalue.Text = this.microscopeController.StageConditions.StageX.ToString(@"F2", CultureInfo.CurrentCulture);
  62. }
  63. if (this.microscopeController.StageCapabilities.StageY.CanRead)
  64. {
  65. this.lbY.Content = this.microscopeController.StageConditions.StageY.ToString(@"F2", CultureInfo.CurrentCulture);
  66. this.tbYvalue.Text = this.microscopeController.StageConditions.StageY.ToString(@"F2", CultureInfo.CurrentCulture);
  67. }
  68. if (this.microscopeController.StageCapabilities.StageZ.CanRead)
  69. {
  70. this.lbZ.Content = this.microscopeController.StageConditions.StageZ.ToString(@"F2", CultureInfo.CurrentCulture);
  71. this.tbZvalue.Text = this.microscopeController.StageConditions.StageZ.ToString(@"F2", CultureInfo.CurrentCulture);
  72. }
  73. if (this.microscopeController.StageCapabilities.StageT.CanRead)
  74. {
  75. this.lbT.Content = this.microscopeController.StageConditions.StageT.ToString(@"F2", CultureInfo.CurrentCulture);
  76. this.tbTiltvalue.Text = this.microscopeController.StageConditions.StageT.ToString(@"F2", CultureInfo.CurrentCulture);
  77. }
  78. if (this.microscopeController.StageCapabilities.StageR.CanRead)
  79. {
  80. this.lbR.Content = this.microscopeController.StageConditions.StageR.ToString(@"F2", CultureInfo.CurrentCulture);
  81. this.tbRotateValue.Text = this.microscopeController.StageConditions.StageR.ToString(@"F2", CultureInfo.CurrentCulture);
  82. }
  83. this.lbBacklashStatus.Content = Convert.ToBoolean(this.microscopeController.StageConditions.BacklashOn).ToString(CultureInfo.CurrentCulture);
  84. }
  85. /// <summary>
  86. /// UpdateMicroscopeColumnText Method
  87. /// </summary>
  88. private void UpdateMicroscopeColumnText()
  89. {
  90. this.gbColumn.Header = @"Column " + this.microscopeController.ColumnConnectionStatus.Name;
  91. if (this.microscopeController.ColumnCapabilities.Magnification.CanRead)
  92. {
  93. this.lbMag.Content = this.microscopeController.ColumnConditions.Magnification.ToString(@"F2", CultureInfo.CurrentCulture);
  94. this.tbMagValue.Text = this.microscopeController.ColumnConditions.Magnification.ToString(@"F2", CultureInfo.CurrentCulture);
  95. }
  96. if (this.microscopeController.ColumnCapabilities.WorkingDistance.CanRead)
  97. {
  98. this.lbWd.Content = this.microscopeController.ColumnConditions.WorkingDistance.ToString(@"F2", CultureInfo.CurrentCulture);
  99. this.tbWorkDistance.Text = this.microscopeController.ColumnConditions.WorkingDistance.ToString(@"F2", CultureInfo.CurrentCulture);
  100. }
  101. if (this.microscopeController.ColumnCapabilities.HighVoltage.CanRead)
  102. {
  103. this.lbHv.Content = this.microscopeController.ColumnConditions.HighVoltage.ToString(@"F2", CultureInfo.CurrentCulture);
  104. this.tbHvValue.Text = this.microscopeController.ColumnConditions.HighVoltage.ToString(@"F2", CultureInfo.CurrentCulture);
  105. }
  106. if (this.microscopeController.ColumnCapabilities.BeamOn.CanRead)
  107. {
  108. this.lbBeamStatus.Content = Convert.ToBoolean(this.microscopeController.ColumnConditions.BeamOn).ToString(CultureInfo.CurrentCulture);
  109. }
  110. if (this.microscopeController.ColumnCapabilities.FilamentOn.CanRead)
  111. {
  112. this.lbFilamentStatus.Content = Convert.ToBoolean(this.microscopeController.ColumnConditions.FilamentOn).ToString(CultureInfo.CurrentCulture);
  113. }
  114. }
  115. #endregion
  116. #region Control Microscope from UI
  117. /// <summary>
  118. /// Set Stage parameters
  119. /// </summary>
  120. /// <param name="sender">sender object</param>
  121. /// <param name="e">RoutedEventArgs</param>
  122. private void SetStageParameters(object sender, RoutedEventArgs e)
  123. {
  124. Dictionary<Stage, double> stageDictionary = new Dictionary<Stage, double>
  125. {
  126. { Stage.StageX, double.Parse(this.tbXvalue.Text, CultureInfo.CurrentCulture) },
  127. { Stage.StageY, double.Parse(this.tbYvalue.Text, CultureInfo.CurrentCulture) },
  128. { Stage.StageZ, double.Parse(this.tbZvalue.Text, CultureInfo.CurrentCulture) },
  129. { Stage.StageT, double.Parse(this.tbTiltvalue.Text, CultureInfo.CurrentCulture) },
  130. { Stage.StageR, double.Parse(this.tbRotateValue.Text, CultureInfo.CurrentCulture) }
  131. };
  132. this.microscopeController.SetStageConditions(stageDictionary);
  133. }
  134. /// <summary>
  135. /// Set Column parameters
  136. /// </summary>
  137. /// <param name="sender">sender object</param>
  138. /// <param name="e">RoutedEventArgs</param>
  139. private void SetColumnParameters(object sender, RoutedEventArgs e)
  140. {
  141. Dictionary<Column, double> columnDictionary = new Dictionary<Column, double>
  142. {
  143. { Column.Magnification, double.Parse(this.tbMagValue.Text, CultureInfo.CurrentCulture) },
  144. { Column.HighVoltage, double.Parse(this.tbHvValue.Text, CultureInfo.CurrentCulture) },
  145. { Column.WorkingDistance, double.Parse(this.tbWorkDistance.Text, CultureInfo.CurrentCulture) }
  146. };
  147. this.microscopeController.SetColumnConditions(columnDictionary);
  148. }
  149. /// <summary>
  150. /// Set Magnification value
  151. /// </summary>
  152. /// <param name="sender">sender object</param>
  153. /// <param name="e">RoutedEventArgs</param>
  154. private void SetMagButton_Click(object sender, RoutedEventArgs e)
  155. {
  156. Dictionary<Column, double> columnDictionary = new Dictionary<Column, double>
  157. {
  158. { Column.Magnification, double.Parse(this.tbMagValue.Text, CultureInfo.CurrentCulture) }
  159. };
  160. this.microscopeController.SetColumnConditions(columnDictionary);
  161. }
  162. /// <summary>
  163. /// Set Working Distance value
  164. /// </summary>
  165. /// <param name="sender">sender object</param>
  166. /// <param name="e">RoutedEventArgs</param>
  167. private void SetWdButton_Click(object sender, RoutedEventArgs e)
  168. {
  169. Dictionary<Column, double> columnDictionary = new Dictionary<Column, double>
  170. {
  171. { Column.WorkingDistance, double.Parse(this.tbWorkDistance.Text, CultureInfo.CurrentCulture) }
  172. };
  173. this.microscopeController.SetColumnConditions(columnDictionary);
  174. }
  175. /// <summary>
  176. /// Set High Voltage value
  177. /// </summary>
  178. /// <param name="sender">sender object</param>
  179. /// <param name="e">RoutedEventArgs</param>
  180. private void SetHvButton_Click(object sender, RoutedEventArgs e)
  181. {
  182. Dictionary<Column, double> columnDictionary = new Dictionary<Column, double>
  183. {
  184. { Column.HighVoltage, double.Parse(this.tbHvValue.Text, CultureInfo.CurrentCulture) }
  185. };
  186. this.microscopeController.SetColumnConditions(columnDictionary);
  187. }
  188. #endregion
  189. /// <summary>
  190. /// Raises the <see cref="E:System.Windows.Window.Closing" /> event.
  191. /// </summary>
  192. /// <param name="e">A <see cref="T:System.ComponentModel.CancelEventArgs" /> that contains the event data.</param>
  193. protected override void OnClosing(CancelEventArgs e)
  194. {
  195. IMicroscopeController currentMicroscopeController = this.microscopeController;
  196. if (currentMicroscopeController != null)
  197. {
  198. // Un-hook events.
  199. currentMicroscopeController.ColumnChange -= this.MicroscopeController_ColumnChange;
  200. currentMicroscopeController.StageChange -= this.MicroscopeController_StageChange;
  201. }
  202. base.OnClosing(e);
  203. }
  204. }
  205. }