Salome HOME
Join modifications from branch OCC_debug_for_3_2_0b1
[modules/smesh.git] / src / SMESH_SWIG / batchmode_mefisto.py
1 #  Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 #
4 #  This library is free software; you can redistribute it and/or
5 #  modify it under the terms of the GNU Lesser General Public
6 #  License as published by the Free Software Foundation; either
7 #  version 2.1 of the License.
8 #
9 #  This library is distributed in the hope that it will be useful,
10 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 #  Lesser General Public License for more details.
13 #
14 #  You should have received a copy of the GNU Lesser General Public
15 #  License along with this library; if not, write to the Free Software
16 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 #  See http://www.salome-platform.org/
19 #
20 import os
21 import re
22
23 import batchmode_salome
24 import batchmode_geompy
25 import batchmode_smesh
26 import StdMeshers
27
28 smesh = batchmode_smesh.smesh
29 smesh.SetCurrentStudy(batchmode_salome.myStudy)
30
31 def CreateMesh (theFileName, area, len = None, nbseg = None):
32     
33     if not(os.path.isfile(theFileName)) or re.search("\.brep$", theFileName) is None :
34         print "Incorrect file name !"
35         return
36
37     if (len is None) and (nbseg is None):
38         print "Define length or number of segments !"
39         return
40
41     if (len is not None) and (nbseg is not None):
42         print "Only one Hypothesis (from length and number of segments) can be defined !"
43         return
44
45     
46     # ----  Import shape from BREP file and add it to the study  
47     shape_mesh = batchmode_geompy.Import(theFileName, "BREP")
48     Id_shape = batchmode_geompy.addToStudy(shape_mesh, "shape_mesh")
49
50
51     # ---- SMESH
52       
53     print "-------------------------- create Hypothesis"
54     if (len is not None):
55         print "-------------------------- LocalLength"
56         hypLength1 = smesh.CreateHypothesis("LocalLength", "libStdMeshersEngine.so")
57         hypLength1.SetLength(len)
58         print "Hypothesis type : ", hypLength1.GetName()
59         print "Hypothesis ID   : ", hypLength1.GetId()
60         print "Hypothesis Value: ", hypLength1.GetLength()
61     
62     if (nbseg is not None):   
63         print "-------------------------- NumberOfSegments"
64         hypNbSeg1 = smesh.CreateHypothesis("NumberOfSegments", "libStdMeshersEngine.so")
65         hypNbSeg1.SetNumberOfSegments(nbseg)
66         print "Hypothesis type : ", hypNbSeg1.GetName()
67         print "Hypothesis ID   : ", hypNbSeg1.GetId()
68         print "Hypothesis Value: ", hypNbSeg1.GetNumberOfSegments()
69
70     if (area == "LengthFromEdges"):
71         print "-------------------------- LengthFromEdges"
72         hypLengthFromEdges = smesh.CreateHypothesis("LengthFromEdges", "libStdMeshersEngine.so")
73         hypLengthFromEdges.SetMode(1)
74         print "Hypothesis type     : ", hypLengthFromEdges.GetName()
75         print "Hypothesis ID       : ", hypLengthFromEdges.GetId()
76         print "LengthFromEdges Mode: ", hypLengthFromEdges.GetMode()
77        
78     else:
79         print "-------------------------- MaxElementArea"
80         hypArea1 = smesh.CreateHypothesis("MaxElementArea", "libStdMeshersEngine.so")
81         hypArea1.SetMaxElementArea(area)
82         print "Hypothesis type : ", hypArea1.GetName()
83         print "Hypothesis ID   : ", hypArea1.GetId()
84         print "Hypothesis Value: ", hypArea1.GetMaxElementArea()
85               
86     
87     print "-------------------------- Regular_1D"
88     algoReg = smesh.CreateHypothesis("Regular_1D", "libStdMeshersEngine.so")
89    
90     listHyp = algoReg.GetCompatibleHypothesis()
91     for hyp in listHyp:
92         print hyp
93     
94     print "Algo name: ", algoReg.GetName()
95     print "Algo ID  : ", algoReg.GetId()
96    
97     print "-------------------------- MEFISTO_2D"
98     algoMef = smesh.CreateHypothesis("MEFISTO_2D", "libStdMeshersEngine.so")
99     
100     listHyp = algoMef.GetCompatibleHypothesis()
101     for hyp in listHyp:
102         print hyp
103         
104     print "Algo name: ", algoMef.GetName()
105     print "Algo ID  : ", algoMef.GetId()
106
107
108     # ---- add hypothesis to shape
109
110     print "-------------------------- add hypothesis to shape"
111     mesh = smesh.CreateMesh(shape_mesh) 
112
113     ret = mesh.AddHypothesis(shape_mesh, algoReg)
114     print "Add Regular_1D algo .... ", 
115     print ret
116     
117     if (nbseg is not None):
118         ret = mesh.AddHypothesis(shape_mesh, hypNbSeg1)
119         print "Add Number Of Segements algo .... ", 
120         print ret
121
122     if (len is not None):
123         ret = mesh.AddHypothesis(shape_mesh,hypLength1)
124         print "Add  Local Length algo .... ", 
125         print ret
126
127     ret = mesh.AddHypothesis(shape_mesh, algoMef)
128     print "Add MEFISTO_2D algo....", 
129     print ret
130     
131     if (area == "LengthFromEdges"):
132         ret = mesh.AddHypothesis( shape_mesh, hypLengthFromEdges)    # length from edge 
133         print "Add Length From Edges algo .... ",
134         print ret
135     else:
136         ret = mesh.AddHypothesis(shape_mesh, hypArea1)
137         print "Add Max Triangle Area algo .... ", 
138         print ret
139     
140     print "-------------------------- compute mesh"
141     ret = smesh.Compute(mesh,shape_mesh)
142     print  "Compute Mesh .... ", 
143     print ret
144     log = mesh.GetLog(0); # no erase trace
145     #for linelog in log:
146     #    print linelog
147
148     print "------------ INFORMATION ABOUT MESH ------------"
149     
150     print "Number of nodes    : ", mesh.NbNodes()
151     print "Number of edges    : ", mesh.NbEdges()
152     print "Number of faces    : ", mesh.NbFaces()
153     print "Number of triangles: ", mesh.NbTriangles()
154
155     return mesh