AcquisitionItem.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. namespace OINA.Extender.Testharness
  2. {
  3. using System;
  4. using System.Globalization;
  5. using System.Windows.Forms;
  6. using OINA.Extender.Acquisition.Ed;
  7. using OINA.Extender.Data.Ed;
  8. /// <summary>
  9. /// Encapsulates an acquiring item
  10. /// </summary>
  11. public class AcquisitionItem
  12. {
  13. /// <summary>
  14. /// The parent ListBox
  15. /// </summary>
  16. private ListBox parentListBox;
  17. /// <summary>
  18. /// Gets the ed spectrum.
  19. /// </summary>
  20. /// <value>
  21. /// The ed spectrum.
  22. /// </value>
  23. public IEdSpectrum EdSpectrum { get; private set; }
  24. /// <summary>
  25. /// Gets the label.
  26. /// </summary>
  27. /// <value>
  28. /// The label.
  29. /// </value>
  30. public string Label
  31. {
  32. get
  33. {
  34. double progress = (this.CurrentProgress / this.AcquisitionTime) * 100.0;
  35. if (progress > 0.0)
  36. {
  37. return string.Format(CultureInfo.CurrentCulture, @"({0:0.00}%) {1}", progress, this.EdSpectrum.Label);
  38. }
  39. else
  40. {
  41. return this.EdSpectrum.Label;
  42. }
  43. }
  44. }
  45. /// <summary>
  46. /// Gets the aquisition mode.
  47. /// </summary>
  48. /// <value>
  49. /// The aquisition mode.
  50. /// </value>
  51. public EdAcquireMode AcquisitionMode { get; private set; }
  52. /// <summary>
  53. /// Gets the aquisition time.
  54. /// </summary>
  55. /// <value>
  56. /// The aquisition time.
  57. /// </value>
  58. public double AcquisitionTime { get; private set; }
  59. /// <summary>
  60. /// Gets the current progress.
  61. /// </summary>
  62. /// <value>
  63. /// The current progress.
  64. /// </value>
  65. public double CurrentProgress
  66. {
  67. get
  68. {
  69. if (this.AcquisitionMode == EdAcquireMode.LiveTime)
  70. {
  71. return this.EdSpectrum.LiveTimeSeconds * 1000.0;
  72. }
  73. else
  74. {
  75. return this.EdSpectrum.RealTimeSeconds * 1000.0;
  76. }
  77. }
  78. }
  79. /// <summary>
  80. /// Initializes a new instance of the <see cref="AcquisitionItem" /> class.
  81. /// </summary>
  82. /// <param name="edSpectrum">The ed spectrum.</param>
  83. /// <param name="mode">The mode.</param>
  84. /// <param name="acquisitionTime">The aquisition time.</param>
  85. /// <param name="parent">The parent.</param>
  86. public AcquisitionItem(IEdSpectrum edSpectrum, EdAcquireMode mode, double acquisitionTime, ListBox parent)
  87. {
  88. this.parentListBox = parent;
  89. this.EdSpectrum = edSpectrum;
  90. this.AcquisitionMode = mode;
  91. this.AcquisitionTime = acquisitionTime;
  92. this.EdSpectrum.DataChanged += this.OnEdSpectrumDataChanged;
  93. }
  94. /// <summary>
  95. /// Updates the ListBox item.
  96. /// </summary>
  97. /// <param name="listbox">The listbox.</param>
  98. /// <param name="item">The item.</param>
  99. private static void UpdateListBoxItem(ListBox listbox, object item)
  100. {
  101. int index = listbox.Items.IndexOf(item);
  102. if (index >= 0)
  103. {
  104. int currIndex = listbox.SelectedIndex;
  105. listbox.BeginUpdate();
  106. try
  107. {
  108. listbox.ClearSelected();
  109. listbox.Items[index] = item;
  110. listbox.SelectedIndex = currIndex;
  111. }
  112. finally
  113. {
  114. listbox.EndUpdate();
  115. }
  116. }
  117. }
  118. /// <summary>
  119. /// Called when [ed spectrum data changed].
  120. /// </summary>
  121. /// <param name="sender">The sender.</param>
  122. /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
  123. public void OnEdSpectrumDataChanged(object sender, EventArgs e)
  124. {
  125. if (this.parentListBox.InvokeRequired)
  126. {
  127. MethodInvoker updateItem = delegate { UpdateListBoxItem(this.parentListBox, this); };
  128. this.parentListBox.Invoke(updateItem);
  129. return;
  130. }
  131. }
  132. }
  133. }