X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGeomAlgoAPI%2FGeomAlgoAPI_MakeShape.cpp;h=916feb8142afc338f158f68bd5578f0daecab1c2;hb=f2f34e30b41047d12277ad87e1adf6c0e410e4ff;hp=679526befc0e3e94fad7d9fa0f636cd8516ac822;hpb=3d05371426a5cff18de7567af866d1ca8a8c6128;p=modules%2Fshaper.git diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.cpp index 679526bef..916feb814 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.cpp @@ -1,58 +1,262 @@ -// File: GeomAlgoAPI_MakeShape.cpp -// Created: 20 Oct 2014 -// Author: Sergey ZARITCHNY +// 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 +#include "GeomAlgoAPI_MakeShape.h" + +#include +#include +#include +#include +#include +#include +#include #include #include -GeomAlgoAPI_MakeShape::GeomAlgoAPI_MakeShape(void* theMkShape) - : GeomAPI_Interface(theMkShape) -{} +#include -const boost::shared_ptr GeomAlgoAPI_MakeShape::shape() const +//================================================================================================= +GeomAlgoAPI_MakeShape::GeomAlgoAPI_MakeShape() +: myBuilderType(Unknown), + myDone(false) +{ +} + +//================================================================================================= +bool GeomAlgoAPI_MakeShape::isDone() const +{ + return myDone; +} + +//================================================================================================= +const std::shared_ptr GeomAlgoAPI_MakeShape::shape() const { return myShape; } -/// Returns the list of shapes generated from the shape -void GeomAlgoAPI_MakeShape::generated( - const boost::shared_ptr theShape, ListOfShape& theHistory) +//================================================================================================= +bool GeomAlgoAPI_MakeShape::isValid() const +{ + BRepCheck_Analyzer aChecker(myShape->impl()); + return (aChecker.IsValid() == Standard_True); +} + +//================================================================================================= +bool GeomAlgoAPI_MakeShape::hasVolume() const +{ + bool hasVolume = false; + if(isValid()) { + const TopoDS_Shape& aRShape = myShape->impl(); + GProp_GProps aGProp; + BRepGProp::VolumeProperties(aRShape, aGProp); + if(aGProp.Mass() > Precision::Confusion()) + hasVolume = true; + } + return hasVolume; +} + +//================================================================================================= +std::shared_ptr GeomAlgoAPI_MakeShape::mapOfSubShapes() const +{ + return myMap; +} + +//================================================================================================= +void GeomAlgoAPI_MakeShape::generated(const std::shared_ptr theShape, + ListOfShape& theHistory) { - BRepBuilderAPI_MakeShape* aBuilder = implPtr(); - if(aBuilder) { - const TopTools_ListOfShape& aList = aBuilder->Generated(theShape->impl()); - TopTools_ListIteratorOfListOfShape it(aList); - for(;it.More();it.Next()) { - boost::shared_ptr aShape(new GeomAPI_Shape()); - aShape->setImpl(&(it.Value())); - theHistory.push_back(aShape); + TopTools_ListOfShape aList; + if(myBuilderType == OCCT_BRepBuilderAPI_MakeShape) { + BRepBuilderAPI_MakeShape* aMakeShape = implPtr(); + aList = aMakeShape->Generated(theShape->impl()); + } else if(myBuilderType == OCCT_BOPAlgo_Builder) { + BOPAlgo_Builder* aBOPBuilder = implPtr(); + aList = aBOPBuilder->Generated(theShape->impl()); + } + for(TopTools_ListIteratorOfListOfShape anIt(aList); anIt.More(); anIt.Next()) { + if(anIt.Value().IsNull()) { + continue; } + std::shared_ptr aShape(new GeomAPI_Shape()); + aShape->setImpl(new TopoDS_Shape(anIt.Value())); + theHistory.push_back(aShape); } } -/// Returns the list of shapes modified from the shape -void GeomAlgoAPI_MakeShape::modified( - const boost::shared_ptr theShape, ListOfShape& theHistory) +//================================================================================================= +void GeomAlgoAPI_MakeShape::modified(const std::shared_ptr theShape, + ListOfShape& theHistory) { - BRepBuilderAPI_MakeShape* aBuilder = implPtr(); - if(aBuilder) { - const TopTools_ListOfShape& aList = aBuilder->Modified(theShape->impl()); - TopTools_ListIteratorOfListOfShape it(aList); - for(;it.More();it.Next()) { - boost::shared_ptr aShape(new GeomAPI_Shape()); - aShape->setImpl(&(it.Value())); - theHistory.push_back(aShape); + TopTools_ListOfShape aList; + if(myBuilderType == OCCT_BRepBuilderAPI_MakeShape) { + BRepBuilderAPI_MakeShape* aMakeShape = implPtr(); + try { + aList = aMakeShape->Modified(theShape->impl()); + } catch(Standard_NoSuchObject) { + } + } else if(myBuilderType == OCCT_BOPAlgo_Builder) { + BOPAlgo_Builder* aBOPBuilder = implPtr(); + aList = aBOPBuilder->Modified(theShape->impl()); + } + for(TopTools_ListIteratorOfListOfShape anIt(aList); anIt.More(); anIt.Next()) { + if(anIt.Value().IsNull()) { + continue; } + std::shared_ptr aShape(new GeomAPI_Shape()); + aShape->setImpl(new TopoDS_Shape(anIt.Value())); + theHistory.push_back(aShape); } } -/// Returns whether the shape is an edge -bool GeomAlgoAPI_MakeShape::isDeleted(const boost::shared_ptr theShape) +//================================================================================================= +bool GeomAlgoAPI_MakeShape::isDeleted(const std::shared_ptr theShape) { - bool isDeleted(false); - BRepBuilderAPI_MakeShape* aBuilder = implPtr(); - if(aBuilder) { - isDeleted = aBuilder->IsDeleted(theShape->impl()) == Standard_True; + bool isDeleted = false; + if(myBuilderType == OCCT_BRepBuilderAPI_MakeShape) { + BRepBuilderAPI_MakeShape* aMakeShape = implPtr(); + isDeleted = aMakeShape->IsDeleted(theShape->impl()) == Standard_True; + } else if(myBuilderType == OCCT_BOPAlgo_Builder) { + BOPAlgo_Builder* aBOPBuilder = implPtr(); + isDeleted = aBOPBuilder->IsDeleted(theShape->impl()) == Standard_True; } + return isDeleted; } + +//================================================================================================= +void GeomAlgoAPI_MakeShape::setBuilderType(const BuilderType theBuilderType) +{ + myBuilderType = theBuilderType; +} + +//================================================================================================= +void GeomAlgoAPI_MakeShape::setDone(const bool theFlag) +{ + myDone = theFlag; +} + +//================================================================================================= +void GeomAlgoAPI_MakeShape::setShape(const std::shared_ptr theShape) +{ + if(myShape.get() && myShape->isEqual(theShape)) { + return; + } + + myShape = theShape; + + // Filling data map to keep correct orientation of sub-shapes. + if(myShape.get()) { + if(myMap.get()) { + myMap->clear(); + } else { + myMap.reset(new GeomAPI_DataMapOfShapeShape); + } + + const TopoDS_Shape& aTopoDSShape = myShape->impl(); + for(TopExp_Explorer anExp(aTopoDSShape,TopAbs_VERTEX); anExp.More(); anExp.Next()) { + std::shared_ptr aCurrentShape(new GeomAPI_Shape()); + aCurrentShape->setImpl(new TopoDS_Shape(anExp.Current())); + myMap->bind(aCurrentShape, aCurrentShape); + } + for(TopExp_Explorer anExp(aTopoDSShape,TopAbs_EDGE); anExp.More(); anExp.Next()) { + std::shared_ptr aCurrentShape(new GeomAPI_Shape()); + aCurrentShape->setImpl(new TopoDS_Shape(anExp.Current())); + myMap->bind(aCurrentShape, aCurrentShape); + } + for(TopExp_Explorer anExp(aTopoDSShape,TopAbs_FACE); anExp.More(); anExp.Next()) { + std::shared_ptr aCurrentShape(new GeomAPI_Shape()); + aCurrentShape->setImpl(new TopoDS_Shape(anExp.Current())); + myMap->bind(aCurrentShape, aCurrentShape); + } + } else { + if(myMap.get()) { + myMap->clear(); + } + } +} + +//================================================================================================= +void GeomAlgoAPI_MakeShape::initialize() { + switch (myBuilderType) { + case OCCT_BRepBuilderAPI_MakeShape: { + myDone = implPtr()->IsDone() == Standard_True; + myShape.reset(new GeomAPI_Shape()); + myShape->setImpl(new TopoDS_Shape(implPtr()->Shape())); + break; + } + case OCCT_BOPAlgo_Builder: { + myDone = true; + myShape.reset(new GeomAPI_Shape()); + myShape->setImpl(new TopoDS_Shape(implPtr()->Shape())); + break; + } + } + + if(myMap.get()) { + myMap->clear(); + } else { + myMap.reset(new GeomAPI_DataMapOfShapeShape); + } + + const TopoDS_Shape& aTopoDSShape = myShape->impl(); + for(TopExp_Explorer anExp(aTopoDSShape,TopAbs_FACE); anExp.More(); anExp.Next()) { + std::shared_ptr aCurrentShape(new GeomAPI_Shape()); + aCurrentShape->setImpl(new TopoDS_Shape(anExp.Current())); + myMap->bind(aCurrentShape, aCurrentShape); + } +} + + +//================================================================================================= +void GeomAlgoAPI_MakeShape::prepareNamingFaces() +{ + long long index = 1; + GeomAPI_ShapeExplorer anExp(shape(), GeomAPI_Shape::FACE); + for(GeomAPI_ShapeExplorer anExp(shape(), GeomAPI_Shape::FACE); anExp.more(); anExp.next()) { + std::shared_ptr aFace = anExp.current(); + myCreatedFaces["Face_" + std::to_string(index++)] = aFace; + } +} + + +//================================================================================================= +bool GeomAlgoAPI_MakeShape::checkValid(std::string theMessage){ + + // isValid() is called from this method + if (!isValid()) { + myError = theMessage + " :: resulting shape is not valid."; + return false; + } + + // Check the number of volumes in myShape, make sure there's one and only one. + TopoDS_Shape aTopoDSShape = myShape->impl(); + int aNbVolumes = 0; + for(TopExp_Explorer anExp(aTopoDSShape,TopAbs_SOLID); anExp.More(); anExp.Next()) { + aNbVolumes ++; + } + + if (aNbVolumes != 1) { + myError = theMessage + + " :: connexity error, the resulting shape is made of several separate solids."; + return false; + } + + return true ; +} +