Digital Twin - GUI
MachineCB.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Threading.Tasks;
6 using System.Windows.Forms;
7 
8 namespace GUI.Datatypes
9 {
13 
18  public class MachineCB : CheckBox
19  {
23  private List<ProductCB> products;
25  private bool[] timeslots;
27  public double Bauteilwechselphase;
28 
34 
37  public MachineCB(String name, LocationCB loc) : base()
38  {
39  this.Name = name;
40  this.Text = name;
41  this.ThreeState = true;
42  location = loc;
43  products = new List<ProductCB>();
44  loc.addMachine(this);
45  timeslots = new bool[]{true};
46  Bauteilwechselphase = 0;
47  }
48 
53 
57  public void addProduct(ProductCB prod)
58  {
59  if(!products.Contains(prod))
60  {
61  products.Add(prod);
62  }
63  }
64 
69  public List<ProductCB> getProducts()
70  {
71  return products;
72  }
73 
79  {
80  return location;
81  }
82 
86 
90  public void checkAllProducts()
91  {
92  foreach (ProductCB prod in products)
93  {
94  prod.CheckState = CheckState.Checked;
95  }
96  }
97 
101 
105  public void uncheckAllProducts()
106  {
107  foreach (ProductCB prod in products)
108  {
109  prod.CheckState = CheckState.Unchecked;
110  }
111  }
112 
117 
121  public double allChildrenChecked()
122  {
123  int sum = 0;
124 
125  foreach (ProductCB p in products)
126  {
127  if (p.CheckState.Equals(CheckState.Checked)) sum += 2;
128  if (p.CheckState.Equals(CheckState.Indeterminate)) sum += 1;
129  if (p.CheckState.Equals(CheckState.Unchecked)) sum += 0;
130  }
131 
132  double d = (double)sum / (double)products.Count;
133  return d;
134  }
135 
141 
145  public bool stateOfTimeslot(int t)
146  {
147  return timeslots[t];
148  }
149 
154 
158  public void changeStateOfTimeslot(int t)
159  {
160  timeslots[t] = !timeslots[t];
161  }
162 
168 
172  public void changeStateOfTimeslot(int t, bool b)
173  {
174  timeslots[t] = b;
175  }
176 
181 
185  public void setNumberOfTimeslots(int num)
186  {
187  timeslots = new bool[num];
188  for (int i = 0; i<timeslots.Length; i++)
189  {
190  timeslots[i] = true;
191  }
192  }
193 
199 
203  public List<String> extendProductList(List<String> l)
204  {
205  foreach (ProductCB p in products)
206  {
207  if (p.CheckState != CheckState.Unchecked)
208  {
209  if (!l.Contains(p.Name))
210  {
211  l.Add(p.Name);
212  }
213  }
214  }
215  return l;
216  }
217  }
218 }
bool stateOfTimeslot(int t)
Get the availability of this machine at timeslot t.
Definition: MachineCB.cs:145
MachineCB(String name, LocationCB loc)
The Constructor.
Definition: MachineCB.cs:37
void addProduct(ProductCB prod)
Add a product to this machine.
Definition: MachineCB.cs:57
void addMachine(MachineCB m)
Add a machine to this location.
Definition: LocationCB.cs:178
bool[] timeslots
An array that stores for each timeslot if the machine is available on this time.
Definition: MachineCB.cs:25
void setNumberOfTimeslots(int num)
Sets the number of timeslots to a certain amount.
Definition: MachineCB.cs:185
void checkAllProducts()
Check all the product Checkboxes that belong to this machine.
Definition: MachineCB.cs:90
void uncheckAllProducts()
Uncheck all the product Checkboxes that belong to this machine.
Definition: MachineCB.cs:105
LocationCB getLocation()
Grants access to the location where the machine is located.
Definition: MachineCB.cs:78
LocationCB location
Location this machine belongs to.
Definition: MachineCB.cs:21
List< ProductCB > getProducts()
Grants access to the list of products that belong to the machine.
Definition: MachineCB.cs:69
A wrapper class for products.
Definition: ProductCB.cs:18
A wrapper class for locations.
Definition: LocationCB.cs:19
List< String > extendProductList(List< String > l)
Extends the List of products that can be produced.
Definition: MachineCB.cs:203
List< ProductCB > products
List of products this machine can produce.
Definition: MachineCB.cs:23
double Bauteilwechselphase
A number that describes the time needed to change toolkits on this machine (in minutes).
Definition: MachineCB.cs:27
void changeStateOfTimeslot(int t)
Change the availability of this machine at timeslot t.
Definition: MachineCB.cs:158
double allChildrenChecked()
Check if every procuct belonging to the machine is checked.
Definition: MachineCB.cs:121
void changeStateOfTimeslot(int t, bool b)
Change the availability of this machine at timeslot t to a ceratin value.
Definition: MachineCB.cs:172
A wrapper class for machines.
Definition: MachineCB.cs:18