-// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2014 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
// 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.
+// 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
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-#include <Standard_Stream.hxx>
-
#include <GEOMImpl_PartitionDriver.hxx>
#include <GEOMImpl_IPartition.hxx>
#include <GEOMImpl_Types.hxx>
-
+#include <GEOMUtils.hxx>
#include <GEOM_Object.hxx>
#include <GEOM_Function.hxx>
-
#include <GEOMAlgo_Splitter.hxx>
#include <TDataStd_IntegerArray.hxx>
#include <TNaming_CopyShape.hxx>
-//#include <BRepBuilderAPI_Copy.hxx>
-#include <BRep_Tool.hxx>
-#include <BRepAlgo.hxx>
-#include <BRepTools.hxx>
-
#include <TopAbs.hxx>
#include <TopExp.hxx>
-#include <TopoDS.hxx>
#include <TopoDS_Shape.hxx>
-#include <TopoDS_Vertex.hxx>
-#include <TopoDS_Wire.hxx>
#include <TopoDS_Iterator.hxx>
#include <TopTools_MapOfShape.hxx>
#include <TopTools_IndexedMapOfShape.hxx>
#include <TopTools_ListIteratorOfListOfShape.hxx>
#include <TopTools_DataMapOfShapeShape.hxx>
-#include <ShapeFix_ShapeTolerance.hxx>
-#include <ShapeFix_Shape.hxx>
-
#include <TColStd_IndexedDataMapOfTransientTransient.hxx>
-#include <TColStd_ListIteratorOfListOfInteger.hxx>
-#include <TColStd_ListOfInteger.hxx>
#include <Standard_NullObject.hxx>
-#include <Precision.hxx>
-#include <gp_Pnt.hxx>
+#include <StdFail_NotDone.hxx>
+#include <BOPAlgo_CheckerSI.hxx>
+#include <BOPCol_IndexedDataMapOfShapeListOfShape.hxx>
+#include <BOPCol_ListOfShape.hxx>
+#include <BOPDS_DS.hxx>
+
+// Depth of self-intersection check (see BOPAlgo_CheckerSI::SetLevelOfCheck() for more details)
+// Default value for BOPAlgo_CheckerSI gives very long computation when checking face-to-face intersections;
+// here check level is decreased to more appropriate value to avoid problems with performance).
+#define BOP_SELF_INTERSECTIONS_LEVEL 4
//=======================================================================
//function : GetID
}
}
+static void CheckSelfIntersection(const TopoDS_Shape &theShape)
+{
+ BOPAlgo_CheckerSI aCSI; // checker of self-interferences
+ BOPCol_ListOfShape aList;
+
+ aList.Append(theShape);
+ aCSI.SetLevelOfCheck(BOP_SELF_INTERSECTIONS_LEVEL);
+ aCSI.SetArguments(aList);
+ aCSI.Perform();
+
+ if (aCSI.ErrorStatus() || aCSI.DS().Interferences().Extent() > 0) {
+ StdFail_NotDone::Raise("Partition operation will not be performed, because argument shape is self-intersected");
+ }
+}
+
//=======================================================================
//function : Execute
//purpose :
GEOMImpl_IPartition aCI (aFunction);
Standard_Integer aType = aFunction->GetType();
+ const Standard_Boolean isCheckSelfInte = aCI.GetCheckSelfIntersection();
TopoDS_Shape aShape;
- //sklNMTAlgo_Splitter1 PS;
GEOMAlgo_Splitter PS;
TopTools_DataMapOfShapeShape aCopyMap;
Standard_NullObject::Raise("In Partition a shape is null");
}
+ // Check self-intersection.
+ if (isCheckSelfInte && aType == PARTITION_NO_SELF_INTERSECTIONS) {
+ CheckSelfIntersection(aShape_i);
+ }
+
TopoDS_Shape aShape_i_copy;
TNaming_CopyShape::CopyTool(aShape_i, aMapTShapes, aShape_i_copy);
for (; aSimpleIter.More(); aSimpleIter.Next()) {
const TopoDS_Shape& aSimpleSh = aSimpleIter.Value();
if (ShapesMap.Add(aSimpleSh)) {
- PS.AddShape(aSimpleSh);
+ PS.AddArgument(aSimpleSh);
//skl if (DoRemoveWebs) {
//skl if (aMaterials->Length() >= ind)
//skl PS.SetMaterial(aSimpleSh, aMaterials->Value(ind));
if (aShape_i.IsNull()) {
Standard_NullObject::Raise("In Partition a tool shape is null");
}
+
+ // Check self-intersection.
+ if (isCheckSelfInte && aType == PARTITION_NO_SELF_INTERSECTIONS) {
+ CheckSelfIntersection(aShape_i);
+ }
+
//
//BRepBuilderAPI_Copy aCopyTool (aShape_i);
TopoDS_Shape aShape_i_copy;
for (; aSimpleIter.More(); aSimpleIter.Next()) {
const TopoDS_Shape& aSimpleSh = aSimpleIter.Value();
if (!ToolsMap.Contains(aSimpleSh) && ShapesMap.Add(aSimpleSh))
- PS.AddShape(aSimpleSh);
+ PS.AddArgument(aSimpleSh);
}
}
for (; aSimpleIter.More(); aSimpleIter.Next()) {
const TopoDS_Shape& aSimpleSh = aSimpleIter.Value();
if (!ToolsMap.Contains(aSimpleSh) && ShapesMap.Add(aSimpleSh))
- PS.AddShape(aSimpleSh);
+ PS.AddArgument(aSimpleSh);
}
}
}
// add object shapes that are in ListShapes;
- PS.AddShape(aShapeArg_copy);
- //PS.AddShape(aShapeArg);
+ TopTools_ListOfShape aSimpleShapes;
+ TopTools_MapOfShape aShapesMap;
+
+ PrepareShapes(aShapeArg_copy, aType, aSimpleShapes);
+
+ TopTools_ListIteratorOfListOfShape aSimpleIter (aSimpleShapes);
+
+ for (; aSimpleIter.More(); aSimpleIter.Next()) {
+ const TopoDS_Shape& aSimpleSh = aSimpleIter.Value();
+
+ if (aShapesMap.Add(aSimpleSh)) {
+ PS.AddArgument(aSimpleSh);
+ }
+ }
// add tool shapes that are in ListTools and not in ListShapes;
PS.AddTool(aPlaneArg_copy);
aShape = PS.Shape();
if (aShape.IsNull()) {
// Mantis issue 22009
- if (PS.ErrorStatus() == 10 && PS.Tools().Extent() == 0 && PS.Shapes().Extent() == 1)
- aShape = PS.Shapes().First();
+ if (PS.ErrorStatus() == 100 && PS.Tools().Extent() == 0 && PS.Arguments().Extent() == 1)
+ aShape = PS.Arguments().First();
else
return 0;
}
Standard_ConstructionError::Raise("Partition aborted : non valid shape result");
//end of IPAL21418
- if (!BRepAlgo::IsValid(aShape)) {
- // 08.07.2008 added by skl during fixing bug 19761 from Mantis
- 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();
- if (!BRepAlgo::IsValid(aShape))
- Standard_ConstructionError::Raise("Partition aborted : non valid shape result");
- }
+ if ( !GEOMUtils::CheckShape(aShape, true) && !GEOMUtils::FixShapeTolerance(aShape) )
+ Standard_ConstructionError::Raise("Partition aborted : non valid shape result");
aFunction->SetValue(aShape);
TopExp::MapShapes(aShape, aResIndices);
// Map: source_shape/images of source_shape in Result
- const TopTools_IndexedDataMapOfShapeListOfShape& aMR = PS.ImagesResult();
+ const BOPCol_IndexedDataMapOfShapeListOfShape& aMR = PS.ImagesResult();
+ //const TopTools_IndexedDataMapOfShapeListOfShape& aMR = PS.ImagesResult();
// history for all argument shapes
// be sure to use aCopyMap
//
if (!aMR.Contains(anEntity)) continue;
- const TopTools_ListOfShape& aModified = aMR.FindFromKey(anEntity);
+ const BOPCol_ListOfShape& aModified = aMR.FindFromKey(anEntity);
+ //const TopTools_ListOfShape& aModified = aMR.FindFromKey(anEntity);
Standard_Integer nbModified = aModified.Extent();
if (nbModified > 0) { // Mantis issue 0021182
int ih = 1;
- TopTools_ListIteratorOfListOfShape itM (aModified);
+ BOPCol_ListIteratorOfListOfShape itM (aModified);
for (; itM.More() && nbModified > 0; itM.Next(), ++ih) {
if (!aResIndices.Contains(itM.Value())) {
nbModified = 0;
TDataStd_IntegerArray::Set(aWhatHistoryLabel, 1, nbModified);
int ih = 1;
- TopTools_ListIteratorOfListOfShape itM (aModified);
+ BOPCol_ListIteratorOfListOfShape itM (aModified);
+ //TopTools_ListIteratorOfListOfShape itM (aModified);
for (; itM.More(); itM.Next(), ++ih) {
int id = aResIndices.FindIndex(itM.Value());
anAttr->SetValue(ih, id);
AddParam( theParams, "Resulting type", (TopAbs_ShapeEnum) aCI.GetLimit());
AddParam( theParams, "Keep shapes of lower type", aCI.GetKeepNonlimitShapes());
AddParam( theParams, "No object intersections", ( aType == PARTITION_NO_SELF_INTERSECTIONS ));
+
+ if (aType == PARTITION_NO_SELF_INTERSECTIONS) {
+ AddParam( theParams, "Check self-intersections", aCI.GetCheckSelfIntersection());
+ }
break;
case PARTITION_HALF:
AddParam( theParams, "Object", aCI.GetShape() );