SECI  1
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events
UserInterface.xaml.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.Collections.Specialized;
4 using System.Linq;
5 using System.Text;
6 using System.Windows;
7 using System.Windows.Controls;
8 using System.Windows.Data;
9 using System.Windows.Documents;
10 using System.Windows.Input;
11 using System.Windows.Media;
12 using System.Windows.Media.Imaging;
13 using System.Windows.Navigation;
14 using System.Windows.Shapes;
15 using System.ComponentModel;
16 using System.IO;
17 
18 namespace SeciUserInterface
19 {
23  public partial class UserInterface : Window
24  {
26  private static Boolean _manager = false; //Is the manager logged in?
27  private Boolean _changesMade = false; //Unsaved changes?
28  private BackgroundWorker _backgroundSave = new BackgroundWorker();
29  private BackgroundWorker _backgroundAutoSave = new BackgroundWorker();
30  private List<String> _recentConfigs = new List<string>();
31  private const int _numberLastConfigs = 3;
32  private const String _beamlogTabname = "Beam-Logger";
33  private const String _dummyTabname = "secisWonderfulHackTab"; //Name for tab that is used to get cascading right
34  private Boolean _closingBecauseLvRunning = false; //this indicates that seci is being closed because LabVIEW is running.
36  private Boolean _userCanSaveConfig = true;
37  private Boolean _forceRestart = false;
38  private Boolean _lvLost = false;
39 
41 
42  private delegate void UpdateGuiDelegate();
43  private delegate void UpdateDashboardDelegate(Boolean timeout);
44 
46 
47  public UserInterface()
48  {
49  try
50  {
51  Seci.Managers.SeciMgr.IsBusy = true;
52 
53  //Check to see if Seci died - if so we may want to auto reload the last config
54  _forceRestart = !Properties.Settings.Default.CleanKill;
55 
56  //On start up set CleanKill to false, it will be changed to true if the user
57  //closes Seci.
58  Properties.Settings.Default.CleanKill = false;
59  Properties.Settings.Default.Save();
60 
61  //Set up directories and read app settings
62  String exeLocation = System.Reflection.Assembly.GetExecutingAssembly().Location;
63  Seci.Managers.SeciMgr.InitialiseSeci(exeLocation.Substring(0, exeLocation.LastIndexOf('\\')));
64  ApplicationCommands.New.InputGestures.Clear(); //Disables Ctrl+N for New Command
65 
66  InitializeComponent();
67 
68  _splashscreen = new Forms.SeciSplashscreen("SECI is loading - please wait", this);
69  _splashscreen.Show();
70 
71  if (Seci.Definitions.Status.DashboardType == "PERIOD")
72  {
74  }
75  else if (Seci.Definitions.Status.DashboardType == "PEARL")
76  {
78  }
79  else if (Seci.Definitions.Status.DashboardType == "POLARIS")
80  {
82  }
83  else
84  {
86  }
87 
88  pnlDashboard.Children.Insert(0, _dashboard);
89 
90  //Set up height binding for blocksDisplay
91  Binding b = new Binding();
92  b.Source = _dashboard;
93  b.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
94  b.Path = new PropertyPath("ActualHeight");
95  this.blocksDisplay.SetBinding(SeciControls.BlockDisplay.HeightProperty, b);
96 
97  if (Seci.Definitions.Status.IsMuonInstrument)
98  {
99  _dashboard.IsMuon = true;
100  }
101 
102  //Show version number in title
103  this.Title += " (Version " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString() + ")";
104 
105  if (labViewRunning(_forceRestart || Seci.Definitions.Status.AutoloadLastConfig))
106  {
107  //if labview is not killed then just exit
109  Application.Current.Shutdown();
110  return;
111  }
112 
115  }
116  catch (Exception err)
117  {
118  MessageBox.Show("Start up error: " + err.Message);
119  }
120  }
121 
122  private void UserInterface_Loaded(object sender, RoutedEventArgs e)
123  {
124  if (Seci.Definitions.Status.DelayStartup)
125  {
126  //Delays startup to allow debugger to be attached
127  System.Threading.Thread.Sleep(30000);
128  }
129 
130  //Adjust the navbar
131  StringCollection navbarnames = Properties.Settings.Default.NavBarSettings;
132  List<KeyValuePair<String, String>> order = new List<KeyValuePair<String, String>>();
133  foreach (String str in navbarnames)
134  {
135  String[] temp = str.Split('|');
136  if (temp.Length == 2)
137  {
138  order.Add(new KeyValuePair<string, string>(temp[0].Trim(), temp[1].Trim()));
139  }
140  }
141  navBar.SetButtonOrderAndNames(order);
142 
143  navBar.LostTimeVisible = Properties.Settings.Default.LostTimeVisible;
144  navBar.VisVisibleForUser = Properties.Settings.Default.VisAvailable;
145  navBar.DaeVisibleForUser = Properties.Settings.Default.DaeViAvailable;
146  navBar.UserCanEditVISettings = Properties.Settings.Default.UserCanEditVISettings;
147  navBar.JournelViewerVisible = Properties.Settings.Default.ShowJournalViewer;
148  navBar.SetTabsVisibility(_manager);
149  advancedOptions.ShowLostTime = navBar.LostTimeVisible;
150  advancedOptions.VisAvailable = navBar.VisVisibleForUser;
151  advancedOptions.DaeAvailable = navBar.DaeVisibleForUser;
152  advancedOptions.ShowJournalViewer = navBar.JournelViewerVisible;
153  advancedOptions.ShowBeamlogger = Properties.Settings.Default.ShowBeamlogger;
154  advancedOptions.BigFontsDashboard = Properties.Settings.Default.UseBigFontsDashboard;
155  advancedOptions.PlotOnGenieTab = Properties.Settings.Default.GraphsOnGenieTab;
156  Seci.Managers.SeciMgr.WebDashboardEnabled = Properties.Settings.Default.WebDashboardEnabled;
157  Seci.Managers.SeciMgr.WebDashboardShowTitle = Properties.Settings.Default.WebDashboardShowTitle;
158  advancedOptions.ShowWebDashboard = Seci.Managers.SeciMgr.WebDashboardEnabled;
159  advancedOptions.WebDashboardShowTitle = Seci.Managers.SeciMgr.WebDashboardShowTitle;
160  bugzillaDisplayer.Navigate(new Uri(Seci.Definitions.Status.BugzillaWebpage));
161 
162  advancedOptions.PythonAvailable = Seci.Definitions.Status.IsPythonAvailable;
163 
164  //Load the phone numbers for the alerts
165  Seci.Managers.AlertsMgr.LoadPhoneNumbers();
166 
167  if (Seci.Definitions.Status.KillIcpOnExit)
168  {
169  //Make sure ICP is not running
170  Seci.Standard.Dae.KillIcp();
171 
172  //Also, kill the ISIS Data Server
173  Seci.Standard.Dae.KillIsisDataSvr();
174  }
175 
176  //Kill any Genie windows left over from a previous Seci session
177  if (!String.IsNullOrEmpty(Properties.Settings.Default.ScriptPIDS))
178  {
179  System.Diagnostics.Process[] procList = System.Diagnostics.Process.GetProcessesByName("tkgenie32");
180 
181  if (procList.Length > 0)
182  {
183  String[] old_pids = Properties.Settings.Default.ScriptPIDS.Split(';');
184 
185  for (int i = 0; i < old_pids.Length; ++i)
186  {
187  int pid = 0;
188  if (int.TryParse(old_pids[i], out pid))
189  {
190  for (int j = 0; j < procList.Length; ++j)
191  {
192  if (pid == procList[j].Id)
193  {
194  try
195  {
196  procList[j].Kill();
197  }
198  catch (Exception err)
199  {
200  Seci.Helpers.MessageLogger.WriteMessage("UserInterface_Loaded", "Failed to kill Genie orphan: " + err.Message);
201  }
202  }
203  }
204  }
205  }
206  }
207  Properties.Settings.Default.ScriptPIDS = "";
208  }
209 
210  //Start LabVIEW and the standard VIs
211  Seci.Managers.SeciMgr.InitialiseLabView(true);
213  dae.AddDae();
214 
215  if (Seci.Definitions.Status.AutoloadLastConfig && !String.IsNullOrEmpty(Properties.Settings.Default.LastConfig))
216  {
217  FileInfo fi = new FileInfo(Seci.Definitions.Status.ConfigDir + Properties.Settings.Default.LastConfig);
218 
219  if (fi.Exists)
220  {
221  //Open last configuration
222  _splashscreen.Close();
223  startTimers();
224  pauseTimers();
225  eventViewer.AddMessage("Seci automatically started with last configuration", false);
226  openConfig(Seci.Definitions.Status.ConfigDir + Properties.Settings.Default.LastConfig, false);
227  Seci.Helpers.MessageLogger.WriteMessage("UserInterface", "Last configuration was loaded automatically");
228  Seci.Managers.SeciMgr.IsBusy = false;
229  return;
230  }
231  }
232  else if (_forceRestart && !String.IsNullOrEmpty(Properties.Settings.Default.LastConfig))
233  {
234  Seci.Helpers.MessageLogger.WriteMessage("UserInterface", "Seci was not closed properly last time it was running.");
235  FileInfo fi = new FileInfo(Seci.Definitions.Status.ConfigDir + Properties.Settings.Default.LastConfig);
236 
237  if (fi.Exists)
238  {
240  if (dlg.ShowDialog() == true)
241  {
242  _splashscreen.Close();
243  startTimers();
244  pauseTimers();
245  eventViewer.AddMessage("Seci started with last configuration", false);
246  openConfig(Seci.Definitions.Status.ConfigDir + Properties.Settings.Default.LastConfig, false);
247  Seci.Helpers.MessageLogger.WriteMessage("UserInterface", "Last configuration was loaded");
248  Seci.Managers.SeciMgr.IsBusy = false;
249  return;
250  }
251  }
252  }
253 
254  //if (!Properties.Settings.Default.LogBlocks)
255  //{
256  // Seci.Managers.BlockMgr.LogValuesEnabled = false;
257  // advancedOptions.LogBlocksEnabled = false;
258  //}
259  //else
260  //{
261  // Seci.Managers.BlockMgr.LogValuesEnabled = true;
262  // advancedOptions.LogBlocksEnabled = true;
263  //}
264 
265  //Start the update and error timers
266  startTimers();
267 
268  //Is scripting page visible?
269  if (Seci.Definitions.Status.ShowScriptingPage)
270  {
271  //Open at least one Open Genie terminal
272  startOpenGenies();
273  }
274  else
275  {
276  navBar.HideScriptingTab();
277  }
278 
279  eventViewer.AddMessage("Seci started", false);
280 
281  _splashscreen.Close();
282 
284 
285  Seci.Managers.SeciMgr.IsBusy = false;
286  }
287 
288  #region NavBar Events
289 
290  void navBar_OnExperimentDetailsClicked(object sender, EventArgs e)
291  {
293  experimentDetails.Visibility = Visibility.Visible;
294  userInfo.Update();
295  userInfo.Visibility = Visibility.Visible;
296  sampleInfo.Update();
297  sampleInfo.Visibility = Visibility.Visible;
298  beamlineInfo.Update();
299  beamlineInfo.Visibility = Visibility.Visible;
300  }
301 
302  #region LabVIEW
303 
304  void navBar_OnVIsClicked(object sender, EventArgs e)
305  {
307  viTab.Visibility = Visibility.Visible;
308  }
309 
310  void navBar_OnAddVIClicked(object sender, EventArgs e)
311  {
312  Seci.Managers.SeciMgr.IsBusy = true;
313 
314  try
315  {
316  Dialogs.VIs.AddVI addVI = new Dialogs.VIs.AddVI();
317  if (addVI.ShowDialog() == System.Windows.Forms.DialogResult.OK)
318  {
319  List<String> vis = Seci.Managers.LabViewMgr.GetListOfVIs(true);
320 
321  //Add and Load the VIs
322  for (int i = 0; i < addVI.VIsToAdd.Count; ++i)
323  {
324  if (!vis.Contains(addVI.VIsToAdd[i].ToLower()))
325  {
326  Seci.Managers.LabViewMgr.AddVI(new Seci.LabView.LabViewPanelInfo(addVI.VIsToAdd[i], true, false));
327  Seci.Managers.LabViewMgr.ShowVI(addVI.VIsToAdd[i]);
328  }
329  }
330 
331  _changesMade = true;
332  _backgroundAutoSave.RunWorkerAsync();
333  }
334  }
335  catch (FileNotFoundException err)
336  {
337  // WriteError("AddVI ", err);
338  eventViewer.AddMessage("Could not extract information from llb file: " + err.Message, true);
339  MessageBox.Show("Could not extract information from llb file! " + err.Message + "!", "Error!", MessageBoxButton.OK, MessageBoxImage.Error);
340  }
341  catch (Exception err)
342  {
343  //WriteError("AddVI ", err);
344  eventViewer.AddMessage("Could not add VI: " + err.Message, true);
345  MessageBox.Show("Could not add VI!", "Error!", MessageBoxButton.OK, MessageBoxImage.Error);
346  }
347  finally
348  {
349  Seci.Managers.SeciMgr.IsBusy = false;
350  }
351  }
352 
353  void navBar_OnRemoveVIClicked(object sender, EventArgs e)
354  {
355  Seci.Managers.SeciMgr.IsBusy = true;
356 
357  //Get all the non sub-config VIs
358  Seci.SerialisableList<Seci.LabView.LabViewPanelInfo> all = Seci.Managers.LabViewMgr.GetAllPanelsInfo();
359  Seci.SerialisableList<Seci.LabView.LabViewPanelInfo> confOnly = new Seci.SerialisableList<Seci.LabView.LabViewPanelInfo>();
360 
361  for (int i = 0; i < all.Count; ++i)
362  {
363  if (String.IsNullOrEmpty(all[i].OwningComponent))
364  {
365  confOnly.Add(all[i]);
366  }
367  }
368 
369  Dialogs.VIs.RemoveVI removeVI = new Dialogs.VIs.RemoveVI(confOnly);
370 
371  if (removeVI.ShowDialog() == System.Windows.Forms.DialogResult.OK)
372  {
373  //Remove the vis
374  if (removeVI.ToRemove != null)
375  {
376  //Remove the VIs
377  for (int i = 0; i < removeVI.ToRemove.Count; ++i)
378  {
379  Seci.SerialisableList<Seci.LabView.LabViewPanelInfo> panels = Seci.Managers.LabViewMgr.GetAllPanelsInfo();
380 
381  //Find out which objects correspond to the names to remove
382  for (int j = 0; j < panels.Count; ++j)
383  {
384  if (panels[j].FilePath == removeVI.ToRemove[i])
385  {
386  //First remove any blocks that correspond to the VI's being removed
387  Seci.Managers.BlockMgr.Blocks.RemoveByVI(removeVI.ToRemove[i]);
388 
389  //Then remove the VI
390  Seci.Managers.LabViewMgr.RemoveVI(removeVI.ToRemove[i]);
391 
392  break;
393  }
394  }
395  }
396  }
397 
398  //Remove from the tabs
399  foreach (string viname in removeVI.ToRemove)
400  {
401  viTab.RemoveVi(viname);
402  }
403 
404  blocksDisplay.SetBlocksToShow(Seci.Managers.BlockMgr.Blocks.GetKeys());
405  _changesMade = true;
406  _backgroundAutoSave.RunWorkerAsync();
407  }
408 
409  Seci.Managers.SeciMgr.IsBusy = false;
410  }
411 
412  void navBar_OnConfigureVIClicked(object sender, EventArgs e)
413  {
414  Seci.Managers.SeciMgr.IsBusy = true;
415 
416  Dialogs.VIs.SetVIProperties props = new Dialogs.VIs.SetVIProperties(Seci.Managers.LabViewMgr.GetAllPanelsInfo(), false);
417  if (props.ShowDialog() == System.Windows.Forms.DialogResult.OK)
418  {
419  //Set visibility
420  for (int i = 0; i < props.Panels.Count; ++i)
421  {
422  //Show panel or not
423  if (props.Panels[i].ShowPanel)
424  {
425  Seci.Managers.LabViewMgr.ShowVI(props.Panels[i].FilePath);
426  }
427  else
428  {
429  Seci.Managers.LabViewMgr.HideVI(props.Panels[i].FilePath);
430  }
431  }
432 
433  //Copy back
434  Seci.Managers.LabViewMgr.SetPanelsInfo(props.Panels);
435 
436  _changesMade = true;
437  _backgroundAutoSave.RunWorkerAsync();
438  }
439 
440  Seci.Managers.SeciMgr.IsBusy = false;
441  }
442 
443  void navBar_OnEditTabsClicked(object sender, EventArgs e)
444  {
445  Seci.Managers.SeciMgr.IsBusy = true;
446 
447  List<String> nonEdit = new List<string>();
448  nonEdit.Add(_beamlogTabname);
449  List<String> secret = new List<string>();
450  secret.Add(_dummyTabname);
451 
452  Dialogs.Tabs.EditTabs tab = new Dialogs.Tabs.EditTabs(ref viTab, nonEdit, secret, Seci.Managers.ConfigurationMgr.GetTabs());
453  if (tab.ShowDialog() == System.Windows.Forms.DialogResult.OK)
454  {
455  _changesMade = true;
456  _backgroundAutoSave.RunWorkerAsync();
457  }
458 
459  Seci.Managers.SeciMgr.IsBusy = false;
460  }
461 
462  void navBar_OnConfigureBlocksClicked(object sender, EventArgs e)
463  {
464  Seci.Managers.SeciMgr.IsBusy = true;
465 
467  confBlocks.BlocksCopy = Seci.Managers.BlockMgr.GetBlocksClone();
468  if (confBlocks.ShowDialog() == System.Windows.Forms.DialogResult.OK)
469  {
470  //Put the changes into the configuration
471  //Pause threads and wait a second to give threads fired off time to finish
472  Seci.Managers.SeciMgr.PauseThreads();
473  System.Threading.Thread.Sleep(1000);
474 
475  //Copy updated blocks onto main config blocks
476  Seci.Managers.BlockMgr.SetBlocks(confBlocks.BlocksCopy);
477 
478  if (Seci.Definitions.Status.UseDaeMonitorVI)
479  {
480  Seci.Standard.DaeMonitor.WriteBlockList();
481  }
482 
483  //Copy the BlockGroups
484  Seci.Managers.BlockMgr.ReorderBlockGroups(confBlocks.GroupOrder);
485 
486  //Restart threads
487  Seci.Managers.SeciMgr.ResumeThreads();
488 
489  //Set up blocks display
490  blocksDisplay.SetBlocksToShow(Seci.Managers.BlockMgr.Blocks.GetKeys());
491  if (!_dashboard.IsExpanded())
492  {
493  blocksDisplay.Visibility = Visibility.Collapsed;
494  }
495  _changesMade = true;
496 
497  _backgroundAutoSave.RunWorkerAsync();
498 
499  if (!Properties.Settings.Default.UsePython)
500  {
501  MessageBox.Show("To implement these changes in Open GENIE you will need to type \"GetBlocks\" in the Open GENIE scripting window(s).", "Blocks Changed", MessageBoxButton.OK, MessageBoxImage.Information);
502  }
503  }
504 
505  Seci.Managers.SeciMgr.IsBusy = false;
506  }
507 
508 
509  void navBar_OnDisplayBlocksClicked(object sender, EventArgs e)
510  {
511  if (_rcv == null || _rcv.IsDisposed)
512  {
514  _rcv.Show();
515  }
516  else
517  {
518  _rcv.Show();
519  if (_rcv.WindowState == System.Windows.Forms.FormWindowState.Minimized)
520  {
521  _rcv.WindowState = System.Windows.Forms.FormWindowState.Normal;
522  }
523  _rcv.BringToFront();
524  }
525  }
526 
527  #endregion
528 
529  void navBar_OnLostTimeClicked(object sender, EventArgs e)
530  {
532  lostTime.Visibility = Visibility.Visible;
533  }
534 
535 
536 
537  void navBar_OnOpenGenieClicked(object sender, EventArgs e)
538  {
540  OpenGenie1.Visibility = Visibility.Visible;
541  if (navBar.TwoGeniesAvailable)
542  {
543  OpenGenie2.Visibility = Visibility.Visible;
544  }
545 
546  if (Properties.Settings.Default.GraphsOnGenieTab && _graphs.Count > 0)
547  {
548  genieGraphPanel.Visibility = Visibility.Visible;
549  }
550  else
551  {
552  genieGraphPanel.Visibility = Visibility.Collapsed;
553  }
554 
555  OpenGenie1.SetFocus();
556  }
557 
558  void navBar_OnDaeClicked(object sender, EventArgs e)
559  {
561  dae.Visibility = Visibility.Visible;
562  }
563 
564  void navBar_OnGraphsClicked(object sender, EventArgs e)
565  {
567  graphPanel.Visibility = Visibility.Visible;
568  }
569 
570  void navBar_OnSettingsClicked(object sender, EventArgs e)
571  {
573  IniEditor.Visibility = Visibility.Visible;
574  }
575 
576  void navBar_OnAdvancedClicked(object sender, EventArgs e)
577  {
579  advancedOptions.Visibility = Visibility.Visible;
580  }
581 
582  void navBar_OnJournalViewerClicked(object sender, EventArgs e)
583  {
585  JournalViewer.Visibility = Visibility.Visible;
586  }
587 
588  void navBar_OnSystemMessagesClicked(object sender, EventArgs e)
589  {
591  MessagesPanel.Visibility = Visibility.Visible;
592  }
593 
594  void navBar_OnBeamStatusClicked(object sender, EventArgs e)
595  {
597  BeamStatus.Visibility = Visibility.Visible;
598  }
599 
600  void navBar_OnIsisMessagesClicked(object sender, EventArgs e)
601  {
603  mcrnews.Visibility = Visibility.Visible;
604  }
605 
606  void navBar_OnReportProblemClicked(object sender, EventArgs e)
607  {
609  bugzillaDisplayer.Visibility = Visibility.Visible;
610  }
611 
612  void navBar_OnHelpClicked(object sender, EventArgs e)
613  {
615  helpPanel.Visibility = Visibility.Visible;
616  }
617 
619  {
620  experimentDetails.Visibility = Visibility.Collapsed;
621  userInfo.Visibility = Visibility.Collapsed;
622  sampleInfo.Visibility = Visibility.Collapsed;
623  beamlineInfo.Visibility = Visibility.Collapsed;
624  viTab.Visibility = Visibility.Collapsed;
625  OpenGenie1.Visibility = Visibility.Collapsed;
626  OpenGenie2.Visibility = Visibility.Collapsed;
627  dae.Visibility = Visibility.Collapsed;
628  advancedOptions.Visibility = Visibility.Collapsed;
629  mcrnews.Visibility = Visibility.Collapsed;
630  MessagesPanel.Visibility = Visibility.Collapsed;
631  graphPanel.Visibility = Visibility.Collapsed;
632  BeamStatus.Visibility = Visibility.Collapsed;
633  helpPanel.Visibility = Visibility.Collapsed;
634  JournalViewer.Visibility = Visibility.Collapsed;
635  genieGraphPanel.Visibility = Visibility.Collapsed;
636  bugzillaDisplayer.Visibility = Visibility.Collapsed;
637  IniEditor.Visibility = Visibility.Collapsed;
638  lostTime.Visibility = Visibility.Collapsed;
639  }
640 
641  #endregion
642 
643  #region Timers and Threads
644 
645  private void startTimers()
646  {
647  Seci.Managers.SeciMgr.StartThreads(true, true);
648  Seci.Managers.SeciMgr.OnValuesUpdated += new Seci.Managers.SeciMgr.ValuesUpdatedEventHandler(SeciInterface_ValuesUpdated);
649  Seci.Managers.SeciMgr.OnNewLVMessage += new EventHandler(SeciInterface_OnNewLVMessage);
650  Seci.Managers.SeciMgr.OnLVNotThere += new EventHandler(SeciInterface_OnLVNotThere);
651  viTab.StartTimers(Seci.Definitions.Status.ViHostRefreshRate);
652  }
653 
654  public static void pauseTimers()
655  {
656  Seci.Managers.SeciMgr.PauseThreads();
657 
658  //Wait a second to give threads fired off time to finish
659  System.Threading.Thread.Sleep(1000);
660  }
661 
662  public void resumeTimers()
663  {
664  Seci.Managers.SeciMgr.ResumeThreads();
665  viTab.StartTimers(Seci.Definitions.Status.ViHostRefreshRate);
666  }
667 
668  private void SeciInterface_ValuesUpdated(Boolean timeout)
669  {
670  try
671  {
672  //if (!_closing) //If the form is closing then don't update
673  //{
674  this.Dispatcher.Invoke(new UpdateDashboardDelegate(UpdateMainGUI), timeout);
675  //}
676  }
677  catch
678  {
679  }
680  }
681 
682  private void UpdateMainGUI(Boolean timeout)
683  {
684  //Update dashboard
685  if (!timeout)
686  {
687  _dashboard.UpdateControl();
688  }
689 
690  blocksDisplay.UpdateControl();
691  if (_graphs != null && _graphs.Count > 0)
692  {
693  foreach (SeciControls.Graphing.GraphWrapper graph in _graphs)
694  {
695  graph.UpdateControl();
696  }
697  }
698 
699  if (!Seci.Managers.BlockMgr.LogValuesEnabled)
700  {
701  txtWarning.Text = "Warning: Blocks values are not being logged";
702  txtWarning.Visibility = System.Windows.Visibility.Visible;
703  }
704  else
705  {
706  txtWarning.Visibility = System.Windows.Visibility.Collapsed;
707  }
708  }
709 
710  void SeciInterface_OnNewLVMessage(object sender, EventArgs e)
711  {
712  try
713  {
714  //if (!_closing) //If the form is closing then don't update
715  //{
716  this.Dispatcher.Invoke(new UpdateGuiDelegate(UpdateErrorsGUI), null);
717  //}
718  }
719  catch
720  {
721  //WriteError("SeciInterface_OnNewLVMessage", err);
722  }
723  }
724 
725  void SeciInterface_OnLVNotThere(object sender, EventArgs e)
726  {
727  if (!_lvLost)
728  {
729  _lvLost = true;
730  this.Dispatcher.Invoke(new UpdateGuiDelegate(showWarning), null);
731  MessageBox.Show("Seci has lost connection to LabVIEW - this probably means LabVIEW has a very serious problem", "SECI - LabVIEW connection lost", MessageBoxButton.OK, MessageBoxImage.Error);
732  }
733  }
734 
735  private void showWarning()
736  {
737  txtWarning.Text = "Seci has lost connection to LabVIEW - this probably means LabVIEW has a very serious problem";
738  txtWarning.Visibility = System.Windows.Visibility.Visible;
739  }
740 
741  private void UpdateErrorsGUI()
742  {
743  //Get the messages
744  Seci.SerialisableList<Seci.Standard.MessageInfo> errorMessages = Seci.Standard.MessageQueue.Messages;
745 
746  if (errorMessages != null)
747  {
748  int numErrors = 0;
749  int numQuestions = 0;
750 
751  //Check for questions and errors
752  for (int i = 0; i < errorMessages.Count; ++i)
753  {
754  if (errorMessages[i].WaitForResponse)
755  {
756  ++numQuestions;
757  }
758  else
759  {
760  ++numErrors;
761  }
762  }
763 
764  //Update navbar
765  navBar.SetErrorCounter(numErrors, numQuestions);
766  //Display the messages
767  errorViewer.AddMessages(errorMessages);
768  }
769  }
770 
771  #endregion
772 
773  #region Closing
774 
775  private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
776  {
777  Seci.Managers.SeciMgr.IsBusy = true;
778 
780  {
781  if (_manager && Seci.Managers.AssocFileMgr.AnyModificationsToParFiles())
782  {
783  if (MessageBox.Show("At least one TPAR or MPAR has been modified, to make the changes permanent the configuration must be saved. Are you sure you still wish to close SECI?", "Unsaved Changes!", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No)
784  {
785  e.Cancel = true;
786  Seci.Managers.SeciMgr.IsBusy = false;
787  return;
788  }
789  }
790 
791  if (_changesMade || Seci.Managers.AssocFileMgr.AnyModifications())
792  {
793  if (MessageBox.Show("There are unsaved changes to the configuration. Are you sure you wish to close SECI?", "Unsaved Changes!", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No)
794  {
795  e.Cancel = true;
796  Seci.Managers.SeciMgr.IsBusy = false;
797  return;
798  }
799  }
800  else
801  {
802  if (MessageBox.Show("Close SECI?", "Close?", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No)
803  {
804  e.Cancel = true;
805  Seci.Managers.SeciMgr.IsBusy = false;
806  return;
807  }
808  }
809 
810  //Stop updating
811  pauseTimers();
812 
813  System.Threading.Thread.Sleep(1000);
814 
815  //Close the configuration
816  Seci.Managers.ConfigurationMgr.CloseConfiguration(Seci.Definitions.Status.KillIcpOnExit);
817  Seci.Managers.SeciMgr.CloseSeci();
818 
819  //Update the app settings
820  saveSettings();
821 
822  helpPanel.Dispose();
823 
824  Seci.Helpers.MessageLogger.WriteMessage("SeciGui", "User closed SECI");
825  }
826  }
827 
828  private void saveSettings()
829  {
830  Properties.Settings.Default.CleanKill = true;
831  Properties.Settings.Default.VisAvailable = navBar.VisVisibleForUser;
832  Properties.Settings.Default.DaeViAvailable = navBar.DaeVisibleForUser;
833  Properties.Settings.Default.UserCanEditVISettings = navBar.UserCanEditVISettings;
834  Properties.Settings.Default.UsePython = (bool)advancedOptions.UsePython;
835  Properties.Settings.Default.UseTwoGenies = navBar.TwoGeniesAvailable;
836  Properties.Settings.Default.ShowJournalViewer = navBar.JournelViewerVisible;
837  Properties.Settings.Default.ShowBeamlogger = (bool)advancedOptions.ShowBeamlogger;
838  Properties.Settings.Default.UseBigFontsDashboard = (bool)advancedOptions.BigFontsDashboard;
839  Properties.Settings.Default.WebDashboardEnabled = Seci.Managers.SeciMgr.WebDashboardEnabled;
840  Properties.Settings.Default.WebDashboardShowTitle = Seci.Managers.SeciMgr.WebDashboardShowTitle;
841  Properties.Settings.Default.LogBlocks = Seci.Managers.BlockMgr.LogValuesEnabled;
842  Properties.Settings.Default.LostTimeVisible = navBar.LostTimeVisible;
843  Properties.Settings.Default.Save();
844  }
845 
846  #endregion
847 
848  #region File
849 
850  private void menuNewCommand(object sender, RoutedEventArgs e)
851  {
852  Seci.Managers.SeciMgr.IsBusy = true;
853 
854  if (okayToCloseConfig())
855  {
856  _splashscreen = new Forms.SeciSplashscreen("Creating a new Configuration", this);
857  _splashscreen.Show();
858  RestartSeci();
859 
860  txtConfig.Text = "None";
861 
862  Seci.Managers.ConfigurationMgr.CreateNewConfiguration();
863  //Add the beam logger tab if it has not already been added
864  if (Seci.Managers.ConfigurationMgr.GetTabs().Count == 0)
865  {
866  Seci.Managers.ConfigurationMgr.GetTabs().Add(new Seci.Definitions.Tab(_beamlogTabname, (bool)advancedOptions.ShowBeamlogger));
867  }
868 
869  //Pause a couple seconds to make sure VIs have loaded
870  System.Threading.Thread.Sleep(2000);
871 
872  //Is scripting page visible?
873  if (Seci.Definitions.Status.ShowScriptingPage)
874  {
875  //Open at least one Open Genie terminal
876  startOpenGenies();
877  }
878  else
879  {
880  navBar.HideScriptingTab();
881  }
882 
883  eventViewer.AddMessage("New configuration selected", false);
884  cascadeTabs();
885 
886  //Restart timers
887  resumeTimers();
888  _splashscreen.Close();
889  }
890 
891  Seci.Managers.SeciMgr.IsBusy = false;
892  }
893 
894  private void menuOpenCommand(object sender, RoutedEventArgs e)
895  {
896  Seci.Managers.SeciMgr.IsBusy = true;
897 
898  if (okayToCloseConfig())
899  {
900  System.Windows.Forms.OpenFileDialog openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
901  openFileDialog1.InitialDirectory = Seci.Definitions.Status.ConfigDir;
902  openFileDialog1.Filter = "SECI Configuration|*.conf|SECI Sub-Configuration|*.comp";
903 
904  if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
905  {
906  openConfig(openFileDialog1.FileName, true);
907  }
908  }
909 
910  Seci.Managers.SeciMgr.IsBusy = false;
911  }
912 
913  private void menuSaveCommand(object sender, RoutedEventArgs e)
914  {
915  Seci.Managers.SeciMgr.IsBusy = true;
916 
917  if (!_userCanSaveConfig && !_manager)
918  {
919  MessageBox.Show("Sorry, you do not have permission to save configurations.", "Cannot save", MessageBoxButton.OK, MessageBoxImage.Exclamation);
920  }
921  else
922  {
923  if (String.IsNullOrEmpty(Seci.Managers.ConfigurationMgr.ConfigName))
924  {
925  //Use saveAs instead
926  menuSaveAsCommand(sender, e);
927  }
928  else
929  {
930  doSave(false, Seci.Managers.ConfigurationMgr.ConfigName);
931  }
932  }
933 
934  Seci.Managers.SeciMgr.IsBusy = false;
935  }
936 
937  private void menuSaveAsCommand(object sender, RoutedEventArgs e)
938  {
939  Seci.Managers.SeciMgr.IsBusy = true;
940 
941  if (!_userCanSaveConfig && !_manager)
942  {
943  MessageBox.Show("Sorry, you do not have permission to save configurations.", "Cannot save", MessageBoxButton.OK, MessageBoxImage.Exclamation);
944  }
945  else
946  {
947  System.Windows.Forms.SaveFileDialog saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
948  saveFileDialog1.InitialDirectory = Seci.Definitions.Status.ConfigDir;
949 
950  if (Seci.Managers.ComponentMgr.GetNames() != null && Seci.Managers.ComponentMgr.GetNames().Count > 0)
951  {
952  //Save as a configuration only
953  saveFileDialog1.Filter = "SECI Configuration|*.conf";
954  }
955  else
956  {
957  //Save as a configuration or component
958  saveFileDialog1.Filter = "SECI Configuration|*.conf|SECI Sub-configuration|*.comp";
959  }
960 
961  //Save it
962  if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
963  {
964  doSave(true, saveFileDialog1.FileName);
965  }
966  }
967 
968  Seci.Managers.SeciMgr.IsBusy = false;
969  }
970 
971  private void menuExitCommand(object sender, RoutedEventArgs e)
972  {
973  this.Close();
974  }
975 
976  private void startOpenGenies()
977  {
978  //Restart Open Genie(s)
979  if (Seci.Definitions.Status.IsPythonAvailable && Properties.Settings.Default.UsePython)
980  {
981  advancedOptions.UsePython = true;
982  setToPython();
983  }
984  else
985  {
986  setToGenie();
987  }
988 
989  OpenGenie1.StartProcess();
990  if (navBar.TwoGeniesAvailable || Properties.Settings.Default.UseTwoGenies)
991  {
992  navBar.TwoGeniesAvailable = true;
993  advancedOptions.TwoGeniesAvailable = true;
994  OpenGenie2.StartProcess();
995  }
996 
998  }
999 
1000  private void saveScriptingPids()
1001  {
1002  List<int> pids = new List<int>();
1003  pids.Add(OpenGenie1.GetPID());
1004 
1005  if (navBar.TwoGeniesAvailable || Properties.Settings.Default.UseTwoGenies)
1006  {
1007  pids.Add(OpenGenie2.GetPID());
1008  }
1009 
1010  //Get the PIDs and save them
1011  String sPids = "";
1012  foreach (int p in pids)
1013  {
1014  sPids += p.ToString() + ";";
1015  }
1016 
1017  Properties.Settings.Default.ScriptPIDS = sPids.Substring(0, sPids.Length - 1);
1018  Properties.Settings.Default.Save();
1019  }
1020 
1021  private void setToPython()
1022  {
1023  OpenGenie1.UsePython(true);
1024  OpenGenie2.UsePython(true);
1025  OpenGenie1.SetLinkMessage("Start Python");
1026  OpenGenie2.SetLinkMessage("Start Python");
1027  OpenGenie1.Initialise(Seci.Definitions.Status.PythonPath, Seci.Definitions.Status.PythonArgs);
1028  OpenGenie2.Initialise(Seci.Definitions.Status.PythonPath, Seci.Definitions.Status.PythonArgs);
1029  }
1030 
1031  private void setToGenie()
1032  {
1033  OpenGenie1.UsePython(false);
1034  OpenGenie2.UsePython(false);
1035  OpenGenie1.SetLinkMessage("Start Open Genie");
1036  OpenGenie2.SetLinkMessage("Start Open Genie");
1037  OpenGenie1.Initialise(Seci.Definitions.Status.OpenGenieLocation, "");
1038  OpenGenie2.Initialise(Seci.Definitions.Status.OpenGenieLocation, "");
1039  }
1040 
1041  private void RestartSeci()
1042  {
1043  //Pause updating and error timers
1044  pauseTimers();
1045  Seci.Managers.SeciMgr.ClearDatabaseQueues();
1046 
1047  //Clear layout
1048  blocksDisplay.SetBlocksToShow(null);
1049  viTab.RemoveAllTabs();
1050  dae.RemoveDae();
1051  deleteGraphs();
1052  IniEditor.ClearFiles();
1053  IniEditor.Visibility = Visibility.Collapsed;
1054  navBar.SettingsVisible = false;
1055  navBar.GraphsAvailable = false;
1056  navBar.SetTabsVisibility(_manager);
1057 
1058  //Close current config
1059  Seci.Managers.ConfigurationMgr.CloseConfiguration(Seci.Definitions.Status.KillIcpOnConfigChange);
1060 
1061  //Needs a few seconds to let everything close (see Ticket #78)
1062  System.Threading.Thread.Sleep(10000);
1063 
1064  //Close Open Genie(s)
1065  OpenGenie1.KillProcess();
1066  if (navBar.TwoGeniesAvailable)
1067  {
1068  OpenGenie2.KillProcess();
1069  }
1070 
1071  //Clear LV messages
1072  errorViewer.ClearMessages();
1073  navBar.SetErrorCounter(0, 0);
1074 
1075  //And reinitialise LabVIEW
1076  Seci.Managers.SeciMgr.InitialiseLabView(true);
1077  addBeamloggerTab();
1078  dae.AddDae();
1079 
1080  _changesMade = false;
1081  }
1082 
1083  private Boolean okayToCloseConfig()
1084  {
1085  if (_changesMade || Seci.Managers.AssocFileMgr.AnyModifications())
1086  {
1087  if (MessageBox.Show("There are unsaved changes to the current configuration - are you sure you wish to close it?", "Unsaved Changes!", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No)
1088  {
1089  return false;
1090  }
1091  }
1092 
1093  return true;
1094  }
1095 
1096  //For some reason labview will not move the vi on the last tab to the correct
1097  //position. So, to get round this we add a dummy tab as the last tab and hide it.
1098  //Though this is far from elegant it works well.
1099  //We use the sample parameters vi, but it could be any of the standard VIs.
1100  private void cascadeTabs()
1101  {
1102  if (viTab.AddDummyTab(_dummyTabname))
1103  {
1104  viTab.AddVi(_dummyTabname, Seci.Standard.SampleParameters.FilePath);
1105  }
1106  viTab.CascadeAllTabs();
1107  }
1108 
1109  private void openConfig(String filepath, Boolean restartSeci)
1110  {
1111  _splashscreen = new Forms.SeciSplashscreen("Opening Configuration", this);
1112  _splashscreen.Show();
1113 
1114  if (restartSeci)
1115  {
1116  RestartSeci();
1117  }
1118 
1119  try
1120  {
1121  Seci.Managers.ConfigurationMgr.OpenConfiguration(filepath);
1122  eventViewer.AddMessage("Configuration opened: " + Seci.Managers.ConfigurationMgr.ConfigName, false);
1123  }
1124  catch (Exception err)
1125  {
1126  _splashscreen.Close();
1127 
1128  MessageBox.Show("Failed to open configuration" + Environment.NewLine + err.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
1129  eventViewer.AddMessage("Failed to open configuration: " + filepath, false);
1130  Seci.Helpers.MessageLogger.WriteMessage("openConfig", "Failed to open configuration: " + err.Message);
1131 
1132  _splashscreen = new Forms.SeciSplashscreen("Resetting SECI", this);
1133  _splashscreen.Show();
1134  RestartSeci();
1135  }
1136 
1137  setupTabs();
1138 
1139  //Is scripting page visible?
1140  if (Seci.Definitions.Status.ShowScriptingPage)
1141  {
1142  //Open at least one Open Genie terminal
1143  startOpenGenies();
1144  }
1145  else
1146  {
1147  navBar.HideScriptingTab();
1148  }
1149 
1150  blocksDisplay.SetBlocksToShow(Seci.Managers.BlockMgr.Blocks.GetKeys());
1151  txtConfig.Text = Seci.Managers.ConfigurationMgr.ConfigName;
1152 
1153  //Set up graphs
1154  setupGraphs(Seci.Managers.ConfigurationMgr.GetGraphDefinitions());
1155 
1156  //If muon load any tpar or mpar files
1157  setupIniFiles(true);
1158 
1159  List<String> visNotLoaded = Seci.Managers.LabViewMgr.GetVIsNotLoaded();
1160 
1161  if (visNotLoaded != null && visNotLoaded.Count > 0)
1162  {
1163  String message = "The following VIs were not loaded and their associated Blocks were removed:" + Environment.NewLine;
1164  foreach (String name in visNotLoaded)
1165  {
1166  message += " " + name + Environment.NewLine;
1167  }
1168 
1169  eventViewer.AddMessage(message.Trim(), false);
1170  }
1171 
1172  resumeTimers();
1173 
1174  updateRecentConfigs(Seci.Managers.ConfigurationMgr.ConfigName);
1175 
1176  //Cascade the tabs they will be moved to the correct position later
1177  cascadeTabs();
1178 
1179  //Set tab visibility if user
1181 
1182  _splashscreen.Close();
1183  }
1184 
1185  private void setupIniFiles(Boolean clear)
1186  {
1187  if (Seci.Definitions.Status.IsMuonInstrument)
1188  {
1189  if (clear)
1190  {
1191  IniEditor.ClearFiles();
1192  }
1193 
1194  List<String> par_files = new List<string>();
1195  foreach (String file in Seci.Managers.AssocFileMgr.GetListOfAsscFiles(true))
1196  {
1197  if (file.ToLower().EndsWith(".tpar") || file.ToLower().EndsWith(".mpar"))
1198  {
1199  par_files.Add(file);
1200  }
1201  }
1202 
1203  if (par_files.Count > 0)
1204  {
1205  IniEditor.LoadFiles(par_files);
1206  navBar.SettingsVisible = true;
1207  navBar.SetTabsVisibility(_manager);
1208  }
1209  }
1210  }
1211 
1212  private void setupTabs()
1213  {
1214  Seci.SerialisableList<Seci.LabView.LabViewPanelInfo> panels = Seci.Managers.LabViewMgr.GetAllPanelsInfo();
1215 
1216  for (int i = 0; i < panels.Count; ++i)
1217  {
1218  if (!String.IsNullOrEmpty(panels[i].Group))
1219  {
1220  viTab.AddTab(panels[i].Group);
1221  if (panels[i].Bounds != null)
1222  {
1223  if (!viTab.DoesTabContainsVi(panels[i].Group, panels[i].FilePath))
1224  {
1225  viTab.AddVi(panels[i].Group, panels[i].FilePath, panels[i].Bounds[0], panels[i].Bounds[1]);
1226  }
1227  }
1228  else
1229  {
1230  viTab.AddVi(panels[i].Group, panels[i].FilePath);
1231  }
1232  }
1233  }
1234 
1235  Seci.SerialisableList<Seci.Definitions.Tab> tabs_conf = Seci.Managers.ConfigurationMgr.GetTabs();
1236 
1237  //Remove any duplicates
1238  for (int i = 0; i < tabs_conf.Count; ++i)
1239  {
1240  for (int j = tabs_conf.Count - 1; j > i; --j)
1241  {
1242  if (tabs_conf[i].Name == tabs_conf[j].Name)
1243  {
1244  tabs_conf.RemoveAt(j);
1245  }
1246  }
1247  }
1248 
1249  List<String> tabs = viTab.GetTabNames(true);
1250  for (int i = tabs_conf.Count - 1; i >= 0; --i)
1251  {
1252  if (!tabs.Contains(tabs_conf[i].Name))
1253  {
1254  tabs_conf.RemoveAt(i);
1255  }
1256  }
1257 
1258  //Set tab order and show beamlogger tab by default
1259  viTab.SetTabOrder(tabs_conf);
1260  viTab.SelectTab(_beamlogTabname);
1261  }
1262 
1263  private void doSave(Boolean isNewFile, String fullFileName)
1264  {
1265  String fileName;
1266 
1267  //Set config name
1268  fileName = fullFileName.Substring(fullFileName.LastIndexOf("\\") + 1);
1269 
1270  if (isNewFile && !fullFileName.StartsWith(Seci.Definitions.Status.ConfigDir))
1271  {
1272  MessageBox.Show("Configurations and components must be saved in the Configurations directory", "Trying to Save in wrong location");
1273  return;
1274  }
1275 
1276  String oldName = Seci.Managers.ConfigurationMgr.ConfigName;
1277  Seci.Managers.ConfigurationMgr.ConfigName = fileName;
1278 
1279  //Populate tab order list
1280  List<String> tabs = viTab.GetTabNames(false);
1281  tabs.Remove(_dummyTabname);
1282  Seci.Managers.ConfigurationMgr.SetTabOrder(null);
1283 
1284  //Populate configurations graph definitions
1285  Seci.Managers.ConfigurationMgr.SetGraphDefinitions(getDefinitions());
1286 
1287  //Check user has permission to save
1288  Boolean okayToSave = Seci.Managers.ConfigurationMgr.OkayToSave(_manager);
1289 
1290  if (fileName.ToLower().EndsWith(".comp") && Seci.Managers.ComponentMgr.GetNames().Count > 0)
1291  {
1292  MessageBox.Show("This configuration contains at least one component, so it cannot be saved as a component");
1293  }
1294 
1295  //Check user has permission to save
1296  if (okayToSave)
1297  {
1298  //Call background save
1299  txtStatus.Text = "Saving...";
1300 
1301  try
1302  {
1303  _backgroundSave.RunWorkerAsync();
1304  }
1305  catch (Exception err)
1306  {
1307  Seci.Managers.ConfigurationMgr.ConfigName = oldName;
1308  eventViewer.AddMessage("Failed to save configuration: " + err.Message, true);
1309  //WriteError("saveConfig ", err);
1310  }
1311  txtConfig.Text = Seci.Managers.ConfigurationMgr.ConfigName;
1312  updateRecentConfigs(txtConfig.Text);
1313  }
1314  else
1315  {
1316  Seci.Managers.ConfigurationMgr.ConfigName = oldName;
1317  MessageBox.Show("Sorry, you must be logged in with the manager account to overwrite this configuration!", "Cannot Overwrite!", MessageBoxButton.OK, MessageBoxImage.Error);
1318  }
1319  }
1320 
1321  void backgroundSave_DoWork(object sender, DoWorkEventArgs e)
1322  {
1323  Seci.Managers.ConfigurationMgr.SaveConfiguration(_manager, false);
1324  }
1325 
1326  void backgroundSave_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
1327  {
1328  txtStatus.Text = "";
1329  eventViewer.AddMessage("Configuration saved: " + Seci.Managers.ConfigurationMgr.ConfigName, false);
1330  _changesMade = false;
1331  }
1332 
1333  void backgroundAutoSave_DoWork(object sender, DoWorkEventArgs e)
1334  {
1335  //Always do auto save as manager
1336  Seci.Managers.ConfigurationMgr.SaveConfiguration(true, true);
1337  }
1338 
1339  #endregion
1340 
1341  #region Manager
1342 
1343  private void menuMgrLogin_Click(object sender, RoutedEventArgs e)
1344  {
1345  Seci.Managers.SeciMgr.IsBusy = true;
1346 
1348 
1349  if (login.ShowDialog() == System.Windows.Forms.DialogResult.OK)
1350  {
1351  _manager = true;
1352  fileMenu.LogInEnabled = false;
1353  fileMenu.LogOutEnabled = true;
1354  navBar.SetTabsVisibility(_manager);
1355 
1356  if (!navBar.VisVisibleForUser)
1357  {
1358  showNonTabbedVis();
1359  }
1360 
1361  //Show all VI tabs
1363  }
1364 
1365  Seci.Managers.SeciMgr.IsBusy = false;
1366  }
1367 
1368  private void SetViTabsVisibility()
1369  {
1370  bool anyVisible = false;
1371 
1372  foreach (var tab in Seci.Managers.ConfigurationMgr.GetTabs())
1373  {
1374  if (tab.VisibleForUser || _manager)
1375  {
1376  viTab.UnhideTab(tab.Name);
1377  anyVisible = true;
1378  }
1379  else
1380  {
1381  viTab.HideTab(tab.Name);
1382  }
1383  }
1384 
1385  if (!anyVisible)
1386  {
1387  viTab.SelectTab(-1);
1388  }
1389  else
1390  {
1391  viTab.SetToFirstVisible();
1392  }
1393  }
1394 
1395  private void menuMgrLogout_Click(object sender, RoutedEventArgs e)
1396  {
1397  Seci.Managers.SeciMgr.IsBusy = true;
1398 
1399  _manager = false;
1400  fileMenu.LogInEnabled = true;
1401  fileMenu.LogOutEnabled = false;
1402  navBar.SetTabsVisibility(_manager);
1403  hideMainControls();
1404  navBar.DeselectSelectedItem();
1405 
1406  if (!navBar.VisVisibleForUser)
1407  {
1408  hideNonTabbedVis();
1409  }
1410  else
1411  {
1412  showNonTabbedVis();
1413  }
1414 
1415  //Hide any VI tabs that should be hidden
1417 
1418  Seci.Managers.SeciMgr.IsBusy = false;
1419  }
1420 
1422  {
1423  Seci.SerialisableList<Seci.LabView.LabViewPanelInfo> vis = getLooseVis();
1424 
1425  for (int i = 0; i < vis.Count; ++i)
1426  {
1427  Seci.Managers.LabViewMgr.HideVI(vis[i].FilePath);
1428  }
1429  }
1430 
1432  {
1433  Seci.SerialisableList<Seci.LabView.LabViewPanelInfo> vis = getLooseVis();
1434 
1435  for (int i = 0; i < vis.Count; ++i)
1436  {
1437  //Show panel or not
1438  if (vis[i].ShowPanel)
1439  {
1440  Seci.Managers.LabViewMgr.ShowVI(vis[i].FilePath);
1441  }
1442  else
1443  {
1444  Seci.Managers.LabViewMgr.HideVI(vis[i].FilePath);
1445  }
1446  }
1447  }
1448 
1449  private Seci.SerialisableList<Seci.LabView.LabViewPanelInfo> getLooseVis()
1450  {
1451  Seci.SerialisableList<Seci.LabView.LabViewPanelInfo> vis = Seci.Managers.LabViewMgr.GetAllPanelsInfo();
1452  List<String> visInTabs = viTab.GetAllVisInTabs();
1453 
1454  List<String> tohide = new List<String>();
1455 
1456  for (int i = 0; i < vis.Count; ++i)
1457  {
1458  if (!vis[i].ShowPanel || visInTabs.Contains(vis[i].FilePath))
1459  {
1460  //Do nothing
1461  }
1462  else
1463  {
1464  tohide.Add(vis[i].FilePath);
1465 
1466  }
1467  }
1468  return vis;
1469  }
1470 
1471  #endregion
1472 
1473  #region User Info
1474 
1475  void userInfo_OnEditUsersClicked(object sender, EventArgs e)
1476  {
1477  Seci.Managers.SeciMgr.IsBusy = true;
1478 
1479  if (!_manager)
1480  {
1481  MessageBox.Show("You must be logged in with the Manager account to perform this action.", "Unauthorised", MessageBoxButton.OK, MessageBoxImage.Stop);
1482  }
1483  else
1484  {
1486  editUsers.oldUsers = Seci.Standard.UserDetails.GetUsers();
1487 
1488  if (editUsers.ShowDialog() == System.Windows.Forms.DialogResult.OK)
1489  {
1490  try
1491  {
1492  Seci.Standard.UserDetails.SetUsers(editUsers.newUsers);
1493  System.Threading.Thread.Sleep(600);
1494  }
1495  catch
1496  {
1497  }
1498 
1499  userInfo.Update();
1500  }
1501  }
1502 
1503  Seci.Managers.SeciMgr.IsBusy = false;
1504  }
1505 
1506  #endregion
1507 
1508  #region Advanced Options
1509 
1510  private void advancedOptions_OnCheckStatusChanged(object sender, EventArgs e)
1511  {
1512  CheckBox chk = sender as CheckBox;
1513  if (chk.IsChecked == true)
1514  {
1515  navBar.DaeVisibleForUser = true;
1516  }
1517  else
1518  {
1519  navBar.DaeVisibleForUser = false;
1520  }
1521  }
1522 
1523  void advancedOptions_OnVisAvailableCheckChanged(object sender, EventArgs e)
1524  {
1525  CheckBox chk = sender as CheckBox;
1526  if (chk.IsChecked == true)
1527  {
1528  navBar.VisVisibleForUser = true;
1529  }
1530  else
1531  {
1532  navBar.VisVisibleForUser = false;
1533  }
1534  }
1535 
1536  void advancedOptions_OnUserCanSaveCheckChanged(object sender, EventArgs e)
1537  {
1538  CheckBox chk = sender as CheckBox;
1539  if (chk.IsChecked == true)
1540  {
1541  _userCanSaveConfig = true;
1542  }
1543  else
1544  {
1545  _userCanSaveConfig = false;
1546  }
1547  }
1548 
1549  void advancedOptions_OnModifyVisCheckChanged(object sender, EventArgs e)
1550  {
1551  CheckBox chk = sender as CheckBox;
1552  if (chk.IsChecked == true)
1553  {
1554  navBar.UserCanEditVISettings = true;
1555  }
1556  else
1557  {
1558  navBar.UserCanEditVISettings = false;
1559  }
1560  }
1561 
1562  void advancedOptions_OnAddExeClicked(object sender, EventArgs e)
1563  {
1564  Seci.Managers.SeciMgr.IsBusy = true;
1565 
1567  if (add.ShowDialog() == System.Windows.Forms.DialogResult.OK)
1568  {
1569  _changesMade = true;
1570  _backgroundAutoSave.RunWorkerAsync();
1571  }
1572 
1573  Seci.Managers.SeciMgr.IsBusy = false;
1574  }
1575 
1576  void advancedOptions_OnRemoveExeClicked(object sender, EventArgs e)
1577  {
1578  Seci.Managers.SeciMgr.IsBusy = true;
1579 
1581  if (remove.ShowDialog() == System.Windows.Forms.DialogResult.OK)
1582  {
1583  _changesMade = true;
1584  _backgroundAutoSave.RunWorkerAsync();
1585  }
1586 
1587  Seci.Managers.SeciMgr.IsBusy = false;
1588  }
1589 
1590  void advancedOptions_OnAddAssocFileClicked(object sender, EventArgs e)
1591  {
1592  Seci.Managers.SeciMgr.IsBusy = true;
1593 
1595  if (add.ShowDialog() == System.Windows.Forms.DialogResult.OK)
1596  {
1597  _changesMade = true;
1598  setupIniFiles(false);
1599  _backgroundAutoSave.RunWorkerAsync();
1600  }
1601 
1602  Seci.Managers.SeciMgr.IsBusy = false;
1603  }
1604 
1605  void advancedOptions_OnRemoveAssocFileClicked(object sender, EventArgs e)
1606  {
1607  Seci.Managers.SeciMgr.IsBusy = true;
1608 
1610  if (remove.ShowDialog() == System.Windows.Forms.DialogResult.OK)
1611  {
1612  _changesMade = true;
1613  _backgroundAutoSave.RunWorkerAsync();
1614  }
1615 
1616  Seci.Managers.SeciMgr.IsBusy = false;
1617  }
1618 
1619  void advancedOptions_OnConfigureGraphsClicked(object sender, EventArgs e)
1620  {
1621  Seci.Managers.SeciMgr.IsBusy = true;
1622 
1624 
1625  if (Properties.Settings.Default.GraphsOnGenieTab)
1626  {
1627  conf = new SeciUserInterface.Dialogs.Graphs.ConfigureGraphs(Seci.Definitions.Status.MaxNumberGenieGraphs);
1628  }
1629  else
1630  {
1631  conf = new SeciUserInterface.Dialogs.Graphs.ConfigureGraphs(Seci.Definitions.Status.MaxNumberGraphs);
1632  }
1633  conf.Graphs = getDefinitions();
1634  if (conf.ShowDialog() == System.Windows.Forms.DialogResult.OK)
1635  {
1636  setDefinitions(conf.Graphs);
1637  setupGraphs(conf.Graphs);
1638  }
1639 
1640  Seci.Managers.SeciMgr.IsBusy = false;
1641  }
1642 
1643  void advancedOptions_OnConfigAlertsClicked(object sender, EventArgs e)
1644  {
1645  Seci.Managers.SeciMgr.IsBusy = true;
1646 
1648  alerts.Alerts = Seci.Managers.AlertsMgr.GetAlertsCopy();
1649  alerts.PhoneNumbers = Seci.Managers.AlertsMgr.GetPhoneNumbersCopy();
1650 
1651  if (alerts.ShowDialog() == true)
1652  {
1653  Seci.Managers.AlertsMgr.SetAlerts(alerts.Alerts);
1654  Seci.Managers.AlertsMgr.SetPhoneNumbers(alerts.PhoneNumbers);
1655  Seci.Managers.AlertsMgr.SavePhoneNumbers();
1656  }
1657 
1658  Seci.Managers.SeciMgr.IsBusy = false;
1659  }
1660 
1661  void advancedOptions_OnHideTabsClicked(object sender, EventArgs e)
1662  {
1663  Seci.Managers.SeciMgr.IsBusy = true;
1664 
1665  Dialogs.Tabs.HideTabs hide = new Dialogs.Tabs.HideTabs(Seci.Managers.ConfigurationMgr.GetTabs());
1666  hide.Owner = this;
1667  hide.ShowDialog();
1668 
1669  Seci.Managers.SeciMgr.IsBusy = false;
1670  }
1671 
1672  void advancedOptions_OnShowLostTimeCheckChanged(object sender, EventArgs e)
1673  {
1674  CheckBox chk = sender as CheckBox;
1675  if (chk.IsChecked == true)
1676  {
1677  navBar.LostTimeVisible = true;
1678  }
1679  else
1680  {
1681  navBar.LostTimeVisible = false;
1682  }
1683 
1684  navBar.SetTabsVisibility(_manager);
1685  }
1686 
1687  void advancedOptions_OnPlotOnGenieTabCheckChanged(object sender, EventArgs e)
1688  {
1689  CheckBox chk = sender as CheckBox;
1690  if (chk.IsChecked == true)
1691  {
1692  Properties.Settings.Default.GraphsOnGenieTab = true;
1693  }
1694  else
1695  {
1696  Properties.Settings.Default.GraphsOnGenieTab = false;
1697  }
1698  setupGraphs(Seci.Managers.ConfigurationMgr.GetGraphDefinitions());
1699  }
1700 
1701  void advancedOptions_OnAddSubConfigClicked(object sender, EventArgs e)
1702  {
1703  Seci.Managers.SeciMgr.IsBusy = true;
1704 
1705  System.Windows.Forms.OpenFileDialog openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
1706  openFileDialog1.InitialDirectory = Seci.Definitions.Status.ConfigDir;
1707  openFileDialog1.Filter = "SECI Sub-Configuration|*.comp";
1708 
1709  if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
1710  {
1711  _splashscreen = new Forms.SeciSplashscreen("Adding Sub-Configuration - please wait", this);
1712  _splashscreen.Show();
1713 
1714  pauseTimers();
1715 
1716  if (Seci.Managers.ComponentMgr.AddComponent(openFileDialog1.FileName))
1717  {
1718  blocksDisplay.SetBlocksToShow(Seci.Managers.BlockMgr.Blocks.GetKeys());
1719  setupTabs();
1720  cascadeTabs();
1721  setupGraphs(Seci.Managers.ConfigurationMgr.GetGraphDefinitions());
1722  eventViewer.AddMessage("Component Added: " + openFileDialog1.FileName.Substring(openFileDialog1.FileName.LastIndexOf("\\") + 1), false);
1723 
1724  //May need to update block list for Genie
1725  if (Seci.Definitions.Status.UseDaeMonitorVI)
1726  {
1727  Seci.Standard.DaeMonitor.WriteBlockList();
1728  }
1729 
1730  _changesMade = true;
1731  }
1732 
1733  resumeTimers();
1734 
1735  _splashscreen.Close();
1736  }
1737  Seci.Managers.SeciMgr.IsBusy = false;
1738  }
1739 
1740  void advancedOptions_OnRemoveSubConfigClicked(object sender, EventArgs e)
1741  {
1742  Seci.Managers.SeciMgr.IsBusy = true;
1743 
1745  if (remove.ShowDialog() == System.Windows.Forms.DialogResult.OK)
1746  {
1747  _splashscreen = new Forms.SeciSplashscreen("Removing Sub-Configuration(s) - please wait", this);
1748  _splashscreen.Show();
1749 
1750  if (remove.toRemove.Count > 0)
1751  {
1752  pauseTimers();
1753 
1754  foreach (String name in remove.toRemove)
1755  {
1756  removeSubConfig(name);
1757  eventViewer.AddMessage("Component Removed: " + name, false);
1758  }
1759 
1760  //May need to update block list for Genie
1761  if (Seci.Definitions.Status.UseDaeMonitorVI)
1762  {
1763  Seci.Standard.DaeMonitor.WriteBlockList();
1764  }
1765 
1766  resumeTimers();
1767  _changesMade = true;
1768  _backgroundAutoSave.RunWorkerAsync();
1769  }
1770 
1771  _splashscreen.Close();
1772  }
1773 
1774  Seci.Managers.SeciMgr.IsBusy = false;
1775  }
1776 
1777  void advancedOptions_OnEditSubConfigClicked(object sender, EventArgs e)
1778  {
1779  Seci.Managers.SeciMgr.IsBusy = true;
1780 
1781  if (Seci.Standard.Dae.RunStatus != "SETUP")
1782  {
1783  MessageBox.Show("Sub-Configurations can only be edited when in SETUP", "SECI - Not in SETUP");
1784  }
1785  else
1786  {
1787  if (Seci.Managers.ComponentMgr.Components.Count > 0)
1788  {
1790  select.Owner = this;
1791 
1792  if (select.ShowDialog() == true)
1793  {
1794  _splashscreen = new Forms.SeciSplashscreen("Reloading Sub-Configuration(s) - please wait", this);
1795  _splashscreen.Show();
1796 
1797  //Pause threads and reload component
1798  pauseTimers();
1799 
1800  removeSubConfig(select.ComponentName);
1801 
1802  Seci.Managers.ComponentMgr.AddComponent(Seci.Definitions.Status.ConfigDir + select.ComponentName);
1803 
1804  blocksDisplay.SetBlocksToShow(Seci.Managers.BlockMgr.Blocks.GetKeys());
1805  setupTabs();
1806  cascadeTabs();
1807  setupGraphs(Seci.Managers.ConfigurationMgr.GetGraphDefinitions());
1808 
1809  //May need to update block list for Genie
1810  if (Seci.Definitions.Status.UseDaeMonitorVI)
1811  {
1812  Seci.Standard.DaeMonitor.WriteBlockList();
1813  }
1814 
1815  resumeTimers();
1816  _changesMade = false;
1817  _splashscreen.Close();
1818  }
1819  }
1820  else
1821  {
1822  MessageBox.Show("No sub-configurations in the current configuration", "SECI - No Sub-Configurations");
1823  }
1824  }
1825  Seci.Managers.SeciMgr.IsBusy = false;
1826  }
1827 
1828  void advancedOptions_OnUsePythonChanged(object sender, EventArgs e)
1829  {
1830  CheckBox chk = sender as CheckBox;
1831  if (chk.IsChecked == true)
1832  {
1833  setToPython();
1834  }
1835  else
1836  {
1837  setToGenie();
1838  }
1839  }
1840 
1841  void advancedOptions_OnTwoGeniesCheckChanged(object sender, EventArgs e)
1842  {
1843  CheckBox chk = sender as CheckBox;
1844  if (chk.IsChecked == true)
1845  {
1846  navBar.TwoGeniesAvailable = true;
1847  }
1848  else
1849  {
1850  navBar.TwoGeniesAvailable = false;
1851  }
1852  }
1853 
1854  void advancedOptions_OnShowBeamloggerCheckChanged(object sender, EventArgs e)
1855  {
1856  CheckBox chk = sender as CheckBox;
1857  setBeamloggerTabVisibility(chk.IsChecked);
1858  }
1859 
1860  void advancedOptions_OnBigFontsDashboardCheckChanged(object sender, EventArgs e)
1861  {
1862  CheckBox chk = sender as CheckBox;
1863  if (chk.IsChecked == true)
1864  {
1865  SeciControls.StandardDashboard.SetIsBigFonts(_dashboard, true);
1866  SeciControls.BlockDisplay.SetIsBigFonts(blocksDisplay, true);
1867  }
1868  else
1869  {
1870  SeciControls.StandardDashboard.SetIsBigFonts(_dashboard, false);
1871  SeciControls.BlockDisplay.SetIsBigFonts(blocksDisplay, false);
1872  }
1873  }
1874 
1875  void advancedOptions_OnJournelViewerCheckChanged(object sender, EventArgs e)
1876  {
1877  CheckBox chk = sender as CheckBox;
1878  if (chk.IsChecked == true)
1879  {
1880  navBar.JournelViewerVisible = true;
1881  navBar.SetTabsVisibility(_manager);
1882  }
1883  else
1884  {
1885  navBar.JournelViewerVisible = false;
1886  navBar.SetTabsVisibility(_manager);
1887  }
1888  }
1889 
1890  void advancedOptions_OnWebDashboardEnabledCheckChanged(object sender, EventArgs e)
1891  {
1892  CheckBox chk = sender as CheckBox;
1893  if (chk.IsChecked == true)
1894  {
1895  Seci.Managers.SeciMgr.WebDashboardEnabled = true;
1896  }
1897  else
1898  {
1899  Seci.Managers.SeciMgr.WebDashboardEnabled = false;
1900  }
1901  }
1902 
1904  {
1905  CheckBox chk = sender as CheckBox;
1906  if (chk.IsChecked == true)
1907  {
1908  Seci.Managers.SeciMgr.WebDashboardShowTitle = true;
1909  }
1910  else
1911  {
1912  Seci.Managers.SeciMgr.WebDashboardShowTitle = false;
1913  }
1914  }
1915 
1916  void removeSubConfig(String name)
1917  {
1918  Seci.Managers.ComponentMgr.RemoveComponent(name);
1919  blocksDisplay.SetBlocksToShow(Seci.Managers.BlockMgr.Blocks.GetKeys());
1920  viTab.RemoveAllTabs();
1921  addBeamloggerTab();
1922  setupTabs();
1923  cascadeTabs();
1924  setupGraphs(Seci.Managers.ConfigurationMgr.GetGraphDefinitions());
1925  }
1926 
1927  private void addBeamloggerTab()
1928  {
1929  //Add the tab
1930  if (!viTab.GetAllVisInTabs().Contains(_beamlogTabname))
1931  {
1932  viTab.AddTab(_beamlogTabname);
1933  }
1934 
1935  Seci.Managers.ConfigurationMgr.GetTabs().Add(new Seci.Definitions.Tab(_beamlogTabname, true));
1936 
1937  //Add the vi
1938  Seci.Standard.BeamLogger.ShowVi();
1939  viTab.AddVi(_beamlogTabname, Seci.Standard.BeamLogger.FilePath);
1940  cascadeTabs();
1941 
1943  }
1944 
1945  private void setBeamloggerTabVisibility(Boolean? visible)
1946  {
1947  if (visible == true)
1948  {
1949  viTab.UnhideTab(_beamlogTabname);
1950  viTab.SelectTab(0);
1951  Seci.Managers.ConfigurationMgr.SetTabVisibility(_beamlogTabname, true);
1952  }
1953  else
1954  {
1955  viTab.HideTab(_beamlogTabname);
1956  viTab.SelectTab(-1);
1957  Seci.Managers.ConfigurationMgr.SetTabVisibility(_beamlogTabname, false);
1958  }
1959  }
1960 
1961  #endregion
1962 
1963  #region Recent Configs Stuff
1964 
1965  private void setupRecentConfigs()
1966  {
1967  String raw = Properties.Settings.Default.RecentConfigs;
1968 
1969  if (!String.IsNullOrEmpty(raw))
1970  {
1971  if (raw.EndsWith(";"))
1972  {
1973  raw = raw.Substring(0, raw.Length - 1);
1974  }
1975 
1976  String[] confs = raw.Split(';');
1977  _recentConfigs = new List<string>(confs);
1978  }
1980  }
1981 
1982  private void updateRecentConfigs(String config)
1983  {
1984  Properties.Settings.Default.LastConfig = config;
1985 
1986  if (config != "")
1987  {
1988  if (!_recentConfigs.Contains(config))
1989  {
1990  _recentConfigs.Insert(0, config);
1991  }
1992  else
1993  {
1994  _recentConfigs.Remove(config);
1995  _recentConfigs.Insert(0, config);
1996  }
1997 
1998  while (_recentConfigs.Count > _numberLastConfigs)
1999  {
2000  _recentConfigs.RemoveAt(_recentConfigs.Count - 1);
2001  }
2002 
2004 
2005  String confs = "";
2006 
2007  for (int i = 0; i < _numberLastConfigs; ++i)
2008  {
2009  if (_recentConfigs != null && i < _recentConfigs.Count)
2010  {
2011  if (_recentConfigs[i] != "")
2012  {
2013  confs += _recentConfigs[i] + ";";
2014  }
2015  }
2016  }
2017 
2018  Properties.Settings.Default.RecentConfigs = confs;
2019  }
2020  Properties.Settings.Default.Save();
2021  }
2022 
2024  {
2025  List<String> recent = new List<string>();
2026 
2027  for (int i = 0; i < _recentConfigs.Count; ++i)
2028  {
2029  if (i >= _numberLastConfigs)
2030  {
2031  break;
2032  }
2033 
2034  if (!String.IsNullOrEmpty(_recentConfigs[i]))
2035  {
2036  recent.Add(_recentConfigs[i]);
2037  }
2038  }
2039 
2040  fileMenu.SetLastConfigs(recent);
2041  }
2042 
2043  void OnRecentConfig_Click(object sender, RoutedEventArgs e)
2044  {
2045  Seci.Managers.SeciMgr.IsBusy = true;
2046 
2047  System.Windows.Forms.ToolStripMenuItem temp = sender as System.Windows.Forms.ToolStripMenuItem;
2048 
2049  foreach (String filepath in _recentConfigs)
2050  {
2051  if (filepath.EndsWith(temp.Text.ToString()))
2052  {
2053  //Check conf exists
2054  FileInfo fi = new FileInfo(Seci.Definitions.Status.ConfigDir + filepath);
2055  if (fi.Exists)
2056  {
2057  openConfig(Seci.Definitions.Status.ConfigDir + filepath, true);
2058  break;
2059  }
2060  else
2061  {
2062  MessageBox.Show("File does not exist, it probably has been deleted for some reason", "SECI - File Not Found");
2063  //Remove it from the list
2064  _recentConfigs.Remove(filepath);
2066  break;
2067  }
2068  }
2069  }
2070 
2071  Seci.Managers.SeciMgr.IsBusy = false;
2072  }
2073 
2074  #endregion
2075 
2076  #region Graphing
2077 
2078  private void setupGraphs(List<Seci.Definitions.GraphDefinition> graphs)
2079  {
2080  deleteGraphs();
2081 
2082  if (graphs != null && graphs.Count > 0)
2083  {
2084  navBar.GraphsAvailable = !Properties.Settings.Default.GraphsOnGenieTab;
2085  setupGraphPanel(graphs.Count);
2086 
2087  foreach (Seci.Definitions.GraphDefinition def in graphs)
2088  {
2090  temp.SetupGraph(def);
2091  _graphs.Add(temp);
2092 
2093  if (Properties.Settings.Default.GraphsOnGenieTab)
2094  {
2095  if (genieGraphPanel.Children.Count < Seci.Definitions.Status.MaxNumberGenieGraphs)
2096  {
2097  genieGraphPanel.Children.Add(temp);
2098  }
2099  else
2100  {
2101  int max = Seci.Definitions.Status.MaxNumberGenieGraphs;
2102  eventViewer.AddMessage("The number of graphs exceeds the maximum allowed (" + max
2103  + "). Only the first " + max + " will be shown.", false);
2104  break;
2105  }
2106  }
2107  else
2108  {
2109  graphPanel.Children.Add(temp);
2110  }
2111  }
2112  }
2113  else
2114  {
2115  navBar.GraphsAvailable = false;
2116  }
2117 
2118  navBar.SetTabsVisibility(_manager);
2119  }
2120 
2121  private void deleteGraphs()
2122  {
2123  _graphs.Clear();
2124  if (Properties.Settings.Default.GraphsOnGenieTab)
2125  {
2126  genieGraphPanel.Children.Clear();
2127  }
2128  else
2129  {
2130  graphPanel.Children.Clear();
2131  }
2132  }
2133 
2134  private void setupGraphPanel(int numGraphs)
2135  {
2136  if (Properties.Settings.Default.GraphsOnGenieTab)
2137  {
2138  genieGraphPanel.Children.Clear();
2139 
2140  //Limit to two columns max
2141  if (numGraphs == 1)
2142  {
2143  genieGraphPanel.Columns = 1;
2144  }
2145  else
2146  {
2147  genieGraphPanel.Columns = 2;
2148  }
2149 
2150  if (numGraphs % 2 == 0)
2151  {
2152  genieGraphPanel.Rows = numGraphs / 2 - 1;
2153  }
2154  else
2155  {
2156  genieGraphPanel.Rows = numGraphs / 2;
2157  }
2158  }
2159  else
2160  {
2161  graphPanel.Children.Clear();
2162 
2163  //Limit to two columns max
2164  if (numGraphs == 1)
2165  {
2166  graphPanel.Columns = 1;
2167  }
2168  else
2169  {
2170  graphPanel.Columns = 2;
2171  }
2172 
2173 
2174  if (numGraphs == 2)
2175  {
2176  graphPanel.Rows = 2;
2177  }
2178  else if (numGraphs % 2 == 0)
2179  {
2180  graphPanel.Rows = numGraphs / 2;
2181  }
2182  else
2183  {
2184  graphPanel.Rows = numGraphs / 2 + 1;
2185  }
2186  }
2187  }
2188 
2190  {
2191  return Seci.Managers.ConfigurationMgr.GetGraphDefinitions();
2192  }
2193 
2194 
2195  private void setDefinitions(List<Seci.Definitions.GraphDefinition> graphs)
2196  {
2197  Seci.Managers.ConfigurationMgr.SetGraphDefinitions(graphs);
2198  }
2199 
2200  #endregion
2201 
2202  private void setupEventHandlers()
2203  {
2204  //Background save
2205  _backgroundSave.DoWork += new DoWorkEventHandler(backgroundSave_DoWork);
2206  _backgroundSave.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundSave_RunWorkerCompleted);
2207 
2208  //Background autosave
2209  _backgroundAutoSave.DoWork += new DoWorkEventHandler(backgroundAutoSave_DoWork);
2210 
2211  //Experiment Details Tab
2212  navBar.OnExperimentDetailsClicked += new EventHandler(navBar_OnExperimentDetailsClicked);
2213 
2214  //Vi Tab
2215  navBar.OnVIsClicked += new EventHandler(navBar_OnVIsClicked);
2216  navBar.OnAddVIClicked += new EventHandler(navBar_OnAddVIClicked);
2217  navBar.OnRemoveVIClicked += new EventHandler(navBar_OnRemoveVIClicked);
2218  navBar.OnConfigureVIClicked += new EventHandler(navBar_OnConfigureVIClicked);
2219  navBar.OnEditTabsClicked += new EventHandler(navBar_OnEditTabsClicked);
2220  navBar.OnConfigureBlocksClicked += new EventHandler(navBar_OnConfigureBlocksClicked);
2221  navBar.OnDisplayBlocksClicked += new EventHandler(navBar_OnDisplayBlocksClicked);
2222  navBar.OnLostTimeClicked += new EventHandler(navBar_OnLostTimeClicked);
2223 
2224  //Open Genie Tab
2225  navBar.OnOpenGenieClicked += new EventHandler(navBar_OnOpenGenieClicked);
2226 
2227  //Dae Tab
2228  navBar.OnDaeClicked += new EventHandler(navBar_OnDaeClicked);
2229 
2230  //Graphs Tab
2231  navBar.OnGraphsClicked += new EventHandler(navBar_OnGraphsClicked);
2232  Seci.Managers.SeciMgr.ClearGraphRequested += new Seci.Managers.SeciMgr.RemotingEventHandler(SeciMgr_ClearGraphRequested);
2233 
2234  //Settings Tab
2235  navBar.OnSettingsClicked += new EventHandler(navBar_OnSettingsClicked);
2236 
2237  //Advanced Options Tab
2238  navBar.OnAdvancedClicked += new EventHandler(navBar_OnAdvancedClicked);
2239 
2240  //Journal Viewer Tab
2241  navBar.OnJournalViewerClicked += new EventHandler(navBar_OnJournalViewerClicked);
2242 
2243  //System Messages Tab
2244  navBar.OnSystemMessagesClicked += new EventHandler(navBar_OnSystemMessagesClicked);
2245 
2246  //Beam Status Tab
2247  navBar.OnBeamStatusClicked += new EventHandler(navBar_OnBeamStatusClicked);
2248 
2249  //Isis Messages Tab
2250  navBar.OnIsisMessagesClicked += new EventHandler(navBar_OnIsisMessagesClicked);
2251 
2252  //Report a Problem Tab
2253  navBar.OnReportProblemClicked += new EventHandler(navBar_OnReportProblemClicked);
2254 
2255  //Help Tab
2256  navBar.OnHelpClicked += new EventHandler(navBar_OnHelpClicked);
2257 
2258  //User Info
2259  userInfo.OnEditUsersClicked += new EventHandler(userInfo_OnEditUsersClicked);
2260 
2261  //Expand and collapse dashboard
2262  _dashboard.OnExpanded += new RoutedEventHandler(dashboard_OnExpanded);
2263  _dashboard.OnUnexpanded += new RoutedEventHandler(dashboard_OnCollapsed);
2264 
2265  //Scripting windows relaunched
2266  OpenGenie1.OnNewScriptingProcessStarted += new EventHandler(OpenGenie_OnNewScriptingProcessStarted);
2267  OpenGenie2.OnNewScriptingProcessStarted += new EventHandler(OpenGenie_OnNewScriptingProcessStarted);
2268 
2269  //Change configuration requested
2270  Seci.Managers.ConfigurationMgr.ConfigChangeRequested += new Seci.Managers.RemotingEventHandler(ConfigurationMgr_ConfigChangeRequested);
2271 
2272  advancedOptions.OnDaeAvailableCheckChanged += new EventHandler(advancedOptions_OnCheckStatusChanged);
2273  advancedOptions.OnVisAvailableCheckChanged += new EventHandler(advancedOptions_OnVisAvailableCheckChanged);
2274  advancedOptions.OnModifyVisCheckChanged += new EventHandler(advancedOptions_OnModifyVisCheckChanged);
2275  advancedOptions.OnUserCanSaveCheckChanged += new EventHandler(advancedOptions_OnUserCanSaveCheckChanged);
2276  advancedOptions.OnAddExeClicked += new EventHandler(advancedOptions_OnAddExeClicked);
2277  advancedOptions.OnRemoveExeClicked += new EventHandler(advancedOptions_OnRemoveExeClicked);
2278  advancedOptions.OnConfigureGraphsClicked += new EventHandler(advancedOptions_OnConfigureGraphsClicked);
2279  advancedOptions.OnUsePythonChanged += new EventHandler(advancedOptions_OnUsePythonChanged);
2280  advancedOptions.OnTwoGeniesCheckChanged += new EventHandler(advancedOptions_OnTwoGeniesCheckChanged);
2281  advancedOptions.OnShowBeamloggerCheckChanged += new EventHandler(advancedOptions_OnShowBeamloggerCheckChanged);
2282  advancedOptions.OnBigFontsDashboardCheckChanged += new EventHandler(advancedOptions_OnBigFontsDashboardCheckChanged);
2283  advancedOptions.OnJournelViewerCheckChanged += new EventHandler(advancedOptions_OnJournelViewerCheckChanged);
2284  advancedOptions.OnWebDashboardEnabledCheckChanged += new EventHandler(advancedOptions_OnWebDashboardEnabledCheckChanged);
2285  advancedOptions.OnWebDashboardShowTitleCheckChanged += new EventHandler(advancedOptions_OnWebDashboardShowTitleCheckChanged);
2286  advancedOptions.OnAddAssocFileClicked += new EventHandler(advancedOptions_OnAddAssocFileClicked);
2287  advancedOptions.OnRemoveAssocFileClicked += new EventHandler(advancedOptions_OnRemoveAssocFileClicked);
2288  advancedOptions.OnAddSubConfigClicked += new EventHandler(advancedOptions_OnAddSubConfigClicked);
2289  advancedOptions.OnRemoveSubConfigClicked += new EventHandler(advancedOptions_OnRemoveSubConfigClicked);
2290  advancedOptions.OnEditSubConfigClicked += new EventHandler(advancedOptions_OnEditSubConfigClicked);
2291  advancedOptions.OnPlotOnGenieTabCheckChanged += new EventHandler(advancedOptions_OnPlotOnGenieTabCheckChanged);
2292  advancedOptions.OnConfigAlertsClicked += new EventHandler(advancedOptions_OnConfigAlertsClicked);
2293  advancedOptions.OnHideTabsClicked += new EventHandler(advancedOptions_OnHideTabsClicked);
2294  advancedOptions.OnShowLostTimeCheckChanged += new EventHandler(advancedOptions_OnShowLostTimeCheckChanged);
2295  //advancedOptions.OnLogBlocksCheckChanged += new EventHandler(advancedOptions_OnLogBlocksCheckChanged);
2296 
2297  errorViewer.OnQuestionAsked += new SeciControls.MessagesWrapper.QuestionHandler(pauseTimers);
2298  errorViewer.OnQuestionAnswered += new SeciControls.MessagesWrapper.QuestionHandler(resumeTimers);
2299 
2300  SeciControls.EventViewer.OnError += new SeciControls.EventViewer.SeciErrorHandler(EventViewer_OnError);
2301  }
2302 
2303  void OpenGenie_OnNewScriptingProcessStarted(object sender, EventArgs e)
2304  {
2305  //Update the saved PIDs
2307  }
2308 
2310  {
2311  if (vars != null && vars.Length == 1)
2312  {
2313  Action action = delegate()
2314  {
2315  Seci.Managers.SeciMgr.IsBusy = true;
2316  openConfig(vars[0], true);
2317  Seci.Managers.SeciMgr.IsBusy = false;
2318  };
2319 
2320  this.Dispatcher.Invoke(action);
2321  }
2322  }
2323 
2324  void SeciMgr_ClearGraphRequested(string[] vars)
2325  {
2326  this.Dispatcher.Invoke(new UpdateGuiDelegate(clearGraphs), null);
2327  }
2328 
2330  {
2331  foreach (SeciControls.Graphing.GraphWrapper graph in _graphs)
2332  {
2333  graph.ClearGraphPoints();
2334  }
2335  }
2336 
2337  void dashboard_OnCollapsed(object sender, EventArgs e)
2338  {
2339  blocksDisplay.Visibility = Visibility.Collapsed;
2340  }
2341 
2342  void dashboard_OnExpanded(object sender, EventArgs e)
2343  {
2344  blocksDisplay.Visibility = Visibility.Visible;
2345  }
2346 
2347  private void EventViewer_OnError(string message)
2348  {
2349  MessageBox.Show(message, "Seci Error", MessageBoxButton.OK, MessageBoxImage.Error);
2350  }
2351 
2352  private Boolean labViewRunning(Boolean force)
2353  {
2354  System.Diagnostics.Process[] procList;
2355 
2356  procList = System.Diagnostics.Process.GetProcessesByName("LabView");
2357 
2358  if (procList.GetLength(0) > 0)
2359  {
2360  _splashscreen.Hide();
2361  if (force || MessageBox.Show("It appears that LabVIEW is running - SECI cannot start if LabVIEW is already running.\n\nWould you like SECI to close LabVIEW and continue loading? \n\nNote: any unsaved changes to VI's will be lost.", "LabVIEW Running!", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
2362  {
2363  try
2364  {
2365  Seci.Helpers.MessageLogger.WriteMessage("UserInterface", "User chose to close LabVIEW");
2366  procList[0].Kill();
2367  _splashscreen.Show();
2368  return false;
2369  }
2370  catch
2371  {
2372  }
2373  }
2374  else
2375  {
2376  return true;
2377  }
2378  }
2379 
2380  return false;
2381  }
2382  }
2383 }
void ConfigurationMgr_ConfigChangeRequested(string[] vars)
This class is used for serializing the graphs for saving in the configuration.
void navBar_OnReportProblemClicked(object sender, EventArgs e)
Interaction logic for PearlDashboard.xaml
void SeciInterface_ValuesUpdated(Boolean timeout)
void navBar_OnSettingsClicked(object sender, EventArgs e)
void navBar_OnAdvancedClicked(object sender, EventArgs e)
void OnRecentConfig_Click(object sender, RoutedEventArgs e)
void advancedOptions_OnTwoGeniesCheckChanged(object sender, EventArgs e)
void menuMgrLogout_Click(object sender, RoutedEventArgs e)
void advancedOptions_OnEditSubConfigClicked(object sender, EventArgs e)
void OpenGenie_OnNewScriptingProcessStarted(object sender, EventArgs e)
delegate void UpdateGuiDelegate()
Interaction logic for GraphWrapper.xaml
void advancedOptions_OnAddExeClicked(object sender, EventArgs e)
void advancedOptions_OnWebDashboardShowTitleCheckChanged(object sender, EventArgs e)
void menuNewCommand(object sender, RoutedEventArgs e)
void backgroundSave_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
Interaction logic for ReloadDialog.xaml
void setupGraphs(List< Seci.Definitions.GraphDefinition > graphs)
void navBar_OnDisplayBlocksClicked(object sender, EventArgs e)
void advancedOptions_OnHideTabsClicked(object sender, EventArgs e)
void advancedOptions_OnRemoveExeClicked(object sender, EventArgs e)
void navBar_OnEditTabsClicked(object sender, EventArgs e)
void dashboard_OnCollapsed(object sender, EventArgs e)
void SeciInterface_OnNewLVMessage(object sender, EventArgs e)
void EventViewer_OnError(string message)
void navBar_OnIsisMessagesClicked(object sender, EventArgs e)
void doSave(Boolean isNewFile, String fullFileName)
void menuExitCommand(object sender, RoutedEventArgs e)
void navBar_OnDaeClicked(object sender, EventArgs e)
void navBar_OnVIsClicked(object sender, EventArgs e)
void advancedOptions_OnBigFontsDashboardCheckChanged(object sender, EventArgs e)
void advancedOptions_OnWebDashboardEnabledCheckChanged(object sender, EventArgs e)
void advancedOptions_OnAddSubConfigClicked(object sender, EventArgs e)
void menuMgrLogin_Click(object sender, RoutedEventArgs e)
void navBar_OnConfigureBlocksClicked(object sender, EventArgs e)
void advancedOptions_OnRemoveSubConfigClicked(object sender, EventArgs e)
Interaction logic for PolarisDashboard.xaml
Interaction logic for AlternativeDashboard.xaml
void advancedOptions_OnUsePythonChanged(object sender, EventArgs e)
void navBar_OnRemoveVIClicked(object sender, EventArgs e)
void menuOpenCommand(object sender, RoutedEventArgs e)
void advancedOptions_OnConfigureGraphsClicked(object sender, EventArgs e)
Forms.SeciSplashscreen _splashscreen
void advancedOptions_OnUserCanSaveCheckChanged(object sender, EventArgs e)
void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
void advancedOptions_OnModifyVisCheckChanged(object sender, EventArgs e)
void navBar_OnJournalViewerClicked(object sender, EventArgs e)
void backgroundSave_DoWork(object sender, DoWorkEventArgs e)
void SeciInterface_OnLVNotThere(object sender, EventArgs e)
Interaction logic for ConfigureAlertSystem.xaml
void UpdateMainGUI(Boolean timeout)
void advancedOptions_OnShowBeamloggerCheckChanged(object sender, EventArgs e)
void advancedOptions_OnShowLostTimeCheckChanged(object sender, EventArgs e)
void backgroundAutoSave_DoWork(object sender, DoWorkEventArgs e)
void SeciMgr_ClearGraphRequested(string[] vars)
void navBar_OnExperimentDetailsClicked(object sender, EventArgs e)
List< SeciControls.Graphing.GraphWrapper > _graphs
void navBar_OnAddVIClicked(object sender, EventArgs e)
Seci.SerialisableList< Seci.LabView.LabViewPanelInfo > getLooseVis()
Interaction logic for SeciUserInterface.xaml
This class contains all the information about a LabVIEW VI that needs to be saved in the configuratio...
Boolean labViewRunning(Boolean force)
void setBeamloggerTabVisibility(Boolean?visible)
void advancedOptions_OnVisAvailableCheckChanged(object sender, EventArgs e)
Interaction logic for SeciLoadingSplashscreen.xaml
void navBar_OnLostTimeClicked(object sender, EventArgs e)
void menuSaveAsCommand(object sender, RoutedEventArgs e)
void navBar_OnOpenGenieClicked(object sender, EventArgs e)
void UserInterface_Loaded(object sender, RoutedEventArgs e)
This class is used to store the message data that is retrieved from the message panel vi...
void userInfo_OnEditUsersClicked(object sender, EventArgs e)
SeciControls.BaseDashboardControl _dashboard
void menuSaveCommand(object sender, RoutedEventArgs e)
void advancedOptions_OnConfigAlertsClicked(object sender, EventArgs e)
void advancedOptions_OnPlotOnGenieTabCheckChanged(object sender, EventArgs e)
void setDefinitions(List< Seci.Definitions.GraphDefinition > graphs)
void navBar_OnSystemMessagesClicked(object sender, EventArgs e)
void navBar_OnGraphsClicked(object sender, EventArgs e)
void advancedOptions_OnAddAssocFileClicked(object sender, EventArgs e)
Interaction logic for SelectSubConfig.xaml
void navBar_OnConfigureVIClicked(object sender, EventArgs e)
void advancedOptions_OnRemoveAssocFileClicked(object sender, EventArgs e)
void advancedOptions_OnCheckStatusChanged(object sender, EventArgs e)
void advancedOptions_OnJournelViewerCheckChanged(object sender, EventArgs e)
void openConfig(String filepath, Boolean restartSeci)
void navBar_OnHelpClicked(object sender, EventArgs e)
delegate void UpdateDashboardDelegate(Boolean timeout)
void dashboard_OnExpanded(object sender, EventArgs e)
List< Seci.Definitions.GraphDefinition > getDefinitions()
Interaction logic for HideTabs.xaml
void navBar_OnBeamStatusClicked(object sender, EventArgs e)
Interaction logic for StandardDashboard.xaml