1 // Copyright (C) 2006-2016 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, or (at your option) any later version.
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 )
44 _mapOfViewWindow.clear();
47 /*! create a new QxScene_ViewWindow unless the active view is an empty
48 * QxScene_ViewWindow automatically created when SALOME module is loaded.
50 QxScene_ViewWindow* SalomeWrap_Module::getNewWindow(QGraphicsScene *scene)
52 SUIT_ViewManager *svm = 0;
53 if (_mapOfViewWindow.empty()) // --- reuse already created view manager
54 svm = getApp()->getViewManager(QxScene_Viewer::Type(), true);
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();
65 svw = svm->createViewWindow();
66 if (svw) aView = dynamic_cast<QxScene_ViewWindow*>(svw);
69 aView->setScene(scene);
70 _mapOfViewWindow[scene] = aView;
74 int SalomeWrap_Module::AssociateViewToWindow(QGraphicsView* gView,
75 QxScene_ViewWindow* viewWindow)
77 viewWindow->setSceneView(gView);
78 viewWindow->setCentralWidget(gView);
79 return viewWindow->getViewManager()->study()->id();
82 int SalomeWrap_Module::activeStudyId()
84 return getApp()->activeStudy()->id();
87 QDockWidget* SalomeWrap_Module::objectBrowser() {
88 if ( !getApp()->objectBrowser() )
91 QWidget* wid = getApp()->objectBrowser()->treeView();
97 QDockWidget* dock = 0;
98 QWidget* w = wid->parentWidget();
99 while ( w && !dock ) {
100 dock = ::qobject_cast<QDockWidget*>( w );
101 w = w->parentWidget();
108 QAction* SalomeWrap_Module::wCreateAction(const int id,
109 const QString& toolTip,
112 const QString& status,
119 return createAction(id, toolTip, icon, menu, status, shortCut,
120 parent, checkable, receiver, member);
123 int SalomeWrap_Module::wCreateMenu(const QString& subMenu,
124 const int parentMenuId,
129 return createMenu(subMenu, parentMenuId, menuId, groupId, index);
132 int SalomeWrap_Module::wCreateMenu(const QString& subMenu,
133 const QString& parentMenu,
138 return createMenu(subMenu, parentMenu, menuId, groupId, index);
141 int SalomeWrap_Module::wCreateMenu(const int actionId,
146 return createMenu(actionId, menuId, groupId, index);
149 int SalomeWrap_Module:: wCreateMenu(const int actionId,
154 return createMenu(actionId, menu, groupId, index);
157 int SalomeWrap_Module::wCreateMenu(QAction* action,
163 return createMenu(action, menuId, actionId, groupId, index);
166 int SalomeWrap_Module::wCreateMenu(QAction* action,
172 return createMenu(action, menu, actionId, groupId, index);
175 int SalomeWrap_Module::wCreateTool(const QString& title, const QString& name)
177 return createTool(title, name);
180 int SalomeWrap_Module::wCreateTool(const int actionId,
184 return createTool(actionId, toolbarId, index);
187 int SalomeWrap_Module::wCreateTool(const int actionId,
188 const QString& toolbar,
191 return createTool(actionId, toolbar, index);
194 int SalomeWrap_Module::wCreateTool(QAction* action,
199 return createTool(action, toolbarId, actionId, index);
202 int SalomeWrap_Module::wCreateTool(QAction* action,
203 const QString& toolbar,
207 return createTool(action, toolbar, actionId, index);
210 QAction* SalomeWrap_Module::wSeparator()
215 SalomeWrap_DataModel* SalomeWrap_Module::getDataModel()
217 return dynamic_cast<SalomeWrap_DataModel*>(dataModel());
220 CAM_DataModel* SalomeWrap_Module::createDataModel()
222 return new SalomeWrap_DataModel(this);