From 6e511a39b3b982757b90b73a7cfc4a1139ebc83c Mon Sep 17 00:00:00 2001 From: azv Date: Mon, 10 Dec 2018 11:52:48 +0300 Subject: [PATCH] [Code coverage]: Move checking the algorithm's result into separate function --- src/BuildPlugin/BuildPlugin_Edge.cpp | 19 ++---- src/BuildPlugin/BuildPlugin_Filling.cpp | 31 ++-------- src/BuildPlugin/BuildPlugin_Filling.h | 3 - src/BuildPlugin/BuildPlugin_Polyline.cpp | 8 +-- src/BuildPlugin/BuildPlugin_Shell.cpp | 19 ++---- src/BuildPlugin/BuildPlugin_Vertex.cpp | 23 ++----- .../FeaturesPlugin_BooleanCommon.cpp | 62 +++---------------- .../FeaturesPlugin_BooleanCut.cpp | 48 +++----------- .../FeaturesPlugin_BooleanFill.cpp | 33 +++------- .../FeaturesPlugin_BooleanFuse.cpp | 47 +++----------- .../FeaturesPlugin_BooleanSmash.cpp | 34 +++------- .../FeaturesPlugin_CompositeSketch.cpp | 42 +++---------- .../FeaturesPlugin_CompositeSketch.h | 3 - .../FeaturesPlugin_Extrusion.cpp | 5 +- src/FeaturesPlugin/FeaturesPlugin_Fillet.cpp | 28 ++------- src/FeaturesPlugin/FeaturesPlugin_Fillet.h | 3 - .../FeaturesPlugin_FusionFaces.cpp | 14 ++--- .../FeaturesPlugin_Intersection.cpp | 17 ++--- .../FeaturesPlugin_MultiRotation.cpp | 17 ++--- .../FeaturesPlugin_MultiTranslation.cpp | 33 +++------- .../FeaturesPlugin_Partition.cpp | 29 ++------- src/FeaturesPlugin/FeaturesPlugin_Pipe.cpp | 35 +++-------- .../FeaturesPlugin_Placement.cpp | 17 ++--- src/FeaturesPlugin/FeaturesPlugin_Recover.cpp | 16 ++--- .../FeaturesPlugin_Revolution.cpp | 5 +- .../FeaturesPlugin_Rotation.cpp | 33 +++------- src/FeaturesPlugin/FeaturesPlugin_Scale.cpp | 33 +++------- .../FeaturesPlugin_Symmetry.cpp | 49 +++------------ .../FeaturesPlugin_Translation.cpp | 49 +++------------ src/FeaturesPlugin/FeaturesPlugin_Union.cpp | 26 ++------ src/GeomAlgoAPI/GeomAlgoAPI_Tools.cpp | 30 +++++++++ src/GeomAlgoAPI/GeomAlgoAPI_Tools.h | 21 +++++++ 32 files changed, 216 insertions(+), 616 deletions(-) diff --git a/src/BuildPlugin/BuildPlugin_Edge.cpp b/src/BuildPlugin/BuildPlugin_Edge.cpp index a3a247e30..28be282f6 100644 --- a/src/BuildPlugin/BuildPlugin_Edge.cpp +++ b/src/BuildPlugin/BuildPlugin_Edge.cpp @@ -24,6 +24,7 @@ #include #include +#include //================================================================================================= BuildPlugin_Edge::BuildPlugin_Edge() @@ -78,21 +79,9 @@ void BuildPlugin_Edge::execute() // Copy shape. GeomMakeShapePtr aCopyAlgo(new GeomAlgoAPI_Copy(aShape)); - // Check that algo is done. - if(!aCopyAlgo->isDone()) { - setError("Error: " + getKind() + " algorithm failed."); - return; - } - - // Check if shape is not null. - if(!aCopyAlgo->shape().get() || aCopyAlgo->shape()->isNull()) { - setError("Error: Resulting shape is null."); - return; - } - - // Check that resulting shape is valid. - if(!aCopyAlgo->isValid()) { - setError("Error: Resulting shape is not valid."); + std::string anError; + if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aCopyAlgo, getKind(), anError)) { + setError(anError); return; } diff --git a/src/BuildPlugin/BuildPlugin_Filling.cpp b/src/BuildPlugin/BuildPlugin_Filling.cpp index 6e95dd32c..dcf51a8b5 100644 --- a/src/BuildPlugin/BuildPlugin_Filling.cpp +++ b/src/BuildPlugin/BuildPlugin_Filling.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -116,7 +117,9 @@ void BuildPlugin_Filling::execute() // build result aFilling->build(aParameters.isApprox); - if (isAlgorithmFailed(aFilling)) { + std::string anError; + if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aFilling, getKind(), anError)) { + setError(anError); removeResults(0); return; } @@ -134,32 +137,6 @@ void BuildPlugin_Filling::execute() setResult(aResultBody, 0); } -bool BuildPlugin_Filling::isAlgorithmFailed( - const std::shared_ptr& theAlgorithm) -{ - if (!theAlgorithm->isDone()) { - static const std::string aFeatureError = "Error: filling algorithm failed."; - std::string anAlgoError = theAlgorithm->getError(); - if (anAlgoError.empty()) - anAlgoError = aFeatureError; - else - anAlgoError = aFeatureError + " " + anAlgoError; - setError(anAlgoError); - return true; - } - if (theAlgorithm->shape()->isNull()) { - static const std::string aShapeError = "Error: Resulting shape of filling is Null."; - setError(aShapeError); - return true; - } - if (!theAlgorithm->isValid()) { - std::string aFeatureError = "Error: Resulting shape of filling is not valid."; - setError(aFeatureError); - return true; - } - return false; -} - //================================================================================================= void BuildPlugin_Filling::attributeChanged(const std::string& theID) { diff --git a/src/BuildPlugin/BuildPlugin_Filling.h b/src/BuildPlugin/BuildPlugin_Filling.h index cb19f063f..aadc2292d 100644 --- a/src/BuildPlugin/BuildPlugin_Filling.h +++ b/src/BuildPlugin/BuildPlugin_Filling.h @@ -164,9 +164,6 @@ public: BUILDPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID); private: - /// Check the filling algorithm is failed - bool isAlgorithmFailed(const std::shared_ptr& theAlgorithm); - /// Convert shape to edge according to construction method std::shared_ptr toEdge(const std::shared_ptr& theShape, const std::string& theMethod); diff --git a/src/BuildPlugin/BuildPlugin_Polyline.cpp b/src/BuildPlugin/BuildPlugin_Polyline.cpp index 17702ae33..da0bbfb99 100644 --- a/src/BuildPlugin/BuildPlugin_Polyline.cpp +++ b/src/BuildPlugin/BuildPlugin_Polyline.cpp @@ -92,10 +92,10 @@ void BuildPlugin_Polyline::execute() // Create wire from edges GeomShapePtr aWire = GeomAlgoAPI_WireBuilder::wire(anEdges); - if (!aWire.get()) { - setError("Error: Result polyline is empty."); - return; - } + if (!aWire.get()) { + setError("Error: Result polyline is empty."); + return; + } // Check the wire. if (GeomAlgoAPI_WireBuilder::isSelfIntersected(aWire)) { diff --git a/src/BuildPlugin/BuildPlugin_Shell.cpp b/src/BuildPlugin/BuildPlugin_Shell.cpp index cc361be59..bd73c2f1f 100644 --- a/src/BuildPlugin/BuildPlugin_Shell.cpp +++ b/src/BuildPlugin/BuildPlugin_Shell.cpp @@ -25,6 +25,7 @@ #include #include +#include #include //================================================================================================= @@ -58,21 +59,9 @@ void BuildPlugin_Shell::execute() // Sew faces. GeomMakeShapePtr aSewingAlgo(new GeomAlgoAPI_Sewing(aShapes)); - // Check that algo is done. - if(!aSewingAlgo->isDone()) { - setError("Error: " + getKind() + " algorithm failed."); - return; - } - - // Check if shape is not null. - if(!aSewingAlgo->shape().get() || aSewingAlgo->shape()->isNull()) { - setError("Error: Resulting shape is null."); - return; - } - - // Check that resulting shape is valid. - if(!aSewingAlgo->isValid()) { - setError("Error: Resulting shape is not valid."); + std::string anError; + if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aSewingAlgo, getKind(), anError)) { + setError(anError); return; } diff --git a/src/BuildPlugin/BuildPlugin_Vertex.cpp b/src/BuildPlugin/BuildPlugin_Vertex.cpp index 585682a32..a2475d870 100644 --- a/src/BuildPlugin/BuildPlugin_Vertex.cpp +++ b/src/BuildPlugin/BuildPlugin_Vertex.cpp @@ -24,6 +24,7 @@ #include #include +#include //================================================================================================= BuildPlugin_Vertex::BuildPlugin_Vertex() @@ -76,29 +77,17 @@ void BuildPlugin_Vertex::execute() } // Copy shape. - GeomAlgoAPI_Copy aCopyAlgo(aShape); + std::shared_ptr aCopyAlgo(new GeomAlgoAPI_Copy(aShape)); - // Check that algo is done. - if(!aCopyAlgo.isDone()) { - setError("Error: " + getKind() + " algorithm failed."); - return; - } - - // Check if shape is not null. - if(!aCopyAlgo.shape().get() || aCopyAlgo.shape()->isNull()) { - setError("Error: Resulting shape is null."); - return; - } - - // Check that resulting shape is valid. - if(!aCopyAlgo.isValid()) { - setError("Error: Resulting shape is not valid."); + std::string anError; + if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aCopyAlgo, getKind(), anError)) { + setError(anError); return; } // Store result. ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex); - aResultBody->storeModified(aShape, aCopyAlgo.shape()); + aResultBody->storeModified(aShape, aCopyAlgo->shape()); setResult(aResultBody, aResultIndex); ++aResultIndex; } diff --git a/src/FeaturesPlugin/FeaturesPlugin_BooleanCommon.cpp b/src/FeaturesPlugin/FeaturesPlugin_BooleanCommon.cpp index 942279a4f..df16a3149 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_BooleanCommon.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_BooleanCommon.cpp @@ -36,6 +36,7 @@ #include #include #include +#include //================================================================================================== @@ -128,6 +129,7 @@ void FeaturesPlugin_BooleanCommon::execute() } int aResultIndex = 0; + std::string anError; std::shared_ptr aMakeShapeList(new GeomAlgoAPI_MakeShapeList()); std::vector aResultBaseAlgoList; ListOfShape aResultShapesList; @@ -142,19 +144,8 @@ void FeaturesPlugin_BooleanCommon::execute() *anObjectsIt, GeomAlgoAPI_Boolean::BOOL_COMMON)); - if (!aCommonAlgo->isDone()) { - std::string aFeatureError = "Error: An algorithm failed."; - setError(aFeatureError); - return; - } - if (aCommonAlgo->shape()->isNull()) { - static const std::string aShapeError = "Error: Resulting shape is Null."; - setError(aShapeError); - return; - } - if (!aCommonAlgo->isValid()) { - std::string aFeatureError = "Error: Resulting shape is not valid."; - setError(aFeatureError); + if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aCommonAlgo, getKind(), anError)) { + setError(anError); return; } @@ -220,19 +211,8 @@ void FeaturesPlugin_BooleanCommon::execute() aResShape = aBoolAlgo->shape(); // Checking that the algorithm worked properly. - if (!aBoolAlgo->isDone()) { - static const std::string aFeatureError = "Error: Boolean algorithm failed."; - setError(aFeatureError); - return; - } - if (aResShape->isNull()) { - static const std::string aShapeError = "Error: Resulting shape is Null."; - setError(aShapeError); - return; - } - if (!aBoolAlgo->isValid()) { - std::string aFeatureError = "Error: Resulting shape is not valid."; - setError(aFeatureError); + if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aBoolAlgo, getKind(), anError)) { + setError(anError); return; } @@ -294,19 +274,8 @@ void FeaturesPlugin_BooleanCommon::execute() GeomAlgoAPI_Boolean::BOOL_COMMON)); // Checking that the algorithm worked properly. - if (!aCommonAlgo->isDone()) { - static const std::string aFeatureError = "Error: Boolean algorithm failed."; - setError(aFeatureError); - return; - } - if (aCommonAlgo->shape()->isNull()) { - static const std::string aShapeError = "Error: Resulting shape is Null."; - setError(aShapeError); - return; - } - if (!aCommonAlgo->isValid()) { - std::string aFeatureError = "Error: Resulting shape is not valid."; - setError(aFeatureError); + if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aCommonAlgo, getKind(), anError)) { + setError(anError); return; } @@ -386,19 +355,8 @@ void FeaturesPlugin_BooleanCommon::execute() GeomAlgoAPI_Boolean::BOOL_COMMON)); // Checking that the algorithm worked properly. - if (!aCommonAlgo->isDone()) { - static const std::string aFeatureError = "Error: Boolean algorithm failed."; - setError(aFeatureError); - return; - } - if (aCommonAlgo->shape()->isNull()) { - static const std::string aShapeError = "Error: Resulting shape is Null."; - setError(aShapeError); - return; - } - if (!aCommonAlgo->isValid()) { - std::string aFeatureError = "Error: Resulting shape is not valid."; - setError(aFeatureError); + if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aCommonAlgo, getKind(), anError)) { + setError(anError); return; } diff --git a/src/FeaturesPlugin/FeaturesPlugin_BooleanCut.cpp b/src/FeaturesPlugin/FeaturesPlugin_BooleanCut.cpp index ae5cac2f5..bfe0fdc2c 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_BooleanCut.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_BooleanCut.cpp @@ -31,6 +31,8 @@ #include #include #include +#include + #include #include @@ -103,6 +105,7 @@ void FeaturesPlugin_BooleanCut::execute() std::vector aResultBaseAlgoList; ListOfShape aResultShapesList; + std::string anError; // For solids cut each object with all tools. for(ListOfShape::iterator anObjectsIt = anObjects.begin(); @@ -117,19 +120,8 @@ void FeaturesPlugin_BooleanCut::execute() GeomShapePtr aResShape = aCutAlgo->shape(); // Checking that the algorithm worked properly. - if (!aCutAlgo->isDone()) { - static const std::string aFeatureError = "Error: Boolean algorithm failed."; - setError(aFeatureError); - return; - } - if(aResShape->isNull()) { - static const std::string aShapeError = "Error: Resulting shape is Null."; - setError(aShapeError); - return; - } - if (!aCutAlgo->isValid()) { - std::string aFeatureError = "Error: Resulting shape is not valid."; - setError(aFeatureError); + if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aCutAlgo, getKind(), anError)) { + setError(anError); return; } @@ -192,19 +184,8 @@ void FeaturesPlugin_BooleanCut::execute() GeomAlgoAPI_Boolean::BOOL_CUT)); // Checking that the algorithm worked properly. - if (!aCutAlgo->isDone()) { - static const std::string aFeatureError = "Error: Boolean algorithm failed."; - setError(aFeatureError); - return; - } - if (aCutAlgo->shape()->isNull()) { - static const std::string aShapeError = "Error: Resulting shape is Null."; - setError(aShapeError); - return; - } - if (!aCutAlgo->isValid()) { - std::string aFeatureError = "Error: Resulting shape is not valid."; - setError(aFeatureError); + if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aCutAlgo, getKind(), anError)) { + setError(anError); return; } @@ -284,19 +265,8 @@ void FeaturesPlugin_BooleanCut::execute() GeomAlgoAPI_Boolean::BOOL_CUT)); // Checking that the algorithm worked properly. - if (!aCutAlgo->isDone()) { - static const std::string aFeatureError = "Error: Boolean algorithm failed."; - setError(aFeatureError); - return; - } - if (aCutAlgo->shape()->isNull()) { - static const std::string aShapeError = "Error: Resulting shape is Null."; - setError(aShapeError); - return; - } - if (!aCutAlgo->isValid()) { - std::string aFeatureError = "Error: Resulting shape is not valid."; - setError(aFeatureError); + if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aCutAlgo, getKind(), anError)) { + setError(anError); return; } diff --git a/src/FeaturesPlugin/FeaturesPlugin_BooleanFill.cpp b/src/FeaturesPlugin/FeaturesPlugin_BooleanFill.cpp index 1bf980942..d9f7faf2b 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_BooleanFill.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_BooleanFill.cpp @@ -30,6 +30,8 @@ #include #include #include +#include + #include #include #include @@ -46,6 +48,7 @@ FeaturesPlugin_BooleanFill::FeaturesPlugin_BooleanFill() //================================================================================================= void FeaturesPlugin_BooleanFill::execute() { + std::string anError; ListOfShape anObjects, aTools, anEdgesAndFaces, aPlanes; std::map, ListOfShape> aCompSolidsObjects; @@ -148,19 +151,8 @@ void FeaturesPlugin_BooleanFill::execute() } // Checking that the algorithm worked properly. - if(!aBoolAlgo->isDone()) { - static const std::string aFeatureError = "Error: Boolean algorithm failed."; - setError(aFeatureError); - return; - } - if(aResShape->isNull()) { - static const std::string aShapeError = "Error: Resulting shape is Null."; - setError(aShapeError); - return; - } - if(!aBoolAlgo->isValid()) { - std::string aFeatureError = "Error: Resulting shape is not valid."; - setError(aFeatureError); + if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aBoolAlgo, getKind(), anError)) { + setError(anError); return; } @@ -224,19 +216,8 @@ void FeaturesPlugin_BooleanFill::execute() aBoolAlgo.reset(new GeomAlgoAPI_Partition(aUsedInOperationSolids, aToolsWithPlanes)); // Checking that the algorithm worked properly. - if(!aBoolAlgo->isDone()) { - static const std::string aFeatureError = "Error: Boolean algorithm failed."; - setError(aFeatureError); - return; - } - if(aBoolAlgo->shape()->isNull()) { - static const std::string aShapeError = "Error: Resulting shape is Null."; - setError(aShapeError); - return; - } - if(!aBoolAlgo->isValid()) { - std::string aFeatureError = "Error: Resulting shape is not valid."; - setError(aFeatureError); + if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aBoolAlgo, getKind(), anError)) { + setError(anError); return; } diff --git a/src/FeaturesPlugin/FeaturesPlugin_BooleanFuse.cpp b/src/FeaturesPlugin/FeaturesPlugin_BooleanFuse.cpp index b09cde2e7..f6e4599f7 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_BooleanFuse.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_BooleanFuse.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -60,6 +61,7 @@ void FeaturesPlugin_BooleanFuse::initAttributes() //================================================================================================== void FeaturesPlugin_BooleanFuse::execute() { + std::string anError; ListOfShape anObjects, aTools, anEdgesAndFaces; std::map aCompSolidsObjects; @@ -218,19 +220,8 @@ void FeaturesPlugin_BooleanFuse::execute() GeomAlgoAPI_Boolean::BOOL_FUSE)); // Checking that the algorithm worked properly. - if (!aFuseAlgo->isDone()) { - static const std::string aFeatureError = "Error: Boolean algorithm failed."; - setError(aFeatureError); - return; - } - if (aFuseAlgo->shape()->isNull()) { - static const std::string aShapeError = "Error: Resulting shape is Null."; - setError(aShapeError); - return; - } - if (!aFuseAlgo->isValid()) { - std::string aFeatureError = "Error: Resulting shape is not valid."; - setError(aFeatureError); + if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aFuseAlgo, getKind(), anError)) { + setError(anError); return; } @@ -250,19 +241,8 @@ void FeaturesPlugin_BooleanFuse::execute() } std::shared_ptr aFillerAlgo( new GeomAlgoAPI_PaveFiller(aShapesToAdd, true)); - if (!aFillerAlgo->isDone()) { - std::string aFeatureError = "Error: PaveFiller algorithm failed."; - setError(aFeatureError); - return; - } - if (aFillerAlgo->shape()->isNull()) { - static const std::string aShapeError = "Error: Resulting shape is Null."; - setError(aShapeError); - return; - } - if (!aFillerAlgo->isValid()) { - std::string aFeatureError = "Error: Resulting shape is not valid."; - setError(aFeatureError); + if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aFillerAlgo, getKind(), anError)) { + setError(anError); return; } @@ -280,19 +260,8 @@ void FeaturesPlugin_BooleanFuse::execute() std::shared_ptr aUnifyAlgo( new GeomAlgoAPI_UnifySameDomain(aShape)); - if (!aUnifyAlgo->isDone()) { - std::string aFeatureError = "Error: PaveFiller algorithm failed."; - setError(aFeatureError); - return; - } - if (aUnifyAlgo->shape()->isNull()) { - static const std::string aShapeError = "Error: Resulting shape is Null."; - setError(aShapeError); - return; - } - if (!aUnifyAlgo->isValid()) { - std::string aFeatureError = "Error: Resulting shape is not valid."; - setError(aFeatureError); + if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aUnifyAlgo, getKind(), anError)) { + setError(anError); return; } diff --git a/src/FeaturesPlugin/FeaturesPlugin_BooleanSmash.cpp b/src/FeaturesPlugin/FeaturesPlugin_BooleanSmash.cpp index 65f1a77fe..ee6c3c785 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_BooleanSmash.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_BooleanSmash.cpp @@ -31,6 +31,8 @@ #include #include #include +#include + #include #include @@ -50,6 +52,7 @@ void FeaturesPlugin_BooleanSmash::initAttributes() //================================================================================================== void FeaturesPlugin_BooleanSmash::execute() { + std::string anError; ListOfShape anObjects, aTools; std::map, ListOfShape> aCompSolidsObjects; @@ -180,21 +183,11 @@ void FeaturesPlugin_BooleanSmash::execute() GeomAlgoAPI_Boolean::BOOL_CUT)); // Checking that the algorithm worked properly. - if (!aBoolAlgo->isDone()) { - static const std::string aFeatureError = "Error: Boolean algorithm failed."; - setError(aFeatureError); - return; - } - if (aBoolAlgo->shape()->isNull()) { - static const std::string aShapeError = "Error: Resulting shape is Null."; - setError(aShapeError); - return; - } - if (!aBoolAlgo->isValid()) { - std::string aFeatureError = "Error: Resulting shape is not valid."; - setError(aFeatureError); + if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aBoolAlgo, getKind(), anError)) { + setError(anError); return; } + aMakeShapeList->appendAlgo(aBoolAlgo); // Put all (cut result, tools and not used solids) to PaveFiller. @@ -211,19 +204,8 @@ void FeaturesPlugin_BooleanSmash::execute() else { std::shared_ptr aFillerAlgo( new GeomAlgoAPI_PaveFiller(aShapesToAdd, true)); - if (!aFillerAlgo->isDone()) { - std::string aFeatureError = "Error: PaveFiller algorithm failed."; - setError(aFeatureError); - return; - } - if (aFillerAlgo->shape()->isNull()) { - static const std::string aShapeError = "Error: Resulting shape is Null."; - setError(aShapeError); - return; - } - if (!aFillerAlgo->isValid()) { - std::string aFeatureError = "Error: Resulting shape is not valid."; - setError(aFeatureError); + if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aFillerAlgo, getKind(), anError)) { + setError(anError); return; } diff --git a/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.cpp b/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.cpp index 272b43001..e3d5803ba 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.cpp @@ -84,11 +84,12 @@ int FeaturesPlugin_CompositeSketch::numberOfSubs(bool forTree) const std::shared_ptr FeaturesPlugin_CompositeSketch::subFeature(const int theIndex, bool forTree) { + FeaturePtr aSubFeature; if(theIndex == 0) { - return std::dynamic_pointer_cast(data()->reference(SKETCH_ID())->value()); + aSubFeature = + std::dynamic_pointer_cast(data()->reference(SKETCH_ID())->value()); } - - return std::shared_ptr(); + return aSubFeature; } //================================================================================================= @@ -108,14 +109,14 @@ int FeaturesPlugin_CompositeSketch::subFeatureId(const int theIndex) const //================================================================================================= bool FeaturesPlugin_CompositeSketch::isSub(ObjectPtr theObject) const { + bool isSubFeature = false; // Check is this feature of result FeaturePtr aFeature = std::dynamic_pointer_cast(theObject); - if(!aFeature.get()) { - return false; + if (aFeature.get()) { + ObjectPtr aSub = data()->reference(SKETCH_ID())->value(); + isSubFeature = aSub == theObject; } - - ObjectPtr aSub = data()->reference(SKETCH_ID())->value(); - return aSub == theObject; + return isSubFeature; } //================================================================================================= @@ -235,31 +236,6 @@ void FeaturesPlugin_CompositeSketch::getBaseShapes(ListOfShape& theBaseShapesLis } } -//================================================================================================= -bool FeaturesPlugin_CompositeSketch::isMakeShapeValid( - const std::shared_ptr theMakeShape) -{ - // Check that algo is done. - if(!theMakeShape->isDone()) { - setError("Error: " + getKind() + " algorithm failed."); - return false; - } - - // Check if shape is not null. - if(!theMakeShape->shape().get() || theMakeShape->shape()->isNull()) { - setError("Error: Resulting shape is null."); - return false; - } - - // Check that resulting shape is valid. - if(!theMakeShape->isValid()) { - setError("Error: Resulting shape is not valid."); - return false; - } - - return true; -} - //================================================================================================= void FeaturesPlugin_CompositeSketch::storeResult(const GeomShapePtr theBaseShape, const std::shared_ptr theMakeShape, diff --git a/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.h b/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.h index e4774bde8..f714351aa 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.h +++ b/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.h @@ -83,9 +83,6 @@ protected: /// \param[in] theIsMakeShells if true make shells from faces with shared edges. void getBaseShapes(ListOfShape& theBaseShapesList, const bool theIsMakeShells = true); - /// Checks make shape algo. - bool isMakeShapeValid(const std::shared_ptr theMakeShape); - /// Stores result of generation. void storeResult(const GeomShapePtr theBaseShape, const std::shared_ptr theMakeShape, diff --git a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp index 8944dd362..05a31bb3e 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -167,6 +168,7 @@ bool FeaturesPlugin_Extrusion::makeExtrusions(ListOfShape& theBaseShapes, } // Generating result for each base shape. + std::string anError; for(ListOfShape::const_iterator anIter = theBaseShapes.cbegin(); anIter != theBaseShapes.cend(); anIter++) { std::shared_ptr aBaseShape = *anIter; @@ -174,7 +176,8 @@ bool FeaturesPlugin_Extrusion::makeExtrusions(ListOfShape& theBaseShapes, std::shared_ptr aPrismAlgo(new GeomAlgoAPI_Prism(aBaseShape, aDir, aToShape, aToSize, aFromShape, aFromSize)); - if(!isMakeShapeValid(aPrismAlgo)) { + if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aPrismAlgo, getKind(), anError)) { + setError(anError); return false; } diff --git a/src/FeaturesPlugin/FeaturesPlugin_Fillet.cpp b/src/FeaturesPlugin/FeaturesPlugin_Fillet.cpp index b4ce7d588..cf1dda3d2 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Fillet.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Fillet.cpp @@ -31,6 +31,7 @@ #include #include +#include #include #include @@ -147,6 +148,7 @@ void FeaturesPlugin_Fillet::execute() GeomAlgoAPI_MakeShapeList aMakeShapeList; std::shared_ptr aFilletBuilder; int aResultIndex = 0; + std::string anError; GeomAPI_DataMapOfShapeMapOfShapes::iterator anIt = aSolidsAndSubs.begin(); for (; anIt != aSolidsAndSubs.end(); ++anIt) { @@ -158,8 +160,11 @@ void FeaturesPlugin_Fillet::execute() aFilletBuilder.reset(new GeomAlgoAPI_Fillet(aSolid, aFilletEdges, aRadius1)); else aFilletBuilder.reset(new GeomAlgoAPI_Fillet(aSolid, aFilletEdges, aRadius1, aRadius2)); - if (isFailed(aFilletBuilder)) + + if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aFilletBuilder, getKind(), anError)) { + setError(anError); return; + } GeomShapePtr aResult = unwrapCompound(aFilletBuilder->shape()); std::shared_ptr aResultBody = @@ -172,27 +177,6 @@ void FeaturesPlugin_Fillet::execute() removeResults(aResultIndex); } -bool FeaturesPlugin_Fillet::isFailed( - const std::shared_ptr& theAlgorithm) -{ - if (!theAlgorithm->isDone()) { - static const std::string aFeatureError = "Error: fillet algorithm failed."; - setError(aFeatureError); - return true; - } - if (theAlgorithm->shape()->isNull()) { - static const std::string aShapeError = "Error: Resulting shape of fillet is Null."; - setError(aShapeError); - return true; - } - if (!theAlgorithm->isValid()) { - std::string aFeatureError = "Error: Resulting shape of fillet is not valid."; - setError(aFeatureError); - return true; - } - return false; -} - void FeaturesPlugin_Fillet::loadNamingDS( std::shared_ptr theResultBody, const std::shared_ptr theBaseShape, diff --git a/src/FeaturesPlugin/FeaturesPlugin_Fillet.h b/src/FeaturesPlugin/FeaturesPlugin_Fillet.h index c91956ae0..15472e217 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Fillet.h +++ b/src/FeaturesPlugin/FeaturesPlugin_Fillet.h @@ -106,9 +106,6 @@ public: FeaturesPlugin_Fillet(); private: - /// Check algorithm is finished correctly and store error otherwise - bool isFailed(const std::shared_ptr& theAlgorithm); - /// 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/FeaturesPlugin/FeaturesPlugin_FusionFaces.cpp b/src/FeaturesPlugin/FeaturesPlugin_FusionFaces.cpp index d9973525d..22e2d8383 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_FusionFaces.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_FusionFaces.cpp @@ -30,6 +30,7 @@ #include #include +#include #include @@ -60,16 +61,9 @@ void FeaturesPlugin_FusionFaces::execute() std::shared_ptr anAlgo(new GeomAlgoAPI_UnifySameDomain(aBaseShape)); // Check algo status - if (!anAlgo->isDone()) { - setError("Error: Fusion algorithm failed."); - return; - } - if (anAlgo->shape()->isNull()) { - setError("Error: Resulting shape is Null."); - return; - } - if (!anAlgo->isValid()) { - setError("Error: Resulting shape is not valid."); + std::string anError; + if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(anAlgo, getKind(), anError)) { + setError(anError); return; } diff --git a/src/FeaturesPlugin/FeaturesPlugin_Intersection.cpp b/src/FeaturesPlugin/FeaturesPlugin_Intersection.cpp index 6c8f51aff..93a02c79f 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Intersection.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Intersection.cpp @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -71,19 +72,9 @@ void FeaturesPlugin_Intersection::execute() GeomMakeShapePtr anIntersectionAlgo(new GeomAlgoAPI_Intersection(anObjects)); // Checking that the algorithm worked properly. - if (!anIntersectionAlgo->isDone()) { - static const std::string aFeatureError = "Error: Intersection algorithm failed."; - setError(aFeatureError); - return; - } - if (anIntersectionAlgo->shape()->isNull()) { - static const std::string aShapeError = "Error: Resulting shape is Null."; - setError(aShapeError); - return; - } - if (!anIntersectionAlgo->isValid()) { - std::string aFeatureError = "Error: Resulting shape is not valid."; - setError(aFeatureError); + std::string anError; + if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(anIntersectionAlgo, getKind(), anError)) { + setError(anError); return; } diff --git a/src/FeaturesPlugin/FeaturesPlugin_MultiRotation.cpp b/src/FeaturesPlugin/FeaturesPlugin_MultiRotation.cpp index 9391b36e0..622ea8de8 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_MultiRotation.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_MultiRotation.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -172,6 +173,7 @@ void FeaturesPlugin_MultiRotation::performRotation1D() aResultIndex++; } } else { + std::string anError; ListOfShape aListOfShape; std::list > aListOfRotationAlgo; @@ -187,19 +189,8 @@ void FeaturesPlugin_MultiRotation::performRotation1D() aRotationnAlgo->build(); // Checking that the algorithm worked properly. - if (!aRotationnAlgo->isDone()) { - static const std::string aFeatureError = "Error : Multitranslation algorithm failed."; - setError(aFeatureError); - break; - } - if (aRotationnAlgo->shape()->isNull()) { - static const std::string aShapeError = "Error : Resulting shape is null."; - setError(aShapeError); - break; - } - if (!aRotationnAlgo->isValid()) { - static const std::string aFeatureError = "Error : Resulting shape in not valid."; - setError(aFeatureError); + if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aRotationnAlgo, getKind(), anError)) { + setError(anError); break; } aListOfShape.push_back(aRotationnAlgo->shape()); diff --git a/src/FeaturesPlugin/FeaturesPlugin_MultiTranslation.cpp b/src/FeaturesPlugin/FeaturesPlugin_MultiTranslation.cpp index ffe7c5b25..4657f8e0a 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_MultiTranslation.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_MultiTranslation.cpp @@ -21,6 +21,7 @@ #include #include +#include #include #include @@ -173,6 +174,7 @@ void FeaturesPlugin_MultiTranslation::performOneDirection() aResultIndex++; } } else { + std::string anError; ListOfShape aListOfShape; std::list > aListOfTranslationAlgo; @@ -188,19 +190,8 @@ void FeaturesPlugin_MultiTranslation::performOneDirection() aTranslationAlgo->build(); // Checking that the algorithm worked properly. - if (!aTranslationAlgo->isDone()) { - static const std::string aFeatureError = "Error : Multitranslation algorithm failed."; - setError(aFeatureError); - break; - } - if (aTranslationAlgo->shape()->isNull()) { - static const std::string aShapeError = "Error : Resulting shape is null."; - setError(aShapeError); - break; - } - if (!aTranslationAlgo->isValid()) { - static const std::string aFeatureError = "Error : Resulting shape in not valid."; - setError(aFeatureError); + if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aTranslationAlgo, getKind(), anError)) { + setError(anError); break; } aListOfShape.push_back(aTranslationAlgo->shape()); @@ -380,6 +371,7 @@ void FeaturesPlugin_MultiTranslation::performTwoDirection() } } } else { + std::string anError; ListOfShape aListOfShape; std::list > aListOfTranslationAlgo; @@ -399,21 +391,10 @@ void FeaturesPlugin_MultiTranslation::performTwoDirection() aTranslationAlgo->build(); // Checking that the algorithm worked properly. - if (!aTranslationAlgo->isDone()) { - static const std::string aFeatureError = "Error : Multitranslation algorithm failed."; - setError(aFeatureError); + if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aTranslationAlgo, getKind(), anError)) { + setError(anError); break; } - if (aTranslationAlgo->shape()->isNull()) { - static const std::string aShapeError = "Error : Resulting shape is null."; - setError(aShapeError); - break; - } - if (!aTranslationAlgo->isValid()) { - static const std::string aFeatureError = "Error : Resulting shape in not valid."; - setError(aFeatureError); - break; - } aListOfShape.push_back(aTranslationAlgo->shape()); aListOfTranslationAlgo.push_back(aTranslationAlgo); } diff --git a/src/FeaturesPlugin/FeaturesPlugin_Partition.cpp b/src/FeaturesPlugin/FeaturesPlugin_Partition.cpp index ca91f21b6..43ae4130c 100755 --- a/src/FeaturesPlugin/FeaturesPlugin_Partition.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Partition.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include @@ -66,9 +67,6 @@ static bool cutUnusedSubs(CompsolidSubs& theObjects, CompsolidSubs& theNotUsed, std::shared_ptr& theMakeShapeList, std::string& theError); -static bool isAlgoFailed(const std::shared_ptr& theAlgo, - std::string& theError); - //================================================================================================= FeaturesPlugin_Partition::FeaturesPlugin_Partition() @@ -125,7 +123,7 @@ void FeaturesPlugin_Partition::execute() new GeomAlgoAPI_Partition(aTargetObjects, aPlanes)); // Checking that the algorithm worked properly. - if (isAlgoFailed(aPartitionAlgo, aError)) { + if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aPartitionAlgo, getKind(), aError)) { setError(aError); return; } @@ -143,7 +141,7 @@ void FeaturesPlugin_Partition::execute() aPartitionAlgo.reset(new GeomAlgoAPI_Partition(aTargetObjects, ListOfShape())); // Checking that the algorithm worked properly. - if (isAlgoFailed(aPartitionAlgo, aError)) { + if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aPartitionAlgo, getKind(), aError)) { setError(aError); return; } @@ -376,7 +374,7 @@ static bool cutSubs(const GeomShapePtr& theFirstArgument, // cut from current list of solids aCutAlgo.reset( new GeomAlgoAPI_Boolean(aUIt->second, theTools, GeomAlgoAPI_Boolean::BOOL_CUT)); - if (isAlgoFailed(aCutAlgo, theError)) + if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aCutAlgo, "", theError)) return false; theMakeShapeList->appendAlgo(aCutAlgo); @@ -411,22 +409,3 @@ bool cutUnusedSubs(CompsolidSubs& theObjects, CompsolidSubs& theNotUsed, return cutSubs(aFirstArgument, theObjects, aToolsForUsed, theMakeShapeList, theError) && cutSubs(aFirstArgument, theNotUsed, aToolsForUnused, theMakeShapeList, theError); } - -bool isAlgoFailed(const std::shared_ptr& theAlgo, std::string& theError) -{ - if (!theAlgo->isDone()) { - theError = "Error: Partition algorithm failed."; - return true; - } - if (theAlgo->shape()->isNull()) { - theError = "Error: Resulting shape is Null."; - return true; - } - if (!theAlgo->isValid()) { - theError = "Error: Resulting shape is not valid."; - return true; - } - - theError.clear(); - return false; -} diff --git a/src/FeaturesPlugin/FeaturesPlugin_Pipe.cpp b/src/FeaturesPlugin/FeaturesPlugin_Pipe.cpp index 425ac1f49..b81823597 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Pipe.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Pipe.cpp @@ -30,6 +30,8 @@ #include #include #include +#include + #include #include @@ -222,6 +224,7 @@ void FeaturesPlugin_Pipe::execute() // Generating result for each object. int aResultIndex = 0; + std::string anError; if(aCreationMethod == CREATION_METHOD_SIMPLE() || aCreationMethod == CREATION_METHOD_BINORMAL()) { for(ListOfShape::const_iterator @@ -235,20 +238,8 @@ void FeaturesPlugin_Pipe::execute() aPathShape, aBiNormal)); - if(!aPipeAlgo->isDone()) { - setError("Error: Pipe algorithm failed."); - aResultIndex = 0; - break; - } - - // Check if shape is valid - if(!aPipeAlgo->shape().get() || aPipeAlgo->shape()->isNull()) { - setError("Error: Resulting shape is Null."); - aResultIndex = 0; - break; - } - if(!aPipeAlgo->isValid()) { - setError("Error: Resulting shape is not valid."); + if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aPipeAlgo, getKind(), anError)) { + setError(anError); aResultIndex = 0; break; } @@ -260,20 +251,8 @@ void FeaturesPlugin_Pipe::execute() aLocations, aPathShape)); - if(!aPipeAlgo->isDone()) { - setError("Error: Pipe algorithm failed."); - removeResults(0); - return; - } - - // Check if shape is valid - if(!aPipeAlgo->shape().get() || aPipeAlgo->shape()->isNull()) { - setError("Error: Resulting shape is Null."); - removeResults(0); - return; - } - if(!aPipeAlgo->isValid()) { - setError("Error: Resulting shape is not valid."); + if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aPipeAlgo, getKind(), anError)) { + setError(anError); removeResults(0); return; } diff --git a/src/FeaturesPlugin/FeaturesPlugin_Placement.cpp b/src/FeaturesPlugin/FeaturesPlugin_Placement.cpp index de1e0a219..b4ae07c3d 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Placement.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Placement.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include @@ -142,6 +143,7 @@ void FeaturesPlugin_Placement::execute() // Applying transformation to each object. int aResultIndex = 0; + std::string anError; std::list::iterator aContext = aContextes.begin(); for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); anObjectsIt++, aContext++) { @@ -158,19 +160,8 @@ void FeaturesPlugin_Placement::execute() aTrsf)); // Checking that the algorithm worked properly. - if(!aTransformAlgo->isDone()) { - static const std::string aFeatureError = "Error: Transform algorithm failed."; - setError(aFeatureError); - break; - } - if(aTransformAlgo->shape()->isNull()) { - static const std::string aShapeError = "Error: Resulting shape is Null."; - setError(aShapeError); - break; - } - if(!aTransformAlgo->isValid()) { - std::string aFeatureError = "Error: Resulting shape is not valid."; - setError(aFeatureError); + if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aTransformAlgo, getKind(), anError)) { + setError(anError); break; } diff --git a/src/FeaturesPlugin/FeaturesPlugin_Recover.cpp b/src/FeaturesPlugin/FeaturesPlugin_Recover.cpp index f4c92fee8..0bf95c301 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Recover.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Recover.cpp @@ -31,6 +31,7 @@ #include #include #include +#include FeaturesPlugin_Recover::FeaturesPlugin_Recover() { @@ -45,6 +46,7 @@ void FeaturesPlugin_Recover::initAttributes() void FeaturesPlugin_Recover::execute() { + std::string anError; int aResultIndex = 0; AttributeRefListPtr aRecovered = reflist(RECOVERED_ENTITIES()); for(int anIndex = aRecovered->size() - 1; anIndex >= 0; anIndex--) { @@ -61,18 +63,8 @@ void FeaturesPlugin_Recover::execute() // Copy shape. std::shared_ptr aCopyAlgo(new GeomAlgoAPI_Copy(aShape)); // Check that algo is done. - if(!aCopyAlgo->isDone()) { - setError("Error: recover algorithm failed."); - return; - } - // Check if shape is not null. - if(!aCopyAlgo->shape().get() || aCopyAlgo->shape()->isNull()) { - setError("Error: resulting shape is null."); - return; - } - // Check that resulting shape is valid. - if(!aCopyAlgo->isValid()) { - setError("Error: resulting shape is not valid."); + if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aCopyAlgo, getKind(), anError)) { + setError(anError); return; } diff --git a/src/FeaturesPlugin/FeaturesPlugin_Revolution.cpp b/src/FeaturesPlugin/FeaturesPlugin_Revolution.cpp index 2f941d59e..bbd7b41f3 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Revolution.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Revolution.cpp @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -177,6 +178,7 @@ bool FeaturesPlugin_Revolution::makeRevolutions(ListOfShape& theBaseShapes, } // Generating result for each base shape. + std::string anError; for(ListOfShape::const_iterator anIter = theBaseShapes.cbegin(); anIter != theBaseShapes.cend(); anIter++) { GeomShapePtr aBaseShape = *anIter; @@ -185,7 +187,8 @@ bool FeaturesPlugin_Revolution::makeRevolutions(ListOfShape& theBaseShapes, aBaseShape, anAxis, aToShape, aToAngle, aFromShape, aFromAngle)); - if(!isMakeShapeValid(aRevolAlgo)) { + if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aRevolAlgo, getKind(), anError)) { + setError(anError); return false; } diff --git a/src/FeaturesPlugin/FeaturesPlugin_Rotation.cpp b/src/FeaturesPlugin/FeaturesPlugin_Rotation.cpp index 7305870f4..01547d62f 100755 --- a/src/FeaturesPlugin/FeaturesPlugin_Rotation.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Rotation.cpp @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -137,6 +138,7 @@ void FeaturesPlugin_Rotation::performTranslationByAxisAndAngle() double anAngle = real(FeaturesPlugin_Rotation::ANGLE_ID())->value(); // Rotating each object. + std::string anError; int aResultIndex = 0; std::list::iterator aContext = aContextes.begin(); for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); @@ -165,19 +167,8 @@ void FeaturesPlugin_Rotation::performTranslationByAxisAndAngle() aRotationAlgo->build(); // Checking that the algorithm worked properly. - if(!aRotationAlgo->isDone()) { - static const std::string aFeatureError = "Error: Rotation algorithm failed."; - setError(aFeatureError); - break; - } - if(aRotationAlgo->shape()->isNull()) { - static const std::string aShapeError = "Error: Resulting shape is Null."; - setError(aShapeError); - break; - } - if(!aRotationAlgo->isValid()) { - std::string aFeatureError = "Error: Resulting shape is not valid."; - setError(aFeatureError); + if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aRotationAlgo, getKind(), anError)) { + setError(anError); break; } @@ -245,6 +236,7 @@ void FeaturesPlugin_Rotation::performTranslationByThreePoints() } // Rotating each object. + std::string anError; int aResultIndex = 0; std::list::iterator aContext = aContextes.begin(); for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); @@ -274,19 +266,8 @@ void FeaturesPlugin_Rotation::performTranslationByThreePoints() aRotationAlgo->build(); // Checking that the algorithm worked properly. - if(!aRotationAlgo->isDone()) { - static const std::string aFeatureError = "Error: Rotation algorithm failed."; - setError(aFeatureError); - break; - } - if(aRotationAlgo->shape()->isNull()) { - static const std::string aShapeError = "Error : Resulting shape is Null."; - setError(aShapeError); - break; - } - if(!aRotationAlgo->isValid()) { - std::string aFeatureError = "Error: Resulting shape is not valid."; - setError(aFeatureError); + if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aRotationAlgo, getKind(), anError)) { + setError(anError); break; } diff --git a/src/FeaturesPlugin/FeaturesPlugin_Scale.cpp b/src/FeaturesPlugin/FeaturesPlugin_Scale.cpp index bc1ef0189..a2c6105c8 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Scale.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Scale.cpp @@ -21,6 +21,7 @@ #include #include +#include #include #include @@ -114,6 +115,7 @@ void FeaturesPlugin_Scale::performScaleByFactor() double aScaleFactor = real(FeaturesPlugin_Scale::SCALE_FACTOR_ID())->value(); // Moving each object. + std::string anError; int aResultIndex = 0; std::list::iterator aContext = aContextes.begin(); for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); @@ -130,19 +132,8 @@ void FeaturesPlugin_Scale::performScaleByFactor() aScaleAlgo->build(); // Checking that the algorithm worked properly. - if(!aScaleAlgo->isDone()) { - static const std::string aFeatureError = "Error: Symmetry algorithm failed."; - setError(aFeatureError); - break; - } - if(aScaleAlgo->shape()->isNull()) { - static const std::string aShapeError = "Error: Resulting shape is Null."; - setError(aShapeError); - break; - } - if(!aScaleAlgo->isValid()) { - std::string aFeatureError = "Error: Resulting shape is not valid."; - setError(aFeatureError); + if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aScaleAlgo, getKind(), anError)) { + setError(anError); break; } @@ -199,6 +190,7 @@ void FeaturesPlugin_Scale::performScaleByDimensions() double aScaleFactorZ = real(FeaturesPlugin_Scale::SCALE_FACTOR_Z_ID())->value(); // Moving each object. + std::string anError; int aResultIndex = 0; std::list::iterator aContext = aContextes.begin(); for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); @@ -218,19 +210,8 @@ void FeaturesPlugin_Scale::performScaleByDimensions() aScaleAlgo->build(); // Checking that the algorithm worked properly. - if(!aScaleAlgo->isDone()) { - static const std::string aFeatureError = "Error: Symmetry algorithm failed."; - setError(aFeatureError); - break; - } - if(aScaleAlgo->shape()->isNull()) { - static const std::string aShapeError = "Error: Resulting shape is Null."; - setError(aShapeError); - break; - } - if(!aScaleAlgo->isValid()) { - std::string aFeatureError = "Error: Resulting shape is not valid."; - setError(aFeatureError); + if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aScaleAlgo, getKind(), anError)) { + setError(anError); break; } diff --git a/src/FeaturesPlugin/FeaturesPlugin_Symmetry.cpp b/src/FeaturesPlugin/FeaturesPlugin_Symmetry.cpp index 93707eeb0..333820a8d 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Symmetry.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Symmetry.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -134,6 +135,7 @@ void FeaturesPlugin_Symmetry::performSymmetryByPoint() } // Moving each object. + std::string anError; int aResultIndex = 0; std::list::iterator aContext = aContextes.begin(); for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); @@ -160,19 +162,8 @@ void FeaturesPlugin_Symmetry::performSymmetryByPoint() aSymmetryAlgo->build(); // Checking that the algorithm worked properly. - if(!aSymmetryAlgo->isDone()) { - static const std::string aFeatureError = "Error: Symmetry algorithm failed."; - setError(aFeatureError); - break; - } - if(aSymmetryAlgo->shape()->isNull()) { - static const std::string aShapeError = "Error: Resulting shape is Null."; - setError(aShapeError); - break; - } - if(!aSymmetryAlgo->isValid()) { - std::string aFeatureError = "Error: Resulting shape is not valid."; - setError(aFeatureError); + if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aSymmetryAlgo, getKind(), anError)) { + setError(anError); break; } @@ -230,6 +221,7 @@ void FeaturesPlugin_Symmetry::performSymmetryByAxis() // Moving each object. + std::string anError; int aResultIndex = 0; std::list::iterator aContext = aContextes.begin(); for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); @@ -256,19 +248,8 @@ void FeaturesPlugin_Symmetry::performSymmetryByAxis() aSymmetryAlgo->build(); // Checking that the algorithm worked properly. - if(!aSymmetryAlgo->isDone()) { - static const std::string aFeatureError = "Error: Symmetry algorithm failed."; - setError(aFeatureError); - break; - } - if(aSymmetryAlgo->shape()->isNull()) { - static const std::string aShapeError = "Error: Resulting shape is Null."; - setError(aShapeError); - break; - } - if(!aSymmetryAlgo->isValid()) { - std::string aFeatureError = "Error: Resulting shape is not valid."; - setError(aFeatureError); + if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aSymmetryAlgo, getKind(), anError)) { + setError(anError); break; } @@ -326,6 +307,7 @@ void FeaturesPlugin_Symmetry::performSymmetryByPlane() // Moving each object. + std::string anError; int aResultIndex = 0; std::list::iterator aContext = aContextes.begin(); for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); @@ -351,19 +333,8 @@ void FeaturesPlugin_Symmetry::performSymmetryByPlane() aSymmetryAlgo->build(); // Checking that the algorithm worked properly. - if(!aSymmetryAlgo->isDone()) { - static const std::string aFeatureError = "Error: Symmetry algorithm failed."; - setError(aFeatureError); - break; - } - if(aSymmetryAlgo->shape()->isNull()) { - static const std::string aShapeError = "Error: Resulting shape is Null."; - setError(aShapeError); - break; - } - if(!aSymmetryAlgo->isValid()) { - std::string aFeatureError = "Error: Resulting shape is not valid."; - setError(aFeatureError); + if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aSymmetryAlgo, getKind(), anError)) { + setError(anError); break; } diff --git a/src/FeaturesPlugin/FeaturesPlugin_Translation.cpp b/src/FeaturesPlugin/FeaturesPlugin_Translation.cpp index 14de51957..e303f2b12 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Translation.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Translation.cpp @@ -34,6 +34,7 @@ #include #include +#include #include @@ -150,6 +151,7 @@ void FeaturesPlugin_Translation::performTranslationByAxisAndDistance() double aDistance = real(FeaturesPlugin_Translation::DISTANCE_ID())->value(); // Moving each object. + std::string anError; int aResultIndex = 0; std::list::iterator aContext = aContextes.begin(); for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); @@ -177,19 +179,8 @@ void FeaturesPlugin_Translation::performTranslationByAxisAndDistance() aTranslationAlgo->build(); // Checking that the algorithm worked properly. - if(!aTranslationAlgo->isDone()) { - static const std::string aFeatureError = "Error: Translation algorithm failed."; - setError(aFeatureError); - break; - } - if(aTranslationAlgo->shape()->isNull()) { - static const std::string aShapeError = "Error: Resulting shape is Null."; - setError(aShapeError); - break; - } - if(!aTranslationAlgo->isValid()) { - std::string aFeatureError = "Error: Resulting shape is not valid."; - setError(aFeatureError); + if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aTranslationAlgo, getKind(), anError)) { + setError(anError); break; } @@ -236,6 +227,7 @@ void FeaturesPlugin_Translation::performTranslationByDimensions() double aDZ = real(FeaturesPlugin_Translation::DZ_ID())->value(); // Moving each object. + std::string anError; int aResultIndex = 0; std::list::iterator aContext = aContextes.begin(); for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); @@ -263,19 +255,8 @@ void FeaturesPlugin_Translation::performTranslationByDimensions() aTranslationAlgo->build(); // Checking that the algorithm worked properly. - if(!aTranslationAlgo->isDone()) { - static const std::string aFeatureError = "Error: Translation algorithm failed."; - setError(aFeatureError); - break; - } - if(aTranslationAlgo->shape()->isNull()) { - static const std::string aShapeError = "Error: Resulting shape is Null."; - setError(aShapeError); - break; - } - if(!aTranslationAlgo->isValid()) { - std::string aFeatureError = "Error: Resulting shape is not valid."; - setError(aFeatureError); + if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aTranslationAlgo, getKind(), anError)) { + setError(anError); break; } @@ -335,6 +316,7 @@ void FeaturesPlugin_Translation::performTranslationByTwoPoints() } // Moving each object. + std::string anError; int aResultIndex = 0; std::list::iterator aContext = aContextes.begin(); for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); @@ -362,19 +344,8 @@ void FeaturesPlugin_Translation::performTranslationByTwoPoints() aTranslationAlgo->build(); // Checking that the algorithm worked properly. - if(!aTranslationAlgo->isDone()) { - static const std::string aFeatureError = "Error: Translation algorithm failed."; - setError(aFeatureError); - break; - } - if(aTranslationAlgo->shape()->isNull()) { - static const std::string aShapeError = "Error: Resulting shape is Null."; - setError(aShapeError); - break; - } - if(!aTranslationAlgo->isValid()) { - std::string aFeatureError = "Error: Resulting shape is not valid."; - setError(aFeatureError); + if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aTranslationAlgo, getKind(), anError)) { + setError(anError); break; } diff --git a/src/FeaturesPlugin/FeaturesPlugin_Union.cpp b/src/FeaturesPlugin/FeaturesPlugin_Union.cpp index e9cbaee7d..fe7122c4a 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Union.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Union.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -109,6 +110,7 @@ void FeaturesPlugin_Union::execute() } // Fuse objects. + std::string anError; std::shared_ptr anAlgo; ListOfShape aTools; if (anObjects.front()->shapeType() == GeomAPI_Shape::SOLID) { @@ -123,16 +125,8 @@ void FeaturesPlugin_Union::execute() // Checking that the algorithm worked properly. std::shared_ptr aMakeShapeList(new GeomAlgoAPI_MakeShapeList()); GeomAPI_DataMapOfShapeShape aMapOfShapes; - if(!anAlgo->isDone()) { - setError("Error: Boolean algorithm failed."); - return; - } - if(anAlgo->shape()->isNull()) { - setError("Error: Resulting shape is Null."); - return; - } - if(!anAlgo->isValid()) { - setError("Error: Resulting shape is not valid."); + if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(anAlgo, getKind(), anError)) { + setError(anError); return; } @@ -149,16 +143,8 @@ void FeaturesPlugin_Union::execute() aShapesToAdd.push_back(aShape); std::shared_ptr aFillerAlgo( new GeomAlgoAPI_PaveFiller(aShapesToAdd, true)); - if(!aFillerAlgo->isDone()) { - setError("Error: PaveFiller algorithm failed."); - return; - } - if(aFillerAlgo->shape()->isNull()) { - setError("Error: Resulting shape is Null."); - return; - } - if(!aFillerAlgo->isValid()) { - setError("Error: Resulting shape is not valid."); + if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aFillerAlgo, getKind(), anError)) { + setError(anError); return; } diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Tools.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Tools.cpp index 5a893f50b..e642cc59f 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Tools.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Tools.cpp @@ -19,6 +19,7 @@ // #include "GeomAlgoAPI_Tools.h" +#include "GeomAlgoAPI_MakeShape.h" #include @@ -58,3 +59,32 @@ std::string File_Tools::name(const std::string& theFileName) OSD_Path aPath(aFileName); return aPath.Name().ToCString(); } + +bool AlgoError::isAlgorithmFailed(const GeomMakeShapePtr& theAlgorithm, + const std::string& theFeature, + std::string& theError) +{ + theError.clear(); + if (!theAlgorithm->isDone()) { + theError = "Error: " + (theFeature.empty() ? "The" : theFeature) + " algorithm failed."; + std::string anAlgoError = theAlgorithm->getError(); + if (!anAlgoError.empty()) + theError += " " + anAlgoError; + return true; + } + if (!theAlgorithm->shape() || theAlgorithm->shape()->isNull()) { + theError = "Error: Resulting shape"; + if (!theFeature.empty()) + theError += "of " + theFeature; + theError += " is Null."; + return true; + } + if (!theAlgorithm->isValid()) { + theError = "Error: Resulting shape"; + if (!theFeature.empty()) + theError += "of " + theFeature; + theError += " is not valid."; + return true; + } + return false; +} diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Tools.h b/src/GeomAlgoAPI/GeomAlgoAPI_Tools.h index f17efdc3b..bb0c28f2b 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Tools.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Tools.h @@ -23,8 +23,11 @@ #include +#include #include +class GeomAlgoAPI_MakeShape; + namespace GeomAlgoAPI_Tools { /** \class Localizer @@ -56,6 +59,24 @@ public: GEOMALGOAPI_EXPORT static std::string name(const std::string& theFileName); }; +/** \class AlgoError + * \ingroup DataAlgo + * \brief Verify error in MakeShape algorithm. + */ +class AlgoError { +public: + /** \brief Verify MakeShape algorithm for failures + * \param[in] theAlgorithm object to verify the failure + * \param[in] theFeature kind of the feature, the algorithm belongs to + * \param[out] theError error string (empty if the feature succeed) + * \return \c true if succeed + */ + GEOMALGOAPI_EXPORT static bool isAlgorithmFailed( + const std::shared_ptr& theAlgorithm, + const std::string& theFeature, + std::string& theError); +}; + } // GeomAlgoAPI_Tools #endif /* GEOMALGOAPI_TOOLS_H_ */ -- 2.30.2