예제 #1
0
 public override void Disopose()
 {
     if (RegionSearch != null && RegionSearch.IsInitialized())
     {
         RegionSearch.Dispose();
     }
     if (RegionRoi != null && RegionRoi.IsInitialized())
     {
         RegionRoi.Dispose();
     }
     if (ModeID != null)
     {
         HOperatorSet.ClearShapeModel(ModeID);
     }
 }
예제 #2
0
        public override Object Read(string strPath)
        {
            string strSaveRegions = strPath;

            try
            {
                strPath = strPath + "\\" + m_strStepName + ".xml";
                //string strPath = VisionMgr.GetInstance().CurrentVisionProcessDir + "\\" + m_strStepName + "\\" + m_strStepName + ".xml";
                VisionShapParam tempvisionShapParam = (VisionShapParam)AccessXmlSerializer.XmlToObject(strPath, visionShapParam.GetType());
                if (tempvisionShapParam == null)
                {
                    MessageBox.Show(m_strStepName + ": 视觉处理项目加载失败,请检查", "Err", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    _logger.Warn(m_strStepName + ": 视觉处理项目加载失败,请检查");
                    return(null);
                }
                visionShapParam = tempvisionShapParam;

                if (visionShapParam != null && File.Exists(visionShapParam.ModeShmPath))
                {
                    if (ModeID != null)
                    {
                        HOperatorSet.ClearShapeModel(ModeID);
                    }
                    ModeID = null;
                    HOperatorSet.ReadShapeModel(visionShapParam.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);
                }

                if (visionShapParam != null && File.Exists(visionShapParam.SeachRectRegionPath))
                {
                    if (RegionSearch != null && RegionSearch.IsInitialized())
                    {
                        RegionSearch.Dispose();
                    }
                    HOperatorSet.ReadRegion(out RegionSearch, visionShapParam.SeachRectRegionPath);
                    if (RegionSearch == null || RegionSearch.IsInitialized())
                    {
                        _logger.Warn(m_strStepName + "读取项目:" + "搜索区域读取失败");
                    }
                    //     MessageBox.Show(m_strStepName + "读取项目:" + "搜索区域读取失败", "Err", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    _logger.Warn(m_strStepName + "读取项目:" + "搜索区域读取失败");
                    // MessageBox.Show(m_strStepName + "读取项目:" + "搜索区域读取失败", "Err", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                if (visionShapParam != null && File.Exists(visionShapParam.RoiRegionPath))
                {
                    if (RegionRoi != null && RegionRoi.IsInitialized())
                    {
                        RegionRoi.Dispose();
                    }
                    HOperatorSet.ReadRegion(out RegionRoi, visionShapParam.RoiRegionPath);
                    if (RegionRoi == null || RegionRoi.IsInitialized())
                    {
                        _logger.Warn(m_strStepName + "读取项目:" + "roi读取失败");
                    }
                    //     MessageBox.Show(m_strStepName + "读取项目:" + "roi读取失败", "Err", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    _logger.Warn(m_strStepName + "读取项目:" + "roi读取失败");
                    // MessageBox.Show(m_strStepName + "读取项目:" + "roi读取失败", "Err", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            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();
            //  ReadRegions(strSaveRegions);
            return(visionShapParam);
        }
예제 #3
0
        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);
        }