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