void SetExpressionEvalTypeByParameterType(ref NationalInstruments.TestStand.Interop.UI.Ax.AxExpressionEdit expEdit, string parameterType) { EvaluationTypes eval = seqContext.Engine.NewEvaluationTypes(); switch (parameterType) { //Initialize the correct type of parameter based on the Users Type setting case "Path": eval.PropertyValueTypeFlags = 0x4; //set string as the valid evaluation type break; case "Boolean": eval.PropertyValueTypeFlags = 0x1; //boolean type break; case "Double": case "I32": case "I64": case "U32": case "U64": eval.PropertyValueTypeFlags = 0x2; //numeric type break; default: eval.PropertyValueTypeFlags = 0x4; break; } expEdit.SetValidEvaluationTypes(eval); }
void InitializeTableView(SequenceContext _seqContext, string fileExp, string[] _parameterValues, string[] _parameterTypes, bool reset) { //MessageBox.Show(reset.ToString()); PropertyObject seqContextPO; seqContextPO = _seqContext.AsPropertyObject(); string filePath = StringUtilities.unparseFilePathString(fileExp); this.OpenSelectSingleChannelsDialog = new SelectSingleChannelPanel(this); string[] comboBoxParameterTypes = { "Path", "Boolean", "Double", "I32", "I64", "U32", "U64" }; this.tableLayoutPanel1.Controls.Clear();//Empty the table //Add in the column headers this.tableLayoutPanel1.Controls.Add(this.ParameterNameTitle_label, 0, 0); this.tableLayoutPanel1.Controls.Add(this.ParameterTypeTitle_label, 1, 0); this.tableLayoutPanel1.Controls.Add(this.ParameterValueTitle_label, 2, 0); this.tableLayoutPanel1.Controls.Add(this.SelectChannelTitle_label, 3, 0); this.tableLayoutPanel1.AutoSize = true; this.tableLayoutPanel1.RowCount = 1; TableLayoutRowStyleCollection rowStyles = this.tableLayoutPanel1.RowStyles; foreach (RowStyle style in rowStyles) { if (style.SizeType == SizeType.Percent) { style.SizeType = SizeType.AutoSize; } } if (filePath != null && filePath != "" && System.IO.File.Exists(filePath)) //Don't try to initialize with a blank filepath { try { RealTimeSequence newRTSeq = new RealTimeSequence(filePath); ParameterDeclaration[] seqParam = newRTSeq.Variables.Parameters.Variables; string parameterValueElement; ReturnDeclaration returnParam = newRTSeq.Variables.ReturnType; string returnParamType = returnParam.DataType.ToString(); returnParamDataType = returnParamType; if (!reset) { this.tableLayoutPanel1.RowCount = seqParam.Length + 1; //Need rows for the header and one row for each parameter if (seqParam.Length != _parameterValues.Length) { VSDialogs vsdialog = new VSDialogs(); vsdialog.ShowWarningDialog("It appears that the Real-Time Sequence has changed. Please reload the file by clicking \"Browse...\"."); } if (seqParam.Length == _parameterValues.Length && seqParam.Length > 0 && _parameterValues.Length > 0) { for (int i = 0; i < seqParam.Length; i++) { ParameterDeclaration param = seqParam[i]; System.Windows.Forms.Label currentNameLabel = new System.Windows.Forms.Label(); System.Windows.Forms.ComboBox currentTypeComboBox = new System.Windows.Forms.ComboBox(); currentTypeComboBox.Enabled = false; NationalInstruments.TestStand.Interop.UI.Ax.AxExpressionEdit currentExpression = new NationalInstruments.TestStand.Interop.UI.Ax.AxExpressionEdit(); if (param.EvaluationMethod == EvaluationMethod.ByReference) { parameterValueElement = StringUtilities.removeDoubleQuotesAroundString(_parameterValues[i]); if (param.DefaultAssignment.Channel.ToString() == parameterValueElement) { int rowToAddControl = i + 1; currentNameLabel.Text = param.Identifier; currentNameLabel.AutoSize = true; this.tableLayoutPanel1.Controls.Add(currentNameLabel, 0, rowToAddControl); currentTypeComboBox.Items.AddRange(comboBoxParameterTypes); currentTypeComboBox.SelectedValueChanged += new System.EventHandler(this.ParameterTypeChanged); currentExpression.Visible = true; currentExpression.Dock = DockStyle.Fill; this.tableLayoutPanel1.Controls.Add(currentExpression, 2, rowToAddControl); currentExpression.Parent = tableLayoutPanel1; string handle = currentExpression.Handle.ToString();//force creation of the handle System.Windows.Forms.Button selectChannelButton = new System.Windows.Forms.Button(); selectChannelButton.Text = "Browse..."; selectChannelButton.Enabled = false; selectChannelButton.Click += new System.EventHandler(selectChannelButton_Click); selectChannelButton.Parent = this.tableLayoutPanel1; this.tableLayoutPanel1.Controls.Add(selectChannelButton, 3, rowToAddControl); currentExpression.CreateControl(); currentExpression.Context = seqContextPO; currentExpression.SyntaxHighlightingEnabled = true; currentExpression.Style = NationalInstruments.TestStand.Interop.UI.ExpressionEditStyles.ExpressionEditStyle_Edit; currentExpression.TextType = NationalInstruments.TestStand.Interop.UI.TextTypes.TextType_Expression; currentExpression.Text = StringUtilities.addDoubleQuotesAroundString(param.DefaultAssignment.Channel.ToString());//Just use the DefaultAssignment if they are the same. this.tableLayoutPanel1.GetControlFromPosition(3, rowToAddControl).Enabled = true; currentTypeComboBox.SelectedText = "Path"; this.tableLayoutPanel1.Controls.Add(currentTypeComboBox, 1, rowToAddControl); } else { int rowToAddControl = i + 1; currentNameLabel.Text = param.Identifier; currentNameLabel.AutoSize = true; this.tableLayoutPanel1.Controls.Add(currentNameLabel, 0, rowToAddControl); currentTypeComboBox.Items.AddRange(comboBoxParameterTypes); currentTypeComboBox.SelectedValueChanged += new System.EventHandler(this.ParameterTypeChanged); currentExpression.Visible = true; currentExpression.Dock = DockStyle.Fill; this.tableLayoutPanel1.Controls.Add(currentExpression, 2, rowToAddControl); currentExpression.Parent = tableLayoutPanel1; string handle = currentExpression.Handle.ToString();//force creation of the handle System.Windows.Forms.Button selectChannelButton = new System.Windows.Forms.Button(); selectChannelButton.Text = "Browse..."; selectChannelButton.Enabled = false; selectChannelButton.Click += new System.EventHandler(selectChannelButton_Click); selectChannelButton.Parent = this.tableLayoutPanel1; this.tableLayoutPanel1.Controls.Add(selectChannelButton, 3, rowToAddControl); currentExpression.CreateControl(); currentExpression.Context = seqContextPO; currentExpression.SyntaxHighlightingEnabled = true; currentExpression.Style = NationalInstruments.TestStand.Interop.UI.ExpressionEditStyles.ExpressionEditStyle_Edit; currentExpression.TextType = NationalInstruments.TestStand.Interop.UI.TextTypes.TextType_Expression; currentExpression.Text = StringUtilities.addDoubleQuotesAroundString(parameterValueElement);//Use the value from TestStand instead of the DefaultAssignment if they are not the same. this.tableLayoutPanel1.GetControlFromPosition(3, rowToAddControl).Enabled = true; currentTypeComboBox.SelectedText = "Path"; this.tableLayoutPanel1.Controls.Add(currentTypeComboBox, 1, rowToAddControl); } } else { parameterValueElement = StringUtilities.removeDoubleQuotesAroundString(_parameterValues[i]); if (param.DefaultAssignment.ToString() == parameterValueElement) { int rowToAddControl = i + 1; currentNameLabel.Text = param.Identifier; currentNameLabel.AutoSize = true; this.tableLayoutPanel1.Controls.Add(currentNameLabel, 0, rowToAddControl); currentTypeComboBox.Items.AddRange(comboBoxParameterTypes); currentTypeComboBox.SelectedValueChanged += new System.EventHandler(this.ParameterTypeChanged); currentExpression.Visible = true; currentExpression.Dock = DockStyle.Fill; this.tableLayoutPanel1.Controls.Add(currentExpression, 2, rowToAddControl); currentExpression.Parent = tableLayoutPanel1; string handle = currentExpression.Handle.ToString();//force creation of the handle System.Windows.Forms.Button selectChannelButton = new System.Windows.Forms.Button(); selectChannelButton.Text = "Browse..."; selectChannelButton.Enabled = false; selectChannelButton.Click += new System.EventHandler(selectChannelButton_Click); selectChannelButton.Parent = this.tableLayoutPanel1; this.tableLayoutPanel1.Controls.Add(selectChannelButton, 3, rowToAddControl); currentExpression.CreateControl(); currentExpression.Context = seqContextPO; currentExpression.SyntaxHighlightingEnabled = true; currentExpression.Style = NationalInstruments.TestStand.Interop.UI.ExpressionEditStyles.ExpressionEditStyle_Edit; currentExpression.TextType = NationalInstruments.TestStand.Interop.UI.TextTypes.TextType_Expression; currentExpression.Text = param.DefaultAssignment.ToString();//Just use the DefaultAssignment if they are the same. this.tableLayoutPanel1.GetControlFromPosition(3, rowToAddControl).Enabled = false; switch (param.DefaultValue.Type.ToString()) { case "Double": currentTypeComboBox.SelectedText = "Double"; break; case "UInt64": currentTypeComboBox.SelectedText = "U64"; break; case "Int64": currentTypeComboBox.SelectedText = "I64"; break; case "UInt32": currentTypeComboBox.SelectedText = "U32"; break; case "Int32": currentTypeComboBox.SelectedText = "I32"; break; case "Boolean": currentTypeComboBox.SelectedText = "Boolean"; break; } this.tableLayoutPanel1.Controls.Add(currentTypeComboBox, 1, rowToAddControl); } else { int rowToAddControl = i + 1; currentNameLabel.Text = param.Identifier; currentNameLabel.AutoSize = true; this.tableLayoutPanel1.Controls.Add(currentNameLabel, 0, rowToAddControl); currentTypeComboBox.Items.AddRange(comboBoxParameterTypes); currentTypeComboBox.SelectedValueChanged += new System.EventHandler(this.ParameterTypeChanged); currentExpression.Visible = true; currentExpression.Dock = DockStyle.Fill; this.tableLayoutPanel1.Controls.Add(currentExpression, 2, rowToAddControl); currentExpression.Parent = tableLayoutPanel1; string handle = currentExpression.Handle.ToString();//force creation of the handle System.Windows.Forms.Button selectChannelButton = new System.Windows.Forms.Button(); selectChannelButton.Text = "Browse..."; selectChannelButton.Enabled = false; selectChannelButton.Click += new System.EventHandler(selectChannelButton_Click); selectChannelButton.Parent = this.tableLayoutPanel1; this.tableLayoutPanel1.Controls.Add(selectChannelButton, 3, rowToAddControl); currentExpression.CreateControl(); currentExpression.Context = seqContextPO; currentExpression.SyntaxHighlightingEnabled = true; currentExpression.Style = NationalInstruments.TestStand.Interop.UI.ExpressionEditStyles.ExpressionEditStyle_Edit; currentExpression.TextType = NationalInstruments.TestStand.Interop.UI.TextTypes.TextType_Expression; currentExpression.Text = parameterValueElement;//Use the value from TestStand instead of the DefaultAssignment if they are not the same. this.tableLayoutPanel1.GetControlFromPosition(3, rowToAddControl).Enabled = false; switch (param.DefaultValue.Type.ToString()) { case "Double": currentTypeComboBox.SelectedText = "Double"; break; case "UInt64": currentTypeComboBox.SelectedText = "U64"; break; case "Int64": currentTypeComboBox.SelectedText = "I64"; break; case "UInt32": currentTypeComboBox.SelectedText = "U32"; break; case "Int32": currentTypeComboBox.SelectedText = "I32"; break; case "Boolean": currentTypeComboBox.SelectedText = "Boolean"; break; } this.tableLayoutPanel1.Controls.Add(currentTypeComboBox, 1, rowToAddControl); } //switch (param.DefaultValue.Type.ToString()) //{ // case "Double": // currentTypeComboBox.SelectedText = "Double"; // break; // case "UInt64": // currentTypeComboBox.SelectedText = "U64"; // break; // case "Int64": // currentTypeComboBox.SelectedText = "I64"; // break; // case "UInt32": // currentTypeComboBox.SelectedText = "U32"; // break; // case "Int32": // currentTypeComboBox.SelectedText = "I32"; // break; // case "Boolean": // currentTypeComboBox.SelectedText = "Boolean"; // break; //} } } } } if (reset) { this.tableLayoutPanel1.RowCount = seqParam.Length + 1; //Need rows for the header and one row for each parameter if (seqParam.Length > 0) { this.tableLayoutPanel1.AutoSize = true; int n = 1; foreach (ParameterDeclaration param in seqParam) { System.Windows.Forms.Label currentNameLabel = new System.Windows.Forms.Label(); currentNameLabel.Text = param.Identifier; currentNameLabel.AutoSize = true; this.tableLayoutPanel1.Controls.Add(currentNameLabel, 0, n); System.Windows.Forms.ComboBox currentTypeComboBox = new System.Windows.Forms.ComboBox(); currentTypeComboBox.Items.AddRange(comboBoxParameterTypes); currentTypeComboBox.SelectedValueChanged += new System.EventHandler(this.ParameterTypeChanged); currentTypeComboBox.Enabled = false; NationalInstruments.TestStand.Interop.UI.Ax.AxExpressionEdit currentExpression = new NationalInstruments.TestStand.Interop.UI.Ax.AxExpressionEdit(); currentExpression.Visible = true; currentExpression.Dock = DockStyle.Fill; this.tableLayoutPanel1.Controls.Add(currentExpression, 2, n); currentExpression.Parent = tableLayoutPanel1; string handle = currentExpression.Handle.ToString();//force creation of the handle System.Windows.Forms.Button selectChannelButton = new System.Windows.Forms.Button(); selectChannelButton.Text = "Browse..."; selectChannelButton.Enabled = false; selectChannelButton.Click += new System.EventHandler(selectChannelButton_Click); selectChannelButton.Parent = this.tableLayoutPanel1; this.tableLayoutPanel1.Controls.Add(selectChannelButton, 3, n); currentExpression.CreateControl(); currentExpression.Context = seqContextPO; currentExpression.SyntaxHighlightingEnabled = true; currentExpression.Style = NationalInstruments.TestStand.Interop.UI.ExpressionEditStyles.ExpressionEditStyle_Edit; currentExpression.TextType = NationalInstruments.TestStand.Interop.UI.TextTypes.TextType_Expression; if (param.EvaluationMethod == EvaluationMethod.ByReference) { currentTypeComboBox.SelectedText = "Path"; currentExpression.Text = StringUtilities.addDoubleQuotesAroundString(param.DefaultAssignment.Channel.ToString()); this.tableLayoutPanel1.GetControlFromPosition(3, n).Enabled = true; } else { switch (param.DefaultValue.Type.ToString()) { case "Double": currentTypeComboBox.SelectedText = "Double"; break; case "UInt64": currentTypeComboBox.SelectedText = "U64"; break; case "Int64": currentTypeComboBox.SelectedText = "I64"; break; case "UInt32": currentTypeComboBox.SelectedText = "U32"; break; case "Int32": currentTypeComboBox.SelectedText = "I32"; break; case "Boolean": currentTypeComboBox.SelectedText = "Boolean"; break; } currentExpression.Text = param.DefaultAssignment.ToString(); } this.tableLayoutPanel1.Controls.Add(currentTypeComboBox, 1, n); n++; } } } } catch (System.ArgumentException) { VSDialogs dialogs = new VSDialogs(); dialogs.ShowWarningDialog("Invalid Filepath:" + filePath); } } }