From: dbv Date: Wed, 23 Dec 2015 16:00:34 +0000 (+0300) Subject: GeomAlgoAPI_Partition now derived from GeomAlgoAPI_MakeShape X-Git-Tag: V_2.1.0~82 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=87ac65e82ce1ebcb027da959517b1654ce2b5076;p=modules%2Fshaper.git GeomAlgoAPI_Partition now derived from GeomAlgoAPI_MakeShape --- diff --git a/src/FeaturesPlugin/FeaturesPlugin_Partition.cpp b/src/FeaturesPlugin/FeaturesPlugin_Partition.cpp index 94b7f4bce..e7e74c68e 100755 --- a/src/FeaturesPlugin/FeaturesPlugin_Partition.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Partition.cpp @@ -48,20 +48,6 @@ void FeaturesPlugin_Partition::initAttributes() data()->addAttribute(COMBINE_ID(), ModelAPI_AttributeBoolean::typeId()); } -//================================================================================================= -std::shared_ptr FeaturesPlugin_Partition::getShape(const std::string& theAttrName) -{ - std::shared_ptr aObjRef = - std::dynamic_pointer_cast(data()->attribute(theAttrName)); - if (aObjRef) { - std::shared_ptr aConstr = - std::dynamic_pointer_cast(aObjRef->value()); - if (aConstr) - return aConstr->shape(); - } - return std::shared_ptr(); -} - //================================================================================================= void FeaturesPlugin_Partition::execute() { @@ -122,30 +108,30 @@ void FeaturesPlugin_Partition::execute() anObjects.clear(); anObjects.push_back(aCompoud); } - GeomAlgoAPI_Partition aPartitionAlgo(anObjects, aTools); + std::shared_ptr aPartitionAlgo(new GeomAlgoAPI_Partition(anObjects, aTools)); // Checking that the algorithm worked properly. - if (!aPartitionAlgo.isDone()) { + if (!aPartitionAlgo->isDone()) { static const std::string aFeatureError = "Partition algorithm failed"; setError(aFeatureError); return; } - if (aPartitionAlgo.shape()->isNull()) { + if (aPartitionAlgo->shape()->isNull()) { static const std::string aShapeError = "Resulting shape is Null"; setError(aShapeError); return; } - if (!aPartitionAlgo.isValid()) { + if (!aPartitionAlgo->isValid()) { std::string aFeatureError = "Warning: resulting shape is not valid"; setError(aFeatureError); return; } - if (GeomAlgoAPI_ShapeTools::volume(aPartitionAlgo.shape()) > 1.e-7) { + if (GeomAlgoAPI_ShapeTools::volume(aPartitionAlgo->shape()) > 1.e-7) { std::shared_ptr aResultBody = document()->createBody(data(), aResultIndex); - aMakeShapeList.appendAlgo(aPartitionAlgo.makeShape()); - GeomAPI_DataMapOfShapeShape aMapOfShapes = *aPartitionAlgo.mapOfShapes().get(); - loadNamingDS(aResultBody, anObjects.front(), aToolsForNaming, aPartitionAlgo.shape(), aMakeShapeList, aMapOfShapes); + aMakeShapeList.appendAlgo(aPartitionAlgo); + GeomAPI_DataMapOfShapeShape& aMapOfShapes = *aPartitionAlgo->mapOfSubShapes().get(); + loadNamingDS(aResultBody, anObjects.front(), aToolsForNaming, aPartitionAlgo->shape(), aMakeShapeList, aMapOfShapes); setResult(aResultBody, aResultIndex); aResultIndex++; } @@ -154,30 +140,31 @@ void FeaturesPlugin_Partition::execute() for (ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); anObjectsIt++) { std::shared_ptr anObject = *anObjectsIt; ListOfShape aListWithObject; aListWithObject.push_back(anObject); - GeomAlgoAPI_Partition aPartitionAlgo(aListWithObject, aTools); + std::shared_ptr aPartitionAlgo(new GeomAlgoAPI_Partition(aListWithObject, aTools)); // Checking that the algorithm worked properly. - if (!aPartitionAlgo.isDone()) { + if (!aPartitionAlgo->isDone()) { static const std::string aFeatureError = "Partition algorithm failed"; setError(aFeatureError); return; } - if (aPartitionAlgo.shape()->isNull()) { + if (aPartitionAlgo->shape()->isNull()) { static const std::string aShapeError = "Resulting shape is Null"; setError(aShapeError); return; } - if (!aPartitionAlgo.isValid()) { + if (!aPartitionAlgo->isValid()) { std::string aFeatureError = "Warning: resulting shape is not valid"; setError(aFeatureError); return; } - if (GeomAlgoAPI_ShapeTools::volume(aPartitionAlgo.shape()) > 1.e-7) { + if (GeomAlgoAPI_ShapeTools::volume(aPartitionAlgo->shape()) > 1.e-7) { std::shared_ptr aResultBody = document()->createBody(data(), aResultIndex); - aMakeShapeList.appendAlgo(aPartitionAlgo.makeShape()); - GeomAPI_DataMapOfShapeShape aMapOfShapes = *aPartitionAlgo.mapOfShapes().get(); - loadNamingDS(aResultBody, anObject, aToolsForNaming, aPartitionAlgo.shape(), aMakeShapeList, aMapOfShapes); + GeomAlgoAPI_MakeShapeList aMakeShapeListCopy = aMakeShapeList; + aMakeShapeListCopy.appendAlgo(aPartitionAlgo); + GeomAPI_DataMapOfShapeShape aMapOfShapes = *aPartitionAlgo->mapOfSubShapes().get(); + loadNamingDS(aResultBody, anObject, aToolsForNaming, aPartitionAlgo->shape(), aMakeShapeListCopy, aMapOfShapes); setResult(aResultBody, aResultIndex); aResultIndex++; } diff --git a/src/FeaturesPlugin/FeaturesPlugin_Partition.h b/src/FeaturesPlugin/FeaturesPlugin_Partition.h index eaa17dd23..bd7d7a7c5 100755 --- a/src/FeaturesPlugin/FeaturesPlugin_Partition.h +++ b/src/FeaturesPlugin/FeaturesPlugin_Partition.h @@ -12,12 +12,11 @@ #include -/**\class FeaturesPlugin_Partition - * \ingroup Plugins - * \brief Feature for applying of Partition operations on Solids. Partition makes conjunctional - * faces of solids as shared. The result of partitions is a compsolid. - * Main objects are solids, tool objects are solids or faces - */ +/// \class FeaturesPlugin_Partition +/// \ingroup Plugins +/// \brief Feature for applying of Partition operations on Solids. Partition makes conjunctional +/// faces of solids as shared. The result of partitions is a compsolid. +/// Main objects are solids, tool objects are solids or faces class FeaturesPlugin_Partition : public ModelAPI_Feature { public: @@ -64,8 +63,6 @@ public: FeaturesPlugin_Partition(); private: - std::shared_ptr getShape(const std::string& theAttrName); - /// Load Naming data structure of the feature to the document void loadNamingDS(std::shared_ptr theResultBody, const std::shared_ptr theBaseShape, diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Partition.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Partition.cpp index 425c71e13..63a1ddc9e 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Partition.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Partition.cpp @@ -11,31 +11,16 @@ #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include -#include #include -#include -#include //================================================================================================= std::shared_ptr GeomAlgoAPI_Partition::make(const ListOfShape& theObjects, const ListOfShape& theTools) { - GeomAlgoAPI_Partition aBoolAlgo(theObjects, theTools); - if(aBoolAlgo.isDone() && !aBoolAlgo.shape()->isNull() && aBoolAlgo.isValid()) { - return aBoolAlgo.shape(); + GeomAlgoAPI_Partition aPartitionAlgo(theObjects, theTools); + if(aPartitionAlgo.isDone() && !aPartitionAlgo.shape()->isNull() && aPartitionAlgo.isValid()) { + return aPartitionAlgo.shape(); } return std::shared_ptr(); } @@ -43,7 +28,6 @@ std::shared_ptr GeomAlgoAPI_Partition::make(const ListOfShape& th //================================================================================================= GeomAlgoAPI_Partition::GeomAlgoAPI_Partition(const ListOfShape& theObjects, const ListOfShape& theTools) -: myDone(false) { build(theObjects, theTools); } @@ -59,7 +43,8 @@ void GeomAlgoAPI_Partition::build(const ListOfShape& theObjects, // Creating partition operation. GEOMAlgo_Splitter* anOperation = new GEOMAlgo_Splitter; - myMkShape.reset(new GeomAlgoAPI_MakeShape(anOperation, GeomAlgoAPI_MakeShape::OCCT_BOPAlgo_Builder)); + this->setImpl(anOperation); + this->setBuilderType(OCCT_BOPAlgo_Builder); // Getting objects. for (ListOfShape::const_iterator anObjectsIt = theObjects.begin(); anObjectsIt != theObjects.end(); anObjectsIt++) { @@ -75,11 +60,10 @@ void GeomAlgoAPI_Partition::build(const ListOfShape& theObjects, // Building and getting result. anOperation->Perform(); - TopoDS_Shape aResult = anOperation->Shape(); - myDone = !aResult.IsNull(); - if (!myDone) { + if(anOperation->ErrorStatus() != 0) { return; } + TopoDS_Shape aResult = anOperation->Shape(); if(aResult.ShapeType() == TopAbs_COMPOUND) { aResult = GeomAlgoAPI_DFLoader::refineResult(aResult); @@ -105,44 +89,8 @@ void GeomAlgoAPI_Partition::build(const ListOfShape& theObjects, } } - // fill 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); - } - myShape.reset(new GeomAPI_Shape()); - myShape->setImpl(new TopoDS_Shape(aResult)); -} - -//================================================================================================= -const bool GeomAlgoAPI_Partition::isDone() const -{ - return myDone; -} - -//================================================================================================= -const bool GeomAlgoAPI_Partition::isValid() const -{ - BRepCheck_Analyzer aChecker(myShape->impl()); - return (aChecker.IsValid() == Standard_True); -} - -//================================================================================================= -const std::shared_ptr& GeomAlgoAPI_Partition::shape() const -{ - return myShape; -} - -//================================================================================================= -std::shared_ptr GeomAlgoAPI_Partition::mapOfShapes() const -{ - return myMap; -} - -//================================================================================================= -std::shared_ptr GeomAlgoAPI_Partition::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_Partition.h b/src/GeomAlgoAPI/GeomAlgoAPI_Partition.h index 39f69b5fe..ea214adde 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Partition.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Partition.h @@ -11,23 +11,17 @@ #include #include -#include -#include -#include - -/** \class GeomAlgoAPI_Partition - * \ingroup DataAlgo - * \brief Allows to perform of partition operations - */ -class GeomAlgoAPI_Partition : public GeomAPI_Interface +/// \class GeomAlgoAPI_Partition +/// \ingroup DataAlgo +/// \brief Allows to perform of partition operations +class GeomAlgoAPI_Partition : public GeomAlgoAPI_MakeShape { public: - /** \brief Creates common partition operation. - * \param[in] theObjects the main shape. - * \param[in] theTools second shape. - * \return a solid as result of operation. - */ + /// \brief Creates common partition operation. + /// \param[in] theObjects the main shape. + /// \param[in] theTools second shape. + /// \return a solid as result of operation. GEOMALGOAPI_EXPORT static std::shared_ptr make(const ListOfShape& theObjects, const ListOfShape& theTools); @@ -35,32 +29,10 @@ public: GEOMALGOAPI_EXPORT GeomAlgoAPI_Partition(const ListOfShape& theObjects, const ListOfShape& theTools); - /// \return true if algorithm succeed. - GEOMALGOAPI_EXPORT const bool isDone() const; - - /// \return true if resulting shape is valid. - GEOMALGOAPI_EXPORT const bool isValid() const; - - /// \return result of the boolean algorithm. - GEOMALGOAPI_EXPORT const std::shared_ptr& shape() 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 for History processing. - GEOMALGOAPI_EXPORT std::shared_ptr makeShape() const; - private: /// Builds resulting shape. void build(const ListOfShape& theObjects, const ListOfShape& theTools); - -private: - /// Fields. - bool myDone; - std::shared_ptr myShape; - std::shared_ptr myMap; - std::shared_ptr myMkShape; }; #endif