Salome HOME
Fix memory leaks
[modules/geom.git] / src / GEOM_SWIG / GEOM_Spanner.py
index f95ab64e39280d4c39e7d10852c3c5a9e3747cf4..8d7a0189d540e93ab64e09af1f8d19df5382bf46 100644 (file)
@@ -1,45 +1,41 @@
-#  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
+#  -*- coding: iso-8859-1 -*-
+# Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
 #
-#  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-#  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+# 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 as published by the Free Software Foundation; either
-#  version 2.1 of the License.
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
 #
-#  This library is distributed in the hope that it will be useful,
-#  but WITHOUT ANY WARRANTY; without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-#  Lesser General Public License for more details.
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
 #
-#  You should have received a copy 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
+# You should have received a copy 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.com
+# 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$
+#
 # ! 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 #############
 #
+############# MakeSpanner #############
 def MakeSpanner (geompy, math, isBlocksTest = 0, isMeshTest = 0, smesh = None):
 
   ### Variables ###
 
   th = 4.0
 
-  ### BlocksOp ###
-
-  BlocksOp = geompy.BlocksOp
-
   ### Basic points and directions ###
 
   p0  = geompy.MakeVertex(0., 0., 0.)
@@ -103,7 +99,7 @@ def MakeSpanner (geompy, math, isBlocksTest = 0, isMeshTest = 0, smesh = None):
   else:
     print "Prism 1 is not a hexahedral solid"
 
-  Prism1_faces = geompy.SubShapeAllSorted(Prism1, geompy.ShapeType["FACE"])
+  Prism1_faces = geompy.SubShapeAllSortedCentres(Prism1, geompy.ShapeType["FACE"])
   ii = 1
   for aFace in  Prism1_faces:
     name = geompy.SubShapeName(aFace, Prism1)
@@ -279,17 +275,21 @@ def MakeSpanner (geompy, math, isBlocksTest = 0, isMeshTest = 0, smesh = None):
   Face22h = geompy.GetOppositeFace(Block2h, Face21h)
   id_face22h = geompy.addToStudyInFather(Block2h, Face22h, "Face 2")
 
-  Block3h = BlocksOp.GetBlockByParts(Handle, [Face11h, Face21h])
-  if BlocksOp.IsDone() == 0:
-    Block3h = BlocksOp.GetBlockByParts(Handle, [Face11h, Face22h])
-    if BlocksOp.IsDone() == 0:
-        Block3h = BlocksOp.GetBlockByParts(Handle, [Face12h, Face21h])
-        if BlocksOp.IsDone() == 0:
-            Block3h = BlocksOp.GetBlockByParts(Handle, [Face12h, Face22h])
-  if BlocksOp.IsDone() == 0:
-    print "ERROR: BlocksOp.GetBlockByParts() failed : ", BlocksOp.GetErrorCode()
-  else:
-    id_block3h = geompy.addToStudyInFather(Handle, Block3h, "Block 3 of Handle")
+  try:
+    Block3h = geompy.GetBlockByParts(Handle, [Face11h, Face21h])
+  except RuntimeError:
+    try:
+      Block3h = geompy.GetBlockByParts(Handle, [Face11h, Face22h])
+    except RuntimeError:
+      try:
+        Block3h = geompy.GetBlockByParts(Handle, [Face12h, Face21h])
+      except RuntimeError:
+        try:
+          Block3h = geompy.GetBlockByParts(Handle, [Face12h, Face22h])
+        except RuntimeError:
+          print "ERROR: BlocksOp.GetBlockByParts() failed : ", geompy.BlocksOp.GetErrorCode()
+        else:
+          id_block3h = geompy.addToStudyInFather(Handle, Block3h, "Block 3 of Handle")
 
   ### The whole shape ###
 
@@ -299,9 +299,14 @@ def MakeSpanner (geompy, math, isBlocksTest = 0, isMeshTest = 0, smesh = None):
 
   ### Check the Spanner ###
 
-  isCompOfBlocks6 = BlocksOp.CheckCompoundOfBlocks(Spanner)
+  isCompOfBlocks6 = geompy.CheckCompoundOfBlocks(Spanner)
   if isCompOfBlocks6 == 0:
     print "Spanner is not a compound of hexahedral solids"
+    (NonBlocks, NonQuads) = geompy.GetNonBlocks(Spanner)
+    if NonBlocks is not None:
+      geompy.addToStudyInFather(Spanner, NonBlocks, "Group of non-hexahedral solids")
+    if NonQuads is not None:
+      geompy.addToStudyInFather(Spanner, NonQuads, "Group of non-quadrangular faces")
   else:
     print "Spanner is a compound of hexahedral solids"
 
@@ -381,7 +386,7 @@ def MakeSpanner (geompy, math, isBlocksTest = 0, isMeshTest = 0, smesh = None):
 
     # ---- add long edges of the top face in study
 
-    FaceTop_edges = geompy.SubShapeAllSorted(FaceTop, geompy.ShapeType["EDGE"])
+    FaceTop_edges = geompy.SubShapeAllSortedCentres(FaceTop, geompy.ShapeType["EDGE"])
     Edge1 = FaceTop_edges[0]
     Edge2 = FaceTop_edges[3]
     Id_Edge1 = geompy.addToStudyInFather(FaceTop, Edge1, "Edge 1")