-// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
+// 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
+// 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.
//
-// 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
#include <Standard_Stream.hxx>
#include <GEOMImpl_IHealing.hxx>
#include <GEOM_Function.hxx>
+#include <GEOMImpl_GlueDriver.hxx>
+
#include <ShHealOper_ShapeProcess.hxx>
#include <ShHealOper_RemoveFace.hxx>
#include <ShHealOper_CloseContour.hxx>
#include <ShHealOper_EdgeDivide.hxx>
#include <ShHealOper_ChangeOrientation.hxx>
-#include <TopoDS.hxx>
+#include <BRep_Builder.hxx>
+
#include <TopExp.hxx>
+#include <TopoDS.hxx>
+#include <TopoDS_Iterator.hxx>
#include <TopTools_IndexedMapOfShape.hxx>
+#include <TColStd_IndexedDataMapOfTransientTransient.hxx>
+#include <TNaming_CopyShape.hxx>
+#include <ShapeFix_ShapeTolerance.hxx>
+#include <ShapeFix_Shape.hxx>
+#include <BRepCheck_Analyzer.hxx>
+
+#include <Precision.hxx>
+
#include <StdFail_NotDone.hxx>
//=======================================================================
case CHANGE_ORIENTATION:
ChangeOrientation(&HI, anOriginalShape, aShape);
break;
+ case LIMIT_TOLERANCE:
+ LimitTolerance(&HI, anOriginalShape, aShape);
+ break;
default:
return 0;
}
//function : SupressFaces
//purpose :
//=======================================================================
+void SuppressFacesRec (const TopTools_SequenceOfShape& theShapesFaces,
+ const TopoDS_Shape& theOriginalShape,
+ TopoDS_Shape& theOutShape)
+{
+ if ((theOriginalShape.ShapeType() != TopAbs_COMPOUND &&
+ theOriginalShape.ShapeType() != TopAbs_COMPSOLID))
+ {
+ ShHealOper_RemoveFace aHealer (theOriginalShape);
+ Standard_Boolean aResult = aHealer.Perform(theShapesFaces);
+
+ if (aResult)
+ theOutShape = aHealer.GetResultShape();
+ else
+ raiseNotDoneExeption(aHealer.GetErrorStatus());
+ }
+ else
+ {
+ BRep_Builder BB;
+ TopoDS_Compound CC;
+ BB.MakeCompound(CC);
+
+ TopTools_MapOfShape mapShape;
+ TopoDS_Iterator It (theOriginalShape, Standard_True, Standard_True);
+
+ for (; It.More(); It.Next()) {
+ TopoDS_Shape aShape_i = It.Value();
+ if (mapShape.Add(aShape_i)) {
+ // check, if current shape contains at least one of faces to be removed
+ bool isFound = false;
+ TopTools_IndexedMapOfShape aShapes_i;
+ TopExp::MapShapes(aShape_i, aShapes_i);
+ for (int i = 1; i <= theShapesFaces.Length() && !isFound; i++) {
+ const TopoDS_Shape& aFace_i = theShapesFaces.Value(i);
+ if (aShapes_i.Contains(aFace_i)) isFound = true;
+ }
+ if (isFound) {
+ TopoDS_Shape anOutSh_i;
+ SuppressFacesRec(theShapesFaces, aShape_i, anOutSh_i);
+ if ( !anOutSh_i.IsNull() )
+ BB.Add(CC, anOutSh_i);
+ }
+ else {
+ // nothing to do
+ BB.Add(CC, aShape_i);
+ }
+ }
+ }
+ theOutShape = CC;
+ }
+}
+
Standard_Boolean GEOMImpl_HealingDriver::SuppressFaces (GEOMImpl_IHealing* theHI,
const TopoDS_Shape& theOriginalShape,
TopoDS_Shape& theOutShape) const
{
Handle(TColStd_HArray1OfInteger) aFaces = theHI->GetFaces();
- ShHealOper_RemoveFace aHealer (theOriginalShape);
-
Standard_Boolean aResult = Standard_False;
- if (aFaces.IsNull()) // remove all faces
- {
+
+ if (aFaces.IsNull()) {
+ ShHealOper_RemoveFace aHealer (theOriginalShape);
aResult = aHealer.Perform();
+
+ if (aResult)
+ theOutShape = aHealer.GetResultShape();
+ else
+ raiseNotDoneExeption(aHealer.GetErrorStatus());
}
- else
- {
+ else {
TopTools_SequenceOfShape aShapesFaces;
TopTools_IndexedMapOfShape aShapes;
TopExp::MapShapes(theOriginalShape, aShapes);
TopoDS_Shape aFace = aShapes.FindKey(indexOfFace);
aShapesFaces.Append(aFace);
}
-
- aResult = aHealer.Perform(aShapesFaces);
+ SuppressFacesRec(aShapesFaces, theOriginalShape, theOutShape);
+ if ((theOriginalShape.ShapeType() == TopAbs_COMPOUND ||
+ theOriginalShape.ShapeType() == TopAbs_COMPSOLID)) {
+ TopoDS_Shape aSh = theOutShape;
+ theOutShape = GEOMImpl_GlueDriver::GlueFaces(aSh, Precision::Confusion(), Standard_True);
+ }
}
- if ( aResult )
- theOutShape = aHealer.GetResultShape();
- else
- raiseNotDoneExeption( aHealer.GetErrorStatus() );
-
- return aResult;
+ return Standard_True;
}
//=======================================================================
return aResult;
}
+//=======================================================================
+//function : LimitTolerance
+//purpose :
+//=======================================================================
+void GEOMImpl_HealingDriver::LimitTolerance (GEOMImpl_IHealing* theHI,
+ const TopoDS_Shape& theOriginalShape,
+ TopoDS_Shape& theOutShape) const
+{
+ Standard_Real aTol = theHI->GetTolerance();
+ if (aTol < Precision::Confusion())
+ aTol = Precision::Confusion();
+
+ // 1. Make a copy to prevent the original shape changes.
+ TopoDS_Shape aShapeCopy;
+ TColStd_IndexedDataMapOfTransientTransient aMapTShapes;
+ TNaming_CopyShape::CopyTool(theOriginalShape, aMapTShapes, aShapeCopy);
+
+ // 2. Limit tolerance.
+ ShapeFix_ShapeTolerance aSFT;
+ aSFT.LimitTolerance(aShapeCopy, aTol, aTol, TopAbs_SHAPE);
+
+ // 3. Fix obtained shape.
+ Handle(ShapeFix_Shape) aSfs = new ShapeFix_Shape (aShapeCopy);
+ aSfs->Perform();
+ theOutShape = aSfs->Shape();
+
+ BRepCheck_Analyzer ana (theOutShape, Standard_True);
+ if (!ana.IsValid())
+ StdFail_NotDone::Raise("Non valid shape result");
+}
//=======================================================================
//function : GEOMImpl_HealingDriver_Type_