1 // Copyright (C) 2006-2012 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "SalomeWrap_Module.hxx"
21 #include "SalomeWrap_DataModel.hxx"
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>
30 #include <SUIT_DataBrowser.h>
31 #include <QtxTreeView.h>
32 #include <SUIT_DataObject.h>
37 #include "YacsTrace.hxx"
41 SalomeWrap_Module::SalomeWrap_Module(const char* name) :
42 SalomeApp_Module( name ),
43 LightApp_Module( name )
45 _mapOfViewWindow.clear();
48 /*! create a new QxScene_ViewWindow unless the active view is an empty
49 * QxScene_ViewWindow automatically created when SALOME module is loaded.
51 QxScene_ViewWindow* SalomeWrap_Module::getNewWindow(QGraphicsScene *scene)
53 SUIT_ViewManager *svm = 0;
54 if (_mapOfViewWindow.empty()) // --- reuse already created view manager
55 svm = getApp()->getViewManager(QxScene_Viewer::Type(), true);
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();
66 svw = svm->createViewWindow();
67 if (svw) aView = dynamic_cast<QxScene_ViewWindow*>(svw);
70 aView->setScene(scene);
71 _mapOfViewWindow[scene] = aView;
75 int SalomeWrap_Module::AssociateViewToWindow(QGraphicsView* gView,
76 QxScene_ViewWindow* viewWindow)
78 viewWindow->setSceneView(gView);
79 viewWindow->setCentralWidget(gView);
80 return viewWindow->getViewManager()->study()->id();
83 int SalomeWrap_Module::activeStudyId()
85 return getApp()->activeStudy()->id();
88 QDockWidget* SalomeWrap_Module::objectBrowser() {
89 QWidget* wid = getApp()->objectBrowser()->treeView();
95 QDockWidget* dock = 0;
96 QWidget* w = wid->parentWidget();
97 while ( w && !dock ) {
98 dock = ::qobject_cast<QDockWidget*>( w );
99 w = w->parentWidget();
106 QAction* SalomeWrap_Module::wCreateAction(const int id,
107 const QString& toolTip,
110 const QString& status,
117 return createAction(id, toolTip, icon, menu, status, shortCut,
118 parent, checkable, receiver, member);
121 int SalomeWrap_Module::wCreateMenu(const QString& subMenu,
122 const int parentMenuId,
127 return createMenu(subMenu, parentMenuId, menuId, groupId, index);
130 int SalomeWrap_Module::wCreateMenu(const QString& subMenu,
131 const QString& parentMenu,
136 return createMenu(subMenu, parentMenu, menuId, groupId, index);
139 int SalomeWrap_Module::wCreateMenu(const int actionId,
144 return createMenu(actionId, menuId, groupId, index);
147 int SalomeWrap_Module:: wCreateMenu(const int actionId,
152 return createMenu(actionId, menu, groupId, index);
155 int SalomeWrap_Module::wCreateMenu(QAction* action,
161 return createMenu(action, menuId, actionId, groupId, index);
164 int SalomeWrap_Module::wCreateMenu(QAction* action,
170 return createMenu(action, menu, actionId, groupId, index);
173 int SalomeWrap_Module::wCreateTool(const QString& name)
175 return createTool(name);
178 int SalomeWrap_Module::wCreateTool(const int actionId,
182 return createTool(actionId, toolbarId, index);
185 int SalomeWrap_Module::wCreateTool(const int actionId,
186 const QString& toolbar,
189 return createTool(actionId, toolbar, index);
192 int SalomeWrap_Module::wCreateTool(QAction* action,
197 return createTool(action, toolbarId, actionId, index);
200 int SalomeWrap_Module::wCreateTool(QAction* action,
201 const QString& toolbar,
205 return createTool(action, toolbar, actionId, index);
208 QAction* SalomeWrap_Module::wSeparator()
213 SalomeWrap_DataModel* SalomeWrap_Module::getDataModel()
215 return dynamic_cast<SalomeWrap_DataModel*>(dataModel());
218 CAM_DataModel* SalomeWrap_Module::createDataModel()
220 return new SalomeWrap_DataModel(this);