Salome HOME
[PY3] 2to3 results
[modules/smesh.git] / src / SMESH_SWIG / batchmode_mefisto.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2016  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, or (at your option) any later version.
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
24 import os
25 import re
26
27 import batchmode_salome
28 import batchmode_geompy
29 from . import batchmode_smesh
30 from salome.StdMeshers import StdMeshersBuilder
31
32 smesh = batchmode_smesh.smesh
33 smesh.SetCurrentStudy(batchmode_salome.myStudy)
34
35 def CreateMesh (theFileName, area, len = None, nbseg = None):
36     
37     if not(os.path.isfile(theFileName)) or re.search("\.brep$", theFileName) is None :
38         print("Incorrect file name !")
39         return
40
41     if (len is None) and (nbseg is None):
42         print("Define length or number of segments !")
43         return
44
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 !")
47         return
48
49     
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")
53
54
55     # ---- SMESH
56     print("-------------------------- create mesh")
57     mesh = smesh.Mesh(shape_mesh)
58       
59     print("-------------------------- create Hypothesis")
60     if (len is not None):
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())
67     
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())
75
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())
83        
84     else:
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())
91               
92     
93     print("-------------------------- Regular_1D")
94     listHyp = algoReg.GetCompatibleHypothesis()
95     for hyp in listHyp:
96         print(hyp)
97     
98     print("Algo name: ", algoReg.GetName())
99     print("Algo ID  : ", algoReg.GetId())
100    
101     print("-------------------------- MEFISTO_2D")
102     listHyp = algoMef.GetCompatibleHypothesis()
103     for hyp in listHyp:
104         print(hyp)
105         
106     print("Algo name: ", algoMef.GetName())
107     print("Algo ID  : ", algoMef.GetId())
108
109
110     # ---- add hypothesis to shape
111
112     print("-------------------------- compute mesh")
113     ret = mesh.Compute()
114     print("Compute Mesh .... ", end=' ') 
115     print(ret)
116     log = mesh.GetLog(0); # no erase trace
117     #for linelog in log:
118     #    print linelog
119
120     print("------------ INFORMATION ABOUT MESH ------------")
121     
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())
126
127     return mesh