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), _processingController(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;
60 if (_processingController)
61 delete _processingController;
67 init(); // initialize engine, if necessary
74 // initialize MED module engine (load, if necessary)
75 if ( CORBA::is_nil( myEngine ) ) {
76 Engines::EngineComponent_var comp =
77 SalomeApp_Application::lcc()->FindOrLoad_Component( "FactoryServer", "MED" );
78 myEngine = MED_ORB::MED_Gen::_narrow( comp );
83 MEDModule::initialize( CAM_Application* app )
85 // call the parent implementation
86 SalomeApp_Module::initialize( app );
88 // The following initializes the GUI widget and associated actions
89 this->createModuleWidgets();
90 this->createModuleActions();
94 MEDModule::engineIOR() const
96 init(); // initialize engine, if necessary
97 CORBA::String_var anIOR = getApp()->orb()->object_to_string( myEngine.in() );
98 return QString( anIOR.in() );
102 MEDModule::iconName() const
104 return tr("ICO_MED_SMALL");
108 MEDModule::windows( QMap<int, int>& theMap ) const
110 // want Object browser, in the left area
111 theMap.insert( SalomeApp_Application::WT_ObjectBrowser,
112 Qt::LeftDockWidgetArea );
113 #ifndef DISABLE_PYCONSOLE
114 // want Python console, in the bottom area
115 theMap.insert( SalomeApp_Application::WT_PyConsole,
116 Qt::BottomDockWidgetArea );
121 MEDModule::viewManagers( QStringList& list ) const
123 #ifndef DISABLE_PVVIEWER
124 list.append( PVViewer_Viewer::Type() );
129 MEDModule::createPreferences()
131 int genTab = addPreference(tr("PREF_TAB_GENERAL"));
133 int themeGroup = addPreference(tr("PREF_THEME_GROUP"), genTab);
134 setPreferenceProperty(themeGroup, "columns", 2);
135 int icons = addPreference(tr("PREF_ICONS"), themeGroup, LightApp_Preferences::Selector, "MEDCalc", "icons" );
136 QStringList iconsThemes;
137 iconsThemes.append(tr("PREF_ICON_THEME_MODERN"));
138 iconsThemes.append(tr("PREF_ICON_THEME_CLASSIC"));
139 QList<QVariant> indices;
142 setPreferenceProperty(icons, "strings", iconsThemes);
143 setPreferenceProperty(icons, "indexes", indices);
147 MEDModule::activateModule( SUIT_Study* theStudy )
149 if ( CORBA::is_nil( myEngine ) )
152 // call parent implementation
153 bool bOk = SalomeApp_Module::activateModule( theStudy );
158 setMenuShown( true );
160 setToolShown( true );
162 //this->createStudyComponent(theStudy);
163 _workspaceController->showDockWidgets(true);
164 //this->setDockLayout(StandardApp_Module::DOCKLAYOUT_LEFT_VLARGE);
166 // return the activation status
171 MEDModule::deactivateModule( SUIT_Study* theStudy )
173 _workspaceController->showDockWidgets(false);
174 //this->unsetDockLayout();
177 setMenuShown( false );
179 setToolShown( false );
181 // call parent implementation and return the activation status
182 return SalomeApp_Module::deactivateModule( theStudy );
186 // =====================================================================
187 // This part add custom widgets (a dockwidget containing a tree view
188 // in this example) and add special actions in the toolbox of the
190 // =====================================================================
194 * This function implements the interface StandardApp_Module. It
195 * creates the widgets specific for this module, in particular the
196 * workspace widget and the dataspace widget.
199 MEDModule::createModuleWidgets() {
200 _studyEditor = new SALOME_AppStudyEditor(getApp());
201 _datasourceController = new DatasourceController(this);
202 _workspaceController = new WorkspaceController(this);
203 _xmedDataModel = new XmedDataModel();
204 _workspaceController->setDataModel(_xmedDataModel);
205 _presentationController = new PresentationController(this);
206 _processingController = new ProcessingController(this);
208 connect(_datasourceController, SIGNAL(datasourceSignal(const DatasourceEvent*)),
209 _workspaceController, SLOT(processDatasourceEvent(const DatasourceEvent*)));
211 connect(_presentationController, SIGNAL(presentationSignal(const PresentationEvent*)),
212 _workspaceController, SLOT(processPresentationEvent(const PresentationEvent*)));
214 connect(_processingController, SIGNAL(processingSignal(const ProcessingEvent*)),
215 _workspaceController, SLOT(processProcessingEvent(const ProcessingEvent*)));
217 connect(_workspaceController, SIGNAL(workspaceSignal(const MEDCALC::MedEvent*)),
218 _datasourceController, SLOT(processWorkspaceEvent(const MEDCALC::MedEvent*)));
220 connect(_workspaceController, SIGNAL(workspaceSignal(const MEDCALC::MedEvent*)),
221 _presentationController, SLOT(processWorkspaceEvent(const MEDCALC::MedEvent*)));
225 MEDModule::createModuleActions() {
226 _datasourceController->createActions();
227 _workspaceController->createActions();
228 _presentationController->createActions();
229 _processingController->createActions();
233 MEDModule::createStandardAction(const QString& label,
235 const char* slotmember,
236 const QString& iconName,
237 const QString& tooltip)
239 SUIT_Desktop* dsk = getApp()->desktop();
240 SUIT_ResourceMgr* resMgr = getApp()->resourceMgr();
242 // If the tooltip is not defined, we choose instead the label text.
243 QString effToolTip(tooltip);
244 if ( effToolTip.isEmpty() )
247 QAction* action = createAction(-1,
249 resMgr->loadPixmap("MED", iconName),
258 return actionId(action);
262 MEDModule::addActionInPopupMenu(int actionId,const QString& menus,const QString& rule)
264 // _GBO_ for a fine customization of the rule (for example with a
265 // test on the type of the selected object), see the LIGTH module:
266 // implement "LightApp_Selection* createSelection() const;"
268 QtxPopupMgr* mgr = this->popupMgr();
269 this->action( actionId )->setIconVisibleInMenu(true);
270 if (! menus.isEmpty())
271 mgr->insert ( this->action( actionId ), menus, parentId, 0 );
273 mgr->insert ( this->action( actionId ), parentId, 0 );
274 mgr->setRule( this->action( actionId ), rule, QtxPopupMgr::VisibleRule );
277 MEDCALC::MEDPresentationViewMode
278 MEDModule::getSelectedViewMode()
280 return _presentationController->getSelectedViewMode();
283 MEDCALC::MEDPresentationColorMap
284 MEDModule::getSelectedColorMap()
286 return _presentationController->getSelectedColorMap();