1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
4 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License.
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
27 import batchmode_salome
28 import batchmode_geompy
29 import batchmode_smesh
32 smesh = batchmode_smesh.smesh
33 smesh.SetCurrentStudy(batchmode_salome.myStudy)
35 def CreateMesh (theFileName, area, len = None, nbseg = None):
37 if not(os.path.isfile(theFileName)) or re.search("\.brep$", theFileName) is None :
38 print "Incorrect file name !"
41 if (len is None) and (nbseg is None):
42 print "Define length or number of segments !"
45 if (len is not None) and (nbseg is not None):
46 print "Only one Hypothesis (from length and number of segments) can be defined !"
50 # ---- Import shape from BREP file and add it to the study
51 shape_mesh = batchmode_geompy.Import(theFileName, "BREP")
52 Id_shape = batchmode_geompy.addToStudy(shape_mesh, "shape_mesh")
56 print "-------------------------- create mesh"
57 mesh = smesh.Mesh(shape_mesh)
59 print "-------------------------- create Hypothesis"
61 print "-------------------------- LocalLength"
62 algoReg = mesh.Segment()
63 hypLength1 = algoReg.LocalLength(len)
64 print "Hypothesis type : ", hypLength1.GetName()
65 print "Hypothesis ID : ", hypLength1.GetId()
66 print "Hypothesis Value: ", hypLength1.GetLength()
68 if (nbseg is not None):
69 print "-------------------------- NumberOfSegments"
70 algoReg = mesh.Segment()
71 hypNbSeg1 = algoReg.NumberOfSegments(nbseg)
72 print "Hypothesis type : ", hypNbSeg1.GetName()
73 print "Hypothesis ID : ", hypNbSeg1.GetId()
74 print "Hypothesis Value: ", hypNbSeg1.GetNumberOfSegments()
76 if (area == "LengthFromEdges"):
77 print "-------------------------- LengthFromEdges"
78 algoMef = mesh.Triangle()
79 hypLengthFromEdges = algoMef.LengthFromEdges(1)
80 print "Hypothesis type : ", hypLengthFromEdges.GetName()
81 print "Hypothesis ID : ", hypLengthFromEdges.GetId()
82 print "LengthFromEdges Mode: ", hypLengthFromEdges.GetMode()
85 print "-------------------------- MaxElementArea"
86 algoMef = mesh.Triangle()
87 hypArea1 = algoMef.MaxElementArea(area)
88 print "Hypothesis type : ", hypArea1.GetName()
89 print "Hypothesis ID : ", hypArea1.GetId()
90 print "Hypothesis Value: ", hypArea1.GetMaxElementArea()
93 print "-------------------------- Regular_1D"
94 listHyp = algoReg.GetCompatibleHypothesis()
98 print "Algo name: ", algoReg.GetName()
99 print "Algo ID : ", algoReg.GetId()
101 print "-------------------------- MEFISTO_2D"
102 listHyp = algoMef.GetCompatibleHypothesis()
106 print "Algo name: ", algoMef.GetName()
107 print "Algo ID : ", algoMef.GetId()
110 # ---- add hypothesis to shape
112 print "-------------------------- compute mesh"
114 print "Compute Mesh .... ",
116 log = mesh.GetLog(0); # no erase trace
120 print "------------ INFORMATION ABOUT MESH ------------"
122 print "Number of nodes : ", mesh.NbNodes()
123 print "Number of edges : ", mesh.NbEdges()
124 print "Number of faces : ", mesh.NbFaces()
125 print "Number of triangles: ", mesh.NbTriangles()