X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FGeomAlgoAPI%2FGeomAlgoAPI_Pipe.cpp;h=236f8e944d0efdc87925cc54a9a697170d8d55bb;hb=ade68d25465a422af49d71881550bd89a2ecb824;hp=d8056eb153fd19204c2c6841bf12e668e3096b31;hpb=57e5ff999c4f23cc66bc2c91fc298c8acf63b2b2;p=modules%2Fshaper.git diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Pipe.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Pipe.cpp index d8056eb15..236f8e944 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Pipe.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Pipe.cpp @@ -1,11 +1,27 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: GeomAlgoAPI_Pipe.cpp -// Created: 16 March 2016 -// Author: Dmitry Bobylev +// Copyright (C) 2014-2017 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 +// License as published by the Free Software Foundation; either +// 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 +// 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 +// +// See http://www.salome-platform.org/ or +// email : webmaster.salome@opencascade.com +// #include "GeomAlgoAPI_Pipe.h" +#include "GeomAlgoAPI_DFLoader.h" + #include #include #include @@ -28,36 +44,32 @@ static bool getBase(TopoDS_Shape& theBaseOut, static bool getPath(TopoDS_Wire& thePathOut, const GeomShapePtr thePathShape); static bool buildPipe(BRepOffsetAPI_MakePipeShell* thePipeBuilder); +static ListOfShape getListFromShape(const TopoDS_Shape& theShape); -//================================================================================================= +//================================================================================================== GeomAlgoAPI_Pipe::GeomAlgoAPI_Pipe(const GeomShapePtr theBaseShape, const GeomShapePtr thePathShape) -: /*myIsPipeShellUsed(false),*/ - myBaseShape(theBaseShape), - myPathShape(thePathShape) { build(theBaseShape, thePathShape); } -//================================================================================================= +//================================================================================================== GeomAlgoAPI_Pipe::GeomAlgoAPI_Pipe(const GeomShapePtr theBaseShape, const GeomShapePtr thePathShape, const GeomShapePtr theBiNormal) -//: myIsPipeShellUsed(true) { build(theBaseShape, thePathShape, theBiNormal); } -//================================================================================================= +//================================================================================================== GeomAlgoAPI_Pipe::GeomAlgoAPI_Pipe(const ListOfShape& theBaseShapes, const ListOfShape& theLocations, const GeomShapePtr thePathShape) -//: myIsPipeShellUsed(true) { build(theBaseShapes, theLocations, thePathShape); } -//================================================================================================= +//================================================================================================== void GeomAlgoAPI_Pipe::build(const GeomShapePtr theBaseShape, const GeomShapePtr thePathShape) { @@ -72,7 +84,7 @@ void GeomAlgoAPI_Pipe::build(const GeomShapePtr theBaseShape, TopAbs_ShapeEnum aBaseShapeType = aBaseShape.ShapeType(); if(aBaseShapeType != TopAbs_VERTEX && aBaseShapeType != TopAbs_EDGE && aBaseShapeType != TopAbs_WIRE && aBaseShapeType != TopAbs_FACE && - aBaseShapeType != TopAbs_SHELL) { + aBaseShapeType != TopAbs_SHELL && aBaseShapeType != TopAbs_COMPOUND) { return; } @@ -97,21 +109,19 @@ void GeomAlgoAPI_Pipe::build(const GeomShapePtr theBaseShape, this->initialize(aPipeBuilder); // Setting naming. - GeomShapePtr aFromShape(new GeomAPI_Shape), aToShape(new GeomAPI_Shape); - aFromShape->setImpl(new TopoDS_Shape(aPipeBuilder->FirstShape())); - aToShape->setImpl(new TopoDS_Shape(aPipeBuilder->LastShape())); - this->addFromShape(aFromShape); - this->addToShape(aToShape); + this->setToShapes(getListFromShape(aPipeBuilder->LastShape())); + this->setFromShapes(getListFromShape(aPipeBuilder->FirstShape())); // Setting result. - TopoDS_Shape aResultShape = aPipeBuilder->Shape(); - GeomShapePtr aResultGeomShape(new GeomAPI_Shape()); - aResultGeomShape->setImpl(new TopoDS_Shape(aResultShape)); - this->setShape(aResultGeomShape); + TopoDS_Shape aResult = aPipeBuilder->Shape(); + aResult = GeomAlgoAPI_DFLoader::refineResult(aResult); + GeomShapePtr aGeomSh(new GeomAPI_Shape()); + aGeomSh->setImpl(new TopoDS_Shape(aResult)); + this->setShape(aGeomSh); this->setDone(true); } -//================================================================================================= +//================================================================================================== void GeomAlgoAPI_Pipe::build(const GeomShapePtr theBaseShape, const GeomShapePtr thePathShape, const GeomShapePtr theBiNormal) @@ -165,31 +175,30 @@ void GeomAlgoAPI_Pipe::build(const GeomShapePtr theBaseShape, return; } } - if(aPipeBuilder->Shape().IsNull()) { + TopoDS_Shape aResult = aPipeBuilder->Shape(); + if(aResult.IsNull()) { return; } // Setting naming. - GeomShapePtr aFromShape(new GeomAPI_Shape), aToShape(new GeomAPI_Shape); - aFromShape->setImpl(new TopoDS_Shape(aPipeBuilder->FirstShape())); - aToShape->setImpl(new TopoDS_Shape(aPipeBuilder->LastShape())); - this->addFromShape(aFromShape); - this->addToShape(aToShape); + this->setToShapes(getListFromShape(aPipeBuilder->LastShape())); + this->setFromShapes(getListFromShape(aPipeBuilder->FirstShape())); // Setting result. - TopoDS_Shape aResultShape = aPipeBuilder->Shape(); - GeomShapePtr aResultGeomShape(new GeomAPI_Shape()); - aResultGeomShape->setImpl(new TopoDS_Shape(aResultShape)); - this->setShape(aResultGeomShape); + aResult = GeomAlgoAPI_DFLoader::refineResult(aResult); + GeomShapePtr aGeomSh(new GeomAPI_Shape()); + aGeomSh->setImpl(new TopoDS_Shape(aResult)); + this->setShape(aGeomSh); this->setDone(true); } -//================================================================================================= +//================================================================================================== void GeomAlgoAPI_Pipe::build(const ListOfShape& theBaseShapes, const ListOfShape& theLocations, const GeomShapePtr thePathShape) { - if(theBaseShapes.empty() || (!theLocations.empty() && theLocations.size() != theBaseShapes.size())) { + if(theBaseShapes.empty() || + (!theLocations.empty() && theLocations.size() != theBaseShapes.size())) { return; } @@ -205,49 +214,66 @@ void GeomAlgoAPI_Pipe::build(const ListOfShape& theBaseShapes, } // Making pipe. - BRepOffsetAPI_MakePipeShell* aPipeBuilder = new BRepOffsetAPI_MakePipeShell(aPathWire); - if(!aPipeBuilder) { - return; - } + Standard_Boolean isDone = Standard_False; bool anIsSolidNeeded = false; - ListOfShape::const_iterator aBaseIt = theBaseShapes.cbegin(); - ListOfShape::const_iterator aLocIt = theLocations.cbegin(); - while(aBaseIt != theBaseShapes.cend()) { - GeomShapePtr aBase = *aBaseIt; - TopoDS_Shape aBaseShape; - TopAbs_ShapeEnum aBaseShapeType; - if(!getBase(aBaseShape, aBaseShapeType, aBase)) { - delete aPipeBuilder; + BRepOffsetAPI_MakePipeShell* aPipeBuilder; + for(int i = 0; i < 2; ++i) { + aPipeBuilder = new BRepOffsetAPI_MakePipeShell(aPathWire); + if(!aPipeBuilder) { return; } - ++aBaseIt; - if(aBaseShapeType == TopAbs_FACE) { - anIsSolidNeeded = true; - } - - if(aHasLocations) { - GeomShapePtr aLocation = *aLocIt; - if(!aLocation.get() || aLocation->shapeType() != GeomAPI_Shape::VERTEX) { + ListOfShape::const_iterator aBaseIt = theBaseShapes.cbegin(); + ListOfShape::const_iterator aLocIt = theLocations.cbegin(); + while(aBaseIt != theBaseShapes.cend()) { + GeomShapePtr aBase = *aBaseIt; + TopoDS_Shape aBaseShape; + TopAbs_ShapeEnum aBaseShapeType; + if(!getBase(aBaseShape, aBaseShapeType, aBase)) { delete aPipeBuilder; return; } - TopoDS_Vertex aLocationVertex = aLocation->impl(); - ++aLocIt; - aPipeBuilder->Add(aBaseShape, aLocationVertex); - } else { - aPipeBuilder->Add(aBaseShape); + ++aBaseIt; + if(aBaseShapeType == TopAbs_FACE) { + anIsSolidNeeded = true; + } + + if(aHasLocations) { + GeomShapePtr aLocation = *aLocIt; + if(!aLocation.get() || aLocation->shapeType() != GeomAPI_Shape::VERTEX) { + delete aPipeBuilder; + return; + } + TopoDS_Vertex aLocationVertex = aLocation->impl(); + ++aLocIt; + aPipeBuilder->Add(aBaseShape, aLocationVertex); + } else { + aPipeBuilder->Add(aBaseShape); + } + } + + if(aPipeBuilder->IsReady() == Standard_False) { + delete aPipeBuilder; + return; + } + + if (i == 1) { + // Try to use Descrete Trihedron mode. + aPipeBuilder->SetDiscreteMode(); + } + aPipeBuilder->Build(); + isDone = aPipeBuilder->IsDone(); + + if (isDone) { + break; } - } - if(aPipeBuilder->IsReady() == Standard_False) { delete aPipeBuilder; - return; } - if(!buildPipe(aPipeBuilder)) { - delete aPipeBuilder; + if (!isDone) { return; } + this->initialize(aPipeBuilder); // Checking result. @@ -256,9 +282,7 @@ void GeomAlgoAPI_Pipe::build(const ListOfShape& theBaseShapes, return; } } - if(aPipeBuilder->Shape().IsNull()) { - return; - } + TopoDS_Shape aResult = aPipeBuilder->Shape(); // Setting naming. GeomShapePtr aFromShape(new GeomAPI_Shape), aToShape(new GeomAPI_Shape); @@ -268,14 +292,17 @@ void GeomAlgoAPI_Pipe::build(const ListOfShape& theBaseShapes, this->addToShape(aToShape); // Setting result. - TopoDS_Shape aResultShape = aPipeBuilder->Shape(); - GeomShapePtr aResultGeomShape(new GeomAPI_Shape()); - aResultGeomShape->setImpl(new TopoDS_Shape(aResultShape)); - this->setShape(aResultGeomShape); + if(aResult.IsNull()) { + return; + } + aResult = GeomAlgoAPI_DFLoader::refineResult(aResult); + GeomShapePtr aGeomSh(new GeomAPI_Shape()); + aGeomSh->setImpl(new TopoDS_Shape(aResult)); + this->setShape(aGeomSh); this->setDone(true); } -//================================================================================================= +//================================================================================================== void GeomAlgoAPI_Pipe::generated(const GeomShapePtr theShape, ListOfShape& theHistory) { @@ -283,7 +310,7 @@ void GeomAlgoAPI_Pipe::generated(const GeomShapePtr theShape, } // Auxilary functions: -//================================================================================================= +//================================================================================================== bool getBase(TopoDS_Shape& theBaseOut, TopAbs_ShapeEnum& theBaseTypeOut, const GeomShapePtr theBaseShape) @@ -313,7 +340,7 @@ bool getBase(TopoDS_Shape& theBaseOut, return true; } -//================================================================================================= +//================================================================================================== bool getPath(TopoDS_Wire& thePathOut, const GeomShapePtr thePathShape) { @@ -338,7 +365,7 @@ bool getPath(TopoDS_Wire& thePathOut, return true; } -//================================================================================================= +//================================================================================================== bool buildPipe(BRepOffsetAPI_MakePipeShell* thePipeBuilder) { thePipeBuilder->Build(); @@ -353,4 +380,25 @@ bool buildPipe(BRepOffsetAPI_MakePipeShell* thePipeBuilder) } return isDone == Standard_True; -} \ No newline at end of file +} + +//================================================================================================== +ListOfShape getListFromShape(const TopoDS_Shape& theShape) +{ + ListOfShape aList; + + TopAbs_ShapeEnum aType = theShape.ShapeType(); + if(aType == TopAbs_WIRE || aType == TopAbs_SHELL || aType == TopAbs_COMPOUND) { + for(TopoDS_Iterator anIt(theShape); anIt.More(); anIt.Next()) { + GeomShapePtr aGeomShape(new GeomAPI_Shape()); + aGeomShape->setImpl(new TopoDS_Shape(anIt.Value())); + aList.push_back(aGeomShape); + } + } else { + GeomShapePtr aGeomShape(new GeomAPI_Shape()); + aGeomShape->setImpl(new TopoDS_Shape(theShape)); + aList.push_back(aGeomShape); + } + + return aList; +}