Salome HOME
0bd4106a1a2618ed8e8b8484ff48551be36e623e
[modules/jobmanager.git] / src / salomegui / BL_SalomeGui.cxx
1 // Copyright (C) 2009-2016  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 #include <SUIT_Desktop.h>
24 #include <SUIT_ViewWindow.h>
25
26 BL::SalomeGui::SalomeGui() : MainWindows_SALOME("JobManager")
27 {
28   DEBTRACE("Creating BL::SalomeGui");
29   _gengui = NULL;
30 }
31
32 BL::SalomeGui::~SalomeGui()
33 {
34   DEBTRACE("Destroying BL::SalomeGui");
35   if (getApp())
36     disconnect(getApp(), SIGNAL(studyClosed()), this, SLOT(studyClosed()));
37   if (_gengui)
38     delete _gengui;
39 }
40
41 void 
42 BL::SalomeGui::initialize(CAM_Application* app)
43 {
44    DEBTRACE("Entering in initialize");
45    SalomeApp_Module::initialize(app); // MANDATORY -> Otherwise SISEGV...
46    connect( getApp(), SIGNAL(studyClosed()), this, SLOT(studyClosed()));
47    if ( app && app->desktop() )
48      connect( app->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
49               this, SLOT(onWindowActivated( SUIT_ViewWindow* )) );
50 }
51
52 void
53 BL::SalomeGui::studyClosed()
54 {
55   if (_gengui)
56   {
57     _gengui->deleteDockWidget();
58     delete _gengui;
59     _gengui = NULL;
60     _viewWin = NULL;
61   }
62 }
63
64 bool 
65 BL::SalomeGui::activateModule(SUIT_Study* theStudy)
66 {
67   DEBTRACE("Entering in BL::SalomeGui::activateModule");
68
69   if (!_gengui)
70   {
71    BL::MainWindows_SALOME::initialize(getApp());
72    BL::MainWindows_SALOME::createView();
73    _gengui = new BL::GenericGui(this);
74
75    _gengui->createDockWidgets();
76    _gengui->createCentralWidget();
77    _gengui->createActions();
78    _gengui->createMenus();
79    _gengui->updateButtonsStates();
80   }
81   else
82    {
83     // Test main view
84     if (!BL::MainWindows_SALOME::restoreViewFocus())
85      {
86       // We need to recreate QT objects and the view
87       BL::MainWindows_SALOME::createView();
88       _gengui->createCentralWidget();
89      }
90    }
91
92   setMenuShown(true);
93   _gengui->showDockWidgets(true);
94   bool bOk = SalomeApp_Module::activateModule(theStudy);
95   return bOk;
96 }
97
98 void 
99 BL::SalomeGui::windows(QMap<int, int>& theMap) const
100 {
101   DEBTRACE("Entering in BL::SalomeGui::windows");
102   theMap.clear();
103   theMap.insert(SalomeApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea);
104 }
105
106 bool 
107 BL::SalomeGui::deactivateModule(SUIT_Study* theStudy)
108 {
109   DEBTRACE("Entering in BL::SalomeGui::deactivateModule");
110   setMenuShown(false);
111   if (_gengui)
112     _gengui->showDockWidgets(false);
113   bool bOk = SalomeApp_Module::deactivateModule(theStudy);
114   return bOk;
115 }
116
117 void 
118 BL::SalomeGui::onWindowActivated( SUIT_ViewWindow* svw)
119 {
120   DEBTRACE("BL::SalomeGui::onWindowActivated");
121   DEBTRACE("activeModule()->moduleName() " << (getApp()->activeModule() ? getApp()->activeModule()->moduleName().toStdString() : "") );
122   
123   if (_viewWin) // Be sure to have a _viewWindow
124     if (svw->getId() == _viewWin->getId()) // Same Id ?
125       if (!getApp()->activeModule() || getApp()->activeModule()->moduleName() != "JobManager") // JobManager already activated ?
126         if ( !getApp()->activateModule("JobManager") ) return;
127 }
128
129 // --- Export the module
130 extern "C"
131 {
132   JOBMANAGER_EXPORT CAM_Module* createModule()
133   {
134     return new BL::SalomeGui();
135   }
136
137   char* getModuleVersion()
138   {
139       return (char*)JOBMANAGER_VERSION_STR;
140   }
141 }