SECI  1
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events
SECI_GUI.Menu.cs
Go to the documentation of this file.
1 using System;
2 using System.ComponentModel;
3 using System.Data;
4 using System.Drawing;
5 using System.Text;
6 using System.Windows.Forms;
7 using System.Collections.Generic;
8 using System.IO;
9 
10 namespace Sample_Environment_Control_Interface
11 {
12  public partial class SECI_GUI
13  {
14  #region "File"
15 
16  private void newToolStripMenuItem_Click(object sender, EventArgs e)
17  {
18  if (okayToCloseConfig())
19  {
21 
22  if (newConf.ShowDialog() == DialogResult.OK)
23  {
24  GeneralSplashScreen.ShowSplashScreen("Please wait...");
25 
26  RestartSeci();
27 
28  if (newConf.IsComponent)
29  {
30  //Is going to be a component
31  Seci.SeciInterface.Configuration_New(true);
33  }
34  else
35  {
36  //Is going to be a configuration
37  Seci.SeciInterface.Configuration_New(false);
39  }
40 
41  GeneralSplashScreen.CloseForm();
42 
43  //Restart timers
44  Resume_Timers();
45  }
46  }
47  }
48 
49  private void openToolStripMenuItem_Click(object sender, EventArgs e)
50  {
51  if (okayToCloseConfig())
52  {
53  try
54  {
55  openFileDialog1 = new OpenFileDialog();
56  openFileDialog1.InitialDirectory = Seci.SeciInterface.SeciStatus.ConfigDir;
57  openFileDialog1.Filter = "SECI Configuration|*.conf|SECI Component|*.comp";
58 
59  if (openFileDialog1.ShowDialog() == DialogResult.OK)
60  {
61  GeneralSplashScreen.ShowSplashScreen("Opening Configuration...");
62  OpenConfig(openFileDialog1.FileName, true);
63  GeneralSplashScreen.CloseForm();
64  }
65 
66  openFileDialog1.Dispose();
67  }
68  catch (Exception err)
69  {
70  MessageBox.Show("Failed to open configuration/component!\nError message was: " + err.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
72  GeneralSplashScreen.CloseForm();
73  }
74  finally
75  {
76 
77  }
78  }
79  }
80 
81  private void OpenConfig(String filename, Boolean checkVIs)
82  {
83  try
84  {
85  Boolean isConf = !filename.EndsWith(".comp");
86 
87  RestartSeci();
88 
89  //Create new version of config
90  if (!isConf)
91  {
92  Seci.SeciInterface.Configuration_New(true);
93  _currentLayout = new GUILayout();
94  }
95  else
96  {
97  Seci.SeciInterface.Configuration_New(false);
98  }
99 
100  //load the configuration
101  Seci.SeciInterface.Configuration_Open(filename);
102 
103  //Check to see if any VI's were not loaded and handle it
104  if (checkVIs)
105  {
107  }
108 
109  //Set up menu
110  setupGuiForConfiguration(isConf);
111 
112  //If it is a configuration then it may have a layout file
113  if (isConf)
114  {
115  OpenGuiLayout(filename);
116  statusStrip1.BringToFront();
117  }
118 
119  SetUpGroupsMenu();
120  _currentLayout.HideAllGroups();
121 
122  }
123  catch (Exception err)
124  {
125  WriteError("OpenConfig ", err);
126  _errorForm.addSeciMessage(DateTime.Now.Date.ToShortDateString(), DateTime.Now.ToShortTimeString(), "Open Configuration", "Could not open configuration.");
127 
128  //Close current config (as it will be corrupted).
129  closeConfigurationToolStripMenuItem_Click(new Object(), new EventArgs());
130 
131  throw new ArgumentException(err.Message);
132  }
133  finally
134  {
135  //Pause a couple seconds to make sure VIs have loaded
136  System.Threading.Thread.Sleep(2000);
137 
138  //Restart timers
139  Resume_Timers();
140  }
141  }
142 
143  private void OpenGuiLayout(String filename)
144  {
145  //Open the corresponding GUI Layout
146  try
147  {
148  _currentLayout = _currentLayout.Load(filename + ".lay");
149  }
150  catch
151  {
152  MessageBox.Show("Failed to load GUI settings - default settings used!", "Could not load GUI settings!", MessageBoxButtons.OK, MessageBoxIcon.Error);
153  _currentLayout = null;
154  }
155 
156  if (_currentLayout != null)
157  {
158  //Add graphs
159  //Add eventhandlers
160  for (int i = 0; i < _currentLayout.Graphs.Count; ++i)
161  {
162  _currentLayout.Graphs[i].EditClicked += new SECI_Controls.Graph.SECI_Graph.CustomEventsMenuHandler(SECIgraph_EditClicked);
163  }
164 
165  this.Controls.AddRange((SECI_Controls.Graph.SECI_Graph[])_currentLayout.Graphs.ToArray());
166 
167  //Add run infos
168  this.Controls.AddRange((SECI_Controls.Run_Information.Scaling_RunInfo[])_currentLayout.RunInfos.ToArray());
169 
170  //Add Block Viewers
171  this.Controls.AddRange((SECI_Controls.Run_Information.Scaling_BlockViewer[])_currentLayout.BlockViewers.ToArray());
172  }
173  }
174 
175  private void HandleVIsNotLoaded()
176  {
177  //See if any VI's were not loaded because the file could not be found
178  List<String> notloaded = Seci.SeciInterface.LV_GetListVIsNotLoaded();
179 
180  if (notloaded != null)
181  {
182 
183  for (int i = 0; i < notloaded.Count; ++i)
184  {
185  //Ask if user wants SECI to look for it
186  if (MessageBox.Show("The VI " + notloaded[i].ToString() + " could not be found. Would you like SECI to search for the VI?", "VI Not Found!", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes)
187  {
188  String VI = notloaded[i].ToString();
189  String searchResult = FileSearch(Seci.SeciInterface.SeciStatus.LabViewDir, VI.Substring(VI.LastIndexOf('\\') + 1));
190 
191  if (searchResult != null)
192  {
193  //Found something
194  if (MessageBox.Show("Found the VI: " + searchResult + ". Would you like this VI to be loaded as an alternative?", "VI Found!", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes)
195  {
196  Seci.SeciInterface.Configuration_ChangeVIPath(notloaded[i].ToString(), searchResult);
197  //And update gui groups
198  _currentLayout.ChangeVIPath(notloaded[i].ToString(), searchResult);
199  }
200  else
201  {
202  //Remove the panel
203  Seci.SeciInterface.Configuration_RemoveLVPanel(notloaded[i].ToString());
204  //And remove from any gui groups
205  _currentLayout.RemoveVIFromAllGroups(notloaded[i].ToString());
206  }
207  }
208  else
209  {
210  //Could not find it!
211  MessageBox.Show("Could not find an alternative VI.", "VI Not Found!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
212 
213  //Remove the panel
214  Seci.SeciInterface.Configuration_RemoveLVPanel(notloaded[i].ToString());
215  //And remove from any gui groups
216  _currentLayout.RemoveVIFromAllGroups(notloaded[i].ToString());
217  }
218  }
219  else
220  {
221  //Remove the panel
222  Seci.SeciInterface.Configuration_RemoveLVPanel(notloaded[i].ToString());
223  //And remove from any gui groups
224  _currentLayout.RemoveVIFromAllGroups(notloaded[i].ToString());
225  }
226  }
227  }
228  }
229 
230  //Search for VI's
231  private String FileSearch(String sDir, String filename)
232  {
233  try
234  {
235  //Search the starting directory first
236  foreach (String f in Directory.GetFiles(sDir, filename))
237  {
238  return sDir + "\\" + filename;
239  }
240 
241  //Then try the sub-directories
242  foreach (string d in Directory.GetDirectories(sDir))
243  {
244  //Search sub-directory, if not hidden
245  DirectoryInfo di = new DirectoryInfo(d);
246 
247  if (di.Attributes != FileAttributes.Hidden)
248  {
249  String result = FileSearch(d, filename);
250 
251  if (result != null)
252  {
253  //Found it
254  return result;
255  }
256  }
257  }
258  }
259  catch
260  {
261 
262  }
263 
264  //could not find it
265  return null;
266 
267  }
268 
269  private void saveToolStripMenuItem_Click(object sender, EventArgs e)
270  {
271  if (String.IsNullOrEmpty(Seci.SeciInterface.ConfigurationName))
272  {
273  //Use saveAs instead
275  }
276  else
277  {
278  //Check user has permission to save
279  Boolean okayToSave = false;
280 
281  if (Seci.SeciInterface.ConfigurationName.ToLower().EndsWith(".conf"))
282  {
283  okayToSave = Seci.SeciInterface.Configuration_AllowedToSave(true, _manager);
284  }
285  else if (Seci.SeciInterface.ConfigurationName.ToLower().EndsWith(".comp"))
286  {
287  okayToSave = Seci.SeciInterface.Configuration_AllowedToSave(false, _manager);
288  }
289 
290  if (okayToSave)
291  {
292  //Call background save
293  toolStripStatusLabel.Text = "Saving...";
294 
295  try
296  {
297  backgroundSave.RunWorkerAsync();
298  }
299  catch (Exception err)
300  {
301  WriteError("saveConfig ", err);
302  }
303  }
304  else
305  {
306  MessageBox.Show("Sorry, you must be logged in with the manager account to overwrite this configuration!", "Cannot Overwrite!", MessageBoxButtons.OK, MessageBoxIcon.Error);
307  }
308 
309  }
310 
311  }
312 
313  private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
314  {
315  if (Seci.SeciInterface.IsAComponent == false)
316  {
317  //Save as a configuration
318  saveFileDialog1 = new SaveFileDialog();
319  saveFileDialog1.InitialDirectory = Seci.SeciInterface.SeciStatus.ConfigDir;
320  saveFileDialog1.Filter = "SECI Configuration|*.conf";
321  saveFileDialog1.InitialDirectory = Seci.SeciInterface.SeciStatus.ConfigDir;
322  }
323  else
324  {
325  //Save as a component
326  saveFileDialog1 = new SaveFileDialog();
327  saveFileDialog1.InitialDirectory = Seci.SeciInterface.SeciStatus.CompDir;
328  saveFileDialog1.Filter = "SECI Component|*.comp";
329  saveFileDialog1.InitialDirectory = Seci.SeciInterface.SeciStatus.CompDir;
330  }
331 
332  //Save it
333  if (saveFileDialog1.ShowDialog() == DialogResult.OK)
334  {
335  String fileName;
336 
337  //Set config name
338  fileName = saveFileDialog1.FileName.Substring(saveFileDialog1.FileName.LastIndexOf("\\") + 1);
339 
340  if (saveFileDialog1.FileName.StartsWith(Seci.SeciInterface.SeciStatus.ConfigDir))
341  {
342  //Check user has permission to save
343  if (Seci.SeciInterface.Configuration_AllowedToSave(true, _manager))
344  {
345  String oldName = Seci.SeciInterface.ConfigurationName;
346  Seci.SeciInterface.ConfigurationName = fileName;
347 
348  //Call background save
349  toolStripStatusLabel.Text = "Saving...";
350 
351  try
352  {
353  backgroundSave.RunWorkerAsync();
354  }
355  catch (Exception err)
356  {
357  Seci.SeciInterface.ConfigurationName = oldName;
358  WriteError("saveConfig ", err);
359  }
360  }
361  else
362  {
363  MessageBox.Show("Sorry, you must be logged in with the manager account to overwrite this configuration!", "Cannot Overwrite!", MessageBoxButtons.OK, MessageBoxIcon.Error);
364  }
365  }
366  else
367  {
368  MessageBox.Show("Configurations and components must be saved in their specified directories!", "Trying to Save in wrong location", MessageBoxButtons.OK, MessageBoxIcon.Error);
369 
370  }
371  }
372  }
373 
374  private void closeConfigurationToolStripMenuItem_Click(object sender, EventArgs e)
375  {
376  if (okayToCloseConfig())
377  {
378  GeneralSplashScreen.ShowSplashScreen("Closing Configuration...");
379  RestartSeci();
380 
381  Seci.SeciInterface.Configuration_New(false);
382 
384 
385  //Restart timers
386  Resume_Timers();
387 
388  GeneralSplashScreen.CloseForm();
389  }
390  }
391 
392 
393  private void RestartSeci()
394  {
395  //Pause updating and error timers
396  Pause_Timers();
397 
398  //Close current config
399  Seci.SeciInterface.Configuration_Close();
400 
401  //Clear layout
402  RemoveControls();
403 
404  //Clear LV messages
405  _lvErrorMessages.Clear();
406  _errorForm.addLabViewMessages(_lvErrorMessages);
407  toolStripErrorLabel.Visible = false;
408  toolStripQuestionLabel.Visible = false;
409 
410  //And reinitialise LabView
411  Seci.SeciInterface.LV_Initialise(true);
412 
413  //Return standard VIs visibility to their last known values
415  }
416 
417 
418  private void exitToolStripMenuItem_Click(object sender, EventArgs e)
419  {
420  this.Close();
421  }
422 
424  {
425  if (showDAEVIToolStripMenuItem.Checked)
426  {
427  Seci.SeciInterface.DAE_ShowVI();
428  }
429 
431  {
432  Seci.SeciInterface.BeamLogger_ShowVI();
433  }
434 
436  {
437  Seci.SeciInterface.LVQ_ShowVI();
438  }
439  }
440 
441  private Boolean okayToCloseConfig()
442  {
443  if (_changesMade || Seci.SeciInterface.Assoc_AnyModifications())
444  {
445  if (MessageBox.Show("There are unsaved changes to the current configuration - are you sure you wish to close it?", "Unsaved Changes!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
446  {
447  return false;
448  }
449  }
450 
451  return true;
452  }
453 
454  #endregion
455 
456  #region "Help"
457 
458  private void contentsToolStripMenuItem_Click(object sender, EventArgs e)
459  {
460  if (!_helpOpen)
461  {
462  help = new Dialogs.Help.HelpForm();
463  help.FormClosed += new FormClosedEventHandler(help_FormClosed);
464  help.Show();
465  _helpOpen = true;
466  }
467  else
468  {
469  help.BringToFront();
470  }
471  }
472 
473  private void help_FormClosed(object sender, FormClosedEventArgs e)
474  {
475  _helpOpen = false;
476  }
477 
478  private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
479  {
481  about.ShowDialog();
482  }
483 
484  private void reportAProblemToolStripMenuItem_Click(object sender, EventArgs e)
485  {
486  //Launch bugzilla in a browser
487  System.Diagnostics.Process p = new System.Diagnostics.Process();
488  p.StartInfo.FileName = "iexplore.exe";
489  p.StartInfo.Arguments = GuiSettings.BugzillaUrl;
490  p.Start();
491  }
492 
493  private void mCRNewsMenuItem_Click(object sender, EventArgs e)
494  {
495  //Launch MCR news in a browser
496  System.Diagnostics.Process p = new System.Diagnostics.Process();
497  p.StartInfo.FileName = "iexplore.exe";
498  p.StartInfo.Arguments = GuiSettings.McrUrl;
499  p.Start();
500  }
501 
502  #endregion
503 
504  #region "LabView"
505 
506  //Add VI
507  private void addVIMenuItem_Click(object sender, EventArgs e)
508  {
509  try
510  {
511  Dialogs.VI.AddVI addVI = new Dialogs.VI.AddVI();
512  if (addVI.ShowDialog() == DialogResult.OK)
513  {
514  _changesMade = true;
515  backgroundAutosave.RunWorkerAsync();
516  }
517  }
518  catch (FileNotFoundException err)
519  {
520  WriteError("AddVI ", err);
521  _errorForm.addSeciMessage(DateTime.Now.Date.ToShortDateString(), DateTime.Now.ToShortTimeString(), "Add VI", err.Message);
522  MessageBox.Show("Could not extract information from llb file! " + err.Message + "!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
523  }
524  catch (Exception err)
525  {
526  WriteError("AddVI ", err);
527  _errorForm.addSeciMessage(DateTime.Now.Date.ToShortDateString(), DateTime.Now.ToShortTimeString(), "Add VI", "Could not add VI.");
528  MessageBox.Show("Could not add VI!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
529  }
530 
531  }
532 
533  //Remove VIs
534  private void removeVIMenuItem_Click(object sender, EventArgs e)
535  {
536  Dialogs.VI.RemoveVI removeVI = new Dialogs.VI.RemoveVI();
537  if (removeVI.ShowDialog() == DialogResult.OK)
538  {
539  _changesMade = true;
540  backgroundAutosave.RunWorkerAsync();
541  }
542  _currentLayout.CheckGroupsValid();
543  }
544 
545  //Set VI properties
546  private void setVIPropertiesMenuItem_Click(object sender, EventArgs e)
547  {
549  if (VIprop.ShowDialog() == DialogResult.OK)
550  {
551  _changesMade = true;
552  backgroundAutosave.RunWorkerAsync();
553  }
554  }
555 
556  //Show DAE VI (Just for debugging, may be removed/disabled in a release build)
557  private void showDAEVIToolStripMenuItem_Click(object sender, EventArgs e)
558  {
559  if (!showDAEVIToolStripMenuItem.Checked)
560  {
561  Seci.SeciInterface.DAE_ShowVI();
562  showDAEVIToolStripMenuItem.Checked = true;
563  }
564  else
565  {
566  Seci.SeciInterface.DAE_HideVI();
567  showDAEVIToolStripMenuItem.Checked = false;
568  }
569  }
570 
571  //Show Error message VI (Just for debugging, will be removed/disabled in a release build)
572  private void showHideErrorPanelToolStripMenuItem_Click(object sender, EventArgs e)
573  {
575  {
576  Seci.SeciInterface.LVQ_ShowVI();
577  showHideErrorPanelToolStripMenuItem.Checked = true;
578  }
579  else
580  {
581  Seci.SeciInterface.LVQ_HideVI();
582  showHideErrorPanelToolStripMenuItem.Checked = false;
583  }
584  }
585 
586  //Show BeamLogger VI
587  private void showHideBeamLoggerToolStripMenuItem_Click(object sender, EventArgs e)
588  {
590  {
591  Seci.SeciInterface.BeamLogger_ShowVI();
592  showHideBeamLoggerToolStripMenuItem.Checked = true;
593  }
594  else
595  {
596  Seci.SeciInterface.BeamLogger_HideVI();
597  showHideBeamLoggerToolStripMenuItem.Checked = false;
598  }
599  }
600 
601  //Show DAE Monitor VI - if present
602  private void showHideDAEMonitorToolStripMenuItem_Click(object sender, EventArgs e)
603  {
605  {
606  Seci.SeciInterface.DAEMonitor_ShowVI();
607  showHideDAEMonitorToolStripMenuItem.Checked = true;
608  }
609  else
610  {
611  Seci.SeciInterface.DAEMonitor_HideVI();
612  showHideDAEMonitorToolStripMenuItem.Checked = false;
613  }
614  }
615 
616  private void showHideSampleParametersToolStripMenuItem_Click(object sender, EventArgs e)
617  {
619  {
620  Seci.SeciInterface.SampleParameters_ShowVI();
621  showHideSampleParametersToolStripMenuItem.Checked = true;
622  }
623  else
624  {
625  Seci.SeciInterface.SampleParameters_HideVI();
626  showHideSampleParametersToolStripMenuItem.Checked = false;
627  }
628  }
629 
630  private void showHideBeamlineParametersToolStripMenuItem_Click(object sender, EventArgs e)
631  {
633  {
634  Seci.SeciInterface.BeamlineParameters_ShowVI();
635  showHideBeamlineParametersToolStripMenuItem.Checked = true;
636  }
637  else
638  {
639  Seci.SeciInterface.BeamlineParameters_HideVI();
640  showHideBeamlineParametersToolStripMenuItem.Checked = false;
641  }
642  }
643 
644  private void showHideUserDetailsToolStripMenuItem_Click(object sender, EventArgs e)
645  {
647  {
648  Seci.SeciInterface.UserDetails_ShowVI();
649  showHideUserDetailsToolStripMenuItem.Checked = true;
650  }
651  else
652  {
653  Seci.SeciInterface.UserDetails_HideVI();
654  showHideUserDetailsToolStripMenuItem.Checked = false;
655  }
656  }
657 
658  #endregion
659 
660  #region "Components"
661 
662  //Add components (only works for configs)
663  private void addComponentMenuItem_Click(object sender, EventArgs e)
664  {
665  if (!Seci.SeciInterface.IsAComponent)
666  {
668 
669  if (add.ShowDialog() == DialogResult.OK)
670  {
671  _changesMade = true;
672  backgroundAutosave.RunWorkerAsync();
673  }
674  }
675  else
676  {
677  MessageBox.Show("Cannot add another component to a component! Components can only be added to configurations.", "Cannot Add Component!", MessageBoxButtons.OK, MessageBoxIcon.Error);
678  }
679 
680  }
681 
682  //Remove components (only works for configs)
683  private void removeComponentMenuItem_Click(object sender, EventArgs e)
684  {
685  if (!Seci.SeciInterface.IsAComponent && Seci.SeciInterface.Components_GetNames().Count > 0)
686  {
687  //Pause updating
688  Pause_Timers();
689 
691  if (removeComp.ShowDialog() == DialogResult.OK)
692  {
693  _changesMade = true;
694  backgroundAutosave.RunWorkerAsync();
695  }
696 
697  _currentLayout.CheckGroupsValid();
698 
699  //Resume updating
700  Resume_Timers();
701  }
702  else
703  {
704  MessageBox.Show("There are no components to remove!", "No Components!", MessageBoxButtons.OK, MessageBoxIcon.Error);
705  }
706 
707  }
708 
709  //mergeComponent (only works for configs)
710  private void mergeComponentMenuItem_Click(object sender, EventArgs e)
711  {
712  //This will merge the components so they are now part of the config.
713  //Hence any changes to the component at a later date will not affect this config
714  if (!Seci.SeciInterface.IsAComponent && Seci.SeciInterface.Components_GetNames().Count > 0)
715  {
716  Dialogs.Config.MergeComponents merge = new Dialogs.Config.MergeComponents();
717 
718  if (merge.ShowDialog() == DialogResult.OK)
719  {
720  _changesMade = true;
721  backgroundAutosave.RunWorkerAsync();
722  }
723  }
724  else
725  {
726  if (Seci.SeciInterface.IsAComponent)
727  {
728  MessageBox.Show("This function is only available for configurations, not components!", "Not a Configuration!", MessageBoxButtons.OK, MessageBoxIcon.Error);
729  }
730  else if (Seci.SeciInterface.Components_GetNames().Count == 0)
731  {
732  MessageBox.Show("There are no components to merge!", "No Components!", MessageBoxButtons.OK, MessageBoxIcon.Error);
733  }
734  }
735  }
736 
737  private void setLoadOrderToolStripMenuItem_Click(object sender, EventArgs e)
738  {
740 
741  if (order.ShowDialog() == DialogResult.OK)
742  {
743  _changesMade = true;
744  backgroundAutosave.RunWorkerAsync();
745  }
746  }
747 
748  #endregion
749 
750  #region "Blocks"
751 
752  private void configureBlocksToolStripMenuItem_Click(object sender, EventArgs e)
753  {
755  if (confBlocks.ShowDialog() == DialogResult.OK)
756  {
757  _changesMade = true;
758  backgroundAutosave.RunWorkerAsync();
759  }
760  }
761 
762  private void runControlEditorToolStripMenuItem_Click(object sender, EventArgs e)
763  {
765  RCV.ShowDialog();
766  }
767 
768  #endregion
769 
770  #region "Associated Files"
771 
772  private void addFilesMenuItem_Click(object sender, EventArgs e)
773  {
775 
776  if (addfiles.ShowDialog() == DialogResult.OK)
777  {
778  _changesMade = true;
779  backgroundAutosave.RunWorkerAsync();
780  }
781  }
782 
783  private void removeFilesMenuItem_Click(object sender, EventArgs e)
784  {
786  if (removefiles.ShowDialog() == DialogResult.OK)
787  {
788  _changesMade = true;
789  backgroundAutosave.RunWorkerAsync();
790  }
791  }
792 
793  #endregion
794 
795  #region "Programmes"
796 
797  private void addProgMenuItem_Click(object sender, EventArgs e)
798  {
800 
801  if (add.ShowDialog() == DialogResult.OK)
802  {
803  _changesMade = true;
804  backgroundAutosave.RunWorkerAsync();
805  }
806  }
807 
808  private void removeProgrammeToolStripMenuItem_Click(object sender, EventArgs e)
809  {
811 
812  if (remove.ShowDialog() == DialogResult.OK)
813  {
814  _changesMade = true;
815  backgroundAutosave.RunWorkerAsync();
816  }
817  }
818 
819  #endregion
820 
821  #region "Configuration"
822 
823  private void addConfigurationMenuItem_Click(object sender, EventArgs e)
824  {
825  if (!Seci.SeciInterface.IsAComponent)
826  {
828 
829  Pause_Timers();
830 
831  try
832  {
833  if (addConf.ShowDialog() == DialogResult.OK)
834  {
835  _changesMade = true;
836  backgroundAutosave.RunWorkerAsync();
837  }
838  }
839  catch (Exception err)
840  {
841  WriteError("addConfiguration ", err);
842  }
843 
844  Resume_Timers();
845  }
846  else
847  {
848  MessageBox.Show("Cannot add configuration to a component!", "Cannot Add Configuration!", MessageBoxButtons.OK, MessageBoxIcon.Error);
849  }
850  }
851 
852  #endregion
853 
854  #region "Messages"
855 
856  private void showSECIMessagesMenuItem_Click(object sender, EventArgs e)
857  {
858  _errorForm.Show();
859  }
860 
861  #endregion
862 
863  #region "Manager"
864 
865  private void logInToolStripMenuItem_Click(object sender, EventArgs e)
866  {
868 
869  if (login.ShowDialog() == DialogResult.OK)
870  {
872  }
873  }
874 
875  private void logOutToolStripMenuItem_Click(object sender, EventArgs e)
876  {
877  setupGuiBasedOnAccount(false);
878  }
879  #endregion
880 
881  #region "Setup GUI"
882 
883  private void setupGuiForSeciStartup()
884  {
885  //Sort out menus
886  saveToolStripMenuItem.Enabled = false;
887  saveAsToolStripMenuItem.Enabled = false;
888  closeConfigurationToolStripMenuItem.Enabled = false;
889  configurationToolStripMenuItem.Enabled = false;
890  layoutToolStripMenuItem.Enabled = false;
891 
892  Seci.SeciInterface.OpenGenie_Show();
893  }
894 
895  private void setupGuiBasedOnAccount(bool isManager)
896  {
897  _manager = isManager;
898  logInToolStripMenuItem.Enabled = !isManager;
899  logOutToolStripMenuItem.Enabled = isManager;
900 
901  if (isManager)
902  {
903  toolStripManagerLbl.Text = "Logged in as Manager";
904  }
905  else
906  {
907  toolStripManagerLbl.Text = "";
908  }
909  }
910 
911  private void setupGuiForConfiguration(Boolean isConf)
912  {
913  saveToolStripMenuItem.Enabled = true;
914  saveAsToolStripMenuItem.Enabled = true;
915  closeConfigurationToolStripMenuItem.Enabled = true;
916  configurationToolStripMenuItem.Enabled = true;
917 
918  layoutToolStripMenuItem.Enabled = isConf;
919  componentsToolStripMenuItem.Enabled = isConf;
920  configurationsToolStripMenuItem.Enabled = isConf;
921 
922  Seci.SeciInterface.OpenGenie_Show();
923  }
924 
925  #endregion
926 
927  #region "Layout"
928 
929  private void editGroupsToolStripMenuItem_Click(object sender, EventArgs e)
930  {
932  if (group.ShowDialog() == DialogResult.OK)
933  {
934  _changesMade = true;
935  backgroundAutosave.RunWorkerAsync();
936  }
937 
938  SetUpGroupsMenu();
939  }
940 
941  private void SetUpGroupsMenu()
942  {
943  List<ToolStripMenuItem> menuitems = new List<ToolStripMenuItem>();
944 
945  for (int i = 0; i < _currentLayout.Groups.GetLength(0); ++i)
946  {
947  menuitems.Add(new ToolStripMenuItem(_currentLayout.Groups[i].GroupName, null, new System.EventHandler(this.ShowGroup_Click), _currentLayout.Groups[i].GroupName));
948  }
949 
950  menuitems.Add(new ToolStripMenuItem("Hide All Pages", null, new System.EventHandler(this.ShowGroup_Click), "Hide All Groups"));
951 
952  if (menuitems.Count > 1)
953  {
954  //SelectButton
955  selectPageButton1.Visible = true;
956  selectPageButton1.DropDown.Items.Clear();
957  selectPageButton1.DropDown.Items.AddRange(menuitems.ToArray());
958  }
959  else
960  {
961  selectPageButton1.Visible = false;
962  }
963  }
964 
965  private void ShowGroup_Click(object sender, EventArgs e)
966  {
967 
968  if (((ToolStripMenuItem)sender).ToString() == "Hide All Pages")
969  {
970  _currentLayout.HideAllGroups();
971  }
972  else
973  {
974  _currentLayout.HideAllGroups();
975  _currentLayout.ShowGroup(((ToolStripMenuItem)sender).Name);
976  }
977  }
978 
979  private void addGraphToolStripMenuItem_Click(object sender, EventArgs e)
980  {
981  SECI_Controls.Graph.AddEditGraph add = new SECI_Controls.Graph.AddEditGraph(Seci.SeciInterface.Blocks_GetAllBlocksAsCollection());
982 
983  if (add.ShowDialog() == DialogResult.OK)
984  {
985  SECI_Controls.Graph.SECI_Graph newgraph = new SECI_Controls.Graph.SECI_Graph();
986 
987  newgraph.Graph = add.Graph;
988 
989  newgraph.EditClicked += new SECI_Controls.Graph.SECI_Graph.CustomEventsMenuHandler(SECIgraph_EditClicked);
990 
991  this.Controls.Add(newgraph);
992  this.Controls[this.Controls.Count - 1].BringToFront();
993  statusStrip1.BringToFront();
994  _currentLayout.Graphs.Add(newgraph);
995  _changesMade = true;
996  backgroundAutosave.RunWorkerAsync();
997  }
998  }
999 
1000  private void runInformationSetupToolStripMenuItem_Click(object sender, EventArgs e)
1001  {
1003 
1004  if (setup.ShowDialog() == DialogResult.OK)
1005  {
1006  //Remove the old controls
1007  for (int i = 0; i < CurrentLayout.RunInfos.Count; ++i)
1008  {
1009  this.Controls.Remove(CurrentLayout.RunInfos[i]);
1010  }
1011 
1012  CurrentLayout.RunInfos = setup.current;
1013 
1014  //Add the new controls
1015  int count = 0;
1016  for (int i = 0; i < CurrentLayout.RunInfos.Count; ++i)
1017  {
1018  if (CurrentLayout.RunInfos[i].Location.X == 0 && CurrentLayout.RunInfos[i].Location.Y == 0)
1019  {
1020  CurrentLayout.RunInfos[i].Location = new Point(400 + 10 * count, 400 + 10 * count);
1021  ++count;
1022  }
1023 
1024  this.Controls.Add(CurrentLayout.RunInfos[i]);
1025  this.Controls[this.Controls.Count - 1].BringToFront();
1026  statusStrip1.BringToFront();
1027  }
1028 
1029  _changesMade = true;
1030  backgroundAutosave.RunWorkerAsync();
1031  }
1032  }
1033 
1034  private void blockViewersSetupToolStripMenuItem_Click(object sender, EventArgs e)
1035  {
1037 
1038  if (setup.ShowDialog() == DialogResult.OK)
1039  {
1040  //Remove the old controls
1041  for (int i = 0; i < CurrentLayout.BlockViewers.Count; ++i)
1042  {
1043  this.Controls.Remove(CurrentLayout.BlockViewers[i]);
1044  }
1045 
1046  CurrentLayout.BlockViewers = setup.current;
1047 
1048  //Add the new controls
1049  int count = 0;
1050  for (int i = 0; i < CurrentLayout.BlockViewers.Count; ++i)
1051  {
1052  if (CurrentLayout.BlockViewers[i].Location.X == 0 && CurrentLayout.BlockViewers[i].Location.Y == 0)
1053  {
1054  CurrentLayout.BlockViewers[i].Location = new Point(400 + 10 * count, 400 + 10 * count);
1055  ++count;
1056  }
1057 
1058  this.Controls.Add(CurrentLayout.BlockViewers[i]);
1059  this.Controls[this.Controls.Count - 1].BringToFront();
1060  statusStrip1.BringToFront();
1061  }
1062  _changesMade = true;
1063  backgroundAutosave.RunWorkerAsync();
1064  }
1065  }
1066 
1067  private void SECIgraph_EditClicked(SECI_Controls.Graph.SECI_Graph sender)
1068  {
1069  SECI_Controls.Graph.AddEditGraph edit = new SECI_Controls.Graph.AddEditGraph(Seci.SeciInterface.Blocks_GetAllBlocksAsCollection());
1070  edit.Graph = sender.Graph;
1071 
1072  if (edit.ShowDialog() == DialogResult.OK)
1073  {
1074  sender.Graph = edit.Graph;
1075  sender.ClearAndRecreate();
1076  _changesMade = true;
1077  backgroundAutosave.RunWorkerAsync();
1078  }
1079 
1080  }
1081 
1082  private void deleteGraphToolStripMenuItem_Click(object sender, EventArgs e)
1083  {
1084  SECI_Controls.Graph.DeleteGraph del = new SECI_Controls.Graph.DeleteGraph();
1085  del.Graphs = (SECI_Controls.Graph.SECI_Graph[])_currentLayout.Graphs.ToArray();
1086 
1087  if (del.ShowDialog() == DialogResult.OK)
1088  {
1089  this.Controls.Remove(_currentLayout.Graphs[del.DeleteIndex]);
1090  _currentLayout.Graphs.RemoveAt(del.DeleteIndex);
1091  _changesMade = true;
1092  backgroundAutosave.RunWorkerAsync();
1093  }
1094  }
1095 
1096  private void RemoveControls()
1097  {
1098  if (_currentLayout.Graphs != null)
1099  {
1100  for (int i = 0; i < _currentLayout.Graphs.Count; ++i)
1101  {
1102  this.Controls.Remove(_currentLayout.Graphs[i]);
1103  }
1104  }
1105 
1106  if (_currentLayout.RunInfos != null)
1107  {
1108  for (int i = 0; i < _currentLayout.RunInfos.Count; ++i)
1109  {
1110  this.Controls.Remove(_currentLayout.RunInfos[i]);
1111  }
1112  }
1113 
1114  if (_currentLayout.BlockViewers != null)
1115  {
1116  for (int i = 0; i < _currentLayout.BlockViewers.Count; ++i)
1117  {
1118  this.Controls.Remove(_currentLayout.BlockViewers[i]);
1119  }
1120  }
1121 
1122  _currentLayout = new GUILayout();
1123  SetUpGroupsMenu();
1124  }
1125 
1126  #endregion
1127 
1128  }
1129 }
void setLoadOrderToolStripMenuItem_Click(object sender, EventArgs e)
System.Windows.Forms.ToolStripMenuItem showHideBeamlineParametersToolStripMenuItem
void SECIgraph_EditClicked(SECI_Controls.Graph.SECI_Graph sender)
void showDAEVIToolStripMenuItem_Click(object sender, EventArgs e)
System.Windows.Forms.ToolStripMenuItem showHideUserDetailsToolStripMenuItem
void addProgMenuItem_Click(object sender, EventArgs e)
void setVIPropertiesMenuItem_Click(object sender, EventArgs e)
Seci.SerialisableList< SECI_Controls.Run_Information.Scaling_BlockViewer > BlockViewers
Definition: GUILayout.cs:48
Seci.SerialisableList< SECI_Controls.Graph.SECI_Graph > Graphs
Definition: GUILayout.cs:51
System.Windows.Forms.ToolStripMenuItem showHideSampleParametersToolStripMenuItem
String FileSearch(String sDir, String filename)
void blockViewersSetupToolStripMenuItem_Click(object sender, EventArgs e)
System.Windows.Forms.ToolStripMenuItem showHideDAEMonitorToolStripMenuItem
void removeProgrammeToolStripMenuItem_Click(object sender, EventArgs e)
System.Windows.Forms.ToolStripMenuItem showHideErrorPanelToolStripMenuItem
void ShowGroup_Click(object sender, EventArgs e)
Seci.SerialisableList< SECI_Controls.Run_Information.Scaling_RunInfo > RunInfos
Definition: GUILayout.cs:45
void newToolStripMenuItem_Click(object sender, EventArgs e)
void reportAProblemToolStripMenuItem_Click(object sender, EventArgs e)
void editGroupsToolStripMenuItem_Click(object sender, EventArgs e)
void contentsToolStripMenuItem_Click(object sender, EventArgs e)
void mergeComponentMenuItem_Click(object sender, EventArgs e)
Seci.SerialisableList< Seci.LabView.MessageInfo > _lvErrorMessages
Definition: SECI_GUI.cs:22
void showHideUserDetailsToolStripMenuItem_Click(object sender, EventArgs e)
void showHideBeamLoggerToolStripMenuItem_Click(object sender, EventArgs e)
void showHideBeamlineParametersToolStripMenuItem_Click(object sender, EventArgs e)
void OpenConfig(String filename, Boolean checkVIs)
System.Windows.Forms.SaveFileDialog saveFileDialog1
void addComponentMenuItem_Click(object sender, EventArgs e)
void mCRNewsMenuItem_Click(object sender, EventArgs e)
void WriteError(String source, Exception e)
Definition: SECI_GUI.cs:311
void showSECIMessagesMenuItem_Click(object sender, EventArgs e)
System.Windows.Forms.ToolStripMenuItem showHideBeamLoggerToolStripMenuItem
void removeVIMenuItem_Click(object sender, EventArgs e)
void closeConfigurationToolStripMenuItem_Click(object sender, EventArgs e)
void showHideDAEMonitorToolStripMenuItem_Click(object sender, EventArgs e)
void runControlEditorToolStripMenuItem_Click(object sender, EventArgs e)
void removeFilesMenuItem_Click(object sender, EventArgs e)
void addVIMenuItem_Click(object sender, EventArgs e)
System.Windows.Forms.ToolStripMenuItem showDAEVIToolStripMenuItem
void addConfigurationMenuItem_Click(object sender, EventArgs e)
void showHideErrorPanelToolStripMenuItem_Click(object sender, EventArgs e)
void addFilesMenuItem_Click(object sender, EventArgs e)
void aboutToolStripMenuItem_Click(object sender, EventArgs e)
void openToolStripMenuItem_Click(object sender, EventArgs e)
void removeComponentMenuItem_Click(object sender, EventArgs e)
void deleteGraphToolStripMenuItem_Click(object sender, EventArgs e)
void runInformationSetupToolStripMenuItem_Click(object sender, EventArgs e)
void logOutToolStripMenuItem_Click(object sender, EventArgs e)
void logInToolStripMenuItem_Click(object sender, EventArgs e)
void exitToolStripMenuItem_Click(object sender, EventArgs e)
void help_FormClosed(object sender, FormClosedEventArgs e)
System.Windows.Forms.OpenFileDialog openFileDialog1
void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
void showHideSampleParametersToolStripMenuItem_Click(object sender, EventArgs e)
void saveToolStripMenuItem_Click(object sender, EventArgs e)
void addGraphToolStripMenuItem_Click(object sender, EventArgs e)
void configureBlocksToolStripMenuItem_Click(object sender, EventArgs e)