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