Exemplo n.º 1
0
        //保存
        public void SaveXML()
        {
            try
            {
                XElement root = new XElement("Recipe");
                XMLHelper.AddIdentifier(root, IdentifyString);
                XMLHelper.AddParameters(root, iniParameters, IdentifyString);
                XMLHelper.AddRegion(root, DieUserRegions, "Die_Regions");
                root.Save(XmlPath);

                if (iniObjects.Image == null || !iniObjects.Image.IsInitialized())
                {
                    MessageBox.Show("请加载参考图像!");
                    return;
                }

                /*
                 * if (!Directory.Exists(iniParameters.TrainningImagesDirectory) )
                 * {
                 *  MessageBox.Show("提示:训练图集没有加载!");
                 * }
                 */
                if (iniParameters.UserRegionForCutOutIndex < 1)
                {
                    MessageBox.Show("请选择参考Die!");
                    return;
                }

                HOperatorSet.WriteImage(iniObjects.Image, "tiff", 0, IniDirectory + "ReferenceImage.tiff");
                HOperatorSet.WriteTuple(iniParameters.ImagePath, IniDirectory + "ImagePath.tup");
                HOperatorSet.WriteTuple(iniParameters.TrainningImagesDirectory, IniDirectory + "TrainningImagesDirectory.tup");
                HOperatorSet.WriteTuple((int)(iniParameters.UserRegionForCutOutIndex), IniDirectory + "UserRegionForCutOutIndex.tup");
                HOperatorSet.WriteTuple(iniParameters.DieImageRowOffset, IniDirectory + "DieImageRowOffset.tup");
                HOperatorSet.WriteTuple(iniParameters.DieImageColumnOffset, IniDirectory + "DieImageColumnOffset.tup");
                SaveHelper.WriteRegion(DieUserRegions, IniDirectory, "CoarseReference");
                HOperatorSet.WriteRegion((createReference as CreateReference).SelectedUserRegion?.CalculateRegion, IniDirectory + "DieReference.reg");

                //1121-lht
                //HOperatorSet.ReadTuple(IniDirectory + "ImageChannelnumber.tup", out HTuple ImageChannelnumber);
                HOperatorSet.WriteTuple(iniParameters.ImageCountChannels, IniDirectory + "ImageChannelnumber.tup");

                /* 功能拓展
                 * if (iniParameters.ImageCountChannels == 3)
                 * {
                 *  HOperatorSet.WriteImage(iniObjects.ImageR, "tiff", 0, ChannelImageDirectory + "ImageR.tiff");
                 *  HOperatorSet.WriteImage(iniObjects.ImageG, "tiff", 0, ChannelImageDirectory + "ImageG.tiff");
                 *  HOperatorSet.WriteImage(iniObjects.ImageB, "tiff", 0, ChannelImageDirectory + "ImageB.tiff");
                 * }
                 */
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "缺少全局数据!");
            }
        }
Exemplo n.º 2
0
        //保存
        public void SaveXML()
        {
            try
            {
                Directory.GetFiles(ModelsDirectory).ToList().ForEach(File.Delete);
                XElement root = new XElement("Recipe");
                XMLHelper.AddIdentifier(root, IdentifyString);
                XElement cutRegionParameterNode = new XElement("CutRegionParameter");

                // 保存初始cutReg, 即膨胀前参数 0125 lw
                XElement CutRegNode = new XElement("CutRegions");
                XMLHelper.AddRegion(CutRegNode, OriRegionUserRegions, "CutReg", false, false, false, false);

                //Models下保存FreeRegion  add by 2020-12-24
                foreach (var item in OriRegionUserRegions)
                {
                    if (item.RegionType == RegionType.Region)
                    {
                        //HOperatorSet.ReadRegion(out HObject freeRegion, $"{ ProductDirctory}\\{ item.RegionPath}");
                        HOperatorSet.WriteRegion(item.CalculateRegion, $"{ProductDirctory}\\{item.RegionPath}");
                    }
                }

                //HOperatorSet.MoveRegion(Algorithm.Region.ConcatRegion(CutRegionUserRegions), out HObject CutRegion, CutRegionParameter.DieImageRowOffset, CutRegionParameter.DieImageColumnOffset);//

                //HTuple file = new HTuple();
                //file = $"{ModelsFile}\\{ CutRegionParameter.OnRecipesIndexs[CutRegionParameter.OnRecipesIndex]}\\";
                //HOperatorSet.WriteRegion(CutRegion, file + "CutRegions.reg");


                cutRegionParameters  = new HTuple();
                CutRegionRecipeNames = new HTuple();
                foreach (var item in CutRegionUserRegions)
                {
                    HOperatorSet.TupleConcat(cutRegionParameters, item.RegionParameters[0], out cutRegionParameters);
                    HOperatorSet.TupleConcat(CutRegionRecipeNames, item.RecipeNames, out CutRegionRecipeNames);
                }
                HOperatorSet.WriteTuple(cutRegionParameters, $"{ModelsDirectory}CutRegionParameters.tup");
                HOperatorSet.WriteTuple(CutRegionRecipeNames, $"{ModelsDirectory}CutRegionRecipeNames.tup");
                CutRegionParameter.CutRegionParameters = cutRegionParameters;
                XMLHelper.AddParameters(cutRegionParameterNode, CutRegionParameter, IdentifyString);

                root.Add(cutRegionParameterNode);
                root.Add(CutRegNode);
                root.Save(XmlPath);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Exemplo n.º 3
0
        //加载
        //--------保存XML
        public void SaveXML()
        {
            try
            {
                Directory.GetFiles(ModelsDirectory).ToList().ForEach(File.Delete);
                //Directory.GetFiles(RecipeDirectory).ToList().ForEach(File.Delete);
                XElement root = new XElement("Recipe");
                XMLHelper.AddIdentifier(root, IdentifyString);

                XElement AroundBondRegInspectParameterNode = new XElement("AroundBondRegInspectParameter");

                XMLHelper.AddParameters(AroundBondRegInspectParameterNode, AroundBondRegInspectParameter, IdentifyString);

                XElement AroundBondRegNode = new XElement("AroundBondRegions");

                XMLHelper.AddRegion(AroundBondRegNode, AroundBondRegUserRegions, "AroundBondReg", false, false, false, true);

                //if (AroundBondDetectionObject.RejectRegion != null)
                //{
                //    //当拒绝区是不规则区域时,拒绝区域保存在Models下
                //    HOperatorSet.WriteRegion(goldenModelObject.RejectRegion, $"{ModelsRecipeDirectory}" + "Reject_FreeRegion.reg");
                //}

                foreach (var item in AroundBondRegUserRegions)
                {
                    if (item.RegionType == RegionType.Region)
                    {
                        //HOperatorSet.ReadRegion(out HObject freeRegion, $"{ ProductDirctory}\\{ item.RegionPath}");
                        HOperatorSet.WriteRegion(item.CalculateRegion, $"{ProductDirctory}\\{item.RegionPath}");
                    }
                }


                root.Add(AroundBondRegInspectParameterNode);
                root.Add(AroundBondRegNode);
                root.Save(XmlPath);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Exemplo n.º 4
0
        //保存
        public void SaveXML()
        {
            Directory.GetFiles(ModelsDirectory).ToList().ForEach(File.Delete);
            XElement root = new XElement("Recipe");

            XMLHelper.AddIdentifier(root, IdentifyString);
            XElement epoxyParameterNode            = new XElement("EpoxyParameter");
            XElement epoxyModelVerifyParameterNode = new XElement("EpoxyModelVerifyParameter");

            XMLHelper.AddParameters(epoxyParameterNode, epoxyParameter, IdentifyString);
            XMLHelper.AddParameters(epoxyModelVerifyParameterNode, epoxyModelVerifyParameter, IdentifyString);
            XMLHelper.AddRegion(root, epoxyUserRegions, "EpoxyUserRegions", true);
            XMLHelper.AddRegion(root, epoxyReferceUserRegions, "EpoxyReferceUserRegions", false);
            root.Add(epoxyParameterNode);
            root.Add(epoxyModelVerifyParameterNode);
            root.Save(XmlPath);
            HOperatorSet.WriteRegion(Algorithm.Region.ConcatRegion(epoxyUserRegions), $"{ModelsDirectory}Inspect_Regions.reg");
            HOperatorSet.WriteRegion((epoxyReferceUserRegions.Where(r => r.IsEnable).Select(r => r.CalculateRegion)).FirstOrDefault(), $"{ModelsDirectory}Reference_Region.reg");

            if (epoxyParameter.ImageCountChannels == 1)
            {
                HOperatorSet.WriteTuple(new HTuple(1), ModelsDirectory + "Image_Index.tup");
            }
            else if (epoxyParameter.ImageCountChannels > 1)
            {
                HOperatorSet.WriteTuple(epoxyModelVerifyParameter.ImageChannelIndex + 1, ModelsDirectory + "Image_Index.tup");
            }

            try
            {
                if (epoxyParameter.OnRecipesIndex >= 0)
                {
                    HOperatorSet.WriteTuple(epoxyParameter.OnRecipesIndexs[epoxyParameter.OnRecipesIndex], $"{ModelsDirectory}OnWhat.tup");
                }
            }
            catch (Exception)//改
            {
                MessageBox.Show("请选择\"银胶属于\"位置!");
            }
        }
Exemplo n.º 5
0
        public override void SaveXML()
        {
            try
            {
                Directory.GetFiles(ModelsRecipeDirectory).ToList().ForEach(File.Delete);
                UserRegion userRegion = (cutOutDie as CutOutDie).UserRegionForCutOut;
                if (userRegion != null)
                {
                    goldenModelParameter.UserRegionForCutOutIndex = userRegion.Index;
                }

                XElement root = new XElement("Recipe");
                XMLHelper.AddIdentifier(root, IdentifyString);
                XElement goldenModelParameterNode        = new XElement("GoldenModelParameter");
                XElement goldenModelInspectParameterNode = new XElement("GoldenModelInspectParameter");

                XMLHelper.AddRegion(root, dieUserRegions, "Die_Regions");
                XMLHelper.AddRegion(root, matchUserRegions, "Match_Region");
                XMLHelper.AddRegion(root, inspectUserRegions, "Inspect_Region");
                XMLHelper.AddRegion(root, subUserRegions, "Sub_Regions");
                XMLHelper.AddRegion(root, rejectUserRegions, "Reject_Region");
                if (goldenModelObject.RejectRegion != null)
                {
                    //当拒绝区是不规则区域时,拒绝区域保存在Models下
                    HOperatorSet.WriteRegion(goldenModelObject.RejectRegion, $"{ModelsRecipeDirectory}" + "Reject_FreeRegion.reg");
                }

                XMLHelper.AddParameters(goldenModelParameterNode, goldenModelParameter, IdentifyString);
                XMLHelper.AddParameters(goldenModelInspectParameterNode, goldenModelInspectParameter, IdentifyString);

                root.Add(goldenModelParameterNode);
                root.Add(goldenModelInspectParameterNode);
                root.Save(XmlPath);

                if (goldenModelParameter.OnRecipesIndexs.Length > 0)
                {
                    HOperatorSet.WriteTuple(goldenModelParameter.OnRecipesIndexs?[goldenModelParameter.OnRecipesIndex], ModelsRecipeDirectory + "OnWhat.tup");
                }
                HOperatorSet.WriteTuple(goldenModelInspectParameter.AngleStart, ModelsRecipeDirectory + "AngleStart.tup");
                HOperatorSet.WriteTuple(goldenModelInspectParameter.AngleExt, ModelsRecipeDirectory + "AngleExt.tup");
                HOperatorSet.WriteTuple(goldenModelInspectParameter.MinMatchScore, ModelsRecipeDirectory + "MinMatchScore.tup");
                HOperatorSet.WriteTuple(goldenModelInspectParameter.MatchNum, ModelsRecipeDirectory + "MatchNum.tup");
                HOperatorSet.WriteTuple(goldenModelInspectParameter.DilationSize, ModelsRecipeDirectory + "DilationSize.tup");
                HOperatorSet.WriteRegion(Algorithm.Region.Union1Region(matchUserRegions), ModelsRecipeDirectory + "Match_Region.reg");
                HOperatorSet.WriteRegion(Algorithm.Region.Union1Region(inspectUserRegions), ModelsRecipeDirectory + "Inspect_Region.reg");
                HOperatorSet.WriteRegion(Algorithm.Region.Union1Region(rejectUserRegions), ModelsRecipeDirectory + "Reject_Region.reg");
                HOperatorSet.WriteRegion(Algorithm.Region.Union1Region(subUserRegions), ModelsRecipeDirectory + "Sub_Region.reg");

                if (goldenModelParameter.ImageCountChannels == 1)
                {
                    HOperatorSet.WriteTuple((new HTuple(1)).TupleConcat(new HTuple(1)).TupleConcat(new HTuple(1)), ModelsRecipeDirectory + "Image_Index.tup");
                }
                else if (goldenModelParameter.ImageCountChannels > 1)
                {
                    // 1122-lw
                    HOperatorSet.WriteTuple((new HTuple(goldenModelParameter.ImageChannelIndex + 1))
                                            .TupleConcat(new HTuple(goldenModelParameter.ImageGoldChannelIndex + 1))
                                            .TupleConcat(new HTuple(goldenModelInspectParameter.ImageChannelIndex_IcExist + 1)),
                                            ModelsRecipeDirectory + "Image_Index.tup");
                }

                HOperatorSet.WriteTuple(new HTuple(goldenModelInspectParameter.IsICExist == false ? 0 : 1)
                                        .TupleConcat(new HTuple(goldenModelInspectParameter.IsICLocate == false ? 0 : 1))
                                        .TupleConcat(new HTuple(goldenModelInspectParameter.IsICOffSet == false ? 0 : 1))
                                        .TupleConcat(new HTuple(goldenModelInspectParameter.IsICSurfaceInspect == false ? 0 : 1)),
                                        ModelsRecipeDirectory + "TaskEnable.tup");

                if (goldenModelParameter.ModelType == 0)
                {
                    HOperatorSet.WriteTuple(new HTuple("ncc"), $"{ModelsRecipeDirectory}Model_Type.tup");
                }
                else if (goldenModelParameter.ModelType == 1)
                {
                    HOperatorSet.WriteTuple(new HTuple("shape"), $"{ModelsRecipeDirectory}Model_Type.tup");
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            try
            {
                if (File.Exists($"{RecipeDirectory}PosModel.dat") || goldenModelObject.PosModelID != null)
                {
                    if (goldenModelParameter.ModelIdPath.Split(',').Length == 1)
                    {
                        if (File.Exists($"{RecipeDirectory}PosModel.dat") || goldenModelObject.PosModelID != null)
                        {
                            if (goldenModelObject.PosModelID != null)
                            {
                                Algorithm.File.SaveModel(ModelsRecipeDirectory + "PosModel.dat", goldenModelParameter.ModelType, goldenModelObject.PosModelID);
                            }
                            else if (File.Exists($"{RecipeDirectory}PosModel.dat"))
                            {
                                HTuple PosModelId = Algorithm.File.ReadModel($"{RecipeDirectory}PosModel.dat", goldenModelParameter.ModelType);
                                Algorithm.File.SaveModel(ModelsRecipeDirectory + "PosModel.dat", goldenModelParameter.ModelType, PosModelId);
                                // 清除模板 lw 0121
                                Algorithm.Model_RegionAlg.HTV_clear_model_recipe(PosModelId, goldenModelParameter.ModelType);
                            }
                        }
                        else
                        {
                            MessageBox.Show("请创建定位模板!");
                        }
                    }
                    else
                    {
                        if (goldenModelObject.PosModelID != null)
                        {
                            String[] ModelIdPathArry = new string[goldenModelObject.PosModelID.TupleLength()];
                            for (int i = 0; i < goldenModelObject.PosModelID.TupleLength(); i++)
                            {
                                ModelIdPathArry[i] = $"{ModelsRecipeDirectory}PosModel_" + i + ".dat";
                            }
                            goldenModelParameter.ModelIdPath = String.Join(",", ModelIdPathArry);
                            Algorithm.File.SaveModel(ModelIdPathArry, goldenModelParameter.ModelType, goldenModelObject.PosModelID);
                        }
                        else if (File.Exists($"{RecipeDirectory}PosModel.dat"))
                        {
                            HTuple   ModelId         = Algorithm.File.ReadModel($"{RecipeDirectory}PosModel.dat".Split(','), goldenModelParameter.ModelType);
                            String[] ModelIdPathArry = new string[ModelId.TupleLength()];
                            for (int i = 0; i < ModelId.TupleLength(); i++)
                            {
                                ModelIdPathArry[i] = $"{ModelsRecipeDirectory}PosModel_" + i + ".dat";
                            }
                            Algorithm.File.SaveModel(ModelIdPathArry, goldenModelParameter.ModelType, ModelId);
                            // 清除模板 lw 0121
                            Algorithm.Model_RegionAlg.HTV_clear_model_recipe(ModelId, goldenModelParameter.ModelType);
                        }
                    }
                }

                if (goldenModelObject.MeadImage != null && goldenModelObject.StdImage != null)
                {
                    HOperatorSet.WriteImage(goldenModelObject.MeadImage, "tiff", 0, ModelsRecipeDirectory + "Mean_Image.tiff");
                    //HOperatorSet.WriteImage(goldenModelObject.StdImage, "tiff", 0, ModelsRecipeDirectory + "Std_Image.tiff");
                }
                else if (File.Exists($"{RecipeDirectory}Mean_Image.tiff") /*&& File.Exists($"{RecipeDirectory}Std_Image.tiff")*/)
                {
                    HOperatorSet.ReadImage(out HObject Mean_Image, $"{RecipeDirectory}Mean_Image.tiff");
                    //HOperatorSet.ReadImage(out HObject Std_Image, $"{RecipeDirectory}Std_Image.tiff"); // 1206
                    HOperatorSet.WriteImage(Mean_Image, "tiff", 0, ModelsRecipeDirectory + "Mean_Image.tiff");
                    //HOperatorSet.WriteImage(Std_Image, "tiff", 0, ModelsRecipeDirectory + "Std_Image.tiff");
                }
                else
                {
                    MessageBox.Show("请生成均值方差图!");
                }


                if (goldenModelObject.LightImage != null && goldenModelObject.DarkImage != null)
                {
                    HOperatorSet.WriteImage(goldenModelObject.LightImage, "tiff", 0, ModelsRecipeDirectory + "Light_Image.tiff");
                    HOperatorSet.WriteImage(goldenModelObject.DarkImage, "tiff", 0, ModelsRecipeDirectory + "Dark_Image.tiff");
                }
                else if (File.Exists($"{RecipeDirectory}Light_Image.tiff") && File.Exists($"{RecipeDirectory}Dark_Image.tiff"))
                {
                    HOperatorSet.ReadImage(out HObject Light_Image, $"{RecipeDirectory}Light_Image.tiff");
                    HOperatorSet.ReadImage(out HObject Dark_Image, $"{RecipeDirectory}Dark_Image.tiff");
                    HOperatorSet.WriteImage(Light_Image, "tiff", 0, ModelsRecipeDirectory + "Light_Image.tiff");
                    HOperatorSet.WriteImage(Dark_Image, "tiff", 0, ModelsRecipeDirectory + "Dark_Image.tiff");
                }
                else
                {
                    MessageBox.Show("请生成亮图像、暗图像!");
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Exemplo n.º 6
0
        //保存
        public void SaveXML()
        {
            try
            {
                Directory.GetFiles(ModelsBondDirectory).ToList().ForEach(File.Delete);
                XElement root = new XElement("Recipe");
                XMLHelper.AddIdentifier(root, IdentifyString);
                XElement bond2ModelNode        = new XElement("Bond2Models");
                HTuple   Bond2_ModelImgIdxTemp = new HTuple();

                foreach (var model in bond2Models)
                {
                    XElement modelNode = new XElement("Model");
                    modelNode.Add(new XAttribute("Index", model.Index.ToString()));
                    //modelNode.Add(new XAttribute("ModelType", model.ModelType.ToString()));
                    modelNode.Add(new XAttribute("ModelIDPath", model.ModelIdPath));
                    modelNode.Add(new XElement("RotatedImagePath", model.RotatedImagePath));
                    modelNode.Add(new XElement("RotatedImageAngel", model.RotatedImageAngel));
                    modelNode.Add(new XAttribute("ImageIndex", model.ImageIndex.ToString()));

                    modelNode.Add(model.Bond2UserRegion?.ToXElement("Bond2ModelRegion"));
                    modelNode.Add(model.Bond2UserRegionDiff?.ToXElement("Bond2ModelRegionDiff"));
                    modelNode.Add(model.RotateLineUserRegion?.ToXElement("RotateLineRegion"));
                    XMLHelper.AddRegion(modelNode, model.RefineUserRegions, "RefineRegions");

                    bond2ModelNode.Add(modelNode);

                    if (bond2ModelParameter.ModelType == 0)
                    {
                        HOperatorSet.WriteTuple(new HTuple("ncc"), $"{ModelsBondDirectory}Model_Type.tup");
                    }
                    else if (bond2ModelParameter.ModelType == 1)
                    {
                        HOperatorSet.WriteTuple(new HTuple("shape"), $"{ModelsBondDirectory}Model_Type.tup");
                    }
                    model.RotatedImagePath = $"{BondDirectory}\\RotatedImage{model.Index.ToString()}.tiff";
                    HOperatorSet.ReadImage(out HObject rotatedImage, model.RotatedImagePath);
                    HOperatorSet.WriteImage(rotatedImage, "tiff", 0, $"{ModelsBondDirectory}RotatedImage{model.Index.ToString()}.tiff");
                }
                XElement bond2ModelParameterNode      = new XElement("Bond2ModelParameter");
                XElement bondAutoRegionsParameterNode = new XElement("BondAutoRegionsParameter");//自动生成
                XElement bondWireParameterNode        = new XElement("BondWireParameter");
                XElement BondVerifyModelParaNode      = new XElement("BondVerifyModelPara");

                XMLHelper.AddParameters(bond2ModelParameterNode, bond2ModelParameter, IdentifyString);
                XMLHelper.AddParameters(bondWireParameterNode, bondWireParameter, IdentifyString);
                XMLHelper.AddParameters(BondVerifyModelParaNode, BondVerifyModelPara, IdentifyString);
                XMLHelper.AddParameters(bondAutoRegionsParameterNode, bondAutoRegionsParameter, IdentifyString);//自动生成

                root.Add(bond2ModelNode);
                root.Add(bond2ModelParameterNode);
                root.Add(bondWireParameterNode);
                root.Add(BondVerifyModelParaNode);      //保存批量设置的模板检测参数
                root.Add(bondAutoRegionsParameterNode); //自动生成

                //XML保存检测区域带参数 add by wj
                XMLHelper.AddRegion(root, BondVerifyUserRegions, "BondVerifyUserRegions", false, false, false, false, true);//xml中加载生成的焊盘区域 2021-01-11

                try
                {
                    if (bond2ModelParameter.ModelIdPath.Split(',').Length >= 1 || bond2ModelObject.ModelID != null)
                    {
                        HTuple ModelId = new HTuple();

                        if (File.Exists($"{BondDirectory}PosModel.dat"))
                        {
                            if (bond2ModelObject.ModelID != null)
                            {
                                ModelId = bond2ModelObject.ModelID;
                            }
                            else if (File.Exists($"{BondDirectory}PosModel.dat"))
                            {
                                ModelId = Algorithm.File.ReadModel($"{BondDirectory}PosModel.dat", bond2ModelParameter.ModelType);
                            }
                            Algorithm.File.SaveModel($"{ModelsBondDirectory}PosModel.dat", bond2ModelParameter.ModelType, ModelId);
                        }
                    }
                    else
                    {
                        MessageBox.Show("请先创建焊点模板");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("焊点不存在或保存失败");
                }

                XElement GroupNode          = new XElement("GenGroups");
                XElement bondWireGroupNode  = new XElement("BondWireGroups");
                HTuple   Bond2_BallNumsTemp = new HTuple();
                HTuple   LineStartAngle     = new HTuple();
                HOperatorSet.GenEmptyObj(out HObject Bond2_Regions);

                foreach (var group in Groups)
                {
                    XElement _groupNode = new XElement("GenGroup");
                    _groupNode.Add(new XAttribute("Index", group.Index.ToString()));
                    _groupNode.Add(new XAttribute("Bond2Numbers", group.Bond2_BallNums.ToString()));
                    _groupNode.Add(group.Bond2UserRegion?.ToXElement("Bond2Region"));
                    _groupNode.Add(group.WireUserRegion?.ToXElement("WireRegion"));
                    GroupNode.Add(_groupNode);
                }
                root.Add(GroupNode);

                foreach (var group in bondWireRegionGroups)
                {
                    XElement groupNode = new XElement("BondWireGroup");
                    groupNode.Add(new XAttribute("Index", group.Index.ToString()));
                    groupNode.Add(new XAttribute("Bond2Numbers", group.Bond2_BallNums.ToString()));
                    groupNode.Add(group.Bond2UserRegion?.ToXElement("Bond2Region"));
                    groupNode.Add(group.WireUserRegion?.ToXElement("WireRegion"));
                    bondWireGroupNode.Add(groupNode);

                    HOperatorSet.ConcatObj(Bond2_Regions, Algorithm.Region.ConcatRegion(group.Bond2UserRegion), out Bond2_Regions);
                    //Bond2_BallNumsTemp = Bond2_BallNumsTemp.TupleConcat(group.Bond2_BallNums);
                    //HOperatorSet.AngleLx(group.WireUserRegion.RegionParameters[0], group.WireUserRegion.RegionParameters[1], group.WireUserRegion.RegionParameters[2], group.WireUserRegion.RegionParameters[3],
                    //                    out HTuple lineAngle);
                    //HOperatorSet.TupleConcat(LineStartAngle, lineAngle, out LineStartAngle);
                }

                HOperatorSet.WriteRegion(Bond2_Regions, $"{ModelsBondDirectory}Inspect_Regions.reg");

                root.Add(bondWireGroupNode);
                root.Save(XmlPath);
                //
                try
                {
                    if (bond2ModelParameter.OnRecipesIndexs.Length > 0)
                    {
                        HOperatorSet.WriteTuple(bond2ModelParameter.OnRecipesIndexs[bond2ModelParameter.OnRecipesIndex], $"{ModelsBondDirectory}OnWhat.tup");
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("请选择\"焊点在\"位置!");
                }

                //if (bond2ModelParameter.ImageCountChannels == 1)
                //{
                //    HOperatorSet.WriteTuple(new HTuple(1), ModelsBondDirectory + "Image_Index.tup");
                //}
                //else if (bond2ModelParameter.ImageCountChannels > 1)
                //{
                //    // 1122_lw
                //    HOperatorSet.WriteTuple(bondWireParameter.ImageChannelIndex + 1, ModelsBondDirectory + "Image_Index.tup");
                //}

                //HOperatorSet.WriteTuple(Bond2_BallNumsTemp, $"{ModelsBondDirectory}BallNum_OnRegion.tup");
                //HOperatorSet.WriteTuple(LineStartAngle, $"{ModelsBondDirectory}Match_StartAngle.tup");
                //HOperatorSet.WriteTuple(bondWireParameter.MinMatchScore, $"{ModelsBondDirectory}Match_MinScore.tup");// MinMatchScore
                //HOperatorSet.WriteTuple(bondWireParameter.AngleExt, $"{ModelsBondDirectory}Match_AngleExt.tup");//  AngleExt
                //if (bondWireParameter.IsCircleBond == true)
                //{
                //    HOperatorSet.WriteTuple(bondWireParameter.BondSize, $"{ModelsBondDirectory}BallRadius.tup");
                //}
                //else
                //{
                //    HOperatorSet.WriteTuple(new HTuple(bondWireParameter.EllipsBondSize[0]).TupleConcat(new HTuple(bondWireParameter.EllipsBondSize[1])), $"{ModelsBondDirectory}BallRadius.tup");
                //}
                //HOperatorSet.WriteTuple(bondWireParameter.IsBondRegRefine == false ? 0 : 1, $"{ModelsBondDirectory}IsBondRegRefine.tup");
                //HOperatorSet.WriteTuple(bondWireParameter.AddBallNum, $"{ModelsBondDirectory}AddBallNum.tup");
                //HOperatorSet.WriteTuple(bondWireParameter.MaxOverlap, $"{ModelsBondDirectory}MaxOverlap.tup");
                //HOperatorSet.WriteTuple(bondWireParameter.MinHistScore, $"{ModelsBondDirectory}MinHistScore.tup");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        //保存 后续添加
        public void SaveXML()
        {
            try
            {
                XElement root = new XElement("Recipe");
                XMLHelper.AddIdentifier(root, IdentifyString);
                XElement surfaceDetectionParameterNode   = new XElement("SurfaceDetectionParameter");
                XElement frameInspectParameterNode       = new XElement("FrameInspectParameter");
                XElement pegRackInspectParameterNode     = new XElement("PegRackInspectParameter");
                XElement bridgeModelInspectParameterNode = new XElement("BridgeInspectParameter");

                XMLHelper.AddIdentifier(root, IdentifyString);

                XMLHelper.AddParameters(surfaceDetectionParameterNode, SurfaceDetectionParameter, IdentifyString);
                XMLHelper.AddParameters(frameInspectParameterNode, FrameModelInspectParameter, IdentifyString);
                XMLHelper.AddParameters(pegRackInspectParameterNode, PegRackModelInspectParameter, IdentifyString);
                XMLHelper.AddParameters(bridgeModelInspectParameterNode, BridgeModelInspectParameter, IdentifyString);

                root.Add(surfaceDetectionParameterNode);
                root.Add(frameInspectParameterNode);
                root.Add(pegRackInspectParameterNode);
                root.Add(bridgeModelInspectParameterNode);

                root.Save(XmlPath);
                root.Save($"{RecipeFile}{SurfaceDetectionParameter.OnRecipesIndexs[SurfaceDetectionParameter.OnRecipesIndex]}\\{XmlName}");

                if (SurfaceDetectionParameter.OnRecipesIndex != -1)
                {
                    if (SurfaceDetectionParameter.ImageCountChannels == 1)
                    {
                        HOperatorSet.WriteTuple((new HTuple(1)).TupleConcat(new HTuple(1)).TupleConcat(new HTuple(1)),
                                                $"{ModelsFile}{SurfaceDetectionParameter.OnRecipesIndexs[SurfaceDetectionParameter.OnRecipesIndex]}\\Inspect_ImageIndex.tup");
                    }
                    else if (SurfaceDetectionParameter.ImageCountChannels > 1)
                    {
                        if (FrameModelInspectParameter.ImageFrameVerifyChannelIndex < 0 || PegRackModelInspectParameter.ImagePegRackVerifyChannelIndex < 0 || BridgeModelInspectParameter.ImageBridgeVerifyChannelIndex < 0)
                        {
                            MessageBox.Show("没有选择检测验证通道图像!");
                        }
                        else
                        {
                            //保存在所选框架上  暂时保存在同一个框架上  1211 lw 图层+1
                            HOperatorSet.WriteTuple((new HTuple(FrameModelInspectParameter.ImageFrameVerifyChannelIndex + 1))
                                                    .TupleConcat(new HTuple(PegRackModelInspectParameter.ImagePegRackVerifyChannelIndex + 1))
                                                    .TupleConcat(new HTuple(BridgeModelInspectParameter.ImageBridgeVerifyChannelIndex + 1)),
                                                    $"{ModelsFile}{SurfaceDetectionParameter.OnRecipesIndexs[SurfaceDetectionParameter.OnRecipesIndex]}\\Inspect_ImageIndex.tup");
                        }
                    }

                    HOperatorSet.WriteTuple(new HTuple(FrameModelInspectParameter.IsFrameSurfaceInspect == false ? 0 : 1)
                                            .TupleConcat(new HTuple(PegRackModelInspectParameter.IsPegRackSurfaceInspect == false ? 0 : 1))
                                            .TupleConcat(new HTuple(BridgeModelInspectParameter.IsBridgeSurfaceInspect == false ? 0 : 1)), $"{ModelsFile}{SurfaceDetectionParameter.OnRecipesIndexs[SurfaceDetectionParameter.OnRecipesIndex]}\\TaskEnable.tup");
                }
                HOperatorSet.WriteTuple(new HTuple(FrameModelInspectParameter.IsFrameSurfaceInspect == false ? 0 : 1)
                                        .TupleConcat(new HTuple(PegRackModelInspectParameter.IsPegRackSurfaceInspect == false ? 0 : 1))
                                        .TupleConcat(new HTuple(BridgeModelInspectParameter.IsBridgeSurfaceInspect == false ? 0 : 1)), ModelsDirectory + "TaskEnable.tup");
            }

            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Exemplo n.º 8
0
        public void SaveXML()
        {
            try
            {
                Directory.GetFiles(ModelsDirectory).ToList().ForEach(File.Delete);
                XElement root = new XElement("Recipe");
                XMLHelper.AddIdentifier(root, IdentifyString);
                //
                XElement wireParameterNode = new XElement("WireParameter");
                XMLHelper.AddParameters(wireParameterNode, wireParameter, IdentifyString);

                //保存起始焊点归属
                XMLHelper.AddOnRecipes(root, startBondOnRecipes, "StartBondOnRecipes");
                XMLHelper.AddRegion(root, startBallAutoUserRegion, "StartBallAutoUserRegion", false, false, false, false);

                //保存结束焊点归属
                XMLHelper.AddOnRecipes(root, endBondOnRecipes, "EndBondOnRecipes");
                XMLHelper.AddRegion(root, stopBallAutoUserRegion, "StopBallAutoUserRegion", false, false, false, false);

                //金线模板组合
                XElement wireRegionsModelGroupNode = new XElement("WireRegionsModelGroup");
                foreach (var modelGroup in wireRegionsModelGroup)
                {
                    XElement modelGroupNode = new XElement("ModelGroup");
                    //组号索引
                    modelGroupNode.Add(new XAttribute("Index", modelGroup.Index.ToString()));
                    //金线模板序号选择
                    modelGroupNode.Add(new XAttribute("SelectModelNumber", modelGroup.SelectModelNumber.ToString()));
                    //模板起始焊点,结束焊点,焊点点金线,金线检测区域带参数
                    modelGroupNode.Add(modelGroup.ModelStartUserRegions?.ToXElement("ModelStartUserRegions"));
                    modelGroupNode.Add(modelGroup.ModelStopUserRegions?.ToXElement("ModelStopUserRegions"));
                    modelGroupNode.Add(modelGroup.RefLineModelRegions?.ToXElement("RefLineModelRegions"));
                    XMLHelper.AddRegion(modelGroupNode, modelGroup.LineModelRegions, "LineModelRegions", false, false, true, false);
                    wireRegionsModelGroupNode.Add(modelGroupNode);
                }

                //-----金线检测区域精修及保存区域
                XElement wireRegionsGroupNode = new XElement("WireRegionsGroup");
                foreach (var group in wireRegionsGroup)
                {
                    XElement groupNode = new XElement("Group");
                    groupNode.Add(new XAttribute("Index", group.Index.ToString()));
                    groupNode.Add(group.BondOnICUserRegions?.ToXElement("BondOnICUserRegions"));
                    groupNode.Add(group.BondOnFrameUserRegions?.ToXElement("BondOnFrameUserRegions"));
                    //groupNode.Add(group.RefLineUserRegions?.ToXElement("RefLineUserRegions"));
                    XMLHelper.AddRegion(groupNode, group.LineUserRegions, "LineUserRegions", false, true, false, false);
                    wireRegionsGroupNode.Add(groupNode);
                }


                root.Add(wireParameterNode);
                root.Add(wireRegionsModelGroupNode);
                root.Add(wireRegionsGroupNode);
                root.Save(XmlPath);

                HOperatorSet.GenEmptyObj(out HObject LineRegions);
                HTuple LineRegionsNumbers = new HTuple();
                HOperatorSet.WriteRegion(Algorithm.Region.ConcatRegion(wireRegionsGroup.Select(r => r.BondOnFrameUserRegions).Where(r => r.IsEnable).Select(r => r.CalculateRegion)), ModelsDirectory + "Start_Regions.reg");
                HOperatorSet.WriteRegion(Algorithm.Region.ConcatRegion(wireRegionsGroup.Select(r => r.BondOnICUserRegions).Where(r => r.IsEnable).Select(r => r.CalculateRegion)), ModelsDirectory + "Stop_Regions.reg");
                foreach (var group in wireRegionsGroup)
                {
                    LineRegions        = LineRegions.ConcatObj(Algorithm.Region.ConcatRegion((group.LineUserRegions).Where(r => r.IsEnable).Select(r => r.CalculateRegion)));
                    LineRegionsNumbers = LineRegionsNumbers.TupleConcat(group.LineUserRegions.Count);
                }

                if (wireParameter.ImageCountChannels == 1)
                {
                    HOperatorSet.WriteTuple(new HTuple(1), ModelsDirectory + "Image_Index.tup");
                }
                else if (wireParameter.ImageCountChannels > 1)
                {
                    HOperatorSet.WriteTuple(wireParameter.ImageIndex + 1, ModelsDirectory + "Image_Index.tup");
                }

                HOperatorSet.WriteRegion(LineRegions, ModelsDirectory + "Inspect_Regions.reg");
                HOperatorSet.WriteTuple(LineRegionsNumbers, RecipeDirectory + "InspectRegNum.tup");
                HOperatorSet.WriteTuple(LineRegionsNumbers, ModelsDirectory + "InspectRegNum.tup");//Recipe下
                HOperatorSet.WriteTuple(wireParameter.IsTailInspect == false ? 0 : 1, ModelsDirectory + "IsInspectTail.tup");

                //保存起始焊点区域归属
                HTuple StartRegBelongToWhat = new HTuple();
                foreach (var StartonRecipe in startBondOnRecipes)
                {
                    if (StartonRecipe.IsSelected)
                    {
                        HOperatorSet.TupleConcat(StartRegBelongToWhat, new HTuple(StartonRecipe.Name), out StartRegBelongToWhat);
                    }
                }
                HOperatorSet.WriteTuple(StartRegBelongToWhat, ModelsDirectory + "StartRegBelongToWhat.tup");
                //1104 改成存带拾取顺序的组合焊点
                HOperatorSet.WriteTuple(new HTuple(wireParameter.StartBondonRecipesIndexs), ModelsDirectory + "StartRegBelongToWhat.tup");

                //保存结束焊点区域归属
                HTuple StopRegBelongToWhat = new HTuple();
                foreach (var StoponRecipe in endBondOnRecipes)
                {
                    if (StoponRecipe.IsSelected)
                    {
                        HOperatorSet.TupleConcat(StopRegBelongToWhat, new HTuple(StoponRecipe.Name), out StopRegBelongToWhat);
                    }
                }
                HOperatorSet.WriteTuple(StopRegBelongToWhat, ModelsDirectory + "StopRegBelongToWhat.tup");
                //1104 改成存带拾取顺序的组合焊点
                HOperatorSet.WriteTuple(new HTuple(wireParameter.StopBondonRecipesIndexs), ModelsDirectory + "StopRegBelongToWhat.tup");

                //1104 存储焊点组合后的重新排序信息
                HTuple Startreg_index_after_sort = new HTuple();
                HTuple ni;
                ni = 0;
                bool start_group_sort = false;
                foreach (var start_reg in startBallAutoUserRegion)
                {
                    //HOperatorSet.TupleConcat(Startreg_index_after_sort, new HTuple(start_reg.Index), out Startreg_index_after_sort);
                    Startreg_index_after_sort[ni] = start_reg.Index_ini;
                    ni++;
                    if (ni != start_reg.Index_ini)
                    {
                        start_group_sort = true;
                    }
                }
                HOperatorSet.WriteTuple(Startreg_index_after_sort, ModelsDirectory + "Startreg_index_after_sort.tup");
                HOperatorSet.WriteTuple(start_group_sort == false ? 0 : 1, ModelsDirectory + "Startreg_need_sort.tup");

                HTuple Stopreg_index_after_sort = new HTuple();
                ni = 0;
                bool stop_group_sort = false;
                foreach (var stop_reg in stopBallAutoUserRegion)
                {
                    //HOperatorSet.TupleConcat(Stopreg_index_after_sort, new HTuple(stop_reg.Index), out Stopreg_index_after_sort);
                    Stopreg_index_after_sort[ni] = stop_reg.Index_ini;
                    ni++;
                    if (ni != stop_reg.Index_ini)
                    {
                        stop_group_sort = true;
                    }
                }
                HOperatorSet.WriteTuple(Stopreg_index_after_sort, ModelsDirectory + "Stopreg_index_after_sort.tup");
                HOperatorSet.WriteTuple(stop_group_sort == false ? 0 : 1, ModelsDirectory + "Stopreg_need_sort.tup");

                HOperatorSet.WriteTuple(new HTuple(wireParameter.IsEnableStartVirtualBond).TupleConcat(new HTuple(wireParameter.IsEnableEndVirtualBond)), ModelsDirectory + "IsEnableVirtualBond.tup");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Exemplo n.º 9
0
        public void SaveXML()
        {
            try
            {
                Directory.GetFiles(ModelsBondDirectory).ToList().ForEach(File.Delete);
                XElement root = new XElement("Recipe");
                XMLHelper.AddIdentifier(root, IdentifyString);
                XElement bondMeasureParameterNode      = new XElement("BondMeasureParameter");
                XElement bond1AutoRegionsParameterNode = new XElement("Bond1AutoRegionsParameter");//自动生成
                XMLHelper.AddParameters(bondMeasureParameterNode, bondMeasureParameter, IdentifyString);
                if (bond1AutoRegionsParameter.RotatedImagePath == null)
                {
                    // 1122
                    bond1AutoRegionsParameter.RotatedImagePath = "";
                }
                XMLHelper.AddParameters(bond1AutoRegionsParameterNode, bond1AutoRegionsParameter, IdentifyString);//自动生成
                XMLHelper.AddRegion(root, bondModelUserRegions, "BondModelUserRegions", true);

                //XMLHelper.AddRegion(root, BondVerifyUserRegions, "BondVerifyUserRegions");//自动生成焊点检测区域
                //
                XMLHelper.AddRegion(root, PadUserRegions, "PadUserRegions", false, false, false, false, true);//xml中加载生成的焊盘区域 2021-01-05

                XElement BondVerifyModelParaNode = new XElement("BondVerifyModelPara");
                XMLHelper.AddParameters(BondVerifyModelParaNode, bondVerifyModelPara, IdentifyString);
                root.Add(BondVerifyModelParaNode);                                                                                //保存批量设置的模板检测参数
                //models下保存焊盘区域
                HOperatorSet.WriteRegion(Algorithm.Region.ConcatRegion(PadUserRegions), ModelsBondDirectory + "Pad_Regions.reg"); //add by wj 2021-0105


                XMLHelper.AddRegion(root, Bond2UserRegion, "Bond2UserRegion");
                XMLHelper.AddRegion(root, Bond2UserRegionDiff, "Bond2UserRegionDiff");
                XMLHelper.AddRegion(root, RotateLineUserRegion, "RotateLineUserRegion");

                XElement BondMeasureVerifyParameterNode = new XElement("BondMeasureVerifyParameter");
                XElement bondWireGroupNode = new XElement("BondWireGroups");
                XMLHelper.AddParameters(BondMeasureVerifyParameterNode, bondMeasureVerifyParameter, IdentifyString);
                root.Add(bondMeasureParameterNode);
                root.Add(bond1AutoRegionsParameterNode);//自动生成
                root.Add(BondMeasureVerifyParameterNode);
                //自动生成焊点区域部分
                foreach (var group in bondWireRegionGroups)
                {
                    XElement groupNode = new XElement("BondWireGroup");
                    groupNode.Add(new XAttribute("Index", group.Index.ToString()));
                    groupNode.Add(new XAttribute("Bond2Numbers", group.Bond2_BallNums.ToString()));
                    groupNode.Add(group.Bond2UserRegion?.ToXElement("Bond2Region"));
                    groupNode.Add(group.WireUserRegion?.ToXElement("WireRegion"));
                    bondWireGroupNode.Add(groupNode);
                }
                root.Add(bondWireGroupNode);
                root.Save(XmlPath);

                //if (bondMeasureParameter.ImageCountChannels == 1)
                //{
                //    HOperatorSet.WriteTuple(new HTuple(1), ModelsBondDirectory + "Image_Index.tup");
                //}
                //else if (bondMeasureParameter.ImageCountChannels > 1)
                //{
                //    HOperatorSet.WriteTuple(bondMeasureVerifyParameter.ImageChannelIndex + 1, ModelsBondDirectory + "Image_Index.tup");
                //}

                //HOperatorSet.WriteRegion(Algorithm.Region.ConcatRegion(BondVerifyUserRegions), ModelsBondDirectory + "Inspect_Regions.reg");

                //HTuple bondOffsetFactor = new HTuple();
                //HTuple bondOverSizeFactor = new HTuple();
                //HTuple bondUnderSizeFactor = new HTuple();
                //HTuple PreJudgeEnable = new HTuple();
                //HTuple SegThreshGray = new HTuple();
                //HTuple SegRegAreaFactor = new HTuple();
                HTuple DistanceThreshold = new HTuple();

                foreach (var item in bondModelUserRegions)
                {
                    //    //HOperatorSet.TupleConcat(bondOffsetFactor,item.BondMeasureVerifyParameterSet.BondOffsetFactor, out bondOffsetFactor);
                    //    HOperatorSet.TupleConcat(bondOverSizeFactor, item.BondMeasureVerifyParameterSet.BondOverSizeFactor, out bondOverSizeFactor);
                    //    HOperatorSet.TupleConcat(bondUnderSizeFactor, item.BondMeasureVerifyParameterSet.BondUnderSizeFactor, out bondUnderSizeFactor);
                    //    HOperatorSet.TupleConcat(PreJudgeEnable, item.BondMeasureVerifyParameterSet.PreJudgeEnable, out PreJudgeEnable);
                    //    HOperatorSet.TupleConcat(SegThreshGray, item.BondMeasureVerifyParameterSet.SegThreshGray, out SegThreshGray);
                    //    HOperatorSet.TupleConcat(SegRegAreaFactor, item.BondMeasureVerifyParameterSet.SegRegAreaFactor, out SegRegAreaFactor);
                    HOperatorSet.TupleConcat(DistanceThreshold, item.BondMeasureModelParameter.DistanceThreshold, out DistanceThreshold);
                }
                //HOperatorSet.WriteTuple(bondOffsetFactor, $"{ModelsBondDirectory}BondOffsetFactor.tup");
                //HOperatorSet.WriteTuple(bondOverSizeFactor, $"{ModelsBondDirectory}BondOverSizeFactor.tup");
                //HOperatorSet.WriteTuple(bondUnderSizeFactor, $"{ModelsBondDirectory}BondUnderSizeFactor.tup");
                //HOperatorSet.WriteTuple(PreJudgeEnable, $"{ModelsBondDirectory}PreJudgeEnable.tup");
                //HOperatorSet.WriteTuple(SegThreshGray, $"{ModelsBondDirectory}SegThreshGray.tup");
                //HOperatorSet.WriteTuple(SegRegAreaFactor, $"{ModelsBondDirectory}SegRegAreaFactor.tup");
                HOperatorSet.WriteTuple(DistanceThreshold, $"{ModelsBondDirectory}MetrologyDistanceThreshold.tup");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            try
            {
                if (bondMeasureParameter.OnRecipesIndexs.Length > 0)
                {
                    HOperatorSet.WriteTuple(bondMeasureParameter.OnRecipesIndexs[bondMeasureParameter.OnRecipesIndex], $"{ModelsBondDirectory}OnWhat.tup");
                }
            }
            catch (Exception)//改
            {
                MessageBox.Show("请选择\"焊点在\"位置!");
            }

            try
            {
                if (bondMeasureModelObject.MetrologyHandle != null)
                {
                    HOperatorSet.WriteMetrologyModel(bondMeasureModelObject.MetrologyHandle, $"{ModelsBondDirectory}" + "MetrologyHandle.mtr");
                }
                else if (File.Exists($"{BondMeasureDirectory}MetrologyHandle.mtr"))
                {
                    HOperatorSet.ReadMetrologyModel($"{BondMeasureDirectory}MetrologyHandle.mtr", out HTuple metrologyHandle);
                    HOperatorSet.WriteMetrologyModel(metrologyHandle, $"{ModelsBondDirectory}" + "MetrologyHandle.mtr");
                }
                HOperatorSet.WriteTuple(Algorithm.Region.MetrologyType(bondModelUserRegions), $"{ModelsBondDirectory}MetrologyType.tup");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "模板句柄保存异常!");
            }
        }
Exemplo n.º 10
0
        public override void SaveXML()
        {
            try
            {
                // 保留表面检测保存区域 0113 lw
                HObject ho_Frame_Region = null;
                if (File.Exists($"{ModelsRecipeDirectory}Frame_Region.reg"))
                {
                    HOperatorSet.ReadRegion(out ho_Frame_Region, ModelsRecipeDirectory + "Frame_Region.reg");
                }

                HObject ho_PegRack_Region = null;
                if (File.Exists($"{ModelsRecipeDirectory}PegRack_Region.reg"))
                {
                    HOperatorSet.ReadRegion(out ho_PegRack_Region, ModelsRecipeDirectory + "PegRack_Region.reg");
                }

                HObject ho_Bridge_Region = null;
                if (File.Exists($"{ModelsRecipeDirectory}Bridge_Region.reg"))
                {
                    HOperatorSet.ReadRegion(out ho_Bridge_Region, ModelsRecipeDirectory + "Bridge_Region.reg");
                }

                //Models删除文件
                Directory.GetFiles(ModelsRecipeDirectory).ToList().ForEach(File.Delete);

                if (ho_Frame_Region != null)
                {
                    HOperatorSet.WriteRegion(ho_Frame_Region, ModelsRecipeDirectory + "Frame_Region.reg");
                    ho_Frame_Region.Dispose();
                }
                if (ho_PegRack_Region != null)
                {
                    HOperatorSet.WriteRegion(ho_PegRack_Region, ModelsRecipeDirectory + "PegRack_Region.reg");
                    ho_PegRack_Region.Dispose();
                }
                if (ho_Bridge_Region != null)
                {
                    HOperatorSet.WriteRegion(ho_Bridge_Region, ModelsRecipeDirectory + "Bridge_Region.reg");
                    ho_Bridge_Region.Dispose();
                }

                XElement root = new XElement("Recipe");
                XElement goldenModelParameterNode        = new XElement("GoldenModelParameter");
                XElement frameLocateInspectParameterNode = new XElement("FrameLocateParameter");
                XMLHelper.AddIdentifier(root, IdentifyString);
                XMLHelper.AddRegion(root, dieUserRegions, "Die_Regions");

                //多框架区域保存
                XElement matchRegionGroupsNode = new XElement("MatchRegionGroup");
                foreach (var group in MatchRegionsGroups)
                {
                    XElement matchRegionNode = new XElement("MatchRegion");
                    matchRegionNode.Add(new XAttribute("Index", group.Index.ToString()));
                    XMLHelper.AddRegion(matchRegionNode, group.MatchUserRegions, "Region");
                    matchRegionGroupsNode.Add(matchRegionNode);
                }
                //框架区域保存
                XMLHelper.AddRegion(root, FrameUserRegions, "Frame_Region");

                XMLHelper.AddParameters(goldenModelParameterNode, goldenModelParameter, IdentifyString);
                XMLHelper.AddParameters(frameLocateInspectParameterNode, frameLocateInspectParameter, IdentifyString);
                root.Add(goldenModelParameterNode);
                root.Add(frameLocateInspectParameterNode);
                root.Add(matchRegionGroupsNode);
                root.Save(XmlPath);

                if (goldenModelParameter.ImageCountChannels == 1)
                {
                    HOperatorSet.WriteTuple(new HTuple(1), ModelsRecipeDirectory + "Image_Index.tup");
                }
                else if (goldenModelParameter.ImageCountChannels > 1)
                {
                    //1121
                    HOperatorSet.WriteTuple(new HTuple(goldenModelParameter.ImageChannelIndex + 1), ModelsRecipeDirectory + "Image_Index.tup");
                }

                if (goldenModelParameter.ModelType == 0)
                {
                    HOperatorSet.WriteTuple(new HTuple("ncc"), $"{ModelsRecipeDirectory}Model_Type.tup");
                }
                else if (goldenModelParameter.ModelType == 1)
                {
                    HOperatorSet.WriteTuple(new HTuple("shape"), $"{ModelsRecipeDirectory}Model_Type.tup");
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            //try
            //{
            //    if (File.Exists($"{RecipeDirectory}PosModel.dat")|| goldenModelObject.PosModelID != null)
            //    {
            //        if (goldenModelObject.PosModelID != null)
            //        {
            //            Algorithm.File.SaveModel(ModelsRecipeDirectory + "PosModel.dat", goldenModelParameter.ModelType, goldenModelObject.PosModelID);
            //        }
            //        else if (File.Exists($"{RecipeDirectory}PosModel.dat"))
            //        {
            //            HTuple PosModelId = Algorithm.File.ReadModel($"{RecipeDirectory}PosModel.dat", goldenModelParameter.ModelType);
            //            Algorithm.File.SaveModel(ModelsRecipeDirectory + "PosModel.dat", goldenModelParameter.ModelType, PosModelId);
            //        }
            //    }
            //    else
            //    {
            //        MessageBox.Show("请创建定位模板!");
            //    }
            //}
            //catch (System.Exception ex)
            //{
            //    MessageBox.Show(ex.ToString(),"保存模板错误!");
            //}

            try
            {
                HOperatorSet.WriteTuple(frameLocateInspectParameter.AngleStart, FilePath.EnsureDirectoryExisted($"{ModelsRecipeDirectory}") + "AngleStart.tup");
                HOperatorSet.WriteTuple(frameLocateInspectParameter.AngleExt, FilePath.EnsureDirectoryExisted($"{ModelsRecipeDirectory}") + "AngleExt.tup");
                HOperatorSet.WriteTuple(frameLocateInspectParameter.MinMatchScore, FilePath.EnsureDirectoryExisted($"{ModelsRecipeDirectory}") + "MinMatchScore.tup");
                HOperatorSet.WriteTuple(frameLocateInspectParameter.MatchNum, FilePath.EnsureDirectoryExisted($"{ModelsRecipeDirectory}") + "MatchNum.tup");

                //HOperatorSet.WriteRegion(Algorithm.Region.Union1Region(matchUserRegions), ModelsRecipeDirectory + "Match_Region.reg");
                HOperatorSet.GenEmptyObj(out HObject matchRegions);
                foreach (var item in MatchRegionsGroups)
                {
                    // lw - 0115  每组区域应Union
                    HOperatorSet.ConcatObj(Algorithm.Region.Union1Region(item.MatchUserRegions.Where(r => r.IsEnable)), matchRegions, out matchRegions);
                }
                HOperatorSet.WriteRegion(matchRegions, ModelsRecipeDirectory + "Match_Region.reg");
                matchRegions.Dispose();

                if (FrameUserRegions.Count > 0)
                {
                    HOperatorSet.WriteRegion(FrameUserRegions[0].CalculateRegion, ModelsRecipeDirectory + "FrameRegion.reg");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            //保存模板
            string[] ModelPathArr = goldenModelParameter.PosModelIdPath.Split(',');

            if (goldenModelObject.PosModelID == null && File.Exists(ModelPathArr[0]))
            {
                goldenModelObject.PosModelID = Algorithm.File.ReadModel(ModelPathArr, goldenModelParameter.ModelType);
            }
            else if (goldenModelObject.PosModelID == null)
            {
                MessageBox.Show("请先创建定位模板!");
                return;
            }
            if (goldenModelObject.PosModelID.Length == 1)
            {
                string ModelsIDPath = $"{ModelsRecipeDirectory}PosModel.dat";
                Algorithm.File.SaveModel(ModelsIDPath, goldenModelParameter.ModelType, goldenModelObject.PosModelID);
            }
            else if (goldenModelObject.PosModelID.Length > 1)
            {
                String[] ModelIdPathArry = new string[goldenModelObject.PosModelID.Length];
                for (int i = 0; i < goldenModelParameter.PosModelIdPath.Split(',').Length; i++)
                {
                    ModelIdPathArry[i] = $"{ModelsRecipeDirectory}PosModel_" + i + ".dat";
                }
                Algorithm.File.SaveModel(ModelIdPathArry, goldenModelParameter.ModelType, goldenModelObject.PosModelID);//
            }
            else
            {
                MessageBox.Show("请先创建模板!");
            }

            //try
            //{
            //    if (($"{RecipeDirectory}PosModel.dat").Contains("PosModel"))
            //    {
            //        if (goldenModelParameter.ModelIdPath.Split(',').Length == 1 && goldenModelParameter.ModelIdPath != "")
            //        {
            //            if (File.Exists($"{RecipeDirectory}PosModel.dat") || goldenModelObject.PosModelID != null)
            //            {
            //                if (goldenModelObject.PosModelID != null)
            //                {
            //                    Algorithm.File.SaveModel(ModelsRecipeDirectory + "PosModel.dat", goldenModelParameter.ModelType, goldenModelObject.PosModelID);
            //                }
            //                else if (File.Exists($"{RecipeDirectory}PosModel.dat"))
            //                {
            //                    HTuple PosModelId = Algorithm.File.ReadModel($"{RecipeDirectory}PosModel.dat", goldenModelParameter.ModelType);
            //                    Algorithm.File.SaveModel(ModelsRecipeDirectory + "PosModel.dat", goldenModelParameter.ModelType, PosModelId);
            //                }
            //            }
            //            else
            //            {
            //                MessageBox.Show("请创建定位模板!");
            //            }
            //        }
            //        else
            //        {
            //            if (goldenModelObject.PosModelID != null)
            //            {
            //                String[] ModelIdPathArry = new string[goldenModelObject.PosModelID.TupleLength()];
            //                for (int i = 0; i < goldenModelObject.PosModelID.TupleLength(); i++)
            //                {
            //                    ModelIdPathArry[i] = $"{ModelsRecipeDirectory}PosModel_" + i + ".dat";
            //                }
            //                goldenModelParameter.ModelIdPath = String.Join(",", ModelIdPathArry);
            //                Algorithm.File.SaveModel(ModelIdPathArry, goldenModelParameter.ModelType, goldenModelObject.PosModelID);
            //            }
            //            else if (File.Exists($"{RecipeDirectory}PosModel.dat"))
            //            {
            //                HTuple ModelId = Algorithm.File.ReadModel($"{RecipeDirectory}PosModel.dat".Split(','), goldenModelParameter.ModelType);
            //                String[] ModelIdPathArry = new string[ModelId.TupleLength()];
            //                for (int i = 0; i < ModelId.TupleLength(); i++)
            //                {
            //                    ModelIdPathArry[i] = $"{ModelsRecipeDirectory}PosModel_" + i + ".dat";
            //                }
            //                Algorithm.File.SaveModel(ModelIdPathArry, goldenModelParameter.ModelType, ModelId);
            //            }
            //        }
            //    }
            //}
            //catch (System.Exception ex)
            //{
            //    MessageBox.Show(ex.ToString());
            //}
        }