1 // Copyright (C) 2007-2021 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>
25 #include "MEDCALCGUI_Displayer.hxx"
27 #include "SALOME_LifeCycleCORBA.hxx"
28 #include "QtxPopupMgr.h"
29 #include <QtxInfoPanel.h>
31 #include <LightApp_Preferences.h>
32 #include <SUIT_Desktop.h>
33 #include <SUIT_ResourceMgr.h>
34 #include <SUIT_Session.h>
35 #include <SUIT_DataBrowser.h>
36 #include <SalomeApp_Study.h>
37 #include <SalomeApp_DataObject.h>
38 #include <SalomeApp_DataModel.h>
39 #include <SUIT_ViewManager.h>
40 #include <SUIT_ViewWindow.h>
42 #include <SALOMEconfig.h>
43 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
44 #include <SALOMEDS_SObject.hxx>
45 #include <SALOMEDS_Study.hxx>
47 #ifndef DISABLE_PVVIEWER
48 #include <PVViewer_ViewModel.h>
49 #include <PVViewer_GUIElements.h>
52 #include "MEDFactoryClient.hxx"
53 #include "MEDPresentationManager_i.hxx"
54 #include "MED_Component_Generator.hxx"
59 #include <pqAnimationManager.h>
60 #include <pqPVApplicationCore.h>
61 #include <pqAnimationScene.h>
62 #include <pqActiveObjects.h>
65 //! The only instance of the reference to engine
66 MED_ORB::MED_Gen_var MEDModule::_MED_engine;
68 MEDModule::MEDModule() :
69 SalomeApp_Module("FIELDS"), _studyEditor(0),
70 _datasourceController(0), _workspaceController(0), _presentationController(0),
71 _processingController(0), _pvGuiElements(0),
73 _enableVisibilityStateUpdate(true)
75 STDLOG("MEDModule::MEDModule()");
76 // Note also that we can't use the getApp() function here because
77 // the initialize(...) function has not been called yet.
79 init(); // internal initialization
82 MEDModule::~MEDModule()
85 STDLOG("MEDModule::~MEDModule(): cleaning up engine side.");
86 _MED_engine->cleanUp();
87 MEDFactoryClient::getFactory()->getPresentationManager()->cleanUp();
88 MEDFactoryClient::getFactory()->getDataManager()->cleanUp();
92 if (_datasourceController)
93 delete _datasourceController;
94 //if (_workspaceController)
95 // delete _workspaceController;
96 if (_presentationController)
97 delete _presentationController;
98 if (_processingController)
99 delete _processingController;
105 init(); // initialize engine, if necessary
112 // initialize FIELDS module engine (load, if necessary)
113 Engines::EngineComponent_var comp;
114 if ( CORBA::is_nil( _MED_engine ) ) {
115 SALOME_NamingService_Abstract *ns = SalomeApp_Application::namingService();
116 if( dynamic_cast<SALOME_NamingService *>(ns) )
118 comp = SalomeApp_Application::lcc()->FindOrLoad_Component( "FactoryServer", "FIELDS" );
122 comp = RetrieveMEDInstance();
123 CORBA::Object_var comp2 = CORBA::Object::_narrow(comp);
124 KERNEL::RegisterCompo("FIELDS",comp2);
126 _MED_engine = MED_ORB::MED_Gen::_narrow( comp );
127 if (CORBA::is_nil( _MED_engine )) {
128 STDLOG("Could not narrow FIELDS engine");
133 //void MEDModule::onEventLoopStarted()
135 // if(!getApp()->isMainEventLoopStarted())
137 // QTimer::singleShot(100, this, SLOT(onEventLoopStarted()));
143 MEDModule::initialize( CAM_Application* app )
145 STDLOG("MEDModule::initialize()");
146 // call the parent implementation
147 SalomeApp_Module::initialize( app );
149 if (! getApp()->objectBrowser())
150 getApp()->getWindow(SalomeApp_Application::WT_ObjectBrowser);
152 // rnv: #20430 [CEA 20428] FIELDS : improvement of simplified visualisations:
153 // Disable auto expanding
154 //getApp()->objectBrowser()->setAutoOpenLevel(5);
156 if (app && app->desktop()) {
157 connect((QObject*) (getApp()->objectBrowser()->treeView()), SIGNAL(doubleClicked(const QModelIndex&)),
158 this, SLOT(onDblClick(const QModelIndex&)));
159 connect((QObject*) (getApp()->objectBrowser()->treeView()), SIGNAL(clicked(const QModelIndex&)),
160 this, SLOT(onClick(const QModelIndex&)));
163 // The following initializes the GUI widget and associated actions
164 this->createModuleWidgets();
165 this->createModuleActions();
167 // Now that the workspace controller is created, ParaView core application has normally been started,
168 // and hidden GUI elements have been created. We can fire the VCR toolbar activation:
173 MEDModule::engineIOR() const
175 init(); // initialize engine, if necessary
176 CORBA::String_var anIOR = getApp()->orb()->object_to_string( _MED_engine.in() );
177 return QString( anIOR.in() );
181 MEDModule::iconName() const
183 return tr("ICO_MED_SMALL");
187 MEDModule::windows( QMap<int, int>& theMap ) const
189 STDLOG("MEDModule::windows()");
190 // want Object browser, in the left area
191 theMap.insert( SalomeApp_Application::WT_ObjectBrowser,
192 Qt::LeftDockWidgetArea );
193 // help windows in the right area
194 theMap.insert( SalomeApp_Application::WT_InfoPanel, Qt::RightDockWidgetArea);
195 #ifndef DISABLE_PYCONSOLE
196 // want Python console, in the bottom area
197 theMap.insert( SalomeApp_Application::WT_PyConsole,
198 Qt::BottomDockWidgetArea );
203 MEDModule::viewManagers( QStringList& list ) const
205 #ifndef DISABLE_PVVIEWER
206 list.append( PVViewer_Viewer::Type() );
211 MEDModule::createPreferences()
213 int genTab = addPreference(tr("PREF_TAB_GENERAL"));
215 int themeGroup = addPreference(tr("PREF_THEME_GROUP"), genTab);
216 setPreferenceProperty(themeGroup, "columns", 2);
217 int icons = addPreference(tr("PREF_ICONS"), themeGroup, LightApp_Preferences::Selector, "MEDCalc", "icons" );
218 QStringList iconsThemes;
219 iconsThemes.append(tr("PREF_ICON_THEME_MODERN"));
220 iconsThemes.append(tr("PREF_ICON_THEME_CLASSIC"));
221 QList<QVariant> indices;
224 setPreferenceProperty(icons, "strings", iconsThemes);
225 setPreferenceProperty(icons, "indexes", indices);
229 MEDModule::activateModule( SUIT_Study* theStudy )
231 STDLOG("MEDModule::activateModule()");
232 if ( CORBA::is_nil( _MED_engine ) )
235 // call parent implementation
236 bool bOk = SalomeApp_Module::activateModule( theStudy );
241 setMenuShown( true );
243 setToolShown( true );
245 // Fill in Help Panel
246 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(application());
247 QtxInfoPanel* ip = app->infoPanel();
248 app->infoPanel()->setTitle(tr("HELP_WELCOME_FIELDS"));
250 // short introduction of FIEDS module
251 int gp = ip->addGroup(tr("HELP_GRP_PRESENTATION"));
252 int lp1 = ip->addLabel(tr("HELP_LABEL_PRES1"), gp);
253 int lp2 = ip->addLabel(tr("HELP_LABEL_PRES2"), gp);
254 int lp3 = ip->addLabel(tr("HELP_LABEL_PRES3"), gp);
257 // getting started Simplified Visu
258 int gv = ip->addGroup(tr("HELP_GRP_VISUALISATION"));
259 int lv1 = ip->addLabel(tr("HELP_LABEL_VISU1"), gv);
260 int av1 = ip->addAction(action(FIELDSOp::OpAddDataSource) , gv);
261 int lv2 = ip->addLabel(tr("HELP_LABEL_VISU2"), gv);
262 int lv3 = ip->addLabel(tr("HELP_LABEL_VISU3"), gv);
263 QString qs31="<ul><li>" + tr("LAB_VIEW_MODE_REPLACE") + "</li></ul>";
264 QString qs32="<ul><li>" + tr("LAB_VIEW_MODE_OVERLAP") + "</li></ul>";
265 QString qs33="<ul><li>" + tr("LAB_VIEW_MODE_NEW_LAYOUT") + "</li></ul>";
266 QString qs34="<ul><li>" + tr("LAB_VIEW_MODE_SPLIT_VIEW") + "</li></ul>";
267 int lv31 = ip->addLabel(qs31, gv);
268 int lv32 = ip->addLabel(qs32, gv);
269 int lv33 = ip->addLabel(qs33, gv);
270 int lv34 = ip->addLabel(qs34, gv);
271 int lv4 = ip->addLabel(tr("HELP_LABEL_VISU4"), gv);
272 int av2 = ip->addAction(action(FIELDSOp::OpScalarMap) , gv);
273 int av3 = ip->addAction(action(FIELDSOp::OpContour) , gv);
274 int av4 = ip->addAction(action(FIELDSOp::OpVectorFields) , gv);
275 int av5 = ip->addAction(action(FIELDSOp::OpSlices) , gv);
276 int av6 = ip->addAction(action(FIELDSOp::OpDeflectionShape) , gv);
277 int av7 = ip->addAction(action(FIELDSOp::OpPointSprite) , gv);
278 int av8 = ip->addAction(action(FIELDSOp::OpPlot3D) , gv);
279 int av9 = ip->addAction(action(FIELDSOp::OpStreamLines) , gv);
280 int av10 = ip->addAction(action(FIELDSOp::OpCutSegment) , gv);
282 // getting started interpolation
283 int gi = ip->addGroup(tr("HELP_GRP_INTERPOLATION"));
284 int li1 = ip->addLabel(tr("HELP_LABEL_INTERP1"), gi);
285 int li2 = ip->addLabel(tr("HELP_LABEL_INTERP2"), gi);
286 int li3 = ip->addLabel(tr("HELP_LABEL_INTERP3"), gi);
287 int ai1 = ip->addAction(action(FIELDSOp::OpProcessingInterpolation) , gi);
288 int li4 = ip->addLabel(tr("HELP_LABEL_INTERP4"), gi);
292 //this->createStudyComponent(theStudy);
293 _workspaceController->showDockWidgets(true);
294 _presentationController->showDockWidgets(true);
295 //this->setDockLayout(StandardApp_Module::DOCKLAYOUT_LEFT_VLARGE);
297 // Mark the start of the main event loop - important for test playback:
298 // QObject::connect(getApp(), SIGNAL(activated(SUIT_Application *)), this, SLOT(onEventLoopStarted(SUIT_Application *)));
299 // QTimer::singleShot(0, this, SLOT(onEventLoopStarted()));
301 // return the activation status
303 QObject::connect(&pqActiveObjects::instance(), SIGNAL(viewChanged(pqView*)), this,
304 SLOT(onViewChanged()), Qt::QueuedConnection);
310 MEDModule::deactivateModule( SUIT_Study* theStudy )
312 STDLOG("MEDModule::deactivateModule()");
313 _workspaceController->showDockWidgets(false);
314 _presentationController->showDockWidgets(false);
315 //this->unsetDockLayout();
318 setMenuShown( false );
320 setToolShown( false );
322 // call parent implementation and return the activation status
323 return SalomeApp_Module::deactivateModule( theStudy );
327 // =====================================================================
328 // This part add custom widgets (a dockwidget containing a tree view
329 // in this example) and add special actions in the toolbox of the
331 // =====================================================================
335 * This function implements the interface StandardApp_Module. It
336 * creates the widgets specific for this module, in particular the
337 * workspace widget and the dataspace widget.
340 MEDModule::createModuleWidgets() {
341 _studyEditor = new SALOME_AppStudyEditor(getApp());
342 _datasourceController = new DatasourceController(this);
343 _workspaceController = new WorkspaceController(this);
344 _xmedDataModel = new XmedDataModel();
345 _workspaceController->setDataModel(_xmedDataModel);
346 _presentationController = new PresentationController(this);
347 // ABN: ultimately console driver should be owned by module: everyone needs it, not only WorkspaceController
348 _presentationController->setConsoleDriver(_workspaceController->getConsoleDriver());
349 _processingController = new ProcessingController(this);
350 #ifdef MED_HAS_QTTESTING
351 _testController = new TestController(this);
354 connect(_datasourceController, SIGNAL(datasourceSignal(const DatasourceEvent*)),
355 _workspaceController, SLOT(processDatasourceEvent(const DatasourceEvent*)));
357 connect(_presentationController, SIGNAL(presentationSignal(const PresentationEvent*)),
358 _presentationController, SLOT(processPresentationEvent(const PresentationEvent*)));
360 connect(_processingController, SIGNAL(processingSignal(const ProcessingEvent*)),
361 _workspaceController, SLOT(processProcessingEvent(const ProcessingEvent*)));
363 connect(_workspaceController, SIGNAL(workspaceSignal(const MEDCALC::MedEvent*)),
364 _datasourceController, SLOT(processWorkspaceEvent(const MEDCALC::MedEvent*)));
366 connect(_workspaceController, SIGNAL(workspaceSignal(const MEDCALC::MedEvent*)),
367 _presentationController, SLOT(processWorkspaceEvent(const MEDCALC::MedEvent*)));
369 connect(&pqActiveObjects::instance(), &pqActiveObjects::viewChanged, [this](pqView* view) { this->updateVisibilityState(); });
374 void MEDModule::updateVisibilityState(const bool all, const QStringList& entries)
376 if (!_enableVisibilityStateUpdate) {
379 QStringList allPrsEntries = QStringList();
380 const QStringList& workList = ( all ? allPrsEntries : entries );
382 SALOMEDS::Study_var aStudy = KERNEL::getStudyServant();
383 if (aStudy->_is_nil())
385 SALOMEDS::SComponent_var father = aStudy->FindComponent("FIELDS");
386 if (father->_is_nil())
388 SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(father);
389 SALOMEDS::GenericAttribute_var anAttribute;
390 for (it->InitEx(true); it->More(); it->Next())
392 SALOMEDS::SObject_var child(it->Value());
393 if (child->FindAttribute(anAttribute, "AttributeParameter"))
395 SALOMEDS::AttributeParameter_var attrParam = SALOMEDS::AttributeParameter::_narrow(anAttribute);
396 if (!attrParam->IsSet(IS_PRESENTATION, PT_BOOLEAN) || !attrParam->GetBool(IS_PRESENTATION) || !attrParam->IsSet(PRESENTATION_ID, PT_INTEGER))
398 allPrsEntries.append(child->GetID());
403 // update visibility state of objects
404 LightApp_Application* app = dynamic_cast<LightApp_Application*>(SUIT_Session::session()->activeApplication());
407 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
410 SUIT_Study* activeStudy = app->activeStudy();
413 SUIT_ViewWindow* aViewWindow = app->desktop()->activeWindow();
416 SUIT_ViewManager* aViewManager = aViewWindow->getViewManager();
420 SUIT_ViewModel * aViewModel = aViewManager->getViewModel();
421 DataObjectList aList;
422 for(const auto& str : workList) {
423 aList.append(appStudy->findObjectByEntry(str));
425 app->updateVisibilityState(aList, aViewModel);
430 MEDModule::initToolbars()
432 // VCR and Time toolbars:
433 SUIT_Desktop* dsk = getApp()->desktop();
434 _pvGuiElements = PVViewer_GUIElements::GetInstance(dsk);
436 _pvGuiElements->getVCRToolbar(); // make sure VCR toolbar is built
437 _pvGuiElements->setToolBarVisible(false);
438 _pvGuiElements->setVCRTimeToolBarVisible(true);
440 // Emit signal in order to make sure that animation scene is set - same trick as in PARAVIS module activation
441 QMetaObject::invokeMethod( pqPVApplicationCore::instance()->animationManager(),
442 "activeSceneChanged",
443 Q_ARG( pqAnimationScene*, pqPVApplicationCore::instance()->animationManager()->getActiveScene() ) );
445 #ifdef MED_HAS_QTTESTING
446 connect(_workspaceController, SIGNAL(workspaceSignal(const MEDCALC::MedEvent*)),
447 _testController, SLOT(processWorkspaceEvent(const MEDCALC::MedEvent*)));
452 MEDModule::getCurrentAnimationTimestamp()
454 double timestamp = pqPVApplicationCore::instance()->animationManager()->getActiveScene()->getAnimationTime();
459 MEDModule::createModuleActions() {
460 _datasourceController->createActions();
461 _workspaceController->createActions();
462 _presentationController->createActions();
463 _processingController->createActions();
464 #ifdef MED_HAS_QTTESTING
465 _testController->createActions();
470 MEDModule::createStandardAction(const QString& label,
472 const char* slotmember,
473 const QString& iconName,
474 const QString& tooltip,
477 SUIT_Desktop* dsk = getApp()->desktop();
478 SUIT_ResourceMgr* resMgr = getApp()->resourceMgr();
480 // If the tooltip is not defined, we choose instead the label text.
481 QString effToolTip(tooltip);
482 if ( effToolTip.isEmpty() )
486 if (iconName.isEmpty())
489 ico = QIcon(resMgr->loadPixmap("FIELDS", iconName));
491 QAction* action = createAction(actionid,
502 return actionId(action);
506 MEDModule::addActionInPopupMenu(int actionId,const QString& menus,const QString& rule)
508 // _GBO_ for a fine customization of the rule (for example with a
509 // test on the type of the selected object), see the LIGHT module:
510 // implement "LightApp_Selection* createSelection() const;"
512 QtxPopupMgr* mgr = this->popupMgr();
513 this->action( actionId )->setIconVisibleInMenu(true);
514 if (! menus.isEmpty())
515 mgr->insert ( this->action( actionId ), menus, parentId, 0 );
517 mgr->insert ( this->action( actionId ), parentId, 0 );
518 mgr->setRule( this->action( actionId ), rule, QtxPopupMgr::VisibleRule );
521 //MEDCALC::ViewModeType
522 //MEDModule::getSelectedViewMode() const
524 // return _presentationController->getSelectedViewMode();
527 //MEDCALC::ColorMapType
528 //MEDModule::getSelectedColorMap() const
530 // return _presentationController->getSelectedColorMap();
533 //MEDCALC::ScalarBarRangeType
534 //MEDModule::getSelectedScalarBarRange() const
536 // return _presentationController->getSelectedScalarBarRange();
541 * Returns presentation name, type and ID from the currently selected presentation in the object
545 MEDModule::itemClickGeneric(std::string & name, std::string & type, int & presId) const
547 DataObjectList dol = getApp()->objectBrowser()->getSelected();
550 SalomeApp_DataObject* item = dynamic_cast<SalomeApp_DataObject*>(dol[0]);
553 SalomeApp_DataModel *model = dynamic_cast<SalomeApp_DataModel*>(dataModel());
557 if (item->componentDataType().toStdString() != "FIELDS")
559 _PTR(SObject) obj = item->object();
560 _PTR(GenericAttribute) anAttribute;
562 if (! obj->FindAttribute(anAttribute, "AttributeName"))
564 _PTR(AttributeName) attrName(anAttribute);
565 name = attrName->Value();
567 if (! obj->FindAttribute(anAttribute, "AttributeParameter"))
569 _PTR(AttributeParameter) attrParam(anAttribute);
570 if (! attrParam->IsSet(IS_PRESENTATION, PT_BOOLEAN)
571 || ! attrParam->GetBool(IS_PRESENTATION)) { // Not a presentation
574 // if (!attrParam->IsSet(FIELD_ID, PT_INTEGER))
576 // fieldId = attrParam->GetInt(FIELD_ID);
577 if (!attrParam->IsSet(PRESENTATION_ID, PT_INTEGER))
579 presId = attrParam->GetInt(PRESENTATION_ID);
580 if (!attrParam->IsSet(PRESENTATION_TYPE, PT_STRING))
582 type = attrParam->GetString(PRESENTATION_TYPE);
587 MEDModule::onClick(const QModelIndex & /*index*/)
590 std::string name, type;
591 if (!itemClickGeneric(name, type, presId))
593 // Not a presentation - clear widget:
594 emit presentationSelected(-1, QString(""), QString(""));
598 // STDLOG("Presentation selection");
599 // std::ostringstream oss;
600 // oss << fieldId << " / " << presId;
601 // STDLOG(" - Field id / pres id: " + oss.str());
602 // STDLOG(" - Presentation type: " + type);
603 // STDLOG(" - Presentation name: " + name);
605 emit presentationSelected(presId, QString::fromStdString(type), QString::fromStdString(name) ); // caught by PresentationController
609 MEDModule::onDblClick(const QModelIndex& /*index*/)
612 std::string name, type;
613 if (!itemClickGeneric(name, type, presId))
616 // STDLOG("Presentation double click");
617 // STDLOG(" Presentation infos:");
618 // STDLOG(" - Component: " + item->componentDataType().toStdString());
619 // STDLOG(" - Item entry: " + item->entry().toStdString());
620 // STDLOG(" - Item name: " + item->name().toStdString());
621 // std::ostringstream oss;
623 // STDLOG(" - Field id: " + oss.str());
624 // STDLOG(" - Presentation name: " + name);
628 MEDModule::requestSALOMETermination() const
630 STDLOG("Requesting SALOME termination!!");
631 SUIT_Session::session()->closeSession( SUIT_Session::DONT_SAVE, 1 ); // killServers = True
635 //bool MEDModule::hasMainEventLoopStarted() const
637 // return _eventLoopStarted;
641 MEDModule::getIntParamFromStudyEditor(SALOMEDS::SObject_var obj, const char* name)
646 SALOMEDS::GenericAttribute_var anAttr;
647 SALOMEDS::AttributeParameter_var aParam;
648 if ( obj->FindAttribute(anAttr,"AttributeParameter") ) {
649 aParam = SALOMEDS::AttributeParameter::_narrow(anAttr);
650 if (aParam->IsSet(name, PT_INTEGER))
651 return aParam->GetInt(name);
656 LightApp_Displayer* MEDModule::displayer()
659 _displayer = new MEDCALCGUI_Displayer(_presentationController);
663 void MEDModule::visibilityStateUpdateOff() {
664 _enableVisibilityStateUpdate = false;
666 void MEDModule::visibilityStateUpdateOn() {
667 _enableVisibilityStateUpdate = true;