private void roundButton_VisionPrTest_Click(object sender, EventArgs e) { if (comboBox_SelVisionPR.SelectedIndex == -1) { return; } string strVisionPrName = comboBox_SelVisionPR.Items[comboBox_SelVisionPR.SelectedIndex].ToString(); roundButton_VisionPrTest.Enabled = false; Action action = new Action(() => { string camname = VisionMgr.GetInstance().GetCamName(strVisionPrName); double?Expouse = VisionMgr.GetInstance().GetExpourseTime(strVisionPrName); double?Gain = VisionMgr.GetInstance().GetGain(strVisionPrName); CameraMgr.GetInstance().SetCamExposure(camname, (double)Expouse); CameraMgr.GetInstance().SetCamGain(camname, (double)Gain); CameraMgr.GetInstance().BindWindow(camname, visionControl1); CameraMgr.GetInstance().ClaerPr(camname); CameraMgr.GetInstance().GetCamera(camname).SetTriggerMode(CameraModeType.Software); } ); action.BeginInvoke((ar) => { roundButton_VisionPrTest.Invoke((MethodInvoker)(() => { roundButton_VisionPrTest.Enabled = true; }), null); }, null); }
private void Form_Manual_Load(object sender, EventArgs e) { visionControl1.InitWindow(); Thread.Sleep(10); List <string> camname = CameraMgr.GetInstance().GetCameraNameArr(); foreach (var temp in camname) { comboBox_SelCamera.Items.Add(temp.ToString()); } if (camname != null && camname.Count > 0) { comboBox_SelCamera.Visible = true; comboBox_SelCamera.SelectedIndex = 0; } else { visionControl1.Visible = false; button_ContinuousSnap.Visible = false; button2.Visible = false; comboBox_SelVisionPR.Visible = false; roundButton_VisionPrTest.Visible = false; } VisionMgr.GetInstance().PrItemChangedEvent += ChagedPrItem; ChagedPrItem(""); }
private void LoadProductFile(string strFile) { if (InvokeRequired) { this.BeginInvoke(new Action(() => LoadProductFile(strFile))); } else { label_CurrentFile.Text = "当前产品:" + strFile; //读取工站位置坐标 ConfigToolMgr.GetInstance().UpdatePointFilePath(); Dictionary <string, PointInfo> dicPonit = new Dictionary <string, PointInfo>(); foreach (var tem in StationMgr.GetInstance().GetAllStationName()) { ConfigToolMgr.GetInstance().ReadPoint(tem, out dicPonit); StationMgr.GetInstance().GetStation(tem).SetStationPointDic(dicPonit); } ConfigToolMgr.GetInstance().UpdataMoveparamconfigPath(); ConfigToolMgr.GetInstance().ReadMoveParamConfig(); ConfigToolMgr.GetInstance().ReadHomeParamConfig(); VisionMgr.GetInstance().CurrentVisionProcessDir = ParamSetMgr.GetInstance().CurrentWorkDir + "\\" + ParamSetMgr.GetInstance().CurrentProductFile + "\\" + @"Config\Vision\"; VisionMgr.GetInstance().Read(); ParamSetMgr.GetInstance().m_eventLoadProductFileUpadata?.Invoke(); //VisionMgr.GetInstance().PrItemChangedEvent GC.Collect(); } }
private void roundButton_AddItem_Click(object sender, EventArgs e) { ItemAdd itemAdd = null; if (CameraMgr.GetInstance().GetCameraNameArr() != null && CameraMgr.GetInstance().GetCameraNameArr().Count > 0) { itemAdd = new ItemAdd(CameraMgr.GetInstance().GetCameraNameArr().ToArray()); } else { itemAdd = new ItemAdd(null); } DialogResult dialogResult = itemAdd.ShowDialog(); if (dialogResult == DialogResult.Yes) { if (VisionMgr.GetInstance().GetItemNamesAndTypes().ContainsKey(itemAdd.ItemName)) { MessageBox.Show("视觉处理:名称重复", "Err", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { int index = dataGridViewProcessItem.Rows.Count; CreateAndSaveItem(itemAdd.ItemName, itemAdd.VisionProcssName, itemAdd.CamName, itemAdd.Exposure, itemAdd.Gain); } dataGridViewProcessItem.Rows.Add("False", itemAdd.ItemName, itemAdd.VisionProcssName, itemAdd.CamName, itemAdd.Exposure.ToString(), itemAdd.Gain.ToString()); } }
/// <summary> /// 当前项目的Type 返回中文名 类型 /// </summary> /// <param name="strItem"></param> /// <returns></returns> string GetChinseNameByVisionType(string strItem) { int nIndex = VisionMgr.GetInstance().GetItemNamesAndTypes()[strItem].VisionType.LastIndexOf("."); string strType = VisionMgr.GetInstance().GetItemNamesAndTypes()[strItem].VisionType.Substring(nIndex + 1); string strTypeName = ""; switch (strType) { case "VisionShapMatch": strTypeName = "模板匹配"; break; case "Vision2dCode": strTypeName = "二维码"; break; case "Vision1dCode": strTypeName = "一维码"; break; default: MessageBox.Show("视觉处理基类未完善", "Err", MessageBoxButtons.OK, MessageBoxIcon.Error); break; } return(strTypeName); }
public void CreateAndSaveItem(string strItem, string strVisionType, string strCamName, double dExposure, double dGain) { VisionSetpBase visionSetpBase = VisionMgr.GetInstance().GetItem(strItem); StepVisionInfo stepVisionInfo = new StepVisionInfo(); if (visionSetpBase == null) { visionSetpBase = CreatVisonObjByType(strVisionType, strItem); } else { string strTypeName = ""; //string strTypeName= GetChinseNameByVisionType(strItem); if (strVisionType != visionSetpBase.PrTyppeItem.ToString()) { visionSetpBase = CreatVisonObjByType(strVisionType, strItem); } } visionSetpBase.m_camparam.m_dGain = dGain; visionSetpBase.m_camparam.m_dExposureTime = dExposure; visionSetpBase.m_camparam.m_strCamName = strCamName; stepVisionInfo.CamParam = visionSetpBase.m_camparam; stepVisionInfo.VisionType = visionSetpBase.GetType().ToString(); VisionMgr.GetInstance().Add(strItem, visionSetpBase, stepVisionInfo); string strVisonItems = VisionMgr.GetInstance().CurrentVisionProcessDir + "VisionMgr.xml"; if (File.Exists(strVisonItems)) { File.Delete(strVisonItems); } VisionMgr.GetInstance().Save(); }
public void init() { string strPath = VisionMgr.GetInstance().CurrentVisionProcessDir + "\\" + "Calib" + "\\" + "DownCCDRobot" + ".xml"; resultCalib = (ResultCalib)resultCalib.Read(strPath); xYMoveCalib.CreateDownRobotCoor(resultCalib.VisionCol.ToArray(), resultCalib.VisionRow.ToArray(), resultCalib.MachineX.ToArray(), resultCalib.MachineY.ToArray()); strPath = VisionMgr.GetInstance().CurrentVisionProcessDir + "\\" + "Calib" + "\\" + "DownCol.tup"; HTuple hTupleDcol; HOperatorSet.ReadTuple(strPath, out hTupleDcol); strPath = VisionMgr.GetInstance().CurrentVisionProcessDir + "\\" + "Calib" + "\\" + "DownRow.tup"; HTuple hTupleDrow; HOperatorSet.ReadTuple(strPath, out hTupleDrow); strPath = VisionMgr.GetInstance().CurrentVisionProcessDir + "\\" + "Calib" + "\\" + "UpCol.tup"; HTuple hTupleUcol; HOperatorSet.ReadTuple(strPath, out hTupleUcol); strPath = VisionMgr.GetInstance().CurrentVisionProcessDir + "\\" + "Calib" + "\\" + "UpRow.tup"; HTuple hTupleUrow; HOperatorSet.ReadTuple(strPath, out hTupleUrow); // xYMoveCalib.CreateUpToDownCameraCoor(hTupleUcol.DArr, hTupleUrow.DArr, hTupleDcol.DArr, hTupleDrow.DArr); xYMoveCalib.CreateUpDownCameraCoor(hTupleUcol.DArr, hTupleUrow.DArr, hTupleDcol.DArr, hTupleDrow.DArr); string strPath1 = VisionMgr.GetInstance().CurrentVisionProcessDir + "\\" + "Calib" + "\\" + "offset" + ".xml"; resultCalib = (ResultCalib)resultCalib.Read(strPath1); }
private void UpdataVisionItems() { VisionSetpBase visionSetpBase = null; if (VisionMgr.GetInstance().GetItemNamesAndTypes() == null) { return; } dataGridViewProcessItem.Rows.Clear(); foreach (var tem in VisionMgr.GetInstance().GetItemNamesAndTypes()) { int index = tem.Value.VisionType.LastIndexOf("."); string strVisionProcessType = tem.Value.VisionType.Substring(index + 1); string strVisionTypeName = ""; if (TypeLists != null) { Type type = TypeLists.Find((t) => { return(tem.Value.VisionType == t.ToString() ? true : false); }); strVisionTypeName = AssemblyOperate.GetDescription(type); } visionSetpBase = VisionMgr.GetInstance().GetItem(tem.Key); dataGridViewProcessItem.Rows.Add("False", tem.Key, strVisionTypeName, visionSetpBase.m_camparam.m_strCamName, visionSetpBase.m_camparam.m_dExposureTime.ToString(), visionSetpBase.m_camparam.m_dGain.ToString()); } }
private void roundButton_Test_Click(object sender, EventArgs e) { if (indexSelVisionSel == -1) { MessageBox.Show("请勾选视觉处理项目", "Err", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } string str = dataGridViewProcessItem.Rows[indexSelVisionSel].Cells[1].Value.ToString(); VisionSetpBase visionSetpBase = VisionMgr.GetInstance().GetItem(str); Action action = new Action(() => { visionSetpBase.Process_image(visionControl1.Img, visionControl1); }); action.BeginInvoke((ar) => { }, null); }
public static bool ReadVisionData() { //视觉初始化 string strVisionConfigPath = AppDomain.CurrentDomain.BaseDirectory + @"config\Vision\" + "VisionMgr" + ".xml"; VisionMgr.GetInstance().CurrentVisionProcessDir = ParamSetMgr.GetInstance().CurrentWorkDir + "\\" + ParamSetMgr.GetInstance().CurrentProductFile + "\\" + @"Config\Vision\"; VisionMgr.GetInstance().Read(); if (VisionMgr.GetInstance().dicVisionType.Count == 0 && bHaveVissionProcess) { AlarmMgr.GetIntance().WarnWithDlg("视觉处理文件文件丢失", null, CommonDlg.DlgWaranType.WaranOK, null, true); } return(true); }
public void ChagedPrItem(string name) { if (InvokeRequired) { this.BeginInvoke(new Action(() => { ChagedPrItem(name); })); } else { comboBox_SelVisionPR.Items.Clear(); foreach (var tem in VisionMgr.GetInstance().GetItemNamesAndTypes()) { comboBox_SelVisionPR.Items.Add(tem.Key); } } }
private void roundButton_Save_Click(object sender, EventArgs e) { // VisionMgr.GetInstance().Save(); if (indexSelVisionSel == -1) { return; } if (dataGridViewProcessItem.Rows[indexSelVisionSel].Cells[1].Value == null || dataGridViewProcessItem.Rows[indexSelVisionSel].Cells[1].Value.ToString() == "") { return; } string strItem = dataGridViewProcessItem.Rows[indexSelVisionSel].Cells[1].Value.ToString(); //判断视觉Item是否填写完整 if (!IstemOK(indexSelVisionSel)) { return; } string strVisionType = dataGridViewProcessItem.Rows[indexSelVisionSel].Cells[2].Value.ToString(); double dExposure = dataGridViewProcessItem.Rows[indexSelVisionSel].Cells[4].Value.ToString().ToDouble(); double dGain = dataGridViewProcessItem.Rows[indexSelVisionSel].Cells[5].Value.ToString().ToDouble(); string strCamName = dataGridViewProcessItem.Rows[indexSelVisionSel].Cells[3].Value.ToString(); switch (strVisionType) { case "模板匹配": Vision_MatchSetCtr1.SaveParm(VisionMgr.GetInstance().GetItem(strItem)); break; case "二维码": vision_2dCodeSetCtr1.SaveParm(VisionMgr.GetInstance().GetItem(strItem)); break; case "一维码": vision_1BarCodeSetCtr1.SaveParm(VisionMgr.GetInstance().GetItem(strItem)); break; case "找圆": vision_FindCircleCtr1.SaveParm(VisionMgr.GetInstance().GetItem(strItem)); break; } CreateAndSaveItem(strItem, strVisionType, strCamName, dExposure, dGain); }
void UpdataVisionItems() { VisionSetpBase visionSetpBase = null; if (VisionMgr.GetInstance().GetItemNamesAndTypes() == null) { return; } dataGridViewProcessItem.Rows.Clear(); foreach (var tem in VisionMgr.GetInstance().GetItemNamesAndTypes()) { int index = tem.Value.VisionType.LastIndexOf("."); string strVisionProcessType = tem.Value.VisionType.Substring(index + 1); string strVisionTypeName = ""; //strVisionTypeName = GetChinseNameByVisionType(tem.Key); // strVisionTypeName= visionSetpBase = VisionMgr.GetInstance().GetItem(tem.Key); strVisionTypeName = visionSetpBase.PrTyppeItem.ToString(); dataGridViewProcessItem.Rows.Add("False", tem.Key, strVisionTypeName, visionSetpBase.m_camparam.m_strCamName, visionSetpBase.m_camparam.m_dExposureTime.ToString(), visionSetpBase.m_camparam.m_dGain.ToString()); } }
private void roundButton_SeachArea_Click(object sender, EventArgs e) { if (indexSelVisionSel == -1) { MessageBox.Show("请勾选视觉处理项目", "Err", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } HTuple row1, col1, row2, col2; HObject obj = visionControl1.DrawRectangle(out row1, out col1, out row2, out col2); string str = dataGridViewProcessItem.Rows[indexSelVisionSel].Cells[1].Value.ToString(); VisionSetpBase visionSetpBase = VisionMgr.GetInstance().GetItem(str); string strPath = VisionMgr.GetInstance().CurrentVisionProcessDir + "\\" + str + "\\" + str + "_SearchRect.hobj"; switch (dataGridViewProcessItem.Rows[indexSelVisionSel].Cells[2].Value.ToString()) { case "模板匹配": ((VisionShapMatch)visionSetpBase).visionShapParam.SeachRectRegionPath = strPath; HOperatorSet.WriteRegion(obj, strPath); visionSetpBase.Save(); ((VisionShapMatch)visionSetpBase).Read(); break; case "二维码": ((Vision2dCode)visionSetpBase).vision2dCodeParam.Mode2dcodeSearchPath = strPath; HOperatorSet.WriteRegion(obj, strPath); visionSetpBase.Save(); ((Vision2dCode)visionSetpBase).Read(); break; case "一维码": ((Vision1dCode)visionSetpBase).vision1dCodeParam.Mode1dcodeSearchPath = strPath; HOperatorSet.WriteRegion(obj, strPath); visionSetpBase.Save(); ((Vision1dCode)visionSetpBase).Read(); break; } obj.Dispose(); }
private void roundButton_Save_Click(object sender, EventArgs e) { // VisionMgr.GetInstance().Save(); if (indexSelVisionSel == -1) { return; } if (dataGridViewProcessItem.Rows[indexSelVisionSel].Cells[1].Value == null || dataGridViewProcessItem.Rows[indexSelVisionSel].Cells[1].Value.ToString() == "") { return; } string strItem = dataGridViewProcessItem.Rows[indexSelVisionSel].Cells[1].Value.ToString(); //判断视觉Item是否填写完整 if (!IsItemOK(indexSelVisionSel)) { return; } string strVisionType = dataGridViewProcessItem.Rows[indexSelVisionSel].Cells[2].Value.ToString(); double dExposure = dataGridViewProcessItem.Rows[indexSelVisionSel].Cells[4].Value.ToString().ToDouble(); double dGain = dataGridViewProcessItem.Rows[indexSelVisionSel].Cells[5].Value.ToString().ToDouble(); string strCamName = dataGridViewProcessItem.Rows[indexSelVisionSel].Cells[3].Value.ToString(); int nlight = dataGridViewProcessItem.Rows[indexSelVisionSel].Cells[3].Value.ToString().ToInt(); VisionMgr.GetInstance().SetLightVal(strItem, nlight); VisionSetpBase visionSetpBase = VisionMgr.GetInstance().GetItem(strItem); visionSetpBase.m_camparam.m_dGain = dGain; visionSetpBase.m_camparam.m_dExposureTime = dExposure; visionSetpBase.m_camparam.m_strCamName = strCamName; visionSetpBase.SaveParm(); visionSetpBase.Save(); VisionMgr.GetInstance().Save(); }
private void roundButton_Add_Click(object sender, EventArgs e) { VisionProcssName = comboBox_SelVisionProcessType.Text; CamName = comboBox_camSel.Text; Exposure = textBox_ExposureTime.Text.ToDouble(); Gain = textBox_Gain.Text.ToDouble(); ItemName = textBox_ItemName.Text; nLightVal = txtLightVal.Text.ToInt(); if (Gain == 0 || Exposure == 0 || VisionProcssName == "" || ItemName == "") { MessageBox.Show("参数设置错误", "Err", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { Close(); Dispose(); if (VisionMgr.GetInstance().GetItemNamesAndTypes().ContainsKey(ItemName)) { MessageBox.Show($"{ItemName} 已经存在此项,重名了", "Err", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Type ty = AssemblyOperate.GetTypeFromAssemblyByDescrition(VisionProcssName, typeof(VisionSetpBase)); visionSetpBase = Activator.CreateInstance(ty, ItemName) as VisionSetpBase; visionSetpBase.m_camparam.m_dExposureTime = Exposure; visionSetpBase.m_camparam.m_dGain = Gain; visionSetpBase.m_camparam.m_strCamName = CamName; StepVisionInfo stepVisionInfo = new StepVisionInfo(); stepVisionInfo.CamParam = visionSetpBase.m_camparam; stepVisionInfo.VisionType = ty.ToString(); stepVisionInfo.nLightVal = nLightVal; VisionMgr.GetInstance().Add(ItemName, visionSetpBase, stepVisionInfo); VisionMgr.GetInstance().Save(); this.DialogResult = DialogResult.Yes; } }
private void roundButton_DelItem_Click(object sender, EventArgs e) { int CellSelectedRow = dataGridViewProcessItem.SelectedCells[0].RowIndex; if (dataGridViewProcessItem.Rows[CellSelectedRow].Cells[0].Value == null) { return; } string strItemName = dataGridViewProcessItem.Rows[CellSelectedRow].Cells[1].Value.ToString(); DataGridViewRow row = dataGridViewProcessItem.Rows[CellSelectedRow]; dataGridViewProcessItem.Rows.Remove(row); VisionMgr.GetInstance().DelItem(strItemName); VisionMgr.GetInstance().Save(); foreach (var temp in panel_VisionCtrls.Controls) { ((Control)temp).Hide(); } if (indexSelVisionSel != -1 && indexSelVisionSel == CellSelectedRow) { indexSelVisionSel = -1; } }
public void Save() { string strPath = VisionMgr.GetInstance().CurrentVisionProcessDir + "\\" + "Calib" + "\\" + "offset" + ".xml"; resultCalib.Save(strPath); }
private void dataGridViewProcessItem_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (this.dataGridViewProcessItem.Rows[e.RowIndex].Cells[e.ColumnIndex].GetType() != typeof(DataGridViewCheckBoxCell)) { return; } if (this.dataGridViewProcessItem.Rows[e.RowIndex].Cells[e.ColumnIndex].GetType() == typeof(DataGridViewCheckBoxCell)) { for (int i = 0; i < this.dataGridViewProcessItem.RowCount; i++) { this.dataGridViewProcessItem.Rows[i].Cells[e.ColumnIndex].Value = false; } //this.dataGridViewProcessItem.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = true; indexSelVisionSel = e.RowIndex; } DataGridViewCheckBoxCell checkCell = (DataGridViewCheckBoxCell)this.dataGridViewProcessItem.Rows[e.RowIndex].Cells[e.ColumnIndex]; if ((bool)checkCell.EditedFormattedValue == true) { indexSelVisionSel = e.RowIndex; } else { indexSelVisionSel = -1; } foreach (var temp in panel_VisionCtrls.Controls) { ((Control)temp).Hide(); } if (indexSelVisionSel == -1) { dataGridViewProcessItem.Columns[2].ReadOnly = true; return; } dataGridViewProcessItem.Columns[2].ReadOnly = false; //if (!IstemOK(e.RowIndex)) return; string ItemName = ""; ItemName = dataGridViewProcessItem.Rows[e.RowIndex].Cells[1].Value.ToString(); VisionSetpBase visionSetpBase = VisionMgr.GetInstance().GetItem(ItemName); if (dataGridViewProcessItem.Rows[e.RowIndex].Cells[2].Value.ToString() != visionSetpBase.PrTyppeItem.ToString()) { string str = visionSetpBase.m_strStepName + " 当前的视觉类型为:" + visionSetpBase.PrTyppeItem.ToString() + "是否切换到视觉类型:" + dataGridViewProcessItem.Rows[e.RowIndex].Cells[2].Value.ToString(); DialogResult dialogResult = MessageBox.Show(str, "Err", MessageBoxButtons.YesNo, MessageBoxIcon.Error); if (dialogResult == DialogResult.Yes) { visionSetpBase.Disopose(); string camname = visionSetpBase.m_camparam.m_strCamName; double exposure = visionSetpBase.m_camparam.m_dExposureTime; double dGain = visionSetpBase.m_camparam.m_dGain; VisionMgr.GetInstance().DelItem(ItemName); visionSetpBase = null; string strtype = dataGridViewProcessItem.Rows[e.RowIndex].Cells[2].Value.ToString(); CreateAndSaveItem(ItemName, strtype, camname, exposure, dGain); visionSetpBase = VisionMgr.GetInstance().GetItem(ItemName); } else { return; } } switch (dataGridViewProcessItem.Rows[e.RowIndex].Cells[2].Value.ToString()) { case "模板匹配": Vision_MatchSetCtr1.Show(); Vision_MatchSetCtr1.FlushToDlg(visionSetpBase, visionControl1); roundButton_ShapeROIAdd.Show(); roundButton_ShapeROISub.Show(); break; case "二维码": vision_2dCodeSetCtr1.Show(); vision_2dCodeSetCtr1.FlushToDlg(visionSetpBase, visionControl1); break; case "一维码": vision_1BarCodeSetCtr1.Show(); vision_1BarCodeSetCtr1.FlushToDlg(visionSetpBase, visionControl1); break; case "找圆": vision_FindCircleCtr1.Show(); vision_FindCircleCtr1.FlushToDlg(visionSetpBase, visionControl1); break; } roundButton_SeachArea.Show(); // roundButton_DrawRect1.Show(); roundButton_Test.Show(); }
public object read() { string strPath = VisionMgr.GetInstance().CurrentVisionProcessDir + "\\" + "Calib" + "\\" + "offset" + ".xml"; return resultCalib.Read(strPath); }
private void dataGridViewProcessItem_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (this.dataGridViewProcessItem.Rows[e.RowIndex].Cells[e.ColumnIndex].GetType() != typeof(DataGridViewCheckBoxCell)) { return; } if (this.dataGridViewProcessItem.Rows[e.RowIndex].Cells[e.ColumnIndex].GetType() == typeof(DataGridViewCheckBoxCell)) { for (int i = 0; i < this.dataGridViewProcessItem.RowCount; i++) { this.dataGridViewProcessItem.Rows[i].Cells[e.ColumnIndex].Value = false; } //this.dataGridViewProcessItem.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = true; indexSelVisionSel = e.RowIndex; } DataGridViewCheckBoxCell checkCell = (DataGridViewCheckBoxCell)this.dataGridViewProcessItem.Rows[e.RowIndex].Cells[e.ColumnIndex]; if ((bool)checkCell.EditedFormattedValue == true) { indexSelVisionSel = e.RowIndex; } else { indexSelVisionSel = -1; } foreach (var temp in panel_VisionCtrls.Controls) { ((Control)temp).Hide(); } if (indexSelVisionSel == -1) { dataGridViewProcessItem.Columns[2].ReadOnly = true; return; } dataGridViewProcessItem.Columns[2].ReadOnly = false; string ItemName = ""; ItemName = dataGridViewProcessItem.Rows[e.RowIndex].Cells[1].Value.ToString(); VisionSetpBase visionSetpBase = VisionMgr.GetInstance().GetItem(ItemName); //if( // dataGridViewProcessItem.Rows[e.RowIndex].Cells[2].Value.ToString()!="" && // AssemblyOperate.GetDescription(visionSetpBase.GetType())!="NoDescrition"&& // dataGridViewProcessItem.Rows[e.RowIndex].Cells[2].Value.ToString()!= AssemblyOperate.GetDescription(visionSetpBase.GetType())) //{ // string str = visionSetpBase.m_strStepName + " 当前的视觉类型为:" + AssemblyOperate.GetDescription(visionSetpBase.GetType()) + "是否切换到视觉类型:" + dataGridViewProcessItem.Rows[e.RowIndex].Cells[2].Value.ToString(); // DialogResult dialogResult= MessageBox.Show(str, "Err", MessageBoxButtons.YesNo, MessageBoxIcon.Error); // if(dialogResult== DialogResult.Yes) // { // visionSetpBase.Disopose(); // string camname = visionSetpBase.m_camparam.m_strCamName; // double exposure = visionSetpBase.m_camparam.m_dExposureTime; // double dGain = visionSetpBase.m_camparam.m_dGain; // VisionMgr.GetInstance().DelItem(ItemName); // visionSetpBase = null; // string strtype = dataGridViewProcessItem.Rows[e.RowIndex].Cells[2].Value.ToString(); // visionSetpBase= VisionMgr.GetInstance().GetItem(ItemName); // } // else // return; //} visionSetpBase.FlushToDlg(visionControl1, panel_VisionCtrls); if (dataGridViewProcessItem.Rows[e.RowIndex].Cells[2].Value.ToString() == "模板匹配") { roundButton_ShapeROIAdd.Show(); roundButton_ShapeROISub.Show(); } else { roundButton_ShapeROIAdd.Hide(); roundButton_ShapeROISub.Hide(); } roundButton_SeachArea.Show(); roundButton_Test.Show(); }
private void Form1_Load(object sender, EventArgs e) { //读取网口串口配置 ParamSetMgr.GetInstance().SetBoolParam("启用安全门", true); ParamSetMgr.GetInstance().SetBoolParam("启用安全光栅", true); ConfigToolMgr.GetInstance().ReadEthConfig(); ConfigToolMgr.GetInstance().ReadComConfig(); //读硬件配置 并创建IO,Motion 卡类 对象 并以默认参数配置卡 ConfigToolMgr.GetInstance().ReadMotionCardConfig(); ConfigToolMgr.GetInstance().ReadIoCardConfig(); ConfigToolMgr.GetInstance().ReadIoInputConfig(); ConfigToolMgr.GetInstance().ReadIoOutputConfig(); //读工站配置 ConfigToolMgr.GetInstance().ReadStationConfig(); //读取用户设置 ConfigToolMgr.GetInstance().ReadUserConfig(); //读取产品文件 ConfigToolMgr.GetInstance().ReadProductDir_Name(); //读运动配置 ConfigToolMgr.GetInstance().ReadMoveParamConfig(); ConfigToolMgr.GetInstance().ReadHomeParamConfig(); ConfigToolMgr.GetInstance().ReadUserParam(); //视觉x文件路径初始化 VisionMgr.GetInstance().CurrentVisionProcessDir = ParamSetMgr.GetInstance().CurrentWorkDir + "\\" + ParamSetMgr.GetInstance().CurrentProductFile + "\\" + @"Config\Vision\"; string str = VisionMgr.GetInstance().CurrentVisionProcessDir; //初始化 Motion IO MotionMgr.GetInstace().OpenAllCard(); IOMgr.GetInstace().initAllIoCard(); //AA参数加载 UserConfig.BandEventOnForm1(this); this.WindowState = FormWindowState.Maximized; int BtnHeight = button_stop.Height + 10; panel_window.Location = new System.Drawing.Point(0, BtnHeight); panel_window.Size = new Size(this.Width - 30, this.Height - BtnHeight - 1); Form_Auto autoform = new Form_Auto(); m_dicAllWindows.Add(button_Home, autoform); m_dicAllWindows.Add(button_Set, new Form_Set()); m_dicAllWindows.Add(button_vision, new Form_VisionDebug()); m_dicAllWindows.Add(button_Param, new Form_ParamSet()); m_dicAllWindows.Add(button_UserSMgr, new UserManger()); m_currentForm = autoform; UserConfig.AddStation(); //读取工站位置坐标 Dictionary <string, PointInfo> dicPonit = new Dictionary <string, PointInfo>(); foreach (var tem in StationMgr.GetInstance().GetAllStationName()) { ConfigToolMgr.GetInstance().ReadPoint(tem, out dicPonit); StationMgr.GetInstance().GetStation(tem).SetStationPointDic(dicPonit); } // 注册安全函数 UserConfig.AddIoSafeOperate(); UserConfig.AddAxisSafeOperate(); //初始化 工站状态 GlobalVariable.g_StationState = StationState.StationStateStop; IOMgr.GetInstace().m_deltgateSystemSingl += ProcessSysIo; MotionMgr.GetInstace().m_eventAxisSingl += ProcessSysIo; autoform.TopLevel = false; autoform.Dock = DockStyle.Fill; autoform.Parent = this.panel_window; autoform.Show(); //初始化权限 sys.g_eventRightChanged += ChangedUserRight; User user = new User(); int index = sys.g_listUser.FindIndex(t => t._userName == "admin"); if (index == -1) { user = new User() { _userName = "******", _userPassWord = "******", _userRight = UserRight.超级管理员 }; sys.g_listUser.Add(user); } index = sys.g_listUser.FindIndex(t => t._userName == "user"); if (index == -1) { user = new User() { _userName = "******", _userPassWord = "******", _userRight = UserRight.客户操作员 }; sys.g_listUser.Add(user); } index = sys.g_listUser.FindIndex(t => t._userName == "debug"); if (index == -1) { user = new User() { _userName = "******", _userPassWord = "******", _userRight = UserRight.调试工程师 }; sys.g_listUser.Add(user); } index = sys.g_listUser.FindIndex(t => t._userName == "engineer"); if (index == -1) { user = new User() { _userName = "******", _userPassWord = "******", _userRight = UserRight.软件工程师 }; sys.g_listUser.Add(user); } GlobalVariable.g_eventStationStateChanged += StationStateChangedHandler; }
private void roundButton_ShapeROISub_Click(object sender, EventArgs e) { if (indexSelVisionSel == -1) { MessageBox.Show("请勾选视觉处理项目", "Err", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } HTuple row1, col1, row2, col2; HObject obj = visionControl1.DrawShape(); if (obj == null) { return; } HObject oldRegion = null; string str = dataGridViewProcessItem.Rows[indexSelVisionSel].Cells[1].Value.ToString(); VisionSetpBase visionSetpBase = VisionMgr.GetInstance().GetItem(str); string strPath = VisionMgr.GetInstance().CurrentVisionProcessDir + "\\" + str + "\\" + str + "_Roi" + ".hobj"; switch (dataGridViewProcessItem.Rows[indexSelVisionSel].Cells[2].Value.ToString()) { case "模板匹配": ((VisionShapMatch)visionSetpBase).visionShapParam.RoiRegionPath = strPath; visionSetpBase.Read(); try { if (File.Exists(strPath)) { HOperatorSet.ReadRegion(out oldRegion, strPath); if (oldRegion != null && oldRegion.IsInitialized()) { HOperatorSet.Difference(oldRegion, obj, out obj); } } HOperatorSet.WriteRegion(obj, strPath); ((VisionShapMatch)visionSetpBase).SetRoiRegion(obj); HOperatorSet.DispObj(obj, visionControl1.GetHalconWindow()); visionSetpBase.Save(); } catch (HalconException e1) { MessageBox.Show(visionSetpBase.m_strStepName + "画ROi失败" + e1.Message, "Err", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } finally { oldRegion?.Dispose(); obj?.Dispose(); } break; case "二维码": break; case "一维码": break; } obj.Dispose(); }