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