Salome HOME
Add settings for Plot2D viewer.
[modules/gui.git] / src / SalomeApp / SalomeApp_Tools.cxx
1 #include "SalomeApp_Tools.h"
2
3 #include <SUIT_Session.h>
4 #include <SUIT_Desktop.h>
5 #include <SUIT_MessageBox.h>
6
7 #include <utilities.h>
8
9 /*!
10   Convert QColor to Quantity_Color, if QColor is valid.
11 */
12 Quantity_Color SalomeApp_Tools::color( const QColor& c )
13 {
14         Quantity_Color aColor;
15         if ( c.isValid() )
16                 aColor = Quantity_Color( c.red() / 255., c.green() / 255., c.blue() / 255., Quantity_TOC_RGB );
17         return aColor;
18 }
19
20 /*!
21   Convert Quantity_Color to QColor.
22 */
23 QColor SalomeApp_Tools::color( const Quantity_Color& c )
24 {
25         return QColor( (int)( c.Red() * 255 ), (int)( c.Green() * 255 ), (int)( c.Blue() * 255 ) );
26 }
27
28 /*!
29   Gets message on exception \a S_ex.
30 */
31 QString SalomeApp_Tools::ExceptionToString( const SALOME::SALOME_Exception& S_ex )
32 {
33   QString message;
34   
35   switch ( S_ex.details.type )
36   {
37   case SALOME::COMM:
38   case SALOME::INTERNAL_ERROR:
39     {
40             message = QString( S_ex.details.text );
41             QString source( S_ex.details.sourceFile );
42             QString line;
43             line.setNum( S_ex.details.lineNumber );
44             message = message + " \n" + source + " : " + line;
45       break;
46     }
47   case SALOME::BAD_PARAM:
48     {
49             message = QString( S_ex.details.text );
50 #ifdef _DEBUG_
51             QString source( S_ex.details.sourceFile );
52             QString line;
53             line.setNum( S_ex.details.lineNumber );
54             message = message + " \n" + source + " : " + line;
55 #endif
56             break;
57     }
58   default:
59     {
60             message = QString( "SALOME CORBA Exception Type invalid" );
61             QString source( S_ex.details.sourceFile );
62             QString line;
63             line.setNum( S_ex.details.lineNumber );
64             message = message + " \n" + source + " : " + line;
65             break;
66     }
67   }
68   return message;
69 }
70
71 /*!
72   Gets message box on exception \a S_ex.
73 */
74 void SalomeApp_Tools::QtCatchCorbaException( const SALOME::SALOME_Exception& S_ex )
75 {
76   QString message = ExceptionToString( S_ex );
77
78   QString title;
79   bool error = true;
80   switch ( S_ex.details.type )
81   {
82   case SALOME::COMM:
83   case SALOME::INTERNAL_ERROR:
84     title = QObject::tr( "Engine Error" );
85     break;
86   case SALOME::BAD_PARAM:
87     error = false;
88     title = QObject::tr( "Engine Warning" );
89           break;
90   default:
91     title = QObject::tr( "Internal SALOME Error" );
92     break;
93   }
94
95   if ( error )
96     SUIT_MessageBox::error1( SUIT_Session::session()->activeApplication()->desktop(),
97                                    title, message, QObject::tr( "OK" ) );
98   else
99     SUIT_MessageBox::warn1( SUIT_Session::session()->activeApplication()->desktop(),
100                                   title, message, QObject::tr( "OK" ) );
101
102 }