public static List <MyVertex> extractVertecesFromSelectedFaces(SldWorks SwApplication, ModelDoc2 swModel) { // Create a file to write to. StringBuilder sb = new StringBuilder(); List <MyVertex> listPointVertex = new List <MyVertex>(); var selectedEntities = BRepFunctions.GetSelectedFaces(SwApplication, swModel); SwApplication.SendMsgToUser("Numero entità selezionate " + selectedEntities.Count.ToString()); foreach (Entity selection in selectedEntities) { var VertecesList = BRepFunctions.MyGetVertexFromFace(selection); foreach (SolidWorks.Interop.sldworks.Vertex vertex in VertecesList) { var point = (Array)vertex.GetPoint(); var currentVertex = new ClassesOfObjects.MyVertex((double)point.GetValue(0), (double)point.GetValue(1), (double)point.GetValue(2)); listPointVertex.Add(currentVertex); } } return(listPointVertex); }
public static MyRepeatedEntity KLBuildRepeatedEntity(List <Entity> entityList, int idNewRepeatedEntity, double[,] compositionMatrixOfComponentPart, SldWorks swapp) { List <Face2> listOfFacesForRepeatedEntity = new List <Face2>(); List <MyVertex> listOfMyVertexForRepeatedEntity = new List <MyVertex>(); List <MyVertex> listOfMyVertexAddedForRepeatedEntity = new List <MyVertex>(); List <MyVertex> listOfMyVertexOfCurrentFace = new List <MyVertex>(); List <MyVertex> listOfAddedMyVertexOfCurrentFace = new List <MyVertex>(); var listOfMyPlane = new List <MyPlane>(); var listOfMySphere = new List <MySphere>(); var listOfMyCone = new List <MyCone>(); var listOfMyCylinder = new List <MyCylinder>(); var listOfMyTorus = new List <MyTorus>(); //const string fileNameBuildRepeatedEntity = "buildRepeatedEntity.txt"; //string whatToWrite = ""; //whatToWrite = string.Format("Numero di facce : {0}", entityList.Count); // KLdebug.Print(whatToWrite, fileNameBuildRepeatedEntity); foreach (Entity entity in entityList) { // face storing and classification: var face = (Face2)entity; if (((((Surface)face.GetSurface()).Identity() == (int)swSurfaceTypes_e.PLANE_TYPE)) || ((((Surface)face.GetSurface()).Identity() == (int)swSurfaceTypes_e.CYLINDER_TYPE)) || ((((Surface)face.GetSurface()).Identity() == (int)swSurfaceTypes_e.SPHERE_TYPE))) { listOfFacesForRepeatedEntity.Add(face); KLClassifyFace(entity, ref listOfMyPlane, ref listOfMySphere, ref listOfMyCone, ref listOfMyCylinder, ref listOfMyTorus, compositionMatrixOfComponentPart); // vertex storing and classification (from a current face): listOfMyVertexOfCurrentFace.Clear(); listOfAddedMyVertexOfCurrentFace.Clear(); BRepFunctions.MyGetPointFromFaceEntity(entity, ref listOfMyVertexOfCurrentFace, ref listOfAddedMyVertexOfCurrentFace, swapp); // If in the face itself there are two MyVertex repeated (in listOfMyVertexOfCurrentFace) with // the following foreach instruction they are stored only once. foreach (MyVertex myVert in listOfMyVertexOfCurrentFace) { double[] vertexAffine = { myVert.x, myVert.y, myVert.z, 1 }; var newVertex = Matrix.Multiply(compositionMatrixOfComponentPart, vertexAffine); var vertexToAdd = new MyVertex(newVertex[0], newVertex[1], newVertex[2]); if (!(listOfMyVertexForRepeatedEntity.Contains(vertexToAdd))) { listOfMyVertexForRepeatedEntity.Add(vertexToAdd); //whatToWrite = string.Format("Aggiunto Vertice normale: ({0},{1},{2})", myVert.x, myVert.y, // myVert.z); //KLdebug.Print(whatToWrite, fileNameBuildRepeatedEntity); } } // If in the face itself there are two MyVertex repeated (in listOfAddedMyVertexOfCurrentFace) with //// the following foreach instruction they are stored only once. foreach (MyVertex myVert in listOfAddedMyVertexOfCurrentFace) { double[] vertexAffine = { myVert.x, myVert.y, myVert.z, 1 }; var newVertex = Matrix.Multiply(compositionMatrixOfComponentPart, vertexAffine); var vertexToAdd = new MyVertex(newVertex[0], newVertex[1], newVertex[2]); if (!(listOfMyVertexAddedForRepeatedEntity.Contains(vertexToAdd))) { listOfMyVertexAddedForRepeatedEntity.Add(vertexToAdd); //whatToWrite = string.Format("Aggiunto Vertice su edge curvo chiuso: ({0},{1},{2})", myVert.x, // myVert.y, myVert.z); //KLdebug.Print(whatToWrite, fileNameBuildRepeatedEntity); } } } } // Centroid computation: //KLdebug.Print(" ", fileNameBuildRepeatedEntity); var listOfAllVertices = new List <MyVertex>(); listOfAllVertices.AddRange(listOfMyVertexForRepeatedEntity); listOfAllVertices.AddRange(listOfMyVertexAddedForRepeatedEntity); MyVertex outputCentroid = computeCentroidsOfVertices(listOfAllVertices); // centroid of the vertices //whatToWrite = string.Format("Baricentro ({0},{1},{2})", outputCentroid.x, outputCentroid.y, outputCentroid.z); //KLdebug.Print(whatToWrite, fileNameBuildRepeatedEntity); // Creation of new MyRepeatedEntity: MyRepeatedEntity outputRepeatedEntity = new MyRepeatedEntity(idNewRepeatedEntity, listOfFacesForRepeatedEntity, outputCentroid, listOfMyVertexForRepeatedEntity, listOfMyVertexAddedForRepeatedEntity, listOfMyPlane, listOfMySphere, listOfMyCone, listOfMyCylinder, listOfMyTorus, compositionMatrixOfComponentPart); return(outputRepeatedEntity); }
// The function takes as input - a Face2 //. - a list of Face2 to remove from the the adjacent ones //It returns the list of the surfaces corresponding to the faces adjacent to the input face but not in the //list of faces to remove. // (this list of faces to remove is provided in preparation for the next function, as for every // face of a RE we want to consider the surfaces corresponding only to faces of the BRep different // from the faces of the RE itself). public static List <Surface> GetSurfacesOfFacesAdjacentToFace(Face2 inputFace, List <Face2> listOfFacesToRemoveFromTheAdjacents, SldWorks swApplWorks) { List <Surface> outputListOfSurfaces = new List <Surface>(); List <Face2> listOfAdjacentFaces = new List <Face2>(); listOfAdjacentFaces = BRepFunctions.MyAdjacenceFace(inputFace, swApplWorks); if (listOfAdjacentFaces == null) { return(outputListOfSurfaces); } listOfAdjacentFaces.RemoveAll(face => listOfFacesToRemoveFromTheAdjacents.FindIndex(facebis => face.GetFaceId() == facebis.GetFaceId()) != -1); #region stampa dati della superficie esaminata //var thisSurface = (Surface)inputFace.GetSurface(); //var firstPlaneParameters1 = thisSurface.PlaneParams; //double[] firstPlaneNormalUnchecked1 = { firstPlaneParameters1[0], firstPlaneParameters1[1], firstPlaneParameters1[2] }; //double[] firstPlanePoint1 = { firstPlaneParameters1[3], firstPlaneParameters1[4], firstPlaneParameters1[5] }; //double[] firstPlaneNormal1 = GeometryFunctions.MyGetNormalForPlaneFace(inputFace, out firstPlaneNormalUnchecked1); //MyPlane firstPlane1 = new MyPlane(firstPlaneNormal1, firstPlanePoint1); //KLdebug.Print("Superficie della faccia in esame:", fileNameBuildRepeatedEntity); //string whatToWrite1 = string.Format("a {0}, b {1}, c {2}, d {3}", firstPlane1.a, firstPlane1.b, firstPlane1.c, firstPlane1.d); //KLdebug.Print(whatToWrite1, fileNameBuildRepeatedEntity); //KLdebug.Print(" ", "buildRepeatedEntity.txt"); #endregion int index = 0; foreach (Face2 face in listOfAdjacentFaces) { var newSurface = (Surface)face.GetSurface(); #region stampa dati della superficie trovata adiacente a quella esaminata //var firstPlaneParameters = newSurface.PlaneParams; //double[] firstPlaneNormalUnchecked = { firstPlaneParameters[0], firstPlaneParameters[1], firstPlaneParameters[2] }; //double[] firstPlanePoint = { firstPlaneParameters[3], firstPlaneParameters[4], firstPlaneParameters[5] }; //double[] firstPlaneNormal = GeometryFunctions.MyGetNormalForPlaneFace(face, out firstPlaneNormalUnchecked); //MyPlane firstPlane = new MyPlane(firstPlaneNormal, firstPlanePoint); ////string whatToWriteBis = string.Format("Primo normale: a {0}, b {1}, c {2}", firstPlaneNormal.GetValue(0), firstPlaneNormal.GetValue(1), firstPlaneNormal.GetValue(2)); //string whatToWrite = string.Format("a {0}, b {1}, c {2}, d {3}", firstPlane.a, firstPlane.b, firstPlane.c, firstPlane.d); ////KLdebug.Print(whatToWriteBis, fileNameBuildRepeatedEntity); //KLdebug.Print(whatToWrite, fileNameBuildRepeatedEntity); #endregion string whatToWrite1 = ""; if (outputListOfSurfaces.FindIndex(surface => MyEqualsSurface(surface, newSurface, swApplWorks)) == -1) { outputListOfSurfaces.Add(newSurface); index++; } else { //var indexOfExistingSurface = outputListOfSurfaces.FindIndex(surface => myEqualsSurface(surface, newSurface)); } } return(outputListOfSurfaces); }