Salome HOME
updated copyright message
[modules/gui.git] / src / SalomeApp / SalomeApp_Tools.cxx
1 // Copyright (C) 2007-2023  CEA, EDF, 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 #include "SalomeApp_Tools.h"
24
25 #include <SUIT_Session.h>
26 #include <SUIT_Desktop.h>
27 #include <SUIT_MessageBox.h>
28
29 #include <utilities.h>
30
31 #include <QColor>
32 #include <QString>
33
34 #include <Quantity_Color.hxx>
35
36 /*!
37   Convert QColor to Quantity_Color, if QColor is valid.
38 */
39 Quantity_Color SalomeApp_Tools::color( const QColor& c )
40 {
41         Quantity_Color aColor;
42         if ( c.isValid() )
43                 aColor = Quantity_Color( c.red() / 255., c.green() / 255., c.blue() / 255., Quantity_TOC_RGB );
44         return aColor;
45 }
46
47 /*!
48   Convert Quantity_Color to QColor.
49 */
50 QColor SalomeApp_Tools::color( const Quantity_Color& c )
51 {
52         return QColor( (int)( c.Red() * 255 ), (int)( c.Green() * 255 ), (int)( c.Blue() * 255 ) );
53 }
54
55 /*!
56   Gets message on exception \a S_ex.
57 */
58 QString SalomeApp_Tools::ExceptionToString( const SALOME::SALOME_Exception& S_ex )
59 {
60   QString message;
61   
62   switch ( S_ex.details.type )
63   {
64   case SALOME::COMM:
65   case SALOME::INTERNAL_ERROR:
66     {
67             message = QString( S_ex.details.text );
68             QString source( S_ex.details.sourceFile );
69             QString line;
70             line.setNum( S_ex.details.lineNumber );
71             message = message + " \n" + source + " : " + line;
72       break;
73     }
74   case SALOME::BAD_PARAM:
75     {
76             message = QString( S_ex.details.text );
77 #ifdef _DEBUG_
78             QString source( S_ex.details.sourceFile );
79             QString line;
80             line.setNum( S_ex.details.lineNumber );
81             message = message + " \n" + source + " : " + line;
82 #endif
83             break;
84     }
85   default:
86     {
87             message = QString( "SALOME CORBA Exception Type invalid" );
88             QString source( S_ex.details.sourceFile );
89             QString line;
90             line.setNum( S_ex.details.lineNumber );
91             message = message + " \n" + source + " : " + line;
92             break;
93     }
94   }
95   return message;
96 }
97
98 /*!
99   Gets message box on exception \a S_ex.
100 */
101 void SalomeApp_Tools::QtCatchCorbaException( const SALOME::SALOME_Exception& S_ex )
102 {
103   QString message = ExceptionToString( S_ex );
104
105   QString title;
106   bool error = true;
107   switch ( S_ex.details.type )
108   {
109   case SALOME::COMM:
110   case SALOME::INTERNAL_ERROR:
111     title = QObject::tr( "Engine Error" );
112     break;
113   case SALOME::BAD_PARAM:
114     error = false;
115     title = QObject::tr( "Engine Warning" );
116           break;
117   default:
118     title = QObject::tr( "Internal SALOME Error" );
119     break;
120   }
121
122   if ( error )
123     SUIT_MessageBox::critical( SUIT_Session::session()->activeApplication()->desktop(),
124                                title, message );
125   else
126     SUIT_MessageBox::warning( SUIT_Session::session()->activeApplication()->desktop(),
127                               title, message );
128
129 }