コード例 #1
0
ファイル: MyNewDefineFeature.cs プロジェクト: Superherme/UG-
        //判断特征类型
        public static NewSelfDefFeatureType GetFeatureType(MyNewDefineFeature Feature1)
        {
            NewSelfDefFeatureType FeatureType = NewSelfDefFeatureType.OTHER_TYPE;

            HashSet <Tag>     Edge_Feature;
            HashSet <Point3d> Vertex_Feature;

            MyNewEdge.GetEdgeOfFeature(Feature1, out Edge_Feature);
            MyVertex.GetVertexOfFeature(Feature1, out Vertex_Feature);
            Feature1.EdgeNumber   = Edge_Feature.Count;                  //特征中边的数目
            Feature1.VertexNumber = Vertex_Feature.Count;                //特征中顶点的数目;

            Feature1.FeatureFaceAngleGraphic = new AngleGraph(Feature1); //构建特征中面之间的夹角图
            //先识别出每个孤立特征的特征类型,然后在进行组合
            if (IsThroughHole(Feature1))                                 //通孔
            {
                FeatureType = NewSelfDefFeatureType.ThroughHole;
                for (int i = 0; i < Feature1.FeatureAdjacentFaceList.Count; i++)
                {
                    if (Feature1.FeatureAdjacentFaceList[i].FaceType == MyNewFaceType.Cylindrical)
                    {
                        FeatureType = NewSelfDefFeatureType.HORIZONTAL_HOLE;//横孔
                    }
                }
            }
            else if (IsRECT_THROUGH_SOLT(Feature1))//矩形通腔
            {
                FeatureType = NewSelfDefFeatureType.RECT_THROUGH_SOLT;
            }
            else if (IsCounterboreHole(Feature1))//盲孔
            {
                FeatureType = NewSelfDefFeatureType.BlindHole;
            }
            else if (IsConicalHole(Feature1))//锥孔
            {
                FeatureType = NewSelfDefFeatureType.Conical_HOLE;
            }
            else if (IsIsolatedSmoothSurface(Feature1))
            {
                FeatureType = NewSelfDefFeatureType.ISOLATED_SMOOTH_SURFACE; //孤立的光顺面;
            }
            else if (IsRectCavity(Feature1))                                 //判断是否是矩形腔
            {
                FeatureType = NewSelfDefFeatureType.RECT_CAVITY;             //矩形腔
            }
            else if (IsOutterCylinderSurface(Feature1))
            {
                FeatureType = NewSelfDefFeatureType.Outter_Cylinder_Surface;//凸台特征的外圆柱面
            }
            return(FeatureType);
        }
コード例 #2
0
ファイル: Dimension.cs プロジェクト: Superherme/UG-
        //平行平面的标注,1、型腔的标注
        public static void ParallelFaceDime(Tag Face1, Tag Face2, Tag BasicFace)
        {
            Part workPart = theSession.Parts.Work;

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

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

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

            Face face1 = MyFace.GetFaceByTag(Face1);

            associativity1.FirstObject = face1;

            NXObject nullNXObject = null;

            associativity1.SecondObject = nullNXObject;

            associativity1.ObjectView = workPart.ModelingViews.WorkView;

            //得到一个面上的一点
            double[] DefPoint1 = { 0.0, 0.0, 0.0 };
            MyVertex.GetVertexOfFace(Face1, ref DefPoint1);
            Point3d pickPoint1 = new Point3d(DefPoint1[0], DefPoint1[1], DefPoint1[2]);//寻找面face1上的点

            associativity1.PickPoint = pickPoint1;

            NXOpen.Annotations.Associativity[] associativity2 = new NXOpen.Annotations.Associativity[1];
            associativity2[0] = associativity1;
            dimensionData1.SetAssociativity(1, associativity2);
            associativity1.Dispose();

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

            Face face2 = MyFace.GetFaceByTag(Face2);

            associativity3.FirstObject  = face2;
            associativity3.SecondObject = nullNXObject;
            //得到一个面上的一点
            double[] DefPoint2 = { 0.0, 0.0, 0.0 };
            MyVertex.GetVertexOfFace(Face1, ref DefPoint2);

            Point3d pickPoint2 = new Point3d(DefPoint2[0], DefPoint2[1], DefPoint2[2]);//寻找face2上的点

            associativity3.PickPoint = pickPoint2;

            NXOpen.Annotations.Associativity[] associativity4 = new NXOpen.Annotations.Associativity[1];
            associativity4[0] = associativity3;
            dimensionData1.SetAssociativity(2, associativity4);

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

            Xform xform2;

            if (BasicFace == Tag.Null)
            {
                xform2 = dimensionData1.GetInferredPlane(PmiDefaultPlane.ModelView, NXOpen.Annotations.DimensionType.Perpendicular);
            }
            else
            {
                xform2 = dimensionData1.GetInferredPlane(AutoSelectPMIPlane(Face1, BasicFace), NXOpen.Annotations.DimensionType.Perpendicular);
            }

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

            NXOpen.Annotations.PmiPerpendicularDimension pmiPerpendicularDimension1;
            pmiPerpendicularDimension1 = workPart.Dimensions.CreatePmiPerpendicularDimension(dimensionData1, pmiData1, xform2, origin1);

            pmiPerpendicularDimension1.IsOriginCentered = true;

            int nErrs3;

            nErrs3 = theSession.UpdateManager.DoUpdate(markId3);
        }
コード例 #3
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++;
                            }
                        }
                    }
                }
            }
        }