X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGeomAlgoAPI%2FGeomAlgoAPI_Pipe.cpp;h=819c8d70963bba7aa0da9d4016e3510a580e2c01;hb=fdd802da7683f66ca609cf12b1e11be9642149d6;hp=4ce80d3ffb0849a8149e182400328aaa2bbf6ae2;hpb=e2823a1620aa63a7df7f6c952b9ae241766abf7a;p=modules%2Fshaper.git diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Pipe.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Pipe.cpp index 4ce80d3ff..819c8d709 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Pipe.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Pipe.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// Copyright (C) 2014-2020 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -12,10 +12,9 @@ // // 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_Pipe.h" @@ -25,6 +24,7 @@ #include #include #include +#include #include #include @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -77,16 +78,32 @@ GeomAlgoAPI_Pipe::GeomAlgoAPI_Pipe(const ListOfShape& theBaseShapes, void GeomAlgoAPI_Pipe::build(const GeomShapePtr theBaseShape, const GeomShapePtr thePathShape) { - // Getting base shape and path. - TopoDS_Shape aBaseShape; - TopAbs_ShapeEnum aBaseShapeType; - TopoDS_Wire aPathWire; - if (!getBase(aBaseShape, aBaseShapeType, theBaseShape) || - !getPath(aPathWire, thePathShape)) { + // Getting base shape. + if(!theBaseShape.get()) { + return; + } + TopoDS_Shape aBaseShape = theBaseShape->impl(); + if(aBaseShape.IsNull()) { + return; + } + TopAbs_ShapeEnum aBaseShapeType = aBaseShape.ShapeType(); + if(aBaseShapeType != TopAbs_VERTEX && aBaseShapeType != TopAbs_EDGE && + aBaseShapeType != TopAbs_WIRE && aBaseShapeType != TopAbs_FACE && + aBaseShapeType != TopAbs_SHELL && aBaseShapeType != TopAbs_COMPOUND) { return; } + // Getting path. + TopoDS_Wire aPathWire; + if(!getPath(aPathWire, thePathShape)) { + return; + } + GeomShapePtr anOldPath(new GeomAPI_Shape), aNewPath(new GeomAPI_Shape); + anOldPath->setImpl(new TopoDS_Shape(aPathWire)); aPathWire.Move(getPathToBaseTranslation(aBaseShape, aPathWire)); + aNewPath->setImpl(new TopoDS_Shape(aPathWire)); + if (!anOldPath->isSame(aNewPath)) + addMovedPath(anOldPath, aNewPath); // Making pipe. BRepOffsetAPI_MakePipe* aPipeBuilder = new BRepOffsetAPI_MakePipe(aPathWire, aBaseShape); @@ -130,7 +147,12 @@ void GeomAlgoAPI_Pipe::build(const GeomShapePtr theBaseShape, return; } + GeomShapePtr anOldPath(new GeomAPI_Shape), aNewPath(new GeomAPI_Shape); + anOldPath->setImpl(new TopoDS_Shape(aPathWire)); aPathWire.Move(getPathToBaseTranslation(theBaseShape->impl(), aPathWire)); + aNewPath->setImpl(new TopoDS_Shape(aPathWire)); + if (!anOldPath->isSame(aNewPath)) + addMovedPath(anOldPath, aNewPath); // Getting Bi-Normal. TopoDS_Shape aBiNormalShape = theBiNormal->impl(); @@ -201,7 +223,13 @@ void GeomAlgoAPI_Pipe::build(const ListOfShape& theBaseShapes, TopoDS_Shape aReallyBase = theBaseShapes.front()->impl(); gp_Trsf aTrsf = getPathToBaseTranslation(aReallyBase, aPathWire); + + GeomShapePtr anOldPath(new GeomAPI_Shape), aNewPath(new GeomAPI_Shape); + anOldPath->setImpl(new TopoDS_Shape(aPathWire)); aPathWire.Move(aTrsf); + aNewPath->setImpl(new TopoDS_Shape(aPathWire)); + if (!anOldPath->isSame(aNewPath)) + addMovedPath(anOldPath, aNewPath); // Get locations after moving path shape. std::list aLocations; @@ -319,7 +347,10 @@ void GeomAlgoAPI_Pipe::build(const ListOfShape& theBaseShapes, void GeomAlgoAPI_Pipe::generated(const GeomShapePtr theShape, ListOfShape& theHistory) { - GeomAlgoAPI_MakeShape::generated(theShape, theHistory); + if (myMovedPath.isBound(theShape)) + GeomAlgoAPI_MakeShape::generated(myMovedPath.find(theShape), theHistory); + else + GeomAlgoAPI_MakeShape::generated(theShape, theHistory); } // Auxilary functions: @@ -387,6 +418,31 @@ gp_Trsf getPathToBaseTranslation(const TopoDS_Shape& theBase, const TopoDS_Shape if (aDist.IsDone() && aDist.Value() > Precision::Confusion()) { gp_Pnt aPntBase = aDist.PointOnShape1(1); gp_Pnt aPntPath = aDist.PointOnShape2(1); + // get the end point on the path nearest to the found point, + // because the path is almost usually started from the one of the sections + if (!BRep_Tool::IsClosed(thePath)) { + TopoDS_Wire aPathWire = TopoDS::Wire(thePath); + if (!aPathWire.IsNull()) { + TopoDS_Vertex aV1, aV2; + TopExp::Vertices(aPathWire, aV1, aV2); + + gp_Pnt aStart = BRep_Tool::Pnt(aV1); + gp_Pnt anEnd = BRep_Tool::Pnt(aV2); + + // compare 3 distances + double aDistToStart = aPntBase.Distance(aStart); + double aDistToEnd = aPntBase.Distance(anEnd); + double aMinDist = aPntBase.Distance(aPntPath); + + static const double THE_THRESHOLD = 0.01; // threshold for distance ratio + double aDeltaStart = Abs(aDistToStart - aMinDist); + double aDeltaEnd = Abs(aDistToEnd - aMinDist); + if (aDeltaStart < THE_THRESHOLD * aDeltaEnd) + aPntPath = aStart; + else if (aDeltaEnd < THE_THRESHOLD * aDeltaStart) + aPntPath = anEnd; + } + } aTranslation.SetTranslation(aPntPath, aPntBase); } @@ -430,3 +486,14 @@ ListOfShape getListFromShape(const TopoDS_Shape& theShape) return aList; } + +//================================================================================================== +void GeomAlgoAPI_Pipe::addMovedPath(GeomShapePtr thePath, GeomShapePtr theMoved) +{ + myMovedPath.clear(); + GeomAPI_ShapeExplorer anOldExp(thePath, GeomAPI_Shape::EDGE); + GeomAPI_ShapeExplorer aNewExp(theMoved, GeomAPI_Shape::EDGE); + for(; anOldExp.more(); anOldExp.next(), aNewExp.next()) { + myMovedPath.bind(anOldExp.current(), aNewExp.current()); + } +}