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