public void Read() { string strVisionConfigPath = VisionMgr.GetInstance().CurrentVisionProcessDir + "VisionMgr" + ".xml"; if (VisionMgr.GetInstance().CurrentVisionProcessDir == null && ParamSetMgr.GetInstance().CurrentProductFile == null && ParamSetMgr.GetInstance().CurrentProductFile == "" && !Directory.Exists(VisionMgr.GetInstance().CurrentVisionProcessDir)) { Directory.CreateDirectory(VisionMgr.GetInstance().CurrentVisionProcessDir); } dicVisionType.Clear(); dicVisionType = (SerialDictionary <string, StepVisionInfo>)AccessXmlSerializer.XmlToObject(strVisionConfigPath, dicVisionType.GetType()); dicVision.Clear(); if (dicVisionType == null) { dicVisionType = new SerialDictionary <string, StepVisionInfo>(); } foreach (var temp in dicVisionType) { Type type = AssemblyOperate.GetTypeFromAssembly(temp.Value.VisionType); object[] args = new object[] { temp.Key }; Add(temp.Key, Activator.CreateInstance(type, args) as VisionSetpBase); dicVision[temp.Key].Read(); dicVision[temp.Key].m_camparam = temp.Value.CamParam; } }
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 ItemAdd_Load(object sender, EventArgs e) { comboBox_SelVisionProcessType.Items.Clear(); List <Type> TypeList = AssemblyOperate.GetAllSubClassTypeOnRunDir(typeof(VisionSetpBase)); foreach (var temp in TypeList) { string DescriptionName = AssemblyOperate.GetDescription(temp); if (DescriptionName != "NoDescription") { comboBox_SelVisionProcessType.Items.Add(DescriptionName); comboBox_SelVisionProcessType.SelectedIndex = 0; } } }
private void Form_CameraDebug_Load(object sender, EventArgs e) { visionControl1.InitWindow(); HOperatorSet.SetDraw(visionControl1.GetHalconWindow(), "margin"); Thread.Sleep(10); List <string> camname = CameraMgr.GetInstance().GetCameraNameArr(); foreach (var temp in camname) { this.Sel.Items.Add(temp.ToString()); comboBox_SelCam.Items.Add(temp.ToString()); CameraMgr.GetInstance().ClaerPr(temp.ToString()); } if (camname.Count > 0) { comboBox_SelCam.SelectedIndex = 0; } DataGridViewComboBoxColumn sd = (DataGridViewComboBoxColumn)dataGridViewProcessItem.Columns[2]; sd.Items.Clear(); TypeLists = AssemblyOperate.GetAllSubClassTypeOnRunDir(typeof(VisionSetpBase)); foreach (var temp in TypeLists) { string DescriptionName = AssemblyOperate.GetDescription(temp); if (DescriptionName != "NoDescription") { sd.Items.Add(DescriptionName); } } dataGridViewProcessItem.Columns[1].ReadOnly = true; dataGridViewProcessItem.Columns[2].ReadOnly = true; dataGridViewProcessItem.Columns[3].ReadOnly = true; textBox_exposureTimeVal.Text = CameraMgr.GetInstance().GetCamExposure(comboBox_SelCam.Text).ToString(); textBox_GainVal.Text = CameraMgr.GetInstance().GetCamGain(comboBox_SelCam.Text).ToString(); CameraMgr.GetInstance().BindWindow(comboBox_SelCam.Text, visionControl1); CameraMgr.GetInstance().SetAcquisitionMode(comboBox_SelCam.Text); UpdataVisionItems(); ParamSetMgr.GetInstance().m_eventLoadProductFileUpadata += UpdataVisionItems; }
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; } }
public override Object Read() { try { VisionShapParam tempvisionShapParam = null; string strPath = VisionMgr.GetInstance().CurrentVisionProcessDir + "\\" + m_strStepName + "\\" + m_strStepName + ".xml"; if (strSavePath != "") { strPath = strSavePath + "\\" + m_strStepName + ".xml"; } strPath = VisionMgr.GetInstance().CurrentVisionProcessDir + "\\" + m_strStepName + "\\" + m_strStepName + ".json"; if (strSavePath != "") { strPath = strSavePath + "\\" + m_strStepName + ".json"; } object visionShapMatch2 = AccessJosnSerializer.JsonToObject(strPath, typeof(object)); //string json = visionShapMatch2.ToString(); //var q = JsonConvert.DeserializeObject<dynamic>(json); //Newtonsoft.Json.Linq.JObject jobj = Newtonsoft.Json.Linq.JObject.Parse(json); //string jsonShapelist= jobj["shapeslist"].ToString(); //List<shapeparam> ss = JsonConvert.DeserializeObject<List<shapeparam>>(jsonShapelist); //var qq = JsonConvert.DeserializeObject<dynamic>(jsonShapelist); //Newtonsoft.Json.Linq.JObject jobjShape = Newtonsoft.Json.Linq.JObject.Parse(qq.ToString()); //string jsonShapelists = jobjShape["usrshape"].ToString(); VisionShapMatch visionShapMatch = (VisionShapMatch)AccessJosnSerializer.JsonToObject(strPath, this.GetType()); string str = visionShapMatch2.ToString(); int indexFindex = str.IndexOf("\"shapeslist\":"); string sub1 = str.Substring(indexFindex); int indexFirist = sub1.IndexOf("["); string sub2 = sub1.Substring(indexFirist); int indexLast = sub2.IndexOf("]"); int nLen = indexLast - indexFirist; if (indexLast != -1 && indexFirist != -1 && nLen > 0) { string sub = sub2.Substring(0, indexLast + 1); string strReg = "<Item>"; List <object> list = (List <object>)JsonConvert.DeserializeObject(sub, typeof(List <object>)); // List<shapeparam> list = (List<shapeparam>)AccessJosnSerializer.JsonToObject(strPath,typeof( shapeparam)); for (int i = 0; i < list.Count; i++) { if (list[i].ToString() != null) { int index = list[i].ToString().IndexOf("\"usrshape\": "); if (index != -1) { string Itemstring = list[i].ToString(); string subusrshape = list[i].ToString().Substring(index); int index2 = subusrshape.IndexOf("{"); int index3 = subusrshape.IndexOf("}"); if (index2 != -1 && index3 != -1) { int nLenOfUserShape = index3 - index2; string subusrshapeObj = subusrshape.Substring(index2 - 1, nLenOfUserShape + 2); Type TY = AssemblyOperate.GetTypeFromAssembly(visionShapMatch.shapeslist[i].usrshape.UserTypeName); UserShape tem = (UserShape)JsonConvert.DeserializeObject(subusrshapeObj, TY); visionShapMatch.shapeslist[i].usrshape = tem; } } } } } if (visionShapMatch == null || visionShapMatch.visionShapParam == null) { MessageBox.Show(m_strStepName + ": 视觉处理项目加载失败,请检查", "Err", MessageBoxButtons.OK, MessageBoxIcon.Error); _logger.Warn(m_strStepName + ": 视觉处理项目加载失败,请检查"); return(null); } visionShapParam = tempvisionShapParam = visionShapMatch.visionShapParam; this.shapeslist.Clear(); int nIndex = 0; for (int s = 0; s < visionShapMatch.shapeslist.Count; s++) { shapeslist.Add(new shapeparam() { name = visionShapMatch.shapeslist[s].name, shapeType = visionShapMatch.shapeslist[s].shapeType, usrshape = visionShapMatch.shapeslist[s].usrshape.Clone(), }); } string ModeShmPath = VisionMgr.GetInstance().CurrentVisionProcessDir + "\\" + m_strStepName + "\\" + m_strStepName + "_Mode.shm"; if (visionShapParam != null && visionShapParam.ModeType == eModleType.形状 && File.Exists(ModeShmPath)) { if (ModeID != null) { HOperatorSet.ClearShapeModel(ModeID); } ModeID = null; HOperatorSet.ReadShapeModel(ModeShmPath, out ModeID); if (ModeID == null || ModeID.Length <= 0) { MessageBox.Show(m_strStepName + "读取项目:" + "模板读取失败", "Err", MessageBoxButtons.OK, MessageBoxIcon.Error); _logger.Warn(m_strStepName + "读取项目:" + "模板读取失败"); } } else { _logger.Warn(m_strStepName + "读取项目:" + "模板读取失败"); MessageBox.Show(m_strStepName + "读取项目:" + "模板读取失败", "Err", MessageBoxButtons.OK, MessageBoxIcon.Error); } string SeachRectRegionPath = VisionMgr.GetInstance().CurrentVisionProcessDir + "\\" + m_strStepName + "\\" + m_strStepName + "_SearchRect.hobj"; if (visionShapParam != null && File.Exists(SeachRectRegionPath)) { if (RegionSearch != null && RegionSearch.IsInitialized()) { RegionSearch.Dispose(); } HOperatorSet.ReadRegion(out RegionSearch, SeachRectRegionPath); if (RegionSearch == null || RegionSearch.IsInitialized()) { _logger.Warn(m_strStepName + "读取项目:" + "搜索区域读取失败"); } } else { _logger.Warn(m_strStepName + "读取项目:" + "搜索区域读取失败"); } string RoiRegionPath = VisionMgr.GetInstance().CurrentVisionProcessDir + "\\" + m_strStepName + "\\" + m_strStepName + "_Roi.hobj"; if (visionShapParam != null && File.Exists(RoiRegionPath)) { if (RegionRoi != null && RegionRoi.IsInitialized()) { RegionRoi.Dispose(); } HOperatorSet.ReadRegion(out RegionRoi, RoiRegionPath); if (RegionRoi == null || RegionRoi.IsInitialized()) { _logger.Warn(m_strStepName + "读取项目:" + "roi读取失败"); } } else { _logger.Warn(m_strStepName + "读取项目:" + "roi读取失败"); } } catch (Exception e1) { _logger.Warn(m_strStepName + "读取项目:" + e1.Message); MessageBox.Show(m_strStepName + "读取项目:" + e1.Message, "Err", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch { _logger.Warn(m_strStepName + "读取项目失败"); MessageBox.Show(m_strStepName + "读取项目失败", "Err", MessageBoxButtons.OK, MessageBoxIcon.Error); } GC.Collect(); return(visionShapParam); }