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"
49 #include "MEDFactoryClient.hxx"
50 #include "MEDPresentationManager_i.hxx"
55 #include <pqAnimationManager.h>
56 #include <pqPVApplicationCore.h>
59 //! The only instance of the reference to engine
60 MED_ORB::MED_Gen_var MEDModule::_MED_engine;
61 //! The only instance of the MEDPresentationManager
62 MEDCALC::MEDPresentationManager_ptr MEDModule::_presManager;
64 MEDModule::MEDModule() :
65 SalomeApp_Module("MED"), _studyEditor(0),
66 _datasourceController(0), _workspaceController(0), _presentationController(0),
67 _processingController(0), _pvGuiElements(0)
69 // Note also that we can't use the getApp() function here because
70 // the initialize(...) function has not been called yet.
72 init(); // internal initialization
75 MEDModule::~MEDModule()
79 if (_datasourceController)
80 delete _datasourceController;
81 //if (_workspaceController)
82 // delete _workspaceController;
83 if (_presentationController)
84 delete _presentationController;
85 if (_processingController)
86 delete _processingController;
92 init(); // initialize engine, if necessary
99 // initialize MED module engine (load, if necessary)
100 if ( CORBA::is_nil( _MED_engine ) ) {
101 Engines::EngineComponent_var comp =
102 SalomeApp_Application::lcc()->FindOrLoad_Component( "FactoryServer", "MED" );
103 _MED_engine = MED_ORB::MED_Gen::_narrow( comp );
106 // Retrieve MEDFactory to get MEDPresentationManager (sometimes
107 if ( ! _presManager ) {
108 _presManager = MEDFactoryClient::getFactory()->getPresentationManager();
112 //void MEDModule::onEventLoopStarted()
114 // if(!getApp()->isMainEventLoopStarted())
116 // QTimer::singleShot(100, this, SLOT(onEventLoopStarted()));
122 MEDModule::initialize( CAM_Application* app )
124 // call the parent implementation
125 SalomeApp_Module::initialize( app );
127 getApp()->objectBrowser()->setAutoOpenLevel(5);
129 if (app && app->desktop()) {
130 connect((QObject*) (getApp()->objectBrowser()->treeView()), SIGNAL(doubleClicked(const QModelIndex&)),
131 this, SLOT(onDblClick(const QModelIndex&)));
132 connect((QObject*) (getApp()->objectBrowser()->treeView()), SIGNAL(clicked(const QModelIndex&)),
133 this, SLOT(onClick(const QModelIndex&)));
136 // The following initializes the GUI widget and associated actions
137 this->createModuleWidgets();
138 this->createModuleActions();
142 MEDModule::engineIOR() const
144 init(); // initialize engine, if necessary
145 CORBA::String_var anIOR = getApp()->orb()->object_to_string( _MED_engine.in() );
146 return QString( anIOR.in() );
150 MEDModule::iconName() const
152 return tr("ICO_MED_SMALL");
156 MEDModule::windows( QMap<int, int>& theMap ) const
158 // want Object browser, in the left area
159 theMap.insert( SalomeApp_Application::WT_ObjectBrowser,
160 Qt::LeftDockWidgetArea );
161 #ifndef DISABLE_PYCONSOLE
162 // want Python console, in the bottom area
163 theMap.insert( SalomeApp_Application::WT_PyConsole,
164 Qt::BottomDockWidgetArea );
169 MEDModule::viewManagers( QStringList& list ) const
171 #ifndef DISABLE_PVVIEWER
172 list.append( PVViewer_Viewer::Type() );
177 MEDModule::createPreferences()
179 int genTab = addPreference(tr("PREF_TAB_GENERAL"));
181 int themeGroup = addPreference(tr("PREF_THEME_GROUP"), genTab);
182 setPreferenceProperty(themeGroup, "columns", 2);
183 int icons = addPreference(tr("PREF_ICONS"), themeGroup, LightApp_Preferences::Selector, "MEDCalc", "icons" );
184 QStringList iconsThemes;
185 iconsThemes.append(tr("PREF_ICON_THEME_MODERN"));
186 iconsThemes.append(tr("PREF_ICON_THEME_CLASSIC"));
187 QList<QVariant> indices;
190 setPreferenceProperty(icons, "strings", iconsThemes);
191 setPreferenceProperty(icons, "indexes", indices);
195 MEDModule::activateModule( SUIT_Study* theStudy )
197 if ( CORBA::is_nil( _MED_engine ) )
200 // call parent implementation
201 bool bOk = SalomeApp_Module::activateModule( theStudy );
206 setMenuShown( true );
208 setToolShown( true );
210 //this->createStudyComponent(theStudy);
211 _workspaceController->showDockWidgets(true);
212 _presentationController->showDockWidgets(true);
213 //this->setDockLayout(StandardApp_Module::DOCKLAYOUT_LEFT_VLARGE);
215 // Mark the start of the main event loop - important for test playback:
216 // QObject::connect(getApp(), SIGNAL(activated(SUIT_Application *)), this, SLOT(onEventLoopStarted(SUIT_Application *)));
217 // QTimer::singleShot(0, this, SLOT(onEventLoopStarted()));
219 // return the activation status
224 MEDModule::deactivateModule( SUIT_Study* theStudy )
226 _workspaceController->showDockWidgets(false);
227 _presentationController->showDockWidgets(false);
228 //this->unsetDockLayout();
231 setMenuShown( false );
233 setToolShown( false );
235 // call parent implementation and return the activation status
236 return SalomeApp_Module::deactivateModule( theStudy );
240 // =====================================================================
241 // This part add custom widgets (a dockwidget containing a tree view
242 // in this example) and add special actions in the toolbox of the
244 // =====================================================================
248 * This function implements the interface StandardApp_Module. It
249 * creates the widgets specific for this module, in particular the
250 * workspace widget and the dataspace widget.
253 MEDModule::createModuleWidgets() {
254 _studyEditor = new SALOME_AppStudyEditor(getApp());
255 _datasourceController = new DatasourceController(this);
256 _workspaceController = new WorkspaceController(this);
257 _xmedDataModel = new XmedDataModel();
258 _workspaceController->setDataModel(_xmedDataModel);
259 _presentationController = new PresentationController(this);
260 _processingController = new ProcessingController(this);
261 #ifdef MED_HAS_QTTESTING
262 _testController = new TestController(this);
265 connect(_datasourceController, SIGNAL(datasourceSignal(const DatasourceEvent*)),
266 _workspaceController, SLOT(processDatasourceEvent(const DatasourceEvent*)));
268 connect(_presentationController, SIGNAL(presentationSignal(const PresentationEvent*)),
269 _workspaceController, SLOT(processPresentationEvent(const PresentationEvent*)));
271 connect(_processingController, SIGNAL(processingSignal(const ProcessingEvent*)),
272 _workspaceController, SLOT(processProcessingEvent(const ProcessingEvent*)));
274 connect(_workspaceController, SIGNAL(workspaceSignal(const MEDCALC::MedEvent*)),
275 _datasourceController, SLOT(processWorkspaceEvent(const MEDCALC::MedEvent*)));
277 connect(_workspaceController, SIGNAL(workspaceSignal(const MEDCALC::MedEvent*)),
278 _presentationController, SLOT(processWorkspaceEvent(const MEDCALC::MedEvent*)));
281 // Now that the workspace controller is created, ParaView core application has normally been started,
282 // and hidden GUI elements have been created. We can fire the VCR toolbar activation:
287 MEDModule::initToolbars()
289 // VCR and Time toolbars:
290 SUIT_Desktop* dsk = getApp()->desktop();
291 _pvGuiElements = PVViewer_GUIElements::GetInstance(dsk);
293 _pvGuiElements->getVCRToolbar(); // make sure VCR toolbar is built
294 _pvGuiElements->setToolBarVisible(false);
295 _pvGuiElements->setVCRTimeToolBarVisible(true);
297 // Emit signal in order to make sure that animation scene is set - same trick as in PARAVIS module activation
298 QMetaObject::invokeMethod( pqPVApplicationCore::instance()->animationManager(),
299 "activeSceneChanged",
300 Q_ARG( pqAnimationScene*, pqPVApplicationCore::instance()->animationManager()->getActiveScene() ) );
302 #ifdef MED_HAS_QTTESTING
303 connect(_workspaceController, SIGNAL(workspaceSignal(const MEDCALC::MedEvent*)),
304 _testController, SLOT(processWorkspaceEvent(const MEDCALC::MedEvent*)));
309 MEDModule::createModuleActions() {
310 _datasourceController->createActions();
311 _workspaceController->createActions();
312 _presentationController->createActions();
313 _processingController->createActions();
314 #ifdef MED_HAS_QTTESTING
315 _testController->createActions();
320 MEDModule::createStandardAction(const QString& label,
322 const char* slotmember,
323 const QString& iconName,
324 const QString& tooltip)
326 SUIT_Desktop* dsk = getApp()->desktop();
327 SUIT_ResourceMgr* resMgr = getApp()->resourceMgr();
329 // If the tooltip is not defined, we choose instead the label text.
330 QString effToolTip(tooltip);
331 if ( effToolTip.isEmpty() )
335 if (iconName.isEmpty())
338 ico = QIcon(resMgr->loadPixmap("MED", iconName));
340 QAction* action = createAction(-1,
351 return actionId(action);
355 MEDModule::addActionInPopupMenu(int actionId,const QString& menus,const QString& rule)
357 // _GBO_ for a fine customization of the rule (for example with a
358 // test on the type of the selected object), see the LIGHT module:
359 // implement "LightApp_Selection* createSelection() const;"
361 QtxPopupMgr* mgr = this->popupMgr();
362 this->action( actionId )->setIconVisibleInMenu(true);
363 if (! menus.isEmpty())
364 mgr->insert ( this->action( actionId ), menus, parentId, 0 );
366 mgr->insert ( this->action( actionId ), parentId, 0 );
367 mgr->setRule( this->action( actionId ), rule, QtxPopupMgr::VisibleRule );
370 MEDCALC::MEDPresentationViewMode
371 MEDModule::getSelectedViewMode()
373 return _presentationController->getSelectedViewMode();
376 MEDCALC::MEDPresentationColorMap
377 MEDModule::getSelectedColorMap()
379 return _presentationController->getSelectedColorMap();
383 MEDModule::itemClickGeneric(const QModelIndex & index, std::string & name, 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);
422 MEDModule::onClick(const QModelIndex & index)
426 if (!itemClickGeneric(index, name, fieldId, presId))
429 STDLOG("Presentation selection (activate view)");
430 std::ostringstream oss;
431 oss << fieldId << " / " << presId;
432 STDLOG(" - Field id / pres id: " + oss.str());
433 STDLOG(" - Presentation name: " + name);
435 _presManager->activateView(presId);
439 MEDModule::onDblClick(const QModelIndex& index)
443 if (!itemClickGeneric(index, name, fieldId, presId))
446 STDLOG("Presentation edition: NOT IMPLEMENTED YET");
447 STDLOG(" Presention infos:");
448 // STDLOG(" - Component: " + item->componentDataType().toStdString());
449 // STDLOG(" - Item entry: " + item->entry().toStdString());
450 // STDLOG(" - Item name: " + item->name().toStdString());
451 std::ostringstream oss;
453 STDLOG(" - Field id: " + oss.str());
454 STDLOG(" - Presentation name: " + name);
457 // get edited values from a popup widget
459 // call presentation edit function
464 MEDModule::requestSALOMETermination() const
466 STDLOG("Requesting SALOME termination!!");
467 SUIT_Session::session()->closeSession( SUIT_Session::DONT_SAVE, 1 ); // killServers = True
471 //bool MEDModule::hasMainEventLoopStarted() const
473 // return _eventLoopStarted;