MakeFaceWires and MakeFace can raise RuntimeError in case of a non planar detected

This commit is contained in:
Anthony Geay 2022-06-09 13:44:53 +02:00
parent c00b6875b6
commit 1b56fc0813
3 changed files with 68 additions and 4 deletions

View File

@ -0,0 +1,57 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2022 CEA/DEN, EDF R&D
#
# 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.
#
# 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
#
import unittest
import salome
salome.salome_init()
import GEOM
from salome.geom import geomBuilder
geompy = geomBuilder.New()
class BasicGeomObjsEx11(unittest.TestCase):
def testNoRaiseOnMakeFaceWires(self):
"""
Work in pair with testRaiseOnMakeFaceWires
"""
pts = [(0,0,0),(1,0,0),(1,1,1e-6),(0,1,0)] # diff with testRaiseOnMakeFaceWires is 1e-6 instead of 1e-5
vertices = [ geompy.MakeVertex(*list(elt)) for elt in pts]
polyline0 = geompy.MakePolyline([ vertices[nodeidx] for nodeidx in range(len(pts)) ], True)
wire_0 = geompy.MakeFaceWires( [ polyline0 ] , isPlanarWanted = True, theName=None, raiseException=True) # isPlanarWanted and raiseException are expected to be True here !
self.assertTrue(wire_0) # wire_0 is expected to be not None because wire has been created and detected to be planar
wire_1 = geompy.MakeFace( polyline0 , isPlanarWanted = True, theName=None, raiseException=True) # isPlanarWanted and raiseException are expected to be True here !
self.assertTrue(wire_1)
def testRaiseOnMakeFaceWires(self):
"""
Work in pair with testNoRaiseOnMakeFaceWires
"""
pts = [(0,0,0),(1,0,0),(1,1,1e-5),(0,1,0)] # diff with testRaiseOnMakeFaceWires is 1e-5 instead of 1e-6
vertices = [ geompy.MakeVertex(*list(elt)) for elt in pts]
polyline0 = geompy.MakePolyline([ vertices[nodeidx] for nodeidx in range(len(pts)) ], True)
# MakeFaceWires is expected to fail here because third point is too far from Oxy plane
self.assertRaises( RuntimeError, geompy.MakeFaceWires, [ polyline0 ] , True, None, True )# isPlanarWanted and raiseException are expected to be True here !
wire_0 = geompy.MakeFaceWires( [ polyline0 ] , isPlanarWanted = True, theName=None, raiseException=False) # returns something bug wire_0 is incorrect
self.assertRaises( RuntimeError, geompy.MakeFace, polyline0 , True, None, True )# isPlanarWanted and raiseException are expected to be True here !
wire_1 = geompy.MakeFace( polyline0 , isPlanarWanted = True, theName=None, raiseException=False) # returns something bug wire_1 is incorrect
if __name__ == '__main__':
unittest.main()

View File

@ -38,6 +38,7 @@ SET(GOOD_TESTS
basic_geom_objs_ex08.py
basic_geom_objs_ex09.py
basic_geom_objs_ex10.py
basic_geom_objs_ex11.py
basic_operations_ex01.py
basic_operations_ex02.py
basic_operations_ex03.py

View File

@ -379,6 +379,12 @@ def RaiseIfFailed (Method_name, Operation):
if not Operation.IsDone() and Operation.GetErrorCode() != "NOT_FOUND_ANY":
raise RuntimeError(Method_name + " : " + Operation.GetErrorCode())
def PrintOrRaise(message, raiseException=False):
if raiseException:
raise RuntimeError(message)
else:
print(message)
## Return list of variables value from salome notebook
## @ingroup l1_geomBuilder_auxiliary
def ParseParameters(*parameters):
@ -4750,7 +4756,7 @@ class geomBuilder(GEOM._objref_GEOM_Gen):
#
# @ref tui_creation_face "Example"
@ManageTransactions("ShapesOp")
def MakeFace(self, theWire, isPlanarWanted, theName=None):
def MakeFace(self, theWire, isPlanarWanted, theName=None, raiseException=False):
"""
Create a face on the given wire.
@ -4771,7 +4777,7 @@ class geomBuilder(GEOM._objref_GEOM_Gen):
# Example: see GEOM_TestAll.py
anObj = self.ShapesOp.MakeFace(theWire, isPlanarWanted)
if isPlanarWanted and anObj is not None and self.ShapesOp.GetErrorCode() == "MAKE_FACE_TOLERANCE_TOO_BIG":
print("WARNING: Cannot build a planar face: required tolerance is too big. Non-planar face is built.")
PrintOrRaise("WARNING: Cannot build a planar face: required tolerance is too big. Non-planar face is built.",raiseException)
else:
RaiseIfFailed("MakeFace", self.ShapesOp)
self._autoPublish(anObj, theName, "face")
@ -4792,7 +4798,7 @@ class geomBuilder(GEOM._objref_GEOM_Gen):
#
# @ref tui_creation_face "Example"
@ManageTransactions("ShapesOp")
def MakeFaceWires(self, theWires, isPlanarWanted, theName=None):
def MakeFaceWires(self, theWires, isPlanarWanted, theName=None, raiseException=False):
"""
Create a face on the given wires set.
@ -4813,7 +4819,7 @@ class geomBuilder(GEOM._objref_GEOM_Gen):
# Example: see GEOM_TestAll.py
anObj = self.ShapesOp.MakeFaceWires(ToList(theWires), isPlanarWanted)
if isPlanarWanted and anObj is not None and self.ShapesOp.GetErrorCode() == "MAKE_FACE_TOLERANCE_TOO_BIG":
print("WARNING: Cannot build a planar face: required tolerance is too big. Non-planar face is built.")
PrintOrRaise("WARNING: Cannot build a planar face: required tolerance is too big. Non-planar face is built.",raiseException)
else:
RaiseIfFailed("MakeFaceWires", self.ShapesOp)
self._autoPublish(anObj, theName, "face")