Salome HOME
Update copyrights 2014.
[modules/yacs.git] / src / salomewrap / SalomeWrap_Module.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 #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 int SalomeWrap_Module::AssociateViewToWindow(QGraphicsView* gView,
75                                              QxScene_ViewWindow* viewWindow)
76 {
77   viewWindow->setSceneView(gView);
78   viewWindow->setCentralWidget(gView);
79   return viewWindow->getViewManager()->study()->id();
80 }
81
82 int SalomeWrap_Module::activeStudyId()
83 {
84   return getApp()->activeStudy()->id();
85 }
86
87 QDockWidget* SalomeWrap_Module::objectBrowser() {
88   QWidget* wid = getApp()->objectBrowser()->treeView();
89
90   if ( !wid ) {
91     return 0;
92   };
93
94   QDockWidget* dock = 0;
95   QWidget* w = wid->parentWidget();
96   while ( w && !dock ) {
97     dock = ::qobject_cast<QDockWidget*>( w );
98     w = w->parentWidget();
99   };
100
101   return dock;
102 }
103
104
105 QAction* SalomeWrap_Module::wCreateAction(const int id,
106                                           const QString& toolTip,
107                                           const QIcon& icon,
108                                           const QString& menu,
109                                           const QString& status,
110                                           const int shortCut,
111                                           QObject* parent,
112                                           bool checkable,
113                                           QObject* receiver,
114                                           const char* member)
115 {
116   return createAction(id, toolTip, icon, menu, status, shortCut,
117                       parent, checkable, receiver, member);
118 }
119       
120 int SalomeWrap_Module::wCreateMenu(const QString& subMenu,
121                                    const int parentMenuId,
122                                    const int menuId,
123                                    const int groupId,
124                                    const int index)
125 {
126   return createMenu(subMenu, parentMenuId, menuId, groupId, index);
127 }
128
129 int SalomeWrap_Module::wCreateMenu(const QString& subMenu,
130                                    const QString& parentMenu,
131                                    const int menuId,
132                                    const int groupId,
133                                    const int index)
134 {
135   return createMenu(subMenu, parentMenu, menuId, groupId, index);
136 }
137
138 int SalomeWrap_Module::wCreateMenu(const int actionId,
139                                    const int menuId,
140                                    const int groupId,
141                                    const int index)
142 {
143   return createMenu(actionId, menuId, groupId, index);
144 }
145
146 int SalomeWrap_Module:: wCreateMenu(const int actionId,
147                                     const QString& menu,
148                                     const int groupId,
149                                     const int index)
150 {
151   return createMenu(actionId, menu, groupId, index);
152 }
153
154 int SalomeWrap_Module::wCreateMenu(QAction* action,
155                                    const int menuId,
156                                    const int actionId,
157                                    const int groupId,
158                                    const int index)
159 {
160   return createMenu(action, menuId, actionId, groupId, index);
161 }
162
163 int SalomeWrap_Module::wCreateMenu(QAction* action,
164                                    const QString& menu,
165                                    const int actionId,
166                                    const int groupId,
167                                    const int index)
168 {
169   return createMenu(action, menu, actionId, groupId, index);
170 }
171
172 int SalomeWrap_Module::wCreateTool(const QString& name)
173 {
174   return createTool(name);
175 }
176
177 int SalomeWrap_Module::wCreateTool(const int actionId,
178                                    const int toolbarId, 
179                                    const int index)
180 {
181   return createTool(actionId, toolbarId, index);
182 }
183
184 int SalomeWrap_Module::wCreateTool(const int actionId,
185                                    const QString& toolbar,
186                                    const int index)
187 {
188   return createTool(actionId, toolbar, index);
189 }
190
191 int SalomeWrap_Module::wCreateTool(QAction* action, 
192                                    const int toolbarId,
193                                    const int actionId,
194                                    const int index)
195 {
196   return createTool(action, toolbarId, actionId, index);
197 }
198
199 int SalomeWrap_Module::wCreateTool(QAction* action,
200                                    const QString& toolbar,
201                                    const int actionId,
202                                    const int index)
203 {
204   return createTool(action, toolbar, actionId, index);
205 }
206
207 QAction* SalomeWrap_Module::wSeparator()
208 {
209   return separator();
210 }
211
212 SalomeWrap_DataModel* SalomeWrap_Module::getDataModel()
213 {
214   return dynamic_cast<SalomeWrap_DataModel*>(dataModel());
215 }
216
217 CAM_DataModel* SalomeWrap_Module::createDataModel()
218 {
219   return new SalomeWrap_DataModel(this);
220 }