X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGeomAlgoAPI%2FGeomAlgoAPI_UnifySameDomain.cpp;h=5bb37ab2106ace1ae52bdaac2bca62c20978f437;hb=4c86b629d1bf8daa737f90b64e934c7bd22f6525;hp=1671f382ce341f46dc3ee5c9145f8ee62f3ed6c5;hpb=c0e62209309f0d8168bb9c9095079993a6767e39;p=modules%2Fshaper.git diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_UnifySameDomain.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_UnifySameDomain.cpp index 1671f382c..5bb37ab21 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_UnifySameDomain.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_UnifySameDomain.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// Copyright (C) 2014-2024 CEA, EDF // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -12,20 +12,26 @@ // // 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 +// 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 "GeomAlgoAPI_UnifySameDomain.h" #include +#include #include -#include +#include #include #include +#include +#include +#include +#include +#include +#include //================================================================================================== GeomAlgoAPI_UnifySameDomain::GeomAlgoAPI_UnifySameDomain(const ListOfShape& theShapes) @@ -33,6 +39,13 @@ GeomAlgoAPI_UnifySameDomain::GeomAlgoAPI_UnifySameDomain(const ListOfShape& theS build(theShapes); } +//================================================================================================== +GeomAlgoAPI_UnifySameDomain::GeomAlgoAPI_UnifySameDomain(const GeomShapePtr& theShape) +{ + build(theShape, false); +} + +//================================================================================================== void GeomAlgoAPI_UnifySameDomain::build(const ListOfShape& theShapes) { if(theShapes.empty()) { @@ -41,31 +54,62 @@ void GeomAlgoAPI_UnifySameDomain::build(const ListOfShape& theShapes) // Make compound. GeomShapePtr aCompound = GeomAlgoAPI_CompoundBuilder::compound(theShapes); - ListOfShape aCombined, aFree; + ListOfShape aResults; GeomAlgoAPI_ShapeTools::combineShapes( aCompound, GeomAPI_Shape::SHELL, - aCombined, - aFree); + aResults); - if(aFree.size() > 0 || aCombined.size() > 1) { + if(aResults.size() > 1 || + (aResults.size() == 1 && aResults.front()->shapeType() > GeomAPI_Shape::SHELL)) { return; } - const TopoDS_Shape& aShell = aCombined.front()->impl(); + const TopoDS_Shape& aShell = aResults.front()->impl(); + std::shared_ptr aShape(new GeomAPI_Shape()); + aShape->setImpl(new TopoDS_Shape(aShell)); + build(aShape, true); +} + +// calculates maximum possible tolerance on edges of shape +static Standard_Real defineLinearTolerance(const TopoDS_Shape& theShape) +{ + Standard_Real aMaxTol = Precision::Confusion(); + + TopExp_Explorer Explo(theShape, TopAbs_EDGE); + for (; Explo.More(); Explo.Next()) + { + const TopoDS_Edge& anEdge = TopoDS::Edge(Explo.Current()); + aMaxTol = Max(aMaxTol, BRep_Tool::Tolerance(anEdge)); + } + + return aMaxTol; +} + +//================================================================================================== +void GeomAlgoAPI_UnifySameDomain::build(const GeomShapePtr& theShape, + const bool theIsToSimplifyShell) +{ ShapeUpgrade_UnifySameDomain* aUnifyAlgo = new ShapeUpgrade_UnifySameDomain(); this->setImpl(aUnifyAlgo); - aUnifyAlgo->Initialize(aShell); + const TopoDS_Shape& aShape = theShape->impl(); + aUnifyAlgo->Initialize(aShape, Standard_True, Standard_True, Standard_True); + aUnifyAlgo->SetLinearTolerance(defineLinearTolerance(aShape)); + aUnifyAlgo->SetAngularTolerance(1.e-5); // for #32443 aUnifyAlgo->Build(); TopoDS_Shape aResult = aUnifyAlgo->Shape(); if (aResult.IsNull()) { return; } + // take off the compound if it consists of single sub-shape + if (aResult.ShapeType() == TopAbs_COMPOUND) { + aResult = GeomAlgoAPI_DFLoader::refineResult(aResult); + } - if (aResult.ShapeType() == TopAbs_SHELL) { + if (theIsToSimplifyShell && aResult.ShapeType() == TopAbs_SHELL) { int aNb = 0; TopoDS_Iterator anIt(aResult); for (; anIt.More(); anIt.Next()) { @@ -78,9 +122,9 @@ void GeomAlgoAPI_UnifySameDomain::build(const ListOfShape& theShapes) } } - std::shared_ptr aShape(new GeomAPI_Shape()); - aShape->setImpl(new TopoDS_Shape(aResult)); - this->setShape(aShape); + std::shared_ptr aResShape(new GeomAPI_Shape()); + aResShape->setImpl(new TopoDS_Shape(aResult)); + this->setShape(aResShape); this->setDone(true); } @@ -96,10 +140,13 @@ void GeomAlgoAPI_UnifySameDomain::modified(const std::shared_ptr const ShapeUpgrade_UnifySameDomain& aUnifyAlgo = this->impl(); for (int aIsModified = 0; aIsModified <= 1; aIsModified++) { + if (!aUnifyAlgo.History()->IsSupportedType(aShape)) // to avoid crash in BRepTools_History + continue; const TopTools_ListOfShape& aMList = aIsModified ? aUnifyAlgo.History()->Modified(aShape) : aUnifyAlgo.History()->Generated(aShape); for (TopTools_ListIteratorOfListOfShape aModified(aMList); aModified.More(); aModified.Next()) { - for (TopExp_Explorer anExp(aModified.Value(), aShape.ShapeType()); anExp.More(); anExp.Next()) { + for (TopExp_Explorer anExp(aModified.Value(), aShape.ShapeType()); + anExp.More(); anExp.Next()) { GeomShapePtr aGeomShape(new GeomAPI_Shape()); aGeomShape->setImpl(new TopoDS_Shape(anExp.Current())); theHistory.push_back(aGeomShape);