/// <summary> /// 为Recipe添加一个配置项 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btAddItem_Click(object sender, EventArgs e) { FormXCfgItemEdit fmGenItem = new FormXCfgItemEdit(); fmGenItem.SetItemAllowedTypes(new Type[] { typeof(int), typeof(double), typeof(string), typeof(bool), typeof(PointF), typeof(List <int>), typeof(List <double>), typeof(List <string>), typeof(List <bool>), typeof(List <PointF>) }); if (DialogResult.OK == fmGenItem.ShowDialog()) { string[] allItemNames = _recipe.AllItemNames(); if (null != allItemNames && allItemNames.Contains(fmGenItem.GetItemName())) { MessageBox.Show("添加数据项失败,已包含数据项:" + fmGenItem.GetItemName()); return; } _recipe.AddItem(fmGenItem.GetItemName(), fmGenItem.GetItemValue()); UcJFParamEdit pe = new UcJFParamEdit(); //if (fmGenItem.GetItemType().IsPrimitive) pe.Height = 23; pe.Width = 500; pe.IsHelpVisible = false; pe.SetParamDesribe(JFParamDescribe.Create(fmGenItem.GetItemName(), fmGenItem.GetItemType(), JFValueLimit.NonLimit, null)); //pe.SetParamType(fmGenItem.GetItemType()); pe.SetParamValue(fmGenItem.GetItemValue()); pe.IsValueReadOnly = false; //添加后状态为可编辑 tableLayoutPanel1.Controls.Add(pe); Button btDel = new Button(); btDel.Text = "删除"; btDel.Tag = fmGenItem.GetItemName(); btDel.Click += OnDelButtonClick; tableLayoutPanel1.Controls.Add(btDel); _lstItems.Add(pe); _lstDeleteItemButtons.Add(btDel); } }
void AdjustView() { if (InvokeRequired) { Invoke(new Action(AdjustView)); return; } pnInputParam.Controls.Clear(); pnOutputParam.Controls.Clear(); if (null == _method) { lbInfo.Text = " 方法未设置"; btSetSave.Enabled = false; btCancel.Enabled = false; btAction.Enabled = false; return; } lbInfo.Text = " "; _isEditting = false; btSetSave.Enabled = true; btCancel.Enabled = true; btAction.Enabled = true; string[] inputNames = _method.MethodInputNames; if (inputNames != null) { foreach (string inputName in inputNames) { UcJFParamEdit ucParam = new UcJFParamEdit(); ucParam.IsHelpVisible = false; ucParam.Height = 50; //ucParam.SetParamType(_cfg.GetItemValue(itemName).GetType());//ucParam.SetParamDesribe(_station.GetCfgParamDescribe(itemName)); ucParam.SetParamDesribe(JFParamDescribe.Create(inputName, _method.GetMethodInputType(inputName), JFValueLimit.NonLimit, null)); ucParam.SetParamValue(_method.GetMethodInputValue(inputName)); pnInputParam.Controls.Add(ucParam); ucParam.IsValueReadOnly = true; } } string[] outputNames = _method.MethodOutputNames; if (null != outputNames) { foreach (string outputName in outputNames) { UcJFParamEdit ucParam = new UcJFParamEdit(); ucParam.IsHelpVisible = false; ucParam.Height = 50; //ucParam.SetParamType(_cfg.GetItemValue(itemName).GetType());//ucParam.SetParamDesribe(_station.GetCfgParamDescribe(itemName)); ucParam.SetParamDesribe(JFParamDescribe.Create(outputName, _method.GetMethodOutputType(outputName), JFValueLimit.NonLimit, null)); ucParam.SetParamValue(_method.GetMethodOutputValue(outputName)); pnOutputParam.Controls.Add(ucParam); ucParam.IsValueReadOnly = false; } } }
/// <summary>取消编辑,将配置中的参数恢复到界面和对象中</summary> private void btCancel_Click(object sender, EventArgs e) { IJFInitializable dev = JFHubCenter.Instance.InitorManager[dgvDevs.SelectedRows[0].Cells[0].Value.ToString()]; JFXmlSortedDictionary <string, List <object> > devCfg = JFHubCenter.Instance.SystemCfg.GetItemValue(JFHubCenter.CK_InitDevParams) as JFXmlSortedDictionary <string, List <object> >; List <object> initParams = devCfg[dgvDevs.SelectedRows[0].Cells[0].Value.ToString()]; for (int i = 1; i < initParams.Count; i++) { UcJFParamEdit pe = gbParams.Controls[i + 4] as UcJFParamEdit; pe.SetParamValue(initParams[i]); pe.IsValueReadOnly = true; dev.SetInitParamValue(dev.InitParamNames[i - 1], initParams[i]); } btInit.Enabled = !dev.IsInitOK; btAdd.Enabled = true; btRemove.Enabled = true; //btDebug.Enabled = true; isEditting = false; btEditSave.Text = "编辑参数"; btCancel.Enabled = false; dgvDevs.Enabled = true; Type devType = dev.GetType(); if (typeof(IJFDevice_Camera).IsAssignableFrom(devType) || typeof(IJFDevice_LightController).IsAssignableFrom(devType) || typeof(IJFDevice_MotionDaq).IsAssignableFrom(devType) || typeof(IJFDevice_TrigController).IsAssignableFrom(devType) || typeof(IJFRealtimeUIProvider).IsAssignableFrom(devType)) //提供调试界面 { btDebug.Enabled = true; if (typeof(IJFRealtimeUIProvider).IsAssignableFrom(devType)) { chkSelfUI.Enabled = true; } else { chkSelfUI.Checked = false; chkSelfUI.Enabled = false; } } else { btDebug.Enabled = false; } if (typeof(IJFConfigUIProvider).IsAssignableFrom(devType)) { btCfg.Enabled = true; } else { btCfg.Enabled = false; } }
/// <summary>确定创建Initor对象</summary> private void btOK_Click(object sender, EventArgs e) { if (dgvTypes.SelectedRows == null || dgvTypes.SelectedRows.Count == 0) { MessageBox.Show("请选择需要创建的设备类型"); return; } if (string.IsNullOrWhiteSpace(tbID.Text)) { MessageBox.Show("设备ID不能为空,请重新输入"); tbID.Focus(); return; } if (!_isFixedID && JFHubCenter.Instance.InitorManager.ContainID(tbID.Text)) { IJFInitializable dev = JFHubCenter.Instance.InitorManager.GetInitor(tbID.Text); string disTypeName = JFinitializerHelper.DispalyTypeName(dev.GetType()); MessageBox.Show(string.Format("Initor列表中已存在ID = \"{0}\" Type = \"{1}\"的设备\n请重新输入ID!", tbID.Text, disTypeName)); tbID.Focus(); return; } //IJFDevice newDev = JFHubCenter.Instance.InitorHelp.CreateInstance(dgvTypes.SelectedRows[0].Cells[0].Value.ToString()) as IJFDevice; //for (int i = 2; i < gbParams.Controls.Count;i++) for (int i = 0; i < panelParams.Controls.Count; i++) { //UcJFParamEdit pe = gbParams.Controls[i] as UcJFParamEdit; UcJFParamEdit pe = panelParams.Controls[i] as UcJFParamEdit; object paramVal = null; if (!pe.GetParamValue(out paramVal)) { MessageBox.Show("初始化参数:\"" + pe.Name + "\"获取失败!Error:" + pe.GetParamErrorInfo()); //newDev.Dispose(); pe.Focus(); return; } if (!initor.SetInitParamValue(initor.InitParamNames[i], paramVal)) { MessageBox.Show(string.Format("设置初始化参数失败:Name = {0},Value = {1}", initor.InitParamNames[i], paramVal.ToString())); //newDev.Dispose(); pe.Focus(); return; } } DialogResult = DialogResult.OK; }
public void AdjustRecipe2View() { if (InvokeRequired) { Invoke(new Action(AdjustRecipe2View)); return; } _lstItems.Clear(); _lstDeleteItemButtons.Clear(); tableLayoutPanel1.Controls.Clear(); EditRecipe = false; if (null == _recipe) { lbTips.Text = "Recipe未设置"; return; } lbTips.Text = "Categoty:" + _recipe.Categoty + " ID:" + _recipe.ID; string[] itemNames = _recipe.AllItemNames(); if (null == itemNames || 0 == itemNames.Length) { return; } foreach (string itemName in itemNames) { UcJFParamEdit pe = new UcJFParamEdit(); //pe.SetParamType(_recipe.GetItemValue(itemName).GetType()); pe.SetParamDesribe(JFParamDescribe.Create(itemName, _recipe.GetItemValue(itemName).GetType(), JFValueLimit.NonLimit, null)); pe.SetParamValue(_recipe.GetItemValue(itemName)); pe.IsValueReadOnly = true; pe.Height = 23; pe.Width = 500; pe.IsHelpVisible = false; tableLayoutPanel1.Controls.Add(pe); Button btDel = new Button(); btDel.Text = "删除"; btDel.Tag = itemName; btDel.Click += OnDelButtonClick; _lstItems.Add(pe); _lstDeleteItemButtons.Add(btDel); tableLayoutPanel1.Controls.Add(btDel); } EditRecipe = false; }
private void dgvTypes_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex < 0) { return; } if (RowIndexSelected == e.RowIndex) { return; } RowIndexSelected = e.RowIndex; if (null != initor) { initor.Dispose(); initor = null; } //while (gbParams.Controls.Count > 2) // gbParams.Controls.RemoveAt(2); panelParams.Controls.Clear(); panelParams.AutoScroll = true; initor = JFHubCenter.Instance.InitorHelp.CreateInstance(dgvTypes.Rows[e.RowIndex].Cells[0].Value.ToString()); if (null == initor) { string err = string.Format("Invoke Initor's Ctor Failed!InitorHelp.CreateInstance(Type = {0}) return null", dgvTypes.Rows[e.RowIndex].Cells[0].Value.ToString()); lbTips.Text = err; //MessageBox.Show(err); return; } //int locY = tbID.Location.Y + tbID.Size.Height + 5; string[] paramNames = initor.InitParamNames; if (null == paramNames || 0 == paramNames.Length) { return; } for (int i = 0; i < paramNames.Length; i++) { string pn = paramNames[i]; JFParamDescribe pd = initor.GetInitParamDescribe(pn); UcJFParamEdit uc = new UcJFParamEdit(); //uc.Margin = new Padding(3, 10, 3, 10); panelParams.Controls.Add(uc); uc.SetParamDesribe(pd); uc.IsValueReadOnly = false; } }
public override void UpdateSrc2UI() { if (null == _method) { return; } string[] outputNames = _method.MethodOutputNames; if (null != outputNames) { for (int i = 0; i < outputNames.Length; i++)//foreach (string outputName in outputNames) { string outputName = outputNames[i]; UcJFParamEdit ucParam = pnOutputParam.Controls[i] as UcJFParamEdit; ucParam.SetParamValue(_method.GetMethodOutputValue(outputName)); } } }
/// <summary> /// 取消编辑 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btCancel_Click(object sender, EventArgs e) { string[] inputNames = _method.MethodInputNames; if (null != inputNames) { for (int i = 0; i < inputNames.Length; i++)//foreach (string outputName in outputNames) { string inputName = inputNames[i]; UcJFParamEdit ucParam = pnInputParam.Controls[i] as UcJFParamEdit; ucParam.SetParamValue(_method.GetMethodInputValue(inputName)); ucParam.IsValueReadOnly = true; } } _isEditting = false; btCancel.Enabled = false; btSetSave.Text = "设置输入参数项"; btAction.Enabled = true; }
/// <summary> /// 将当前所选页的工站配置更新到界面上 /// </summary> void UpdateCurrPage(bool isReload, bool enabled = false) { if (null == _station) { return; } TabPage currTP = tabControlCF1.SelectedTab; if (null == currTP) { return; } TableLayoutPanel currPanel = currTP.Controls[0] as TableLayoutPanel; JFXCfg cfg = _station.Config; if (isReload) { string category = currTP.Text; currPanel.Controls.Clear(); string[] itemNames = cfg.ItemNamesInTag(category); if (null == itemNames) { return; } foreach (string itemName in itemNames) { UcJFParamEdit ucParam = new UcJFParamEdit(); ucParam.IsHelpVisible = false; ucParam.Height = 50; ucParam.Width = 600; //ucParam.SetParamDesribe(JFParamDescribe.Create(itemName, cfg.GetItemValue(itemName).GetType(), JFValueLimit.NonLimit, null)); ucParam.SetParamDesribe(_station.GetCfgParamDescribe(itemName)); currPanel.Controls.Add(ucParam); } } foreach (UcJFParamEdit ucParam in currPanel.Controls) { //object paramVal = _station.GetCfgParamValue(ucParam.GetParamDesribe().DisplayName); object paramVal = cfg.GetItemValue(ucParam.GetParamDesribe().DisplayName); ucParam.SetParamValue(paramVal); ucParam.IsValueReadOnly = !enabled; } }
void AdjustView() { timerFlush.Enabled = false; tpRealtime.Controls.Clear(); tpInitCfg.Controls.Clear(); _lstUcParam.Clear(); if (null == _method) { Label lb1 = new Label(); lb1.Text = "方法对象未设置"; tpRealtime.Controls.Add(lb1); Label lb2 = new Label(); lb2.Text = "方法对象未设置"; tpInitCfg.Controls.Add(lb1); return; } if (_method is IJFRealtimeUIProvider) { JFRealtimeUI ui = (_method as IJFRealtimeUIProvider).GetRealtimeUI(); if (null != ui) { ui.Dock = DockStyle.Fill; tpRealtime.Controls.Add(ui); timerFlush.Enabled = true; } } else { UcCommonMethodRtUi ui = new UcCommonMethodRtUi(); ui.Dock = DockStyle.Fill; ui.SetMethod(_method); tpRealtime.Controls.Add(ui); timerFlush.Enabled = true; } int locX = 3, locY = 3; if (_method is IJFConfigUIProvider)//提供参数配置界面 { Button btShowCfg = new Button(); btShowCfg.Text = "参数配置"; btShowCfg.Location = new Point(locX, locY); tpInitCfg.Controls.Add(btShowCfg); btShowCfg.Click += OnButtonClick_ShowCfgUI; locY = btShowCfg.Bottom + 2; } if (_method is IJFInitializable)//初始参数可序列化对象 { IJFInitializable initor = _method as IJFInitializable; string[] initNames = initor.InitParamNames; if (null != initNames && initNames.Length > 0) { isInitParamEditting = false; btSetSaveInit = new Button(); btSetSaveInit.Text = "编辑初始化参数"; btSetSaveInit.Location = new Point(locX, locY); btSetSaveInit.Click += OnButtonClick_InitParamSetSave; tpInitCfg.Controls.Add(btSetSaveInit); btCancelInit = new Button(); btCancelInit.Text = "取消"; btCancelInit.Location = new Point(btSetSaveInit.Right + 2, locY); btCancelInit.Click += OnButtonClick_InitParamCancel; tpInitCfg.Controls.Add(btCancelInit); btCancelInit.Enabled = false; locY = btCancelInit.Bottom + 2; for (int i = 0; i < initNames.Length; i++) { string initName = initNames[i]; JFParamDescribe pd = initor.GetInitParamDescribe(initName); UcJFParamEdit ucParam = new UcJFParamEdit(); ucParam.Width = tpInitCfg.Width - 100; ucParam.Location = new Point(locX, locY); ucParam.SetParamDesribe(pd); ucParam.SetParamValue(initor.GetInitParamValue(initName)); ucParam.IsValueReadOnly = true; _lstUcParam.Add(ucParam); tpInitCfg.Controls.Add(ucParam); ucParam.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; locY = ucParam.Bottom + 2; } InitParam2UI(); } } }
/// <summary>选择设备</summary> private void dgvDevs_CellClick(object sender, DataGridViewCellEventArgs e) { if (dgvDevs.SelectedRows.Count == 0) { return; } btRemove.Enabled = true; RemoveAllPEs(); DataGridViewRow row = dgvDevs.SelectedRows[0]; IJFInitializable dev = JFHubCenter.Instance.InitorManager[row.Cells[0].Value.ToString()]; Type devType = dev.GetType(); if (typeof(IJFDevice_Camera).IsAssignableFrom(devType) || typeof(IJFDevice_LightController).IsAssignableFrom(devType) || typeof(IJFDevice_MotionDaq).IsAssignableFrom(devType) || typeof(IJFDevice_TrigController).IsAssignableFrom(devType) || typeof(IJFRealtimeUIProvider).IsAssignableFrom(devType)) //提供调试界面 { btDebug.Enabled = true; if (typeof(IJFRealtimeUIProvider).IsAssignableFrom(devType)) { chkSelfUI.Enabled = true; } else { chkSelfUI.Checked = false; chkSelfUI.Enabled = false; } } else { btDebug.Enabled = false; } if (typeof(IJFConfigUIProvider).IsAssignableFrom(devType)) { btCfg.Enabled = true; } else { btCfg.Enabled = false; } tbDevID.Text = row.Cells[0].Value.ToString(); btInit.Enabled = !dev.IsInitOK; string[] iniParamNames = dev.InitParamNames; if (null == iniParamNames) { btEditSave.Enabled = false; return; } btEditSave.Enabled = true; int locY = btInit.Location.Y + btInit.Size.Height + 5; foreach (string ipName in iniParamNames) { UcJFParamEdit pe = new UcJFParamEdit(); pe.Width = gbParams.Width - 1; pe.Location = new Point(4, locY); pe.SetParamDesribe(dev.GetInitParamDescribe(ipName)); locY += pe.Height; pe.SetParamValue(dev.GetInitParamValue(ipName)); pe.IsValueReadOnly = true; gbParams.Controls.Add(pe); } }
bool isEditting; ///是否处于编辑初始化参数状态 /// <summary>编辑/保存 初始化参数</summary> private void btEditSave_Click(object sender, EventArgs e) { if (!isEditting)//参数未编辑状态 { if (dgvDevs.SelectedRows == null || 0 == dgvDevs.SelectedRows.Count) { MessageBox.Show("请选择需要编辑参数的对象"); return; } if (gbParams.Controls.Count <= 5) //没有初始化参数 { return; } for (int i = 5; i < gbParams.Controls.Count; i++) { UcJFParamEdit pe = gbParams.Controls[i] as UcJFParamEdit; pe.IsValueReadOnly = false; } dgvDevs.Enabled = false; btEditSave.Text = "保存"; btCancel.Enabled = true; btInit.Enabled = false; btAdd.Enabled = false; btRemove.Enabled = false; btDebug.Enabled = false; isEditting = true; } else //编辑完成,需要存储编辑后的参数 { IJFInitializable dev = JFHubCenter.Instance.InitorManager[dgvDevs.SelectedRows[0].Cells[0].Value.ToString()]; List <object> initParams = new List <object>(); initParams.Add(dev.GetType().AssemblyQualifiedName);//DevType for (int i = 5; i < gbParams.Controls.Count; i++) { object paramVal = null; UcJFParamEdit pe = gbParams.Controls[i] as UcJFParamEdit; if (!pe.GetParamValue(out paramVal)) { pe.Focus(); MessageBox.Show("参数\"" + dev.InitParamNames[i - 5] + "\"格式错误:" + pe.GetParamErrorInfo()); return; } if (!dev.SetInitParamValue(dev.InitParamNames[i - 5], paramVal)) { pe.Focus(); MessageBox.Show("设置参数\"" + dev.InitParamNames[i - 5] + "\"失败:" + dev.GetInitErrorInfo()); return; } //initParams.Add(paramVal); //替换为以下代码,适应数组/基类型混编的参数列表 //paramsInCfg.Add(dev.GetInitParamValue(dev.InitParamNames[i])); 本行代码用以下代码代替,以支持有限的 简单类型 + 数组(列表)类型的组合 //暂时的解决方法:将数组类型转化为字符串存储 Type paramType = dev.GetInitParamDescribe(dev.InitParamNames[i - 5]).ParamType; SerializableAttribute[] sas = paramType.GetCustomAttributes(typeof(SerializableAttribute), false) as SerializableAttribute[]; if (sas != null && sas.Length > 0) //如果是可序列化的类型,直接保存序列化后的文本 { StringBuilder buffer = new StringBuilder(); XmlSerializer serializer = new XmlSerializer(paramType); using (TextWriter writer = new StringWriter(buffer)) { serializer.Serialize(writer, paramVal); } string xmlTxt = buffer.ToString(); initParams.Add(xmlTxt); // paramsInCfg.Add(xmlTxt); } else { if (paramType.IsValueType || paramType == typeof(string)) //单值对象和字符串对象直接添加 { initParams.Add(paramVal); } else //目前支持Array 和 List { if (paramType.IsArray) //参数类型是数组 { if (null == paramVal) { initParams.Add(""); } else { StringBuilder sb = new StringBuilder(); string splitString = "$"; for (int j = 0; j < (paramVal as Array).Length; j++) { sb.Append((paramVal as Array).GetValue(j).ToString()); if (j < (paramVal as Array).Length - 1) { sb.Append(splitString); } } initParams.Add(sb.ToString());//paramsInCfg.Add(string.Join(splitString, paramVal)); //使用ASC 响铃符作为间隔 } } else if (typeof(IList).IsAssignableFrom(paramType)) //除了数组之外的队列类型 { if (null == paramVal) { initParams.Add(""); } else { StringBuilder sb = new StringBuilder(); string splitString = "$"; for (int j = 0; j < (paramVal as IList).Count; j++) { sb.Append((paramVal as IList)[j].ToString()); if (j < (paramVal as IList).Count - 1) { sb.Append(splitString); } } initParams.Add(sb.ToString()); //paramsInCfg.Add(string.Join(System.Text.Encoding.ASCII.GetString(new byte[] { 0x07 }), paramVal)); //使用ASC 响铃符作为间隔 } } } } } for (int i = 5; i < gbParams.Controls.Count; i++) { UcJFParamEdit pe = gbParams.Controls[i] as UcJFParamEdit; pe.IsValueReadOnly = true; } if (!dev.Initialize()) { MessageBox.Show("用当前参数初始化设备失败:" + dev.GetInitErrorInfo()); } JFXmlSortedDictionary <string, List <object> > devCfg = JFHubCenter.Instance.SystemCfg.GetItemValue(JFHubCenter.CK_InitDevParams) as JFXmlSortedDictionary <string, List <object> >; devCfg[dgvDevs.SelectedRows[0].Cells[0].Value.ToString()] = initParams; JFHubCenter.Instance.SystemCfg.NotifyItemChanged(JFHubCenter.CK_InitDevParams); JFHubCenter.Instance.SystemCfg.Save(); btInit.Enabled = true; btAdd.Enabled = true; btRemove.Enabled = true; //btDebug.Enabled = true; isEditting = false; btEditSave.Text = "编辑参数"; btCancel.Enabled = false; dgvDevs.Enabled = true; Type devType = dev.GetType(); if (typeof(IJFDevice_Camera).IsAssignableFrom(devType) || typeof(IJFDevice_LightController).IsAssignableFrom(devType) || typeof(IJFDevice_MotionDaq).IsAssignableFrom(devType) || typeof(IJFDevice_TrigController).IsAssignableFrom(devType) || typeof(IJFRealtimeUIProvider).IsAssignableFrom(devType)) //提供调试界面 { btDebug.Enabled = true; if (typeof(IJFRealtimeUIProvider).IsAssignableFrom(devType)) { chkSelfUI.Enabled = true; } else { chkSelfUI.Checked = false; chkSelfUI.Enabled = false; } } else { btDebug.Enabled = false; } if (typeof(IJFConfigUIProvider).IsAssignableFrom(devType)) { btCfg.Enabled = true; } else { btCfg.Enabled = false; } } }
/// <summary>添加新设备</summary> private void btAdd_Click(object sender, EventArgs e) { FormCreateInitor fm = new FormCreateInitor(); fm.Text = "创建" + InitorCaption + "对象"; fm.MatchType = InitorType; if (DialogResult.OK == fm.ShowDialog()) { IJFInitializable newDevice = fm.Initor; string devID = fm.ID; JFHubCenter.Instance.InitorManager.Add(devID, newDevice); DataGridViewRow row = new DataGridViewRow(); DataGridViewTextBoxCell cellID = new DataGridViewTextBoxCell(); cellID.Value = devID; row.Cells.Add(cellID); DataGridViewTextBoxCell cellModel = new DataGridViewTextBoxCell(); cellModel.Value = JFinitializerHelper.DispalyTypeName(newDevice.GetType()); row.Cells.Add(cellModel); DataGridViewTextBoxCell cellType = new DataGridViewTextBoxCell(); cellType.Value = newDevice.GetType().Name; row.Cells.Add(cellType); dgvDevs.Rows.Add(row); newDevice.Initialize(); if (!newDevice.IsInitOK) { btInit.Enabled = true; row.DefaultCellStyle.ForeColor = Color.Red; } else { btInit.Enabled = false; } /// 更新参数到界面 dgvDevs.Rows[dgvDevs.Rows.Count - 1].Selected = true; RemoveAllPEs(); string[] iniParamNames = newDevice.InitParamNames; if (null == iniParamNames) { btEditSave.Enabled = false; return; } btEditSave.Enabled = true; int locY = btInit.Location.Y + btInit.Size.Height + 5; foreach (string ipName in iniParamNames) { UcJFParamEdit pe = new UcJFParamEdit(); pe.Width = gbParams.Width - 1; pe.Location = new Point(4, locY); pe.SetParamDesribe(newDevice.GetInitParamDescribe(ipName)); locY += pe.Height; pe.SetParamValue(newDevice.GetInitParamValue(ipName)); pe.IsValueReadOnly = true; gbParams.Controls.Add(pe); } Type devType = newDevice.GetType(); if (typeof(IJFDevice_Camera).IsAssignableFrom(devType) || typeof(IJFDevice_LightController).IsAssignableFrom(devType) || typeof(IJFDevice_MotionDaq).IsAssignableFrom(devType) || typeof(IJFDevice_TrigController).IsAssignableFrom(devType) || typeof(IJFRealtimeUIProvider).IsAssignableFrom(devType)) //提供调试界面 { btDebug.Enabled = true; if (typeof(IJFRealtimeUIProvider).IsAssignableFrom(devType)) { chkSelfUI.Enabled = true; } else { chkSelfUI.Checked = false; chkSelfUI.Enabled = false; } } else { btDebug.Enabled = false; } if (typeof(IJFConfigUIProvider).IsAssignableFrom(devType)) { btCfg.Enabled = true; } else { btCfg.Enabled = false; } } }
void AdjustStationView() { if (InvokeRequired) { Invoke(new Action(AdjustStationView)); return; } tabControlCF1.TabPages.Clear(); isEditting = false; btEditSave.Text = "编辑"; btCancel.Enabled = false; if (null == _station) { lbInfo.Text = "工站未设置!"; btEditSave.Enabled = false; return; } lbInfo.Text = "工站:" + _station.Name; JFXCfg cfg = _station.Config; string[] categorys = cfg.AllTags; if (null == categorys || categorys.Length < 2) //只有一个无名称Tag,由于保存私有配置 { lbInfo.Text += " 无定制化参数"; btEditSave.Enabled = false; return; } btEditSave.Enabled = true; foreach (string category in categorys) { if (string.IsNullOrEmpty(category)) { continue; } TabPage tp = new TabPage(category); tabControlCF1.TabPages.Add(tp); string[] itemNames = cfg.ItemNamesInTag(category); if (null == itemNames) { continue; } TableLayoutPanel panel = new TableLayoutPanel(); panel.ColumnCount = 1; panel.AutoScroll = true; panel.Dock = DockStyle.Fill; tp.Controls.Add(panel); foreach (string itemName in itemNames) { UcJFParamEdit ucParam = new UcJFParamEdit(); ucParam.IsHelpVisible = false; ucParam.Height = 23; ucParam.SetParamDesribe(_station.GetCfgParamDescribe(itemName)); ucParam.SetParamValue(_station.GetCfgParamValue(itemName)); ucParam.IsValueReadOnly = false; panel.Controls.Add(ucParam); ucParam.IsValueReadOnly = true; } } //if (tabControlCF1.TabCount > 0) // tabControlCF1.SelectedIndex = 0; }
void AdjustStationView() { if (InvokeRequired) { Invoke(new Action(AdjustStationView)); return; } tabControlCF1.TabPages.Clear(); isEditting = false; btEditSave.Text = "编辑"; btCancel.Enabled = false; if (null == _station) { lbInfo.Text = "工站未设置!"; btEditSave.Enabled = false; return; } JFXCfg cfg = _station.Config; lbInfo.Text = "工站:" + _station.Name + " 文件路径:" + cfg.FilePath; string[] namedCategorys = cfg.AllTags; //if(null == categorys || categorys.Length < 2) //只有一个无名称Tag,由于保存私有配置 //{ // lbInfo.Text += " 无定制化参数"; // btEditSave.Enabled = false; // return; //} List <string> categorys = new List <string>(); if (!AllowedShowUnnameTag) { if (null == categorys || categorys.Count < 2) //只有一个无名称Tag,由于保存私有配置 { lbInfo.Text += " 无定制化参数"; btEditSave.Enabled = false; return; } } else { categorys.Add(""); } if (namedCategorys != null) { categorys.AddRange(namedCategorys); } btEditSave.Enabled = true; foreach (string category in categorys) { if (string.IsNullOrEmpty(category)) { continue; } TabPage tp = new TabPage(category); tabControlCF1.TabPages.Add(tp); string[] itemNames = cfg.ItemNamesInTag(category); if (null == itemNames) { continue; } TableLayoutPanel panel = new TableLayoutPanel(); //panel.RowStyles[0] = new RowStyle(SizeType.Absolute, 55); panel.RowStyles.Add(new RowStyle(SizeType.Absolute, 55)); panel.ColumnCount = 1; panel.AutoScroll = true; panel.Dock = DockStyle.Fill; tp.Controls.Add(panel); for (int i = 0; i < itemNames.Length; i++)//foreach (string itemName in itemNames) { string itemName = itemNames[i]; UcJFParamEdit ucParam = new UcJFParamEdit(); ucParam.IsHelpVisible = false; ucParam.Height = 50; ucParam.Width = 600;//panel.Width*2/3; //ucParam.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right ; ucParam.SetParamDesribe(_station.GetCfgParamDescribe(itemName)); //ucParam.SetParamDesribe(JFParamDescribe.Create(itemName, cfg.GetItemValue(itemName).GetType(), JFValueLimit.NonLimit, null)); ucParam.SetParamValue(cfg.GetItemValue(itemName)); ucParam.IsValueReadOnly = false; panel.Controls.Add(ucParam); ucParam.IsValueReadOnly = true; //panel.RowStyles[i].SizeType = SizeType.Absolute; //panel.RowStyles[i].Height = 55; } } //if (tabControlCF1.TabCount > 0) // tabControlCF1.SelectedIndex = 0; }