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>
58 //! The only instance of the reference to engine
59 MED_ORB::MED_Gen_var MEDModule::_MED_engine;
60 //! The only instance of the MEDPresentationManager
61 MEDCALC::MEDPresentationManager_ptr MEDModule::_presManager;
63 MEDModule::MEDModule() :
64 SalomeApp_Module("MED"), _studyEditor(0),
65 _datasourceController(0), _workspaceController(0), _presentationController(0),
66 _processingController(0), _pvGuiElements(0)
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()
78 if (_datasourceController)
79 delete _datasourceController;
80 //if (_workspaceController)
81 // delete _workspaceController;
82 if (_presentationController)
83 delete _presentationController;
84 if (_processingController)
85 delete _processingController;
91 init(); // initialize engine, if necessary
98 // initialize MED module engine (load, if necessary)
99 if ( CORBA::is_nil( _MED_engine ) ) {
100 Engines::EngineComponent_var comp =
101 SalomeApp_Application::lcc()->FindOrLoad_Component( "FactoryServer", "MED" );
102 _MED_engine = MED_ORB::MED_Gen::_narrow( comp );
105 // Retrieve MEDFactory to get MEDPresentationManager (sometimes
106 if ( ! _presManager ) {
107 _presManager = MEDFactoryClient::getFactory()->getPresentationManager();
111 //void MEDModule::onEventLoopStarted()
113 // if(!getApp()->isMainEventLoopStarted())
115 // QTimer::singleShot(100, this, SLOT(onEventLoopStarted()));
121 MEDModule::initialize( CAM_Application* app )
123 // call the parent implementation
124 SalomeApp_Module::initialize( app );
126 getApp()->objectBrowser()->setAutoOpenLevel(5);
128 if (app && app->desktop()) {
129 connect((QObject*) (getApp()->objectBrowser()->treeView()), SIGNAL(doubleClicked(const QModelIndex&)),
130 this, SLOT(onDblClick(const QModelIndex&)));
131 connect((QObject*) (getApp()->objectBrowser()->treeView()), SIGNAL(clicked(const QModelIndex&)),
132 this, SLOT(onClick(const QModelIndex&)));
135 // The following initializes the GUI widget and associated actions
136 this->createModuleWidgets();
137 this->createModuleActions();
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 )
225 _workspaceController->showDockWidgets(false);
226 _presentationController->showDockWidgets(false);
227 //this->unsetDockLayout();
230 setMenuShown( false );
232 setToolShown( false );
234 // call parent implementation and return the activation status
235 return SalomeApp_Module::deactivateModule( theStudy );
239 // =====================================================================
240 // This part add custom widgets (a dockwidget containing a tree view
241 // in this example) and add special actions in the toolbox of the
243 // =====================================================================
247 * This function implements the interface StandardApp_Module. It
248 * creates the widgets specific for this module, in particular the
249 * workspace widget and the dataspace widget.
252 MEDModule::createModuleWidgets() {
253 _studyEditor = new SALOME_AppStudyEditor(getApp());
254 _datasourceController = new DatasourceController(this);
255 _workspaceController = new WorkspaceController(this);
256 _xmedDataModel = new XmedDataModel();
257 _workspaceController->setDataModel(_xmedDataModel);
258 _presentationController = new PresentationController(this);
259 _processingController = new ProcessingController(this);
260 #ifdef MED_HAS_QTTESTING
261 _testController = new TestController(this);
264 connect(_datasourceController, SIGNAL(datasourceSignal(const DatasourceEvent*)),
265 _workspaceController, SLOT(processDatasourceEvent(const DatasourceEvent*)));
267 connect(_presentationController, SIGNAL(presentationSignal(const PresentationEvent*)),
268 _workspaceController, SLOT(processPresentationEvent(const PresentationEvent*)));
270 connect(_processingController, SIGNAL(processingSignal(const ProcessingEvent*)),
271 _workspaceController, SLOT(processProcessingEvent(const ProcessingEvent*)));
273 connect(_workspaceController, SIGNAL(workspaceSignal(const MEDCALC::MedEvent*)),
274 _datasourceController, SLOT(processWorkspaceEvent(const MEDCALC::MedEvent*)));
276 connect(_workspaceController, SIGNAL(workspaceSignal(const MEDCALC::MedEvent*)),
277 _presentationController, SLOT(processWorkspaceEvent(const MEDCALC::MedEvent*)));
280 // Now that the workspace controller is created, ParaView core application has normally been started,
281 // and hidden GUI elements have been created. We can fire the VCR toolbar activation:
286 MEDModule::initToolbars()
288 // VCR and Time toolbars:
289 SUIT_Desktop* dsk = getApp()->desktop();
290 _pvGuiElements = PVViewer_GUIElements::GetInstance(dsk);
292 _pvGuiElements->getVCRToolbar(); // make sure VCR toolbar is built
293 _pvGuiElements->setToolBarVisible(false);
294 _pvGuiElements->setVCRTimeToolBarVisible(true);
296 // Emit signal in order to make sure that animation scene is set - same trick as in PARAVIS module activation
297 QMetaObject::invokeMethod( pqPVApplicationCore::instance()->animationManager(),
298 "activeSceneChanged",
299 Q_ARG( pqAnimationScene*, pqPVApplicationCore::instance()->animationManager()->getActiveScene() ) );
301 #ifdef MED_HAS_QTTESTING
302 connect(_workspaceController, SIGNAL(workspaceSignal(const MEDCALC::MedEvent*)),
303 _testController, SLOT(processWorkspaceEvent(const MEDCALC::MedEvent*)));
308 MEDModule::createModuleActions() {
309 _datasourceController->createActions();
310 _workspaceController->createActions();
311 _presentationController->createActions();
312 _processingController->createActions();
313 #ifdef MED_HAS_QTTESTING
314 _testController->createActions();
319 MEDModule::createStandardAction(const QString& label,
321 const char* slotmember,
322 const QString& iconName,
323 const QString& tooltip)
325 SUIT_Desktop* dsk = getApp()->desktop();
326 SUIT_ResourceMgr* resMgr = getApp()->resourceMgr();
328 // If the tooltip is not defined, we choose instead the label text.
329 QString effToolTip(tooltip);
330 if ( effToolTip.isEmpty() )
334 if (iconName.isEmpty())
337 ico = QIcon(resMgr->loadPixmap("MED", iconName));
339 QAction* action = createAction(-1,
350 return actionId(action);
354 MEDModule::addActionInPopupMenu(int actionId,const QString& menus,const QString& rule)
356 // _GBO_ for a fine customization of the rule (for example with a
357 // test on the type of the selected object), see the LIGHT module:
358 // implement "LightApp_Selection* createSelection() const;"
360 QtxPopupMgr* mgr = this->popupMgr();
361 this->action( actionId )->setIconVisibleInMenu(true);
362 if (! menus.isEmpty())
363 mgr->insert ( this->action( actionId ), menus, parentId, 0 );
365 mgr->insert ( this->action( actionId ), parentId, 0 );
366 mgr->setRule( this->action( actionId ), rule, QtxPopupMgr::VisibleRule );
369 MEDCALC::MEDPresentationViewMode
370 MEDModule::getSelectedViewMode()
372 return _presentationController->getSelectedViewMode();
375 MEDCALC::MEDPresentationColorMap
376 MEDModule::getSelectedColorMap()
378 return _presentationController->getSelectedColorMap();
382 MEDModule::itemClickGeneric(const QModelIndex & index, std::string & name, int & fieldId, int & presId) const
384 DataObjectList dol = getApp()->objectBrowser()->getSelected();
387 SalomeApp_DataObject* item = dynamic_cast<SalomeApp_DataObject*>(dol[0]);
390 SalomeApp_DataModel *model = dynamic_cast<SalomeApp_DataModel*>(dataModel());
394 if (item->componentDataType().toStdString() != "MED")
396 _PTR(SObject) obj = item->object();
397 _PTR(GenericAttribute) anAttribute;
399 if (! obj->FindAttribute(anAttribute, "AttributeName"))
401 _PTR(AttributeName) attrName(anAttribute);
402 name = attrName->Value();
404 if (! obj->FindAttribute(anAttribute, "AttributeParameter"))
406 _PTR(AttributeParameter) attrParam(anAttribute);
407 if (! attrParam->IsSet(IS_PRESENTATION, PT_BOOLEAN)
408 || ! attrParam->GetBool(IS_PRESENTATION)) { // Not a presentation
411 if (!attrParam->IsSet(FIELD_ID, PT_INTEGER))
413 fieldId = attrParam->GetInt(FIELD_ID);
414 if (!attrParam->IsSet(PRESENTATION_ID, PT_INTEGER))
416 presId = attrParam->GetInt(PRESENTATION_ID);
421 MEDModule::onClick(const QModelIndex & index)
425 if (!itemClickGeneric(index, name, fieldId, presId))
428 STDLOG("Presentation selection (activate view)");
429 std::ostringstream oss;
430 oss << fieldId << " / " << presId;
431 STDLOG(" - Field id / pres id: " + oss.str());
432 STDLOG(" - Presentation name: " + name);
434 _presManager->activateView(presId);
438 MEDModule::onDblClick(const QModelIndex& index)
442 if (!itemClickGeneric(index, name, fieldId, presId))
445 STDLOG("Presentation edition: NOT IMPLEMENTED YET");
446 STDLOG(" Presention infos:");
447 // STDLOG(" - Component: " + item->componentDataType().toStdString());
448 // STDLOG(" - Item entry: " + item->entry().toStdString());
449 // STDLOG(" - Item name: " + item->name().toStdString());
450 std::ostringstream oss;
452 STDLOG(" - Field id: " + oss.str());
453 STDLOG(" - Presentation name: " + name);
456 // get edited values from a popup widget
458 // call presentation edit function
463 MEDModule::requestSALOMETermination() const
465 STDLOG("Requesting SALOME termination!!");
466 SUIT_Session::session()->closeSession( SUIT_Session::DONT_SAVE, 1 ); // killServers = True
470 //bool MEDModule::hasMainEventLoopStarted() const
472 // return _eventLoopStarted;