X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGEOMImpl%2FGEOMImpl_HealingDriver.cxx;h=fe08dc9e532320a3cfef697ae169a8ca81196270;hb=aa829b078e5ae308a86fe8c28de055a3e29131e6;hp=ffe05748ebe074dcf35834a56800ff4f5a13883f;hpb=9499b99fe2dcb53e1ea364f97986f8f432b04600;p=modules%2Fgeom.git diff --git a/src/GEOMImpl/GEOMImpl_HealingDriver.cxx b/src/GEOMImpl/GEOMImpl_HealingDriver.cxx index ffe05748e..fe08dc9e5 100644 --- a/src/GEOMImpl/GEOMImpl_HealingDriver.cxx +++ b/src/GEOMImpl/GEOMImpl_HealingDriver.cxx @@ -1,18 +1,20 @@ -// 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 // modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either +// 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 +// +// 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 +// 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 @@ -25,6 +27,8 @@ #include #include +#include + #include #include #include @@ -32,11 +36,23 @@ #include #include #include +#include + +#include -#include #include +#include +#include #include +#include +#include +#include +#include +#include + +#include + #include //======================================================================= @@ -64,12 +80,10 @@ const Standard_GUID& GEOMImpl_HealingDriver::GetID() return aHealingDriver; } - //======================================================================= //function : GEOMImpl_HealingDriver //purpose : //======================================================================= - GEOMImpl_HealingDriver::GEOMImpl_HealingDriver() { } @@ -115,6 +129,12 @@ Standard_Integer GEOMImpl_HealingDriver::Execute(TFunction_Logbook& log) const case DIVIDE_EDGE: AddPointOnEdge(&HI, anOriginalShape, aShape); break; + case CHANGE_ORIENTATION: + ChangeOrientation(&HI, anOriginalShape, aShape); + break; + case LIMIT_TOLERANCE: + LimitTolerance(&HI, anOriginalShape, aShape); + break; default: return 0; } @@ -178,19 +198,75 @@ Standard_Boolean GEOMImpl_HealingDriver::ShapeProcess (GEOMImpl_IHealing* theHI, //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(); - } else { + + if (aResult) + theOutShape = aHealer.GetResultShape(); + else + raiseNotDoneExeption(aHealer.GetErrorStatus()); + } + else { TopTools_SequenceOfShape aShapesFaces; TopTools_IndexedMapOfShape aShapes; TopExp::MapShapes(theOriginalShape, aShapes); @@ -199,16 +275,15 @@ Standard_Boolean GEOMImpl_HealingDriver::SuppressFaces (GEOMImpl_IHealing* theHI 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; } //======================================================================= @@ -379,6 +454,57 @@ Standard_Boolean GEOMImpl_HealingDriver::AddPointOnEdge (GEOMImpl_IHealing* theH } +//======================================================================= +//function : ChangeOrientation +//purpose : +//======================================================================= +Standard_Boolean GEOMImpl_HealingDriver::ChangeOrientation (GEOMImpl_IHealing* theHI, + const TopoDS_Shape& theOriginalShape, + TopoDS_Shape& theOutShape) const +{ + ShHealOper_ChangeOrientation aHealer (theOriginalShape); + + Standard_Boolean aResult = aHealer.Perform(); + + if (aResult) + theOutShape = aHealer.GetResultShape(); + else + raiseNotDoneExeption( aHealer.GetErrorStatus() ); + + 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_ //purpose : @@ -396,10 +522,10 @@ Standard_EXPORT Handle_Standard_Type& GEOMImpl_HealingDriver_Type_() static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL}; static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_HealingDriver", - sizeof(GEOMImpl_HealingDriver), - 1, - (Standard_Address)_Ancestors, - (Standard_Address)NULL); + sizeof(GEOMImpl_HealingDriver), + 1, + (Standard_Address)_Ancestors, + (Standard_Address)NULL); return _aType; } @@ -419,7 +545,5 @@ const Handle(GEOMImpl_HealingDriver) Handle(GEOMImpl_HealingDriver)::DownCast(co } } - return _anOtherObject ; + return _anOtherObject; } - -