Back to index

salome-gui  6.5.0
SalomeApp_Tools.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #include "SalomeApp_Tools.h"
00024 
00025 #include <SUIT_Session.h>
00026 #include <SUIT_Desktop.h>
00027 #include <SUIT_MessageBox.h>
00028 
00029 #include <utilities.h>
00030 
00031 #include <QColor>
00032 #include <QString>
00033 
00034 #include <Quantity_Color.hxx>
00035 
00039 Quantity_Color SalomeApp_Tools::color( const QColor& c )
00040 {
00041         Quantity_Color aColor;
00042         if ( c.isValid() )
00043                 aColor = Quantity_Color( c.red() / 255., c.green() / 255., c.blue() / 255., Quantity_TOC_RGB );
00044         return aColor;
00045 }
00046 
00050 QColor SalomeApp_Tools::color( const Quantity_Color& c )
00051 {
00052         return QColor( (int)( c.Red() * 255 ), (int)( c.Green() * 255 ), (int)( c.Blue() * 255 ) );
00053 }
00054 
00058 QString SalomeApp_Tools::ExceptionToString( const SALOME::SALOME_Exception& S_ex )
00059 {
00060   QString message;
00061   
00062   switch ( S_ex.details.type )
00063   {
00064   case SALOME::COMM:
00065   case SALOME::INTERNAL_ERROR:
00066     {
00067             message = QString( S_ex.details.text );
00068             QString source( S_ex.details.sourceFile );
00069             QString line;
00070             line.setNum( S_ex.details.lineNumber );
00071             message = message + " \n" + source + " : " + line;
00072       break;
00073     }
00074   case SALOME::BAD_PARAM:
00075     {
00076             message = QString( S_ex.details.text );
00077 #ifdef _DEBUG_
00078             QString source( S_ex.details.sourceFile );
00079             QString line;
00080             line.setNum( S_ex.details.lineNumber );
00081             message = message + " \n" + source + " : " + line;
00082 #endif
00083             break;
00084     }
00085   default:
00086     {
00087             message = QString( "SALOME CORBA Exception Type invalid" );
00088             QString source( S_ex.details.sourceFile );
00089             QString line;
00090             line.setNum( S_ex.details.lineNumber );
00091             message = message + " \n" + source + " : " + line;
00092             break;
00093     }
00094   }
00095   return message;
00096 }
00097 
00101 void SalomeApp_Tools::QtCatchCorbaException( const SALOME::SALOME_Exception& S_ex )
00102 {
00103   QString message = ExceptionToString( S_ex );
00104 
00105   QString title;
00106   bool error = true;
00107   switch ( S_ex.details.type )
00108   {
00109   case SALOME::COMM:
00110   case SALOME::INTERNAL_ERROR:
00111     title = QObject::tr( "Engine Error" );
00112     break;
00113   case SALOME::BAD_PARAM:
00114     error = false;
00115     title = QObject::tr( "Engine Warning" );
00116           break;
00117   default:
00118     title = QObject::tr( "Internal SALOME Error" );
00119     break;
00120   }
00121 
00122   if ( error )
00123     SUIT_MessageBox::critical( SUIT_Session::session()->activeApplication()->desktop(),
00124                                title, message );
00125   else
00126     SUIT_MessageBox::warning( SUIT_Session::session()->activeApplication()->desktop(),
00127                               title, message );
00128 
00129 }