Salome HOME
Merging with WPdev
[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/ or email : webmaster.salome@opencascade.com
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     print "-------------------------- create mesh"
53     mesh = smesh.Mesh(shape_mesh)
54       
55     print "-------------------------- create Hypothesis"
56     if (len is not None):
57         print "-------------------------- LocalLength"
58         algoReg = mesh.Segment()
59         hypLength1 = algoReg.LocalLength(len)
60         print "Hypothesis type : ", hypLength1.GetName()
61         print "Hypothesis ID   : ", hypLength1.GetId()
62         print "Hypothesis Value: ", hypLength1.GetLength()
63     
64     if (nbseg is not None):   
65         print "-------------------------- NumberOfSegments"
66         algoReg = mesh.Segment()
67         hypNbSeg1 = algoReg.NumberOfSegments(nbseg)
68         print "Hypothesis type : ", hypNbSeg1.GetName()
69         print "Hypothesis ID   : ", hypNbSeg1.GetId()
70         print "Hypothesis Value: ", hypNbSeg1.GetNumberOfSegments()
71
72     if (area == "LengthFromEdges"):
73         print "-------------------------- LengthFromEdges"
74         algoMef = mesh.Triangle()
75         hypLengthFromEdges = algoMef.LengthFromEdges(1)
76         print "Hypothesis type     : ", hypLengthFromEdges.GetName()
77         print "Hypothesis ID       : ", hypLengthFromEdges.GetId()
78         print "LengthFromEdges Mode: ", hypLengthFromEdges.GetMode()
79        
80     else:
81         print "-------------------------- MaxElementArea"
82         algoMef = mesh.Triangle()
83         hypArea1 = algoMef.MaxElementArea(area)
84         print "Hypothesis type : ", hypArea1.GetName()
85         print "Hypothesis ID   : ", hypArea1.GetId()
86         print "Hypothesis Value: ", hypArea1.GetMaxElementArea()
87               
88     
89     print "-------------------------- Regular_1D"
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     listHyp = algoMef.GetCompatibleHypothesis()
99     for hyp in listHyp:
100         print hyp
101         
102     print "Algo name: ", algoMef.GetName()
103     print "Algo ID  : ", algoMef.GetId()
104
105
106     # ---- add hypothesis to shape
107
108     print "-------------------------- compute mesh"
109     ret = mesh.Compute()
110     print  "Compute Mesh .... ", 
111     print ret
112     log = mesh.GetLog(0); # no erase trace
113     #for linelog in log:
114     #    print linelog
115
116     print "------------ INFORMATION ABOUT MESH ------------"
117     
118     print "Number of nodes    : ", mesh.NbNodes()
119     print "Number of edges    : ", mesh.NbEdges()
120     print "Number of faces    : ", mesh.NbFaces()
121     print "Number of triangles: ", mesh.NbTriangles()
122
123     return mesh