1 # Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 import batchmode_salome
24 import batchmode_geompy
25 import batchmode_smesh
28 smesh = batchmode_smesh.smesh
29 smesh.SetCurrentStudy(batchmode_salome.myStudy)
31 def CreateMesh (theFileName, area, len = None, nbseg = None):
33 if not(os.path.isfile(theFileName)) or re.search("\.brep$", theFileName) is None :
34 print "Incorrect file name !"
37 if (len is None) and (nbseg is None):
38 print "Define length or number of segments !"
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 !"
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")
52 print "-------------------------- create mesh"
53 mesh = smesh.Mesh(shape_mesh)
55 print "-------------------------- create Hypothesis"
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()
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()
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()
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()
89 print "-------------------------- Regular_1D"
90 listHyp = algoReg.GetCompatibleHypothesis()
94 print "Algo name: ", algoReg.GetName()
95 print "Algo ID : ", algoReg.GetId()
97 print "-------------------------- MEFISTO_2D"
98 listHyp = algoMef.GetCompatibleHypothesis()
102 print "Algo name: ", algoMef.GetName()
103 print "Algo ID : ", algoMef.GetId()
106 # ---- add hypothesis to shape
108 print "-------------------------- compute mesh"
110 print "Compute Mesh .... ",
112 log = mesh.GetLog(0); # no erase trace
116 print "------------ INFORMATION ABOUT MESH ------------"
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()