Salome HOME
NRI : Change lGeometryClient by lGEOMClient.
[modules/smesh.git] / src / SMESH_SWIG / SMESH_test1.py
1 import SMESH
2 import smeshpy
3 import salome
4 from salome import sg
5 import math
6 #import SMESH_BasicHypothesis_idl
7
8 import geompy
9
10 geom = salome.lcc.FindOrLoadComponent("FactoryServer", "Geometry")
11 myBuilder = salome.myStudy.NewBuilder()
12 from geompy import gg
13
14 smeshgui = salome.ImportComponentGUI("SMESH")
15 smeshgui.Init(salome.myStudyId);
16
17 ShapeTypeCompSolid = 1
18 ShapeTypeSolid = 2
19 ShapeTypeShell = 3
20 ShapeTypeFace = 4
21 ShapeTypeWire = 5
22 ShapeTypeEdge = 6
23 ShapeTypeVertex = 7
24
25 # ---- define a box
26
27 box = geompy.MakeBox(0., 0., 0., 100., 200., 300.)
28 idbox = geompy.addToStudy(box,"box")
29
30 # ---- add first face of box in study
31
32 subShapeList=geompy.SubShapeAll(box,ShapeTypeFace)
33 face=subShapeList[0]
34 name = geompy.SubShapeName( face._get_Name(), box._get_Name() )
35 print name
36 idface=geompy.addToStudyInFather(box,face,name)
37
38 # ---- add shell from box  in study
39
40 subShellList=geompy.SubShapeAll(box,ShapeTypeShell)
41 shell = subShellList[0]
42 name = geompy.SubShapeName( shell._get_Name(), box._get_Name() )
43 print name
44 idshell=geompy.addToStudyInFather(box,shell,name)
45
46 # ---- add first edge of face in study
47
48 edgeList = geompy.SubShapeAll(face,ShapeTypeEdge)
49 edge=edgeList[0];
50 name = geompy.SubShapeName( edge._get_Name(), face._get_Name() )
51 print name
52 idedge=geompy.addToStudyInFather(face,edge,name)
53
54 # ---- launch SMESH, init a Mesh with the box
55 gen=smeshpy.smeshpy()
56 mesh=gen.Init(idbox)
57
58 idmesh = smeshgui.AddNewMesh( salome.orb.object_to_string(mesh) )
59 smeshgui.SetName(idmesh, "Meshbox");
60 smeshgui.SetShape(idbox, idmesh);
61
62 # ---- create Hypothesis
63
64 print "-------------------------- create Hypothesis"
65 print "-------------------------- LocalLength"
66 hyp1=gen.CreateHypothesis("LocalLength")
67 hypLen1 = hyp1._narrow(SMESH.SMESH_LocalLength)
68 hypLen1.SetLength(100)
69 print hypLen1.GetName()
70 print hypLen1.GetId()
71 print hypLen1.GetLength()
72
73 idlength = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypLen1) );
74 smeshgui.SetName(idlength, "Local_Length_100");
75
76 print "-------------------------- NumberOfSegments"
77 hyp2=gen.CreateHypothesis("NumberOfSegments")
78 hypNbSeg1=hyp2._narrow(SMESH.SMESH_NumberOfSegments)
79 hypNbSeg1.SetNumberOfSegments(7)
80 print hypNbSeg1.GetName()
81 print hypNbSeg1.GetId()
82 print hypNbSeg1.GetNumberOfSegments()
83
84 idseg = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypNbSeg1) );
85 smeshgui.SetName(idseg, "NumberOfSegments_7");
86
87 print "-------------------------- MaxElementArea"
88 hyp3=gen.CreateHypothesis("MaxElementArea")
89 hypArea1=hyp3._narrow(SMESH.SMESH_MaxElementArea)
90 hypArea1.SetMaxElementArea(2500)
91 print hypArea1.GetName()
92 print hypArea1.GetId()
93 print hypArea1.GetMaxElementArea()
94
95 idarea1 = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypArea1) );
96 smeshgui.SetName(idarea1, "MaxElementArea_2500");
97
98 print "-------------------------- MaxElementArea"
99 hyp3=gen.CreateHypothesis("MaxElementArea")
100 hypArea2=hyp3._narrow(SMESH.SMESH_MaxElementArea)
101 hypArea2.SetMaxElementArea(500)
102 print hypArea2.GetName()
103 print hypArea2.GetId()
104 print hypArea2.GetMaxElementArea()
105
106 idarea2 = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypArea2) );
107 smeshgui.SetName(idarea2, "MaxElementArea_500");
108
109 print "-------------------------- Regular_1D"
110 alg1=gen.CreateHypothesis("Regular_1D")
111 algo1=alg1._narrow(SMESH.SMESH_Algo)
112 listHyp=algo1.GetCompatibleHypothesis()
113 for hyp in listHyp:
114     print hyp
115 algoReg=alg1._narrow(SMESH.SMESH_Regular_1D)
116 print algoReg.GetName()
117 print algoReg.GetId()
118
119 idreg = smeshgui.AddNewAlgorithms( salome.orb.object_to_string(algoReg) );
120 smeshgui.SetName(idreg, "Regular_1D");
121
122 print "-------------------------- MEFISTO_2D"
123 alg2=gen.CreateHypothesis("MEFISTO_2D")
124 algo2=alg2._narrow(SMESH.SMESH_Algo)
125 listHyp=algo2.GetCompatibleHypothesis()
126 for hyp in listHyp:
127     print hyp
128 algoMef=alg2._narrow(SMESH.SMESH_MEFISTO_2D)
129 print algoMef.GetName()
130 print algoMef.GetId()
131
132 idmef = smeshgui.AddNewAlgorithms( salome.orb.object_to_string(algoMef) );
133 smeshgui.SetName(idmef, "MEFISTO_2D");
134
135 # ---- add hypothesis to edge
136
137 print "-------------------------- add hypothesis to edge"
138 edge=salome.IDToObject(idedge)
139 submesh=mesh.GetElementsOnShape(edge)
140 ret=mesh.AddHypothesis(edge,algoReg)
141 print ret
142 ret=mesh.AddHypothesis(edge,hypLen1)
143 print ret
144
145 idsm1 = smeshgui.AddSubMeshOnShape( idmesh,
146                                     idedge,
147                                     salome.orb.object_to_string(submesh),
148                                     ShapeTypeEdge )
149 smeshgui.SetName(idsm1, "SubMeshEdge")
150 smeshgui.SetAlgorithms( idsm1, idreg );
151 smeshgui.SetHypothesis( idsm1, idlength );
152
153 print "-------------------------- add hypothesis to face"
154 face=salome.IDToObject(idface)
155 submesh=mesh.GetElementsOnShape(face)
156 ret=mesh.AddHypothesis(face,hypArea2)
157 print ret
158
159 idsm2 = smeshgui.AddSubMeshOnShape( idmesh,
160                                     idface,
161                                     salome.orb.object_to_string(submesh),
162                                     ShapeTypeFace )
163 smeshgui.SetName(idsm2, "SubMeshFace")
164 smeshgui.SetHypothesis( idsm2, idarea2 );
165
166 # ---- add hypothesis to box
167
168 print "-------------------------- add hypothesis to box"
169 box=salome.IDToObject(idbox)
170 submesh=mesh.GetElementsOnShape(box)
171 ret=mesh.AddHypothesis(box,algoReg)
172 print ret
173 ret=mesh.AddHypothesis(box,hypNbSeg1)
174 print ret
175 ret=mesh.AddHypothesis(box,algoMef)
176 print ret
177 ret=mesh.AddHypothesis(box,hypArea1)
178 print ret
179
180 smeshgui.SetAlgorithms( idmesh, idreg );
181 smeshgui.SetHypothesis( idmesh, idseg );
182 smeshgui.SetAlgorithms( idmesh, idmef );
183 smeshgui.SetHypothesis( idmesh, idarea1 );
184
185 sg.updateObjBrowser(1);