From: Clarisse Genrault Date: Tue, 21 Jun 2016 13:19:41 +0000 (+0200) Subject: Adding error handling. X-Git-Tag: V_2.5.0~233 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=2e672b9dcc8e975fa44f6bd687a47a298b152826;p=modules%2Fshaper.git Adding error handling. Adding check for shape result (before and after launch algo). --- diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.cpp index 87d38d2b8..4f74d5aef 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.cpp @@ -3,6 +3,8 @@ // File: GeomAlgoAPI_MakeShape.cpp // Created: 20 Oct 2014 // Author: Sergey ZARITCHNY +// +// Modified by Clarisse Genrault (CEA) : 17 Mar 2016 #include "GeomAlgoAPI_MakeShape.h" @@ -15,6 +17,7 @@ #include #include #include +#include //================================================================================================= GeomAlgoAPI_MakeShape::GeomAlgoAPI_MakeShape() @@ -154,11 +157,6 @@ void GeomAlgoAPI_MakeShape::setShape(const std::shared_ptr theSha } const TopoDS_Shape& aTopoDSShape = myShape->impl(); - for(TopExp_Explorer anExp(aTopoDSShape,TopAbs_EDGE); anExp.More(); anExp.Next()) { - std::shared_ptr aCurrentShape(new GeomAPI_Shape()); - aCurrentShape->setImpl(new TopoDS_Shape(anExp.Current())); - myMap->bind(aCurrentShape, aCurrentShape); - } for(TopExp_Explorer anExp(aTopoDSShape,TopAbs_FACE); anExp.More(); anExp.Next()) { std::shared_ptr aCurrentShape(new GeomAPI_Shape()); aCurrentShape->setImpl(new TopoDS_Shape(anExp.Current())); @@ -201,3 +199,41 @@ void GeomAlgoAPI_MakeShape::initialize() { myMap->bind(aCurrentShape, aCurrentShape); } } + + +//================================================================================================= +void GeomAlgoAPI_MakeShape::prepareNamingFaces() +{ + int index = 1; + GeomAPI_ShapeExplorer anExp(shape(), GeomAPI_Shape::FACE); + for(GeomAPI_ShapeExplorer anExp(shape(), GeomAPI_Shape::FACE); anExp.more(); anExp.next()) { + std::shared_ptr aFace = anExp.current(); + myCreatedFaces["Face_" + std::to_string(index++)] = aFace; + } +} + + +//================================================================================================= +bool GeomAlgoAPI_MakeShape::checkValid(std::string theMessage){ + + // isValid() is called from this method + if (!isValid()) { + myError = theMessage + " :: resulting shape is not valid."; + return false; + } + + // Check the number of volumes in myShape, make sure there's one and only one. + TopoDS_Shape aTopoDSShape = myShape->impl(); + int aNbVolumes = 0; + for(TopExp_Explorer anExp(aTopoDSShape,TopAbs_SOLID); anExp.More(); anExp.Next()) { + aNbVolumes ++; + } + + if (aNbVolumes != 1) { + myError = theMessage + " :: connexity error, the resulting shape is made of several separate solids."; + return false; + } + + return true ; +} + diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.h b/src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.h index 0131da446..1b423738e 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.h @@ -3,6 +3,9 @@ // File: GeomAlgoAPI_MakeShape.h // Created: 17 Oct 2014 // Author: Sergey ZARITCHNY +// +// Modified by Clarisse Genrault (CEA) : 17 Mar 2016 + #ifndef GeomAlgoAPI_MakeShape_H_ #define GeomAlgoAPI_MakeShape_H_ @@ -11,6 +14,7 @@ #include #include +#include /// \class GeomAlgoAPI_MakeShape /// \ingroup DataAlgo @@ -80,6 +84,21 @@ public: /// \param[in] theShape base shape. GEOMALGOAPI_EXPORT virtual bool isDeleted(const std::shared_ptr theShape); + /// \return true if the data were correct. + GEOMALGOAPI_EXPORT virtual bool check() { return true; }; + + /// \return the list of created faces. + GEOMALGOAPI_EXPORT std::map< std::string, std::shared_ptr > getCreatedFaces() {return myCreatedFaces;} + + /// \return the error. + GEOMALGOAPI_EXPORT std::string getError() { return myError; } + + /// \brief Prepare the naming of faces. + GEOMALGOAPI_EXPORT virtual void prepareNamingFaces(); + + /// \brief Check the validity of the produced shape. + GEOMALGOAPI_EXPORT bool checkValid(std::string theMessage); + protected: /// \brief Sets builder type. /// \param[in] theBuilderType new builder type. @@ -95,7 +114,9 @@ protected: protected: std::shared_ptr myMap; ///< Data map to keep correct orientation of sub-shapes. - + std::string myError; /// Error occurred during the execution of an algorithm. + std::map< std::string, std::shared_ptr > myCreatedFaces; /// Map of created faces with their name for naming. + private: /// \brief Initializes internals. void initialize();