def CreateSalomeGeom(newnode, newline, groupline=[], groupnode=[]): """creation a la volle d une geometrie dans salome n'est disponible que depuis salome""" liennoeudsalome = [] for i in range(0, newnode.shape[0]): liennoeudsalome.append( geompy.MakeVertex(newnode[i, 0], newnode[i, 1], newnode[i, 2])) lienlinesalome = [] for i in range(0, len(newline)): lienlinesalome.append( geompy.MakeLineTwoPnt(liennoeudsalome[newline[i][0]], liennoeudsalome[newline[i][1]])) complist = [] complist.extend(liennoeudsalome) complist.extend(lienlinesalome) outshape = geompy.MakeCompound(complist) sortie = geompy.addToStudy(outshape, "treilli") sortiegr = [] #creation des groupes for groupe in groupline: if (len(groupe[1]) > 0): newgr = geompy.CreateGroup(outshape, geompy.ShapeType["EDGE"]) for a in groupe[1]: lineid = geompy.GetSubShapeID(outshape, lienlinesalome[a]) geompy.AddObject(newgr, lineid) sortiegr.append( geompy.addToStudyInFather(outshape, newgr, groupe[0])) #creation des groupes for groupe in groupnode: if (len(groupe[1]) > 0): newgr = geompy.CreateGroup(outshape, geompy.ShapeType["VERTEX"]) for a in groupe[1]: noeudid = geompy.GetSubShapeID(outshape, liennoeudsalome[a]) geompy.AddObject(newgr, noeudid) sortiegr.append( geompy.addToStudyInFather(outshape, newgr, groupe[0])) #gg = salome.ImportComponentGUI("GEOM") # #gg.createAndDisplayGO(sortie) #for a in sortiegr: # gg.createAndDisplayGO(a) salome.sg.updateObjBrowser(1) print "salome geom done"
def split_cooler_to_faces(cooler_obj): groups = [] counter = 0 for each_face in geompy.SubShapeAllSortedCentres(cooler, geompy.ShapeType["FACE"]): groups.append (geompy.CreateGroup(cooler, geompy.ShapeType["FACE"])) geompy.AddObject (groups[counter], geompy.GetSubShapeID(cooler, each_face)) geompy.addToStudyInFather (cooler, groups[counter], 'face_' + str(counter+1)) counter+=1 return groups
def SelectEdgesParalletTo(aObject, aVector, aTol): allEdgesList = [] allEdgesList = geompy.SubShapeAll(aObject, geompy.ShapeType["EDGE"]) edgeGroup = geompy.CreateGroup(aObject, geompy.ShapeType["EDGE"]) nEdges = len(allEdgesList) nSelected = 0 for jEdge in range(0, nEdges): isParallel = VectorsAreParallel(aVector, allEdgesList[jEdge], aTol) if isParallel: edgeID = geompy.GetSubShapeID(aObject, allEdgesList[jEdge]) geompy.AddObject(edgeGroup, edgeID) nSelected = nSelected + 1 print nSelected print "done" return edgeGroup
def SelectEdgesWithLenEqualAndParallelTo(aObject, aLen, aVector, aTol): allEdgesList = [] allEdgesList = geompy.SubShapeAll(aObject, geompy.ShapeType["EDGE"]) edgeGroup = geompy.CreateGroup(aObject, geompy.ShapeType["EDGE"]) nEdges = len(allEdgesList) nSelected = 0 for jEdge in range(0, nEdges): edgeProps = geompy.BasicProperties(allEdgesList[jEdge]) edgeLen = edgeProps[0] lenDiff = math.fabs(edgeLen - aLen) isParallel = VectorsAreParallel(aVector, allEdgesList[jEdge], aTol) if (isParallel and (lenDiff <= aTol)): edgeID = geompy.GetSubShapeID(aObject, allEdgesList[jEdge]) geompy.AddObject(edgeGroup, edgeID) nSelected = nSelected + 1 return edgeGroup
def SelectFacesWithCoordinateAndGreaterRadius(aObject, aCoord, aCoordID, aCenter, aRadius, aTol): allFacesList = [] allFacesList = geompy.SubShapeAll(aObject, geompy.ShapeType["FACE"]) facesGroup = geompy.CreateGroup(aObject, geompy.ShapeType["FACE"]) nFaces = len(allFacesList) nSelected = 0 for jFace in range(0, nFaces): jFaceCOM = geompy.MakeCDG(allFacesList[jFace]) isOnCoordinate = PointOnCoordinate(jFaceCOM, aCoord, aCoordID, aTol) isGreaterRadius = PointGreaterRadius(jFaceCOM, aCenter, aRadius, aTol) if (isOnCoordinate and isGreaterRadius): faceID = geompy.GetSubShapeID(aObject, allFacesList[jFace]) geompy.AddObject(facesGroup, faceID) nSelected = nSelected + 1 print nSelected print "done" return facesGroup
def SelectFacesWithNormalParallelToVec(aObject, aVectors, aTol): allFacesList = [] allFacesList = geompy.SubShapeAll(aObject, geompy.ShapeType["FACE"]) facesGroup = geompy.CreateGroup(aObject, geompy.ShapeType["FACE"]) nFaces = len(allFacesList) nSelected = 0 for jFace in range(0, nFaces): jFaceCOM = geompy.MakeCDG(allFacesList[jFace]) jFaceNormal = geompy.GetNormal(allFacesList[jFace], jFaceCOM) isParallel = VectorsAreParallelVec(jFaceNormal, aVectors, aTol) if isParallel: faceID = geompy.GetSubShapeID(aObject, allFacesList[jFace]) geompy.AddObject(facesGroup, faceID) nSelected = nSelected + 1 print nSelected print "done" return facesGroup
def SelectFacesWithCOM_OnRadius(aObject, aCenter, aRadius, aTol): # all Faces allFacesList = [] selectedFacesList = [] allFacesList = geompy.SubShapeAll(aObject, geompy.ShapeType["FACE"]) facesGroup = geompy.CreateGroup(aObject, geompy.ShapeType["FACE"]) nFaces = len(allFacesList) nSelected = 0 for jFace in range(0, nFaces): jFaceCOM = geompy.MakeCDG(allFacesList[jFace]) isOnRadius = PointOnRadius(jFaceCOM, aCenter, aRadius, aTol) if isOnRadius: faceID = geompy.GetSubShapeID(aObject, allFacesList[jFace]) geompy.AddObject(facesGroup, faceID) nSelected = nSelected + 1 print nSelected print "done" return facesGroup
def SelectFacesWithCOM_OnCoordinate(aObject, aCoordValue, aCoordID, aTol): # 0 - X, 1 - Y, 2 - Z # all Faces allFacesList = [] selectedFacesList = [] allFacesList = geompy.SubShapeAll(aObject, geompy.ShapeType["FACE"]) facesGroup = geompy.CreateGroup(aObject, geompy.ShapeType["FACE"]) nFaces = len(allFacesList) nSelected = 0 for jFace in range(0, nFaces): jFaceCOM = geompy.MakeCDG(allFacesList[jFace]) isOnCoordinate = PointOnCoordinate(jFaceCOM, aCoordValue, aCoordID, aTol) if isOnCoordinate: faceID = geompy.GetSubShapeID(aObject, allFacesList[jFace]) geompy.AddObject(facesGroup, faceID) nSelected = nSelected + 1 print nSelected print "done" return facesGroup
globalsolid = geompy.MakePartition([Box_1], [grfaceCompound], [], [], geompy.ShapeType["SOLID"], 0, [], 1) geompy.addToStudy(globalsolid, 'globalsolid') #generation des groupes groupe = [] #EDGE #Rien #FACE #infbase groupe de face qui represente le pied de la structure grinfbase = geompy.CreateGroup(globalsolid, geompy.ShapeType["FACE"]) [geomObj_248] = geompy.SubShapeAll(infbase, geompy.ShapeType["FACE"]) geomObj_temp = geompy.GetSame(globalsolid, geomObj_248) tempid = geompy.GetSubShapeID(globalsolid, geomObj_temp) geompy.AddObject(grinfbase, tempid) geompy.addToStudyInFather(globalsolid, grinfbase, "infbase") groupe.append(grinfbase) #faces de contacte hautes touttop = geompy.CreateGroup(globalsolid, geompy.ShapeType["FACE"]) for a in range(0, nsub + 1): for b in range(0, nsub + 1): grtop = geompy.CreateGroup(globalsolid, geompy.ShapeType["FACE"]) [tempgeomObj] = geompy.SubShapeAll(facenodeup[a][b], geompy.ShapeType["FACE"]) geomObj_temp = geompy.GetSame(globalsolid, tempgeomObj) geompy.UnionList(touttop, [geomObj_temp]) geompy.UnionList(grtop, [geomObj_temp]) #legerement plus long que la ligne au dessus
################################################# ## GROUP (SOLID) ################################################# # Get ID (solid) id_p1_solids = [] #initialize the array for aSolid in range(0, len(p1_solids)): id_p1_solids.append(geompy.GetSubShapeID( p1, p1_solids[aSolid])) #get the ID of the solid and add it to the array # make groups (solid) g = [] for aGroup in range(0, len(p1_solids)): g.append(geompy.CreateGroup(p1, geompy.ShapeType["SOLID"])) for aGroup in range(0, len(p1_solids)): geompy.AddObject(g[aGroup], id_p1_solids[aGroup]) # add objects in the study id_p1 = geompy.addToStudy(p1, "Part1") for aGroup in range(0, len(p1_solids)): geompy.addToStudyInFather(p1, g[aGroup], 'body{0}'.format(aGroup + 1)) ################################################# ## GROUP (FACE) # Ref : http://docs.salome-platform.org/latest/gui/GEOM/tui_working_with_groups_page.html ################################################# for aSolid in range(0, len(p1_solids)): # Get ID (surface) p1_sufaces = geompy.ExtractShapes(p1_solids[aSolid], geompy.ShapeType["FACE"], False) id_p1_sufaces = []
## Geometry part ## salome.salome_init() geompy.init_geom(salome.myStudy) cooler = geompy.MakeBoxDXDYDZ(30, 20, 70) group = geompy.CreateGroup(cooler, geompy.ShapeType["FACE"]) geompy.addToStudy(cooler, 'cooler') groups = [] counter = 0 for each_face in geompy.SubShapeAllSortedCentres(cooler, geompy.ShapeType["FACE"]): groups.append(geompy.CreateGroup(cooler, geompy.ShapeType["FACE"])) geompy.AddObject(groups[counter], geompy.GetSubShapeID(cooler, each_face)) geompy.addToStudyInFather(cooler, groups[counter], 'face_' + str(counter + 1)) counter += 1 update_screen() ## Mesh part ## smesh.SetCurrentStudy(salome.myStudy) cooler_mesh = smesh.CreateMesh(cooler) #update_screen() for geom_group in groups: mesh_group = cooler_mesh.CreateGroupFromGEOM(SMESH.FACE, geom_group.GetName(), geom_group) update_screen()
def injectorEdgeGroups (aInjGeom, aInjLens, aInjRads, aWallS ,aTol): # L1= aInjLens[0] L2= aInjLens[1] L3= aInjLens[2] L4= aInjLens[3] L5= aInjLens[4] L6= aInjLens[5] # R0= aInjRads[0] R1= aInjRads[1] R2= aInjRads[2] R3= aInjRads[3] R4= aInjRads[4] # S = aWallS # RMAX = R4 LSUMM = L1 + L2 + L3 + L4 + L5 + L6 X = [-(L1+L2), -L2, 0, L3, L3+L4, L3+L4+L5, L3+L4+L5+L6] Sqrt2By2 = math.sqrt(2.0)/2.0 YL1 = R2 * Sqrt2By2 * 0.5 ZL1 = R2 * Sqrt2By2 * 0.5 YL2 = (R1+S) * Sqrt2By2 ZL2 = (R1+S) * Sqrt2By2 YL2b= (R1) * Sqrt2By2 ZL2b= (R1) * Sqrt2By2 YL3 = (R2+S) * Sqrt2By2 ZL3 = (R2+S) * Sqrt2By2 YL3b= (R2) * Sqrt2By2 ZL3b= (R2) * Sqrt2By2 # v0 = geompy.MakeVertex(X[0], YL1, ZL1) v0a= geompy.MakeVertex(X[0], YL2, ZL2) v0b= geompy.MakeVertex(X[0], YL2b, ZL2b) v1 = geompy.MakeVertex(X[1], YL1, ZL1) v1a= geompy.MakeVertex(X[1], YL2, ZL2) v2 = geompy.MakeVertex(X[2], YL1, ZL1) v2a= geompy.MakeVertex(X[2], YL3, ZL3) v2b= geompy.MakeVertex(X[2], YL3b, ZL3b) v3 = geompy.MakeVertex(X[3], YL1, ZL1) v4 = geompy.MakeVertex(X[4], YL1, ZL1) v5 = geompy.MakeVertex(X[5], YL1, ZL1) v6 = geompy.MakeVertex(X[6], YL1, ZL1) # Edge_L1 = edgeSelect.EdgeOnEnds (aInjGeom, v0, v1, aTol) Edge_L1a= edgeSelect.EdgeOnEnds (aInjGeom, v0a,v1a,aTol) Edge_L2a= edgeSelect.EdgeOnEnds (aInjGeom, v1a,v2a,aTol) Edge_L2 = edgeSelect.EdgeOnEnds (aInjGeom, v1, v2, aTol) Edge_L3 = edgeSelect.EdgeOnEnds (aInjGeom, v2, v3, aTol) Edge_L4 = edgeSelect.EdgeOnEnds (aInjGeom, v3, v4, aTol) Edge_L5 = edgeSelect.EdgeOnEnds (aInjGeom, v4, v5, aTol) Edge_L6 = edgeSelect.EdgeOnEnds (aInjGeom, v5, v6, aTol) # Edge_L1_Group = geompy.CreateGroup(aInjGeom, geompy.ShapeType["EDGE"]) Edge_L1_ID = geompy.GetSubShapeID(aInjGeom, Edge_L1) geompy.AddObject(Edge_L1_Group, Edge_L1_ID) geompy.addToStudyInFather(aInjGeom,Edge_L1_Group,"LE1") # Edge_L1a_Group = geompy.CreateGroup(aInjGeom, geompy.ShapeType["EDGE"]) Edge_L1a_ID = geompy.GetSubShapeID(aInjGeom, Edge_L1a) geompy.AddObject(Edge_L1a_Group, Edge_L1a_ID) geompy.addToStudyInFather(aInjGeom,Edge_L1a_Group,"LE1a") # Edge_L2_Group = geompy.CreateGroup(aInjGeom, geompy.ShapeType["EDGE"]) Edge_L2_ID = geompy.GetSubShapeID(aInjGeom, Edge_L2) geompy.AddObject(Edge_L2_Group, Edge_L2_ID) geompy.addToStudyInFather(aInjGeom,Edge_L2_Group,"LE2") # Edge_L2a_Group = geompy.CreateGroup(aInjGeom, geompy.ShapeType["EDGE"]) Edge_L2a_ID = geompy.GetSubShapeID(aInjGeom, Edge_L2a) geompy.AddObject(Edge_L2a_Group, Edge_L2a_ID) geompy.addToStudyInFather(aInjGeom,Edge_L2a_Group,"LE2a") # Edge_L3_Group = geompy.CreateGroup(aInjGeom, geompy.ShapeType["EDGE"]) Edge_L3_ID = geompy.GetSubShapeID(aInjGeom, Edge_L3) geompy.AddObject(Edge_L3_Group, Edge_L3_ID) geompy.addToStudyInFather(aInjGeom,Edge_L3_Group,"LE3") # Edge_L4_Group = geompy.CreateGroup(aInjGeom, geompy.ShapeType["EDGE"]) Edge_L4_ID = geompy.GetSubShapeID(aInjGeom, Edge_L4) geompy.AddObject(Edge_L4_Group, Edge_L4_ID) geompy.addToStudyInFather(aInjGeom,Edge_L4_Group,"LE4") # Edge_L5_Group = geompy.CreateGroup(aInjGeom, geompy.ShapeType["EDGE"]) Edge_L5_ID = geompy.GetSubShapeID(aInjGeom, Edge_L5) geompy.AddObject(Edge_L5_Group, Edge_L5_ID) geompy.addToStudyInFather(aInjGeom,Edge_L5_Group,"LE5") # Edge_L6_Group = geompy.CreateGroup(aInjGeom, geompy.ShapeType["EDGE"]) Edge_L6_ID = geompy.GetSubShapeID(aInjGeom, Edge_L6) geompy.AddObject(Edge_L6_Group, Edge_L6_ID) geompy.addToStudyInFather(aInjGeom,Edge_L6_Group,"LE6") # YL5 = R2 * 0.5 ZL5 = 0.0 YL6 = -R2 * 0.5 ZL6 = 0.0 YL7 = YL5 * Sqrt2By2 ZL7 = YL7 YL8 = YL6 * Sqrt2By2 ZL8 = YL7 # v7 = geompy.MakeVertex(X[0], YL5, ZL5) v8 = geompy.MakeVertex(X[0], YL7, ZL7) v9 = geompy.MakeVertex(X[0], YL6, ZL6) v10 = geompy.MakeVertex(X[0], YL8, ZL8) # Edge_A11 = edgeSelect.EdgeOnEnds (aInjGeom, v7, v8, aTol) Edge_A12 = edgeSelect.EdgeOnEnds (aInjGeom, v9, v10, aTol) Edge_A2 = edgeSelect.EdgeOnEnds (aInjGeom, v8, v10, aTol) # Edge_A1_Group = geompy.CreateGroup(aInjGeom, geompy.ShapeType["EDGE"]) Edge_A11_ID = geompy.GetSubShapeID(aInjGeom, Edge_A11) Edge_A12_ID = geompy.GetSubShapeID(aInjGeom, Edge_A12) geompy.AddObject(Edge_A1_Group, Edge_A11_ID) geompy.AddObject(Edge_A1_Group, Edge_A12_ID) geompy.addToStudyInFather(aInjGeom,Edge_A1_Group,"AE1") # Edge_A2_Group = geompy.CreateGroup(aInjGeom, geompy.ShapeType["EDGE"]) Edge_A2_ID = geompy.GetSubShapeID(aInjGeom, Edge_A2) geompy.AddObject(Edge_A2_Group, Edge_A2_ID) geompy.addToStudyInFather(aInjGeom,Edge_A2_Group,"AE2") # Edge_R1 = edgeSelect.EdgeOnEnds (aInjGeom, v8, v0b, aTol) Edge_R2 = edgeSelect.EdgeOnEnds (aInjGeom, v2a,v2b,aTol) # Edge_R1_Group = geompy.CreateGroup(aInjGeom, geompy.ShapeType["EDGE"]) Edge_R1_ID = geompy.GetSubShapeID(aInjGeom, Edge_R1) geompy.AddObject(Edge_R1_Group, Edge_R1_ID) geompy.addToStudyInFather(aInjGeom,Edge_R1_Group,"RE1") # Edge_R2_Group = geompy.CreateGroup(aInjGeom, geompy.ShapeType["EDGE"]) Edge_R2_ID = geompy.GetSubShapeID(aInjGeom, Edge_R2) geompy.AddObject(Edge_R2_Group, Edge_R2_ID) geompy.addToStudyInFather(aInjGeom,Edge_R2_Group,"RE2") # subMeshEdges = [Edge_L1_Group, Edge_L1a_Group, Edge_L2_Group, Edge_L2a_Group, Edge_L3_Group, Edge_L4_Group, Edge_L5_Group, Edge_L6_Group, Edge_A1_Group, Edge_A2_Group, Edge_R1_Group, Edge_R2_Group] return subMeshEdges