Salome HOME
correct previous integration (Porting to Python 2.6)
[modules/smesh.git] / src / SMESH_SWIG / SMESH_test.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 #  SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
24 #  File   : SMESH_test.py
25 #  Module : SMESH
26 #
27 import salome
28 import geompy
29 import smesh
30
31 # ---- define a box
32
33 box = geompy.MakeBox(0., 0., 0., 100., 200., 300.)
34 idb = geompy.addToStudy(box, "box")
35
36 # ---- add first face of box in study
37
38 subShapeList = geompy.SubShapeAll(box, geompy.ShapeType["FACE"])
39 face = subShapeList[0]
40 name = geompy.SubShapeName(face, box)
41 idf = geompy.addToStudyInFather(box, face, name)
42
43 # ---- add shell from box  in study
44
45 subShellList = geompy.SubShapeAll(box, geompy.ShapeType["SHELL"])
46 shell = subShellList[0]
47 name = geompy.SubShapeName(shell, box)
48 ids = geompy.addToStudyInFather(box, shell, name)
49
50 # ---- add first edge of face in study
51
52 edgeList = geompy.SubShapeAll(face, geompy.ShapeType["EDGE"])
53 edge = edgeList[0];
54 name = geompy.SubShapeName(edge, face)
55 ide = geompy.addToStudyInFather(face, edge, name)
56
57 # ---- SMESH
58
59 box = salome.IDToObject(idb)
60 mesh = smesh.Mesh(box, "Meshbox")
61
62 print "-------------------------- add hypothesis to box"
63
64 algo_1 = mesh.Segment(box)
65 hyp = algo_1.LocalLength(100)
66 print hyp.GetName()
67 print hyp.GetId()
68 print hyp.GetLength()
69
70 algo_2 = mesh.Triangle(smesh.MEFISTO, box)
71 hyp = algo_2.MaxElementArea(5000)
72 print hyp.GetName()
73 print hyp.GetId()
74 print hyp.GetMaxElementArea()
75
76 smesh.SetName(algo_2.GetSubMesh(), "SubMeshBox")
77
78
79 print "-------------------------- add hypothesis to edge"
80
81 edge = salome.IDToObject(ide)
82
83 algo_3 = mesh.Segment(edge)
84 hyp = algo_3.LocalLength(100)
85 print hyp.GetName()
86 print hyp.GetId()
87 print hyp.GetLength()
88
89 smesh.SetName(algo_3.GetSubMesh(), "SubMeshEdge")
90
91
92 print "-------------------------- compute face"
93
94 face = salome.IDToObject(idf)
95
96 ret = mesh.Compute(face)
97 print ret
98 log = mesh.GetLog(0) # 0 - GetLog without ClearLog after, else if 1 - ClearLog after
99 for a in log:
100     print "-------"
101     ii = 0
102     ir = 0
103     comType = a.commandType
104     if comType == 0:
105         for i in range(a.number):
106             ind = a.indexes[ii]
107             ii = ii+1
108             r1 = a.coords[ir]
109             ir = ir+1
110             r2 = a.coords[ir]
111             ir = ir+1
112             r3 = a.coords[ir]
113             ir = ir+1
114             print "AddNode %i - %g %g %g" % (ind, r1, r2, r3)
115     elif comType == 1:
116         for i in range(a.number):
117             ind = a.indexes[ii]
118             ii = ii+1
119             i1 = a.indexes[ii]
120             ii = ii+1
121             i2 = a.indexes[ii]
122             ii = ii+1
123             print "AddEdge %i - %i %i" % (ind, i1, i2)
124     elif comType == 2:
125         for i in range(a.number):
126             ind = a.indexes[ii]
127             ii = ii+1
128             i1 = a.indexes[ii]
129             ii = ii+1
130             i2 = a.indexes[ii]
131             ii = ii+1
132             i3 = a.indexes[ii]
133             #ii = ii+1
134             print "AddTriangle %i - %i %i %i" % (ind, i1, i2, i3)