2 using System.Collections;
3 using System.Collections.Generic;
4 using System.ComponentModel;
8 using System.Windows.Forms;
10 namespace SeciUserInterface.Dialogs.Blocks
17 public Boolean IsComponent =
false;
22 InitializeComponent();
35 txtLower.Text =
"-Infinity";
36 txtUpper.Text =
"Infinity";
37 comFormatting.SelectedIndex = 0;
42 this.Text =
"SECI - Edit Block";
46 txtBlockName.Text = Block.BlockName;
47 txtUnits.Text = Block.BlockUnits;
48 txtAlias.Text = Block.Alias;
50 txtLogRate.Text = Block.LoggingRate.ToString();
52 comVI.SelectedItem = Block.ParentVI.ToLower();
53 comRead.SelectedItem = Block.ReadControl;
55 chkEnabled.Checked = Block.BlockEnabled;
56 chkVisible.Checked = Block.Visible;
58 if (Block.ApplyFormatting)
60 comFormatting.SelectedIndex = 0;
62 else if (Block.ApplyFixedFormatting)
64 comFormatting.SelectedIndex = 1;
68 comFormatting.SelectedIndex = 2;
71 txtDecPlaces.Text = Block.NumberDecimalPlaces.ToString();
74 if (Block.LogValueToFile)
76 radLog.Checked =
true;
77 if (Block.LogChangesTolerance)
79 chkOnlyIfChanged.Checked =
true;
80 txtLogTolerance.Text = Block.Tolerance.ToString();
84 chkOnlyIfChanged.Checked =
false;
87 if (Block.LogChangesOnly)
89 radOnlyChangesTol.Checked =
true;
90 txtTolerance.Text = Block.Tolerance.ToString();
96 radNoLogging.Checked =
true;
99 chkLogToSingleFile.Checked = Block.LogToSharedFile;
101 if (Block.WriteControl != null)
103 comWrite.SelectedItem = Block.WriteControl;
106 if (Block.GoButton != null)
108 comGo.SelectedItem = Block.GoButton;
111 if (Block.WaitForControl != null)
113 comWaitfor.SelectedItem = Block.WaitForControl;
118 chkRuncontrol.Checked = Block.UnderRunControl;
119 Seci.Definitions.ControlType type = Seci.Managers.LabViewMgr.GetControlType(comVI.SelectedItem.ToString(), comRead.SelectedItem.ToString());
120 if (type == Seci.Definitions.ControlType.BOOLEAN || type == Seci.Definitions.ControlType.STRING)
122 txtRCValue.Text = Block.RunControlValue;
126 txtUpper.Text = Block.UpperLimit.ToString();
127 txtLower.Text = Block.LowerLimit.ToString();
131 chkSaveSettings.Checked = Block.SaveSettings;
135 txtBlockName.ReadOnly =
true;
139 if (Seci.Definitions.Status.LogAllBlocksToSingleFile)
141 chkLogToSingleFile.Checked =
true;
142 chkLogToSingleFile.Enabled =
false;
146 catch (Exception err)
148 MessageBox.Show(err.Message);
157 for (
int i = 0; i < panels.Count; ++i)
159 comVI.Items.Add(panels[i].FilePath.ToLower());
163 comVI.Items.Add(Seci.Standard.Dae.FilePath.ToLower());
166 comVI.Items.Add(Seci.Standard.BeamLogger.FilePath.ToLower());
173 String[] controls = Seci.Managers.LabViewMgr.GetVIControls(VIname).ToArray();
175 comRead.Items.Clear();
176 comRead.Items.AddRange(controls);
177 comRead.SelectedIndex = -1;
180 comWrite.Items.Clear();
181 comWrite.Items.AddRange(controls);
182 comWrite.SelectedIndex = -1;
186 comGo.Items.AddRange(controls);
187 comGo.SelectedIndex = -1;
190 comWaitfor.Items.Clear();
191 comWaitfor.Items.AddRange(controls);
192 comWaitfor.SelectedIndex = -1;
194 catch (Exception err)
196 MessageBox.Show(err.Message);
202 if (comVI.SelectedIndex != -1)
204 fillInControls(comVI.SelectedItem.ToString());
210 comWrite.SelectedIndex = -1;
215 comGo.SelectedIndex = -1;
220 comWaitfor.SelectedIndex = -1;
226 if (checkFilledOutCorrectly())
231 newBlock.BlockName = txtBlockName.Text;
232 newBlock.BlockUnits = txtUnits.Text;
233 newBlock.ParentVI = comVI.SelectedItem.ToString();
234 newBlock.Alias = txtAlias.Text;
236 newBlock.ReadControl = comRead.SelectedItem.ToString();
237 newBlock.LoggingRate = Convert.ToSingle(txtLogRate.Text);
239 newBlock.BlockEnabled = chkEnabled.Checked;
240 newBlock.Visible = chkVisible.Checked;
242 if (comFormatting.SelectedIndex == 0)
244 newBlock.ApplyFormatting =
true;
245 newBlock.ApplyFixedFormatting =
false;
246 newBlock.NumberDecimalPlaces = Int32.Parse(txtDecPlaces.Text);
248 else if (comFormatting.SelectedIndex == 1)
250 newBlock.ApplyFormatting =
false;
251 newBlock.ApplyFixedFormatting =
true;
252 newBlock.NumberDecimalPlaces = Int32.Parse(txtDecPlaces.Text);
256 newBlock.ApplyFormatting =
false;
257 newBlock.ApplyFixedFormatting =
false;
258 newBlock.NumberDecimalPlaces = Int32.Parse(txtDecPlaces.Text);
261 newBlock.ReadType = Seci.Managers.LabViewMgr.GetControlType(comVI.SelectedItem.ToString(), comRead.SelectedItem.ToString());
264 newBlock.LoggingRate = Convert.ToSingle(txtLogRate.Text);
268 newBlock.LogValueToFile =
true;
269 if (chkOnlyIfChanged.Checked ==
true)
271 newBlock.LogChangesTolerance =
true;
272 newBlock.Tolerance = Convert.ToDouble(txtLogTolerance.Text);
273 newBlock.LogChangesOnly =
false;
277 newBlock.LogChangesTolerance =
false;
278 newBlock.LogChangesOnly =
false;
281 else if (radOnlyChangesTol.Checked)
283 newBlock.LogValueToFile =
true;
284 newBlock.LogChangesTolerance =
true;
285 newBlock.LogChangesOnly =
true;
286 newBlock.Tolerance = Convert.ToDouble(txtTolerance.Text);
291 newBlock.LogChangesOnly =
false;
292 newBlock.LogValueToFile =
false;
293 newBlock.LogChangesTolerance =
false;
294 newBlock.Tolerance = 0.0;
297 if (newBlock.ReadType == Seci.Definitions.ControlType.NUMERIC)
299 newBlock.SetRunControlLimits(chkRuncontrol.Checked, Convert.ToDouble(txtLower.Text), Convert.ToDouble(txtUpper.Text));
301 else if (newBlock.ReadType == Seci.Definitions.ControlType.BOOLEAN || newBlock.ReadType == Seci.Definitions.ControlType.STRING)
303 newBlock.SetRunControlLimits(chkRuncontrol.Checked, txtRCValue.Text);
307 newBlock.SetRunControlLimits(chkRuncontrol.Checked, Convert.ToDouble(txtLower.Text), Convert.ToDouble(txtUpper.Text));
310 newBlock.SaveSettings = chkSaveSettings.Checked;
312 newBlock.LogToSharedFile = chkLogToSingleFile.Checked;
317 newBlock.Group = Block.Group;
320 if (comWrite.SelectedIndex != -1)
322 newBlock.WriteControl = comWrite.SelectedItem.ToString();
325 if (comGo.SelectedIndex != -1)
327 newBlock.GoButton = comGo.SelectedItem.ToString();
330 if (comWaitfor.SelectedIndex != -1)
332 newBlock.WaitForControl = comWaitfor.SelectedItem.ToString();
339 if (newBlock.BlockName.ToLower() == Seci.Definitions.Status.StatusBlockName.ToLower())
341 MessageBox.Show(
"Block name is reserved. Please, modify the Block name.",
"Block name is not valid", MessageBoxButtons.OK, MessageBoxIcon.Error);
345 if (Dictionary.Contains(newBlock.BlockName))
347 MessageBox.Show(
"Block name already exists. Please, modify the Block name.",
"Block name is not unique", MessageBoxButtons.OK, MessageBoxIcon.Error);
351 if (!String.IsNullOrEmpty(newBlock.Alias) && !Dictionary.IsAliasUnique(newBlock.Alias))
353 MessageBox.Show(
"Alias is not unique. Please, modify the alias.",
"Alias is not unique", MessageBoxButtons.OK, MessageBoxIcon.Error);
358 Dictionary.Add(newBlock.BlockName, newBlock);
360 catch (Exception err)
362 MessageBox.Show(err.Message,
"Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
373 newBlock.OwningComponent = Block.OwningComponent;
374 Dictionary.Replace(Block.BlockName, newBlock.BlockName, newBlock);
376 catch (Exception err)
378 MessageBox.Show(err.Message,
"Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
383 DialogResult = DialogResult.OK;
391 List<String> filledList = checkFilledOutandValid();
393 if (filledList.Count > 0)
395 String message =
"The following entries are invalid:";
397 for (
int i = 0; i < filledList.Count; ++i)
399 message = message + Environment.NewLine + filledList[i];
402 MessageBox.Show(message,
"Invalid Entries!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
415 List<String> list =
new List<String>();
419 if (txtBlockName.Text ==
"")
421 list.Add(
" - No block name entered.");
424 if (comVI.SelectedIndex == -1)
426 list.Add(
" - No VI selected.");
429 if (comRead.SelectedIndex == -1)
431 list.Add(
" - No read control selected.");
434 if (chkRuncontrol.Checked)
436 Seci.Definitions.ControlType type = Seci.Managers.LabViewMgr.GetControlType(comVI.SelectedItem.ToString(), comRead.SelectedItem.ToString());
437 if (type == Seci.Definitions.ControlType.BOOLEAN || type == Seci.Definitions.ControlType.STRING)
439 if (txtRCValue.Text.Trim() ==
"")
441 list.Add(
" - No value entered for run-control.");
446 if (txtUpper.Text.Trim() ==
"")
448 list.Add(
" - No upper limit entered for run-control.");
452 txtUpper.Text = ConfigureBlocks.CheckForInfinity(txtUpper.Text);
454 if (!Double.TryParse(txtUpper.Text, out dummy))
456 list.Add(
" - upper limit value not valid.");
460 if (txtLower.Text.Trim() ==
"")
462 list.Add(
" - No lower limit entered for run-control.");
466 txtLower.Text = ConfigureBlocks.CheckForInfinity(txtLower.Text);
468 if (!Double.TryParse(txtLower.Text, out dummy))
470 list.Add(
" - lower limit value not valid.");
477 if ((txtUpper.Text ==
"") || (!Double.TryParse(txtUpper.Text, out dummy)))
482 if ((txtLower.Text ==
"") || (!Double.TryParse(txtLower.Text, out dummy)))
491 if (txtLogRate.Text ==
"")
493 list.Add(
" - No log rate entered.");
497 if (!Double.TryParse(txtLogRate.Text, out dummy))
499 list.Add(
" - log-rate value not valid.");
505 list.Add(
" - log-rate value must be 5 seconds or higher.");
510 else if (radOnlyChangesTol.Checked)
512 if (txtTolerance.Text ==
"")
514 list.Add(
" - No tolerance entered.");
518 if (!Double.TryParse(txtTolerance.Text, out dummy))
520 list.Add(
" - tolerance value not valid.");
527 if (!
int.TryParse(txtDecPlaces.Text, out decplaces) || decplaces < 0)
529 list.Add(
" - number of decimal places not valid.");
557 if (Char.IsDigit(e.KeyChar) || e.KeyChar ==
'.' || e.KeyChar ==
'\b')
570 if (Char.IsLetterOrDigit(e.KeyChar) || e.KeyChar ==
'_' || e.KeyChar ==
'\b')
582 if (chkRuncontrol.Checked)
584 txtUpper.Enabled =
true;
585 txtLower.Enabled =
true;
586 txtRCValue.Enabled =
true;
590 txtUpper.Enabled =
false;
591 txtLower.Enabled =
false;
592 txtRCValue.Enabled =
false;
598 chkOnlyIfChanged.Enabled = radLog.Checked;
599 txtLogRate.Enabled = radLog.Checked;
600 txtLogTolerance.Enabled = radLog.Checked && chkOnlyIfChanged.Checked;
605 txtLogTolerance.Enabled = chkOnlyIfChanged.Checked;
610 txtTolerance.Enabled = radOnlyChangesTol.Checked;
615 Seci.Definitions.ControlType type = Seci.Managers.LabViewMgr.GetControlType(comVI.SelectedItem.ToString(), comRead.SelectedItem.ToString());
617 if (type == Seci.Definitions.ControlType.NUMERIC)
619 txtUpper.Visible =
true;
620 txtLower.Visible =
true;
621 lblRCLower.Visible =
true;
622 lblRCUpper.Visible =
true;
623 lblRCValue.Visible =
false;
624 txtRCValue.Visible =
false;
626 else if (type == Seci.Definitions.ControlType.STRING || type == Seci.Definitions.ControlType.BOOLEAN)
628 txtUpper.Visible =
false;
629 txtLower.Visible =
false;
630 lblRCLower.Visible =
false;
631 lblRCUpper.Visible =
false;
632 lblRCValue.Visible =
true;
633 txtRCValue.Visible =
true;
637 txtUpper.Visible =
true;
638 txtLower.Visible =
true;
639 lblRCLower.Visible =
true;
640 lblRCUpper.Visible =
true;
641 lblRCValue.Visible =
false;
642 txtRCValue.Visible =
false;
void btnClearWrite_Click(object sender, EventArgs e)
This class is used for storing the information for any blocks that are created and provides methods f...
Seci.BlockDictionary Dictionary
Boolean isCharValid(KeyPressEventArgs e)
void btnOK_Click(object sender, EventArgs e)
void AddBlock_Load(object sender, EventArgs e)
Boolean checkFilledOutCorrectly()
void comRead_SelectedIndexChanged(object sender, EventArgs e)
Boolean isNumeric(KeyPressEventArgs e)
void radOnlyChangesTol_CheckedChanged(object sender, EventArgs e)
Seci.Definitions.BlockInfo Block
void radLog_CheckedChanged(object sender, EventArgs e)
void isCharValid_KeyPress(object sender, KeyPressEventArgs e)
void btnClearWaitfor_Click(object sender, EventArgs e)
void chkRuncontrol_CheckedChanged(object sender, EventArgs e)
Specialised version of the Dictionary class which can be converted to XML. Also has some additional s...
void NumericOnly_KeyPress(object sender, KeyPressEventArgs e)
void btnClearGo_Click(object sender, EventArgs e)
This class contains all the information about a LabVIEW VI that needs to be saved in the configuratio...
List< String > checkFilledOutandValid()
void chkOnlyIfChanged_CheckedChanged(object sender, EventArgs e)
void comVI_SelectedIndexChanged(object sender, EventArgs e)
void fillInControls(String VIname)