SECI  1
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events
PearlDashboard.xaml.cs
Go to the documentation of this file.
1 using System;
2 using System.Windows;
3 using System.Windows.Controls;
4 using System.Windows.Media;
5 using System.Globalization;
6 using System.Text.RegularExpressions;
7 
8 namespace SeciControls
9 {
13  public partial class PearlDashboard : BaseDashboardControl
14  {
15  private String _oldTitle;
16  private Boolean _codeChangingTitle = false;
17  private Brush _brushWarning;
18  private Brush _brushNormal;
19 
20  public PearlDashboard()
21  {
22  InitializeComponent();
23  _brushWarning = (SolidColorBrush)this.FindResource("WarningTextBrush");
24  _brushNormal = (SolidColorBrush)this.FindResource("NormalTextBrush");
25 
26  if (!Seci.Definitions.Status.EnableDashboardTitleEdit)
27  {
28  txtTitle.Visibility = System.Windows.Visibility.Visible;
29  txtEditTitle.Visibility = System.Windows.Visibility.Collapsed;
30  }
31  }
32 
33  public override Boolean IsExpanded()
34  {
35  return expander1.IsExpanded;
36  }
37 
38  private void txtTitle_TextChanged(object sender, TextChangedEventArgs e)
39  {
40  if (btnSet != null && !_codeChangingTitle)
41  {
42  if (btnSet.Visibility == Visibility.Collapsed)
43  {
44  btnSet.Visibility = Visibility.Visible;
45  btnCancel.Visibility = Visibility.Visible;
46  _oldTitle = Seci.Standard.Dae.RunTitle;
47  }
48  }
49  }
50 
51  private void btnSet_Click(object sender, RoutedEventArgs e)
52  {
53  if (_oldTitle.Trim() != Seci.Standard.Dae.RunTitle.Trim())
54  {
55  //The title has been changed by other means during the edit (i.e. via Open GENIE)
56  if (MessageBox.Show("The current run title has been changed to \"" + Seci.Standard.Dae.RunTitle +
57  "\" do you wish to replace it with your changes?", "Title Changed During Edit",
58  MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No)
59  {
60  txtTitle.Text = Seci.Standard.Dae.RunTitle;
61  btnSet.Visibility = Visibility.Collapsed;
62  btnCancel.Visibility = Visibility.Collapsed;
63  _oldTitle = "";
64  return;
65  }
66  }
67 
68  //Set new title
69  Seci.Standard.Dae.SetTitle(txtEditTitle.Text);
70 
71  btnSet.Visibility = Visibility.Collapsed;
72  btnCancel.Visibility = Visibility.Collapsed;
73  _oldTitle = "";
74 
75  _codeChangingTitle = true;
76  txtTitle.Text = "Updating...";
77  _codeChangingTitle = false;
78  }
79 
80  private void btnCancel_Click(object sender, RoutedEventArgs e)
81  {
82  txtTitle.Text = Seci.Standard.Dae.RunTitle;
83  btnSet.Visibility = Visibility.Collapsed;
84  btnCancel.Visibility = Visibility.Collapsed;
85  _oldTitle = "";
86  }
87 
88  private void expander1_StateChanged(object sender, RoutedEventArgs e)
89  {
90  if (mainGrid != null)
91  {
92  if (expander1.IsExpanded)
93  {
94  mainGrid.Visibility = Visibility.Visible;
95  RoutedEventArgs newEventArgs = new RoutedEventArgs(PearlDashboard.OnExpandedEvent);
96  RaiseEvent(newEventArgs);
97  }
98  else
99  {
100  mainGrid.Visibility = Visibility.Collapsed;
101  RoutedEventArgs newEventArgs = new RoutedEventArgs(PearlDashboard.OnUnexpandedEvent);
102  RaiseEvent(newEventArgs);
103  }
104  }
105  }
106 
107  public override void UpdateControl()
108  {
109  //Top row
110  txtInst.Text = Seci.Definitions.Status.Instrument.ToUpper();
111 
112  if (Seci.Standard.Dae.RunNumber == null)
113  {
114  //probably a problem with the DAE
115  txtStatus.Text = "UNKNOWN";
116  return;
117  }
118 
119  //Remove leading zeroes from run number
120  txtRunNum.Text = Regex.Replace(Seci.Standard.Dae.RunNumber, @"^0*", "");
121  setStatusColour(Seci.Standard.Dae.RunStatus);
122 
123  if (Seci.Standard.Dae.RunStatus == "SETUP")
124  {
125  txtRunNumLabel.Text = "Next Run";
126  }
127  else
128  {
129  txtRunNumLabel.Text = "Run";
130  }
131 
132  //Middle area
133  DateTime time = DateTime.Now;
134  txtTime.Text = time.ToShortTimeString() + " " + time.Day + " " + CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(time.Month) + " " + time.Year;
135  txtUsers.Text = Seci.Standard.Dae.UserName;
136 
137  //Update title only if it is not being edited
138  if (txtEditTitle.Visibility == Visibility.Visible && btnSet.Visibility == Visibility.Collapsed)
139  {
140  _codeChangingTitle = true;
141  txtEditTitle.Text = Seci.Standard.Dae.RunTitle;
142  _codeChangingTitle = false;
143  }
144  else if (txtTitle.Visibility == Visibility.Visible)
145  {
146  txtTitle.Text = Seci.Standard.Dae.RunTitle;
147  }
148 
149  //Bottom area
150  txtRunTime.Text = Seci.Standard.Dae.RunDurationTotal;
151  txtFrames.Text = Seci.Standard.Dae.GoodFramesTotal + " / " + Seci.Standard.Dae.RawFramesTotal;
152 
153  if (IsMuon)
154  {
155  txtCurrTotal.Text = Seci.Standard.Dae.CountRate;
156  txtMonCounts.Text = Seci.Standard.Dae.TotalDaeCounts;
157  txtShutter.Text = Seci.Standard.BeamLogger.GetKickerStatus();
158  }
159  else
160  {
161  String curr = Seci.Standard.Dae.BeamCurrent;
162  String tot = Seci.Standard.Dae.TotalUAmps;
163 
164  if (!curr.Contains("e") && curr.IndexOf('.') != -1 && curr.IndexOf('.') + 2 < curr.Length)
165  {
166  curr = curr.Substring(0, curr.IndexOf('.') + 2);
167  }
168 
169  if (!tot.Contains("e") && tot.IndexOf('.') != -1 && tot.IndexOf('.') + 4 < tot.Length)
170  {
171  tot = tot.Substring(0, tot.IndexOf('.') + 4);
172  }
173 
174  txtCurrTotal.Text = curr + " / " + tot;
175  txtShutter.Text = Seci.Standard.BeamLogger.GetShutterStatus();
176  if (txtShutter.Text.ToLower() != "open")
177  {
178  txtShutter.Foreground = _brushWarning;
179  }
180  else
181  {
182  txtShutter.Foreground = _brushNormal;
183  }
184  txtMonCounts.Text = Seci.Standard.Dae.MonitorCounts;
185  }
186 
187  txtTimeChannels.Text = Seci.Standard.Dae.NumberOfTimeChannels;
188  txtNumSpectra.Text = Seci.Standard.Dae.NumberOfSpectra;
189  txtDaeMemory.Text = Seci.Standard.Dae.DaeMemoryUsed;
190  txtTimingSource.Text = Seci.Standard.Dae.DaeTimingSource;
191  txtMethTemp.Text = Seci.Standard.BeamLogger.GetTs1MethaneTemp() + "K";
192  }
193 
194  private void setStatusColour(String runStatus)
195  {
196  string status = runStatus.ToUpper();
197  txtStatus.Text = status;
198 
199  Brush brush;
200 
201  switch (status)
202  {
203  case "PROCESSING":
204  brush = new SolidColorBrush(Colors.Yellow);
205  break;
206  case "RUNNING":
207  brush = new SolidColorBrush(Colors.LightGreen);
208  break;
209  case "SETUP":
210  brush = new SolidColorBrush(Colors.LightBlue);
211  break;
212  case "PAUSED":
213  brush = new SolidColorBrush(Colors.Red);
214  break;
215  case "WAITING":
216  brush = new SolidColorBrush(Colors.Goldenrod);
217  break;
218  case "VETOING":
219  brush = new SolidColorBrush(Colors.Goldenrod);
220  break;
221  case "ENDING":
222  brush = new SolidColorBrush(Colors.RoyalBlue);
223  break;
224  case "SAVING":
225  brush = new SolidColorBrush(Colors.RoyalBlue);
226  break;
227  default:
228  brush = new SolidColorBrush(Colors.White);
229  break;
230  }
231 
232  topRow.Background = brush;
233  }
234  }
235 }
Interaction logic for PearlDashboard.xaml
static readonly RoutedEvent OnExpandedEvent
void txtTitle_TextChanged(object sender, TextChangedEventArgs e)
void btnCancel_Click(object sender, RoutedEventArgs e)
void setStatusColour(String runStatus)
void expander1_StateChanged(object sender, RoutedEventArgs e)
void btnSet_Click(object sender, RoutedEventArgs e)
static readonly RoutedEvent OnUnexpandedEvent