Salome HOME
DCQ : Merge with Ecole_Ete_a6.
[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 salome
26 import geompy
27
28 import StdMeshers
29
30 geom  = salome.lcc.FindOrLoadComponent("FactoryServer", "GEOM")
31 smesh = salome.lcc.FindOrLoadComponent("FactoryServer", "SMESH")
32
33 geom.GetCurrentStudy(salome.myStudy._get_StudyId())
34 smesh.SetCurrentStudy(salome.myStudy)
35
36 ShapeTypeCompSolid = 1
37 ShapeTypeSolid = 2
38 ShapeTypeShell = 3
39 ShapeTypeFace = 4
40 ShapeTypeWire = 5
41 ShapeTypeEdge = 6
42 ShapeTypeVertex = 7
43
44 # ---- define a box
45
46 box = geompy.MakeBox(0., 0., 0., 100., 200., 300.)
47 idbox = geompy.addToStudy(box,"box")
48
49 # ---- add first face of box in study
50
51 subShapeList=geompy.SubShapeAll(box,ShapeTypeFace)
52 face=subShapeList[0]
53 name = geompy.SubShapeName( face._get_Name(), box._get_Name() )
54 print name
55 idface=geompy.addToStudyInFather(box,face,name)
56
57 # ---- add shell from box  in study
58
59 subShellList=geompy.SubShapeAll(box,ShapeTypeShell)
60 shell = subShellList[0]
61 name = geompy.SubShapeName( shell._get_Name(), box._get_Name() )
62 print name
63 idshell=geompy.addToStudyInFather(box,shell,name)
64
65 # ---- add first edge of face in study
66
67 edgeList = geompy.SubShapeAll(face,ShapeTypeEdge)
68 edge=edgeList[0];
69 name = geompy.SubShapeName( edge._get_Name(), face._get_Name() )
70 print name
71 idedge=geompy.addToStudyInFather(face,edge,name)
72
73 # ---- launch SMESH
74 smeshgui = salome.ImportComponentGUI("SMESH")
75 smeshgui.Init(salome.myStudyId);
76
77 # ---- create Hypothesis
78
79 print "-------------------------- create Hypothesis"
80 print "-------------------------- LocalLength"
81
82 hypLen1 = smesh.CreateHypothesis("LocalLength", "libStdMeshersEngine.so")
83 hypLen1.SetLength(100)
84 print hypLen1.GetName()
85 print hypLen1.GetId()
86 print hypLen1.GetLength()
87
88 idlength = salome.ObjectToID(hypLen1) 
89 smeshgui.SetName(idlength, "Local_Length_100");
90
91 print "-------------------------- NumberOfSegments"
92 hypNbSeg1 = smesh.CreateHypothesis("NumberOfSegments", "libStdMeshersEngine.so")
93 hypNbSeg1.SetNumberOfSegments(7)
94 print hypNbSeg1.GetName()
95 print hypNbSeg1.GetId()
96 print hypNbSeg1.GetNumberOfSegments()
97
98 idseg = salome.ObjectToID(hypNbSeg1) 
99 smeshgui.SetName(idseg, "NumberOfSegments_7");
100
101 print "-------------------------- MaxElementArea"
102 hypArea1 = smesh.CreateHypothesis("MaxElementArea", "libStdMeshersEngine.so")
103 hypArea1.SetMaxElementArea(2500)
104 print hypArea1.GetName()
105 print hypArea1.GetId()
106 print hypArea1.GetMaxElementArea()
107
108 idarea1 = salome.ObjectToID(hypArea1)
109 smeshgui.SetName(idarea1, "MaxElementArea_2500");
110
111 print "-------------------------- MaxElementArea"
112 hypArea2 = smesh.CreateHypothesis("MaxElementArea", "libStdMeshersEngine.so")
113 hypArea2.SetMaxElementArea(500)
114 print hypArea2.GetName()
115 print hypArea2.GetId()
116 print hypArea2.GetMaxElementArea()
117
118 idarea2 = salome.ObjectToID(hypArea2)
119 smeshgui.SetName(idarea2, "MaxElementArea_500");
120
121 print "-------------------------- Regular_1D"
122 algoReg = smesh.CreateHypothesis("Regular_1D", "libStdMeshersEngine.so")
123 listHyp=algoReg.GetCompatibleHypothesis()
124 for hyp in listHyp:
125     print hyp
126 print algoReg.GetName()
127 print algoReg.GetId()
128
129 idreg = salome.ObjectToID(algoReg)
130 smeshgui.SetName(idreg, "Regular_1D");
131
132 print "-------------------------- MEFISTO_2D"
133 algoMef = smesh.CreateHypothesis("MEFISTO_2D", "libStdMeshersEngine.so")
134 listHyp=algoMef.GetCompatibleHypothesis()
135 for hyp in listHyp:
136     print hyp
137 print algoMef.GetName()
138 print algoMef.GetId()
139
140 idmef = salome.ObjectToID(algoMef)
141 smeshgui.SetName(idmef, "MEFISTO_2D");
142
143 # ---- Init a Mesh with the box
144
145 box=salome.IDToObject(idbox)
146 mesh=smesh.CreateMesh(box)
147
148 idmesh = salome.ObjectToID(mesh)
149 smeshgui.SetName(idmesh, "Meshbox");
150
151 # ---- add hypothesis to box
152 print "-------------------------- add hypothesis to box"
153 mesh.AddHypothesis(box,algoReg)
154 mesh.AddHypothesis(box,hypNbSeg1)
155 mesh.AddHypothesis(box,algoMef)
156 mesh.AddHypothesis(box,hypArea1)
157
158 # ---- add hypothesis to edge
159
160 print "-------------------------- add hypothesis to edge"
161 edge=salome.IDToObject(idedge)
162 submesh = mesh.GetSubMesh(edge, "SubMeshEdge")
163 mesh.AddHypothesis(edge , algoReg)
164 mesh.AddHypothesis(edge, hypLen1)
165
166 print "-------------------------- add hypothesis to face"
167 face = salome.IDToObject(idface)
168 submesh =mesh.GetSubMesh(face, "SubMeshFace")
169 mesh.AddHypothesis(face,hypArea2)
170
171 salome.sg.updateObjBrowser(1);