Back to index

salome-geom  6.5.0
Functions
GEOM_Spanner Namespace Reference

Functions

def MakeSpanner
 MakeSpanner #############.

Function Documentation

def GEOM_Spanner.MakeSpanner (   geompy,
  math,
  isBlocksTest = 0,
  isMeshTest = 0,
  smesh = None 
)

MakeSpanner #############.

Definition at line 35 of file GEOM_Spanner.py.

00035 
00036 def MakeSpanner (geompy, math, isBlocksTest = 0, isMeshTest = 0, smesh = None):
00037 
00038   ### Variables ###
00039 
00040   th = 4.0
00041 
00042   ### BlocksOp ###
00043 
00044   BlocksOp = geompy.BlocksOp
00045 
00046   ### Basic points and directions ###
00047 
00048   p0  = geompy.MakeVertex(0., 0., 0.)
00049   pth = geompy.MakeVertex(0., 0., th)
00050 
00051   vx = geompy.MakeVectorDXDYDZ(1., 0., 0.)
00052   vy = geompy.MakeVectorDXDYDZ(0., 1., 0.)
00053   vz = geompy.MakeVectorDXDYDZ(0., 0., 1.)
00054 
00055   vxy = geompy.MakeVectorDXDYDZ(1., 1., 0.)
00056 
00057   ### Block 1 ###
00058 
00059   p_10_0  = geompy.MakeVertex(10.,  0., 0.)
00060   p_10_25 = geompy.MakeVertex(10., 25., 0.)
00061   p_0_35  = geompy.MakeVertex( 0., 35., 0.)
00062   p_0_10  = geompy.MakeVertex( 0., 10., 0.)
00063 
00064   Face11 = geompy.MakeQuad4Vertices(p_10_0, p_10_25, p_0_10, p_0_35);
00065   id_face11 = geompy.addToStudy(Face11, "1 Face for Block 1")
00066 
00067   Face12 = geompy.MakeTranslationTwoPoints(Face11, p0, pth)
00068   id_face12 = geompy.addToStudy(Face12, "2 Face for Block 1")
00069 
00070   Block1 = geompy.MakeHexa2Faces(Face11, Face12)
00071   id_block1 = geompy.addToStudy(Block1, "Block 1")
00072 
00073   ### Block 2 ###
00074 
00075   p_15_0  = geompy.MakeVertex(15.,  0., 0.)
00076   p_15_20 = geompy.MakeVertex(15., 20., 0.)
00077 
00078   Edge21 = geompy.MakeEdge(p_15_0, p_15_20)
00079   id_edge21 = geompy.addToStudy(Edge21, "1 Edge for Block 2")
00080 
00081   Edge22 = geompy.GetEdge(Block1, p_10_0, p_10_25)
00082   id_edge22 = geompy.addToStudy(Edge22, "2 Edge for Block 2")
00083 
00084   Face21 = geompy.MakeQuad2Edges(Edge21, Edge22);
00085   id_face21 = geompy.addToStudy(Face21, "1 Face for Block 2")
00086 
00087   Face22 = geompy.MakeTranslationTwoPoints(Face21, p0, pth)
00088   id_face22 = geompy.addToStudy(Face22, "2 Face for Block 2")
00089 
00090   Block2 = geompy.MakeHexa2Faces(Face21, Face22)
00091   id_block2 = geompy.addToStudy(Block2, "Block 2")
00092 
00093   ### Block 3 ###
00094 
00095   p_15_10_1 = geompy.MakeVertex(15., 10., 1.)
00096 
00097   Face31 = geompy.GetFaceNearPoint(Block2, p_15_10_1)
00098   id_face31 = geompy.addToStudy(Face31, "1 Face for Block 3")
00099 
00100   Prism1 = geompy.MakePrismVecH(Face31, vx, 5);
00101   id_prism1 = geompy.addToStudy(Prism1, "Prism to be Block 3")
00102 
00103   nbFaces = geompy.ShapesOp.NumberOfFaces(Prism1)
00104   if nbFaces == 6:
00105     print "Prism 1 is a hexahedral solid"
00106   else:
00107     print "Prism 1 is not a hexahedral solid"
00108 
00109   Prism1_faces = geompy.SubShapeAllSortedCentres(Prism1, geompy.ShapeType["FACE"])
00110   ii = 1
00111   for aFace in  Prism1_faces:
00112     name = geompy.SubShapeName(aFace, Prism1)
00113     Id_Face = geompy.addToStudyInFather(Prism1, aFace, name)
00114     ii = ii + 1
00115 
00116   Block3 = geompy.MakeHexa(Prism1_faces[0], Prism1_faces[1],
00117                            Prism1_faces[2], Prism1_faces[3],
00118                            Prism1_faces[4], Prism1_faces[5]);
00119   id_block3 = geompy.addToStudy(Block3, "Block 3")
00120 
00121   ### Block 4 ###
00122 
00123   Face41 = geompy.GetOppositeFace(Block3, Face31)
00124   id_face41 = geompy.addToStudy(Face41, "1 Face for Block 4")
00125 
00126   p_25_5  = geompy.MakeVertex(25.,  5., 0.)
00127   p_25_20 = geompy.MakeVertex(25., 20., 0.)
00128 
00129   Edge41 = geompy.MakeEdge(p_25_5, p_25_20)
00130   id_edge41 = geompy.addToStudy(Edge41, "1 Edge for Block 4")
00131 
00132   p_25_5_2  = geompy.MakeVertex(25.,  5., th)
00133   p_25_20_2 = geompy.MakeVertex(25., 20., th)
00134 
00135   Edge42 = geompy.MakeEdge(p_25_5_2, p_25_20_2)
00136   id_edge42 = geompy.addToStudy(Edge42, "2 Edge for Block 4")
00137 
00138   Edge43 = geompy.MakeEdge(p_25_5, p_25_5_2)
00139   id_edge43 = geompy.addToStudy(Edge43, "3 Edge for Block 4")
00140 
00141   Edge44 = geompy.MakeEdge(p_25_20, p_25_20_2)
00142   id_edge44 = geompy.addToStudy(Edge44, "4 Edge for Block 4")
00143 
00144   Face42 = geompy.MakeQuad(Edge41, Edge42, Edge43, Edge44)
00145   id_face42 = geompy.addToStudy(Face42, "2 Face for Block 4")
00146 
00147   Block4 = geompy.MakeHexa2Faces(Face41, Face42)
00148   id_block4 = geompy.addToStudy(Block4, "Block 4")
00149 
00150   ### Block 5 ###
00151 
00152   p_25_30   = geompy.MakeVertex(25., 30., 0.)
00153   p_25_30_1 = geompy.MakeVertex(25., 30., 1)
00154   axis_rot = geompy.MakeVector(p_25_30, p_25_30_1)
00155 
00156   Face51 = Face42
00157   Face52 = geompy.MakeRotation(Face51, axis_rot, math.pi/2.)
00158   id_face52 = geompy.addToStudy(Face52, "2 Face for Block 5")
00159 
00160   Block5 = geompy.MakeHexa2Faces(Face51, Face52)
00161   id_block5 = geompy.addToStudy(Block5, "Block 5")
00162 
00163   ### Compound of blocks 1 - 4 ###
00164 
00165   Comp1234 = geompy.MakeCompound([Block1, Block2, Block3, Block4])
00166   Glue1234 = geompy.MakeGlueFaces(Comp1234, 1e-5)
00167   id_glue1234 = geompy.addToStudy(Glue1234, "Glue 1234")
00168 
00169   plane_mirror = geompy.MakePlane(p_25_30, vxy, 100.)
00170   #id_plane_mirror = geompy.addToStudy(plane_mirror, "Plane for mirror")
00171 
00172   Mirror1 = geompy.MakeMirrorByPlane(Glue1234, plane_mirror)
00173   id_mirror1 = geompy.addToStudy(Mirror1, "Mirror 1")
00174 
00175   ### The second end ###
00176 
00177   p_18_0 = geompy.MakeVertex(18., 0., 0.)
00178   p_20_0 = geompy.MakeVertex(20., 0., 0.)
00179   p_40_0 = geompy.MakeVertex(40., 0., 0.)
00180 
00181   Edge1s = geompy.MakeEdge(p_20_0, p_40_0)
00182   id_edge1s = geompy.addToStudy(Edge1s, "1 Edge for Block 1s")
00183 
00184   Edge2s = geompy.MakeRotation(Edge1s, vz, math.pi/12.)
00185   id_edge2s = geompy.addToStudy(Edge2s, "2 Edge for Block 1s")
00186 
00187   p_18_0_r = geompy.MakeRotation(p_18_0, vz, math.pi/24.)
00188   p_20_0_r = geompy.MakeRotation(p_20_0, vz, math.pi/12.)
00189   p_40_0_r = geompy.MakeRotation(p_40_0, vz, math.pi/12.)
00190 
00191   Edge3s = geompy.MakeEdge(p_40_0, p_40_0_r)
00192   id_edge3s = geompy.addToStudy(Edge3s, "3 Edge for Block 1s")
00193 
00194   Edge4s = geompy.MakeArc(p_20_0, p_18_0_r, p_20_0_r)
00195   id_edge4s = geompy.addToStudy(Edge4s, "4 Edge for Block 1s")
00196 
00197   Face1s = geompy.MakeQuad(Edge1s, Edge2s, Edge3s, Edge4s)
00198   id_face1s = geompy.addToStudy(Face1s, "1 Face for Block 1s")
00199 
00200   Block1s = geompy.MakePrismVecH(Face1s, vz, th);
00201   id_block1s = geompy.addToStudy(Block1s, "Block 1s")
00202 
00203   p_30_0_1 = geompy.MakeVertex(30., 0., 1.)
00204 
00205   Face2s = geompy.GetFaceNearPoint(Block1s, p_30_0_1)
00206   id_face2s = geompy.addToStudy(Face2s, "2 Face of Block 1s")
00207 
00208   f2s_ind = geompy.LocalOp.GetSubShapeIndex(Block1s, Face2s)
00209 
00210   Block1s_tr1 = geompy.MakeMultiTransformation1D(Block1s, f2s_ind, 0, 24)
00211   id_block1s_tr1 = geompy.addToStudy(Block1s_tr1, "Multi-transformed Block 1s")
00212 
00213   p_60_150_0 = geompy.MakeVertex(60., -150., 0.)
00214   Gear = geompy.MakeTranslationTwoPoints(Block1s_tr1, p0, p_60_150_0)
00215   id_gear = geompy.addToStudy(Gear, "Gear")
00216 
00217   ### Link two parts ###
00218 
00219   ### Linking Block 1 ###
00220 
00221   p_55_0_1 = geompy.MakeVertex(55., 0., 1.)
00222   p_55_110_1 = geompy.MakeVertex(55., -110., 1.)
00223 
00224   Face11l = geompy.GetFaceNearPoint(Block5, p_55_0_1)
00225   id_face11l = geompy.addToStudy(Face11l, "1 Face for Linking Block 1")
00226 
00227   Face12l = geompy.GetFaceNearPoint(Gear, p_55_110_1)
00228   id_face12l = geompy.addToStudy(Face12l, "2 Face for Linking Block 1")
00229 
00230   Block1l = geompy.MakeHexa2Faces(Face11l, Face12l)
00231   id_block1l = geompy.addToStudy(Block1l, "Linking Block 1")
00232 
00233   ### Linking Block 2 ###
00234 
00235   p_25_0_1 = geompy.MakeVertex(25., 0., 1.)
00236   p_45_110_1 = geompy.MakeVertex(45., -110., 1.)
00237 
00238   Face21l = geompy.GetFaceNearPoint(Block4, p_25_0_1)
00239   id_face21l = geompy.addToStudy(Face21l, "1 Face for Linking Block 2")
00240 
00241   Face22l = geompy.GetFaceNearPoint(Gear, p_45_110_1)
00242   id_face22l = geompy.addToStudy(Face22l, "2 Face for Linking Block 2")
00243 
00244   Block2l = geompy.MakeHexa2Faces(Face21l, Face22l)
00245   id_block2l = geompy.addToStudy(Block2l, "Linking Block 2")
00246 
00247   ### Linking Block 3 ###
00248 
00249   p_55_30_1 = geompy.MakeVertex(55., 30., 1.)
00250   p_65_110_1 = geompy.MakeVertex(65., -110., 1.)
00251 
00252   Face31l = geompy.GetFaceNearPoint(Mirror1, p_55_30_1)
00253   id_face31l = geompy.addToStudy(Face31l, "1 Face for Linking Block 3")
00254 
00255   Face32l = geompy.GetFaceNearPoint(Gear, p_65_110_1)
00256   id_face32l = geompy.addToStudy(Face32l, "2 Face for Linking Block 3")
00257 
00258   Block3l = geompy.MakeHexa2Faces(Face31l, Face32l)
00259   id_block3l = geompy.addToStudy(Block3l, "Linking Block 3")
00260 
00261   ### Handle ###
00262 
00263   CompLB = geompy.MakeCompound([Block1l, Block2l, Block3l])
00264   Handle = geompy.MakeGlueFaces(CompLB, 1e-5)
00265   id_handle = geompy.addToStudy(Handle, "Handle")
00266 
00267   Block1h = geompy.GetBlockNearPoint(Handle, p_45_110_1)
00268   id_block1h = geompy.addToStudyInFather(Handle, Block1h, "Block 1 of Handle")
00269 
00270   Block2h = geompy.GetBlockNearPoint(Handle, p_65_110_1)
00271   id_block2h = geompy.addToStudyInFather(Handle, Block2h, "Block 2 of Handle")
00272 
00273   Face11h = geompy.GetFaceByNormale(Block1h, vx)
00274   id_face11h = geompy.addToStudyInFather(Block1h, Face11h, "Face 1")
00275 
00276   Face12h = geompy.GetOppositeFace(Block1h, Face11h)
00277   id_face12h = geompy.addToStudyInFather(Block1h, Face12h, "Face 2")
00278 
00279   Face21h = geompy.GetFaceByNormale(Block2h, vx)
00280   id_face21h = geompy.addToStudyInFather(Block2h, Face21h, "Face 1")
00281 
00282   Face22h = geompy.GetOppositeFace(Block2h, Face21h)
00283   id_face22h = geompy.addToStudyInFather(Block2h, Face22h, "Face 2")
00284 
00285   Block3h = BlocksOp.GetBlockByParts(Handle, [Face11h, Face21h])
00286   if BlocksOp.IsDone() == 0:
00287     Block3h = BlocksOp.GetBlockByParts(Handle, [Face11h, Face22h])
00288     if BlocksOp.IsDone() == 0:
00289         Block3h = BlocksOp.GetBlockByParts(Handle, [Face12h, Face21h])
00290         if BlocksOp.IsDone() == 0:
00291             Block3h = BlocksOp.GetBlockByParts(Handle, [Face12h, Face22h])
00292   if BlocksOp.IsDone() == 0:
00293     print "ERROR: BlocksOp.GetBlockByParts() failed : ", BlocksOp.GetErrorCode()
00294   else:
00295     id_block3h = geompy.addToStudyInFather(Handle, Block3h, "Block 3 of Handle")
00296 
00297   ### The whole shape ###
00298 
00299   CompALL = geompy.MakeCompound([Glue1234, Block5, Mirror1, Handle, Gear])
00300   Spanner = geompy.MakeGlueFaces(CompALL, 1e-5)
00301   id_glueALL = geompy.addToStudy(Spanner, "The Spanner")
00302 
00303   ### Check the Spanner ###
00304 
00305   isCompOfBlocks6 = BlocksOp.CheckCompoundOfBlocks(Spanner)
00306   if isCompOfBlocks6 == 0:
00307     print "Spanner is not a compound of hexahedral solids"
00308   else:
00309     print "Spanner is a compound of hexahedral solids"
00310 
00311   if isBlocksTest == 1:
00312 
00313     print "##################### Test More #####################"
00314 
00315     ### Get Blocks 4 and 5 from the spanner ###
00316 
00317     Face42_sp = geompy.GetFaceByEdges(Spanner, Edge41, Edge42)
00318     id_face42_sp = geompy.addToStudyInFather(Spanner, Face42_sp, "Face 4_2")
00319 
00320     Blocks_f4_sp = geompy.GetBlocksByParts(Spanner, [Face42_sp])
00321 
00322     isMRot2D = 0
00323 
00324     for aBlock in Blocks_f4_sp:
00325       name = geompy.SubShapeName(aBlock, Spanner)
00326       Id_block = geompy.addToStudyInFather(Spanner, aBlock, name)
00327 
00328       f42_sp_ind = geompy.LocalOp.GetSubShapeIndex(aBlock, Face42_sp)
00329 
00330       Face_5_horiz = geompy.GetFaceByNormale(aBlock, vz)
00331       f_5_horiz_ind = geompy.LocalOp.GetSubShapeIndex(aBlock, Face_5_horiz)
00332 
00333       MRot = None
00334       is2Dok = True
00335       try:
00336         MRot = geompy.MakeMultiTransformation2D(aBlock, f42_sp_ind, 0, 3, f_5_horiz_ind, 0, 5)
00337       except:
00338         is2Dok = False
00339       if is2Dok and MRot is not None:
00340         isMRot2D = 1
00341         p_z100 = geompy.MakeVertex(0., 0., 100.)
00342         MRot_tr = geompy.MakeTranslationTwoPoints(MRot, p0, p_z100)
00343         id_MRot_tr = geompy.addToStudy(MRot_tr, "Multi-rotated block 5")
00344 
00345     if isMRot2D == 0:
00346       print "2D Multi Transformation failed"
00347 
00348     ### Get one face of the Gear ###
00349 
00350     p_20_0_tr   = geompy.MakeTranslationTwoPoints(p_20_0  , p0, p_60_150_0)
00351     p_20_0_r_tr = geompy.MakeTranslationTwoPoints(p_20_0_r, p0, p_60_150_0)
00352     p_40_0_tr   = geompy.MakeTranslationTwoPoints(p_40_0  , p0, p_60_150_0)
00353     p_40_0_r_tr = geompy.MakeTranslationTwoPoints(p_40_0_r, p0, p_60_150_0)
00354 
00355     Face_g_1 = geompy.GetFaceByPoints(Gear, p_20_0_tr, p_20_0_r_tr, p_40_0_tr, p_40_0_r_tr)
00356     id_face_g_1 = geompy.addToStudyInFather(Gear, Face_g_1, "Face of Gear by four points")
00357 
00358     edgesNb = geompy.ShapesOp.NumberOfEdges(Face_g_1)
00359     print "Face of Gear has ", edgesNb, " edges"
00360 
00361     Face_g_1_tr = geompy.MakeTranslationTwoPoints(Face_g_1, p0, pth)
00362     id_face_g_1_tr = geompy.addToStudyInFather(Gear, Face_g_1_tr, "Face of Gear by four points, translated")
00363 
00364     ### equivalent of Block1s, but made as block
00365 
00366     Block_new = geompy.MakeHexa2Faces(Face_g_1, Face_g_1_tr)
00367     id_block_new = geompy.addToStudy(Block_new, "Block New")
00368 
00369   if isMeshTest == 1 and smesh is not None:
00370 
00371     print "##################### Build Mesh #####################"
00372 
00373 
00374     # ---- add a middle block of spanner handle in study
00375 
00376     p_45_0_1 = geompy.MakeVertex(45., 0., 1.)
00377     BlockMh = geompy.GetBlockNearPoint(Spanner, p_45_0_1)
00378     id_blockMh = geompy.addToStudyInFather(Spanner, BlockMh, "Middle Block of Spanner Handle")
00379 
00380     # ---- add the top face of the middle block in study
00381 
00382     FaceTop = geompy.GetFaceByNormale(BlockMh, vz)
00383     id_facetop = geompy.addToStudyInFather(BlockMh, FaceTop, "Top Face")
00384 
00385     # ---- add long edges of the top face in study
00386 
00387     FaceTop_edges = geompy.SubShapeAllSortedCentres(FaceTop, geompy.ShapeType["EDGE"])
00388     Edge1 = FaceTop_edges[0]
00389     Edge2 = FaceTop_edges[3]
00390     Id_Edge1 = geompy.addToStudyInFather(FaceTop, Edge1, "Edge 1")
00391     Id_Edge2 = geompy.addToStudyInFather(FaceTop, Edge2, "Edge 2")
00392 
00393     print "-------------------------- Algorithm and Hypothesis"
00394 
00395     print "---- Init a Mesh with the Spanner"
00396 
00397     mesh = smesh.Mesh(Spanner, "Meshed Spanner")
00398 
00399     print "-------------------------- add hypothesis to Spanner"
00400 
00401     print "-------------------------- NumberOfSegments"
00402     algoReg = mesh.Segment()
00403     listHyp = algoReg.GetCompatibleHypothesis()
00404     for hyp in listHyp:
00405       print hyp
00406     print algoReg.GetName()
00407     print algoReg.GetId()
00408     algoReg.SetName("Regular_1D")
00409 
00410 
00411     hypNbSeg3 = algoReg.NumberOfSegments(3)
00412     print hypNbSeg3.GetName()
00413     print hypNbSeg3.GetId()
00414     print hypNbSeg3.GetNumberOfSegments()
00415     smesh.SetName(hypNbSeg3, "NumberOfSegments_3")
00416 
00417     print "-------------------------- Quadrangle_2D"
00418 
00419     algoQuad = mesh.Quadrangle()
00420     listHyp = algoQuad.GetCompatibleHypothesis()
00421     for hyp in listHyp:
00422         print hyp
00423     print algoQuad.GetName()
00424     print algoQuad.GetId()
00425     algoQuad.SetName("Quadrangle_2D")
00426 
00427     print "-------------------------- add hypothesis to the Middle Block"
00428 
00429     print "-------------------------- LocalLength"
00430     algoRegMb = mesh.Segment(BlockMh)
00431     hypLen1 = algoRegMb.LocalLength(10)
00432     print hypLen1.GetName()
00433     print hypLen1.GetId()
00434     print hypLen1.GetLength()
00435     smesh.SetName(hypLen1, "Local_Length_10")
00436 
00437     print "-------------------------- add hypothesis to the long edges of the Top Face of the Middle Block"
00438 
00439     algoRegE1 = mesh.Segment(Edge1)
00440     hypPropE1 = algoRegE1.Propagation()
00441     print hypPropE1.GetName()
00442     print hypPropE1.GetId()
00443     smesh.SetName(hypPropE1, "Propagation hypothesis")
00444     smesh.SetName(algoRegE1.GetSubMesh(), "SubMesh Edge 1 of Top Face")
00445 
00446     algoRegE2 = mesh.Segment(Edge2)
00447     hypPropE2 = algoRegE2.Propagation()
00448     print hypPropE2.GetName()
00449     print hypPropE2.GetId()
00450     smesh.SetName(hypPropE2, "Propagation hypothesis")
00451     smesh.SetName(algoRegE2.GetSubMesh(), "SubMesh Edge 2 of Top Face")
00452 
00453     print "-------------------------- compute the mesh"
00454     mesh.Compute()
00455 
00456     print "Information about the Mesh:"
00457     print "Number of nodes       : ", mesh.NbNodes()
00458     print "Number of edges       : ", mesh.NbEdges()
00459     print "Number of faces       : ", mesh.NbFaces()
00460     print "Number of triangles   : ", mesh.NbTriangles()
00461     print "Number of quadrangles : ", mesh.NbQuadrangles()
00462     print "Number of volumes     : ", mesh.NbVolumes()
00463     print "Number of tetrahedrons: ", mesh.NbTetras()
00464 
00465   return Spanner