Salome HOME
0023299: [CEA] Finalize multi-study removal
[modules/yacs.git] / src / salomewrap / SalomeWrap_Module.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 #include "SalomeWrap_Module.hxx"
21 #include "SalomeWrap_DataModel.hxx"
22
23 #include <SalomeApp_Application.h>
24 #include <QxScene_ViewManager.h>
25 #include <QxScene_ViewModel.h>
26 #include <QxScene_ViewWindow.h>
27 #include <CAM_DataModel.h>
28 #include <SUIT_Study.h>
29
30 #include <SUIT_DataBrowser.h>
31 #include <QtxTreeView.h>
32 #include <SUIT_DataObject.h>
33
34 #include <cassert>
35
36 //#define _DEVDEBUG_
37 #include "YacsTrace.hxx"
38
39 using namespace std;
40
41 SalomeWrap_Module::SalomeWrap_Module(const char* name) :
42   SalomeApp_Module( name )
43 {
44   _mapOfViewWindow.clear();
45 }
46
47 /*! create a new QxScene_ViewWindow unless the active view is an empty
48  *  QxScene_ViewWindow automatically created when SALOME module is loaded.
49  */
50 QxScene_ViewWindow* SalomeWrap_Module::getNewWindow(QGraphicsScene *scene)
51 {
52   SUIT_ViewManager *svm = 0;
53   if (_mapOfViewWindow.empty()) // --- reuse already created view manager 
54     svm = getApp()->getViewManager(QxScene_Viewer::Type(), true);
55   else
56     svm = getApp()->createViewManager(QxScene_Viewer::Type());
57   SUIT_ViewWindow* svw = svm->getActiveView();
58   QxScene_ViewWindow *aView = 0;
59   QGraphicsScene* existingScene = 0;
60   if (!svw) svw = svm->createViewWindow();
61   if (svw) aView = dynamic_cast<QxScene_ViewWindow*>(svw);
62   if (aView) existingScene = aView->getScene();
63   if (existingScene)
64     {
65       svw = svm->createViewWindow();
66       if (svw) aView = dynamic_cast<QxScene_ViewWindow*>(svw);
67     }
68   YASSERT(aView);
69   aView->setScene(scene);
70   _mapOfViewWindow[scene] = aView;
71   return aView;
72 }
73
74 QDockWidget* SalomeWrap_Module::objectBrowser() {
75   if ( !getApp()->objectBrowser() )
76     return 0;
77
78   QWidget* wid = getApp()->objectBrowser()->treeView();
79
80   if ( !wid ) {
81     return 0;
82   };
83
84   QDockWidget* dock = 0;
85   QWidget* w = wid->parentWidget();
86   while ( w && !dock ) {
87     dock = ::qobject_cast<QDockWidget*>( w );
88     w = w->parentWidget();
89   };
90
91   return dock;
92 }
93
94
95 QAction* SalomeWrap_Module::wCreateAction(const int id,
96                                           const QString& toolTip,
97                                           const QIcon& icon,
98                                           const QString& menu,
99                                           const QString& status,
100                                           const int shortCut,
101                                           QObject* parent,
102                                           bool checkable,
103                                           QObject* receiver,
104                                           const char* member)
105 {
106   return createAction(id, toolTip, icon, menu, status, shortCut,
107                       parent, checkable, receiver, member);
108 }
109       
110 int SalomeWrap_Module::wCreateMenu(const QString& subMenu,
111                                    const int parentMenuId,
112                                    const int menuId,
113                                    const int groupId,
114                                    const int index)
115 {
116   return createMenu(subMenu, parentMenuId, menuId, groupId, index);
117 }
118
119 int SalomeWrap_Module::wCreateMenu(const QString& subMenu,
120                                    const QString& parentMenu,
121                                    const int menuId,
122                                    const int groupId,
123                                    const int index)
124 {
125   return createMenu(subMenu, parentMenu, menuId, groupId, index);
126 }
127
128 int SalomeWrap_Module::wCreateMenu(const int actionId,
129                                    const int menuId,
130                                    const int groupId,
131                                    const int index)
132 {
133   return createMenu(actionId, menuId, groupId, index);
134 }
135
136 int SalomeWrap_Module:: wCreateMenu(const int actionId,
137                                     const QString& menu,
138                                     const int groupId,
139                                     const int index)
140 {
141   return createMenu(actionId, menu, groupId, index);
142 }
143
144 int SalomeWrap_Module::wCreateMenu(QAction* action,
145                                    const int menuId,
146                                    const int actionId,
147                                    const int groupId,
148                                    const int index)
149 {
150   return createMenu(action, menuId, actionId, groupId, index);
151 }
152
153 int SalomeWrap_Module::wCreateMenu(QAction* action,
154                                    const QString& menu,
155                                    const int actionId,
156                                    const int groupId,
157                                    const int index)
158 {
159   return createMenu(action, menu, actionId, groupId, index);
160 }
161
162 int SalomeWrap_Module::wCreateTool(const QString& title, const QString& name)
163 {
164   return createTool(title, name);
165 }
166
167 int SalomeWrap_Module::wCreateTool(const int actionId,
168                                    const int toolbarId, 
169                                    const int index)
170 {
171   return createTool(actionId, toolbarId, index);
172 }
173
174 int SalomeWrap_Module::wCreateTool(const int actionId,
175                                    const QString& toolbar,
176                                    const int index)
177 {
178   return createTool(actionId, toolbar, index);
179 }
180
181 int SalomeWrap_Module::wCreateTool(QAction* action, 
182                                    const int toolbarId,
183                                    const int actionId,
184                                    const int index)
185 {
186   return createTool(action, toolbarId, actionId, index);
187 }
188
189 int SalomeWrap_Module::wCreateTool(QAction* action,
190                                    const QString& toolbar,
191                                    const int actionId,
192                                    const int index)
193 {
194   return createTool(action, toolbar, actionId, index);
195 }
196
197 QAction* SalomeWrap_Module::wSeparator()
198 {
199   return separator();
200 }
201
202 SalomeWrap_DataModel* SalomeWrap_Module::getDataModel()
203 {
204   return dynamic_cast<SalomeWrap_DataModel*>(dataModel());
205 }
206
207 CAM_DataModel* SalomeWrap_Module::createDataModel()
208 {
209   return new SalomeWrap_DataModel(this);
210 }