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 _MED_engine = MED_ORB::MED_Gen::_narrow( comp );
103 //void MEDModule::onEventLoopStarted()
105 // if(!getApp()->isMainEventLoopStarted())
107 // QTimer::singleShot(100, this, SLOT(onEventLoopStarted()));
113 MEDModule::initialize( CAM_Application* app )
115 // call the parent implementation
116 SalomeApp_Module::initialize( app );
118 getApp()->objectBrowser()->setAutoOpenLevel(5);
120 if (app && app->desktop()) {
121 connect((QObject*) (getApp()->objectBrowser()->treeView()), SIGNAL(doubleClicked(const QModelIndex&)),
122 this, SLOT(onDblClick(const QModelIndex&)));
123 connect((QObject*) (getApp()->objectBrowser()->treeView()), SIGNAL(clicked(const QModelIndex&)),
124 this, SLOT(onClick(const QModelIndex&)));
127 // The following initializes the GUI widget and associated actions
128 this->createModuleWidgets();
129 this->createModuleActions();
133 MEDModule::engineIOR() const
135 init(); // initialize engine, if necessary
136 CORBA::String_var anIOR = getApp()->orb()->object_to_string( _MED_engine.in() );
137 return QString( anIOR.in() );
141 MEDModule::iconName() const
143 return tr("ICO_MED_SMALL");
147 MEDModule::windows( QMap<int, int>& theMap ) const
149 // want Object browser, in the left area
150 theMap.insert( SalomeApp_Application::WT_ObjectBrowser,
151 Qt::LeftDockWidgetArea );
152 #ifndef DISABLE_PYCONSOLE
153 // want Python console, in the bottom area
154 theMap.insert( SalomeApp_Application::WT_PyConsole,
155 Qt::BottomDockWidgetArea );
160 MEDModule::viewManagers( QStringList& list ) const
162 #ifndef DISABLE_PVVIEWER
163 list.append( PVViewer_Viewer::Type() );
168 MEDModule::createPreferences()
170 int genTab = addPreference(tr("PREF_TAB_GENERAL"));
172 int themeGroup = addPreference(tr("PREF_THEME_GROUP"), genTab);
173 setPreferenceProperty(themeGroup, "columns", 2);
174 int icons = addPreference(tr("PREF_ICONS"), themeGroup, LightApp_Preferences::Selector, "MEDCalc", "icons" );
175 QStringList iconsThemes;
176 iconsThemes.append(tr("PREF_ICON_THEME_MODERN"));
177 iconsThemes.append(tr("PREF_ICON_THEME_CLASSIC"));
178 QList<QVariant> indices;
181 setPreferenceProperty(icons, "strings", iconsThemes);
182 setPreferenceProperty(icons, "indexes", indices);
186 MEDModule::activateModule( SUIT_Study* theStudy )
188 if ( CORBA::is_nil( _MED_engine ) )
191 // call parent implementation
192 bool bOk = SalomeApp_Module::activateModule( theStudy );
197 setMenuShown( true );
199 setToolShown( true );
201 //this->createStudyComponent(theStudy);
202 _workspaceController->showDockWidgets(true);
203 _presentationController->showDockWidgets(true);
204 //this->setDockLayout(StandardApp_Module::DOCKLAYOUT_LEFT_VLARGE);
206 // Mark the start of the main event loop - important for test playback:
207 // QObject::connect(getApp(), SIGNAL(activated(SUIT_Application *)), this, SLOT(onEventLoopStarted(SUIT_Application *)));
208 // QTimer::singleShot(0, this, SLOT(onEventLoopStarted()));
210 // return the activation status
215 MEDModule::deactivateModule( SUIT_Study* theStudy )
217 _workspaceController->showDockWidgets(false);
218 _presentationController->showDockWidgets(false);
219 //this->unsetDockLayout();
222 setMenuShown( false );
224 setToolShown( false );
226 // call parent implementation and return the activation status
227 return SalomeApp_Module::deactivateModule( theStudy );
231 // =====================================================================
232 // This part add custom widgets (a dockwidget containing a tree view
233 // in this example) and add special actions in the toolbox of the
235 // =====================================================================
239 * This function implements the interface StandardApp_Module. It
240 * creates the widgets specific for this module, in particular the
241 * workspace widget and the dataspace widget.
244 MEDModule::createModuleWidgets() {
245 _studyEditor = new SALOME_AppStudyEditor(getApp());
246 _datasourceController = new DatasourceController(this);
247 _workspaceController = new WorkspaceController(this);
248 _xmedDataModel = new XmedDataModel();
249 _workspaceController->setDataModel(_xmedDataModel);
250 _presentationController = new PresentationController(this);
251 // ABN: ultimately console driver should be owned by module: everyone needs it, not only WorkspaceController
252 _presentationController->setConsoleDriver(_workspaceController->getConsoleDriver());
253 _processingController = new ProcessingController(this);
254 #ifdef MED_HAS_QTTESTING
255 _testController = new TestController(this);
258 connect(_datasourceController, SIGNAL(datasourceSignal(const DatasourceEvent*)),
259 _workspaceController, SLOT(processDatasourceEvent(const DatasourceEvent*)));
261 connect(_presentationController, SIGNAL(presentationSignal(const PresentationEvent*)),
262 _presentationController, SLOT(processPresentationEvent(const PresentationEvent*)));
264 connect(_processingController, SIGNAL(processingSignal(const ProcessingEvent*)),
265 _workspaceController, SLOT(processProcessingEvent(const ProcessingEvent*)));
267 connect(_workspaceController, SIGNAL(workspaceSignal(const MEDCALC::MedEvent*)),
268 _datasourceController, SLOT(processWorkspaceEvent(const MEDCALC::MedEvent*)));
270 connect(_workspaceController, SIGNAL(workspaceSignal(const MEDCALC::MedEvent*)),
271 _presentationController, SLOT(processWorkspaceEvent(const MEDCALC::MedEvent*)));
274 // Now that the workspace controller is created, ParaView core application has normally been started,
275 // and hidden GUI elements have been created. We can fire the VCR toolbar activation:
280 MEDModule::initToolbars()
282 // VCR and Time toolbars:
283 SUIT_Desktop* dsk = getApp()->desktop();
284 _pvGuiElements = PVViewer_GUIElements::GetInstance(dsk);
286 _pvGuiElements->getVCRToolbar(); // make sure VCR toolbar is built
287 _pvGuiElements->setToolBarVisible(false);
288 _pvGuiElements->setVCRTimeToolBarVisible(true);
290 // Emit signal in order to make sure that animation scene is set - same trick as in PARAVIS module activation
291 QMetaObject::invokeMethod( pqPVApplicationCore::instance()->animationManager(),
292 "activeSceneChanged",
293 Q_ARG( pqAnimationScene*, pqPVApplicationCore::instance()->animationManager()->getActiveScene() ) );
295 #ifdef MED_HAS_QTTESTING
296 connect(_workspaceController, SIGNAL(workspaceSignal(const MEDCALC::MedEvent*)),
297 _testController, SLOT(processWorkspaceEvent(const MEDCALC::MedEvent*)));
302 MEDModule::createModuleActions() {
303 _datasourceController->createActions();
304 _workspaceController->createActions();
305 _presentationController->createActions();
306 _processingController->createActions();
307 #ifdef MED_HAS_QTTESTING
308 _testController->createActions();
313 MEDModule::createStandardAction(const QString& label,
315 const char* slotmember,
316 const QString& iconName,
317 const QString& tooltip)
319 SUIT_Desktop* dsk = getApp()->desktop();
320 SUIT_ResourceMgr* resMgr = getApp()->resourceMgr();
322 // If the tooltip is not defined, we choose instead the label text.
323 QString effToolTip(tooltip);
324 if ( effToolTip.isEmpty() )
328 if (iconName.isEmpty())
331 ico = QIcon(resMgr->loadPixmap("MED", iconName));
333 QAction* action = createAction(-1,
344 return actionId(action);
348 MEDModule::addActionInPopupMenu(int actionId,const QString& menus,const QString& rule)
350 // _GBO_ for a fine customization of the rule (for example with a
351 // test on the type of the selected object), see the LIGHT module:
352 // implement "LightApp_Selection* createSelection() const;"
354 QtxPopupMgr* mgr = this->popupMgr();
355 this->action( actionId )->setIconVisibleInMenu(true);
356 if (! menus.isEmpty())
357 mgr->insert ( this->action( actionId ), menus, parentId, 0 );
359 mgr->insert ( this->action( actionId ), parentId, 0 );
360 mgr->setRule( this->action( actionId ), rule, QtxPopupMgr::VisibleRule );
363 //MEDCALC::MEDPresentationViewMode
364 //MEDModule::getSelectedViewMode() const
366 // return _presentationController->getSelectedViewMode();
369 //MEDCALC::MEDPresentationColorMap
370 //MEDModule::getSelectedColorMap() const
372 // return _presentationController->getSelectedColorMap();
375 //MEDCALC::MEDPresentationScalarBarRange
376 //MEDModule::getSelectedScalarBarRange() const
378 // return _presentationController->getSelectedScalarBarRange();
383 MEDModule::itemClickGeneric(const QModelIndex & index, std::string & name, std::string & type, int & fieldId, int & presId) const
385 DataObjectList dol = getApp()->objectBrowser()->getSelected();
388 SalomeApp_DataObject* item = dynamic_cast<SalomeApp_DataObject*>(dol[0]);
391 SalomeApp_DataModel *model = dynamic_cast<SalomeApp_DataModel*>(dataModel());
395 if (item->componentDataType().toStdString() != "MED")
397 _PTR(SObject) obj = item->object();
398 _PTR(GenericAttribute) anAttribute;
400 if (! obj->FindAttribute(anAttribute, "AttributeName"))
402 _PTR(AttributeName) attrName(anAttribute);
403 name = attrName->Value();
405 if (! obj->FindAttribute(anAttribute, "AttributeParameter"))
407 _PTR(AttributeParameter) attrParam(anAttribute);
408 if (! attrParam->IsSet(IS_PRESENTATION, PT_BOOLEAN)
409 || ! attrParam->GetBool(IS_PRESENTATION)) { // Not a presentation
412 if (!attrParam->IsSet(FIELD_ID, PT_INTEGER))
414 fieldId = attrParam->GetInt(FIELD_ID);
415 if (!attrParam->IsSet(PRESENTATION_ID, PT_INTEGER))
417 presId = attrParam->GetInt(PRESENTATION_ID);
418 if (!attrParam->IsSet(PRESENTATION_TYPE, PT_STRING))
420 type = attrParam->GetString(PRESENTATION_TYPE);
425 MEDModule::onClick(const QModelIndex & index)
428 std::string name, type;
429 if (!itemClickGeneric(index, name, type, fieldId, presId))
431 // Not a presentation - clear widget:
432 emit presentationSelected(-1, QString(""), QString(""));
436 // STDLOG("Presentation selection");
437 // std::ostringstream oss;
438 // oss << fieldId << " / " << presId;
439 // STDLOG(" - Field id / pres id: " + oss.str());
440 // STDLOG(" - Presentation type: " + type);
441 // STDLOG(" - Presentation name: " + name);
443 emit presentationSelected(presId, QString::fromStdString(type), QString::fromStdString(name) ); // caught by PresentationController
447 MEDModule::onDblClick(const QModelIndex& index)
450 std::string name, type;
451 if (!itemClickGeneric(index, name, type, fieldId, presId))
454 STDLOG("Presentation edition: NOT IMPLEMENTED YET");
455 STDLOG(" Presentation infos:");
456 // STDLOG(" - Component: " + item->componentDataType().toStdString());
457 // STDLOG(" - Item entry: " + item->entry().toStdString());
458 // STDLOG(" - Item name: " + item->name().toStdString());
459 std::ostringstream oss;
461 STDLOG(" - Field id: " + oss.str());
462 STDLOG(" - Presentation name: " + name);
465 // get edited values from a popup widget
467 // call presentation edit function
472 MEDModule::requestSALOMETermination() const
474 STDLOG("Requesting SALOME termination!!");
475 SUIT_Session::session()->closeSession( SUIT_Session::DONT_SAVE, 1 ); // killServers = True
479 //bool MEDModule::hasMainEventLoopStarted() const
481 // return _eventLoopStarted;