]> SALOME platform Git repositories - modules/yacs.git/blob - src/salomewrap/SalomeWrap_Module.cxx
Salome HOME
0dab3e2ad31bf43dd1aaa65d055168421c4af288
[modules/yacs.git] / src / salomewrap / SalomeWrap_Module.cxx
1 // Copyright (C) 2006-2012  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.
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   LightApp_Module( name )
44 {
45   _mapOfViewWindow.clear();
46 }
47
48 /*! create a new QxScene_ViewWindow unless the active view is an empty
49  *  QxScene_ViewWindow automatically created when SALOME module is loaded.
50  */
51 QxScene_ViewWindow* SalomeWrap_Module::getNewWindow(QGraphicsScene *scene)
52 {
53   SUIT_ViewManager *svm = 0;
54   if (_mapOfViewWindow.empty()) // --- reuse already created view manager 
55     svm = getApp()->getViewManager(QxScene_Viewer::Type(), true);
56   else
57     svm = getApp()->createViewManager(QxScene_Viewer::Type());
58   SUIT_ViewWindow* svw = svm->getActiveView();
59   QxScene_ViewWindow *aView = 0;
60   QGraphicsScene* existingScene = 0;
61   if (!svw) svw = svm->createViewWindow();
62   if (svw) aView = dynamic_cast<QxScene_ViewWindow*>(svw);
63   if (aView) existingScene = aView->getScene();
64   if (existingScene)
65     {
66       svw = svm->createViewWindow();
67       if (svw) aView = dynamic_cast<QxScene_ViewWindow*>(svw);
68     }
69   YASSERT(aView);
70   aView->setScene(scene);
71   _mapOfViewWindow[scene] = aView;
72   return aView;
73 }
74
75 int SalomeWrap_Module::AssociateViewToWindow(QGraphicsView* gView,
76                                              QxScene_ViewWindow* viewWindow)
77 {
78   viewWindow->setSceneView(gView);
79   viewWindow->setCentralWidget(gView);
80   return viewWindow->getViewManager()->study()->id();
81 }
82
83 int SalomeWrap_Module::activeStudyId()
84 {
85   return getApp()->activeStudy()->id();
86 }
87
88 QDockWidget* SalomeWrap_Module::objectBrowser() {
89   QWidget* wid = getApp()->objectBrowser()->treeView();
90
91   if ( !wid ) {
92     return 0;
93   };
94
95   QDockWidget* dock = 0;
96   QWidget* w = wid->parentWidget();
97   while ( w && !dock ) {
98     dock = ::qobject_cast<QDockWidget*>( w );
99     w = w->parentWidget();
100   };
101
102   return dock;
103 }
104
105
106 QAction* SalomeWrap_Module::wCreateAction(const int id,
107                                           const QString& toolTip,
108                                           const QIcon& icon,
109                                           const QString& menu,
110                                           const QString& status,
111                                           const int shortCut,
112                                           QObject* parent,
113                                           bool checkable,
114                                           QObject* receiver,
115                                           const char* member)
116 {
117   return createAction(id, toolTip, icon, menu, status, shortCut,
118                       parent, checkable, receiver, member);
119 }
120       
121 int SalomeWrap_Module::wCreateMenu(const QString& subMenu,
122                                    const int parentMenuId,
123                                    const int menuId,
124                                    const int groupId,
125                                    const int index)
126 {
127   return createMenu(subMenu, parentMenuId, menuId, groupId, index);
128 }
129
130 int SalomeWrap_Module::wCreateMenu(const QString& subMenu,
131                                    const QString& parentMenu,
132                                    const int menuId,
133                                    const int groupId,
134                                    const int index)
135 {
136   return createMenu(subMenu, parentMenu, menuId, groupId, index);
137 }
138
139 int SalomeWrap_Module::wCreateMenu(const int actionId,
140                                    const int menuId,
141                                    const int groupId,
142                                    const int index)
143 {
144   return createMenu(actionId, menuId, groupId, index);
145 }
146
147 int SalomeWrap_Module:: wCreateMenu(const int actionId,
148                                     const QString& menu,
149                                     const int groupId,
150                                     const int index)
151 {
152   return createMenu(actionId, menu, groupId, index);
153 }
154
155 int SalomeWrap_Module::wCreateMenu(QAction* action,
156                                    const int menuId,
157                                    const int actionId,
158                                    const int groupId,
159                                    const int index)
160 {
161   return createMenu(action, menuId, actionId, groupId, index);
162 }
163
164 int SalomeWrap_Module::wCreateMenu(QAction* action,
165                                    const QString& menu,
166                                    const int actionId,
167                                    const int groupId,
168                                    const int index)
169 {
170   return createMenu(action, menu, actionId, groupId, index);
171 }
172
173 int SalomeWrap_Module::wCreateTool(const QString& name)
174 {
175   return createTool(name);
176 }
177
178 int SalomeWrap_Module::wCreateTool(const int actionId,
179                                    const int toolbarId, 
180                                    const int index)
181 {
182   return createTool(actionId, toolbarId, index);
183 }
184
185 int SalomeWrap_Module::wCreateTool(const int actionId,
186                                    const QString& toolbar,
187                                    const int index)
188 {
189   return createTool(actionId, toolbar, index);
190 }
191
192 int SalomeWrap_Module::wCreateTool(QAction* action, 
193                                    const int toolbarId,
194                                    const int actionId,
195                                    const int index)
196 {
197   return createTool(action, toolbarId, actionId, index);
198 }
199
200 int SalomeWrap_Module::wCreateTool(QAction* action,
201                                    const QString& toolbar,
202                                    const int actionId,
203                                    const int index)
204 {
205   return createTool(action, toolbar, actionId, index);
206 }
207
208 QAction* SalomeWrap_Module::wSeparator()
209 {
210   return separator();
211 }
212
213 SalomeWrap_DataModel* SalomeWrap_Module::getDataModel()
214 {
215   return dynamic_cast<SalomeWrap_DataModel*>(dataModel());
216 }
217
218 CAM_DataModel* SalomeWrap_Module::createDataModel()
219 {
220   return new SalomeWrap_DataModel(this);
221 }