namespace OINA.Extender.Testharness
{
using System;
using System.Globalization;
using System.Windows.Forms;
using OINA.Extender.DetectorControl;
///
/// Detector Control Panel Form
///
public partial class DetectorControlPanel : Form
{
///
/// IEdDetectorControl object
///
private IEdDetectorControl currentDetector = null;
///
/// Detector Control Panel constructor
///
/// current detector
public DetectorControlPanel(IEdDetectorControl currentDetector)
{
this.InitializeComponent();
if (currentDetector != null)
{
this.currentDetector = currentDetector;
// Hook up detector controller status events
this.currentDetector.SlideControl.StatusChanged += this.OnDetectorSlideStatusChanged;
this.currentDetector.ThermalControl.StatusChanged += this.OnDetectorOperatingStatusChanged;
this.currentDetector.ShutterControl.StatusChanged += this.OnDetectorShutterStatusChanged;
this.currentDetector.OverloadControl.StatusChanged += this.OnDetectorOverloadStatusChanged;
// Initial UI contents
this.UpdateDetectorStatusText();
this.UpdateSlideStatusText();
this.UpdateThermalStatusText();
this.UpdateShutterStatusText();
this.UpdateOverloadStatusText();
this.tbDelay.Text = this.currentDetector.OverloadControl.Status.OverloadDelay.ToString(@"F2", CultureInfo.InvariantCulture);
this.tbThreshold.Text = this.currentDetector.OverloadControl.Status.OverloadThreshold.ToString(@"F2", CultureInfo.InvariantCulture);
}
}
#region Event handlers
///
/// OnDetectorOverloadStatusChanged
///
/// sender object
/// EventArgs
private void OnDetectorOverloadStatusChanged(object sender, EventArgs e)
{
this.BeginInvoke((Action)this.UpdateOverloadStatusText);
}
///
/// OnDetectorShutterStatusChanged
///
/// sender object
/// EventArgs
private void OnDetectorShutterStatusChanged(object sender, EventArgs e)
{
this.BeginInvoke((Action)this.UpdateShutterStatusText);
}
///
/// OnDetectorOperatingStatusChanged
///
/// sender object
/// EventArgs
private void OnDetectorOperatingStatusChanged(object sender, EventArgs e)
{
this.BeginInvoke((Action)this.UpdateThermalStatusText);
}
///
/// OnDetectorSlideStatusChanged
///
/// sender object
/// EventArgs
private void OnDetectorSlideStatusChanged(object sender, EventArgs e)
{
this.BeginInvoke((Action)this.UpdateSlideStatusText);
}
#endregion
#region Get detector status and Update the UI
///
/// UpdateDetectorStatusText Method
/// Gets and updates the UI with the detector status information
///
private void UpdateDetectorStatusText()
{
this.textDetectorIsReady.Text = this.currentDetector.DetectorStatus.IsDetectorReady.ToString(CultureInfo.InvariantCulture);
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.textPositionStatus.Text = @"Fully Inserted";
break;
case DetectorSlidePositionState.Out:
this.textPositionStatus.Text = @"Fully Retracted";
break;
case DetectorSlidePositionState.Indeterminate:
this.textPositionStatus.Text = @"Indeterminate Position";
break;
default:
this.textPositionStatus.Text = @"Unknown";
break;
}
switch (this.currentDetector.SlideControl.Status.Activity)
{
case DetectorSlideActivity.NotMoving:
this.textActivityStatus.Text = @"Not Moving";
break;
case DetectorSlideActivity.MovingIn:
this.textActivityStatus.Text = @"Moving In";
break;
case DetectorSlideActivity.MovingOut:
this.textActivityStatus.Text = @"Moving Out";
break;
case DetectorSlideActivity.AutoRetracting:
this.textActivityStatus.Text = @"Auto Retracting";
break;
default:
this.textActivityStatus.Text = @"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.textShutterStatus.Text = @"Closed";
break;
case DetectorShutterState.Open:
this.textShutterStatus.Text = @"Open";
break;
case DetectorShutterState.Fault:
this.textShutterStatus.Text = @"Fault";
break;
case DetectorShutterState.ClosedDueToOverload:
this.textShutterStatus.Text = @"Closed due to overload";
break;
default:
this.textShutterStatus.Text = @"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.textOverloadProtection.Text = @"Enabled";
}
else
{
this.textOverloadProtection.Text = @"Disabled";
}
this.textDelay.Text = this.currentDetector.OverloadControl.Status.OverloadDelay.ToString(@"F2", CultureInfo.InvariantCulture);
this.textThreshold.Text = this.currentDetector.OverloadControl.Status.OverloadThreshold.ToString(@"F2", CultureInfo.InvariantCulture);
switch (this.currentDetector.OverloadControl.Status.LowMagInterlock)
{
case LowMagInterlock.Enabled:
this.textInterlockStatus.Text = @"Enabled";
break;
case LowMagInterlock.Disabled:
this.textInterlockStatus.Text = @"Disabled";
break;
case LowMagInterlock.Unknown:
default:
this.textInterlockStatus.Text = @"Unknown";
break;
}
this.UpdateDetectorStatusText();
}
///
/// UpdateOperatingStatusText Method
/// Gets and updates the UI with the detectors Thermal status.
///
private void UpdateThermalStatusText()
{
this.textOperatingStatus.Text = this.currentDetector.ThermalControl.Status.OperatingState.ToString();
this.UpdateDetectorStatusText();
}
#endregion
#region Control Detector from UI
///
/// Move in button click handler
/// If the detectors slide control can be driven in,
/// then this commands the slide controller for the detector to move the slide in.
///
/// sender object
/// EventArgs
private void MoveInButton_Click(object sender, EventArgs e)
{
if (this.currentDetector.SlideControl.CanDriveIn())
{
this.currentDetector.SlideControl.DriveIn();
}
}
///
/// Move out button click handler
/// If the detectors slide control can be driven out,
/// then this commands the slide controller for the detector to move the slide out.
///
/// sender object
/// EventArgs
private void MoveOutButton_Click(object sender, EventArgs e)
{
if (this.currentDetector.SlideControl.CanDriveOut())
{
this.currentDetector.SlideControl.DriveOut();
}
}
///
/// Stop button click handler
/// If the detectors slide control can be stopped,
/// then this commands the slide controller for the detector to stop moving.
///
/// sender object
/// EventArgs
private void StopButton_Click(object sender, EventArgs e)
{
if (this.currentDetector.SlideControl.CanStop())
{
this.currentDetector.SlideControl.Stop();
}
}
///
/// Opearte button click handler
/// If the detectors thermal control can be under automatic control,
/// then this commands it to enter automatic mode.
///
/// sender object
/// EventArgs
private void OperateButton_Click(object sender, EventArgs e)
{
if (this.currentDetector.ThermalControl.CanEnterAutomaticMode())
{
this.currentDetector.ThermalControl.EnterAutomaticMode();
}
}
///
/// Standby button click handler
/// If the detectors thermal control can be placed into standby mode,
/// then this commands it to enter standby mode.
///
/// sender object
/// EventArgs
private void StandbyButton_Click(object sender, EventArgs e)
{
if (this.currentDetector.ThermalControl.CanEnterStandbyMode())
{
this.currentDetector.ThermalControl.EnterStandbyMode();
}
}
///
/// Open button click handler
/// If the detectors shutter control can be opened, this commands it to open.
///
/// sender object
/// EventArgs
private void OpenButton_Click(object sender, EventArgs e)
{
if (this.currentDetector.ShutterControl.CanOpenShutter())
{
this.currentDetector.ShutterControl.OpenShutter();
}
}
///
/// Close button click handler
/// If the detectors shutter control can be closed, this commands it to close.
///
/// sender object
/// EventArgs
private void CloseButton_Click(object sender, EventArgs e)
{
if (this.currentDetector.ShutterControl.CanCloseShutter())
{
this.currentDetector.ShutterControl.CloseShutter();
}
}
///
/// SetOverloadValue button click handler
/// This sets the overload delay and threshold for a detector's overload control
/// to the values specified in the UI if we are allowed.
///
/// sender object
/// EventArgs
private void SetOverloadValueButton_Click(object sender, EventArgs e)
{
float delay = float.Parse(this.tbDelay.Text, CultureInfo.InvariantCulture);
float threshold = float.Parse(this.tbThreshold.Text, CultureInfo.InvariantCulture);
if (this.currentDetector.OverloadControl.CanSetOverloadDelay(delay))
{
this.currentDetector.OverloadControl.SetOverloadDelay(delay);
}
if (this.currentDetector.OverloadControl.CanSetOverloadThreshold(threshold))
{
this.currentDetector.OverloadControl.SetOverloadThreshold(threshold);
}
this.UpdateOverloadStatusText();
}
///
/// ToggleOverloadProtection button click handler
/// Toggles the detectors overload detection if allowed.
///
/// sender object
/// EventArgs
private void ToggleOverloadProtectionButton_Click(object sender, EventArgs 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();
}
///
/// Raises the event.
///
/// A that contains the event data.
protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
{
IEdDetectorControl detector = this.currentDetector;
if (detector != null)
{
// un-hook detector controller status events
detector.SlideControl.StatusChanged -= this.OnDetectorSlideStatusChanged;
detector.ThermalControl.StatusChanged -= this.OnDetectorOperatingStatusChanged;
detector.ShutterControl.StatusChanged -= this.OnDetectorShutterStatusChanged;
detector.OverloadControl.StatusChanged -= this.OnDetectorOverloadStatusChanged;
}
base.OnClosing(e);
}
#endregion
}
}