コード例 #1
0
        public static void ClassifyFace(Face2 face, ref List <MyPlane> listOfMyPlane, ref List <MySphere> listOfMySphere,
                                        ref List <MyCone> listOfMyCone, ref List <MyCylinder> listOfMyCylinder, ref List <MyTorus> listOfMyTorus)
        {
            var faceSurface = (Surface)face.GetSurface();

            if (faceSurface.IsPlane())
            {
                var newMyPlane = CreateMyPlaneFromFace(face);
                listOfMyPlane.Add(newMyPlane);
            }

            if (faceSurface.IsSphere())
            {
                var newMySphere = CreateMySphereFromFace(faceSurface);
                listOfMySphere.Add(newMySphere);
            }

            if (faceSurface.IsCone())
            {
                var newMyCone = CreateMyConeFromFace(faceSurface);
                listOfMyCone.Add(newMyCone);
            }

            if (faceSurface.IsCylinder())
            {
                var newMyCylinder = CreateMyCylinderFromFace(faceSurface, face);
                listOfMyCylinder.Add(newMyCylinder);
            }

            if (faceSurface.IsTorus())
            {
                var newMyTorus = CreateMyTorusFromFace(faceSurface);
                listOfMyTorus.Add(newMyTorus);
            }
        }
コード例 #2
0
        /// <summary>
        /// The my get normal for plane face.
        /// </summary>
        /// <param name="firstFace">
        /// The first face.
        /// </param>
        /// <param name="firstPoint">
        /// The first point.
        /// </param>
        /// <returns>
        /// The <see cref="double[]"/>.
        /// </returns>
        public static double[] MyGetNormalForPlaneFace(Face2 firstFace, out double[] firstPoint)
        {
            var firstSurface = (Surface)firstFace.GetSurface();
            var firstNormal  = new double[3];

            firstPoint = new double[3];

            Array firstValuesPlane = null;

            if (firstSurface.IsPlane())
            {
                firstValuesPlane = firstSurface.PlaneParams;
                Array.Copy(firstValuesPlane, 0, firstNormal, 0, 3);
                Array.Copy(firstValuesPlane, 3, firstPoint, 0, 3);
            }


            // Pongo il verso della normale alla superficie concorde con quello della faccia.
            if (!firstFace.FaceInSurfaceSense())
            {
                firstNormal.SetValue((double)firstValuesPlane.GetValue(0), 0);
                firstNormal.SetValue((double)firstValuesPlane.GetValue(1), 1);
                firstNormal.SetValue((double)firstValuesPlane.GetValue(2), 2);
            }
            else
            {
                firstNormal.SetValue(-(double)firstValuesPlane.GetValue(0), 0);
                firstNormal.SetValue(-(double)firstValuesPlane.GetValue(1), 1);
                firstNormal.SetValue(-(double)firstValuesPlane.GetValue(2), 2);
            }


            return(firstNormal);
        }
コード例 #3
0
ファイル: SwAddin.cs プロジェクト: iamcs/SolidWorks-add-in
        private static void Compare(Face2 faceTarget, Face2 faceCompare, IModelDoc2 modDoc)
        {
            //比较面
            Measure      measure;
            SelectionMgr selMgr;
            SelectData   selData;

            DispatchWrapper[] arrObjIn = new DispatchWrapper[2];
            int ret;

            measure     = modDoc.Extension.CreateMeasure();
            selMgr      = modDoc.SelectionManager;
            selData     = (SelectData)selMgr.CreateSelectData();
            arrObjIn[0] = new DispatchWrapper(faceTarget);
            arrObjIn[1] = new DispatchWrapper(faceCompare);
            ret         = selMgr.SuspendSelectionList();

            selMgr.AddSelectionListObjects((arrObjIn), selData);
            //如果两面贴合,且不为同一面
            if (measure.IsParallel & !faceTarget.IsSame(faceCompare) & measure.Distance <= 0.01)
            {
                //查找所有圆形
                //孔是否贯通
                //若否且孔到比较面的距离小于0.01则认为是漏打孔
                //
                //查找所有圆柱面
                //查找圆柱面的接合面
                //接合面是否有贴合面
                //贴合面是否至少存在一个对应孔
            }
        }
コード例 #4
0
        public void draw(SpriteBatch sprite_batch)
        {
            if (visible)
            {
                Face1.draw(sprite_batch, -face_draw_vector());
                Face2.draw(sprite_batch, -face_draw_vector());

                sprite_batch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);
                // Window background
                Window1.draw(sprite_batch, -draw_vector());
                Window2.draw(sprite_batch, -draw_vector());
                // Text underline
                draw_bar(sprite_batch);

                draw_items(sprite_batch);
                // Cursor
                if (Grey_Cursor.visible)
                {
                    Grey_Cursor.draw(sprite_batch, -(loc + draw_vector()));
                }
                if (active)
                {
                    UICursor.draw(sprite_batch, -(loc + draw_vector()));
                }

                sprite_batch.End();
                if (is_help_active)
                {
                    Help_Window.draw(sprite_batch);
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// 创建面对象
        /// </summary>
        /// <param name="face"></param>
        /// <returns></returns>
        private static SWFace CreateSWFace(Face2 face)
        {
            if (face == null)
            {
                return(null);
            }

            //复制Face信息
            SWFace swFace = new SWFace();

            //ID
            swFace.ID = face.GetFaceId();
            //包围盒
            swFace.BoundingBox = CreateSWBoundingBox(face.GetBox());

            //三角面片
            //int tessTriCount = face.GetTessTriangleCount();
            swFace.TessTriangles = face.GetTessTriangles(false);
            swFace.TessNormals   = face.GetTessNorms();

            //OutPutTessTriangles(tessTriCount, arrTriangles);

            /*
             * if (arrTriangles != null) {
             *  for (int i = 0; i < tessTriCount; i += 9) {
             *      swFace.TessTriangles.Add(CreateSWTriangle(arrTriangles, i));
             *  }
             * }
             */

            //几何信息
            swFace.Surface = CreateSWSurface(face.GetSurface());

            return(swFace);
        }
コード例 #6
0
ファイル: Test5.cs プロジェクト: Titifonky/SwExtension
        public void Decaler(Face2 face, Double decal, Boolean inverser)
        {
            Loop2 bord = null;

            foreach (Loop2 loop in face.GetLoops())
            {
                if (loop.IsOuter())
                {
                    bord = loop;
                    break;
                }
            }

            var listeFace = new List <Face2>();

            foreach (Edge e in bord.GetEdges())
            {
                listeFace.Add(e.eAutreFace(face));
            }

            MdlBase.eEffacerSelection();

            foreach (var f in listeFace)
            {
                f.eSelectEntite(MdlBase, 1, true);
            }

            var feat = MdlBase.FeatureManager.InsertMoveFace3((int)swMoveFaceType_e.swMoveFaceTypeOffset, inverser, 0, decal, null, null, 0, 0);

            WindowLog.Ecrire("Décalage : " + feat.IsRef());
        }
コード例 #7
0
ファイル: Manifold.cs プロジェクト: AeroYoung/HotRunner
        private List <Line> GetManifoldEdge()
        {
            List <Line> lines = new List <Line>();

            ModelDoc2 swDoc   = (ModelDoc2)swApp.ActiveDoc;
            Feature   feature = swDoc.GetFeatureInPrt("runnerCube0");

            object[] faces  = feature.GetFaces();
            Vector   target = new Vector(0, 0, 1);

            for (int i = 0; i < faces.Count(); i++)
            {
                Face2  face   = (Face2)faces[i];
                Vector normal = new Vector(face.Normal);
                if (normal.isSameDir(target, 0.000005) != 1)
                {
                    continue;
                }
                object[] edges = face.GetEdges();
                double   area  = face.GetArea();
                int      count = face.GetEdgeCount();
                for (int j = 0; j < count; j++)
                {
                    Edge  edge  = (Edge)edges[j];
                    Point start = new Point(edge.GetCurveParams3().StartPoint);
                    Point end   = new Point(edge.GetCurveParams3().EndPoint);
                    Line  line  = new Line(start, end);
                    lines.Add(line);
                }
            }

            return(lines);
        }
コード例 #8
0
                public FaceGeom(Face2 swface)
                {
                    SwFace = swface;

                    Surface = (Surface)SwFace.GetSurface();

                    ListeSwFace.Add(SwFace);

                    switch ((swSurfaceTypes_e)Surface.Identity())
                    {
                    case swSurfaceTypes_e.PLANE_TYPE:
                        Type = eTypeFace.Plan;
                        GetInfoPlan();
                        break;

                    case swSurfaceTypes_e.CYLINDER_TYPE:
                        Type = eTypeFace.Cylindre;
                        GetInfoCylindre();
                        break;

                    case swSurfaceTypes_e.EXTRU_TYPE:
                        Type = eTypeFace.Extrusion;
                        GetInfoExtrusion();
                        break;

                    default:
                        break;
                    }
                }
コード例 #9
0
    private void FindSinglePointFaceCollisionWithOthersFace(Shape2 other, Vector3 P, List <Vector3> collPoints, List <Vector3> collNormals)
    {
        var   smallestAmount = Mathf.Infinity;
        Face2 closestFace    = null;

        var faces = other.Faces;

        for (int j = 0; j < faces.Count; j++)
        {
            float amount;
            if (!faces[j].IsAbovePoint(P, out amount))
            {
                return;
            }

            if (amount < smallestAmount)
            {
                closestFace    = faces[j];
                smallestAmount = amount;
            }
        }

        collPoints.Add(other.transform.TransformPoint(P));
        collNormals.Add(other.transform.TransformDirection(closestFace.Normal));
    }
コード例 #10
0
        public static MyCylinder CreateMyCylinderFromFace(Surface faceSurface, Face2 face)
        {
            //OSSERVAZIONE: CI POTREBBERO ESSERE EDGE CHIUSI CHE NON AVERE CENTRO SULL'ASSE
            //AD ESEMPIO EDGE CHIUSI CHE SI CREANO INTERSECANDO UN CILINDRO CON UNA SFERA
            //"INFILATA" SULLA SUA SUPERFICIE LATERALE.
            //DI QUESTI EDGE CHIUSI NON ME NE PREOCCUPO PERCHE' SONO A CONTATTO CON ALTRE FORME
            //DI CUI SPERO DI AVER CONTROLLATO (NEL CONTROLLO DELLA GEOMETRIA) IL GIUSTO
            //POSIZIONAMENTO.


            double[] myCylinderParameters = faceSurface.CylinderParams;
            double[] myCylinderOrigin     =
            {
                (double)myCylinderParameters.GetValue(0), (double)myCylinderParameters.GetValue(1),
                (double)myCylinderParameters.GetValue(2)
            };
            double[] myCylinderAxis =
            {
                (double)myCylinderParameters.GetValue(3), (double)myCylinderParameters.GetValue(4),
                (double)myCylinderParameters.GetValue(5)
            };
            double myCylinderRadius = (double)myCylinderParameters.GetValue(6);

            var newMyCylinder = new MyCylinder(myCylinderOrigin, myCylinderAxis, myCylinderRadius);

            var faceEdges  = (Array)face.GetEdges();
            var numOfEdges = faceEdges.Length;

            int i = 0;
            var currentListOfBaseCircle  = new List <MyCircle>();
            var currentListOfBaseEllipse = new List <MyEllipse>();

            while (i < numOfEdges)
            {
                Edge  edge      = (Edge)faceEdges.GetValue(i);
                Curve curveEdge = edge.GetCurve();
                if (IsClosedEdge(edge))
                {
                    //is the closed edge a circle?
                    if (curveEdge.IsCircle())
                    {
                        double[] circleParam   = curveEdge.CircleParams;
                        var      newBaseCircle = new MyCircle(circleParam);
                        currentListOfBaseCircle.Add(newBaseCircle);
                    }
                    //is the closed edge an ellipse?
                    if (curveEdge.IsEllipse())
                    {
                        double[] ellipseParam   = curveEdge.GetEllipseParams();
                        var      newBaseEllipse = new MyEllipse(ellipseParam);
                        currentListOfBaseEllipse.Add(newBaseEllipse);
                    }
                }
                i++;
            }
            newMyCylinder.listOfBaseCircle  = currentListOfBaseCircle;
            newMyCylinder.listOfBaseEllipse = currentListOfBaseEllipse;
            return(newMyCylinder);
        }
コード例 #11
0
            private void Run(Face2 dessus, Face2 devant, Component2 contreMarche, Feature esquisse)
            {
                if ((dessus == null) || (devant == null))
                {
                    this.LogMethode(new String[] { "Une reference à un objet a été perdue dessus | devant :", dessus.IsRefToString(), "|", devant.IsRefToString() });
                    return;
                }
                try
                {
                    Edge E_Face = dessus.eListeDesArretesCommunes(devant)[0];

                    List <Edge> ListeArrete = dessus.eListeDesArretesContigues(E_Face);

                    // On assigne les cotes de façon arbitraire pour eviter une assignation suplémentaire
                    Edge E_Gauche = ListeArrete[0];
                    Edge E_Droit  = ListeArrete[1];

                    // Création des segements
                    gSegment S1 = new gSegment(E_Gauche);
                    gSegment Sf = new gSegment(E_Face);

                    // Orientation des segements
                    S1.OrienterDe(Sf);
                    Sf.OrienterVers(S1);

                    gVecteur Normal = new gVecteur((Double[])dessus.Normal);

                    // Verification du sens de rotation et modification des cotes si nécessaire
                    if (Sf.Vecteur.RotationTrigo(S1.Vecteur, Normal))
                    {
                        E_Gauche = ListeArrete[1];
                        E_Droit  = ListeArrete[0];
                    }

                    gSegment F = new gSegment(E_Face);
                    gSegment G = new gSegment(E_Gauche);
                    gSegment D = new gSegment(E_Droit);

                    G.OrienterDe(F);
                    D.OrienterDe(F);
                    F.OrienterDe(G);

                    Double gAg1 = G.Vecteur.Angle(F.Vecteur);
                    Double gAg2 = D.Vecteur.Angle(F.Vecteur.Inverse());

                    Double gLg1 = new gPoint(0, 0, 0).Distance(F.Start);
                    Double gLg2 = new gPoint(0, 0, 0).Distance(F.End);
                    Double gLc1 = G.Lg;
                    Double gLc2 = D.Lg;

                    Configurer(contreMarche, gAg1, gAg2, gLg1, gLg2, gLc1, gLc2, esquisse);
                }
                catch (Exception e)
                {
                    this.LogErreur(new Object[] { e });
                }
            }
コード例 #12
0
        public static MyPlane CreateMyPlaneFromFace(Face2 face)
        {
            //KLdebug.Print("FACCIA PIANA", "buildRepeatedEntity.txt");
            //KLdebug.Print(" ", "buildRepeatedEntity.txt");

            double[] planePoint;
            var      normal     = GeometryFunctions.MyGetNormalForPlaneFace(face, out planePoint);
            MyPlane  newMyPlane = new MyPlane(normal, planePoint);

            return(newMyPlane);
        }
コード例 #13
0
ファイル: SwAddin.cs プロジェクト: iamcs/SolidWorks-add-in
        private static void FaceCompare(Face2 faceTarget, Face2 faceCompare, IModelDoc2 modDoc)
        {
            //遍历每一个面,并将face与每一个面比较
            AssemblyDoc asmDoc;

            Component2[] components;

            faceTarget = faceCompare;
            asmDoc     = (AssemblyDoc)modDoc;
            components = (Component2[])asmDoc.GetComponents(true);
            ComponentsTraverse(components, modDoc, Compare, faceTarget);
        }
コード例 #14
0
            // Recherche de l'arrete de devant sur laquelle est contrainte la platine.
            private Edge ArreteDevant(List <Mate2> listeContraintes, Face2 faceDessus)
            {
                Mate2 Ct = null;

                // On rechercher la contrainte avec un point
                foreach (Mate2 Contrainte in listeContraintes)
                {
                    foreach (MateEntity2 Ent in Contrainte.eListeDesEntitesDeContrainte())
                    {
                        if (Ent.ReferenceType2 == (int)swSelectType_e.swSelEXTSKETCHPOINTS)
                        {
                            Ct = Contrainte;
                            break;
                        }
                    }
                    if (Ct.IsRef())
                    {
                        break;
                    }
                }

                if (Ct.IsNull())
                {
                    return(null);
                }

                Face2 F_Devant = null;

                // On recherche la face associée à cette contrainte
                foreach (MateEntity2 Ent in Ct.eListeDesEntitesDeContrainte())
                {
                    if (Ent.ReferenceType2 == (int)swSelectType_e.swSelFACES)
                    {
                        F_Devant = (Face2)Ent.Reference;
                        break;
                    }
                }

                if (F_Devant.IsNull())
                {
                    return(null);
                }

                List <Edge> ListeArretes = F_Devant.eListeDesArretesCommunes(faceDessus);

                if (ListeArretes.Count > 0)
                {
                    return(ListeArretes[0]);
                }

                return(null);
            }
コード例 #15
0
        public static MyPlane KLCreateMyPlaneFromFace(Face2 face, double[,] transformMatrix)
        {
            //KLdebug.Print("FACCIA PIANA", "buildRepeatedEntity.txt");
            //KLdebug.Print(" ", "buildRepeatedEntity.txt");

            double[] planePoint;
            var      normal  = GeometryFunctions.KLMyGetNormalForPlaneFace(face, out planePoint, transformMatrix);
            var      toPrint = string.Format("Normale calcolata {0}, {1}, {2}", normal[0], normal[1], normal[2]);
            //KLdebug.Print(toPrint, "buildRepeatedEntity.txt");
            MyPlane newMyPlane = new MyPlane(normal, planePoint);

            return(newMyPlane);
        }
コード例 #16
0
            private void Contraindre(Feature plan, Face2 e)
            {
                AssemblyDoc Ass = MdlBase.eAssemblyDoc();

                e.eSelectEntite(MdlBase);
                plan.eSelect(true);

                int longstatus = 0;

                Ass.AddMate5((int)swMateType_e.swMateCOINCIDENT,
                             (int)swMateAlign_e.swMateAlignCLOSEST, false, 0, 0, 0, 0, 0, 0, 0, 0, false, false, 0, out longstatus);

                MdlBase.ClearSelection2(true);
            }
コード例 #17
0
        public static double[] KLMyGetNormalForPlaneFace(Face2 firstFace, out double[] firstPoint, double[,] transformMatrix)
        {
            var firstSurface = (Surface)firstFace.GetSurface();
            var firstNormal  = new double[3];

            firstPoint = new double[3];

            Array firstValuesPlane = null;

            if (firstSurface.IsPlane())
            {
                firstValuesPlane = firstSurface.PlaneParams;
                Array.Copy(firstValuesPlane, 0, firstNormal, 0, 3);
                Array.Copy(firstValuesPlane, 3, firstPoint, 0, 3);
            }

            // Pongo il verso della normale alla superficie concorde con quello della faccia.
            if (!firstFace.FaceInSurfaceSense())
            {
                firstNormal.SetValue((double)firstValuesPlane.GetValue(0), 0);
                firstNormal.SetValue((double)firstValuesPlane.GetValue(1), 1);
                firstNormal.SetValue((double)firstValuesPlane.GetValue(2), 2);
            }
            else
            {
                firstNormal.SetValue(-(double)firstValuesPlane.GetValue(0), 0);
                firstNormal.SetValue(-(double)firstValuesPlane.GetValue(1), 1);
                firstNormal.SetValue(-(double)firstValuesPlane.GetValue(2), 2);
            }

            if (transformMatrix != null)
            {
                double[] firstNormalAffine = { (double)firstNormal.GetValue(0), (double)firstNormal.GetValue(1), (double)firstNormal.GetValue(2), 1 };
                double[] firstPointAffine  = { (double)firstPoint.GetValue(0), (double)firstPoint.GetValue(1), (double)firstPoint.GetValue(2), 1 };

                var newFirstNormal = Matrix.Multiply(transformMatrix, firstNormalAffine);
                var newFirstPoint  = Matrix.Multiply(transformMatrix, firstPointAffine);

                firstNormal.SetValue((double)newFirstNormal.GetValue(0), 0);
                firstNormal.SetValue((double)newFirstNormal.GetValue(1), 1);
                firstNormal.SetValue((double)newFirstNormal.GetValue(2), 2);

                firstPoint.SetValue((double)newFirstPoint.GetValue(0), 0);
                firstPoint.SetValue((double)newFirstPoint.GetValue(1), 1);
                firstPoint.SetValue((double)newFirstPoint.GetValue(2), 2);
            }

            return(firstNormal);
        }
コード例 #18
0
            // Recherche de l'arrete de derrière
            private Edge ArreteArriere(Face2 faceDessus, Edge eBase, Edge eFace)
            {
                List <Edge> Liste = faceDessus.eListeDesArretesContigues(eBase);

                // On supprime l'arrete de face
                Liste.Remove(eFace);

                // Il n'en reste qu'une et normalement c'est la bonne
                if (Liste.Count > 0)
                {
                    return(Liste[0]);
                }

                return(null);
            }
コード例 #19
0
        /// <summary>
        /// 创建SWBody对象
        /// </summary>
        /// <param name="body"></param>
        /// <returns></returns>
        private static SWBody CreateSWBody(Body2 body)
        {
            if (body == null)
            {
                return(null);
            }

            SWBody swBody = new SWBody();

            swBody.Name = body.Name;

            //提取Face
            Face2 face = body.GetFirstFace();

            while (face != null)
            {
                swBody.Faces.Add(CreateSWFace(face));
                face = face.GetNextFace();
            }

            //提取Edge
            object[] edges = body.GetEdges();
            if (edges != null)
            {
                foreach (object objEdge in edges)
                {
                    if (objEdge != null)
                    {
                        swBody.Edges.Add(CreateSWEdge((Edge)objEdge));
                    }
                }
            }

            //提取Vertex
            object[] vertices = body.GetVertices();
            if (vertices != null)
            {
                foreach (object objVertex in vertices)
                {
                    if (objVertex != null)
                    {
                        swBody.Vertices.Add(CreateSWVertex((Vertex)objVertex));
                    }
                }
            }

            return(swBody);
        }
コード例 #20
0
            // Recherche de l'arrete sur laquelle est contrainte la platine.
            private Edge ArretePlatine(List <Mate2> listeContraintes, Feature planContrainte, Face2 f_Dessus)
            {
                Mate2 Contrainte = null;

                foreach (Mate2 Ct in listeContraintes)
                {
                    foreach (MateEntity2 Ent in Ct.eListeDesEntitesDeContrainte())
                    {
                        // Si l'entite est un plan
                        if (Ent.ReferenceType2 == (int)swSelectType_e.swSelDATUMPLANES)
                        {
                            RefPlane P = Ent.Reference;
                            Feature  F = (Feature)P;
                            // On vérifie que le plan a le même nom que le plan contrainte
                            if (planContrainte.Name == F.Name)
                            {
                                Contrainte = Ct;
                                break;
                            }
                        }
                    }

                    if (Contrainte.IsRef())
                    {
                        break;
                    }
                }

                foreach (MateEntity2 Ent in Contrainte.eListeDesEntitesDeContrainte())
                {
                    // On récupère la face associée à la contrainte
                    if (Ent.ReferenceType2 == (int)swSelectType_e.swSelFACES)
                    {
                        Face2 F = Ent.Reference;

                        // Liste des arrêtes communes, normalement, il n'y en a qu'une
                        List <Edge> L = F.eListeDesArretesCommunes(f_Dessus);

                        // On renvoi la première
                        if (L.Count > 0)
                        {
                            return(L[0]);
                        }
                    }
                }

                return(null);
            }
コード例 #21
0
        public void update(bool input)
        {
            Face1.update();
            Face2.update();

            update_ui(input);

            if (Glowing_Line != null)
            {
                Glowing_Line.update();
            }
            if (is_help_active)
            {
                Help_Window.update();
            }
        }
コード例 #22
0
                public Boolean AjouterFaceConnectee(Face2 f)
                {
                    var result = UnionArretes(f.eListeDesArretes());

                    if (result > 0)
                    {
                        ListeFaces.Add(f);
                    }

                    if (result == 2)
                    {
                        Fermer = true;
                    }

                    return(result > 0);
                }
コード例 #23
0
        // Recherche d'une face plane attenante à la face
        private Face2 FacePlane(Face2 face)
        {
            List <Face2> ListeFaceTrou = face.eListeDesFacesContigues();

            foreach (Face2 F in ListeFaceTrou)
            {
                Surface S = F.GetSurface();

                if (S.IsPlane())
                {
                    return(F);
                }
            }

            return(null);
        }
コード例 #24
0
        public static void GetFace(ModelDoc2 Doc)
        {
            ModelDocExtension DocEx    = Doc.Extension;
            SelectionMgr      SwSelMrg = Doc.SelectionManager;

            DocEx.SelectByID2("", "FACE", -100 / 1000.0, 60 / 1000.0, 15 / 1000.0, false, -1, null, 0);
            System.Windows.MessageBox.Show("模拟选中面");

            string         selcount = SwSelMrg.GetSelectedObjectCount2(-1).ToString();
            swSelectType_e seltype  = (swSelectType_e)SwSelMrg.GetSelectedObjectType3(1, -1);

            if (seltype == swSelectType_e.swSelFACES)
            {
                Face2 SwFace = SwSelMrg.GetSelectedObject6(1, -1);
                System.Windows.MessageBox.Show("选中数:" + selcount + "\r\n选中类型:" + seltype.ToString() + "\r\n选中面面积:" + SwFace.GetArea().ToString());
            }
        }
コード例 #25
0
        protected Boolean SelectFace(CtrlSelectionBox SelBox, Component2 Cp, Parametre param)
        {
            if (Cp.IsNull())
            {
                return(false);
            }

            String cFace = param.GetValeur <String>();
            Face2  Face  = Cp.eChercherFace(cFace);

            if (Face.IsRef())
            {
                MdlBase.eSelectMulti(Face, SelBox.Marque, true);
            }

            return(true);
        }
コード例 #26
0
        public static void MeasureFace(ModelDoc2 Doc)
        {
            ModelDocExtension DocEx     = Doc.Extension;
            SelectionMgr      SwSelMrg  = Doc.SelectionManager;
            Measure           SwMeasure = DocEx.CreateMeasure();

            DocEx.SelectByID2("", "FACE", -100 / 1000.0, 60 / 1000.0, 15 / 1000.0, false, -1, null, 0);
            DocEx.SelectByID2("", "FACE", 100 / 1000.0, 60 / 1000.0, 15 / 1000.0, true, -1, null, 0);

            Face2 SwFace1 = SwSelMrg.GetSelectedObject6(1, -1);
            Face2 SwFace2 = SwSelMrg.GetSelectedObject6(2, -1);

            Entity[] ents = new Entity[] { (Entity)SwFace1, (Entity)SwFace2 };

            SwMeasure.Calculate(ents);
            System.Windows.MessageBox.Show("中心距:" + (SwMeasure.CenterDistance * 1000).ToString().Trim() + "mm");
        }
コード例 #27
0
        public Feature[] AddTMPBasePlaneFromSelectFace()
        {
            Feature[] tempFeatures = new Feature[2];
            //连接到Solidworks

            ModelDoc2 swModel = (ModelDoc2)iSwApp.ActiveDoc;

            //设定标注尺寸时 不输入值
            iSwApp.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swInputDimValOnCreate, false);

            // Get the pre-selected planar face
            Face2        swSelFace = default(Face2);
            SelectionMgr swSelMgr  = (SelectionMgr)swModel.SelectionManager;

            //获取选择数据
            SelectData swSelData = default(SelectData);

            swSelData = swSelMgr.CreateSelectData();

            swSelFace = (Face2)swSelMgr.GetSelectedObject6(1, 1);

            //var ps = swSelFace.GetTessTriStrips(false);

            //获取屏幕鼠标选择的那个点
            var mousePoint = (double[])swSelMgr.GetSelectionPoint2(1, 1);

            List <Edge> thisFaceEdgeList = GetSelectFaceEdgeList(swSelFace);

            swModel.ViewZoomtofit2();

            Entity swSelFaceEntity = (Entity)swSelFace;

            string skFirstName = "";

            tempFeatures[0] = DrawnSketchOnFace(swModel, mousePoint, thisFaceEdgeList, swSelFaceEntity, out skFirstName);

            var t = (double[])swSelFace.Normal;

            swModel.ClearSelection2(true);

            swSelFaceEntity.Select4(false, swSelData);

            return(tempFeatures);
        }
コード例 #28
0
        /// <summary>
        /// The my distance of non parallel plane.
        /// </summary>
        /// <param name="firstFace">
        /// The first face.
        /// </param>
        /// <param name="secondFace">
        /// The second face.
        /// </param>
        /// <param name="distanceMax">
        /// The distance max.
        /// </param>
        /// <returns>
        /// The <see cref="double"/>.
        /// </returns>
        public static double MyDistanceOfNonParallelPlane(Face2 firstFace, Face2 secondFace, out double distanceMax)
        {
            // Proietto ogni vertice della prima faccia sulla seconda e calcolo la distanza minima e la massima.
            double distanceMin = 100;

            distanceMax = 0;
            var saveFirstFace       = ((Entity)firstFace).GetSafeEntity();
            var swSafeFirstEntity   = (Entity)saveFirstFace.GetSafeEntity();
            var listVertexFirstFace = BRepFunctions.MyGetVertexFromFace(saveFirstFace);

            double[] firstPoint;
            double[] secondPoint;
            var      firstNormal         = GeometryFunctions.MyGetNormalForPlaneFace(firstFace, out firstPoint);
            var      secondNormal        = GeometryFunctions.MyGetNormalForPlaneFace(secondFace, out secondPoint);
            var      secondPlaneEquation = GeometryFunctions.MyGetPlaneEquation(secondNormal, secondPoint);

            // Calcolo la proiezione dei vertici della prima faccia
            foreach (Vertex vertex in listVertexFirstFace)
            {
                // Dal vertice ottengo il punto e lo proietto, considerando la retta passante per il punto e direzione firstNormal
                double[] point = vertex.GetPoint();

                double[] secondEquationLine;
                var      firstEquationLine = GeometryFunctions.MyLineEquation(firstNormal, point, out secondEquationLine);
                var      pointProjection   = GeometryFunctions.MyPointIntersectionLinePlane(
                    firstEquationLine, secondEquationLine, secondPlaneEquation);

                var distanceTest = MyDistanceTwoPoint(point, pointProjection);

                if (distanceTest > distanceMax)
                {
                    distanceMax = distanceTest;
                }

                if (distanceTest < distanceMin)
                {
                    distanceMin = distanceTest;
                }
            }

            return(distanceMin);
        }
コード例 #29
0
        private static List <Edge> GetSelectFaceEdgeList(Face2 swSelFace)
        {
            Object[] eages = (Object[])swSelFace.GetEdges();

            List <Edge> thisFaceEdgeList = new List <Edge>();

            foreach (var item in eages)
            {
                thisFaceEdgeList.Add((Edge)item);

                var tempE  = (Edge)item;
                var tStart = (Vertex)tempE.GetStartVertex();
                var tEnd   = (Vertex)tempE.GetEndVertex();
                var pstart = (double[])tStart.GetPoint();
                var pend   = (double[])tEnd.GetPoint();
                var s      = pstart[0] + "," + pstart[1] + "--------" + pend[0] + "," + pend[1];
            }

            return(thisFaceEdgeList);
        }
コード例 #30
0
        /// <summary>
        /// The my distance parallel plane.
        /// </summary>
        /// <param name="firstFace">
        /// The first face.
        /// </param>
        /// <param name="secondFace">
        /// The second face.
        /// </param>
        /// <returns>
        /// The <see cref="double"/>.
        /// </returns>
        public static double MyDistanceParallelPlane(Face2 firstFace, Face2 secondFace)
        {
            double distance;

            double[] firstPoint;
            double[] secondPoint;

            var firstNormal  = GeometryFunctions.MyGetNormalForPlaneFace(firstFace, out firstPoint);
            var secondNormal = GeometryFunctions.MyGetNormalForPlaneFace(secondFace, out secondPoint);
            var primoPiano   = GeometryFunctions.MyGetPlaneEquation(firstNormal, firstPoint);

            distance =
                Math.Abs(
                    (double)primoPiano.GetValue(0) * (double)secondPoint.GetValue(0)
                    + (double)primoPiano.GetValue(1) * (double)secondPoint.GetValue(1)
                    + (double)primoPiano.GetValue(2) * (double)secondPoint.GetValue(2) + (double)primoPiano.GetValue(3))
                / Math.Sqrt(Math.Pow((double)firstNormal.GetValue(0), 2) + Math.Pow((double)firstNormal.GetValue(1), 2) + Math.Pow((double)firstNormal.GetValue(2), 2));

            return(distance);
        }
コード例 #31
0
ファイル: Program.cs プロジェクト: flair2005/dlnuvaar
        /// <summary>
        /// 创建面对象
        /// </summary>
        /// <param name="face"></param>
        /// <returns></returns>
        private static SWFace CreateSWFace(Face2 face) {
            if (face == null)
                return null;

            //复制Face信息
            SWFace swFace = new SWFace();

            //ID
            swFace.ID = face.GetFaceId();
            //包围盒
            swFace.BoundingBox = CreateSWBoundingBox(face.GetBox());

            //三角面片
            //int tessTriCount = face.GetTessTriangleCount();
            swFace.TessTriangles = face.GetTessTriangles(false);
            swFace.TessNormals = face.GetTessNorms();

            //OutPutTessTriangles(tessTriCount, arrTriangles);
            /* 
            if (arrTriangles != null) {
                for (int i = 0; i < tessTriCount; i += 9) {
                    swFace.TessTriangles.Add(CreateSWTriangle(arrTriangles, i));
                }
            }
            */
           
            //几何信息
            swFace.Surface = CreateSWSurface(face.GetSurface());

            return swFace;
        }