예제 #1
0
 //判断一个特征是否为一个盲孔
 public static bool IsCounterboreHole(MyNewDefineFeature Feature1)
 {
     //单独的盲孔,边数为3的盲孔是存在阶梯孔的情况
     if (Feature1.FaceNumber == 2 && (Feature1.EdgeNumber >= 2) && Feature1.VertexNumber == 0)
     {
         //先计算两面之间的夹角
         double Angle;
         MyFace.AskAngleOfFace(Feature1.MyNewFeature[0].FaceTag, Feature1.MyNewFeature[1].FaceTag, out Angle);
         if (Angle != 90.0)
         {
             return(false);
         }
         if (Feature1.MyNewFeature[0].NodeFaceType == MyNewFaceType.Cylindrical && Feature1.MyNewFeature[1].NodeFaceType == MyNewFaceType.Planar)
         {
             //判断盲孔:一个面为凹圆柱面,一个面为平面,且两面的交线为凹边
             Tag[] SharedEdges;
             Program.theUfmodel.AskSharedEdges(Feature1.MyNewFeature[0].FaceTag, Feature1.MyNewFeature[1].FaceTag, out SharedEdges);
             if (MyEdges.IsConcaveEdge(SharedEdges[0]) && (MyFace.IsConcaveFace(Feature1.MyNewFeature[0].FaceTag) == 2))
             {
                 return(true);
             }
         }
         else if (Feature1.MyNewFeature[1].NodeFaceType == MyNewFaceType.Cylindrical && Feature1.MyNewFeature[0].NodeFaceType == MyNewFaceType.Planar)
         {
             //判断盲孔:一个面为凹圆柱面,一个面为平面,且两面的交线为凹边
             Tag[] SharedEdges;
             Program.theUfmodel.AskSharedEdges(Feature1.MyNewFeature[0].FaceTag, Feature1.MyNewFeature[1].FaceTag, out SharedEdges);
             if (MyEdges.IsConcaveEdge(SharedEdges[0]) && (MyFace.IsConcaveFace(Feature1.MyNewFeature[1].FaceTag) == 2))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
예제 #2
0
 //根据是否含有凹边来判断是否为凹面
 public bool IsConCavityFacebyEdge()
 {
     Tag[] edgeList;
     Program.theUfmodel.AskFaceEdges(FaceTag, out edgeList);
     for (int i = 0; i < edgeList.Length; i++)
     {
         if (MyEdges.IsConcaveEdge(edgeList[i]))
         {
             return(true);
         }
     }
     return(false);
 }
예제 #3
0
        //得到面的内环边的List<Tag>
        public List <Tag> GetFaceInnerListEdges()
        {
            List <Tag> InnerListEdge = new List <Tag>();

            Tag[] edgeList;
            Program.theUfmodel.AskFaceEdges(FaceTag, out edgeList);

            for (int i = 0; i < edgeList.Length; i++)
            {
                if (MyEdges.IsConcaveEdge(edgeList[i]))
                {
                    InnerListEdge.Add(edgeList[i]);
                }
            }
            return(InnerListEdge);
        }
예제 #4
0
파일: Dimension.cs 프로젝트: Superherme/UG-
        //标注孔的尺寸1、盲孔
        public static void HoleDime(Tag edge_tag)
        {
            int edge_type;

            ufmodel.AskEdgeType(edge_tag, out edge_type);

            Part workPart = theSession.Parts.Work;

            NXOpen.Session.UndoMarkId markId2;
            markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Create Dimension");

            NXOpen.Annotations.DimensionData dimensionData1;
            dimensionData1 = workPart.Annotations.NewDimensionData();

            NXOpen.Annotations.Associativity associativity1;
            associativity1 = workPart.Annotations.NewAssociativity();

            Edge edge1 = MyEdges.GetEdgeOfTag(edge_tag);

            associativity1.FirstObject = edge1;

            associativity1.SecondObject = null;
            associativity1.ObjectView   = workPart.ModelingViews.WorkView;

            double[] point1 = { 0.0, 0.0, 0.0 }, point2 = { 0.0, 0.0, 0.0 };
            int      VertexNum;

            ufmodel.AskEdgeVerts(edge_tag, point1, point2, out VertexNum);     //圆弧上只有一个端点

            Point3d pickPoint1 = new Point3d(point1[0], point1[1], point1[2]); //圆弧上一点

            associativity1.PickPoint = pickPoint1;

            NXOpen.Annotations.Associativity[] associativity2 = new NXOpen.Annotations.Associativity[1];
            associativity2[0] = associativity1;
            dimensionData1.SetAssociativity(1, associativity2);
            associativity1.Dispose();//释放对象内存

            NXOpen.Annotations.PmiData pmiData1;
            pmiData1 = workPart.Annotations.NewPmiData();

            Xform xform2;

            xform2 = dimensionData1.GetInferredPlane(NXOpen.Annotations.PmiDefaultPlane.ModelView, NXOpen.Annotations.DimensionType.Diameter);

            Point3d origin1 = new Point3d(0.0, 0, 0.0);

            NXOpen.Annotations.PmiDiameterDimension pmiDiameterDimension1;
            //尺寸数据,PMI数据,标注平面,标注原点
            //try
            //{
            // 输入无效对象   pmiDiameterDimension1 = workPart.Dimensions.CreatePmiDiameterDimension(dimensionData1, pmiData1, xform2, origin1);
            //}
            //catch (System.Exception ex)
            //{

            //}
            pmiDiameterDimension1 = workPart.Dimensions.CreatePmiDiameterDimension(dimensionData1, pmiData1, xform2, origin1);

            //盲孔的标注位置定义圆心
            //NXOpen.UF.UFCurve theCure = theUfSession.Curve;
            //UFCurve.Arc TheArc;
            //theCure.AskArcData(edge_tag,out TheArc);

            //Point3d origin2 = new Point3d(TheArc.arc_center[0], TheArc.arc_center[1], TheArc.arc_center[2]);
            //pmiDiameterDimension1.AnnotationOrigin = origin2;//设置标注原点的位置

            pmiDiameterDimension1.IsOriginCentered = true;

            int nErrs1;

            nErrs1 = theSession.UpdateManager.DoUpdate(markId2);
        }
예제 #5
0
파일: MyFeature.cs 프로젝트: Superherme/UG-
        public static void AskTypeOfFeature(List <List <Tag> > Face_of_Feature, out SelfDefFeatureType[] Types)
        {
            int               FaceNum, EdgeNum, VertexNum;
            HashSet <Tag>     Edge_Feature;
            HashSet <Point3d> Vertex_Feature;

            Types = new SelfDefFeatureType[Face_of_Feature.Count];
            int i = 0;

            foreach (List <Tag> Feature in Face_of_Feature)//List中存储的面
            {
                FaceNum = Feature.Count;
                MyEdges.GetEdgeOfFeature(Feature, out Edge_Feature);
                EdgeNum = Edge_Feature.Count;
                MyVertex.GetVertexOfFeature(Feature, out Vertex_Feature);
                VertexNum = Vertex_Feature.Count;

                //得到燕尾槽的角度图
                AngleGraph Anglegraph = new AngleGraph(Feature);
                //盲孔
                if (FaceNum == 2)//EdegNum=3时为阶梯孔
                {
                    int type1, type2;
                    ufmodel.AskFaceType(Feature[0], out type1);
                    ufmodel.AskFaceType(Feature[1], out type2);
                    if (type1 == 22 && type2 == 16)//16为柱面,22为平面
                    {
                        //判断盲孔:一个面为凹圆柱面,一个面为平面,且两面的交线为凹边
                        Tag [] SharedEdges;
                        ufmodel.AskSharedEdges(Feature[0], Feature[1], out SharedEdges);
                        if (MyEdges.IsConcaveEdge(SharedEdges[0]) && (MyFace.IsConcaveFace(Feature[1]) == 2))
                        {
                            Types[i] = SelfDefFeatureType.BlindHole;
                            //得到盲孔的标注边
                            //Tag Dimeedge = MyEdges.GetDimeEdgeOfHole(Feature[1], Feature[0]);
                            //Dimension.HoleDime(Dimeedge);
                            ++i;
                        }
                    }
                    else if (type1 == 16 && type2 == 22)
                    {
                        //判断盲孔:一个面为凹圆柱面,一个面为平面,且两面的交线为凹边
                        Tag[] SharedEdges;
                        ufmodel.AskSharedEdges(Feature[0], Feature[1], out SharedEdges);
                        if (MyEdges.IsConcaveEdge(SharedEdges[0]) && (MyFace.IsConcaveFace(Feature[0]) == 2))
                        {
                            Types[i] = SelfDefFeatureType.BlindHole;
                            //得到盲孔的标注边
                            //Tag Dimeedge = MyEdges.GetDimeEdgeOfHole(Feature[1], Feature[0]);
                            //Dimension.HoleDime(Dimeedge);
                            ++i;
                        }
                    }
                    else if (type1 == 22 && type2 == 22)
                    {
                        if (Anglegraph.adjmatrix[0, 1] == 90)
                        {
                            Types[i] = SelfDefFeatureType.RECT_STEP;
                            ++i;
                        }
                    }
                }
                else if (FaceNum == 1)
                {
                    int type1;
                    ufmodel.AskFaceType(Feature[0], out type1);
                    if (type1 == 16)
                    {
                        //应该要添加一个判断是否为孔的圆柱面
                        //double[] normal1=MyFace.AskFaceofNormal(Feature[0]);
                        //if (normal1[0] < 0 || normal1[1] < 0 || normal1[2] < 0)//判断圆柱面的法向量是否小于0,如果小于0即为孔的圆柱面
                        //{
                        if (EdgeNum == 4)
                        {
                            Types[i] = SelfDefFeatureType.SEMI_CIRCLE_SOLT;
                            ++i;
                        }
                        else
                        {
                            //Tag[] edge_list;
                            //ufmodel.AskFaceEdges(Feature[0], out edge_list);
                            //Dimension.HoleDime(edge_list[0]);
                            Types[i] = SelfDefFeatureType.ThroughHole;
                            ++i;
                        }
                        //}
                    }
                }
                else if (FaceNum == 5)//型腔
                {
                    if (EdgeNum == 12)
                    {
                        if (VertexNum == 12)
                        {
                            if (MyFace.AllVerticalplane(Anglegraph))//如果相互垂直,则判定为矩形腔
                            {
                                Types[i] = SelfDefFeatureType.ClosePocket;
                                ++i;

                                Tag BasicFace;
                                MyFace.AskBasicFace(Feature, out BasicFace);
                                for (int j = 0; j < FaceNum; ++j)
                                {
                                    //标注矩形腔的长度和宽度
                                    for (int k = j + 1; k < FaceNum; ++k)
                                    {
                                        if (MyFace.ISFaceParallel(Feature[j], Feature[k]))
                                        {
                                            //Dimension.ParallelFaceDime(Feature[j], Feature[k], BasicFace);
                                        }
                                    }
                                }
                                //根据基面来标注矩形槽的深度
                                Tag OutFace;
                                MyFace.AskFaceOutFeature(Feature, out OutFace);
                                Dimension.ParallelFaceDime(OutFace, BasicFace, Tag.Null);
                            }
                        }
                        else if (VertexNum == 8)
                        {
                            bool IsRectSlot = true;
                            for (int index1 = 0; index1 < FaceNum; ++index1)
                            {
                                for (int index2 = index1 + 1; index2 < FaceNum; ++index2)
                                {
                                    double tmp = Anglegraph.adjmatrix[index1, index2];
                                    if (tmp != -1) //相邻,其实还要判断夹角是否相等
                                    {
                                        if (tmp != 90.0 && tmp != 180.0)
                                        {
                                            IsRectSlot = false;
                                        }
                                    }
                                }
                            }
                            if (IsRectSlot)
                            {
                                Types[i] = SelfDefFeatureType.RECT_SOLT;
                                i++;
                            }
                        }
                    }
                }
                else if (FaceNum == 3)
                {
                    if (EdgeNum == 10)
                    {
                        if (VertexNum == 8)
                        {
                            bool IsDoveTatilSolt = true;
                            bool IsRectSolt      = true;
                            for (int index1 = 0; index1 < FaceNum; index1++)
                            {
                                for (int index2 = index1 + 1; index2 < FaceNum; ++index2)
                                {
                                    double tmp = Anglegraph.adjmatrix[index1, index2];
                                    if (tmp != -1)//相邻,其实还要判断夹角是否相等
                                    {
                                        if (tmp >= 90.0 || tmp == 0.0)
                                        {
                                            IsDoveTatilSolt = false;
                                        }
                                        if (tmp != 90.0)
                                        {
                                            IsRectSolt = false;
                                        }
                                    }
                                }
                            }
                            if (IsDoveTatilSolt)
                            {
                                Types[i] = SelfDefFeatureType.DOVE_TAIL_SOLT;
                                ++i;
                            }
                            if (IsRectSolt)//通的矩形槽
                            {
                                Types[i] = SelfDefFeatureType.RECT_THROUGH_SOLT;
                                ++i;
                            }
                        }
                    }
                    else if (EdgeNum == 4)
                    {
                        if (VertexNum == 0)
                        {
                            bool IsCutterSlot = true;
                            for (int index1 = 0; index1 < FaceNum; ++index1)
                            {
                                for (int index2 = index1 + 1; index2 < FaceNum; ++index2)
                                {
                                    double tmp = Anglegraph.adjmatrix[index1, index2];
                                    if (tmp != -1)//相邻,其实还要判断夹角是否相等
                                    {
                                        if (tmp != 90.0 && tmp != 180.0)
                                        {
                                            IsCutterSlot = false;
                                        }
                                    }
                                }
                            }
                            if (IsCutterSlot)
                            {
                                Types[i] = SelfDefFeatureType.Cutter_Slot;//退刀槽
                                i++;
                            }
                        }
                    }
                }
            }
        }
예제 #6
0
        //获取子特征的相关面
        public static void GetFaceArray(out List <List <Tag> > Face_of_Feature)
        {
            //获取零件模型中的凹边:
            Tag[] Edges;
            MyEdges.GetConcaveEdge(out Edges);

            Tag [] face_tag;

            //List<List<Tag>> temp_Face_list;
            Face_of_Feature = new List <List <Tag> >();

            bool IsExit;

            foreach (Tag edge_tag in Edges)
            {
                IsExit = false;
                ufmodel.AskEdgeFaces(edge_tag, out face_tag);

                foreach (List <Tag> list_tag in Face_of_Feature)
                {
                    if (list_tag.Contains(face_tag[0]) && (!list_tag.Contains(face_tag[1])))
                    {
                        list_tag.Add(face_tag[1]);
                        IsExit = true;
                    }
                    else if (list_tag.Contains(face_tag[1]) && (!list_tag.Contains(face_tag[0])))
                    {
                        list_tag.Add(face_tag[0]);
                        IsExit = true;
                    }
                }
                if (!IsExit)
                {
                    List <Tag> TempList1 = new List <Tag>();
                    TempList1.Add(face_tag[0]);
                    TempList1.Add(face_tag[1]);

                    Face_of_Feature.Add(TempList1);
                }
            }

            List <List <Tag> > Face_of_Temp;

            Face_of_Temp = new List <List <Tag> >();

            Face_of_Temp = Face_of_Feature;
            //判断Face_of_Feature中是否有重合的情况,如果有,就合并该List
            for (int i = 0; i < Face_of_Temp.Count; ++i)
            {
                for (int j = 0; j < Face_of_Feature.Count; ++j)
                {
                    if (Face_of_Temp[i] == Face_of_Feature[j])
                    {
                        continue;
                    }
                    if (IsContainsAll(Face_of_Temp[i], Face_of_Feature[j]))//如果有包含关系,删除List
                    {
                        Face_of_Feature.Remove(Face_of_Feature[j]);
                        Face_of_Temp = Face_of_Feature;
                        --j;
                    }
                }
            }

            Face[] AllFace = GetFaceOfBody();
            Tag[]  Cylindredge;
            bool   IsThroughHole;

            foreach (Face SinFace in AllFace)
            {
                IsThroughHole = true;
                if (SinFace.SolidFaceType == Face.FaceType.Cylindrical)
                {
                    ufmodel.AskFaceEdges(SinFace.Tag, out Cylindredge);//圆柱面的边
                    foreach (Tag CyEdge1 in Cylindredge)
                    {
                        if (MyEdges.IsConcaveEdge(CyEdge1))
                        {
                            IsThroughHole = false;
                            break;
                        }
                    }

                    if (MyFace.IsConcaveFace(SinFace.Tag) == 2)//如果是内圆柱面;
                    {
                        if (IsThroughHole && Cylindredge.Length == 2)
                        {
                            List <Tag> TempList2 = new List <Tag>();
                            TempList2.Add(SinFace.Tag);
                            Face_of_Feature.Add(TempList2);
                            //Dimension.HoleDime(Cylindredge[0]);
                            //theUfobj.SetColor(SinFace.Tag, 106);//红色186
                        }
                        else if (Cylindredge.Length == 4)
                        {
                            List <Tag> TempList2 = new List <Tag>();
                            TempList2.Add(SinFace.Tag);
                            Face_of_Feature.Add(TempList2);
                        }
                    }
                }
            }
        }