1 // Copyright (C) 2007-2023 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"
58 #include <pqAnimationManager.h>
59 #include <pqPVApplicationCore.h>
60 #include <pqAnimationScene.h>
61 #include <pqActiveObjects.h>
64 //! The only instance of the reference to engine
65 MED_ORB::MED_Gen_var MEDModule::_MED_engine;
67 MEDModule::MEDModule() :
68 SalomeApp_Module("FIELDS"), _studyEditor(0),
69 _datasourceController(0), _workspaceController(0), _presentationController(0),
70 _processingController(0), _pvGuiElements(0),
72 _enableVisibilityStateUpdate(true)
74 STDLOG("MEDModule::MEDModule()");
75 // Note also that we can't use the getApp() function here because
76 // the initialize(...) function has not been called yet.
78 init(); // internal initialization
81 MEDModule::~MEDModule()
84 STDLOG("MEDModule::~MEDModule(): cleaning up engine side.");
85 _MED_engine->cleanUp();
86 MEDFactoryClient::getFactory()->getPresentationManager()->cleanUp();
87 MEDFactoryClient::getFactory()->getDataManager()->cleanUp();
91 if (_datasourceController)
92 delete _datasourceController;
93 //if (_workspaceController)
94 // delete _workspaceController;
95 if (_presentationController)
96 delete _presentationController;
97 if (_processingController)
98 delete _processingController;
104 init(); // initialize engine, if necessary
111 // initialize FIELDS module engine (load, if necessary)
113 if (CORBA::is_nil(_MED_engine)) {
114 Engines::EngineComponent_var comp =
115 SalomeApp_Application::lcc()->FindOrLoad_Component("FactoryServer", "FIELDS");
116 _MED_engine = MED_ORB::MED_Gen::_narrow(comp);
118 if (CORBA::is_nil( _MED_engine )) {
119 STDLOG("Could not narrow FIELDS engine");
123 //void MEDModule::onEventLoopStarted()
125 // if(!getApp()->isMainEventLoopStarted())
127 // QTimer::singleShot(100, this, SLOT(onEventLoopStarted()));
133 MEDModule::initialize( CAM_Application* app )
135 STDLOG("MEDModule::initialize()");
136 // call the parent implementation
137 SalomeApp_Module::initialize( app );
139 if (! getApp()->objectBrowser())
140 getApp()->getWindow(SalomeApp_Application::WT_ObjectBrowser);
142 // rnv: #20430 [CEA 20428] FIELDS : improvement of simplified visualisations:
143 // Disable auto expanding
144 //getApp()->objectBrowser()->setAutoOpenLevel(5);
146 if (app && app->desktop()) {
147 connect((QObject*) (getApp()->objectBrowser()->treeView()), SIGNAL(doubleClicked(const QModelIndex&)),
148 this, SLOT(onDblClick(const QModelIndex&)));
149 connect((QObject*) (getApp()->objectBrowser()->treeView()), SIGNAL(clicked(const QModelIndex&)),
150 this, SLOT(onClick(const QModelIndex&)));
153 // The following initializes the GUI widget and associated actions
154 this->createModuleWidgets();
155 this->createModuleActions();
157 // Now that the workspace controller is created, ParaView core application has normally been started,
158 // and hidden GUI elements have been created. We can fire the VCR toolbar activation:
163 MEDModule::engineIOR() const
165 init(); // initialize engine, if necessary
166 CORBA::String_var anIOR = getApp()->orb()->object_to_string( _MED_engine.in() );
167 return QString( anIOR.in() );
171 MEDModule::iconName() const
173 return tr("ICO_MED_SMALL");
177 MEDModule::windows( QMap<int, int>& theMap ) const
179 STDLOG("MEDModule::windows()");
180 // want Object browser, in the left area
181 theMap.insert( SalomeApp_Application::WT_ObjectBrowser,
182 Qt::LeftDockWidgetArea );
183 // help windows in the right area
184 theMap.insert( SalomeApp_Application::WT_InfoPanel, Qt::RightDockWidgetArea);
185 #ifndef DISABLE_PYCONSOLE
186 // want Python console, in the bottom area
187 theMap.insert( SalomeApp_Application::WT_PyConsole,
188 Qt::BottomDockWidgetArea );
193 MEDModule::viewManagers( QStringList& list ) const
195 #ifndef DISABLE_PVVIEWER
196 list.append( PVViewer_Viewer::Type() );
201 MEDModule::createPreferences()
203 int genTab = addPreference(tr("PREF_TAB_GENERAL"));
205 int themeGroup = addPreference(tr("PREF_THEME_GROUP"), genTab);
206 setPreferenceProperty(themeGroup, "columns", 2);
207 int icons = addPreference(tr("PREF_ICONS"), themeGroup, LightApp_Preferences::Selector, "MEDCalc", "icons" );
208 QStringList iconsThemes;
209 iconsThemes.append(tr("PREF_ICON_THEME_MODERN"));
210 iconsThemes.append(tr("PREF_ICON_THEME_CLASSIC"));
211 QList<QVariant> indices;
214 setPreferenceProperty(icons, "strings", iconsThemes);
215 setPreferenceProperty(icons, "indexes", indices);
219 MEDModule::activateModule( SUIT_Study* theStudy )
221 STDLOG("MEDModule::activateModule()");
222 if ( CORBA::is_nil( _MED_engine ) )
225 // call parent implementation
226 bool bOk = SalomeApp_Module::activateModule( theStudy );
231 setMenuShown( true );
233 setToolShown( true );
235 // Fill in Help Panel
236 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(application());
237 QtxInfoPanel* ip = app->infoPanel();
238 app->infoPanel()->setTitle(tr("HELP_WELCOME_FIELDS"));
240 // short introduction of FIEDS module
241 int gp = ip->addGroup(tr("HELP_GRP_PRESENTATION"));
242 int lp1 = ip->addLabel(tr("HELP_LABEL_PRES1"), gp);
243 int lp2 = ip->addLabel(tr("HELP_LABEL_PRES2"), gp);
244 int lp3 = ip->addLabel(tr("HELP_LABEL_PRES3"), gp);
247 // getting started Simplified Visu
248 int gv = ip->addGroup(tr("HELP_GRP_VISUALISATION"));
249 int lv1 = ip->addLabel(tr("HELP_LABEL_VISU1"), gv);
250 int av1 = ip->addAction(action(FIELDSOp::OpAddDataSource) , gv);
251 int lv2 = ip->addLabel(tr("HELP_LABEL_VISU2"), gv);
252 int lv3 = ip->addLabel(tr("HELP_LABEL_VISU3"), gv);
253 QString qs31="<ul><li>" + tr("LAB_VIEW_MODE_REPLACE") + "</li></ul>";
254 QString qs32="<ul><li>" + tr("LAB_VIEW_MODE_OVERLAP") + "</li></ul>";
255 QString qs33="<ul><li>" + tr("LAB_VIEW_MODE_NEW_LAYOUT") + "</li></ul>";
256 QString qs34="<ul><li>" + tr("LAB_VIEW_MODE_SPLIT_VIEW") + "</li></ul>";
257 int lv31 = ip->addLabel(qs31, gv);
258 int lv32 = ip->addLabel(qs32, gv);
259 int lv33 = ip->addLabel(qs33, gv);
260 int lv34 = ip->addLabel(qs34, gv);
261 int lv4 = ip->addLabel(tr("HELP_LABEL_VISU4"), gv);
262 int av2 = ip->addAction(action(FIELDSOp::OpScalarMap) , gv);
263 int av3 = ip->addAction(action(FIELDSOp::OpContour) , gv);
264 int av4 = ip->addAction(action(FIELDSOp::OpVectorFields) , gv);
265 int av5 = ip->addAction(action(FIELDSOp::OpSlices) , gv);
266 int av6 = ip->addAction(action(FIELDSOp::OpDeflectionShape) , gv);
267 int av7 = ip->addAction(action(FIELDSOp::OpPointSprite) , gv);
268 int av8 = ip->addAction(action(FIELDSOp::OpPlot3D) , gv);
269 int av9 = ip->addAction(action(FIELDSOp::OpStreamLines) , gv);
270 int av10 = ip->addAction(action(FIELDSOp::OpCutSegment) , gv);
272 // getting started interpolation
273 int gi = ip->addGroup(tr("HELP_GRP_INTERPOLATION"));
274 int li1 = ip->addLabel(tr("HELP_LABEL_INTERP1"), gi);
275 int li2 = ip->addLabel(tr("HELP_LABEL_INTERP2"), gi);
276 int li3 = ip->addLabel(tr("HELP_LABEL_INTERP3"), gi);
277 int ai1 = ip->addAction(action(FIELDSOp::OpProcessingInterpolation) , gi);
278 int li4 = ip->addLabel(tr("HELP_LABEL_INTERP4"), gi);
282 //this->createStudyComponent(theStudy);
283 _workspaceController->showDockWidgets(true);
284 _presentationController->showDockWidgets(true);
285 //this->setDockLayout(StandardApp_Module::DOCKLAYOUT_LEFT_VLARGE);
287 // Mark the start of the main event loop - important for test playback:
288 // QObject::connect(getApp(), SIGNAL(activated(SUIT_Application *)), this, SLOT(onEventLoopStarted(SUIT_Application *)));
289 // QTimer::singleShot(0, this, SLOT(onEventLoopStarted()));
291 // return the activation status
293 QObject::connect(&pqActiveObjects::instance(), SIGNAL(viewChanged(pqView*)), this,
294 SLOT(onViewChanged()), Qt::QueuedConnection);
300 MEDModule::deactivateModule( SUIT_Study* theStudy )
302 STDLOG("MEDModule::deactivateModule()");
303 _workspaceController->showDockWidgets(false);
304 _presentationController->showDockWidgets(false);
305 //this->unsetDockLayout();
308 setMenuShown( false );
310 setToolShown( false );
312 // call parent implementation and return the activation status
313 return SalomeApp_Module::deactivateModule( theStudy );
316 void MEDModule::studyClosed(SUIT_Study* study)
318 STDLOG("MEDModule::studyClosed()");
319 _presentationController->resetPVSession();
321 SalomeApp_Module::studyClosed(study);
325 // =====================================================================
326 // This part add custom widgets (a dockwidget containing a tree view
327 // in this example) and add special actions in the toolbox of the
329 // =====================================================================
333 * This function implements the interface StandardApp_Module. It
334 * creates the widgets specific for this module, in particular the
335 * workspace widget and the dataspace widget.
338 MEDModule::createModuleWidgets() {
339 _studyEditor = new SALOME_AppStudyEditor(getApp());
340 _datasourceController = new DatasourceController(this);
341 _workspaceController = new WorkspaceController(this);
342 _xmedDataModel = new XmedDataModel();
343 _workspaceController->setDataModel(_xmedDataModel);
344 _presentationController = new PresentationController(this);
345 // ABN: ultimately console driver should be owned by module: everyone needs it, not only WorkspaceController
346 _presentationController->setConsoleDriver(_workspaceController->getConsoleDriver());
347 _processingController = new ProcessingController(this);
348 #ifdef MED_HAS_QTTESTING
349 _testController = new TestController(this);
352 connect(_datasourceController, SIGNAL(datasourceSignal(const DatasourceEvent*)),
353 _workspaceController, SLOT(processDatasourceEvent(const DatasourceEvent*)));
355 connect(_presentationController, SIGNAL(presentationSignal(const PresentationEvent*)),
356 _presentationController, SLOT(processPresentationEvent(const PresentationEvent*)));
358 connect(_processingController, SIGNAL(processingSignal(const ProcessingEvent*)),
359 _workspaceController, SLOT(processProcessingEvent(const ProcessingEvent*)));
361 connect(_workspaceController, SIGNAL(workspaceSignal(const MEDCALC::MedEvent*)),
362 _datasourceController, SLOT(processWorkspaceEvent(const MEDCALC::MedEvent*)));
364 connect(_workspaceController, SIGNAL(workspaceSignal(const MEDCALC::MedEvent*)),
365 _presentationController, SLOT(processWorkspaceEvent(const MEDCALC::MedEvent*)));
367 connect(&pqActiveObjects::instance(), &pqActiveObjects::viewChanged, [this](pqView* view) { this->updateVisibilityState(); });
372 void MEDModule::updateVisibilityState(const bool all, const QStringList& entries)
374 if (!_enableVisibilityStateUpdate) {
377 QStringList allPrsEntries = QStringList();
378 const QStringList& workList = ( all ? allPrsEntries : entries );
380 SALOMEDS::Study_var aStudy = KERNEL::getStudyServant();
381 if (aStudy->_is_nil())
383 SALOMEDS::SComponent_var father = aStudy->FindComponent("FIELDS");
384 if (father->_is_nil())
386 SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(father);
387 SALOMEDS::GenericAttribute_var anAttribute;
388 for (it->InitEx(true); it->More(); it->Next())
390 SALOMEDS::SObject_var child(it->Value());
391 if (child->FindAttribute(anAttribute, "AttributeParameter"))
393 SALOMEDS::AttributeParameter_var attrParam = SALOMEDS::AttributeParameter::_narrow(anAttribute);
394 if (!attrParam->IsSet(IS_PRESENTATION, PT_BOOLEAN) || !attrParam->GetBool(IS_PRESENTATION) || !attrParam->IsSet(PRESENTATION_ID, PT_INTEGER))
396 allPrsEntries.append(child->GetID());
401 // update visibility state of objects
402 LightApp_Application* app = dynamic_cast<LightApp_Application*>(SUIT_Session::session()->activeApplication());
405 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
408 SUIT_Study* activeStudy = app->activeStudy();
411 SUIT_ViewWindow* aViewWindow = app->desktop()->activeWindow();
414 SUIT_ViewManager* aViewManager = aViewWindow->getViewManager();
418 SUIT_ViewModel * aViewModel = aViewManager->getViewModel();
419 DataObjectList aList;
420 for(const auto& str : workList) {
421 aList.append(appStudy->findObjectByEntry(str));
423 app->updateVisibilityState(aList, aViewModel);
428 MEDModule::initToolbars()
430 // VCR and Time toolbars:
431 SUIT_Desktop* dsk = getApp()->desktop();
432 _pvGuiElements = PVViewer_GUIElements::GetInstance(dsk);
434 _pvGuiElements->getVCRToolbar(); // make sure VCR toolbar is built
435 _pvGuiElements->setToolBarVisible(false);
436 _pvGuiElements->setVCRTimeToolBarVisible(true);
438 // Emit signal in order to make sure that animation scene is set - same trick as in PARAVIS module activation
439 QMetaObject::invokeMethod( pqPVApplicationCore::instance()->animationManager(),
440 "activeSceneChanged",
441 Q_ARG( pqAnimationScene*, pqPVApplicationCore::instance()->animationManager()->getActiveScene() ) );
443 #ifdef MED_HAS_QTTESTING
444 connect(_workspaceController, SIGNAL(workspaceSignal(const MEDCALC::MedEvent*)),
445 _testController, SLOT(processWorkspaceEvent(const MEDCALC::MedEvent*)));
450 MEDModule::getCurrentAnimationTimestamp()
452 double timestamp = pqPVApplicationCore::instance()->animationManager()->getActiveScene()->getAnimationTime();
457 MEDModule::createModuleActions() {
458 _datasourceController->createActions();
459 _workspaceController->createActions();
460 _presentationController->createActions();
461 _processingController->createActions();
462 #ifdef MED_HAS_QTTESTING
463 _testController->createActions();
468 MEDModule::createStandardAction(const QString& label,
470 const char* slotmember,
471 const QString& iconName,
472 const QString& tooltip,
475 SUIT_Desktop* dsk = getApp()->desktop();
476 SUIT_ResourceMgr* resMgr = getApp()->resourceMgr();
478 // If the tooltip is not defined, we choose instead the label text.
479 QString effToolTip(tooltip);
480 if ( effToolTip.isEmpty() )
484 if (iconName.isEmpty())
487 ico = QIcon(resMgr->loadPixmap("FIELDS", iconName));
489 QAction* action = createAction(actionid,
500 return actionId(action);
504 MEDModule::addActionInPopupMenu(int actionId,const QString& menus,const QString& rule)
506 // _GBO_ for a fine customization of the rule (for example with a
507 // test on the type of the selected object), see the LIGHT module:
508 // implement "LightApp_Selection* createSelection() const;"
510 QtxPopupMgr* mgr = this->popupMgr();
511 this->action( actionId )->setIconVisibleInMenu(true);
512 if (! menus.isEmpty())
513 mgr->insert ( this->action( actionId ), menus, parentId, 0 );
515 mgr->insert ( this->action( actionId ), parentId, 0 );
516 mgr->setRule( this->action( actionId ), rule, QtxPopupMgr::VisibleRule );
519 //MEDCALC::ViewModeType
520 //MEDModule::getSelectedViewMode() const
522 // return _presentationController->getSelectedViewMode();
525 //MEDCALC::ColorMapType
526 //MEDModule::getSelectedColorMap() const
528 // return _presentationController->getSelectedColorMap();
531 //MEDCALC::ScalarBarRangeType
532 //MEDModule::getSelectedScalarBarRange() const
534 // return _presentationController->getSelectedScalarBarRange();
539 * Returns presentation name, type and ID from the currently selected presentation in the object
543 MEDModule::itemClickGeneric(std::string & name, std::string & type, int & presId) const
545 DataObjectList dol = getApp()->objectBrowser()->getSelected();
548 SalomeApp_DataObject* item = dynamic_cast<SalomeApp_DataObject*>(dol[0]);
551 SalomeApp_DataModel *model = dynamic_cast<SalomeApp_DataModel*>(dataModel());
555 if (item->componentDataType().toStdString() != "FIELDS")
557 _PTR(SObject) obj = item->object();
558 _PTR(GenericAttribute) anAttribute;
560 if (! obj->FindAttribute(anAttribute, "AttributeName"))
562 _PTR(AttributeName) attrName(anAttribute);
563 name = attrName->Value();
565 if (! obj->FindAttribute(anAttribute, "AttributeParameter"))
567 _PTR(AttributeParameter) attrParam(anAttribute);
568 if (! attrParam->IsSet(IS_PRESENTATION, PT_BOOLEAN)
569 || ! attrParam->GetBool(IS_PRESENTATION)) { // Not a presentation
572 // if (!attrParam->IsSet(FIELD_ID, PT_INTEGER))
574 // fieldId = attrParam->GetInt(FIELD_ID);
575 if (!attrParam->IsSet(PRESENTATION_ID, PT_INTEGER))
577 presId = attrParam->GetInt(PRESENTATION_ID);
578 if (!attrParam->IsSet(PRESENTATION_TYPE, PT_STRING))
580 type = attrParam->GetString(PRESENTATION_TYPE);
585 MEDModule::onClick(const QModelIndex & /*index*/)
588 std::string name, type;
589 if (!itemClickGeneric(name, type, presId))
591 // Not a presentation - clear widget:
592 emit presentationSelected(-1, QString(""), QString(""));
596 // STDLOG("Presentation selection");
597 // std::ostringstream oss;
598 // oss << fieldId << " / " << presId;
599 // STDLOG(" - Field id / pres id: " + oss.str());
600 // STDLOG(" - Presentation type: " + type);
601 // STDLOG(" - Presentation name: " + name);
603 emit presentationSelected(presId, QString::fromStdString(type), QString::fromStdString(name) ); // caught by PresentationController
607 MEDModule::onDblClick(const QModelIndex& /*index*/)
610 std::string name, type;
611 if (!itemClickGeneric(name, type, presId))
614 // STDLOG("Presentation double click");
615 // STDLOG(" Presentation infos:");
616 // STDLOG(" - Component: " + item->componentDataType().toStdString());
617 // STDLOG(" - Item entry: " + item->entry().toStdString());
618 // STDLOG(" - Item name: " + item->name().toStdString());
619 // std::ostringstream oss;
621 // STDLOG(" - Field id: " + oss.str());
622 // STDLOG(" - Presentation name: " + name);
626 MEDModule::requestSALOMETermination() const
628 STDLOG("Requesting SALOME termination!!");
629 SUIT_Session::session()->closeSession( SUIT_Session::DONT_SAVE, 1 ); // killServers = True
633 //bool MEDModule::hasMainEventLoopStarted() const
635 // return _eventLoopStarted;
639 MEDModule::getIntParamFromStudyEditor(SALOMEDS::SObject_var obj, const char* name)
644 SALOMEDS::GenericAttribute_var anAttr;
645 SALOMEDS::AttributeParameter_var aParam;
646 if ( obj->FindAttribute(anAttr,"AttributeParameter") ) {
647 aParam = SALOMEDS::AttributeParameter::_narrow(anAttr);
648 if (aParam->IsSet(name, PT_INTEGER))
649 return aParam->GetInt(name);
654 LightApp_Displayer* MEDModule::displayer()
657 _displayer = new MEDCALCGUI_Displayer(_presentationController);
661 void MEDModule::visibilityStateUpdateOff() {
662 _enableVisibilityStateUpdate = false;
664 void MEDModule::visibilityStateUpdateOn() {
665 _enableVisibilityStateUpdate = true;