Salome HOME
cd387887f09032a311d4d0188da278a5be813165
[modules/jobmanager.git] / src / wrappers / BL_MainWindows_SALOME.cxx
1 // Copyright (C) 2009-2022  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_MainWindows_SALOME.hxx"
21
22 #include <SalomeApp_Application.h>
23 #include <SalomeApp_Engine_i.h>
24 #include <SUIT_Desktop.h>
25 #include <SUIT_ViewManager.h>
26 #include <SUIT_ViewWindow.h>
27
28 #include <QTextEdit>
29
30 BL::MainWindows_SALOME::MainWindows_SALOME(const QString & module_name) :
31   SalomeApp_Module(module_name)
32 {
33   DEBTRACE("Creating BL::MainWindows_SALOME");
34   _actionId = 190;
35   _currentViewId = -1;
36   _svm = 0;
37 }
38
39 void 
40 BL::MainWindows_SALOME::initialize(SalomeApp_Application * appli)
41 {
42   DEBTRACE("Initialize BL::MainWindows_SALOME");
43   BL_ASSERT(appli);
44   _appli = appli;
45 }
46
47
48 void
49 BL::MainWindows_SALOME::createView()
50 {
51   DEBTRACE("BL::MainWindows_SALOME CreateView");
52   QString vmType = "JobManager View";
53
54   // Get JobManager View Manager
55   _svm = _appli->getViewManager( vmType, true );
56   if (!_svm) {
57     // view manager not found
58     QTextEdit* w = new QTextEdit;
59     _svm = _appli->createViewManager( vmType, w );
60   }
61
62   // Create a view
63   _viewWin = _svm->getActiveView();
64   _viewWin->setClosable( false );
65   _currentViewId = _viewWin->getId();
66   DEBTRACE("End of BL::MainWindows_SALOME CreateView");
67 }
68
69 bool
70 BL::MainWindows_SALOME::restoreViewFocus()
71 {
72   bool result = false;
73   SUIT_ViewWindow* resWnd = 0;
74
75   // Search window
76   QList<SUIT_ViewWindow*> wndlist = _appli->desktop()->windows();
77   SUIT_ViewWindow* wnd;
78   for (int i = 0; i < wndlist.size(); ++i) 
79    {
80     wnd = wndlist.at(i);
81     if (_currentViewId == wnd->getId()) {resWnd = wnd;}
82     if (resWnd) {break;}
83    }
84
85   if (resWnd)
86    {
87     wnd->setFocus();
88     result = true;
89    }
90   return result;
91 }
92
93 QString  
94 BL::MainWindows_SALOME::engineIOR() const
95 {
96   DEBTRACE("Entering in BL::SalomeGui::engineIOR");
97   QString anEngineIOR = SalomeApp_Engine_i::EngineIORForComponent( "JOBMANAGER", true ).c_str();
98   return anEngineIOR;
99 }
100
101 void 
102 BL::MainWindows_SALOME::viewManagers(QStringList& list) const
103 {
104   DEBTRACE("Entering in BL::SalomeGui::viewManagers");
105   if (_svm)
106     list.append(_svm->getType());
107 }
108
109
110 BL::MainWindows_SALOME::~MainWindows_SALOME()
111 {
112   DEBTRACE("Destroying BL::MainWindows_SALOME");
113 }
114
115 QMainWindow * 
116 BL::MainWindows_SALOME::getDockParent()
117 {
118   return _appli->desktop();
119 }
120
121 QMainWindow * 
122 BL::MainWindows_SALOME::getTabParent()
123 {
124   return _viewWin;
125 }
126
127 QAction* 
128 BL::MainWindows_SALOME::createAction(const QString& toolTip,
129                                      const QIcon& icon,
130                                      const QString& menu,
131                                      const QString& status,
132                                      const int accel,
133                                      QObject* parent,
134                                      bool checkable,
135                                      QObject* receiver,
136                                      const char* member,
137                                      const QString & shortCut)
138 {
139   return SalomeApp_Module::createAction(getActionId(), toolTip, icon, menu, status, accel, parent, checkable, receiver, member, shortCut);
140 }
141
142 int
143 BL::MainWindows_SALOME::createTopMenu(const QString & menu_name)
144 {
145   return createMenu(menu_name, -1, -1, 30 );
146 }
147
148 void 
149 BL::MainWindows_SALOME::addActionToMenu(QAction * action, int menu_id)
150 {
151   createMenu(action, menu_id);
152 }