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 <LightApp_Preferences.h>
29 #include <SUIT_Desktop.h>
30 #include <SUIT_ResourceMgr.h>
31 #include <SUIT_Session.h>
32 #include <SalomeApp_Study.h>
34 #ifndef DISABLE_PVVIEWER
35 #include "PVViewer_ViewModel.h"
38 //! The only instance of the reference to engine
39 MED_ORB::MED_Gen_var MEDModule::myEngine;
41 MEDModule::MEDModule() :
42 SalomeApp_Module("MED"), _studyEditor(0), _datasourceController(0), _workspaceController(0), _presentationController(0)
44 // Note also that we can't use the getApp() function here because
45 // the initialize(...) function has not been called yet.
47 init(); // internal initialization
50 MEDModule::~MEDModule()
54 if (_datasourceController)
55 delete _datasourceController;
56 //if (_workspaceController)
57 // delete _workspaceController;
58 if (_presentationController)
59 delete _presentationController;
65 init(); // initialize engine, if necessary
72 // initialize MED module engine (load, if necessary)
73 if ( CORBA::is_nil( myEngine ) ) {
74 Engines::EngineComponent_var comp =
75 SalomeApp_Application::lcc()->FindOrLoad_Component( "FactoryServer", "MED" );
76 myEngine = MED_ORB::MED_Gen::_narrow( comp );
81 MEDModule::initialize( CAM_Application* app )
83 // call the parent implementation
84 SalomeApp_Module::initialize( app );
86 // The following initializes the GUI widget and associated actions
87 this->createModuleWidgets();
88 this->createModuleActions();
92 MEDModule::engineIOR() const
94 init(); // initialize engine, if necessary
95 CORBA::String_var anIOR = getApp()->orb()->object_to_string( myEngine.in() );
96 return QString( anIOR.in() );
100 MEDModule::iconName() const
102 return tr("ICO_MED_SMALL");
106 MEDModule::windows( QMap<int, int>& theMap ) const
108 // want Object browser, in the left area
109 theMap.insert( SalomeApp_Application::WT_ObjectBrowser,
110 Qt::LeftDockWidgetArea );
111 #ifndef DISABLE_PYCONSOLE
112 // want Python console, in the bottom area
113 theMap.insert( SalomeApp_Application::WT_PyConsole,
114 Qt::BottomDockWidgetArea );
119 MEDModule::viewManagers( QStringList& list ) const
121 #ifndef DISABLE_PVVIEWER
122 list.append( PVViewer_Viewer::Type() );
127 MEDModule::createPreferences()
129 int genTab = addPreference(tr("PREF_TAB_GENERAL"));
131 int themeGroup = addPreference(tr("PREF_THEME_GROUP"), genTab);
132 setPreferenceProperty(themeGroup, "columns", 2);
133 int icons = addPreference(tr("PREF_ICONS"), themeGroup, LightApp_Preferences::Selector, "MEDCalc", "icons" );
134 QStringList iconsThemes;
135 iconsThemes.append(tr("PREF_ICON_THEME_MODERN"));
136 iconsThemes.append(tr("PREF_ICON_THEME_CLASSIC"));
137 QList<QVariant> indices;
140 setPreferenceProperty(icons, "strings", iconsThemes);
141 setPreferenceProperty(icons, "indexes", indices);
145 MEDModule::activateModule( SUIT_Study* theStudy )
147 if ( CORBA::is_nil( myEngine ) )
150 // call parent implementation
151 bool bOk = SalomeApp_Module::activateModule( theStudy );
156 setMenuShown( true );
158 setToolShown( true );
160 //this->createStudyComponent(theStudy);
161 _workspaceController->showDockWidgets(true);
162 //this->setDockLayout(StandardApp_Module::DOCKLAYOUT_LEFT_VLARGE);
164 // return the activation status
169 MEDModule::deactivateModule( SUIT_Study* theStudy )
171 _workspaceController->showDockWidgets(false);
172 //this->unsetDockLayout();
175 setMenuShown( false );
177 setToolShown( false );
179 // call parent implementation and return the activation status
180 return SalomeApp_Module::deactivateModule( theStudy );
184 // =====================================================================
185 // This part add custom widgets (a dockwidget containing a tree view
186 // in this example) and add special actions in the toolbox of the
188 // =====================================================================
192 * This function implements the interface StandardApp_Module. It
193 * creates the widgets specific for this module, in particular the
194 * workspace widget and the dataspace widget.
197 MEDModule::createModuleWidgets() {
198 _studyEditor = new SALOME_AppStudyEditor(getApp());
199 _datasourceController = new DatasourceController(this);
200 _workspaceController = new WorkspaceController(this);
201 _xmedDataModel = new XmedDataModel();
202 _workspaceController->setDataModel(_xmedDataModel);
203 _presentationController = new PresentationController(this);
205 connect(_datasourceController, SIGNAL(datasourceSignal(const DatasourceEvent*)),
206 _workspaceController, SLOT(processDatasourceEvent(const DatasourceEvent*)));
208 connect(_presentationController, SIGNAL(presentationSignal(const PresentationEvent*)),
209 _workspaceController, SLOT(processPresentationEvent(const PresentationEvent*)));
211 connect(_workspaceController, SIGNAL(workspaceSignal(const MEDCALC::MedEvent*)),
212 _datasourceController, SLOT(processWorkspaceEvent(const MEDCALC::MedEvent*)));
214 connect(_workspaceController, SIGNAL(workspaceSignal(const MEDCALC::MedEvent*)),
215 _presentationController, SLOT(processWorkspaceEvent(const MEDCALC::MedEvent*)));
219 MEDModule::createModuleActions() {
220 _datasourceController->createActions();
221 _workspaceController->createActions();
222 _presentationController->createActions();
226 MEDModule::createStandardAction(const QString& label,
228 const char* slotmember,
229 const QString& iconName,
230 const QString& tooltip)
232 SUIT_Desktop* dsk = getApp()->desktop();
233 SUIT_ResourceMgr* resMgr = getApp()->resourceMgr();
235 // If the tooltip is not defined, we choose instead the label text.
236 QString effToolTip(tooltip);
237 if ( effToolTip.isEmpty() )
240 QAction* action = createAction(-1,
242 resMgr->loadPixmap("MED", iconName),
251 return actionId(action);
255 MEDModule::addActionInPopupMenu(int actionId,const QString& menus,const QString& rule)
257 // _GBO_ for a fine customization of the rule (for example with a
258 // test on the type of the selected object), see the LIGTH module:
259 // implement "LightApp_Selection* createSelection() const;"
261 QtxPopupMgr* mgr = this->popupMgr();
262 this->action( actionId )->setIconVisibleInMenu(true);
263 if (! menus.isEmpty())
264 mgr->insert ( this->action( actionId ), menus, parentId, 0 );
266 mgr->insert ( this->action( actionId ), parentId, 0 );
267 mgr->setRule( this->action( actionId ), rule, QtxPopupMgr::VisibleRule );
270 MEDCALC::MEDPresentationViewMode
271 MEDModule::getSelectedViewMode()
273 return _presentationController->getSelectedViewMode();