-# GEOM GEOM_SWIG : binding of C++ implementaion with Python
+# -*- coding: iso-8859-1 -*-
+# Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
#
-# Copyright (C) 2003 CEA
+# Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
-# See http://www.salome-platform.org or email : webmaster.salome@opencascade.org
-#
-#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
#
+# GEOM GEOM_SWIG : binding of C++ implementaion with Python
# File : GEOM_Spanner.py
# Author : Julia DOROVSKIKH
# Module : GEOM
# $Header$
-
-def GetFaceNearPoint (geompy, block, pnt):
- anObj = geompy.BlocksOp.GetFaceNearPoint(block, pnt)
- if anObj is None:
- print "GetFaceNearPoint : ", geompy.BlocksOp.GetErrorCode()
- return anObj
-
-def GetOppositeFace (geompy, block, face):
- anObj = geompy.BlocksOp.GetOppositeFace(block, face)
- if anObj is None:
- print "GetOppositeFace : ", geompy.BlocksOp.GetErrorCode()
- return anObj
-
-def GetFaceByNormale (geompy, block, vec):
- anObj = geompy.BlocksOp.GetFaceByNormale(block, vec)
- if anObj is None:
- print "GetFaceByNormale : ", geompy.BlocksOp.GetErrorCode()
- return anObj
-
-def GetBlockNearPoint (geompy, comp, pnt):
- anObj = geompy.BlocksOp.GetBlockNearPoint(comp, pnt)
- if anObj is None:
- print "GetBlockNearPoint : ", geompy.BlocksOp.GetErrorCode()
- return anObj
-
+# ! Please, if you edit this example file, update also
+# ! GEOM_SRC/doc/salome/gui/GEOM/input/tui_test_spanner.doc
+# ! as some sequences of symbols from this example are used during
+# ! documentation generation to identify certain places of this file
############# MakeSpanner #############
-
-def MakeSpanner (salome, geompy, math, isBlocksTest = 0, isMeshTest = 0, smesh = None, hasGUI = 0):
+#
+def MakeSpanner (geompy, math, isBlocksTest = 0, isMeshTest = 0, smesh = None):
### Variables ###
Edge21 = geompy.MakeEdge(p_15_0, p_15_20)
id_edge21 = geompy.addToStudy(Edge21, "1 Edge for Block 2")
- Edge22 = BlocksOp.GetEdge(Block1, p_10_0, p_10_25)
- if Edge22 is None:
- print "BlocksOp.GetEdge(Block1, p_10_0, p_10_25) : ", BlocksOp.GetErrorCode()
+ Edge22 = geompy.GetEdge(Block1, p_10_0, p_10_25)
id_edge22 = geompy.addToStudy(Edge22, "2 Edge for Block 2")
Face21 = geompy.MakeQuad2Edges(Edge21, Edge22);
p_15_10_1 = geompy.MakeVertex(15., 10., 1.)
- Face31 = GetFaceNearPoint(geompy, Block2, p_15_10_1)
+ Face31 = geompy.GetFaceNearPoint(Block2, p_15_10_1)
id_face31 = geompy.addToStudy(Face31, "1 Face for Block 3")
Prism1 = geompy.MakePrismVecH(Face31, vx, 5);
### Block 4 ###
- Face41 = GetOppositeFace(geompy, Block3, Face31)
+ Face41 = geompy.GetOppositeFace(Block3, Face31)
id_face41 = geompy.addToStudy(Face41, "1 Face for Block 4")
p_25_5 = geompy.MakeVertex(25., 5., 0.)
p_30_0_1 = geompy.MakeVertex(30., 0., 1.)
- Face2s = GetFaceNearPoint(geompy, Block1s, p_30_0_1)
+ Face2s = geompy.GetFaceNearPoint(Block1s, p_30_0_1)
id_face2s = geompy.addToStudy(Face2s, "2 Face of Block 1s")
f2s_ind = geompy.LocalOp.GetSubShapeIndex(Block1s, Face2s)
p_55_0_1 = geompy.MakeVertex(55., 0., 1.)
p_55_110_1 = geompy.MakeVertex(55., -110., 1.)
- Face11l = GetFaceNearPoint(geompy, Block5, p_55_0_1)
+ Face11l = geompy.GetFaceNearPoint(Block5, p_55_0_1)
id_face11l = geompy.addToStudy(Face11l, "1 Face for Linking Block 1")
- Face12l = GetFaceNearPoint(geompy, Gear, p_55_110_1)
+ Face12l = geompy.GetFaceNearPoint(Gear, p_55_110_1)
id_face12l = geompy.addToStudy(Face12l, "2 Face for Linking Block 1")
Block1l = geompy.MakeHexa2Faces(Face11l, Face12l)
p_25_0_1 = geompy.MakeVertex(25., 0., 1.)
p_45_110_1 = geompy.MakeVertex(45., -110., 1.)
- Face21l = GetFaceNearPoint(geompy, Block4, p_25_0_1)
+ Face21l = geompy.GetFaceNearPoint(Block4, p_25_0_1)
id_face21l = geompy.addToStudy(Face21l, "1 Face for Linking Block 2")
- Face22l = GetFaceNearPoint(geompy, Gear, p_45_110_1)
+ Face22l = geompy.GetFaceNearPoint(Gear, p_45_110_1)
id_face22l = geompy.addToStudy(Face22l, "2 Face for Linking Block 2")
Block2l = geompy.MakeHexa2Faces(Face21l, Face22l)
p_55_30_1 = geompy.MakeVertex(55., 30., 1.)
p_65_110_1 = geompy.MakeVertex(65., -110., 1.)
- Face31l = GetFaceNearPoint(geompy, Mirror1, p_55_30_1)
+ Face31l = geompy.GetFaceNearPoint(Mirror1, p_55_30_1)
id_face31l = geompy.addToStudy(Face31l, "1 Face for Linking Block 3")
- Face32l = GetFaceNearPoint(geompy, Gear, p_65_110_1)
+ Face32l = geompy.GetFaceNearPoint(Gear, p_65_110_1)
id_face32l = geompy.addToStudy(Face32l, "2 Face for Linking Block 3")
Block3l = geompy.MakeHexa2Faces(Face31l, Face32l)
Handle = geompy.MakeGlueFaces(CompLB, 1e-5)
id_handle = geompy.addToStudy(Handle, "Handle")
- Block1h = GetBlockNearPoint(geompy, Handle, p_45_110_1)
+ Block1h = geompy.GetBlockNearPoint(Handle, p_45_110_1)
id_block1h = geompy.addToStudyInFather(Handle, Block1h, "Block 1 of Handle")
- Block2h = GetBlockNearPoint(geompy, Handle, p_65_110_1)
+ Block2h = geompy.GetBlockNearPoint(Handle, p_65_110_1)
id_block2h = geompy.addToStudyInFather(Handle, Block2h, "Block 2 of Handle")
- Face11h = GetFaceByNormale(geompy, Block1h, vx)
+ Face11h = geompy.GetFaceByNormale(Block1h, vx)
id_face11h = geompy.addToStudyInFather(Block1h, Face11h, "Face 1")
- Face12h = GetOppositeFace(geompy, Block1h, Face11h)
+ Face12h = geompy.GetOppositeFace(Block1h, Face11h)
id_face12h = geompy.addToStudyInFather(Block1h, Face12h, "Face 2")
- Face21h = GetFaceByNormale(geompy, Block2h, vx)
+ Face21h = geompy.GetFaceByNormale(Block2h, vx)
id_face21h = geompy.addToStudyInFather(Block2h, Face21h, "Face 1")
- Face22h = GetOppositeFace(geompy, Block2h, Face21h)
+ Face22h = geompy.GetOppositeFace(Block2h, Face21h)
id_face22h = geompy.addToStudyInFather(Block2h, Face22h, "Face 2")
Block3h = BlocksOp.GetBlockByParts(Handle, [Face11h, Face21h])
### Check the Spanner ###
- isCompOfBlocks6 = BlocksOp.IsCompoundOfBlocks(Spanner, 6, 6)
+ isCompOfBlocks6 = BlocksOp.CheckCompoundOfBlocks(Spanner)
if isCompOfBlocks6 == 0:
print "Spanner is not a compound of hexahedral solids"
else:
### Get Blocks 4 and 5 from the spanner ###
- Face42_sp = BlocksOp.GetFaceByEdges(Spanner, Edge41, Edge42)
- if Face42_sp is None:
- print "BlocksOp.GetFaceByEdges(Spanner, Edge41, Edge42) : ", BlocksOp.GetErrorCode()
+ Face42_sp = geompy.GetFaceByEdges(Spanner, Edge41, Edge42)
id_face42_sp = geompy.addToStudyInFather(Spanner, Face42_sp, "Face 4_2")
- Blocks_f4_sp = BlocksOp.GetBlocksByParts(Spanner, [Face42_sp])
- if Blocks_f4_sp is None:
- print "BlocksOp.GetBlocksByParts() : ", BlocksOp.GetErrorCode()
+ Blocks_f4_sp = geompy.GetBlocksByParts(Spanner, [Face42_sp])
+
+ isMRot2D = 0
for aBlock in Blocks_f4_sp:
name = geompy.SubShapeName(aBlock, Spanner)
f42_sp_ind = geompy.LocalOp.GetSubShapeIndex(aBlock, Face42_sp)
- Face_5_horiz = GetFaceByNormale(geompy, aBlock, vz)
+ Face_5_horiz = geompy.GetFaceByNormale(aBlock, vz)
f_5_horiz_ind = geompy.LocalOp.GetSubShapeIndex(aBlock, Face_5_horiz)
- MRot = geompy.MakeMultiTransformation2D(aBlock, f42_sp_ind, 0, 3, f_5_horiz_ind, 0, 5)
- if MRot is not None:
+ MRot = None
+ is2Dok = True
+ try:
+ MRot = geompy.MakeMultiTransformation2D(aBlock, f42_sp_ind, 0, 3, f_5_horiz_ind, 0, 5)
+ except:
+ is2Dok = False
+ if is2Dok and MRot is not None:
+ isMRot2D = 1
p_z100 = geompy.MakeVertex(0., 0., 100.)
MRot_tr = geompy.MakeTranslationTwoPoints(MRot, p0, p_z100)
id_MRot_tr = geompy.addToStudy(MRot_tr, "Multi-rotated block 5")
- if BlocksOp.IsDone() == 0:
- print "Operation failed"
+ if isMRot2D == 0:
+ print "2D Multi Transformation failed"
### Get one face of the Gear ###
p_40_0_tr = geompy.MakeTranslationTwoPoints(p_40_0 , p0, p_60_150_0)
p_40_0_r_tr = geompy.MakeTranslationTwoPoints(p_40_0_r, p0, p_60_150_0)
- Face_g_1 = BlocksOp.GetFaceByPoints(Gear, p_20_0_tr, p_20_0_r_tr, p_40_0_tr, p_40_0_r_tr)
- if Face_g_1 is None:
- print "BlocksOp.GetFaceByPoints(Gear, ...) : ", BlocksOp.GetErrorCode()
+ Face_g_1 = geompy.GetFaceByPoints(Gear, p_20_0_tr, p_20_0_r_tr, p_40_0_tr, p_40_0_r_tr)
id_face_g_1 = geompy.addToStudyInFather(Gear, Face_g_1, "Face of Gear by four points")
edgesNb = geompy.ShapesOp.NumberOfEdges(Face_g_1)
Block_new = geompy.MakeHexa2Faces(Face_g_1, Face_g_1_tr)
id_block_new = geompy.addToStudy(Block_new, "Block New")
- if isMeshTest == 1:
+ if isMeshTest == 1 and smesh is not None:
print "##################### Build Mesh #####################"
- import StdMeshers
# ---- add a middle block of spanner handle in study
p_45_0_1 = geompy.MakeVertex(45., 0., 1.)
- BlockMh = GetBlockNearPoint(geompy, Spanner, p_45_0_1)
+ BlockMh = geompy.GetBlockNearPoint(Spanner, p_45_0_1)
id_blockMh = geompy.addToStudyInFather(Spanner, BlockMh, "Middle Block of Spanner Handle")
# ---- add the top face of the middle block in study
- FaceTop = GetFaceByNormale(geompy, BlockMh, vz)
+ FaceTop = geompy.GetFaceByNormale(BlockMh, vz)
id_facetop = geompy.addToStudyInFather(BlockMh, FaceTop, "Top Face")
# ---- add long edges of the top face in study
Id_Edge1 = geompy.addToStudyInFather(FaceTop, Edge1, "Edge 1")
Id_Edge2 = geompy.addToStudyInFather(FaceTop, Edge2, "Edge 2")
- # ---- launch SMESH
-
- smeshgui = None
- if hasGUI == 1:
- smeshgui = salome.ImportComponentGUI("SMESH")
- smeshgui.Init(salome.myStudyId)
-
- print "-------------------------- create Hypothesis"
+ print "-------------------------- Algorithm and Hypothesis"
- print "-------------------------- NumberOfSegments"
-
- hypNbSeg3 = smesh.CreateHypothesis("NumberOfSegments", "libStdMeshersEngine.so")
- hypNbSeg3.SetNumberOfSegments(3)
- print hypNbSeg3.GetName()
- print hypNbSeg3.GetId()
- print hypNbSeg3.GetNumberOfSegments()
-
- if hasGUI == 1:
- idseg = salome.ObjectToID(hypNbSeg3)
- smeshgui.SetName(idseg, "NumberOfSegments_3");
-
- print "-------------------------- LocalLength"
-
- hypLen1 = smesh.CreateHypothesis("LocalLength", "libStdMeshersEngine.so")
- hypLen1.SetLength(10)
- print hypLen1.GetName()
- print hypLen1.GetId()
- print hypLen1.GetLength()
-
- if hasGUI == 1:
- idlength = salome.ObjectToID(hypLen1)
- smeshgui.SetName(idlength, "Local_Length_10");
-
- print "-------------------------- Propagation"
-
- hypProp = smesh.CreateHypothesis("Propagation", "libStdMeshersEngine.so")
- print hypProp.GetName()
- print hypProp.GetId()
-
- if hasGUI == 1:
- idprop = salome.ObjectToID(hypProp)
- smeshgui.SetName(idprop, "Propagation hypothesis");
+ print "---- Init a Mesh with the Spanner"
- #print "-------------------------- NumberOfSegments"
- #
- #hypNbSeg15 = smesh.CreateHypothesis("NumberOfSegments", "libStdMeshersEngine.so")
- #hypNbSeg15.SetNumberOfSegments(15)
- #print hypNbSeg15.GetName()
- #print hypNbSeg15.GetId()
- #print hypNbSeg15.GetNumberOfSegments()
- #
- #if hasGUI == 1:
- # idseg15 = salome.ObjectToID(hypNbSeg15)
- # smeshgui.SetName(idseg15, "NumberOfSegments_15");
+ mesh = smesh.Mesh(Spanner, "Meshed Spanner")
- print "-------------------------- Regular_1D"
+ print "-------------------------- add hypothesis to Spanner"
- algoReg = smesh.CreateHypothesis("Regular_1D", "libStdMeshersEngine.so")
+ print "-------------------------- NumberOfSegments"
+ algoReg = mesh.Segment()
listHyp = algoReg.GetCompatibleHypothesis()
for hyp in listHyp:
- print hyp
+ print hyp
print algoReg.GetName()
print algoReg.GetId()
+ algoReg.SetName("Regular_1D")
+
- if hasGUI == 1:
- idreg = salome.ObjectToID(algoReg)
- smeshgui.SetName(idreg, "Regular_1D");
+ hypNbSeg3 = algoReg.NumberOfSegments(3)
+ print hypNbSeg3.GetName()
+ print hypNbSeg3.GetId()
+ print hypNbSeg3.GetNumberOfSegments()
+ smesh.SetName(hypNbSeg3, "NumberOfSegments_3")
print "-------------------------- Quadrangle_2D"
- algoQuad = smesh.CreateHypothesis("Quadrangle_2D", "libStdMeshersEngine.so")
+ algoQuad = mesh.Quadrangle()
listHyp = algoQuad.GetCompatibleHypothesis()
for hyp in listHyp:
print hyp
print algoQuad.GetName()
print algoQuad.GetId()
-
- if hasGUI == 1:
- idquad = salome.ObjectToID(algoQuad)
- smeshgui.SetName(idquad, "Quadrangle_2D");
-
- print "---- Init a Mesh with the Spanner"
-
- mesh = smesh.CreateMesh(Spanner)
- if hasGUI == 1:
- idmesh = salome.ObjectToID(mesh)
- smeshgui.SetName(idmesh, "Meshed Spanner");
-
- print "-------------------------- add hypothesis to Spanner"
-
- mesh.AddHypothesis(Spanner, algoReg)
- mesh.AddHypothesis(Spanner, hypNbSeg3)
- mesh.AddHypothesis(Spanner, algoQuad)
+ algoQuad.SetName("Quadrangle_2D")
print "-------------------------- add hypothesis to the Middle Block"
- submesh_bl = mesh.GetSubMesh(BlockMh, "SubMesh Middle Block")
- mesh.AddHypothesis(BlockMh, hypLen1)
+ print "-------------------------- LocalLength"
+ algoRegMb = mesh.Segment(BlockMh)
+ hypLen1 = algoRegMb.LocalLength(10)
+ print hypLen1.GetName()
+ print hypLen1.GetId()
+ print hypLen1.GetLength()
+ smesh.SetName(hypLen1, "Local_Length_10")
print "-------------------------- add hypothesis to the long edges of the Top Face of the Middle Block"
- submesh_e1 = mesh.GetSubMesh(Edge1, "SubMesh Edge 1 of Top Face")
- mesh.AddHypothesis(Edge1, hypProp)
- #mesh.AddHypothesis(Edge1, hypNbSeg15)
+ algoRegE1 = mesh.Segment(Edge1)
+ hypPropE1 = algoRegE1.Propagation()
+ print hypPropE1.GetName()
+ print hypPropE1.GetId()
+ smesh.SetName(hypPropE1, "Propagation hypothesis")
+ smesh.SetName(algoRegE1.GetSubMesh(), "SubMesh Edge 1 of Top Face")
- submesh_e2 = mesh.GetSubMesh(Edge2, "SubMesh Edge 2 of Top Face")
- mesh.AddHypothesis(Edge2, hypProp)
- #mesh.AddHypothesis(Edge2, hypNbSeg15)
+ algoRegE2 = mesh.Segment(Edge2)
+ hypPropE2 = algoRegE2.Propagation()
+ print hypPropE2.GetName()
+ print hypPropE2.GetId()
+ smesh.SetName(hypPropE2, "Propagation hypothesis")
+ smesh.SetName(algoRegE2.GetSubMesh(), "SubMesh Edge 2 of Top Face")
print "-------------------------- compute the mesh"
- smesh.Compute(mesh, Spanner)
+ mesh.Compute()
print "Information about the Mesh:"
print "Number of nodes : ", mesh.NbNodes()