1 // Copyright (C) 2007-2017 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"
24 #include <MEDCalcConstants.hxx>
26 #include "SALOME_LifeCycleCORBA.hxx"
27 #include "QtxPopupMgr.h"
29 #include <LightApp_Preferences.h>
30 #include <SUIT_Desktop.h>
31 #include <SUIT_ResourceMgr.h>
32 #include <SUIT_Session.h>
33 #include <SUIT_DataBrowser.h>
34 #include <SalomeApp_Study.h>
35 #include <SalomeApp_DataObject.h>
36 #include <SalomeApp_DataModel.h>
38 #include <SALOMEconfig.h>
39 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
40 #include <SALOMEDS_SObject.hxx>
41 #include <SALOMEDS_Study.hxx>
43 #ifndef DISABLE_PVVIEWER
44 #include <PVViewer_ViewModel.h>
45 #include <PVViewer_GUIElements.h>
48 #include "MEDFactoryClient.hxx"
49 #include "MEDPresentationManager_i.hxx"
54 #include <pqAnimationManager.h>
55 #include <pqPVApplicationCore.h>
57 //! The only instance of the reference to engine
58 MED_ORB::MED_Gen_var MEDModule::_MED_engine;
60 MEDModule::MEDModule() :
61 SalomeApp_Module("MED"), _studyEditor(0),
62 _datasourceController(0), _workspaceController(0), _presentationController(0),
63 _processingController(0), _pvGuiElements(0)
65 STDLOG("MEDModule::MEDModule()");
66 // Note also that we can't use the getApp() function here because
67 // the initialize(...) function has not been called yet.
69 init(); // internal initialization
72 MEDModule::~MEDModule()
75 STDLOG("MEDModule::~MEDModule(): cleaning up engine side.");
76 _MED_engine->cleanUp();
77 MEDFactoryClient::getFactory()->getPresentationManager()->cleanUp();
78 MEDFactoryClient::getFactory()->getDataManager()->cleanUp();
82 if (_datasourceController)
83 delete _datasourceController;
84 //if (_workspaceController)
85 // delete _workspaceController;
86 if (_presentationController)
87 delete _presentationController;
88 if (_processingController)
89 delete _processingController;
95 init(); // initialize engine, if necessary
102 // initialize MED module engine (load, if necessary)
103 if ( CORBA::is_nil( _MED_engine ) ) {
104 Engines::EngineComponent_var comp =
105 SalomeApp_Application::lcc()->FindOrLoad_Component( "FactoryServer", "MED" );
106 if (CORBA::is_nil( comp ))
107 STDLOG("Could not FindOrLoad_Component MED");
108 _MED_engine = MED_ORB::MED_Gen::_narrow( comp );
109 if (CORBA::is_nil( _MED_engine ))
110 STDLOG("Could not narrow MED engine");
114 //void MEDModule::onEventLoopStarted()
116 // if(!getApp()->isMainEventLoopStarted())
118 // QTimer::singleShot(100, this, SLOT(onEventLoopStarted()));
124 MEDModule::initialize( CAM_Application* app )
126 STDLOG("MEDModule::initialize()");
127 // call the parent implementation
128 SalomeApp_Module::initialize( app );
130 if (! getApp()->objectBrowser())
131 getApp()->getWindow(SalomeApp_Application::WT_ObjectBrowser);
133 getApp()->objectBrowser()->setAutoOpenLevel(5);
135 if (app && app->desktop()) {
136 connect((QObject*) (getApp()->objectBrowser()->treeView()), SIGNAL(doubleClicked(const QModelIndex&)),
137 this, SLOT(onDblClick(const QModelIndex&)));
138 connect((QObject*) (getApp()->objectBrowser()->treeView()), SIGNAL(clicked(const QModelIndex&)),
139 this, SLOT(onClick(const QModelIndex&)));
142 // The following initializes the GUI widget and associated actions
143 this->createModuleWidgets();
144 this->createModuleActions();
146 // Now that the workspace controller is created, ParaView core application has normally been started,
147 // and hidden GUI elements have been created. We can fire the VCR toolbar activation:
152 MEDModule::engineIOR() const
154 init(); // initialize engine, if necessary
155 CORBA::String_var anIOR = getApp()->orb()->object_to_string( _MED_engine.in() );
156 return QString( anIOR.in() );
160 MEDModule::iconName() const
162 return tr("ICO_MED_SMALL");
166 MEDModule::windows( QMap<int, int>& theMap ) const
168 STDLOG("MEDModule::windows()");
169 // want Object browser, in the left area
170 theMap.insert( SalomeApp_Application::WT_ObjectBrowser,
171 Qt::LeftDockWidgetArea );
172 #ifndef DISABLE_PYCONSOLE
173 // want Python console, in the bottom area
174 theMap.insert( SalomeApp_Application::WT_PyConsole,
175 Qt::BottomDockWidgetArea );
180 MEDModule::viewManagers( QStringList& list ) const
182 #ifndef DISABLE_PVVIEWER
183 list.append( PVViewer_Viewer::Type() );
188 MEDModule::createPreferences()
190 int genTab = addPreference(tr("PREF_TAB_GENERAL"));
192 int themeGroup = addPreference(tr("PREF_THEME_GROUP"), genTab);
193 setPreferenceProperty(themeGroup, "columns", 2);
194 int icons = addPreference(tr("PREF_ICONS"), themeGroup, LightApp_Preferences::Selector, "MEDCalc", "icons" );
195 QStringList iconsThemes;
196 iconsThemes.append(tr("PREF_ICON_THEME_MODERN"));
197 iconsThemes.append(tr("PREF_ICON_THEME_CLASSIC"));
198 QList<QVariant> indices;
201 setPreferenceProperty(icons, "strings", iconsThemes);
202 setPreferenceProperty(icons, "indexes", indices);
206 MEDModule::activateModule( SUIT_Study* theStudy )
208 STDLOG("MEDModule::activateModule()");
209 if ( CORBA::is_nil( _MED_engine ) )
212 // call parent implementation
213 bool bOk = SalomeApp_Module::activateModule( theStudy );
218 setMenuShown( true );
220 setToolShown( true );
222 //this->createStudyComponent(theStudy);
223 _workspaceController->showDockWidgets(true);
224 _presentationController->showDockWidgets(true);
225 //this->setDockLayout(StandardApp_Module::DOCKLAYOUT_LEFT_VLARGE);
227 // Mark the start of the main event loop - important for test playback:
228 // QObject::connect(getApp(), SIGNAL(activated(SUIT_Application *)), this, SLOT(onEventLoopStarted(SUIT_Application *)));
229 // QTimer::singleShot(0, this, SLOT(onEventLoopStarted()));
231 // return the activation status
236 MEDModule::deactivateModule( SUIT_Study* theStudy )
238 STDLOG("MEDModule::deactivateModule()");
239 _workspaceController->showDockWidgets(false);
240 _presentationController->showDockWidgets(false);
241 //this->unsetDockLayout();
244 setMenuShown( false );
246 setToolShown( false );
248 // call parent implementation and return the activation status
249 return SalomeApp_Module::deactivateModule( theStudy );
253 // =====================================================================
254 // This part add custom widgets (a dockwidget containing a tree view
255 // in this example) and add special actions in the toolbox of the
257 // =====================================================================
261 * This function implements the interface StandardApp_Module. It
262 * creates the widgets specific for this module, in particular the
263 * workspace widget and the dataspace widget.
266 MEDModule::createModuleWidgets() {
267 _studyEditor = new SALOME_AppStudyEditor(getApp());
268 _datasourceController = new DatasourceController(this);
269 _workspaceController = new WorkspaceController(this);
270 _xmedDataModel = new XmedDataModel();
271 _workspaceController->setDataModel(_xmedDataModel);
272 _presentationController = new PresentationController(this);
273 // ABN: ultimately console driver should be owned by module: everyone needs it, not only WorkspaceController
274 _presentationController->setConsoleDriver(_workspaceController->getConsoleDriver());
275 _processingController = new ProcessingController(this);
276 #ifdef MED_HAS_QTTESTING
277 _testController = new TestController(this);
280 connect(_datasourceController, SIGNAL(datasourceSignal(const DatasourceEvent*)),
281 _workspaceController, SLOT(processDatasourceEvent(const DatasourceEvent*)));
283 connect(_presentationController, SIGNAL(presentationSignal(const PresentationEvent*)),
284 _presentationController, SLOT(processPresentationEvent(const PresentationEvent*)));
286 connect(_processingController, SIGNAL(processingSignal(const ProcessingEvent*)),
287 _workspaceController, SLOT(processProcessingEvent(const ProcessingEvent*)));
289 connect(_workspaceController, SIGNAL(workspaceSignal(const MEDCALC::MedEvent*)),
290 _datasourceController, SLOT(processWorkspaceEvent(const MEDCALC::MedEvent*)));
292 connect(_workspaceController, SIGNAL(workspaceSignal(const MEDCALC::MedEvent*)),
293 _presentationController, SLOT(processWorkspaceEvent(const MEDCALC::MedEvent*)));
297 MEDModule::initToolbars()
299 // VCR and Time toolbars:
300 SUIT_Desktop* dsk = getApp()->desktop();
301 _pvGuiElements = PVViewer_GUIElements::GetInstance(dsk);
303 _pvGuiElements->getVCRToolbar(); // make sure VCR toolbar is built
304 _pvGuiElements->setToolBarVisible(false);
305 _pvGuiElements->setVCRTimeToolBarVisible(true);
307 // Emit signal in order to make sure that animation scene is set - same trick as in PARAVIS module activation
308 QMetaObject::invokeMethod( pqPVApplicationCore::instance()->animationManager(),
309 "activeSceneChanged",
310 Q_ARG( pqAnimationScene*, pqPVApplicationCore::instance()->animationManager()->getActiveScene() ) );
312 #ifdef MED_HAS_QTTESTING
313 connect(_workspaceController, SIGNAL(workspaceSignal(const MEDCALC::MedEvent*)),
314 _testController, SLOT(processWorkspaceEvent(const MEDCALC::MedEvent*)));
319 MEDModule::createModuleActions() {
320 _datasourceController->createActions();
321 _workspaceController->createActions();
322 _presentationController->createActions();
323 _processingController->createActions();
324 #ifdef MED_HAS_QTTESTING
325 _testController->createActions();
330 MEDModule::createStandardAction(const QString& label,
332 const char* slotmember,
333 const QString& iconName,
334 const QString& tooltip)
336 SUIT_Desktop* dsk = getApp()->desktop();
337 SUIT_ResourceMgr* resMgr = getApp()->resourceMgr();
339 // If the tooltip is not defined, we choose instead the label text.
340 QString effToolTip(tooltip);
341 if ( effToolTip.isEmpty() )
345 if (iconName.isEmpty())
348 ico = QIcon(resMgr->loadPixmap("MED", iconName));
350 QAction* action = createAction(-1,
361 return actionId(action);
365 MEDModule::addActionInPopupMenu(int actionId,const QString& menus,const QString& rule)
367 // _GBO_ for a fine customization of the rule (for example with a
368 // test on the type of the selected object), see the LIGHT module:
369 // implement "LightApp_Selection* createSelection() const;"
371 QtxPopupMgr* mgr = this->popupMgr();
372 this->action( actionId )->setIconVisibleInMenu(true);
373 if (! menus.isEmpty())
374 mgr->insert ( this->action( actionId ), menus, parentId, 0 );
376 mgr->insert ( this->action( actionId ), parentId, 0 );
377 mgr->setRule( this->action( actionId ), rule, QtxPopupMgr::VisibleRule );
380 //MEDCALC::ViewModeType
381 //MEDModule::getSelectedViewMode() const
383 // return _presentationController->getSelectedViewMode();
386 //MEDCALC::ColorMapType
387 //MEDModule::getSelectedColorMap() const
389 // return _presentationController->getSelectedColorMap();
392 //MEDCALC::ScalarBarRangeType
393 //MEDModule::getSelectedScalarBarRange() const
395 // return _presentationController->getSelectedScalarBarRange();
400 * Returns presentation name, type and ID from the currently selected presentation in the object
404 MEDModule::itemClickGeneric(std::string & name, std::string & type, int & presId) const
406 DataObjectList dol = getApp()->objectBrowser()->getSelected();
409 SalomeApp_DataObject* item = dynamic_cast<SalomeApp_DataObject*>(dol[0]);
412 SalomeApp_DataModel *model = dynamic_cast<SalomeApp_DataModel*>(dataModel());
416 if (item->componentDataType().toStdString() != "MED")
418 _PTR(SObject) obj = item->object();
419 _PTR(GenericAttribute) anAttribute;
421 if (! obj->FindAttribute(anAttribute, "AttributeName"))
423 _PTR(AttributeName) attrName(anAttribute);
424 name = attrName->Value();
426 if (! obj->FindAttribute(anAttribute, "AttributeParameter"))
428 _PTR(AttributeParameter) attrParam(anAttribute);
429 if (! attrParam->IsSet(IS_PRESENTATION, PT_BOOLEAN)
430 || ! attrParam->GetBool(IS_PRESENTATION)) { // Not a presentation
433 // if (!attrParam->IsSet(FIELD_ID, PT_INTEGER))
435 // fieldId = attrParam->GetInt(FIELD_ID);
436 if (!attrParam->IsSet(PRESENTATION_ID, PT_INTEGER))
438 presId = attrParam->GetInt(PRESENTATION_ID);
439 if (!attrParam->IsSet(PRESENTATION_TYPE, PT_STRING))
441 type = attrParam->GetString(PRESENTATION_TYPE);
446 MEDModule::onClick(const QModelIndex & index)
449 std::string name, type;
450 if (!itemClickGeneric(name, type, presId))
452 // Not a presentation - clear widget:
453 emit presentationSelected(-1, QString(""), QString(""));
457 // STDLOG("Presentation selection");
458 // std::ostringstream oss;
459 // oss << fieldId << " / " << presId;
460 // STDLOG(" - Field id / pres id: " + oss.str());
461 // STDLOG(" - Presentation type: " + type);
462 // STDLOG(" - Presentation name: " + name);
464 emit presentationSelected(presId, QString::fromStdString(type), QString::fromStdString(name) ); // caught by PresentationController
468 MEDModule::onDblClick(const QModelIndex& index)
471 std::string name, type;
472 if (!itemClickGeneric(name, type, presId))
475 // STDLOG("Presentation double click");
476 // STDLOG(" Presentation infos:");
477 // STDLOG(" - Component: " + item->componentDataType().toStdString());
478 // STDLOG(" - Item entry: " + item->entry().toStdString());
479 // STDLOG(" - Item name: " + item->name().toStdString());
480 // std::ostringstream oss;
482 // STDLOG(" - Field id: " + oss.str());
483 // STDLOG(" - Presentation name: " + name);
487 MEDModule::requestSALOMETermination() const
489 STDLOG("Requesting SALOME termination!!");
490 SUIT_Session::session()->closeSession( SUIT_Session::DONT_SAVE, 1 ); // killServers = True
494 //bool MEDModule::hasMainEventLoopStarted() const
496 // return _eventLoopStarted;
500 MEDModule::getIntParamFromStudyEditor(SALOMEDS::SObject_var obj, const char* name)
505 SALOMEDS::GenericAttribute_var anAttr;
506 SALOMEDS::AttributeParameter_var aParam;
507 if ( obj->FindAttribute(anAttr,"AttributeParameter") ) {
508 aParam = SALOMEDS::AttributeParameter::_narrow(anAttr);
509 if (aParam->IsSet(name, PT_INTEGER))
510 return aParam->GetInt(name);