1 # GEOM GEOM_SWIG : binding of C++ implementaion with Python
3 # Copyright (C) 2003 CEA
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License.
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 # File : GEOM_Spanner.py
24 # Author : Julia DOROVSKIKH
28 # ! Please, if you edit this example file, update also
29 # ! GEOM_SRC/doc/salome/gui/GEOM/input/tui_test_spanner.doc
30 # ! as some sequences of symbols from this example are used during
31 # ! documentation generation to identify certain places of this file
33 ############# MakeSpanner #############
35 def MakeSpanner (geompy, math, isBlocksTest = 0, isMeshTest = 0, smesh = None):
43 BlocksOp = geompy.BlocksOp
45 ### Basic points and directions ###
47 p0 = geompy.MakeVertex(0., 0., 0.)
48 pth = geompy.MakeVertex(0., 0., th)
50 vx = geompy.MakeVectorDXDYDZ(1., 0., 0.)
51 vy = geompy.MakeVectorDXDYDZ(0., 1., 0.)
52 vz = geompy.MakeVectorDXDYDZ(0., 0., 1.)
54 vxy = geompy.MakeVectorDXDYDZ(1., 1., 0.)
58 p_10_0 = geompy.MakeVertex(10., 0., 0.)
59 p_10_25 = geompy.MakeVertex(10., 25., 0.)
60 p_0_35 = geompy.MakeVertex( 0., 35., 0.)
61 p_0_10 = geompy.MakeVertex( 0., 10., 0.)
63 Face11 = geompy.MakeQuad4Vertices(p_10_0, p_10_25, p_0_10, p_0_35);
64 id_face11 = geompy.addToStudy(Face11, "1 Face for Block 1")
66 Face12 = geompy.MakeTranslationTwoPoints(Face11, p0, pth)
67 id_face12 = geompy.addToStudy(Face12, "2 Face for Block 1")
69 Block1 = geompy.MakeHexa2Faces(Face11, Face12)
70 id_block1 = geompy.addToStudy(Block1, "Block 1")
74 p_15_0 = geompy.MakeVertex(15., 0., 0.)
75 p_15_20 = geompy.MakeVertex(15., 20., 0.)
77 Edge21 = geompy.MakeEdge(p_15_0, p_15_20)
78 id_edge21 = geompy.addToStudy(Edge21, "1 Edge for Block 2")
80 Edge22 = geompy.GetEdge(Block1, p_10_0, p_10_25)
81 id_edge22 = geompy.addToStudy(Edge22, "2 Edge for Block 2")
83 Face21 = geompy.MakeQuad2Edges(Edge21, Edge22);
84 id_face21 = geompy.addToStudy(Face21, "1 Face for Block 2")
86 Face22 = geompy.MakeTranslationTwoPoints(Face21, p0, pth)
87 id_face22 = geompy.addToStudy(Face22, "2 Face for Block 2")
89 Block2 = geompy.MakeHexa2Faces(Face21, Face22)
90 id_block2 = geompy.addToStudy(Block2, "Block 2")
94 p_15_10_1 = geompy.MakeVertex(15., 10., 1.)
96 Face31 = geompy.GetFaceNearPoint(Block2, p_15_10_1)
97 id_face31 = geompy.addToStudy(Face31, "1 Face for Block 3")
99 Prism1 = geompy.MakePrismVecH(Face31, vx, 5);
100 id_prism1 = geompy.addToStudy(Prism1, "Prism to be Block 3")
102 nbFaces = geompy.ShapesOp.NumberOfFaces(Prism1)
104 print "Prism 1 is a hexahedral solid"
106 print "Prism 1 is not a hexahedral solid"
108 Prism1_faces = geompy.SubShapeAllSorted(Prism1, geompy.ShapeType["FACE"])
110 for aFace in Prism1_faces:
111 name = geompy.SubShapeName(aFace, Prism1)
112 Id_Face = geompy.addToStudyInFather(Prism1, aFace, name)
115 Block3 = geompy.MakeHexa(Prism1_faces[0], Prism1_faces[1],
116 Prism1_faces[2], Prism1_faces[3],
117 Prism1_faces[4], Prism1_faces[5]);
118 id_block3 = geompy.addToStudy(Block3, "Block 3")
122 Face41 = geompy.GetOppositeFace(Block3, Face31)
123 id_face41 = geompy.addToStudy(Face41, "1 Face for Block 4")
125 p_25_5 = geompy.MakeVertex(25., 5., 0.)
126 p_25_20 = geompy.MakeVertex(25., 20., 0.)
128 Edge41 = geompy.MakeEdge(p_25_5, p_25_20)
129 id_edge41 = geompy.addToStudy(Edge41, "1 Edge for Block 4")
131 p_25_5_2 = geompy.MakeVertex(25., 5., th)
132 p_25_20_2 = geompy.MakeVertex(25., 20., th)
134 Edge42 = geompy.MakeEdge(p_25_5_2, p_25_20_2)
135 id_edge42 = geompy.addToStudy(Edge42, "2 Edge for Block 4")
137 Edge43 = geompy.MakeEdge(p_25_5, p_25_5_2)
138 id_edge43 = geompy.addToStudy(Edge43, "3 Edge for Block 4")
140 Edge44 = geompy.MakeEdge(p_25_20, p_25_20_2)
141 id_edge44 = geompy.addToStudy(Edge44, "4 Edge for Block 4")
143 Face42 = geompy.MakeQuad(Edge41, Edge42, Edge43, Edge44)
144 id_face42 = geompy.addToStudy(Face42, "2 Face for Block 4")
146 Block4 = geompy.MakeHexa2Faces(Face41, Face42)
147 id_block4 = geompy.addToStudy(Block4, "Block 4")
151 p_25_30 = geompy.MakeVertex(25., 30., 0.)
152 p_25_30_1 = geompy.MakeVertex(25., 30., 1)
153 axis_rot = geompy.MakeVector(p_25_30, p_25_30_1)
156 Face52 = geompy.MakeRotation(Face51, axis_rot, math.pi/2.)
157 id_face52 = geompy.addToStudy(Face52, "2 Face for Block 5")
159 Block5 = geompy.MakeHexa2Faces(Face51, Face52)
160 id_block5 = geompy.addToStudy(Block5, "Block 5")
162 ### Compound of blocks 1 - 4 ###
164 Comp1234 = geompy.MakeCompound([Block1, Block2, Block3, Block4])
165 Glue1234 = geompy.MakeGlueFaces(Comp1234, 1e-5)
166 id_glue1234 = geompy.addToStudy(Glue1234, "Glue 1234")
168 plane_mirror = geompy.MakePlane(p_25_30, vxy, 100.)
169 #id_plane_mirror = geompy.addToStudy(plane_mirror, "Plane for mirror")
171 Mirror1 = geompy.MakeMirrorByPlane(Glue1234, plane_mirror)
172 id_mirror1 = geompy.addToStudy(Mirror1, "Mirror 1")
174 ### The second end ###
176 p_18_0 = geompy.MakeVertex(18., 0., 0.)
177 p_20_0 = geompy.MakeVertex(20., 0., 0.)
178 p_40_0 = geompy.MakeVertex(40., 0., 0.)
180 Edge1s = geompy.MakeEdge(p_20_0, p_40_0)
181 id_edge1s = geompy.addToStudy(Edge1s, "1 Edge for Block 1s")
183 Edge2s = geompy.MakeRotation(Edge1s, vz, math.pi/12.)
184 id_edge2s = geompy.addToStudy(Edge2s, "2 Edge for Block 1s")
186 p_18_0_r = geompy.MakeRotation(p_18_0, vz, math.pi/24.)
187 p_20_0_r = geompy.MakeRotation(p_20_0, vz, math.pi/12.)
188 p_40_0_r = geompy.MakeRotation(p_40_0, vz, math.pi/12.)
190 Edge3s = geompy.MakeEdge(p_40_0, p_40_0_r)
191 id_edge3s = geompy.addToStudy(Edge3s, "3 Edge for Block 1s")
193 Edge4s = geompy.MakeArc(p_20_0, p_18_0_r, p_20_0_r)
194 id_edge4s = geompy.addToStudy(Edge4s, "4 Edge for Block 1s")
196 Face1s = geompy.MakeQuad(Edge1s, Edge2s, Edge3s, Edge4s)
197 id_face1s = geompy.addToStudy(Face1s, "1 Face for Block 1s")
199 Block1s = geompy.MakePrismVecH(Face1s, vz, th);
200 id_block1s = geompy.addToStudy(Block1s, "Block 1s")
202 p_30_0_1 = geompy.MakeVertex(30., 0., 1.)
204 Face2s = geompy.GetFaceNearPoint(Block1s, p_30_0_1)
205 id_face2s = geompy.addToStudy(Face2s, "2 Face of Block 1s")
207 f2s_ind = geompy.LocalOp.GetSubShapeIndex(Block1s, Face2s)
209 Block1s_tr1 = geompy.MakeMultiTransformation1D(Block1s, f2s_ind, 0, 24)
210 id_block1s_tr1 = geompy.addToStudy(Block1s_tr1, "Multi-transformed Block 1s")
212 p_60_150_0 = geompy.MakeVertex(60., -150., 0.)
213 Gear = geompy.MakeTranslationTwoPoints(Block1s_tr1, p0, p_60_150_0)
214 id_gear = geompy.addToStudy(Gear, "Gear")
216 ### Link two parts ###
218 ### Linking Block 1 ###
220 p_55_0_1 = geompy.MakeVertex(55., 0., 1.)
221 p_55_110_1 = geompy.MakeVertex(55., -110., 1.)
223 Face11l = geompy.GetFaceNearPoint(Block5, p_55_0_1)
224 id_face11l = geompy.addToStudy(Face11l, "1 Face for Linking Block 1")
226 Face12l = geompy.GetFaceNearPoint(Gear, p_55_110_1)
227 id_face12l = geompy.addToStudy(Face12l, "2 Face for Linking Block 1")
229 Block1l = geompy.MakeHexa2Faces(Face11l, Face12l)
230 id_block1l = geompy.addToStudy(Block1l, "Linking Block 1")
232 ### Linking Block 2 ###
234 p_25_0_1 = geompy.MakeVertex(25., 0., 1.)
235 p_45_110_1 = geompy.MakeVertex(45., -110., 1.)
237 Face21l = geompy.GetFaceNearPoint(Block4, p_25_0_1)
238 id_face21l = geompy.addToStudy(Face21l, "1 Face for Linking Block 2")
240 Face22l = geompy.GetFaceNearPoint(Gear, p_45_110_1)
241 id_face22l = geompy.addToStudy(Face22l, "2 Face for Linking Block 2")
243 Block2l = geompy.MakeHexa2Faces(Face21l, Face22l)
244 id_block2l = geompy.addToStudy(Block2l, "Linking Block 2")
246 ### Linking Block 3 ###
248 p_55_30_1 = geompy.MakeVertex(55., 30., 1.)
249 p_65_110_1 = geompy.MakeVertex(65., -110., 1.)
251 Face31l = geompy.GetFaceNearPoint(Mirror1, p_55_30_1)
252 id_face31l = geompy.addToStudy(Face31l, "1 Face for Linking Block 3")
254 Face32l = geompy.GetFaceNearPoint(Gear, p_65_110_1)
255 id_face32l = geompy.addToStudy(Face32l, "2 Face for Linking Block 3")
257 Block3l = geompy.MakeHexa2Faces(Face31l, Face32l)
258 id_block3l = geompy.addToStudy(Block3l, "Linking Block 3")
262 CompLB = geompy.MakeCompound([Block1l, Block2l, Block3l])
263 Handle = geompy.MakeGlueFaces(CompLB, 1e-5)
264 id_handle = geompy.addToStudy(Handle, "Handle")
266 Block1h = geompy.GetBlockNearPoint(Handle, p_45_110_1)
267 id_block1h = geompy.addToStudyInFather(Handle, Block1h, "Block 1 of Handle")
269 Block2h = geompy.GetBlockNearPoint(Handle, p_65_110_1)
270 id_block2h = geompy.addToStudyInFather(Handle, Block2h, "Block 2 of Handle")
272 Face11h = geompy.GetFaceByNormale(Block1h, vx)
273 id_face11h = geompy.addToStudyInFather(Block1h, Face11h, "Face 1")
275 Face12h = geompy.GetOppositeFace(Block1h, Face11h)
276 id_face12h = geompy.addToStudyInFather(Block1h, Face12h, "Face 2")
278 Face21h = geompy.GetFaceByNormale(Block2h, vx)
279 id_face21h = geompy.addToStudyInFather(Block2h, Face21h, "Face 1")
281 Face22h = geompy.GetOppositeFace(Block2h, Face21h)
282 id_face22h = geompy.addToStudyInFather(Block2h, Face22h, "Face 2")
284 Block3h = BlocksOp.GetBlockByParts(Handle, [Face11h, Face21h])
285 if BlocksOp.IsDone() == 0:
286 Block3h = BlocksOp.GetBlockByParts(Handle, [Face11h, Face22h])
287 if BlocksOp.IsDone() == 0:
288 Block3h = BlocksOp.GetBlockByParts(Handle, [Face12h, Face21h])
289 if BlocksOp.IsDone() == 0:
290 Block3h = BlocksOp.GetBlockByParts(Handle, [Face12h, Face22h])
291 if BlocksOp.IsDone() == 0:
292 print "ERROR: BlocksOp.GetBlockByParts() failed : ", BlocksOp.GetErrorCode()
294 id_block3h = geompy.addToStudyInFather(Handle, Block3h, "Block 3 of Handle")
296 ### The whole shape ###
298 CompALL = geompy.MakeCompound([Glue1234, Block5, Mirror1, Handle, Gear])
299 Spanner = geompy.MakeGlueFaces(CompALL, 1e-5)
300 id_glueALL = geompy.addToStudy(Spanner, "The Spanner")
302 ### Check the Spanner ###
304 isCompOfBlocks6 = BlocksOp.CheckCompoundOfBlocks(Spanner)
305 if isCompOfBlocks6 == 0:
306 print "Spanner is not a compound of hexahedral solids"
308 print "Spanner is a compound of hexahedral solids"
310 if isBlocksTest == 1:
312 print "##################### Test More #####################"
314 ### Get Blocks 4 and 5 from the spanner ###
316 Face42_sp = geompy.GetFaceByEdges(Spanner, Edge41, Edge42)
317 id_face42_sp = geompy.addToStudyInFather(Spanner, Face42_sp, "Face 4_2")
319 Blocks_f4_sp = geompy.GetBlocksByParts(Spanner, [Face42_sp])
323 for aBlock in Blocks_f4_sp:
324 name = geompy.SubShapeName(aBlock, Spanner)
325 Id_block = geompy.addToStudyInFather(Spanner, aBlock, name)
327 f42_sp_ind = geompy.LocalOp.GetSubShapeIndex(aBlock, Face42_sp)
329 Face_5_horiz = geompy.GetFaceByNormale(aBlock, vz)
330 f_5_horiz_ind = geompy.LocalOp.GetSubShapeIndex(aBlock, Face_5_horiz)
335 MRot = geompy.MakeMultiTransformation2D(aBlock, f42_sp_ind, 0, 3, f_5_horiz_ind, 0, 5)
338 if is2Dok and MRot is not None:
340 p_z100 = geompy.MakeVertex(0., 0., 100.)
341 MRot_tr = geompy.MakeTranslationTwoPoints(MRot, p0, p_z100)
342 id_MRot_tr = geompy.addToStudy(MRot_tr, "Multi-rotated block 5")
345 print "2D Multi Transformation failed"
347 ### Get one face of the Gear ###
349 p_20_0_tr = geompy.MakeTranslationTwoPoints(p_20_0 , p0, p_60_150_0)
350 p_20_0_r_tr = geompy.MakeTranslationTwoPoints(p_20_0_r, p0, p_60_150_0)
351 p_40_0_tr = geompy.MakeTranslationTwoPoints(p_40_0 , p0, p_60_150_0)
352 p_40_0_r_tr = geompy.MakeTranslationTwoPoints(p_40_0_r, p0, p_60_150_0)
354 Face_g_1 = geompy.GetFaceByPoints(Gear, p_20_0_tr, p_20_0_r_tr, p_40_0_tr, p_40_0_r_tr)
355 id_face_g_1 = geompy.addToStudyInFather(Gear, Face_g_1, "Face of Gear by four points")
357 edgesNb = geompy.ShapesOp.NumberOfEdges(Face_g_1)
358 print "Face of Gear has ", edgesNb, " edges"
360 Face_g_1_tr = geompy.MakeTranslationTwoPoints(Face_g_1, p0, pth)
361 id_face_g_1_tr = geompy.addToStudyInFather(Gear, Face_g_1_tr, "Face of Gear by four points, translated")
363 ### equivalent of Block1s, but made as block
365 Block_new = geompy.MakeHexa2Faces(Face_g_1, Face_g_1_tr)
366 id_block_new = geompy.addToStudy(Block_new, "Block New")
368 if isMeshTest == 1 and smesh is not None:
370 print "##################### Build Mesh #####################"
373 # ---- add a middle block of spanner handle in study
375 p_45_0_1 = geompy.MakeVertex(45., 0., 1.)
376 BlockMh = geompy.GetBlockNearPoint(Spanner, p_45_0_1)
377 id_blockMh = geompy.addToStudyInFather(Spanner, BlockMh, "Middle Block of Spanner Handle")
379 # ---- add the top face of the middle block in study
381 FaceTop = geompy.GetFaceByNormale(BlockMh, vz)
382 id_facetop = geompy.addToStudyInFather(BlockMh, FaceTop, "Top Face")
384 # ---- add long edges of the top face in study
386 FaceTop_edges = geompy.SubShapeAllSorted(FaceTop, geompy.ShapeType["EDGE"])
387 Edge1 = FaceTop_edges[0]
388 Edge2 = FaceTop_edges[3]
389 Id_Edge1 = geompy.addToStudyInFather(FaceTop, Edge1, "Edge 1")
390 Id_Edge2 = geompy.addToStudyInFather(FaceTop, Edge2, "Edge 2")
392 print "-------------------------- Algorithm and Hypothesis"
394 print "---- Init a Mesh with the Spanner"
396 mesh = smesh.Mesh(Spanner, "Meshed Spanner")
398 print "-------------------------- add hypothesis to Spanner"
400 print "-------------------------- NumberOfSegments"
401 algoReg = mesh.Segment()
402 listHyp = algoReg.GetCompatibleHypothesis()
405 print algoReg.GetName()
406 print algoReg.GetId()
407 algoReg.SetName("Regular_1D")
410 hypNbSeg3 = algoReg.NumberOfSegments(3)
411 print hypNbSeg3.GetName()
412 print hypNbSeg3.GetId()
413 print hypNbSeg3.GetNumberOfSegments()
414 smesh.SetName(hypNbSeg3, "NumberOfSegments_3")
416 print "-------------------------- Quadrangle_2D"
418 algoQuad = mesh.Quadrangle()
419 listHyp = algoQuad.GetCompatibleHypothesis()
422 print algoQuad.GetName()
423 print algoQuad.GetId()
424 algoQuad.SetName("Quadrangle_2D")
426 print "-------------------------- add hypothesis to the Middle Block"
428 print "-------------------------- LocalLength"
429 algoRegMb = mesh.Segment(BlockMh)
430 hypLen1 = algoRegMb.LocalLength(10)
431 print hypLen1.GetName()
432 print hypLen1.GetId()
433 print hypLen1.GetLength()
434 smesh.SetName(hypLen1, "Local_Length_10")
436 print "-------------------------- add hypothesis to the long edges of the Top Face of the Middle Block"
438 algoRegE1 = mesh.Segment(Edge1)
439 hypPropE1 = algoRegE1.Propagation()
440 print hypPropE1.GetName()
441 print hypPropE1.GetId()
442 smesh.SetName(hypPropE1, "Propagation hypothesis")
443 smesh.SetName(algoRegE1.GetSubMesh(), "SubMesh Edge 1 of Top Face")
445 algoRegE2 = mesh.Segment(Edge2)
446 hypPropE2 = algoRegE2.Propagation()
447 print hypPropE2.GetName()
448 print hypPropE2.GetId()
449 smesh.SetName(hypPropE2, "Propagation hypothesis")
450 smesh.SetName(algoRegE2.GetSubMesh(), "SubMesh Edge 2 of Top Face")
452 print "-------------------------- compute the mesh"
455 print "Information about the Mesh:"
456 print "Number of nodes : ", mesh.NbNodes()
457 print "Number of edges : ", mesh.NbEdges()
458 print "Number of faces : ", mesh.NbFaces()
459 print "Number of triangles : ", mesh.NbTriangles()
460 print "Number of quadrangles : ", mesh.NbQuadrangles()
461 print "Number of volumes : ", mesh.NbVolumes()
462 print "Number of tetrahedrons: ", mesh.NbTetras()