-// Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// Copyright (C) 2007-2011 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
//
// This library is free software; you can redistribute it and/or
// License as published by the Free Software Foundation; either
// version 2.1 of the License.
//
-// This library is distributed in the hope that it will be useful
+// 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.
#include <GEOMImpl_GlueDriver.hxx>
#include <GEOM_Function.hxx>
+#include <ShapeFix_ShapeTolerance.hxx>
+#include <ShapeFix_Shape.hxx>
+
#include <BRep_Builder.hxx>
#include <BRepAlgo.hxx>
#include <BRepAlgoAPI_Common.hxx>
#include <BRepAlgoAPI_Cut.hxx>
#include <BRepAlgoAPI_Fuse.hxx>
#include <BRepAlgoAPI_Section.hxx>
+#include <BRepCheck_Analyzer.hxx>
+
#include <TopExp_Explorer.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Compound.hxx>
#include <TopTools_MapOfShape.hxx>
#include <TopTools_ListOfShape.hxx>
#include <TopTools_ListIteratorOfListOfShape.hxx>
+
#include <Precision.hxx>
#include <Standard_ConstructionError.hxx>
return aBooleanDriver;
}
-
//=======================================================================
//function : GEOMImpl_BooleanDriver
//purpose :
//function : Execute
//purpose :
//=======================================================================
-Standard_Integer GEOMImpl_BooleanDriver::Execute(TFunction_Logbook& log) const
+Standard_Integer GEOMImpl_BooleanDriver::Execute (TFunction_Logbook& log) const
{
if (Label().IsNull()) return 0;
Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
TopoDS_Shape aShape2 = aRefShape2->GetValue();
if (!aShape1.IsNull() && !aShape2.IsNull()) {
+ // check arguments for Mantis issue 0021019
+ BRepCheck_Analyzer ana (aShape1, Standard_True);
+ if (!ana.IsValid())
+ StdFail_NotDone::Raise("Common operation will not be performed, because argument shape is not valid");
+ ana.Init(aShape2);
+ if (!ana.IsValid())
+ StdFail_NotDone::Raise("Common operation will not be performed, because argument shape is not valid");
+
// perform COMMON operation
if (aType == BOOLEAN_COMMON) {
BRep_Builder B;
}
if (aShape.IsNull()) return 0;
- if (!BRepAlgo::IsValid(aShape)) {
- Standard_ConstructionError::Raise("Boolean operation aborted : non valid shape result");
+
+ // as boolean operations always produce compound, lets simplify it
+ // for the case, if it contans only one sub-shape
+ TopTools_ListOfShape listShapeRes;
+ AddSimpleShapes(aShape, listShapeRes);
+ if (listShapeRes.Extent() == 1) {
+ aShape = listShapeRes.First();
+ if (aShape.IsNull()) return 0;
+ }
+
+ // 08.07.2008 skl for bug 19761 from Mantis
+ BRepCheck_Analyzer ana (aShape, Standard_True);
+ ana.Init(aShape);
+ if (!ana.IsValid()) {
+ ShapeFix_ShapeTolerance aSFT;
+ aSFT.LimitTolerance(aShape, Precision::Confusion(),
+ Precision::Confusion(), TopAbs_SHAPE);
+ Handle(ShapeFix_Shape) aSfs = new ShapeFix_Shape(aShape);
+ aSfs->Perform();
+ aShape = aSfs->Shape();
+ ana.Init(aShape);
+ if (!ana.IsValid())
+ Standard_ConstructionError::Raise("Boolean operation aborted : non valid shape result");
}
+ //if (!BRepAlgo::IsValid(aShape)) {
+ // Standard_ConstructionError::Raise("Boolean operation aborted : non valid shape result");
+ //}
+
+ //Alternative case to check shape result Mantis 0020604: EDF 1172
+/* TopoDS_Iterator It (aShape, Standard_True, Standard_True);
+ int nbSubshapes=0;
+ for (; It.More(); It.Next())
+ nbSubshapes++;
+ if (!nbSubshapes)
+ Standard_ConstructionError::Raise("Boolean operation aborted : result object is empty compound");*/
+ //end of 0020604: EDF 1172
+ //! the changes temporary commented because of customer needs (see the same mantis bug)
aFunction->SetValue(aShape);
static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_BooleanDriver",
- sizeof(GEOMImpl_BooleanDriver),
- 1,
- (Standard_Address)_Ancestors,
- (Standard_Address)NULL);
+ sizeof(GEOMImpl_BooleanDriver),
+ 1,
+ (Standard_Address)_Ancestors,
+ (Standard_Address)NULL);
return _aType;
}