namespace OINA.Extender.WPF.Testharness
{
using System;
using System.ComponentModel;
using System.Globalization;
using System.Windows;
using OINA.Extender.DetectorControl;
///
/// Interaction logic for DetectorControlPanel.xaml
///
public partial class DetectorControlPanel : Window
{
///
/// IEdDetectorControl object
///
private IEdDetectorControl currentDetector;
///
/// Detector Control Panel constructor
///
/// current detector
public DetectorControlPanel(IEdDetectorControl currentDetector)
{
this.InitializeComponent();
if (currentDetector != null)
{
this.currentDetector = currentDetector;
this.currentDetector.ThermalControl.StatusChanged += this.ThermalControl_StatusChanged;
this.currentDetector.OverloadControl.StatusChanged += this.OverloadControl_StatusChanged;
if (this.currentDetector.ShutterControl != null)
{
this.currentDetector.ShutterControl.StatusChanged += this.ShutterControl_StatusChanged;
this.UpdateShutterStatusText();
this.shutterControlGroup.Visibility = Visibility.Visible;
}
else
{
this.shutterControlGroup.Visibility = Visibility.Collapsed;
}
this.currentDetector.SlideControl.StatusChanged += this.SlideControl_StatusChanged;
this.UpdateDetectorStatusText();
this.UpdateOverloadStatusText();
this.UpdateSlideStatusText();
this.UpdateThermalStatusText();
this.tbDelayValue.Text = this.currentDetector.OverloadControl.Status.OverloadDelay.ToString(@"F2", CultureInfo.CurrentCulture);
this.tbThresholdValue.Text = this.currentDetector.OverloadControl.Status.OverloadThreshold.ToString(@"F2", CultureInfo.CurrentCulture);
}
}
#region Event Handlers
///
/// OnThermalControlStatusChanged
///
/// sender object
/// EventArgs
private void ThermalControl_StatusChanged(object sender, EventArgs e)
{
this.Dispatcher.BeginInvoke((Action)this.UpdateThermalStatusText);
}
///
/// OnOverloadControlStatusChanged
///
/// sender object
/// EventArgs
private void OverloadControl_StatusChanged(object sender, EventArgs e)
{
this.Dispatcher.BeginInvoke((Action)this.UpdateOverloadStatusText);
}
///
/// OnShutterControlStatusChanged
///
/// sender object
/// EventArgs
private void ShutterControl_StatusChanged(object sender, EventArgs e)
{
this.Dispatcher.BeginInvoke((Action)this.UpdateShutterStatusText);
}
///
/// OnSlideControlStatusChanged
///
/// sender object
/// EventArgs
private void SlideControl_StatusChanged(object sender, EventArgs e)
{
this.Dispatcher.BeginInvoke((Action)this.UpdateSlideStatusText);
}
#endregion
#region Update UI content
///
/// UpdateDetectorStatusText Method
/// Gets and updates the UI with the detector status information
///
private void UpdateDetectorStatusText()
{
this.lbDetectorStatus.Content = this.currentDetector.DetectorStatus.IsDetectorReady.ToString(CultureInfo.CurrentCulture);
this.tbDetectorDescription.Text = this.currentDetector.DetectorStatus.StatusDescription;
}
///
/// UpdatePositionText Method
/// Gets and updates the UI with the detectors slide status.
///
private void UpdateSlideStatusText()
{
switch (this.currentDetector.SlideControl.Status.PositionState)
{
case DetectorSlidePositionState.In:
this.lbSlidePosition.Content = @"Fully Inserted";
break;
case DetectorSlidePositionState.Out:
this.lbSlidePosition.Content = @"Fully Retracted";
break;
case DetectorSlidePositionState.Indeterminate:
this.lbSlidePosition.Content = @"Indeterminate Position";
break;
default:
this.lbSlidePosition.Content = @"Unknown";
break;
}
switch (this.currentDetector.SlideControl.Status.Activity)
{
case DetectorSlideActivity.NotMoving:
this.lbSlideActivity.Content = @"Not Moving";
break;
case DetectorSlideActivity.MovingIn:
this.lbSlideActivity.Content = @"Moving In";
break;
case DetectorSlideActivity.MovingOut:
this.lbSlideActivity.Content = @"Moving Out";
break;
case DetectorSlideActivity.AutoRetracting:
this.lbSlideActivity.Content = @"Auto Retracting";
break;
default:
this.lbSlideActivity.Content = @"Unknown";
break;
}
this.UpdateDetectorStatusText();
}
///
/// UpdateShutterStatusText Method
/// Gets and updates the UI with the detectors shutter status.
///
private void UpdateShutterStatusText()
{
if (this.currentDetector.ShutterControl.Status.Enabled)
{
switch (this.currentDetector.ShutterControl.Status.State)
{
case DetectorShutterState.Closed:
this.lbShutterStatus.Content = @"Closed";
break;
case DetectorShutterState.Open:
this.lbShutterStatus.Content = @"Open";
break;
case DetectorShutterState.Fault:
this.lbShutterStatus.Content = @"Fault";
break;
case DetectorShutterState.ClosedDueToOverload:
this.lbShutterStatus.Content = @"Closed due to overload";
break;
default:
this.lbShutterStatus.Content = @"Unknown";
break;
}
}
this.UpdateDetectorStatusText();
}
///
/// UpdateOverloadStatusText Method
/// Gets and updates the UI with the detectors overload status.
///
private void UpdateOverloadStatusText()
{
if (this.currentDetector.OverloadControl.Status.OverloadDetectionEnabled)
{
this.lbOverloadProtection.Content = @"Enabled";
}
else
{
this.lbOverloadProtection.Content = @"Disabled";
}
this.lbOverloadDelay.Content = this.currentDetector.OverloadControl.Status.OverloadDelay.ToString(@"F2", CultureInfo.CurrentCulture);
this.lbOverloadThreshold.Content = this.currentDetector.OverloadControl.Status.OverloadThreshold.ToString(@"F2", CultureInfo.CurrentCulture);
switch (this.currentDetector.OverloadControl.Status.LowMagInterlock)
{
case LowMagInterlock.Enabled:
this.lbInterlockStatus.Content = @"Enabled";
break;
case LowMagInterlock.Disabled:
this.lbInterlockStatus.Content = @"Disabled";
break;
case LowMagInterlock.Unknown:
default:
this.lbInterlockStatus.Content = @"Unknown";
break;
}
this.UpdateDetectorStatusText();
}
///
/// UpdateOperatingStatusText Method
/// Gets and updates the UI with the detectors Thermal status.
///
private void UpdateThermalStatusText()
{
this.lbOperatingStatus.Content = this.currentDetector.ThermalControl.Status.OperatingState.ToString();
this.UpdateDetectorStatusText();
}
#endregion
#region Control Detector from UI
///
/// In button click handler
///
/// sender object
/// RoutedEventArgs
private void MoveIn(object sender, RoutedEventArgs e)
{
if (this.currentDetector.SlideControl.CanDriveIn())
{
this.currentDetector.SlideControl.DriveIn();
}
}
///
/// Out button click handler
///
/// sender object
/// RoutedEventArgs
private void MoveOut(object sender, RoutedEventArgs e)
{
if (this.currentDetector.SlideControl.CanDriveOut())
{
this.currentDetector.SlideControl.DriveOut();
}
}
///
/// Stop button click handler
///
/// sender object
/// RoutedEventArgs
private void MoveStop(object sender, RoutedEventArgs e)
{
if (this.currentDetector.SlideControl.CanStop())
{
this.currentDetector.SlideControl.Stop();
}
}
///
/// Operate button click handler
///
/// sender object
/// RoutedEventArgs
private void Operate_Click(object sender, RoutedEventArgs e)
{
if (this.currentDetector.ThermalControl.CanEnterAutomaticMode())
{
this.currentDetector.ThermalControl.EnterAutomaticMode();
}
}
///
/// Standby button click handler
///
/// sender object
/// RoutedEventArgs
private void Standby_Click(object sender, RoutedEventArgs e)
{
if (this.currentDetector.ThermalControl.CanEnterStandbyMode())
{
this.currentDetector.ThermalControl.EnterStandbyMode();
}
}
///
/// Open button click handler
///
/// sender object
/// RoutedEventArgs
private void Open_Click(object sender, RoutedEventArgs e)
{
if (this.currentDetector.ShutterControl.CanOpenShutter())
{
this.currentDetector.ShutterControl.OpenShutter();
}
}
///
/// Close button click handler
///
/// sender object
/// RoutedEventArgs
private void Close_Click(object sender, RoutedEventArgs e)
{
if (this.currentDetector.ShutterControl.CanCloseShutter())
{
this.currentDetector.ShutterControl.CloseShutter();
}
}
///
/// Toggle Overload Protection button click handler
///
/// sender object
/// RoutedEventArgs
private void ToggleOverloadProtection_Click(object sender, RoutedEventArgs e)
{
if (this.currentDetector.OverloadControl.CanToggleOverloadDetection())
{
if (!this.currentDetector.OverloadControl.Status.OverloadDetectionEnabled)
{
this.currentDetector.OverloadControl.ToggleOverloadDetection(true);
}
else
{
this.currentDetector.OverloadControl.ToggleOverloadDetection(false);
}
}
this.UpdateOverloadStatusText();
}
///
/// Set Overload Value button click handler
///
/// sender object
/// RoutedEventArgs
private void SetOverloadValue_Click(object sender, RoutedEventArgs e)
{
float delay = float.Parse(this.tbDelayValue.Text, CultureInfo.CurrentCulture);
float threshold = float.Parse(this.tbThresholdValue.Text, CultureInfo.CurrentCulture);
if (this.currentDetector.OverloadControl.CanSetOverloadDelay(delay))
{
this.currentDetector.OverloadControl.SetOverloadDelay(delay);
}
if (this.currentDetector.OverloadControl.CanSetOverloadThreshold(threshold))
{
this.currentDetector.OverloadControl.SetOverloadThreshold(threshold);
}
this.UpdateOverloadStatusText();
}
#endregion
///
/// Raises the event.
///
/// A that contains the event data.
protected override void OnClosing(CancelEventArgs e)
{
IEdDetectorControl detector = this.currentDetector;
if (detector != null)
{
// Un-hook events!
detector.ThermalControl.StatusChanged -= this.ThermalControl_StatusChanged;
detector.OverloadControl.StatusChanged -= this.OverloadControl_StatusChanged;
if (detector.ShutterControl != null)
{
detector.ShutterControl.StatusChanged -= this.ShutterControl_StatusChanged;
}
detector.SlideControl.StatusChanged -= this.SlideControl_StatusChanged;
}
base.OnClosing(e);
}
}
}