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