Salome HOME
Copyright update 2020
[modules/smesh.git] / src / SMESHUtils / SMESH_ComputeError.hxx
index ca29c83e0ef103e074f6fa7600684d058c17e45d..57e4214ff0ab5c3d6b73eacf350c91d19cc6ad76 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2020  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
-//  File   : SMESH_Hypothesis.hxx
+//  File   : SMESH_ComputeError.hxx
 //  Author : Edward AGAPOV (eap)
 //  Module : SMESH
 //
 #ifndef SMESH_ComputeError_HeaderFile
 #define SMESH_ComputeError_HeaderFile
 
+#include "SMESH_Utils.hxx"
+#include "SMDS_ElementHolder.hxx"
+
 #include <string>
 #include <list>
 #include <boost/shared_ptr.hpp>
@@ -63,57 +66,64 @@ enum SMESH_ComputeErrorName
 
 // =============================================================
 /*!
- * \brief Contains an algorithm and description of an occured error
+ * \brief Contains an algorithm and description of an occurred error
  */
 // =============================================================
 
-struct SMESH_ComputeError
+struct SMESHUtils_EXPORT SMESH_ComputeError
 {
   int               myName; //!< SMESH_ComputeErrorName or anything algo specific
   std::string       myComment;
   const SMESH_Algo* myAlgo;
 
-  std::list<const SMDS_MeshElement*> myBadElements; //!< to explain COMPERR_BAD_INPUT_MESH
-
   static SMESH_ComputeErrorPtr New( int               error   = COMPERR_OK,
                                     std::string       comment = "",
                                     const SMESH_Algo* algo    = 0)
   { return SMESH_ComputeErrorPtr( new SMESH_ComputeError( error, comment, algo )); }
 
-  SMESH_ComputeError(int               error   = COMPERR_OK,
-                     std::string       comment = "",
-                     const SMESH_Algo* algo    = 0)
-    :myName(error),myComment(comment),myAlgo(algo) {}
+  SMESH_ComputeError( int               error   = COMPERR_OK,
+                      std::string       comment = "",
+                      const SMESH_Algo* algo    = 0)
+    : myName(error), myComment(comment), myAlgo(algo) {}
 
   bool IsOK()        const { return myName == COMPERR_OK; }
   bool IsKO()        const { return myName != COMPERR_OK && myName != COMPERR_WARNING; }
   bool IsCommon()    const { return myName < 0 && myName > COMPERR_LAST_ALGO_ERROR; }
-  bool HasBadElems() const { return !myBadElements.empty(); }
-  inline std::string CommonName() const;
+  virtual bool HasBadElems() const { return false; }
 
-};
+  // not inline methods are implemented in   src/SMESHUtils/SMESH_TryCatch.cxx
 
-#define _case2char(err) case err: return #err;
+  // Return myName as text, to be used to dump errors in terminal
+  std::string CommonName() const;
+
+  // Return the most severe error
+  static SMESH_ComputeErrorPtr Worst( SMESH_ComputeErrorPtr er1,
+                                      SMESH_ComputeErrorPtr er2 );
+
+  virtual ~SMESH_ComputeError() {}
+};
 
-// Return myName as text, to be used to dump errors in terminal
-std::string SMESH_ComputeError::CommonName() const
+struct SMESHUtils_EXPORT SMESH_BadInputElements : public SMESH_ComputeError, SMDS_ElementHolder
 {
-  switch( myName ) {
-  _case2char(COMPERR_OK              );
-  _case2char(COMPERR_BAD_INPUT_MESH  );
-  _case2char(COMPERR_STD_EXCEPTION   );
-  _case2char(COMPERR_OCC_EXCEPTION   );
-  _case2char(COMPERR_SLM_EXCEPTION   );
-  _case2char(COMPERR_EXCEPTION       );
-  _case2char(COMPERR_MEMORY_PB       );
-  _case2char(COMPERR_ALGO_FAILED     );
-  _case2char(COMPERR_BAD_SHAPE       );
-  _case2char(COMPERR_WARNING         );
-  _case2char(COMPERR_CANCELED        );
-  _case2char(COMPERR_NO_MESH_ON_SHAPE);
-  default:;
-  }
-  return "";
-}
+  typedef std::list<const SMDS_MeshElement*> TElemList;
+  TElemList myBadElements; //!< to explain COMPERR_BAD_INPUT_MESH
+
+  SMESH_BadInputElements(const SMDS_Mesh*  mesh,
+                         int               error   = COMPERR_OK,
+                         std::string       comment = "",
+                         const SMESH_Algo* algo    = 0)
+    :SMESH_ComputeError(error, comment ,algo), SMDS_ElementHolder(mesh) {}
+
+  const SMDS_Mesh* GetMesh() const { return myMesh; }
+  const TElemList& GetElements()   { return myBadElements; }
+
+  virtual bool HasBadElems() const { return !myBadElements.empty(); }
+
+  // methods of SMDS_ElementHolder
+  virtual SMDS_ElemIteratorPtr getElements();
+  virtual void tmpClear();
+  virtual void add( const SMDS_MeshElement* element );
+  virtual void compact() { }
+};
 
 #endif