X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGeomAlgoAPI%2FGeomAlgoAPI_MakeShape.cpp;h=dad018f0cee8d427301db1e382540b5df2e37a49;hb=87f348fe7ec3805441bd5524536736eeb2e87501;hp=e608956c683b3d0556672c0bdc5c1f6381339b82;hpb=ec97f1d56de8f3975e2952278c536159c8ff3da0;p=modules%2Fshaper.git diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.cpp index e608956c6..dad018f0c 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.cpp @@ -3,32 +3,33 @@ // File: GeomAlgoAPI_MakeShape.cpp // Created: 20 Oct 2014 // Author: Sergey ZARITCHNY +// +// Modified by Clarisse Genrault (CEA) : 17 Mar 2016 -#include +#include "GeomAlgoAPI_MakeShape.h" #include #include -#include +#include +#include +#include +#include #include #include #include +#include //================================================================================================= -GeomAlgoAPI_MakeShape::GeomAlgoAPI_MakeShape(void* theMkShape, const AlgoType theAlgoType) -: GeomAPI_Interface(theMkShape), - myAlgoType(theAlgoType), - myShape(new GeomAPI_Shape()) +GeomAlgoAPI_MakeShape::GeomAlgoAPI_MakeShape() +: myBuilderType(Unknown), + myDone(false) { - switch (myAlgoType) { - case MakeShape: { - myShape->setImpl(new TopoDS_Shape(implPtr()->Shape())); - break; - } - case BOPAlgoBuilder: { - myShape->setImpl(new TopoDS_Shape(implPtr()->Shape())); - break; - } - } +} + +//================================================================================================= +bool GeomAlgoAPI_MakeShape::isDone() const +{ + return myDone; } //================================================================================================= @@ -37,15 +38,42 @@ const std::shared_ptr GeomAlgoAPI_MakeShape::shape() const return myShape; } +//================================================================================================= +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) { TopTools_ListOfShape aList; - if(myAlgoType == MakeShape) { + if(myBuilderType == OCCT_BRepBuilderAPI_MakeShape) { BRepBuilderAPI_MakeShape* aMakeShape = implPtr(); aList = aMakeShape->Generated(theShape->impl()); - } else if(myAlgoType == BOPAlgoBuilder) { + } else if(myBuilderType == OCCT_BOPAlgo_Builder) { BOPAlgo_Builder* aBOPBuilder = implPtr(); aList = aBOPBuilder->Generated(theShape->impl()); } @@ -64,10 +92,13 @@ void GeomAlgoAPI_MakeShape::modified(const std::shared_ptr theSha ListOfShape& theHistory) { TopTools_ListOfShape aList; - if(myAlgoType == MakeShape) { + if(myBuilderType == OCCT_BRepBuilderAPI_MakeShape) { BRepBuilderAPI_MakeShape* aMakeShape = implPtr(); - aList = aMakeShape->Modified(theShape->impl()); - } else if(myAlgoType == BOPAlgoBuilder) { + try { + aList = aMakeShape->Modified(theShape->impl()); + } catch(Standard_NoSuchObject) { + } + } else if(myBuilderType == OCCT_BOPAlgo_Builder) { BOPAlgo_Builder* aBOPBuilder = implPtr(); aList = aBOPBuilder->Modified(theShape->impl()); } @@ -85,13 +116,135 @@ void GeomAlgoAPI_MakeShape::modified(const std::shared_ptr theSha bool GeomAlgoAPI_MakeShape::isDeleted(const std::shared_ptr theShape) { bool isDeleted = false; - if(myAlgoType == MakeShape) { + if(myBuilderType == OCCT_BRepBuilderAPI_MakeShape) { BRepBuilderAPI_MakeShape* aMakeShape = implPtr(); isDeleted = aMakeShape->IsDeleted(theShape->impl()) == Standard_True; - } else if(myAlgoType == BOPAlgoBuilder) { + } 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 ; +} +