1 // Copyright (C) 2007-2020 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"
28 #include <QtxInfoPanel.h>
30 #include <LightApp_Preferences.h>
31 #include <SUIT_Desktop.h>
32 #include <SUIT_ResourceMgr.h>
33 #include <SUIT_Session.h>
34 #include <SUIT_DataBrowser.h>
35 #include <SalomeApp_Study.h>
36 #include <SalomeApp_DataObject.h>
37 #include <SalomeApp_DataModel.h>
39 #include <SALOMEconfig.h>
40 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
41 #include <SALOMEDS_SObject.hxx>
42 #include <SALOMEDS_Study.hxx>
44 #ifndef DISABLE_PVVIEWER
45 #include <PVViewer_ViewModel.h>
46 #include <PVViewer_GUIElements.h>
49 #include "MEDFactoryClient.hxx"
50 #include "MEDPresentationManager_i.hxx"
55 #include <pqAnimationManager.h>
56 #include <pqPVApplicationCore.h>
57 #include <pqAnimationScene.h>
59 //! The only instance of the reference to engine
60 MED_ORB::MED_Gen_var MEDModule::_MED_engine;
62 MEDModule::MEDModule() :
63 SalomeApp_Module("FIELDS"), _studyEditor(0),
64 _datasourceController(0), _workspaceController(0), _presentationController(0),
65 _processingController(0), _pvGuiElements(0)
67 STDLOG("MEDModule::MEDModule()");
68 // Note also that we can't use the getApp() function here because
69 // the initialize(...) function has not been called yet.
71 init(); // internal initialization
74 MEDModule::~MEDModule()
77 STDLOG("MEDModule::~MEDModule(): cleaning up engine side.");
78 _MED_engine->cleanUp();
79 MEDFactoryClient::getFactory()->getPresentationManager()->cleanUp();
80 MEDFactoryClient::getFactory()->getDataManager()->cleanUp();
84 if (_datasourceController)
85 delete _datasourceController;
86 //if (_workspaceController)
87 // delete _workspaceController;
88 if (_presentationController)
89 delete _presentationController;
90 if (_processingController)
91 delete _processingController;
97 init(); // initialize engine, if necessary
104 // initialize FIELDS module engine (load, if necessary)
105 if ( CORBA::is_nil( _MED_engine ) ) {
106 Engines::EngineComponent_var comp =
107 SalomeApp_Application::lcc()->FindOrLoad_Component( "FactoryServer", "FIELDS" );
108 if (CORBA::is_nil( comp )) {
109 STDLOG("Could not FindOrLoad_Component FIELDS");
111 _MED_engine = MED_ORB::MED_Gen::_narrow( comp );
112 if (CORBA::is_nil( _MED_engine )) {
113 STDLOG("Could not narrow FIELDS engine");
118 //void MEDModule::onEventLoopStarted()
120 // if(!getApp()->isMainEventLoopStarted())
122 // QTimer::singleShot(100, this, SLOT(onEventLoopStarted()));
128 MEDModule::initialize( CAM_Application* app )
130 STDLOG("MEDModule::initialize()");
131 // call the parent implementation
132 SalomeApp_Module::initialize( app );
134 if (! getApp()->objectBrowser())
135 getApp()->getWindow(SalomeApp_Application::WT_ObjectBrowser);
137 getApp()->objectBrowser()->setAutoOpenLevel(5);
139 if (app && app->desktop()) {
140 connect((QObject*) (getApp()->objectBrowser()->treeView()), SIGNAL(doubleClicked(const QModelIndex&)),
141 this, SLOT(onDblClick(const QModelIndex&)));
142 connect((QObject*) (getApp()->objectBrowser()->treeView()), SIGNAL(clicked(const QModelIndex&)),
143 this, SLOT(onClick(const QModelIndex&)));
146 // The following initializes the GUI widget and associated actions
147 this->createModuleWidgets();
148 this->createModuleActions();
150 // Now that the workspace controller is created, ParaView core application has normally been started,
151 // and hidden GUI elements have been created. We can fire the VCR toolbar activation:
156 MEDModule::engineIOR() const
158 init(); // initialize engine, if necessary
159 CORBA::String_var anIOR = getApp()->orb()->object_to_string( _MED_engine.in() );
160 return QString( anIOR.in() );
164 MEDModule::iconName() const
166 return tr("ICO_MED_SMALL");
170 MEDModule::windows( QMap<int, int>& theMap ) const
172 STDLOG("MEDModule::windows()");
173 // want Object browser, in the left area
174 theMap.insert( SalomeApp_Application::WT_ObjectBrowser,
175 Qt::LeftDockWidgetArea );
176 // help windows in the right area
177 theMap.insert( SalomeApp_Application::WT_InfoPanel, Qt::RightDockWidgetArea);
178 #ifndef DISABLE_PYCONSOLE
179 // want Python console, in the bottom area
180 theMap.insert( SalomeApp_Application::WT_PyConsole,
181 Qt::BottomDockWidgetArea );
186 MEDModule::viewManagers( QStringList& list ) const
188 #ifndef DISABLE_PVVIEWER
189 list.append( PVViewer_Viewer::Type() );
194 MEDModule::createPreferences()
196 int genTab = addPreference(tr("PREF_TAB_GENERAL"));
198 int themeGroup = addPreference(tr("PREF_THEME_GROUP"), genTab);
199 setPreferenceProperty(themeGroup, "columns", 2);
200 int icons = addPreference(tr("PREF_ICONS"), themeGroup, LightApp_Preferences::Selector, "MEDCalc", "icons" );
201 QStringList iconsThemes;
202 iconsThemes.append(tr("PREF_ICON_THEME_MODERN"));
203 iconsThemes.append(tr("PREF_ICON_THEME_CLASSIC"));
204 QList<QVariant> indices;
207 setPreferenceProperty(icons, "strings", iconsThemes);
208 setPreferenceProperty(icons, "indexes", indices);
212 MEDModule::activateModule( SUIT_Study* theStudy )
214 STDLOG("MEDModule::activateModule()");
215 if ( CORBA::is_nil( _MED_engine ) )
218 // call parent implementation
219 bool bOk = SalomeApp_Module::activateModule( theStudy );
224 setMenuShown( true );
226 setToolShown( true );
228 // Fill in Help Panel
229 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(application());
230 QtxInfoPanel* ip = app->infoPanel();
231 app->infoPanel()->setTitle(tr("HELP_WELCOME_FIELDS"));
233 // short introduction of FIEDS module
234 int gp = ip->addGroup(tr("HELP_GRP_PRESENTATION"));
235 int lp1 = ip->addLabel(tr("HELP_LABEL_PRES1"), gp);
236 int lp2 = ip->addLabel(tr("HELP_LABEL_PRES2"), gp);
237 int lp3 = ip->addLabel(tr("HELP_LABEL_PRES3"), gp);
240 // getting started Simplified Visu
241 int gv = ip->addGroup(tr("HELP_GRP_VISUALISATION"));
242 int lv1 = ip->addLabel(tr("HELP_LABEL_VISU1"), gv);
243 int av1 = ip->addAction(action(FIELDSOp::OpAddDataSource) , gv);
244 int lv2 = ip->addLabel(tr("HELP_LABEL_VISU2"), gv);
245 int lv3 = ip->addLabel(tr("HELP_LABEL_VISU3"), gv);
246 QString qs31="<ul><li>" + tr("LAB_VIEW_MODE_REPLACE") + "</li></ul>";
247 QString qs32="<ul><li>" + tr("LAB_VIEW_MODE_OVERLAP") + "</li></ul>";
248 QString qs33="<ul><li>" + tr("LAB_VIEW_MODE_NEW_LAYOUT") + "</li></ul>";
249 QString qs34="<ul><li>" + tr("LAB_VIEW_MODE_SPLIT_VIEW") + "</li></ul>";
250 int lv31 = ip->addLabel(qs31, gv);
251 int lv32 = ip->addLabel(qs32, gv);
252 int lv33 = ip->addLabel(qs33, gv);
253 int lv34 = ip->addLabel(qs34, gv);
254 int lv4 = ip->addLabel(tr("HELP_LABEL_VISU4"), gv);
255 int av2 = ip->addAction(action(FIELDSOp::OpScalarMap) , gv);
256 int av3 = ip->addAction(action(FIELDSOp::OpContour) , gv);
257 int av4 = ip->addAction(action(FIELDSOp::OpVectorFields) , gv);
258 int av5 = ip->addAction(action(FIELDSOp::OpSlices) , gv);
259 int av6 = ip->addAction(action(FIELDSOp::OpDeflectionShape) , gv);
260 int av7 = ip->addAction(action(FIELDSOp::OpPointSprite) , gv);
262 // getting started interpolation
263 int gi = ip->addGroup(tr("HELP_GRP_INTERPOLATION"));
264 int li1 = ip->addLabel(tr("HELP_LABEL_INTERP1"), gi);
265 int li2 = ip->addLabel(tr("HELP_LABEL_INTERP2"), gi);
266 int li3 = ip->addLabel(tr("HELP_LABEL_INTERP3"), gi);
267 int ai1 = ip->addAction(action(FIELDSOp::OpProcessingInterpolation) , gi);
268 int li4 = ip->addLabel(tr("HELP_LABEL_INTERP4"), gi);
272 //this->createStudyComponent(theStudy);
273 _workspaceController->showDockWidgets(true);
274 _presentationController->showDockWidgets(true);
275 //this->setDockLayout(StandardApp_Module::DOCKLAYOUT_LEFT_VLARGE);
277 // Mark the start of the main event loop - important for test playback:
278 // QObject::connect(getApp(), SIGNAL(activated(SUIT_Application *)), this, SLOT(onEventLoopStarted(SUIT_Application *)));
279 // QTimer::singleShot(0, this, SLOT(onEventLoopStarted()));
281 // return the activation status
286 MEDModule::deactivateModule( SUIT_Study* theStudy )
288 STDLOG("MEDModule::deactivateModule()");
289 _workspaceController->showDockWidgets(false);
290 _presentationController->showDockWidgets(false);
291 //this->unsetDockLayout();
294 setMenuShown( false );
296 setToolShown( false );
298 // call parent implementation and return the activation status
299 return SalomeApp_Module::deactivateModule( theStudy );
303 // =====================================================================
304 // This part add custom widgets (a dockwidget containing a tree view
305 // in this example) and add special actions in the toolbox of the
307 // =====================================================================
311 * This function implements the interface StandardApp_Module. It
312 * creates the widgets specific for this module, in particular the
313 * workspace widget and the dataspace widget.
316 MEDModule::createModuleWidgets() {
317 _studyEditor = new SALOME_AppStudyEditor(getApp());
318 _datasourceController = new DatasourceController(this);
319 _workspaceController = new WorkspaceController(this);
320 _xmedDataModel = new XmedDataModel();
321 _workspaceController->setDataModel(_xmedDataModel);
322 _presentationController = new PresentationController(this);
323 // ABN: ultimately console driver should be owned by module: everyone needs it, not only WorkspaceController
324 _presentationController->setConsoleDriver(_workspaceController->getConsoleDriver());
325 _processingController = new ProcessingController(this);
326 #ifdef MED_HAS_QTTESTING
327 _testController = new TestController(this);
330 connect(_datasourceController, SIGNAL(datasourceSignal(const DatasourceEvent*)),
331 _workspaceController, SLOT(processDatasourceEvent(const DatasourceEvent*)));
333 connect(_presentationController, SIGNAL(presentationSignal(const PresentationEvent*)),
334 _presentationController, SLOT(processPresentationEvent(const PresentationEvent*)));
336 connect(_processingController, SIGNAL(processingSignal(const ProcessingEvent*)),
337 _workspaceController, SLOT(processProcessingEvent(const ProcessingEvent*)));
339 connect(_workspaceController, SIGNAL(workspaceSignal(const MEDCALC::MedEvent*)),
340 _datasourceController, SLOT(processWorkspaceEvent(const MEDCALC::MedEvent*)));
342 connect(_workspaceController, SIGNAL(workspaceSignal(const MEDCALC::MedEvent*)),
343 _presentationController, SLOT(processWorkspaceEvent(const MEDCALC::MedEvent*)));
347 MEDModule::initToolbars()
349 // VCR and Time toolbars:
350 SUIT_Desktop* dsk = getApp()->desktop();
351 _pvGuiElements = PVViewer_GUIElements::GetInstance(dsk);
353 _pvGuiElements->getVCRToolbar(); // make sure VCR toolbar is built
354 _pvGuiElements->setToolBarVisible(false);
355 _pvGuiElements->setVCRTimeToolBarVisible(true);
357 // Emit signal in order to make sure that animation scene is set - same trick as in PARAVIS module activation
358 QMetaObject::invokeMethod( pqPVApplicationCore::instance()->animationManager(),
359 "activeSceneChanged",
360 Q_ARG( pqAnimationScene*, pqPVApplicationCore::instance()->animationManager()->getActiveScene() ) );
362 #ifdef MED_HAS_QTTESTING
363 connect(_workspaceController, SIGNAL(workspaceSignal(const MEDCALC::MedEvent*)),
364 _testController, SLOT(processWorkspaceEvent(const MEDCALC::MedEvent*)));
369 MEDModule::getCurrentAnimationTimestamp()
371 double timestamp = pqPVApplicationCore::instance()->animationManager()->getActiveScene()->getAnimationTime();
376 MEDModule::createModuleActions() {
377 _datasourceController->createActions();
378 _workspaceController->createActions();
379 _presentationController->createActions();
380 _processingController->createActions();
381 #ifdef MED_HAS_QTTESTING
382 _testController->createActions();
387 MEDModule::createStandardAction(const QString& label,
389 const char* slotmember,
390 const QString& iconName,
391 const QString& tooltip,
394 SUIT_Desktop* dsk = getApp()->desktop();
395 SUIT_ResourceMgr* resMgr = getApp()->resourceMgr();
397 // If the tooltip is not defined, we choose instead the label text.
398 QString effToolTip(tooltip);
399 if ( effToolTip.isEmpty() )
403 if (iconName.isEmpty())
406 ico = QIcon(resMgr->loadPixmap("FIELDS", iconName));
408 QAction* action = createAction(actionid,
419 return actionId(action);
423 MEDModule::addActionInPopupMenu(int actionId,const QString& menus,const QString& rule)
425 // _GBO_ for a fine customization of the rule (for example with a
426 // test on the type of the selected object), see the LIGHT module:
427 // implement "LightApp_Selection* createSelection() const;"
429 QtxPopupMgr* mgr = this->popupMgr();
430 this->action( actionId )->setIconVisibleInMenu(true);
431 if (! menus.isEmpty())
432 mgr->insert ( this->action( actionId ), menus, parentId, 0 );
434 mgr->insert ( this->action( actionId ), parentId, 0 );
435 mgr->setRule( this->action( actionId ), rule, QtxPopupMgr::VisibleRule );
438 //MEDCALC::ViewModeType
439 //MEDModule::getSelectedViewMode() const
441 // return _presentationController->getSelectedViewMode();
444 //MEDCALC::ColorMapType
445 //MEDModule::getSelectedColorMap() const
447 // return _presentationController->getSelectedColorMap();
450 //MEDCALC::ScalarBarRangeType
451 //MEDModule::getSelectedScalarBarRange() const
453 // return _presentationController->getSelectedScalarBarRange();
458 * Returns presentation name, type and ID from the currently selected presentation in the object
462 MEDModule::itemClickGeneric(std::string & name, std::string & type, int & presId) const
464 DataObjectList dol = getApp()->objectBrowser()->getSelected();
467 SalomeApp_DataObject* item = dynamic_cast<SalomeApp_DataObject*>(dol[0]);
470 SalomeApp_DataModel *model = dynamic_cast<SalomeApp_DataModel*>(dataModel());
474 if (item->componentDataType().toStdString() != "FIELDS")
476 _PTR(SObject) obj = item->object();
477 _PTR(GenericAttribute) anAttribute;
479 if (! obj->FindAttribute(anAttribute, "AttributeName"))
481 _PTR(AttributeName) attrName(anAttribute);
482 name = attrName->Value();
484 if (! obj->FindAttribute(anAttribute, "AttributeParameter"))
486 _PTR(AttributeParameter) attrParam(anAttribute);
487 if (! attrParam->IsSet(IS_PRESENTATION, PT_BOOLEAN)
488 || ! attrParam->GetBool(IS_PRESENTATION)) { // Not a presentation
491 // if (!attrParam->IsSet(FIELD_ID, PT_INTEGER))
493 // fieldId = attrParam->GetInt(FIELD_ID);
494 if (!attrParam->IsSet(PRESENTATION_ID, PT_INTEGER))
496 presId = attrParam->GetInt(PRESENTATION_ID);
497 if (!attrParam->IsSet(PRESENTATION_TYPE, PT_STRING))
499 type = attrParam->GetString(PRESENTATION_TYPE);
504 MEDModule::onClick(const QModelIndex & /*index*/)
507 std::string name, type;
508 if (!itemClickGeneric(name, type, presId))
510 // Not a presentation - clear widget:
511 emit presentationSelected(-1, QString(""), QString(""));
515 // STDLOG("Presentation selection");
516 // std::ostringstream oss;
517 // oss << fieldId << " / " << presId;
518 // STDLOG(" - Field id / pres id: " + oss.str());
519 // STDLOG(" - Presentation type: " + type);
520 // STDLOG(" - Presentation name: " + name);
522 emit presentationSelected(presId, QString::fromStdString(type), QString::fromStdString(name) ); // caught by PresentationController
526 MEDModule::onDblClick(const QModelIndex& /*index*/)
529 std::string name, type;
530 if (!itemClickGeneric(name, type, presId))
533 // STDLOG("Presentation double click");
534 // STDLOG(" Presentation infos:");
535 // STDLOG(" - Component: " + item->componentDataType().toStdString());
536 // STDLOG(" - Item entry: " + item->entry().toStdString());
537 // STDLOG(" - Item name: " + item->name().toStdString());
538 // std::ostringstream oss;
540 // STDLOG(" - Field id: " + oss.str());
541 // STDLOG(" - Presentation name: " + name);
545 MEDModule::requestSALOMETermination() const
547 STDLOG("Requesting SALOME termination!!");
548 SUIT_Session::session()->closeSession( SUIT_Session::DONT_SAVE, 1 ); // killServers = True
552 //bool MEDModule::hasMainEventLoopStarted() const
554 // return _eventLoopStarted;
558 MEDModule::getIntParamFromStudyEditor(SALOMEDS::SObject_var obj, const char* name)
563 SALOMEDS::GenericAttribute_var anAttr;
564 SALOMEDS::AttributeParameter_var aParam;
565 if ( obj->FindAttribute(anAttr,"AttributeParameter") ) {
566 aParam = SALOMEDS::AttributeParameter::_narrow(anAttr);
567 if (aParam->IsSet(name, PT_INTEGER))
568 return aParam->GetInt(name);