Salome HOME
Merge from V5_1_4_BR 07/05/2010
[modules/smesh.git] / src / SMESH / SMESH_ComputeError.hxx
1 //  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  This library is free software; you can redistribute it and/or
4 //  modify it under the terms of the GNU Lesser General Public
5 //  License as published by the Free Software Foundation; either
6 //  version 2.1 of the License.
7 //
8 //  This library is distributed in the hope that it will be useful,
9 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 //  Lesser General Public License for more details.
12 //
13 //  You should have received a copy of the GNU Lesser General Public
14 //  License along with this library; if not, write to the Free Software
15 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 //  SMESH SMESH : implementaion of SMESH idl descriptions
21 //  File   : SMESH_Hypothesis.hxx
22 //  Author : Edward AGAPOV (eap)
23 //  Module : SMESH
24 //  $Header: 
25 //
26 #ifndef SMESH_ComputeError_HeaderFile
27 #define SMESH_ComputeError_HeaderFile
28
29 #include <string>
30 #include <list>
31 #include <boost/shared_ptr.hpp>
32
33 class SMESH_Algo;
34 class SMDS_MeshElement;
35 struct SMESH_ComputeError;
36
37 typedef boost::shared_ptr<SMESH_ComputeError> SMESH_ComputeErrorPtr;
38
39 // =============================================================
40
41 enum SMESH_ComputeErrorName
42 {
43   // If you modify it, pls update SMESH_ComputeError::CommonName() below.
44   // Positive values are for algo specific errors
45   COMPERR_OK             = -1,
46   COMPERR_BAD_INPUT_MESH = -2,  //!< wrong mesh on lower submesh
47   COMPERR_STD_EXCEPTION  = -3,  //!< some std exception raised
48   COMPERR_OCC_EXCEPTION  = -4,  //!< OCC exception raised
49   COMPERR_SLM_EXCEPTION  = -5,  //!< SALOME exception raised
50   COMPERR_EXCEPTION      = -6,  //!< other exception raised
51   COMPERR_MEMORY_PB      = -7,  //!< std::bad_alloc exception
52   COMPERR_ALGO_FAILED    = -8,  //!< algo failed for some reason
53   COMPERR_BAD_SHAPE      = -9   //!< bad geometry
54 };
55
56 // =============================================================
57 /*!
58  * \brief Contains algorithm and description of occured error
59  */
60 // =============================================================
61
62 struct SMESH_ComputeError
63 {
64   int               myName; //!< SMESH_ComputeErrorName or anything algo specific
65   std::string       myComment;
66   const SMESH_Algo* myAlgo;
67
68   std::list<const SMDS_MeshElement*> myBadElements; //!< to explain COMPERR_BAD_INPUT_MESH
69
70   static SMESH_ComputeErrorPtr New( int               error   = COMPERR_OK,
71                                     std::string       comment = "",
72                                     const SMESH_Algo* algo    = 0)
73   { return SMESH_ComputeErrorPtr( new SMESH_ComputeError( error, comment, algo )); }
74
75   SMESH_ComputeError(int               error   = COMPERR_OK,
76                      std::string       comment = "",
77                      const SMESH_Algo* algo    = 0)
78     :myName(error),myComment(comment),myAlgo(algo) {}
79
80   bool IsOK()     { return myName == COMPERR_OK; }
81   bool IsCommon() { return myName < 0; }
82   inline std::string CommonName() const;
83
84 };
85
86 #define _case2char(err) case err: return #err;
87
88 std::string SMESH_ComputeError::CommonName() const
89 {
90   switch( myName ) {
91   _case2char(COMPERR_OK            );
92   _case2char(COMPERR_BAD_INPUT_MESH);
93   _case2char(COMPERR_STD_EXCEPTION );
94   _case2char(COMPERR_OCC_EXCEPTION );
95   _case2char(COMPERR_SLM_EXCEPTION );
96   _case2char(COMPERR_EXCEPTION     );
97   _case2char(COMPERR_MEMORY_PB     );
98   _case2char(COMPERR_ALGO_FAILED   );
99   _case2char(COMPERR_BAD_SHAPE     );
100   default:;
101   }
102   return "";
103 }
104
105 #endif