SECI  1
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events
LVControl.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 
6 namespace Seci.LabView.Controls
7 {
12  abstract class LvControl
13  {
18  protected SerialisableList<int> _clusterIndices;
19 
21  protected String _name;
22  public String Name { get { return _name; } }
23 
30  public abstract String GetNameAndType();
31 
38  public virtual String[] GetValue(ref strongnameLabview.VirtualInstrument vi)
39  {
40  String[] result;
41 
42  if (_clusterIndices == null)
43  {
44  String temp = Convert.ToString(vi.GetControlValue(_name));
45  String[] temp2 = { temp };
46  result = temp2;
47  }
48  else
49  {
50  String temp = Convert.ToString(GetValueFromCluster(vi)[_clusterIndices[_clusterIndices.Count - 1]]);
51  String[] temp2 = { temp };
52  result = temp2;
53  }
54 
55  return result;
56  }
57 
58  public abstract String GetControlType();
59 
66  public virtual void SetValue(ref strongnameLabview.VirtualInstrument vi, Object value)
67  {
68  if (_clusterIndices == null)
69  {
70  vi.SetControlValue(_name, value);
71  }
72  else
73  {
74  SetValueInCluster(ref vi, value);
75  }
76  }
77 
84  protected Object[] GetValueFromCluster(strongnameLabview.VirtualInstrument vi)
85  {
86  //Split the name as we need the name of the first cluster
87  String[] splitName = _name.Split(':');
88 
89  Object[] vals = (Object[])vi.GetControlValue(splitName[0]);
90 
91  //this works for nested clusters!
92  for (int i = 0; i < _clusterIndices.Count - 1; ++i)
93  {
94  vals = (Object[])vals[_clusterIndices[i]];
95  }
96 
97  return vals;
98  }
99 
112  protected void SetValueInCluster(ref strongnameLabview.VirtualInstrument vi, Object value)
113  {
114  //Split the name as we need the name of the first cluster
115  String[] splitName = _name.Split(':');
116 
117  Object[] vals = (Object[])vi.GetControlValue(splitName[0]);
118 
119  //Need to find the value to change
120  if (_clusterIndices.Count == 1)
121  {
122  vals[_clusterIndices[0]] = value;
123  }
124  else if (_clusterIndices.Count == 2)
125  {
126  ((Object[])vals[_clusterIndices[0]])[_clusterIndices[1]] = value;
127  }
128  else if (_clusterIndices.Count == 3)
129  {
130  ((Object[])(((Object[])vals[_clusterIndices[0]])[_clusterIndices[1]]))[_clusterIndices[2]] = value;
131  }
132  else if (_clusterIndices.Count == 4)
133  {
134  ((Object[])(((Object[])(((Object[])vals[_clusterIndices[0]])[_clusterIndices[1]]))[_clusterIndices[2]]))[_clusterIndices[3]] = value;
135  }
136  else
137  {
138  //It is unlikely that ANYONE would nest 5 levels of clusters but just in case
139  //We throw an error up to next level
140  throw new ArgumentException("Looking for a nested cluster >4 deep.");
141  }
142 
143  //Then send all the values.
144  //Understandably there is an element of risk attached to sending all the values
145  //as variables could be adjusted by other means and then overwriten
146  //with the "old" value. This is unlikely though as the read then write is very
147  //quick < 1/1000th ms
148  vi.SetControlValue(splitName[0], vals);
149  }
150  }
151 }
void SetValueInCluster(ref strongnameLabview.VirtualInstrument vi, Object value)
Method for setting a value in a cluster. Individual values in the cluster cannot be set...
Definition: LVControl.cs:112
SerialisableList< int > _clusterIndices
If the control is in a cluster then the index is stored in a SerialisableList. A SerialisableList is ...
Definition: LVControl.cs:18
Object[] GetValueFromCluster(strongnameLabview.VirtualInstrument vi)
Method for returning a cluster value from the front panel. The cluster contains the required control ...
Definition: LVControl.cs:84
String _name
The name of the control.
Definition: LVControl.cs:21
virtual String[] GetValue(ref strongnameLabview.VirtualInstrument vi)
Method for returning a value from the actual front panel control which this class corresponds to...
Definition: LVControl.cs:38
virtual void SetValue(ref strongnameLabview.VirtualInstrument vi, Object value)
Virtual method for setting a value on the actual front panel control which this class corresponds to...
Definition: LVControl.cs:66
This class is the abstract base class of the objects used to store the VI control information...
Definition: LVControl.cs:12