Salome HOME
Update copyright information
[modules/smesh.git] / src / SMESH_SWIG / SMESH_test.py
1 #  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 #
3 #  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 #
6 #  This library is free software; you can redistribute it and/or
7 #  modify it under the terms of the GNU Lesser General Public
8 #  License as published by the Free Software Foundation; either
9 #  version 2.1 of the License.
10 #
11 #  This library is distributed in the hope that it will be useful,
12 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 #  Lesser General Public License for more details.
15 #
16 #  You should have received a copy of the GNU Lesser General Public
17 #  License along with this library; if not, write to the Free Software
18 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 #
20 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #
22 #  SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
23 #  File   : SMESH_test.py
24 #  Module : SMESH
25 #
26 import salome
27 import geompy
28 import smesh
29
30 # ---- define a box
31
32 box = geompy.MakeBox(0., 0., 0., 100., 200., 300.)
33 idb = geompy.addToStudy(box, "box")
34
35 # ---- add first face of box in study
36
37 subShapeList = geompy.SubShapeAll(box, geompy.ShapeType["FACE"])
38 face = subShapeList[0]
39 name = geompy.SubShapeName(face, box)
40 idf = geompy.addToStudyInFather(box, face, name)
41
42 # ---- add shell from box  in study
43
44 subShellList = geompy.SubShapeAll(box, geompy.ShapeType["SHELL"])
45 shell = subShellList[0]
46 name = geompy.SubShapeName(shell, box)
47 ids = geompy.addToStudyInFather(box, shell, name)
48
49 # ---- add first edge of face in study
50
51 edgeList = geompy.SubShapeAll(face, geompy.ShapeType["EDGE"])
52 edge = edgeList[0];
53 name = geompy.SubShapeName(edge, face)
54 ide = geompy.addToStudyInFather(face, edge, name)
55
56 # ---- SMESH
57
58 box = salome.IDToObject(idb)
59 mesh = smesh.Mesh(box, "Meshbox")
60
61 print "-------------------------- add hypothesis to box"
62
63 algo_1 = mesh.Segment(box)
64 hyp = algo_1.LocalLength(100)
65 print hyp.GetName()
66 print hyp.GetId()
67 print hyp.GetLength()
68
69 algo_2 = mesh.Triangle(smesh.MEFISTO, box)
70 hyp = algo_2.MaxElementArea(5000)
71 print hyp.GetName()
72 print hyp.GetId()
73 print hyp.GetMaxElementArea()
74
75 smesh.SetName(algo_2.GetSubMesh(), "SubMeshBox")
76
77
78 print "-------------------------- add hypothesis to edge"
79
80 edge = salome.IDToObject(ide)
81
82 algo_3 = mesh.Segment(edge)
83 hyp = algo_3.LocalLength(100)
84 print hyp.GetName()
85 print hyp.GetId()
86 print hyp.GetLength()
87
88 smesh.SetName(algo_3.GetSubMesh(), "SubMeshEdge")
89
90
91 print "-------------------------- compute face"
92
93 face = salome.IDToObject(idf)
94
95 ret = mesh.Compute(face)
96 print ret
97 log = mesh.GetLog(0) # 0 - GetLog without ClearLog after, else if 1 - ClearLog after
98 for a in log:
99     print "-------"
100     ii = 0
101     ir = 0
102     comType = a.commandType
103     if comType == 0:
104         for i in range(a.number):
105             ind = a.indexes[ii]
106             ii = ii+1
107             r1 = a.coords[ir]
108             ir = ir+1
109             r2 = a.coords[ir]
110             ir = ir+1
111             r3 = a.coords[ir]
112             ir = ir+1
113             print "AddNode %i - %g %g %g" % (ind, r1, r2, r3)
114     elif comType == 1:
115         for i in range(a.number):
116             ind = a.indexes[ii]
117             ii = ii+1
118             i1 = a.indexes[ii]
119             ii = ii+1
120             i2 = a.indexes[ii]
121             ii = ii+1
122             print "AddEdge %i - %i %i" % (ind, i1, i2)
123     elif comType == 2:
124         for i in range(a.number):
125             ind = a.indexes[ii]
126             ii = ii+1
127             i1 = a.indexes[ii]
128             ii = ii+1
129             i2 = a.indexes[ii]
130             ii = ii+1
131             i3 = a.indexes[ii]
132             ii = ii+1
133             print "AddTriangle %i - %i %i %i" % (ind, i1, i2, i3)