Salome HOME
correct previous integration (Porting to Python 2.6)
[modules/smesh.git] / src / SMESH_SWIG / batchmode_mefisto.py
1 #  -*- coding: iso-8859-1 -*-
2 #  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
3 #
4 #  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 #
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.
11 #
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.
16 #
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
20 #
21 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #
23 import os
24 import re
25
26 import batchmode_salome
27 import batchmode_geompy
28 import batchmode_smesh
29 import StdMeshers
30
31 smesh = batchmode_smesh.smesh
32 smesh.SetCurrentStudy(batchmode_salome.myStudy)
33
34 def CreateMesh (theFileName, area, len = None, nbseg = None):
35     
36     if not(os.path.isfile(theFileName)) or re.search("\.brep$", theFileName) is None :
37         print "Incorrect file name !"
38         return
39
40     if (len is None) and (nbseg is None):
41         print "Define length or number of segments !"
42         return
43
44     if (len is not None) and (nbseg is not None):
45         print "Only one Hypothesis (from length and number of segments) can be defined !"
46         return
47
48     
49     # ----  Import shape from BREP file and add it to the study  
50     shape_mesh = batchmode_geompy.Import(theFileName, "BREP")
51     Id_shape = batchmode_geompy.addToStudy(shape_mesh, "shape_mesh")
52
53
54     # ---- SMESH
55     print "-------------------------- create mesh"
56     mesh = smesh.Mesh(shape_mesh)
57       
58     print "-------------------------- create Hypothesis"
59     if (len is not None):
60         print "-------------------------- LocalLength"
61         algoReg = mesh.Segment()
62         hypLength1 = algoReg.LocalLength(len)
63         print "Hypothesis type : ", hypLength1.GetName()
64         print "Hypothesis ID   : ", hypLength1.GetId()
65         print "Hypothesis Value: ", hypLength1.GetLength()
66     
67     if (nbseg is not None):   
68         print "-------------------------- NumberOfSegments"
69         algoReg = mesh.Segment()
70         hypNbSeg1 = algoReg.NumberOfSegments(nbseg)
71         print "Hypothesis type : ", hypNbSeg1.GetName()
72         print "Hypothesis ID   : ", hypNbSeg1.GetId()
73         print "Hypothesis Value: ", hypNbSeg1.GetNumberOfSegments()
74
75     if (area == "LengthFromEdges"):
76         print "-------------------------- LengthFromEdges"
77         algoMef = mesh.Triangle()
78         hypLengthFromEdges = algoMef.LengthFromEdges(1)
79         print "Hypothesis type     : ", hypLengthFromEdges.GetName()
80         print "Hypothesis ID       : ", hypLengthFromEdges.GetId()
81         print "LengthFromEdges Mode: ", hypLengthFromEdges.GetMode()
82        
83     else:
84         print "-------------------------- MaxElementArea"
85         algoMef = mesh.Triangle()
86         hypArea1 = algoMef.MaxElementArea(area)
87         print "Hypothesis type : ", hypArea1.GetName()
88         print "Hypothesis ID   : ", hypArea1.GetId()
89         print "Hypothesis Value: ", hypArea1.GetMaxElementArea()
90               
91     
92     print "-------------------------- Regular_1D"
93     listHyp = algoReg.GetCompatibleHypothesis()
94     for hyp in listHyp:
95         print hyp
96     
97     print "Algo name: ", algoReg.GetName()
98     print "Algo ID  : ", algoReg.GetId()
99    
100     print "-------------------------- MEFISTO_2D"
101     listHyp = algoMef.GetCompatibleHypothesis()
102     for hyp in listHyp:
103         print hyp
104         
105     print "Algo name: ", algoMef.GetName()
106     print "Algo ID  : ", algoMef.GetId()
107
108
109     # ---- add hypothesis to shape
110
111     print "-------------------------- compute mesh"
112     ret = mesh.Compute()
113     print  "Compute Mesh .... ", 
114     print ret
115     log = mesh.GetLog(0); # no erase trace
116     #for linelog in log:
117     #    print linelog
118
119     print "------------ INFORMATION ABOUT MESH ------------"
120     
121     print "Number of nodes    : ", mesh.NbNodes()
122     print "Number of edges    : ", mesh.NbEdges()
123     print "Number of faces    : ", mesh.NbFaces()
124     print "Number of triangles: ", mesh.NbTriangles()
125
126     return mesh