From 2d0d426c672eda06fec825d86bd7c9bc37163c44 Mon Sep 17 00:00:00 2001 From: jfa Date: Wed, 23 Nov 2011 13:29:40 +0000 Subject: [PATCH] Mantis issue 0021432: EDF GEOM: Faces with huge tolerance can be built in GEOM --- src/BuildGUI/BuildGUI_FaceDlg.cxx | 24 ++++++++++++----- src/GEOMGUI/GEOM_msg_en.ts | 4 +++ src/GEOMImpl/GEOMImpl_Block6Explorer.cxx | 29 +++++++++++++-------- src/GEOMImpl/GEOMImpl_Block6Explorer.hxx | 10 +++---- src/GEOMImpl/GEOMImpl_IShapesOperations.cxx | 23 ++++++++++++---- src/GEOMImpl/GEOMImpl_ShapeDriver.cxx | 9 +++++-- src/GEOM_I/GEOM_IShapesOperations_i.cc | 8 ++++-- src/GEOM_SWIG/geompyDC.py | 10 +++++-- 8 files changed, 83 insertions(+), 34 deletions(-) diff --git a/src/BuildGUI/BuildGUI_FaceDlg.cxx b/src/BuildGUI/BuildGUI_FaceDlg.cxx index 15daf9f86..c1561405b 100644 --- a/src/BuildGUI/BuildGUI_FaceDlg.cxx +++ b/src/BuildGUI/BuildGUI_FaceDlg.cxx @@ -18,12 +18,11 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// // GEOM GEOMGUI : GUI for Geometry component // File : BuildGUI_FaceDlg.cxx // Author : Lucien PIGNOLONI, Open CASCADE S.A.S. -// + #include "BuildGUI_FaceDlg.h" #include @@ -33,11 +32,14 @@ #include #include -#include -#include #include #include +#include +#include +#include +#include + //================================================================================= // class : BuildGUI_FaceDlg() // purpose : Constructs a BuildGUI_FaceDlg which is a child of 'parent', with the @@ -247,9 +249,17 @@ bool BuildGUI_FaceDlg::execute( ObjectList& objects ) GEOM::GEOM_Object_var anObj = anOper->MakeFaceWires( objlist.in(), GroupWire->CheckButton1->isChecked() ); - if ( !anObj->_is_nil() ) - objects.push_back( anObj._retn() ); + if (!anObj->_is_nil()) { + objects.push_back(anObj._retn()); + + if (!anOper->IsDone() && QString(anOper->GetErrorCode()) == "MAKE_FACE_TOLERANCE_TOO_BIG") { + SUIT_OverrideCursor wc; + wc.suspend(); + QString msgw = QObject::tr(anOper->GetErrorCode()); + SUIT_MessageBox::warning(this, tr("WRN_WARNING"), msgw, tr("BUT_OK")); + anOper->SetErrorCode("PAL_NO_ERROR"); + } + } return true; } - diff --git a/src/GEOMGUI/GEOM_msg_en.ts b/src/GEOMGUI/GEOM_msg_en.ts index 486a2bbc1..b312d7ce4 100644 --- a/src/GEOMGUI/GEOM_msg_en.ts +++ b/src/GEOMGUI/GEOM_msg_en.ts @@ -605,6 +605,10 @@ Please, select face, shell or solid and try again GEOM_FACE_OPT Try to create a planar face + + MAKE_FACE_TOLERANCE_TOO_BIG + Tolerance of resulting face is too big + GEOM_FACE_OR_LCS Face or LCS diff --git a/src/GEOMImpl/GEOMImpl_Block6Explorer.cxx b/src/GEOMImpl/GEOMImpl_Block6Explorer.cxx index 5086d53c0..48f179cf8 100644 --- a/src/GEOMImpl/GEOMImpl_Block6Explorer.cxx +++ b/src/GEOMImpl/GEOMImpl_Block6Explorer.cxx @@ -18,7 +18,6 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// #include @@ -79,6 +78,8 @@ #define NBEDGES 12 #define NBVERTS 8 +#define PLANAR_FACE_MAX_TOLERANCE 1e-06 + static Standard_Integer mod4 (Standard_Integer nb) { if (nb <= 0) return nb + 4; @@ -1197,10 +1198,12 @@ Standard_Integer GEOMImpl_Block6Explorer::FindFace //function : MakeFace //purpose : //======================================================================= -void GEOMImpl_Block6Explorer::MakeFace (const TopoDS_Wire& theWire, - const Standard_Boolean isPlanarWanted, - TopoDS_Shape& theResult) +TCollection_AsciiString GEOMImpl_Block6Explorer::MakeFace (const TopoDS_Wire& theWire, + const Standard_Boolean isPlanarWanted, + TopoDS_Shape& theResult) { + TCollection_AsciiString aWarning; + // Workaround for Mantis issue 0020956 if (isPlanarWanted) { // Count the number of points in the wire. @@ -1247,14 +1250,14 @@ void GEOMImpl_Block6Explorer::MakeFace (const TopoDS_Wire& theWire, BRepBuilderAPI_MakeFace MK (plane, theWire, isPlanarWanted); if (MK.IsDone()) { theResult = MK.Shape(); - return; + return aWarning; } } else { BRepBuilderAPI_MakeFace MK (theWire, isPlanarWanted); if (MK.IsDone()) { theResult = MK.Shape(); - return; + return aWarning; } } } @@ -1263,7 +1266,7 @@ void GEOMImpl_Block6Explorer::MakeFace (const TopoDS_Wire& theWire, BRepBuilderAPI_MakeFace MK (theWire, isPlanarWanted); if (MK.IsDone()) { theResult = MK.Shape(); - return; + return aWarning; } } @@ -1346,7 +1349,7 @@ void GEOMImpl_Block6Explorer::MakeFace (const TopoDS_Wire& theWire, if (!aFS.Found()) { aFS.Init(theWire, aToleranceReached, isPlanarWanted); - if (!aFS.Found()) return; + if (!aFS.Found()) return aWarning; aToleranceReached = aFS.ToleranceReached(); aTol = aFS.Tolerance(); } @@ -1354,7 +1357,7 @@ void GEOMImpl_Block6Explorer::MakeFace (const TopoDS_Wire& theWire, // Copy the wire, bacause it can be updated with very-very big tolerance here BRepBuilderAPI_Copy aMC (theWire); - if (!aMC.IsDone()) return; + if (!aMC.IsDone()) return aWarning; TopoDS_Wire aWire = TopoDS::Wire(aMC.Shape()); // Update tolerances to BRep_Builder B; @@ -1371,7 +1374,9 @@ void GEOMImpl_Block6Explorer::MakeFace (const TopoDS_Wire& theWire, BRepBuilderAPI_MakeFace MK1 (aWire, isPlanarWanted); if (MK1.IsDone()) { theResult = MK1.Shape(); - return; + if (aTol > PLANAR_FACE_MAX_TOLERANCE) + aWarning = "MAKE_FACE_TOLERANCE_TOO_BIG"; + return aWarning; } #else // After migration on OCCT version, containing PKV's fix. See bug 8293 @@ -1379,8 +1384,10 @@ void GEOMImpl_Block6Explorer::MakeFace (const TopoDS_Wire& theWire, aBMF.Init(theWire, isPlanarWanted, Standard_True); if (aBMF.Error() == BRepLib_FaceDone) { theResult = aBMF.Shape(); - return; + return aWarning; } #endif } + + return aWarning; } diff --git a/src/GEOMImpl/GEOMImpl_Block6Explorer.hxx b/src/GEOMImpl/GEOMImpl_Block6Explorer.hxx index 9734ae744..ea47dfe37 100644 --- a/src/GEOMImpl/GEOMImpl_Block6Explorer.hxx +++ b/src/GEOMImpl/GEOMImpl_Block6Explorer.hxx @@ -18,11 +18,10 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// // File : GEOMImpl_Block6Explorer.hxx // Module : GEOMImpl -// + #ifndef GEOMImpl_Block6Explorer_HeaderFile #define GEOMImpl_Block6Explorer_HeaderFile @@ -30,6 +29,7 @@ #include #include #include +#include #include // Class GEOMImpl_Block6Explorer gives easy and fast access to a certain sub-elements of hexahedral solid @@ -214,9 +214,9 @@ class GEOMImpl_Block6Explorer const Standard_Boolean findAll = Standard_False); // returns number of found faces - static void MakeFace (const TopoDS_Wire& theWire, - const Standard_Boolean isPlanarWanted, - TopoDS_Shape& theResult); + static TCollection_AsciiString MakeFace (const TopoDS_Wire& theWire, + const Standard_Boolean isPlanarWanted, + TopoDS_Shape& theResult); private: // ---------- PRIVATE FIELDS ---------- diff --git a/src/GEOMImpl/GEOMImpl_IShapesOperations.cxx b/src/GEOMImpl/GEOMImpl_IShapesOperations.cxx index f74e646e4..1f958e170 100644 --- a/src/GEOMImpl/GEOMImpl_IShapesOperations.cxx +++ b/src/GEOMImpl/GEOMImpl_IShapesOperations.cxx @@ -83,7 +83,6 @@ #include #include #include -#include #include #include @@ -458,6 +457,7 @@ Handle(GEOM_Object) GEOMImpl_IShapesOperations::MakeFace (Handle(GEOM_Object) th aCI.SetIsPlanar(isPlanarWanted); //Compute the Face value + Standard_Boolean isWarning = Standard_False; try { #if OCC_VERSION_LARGE > 0x06010000 OCC_CATCH_SIGNALS; @@ -470,14 +470,20 @@ Handle(GEOM_Object) GEOMImpl_IShapesOperations::MakeFace (Handle(GEOM_Object) th catch (Standard_Failure) { Handle(Standard_Failure) aFail = Standard_Failure::Caught(); SetErrorCode(aFail->GetMessageString()); - return NULL; + // to provide warning + if (!aFunction->GetValue().IsNull()) { + isWarning = Standard_True; + } else { + return NULL; + } } //Make a Python command GEOM::TPythonDump(aFunction) << aFace << " = geompy.MakeFace(" << theWire << ", " << (int)isPlanarWanted << ")"; - SetErrorCode(OK); + // to provide warning + if (!isWarning) SetErrorCode(OK); return aFace; } @@ -522,6 +528,7 @@ Handle(GEOM_Object) GEOMImpl_IShapesOperations::MakeFaceWires aCI.SetIsPlanar(isPlanarWanted); //Compute the shape + Standard_Boolean isWarning = Standard_False; try { #if OCC_VERSION_LARGE > 0x06010000 OCC_CATCH_SIGNALS; @@ -534,7 +541,12 @@ Handle(GEOM_Object) GEOMImpl_IShapesOperations::MakeFaceWires catch (Standard_Failure) { Handle(Standard_Failure) aFail = Standard_Failure::Caught(); SetErrorCode(aFail->GetMessageString()); - return NULL; + // to provide warning + if (!aFunction->GetValue().IsNull()) { + isWarning = Standard_True; + } else { + return NULL; + } } //Make a Python command @@ -551,7 +563,8 @@ Handle(GEOM_Object) GEOMImpl_IShapesOperations::MakeFaceWires } pd << "], " << (int)isPlanarWanted << ")"; - SetErrorCode(OK); + // to provide warning + if (!isWarning) SetErrorCode(OK); return aShape; } diff --git a/src/GEOMImpl/GEOMImpl_ShapeDriver.cxx b/src/GEOMImpl/GEOMImpl_ShapeDriver.cxx index 37f3937f0..f086e4a78 100644 --- a/src/GEOMImpl/GEOMImpl_ShapeDriver.cxx +++ b/src/GEOMImpl/GEOMImpl_ShapeDriver.cxx @@ -121,6 +121,8 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const Standard_Integer aType = aFunction->GetType(); TopoDS_Shape aShape; + TCollection_AsciiString aWarning; + BRep_Builder B; if (aType == WIRE_EDGES) { @@ -214,7 +216,7 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const Standard_NullObject::Raise ("Shape for face construction is neither a wire nor a closed edge"); } - GEOMImpl_Block6Explorer::MakeFace(W, aCI.GetIsPlanar(), aShape); + aWarning = GEOMImpl_Block6Explorer::MakeFace(W, aCI.GetIsPlanar(), aShape); if (aShape.IsNull()) { Standard_ConstructionError::Raise("Face construction failed"); } @@ -270,7 +272,7 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const // 4.a. Basic face TopoDS_Shape aFFace; TopoDS_Wire aW1 = TopoDS::Wire(aSeqClosedWires->Value(1)); - GEOMImpl_Block6Explorer::MakeFace(aW1, aCI.GetIsPlanar(), aFFace); + aWarning = GEOMImpl_Block6Explorer::MakeFace(aW1, aCI.GetIsPlanar(), aFFace); if (aFFace.IsNull()) { Standard_ConstructionError::Raise("Face construction failed"); } @@ -914,6 +916,9 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const log.SetTouched(Label()); + if (!aWarning.IsEmpty()) + Standard_Failure::Raise(aWarning.ToCString()); + return 1; } diff --git a/src/GEOM_I/GEOM_IShapesOperations_i.cc b/src/GEOM_I/GEOM_IShapesOperations_i.cc index e29a6e763..b3a363628 100644 --- a/src/GEOM_I/GEOM_IShapesOperations_i.cc +++ b/src/GEOM_I/GEOM_IShapesOperations_i.cc @@ -202,7 +202,9 @@ GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::MakeFace //Create the Face Handle(GEOM_Object) anObject = GetOperations()->MakeFace(aWire, isPlanarWanted); - if (!GetOperations()->IsDone() || anObject.IsNull()) + //if (!GetOperations()->IsDone() || anObject.IsNull()) + // enable warning status + if (anObject.IsNull()) return aGEOMObject._retn(); return GetObject(anObject); @@ -236,7 +238,9 @@ GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::MakeFaceWires // Make Face Handle(GEOM_Object) anObject = GetOperations()->MakeFaceWires(aShapes, isPlanarWanted); - if (!GetOperations()->IsDone() || anObject.IsNull()) + //if (!GetOperations()->IsDone() || anObject.IsNull()) + // enable warning status + if (anObject.IsNull()) return aGEOMObject._retn(); return GetObject(anObject); diff --git a/src/GEOM_SWIG/geompyDC.py b/src/GEOM_SWIG/geompyDC.py index 983773905..1e0903119 100644 --- a/src/GEOM_SWIG/geompyDC.py +++ b/src/GEOM_SWIG/geompyDC.py @@ -1731,7 +1731,10 @@ class geompyDC(GEOM._objref_GEOM_Gen): def MakeFace(self,theWire, isPlanarWanted): # Example: see GEOM_TestAll.py anObj = self.ShapesOp.MakeFace(theWire, isPlanarWanted) - RaiseIfFailed("MakeFace", self.ShapesOp) + if anObj is not None and self.ShapesOp.GetErrorCode() == "MAKE_FACE_TOLERANCE_TOO_BIG": + print "WARNING: Tolerance of resulting face is too big." + else: + RaiseIfFailed("MakeFace", self.ShapesOp) return anObj ## Create a face on the given wires set. @@ -1744,7 +1747,10 @@ class geompyDC(GEOM._objref_GEOM_Gen): def MakeFaceWires(self,theWires, isPlanarWanted): # Example: see GEOM_TestAll.py anObj = self.ShapesOp.MakeFaceWires(theWires, isPlanarWanted) - RaiseIfFailed("MakeFaceWires", self.ShapesOp) + if anObj is not None and self.ShapesOp.GetErrorCode() == "MAKE_FACE_TOLERANCE_TOO_BIG": + print "WARNING: Tolerance of resulting face is too big." + else: + RaiseIfFailed("MakeFaceWires", self.ShapesOp) return anObj ## Shortcut to MakeFaceWires() -- 2.39.2