1 // Copyright (C) 2007-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 // Author : Guillaume Boulant (EDF)
22 #include "MEDModule.hxx"
23 #include "QtHelper.hxx"
25 #include "SALOME_LifeCycleCORBA.hxx"
26 #include "QtxPopupMgr.h"
28 #include <SUIT_Desktop.h>
29 #include <SUIT_ResourceMgr.h>
30 #include <SUIT_Session.h>
31 #include <SalomeApp_Study.h>
33 #ifndef DISABLE_PVVIEWER
34 #include "PVViewer_ViewModel.h"
37 //! The only instance of the reference to engine
38 MED_ORB::MED_Gen_var MEDModule::myEngine;
40 MEDModule::MEDModule() :
41 SalomeApp_Module("MED"), _studyEditor(0), _datasourceController(0), _workspaceController(0), _presentationController(0)
43 // Note also that we can't use the getApp() function here because
44 // the initialize(...) function has not been called yet.
46 init(); // internal initialization
49 MEDModule::~MEDModule()
53 if (_datasourceController)
54 delete _datasourceController;
55 //if (_workspaceController)
56 // delete _workspaceController;
57 if (_presentationController)
58 delete _presentationController;
64 init(); // initialize engine, if necessary
71 // initialize MED module engine (load, if necessary)
72 if ( CORBA::is_nil( myEngine ) ) {
73 Engines::EngineComponent_var comp =
74 SalomeApp_Application::lcc()->FindOrLoad_Component( "FactoryServer", "MED" );
75 myEngine = MED_ORB::MED_Gen::_narrow( comp );
80 MEDModule::initialize( CAM_Application* app )
82 // call the parent implementation
83 SalomeApp_Module::initialize( app );
85 // The following initializes the GUI widget and associated actions
86 this->createModuleWidgets();
87 this->createModuleActions();
91 MEDModule::engineIOR() const
93 init(); // initialize engine, if necessary
94 CORBA::String_var anIOR = getApp()->orb()->object_to_string( myEngine.in() );
95 return QString( anIOR.in() );
99 MEDModule::iconName() const
101 return tr("ICO_MED_SMALL");
105 MEDModule::windows( QMap<int, int>& theMap ) const
107 // want Object browser, in the left area
108 theMap.insert( SalomeApp_Application::WT_ObjectBrowser,
109 Qt::LeftDockWidgetArea );
110 #ifndef DISABLE_PYCONSOLE
111 // want Python console, in the bottom area
112 theMap.insert( SalomeApp_Application::WT_PyConsole,
113 Qt::BottomDockWidgetArea );
118 MEDModule::viewManagers( QStringList& list ) const
120 #ifndef DISABLE_PVVIEWER
121 list.append( PVViewer_Viewer::Type() );
126 MEDModule::activateModule( SUIT_Study* theStudy )
128 if ( CORBA::is_nil( myEngine ) )
131 // call parent implementation
132 bool bOk = SalomeApp_Module::activateModule( theStudy );
137 setMenuShown( true );
139 setToolShown( true );
141 //this->createStudyComponent(theStudy);
142 _workspaceController->showDockWidgets(true);
143 //this->setDockLayout(StandardApp_Module::DOCKLAYOUT_LEFT_VLARGE);
145 // return the activation status
150 MEDModule::deactivateModule( SUIT_Study* theStudy )
152 _workspaceController->showDockWidgets(false);
153 //this->unsetDockLayout();
156 setMenuShown( false );
158 setToolShown( false );
160 // call parent implementation and return the activation status
161 return SalomeApp_Module::deactivateModule( theStudy );
165 // =====================================================================
166 // This part add custom widgets (a dockwidget containing a tree view
167 // in this example) and add special actions in the toolbox of the
169 // =====================================================================
173 * This function implements the interface StandardApp_Module. It
174 * creates the widgets specific for this module, in particular the
175 * workspace widget and the dataspace widget.
178 MEDModule::createModuleWidgets() {
179 _studyEditor = new SALOME_AppStudyEditor(getApp());
180 _datasourceController = new DatasourceController(this);
181 _workspaceController = new WorkspaceController(this);
182 _xmedDataModel = new XmedDataModel();
183 _workspaceController->setDataModel(_xmedDataModel);
184 _presentationController = new PresentationController(this);
186 connect(_datasourceController, SIGNAL(datasourceSignal(const DatasourceEvent*)),
187 _workspaceController, SLOT(processDatasourceEvent(const DatasourceEvent*)));
189 connect(_presentationController, SIGNAL(presentationSignal(const PresentationEvent*)),
190 _workspaceController, SLOT(processPresentationEvent(const PresentationEvent*)));
192 connect(_workspaceController, SIGNAL(workspaceSignal(const MEDCALC::MedEvent*)),
193 _datasourceController, SLOT(processWorkspaceEvent(const MEDCALC::MedEvent*)));
195 connect(_workspaceController, SIGNAL(workspaceSignal(const MEDCALC::MedEvent*)),
196 _presentationController, SLOT(processWorkspaceEvent(const MEDCALC::MedEvent*)));
200 MEDModule::createModuleActions() {
201 _datasourceController->createActions();
202 _workspaceController->createActions();
203 _presentationController->createActions();
207 MEDModule::createStandardAction(const QString& label,
209 const char* slotmember,
210 const QString& iconName,
211 const QString& tooltip)
213 SUIT_Desktop* dsk = getApp()->desktop();
214 SUIT_ResourceMgr* resMgr = getApp()->resourceMgr();
216 // If the tooltip is not defined, we choose instead the label text.
217 QString effToolTip(tooltip);
218 if ( effToolTip.isEmpty() )
221 QAction* action = createAction(-1,
223 resMgr->loadPixmap("MED", iconName),
232 return actionId(action);
236 MEDModule::addActionInPopupMenu(int actionId,const QString& menus,const QString& rule)
238 // _GBO_ for a fine customization of the rule (for example with a
239 // test on the type of the selected object), see the LIGTH module:
240 // implement "LightApp_Selection* createSelection() const;"
242 QtxPopupMgr* mgr = this->popupMgr();
243 this->action( actionId )->setIconVisibleInMenu(true);
244 if (! menus.isEmpty())
245 mgr->insert ( this->action( actionId ), menus, parentId, 0 );
247 mgr->insert ( this->action( actionId ), parentId, 0 );
248 mgr->setRule( this->action( actionId ), rule, QtxPopupMgr::VisibleRule );
251 MEDCALC::MEDPresentationViewMode
252 MEDModule::getSelectedViewMode()
254 return _presentationController->getSelectedViewMode();