Salome HOME
Synchronize adm files
[modules/jobmanager.git] / src / salomegui / BL_SalomeGui.cxx
1 // Copyright (C) 2009-2014  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "BL_SalomeGui.hxx"
21 #include "JOBMANAGER_version.h"
22
23 BL::SalomeGui::SalomeGui() : MainWindows_SALOME("JobManager")
24 {
25   DEBTRACE("Creating BL::SalomeGui");
26   _gengui = NULL;
27 }
28
29 BL::SalomeGui::~SalomeGui()
30 {
31   DEBTRACE("Destroying BL::SalomeGui");
32   if (getApp())
33     disconnect(getApp(), SIGNAL(studyClosed()), this, SLOT(studyClosed()));
34   if (_gengui)
35     delete _gengui;
36 }
37
38 void 
39 BL::SalomeGui::initialize(CAM_Application* app)
40 {
41    DEBTRACE("Entering in initialize");
42    SalomeApp_Module::initialize(app); // MANDATORY -> Otherwise SISEGV...
43    connect( getApp(), SIGNAL(studyClosed()), this, SLOT(studyClosed()));
44    if ( app && app->desktop() )
45      connect( app->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
46               this, SLOT(onWindowActivated( SUIT_ViewWindow* )) );
47 }
48
49 void
50 BL::SalomeGui::studyClosed()
51 {
52   if (_gengui)
53   {
54     _gengui->deleteDockWidget();
55     delete _gengui;
56     _gengui = NULL;
57     _viewWin = NULL;
58   }
59 }
60
61 bool 
62 BL::SalomeGui::activateModule(SUIT_Study* theStudy)
63 {
64   DEBTRACE("Entering in BL::SalomeGui::activateModule");
65
66   if (!_gengui)
67   {
68    BL::MainWindows_SALOME::initialize(getApp());
69    BL::MainWindows_SALOME::createView();
70    _gengui = new BL::GenericGui(this);
71
72    _gengui->createDockWidgets();
73    _gengui->createCentralWidget();
74    _gengui->createActions();
75    _gengui->createMenus();
76    _gengui->updateButtonsStates();
77   }
78   else
79    {
80     // Test main view
81     if (!BL::MainWindows_SALOME::restoreViewFocus())
82      {
83       // We need to recreate QT objects and the view
84       BL::MainWindows_SALOME::createView();
85       _gengui->createCentralWidget();
86      }
87    }
88
89   setMenuShown(true);
90   _gengui->showDockWidgets(true);
91   bool bOk = SalomeApp_Module::activateModule(theStudy);
92   return bOk;
93 }
94
95 void 
96 BL::SalomeGui::windows(QMap<int, int>& theMap) const
97 {
98   DEBTRACE("Entering in BL::SalomeGui::windows");
99   theMap.clear();
100   theMap.insert(SalomeApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea);
101 }
102
103 bool 
104 BL::SalomeGui::deactivateModule(SUIT_Study* theStudy)
105 {
106   DEBTRACE("Entering in BL::SalomeGui::deactivateModule");
107   setMenuShown(false);
108   if (_gengui)
109     _gengui->showDockWidgets(false);
110   bool bOk = SalomeApp_Module::deactivateModule(theStudy);
111   return bOk;
112 }
113
114 void 
115 BL::SalomeGui::onWindowActivated( SUIT_ViewWindow* svw)
116 {
117   DEBTRACE("BL::SalomeGui::onWindowActivated");
118   DEBTRACE("activeModule()->moduleName() " << (getApp()->activeModule() ? getApp()->activeModule()->moduleName().toStdString() : "") );
119   
120   if (_viewWin) // Be sure to have a _viewWindow
121     if (svw->getId() == _viewWin->getId()) // Same Id ?
122       if (!getApp()->activeModule() || getApp()->activeModule()->moduleName() != "JobManager") // JobManager already activated ?
123         if ( !getApp()->activateModule("JobManager") ) return;
124 }
125
126 // --- Export the module
127 extern "C"
128 {
129   JOBMANAGER_EXPORT CAM_Module* createModule()
130   {
131     return new BL::SalomeGui();
132   }
133
134   char* getModuleVersion()
135   {
136       return (char*)JOBMANAGER_VERSION_STR;
137   }
138 }