4 import batchmode_salome
5 import batchmode_geompy
8 geom = batchmode_geompy.geom
9 smesh = batchmode_smesh.smesh
11 geom.GetCurrentStudy(batchmode_salome.myStudyId)
12 smesh.SetCurrentStudy(batchmode_salome.myStudy)
14 ShapeType = batchmode_smesh.ShapeType
18 def CreateMesh (theFileName, area, len = None, nbseg = None):
20 if not(os.path.isfile(theFileName)) or re.search("\.brep$", theFileName) is None :
21 print "Incorrect file name !"
24 if (len is None) and (nbseg is None):
25 print "Define length or number of segments !"
28 if (len is not None) and (nbseg is not None):
29 print "Only one Hypothesis (from length and number of segments) can be defined !"
33 # ---- Import shape from BREP file and add it to the study
34 shape_mesh = geom.ImportBREP(theFileName)
35 Id_shape = batchmode_geompy.addToStudy( shape_mesh, "shape_mesh")
41 # ---- create Hypothesis
43 print "-------------------------- create Hypothesis"
45 print "-------------------------- LocalLength"
46 hypLength1 = smesh.CreateHypothesis("LocalLength", "libStdMeshersEngine.so")
47 hypLength1.SetLength(len)
48 print "Hypothesis type: ", hypLength1.GetName()
49 print "Hypothesis ID: ", hypLength1.GetId()
50 print "Hypothesis Value: ", hypLength1.GetLength()
52 if (nbseg is not None):
53 print "-------------------------- NumberOfSegments"
54 hypNbSeg1 = smesh.CreateHypothesis("NumberOfSegments", "libStdMeshersEngine.so")
55 hypNbSeg1.SetNumberOfSegments(nbseg)
56 print "Hypothesis type: ", hypNbSeg1.GetName()
57 print "Hypothesis ID: ", hypNbSeg1.GetId()
58 print "Hypothesis Value: ", hypNbSeg1.GetNumberOfSegments()
61 if (area == "LengthFromEdges"):
62 print "-------------------------- LengthFromEdges"
63 hypLengthFromEdges = smesh.CreateHypothesis("LengthFromEdges", "libStdMeshersEngine.so")
64 hypLengthFromEdges.SetMode(1)
65 print "Hypothesis type: ", hypLengthFromEdges.GetName()
66 print "Hypothesis ID: ", hypLengthFromEdges.GetId()
67 print "LengthFromEdges Mode: ", hypLengthFromEdges.GetMode()
70 print "-------------------------- MaxElementArea"
71 hypArea1 = smesh.CreateHypothesis("MaxElementArea", "libStdMeshersEngine.so")
72 hypArea1.SetMaxElementArea(area)
73 print "Hypothesis type: ", hypArea1.GetName()
74 print "Hypothesis ID: ", hypArea1.GetId()
75 print "Hypothesis Value: ", hypArea1.GetMaxElementArea()
79 print "-------------------------- Regular_1D"
80 algoReg = smesh.CreateHypothesis("Regular_1D", "libStdMeshersEngine.so")
82 listHyp = algoReg.GetCompatibleHypothesis()
86 print "Algo name: ", algoReg.GetName()
87 print "Algo ID: ", algoReg.GetId()
89 print "-------------------------- MEFISTO_2D"
90 algoMef = smesh.CreateHypothesis("MEFISTO_2D", "libStdMeshersEngine.so")
92 listHyp=algoMef.GetCompatibleHypothesis()
96 print "Algo name: ", algoMef.GetName()
97 print "Algo ID: ", algoMef.GetId()
101 # ---- add hypothesis to shape
103 print "-------------------------- add hypothesis to shape"
104 mesh = smesh.CreateMesh(shape_mesh)
106 ret = mesh.AddHypothesis(shape_mesh, algoReg)
107 print "Add Regular_1D algo .... ",
110 if (nbseg is not None):
111 ret=mesh.AddHypothesis(shape_mesh, hypNbSeg1)
112 print "Add Number Of Segements algo .... ",
115 if (len is not None):
116 ret=mesh.AddHypothesis(shape_mesh,hypLength1)
117 print "Add Local Length algo .... ",
120 ret=mesh.AddHypothesis(shape_mesh, algoMef)
121 print "Add MEFISTO_2D algo....",
124 if (area == "LengthFromEdges"):
125 ret = mesh.AddHypothesis( shape_mesh, hypLengthFromEdges) # length from edge
126 print "Add Length From Edges algo .... ",
129 ret=mesh.AddHypothesis(shape_mesh, hypArea1)
130 print "Add Max Triangle Area algo .... ",
135 print "-------------------------- compute mesh"
136 ret=smesh.Compute(mesh,shape_mesh)
137 print "Compute Mesh .... ",
139 log=mesh.GetLog(0); # no erase trace
143 print "------------ INFORMATION ABOUT MESH ------------"
145 print "Number of nodes: ", mesh.NbNodes()
146 print "Number of edges: ", mesh.NbEdges()
147 print "Number of faces: ", mesh.NbFaces()
148 print "Number of triangles: ", mesh.NbTriangles()