Salome HOME
This commit was generated by cvs2git to track changes on a CVS vendor
[modules/kernel.git] / src / Session / SALOME_Session_QThread.cxx
1 //  SALOME Session : implementation of Session.idl
2 //
3 //  Copyright (C) 2003  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SALOME_Session_QThread.cxx
25 //  Author : Paul RASCLE, EDF
26 //  Module : SALOME
27 //  $Header$
28
29 using namespace std;
30 #include <qapplication.h>
31 #include <qlabel.h>
32
33 #include "utilities.h"
34 #include "SALOME_Session_QThread.hxx"
35 #include "SALOME_NamingService.hxx"
36 #include "SALOMEGUI_Application.h"
37 #include "QAD.h"
38 #include "QAD_MessageBox.h"
39 #include "QAD_Application.h"
40 #include "QAD_Settings.h"
41 #include "QAD_Config.h"
42 #include "QAD_Tools.h"
43 // only to use findFile method : perhaps put it in QAD_Tools ???
44 #include "QAD_ResourceMgr.h"
45 #include <qlabel.h>
46
47
48 #include <SALOMEconfig.h>
49 #include CORBA_SERVER_HEADER(SALOMEDS)
50
51 //=============================================================================
52 /*! SALOME_Session_QThread
53  *  constructor
54  */
55 //=============================================================================
56
57 SALOME_Session_QThread::SALOME_Session_QThread(int argc, char ** argv) : QThread()
58 {
59   _qappl = 0 ;
60   _mw = 0 ;
61   _argc = argc ;
62   _argv = argv ;
63   _NS = 0 ;
64 } ;
65
66 //=============================================================================
67 /*! run
68  *  Creates one QApplication for the all the session life.
69  *  Executes the Qt main window of the GUI on a separate thread
70  */
71 //=============================================================================
72
73 void SALOME_Session_QThread::run()
74 {
75   if (_qappl == 0)
76     {
77       _qappl = new QApplication(_argc, _argv );
78       INFOS("creation QApplication");
79     }
80
81   QAD_ASSERT ( QObject::connect(_qappl, SIGNAL(lastWindowClosed()), _qappl, SLOT(quit()) ) );
82   _mw = new SALOMEGUI_Application ( "MDTV-Standard", "HDF", "hdf" );
83   INFOS("creation SALOMEGUI_Application");
84   
85   if ( !SALOMEGUI_Application::addToDesktop ( _mw, _NS ) )
86     {
87       QAD_MessageBox::error1 ( 0,
88                                QObject::tr("ERR_ERROR"), 
89                                QObject::tr("ERR_APP_INITFAILED"),
90                                QObject::tr("BUT_OK") );
91     }
92   else
93     {
94       
95       QFileInfo prgInfo(_argv[0]);
96       QDir prgDir(prgInfo.dirPath(true));
97       QAD_CONFIG->setPrgDir(prgDir);        // CWD is program directory
98       QAD_CONFIG->createConfigFile(false);  // Create config file ~/.tr(MEN_APPNAME)/tr(MEN_APPNAME).conf if there's none
99       QAD_CONFIG->readConfigFile();         // Read config file
100
101       _qappl->setPalette( QAD_Application::getPalette() ); 
102
103       /* Run 'SALOMEGUI' application */
104       QAD_Application::run();
105
106       // T2.12 - catch exceptions thrown on attempts to modified a locked study
107       while (1) {
108         try {
109           MESSAGE("run(): starting the main event loop")
110           _ret = _qappl->exec();
111           break;
112         }
113         catch(SALOMEDS::StudyBuilder::LockProtection&) {
114           MESSAGE("run(): An attempt to modify a locked study has not been handled by QAD_Operation")
115           QApplication::restoreOverrideCursor();
116           QAD_MessageBox::warn1 ( (QWidget*)QAD_Application::getDesktop(),
117                                QObject::tr("WRN_WARNING"), 
118                                QObject::tr("WRN_STUDY_LOCKED"),
119                                QObject::tr("BUT_OK") );
120         }
121         catch(...) {
122           MESSAGE("run(): An exception has been caught")
123           QApplication::restoreOverrideCursor();
124           QAD_MessageBox::error1 ( (QWidget*)QAD_Application::getDesktop(),
125                                QObject::tr("ERR_ERROR"), 
126                                QObject::tr("ERR_APP_EXCEPTION"),
127                                QObject::tr("BUT_OK") );
128         }
129       }
130
131       QString confMsg = "Settings create $HOME/." + QObject::tr("MEN_APPNAME") + "/" + QObject::tr("MEN_APPNAME") + ".conf";
132       MESSAGE (confMsg )
133       QAD_CONFIG->createConfigFile(true);
134     }
135 } ;
136
137 //=============================================================================
138 /*! setNamingService
139  *  gives the naming service interface 
140  */
141 //=============================================================================
142 void SALOME_Session_QThread::setNamingService(SALOME_NamingService *ns)
143 {
144   _NS = ns;
145 }