From 2a232230cb243c76c34315623d6e6689f57e83f4 Mon Sep 17 00:00:00 2001 From: dbv Date: Tue, 22 Dec 2015 16:14:50 +0300 Subject: [PATCH] GeomAlgoAPI_Prism now derived from GeomAlgoAPI_MakeSweep --- src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp | 11 +- .../FeaturesPlugin_CompositeBoolean.cpp | 17 ++- .../FeaturesPlugin_Extrusion.cpp | 12 +- .../FeaturesPlugin_ExtrusionSketch.cpp | 16 +-- .../FeaturesPlugin_Partition.cpp | 6 +- src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.cpp | 60 +++++++++- src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.h | 77 ++++++------- src/GeomAlgoAPI/GeomAlgoAPI_MakeShapeList.cpp | 25 ++--- src/GeomAlgoAPI/GeomAlgoAPI_MakeShapeList.h | 29 ++--- src/GeomAlgoAPI/GeomAlgoAPI_MakeSweep.cpp | 26 ++++- src/GeomAlgoAPI/GeomAlgoAPI_MakeSweep.h | 23 +++- src/GeomAlgoAPI/GeomAlgoAPI_Prism.cpp | 106 +++--------------- src/GeomAlgoAPI/GeomAlgoAPI_Prism.h | 72 +++--------- 13 files changed, 219 insertions(+), 261 deletions(-) diff --git a/src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp b/src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp index 9ab80ccfe..6a9e93929 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -199,7 +198,7 @@ void FeaturesPlugin_Boolean::execute() } GeomAlgoAPI_MakeShapeList aMakeShapeList; - aMakeShapeList.append(aBoolAlgo.makeShape()); + aMakeShapeList.appendAlgo(aBoolAlgo.makeShape()); GeomAPI_DataMapOfShapeShape aMapOfShapes; aMapOfShapes.merge(aBoolAlgo.mapOfShapes()); @@ -213,7 +212,7 @@ void FeaturesPlugin_Boolean::execute() return; } - aMakeShapeList.append(aFillerAlgo.makeShape()); + aMakeShapeList.appendAlgo(aFillerAlgo.makeShape()); aMapOfShapes.merge(aFillerAlgo.mapOfShapes()); if(GeomAlgoAPI_ShapeTools::volume(aFillerAlgo.shape()) > 1.e-7) { @@ -275,7 +274,7 @@ void FeaturesPlugin_Boolean::execute() if(GeomAlgoAPI_ShapeTools::volume(aCutAlgo.shape()) > 1.e-7) { aSolidsToFuse.push_back(aCutAlgo.shape()); - aMakeShapeList.append(aCutAlgo.makeShape()); + aMakeShapeList.appendAlgo(aCutAlgo.makeShape()); aMapOfShapes.merge(aCutAlgo.mapOfShapes()); } } @@ -307,7 +306,7 @@ void FeaturesPlugin_Boolean::execute() } std::shared_ptr aShape = aFuseAlgo.shape(); - aMakeShapeList.append(aFuseAlgo.makeShape()); + aMakeShapeList.appendAlgo(aFuseAlgo.makeShape()); aMapOfShapes.merge(aFuseAlgo.mapOfShapes()); // Add result to not used solids from compsolid (if we have any). @@ -331,7 +330,7 @@ void FeaturesPlugin_Boolean::execute() } aShape = aFillerAlgo.shape(); - aMakeShapeList.append(aFillerAlgo.makeShape()); + aMakeShapeList.appendAlgo(aFillerAlgo.makeShape()); aMapOfShapes.merge(aFillerAlgo.mapOfShapes()); } diff --git a/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.cpp b/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.cpp index c51ac16b5..02e977af9 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.cpp @@ -4,11 +4,10 @@ // Created: 11 June 2015 // Author: Dmitry Bobylev -#include +#include "FeaturesPlugin_CompositeBoolean.h" #include #include -#include #include #include #include @@ -239,7 +238,7 @@ void FeaturesPlugin_CompositeBoolean::execute() } GeomAlgoAPI_MakeShapeList aMakeShapeList; - aMakeShapeList.append(aBoolAlgo.makeShape()); + aMakeShapeList.appendAlgo(aBoolAlgo.makeShape()); GeomAPI_DataMapOfShapeShape aMapOfShapes; aMapOfShapes.merge(aBoolAlgo.mapOfShapes()); @@ -253,7 +252,7 @@ void FeaturesPlugin_CompositeBoolean::execute() return; } - aMakeShapeList.append(aFillerAlgo.makeShape()); + aMakeShapeList.appendAlgo(aFillerAlgo.makeShape()); aMapOfShapes.merge(aFillerAlgo.mapOfShapes()); if(GeomAlgoAPI_ShapeTools::volume(aFillerAlgo.shape()) > 1.e-7) { @@ -309,7 +308,7 @@ void FeaturesPlugin_CompositeBoolean::execute() if(GeomAlgoAPI_ShapeTools::volume(aCutAlgo.shape()) > 1.e-7) { aSolidsToFuse.push_back(aCutAlgo.shape()); - aMakeShapeList.append(aCutAlgo.makeShape()); + aMakeShapeList.appendAlgo(aCutAlgo.makeShape()); aMapOfShapes.merge(aCutAlgo.mapOfShapes()); } } @@ -331,7 +330,7 @@ void FeaturesPlugin_CompositeBoolean::execute() } std::shared_ptr aShape = aFuseAlgo.shape(); - aMakeShapeList.append(aFuseAlgo.makeShape()); + aMakeShapeList.appendAlgo(aFuseAlgo.makeShape()); aMapOfShapes.merge(aFuseAlgo.mapOfShapes()); // Add result to not used solids from compsolid (if we have any). @@ -355,7 +354,7 @@ void FeaturesPlugin_CompositeBoolean::execute() } aShape = aFillerAlgo.shape(); - aMakeShapeList.append(aFillerAlgo.makeShape()); + aMakeShapeList.appendAlgo(aFillerAlgo.makeShape()); aMapOfShapes.merge(aFillerAlgo.mapOfShapes()); } @@ -413,8 +412,8 @@ void FeaturesPlugin_CompositeBoolean::loadNamingDS(std::shared_ptr(*aSolidsAlgosIter)) { std::shared_ptr aPrismAlgo = std::dynamic_pointer_cast(*aSolidsAlgosIter); - aSubShapes = aPrismAlgo->mapOfShapes(); - theResultBody->loadAndOrientGeneratedShapes(aPrismAlgo->makeShape().get(), *aShellsIter, GeomAPI_Shape::EDGE, aGenTag, + aSubShapes = aPrismAlgo->mapOfSubShapes(); + theResultBody->loadAndOrientGeneratedShapes(aPrismAlgo.get(), *aShellsIter, GeomAPI_Shape::EDGE, aGenTag, aLatName, *aSubShapes.get()); aFromFaces = aPrismAlgo->fromFaces(); diff --git a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp index 3f7ed7efd..c0bcd77f3 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp @@ -4,22 +4,16 @@ // Created: 30 May 2014 // Author: Vitaly SMETANNIKOV -#include +#include "FeaturesPlugin_Extrusion.h" -#include #include #include -#include -#include #include -#include #include #include #include #include -#include #include -#include #include #include @@ -171,12 +165,12 @@ void FeaturesPlugin_Extrusion::loadNamingDS(GeomAlgoAPI_Prism& thePrismAlgo, //load result theResultBody->storeGenerated(theBasis, thePrismAlgo.shape()); - std::shared_ptr aSubShapes = thePrismAlgo.mapOfShapes(); + std::shared_ptr aSubShapes = thePrismAlgo.mapOfSubShapes(); //Insert lateral face : Face from Edge const std::string aLatName = "LateralFace"; const int aLatTag = 1; - theResultBody->loadAndOrientGeneratedShapes(thePrismAlgo.makeShape().get(), theBasis, GeomAPI_Shape::EDGE, aLatTag, aLatName, *aSubShapes); + theResultBody->loadAndOrientGeneratedShapes(&thePrismAlgo, theBasis, GeomAPI_Shape::EDGE, aLatTag, aLatName, *aSubShapes); //Insert to faces const std::string aToName = "ToFace"; diff --git a/src/FeaturesPlugin/FeaturesPlugin_ExtrusionSketch.cpp b/src/FeaturesPlugin/FeaturesPlugin_ExtrusionSketch.cpp index 682ea60ac..94fb46a4c 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_ExtrusionSketch.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_ExtrusionSketch.cpp @@ -79,17 +79,17 @@ void FeaturesPlugin_ExtrusionSketch::makeSolid(const std::shared_ptr aPrismAlgo(new GeomAlgoAPI_Prism(theFace, aToShape, aToSize, aFromShape, aFromSize)); // Checking that the algorithm worked properly. - if(!aPrismAlgo.isDone() || !aPrismAlgo.shape().get() || aPrismAlgo.shape()->isNull() || - !aPrismAlgo.isValid()) { + if(!aPrismAlgo->isDone() || !aPrismAlgo->shape().get() || aPrismAlgo->shape()->isNull() || + !aPrismAlgo->isValid()) { return; } - theResult = aPrismAlgo.shape(); - theFromFaces = aPrismAlgo.fromFaces(); - theToFaces = aPrismAlgo.toFaces(); - theMakeShape = aPrismAlgo.makeShape(); - theDataMap = aPrismAlgo.mapOfShapes(); + theResult = aPrismAlgo->shape(); + theFromFaces = aPrismAlgo->fromFaces(); + theToFaces = aPrismAlgo->toFaces(); + theMakeShape = aPrismAlgo; + theDataMap = aPrismAlgo->mapOfSubShapes(); } diff --git a/src/FeaturesPlugin/FeaturesPlugin_Partition.cpp b/src/FeaturesPlugin/FeaturesPlugin_Partition.cpp index 52ee4eaf6..94b7f4bce 100755 --- a/src/FeaturesPlugin/FeaturesPlugin_Partition.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Partition.cpp @@ -93,7 +93,7 @@ void FeaturesPlugin_Partition::execute() aTool = GeomAlgoAPI_ShapeTools::fitPlaneToBox(aContext->shape(), aBoundingPoints); std::shared_ptr aMkShCustom(new GeomAlgoAPI_MakeShapeCustom); aMkShCustom->addModified(aContext->shape(), aTool); - aMakeShapeList.append(aMkShCustom); + aMakeShapeList.appendAlgo(aMkShCustom); aTools.push_back(aTool); aToolsForNaming.push_back(aContext->shape()); } @@ -143,7 +143,7 @@ void FeaturesPlugin_Partition::execute() if (GeomAlgoAPI_ShapeTools::volume(aPartitionAlgo.shape()) > 1.e-7) { std::shared_ptr aResultBody = document()->createBody(data(), aResultIndex); - aMakeShapeList.append(aPartitionAlgo.makeShape()); + aMakeShapeList.appendAlgo(aPartitionAlgo.makeShape()); GeomAPI_DataMapOfShapeShape aMapOfShapes = *aPartitionAlgo.mapOfShapes().get(); loadNamingDS(aResultBody, anObjects.front(), aToolsForNaming, aPartitionAlgo.shape(), aMakeShapeList, aMapOfShapes); setResult(aResultBody, aResultIndex); @@ -175,7 +175,7 @@ void FeaturesPlugin_Partition::execute() if (GeomAlgoAPI_ShapeTools::volume(aPartitionAlgo.shape()) > 1.e-7) { std::shared_ptr aResultBody = document()->createBody(data(), aResultIndex); - aMakeShapeList.append(aPartitionAlgo.makeShape()); + aMakeShapeList.appendAlgo(aPartitionAlgo.makeShape()); GeomAPI_DataMapOfShapeShape aMapOfShapes = *aPartitionAlgo.mapOfShapes().get(); loadNamingDS(aResultBody, anObject, aToolsForNaming, aPartitionAlgo.shape(), aMakeShapeList, aMapOfShapes); setResult(aResultBody, aResultIndex); diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.cpp index 3b0d3ca8b..5419c4f15 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.cpp @@ -4,18 +4,21 @@ // Created: 20 Oct 2014 // Author: Sergey ZARITCHNY -#include +#include "GeomAlgoAPI_MakeShape.h" #include #include -#include +#include +#include +#include +#include #include #include #include //================================================================================================= GeomAlgoAPI_MakeShape::GeomAlgoAPI_MakeShape() -: myBuilderType(OCCT_BRepBuilderAPI_MakeShape), +: myBuilderType(UNKNOWN), myDone(false) { } @@ -32,6 +35,33 @@ 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) @@ -106,7 +136,31 @@ void GeomAlgoAPI_MakeShape::setDone(const bool 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_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(); + } + } } //================================================================================================= diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.h b/src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.h index 272f9f975..acbc9c84f 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.h @@ -12,27 +12,26 @@ #include #include -/** \class GeomAlgoAPI_MakeShape - * \ingroup DataAlgo - * \brief Interface to the root class of all topological shapes constructions - */ +/// \class GeomAlgoAPI_MakeShape +/// \ingroup DataAlgo +/// \brief Interface to the root class of all topological shapes constructions class GeomAlgoAPI_MakeShape : public GeomAPI_Interface { public: /// Builder type enum enum BuilderType { OCCT_BRepBuilderAPI_MakeShape, - OCCT_BOPAlgo_Builder + OCCT_BOPAlgo_Builder, + UNKNOWN }; public: /// \brief Empty constructor. GEOMALGOAPI_EXPORT GeomAlgoAPI_MakeShape(); - /** \brief Constructor by builder and builder type. - * \param[in] theBuilder pointer to the builder. - * \param[in] theBuilderType builder type. - */ + /// \brief Constructor by builder and builder type. + /// \param[in] theBuilder pointer to the builder. + /// \param[in] theBuilderType builder type. template explicit GeomAlgoAPI_MakeShape(T* theBuilder, const BuilderType theBuilderType = OCCT_BRepBuilderAPI_MakeShape) : GeomAPI_Interface(theBuilder), myBuilderType(theBuilderType) @@ -40,10 +39,9 @@ public: initialize(); } - /** \brief Initializes internals. - * \param[in] theBuilder pointer to the builder. - * \param[in] theBuilderType builder type. - */ + /// \brief Initializes internals. + /// \param[in] theBuilder pointer to the builder. + /// \param[in] theBuilderType builder type. template void initialize(T* theBuilder, const BuilderType theBuilderType = OCCT_BRepBuilderAPI_MakeShape) { setImpl(theBuilder); @@ -57,40 +55,43 @@ public: /// \return a shape built by the shape construction algorithm. GEOMALGOAPI_EXPORT virtual const std::shared_ptr shape() const; - /** \return the list of shapes generated from the shape \a theShape. - * \param[in] theShape base shape. - * \param[out] theHistory generated shapes. - */ + /// \return true if resulting shape is valid. + GEOMALGOAPI_EXPORT bool isValid() const; + + /// \return true if resulting shape has volume. + GEOMALGOAPI_EXPORT bool hasVolume() const; + + /// \return map of sub-shapes of the result. To be used for History keeping. + GEOMALGOAPI_EXPORT std::shared_ptr mapOfSubShapes() const; + + /// \return the list of shapes generated from the shape \a theShape. + /// \param[in] theShape base shape. + /// \param[out] theHistory generated shapes. GEOMALGOAPI_EXPORT virtual void generated(const std::shared_ptr theShape, ListOfShape& theHistory); - /** \return the list of shapes modified from the shape \a theShape. - * \param[in] theShape base shape. - * \param[out] theHistory modified shapes. - */ + /// \return the list of shapes modified from the shape \a theShape. + /// \param[in] theShape base shape. + /// \param[out] theHistory modified shapes. GEOMALGOAPI_EXPORT virtual void modified(const std::shared_ptr theShape, ListOfShape& theHistory); - /** \return true if theShape was deleted. - * \param[in] theShape base shape. - */ + /// \return true if theShape was deleted. + /// \param[in] theShape base shape. GEOMALGOAPI_EXPORT virtual bool isDeleted(const std::shared_ptr theShape); protected: - /** \brief Sets builder type. - * \param[in] theBuilderType new builder type. - */ - GEOMALGOAPI_EXPORT void setBuilderType(const BuilderType theBuilderType); - - /** \brief Sets status of builder. - * \param[in] theFlag new status. - */ - GEOMALGOAPI_EXPORT void setDone(const bool theFlag); - - /** \brief Sets result shape. - * \param[in] theShape new shape. - */ - GEOMALGOAPI_EXPORT void setShape(const std::shared_ptr theShape); + /// \brief Sets builder type. + /// \param[in] theBuilderType new builder type. + void setBuilderType(const BuilderType theBuilderType); + + /// \brief Sets status of builder. + /// \param[in] theFlag new status. + void setDone(const bool theFlag); + + /// \brief Sets result shape. + /// \param[in] theShape new shape. + void setShape(const std::shared_ptr theShape); private: /// \brief Initializes internals. diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_MakeShapeList.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_MakeShapeList.cpp index cdcc4596d..1442c5b32 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_MakeShapeList.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_MakeShapeList.cpp @@ -4,12 +4,10 @@ // Created: 27 May 2015 // Author: Dmitry Bobylev -#include +#include "GeomAlgoAPI_MakeShapeList.h" -#include #include -#include -#include +#include //================================================================================================= GeomAlgoAPI_MakeShapeList::GeomAlgoAPI_MakeShapeList() @@ -30,28 +28,21 @@ void GeomAlgoAPI_MakeShapeList::init(const ListOfMakeShape& theMakeShapeList) } //================================================================================================= -void GeomAlgoAPI_MakeShapeList::append(const std::shared_ptr theMakeShape) +void GeomAlgoAPI_MakeShapeList::appendAlgo(const std::shared_ptr theMakeShape) { myListOfMakeShape.push_back(theMakeShape); } -//================================================================================================= -void GeomAlgoAPI_MakeShapeList::append(const GeomAlgoAPI_MakeShapeList& theMakeShapeList) -{ - for(ListOfMakeShape::const_iterator anIt = theMakeShapeList.myListOfMakeShape.cbegin(); - anIt != theMakeShapeList.myListOfMakeShape.cend(); anIt++) { - myListOfMakeShape.push_back(*anIt); - } -} - //================================================================================================= const std::shared_ptr GeomAlgoAPI_MakeShapeList::shape() const { - if(myListOfMakeShape.empty()) { - return std::shared_ptr(); - } else { + std::shared_ptr aShape = GeomAlgoAPI_MakeShape::shape(); + if(aShape.get() && !aShape->impl().IsNull()) { + return aShape; + } else if(!myListOfMakeShape.empty()) { return myListOfMakeShape.back()->shape(); } + return std::shared_ptr(); } //================================================================================================= diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_MakeShapeList.h b/src/GeomAlgoAPI/GeomAlgoAPI_MakeShapeList.h index 64dfa760b..179e0d183 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_MakeShapeList.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_MakeShapeList.h @@ -12,10 +12,9 @@ #include -/** \class GeomAlgoAPI_MakeShapeList - * \ingroup DataAlgo - * \brief List of topological shapes constructions - */ +/// \class GeomAlgoAPI_MakeShapeList +/// \ingroup DataAlgo +/// \brief List of topological shapes constructions class GeomAlgoAPI_MakeShapeList : public GeomAlgoAPI_MakeShape { enum OperationType { @@ -27,25 +26,17 @@ public: /// Default constructor GEOMALGOAPI_EXPORT GeomAlgoAPI_MakeShapeList(); - /** \brief Constructor - * \param[in] theMakeShapeList list of algorithms. - */ + /// \brief Constructor + /// \param[in] theMakeShapeList list of algorithms. GEOMALGOAPI_EXPORT GeomAlgoAPI_MakeShapeList(const ListOfMakeShape& theMakeShapeList); - /** \brief Initializes a class with new list of algorithms. - * \param[in] theMakeShapeList list of algorithms. - */ + /// \brief Initializes a class with new list of algorithms. + /// \param[in] theMakeShapeList list of algorithms. GEOMALGOAPI_EXPORT void init(const ListOfMakeShape& theMakeShapeList); - /** \brief Adds algo to the end of list. - * \param[in] theMakeShape algo to be added. - */ - GEOMALGOAPI_EXPORT void append(const std::shared_ptr theMakeShape); - - /** \brief Adds another one list of algos to the end of list. - * \param[in] theMakeShapeList algo list to be added. - */ - GEOMALGOAPI_EXPORT void append(const GeomAlgoAPI_MakeShapeList& theMakeShapeList); + /// \brief Adds algo to the end of list. + /// \param[in] theMakeShape algo to be added. + GEOMALGOAPI_EXPORT void appendAlgo(const std::shared_ptr theMakeShape); /// \return a shape built by the shape construction algorithms GEOMALGOAPI_EXPORT virtual const std::shared_ptr shape() const; diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_MakeSweep.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_MakeSweep.cpp index 0cb97621f..701a99d14 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_MakeSweep.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_MakeSweep.cpp @@ -4,7 +4,7 @@ // Created: 23 November 2015 // Author: Dmitry Bobylev -#include +#include "GeomAlgoAPI_MakeSweep.h" //================================================================================================= const ListOfShape& GeomAlgoAPI_MakeSweep::fromFaces() const @@ -17,3 +17,27 @@ const ListOfShape& GeomAlgoAPI_MakeSweep::toFaces() const { return myToFaces; } + +//================================================================================================= +void GeomAlgoAPI_MakeSweep::addFromFace(const std::shared_ptr theFace) +{ + myFromFaces.push_back(theFace); +} + +//================================================================================================= +void GeomAlgoAPI_MakeSweep::setFromFaces(const ListOfShape& theListOfFaces) +{ + myFromFaces = theListOfFaces; +} + +//================================================================================================= +void GeomAlgoAPI_MakeSweep::addToFace(const std::shared_ptr theFace) +{ + myToFaces.push_back(theFace); +} + +//================================================================================================= +void GeomAlgoAPI_MakeSweep::setToFaces(const ListOfShape& theListOfFaces) +{ + myToFaces = theListOfFaces; +} diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_MakeSweep.h b/src/GeomAlgoAPI/GeomAlgoAPI_MakeSweep.h index fee768599..d9c5f4ec2 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_MakeSweep.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_MakeSweep.h @@ -27,13 +27,30 @@ class GeomAlgoAPI_MakeSweep : public GeomAlgoAPI_MakeShapeList { public: /// \returns the list of from faces. - GEOMALGOAPI_EXPORT const ListOfShape& fromFaces() const; + GEOMALGOAPI_EXPORT virtual const ListOfShape& fromFaces() const; /// \return the list of to faces. - GEOMALGOAPI_EXPORT const ListOfShape& toFaces() const; + GEOMALGOAPI_EXPORT virtual const ListOfShape& toFaces() const; protected: - GeomAlgoAPI_MakeSweep(){}; + /// Empty constructor. + GeomAlgoAPI_MakeSweep() : GeomAlgoAPI_MakeShapeList() {}; + + /// \brief Adds a face to list of from faces. + /// \param[in] theFace a face to add. + void addFromFace(const std::shared_ptr theFace); + + /// \brief Sets from faces + /// \param[in] theListOfFaces list of from faces. + void setFromFaces(const ListOfShape& theListOfFaces); + + /// \brief Adds a face to list of to faces. + /// \param[in] theFace a face to add. + void addToFace(const std::shared_ptr theFace); + + /// \brief Sets to faces + /// \param[in] theListOfFaces list of to faces. + void setToFaces(const ListOfShape& theListOfFaces); private: ListOfShape myFromFaces; diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Prism.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Prism.cpp index 04f6ef2a8..2e8b00ca7 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Prism.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Prism.cpp @@ -4,7 +4,7 @@ // Created: 5 May 2015 // Author: Dmitry Bobylev -#include +#include "GeomAlgoAPI_Prism.h" #include #include @@ -13,7 +13,6 @@ #include #include #include -#include #include #include @@ -21,12 +20,8 @@ #include #include #include -#include -#include -#include #include #include -#include #include #include #include @@ -38,7 +33,6 @@ GeomAlgoAPI_Prism::GeomAlgoAPI_Prism(std::shared_ptr theBaseShape, double theToSize, double theFromSize) -: myDone(false) { build(theBaseShape, std::shared_ptr(), theToSize, std::shared_ptr(), theFromSize); } @@ -49,7 +43,6 @@ GeomAlgoAPI_Prism::GeomAlgoAPI_Prism(std::shared_ptr theBaseShape double theToSize, std::shared_ptr theFromShape, double theFromSize) -: myDone(false) { build(theBaseShape, theToShape, theToSize, theFromShape, theFromSize); } @@ -92,7 +85,6 @@ void GeomAlgoAPI_Prism::build(const std::shared_ptr& theBaseShape const gp_Pnt& aBasePnt = aBaseLoc->impl(); TopoDS_Shape aResult; - ListOfMakeShape aListOfMakeShape; bool isBoundingShapesSet = theFromShape || theToShape; if(!isBoundingShapesSet) { // Moving base shape. @@ -102,7 +94,7 @@ void GeomAlgoAPI_Prism::build(const std::shared_ptr& theBaseShape if(!aTransformBuilder) { return; } - aListOfMakeShape.push_back(std::shared_ptr(new GeomAlgoAPI_MakeShape(aTransformBuilder))); + this->appendAlgo(std::shared_ptr(new GeomAlgoAPI_MakeShape(aTransformBuilder))); if(!aTransformBuilder->IsDone()) { return; } @@ -113,7 +105,7 @@ void GeomAlgoAPI_Prism::build(const std::shared_ptr& theBaseShape if(!aPrismBuilder) { return; } - aListOfMakeShape.push_back(std::shared_ptr(new GeomAlgoAPI_MakeShape(aPrismBuilder))); + this->appendAlgo(std::shared_ptr(new GeomAlgoAPI_MakeShape(aPrismBuilder))); if(!aPrismBuilder->IsDone()) { return; } @@ -125,8 +117,8 @@ void GeomAlgoAPI_Prism::build(const std::shared_ptr& theBaseShape std::shared_ptr aFromShape(new GeomAPI_Shape), aToShape(new GeomAPI_Shape); aFromShape->setImpl(new TopoDS_Shape(aPrismBuilder->FirstShape(aFace))); aToShape->setImpl(new TopoDS_Shape(aPrismBuilder->LastShape(aFace))); - myFromFaces.push_back(aFromShape); - myToFaces.push_back(aToShape); + this->addFromFace(aFromShape); + this->addToFace(aToShape); } } else { std::shared_ptr aBoundingFromShape = theFromShape ? theFromShape : aBasePlane; @@ -201,7 +193,7 @@ void GeomAlgoAPI_Prism::build(const std::shared_ptr& theBaseShape if(!aTransformBuilder) { return; } - aListOfMakeShape.push_back(std::shared_ptr(new GeomAlgoAPI_MakeShape(aTransformBuilder))); + this->appendAlgo(std::shared_ptr(new GeomAlgoAPI_MakeShape(aTransformBuilder))); if(!aTransformBuilder->IsDone()) { return; } @@ -212,7 +204,7 @@ void GeomAlgoAPI_Prism::build(const std::shared_ptr& theBaseShape if(!aPrismBuilder) { return; } - aListOfMakeShape.push_back(std::shared_ptr(new GeomAlgoAPI_MakeShape(aPrismBuilder))); + this->appendAlgo(std::shared_ptr(new GeomAlgoAPI_MakeShape(aPrismBuilder))); if(!aPrismBuilder->IsDone()) { return; } @@ -271,12 +263,12 @@ void GeomAlgoAPI_Prism::build(const std::shared_ptr& theBaseShape if(!aToCutBuilder->IsDone()) { return; } - aListOfMakeShape.push_back(std::shared_ptr(new GeomAlgoAPI_MakeShape(aToCutBuilder))); + this->appendAlgo(std::shared_ptr(new GeomAlgoAPI_MakeShape(aToCutBuilder))); const TopTools_ListOfShape& aToShapes = aToCutBuilder->Modified(aToShape); for(TopTools_ListIteratorOfListOfShape anIt(aToShapes); anIt.More(); anIt.Next()) { std::shared_ptr aShape(new GeomAPI_Shape()); aShape->setImpl(new TopoDS_Shape(anIt.Value())); - myToFaces.push_back(aShape); + this->addToFace(aShape); } aResult = aToCutBuilder->Shape(); @@ -286,12 +278,12 @@ void GeomAlgoAPI_Prism::build(const std::shared_ptr& theBaseShape if(!aFromCutBuilder->IsDone()) { return; } - aListOfMakeShape.push_back(std::shared_ptr(new GeomAlgoAPI_MakeShape(aFromCutBuilder))); + this->appendAlgo(std::shared_ptr(new GeomAlgoAPI_MakeShape(aFromCutBuilder))); const TopTools_ListOfShape& aFromShapes = aFromCutBuilder->Modified(aFromShape); for(TopTools_ListIteratorOfListOfShape anIt(aFromShapes); anIt.More(); anIt.Next()) { std::shared_ptr aShape(new GeomAPI_Shape()); aShape->setImpl(new TopoDS_Shape(anIt.Value())); - myFromFaces.push_back(aShape); + this->addFromFace(aShape); } aResult = aFromCutBuilder->Shape(); @@ -328,76 +320,8 @@ void GeomAlgoAPI_Prism::build(const std::shared_ptr& theBaseShape if(aResult.IsNull()) { return; } - myShape.reset(new GeomAPI_Shape); - myShape->setImpl(new TopoDS_Shape(aResult)); - - // Filling data map to keep correct orientation of sub-shapes. - myMap.reset(new GeomAPI_DataMapOfShapeShape); - for (TopExp_Explorer Exp(aResult,TopAbs_FACE); Exp.More(); Exp.Next()) { - std::shared_ptr aCurrentShape(new GeomAPI_Shape); - aCurrentShape->setImpl(new TopoDS_Shape(Exp.Current())); - myMap->bind(aCurrentShape, aCurrentShape); - } - - // Setting list of make shape. - myMkShape.reset(new GeomAlgoAPI_MakeShapeList(aListOfMakeShape)); - - myDone = true; -} - -//================================================================================================= -bool GeomAlgoAPI_Prism::isDone() const -{ - return myDone; -} - -//================================================================================================= -bool GeomAlgoAPI_Prism::isValid() const -{ - BRepCheck_Analyzer aChecker(myShape->impl()); - return (aChecker.IsValid() == Standard_True); -} - -//================================================================================================= -bool GeomAlgoAPI_Prism::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_Prism::shape() const -{ - return myShape; -} - -//================================================================================================= -const ListOfShape& GeomAlgoAPI_Prism::fromFaces() const -{ - return myFromFaces; -} - -//================================================================================================= -const ListOfShape& GeomAlgoAPI_Prism::toFaces() const -{ - return myToFaces; -} - -//================================================================================================= -std::shared_ptr GeomAlgoAPI_Prism::mapOfShapes() const -{ - return myMap; -} - -//================================================================================================= -std::shared_ptr GeomAlgoAPI_Prism::makeShape() const -{ - return myMkShape; + std::shared_ptr aShape(new GeomAPI_Shape()); + aShape->setImpl(new TopoDS_Shape(aResult)); + this->setShape(aShape); + this->setDone(true); } diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Prism.h b/src/GeomAlgoAPI/GeomAlgoAPI_Prism.h index e7c18fcb9..f286e6970 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Prism.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Prism.h @@ -9,65 +9,38 @@ #include #include -#include -#include +#include + #include -/** \class GeomAlgoAPI_Prism - * \ingroup DataAlgo - * \brief Allows to create the prism based on a given face and bounding planes. - * \n Note that only planar faces are allowed as bounding faces and resulting - * extrusion will be bounded by the infinite planes taken from the faces. - */ -class GeomAlgoAPI_Prism : public GeomAPI_Interface +/// \class GeomAlgoAPI_Prism +/// \ingroup DataAlgo +/// \brief Allows to create the prism based on a given face and bounding planes. +/// \n Note that only planar faces are allowed as bounding faces and resulting +/// extrusion will be bounded by the infinite planes taken from the faces. +class GeomAlgoAPI_Prism : public GeomAlgoAPI_MakeSweep { public: - /** \brief Creates extrusion for the given shape along the normal for this shape. - * \param[in] theBaseShape face or wire to be extruded. - * \param[in] theToSize offset for "to" plane. - * \param[in] theFromSize offset for "from" plane. - */ + /// \brief Creates extrusion for the given shape along the normal for this shape. + /// \param[in] theBaseShape face or wire to be extruded. + /// \param[in] theToSize offset for "to" plane. + /// \param[in] theFromSize offset for "from" plane. GEOMALGOAPI_EXPORT GeomAlgoAPI_Prism(std::shared_ptr theBaseShape, double theToSize, double theFromSize); - /** \brief Creates extrusion for the given shape along the normal for this shape. - * \param[in] theBaseShape face or wire to be extruded. - * \param[in] theToShape top bounding shape. Can be empty. In this case offset will be applied to the basis. - * \param[in] theToSize offset for "to" plane. - * \param[in] theFromShape bottom bounding shape. Can be empty. In this case offset will be applied to the basis. - * \param[in] theFromSize offset for "from" plane. - */ + /// \brief Creates extrusion for the given shape along the normal for this shape. + /// \param[in] theBaseShape face or wire to be extruded. + /// \param[in] theToShape top bounding shape. Can be empty. In this case offset will be applied to the basis. + /// \param[in] theToSize offset for "to" plane. + /// \param[in] theFromShape bottom bounding shape. Can be empty. In this case offset will be applied to the basis. + /// \param[in] theFromSize offset for "from" plane. GEOMALGOAPI_EXPORT GeomAlgoAPI_Prism(std::shared_ptr theBaseShape, std::shared_ptr theToShape, double theToSize, std::shared_ptr theFromShape, double theFromSize); - /// \return true if algorithm succeed. - GEOMALGOAPI_EXPORT bool isDone() const; - - /// \return true if resulting shape is valid. - GEOMALGOAPI_EXPORT bool isValid() const; - - /// \return true if resulting shape has volume. - GEOMALGOAPI_EXPORT bool hasVolume() const; - - /// \return result of the Prism algorithm. - GEOMALGOAPI_EXPORT std::shared_ptr shape() const; - - /// \returns the list of from faces. - GEOMALGOAPI_EXPORT const ListOfShape& fromFaces() const; - - /// \return the list of to faces. - GEOMALGOAPI_EXPORT const ListOfShape& toFaces() const; - - /// \return map of sub-shapes of the result. To be used for History keeping. - GEOMALGOAPI_EXPORT std::shared_ptr mapOfShapes() const; - - /// \return interface for History processing. - GEOMALGOAPI_EXPORT std::shared_ptr makeShape() const; - private: /// Builds resulting shape. void build(const std::shared_ptr& theBaseShape, @@ -75,15 +48,6 @@ private: double theToSize, const std::shared_ptr& theFromShape, double theFromSize); - -private: - /// Fields. - bool myDone; - std::shared_ptr myShape; - ListOfShape myFromFaces; - ListOfShape myToFaces; - std::shared_ptr myMap; - std::shared_ptr myMkShape; }; #endif -- 2.39.2