Salome HOME
Porting to Python 2.6 - add coding page specification for Python scripts
[modules/smesh.git] / src / SMESH_SWIG / SMESH_test.py
1 #! /usr/bin/python
2 #  -*- coding: iso-8859-1 -*-
3 #  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
4 #
5 #  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
6 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
7 #
8 #  This library is free software; you can redistribute it and/or
9 #  modify it under the terms of the GNU Lesser General Public
10 #  License as published by the Free Software Foundation; either
11 #  version 2.1 of the License.
12 #
13 #  This library is distributed in the hope that it will be useful,
14 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
15 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 #  Lesser General Public License for more details.
17 #
18 #  You should have received a copy of the GNU Lesser General Public
19 #  License along with this library; if not, write to the Free Software
20 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21 #
22 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
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 box = salome.IDToObject(idb)
61 mesh = smesh.Mesh(box, "Meshbox")
62
63 print "-------------------------- add hypothesis to box"
64
65 algo_1 = mesh.Segment(box)
66 hyp = algo_1.LocalLength(100)
67 print hyp.GetName()
68 print hyp.GetId()
69 print hyp.GetLength()
70
71 algo_2 = mesh.Triangle(smesh.MEFISTO, box)
72 hyp = algo_2.MaxElementArea(5000)
73 print hyp.GetName()
74 print hyp.GetId()
75 print hyp.GetMaxElementArea()
76
77 smesh.SetName(algo_2.GetSubMesh(), "SubMeshBox")
78
79
80 print "-------------------------- add hypothesis to edge"
81
82 edge = salome.IDToObject(ide)
83
84 algo_3 = mesh.Segment(edge)
85 hyp = algo_3.LocalLength(100)
86 print hyp.GetName()
87 print hyp.GetId()
88 print hyp.GetLength()
89
90 smesh.SetName(algo_3.GetSubMesh(), "SubMeshEdge")
91
92
93 print "-------------------------- compute face"
94
95 face = salome.IDToObject(idf)
96
97 ret = mesh.Compute(face)
98 print ret
99 log = mesh.GetLog(0) # 0 - GetLog without ClearLog after, else if 1 - ClearLog after
100 for a in log:
101     print "-------"
102     ii = 0
103     ir = 0
104     comType = a.commandType
105     if comType == 0:
106         for i in range(a.number):
107             ind = a.indexes[ii]
108             ii = ii+1
109             r1 = a.coords[ir]
110             ir = ir+1
111             r2 = a.coords[ir]
112             ir = ir+1
113             r3 = a.coords[ir]
114             ir = ir+1
115             print "AddNode %i - %g %g %g" % (ind, r1, r2, r3)
116     elif comType == 1:
117         for i in range(a.number):
118             ind = a.indexes[ii]
119             ii = ii+1
120             i1 = a.indexes[ii]
121             ii = ii+1
122             i2 = a.indexes[ii]
123             ii = ii+1
124             print "AddEdge %i - %i %i" % (ind, i1, i2)
125     elif comType == 2:
126         for i in range(a.number):
127             ind = a.indexes[ii]
128             ii = ii+1
129             i1 = a.indexes[ii]
130             ii = ii+1
131             i2 = a.indexes[ii]
132             ii = ii+1
133             i3 = a.indexes[ii]
134             #ii = ii+1
135             print "AddTriangle %i - %i %i %i" % (ind, i1, i2, i3)