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"
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 // Note also that we can't use the getApp() function here because
66 // the initialize(...) function has not been called yet.
68 init(); // internal initialization
71 MEDModule::~MEDModule()
75 if (_datasourceController)
76 delete _datasourceController;
77 //if (_workspaceController)
78 // delete _workspaceController;
79 if (_presentationController)
80 delete _presentationController;
81 if (_processingController)
82 delete _processingController;
88 init(); // initialize engine, if necessary
95 // initialize MED module engine (load, if necessary)
96 if ( CORBA::is_nil( _MED_engine ) ) {
97 Engines::EngineComponent_var comp =
98 SalomeApp_Application::lcc()->FindOrLoad_Component( "FactoryServer", "MED" );
99 if (CORBA::is_nil( comp ))
100 STDLOG("Could not FindOrLoad_Component MED");
101 _MED_engine = MED_ORB::MED_Gen::_narrow( comp );
102 if (CORBA::is_nil( _MED_engine ))
103 STDLOG("Could not narrow MED engine");
107 //void MEDModule::onEventLoopStarted()
109 // if(!getApp()->isMainEventLoopStarted())
111 // QTimer::singleShot(100, this, SLOT(onEventLoopStarted()));
117 MEDModule::initialize( CAM_Application* app )
119 // call the parent implementation
120 SalomeApp_Module::initialize( app );
122 getApp()->objectBrowser()->setAutoOpenLevel(5);
124 if (app && app->desktop()) {
125 connect((QObject*) (getApp()->objectBrowser()->treeView()), SIGNAL(doubleClicked(const QModelIndex&)),
126 this, SLOT(onDblClick(const QModelIndex&)));
127 connect((QObject*) (getApp()->objectBrowser()->treeView()), SIGNAL(clicked(const QModelIndex&)),
128 this, SLOT(onClick(const QModelIndex&)));
131 // The following initializes the GUI widget and associated actions
132 this->createModuleWidgets();
133 this->createModuleActions();
135 // Now that the workspace controller is created, ParaView core application has normally been started,
136 // and hidden GUI elements have been created. We can fire the VCR toolbar activation:
141 MEDModule::engineIOR() const
143 init(); // initialize engine, if necessary
144 CORBA::String_var anIOR = getApp()->orb()->object_to_string( _MED_engine.in() );
145 return QString( anIOR.in() );
149 MEDModule::iconName() const
151 return tr("ICO_MED_SMALL");
155 MEDModule::windows( QMap<int, int>& theMap ) const
157 // want Object browser, in the left area
158 theMap.insert( SalomeApp_Application::WT_ObjectBrowser,
159 Qt::LeftDockWidgetArea );
160 #ifndef DISABLE_PYCONSOLE
161 // want Python console, in the bottom area
162 theMap.insert( SalomeApp_Application::WT_PyConsole,
163 Qt::BottomDockWidgetArea );
168 MEDModule::viewManagers( QStringList& list ) const
170 #ifndef DISABLE_PVVIEWER
171 list.append( PVViewer_Viewer::Type() );
176 MEDModule::createPreferences()
178 int genTab = addPreference(tr("PREF_TAB_GENERAL"));
180 int themeGroup = addPreference(tr("PREF_THEME_GROUP"), genTab);
181 setPreferenceProperty(themeGroup, "columns", 2);
182 int icons = addPreference(tr("PREF_ICONS"), themeGroup, LightApp_Preferences::Selector, "MEDCalc", "icons" );
183 QStringList iconsThemes;
184 iconsThemes.append(tr("PREF_ICON_THEME_MODERN"));
185 iconsThemes.append(tr("PREF_ICON_THEME_CLASSIC"));
186 QList<QVariant> indices;
189 setPreferenceProperty(icons, "strings", iconsThemes);
190 setPreferenceProperty(icons, "indexes", indices);
194 MEDModule::activateModule( SUIT_Study* theStudy )
196 if ( CORBA::is_nil( _MED_engine ) )
199 // call parent implementation
200 bool bOk = SalomeApp_Module::activateModule( theStudy );
205 setMenuShown( true );
207 setToolShown( true );
209 //this->createStudyComponent(theStudy);
210 _workspaceController->showDockWidgets(true);
211 _presentationController->showDockWidgets(true);
212 //this->setDockLayout(StandardApp_Module::DOCKLAYOUT_LEFT_VLARGE);
214 // Mark the start of the main event loop - important for test playback:
215 // QObject::connect(getApp(), SIGNAL(activated(SUIT_Application *)), this, SLOT(onEventLoopStarted(SUIT_Application *)));
216 // QTimer::singleShot(0, this, SLOT(onEventLoopStarted()));
218 // return the activation status
223 MEDModule::deactivateModule( SUIT_Study* theStudy )
226 STDLOG("MEDModule::deactivateModule(): cleaning up engine side.");
227 _MED_engine->cleanUp();
228 MEDFactoryClient::getFactory()->getPresentationManager()->cleanUp();
229 MEDFactoryClient::getFactory()->getDataManager()->cleanUp();
231 _workspaceController->showDockWidgets(false);
232 _presentationController->showDockWidgets(false);
233 //this->unsetDockLayout();
236 setMenuShown( false );
238 setToolShown( false );
240 // call parent implementation and return the activation status
241 return SalomeApp_Module::deactivateModule( theStudy );
245 // =====================================================================
246 // This part add custom widgets (a dockwidget containing a tree view
247 // in this example) and add special actions in the toolbox of the
249 // =====================================================================
253 * This function implements the interface StandardApp_Module. It
254 * creates the widgets specific for this module, in particular the
255 * workspace widget and the dataspace widget.
258 MEDModule::createModuleWidgets() {
259 _studyEditor = new SALOME_AppStudyEditor(getApp());
260 _datasourceController = new DatasourceController(this);
261 _workspaceController = new WorkspaceController(this);
262 _xmedDataModel = new XmedDataModel();
263 _workspaceController->setDataModel(_xmedDataModel);
264 _presentationController = new PresentationController(this);
265 // ABN: ultimately console driver should be owned by module: everyone needs it, not only WorkspaceController
266 _presentationController->setConsoleDriver(_workspaceController->getConsoleDriver());
267 _processingController = new ProcessingController(this);
268 #ifdef MED_HAS_QTTESTING
269 _testController = new TestController(this);
272 connect(_datasourceController, SIGNAL(datasourceSignal(const DatasourceEvent*)),
273 _workspaceController, SLOT(processDatasourceEvent(const DatasourceEvent*)));
275 connect(_presentationController, SIGNAL(presentationSignal(const PresentationEvent*)),
276 _presentationController, SLOT(processPresentationEvent(const PresentationEvent*)));
278 connect(_processingController, SIGNAL(processingSignal(const ProcessingEvent*)),
279 _workspaceController, SLOT(processProcessingEvent(const ProcessingEvent*)));
281 connect(_workspaceController, SIGNAL(workspaceSignal(const MEDCALC::MedEvent*)),
282 _datasourceController, SLOT(processWorkspaceEvent(const MEDCALC::MedEvent*)));
284 connect(_workspaceController, SIGNAL(workspaceSignal(const MEDCALC::MedEvent*)),
285 _presentationController, SLOT(processWorkspaceEvent(const MEDCALC::MedEvent*)));
289 MEDModule::initToolbars()
291 // VCR and Time toolbars:
292 SUIT_Desktop* dsk = getApp()->desktop();
293 _pvGuiElements = PVViewer_GUIElements::GetInstance(dsk);
295 _pvGuiElements->getVCRToolbar(); // make sure VCR toolbar is built
296 _pvGuiElements->setToolBarVisible(false);
297 _pvGuiElements->setVCRTimeToolBarVisible(true);
299 // Emit signal in order to make sure that animation scene is set - same trick as in PARAVIS module activation
300 QMetaObject::invokeMethod( pqPVApplicationCore::instance()->animationManager(),
301 "activeSceneChanged",
302 Q_ARG( pqAnimationScene*, pqPVApplicationCore::instance()->animationManager()->getActiveScene() ) );
304 #ifdef MED_HAS_QTTESTING
305 connect(_workspaceController, SIGNAL(workspaceSignal(const MEDCALC::MedEvent*)),
306 _testController, SLOT(processWorkspaceEvent(const MEDCALC::MedEvent*)));
311 MEDModule::createModuleActions() {
312 _datasourceController->createActions();
313 _workspaceController->createActions();
314 _presentationController->createActions();
315 _processingController->createActions();
316 #ifdef MED_HAS_QTTESTING
317 _testController->createActions();
322 MEDModule::createStandardAction(const QString& label,
324 const char* slotmember,
325 const QString& iconName,
326 const QString& tooltip)
328 SUIT_Desktop* dsk = getApp()->desktop();
329 SUIT_ResourceMgr* resMgr = getApp()->resourceMgr();
331 // If the tooltip is not defined, we choose instead the label text.
332 QString effToolTip(tooltip);
333 if ( effToolTip.isEmpty() )
337 if (iconName.isEmpty())
340 ico = QIcon(resMgr->loadPixmap("MED", iconName));
342 QAction* action = createAction(-1,
353 return actionId(action);
357 MEDModule::addActionInPopupMenu(int actionId,const QString& menus,const QString& rule)
359 // _GBO_ for a fine customization of the rule (for example with a
360 // test on the type of the selected object), see the LIGHT module:
361 // implement "LightApp_Selection* createSelection() const;"
363 QtxPopupMgr* mgr = this->popupMgr();
364 this->action( actionId )->setIconVisibleInMenu(true);
365 if (! menus.isEmpty())
366 mgr->insert ( this->action( actionId ), menus, parentId, 0 );
368 mgr->insert ( this->action( actionId ), parentId, 0 );
369 mgr->setRule( this->action( actionId ), rule, QtxPopupMgr::VisibleRule );
372 //MEDCALC::ViewModeType
373 //MEDModule::getSelectedViewMode() const
375 // return _presentationController->getSelectedViewMode();
378 //MEDCALC::ColorMapType
379 //MEDModule::getSelectedColorMap() const
381 // return _presentationController->getSelectedColorMap();
384 //MEDCALC::ScalarBarRangeType
385 //MEDModule::getSelectedScalarBarRange() const
387 // return _presentationController->getSelectedScalarBarRange();
392 * Returns presentation name, type and ID from the currently selected presentation in the object
396 MEDModule::itemClickGeneric(std::string & name, std::string & type, int & presId) const
398 DataObjectList dol = getApp()->objectBrowser()->getSelected();
401 SalomeApp_DataObject* item = dynamic_cast<SalomeApp_DataObject*>(dol[0]);
404 SalomeApp_DataModel *model = dynamic_cast<SalomeApp_DataModel*>(dataModel());
408 if (item->componentDataType().toStdString() != "MED")
410 _PTR(SObject) obj = item->object();
411 _PTR(GenericAttribute) anAttribute;
413 if (! obj->FindAttribute(anAttribute, "AttributeName"))
415 _PTR(AttributeName) attrName(anAttribute);
416 name = attrName->Value();
418 if (! obj->FindAttribute(anAttribute, "AttributeParameter"))
420 _PTR(AttributeParameter) attrParam(anAttribute);
421 if (! attrParam->IsSet(IS_PRESENTATION, PT_BOOLEAN)
422 || ! attrParam->GetBool(IS_PRESENTATION)) { // Not a presentation
425 // if (!attrParam->IsSet(FIELD_ID, PT_INTEGER))
427 // fieldId = attrParam->GetInt(FIELD_ID);
428 if (!attrParam->IsSet(PRESENTATION_ID, PT_INTEGER))
430 presId = attrParam->GetInt(PRESENTATION_ID);
431 if (!attrParam->IsSet(PRESENTATION_TYPE, PT_STRING))
433 type = attrParam->GetString(PRESENTATION_TYPE);
438 MEDModule::onClick(const QModelIndex & index)
441 std::string name, type;
442 if (!itemClickGeneric(name, type, presId))
444 // Not a presentation - clear widget:
445 emit presentationSelected(-1, QString(""), QString(""));
449 // STDLOG("Presentation selection");
450 // std::ostringstream oss;
451 // oss << fieldId << " / " << presId;
452 // STDLOG(" - Field id / pres id: " + oss.str());
453 // STDLOG(" - Presentation type: " + type);
454 // STDLOG(" - Presentation name: " + name);
456 emit presentationSelected(presId, QString::fromStdString(type), QString::fromStdString(name) ); // caught by PresentationController
460 MEDModule::onDblClick(const QModelIndex& index)
463 std::string name, type;
464 if (!itemClickGeneric(name, type, presId))
467 // STDLOG("Presentation double click");
468 // STDLOG(" Presentation infos:");
469 // STDLOG(" - Component: " + item->componentDataType().toStdString());
470 // STDLOG(" - Item entry: " + item->entry().toStdString());
471 // STDLOG(" - Item name: " + item->name().toStdString());
472 // std::ostringstream oss;
474 // STDLOG(" - Field id: " + oss.str());
475 // STDLOG(" - Presentation name: " + name);
479 MEDModule::requestSALOMETermination() const
481 STDLOG("Requesting SALOME termination!!");
482 SUIT_Session::session()->closeSession( SUIT_Session::DONT_SAVE, 1 ); // killServers = True
486 //bool MEDModule::hasMainEventLoopStarted() const
488 // return _eventLoopStarted;