Salome HOME
Update copyrights
[modules/smesh.git] / src / SMESHUtils / SMESH_TryCatch.cxx
1 // Copyright (C) 2007-2019  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, or (at your option) any later version.
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
23 // ------------------------------------------------------------------
24 #include "SMESH_TryCatch.hxx"
25
26 void SMESH::throwSalomeEx(const char* txt)
27 {
28   throw SALOME_Exception( txt );
29 }
30
31 void SMESH::doNothing(const char* txt)
32 {
33   MESSAGE( txt << " " << __FILE__ << ": " << __LINE__ );
34 }
35
36 const char* SMESH::returnError(const char* txt)
37 {
38   return txt;
39 }
40
41 // ------------------------------------------------------------------
42
43 #include "SMESH_ComputeError.hxx"
44 #include "SMDS_SetIterator.hxx"
45 #include <boost/make_shared.hpp>
46
47 #define _case2char(err) case err: return #err;
48
49 // Return SMESH_ComputeError::myName as text, to be used to dump errors in terminal
50 std::string SMESH_ComputeError::CommonName() const
51 {
52   switch( myName ) {
53   _case2char(COMPERR_OK              );
54   _case2char(COMPERR_BAD_INPUT_MESH  );
55   _case2char(COMPERR_STD_EXCEPTION   );
56   _case2char(COMPERR_OCC_EXCEPTION   );
57   _case2char(COMPERR_SLM_EXCEPTION   );
58   _case2char(COMPERR_EXCEPTION       );
59   _case2char(COMPERR_MEMORY_PB       );
60   _case2char(COMPERR_ALGO_FAILED     );
61   _case2char(COMPERR_BAD_SHAPE       );
62   _case2char(COMPERR_WARNING         );
63   _case2char(COMPERR_CANCELED        );
64   _case2char(COMPERR_NO_MESH_ON_SHAPE);
65   _case2char(COMPERR_BAD_PARMETERS   );
66   default:;
67   }
68   return "";
69 }
70
71 // Return the most severe error
72 SMESH_ComputeErrorPtr SMESH_ComputeError::Worst( SMESH_ComputeErrorPtr er1,
73                                                  SMESH_ComputeErrorPtr er2 )
74 {
75   if ( !er1 ) return er2;
76   if ( !er2 ) return er1;
77   // both not NULL
78   if ( er1->IsOK() ) return er2;
79   if ( er2->IsOK() ) return er1;
80   // both not OK
81   if ( !er1->IsKO() ) return er2;
82   if ( !er2->IsKO() ) return er1;
83   // both KO
84   bool hasInfo1 = er1->myComment.size() || er1->HasBadElems();
85   bool hasInfo2 = er2->myComment.size() || er2->HasBadElems();
86   if ( er1->myName == er2->myName ||
87        hasInfo1    != hasInfo2 )
88     return hasInfo1 < hasInfo2 ? er2 : er1;
89
90   return er1->myName == COMPERR_CANCELED ? er2 : er1;
91 }
92
93 // Return bad elements
94 SMDS_ElemIteratorPtr SMESH_BadInputElements::getElements()
95 {
96   typedef SMDS_SetIterator< const SMDS_MeshElement*,
97                             std::list< const SMDS_MeshElement* >::const_iterator> TIterator;
98   return boost::make_shared< TIterator >( myBadElements.begin(), myBadElements.end() );
99 }
100
101 // Temporary remove its elements before the mesh compacting
102 void SMESH_BadInputElements::tmpClear()
103 {
104   myBadElements.clear();
105 }
106
107 // Re-add elements after the mesh compacting
108 void SMESH_BadInputElements::add( const SMDS_MeshElement* element )
109 {
110   myBadElements.push_back( element );
111 }