Salome HOME
Merge tag 'V8_3_0a2' into ngr/python3_dev
[modules/smesh.git] / src / SMESH_SWIG / SMESH_flight_skin.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 # Triangulation of the skin of the geometry from a Brep representing a plane
25 # Hypothesis and algorithms for the mesh generation are global
26 #
27 import os
28 import salome
29 salome.salome_init()
30 import GEOM
31 from salome.geom import geomBuilder
32 geompy = geomBuilder.New(salome.myStudy)
33
34 import SMESH, SALOMEDS
35 from salome.smesh import smeshBuilder
36 smesh =  smeshBuilder.New(salome.myStudy)
37
38
39 # ---------------------------- GEOM --------------------------------------
40
41 # import a BRep
42 #before running this script, please be sure about
43 #the path the file fileName
44
45 filePath = os.environ["DATA_DIR"]
46 filePath = filePath + "/Shapes/Brep/"
47
48 filename = "flight_solid.brep"
49 filename = filePath + filename
50
51 shape = geompy.Import(filename, "BREP")
52 idShape = geompy.addToStudy(shape, "flight")
53
54 print("Analysis of the geometry flight :")
55 subShellList = geompy.SubShapeAll(shape, geompy.ShapeType["SHELL"])
56 subFaceList  = geompy.SubShapeAll(shape, geompy.ShapeType["FACE"])
57 subEdgeList  = geompy.SubShapeAll(shape, geompy.ShapeType["EDGE"])
58
59 print("number of Shells in flight : ", len(subShellList))
60 print("number of Faces  in flight : ", len(subFaceList))
61 print("number of Edges  in flight : ", len(subEdgeList))
62
63
64 ### ---------------------------- SMESH --------------------------------------
65 smesh.SetCurrentStudy(salome.myStudy)
66
67 # ---- init a Mesh with the shell
68 shape_mesh = salome.IDToObject( idShape )
69
70 mesh = smesh.Mesh(shape_mesh, "MeshFlight")
71
72
73 # ---- set Hypothesis and Algorithm
74
75 print("-------------------------- LocalLength")
76
77 lengthOfSegments = 0.3
78
79 regular1D = mesh.Segment()
80 hypLength = regular1D.LocalLength(lengthOfSegments)
81 print(hypLength.GetName())
82 print(hypLength.GetId())
83 print(hypLength.GetLength())
84 smesh.SetName(hypLength, "LocalLength_" + str(lengthOfSegments))
85
86 print("-------------------------- LengthFromEdges")
87
88 mefisto2D = mesh.Triangle()
89 hypLengthFromEdge = mefisto2D.LengthFromEdges()
90 print(hypLengthFromEdge.GetName())
91 print(hypLengthFromEdge.GetId())
92 smesh.SetName(hypLengthFromEdge,"LengthFromEdge")
93
94 print("-------------------------- compute the skin flight")
95 ret = mesh.Compute()
96 print(ret)
97 if ret != 0:
98     log = mesh.GetLog(0) # no erase trace
99     for linelog in log:
100         print(linelog)
101     print("Information about the Mesh_mechanic_tetra:")
102     print("Number of nodes      : ", mesh.NbNodes())
103     print("Number of edges      : ", mesh.NbEdges())
104     print("Number of faces      : ", mesh.NbFaces())
105     print("Number of triangles  : ", mesh.NbTriangles())
106     print("Number of volumes    : ", mesh.NbVolumes())
107 else:
108     print("probleme when computing the mesh")
109
110 salome.sg.updateObjBrowser(True)