Salome HOME
Revert "Synchronize adm files"
[modules/yacs.git] / src / salomewrap / SuitWrapper.cxx
1 // Copyright (C) 2006-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 /*!
21  *  only one declaration in src/genericgui,
22  *  implementations in salomewrap and standalonegui
23  */
24     
25 #include "SuitWrapper.hxx"
26 #include "WrapGraphicsView.hxx"
27
28 #include "SalomeWrap_Module.hxx"
29 #include "SalomeWrap_DataModel.hxx"
30
31 #include <SalomeApp_Module.h>
32 #include <SalomeApp_Application.h>
33 #include "SUIT_Session.h"
34 #include "SUIT_ResourceMgr.h"
35
36 #include <QxScene_ViewManager.h>
37 #include <QxScene_ViewModel.h>
38 #include <QxScene_ViewWindow.h>
39 #include <QtxActionToolMgr.h>
40
41 #include <cassert>
42
43 //#define _DEVDEBUG_
44 #include "YacsTrace.hxx"
45
46 using namespace std;
47 using namespace YACS::HMI;
48
49 SuitWrapper::SuitWrapper(QObject* wrapped) : _wrapped(wrapped)
50 {
51 }
52
53 SuitWrapper::~SuitWrapper()
54 {
55 }
56
57 QWidget* SuitWrapper::getNewWindow(QGraphicsScene *scene)
58 {
59   SalomeWrap_Module* module = dynamic_cast<SalomeWrap_Module*>(_wrapped);
60   return module->getNewWindow(scene);
61 }
62
63 /*!
64  * return studyId used in context delete when study is closed.
65  */
66 int SuitWrapper::AssociateViewToWindow(QGraphicsView* gView, QWidget* viewWindow)
67 {
68   SalomeWrap_Module* module = dynamic_cast<SalomeWrap_Module*>(_wrapped);
69   QxScene_ViewWindow *svw = dynamic_cast<QxScene_ViewWindow*>(viewWindow);
70   YASSERT(svw);
71   int studyId = module->AssociateViewToWindow(gView, svw);
72   WrapGraphicsView* wgv = dynamic_cast<WrapGraphicsView*>(gView);
73   YASSERT(wgv);
74   QObject::disconnect(svw->toolMgr()->action(QxScene_ViewWindow::FitAllId),
75                       SIGNAL(triggered(bool)),
76                       svw, SLOT(onViewFitAll()));
77   QObject::connect(svw->toolMgr()->action(QxScene_ViewWindow::FitAllId),
78                    SIGNAL(triggered(bool)),
79                    wgv, SLOT(onViewFitAll()));
80
81   QObject::disconnect(svw->toolMgr()->action(QxScene_ViewWindow::FitRectId),
82                       SIGNAL(triggered(bool)),
83                       svw, SLOT(onViewFitArea()));
84   QObject::connect(svw->toolMgr()->action(QxScene_ViewWindow::FitRectId),
85                    SIGNAL(triggered(bool)),
86                    wgv, SLOT(onViewFitArea()));
87
88   QObject::disconnect(svw->toolMgr()->action(QxScene_ViewWindow::ZoomId),
89                       SIGNAL(triggered(bool)),
90                       svw, SLOT(onViewZoom()));
91   QObject::connect(svw->toolMgr()->action(QxScene_ViewWindow::ZoomId),
92                    SIGNAL(triggered(bool)),
93                    wgv, SLOT(onViewZoom()));
94
95   QObject::disconnect(svw->toolMgr()->action(QxScene_ViewWindow::PanId),
96                       SIGNAL(triggered(bool)),
97                       svw, SLOT(onViewPan()));
98   QObject::connect(svw->toolMgr()->action(QxScene_ViewWindow::PanId),
99                    SIGNAL(triggered(bool)),
100                    wgv, SLOT(onViewPan()));
101
102   QObject::disconnect(svw->toolMgr()->action(QxScene_ViewWindow::GlobalPanId),
103                       SIGNAL(triggered(bool)),
104                       svw, SLOT(onViewGlobalPan()));
105   QObject::connect(svw->toolMgr()->action(QxScene_ViewWindow::GlobalPanId),
106                    SIGNAL(triggered(bool)),
107                    wgv, SLOT(onViewGlobalPan()));
108
109   QObject::disconnect(svw->toolMgr()->action(QxScene_ViewWindow::ResetId),
110                       SIGNAL(triggered(bool)),
111                       svw, SLOT(onViewReset()));
112   QObject::connect(svw->toolMgr()->action(QxScene_ViewWindow::ResetId),
113                    SIGNAL(triggered(bool)),
114                    wgv, SLOT(onViewReset()));
115   return studyId;
116 }
117
118 int SuitWrapper::activeStudyId()
119 {
120   SalomeWrap_Module* module = dynamic_cast<SalomeWrap_Module*>(_wrapped);
121   return module->activeStudyId();
122 }
123
124 QDockWidget* SuitWrapper::objectBrowser()
125 {
126   SalomeWrap_Module* module = dynamic_cast<SalomeWrap_Module*>(_wrapped);
127   return module->objectBrowser();
128 }
129
130 QAction* SuitWrapper::createAction(const int id,
131                                     const QString& toolTip,
132                                     const QIcon& icon,
133                                     const QString& menu,
134                                     const QString& status,
135                                     const int shortCut,
136                                     QObject* parent,
137                                     bool checkable,
138                                     QObject* receiver,
139                                     const char* member)
140 {
141   SalomeWrap_Module* module = dynamic_cast<SalomeWrap_Module*>(_wrapped);
142   return module->wCreateAction(id, toolTip, icon, menu, status, shortCut,
143                                parent, checkable, receiver, member);
144 }
145       
146 int SuitWrapper::createMenu(const QString& subMenu,
147                              const int parentMenuId,
148                              const int menuId,
149                              const int groupId,
150                              const int index)
151 {
152   SalomeWrap_Module* module = dynamic_cast<SalomeWrap_Module*>(_wrapped);
153   return module->wCreateMenu(subMenu, parentMenuId, menuId, groupId, index);
154 }
155
156 int SuitWrapper::createMenu(const QString& subMenu,
157                              const QString& parentMenu,
158                              const int menuId,
159                              const int groupId,
160                              const int index)
161 {
162   SalomeWrap_Module* module = dynamic_cast<SalomeWrap_Module*>(_wrapped);
163   return module->wCreateMenu(subMenu, parentMenu, menuId, groupId, index);
164 }
165
166 int SuitWrapper::createMenu(const int actionId,
167                              const int menuId,
168                              const int groupId,
169                              const int index)
170 {
171   SalomeWrap_Module* module = dynamic_cast<SalomeWrap_Module*>(_wrapped);
172   return module->wCreateMenu(actionId, menuId, groupId, index);
173 }
174
175 int SuitWrapper:: createMenu(const int actionId,
176                              const QString& menu,
177                              const int groupId,
178                              const int index)
179 {
180   SalomeWrap_Module* module = dynamic_cast<SalomeWrap_Module*>(_wrapped);
181   return module->wCreateMenu(actionId, menu, groupId, index);
182 }
183
184 int SuitWrapper::createMenu(QAction* action,
185                              const int menuId,
186                              const int actionId,
187                              const int groupId,
188                              const int index)
189 {
190   SalomeWrap_Module* module = dynamic_cast<SalomeWrap_Module*>(_wrapped);
191   return module->wCreateMenu(action, menuId, actionId, groupId, index);
192 }
193
194 int SuitWrapper::createMenu(QAction* action,
195                              const QString& menu,
196                              const int actionId,
197                              const int groupId,
198                              const int index)
199 {
200   SalomeWrap_Module* module = dynamic_cast<SalomeWrap_Module*>(_wrapped);
201   return module->wCreateMenu(action, menu, actionId, groupId, index);
202 }
203
204 int SuitWrapper::createTool(const QString& name)
205 {
206   SalomeWrap_Module* module = dynamic_cast<SalomeWrap_Module*>(_wrapped);
207   return module->wCreateTool(name);
208 }
209
210 int SuitWrapper::createTool(const int actionId,
211                              const int toolbarId, 
212                              const int index)
213 {
214   SalomeWrap_Module* module = dynamic_cast<SalomeWrap_Module*>(_wrapped);
215   return module->wCreateTool(actionId, toolbarId, index);
216 }
217
218 int SuitWrapper::createTool(const int actionId,
219                              const QString& toolbar,
220                              const int index)
221 {
222   SalomeWrap_Module* module = dynamic_cast<SalomeWrap_Module*>(_wrapped);
223   return module->wCreateTool(actionId, toolbar, index);
224 }
225
226 int SuitWrapper::createTool(QAction* action, 
227                              const int toolbarId,
228                              const int actionId,
229                              const int index)
230 {
231   SalomeWrap_Module* module = dynamic_cast<SalomeWrap_Module*>(_wrapped);
232   return module->wCreateTool(action, toolbarId, actionId, index);
233 }
234
235 int SuitWrapper::createTool(QAction* action,
236                              const QString& toolbar,
237                              const int actionId,
238                              const int index)
239 {
240   SalomeWrap_Module* module = dynamic_cast<SalomeWrap_Module*>(_wrapped);
241   return module->wCreateTool(action, toolbar, actionId, index);
242 }
243
244 QAction* SuitWrapper::separator()
245 {
246   return SalomeWrap_Module::wSeparator();
247 }
248
249 void SuitWrapper::setMenuShown(QAction* act, bool show)
250 {
251   SalomeWrap_Module* module = dynamic_cast<SalomeWrap_Module*>(_wrapped);
252   module->setMenuShown(act, show);
253 }
254
255 void SuitWrapper::setToolShown(QAction* act, bool show)
256 {
257   SalomeWrap_Module* module = dynamic_cast<SalomeWrap_Module*>(_wrapped);
258   module->setToolShown(act, show);
259 }
260
261 void SuitWrapper::createNewSchema(const QString& schemaName,
262                                   QWidget* viewWindow)
263 {
264   SalomeWrap_Module* module = dynamic_cast<SalomeWrap_Module*>(_wrapped);
265   module->getDataModel()->createNewSchema(schemaName, viewWindow);
266 }
267
268 bool SuitWrapper::renameSchema(const QString& oldName,
269                                const QString& newName,
270                                QWidget* viewWindow)
271 {
272   SalomeWrap_Module* module = dynamic_cast<SalomeWrap_Module*>(_wrapped);
273   return module->getDataModel()->renameSchema(oldName, newName, viewWindow);
274 }
275
276 bool SuitWrapper::deleteSchema(QWidget* viewWindow)
277 {
278   SalomeWrap_Module* module = dynamic_cast<SalomeWrap_Module*>(_wrapped);
279   return module->getDataModel()->deleteSchema(viewWindow);
280 }
281
282 void SuitWrapper::createNewRun(const QString& schemaName,
283                                const QString& runName,
284                                QWidget* refWindow,
285                                QWidget* viewWindow)
286 {
287   SalomeWrap_Module* module = dynamic_cast<SalomeWrap_Module*>(_wrapped);
288   module->getDataModel()->createNewRun(schemaName, runName, refWindow, viewWindow);
289 }
290
291 QStringList SuitWrapper::getQuickDirList()
292 {
293   QStringList dirList;
294   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
295   if ( resMgr )
296     dirList = resMgr->stringValue( "FileDlg", "QuickDirList" ).split( ';', QString::SkipEmptyParts );
297   return dirList;
298 }
299
300 void SuitWrapper::onHelpContextModule( const QString& theComponentName, const QString& theFileName, const QString& theContext )
301 {
302   LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
303   if(app)
304     app->onHelpContextModule( theComponentName, theFileName, theContext );
305 }
306