SECI  1
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events
GUILayout.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections;
3 using System.Collections.Generic;
4 using System.Text;
5 using System.IO;
6 using System.Xml;
7 using System.Xml.Serialization;
8 
9 namespace Sample_Environment_Control_Interface
10 {
21  public class GUILayout
22  {
24  private List<Group> _groups = new List<Group>();
25 
27  private Seci.SerialisableList<SECI_Controls.Run_Information.Scaling_RunInfo> _runInfos
28  = new Seci.SerialisableList<SECI_Controls.Run_Information.Scaling_RunInfo>();
29 
31  private Seci.SerialisableList<SECI_Controls.Run_Information.Scaling_BlockViewer> _blockViewers
32  = new Seci.SerialisableList<SECI_Controls.Run_Information.Scaling_BlockViewer>();
33 
35  private Seci.SerialisableList<SECI_Controls.Graph.SECI_Graph> _graphs
36  = new Seci.SerialisableList<SECI_Controls.Graph.SECI_Graph>();
37 
38  public Group[] Groups
39  {
40  get { return _groups.ToArray(); }
41  set { _groups.Clear(); _groups.AddRange(value); }
42  }
43 
44  public Seci.SerialisableList<SECI_Controls.Run_Information.Scaling_RunInfo> RunInfos
45  { get { return _runInfos; } set { _runInfos = value; } }
46 
47  public Seci.SerialisableList<SECI_Controls.Run_Information.Scaling_BlockViewer> BlockViewers
48  { get { return _blockViewers; } set { _blockViewers = value; } }
49 
50  public Seci.SerialisableList<SECI_Controls.Graph.SECI_Graph> Graphs
51  { get { return _graphs; } set { _graphs = value; } }
52 
53  #region "Load/Save"
54 
60  public void Save(String fileName)
61  {
62  FileInfo fi = new FileInfo(fileName);
63 
64  if (fi.Exists && fi.IsReadOnly)
65  {
66  fi.IsReadOnly = false;
67  }
68 
69  //Create the stream
70  FileStream stream = new FileStream(fileName, FileMode.Create);
71 
72  try
73  {
74  //Serialise the config
75  XmlSerializer serialize = new XmlSerializer(typeof(GUILayout));
76  serialize.Serialize(stream, this);
77 
78  }
79  catch (Exception e)
80  {
81  //throw error up to next level
82  throw new ArgumentException(e.Message);
83  }
84  finally
85  {
86  stream.Close();
87  }
88  //Put in to SourceSafe
89  Seci.SeciInterface.SourceSafe_SaveFile(fileName);
90  }
91 
97  public GUILayout Load(String fileName)
98  {
99  GUILayout layout = new GUILayout();
100 
101  //Check file exists
102  FileInfo fi = new FileInfo(fileName);
103 
104  if (fi.Exists)
105  {
106  //deserialises a xml config file
107  FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
108 
109  try
110  {
111  XmlSerializer deserialize = new XmlSerializer(typeof(GUILayout));
112  layout = (GUILayout)deserialize.Deserialize(stream);
113  //Seci.SeciInterface.SourceSafe_SaveFile(fileName);
114  }
115  catch (Exception e)
116  {
117  //throw error up to next level
118  throw new ArgumentException(e.Message);
119  }
120  finally
121  {
122  stream.Close();
123  }
124  }
125  return layout;
126  }
127 
128  #endregion
129 
130  #region "Groups"
131 
137  public void AddGroup(Group grp)
138  {
139  _groups.Add(grp);
140  }
141 
147  public void RemoveGroup(Group grp)
148  {
149  _groups.Remove(grp);
150  }
151 
157  public Boolean GroupExists(String name)
158  {
159  for (int i = 0; i < _groups.Count; ++i)
160  {
161  if (_groups[i].GroupName.ToLower() == name.ToLower())
162  {
163  return true;
164  }
165  }
166 
167  return false;
168  }
169 
174  public void OverWriteGroups(List<Group> newGroups)
175  {
176  _groups = newGroups;
177  }
178 
182  public void HideAllGroups()
183  {
184  for (int i = 0; i < _groups.Count; ++i)
185  {
186  _groups[i].HideGroup();
187  }
188  }
189 
194  public void ShowGroup(String grpName)
195  {
196  for (int i = 0; i < _groups.Count; ++i)
197  {
198  if (grpName == _groups[i].GroupName)
199  {
200  _groups[i].ShowGroup();
201  break;
202  }
203  }
204  }
205 
211  public void RemoveVIFromAllGroups(String viName)
212  {
213  for (int i = 0; i < _groups.Count; ++i)
214  {
215  _groups[i].RemoveVIMember(viName);
216  }
217  }
218 
225  public void ChangeVIPath(String oldPath, String newPath)
226  {
227  for (int i = 0; i < _groups.Count; ++i)
228  {
229  _groups[i].RemoveVIMember(oldPath);
230  _groups[i].AddVIMember(newPath);
231  }
232  }
233 
239  public void RemoveProgFromAllGroups(String progName)
240  {
241  String filepath = Seci.SeciInterface.Exe_GetFilePath(progName);
242 
243  for (int i = 0; i < _groups.Count; ++i)
244  {
245  _groups[i].RemoveProgMember(filepath);
246  }
247  }
248 
256  public void CheckGroupsValid()
257  {
258  for (int i = 0; i < _groups.Count; ++i)
259  {
260  _groups[i].RemoveInvalidMembers();
261  }
262  }
263 
268  public void UpdateGUIvalues()
269  {
270  for (int i = 0; i < _graphs.Count; ++i)
271  {
272  _graphs[i].UpdateControl();
273  }
274 
275  for (int i = 0; i < _runInfos.Count; ++i)
276  {
277  _runInfos[i].UpdateControl();
278  }
279 
280  for (int i = 0; i < _blockViewers.Count; ++i)
281  {
282  _blockViewers[i].UpdateControl();
283  }
284  }
285 
286  #endregion
287 
288  }
289 }
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
List< Group > _groups
Stores the groups that are used to organise the VIs and programmes that are part of the configuration...
Definition: GUILayout.cs:24
Seci.SerialisableList< SECI_Controls.Run_Information.Scaling_RunInfo > _runInfos
Serialisable container for any run information controls that are part of the layout.
Definition: GUILayout.cs:28
Seci.SerialisableList< SECI_Controls.Run_Information.Scaling_RunInfo > RunInfos
Definition: GUILayout.cs:45
void OverWriteGroups(List< Group > newGroups)
Definition: GUILayout.cs:174
Seci.SerialisableList< SECI_Controls.Run_Information.Scaling_BlockViewer > _blockViewers
Serialisable container for any block viewer controls that are part of the layout. ...
Definition: GUILayout.cs:32
void ChangeVIPath(String oldPath, String newPath)
Definition: GUILayout.cs:225
Seci.SerialisableList< SECI_Controls.Graph.SECI_Graph > _graphs
Serialisable container for any graph controls that are part of the layout.
Definition: GUILayout.cs:36