import SALOMEDS
-def demidisk(study, r1, a1, roty=0):
+def demidisk(study, r1, a1, roty=0, solid_thickness=0):
+ if solid_thickness < 1e-7:
+ with_solid = False
+ else:
+ with_solid = True
+
geompy = geomBuilder.New(study)
O = geompy.MakeVertex(0, 0, 0)
arc1 = geompy.MakeArc(v[1], v7, v[3])
l[0] = geompy.MakeLineTwoPnt(v[1], v[3])
face1 = geompy.MakeFaceWires([arc1, l[0]], 1)
- part1 = geompy.MakePartition([face1], [l[2], l[4], l[5], l[6], l[7]], [], [], geompy.ShapeType["FACE"], 0, [], 0, True)
+
+ if with_solid:
+ # Vertices
+ v0 = geompy.MakeVertex(0, r1 + solid_thickness, 0)
+ v1 = geompy.MakeRotation(v0, OX, a1*math.pi/180.0)
+ v2 = geompy.MakeRotation(v0, OX, math.pi - (a1*math.pi/180.0))
+ v3 = geompy.MakeRotation(v0, OX, math.pi)
+ v.extend([v0,v1,v3,v2]) # The order is important for use in pointsProjetes
+ l0 = geompy.MakeLineTwoPnt(v[1], v0)
+ l2 = geompy.MakeRotation(l0, OX, a1*math.pi/180.0)
+ l3 = geompy.MakeRotation(l0, OX, math.pi - (a1*math.pi/180.0))
+ face2 = geompy.MakeRevolution(l0, OX, a1*math.pi/180.0)
+ face3 = geompy.MakeRevolution(l2, OX, math.pi - 2*a1*math.pi/180.0)
+ face4 = geompy.MakeRevolution(l3, OX, a1*math.pi/180.0)
+ part0 = geompy.MakePartition([face1], [l[2], l[4], l[5], l[6], l[7]], [], [], geompy.ShapeType["FACE"], 0, [], 0, True)
+ compound1 = geompy.MakeCompound([part0, face2, face3, face4])
+ part1 = geompy.MakeGlueEdges(compound1,1e-7)
+ else:
+ part1 = geompy.MakePartition([face1], [l[2], l[4], l[5], l[6], l[7]], [], [], geompy.ShapeType["FACE"], 0, [], 0, True)
if roty != 0:
vrot = [ geompy.MakeRotation(vert, OY, roty*math.pi/180.0) for vert in v ]
pass
return lord
-def build_shape(study, r1, r2, h1, h2):
+def build_shape(study, r1, r2, h1, h2, solid_thickness=0):
+ if solid_thickness < 1e-7:
+ with_solid = False
+ else:
+ with_solid = True
+
geompy = geomBuilder.New(study)
O = geompy.MakeVertex(0, 0, 0)
ratio = float(r2)/float(r1)
if ratio > (1.0 -seuilmax):
a1 = 45.0*(1.0 -ratio)/seuilmax
+
+ """
+ res = geompy.MakeCompound([demicyl1,demicyl2])
+ return res
+ """
+
+ # --- creation des faces de la jonction
+ [faci, sect45, arc1, l1, lord90, lord45, edges, arcextru] = jonction(study, r1, r2,\
+ h1, h2, a1)
+ if with_solid:
+ [faci_ext, sect45_ext, arc1_ext, l1_ext, \
+ lord90_ext, lord45_ext, edges_ext, arcextru_ext] = jonction(study, r1 + solid_thickness, r2 + solid_thickness,\
+ h1, h2, a1)
+ faces_jonction_ext = []
+ for i,l in enumerate(lord90):
+ faces_jonction_ext.append(geompy.MakeQuad2Edges(lord90[i],lord90_ext[i]))
+ for i in [1, 3, 6, 7]:
+ faces_jonction_ext.append(geompy.MakeQuad2Edges(edges[i],edges_ext[i]))
+ for i,l in enumerate(lord45):
+ faces_jonction_ext.append(geompy.MakeQuad2Edges(lord45[i],lord45_ext[i]))
+
+ for i,face in enumerate(faces_jonction_ext):
+ geompy.addToStudy(faces_jonction_ext[i], "faci_ext_%d"%i)
+
+ # --- extrusion droite des faces de jonction, pour reconstituer les demi cylindres
+ # TODO : ajouter les faces nécessaires à sect45 dans le cas avec solide
+ if with_solid:
+ sect45 = geompy.MakeCompound([sect45]+faces_jonction_ext[-3:])
+ sect45 = geompy.MakeGlueEdges(sect45, 1e-7)
-
- # --- sections droites des deux demi cylindres avec le partionnement
+ #return sect45, faces_jonction_ext[-3:]
+ extru1 = geompy.MakePrismVecH(sect45, OX, h1+10)
+
+ #base2 = geompy.MakeCompound(faci[5:])
+ #base2 = geompy.MakeGlueEdges(base2, 1e-7)
+ # RNC : perf
+ faces_coupe = faci[5:]
+ if with_solid:
+ faces_coupe = faci[5:]+faces_jonction_ext[:3]
+ base2 = geompy.MakePartition(faces_coupe, [], [], [], geompy.ShapeType["FACE"], 0, [], 0, True)
+ extru2 = geompy.MakePrismVecH(base2, OZ, h2)
+
+ # --- partition et coupe
+
+ if with_solid:
+ demiDisque = geompy.MakeFaceWires([arc1_ext, l1_ext[0]], 1)
+ else:
+ demiDisque = geompy.MakeFaceWires([arc1, l1[0]], 1)
+ demiCylindre = geompy.MakePrismVecH(demiDisque, OX, h1)
+
+ box = geompy.MakeBox(0, -2*(r1+h1), -2*(r1+h1), 2*(r1+h1), 2*(r1+h1), 2*(r1+h1))
+ rot = geompy.MakeRotation(box, OY, 45*math.pi/180.0)
+
+ garder = geompy.MakeCutList(demiCylindre, [extru2, rot], True)
+ geompy.addToStudy(garder,"garder")
+
+ faces_coupe = faci[:5]
+ if with_solid:
+ faces_coupe.extend(faces_jonction_ext[-7:])
+ raccord = geompy.MakePartition([garder], faces_coupe + [arcextru], [], [], geompy.ShapeType["SOLID"], 0, [], 0, True)
+ assemblage = geompy.MakeCompound([raccord, extru1, extru2])
+ assemblage = geompy.MakeGlueFaces(assemblage, 1e-7)
+ # RNC : perf
+ #assemblage = geompy.MakePartition([raccord, extru1, extru2], [], [], [], geompy.ShapeType["SOLID"], 0, [], 0, True)
+
+ #return extru2, garder, raccord
+
+ box = geompy.MakeBox(-1, -(r1+r2+2*solid_thickness), -1, h1, r1+r2+2*solid_thickness, h2)
+ geompy.addToStudy(box, "box")
+ final = geompy.MakeCommonList([box, assemblage], True)
+
+ # --- Partie inférieure
+ v3, l3, arc3, part3 = demidisk(study, r1, a1, 180.0, solid_thickness)
+ geompy.addToStudy(part3,"part3")
+ extru3 = geompy.MakePrismVecH(part3, OX, h1)
+ geompy.addToStudy(extru3,"extru3")
+
+ # --- Symétrie
+
+ compound = geompy.MakeCompound([final, extru3])
+ plane = geompy.MakePlane(O,OX,2000)
+ compound_mirrored = geompy.MakeMirrorByPlane(compound, plane)
+ final = geompy.MakeCompound([compound, compound_mirrored])
+
+ return final
- v1, l1, arc1, part1 = demidisk(study, r1, a1)
+
+def jonction(study, r1, r2, h1, h2, a1):
+
+ O = geompy.MakeVertex(0, 0, 0)
+ OX = geompy.MakeVectorDXDYDZ(1, 0, 0)
+ OY = geompy.MakeVectorDXDYDZ(0, 1, 0)
+ OZ = geompy.MakeVectorDXDYDZ(0, 0, 1)
+
+ # --- sections droites des deux demi cylindres avec le partionnement
+ v1, l1, arc1, part1 = demidisk(study, r1, a1, 0.)
v2, l2, arc2, part2 = demidisk(study, r2, a1, 90.0)
+ #elems_disk1 = [v1, l1, arc1, part1]
+ #elems_disk2 = [v2, l2, arc2, part2]
# --- extrusion des sections --> demi cylindres de travail, pour en extraire les sections utilisées au niveau du Té
# et enveloppe cylindrique du cylindre principal
demicyl1 = geompy.MakePrismVecH(part1, OX, h1)
demicyl2 = geompy.MakePrismVecH(part2, OZ, h2)
arcextru = geompy.MakePrismVecH(arc1, OX, h1)
-
+
# --- plan de coupe à 45° sur le cylindre principal,
# section à 45° du cylndre principal,
- # section du cylindre secondaire par l'enveloppe cylindique du cylindre principal
+ # section du cylindre secondaire par l'enveloppe cylindrique du cylindre principal
plan1 = geompy.MakePlane(O, OX, 4*r1)
planr = geompy.MakeRotation(plan1, OY, 45*math.pi/180.0)
sect90 = geompy.MakeCommonList([demicyl2, arcextru], True)
geompy.addToStudy(sect90, 'sect90')
-
+
# --- liste ordonnée des points projetés sur les deux sections
vord45 = pointsProjetes(study, v1, sect45)
# --- abaissement des quatre points centraux de la section du cylindre secondaire
+ #if with_solid:
+ #dz = -(r2 + solid_thickness)/2.0
+ #else:
+ #dz = -r2/2.0
dz = -r2/2.0
for i in (0, 2, 4, 5):
vord90[i] = geompy.TranslateDXDYDZ(vord90[i], 0, 0, dz, True)
geompy.addToStudyInFather(sect90, vord90[i], 'vm%d'%i)
+ #if with_solid:
+ #for i in (1, 3, 6, 7):
+ #vord90[i] = geompy.TranslateDXDYDZ(vord90[i], 0, 0, dz*solid_thickness/(r2+solid_thickness), True)
+
+ """
+ res=vord90
+ return res
+ """
# --- création des deux arêtes curvilignes sur l'enveloppe cylindrique du cylindre principal, à la jonction
#geompy.addToStudy(plan, "plan%d"%i)
section = geompy.MakeSection(plan, arcextru, True)
secpart = geompy.MakePartition([section], [sect45, sect90], [], [], geompy.ShapeType["EDGE"], 0, [], 0, True)
- #geompy.addToStudy(secpart, "secpart%d"%i)
+ geompy.addToStudy(secpart, "secpart%d"%i)
lsec = geompy.ExtractShapes(secpart, geompy.ShapeType["EDGE"], True)
#print "len(lsec)", len(lsec)
+
+ # TODO : revoir ça dans le cas avec solide
for l in lsec:
pts = geompy.ExtractShapes(l, geompy.ShapeType["VERTEX"], True)
if (((geompy.MinDistance(pts[0], p0) < 0.001) and (geompy.MinDistance(pts[1], p1) < 0.001)) or
((geompy.MinDistance(pts[1], p0) < 0.001) and (geompy.MinDistance(pts[0], p1) < 0.001))):
curv[i+2] =l
- #print "curv_%d OK"%i
+ print "curv_%d OK"%i
break
- for i,l in enumerate(curv):
- geompy.addToStudyInFather(arcextru, l, "curv%d"%i)
+ # RNC : commente temporairement
+ #for i,l in enumerate(curv):
+ # geompy.addToStudyInFather(arcextru, l, "curv%d"%i)
# --- creation des arêtes droites manquantes, des faces et volumes pour les quatre volumes de la jonction
edges[6] = curv[2]
edges[7] = curv[3]
for i,l in enumerate(edges):
+ print i
geompy.addToStudy( l, "edge%d"%i)
ed45 = [None for i in range(8)]
for i,f in enumerate(faci):
geompy.addToStudy(f, "faci_%d"%i)
- # --- extrusion droite des faces de jonction, pour reconstituer les demi cylindres
-
- extru1 = geompy.MakePrismVecH(sect45, OX, h1+10)
-
- base2 = geompy.MakePartition(faci[5:], [], [], [], geompy.ShapeType["FACE"], 0, [], 0, True)
- extru2 = geompy.MakePrismVecH(base2, OZ, h2)
-
- # --- partition et coupe
-
- demiDisque = geompy.MakeFaceWires([arc1, l1[0]], 1)
- demiCylindre = geompy.MakePrismVecH(demiDisque, OX, h1)
-
- box = geompy.MakeBox(0, -2*(r1+h1), -2*(r1+h1), 2*(r1+h1), 2*(r1+h1), 2*(r1+h1))
- rot = geompy.MakeRotation(box, OY, 45*math.pi/180.0)
-
- garder = geompy.MakeCutList(demiCylindre, [extru2, rot], True)
- raccord = geompy.MakePartition([garder], faci, [], [], geompy.ShapeType["SOLID"], 0, [], 0, True)
- assemblage = geompy.MakePartition([raccord, extru1, extru2], [], [], [], geompy.ShapeType["SOLID"], 0, [], 0, True)
-
- box = geompy.MakeBox(-1, -(r1+r2), -1, h1, r1+r2, h2)
- geompy.addToStudy(box, "box")
- final = geompy.MakeCommonList([box, assemblage], True)
+ return faci, sect45, arc1, l1, lord90, lord45, edges, arcextru
+
+if __name__=="__main__":
+ """For testing purpose"""
+ salome.salome_init()
+ theStudy = salome.myStudy
+ geompy = geomBuilder.New(theStudy)
+ res = build_shape(theStudy, 80., 20., 100., 100., 10.)
+ """
+ for i,v in enumerate(res):
+ geompy.addToStudy(v,"v%d"%i)
+ """
+
+ #res = demidisk(theStudy, 80, 45, 0, 10)
+ #geompy.addToStudy(res[3], "res")
+ #for i,v in enumerate(res[0]):
+ # geompy.addToStudy(v,"v%d"%i)
+ geompy.addToStudy(res, "res")
- # --- Partie infiérieure
- v3, l3, arc3, part3 = demidisk(study, r1, a1, 180.0)
- geompy.addToStudy(part3,"part3")
- extru3 = geompy.MakePrismVecH(part3, OX, h1)
- geompy.addToStudy(extru3,"extru3")
-
- # --- Symétrie
-
- compound = geompy.MakeCompound([final, extru3])
- plane = geompy.MakePlane(O,OX,2000)
- compound_mirrored = geompy.MakeMirrorByPlane(compound, plane)
- final = geompy.MakeCompound([compound, compound_mirrored])
-
- return final