Salome HOME
Return deleted code.
[modules/yacs.git] / src / salomewrap / SuitWrapper.cxx
1 // Copyright (C) 2006-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 /*!
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 void 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   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 }
116
117 QDockWidget* SuitWrapper::objectBrowser()
118 {
119   SalomeWrap_Module* module = dynamic_cast<SalomeWrap_Module*>(_wrapped);
120   return module->objectBrowser();
121 }
122
123 QAction* SuitWrapper::createAction(const int id,
124                                     const QString& toolTip,
125                                     const QIcon& icon,
126                                     const QString& menu,
127                                     const QString& status,
128                                     const int shortCut,
129                                     QObject* parent,
130                                     bool checkable,
131                                     QObject* receiver,
132                                     const char* member)
133 {
134   SalomeWrap_Module* module = dynamic_cast<SalomeWrap_Module*>(_wrapped);
135   return module->wCreateAction(id, toolTip, icon, menu, status, shortCut,
136                                parent, checkable, receiver, member);
137 }
138       
139 int SuitWrapper::createMenu(const QString& subMenu,
140                              const int parentMenuId,
141                              const int menuId,
142                              const int groupId,
143                              const int index)
144 {
145   SalomeWrap_Module* module = dynamic_cast<SalomeWrap_Module*>(_wrapped);
146   return module->wCreateMenu(subMenu, parentMenuId, menuId, groupId, index);
147 }
148
149 int SuitWrapper::createMenu(const QString& subMenu,
150                              const QString& parentMenu,
151                              const int menuId,
152                              const int groupId,
153                              const int index)
154 {
155   SalomeWrap_Module* module = dynamic_cast<SalomeWrap_Module*>(_wrapped);
156   return module->wCreateMenu(subMenu, parentMenu, menuId, groupId, index);
157 }
158
159 int SuitWrapper::createMenu(const int actionId,
160                              const int menuId,
161                              const int groupId,
162                              const int index)
163 {
164   SalomeWrap_Module* module = dynamic_cast<SalomeWrap_Module*>(_wrapped);
165   return module->wCreateMenu(actionId, menuId, groupId, index);
166 }
167
168 int SuitWrapper:: createMenu(const int actionId,
169                              const QString& menu,
170                              const int groupId,
171                              const int index)
172 {
173   SalomeWrap_Module* module = dynamic_cast<SalomeWrap_Module*>(_wrapped);
174   return module->wCreateMenu(actionId, menu, groupId, index);
175 }
176
177 int SuitWrapper::createMenu(QAction* action,
178                              const int menuId,
179                              const int actionId,
180                              const int groupId,
181                              const int index)
182 {
183   SalomeWrap_Module* module = dynamic_cast<SalomeWrap_Module*>(_wrapped);
184   return module->wCreateMenu(action, menuId, actionId, groupId, index);
185 }
186
187 int SuitWrapper::createMenu(QAction* action,
188                              const QString& menu,
189                              const int actionId,
190                              const int groupId,
191                              const int index)
192 {
193   SalomeWrap_Module* module = dynamic_cast<SalomeWrap_Module*>(_wrapped);
194   return module->wCreateMenu(action, menu, actionId, groupId, index);
195 }
196
197 int SuitWrapper::createTool(const QString& title, const QString& name)
198 {
199   SalomeWrap_Module* module = dynamic_cast<SalomeWrap_Module*>(_wrapped);
200   return module->wCreateTool(title, name);
201 }
202
203 int SuitWrapper::createTool(const int actionId,
204                              const int toolbarId, 
205                              const int index)
206 {
207   SalomeWrap_Module* module = dynamic_cast<SalomeWrap_Module*>(_wrapped);
208   return module->wCreateTool(actionId, toolbarId, index);
209 }
210
211 int SuitWrapper::createTool(const int actionId,
212                              const QString& toolbar,
213                              const int index)
214 {
215   SalomeWrap_Module* module = dynamic_cast<SalomeWrap_Module*>(_wrapped);
216   return module->wCreateTool(actionId, toolbar, index);
217 }
218
219 int SuitWrapper::createTool(QAction* action, 
220                              const int toolbarId,
221                              const int actionId,
222                              const int index)
223 {
224   SalomeWrap_Module* module = dynamic_cast<SalomeWrap_Module*>(_wrapped);
225   return module->wCreateTool(action, toolbarId, actionId, index);
226 }
227
228 int SuitWrapper::createTool(QAction* action,
229                              const QString& toolbar,
230                              const int actionId,
231                              const int index)
232 {
233   SalomeWrap_Module* module = dynamic_cast<SalomeWrap_Module*>(_wrapped);
234   return module->wCreateTool(action, toolbar, actionId, index);
235 }
236
237 QAction* SuitWrapper::separator()
238 {
239   return SalomeWrap_Module::wSeparator();
240 }
241
242 void SuitWrapper::setMenuShown(QAction* act, bool show)
243 {
244   SalomeWrap_Module* module = dynamic_cast<SalomeWrap_Module*>(_wrapped);
245   module->setMenuShown(act, show);
246 }
247
248 void SuitWrapper::setToolShown(QAction* act, bool show)
249 {
250   SalomeWrap_Module* module = dynamic_cast<SalomeWrap_Module*>(_wrapped);
251   module->setToolShown(act, show);
252 }
253
254 void SuitWrapper::createNewSchema(const QString& schemaName,
255                                   QWidget* viewWindow)
256 {
257   SalomeWrap_Module* module = dynamic_cast<SalomeWrap_Module*>(_wrapped);
258   module->getDataModel()->createNewSchema(schemaName, viewWindow);
259 }
260
261 bool SuitWrapper::renameSchema(const QString& oldName,
262                                const QString& newName,
263                                QWidget* viewWindow)
264 {
265   SalomeWrap_Module* module = dynamic_cast<SalomeWrap_Module*>(_wrapped);
266   return module->getDataModel()->renameSchema(oldName, newName, viewWindow);
267 }
268
269 bool SuitWrapper::deleteSchema(QWidget* viewWindow)
270 {
271   SalomeWrap_Module* module = dynamic_cast<SalomeWrap_Module*>(_wrapped);
272   return module->getDataModel()->deleteSchema(viewWindow);
273 }
274
275 void SuitWrapper::createNewRun(const QString& schemaName,
276                                const QString& runName,
277                                QWidget* refWindow,
278                                QWidget* viewWindow)
279 {
280   SalomeWrap_Module* module = dynamic_cast<SalomeWrap_Module*>(_wrapped);
281   module->getDataModel()->createNewRun(schemaName, runName, refWindow, viewWindow);
282 }
283
284 QStringList SuitWrapper::getQuickDirList()
285 {
286   QStringList dirList;
287   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
288   if ( resMgr )
289     dirList = resMgr->stringValue( "FileDlg", "QuickDirList" ).split( ';', QString::SkipEmptyParts );
290   return dirList;
291 }
292
293 void SuitWrapper::onHelpContextModule( const QString& theComponentName, const QString& theFileName, const QString& theContext )
294 {
295   LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
296   if(app)
297     app->onHelpContextModule( theComponentName, theFileName, theContext );
298 }
299