123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240 |
- namespace OINA.Extender.WPF.Testharness
- {
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Globalization;
- using System.Windows;
- using OINA.Extender;
- using OINA.Extender.MicroscopeControl;
- /// <summary>
- /// Interaction logic for MicroscopeControlPanel.xaml
- /// </summary>
- public partial class MicroscopeControlPanel : Window
- {
- /// <summary>
- /// IMicroscopeController object
- /// </summary>
- private IMicroscopeController microscopeController = null;
- /// <summary>
- /// Interaction logic for MicroscopeControlPanel.xaml
- /// </summary>
- public MicroscopeControlPanel()
- {
- this.InitializeComponent();
- this.microscopeController = AcquireFactory.CreateMicroscopeControl();
- this.microscopeController.ColumnChange += this.MicroscopeController_ColumnChange;
- this.microscopeController.StageChange += this.MicroscopeController_StageChange;
- this.UpdateMicroscopeColumnText();
- this.UpdateMicroscopeStageText();
- }
- #region Event handlers
- /// <summary>
- /// OnMicroscopeColumnChange
- /// </summary>
- /// <param name="sender">sender object</param>
- /// <param name="e">EventArgs</param>
- private void MicroscopeController_ColumnChange(object sender, EventArgs e)
- {
- this.Dispatcher.BeginInvoke((Action)this.UpdateMicroscopeColumnText);
- }
- /// <summary>
- /// OnMicroscopeStageChange
- /// </summary>
- /// <param name="sender">sender object</param>
- /// <param name="e">EventArgs</param>
- private void MicroscopeController_StageChange(object sender, EventArgs e)
- {
- this.Dispatcher.BeginInvoke((Action)this.UpdateMicroscopeStageText);
- }
- #endregion
- #region Update UI content
- /// <summary>
- /// UpdateMicroscopeStageText Method
- /// </summary>
- private void UpdateMicroscopeStageText()
- {
- this.gbStage.Header = @"Stage " + this.microscopeController.StageConnectionStatus.Name;
- if (this.microscopeController.StageCapabilities.StageX.CanRead)
- {
- this.lbX.Content = this.microscopeController.StageConditions.StageX.ToString(@"F2", CultureInfo.CurrentCulture);
- this.tbXvalue.Text = this.microscopeController.StageConditions.StageX.ToString(@"F2", CultureInfo.CurrentCulture);
- }
- if (this.microscopeController.StageCapabilities.StageY.CanRead)
- {
- this.lbY.Content = this.microscopeController.StageConditions.StageY.ToString(@"F2", CultureInfo.CurrentCulture);
- this.tbYvalue.Text = this.microscopeController.StageConditions.StageY.ToString(@"F2", CultureInfo.CurrentCulture);
- }
- if (this.microscopeController.StageCapabilities.StageZ.CanRead)
- {
- this.lbZ.Content = this.microscopeController.StageConditions.StageZ.ToString(@"F2", CultureInfo.CurrentCulture);
- this.tbZvalue.Text = this.microscopeController.StageConditions.StageZ.ToString(@"F2", CultureInfo.CurrentCulture);
- }
- if (this.microscopeController.StageCapabilities.StageT.CanRead)
- {
- this.lbT.Content = this.microscopeController.StageConditions.StageT.ToString(@"F2", CultureInfo.CurrentCulture);
- this.tbTiltvalue.Text = this.microscopeController.StageConditions.StageT.ToString(@"F2", CultureInfo.CurrentCulture);
- }
- if (this.microscopeController.StageCapabilities.StageR.CanRead)
- {
- this.lbR.Content = this.microscopeController.StageConditions.StageR.ToString(@"F2", CultureInfo.CurrentCulture);
- this.tbRotateValue.Text = this.microscopeController.StageConditions.StageR.ToString(@"F2", CultureInfo.CurrentCulture);
- }
- this.lbBacklashStatus.Content = Convert.ToBoolean(this.microscopeController.StageConditions.BacklashOn).ToString(CultureInfo.CurrentCulture);
- }
- /// <summary>
- /// UpdateMicroscopeColumnText Method
- /// </summary>
- private void UpdateMicroscopeColumnText()
- {
- this.gbColumn.Header = @"Column " + this.microscopeController.ColumnConnectionStatus.Name;
- if (this.microscopeController.ColumnCapabilities.Magnification.CanRead)
- {
- this.lbMag.Content = this.microscopeController.ColumnConditions.Magnification.ToString(@"F2", CultureInfo.CurrentCulture);
- this.tbMagValue.Text = this.microscopeController.ColumnConditions.Magnification.ToString(@"F2", CultureInfo.CurrentCulture);
- }
- if (this.microscopeController.ColumnCapabilities.WorkingDistance.CanRead)
- {
- this.lbWd.Content = this.microscopeController.ColumnConditions.WorkingDistance.ToString(@"F2", CultureInfo.CurrentCulture);
- this.tbWorkDistance.Text = this.microscopeController.ColumnConditions.WorkingDistance.ToString(@"F2", CultureInfo.CurrentCulture);
- }
- if (this.microscopeController.ColumnCapabilities.HighVoltage.CanRead)
- {
- this.lbHv.Content = this.microscopeController.ColumnConditions.HighVoltage.ToString(@"F2", CultureInfo.CurrentCulture);
- this.tbHvValue.Text = this.microscopeController.ColumnConditions.HighVoltage.ToString(@"F2", CultureInfo.CurrentCulture);
- }
- if (this.microscopeController.ColumnCapabilities.BeamOn.CanRead)
- {
- this.lbBeamStatus.Content = Convert.ToBoolean(this.microscopeController.ColumnConditions.BeamOn).ToString(CultureInfo.CurrentCulture);
- }
- if (this.microscopeController.ColumnCapabilities.FilamentOn.CanRead)
- {
- this.lbFilamentStatus.Content = Convert.ToBoolean(this.microscopeController.ColumnConditions.FilamentOn).ToString(CultureInfo.CurrentCulture);
- }
- }
- #endregion
- #region Control Microscope from UI
- /// <summary>
- /// Set Stage parameters
- /// </summary>
- /// <param name="sender">sender object</param>
- /// <param name="e">RoutedEventArgs</param>
- private void SetStageParameters(object sender, RoutedEventArgs e)
- {
- Dictionary<Stage, double> stageDictionary = new Dictionary<Stage, double>
- {
- { Stage.StageX, double.Parse(this.tbXvalue.Text, CultureInfo.CurrentCulture) },
- { Stage.StageY, double.Parse(this.tbYvalue.Text, CultureInfo.CurrentCulture) },
- { Stage.StageZ, double.Parse(this.tbZvalue.Text, CultureInfo.CurrentCulture) },
- { Stage.StageT, double.Parse(this.tbTiltvalue.Text, CultureInfo.CurrentCulture) },
- { Stage.StageR, double.Parse(this.tbRotateValue.Text, CultureInfo.CurrentCulture) }
- };
- this.microscopeController.SetStageConditions(stageDictionary);
- }
- /// <summary>
- /// Set Column parameters
- /// </summary>
- /// <param name="sender">sender object</param>
- /// <param name="e">RoutedEventArgs</param>
- private void SetColumnParameters(object sender, RoutedEventArgs e)
- {
- Dictionary<Column, double> columnDictionary = new Dictionary<Column, double>
- {
- { Column.Magnification, double.Parse(this.tbMagValue.Text, CultureInfo.CurrentCulture) },
- { Column.HighVoltage, double.Parse(this.tbHvValue.Text, CultureInfo.CurrentCulture) },
- { Column.WorkingDistance, double.Parse(this.tbWorkDistance.Text, CultureInfo.CurrentCulture) }
- };
- this.microscopeController.SetColumnConditions(columnDictionary);
- }
- /// <summary>
- /// Set Magnification value
- /// </summary>
- /// <param name="sender">sender object</param>
- /// <param name="e">RoutedEventArgs</param>
- private void SetMagButton_Click(object sender, RoutedEventArgs e)
- {
- Dictionary<Column, double> columnDictionary = new Dictionary<Column, double>
- {
- { Column.Magnification, double.Parse(this.tbMagValue.Text, CultureInfo.CurrentCulture) }
- };
- this.microscopeController.SetColumnConditions(columnDictionary);
- }
- /// <summary>
- /// Set Working Distance value
- /// </summary>
- /// <param name="sender">sender object</param>
- /// <param name="e">RoutedEventArgs</param>
- private void SetWdButton_Click(object sender, RoutedEventArgs e)
- {
- Dictionary<Column, double> columnDictionary = new Dictionary<Column, double>
- {
- { Column.WorkingDistance, double.Parse(this.tbWorkDistance.Text, CultureInfo.CurrentCulture) }
- };
- this.microscopeController.SetColumnConditions(columnDictionary);
- }
- /// <summary>
- /// Set High Voltage value
- /// </summary>
- /// <param name="sender">sender object</param>
- /// <param name="e">RoutedEventArgs</param>
- private void SetHvButton_Click(object sender, RoutedEventArgs e)
- {
- Dictionary<Column, double> columnDictionary = new Dictionary<Column, double>
- {
- { Column.HighVoltage, double.Parse(this.tbHvValue.Text, CultureInfo.CurrentCulture) }
- };
- this.microscopeController.SetColumnConditions(columnDictionary);
- }
- #endregion
- /// <summary>
- /// Raises the <see cref="E:System.Windows.Window.Closing" /> event.
- /// </summary>
- /// <param name="e">A <see cref="T:System.ComponentModel.CancelEventArgs" /> that contains the event data.</param>
- protected override void OnClosing(CancelEventArgs e)
- {
- IMicroscopeController currentMicroscopeController = this.microscopeController;
- if (currentMicroscopeController != null)
- {
- // Un-hook events.
- currentMicroscopeController.ColumnChange -= this.MicroscopeController_ColumnChange;
- currentMicroscopeController.StageChange -= this.MicroscopeController_StageChange;
- }
- base.OnClosing(e);
- }
- }
- }
|