1 # Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
18 # See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
22 # File : SMESH_test1.py
30 #import SMESH_BasicHypothesis_idl
34 geom = salome.lcc.FindOrLoadComponent("FactoryServer", "GEOM")
35 myBuilder = salome.myStudy.NewBuilder()
38 smeshgui = salome.ImportComponentGUI("SMESH")
39 smeshgui.Init(salome.myStudyId);
41 ShapeTypeCompSolid = 1
51 box = geompy.MakeBox(0., 0., 0., 100., 200., 300.)
52 idbox = geompy.addToStudy(box,"box")
54 # ---- add first face of box in study
56 subShapeList=geompy.SubShapeAll(box,ShapeTypeFace)
58 name = geompy.SubShapeName( face._get_Name(), box._get_Name() )
60 idface=geompy.addToStudyInFather(box,face,name)
62 # ---- add shell from box in study
64 subShellList=geompy.SubShapeAll(box,ShapeTypeShell)
65 shell = subShellList[0]
66 name = geompy.SubShapeName( shell._get_Name(), box._get_Name() )
68 idshell=geompy.addToStudyInFather(box,shell,name)
70 # ---- add first edge of face in study
72 edgeList = geompy.SubShapeAll(face,ShapeTypeEdge)
74 name = geompy.SubShapeName( edge._get_Name(), face._get_Name() )
76 idedge=geompy.addToStudyInFather(face,edge,name)
78 # ---- launch SMESH, init a Mesh with the box
82 idmesh = smeshgui.AddNewMesh( salome.orb.object_to_string(mesh) )
83 smeshgui.SetName(idmesh, "Meshbox");
84 smeshgui.SetShape(idbox, idmesh);
86 # ---- create Hypothesis
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()
95 print hypLen1.GetLength()
97 idlength = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypLen1) );
98 smeshgui.SetName(idlength, "Local_Length_100");
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()
108 idseg = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypNbSeg1) );
109 smeshgui.SetName(idseg, "NumberOfSegments_7");
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()
119 idarea1 = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypArea1) );
120 smeshgui.SetName(idarea1, "MaxElementArea_2500");
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()
130 idarea2 = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypArea2) );
131 smeshgui.SetName(idarea2, "MaxElementArea_500");
133 print "-------------------------- Regular_1D"
134 alg1=gen.CreateHypothesis("Regular_1D")
135 algo1=alg1._narrow(SMESH.SMESH_Algo)
136 listHyp=algo1.GetCompatibleHypothesis()
139 algoReg=alg1._narrow(SMESH.SMESH_Regular_1D)
140 print algoReg.GetName()
141 print algoReg.GetId()
143 idreg = smeshgui.AddNewAlgorithms( salome.orb.object_to_string(algoReg) );
144 smeshgui.SetName(idreg, "Regular_1D");
146 print "-------------------------- MEFISTO_2D"
147 alg2=gen.CreateHypothesis("MEFISTO_2D")
148 algo2=alg2._narrow(SMESH.SMESH_Algo)
149 listHyp=algo2.GetCompatibleHypothesis()
152 algoMef=alg2._narrow(SMESH.SMESH_MEFISTO_2D)
153 print algoMef.GetName()
154 print algoMef.GetId()
156 idmef = smeshgui.AddNewAlgorithms( salome.orb.object_to_string(algoMef) );
157 smeshgui.SetName(idmef, "MEFISTO_2D");
159 # ---- add hypothesis to edge
161 print "-------------------------- add hypothesis to edge"
162 edge=salome.IDToObject(idedge)
163 submesh=mesh.GetElementsOnShape(edge)
164 ret=mesh.AddHypothesis(edge,algoReg)
166 ret=mesh.AddHypothesis(edge,hypLen1)
169 idsm1 = smeshgui.AddSubMeshOnShape( idmesh,
171 salome.orb.object_to_string(submesh),
173 smeshgui.SetName(idsm1, "SubMeshEdge")
174 smeshgui.SetAlgorithms( idsm1, idreg );
175 smeshgui.SetHypothesis( idsm1, idlength );
177 print "-------------------------- add hypothesis to face"
178 face=salome.IDToObject(idface)
179 submesh=mesh.GetElementsOnShape(face)
180 ret=mesh.AddHypothesis(face,hypArea2)
183 idsm2 = smeshgui.AddSubMeshOnShape( idmesh,
185 salome.orb.object_to_string(submesh),
187 smeshgui.SetName(idsm2, "SubMeshFace")
188 smeshgui.SetHypothesis( idsm2, idarea2 );
190 # ---- add hypothesis to box
192 print "-------------------------- add hypothesis to box"
193 box=salome.IDToObject(idbox)
194 submesh=mesh.GetElementsOnShape(box)
195 ret=mesh.AddHypothesis(box,algoReg)
197 ret=mesh.AddHypothesis(box,hypNbSeg1)
199 ret=mesh.AddHypothesis(box,algoMef)
201 ret=mesh.AddHypothesis(box,hypArea1)
204 smeshgui.SetAlgorithms( idmesh, idreg );
205 smeshgui.SetHypothesis( idmesh, idseg );
206 smeshgui.SetAlgorithms( idmesh, idmef );
207 smeshgui.SetHypothesis( idmesh, idarea1 );
209 sg.updateObjBrowser(1);