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(); }
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()); } }
/// <summary> /// 根据名字创建对象 /// </summary> /// <param name="strVisionType"></param> /// <param name="strItem"></param> /// <returns></returns> VisionSetpBase CreatVisonObjByType(string strVisionType, string strItem) { VisionSetpBase visionSetpBase = null; switch (strVisionType) { case "模板匹配": visionSetpBase = new VisionShapMatch(strItem); break; case "二维码": visionSetpBase = new Vision2dCode(strItem); break; case "一维码": visionSetpBase = new Vision1dCode(strItem); break; case "找圆": visionSetpBase = new VisionFitCircircle(strItem); break; default: MessageBox.Show("视觉处理基类未完善", "Err", MessageBoxButtons.OK, MessageBoxIcon.Error); break; } return(visionSetpBase); }
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); }
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_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(); }
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 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(); }