]> SALOME platform Git repositories - modules/smesh.git/blob - src/SMESH_SWIG/SMESH_test1.py
Salome HOME
NRI : add LICENCE file
[modules/smesh.git] / src / SMESH_SWIG / SMESH_test1.py
1 #  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
3
4 #  This library is free software; you can redistribute it and/or 
5 #  modify it under the terms of the GNU Lesser General Public 
6 #  License as published by the Free Software Foundation; either 
7 #  version 2.1 of the License. 
8
9 #  This library is distributed in the hope that it will be useful, 
10 #  but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 #  Lesser General Public License for more details. 
13
14 #  You should have received a copy of the GNU Lesser General Public 
15 #  License along with this library; if not, write to the Free Software 
16 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
17
18 #  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
19 #
20 #
21 #
22 #  File   : SMESH_test1.py
23 #  Module : SMESH
24
25 import SMESH
26 import smeshpy
27 import salome
28 from salome import sg
29 import math
30 #import SMESH_BasicHypothesis_idl
31
32 import geompy
33
34 geom = salome.lcc.FindOrLoadComponent("FactoryServer", "GEOM")
35 myBuilder = salome.myStudy.NewBuilder()
36 from geompy import gg
37
38 smeshgui = salome.ImportComponentGUI("SMESH")
39 smeshgui.Init(salome.myStudyId);
40
41 ShapeTypeCompSolid = 1
42 ShapeTypeSolid = 2
43 ShapeTypeShell = 3
44 ShapeTypeFace = 4
45 ShapeTypeWire = 5
46 ShapeTypeEdge = 6
47 ShapeTypeVertex = 7
48
49 # ---- define a box
50
51 box = geompy.MakeBox(0., 0., 0., 100., 200., 300.)
52 idbox = geompy.addToStudy(box,"box")
53
54 # ---- add first face of box in study
55
56 subShapeList=geompy.SubShapeAll(box,ShapeTypeFace)
57 face=subShapeList[0]
58 name = geompy.SubShapeName( face._get_Name(), box._get_Name() )
59 print name
60 idface=geompy.addToStudyInFather(box,face,name)
61
62 # ---- add shell from box  in study
63
64 subShellList=geompy.SubShapeAll(box,ShapeTypeShell)
65 shell = subShellList[0]
66 name = geompy.SubShapeName( shell._get_Name(), box._get_Name() )
67 print name
68 idshell=geompy.addToStudyInFather(box,shell,name)
69
70 # ---- add first edge of face in study
71
72 edgeList = geompy.SubShapeAll(face,ShapeTypeEdge)
73 edge=edgeList[0];
74 name = geompy.SubShapeName( edge._get_Name(), face._get_Name() )
75 print name
76 idedge=geompy.addToStudyInFather(face,edge,name)
77
78 # ---- launch SMESH, init a Mesh with the box
79 gen=smeshpy.smeshpy()
80 mesh=gen.Init(idbox)
81
82 idmesh = smeshgui.AddNewMesh( salome.orb.object_to_string(mesh) )
83 smeshgui.SetName(idmesh, "Meshbox");
84 smeshgui.SetShape(idbox, idmesh);
85
86 # ---- create Hypothesis
87
88 print "-------------------------- create Hypothesis"
89 print "-------------------------- LocalLength"
90 hyp1=gen.CreateHypothesis("LocalLength")
91 hypLen1 = hyp1._narrow(SMESH.SMESH_LocalLength)
92 hypLen1.SetLength(100)
93 print hypLen1.GetName()
94 print hypLen1.GetId()
95 print hypLen1.GetLength()
96
97 idlength = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypLen1) );
98 smeshgui.SetName(idlength, "Local_Length_100");
99
100 print "-------------------------- NumberOfSegments"
101 hyp2=gen.CreateHypothesis("NumberOfSegments")
102 hypNbSeg1=hyp2._narrow(SMESH.SMESH_NumberOfSegments)
103 hypNbSeg1.SetNumberOfSegments(7)
104 print hypNbSeg1.GetName()
105 print hypNbSeg1.GetId()
106 print hypNbSeg1.GetNumberOfSegments()
107
108 idseg = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypNbSeg1) );
109 smeshgui.SetName(idseg, "NumberOfSegments_7");
110
111 print "-------------------------- MaxElementArea"
112 hyp3=gen.CreateHypothesis("MaxElementArea")
113 hypArea1=hyp3._narrow(SMESH.SMESH_MaxElementArea)
114 hypArea1.SetMaxElementArea(2500)
115 print hypArea1.GetName()
116 print hypArea1.GetId()
117 print hypArea1.GetMaxElementArea()
118
119 idarea1 = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypArea1) );
120 smeshgui.SetName(idarea1, "MaxElementArea_2500");
121
122 print "-------------------------- MaxElementArea"
123 hyp3=gen.CreateHypothesis("MaxElementArea")
124 hypArea2=hyp3._narrow(SMESH.SMESH_MaxElementArea)
125 hypArea2.SetMaxElementArea(500)
126 print hypArea2.GetName()
127 print hypArea2.GetId()
128 print hypArea2.GetMaxElementArea()
129
130 idarea2 = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypArea2) );
131 smeshgui.SetName(idarea2, "MaxElementArea_500");
132
133 print "-------------------------- Regular_1D"
134 alg1=gen.CreateHypothesis("Regular_1D")
135 algo1=alg1._narrow(SMESH.SMESH_Algo)
136 listHyp=algo1.GetCompatibleHypothesis()
137 for hyp in listHyp:
138     print hyp
139 algoReg=alg1._narrow(SMESH.SMESH_Regular_1D)
140 print algoReg.GetName()
141 print algoReg.GetId()
142
143 idreg = smeshgui.AddNewAlgorithms( salome.orb.object_to_string(algoReg) );
144 smeshgui.SetName(idreg, "Regular_1D");
145
146 print "-------------------------- MEFISTO_2D"
147 alg2=gen.CreateHypothesis("MEFISTO_2D")
148 algo2=alg2._narrow(SMESH.SMESH_Algo)
149 listHyp=algo2.GetCompatibleHypothesis()
150 for hyp in listHyp:
151     print hyp
152 algoMef=alg2._narrow(SMESH.SMESH_MEFISTO_2D)
153 print algoMef.GetName()
154 print algoMef.GetId()
155
156 idmef = smeshgui.AddNewAlgorithms( salome.orb.object_to_string(algoMef) );
157 smeshgui.SetName(idmef, "MEFISTO_2D");
158
159 # ---- add hypothesis to edge
160
161 print "-------------------------- add hypothesis to edge"
162 edge=salome.IDToObject(idedge)
163 submesh=mesh.GetElementsOnShape(edge)
164 ret=mesh.AddHypothesis(edge,algoReg)
165 print ret
166 ret=mesh.AddHypothesis(edge,hypLen1)
167 print ret
168
169 idsm1 = smeshgui.AddSubMeshOnShape( idmesh,
170                                     idedge,
171                                     salome.orb.object_to_string(submesh),
172                                     ShapeTypeEdge )
173 smeshgui.SetName(idsm1, "SubMeshEdge")
174 smeshgui.SetAlgorithms( idsm1, idreg );
175 smeshgui.SetHypothesis( idsm1, idlength );
176
177 print "-------------------------- add hypothesis to face"
178 face=salome.IDToObject(idface)
179 submesh=mesh.GetElementsOnShape(face)
180 ret=mesh.AddHypothesis(face,hypArea2)
181 print ret
182
183 idsm2 = smeshgui.AddSubMeshOnShape( idmesh,
184                                     idface,
185                                     salome.orb.object_to_string(submesh),
186                                     ShapeTypeFace )
187 smeshgui.SetName(idsm2, "SubMeshFace")
188 smeshgui.SetHypothesis( idsm2, idarea2 );
189
190 # ---- add hypothesis to box
191
192 print "-------------------------- add hypothesis to box"
193 box=salome.IDToObject(idbox)
194 submesh=mesh.GetElementsOnShape(box)
195 ret=mesh.AddHypothesis(box,algoReg)
196 print ret
197 ret=mesh.AddHypothesis(box,hypNbSeg1)
198 print ret
199 ret=mesh.AddHypothesis(box,algoMef)
200 print ret
201 ret=mesh.AddHypothesis(box,hypArea1)
202 print ret
203
204 smeshgui.SetAlgorithms( idmesh, idreg );
205 smeshgui.SetHypothesis( idmesh, idseg );
206 smeshgui.SetAlgorithms( idmesh, idmef );
207 smeshgui.SetHypothesis( idmesh, idarea1 );
208
209 sg.updateObjBrowser(1);