Salome HOME
SALOME PAL V1_4_1
[modules/smesh.git] / src / SMESH_SWIG / batchmode_mefisto.py
1 import os
2 import re
3
4 import batchmode_salome
5 import batchmode_geompy
6 import batchmode_smesh
7
8 geom = batchmode_geompy.geom
9 smesh = batchmode_smesh.smesh
10
11 geom.GetCurrentStudy(batchmode_salome.myStudyId)
12 smesh.SetCurrentStudy(batchmode_salome.myStudy)
13
14 ShapeType = batchmode_smesh.ShapeType
15
16 import StdMeshers
17
18 def CreateMesh (theFileName, area, len = None, nbseg = None):
19     
20     if not(os.path.isfile(theFileName)) or re.search("\.brep$", theFileName) is None :
21         print "Incorrect file name !"
22         return
23
24     if (len is None) and (nbseg is None):
25         print "Define length or number of segments !"
26         return
27
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 !"
30         return
31
32     
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")
36
37
38
39     # ---- SMESH
40       
41     # ---- create Hypothesis
42
43     print "-------------------------- create Hypothesis"
44     if (len is not None):
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()
51     
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()
59
60
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()
68        
69     else:
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()
76
77               
78     
79     print "-------------------------- Regular_1D"
80     algoReg = smesh.CreateHypothesis("Regular_1D", "libStdMeshersEngine.so")
81    
82     listHyp = algoReg.GetCompatibleHypothesis()
83     for hyp in listHyp:
84         print hyp
85     
86     print "Algo name: ", algoReg.GetName()
87     print "Algo ID: ", algoReg.GetId()
88    
89     print "-------------------------- MEFISTO_2D"
90     algoMef = smesh.CreateHypothesis("MEFISTO_2D", "libStdMeshersEngine.so")
91     
92     listHyp=algoMef.GetCompatibleHypothesis()
93     for hyp in listHyp:
94         print hyp
95         
96     print "Algo name: ", algoMef.GetName()
97     print "Algo ID: ", algoMef.GetId()
98
99
100
101     # ---- add hypothesis to shape
102
103     print "-------------------------- add hypothesis to shape"
104     mesh = smesh.CreateMesh(shape_mesh) 
105
106     ret = mesh.AddHypothesis(shape_mesh, algoReg)
107     print "Add Regular_1D algo .... ", 
108     print ret
109     
110     if (nbseg is not None):
111         ret=mesh.AddHypothesis(shape_mesh, hypNbSeg1)
112         print "Add Number Of Segements algo .... ", 
113         print ret
114
115     if (len is not None):
116         ret=mesh.AddHypothesis(shape_mesh,hypLength1)
117         print "Add  Local Length algo .... ", 
118         print ret
119
120     ret=mesh.AddHypothesis(shape_mesh, algoMef)
121     print "Add MEFISTO_2D algo....", 
122     print ret
123     
124     if (area == "LengthFromEdges"):
125         ret = mesh.AddHypothesis( shape_mesh, hypLengthFromEdges)    # length from edge 
126         print "Add Length From Edges algo .... ",
127         print ret
128     else:
129         ret=mesh.AddHypothesis(shape_mesh, hypArea1)
130         print "Add Max Triangle Area algo .... ", 
131         print ret
132     
133     # ---- compute mesh
134
135     print "-------------------------- compute mesh"
136     ret=smesh.Compute(mesh,shape_mesh)
137     print  "Compute Mesh .... ", 
138     print ret
139     log=mesh.GetLog(0); # no erase trace
140     #for linelog in log:
141     #    print linelog
142
143     print "------------ INFORMATION ABOUT MESH ------------"
144     
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()
149
150     return mesh