예제 #1
0
        public static void ReadRegionOne(XElement fatherNode,
                                         UserRegion userRegion,
                                         string name,
                                         double rowOffset     = 0,
                                         double columnOffset  = 0,
                                         bool isReadParameter = false)//
        {
            XElement node = fatherNode.Element(name);

            if (node == null)
            {
                return;
            }
            foreach (var element in node.Elements())
            {
                userRegion = (UserRegion.FromXElement(element, isReadParameter, rowOffset, columnOffset));
            }
            return;
        }
예제 #2
0
        public static void ReadRegion(XElement fatherNode,
                                      IList <UserRegion> userRegions,
                                      string name,
                                      double rowOffset              = 0,
                                      double columnOffset           = 0,
                                      bool isReadParameter          = false,
                                      bool isReadAlgoParameter      = false,
                                      bool isReadModelAlgoParameter = false,
                                      bool isReadRegAlgoParameter   = false, //读取AroundBond检测参数
                                      bool IsReadBondAlgoParameter  = false) //读取Bond检测参数
        {
            XElement node = fatherNode.Element(name);

            if (node == null)
            {
                return;
            }
            foreach (var element in node.Elements())
            {
                userRegions.Add(UserRegion.FromXElement(element, isReadParameter, rowOffset, columnOffset, isReadAlgoParameter, isReadModelAlgoParameter, isReadRegAlgoParameter, IsReadBondAlgoParameter));
            }
            return;
        }
예제 #3
0
        //加载
        public void LoadXML(string xmlPath)
        {
            /*
             * await Task.Run(() =>
             * {
             *  while (htWindow.HTWindow.HalconWindow.Handle == (IntPtr)0xffffffffffffffff)
             *  {
             *      Thread.Sleep(500);
             *  }
             * });
             */
            try
            {
                XElement root = XElement.Load(xmlPath);
                XElement bond2ModelParameterNode = root.Element("Bond2ModelParameter");
                if (bond2ModelParameterNode == null)
                {
                    return;
                }
                XElement bond2ModelNode = root.Element("Bond2Models");
                if (bond2ModelNode == null)
                {
                    return;
                }
                XMLHelper.ReadParameters(bond2ModelParameterNode, bond2ModelParameter);
                (createBond2Model as CreateBond2Model).LoadReferenceData();

                bond2Models.Clear();
                bondWireRegionGroups.Clear();
                Groups.Clear();
                XElement bondWireParameterNode = root.Element("BondWireParameter");
                XMLHelper.ReadParameters(bondWireParameterNode, bondWireParameter);

                XElement bondAutoRegionsParameterNode = root.Element("BondAutoRegionsParameter"); //自动
                XMLHelper.ReadParameters(bondAutoRegionsParameterNode, bondAutoRegionsParameter); //自动

                //bond2Models.Clear();放前面
                foreach (var modelNode in bond2ModelNode.Elements("Model"))
                {
                    Bond2Model model = new Bond2Model();
                    model.ModelIdPath          = modelNode.Attribute("ModelIDPath")?.Value;
                    model.Index                = (int.Parse)(modelNode.Attribute("Index")?.Value);
                    model.RotatedImagePath     = modelNode.Element("RotatedImagePath")?.Value;
                    model.Bond2UserRegion      = UserRegion.FromXElement(modelNode.Element("Bond2ModelRegion"));
                    model.RotateLineUserRegion = UserRegion.FromXElement(modelNode.Element("RotateLineRegion"));
                    model.Bond2UserRegionDiff  = UserRegion.FromXElement(modelNode.Element("Bond2ModelRegionDiff"));//
                    XMLHelper.ReadRegion(modelNode, model.RefineUserRegions, "RefineRegions");
                    bond2Models.Add(model);
                    model.Index = bond2Models.Count;
                }
                (createBond2Model as CreateBond2Model).ModelsCount = bond2Models.Count;

                // 自动焊点区域部分
                XElement GenGroupsNode = root.Element("GenGroups");
                if (GenGroupsNode != null)
                {
                    foreach (var groupNode in GenGroupsNode.Elements("GenGroup"))
                    {
                        BondMatchAutoRegionGroup group = new BondMatchAutoRegionGroup();
                        group.Bond2UserRegion = UserRegion.FromXElement(groupNode.Element("Bond2Region"), false, bond2ModelParameter.DieImageRowOffset, bond2ModelParameter.DieImageColumnOffset);
                        group.WireUserRegion  = UserRegion.FromXElement(groupNode.Element("WireRegion"), false, bond2ModelParameter.DieImageRowOffset, bond2ModelParameter.DieImageColumnOffset);
                        //XMLHelper.ReadParameters(groupNode, group.Parameter);
                        Groups.Add(group);
                        group.Index          = Groups.Count;
                        group.Bond2_BallNums = int.Parse(groupNode.Attribute("Bond2Numbers")?.Value);
                    }
                }

                XElement bondWireGroupNode = root.Element("BondWireGroups");
                if (bondWireGroupNode == null)
                {
                    return;
                }

                foreach (var groupNode in bondWireGroupNode.Elements("BondWireGroup"))
                {
                    BondWireRegionGroup group = new BondWireRegionGroup();
                    group.Bond2UserRegion = UserRegion.FromXElement(groupNode.Element("Bond2Region"), false, bond2ModelParameter.DieImageRowOffset, bond2ModelParameter.DieImageColumnOffset);
                    group.WireUserRegion  = UserRegion.FromXElement(groupNode.Element("WireRegion"), false, bond2ModelParameter.DieImageRowOffset, bond2ModelParameter.DieImageColumnOffset);                                                                                                                                                                                         //XMLHelper.ReadParameters(groupNode, group.Parameter);
                    bondWireRegionGroups.Add(group);
                    group.Index          = bondWireRegionGroups.Count;
                    group.Bond2_BallNums = int.Parse(groupNode.Attribute("Bond2Numbers")?.Value);
                }

                (bondMatchAutoRegions as BondMatchAutoRegions).GroupsCount = Groups.Count;
                (addBondMatchRegions as AddBondMatchRegions).GroupsCount   = bondWireRegionGroups.Count;

                (createBond2Model as CreateBond2Model).Initial();

                //加载焊点检测区域及其参数
                XMLHelper.ReadRegion(root, BondVerifyUserRegions, "BondVerifyUserRegions", bond2ModelParameter.DieImageRowOffset, bond2ModelParameter.DieImageColumnOffset, false, false, false, false, true);
                //
                XElement BondVerifyModelParaNode = root.Element("BondVerifyModelPara");
                XMLHelper.ReadParameters(BondVerifyModelParaNode, BondVerifyModelPara);
                // 兼容老产品打开参数不保留 2021-0105 by wj
                if (BondVerifyUserRegions.Count() != 0)
                {
                    //更新PadUserRegions
                    for (int i = 0; i < BondVerifyUserRegions.Count; i++)
                    {
                        //检测区域内通道值设置
                        if (BondVerifyUserRegions.ElementAt(i).ChannelNames.Count() == 0)
                        {
                            BondVerifyUserRegions.ElementAt(i).ChannelNames = bond2ModelParameter.ChannelNames;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
예제 #4
0
        //加载
        public void LoadXML(string xmlPath)
        {
            // 1216 lw 此处保存产品会出错

            /*await Task.Run(() =>
             * {
             *  while (htWindow.HTWindow.HalconWindow.Handle == (IntPtr)0xffffffffffffffff)
             *  {
             *      Thread.Sleep(500);
             *  }
             * });*/

            IsLoadXML = true;

            try
            {
                XElement root = XElement.Load(xmlPath);
                XElement wireParameterNode = root.Element("WireParameter");
                if (wireParameterNode == null)
                {
                    return;
                }
                XMLHelper.ReadParameters(wireParameterNode, wireParameter);

                //从金线自动生成区域加载参考信息
                (wireAddAutoRegion as WireAddAutoRegion).LoadReferenceData();

                //-----------------------------------------------------------------------------------------------------------------------------
                XElement wireRegionsGroupNode = root.Element("WireRegionsGroup");
                if (wireRegionsGroupNode == null)
                {
                    return;
                }

                wireRegionsGroup.Clear();
                foreach (var groupNode in wireRegionsGroupNode.Elements("Group"))
                {
                    WireRegionsGroup group = new WireRegionsGroup();
                    group.BondOnICUserRegions    = UserRegion.FromXElement(groupNode.Element("BondOnICUserRegions"), false, wireParameter.DieImageRowOffset, wireParameter.DieImageColumnOffset, false, false, false);
                    group.BondOnFrameUserRegions = UserRegion.FromXElement(groupNode.Element("BondOnFrameUserRegions"), false, wireParameter.DieImageRowOffset, wireParameter.DieImageColumnOffset, false, false, false);
                    //group.RefLineUserRegions = UserRegion.FromXElement(groupNode.Element("RefLineUserRegions"), false, wireParameter.DieImageRowOffset, wireParameter.DieImageColumnOffset);
                    XMLHelper.ReadRegion(groupNode, group.LineUserRegions, "LineUserRegions", wireParameter.DieImageRowOffset, wireParameter.DieImageColumnOffset, false, true, false, false);

                    //1212 金线检测区域的通道值设置-生成线
                    for (int i = 0; i < group.LineUserRegions.Count(); i++)
                    {
                        if (group.LineUserRegions.ElementAt(i).ChannelNames.Count() == 0)
                        {
                            group.LineUserRegions.ElementAt(i).ChannelNames = wireParameter.ChannelNames; // currentChannelName
                            int tmp_ind;
                            tmp_ind = group.LineUserRegions.ElementAt(i).ImageIndex;
                        }
                    }
                    wireRegionsGroup.Add(group);
                    group.Index = wireRegionsGroup.Count;
                }
                (wireAddRegion as WireAddRegion).GroupsCount = wireRegionsGroup.Count;

                //-----加载自动生成金线界面
                //加载起始焊点区域归属
                startBondOnRecipes.Clear();
                XMLHelper.ReadOnRecipes(root, startBondOnRecipes, "StartBondOnRecipes");
                XMLHelper.ReadRegion(root, startBallAutoUserRegion, "StartBallAutoUserRegion", wireParameter.DieImageRowOffset,
                                     wireParameter.DieImageColumnOffset, false, false, false, false);

                // add lw
                HTuple hv__filePath = new HTuple(), hv_FileExists = new HTuple();
                HTuple Startreg_index_after_sort = new HTuple();
                hv__filePath = ModelsDirectory + "Startreg_index_after_sort.tup";
                HOperatorSet.FileExists(hv__filePath, out hv_FileExists);
                if ((int)(hv_FileExists) != 0)
                {
                    HOperatorSet.ReadTuple(hv__filePath, out Startreg_index_after_sort);
                }
                else
                {
                    Startreg_index_after_sort = HTuple.TupleGenSequence(1, startBallAutoUserRegion.Count, 1);
                }

                for (int i = 0; i < Startreg_index_after_sort.Length; i++)
                {
                    startBallAutoUserRegion[i].Index_ini = Startreg_index_after_sort[i];
                }

                if (startBondOnRecipes.Count == 0)
                {
                    IsLoadXML = false;
                    if (wireParameter.IsEnableStartVirtualBond == true)
                    {
                        wireParameter.IsEnableStartVirtualBond = false;
                        wireParameter.IsEnableStartVirtualBond = true;
                    }
                    if (wireParameter.IsEnableStartVirtualBond == false)
                    {
                        wireParameter.IsEnableStartVirtualBond = true;
                        wireParameter.IsEnableStartVirtualBond = false;
                    }
                }

                //加载结束焊点归属
                endBondOnRecipes.Clear();
                XMLHelper.ReadOnRecipes(root, endBondOnRecipes, "EndBondOnRecipes");
                XMLHelper.ReadRegion(root, stopBallAutoUserRegion, "StopBallAutoUserRegion", wireParameter.DieImageRowOffset,
                                     wireParameter.DieImageColumnOffset, false, false, false, false);

                // add lw
                HTuple Stopreg_index_after_sort  = new HTuple();
                hv__filePath = ModelsDirectory + "Stopreg_index_after_sort.tup";
                HOperatorSet.FileExists(hv__filePath, out hv_FileExists);
                if ((int)(hv_FileExists) != 0)
                {
                    HOperatorSet.ReadTuple(hv__filePath, out Stopreg_index_after_sort);
                }
                else
                {
                    Stopreg_index_after_sort = HTuple.TupleGenSequence(1, stopBallAutoUserRegion.Count, 1);
                }

                for (int i = 0; i < Stopreg_index_after_sort.Length; i++)
                {
                    stopBallAutoUserRegion[i].Index_ini = Stopreg_index_after_sort[i];
                }

                if (endBondOnRecipes.Count == 0)
                {
                    IsLoadXML = false;
                    if (wireParameter.IsEnableEndVirtualBond == true)
                    {
                        wireParameter.IsEnableEndVirtualBond = false;
                        wireParameter.IsEnableEndVirtualBond = true;
                    }
                    if (wireParameter.IsEnableEndVirtualBond == false)
                    {
                        wireParameter.IsEnableEndVirtualBond = true;
                        wireParameter.IsEnableEndVirtualBond = false;
                    }
                }

                //---------------生成界面中金线
                (wireAddAutoRegion as WireAddAutoRegion).UpdateStartandStopLineRegions(true);

                //金线模板Model
                XElement wireRegionsModelGroupNode = root.Element("WireRegionsModelGroup");
                if (wireRegionsModelGroupNode == null)
                {
                    return;
                }
                wireRegionsModelGroup.Clear();

                foreach (var modelGroupNode in wireRegionsModelGroupNode.Elements("ModelGroup"))
                {
                    WireAutoRegionGroup modelGroup = new WireAutoRegionGroup();
                    modelGroup.ModelStartUserRegions = UserRegion.FromXElement(modelGroupNode.Element("ModelStartUserRegions"),
                                                                               false, wireParameter.DieImageRowOffset, wireParameter.DieImageColumnOffset, false, false, false);
                    modelGroup.ModelStopUserRegions = UserRegion.FromXElement(modelGroupNode.Element("ModelStopUserRegions"),
                                                                              false, wireParameter.DieImageRowOffset, wireParameter.DieImageColumnOffset, false, false, false);
                    modelGroup.RefLineModelRegions = UserRegion.FromXElement(modelGroupNode.Element("RefLineModelRegions"), false,
                                                                             wireParameter.DieImageRowOffset, wireParameter.DieImageColumnOffset, false, false, false);
                    XMLHelper.ReadRegion(modelGroupNode, modelGroup.LineModelRegions, "LineModelRegions", wireParameter.DieImageRowOffset,
                                         wireParameter.DieImageColumnOffset, false, false, true, false);
                    //1212 金线检测区域的通道值设置-模板线
                    for (int i = 0; i < modelGroup.LineModelRegions.Count(); i++)
                    {
                        if (modelGroup.LineModelRegions.ElementAt(i).ChannelNames.Count() == 0)
                        {
                            modelGroup.LineModelRegions.ElementAt(i).ChannelNames = wireParameter.ChannelNames;
                            int tmp_ind;
                            tmp_ind = modelGroup.LineModelRegions.ElementAt(i).ImageIndex;
                        }
                    }
                    wireRegionsModelGroup.Add(modelGroup);
                    modelGroup.Index = wireRegionsModelGroup.Count;

                    modelGroup.SelectModelNumber = (int)modelGroupNode.FirstAttribute.NextAttribute;
                }
                (wireAddAutoRegion as WireAddAutoRegion).ModelGroupsCount = wireRegionsModelGroup.Count;

                //恢复自动生成金线起始区域金线ModelType  add by wj
                for (int i = 0; i < wireParameter.WireRegModelType.Length; i++)
                {
                    startBallAutoUserRegion[i].ModelGroups       = wireRegionsModelGroup;
                    startBallAutoUserRegion[i].CurrentModelGroup = wireRegionsModelGroup.ElementAt(wireParameter.WireRegModelType[i] - 1);
                }

                //1109 赋值初始排序
                if (wireParameter.WireAutoIndex_sorted_start.Length == startBallAutoUserRegion.Count)
                {
                    for (int i = 0; i < wireParameter.WireAutoIndex_sorted_start.Length; i++)
                    {
                        startBallAutoUserRegion[i].Index_ini = wireParameter.WireAutoIndex_sorted_start[i];
                    }
                }
                if (wireParameter.WireAutoIndex_sorted_stop.Length == stopBallAutoUserRegion.Count)
                {
                    for (int i = 0; i < wireParameter.WireAutoIndex_sorted_stop.Length; i++)
                    {
                        stopBallAutoUserRegion[i].Index_ini = wireParameter.WireAutoIndex_sorted_stop[i];
                    }
                }

                //1029 default model setting
                if (wireRegionsModelGroup.Count > 0)
                {
                    (wireAddAutoRegion as WireAddAutoRegion).CurrentModelGroup = (wireAddAutoRegion as WireAddAutoRegion).ModelGroups.ElementAt(0);
                }

                if ((wireAddAutoRegion as WireAddAutoRegion).StartBallAutoUserRegion.Count > 0)
                {
                    (wireAddAutoRegion as WireAddAutoRegion).WireParameter.IsStartPickUp = true;
                }
                if ((wireAddAutoRegion as WireAddAutoRegion).StopBallAutoUserRegion.Count > 0)
                {
                    (wireAddAutoRegion as WireAddAutoRegion).WireParameter.IsStopPickUp = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
예제 #5
0
        //加载
        public void LoadXML(string xmlPath)
        {
            /*
             * await Task.Run(() =>
             * {
             *  while (htWindow.HTWindow.HalconWindow.Handle == (IntPtr)0xffffffffffffffff)
             *  {
             *      Thread.Sleep(500);
             *  }
             * });
             */
            try
            {
                XElement root = XElement.Load(xmlPath);
                XElement bondMeasureParameterNode      = root.Element("BondMeasureParameter");
                XElement bond1AutoRegionsParameterNode = root.Element("Bond1AutoRegionsParameter");//自动
                if (bondMeasureParameterNode == null)
                {
                    return;
                }
                XMLHelper.ReadParameters(bondMeasureParameterNode, bondMeasureParameter);
                XMLHelper.ReadParameters(bond1AutoRegionsParameterNode, bond1AutoRegionsParameter);//自动
                (createBondMeasureModel as CreateBondMeasureModel).LoadReferenceData();
                XMLHelper.ReadRegion(root, bondModelUserRegions, "BondModelUserRegions", 0, 0, true);

                //XMLHelper.ReadRegion(root, BondVerifyUserRegions, "BondVerifyUserRegions", bondMeasureParameter.DieImageRowOffset, bondMeasureParameter.DieImageColumnOffset);

                XMLHelper.ReadRegion(root, PadUserRegions, "PadUserRegions", bondMeasureParameter.DieImageRowOffset, bondMeasureParameter.DieImageColumnOffset, false, false, false, false, true);
                //
                XElement BondVerifyModelParaNode = root.Element("BondVerifyModelPara");
                XMLHelper.ReadParameters(BondVerifyModelParaNode, bondVerifyModelPara);
                // 兼容老产品打开参数不保留 2021-0105 by wj
                if (PadUserRegions.Count() != 0)
                {
                    //add by wj 2021-01-05
                    string regionPathName;
                    string regionName = "Pad_Regions";
                    regionPathName = $"\\{regionName}.reg";

                    HOperatorSet.ReadRegion(out HObject freeRegion, $"{ModelsBondDirectory}\\{ regionPathName}");

                    //更新PadUserRegions
                    for (int i = 0; i < PadUserRegions.Count; i++)
                    {
                        //检测区域内通道值设置
                        if (PadUserRegions.ElementAt(i).ChannelNames.Count() == 0)
                        {
                            PadUserRegions.ElementAt(i).ChannelNames = bondMeasureParameter.ChannelNames;
                        }
                        if (PadUserRegions[i].RegionType == RegionType.Region)
                        {
                            HOperatorSet.SelectObj(freeRegion, out HObject padFreeRegion, i + 1);
                            PadUserRegions[i].CalculateRegion = padFreeRegion;
                            HOperatorSet.MoveRegion(padFreeRegion, out HObject _padFreeRegion, -bondMeasureParameter.DieImageRowOffset, -bondMeasureParameter.DieImageColumnOffset);
                            PadUserRegions[i].DisplayRegion = _padFreeRegion;
                        }
                    }
                }

                XMLHelper.ReadRegion(root, Bond2UserRegion, "Bond2UserRegion", 0, 0, true);
                XMLHelper.ReadRegion(root, Bond2UserRegionDiff, "Bond2UserRegionDiff", 0, 0, true);
                XMLHelper.ReadRegion(root, RotateLineUserRegion, "RotateLineUserRegion", 0, 0, true);

                XElement BondMeasureVerifyParameterNode = root.Element("BondMeasureVerifyParameter");
                XMLHelper.ReadParameters(BondMeasureVerifyParameterNode, bondMeasureVerifyParameter);
                (createBondMeasureModel as CreateBondMeasureModel).Initial();

                bondWireRegionGroups.Clear();
                XElement bondWireGroupNode = root.Element("BondWireGroups");
                if (bondWireGroupNode == null)
                {
                    return;
                }
                //自动生成焊点区域部分
                foreach (var groupNode in bondWireGroupNode.Elements("BondWireGroup"))
                {
                    BondWireRegionGroup group = new BondWireRegionGroup();
                    group.Bond2UserRegion = UserRegion.FromXElement(groupNode.Element("Bond2Region"), false);
                    group.WireUserRegion  = UserRegion.FromXElement(groupNode.Element("WireRegion"), false);                                                                                                                                                                                         //XMLHelper.ReadParameters(groupNode, group.Parameter);
                    bondWireRegionGroups.Add(group);
                    group.Index          = bondWireRegionGroups.Count;
                    group.Bond2_BallNums = int.Parse(groupNode.Attribute("Bond2Numbers")?.Value);
                }
                (createAutoBondMeasureModel as CreateAutoBondMeasureModel).GroupsCount = bondWireRegionGroups.Count;
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return;
            }
        }