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"
53 #include <pqAnimationManager.h>
54 #include <pqPVApplicationCore.h>
57 //! The only instance of the reference to engine
58 MED_ORB::MED_Gen_var MEDModule::_MED_engine;
59 //! The only instance of the MEDPresentationManager
60 MEDCALC::MEDPresentationManager_ptr MEDModule::_presManager;
62 MEDModule::MEDModule() :
63 SalomeApp_Module("MED"), _studyEditor(0),
64 _datasourceController(0), _workspaceController(0), _presentationController(0),
65 _processingController(0), _pvGuiElements(0)
67 // Note also that we can't use the getApp() function here because
68 // the initialize(...) function has not been called yet.
70 init(); // internal initialization
73 MEDModule::~MEDModule()
77 if (_datasourceController)
78 delete _datasourceController;
79 //if (_workspaceController)
80 // delete _workspaceController;
81 if (_presentationController)
82 delete _presentationController;
83 if (_processingController)
84 delete _processingController;
90 init(); // initialize engine, if necessary
97 // initialize MED module engine (load, if necessary)
98 if ( CORBA::is_nil( _MED_engine ) ) {
99 Engines::EngineComponent_var comp =
100 SalomeApp_Application::lcc()->FindOrLoad_Component( "FactoryServer", "MED" );
101 _MED_engine = MED_ORB::MED_Gen::_narrow( comp );
104 // Retrieve MEDFactory to get MEDPresentationManager (sometimes
105 if ( ! _presManager ) {
106 _presManager = MEDFactoryClient::getFactory()->getPresentationManager();
111 MEDModule::initialize( CAM_Application* app )
113 // call the parent implementation
114 SalomeApp_Module::initialize( app );
116 getApp()->objectBrowser()->setAutoOpenLevel(5);
118 if (app && app->desktop()) {
119 connect((QObject*) (getApp()->objectBrowser()->treeView()), SIGNAL(doubleClicked(const QModelIndex&)),
120 this, SLOT(onDblClick(const QModelIndex&)));
121 connect((QObject*) (getApp()->objectBrowser()->treeView()), SIGNAL(clicked(const QModelIndex&)),
122 this, SLOT(onClick(const QModelIndex&)));
125 // The following initializes the GUI widget and associated actions
126 this->createModuleWidgets();
127 this->createModuleActions();
131 MEDModule::engineIOR() const
133 init(); // initialize engine, if necessary
134 CORBA::String_var anIOR = getApp()->orb()->object_to_string( _MED_engine.in() );
135 return QString( anIOR.in() );
139 MEDModule::iconName() const
141 return tr("ICO_MED_SMALL");
145 MEDModule::windows( QMap<int, int>& theMap ) const
147 // want Object browser, in the left area
148 theMap.insert( SalomeApp_Application::WT_ObjectBrowser,
149 Qt::LeftDockWidgetArea );
150 #ifndef DISABLE_PYCONSOLE
151 // want Python console, in the bottom area
152 theMap.insert( SalomeApp_Application::WT_PyConsole,
153 Qt::BottomDockWidgetArea );
158 MEDModule::viewManagers( QStringList& list ) const
160 #ifndef DISABLE_PVVIEWER
161 list.append( PVViewer_Viewer::Type() );
166 MEDModule::createPreferences()
168 int genTab = addPreference(tr("PREF_TAB_GENERAL"));
170 int themeGroup = addPreference(tr("PREF_THEME_GROUP"), genTab);
171 setPreferenceProperty(themeGroup, "columns", 2);
172 int icons = addPreference(tr("PREF_ICONS"), themeGroup, LightApp_Preferences::Selector, "MEDCalc", "icons" );
173 QStringList iconsThemes;
174 iconsThemes.append(tr("PREF_ICON_THEME_MODERN"));
175 iconsThemes.append(tr("PREF_ICON_THEME_CLASSIC"));
176 QList<QVariant> indices;
179 setPreferenceProperty(icons, "strings", iconsThemes);
180 setPreferenceProperty(icons, "indexes", indices);
184 MEDModule::activateModule( SUIT_Study* theStudy )
186 if ( CORBA::is_nil( _MED_engine ) )
189 // call parent implementation
190 bool bOk = SalomeApp_Module::activateModule( theStudy );
195 setMenuShown( true );
197 setToolShown( true );
199 //this->createStudyComponent(theStudy);
200 _workspaceController->showDockWidgets(true);
201 _presentationController->showDockWidgets(true);
202 //this->setDockLayout(StandardApp_Module::DOCKLAYOUT_LEFT_VLARGE);
204 // return the activation status
209 MEDModule::deactivateModule( SUIT_Study* theStudy )
211 _workspaceController->showDockWidgets(false);
212 _presentationController->showDockWidgets(false);
213 //this->unsetDockLayout();
216 setMenuShown( false );
218 setToolShown( false );
220 // call parent implementation and return the activation status
221 return SalomeApp_Module::deactivateModule( theStudy );
225 // =====================================================================
226 // This part add custom widgets (a dockwidget containing a tree view
227 // in this example) and add special actions in the toolbox of the
229 // =====================================================================
233 * This function implements the interface StandardApp_Module. It
234 * creates the widgets specific for this module, in particular the
235 * workspace widget and the dataspace widget.
238 MEDModule::createModuleWidgets() {
239 _studyEditor = new SALOME_AppStudyEditor(getApp());
240 _datasourceController = new DatasourceController(this);
241 _workspaceController = new WorkspaceController(this);
242 _xmedDataModel = new XmedDataModel();
243 _workspaceController->setDataModel(_xmedDataModel);
244 _presentationController = new PresentationController(this);
245 _processingController = new ProcessingController(this);
247 connect(_datasourceController, SIGNAL(datasourceSignal(const DatasourceEvent*)),
248 _workspaceController, SLOT(processDatasourceEvent(const DatasourceEvent*)));
250 connect(_presentationController, SIGNAL(presentationSignal(const PresentationEvent*)),
251 _workspaceController, SLOT(processPresentationEvent(const PresentationEvent*)));
253 connect(_processingController, SIGNAL(processingSignal(const ProcessingEvent*)),
254 _workspaceController, SLOT(processProcessingEvent(const ProcessingEvent*)));
256 connect(_workspaceController, SIGNAL(workspaceSignal(const MEDCALC::MedEvent*)),
257 _datasourceController, SLOT(processWorkspaceEvent(const MEDCALC::MedEvent*)));
259 connect(_workspaceController, SIGNAL(workspaceSignal(const MEDCALC::MedEvent*)),
260 _presentationController, SLOT(processWorkspaceEvent(const MEDCALC::MedEvent*)));
262 // Now that the workspace controller is created, ParaView core application has normally been started,
263 // and hidden GUI elements have been created. We can fire the VCR toolbar activation:
268 MEDModule::initToolbars()
270 // VCR and Time toolbars:
271 SUIT_Desktop* dsk = getApp()->desktop();
272 _pvGuiElements = PVViewer_GUIElements::GetInstance(dsk);
274 _pvGuiElements->getVCRToolbar(); // make sure VCR toolbar is built
275 _pvGuiElements->setToolBarVisible(false);
276 _pvGuiElements->setVCRTimeToolBarVisible(true);
278 // Emit signal in order to make sure that animation scene is set - same trick as in PARAVIS module activation
279 QMetaObject::invokeMethod( pqPVApplicationCore::instance()->animationManager(),
280 "activeSceneChanged",
281 Q_ARG( pqAnimationScene*, pqPVApplicationCore::instance()->animationManager()->getActiveScene() ) );
285 MEDModule::createModuleActions() {
286 _datasourceController->createActions();
287 _workspaceController->createActions();
288 _presentationController->createActions();
289 _processingController->createActions();
293 MEDModule::createStandardAction(const QString& label,
295 const char* slotmember,
296 const QString& iconName,
297 const QString& tooltip)
299 SUIT_Desktop* dsk = getApp()->desktop();
300 SUIT_ResourceMgr* resMgr = getApp()->resourceMgr();
302 // If the tooltip is not defined, we choose instead the label text.
303 QString effToolTip(tooltip);
304 if ( effToolTip.isEmpty() )
307 QAction* action = createAction(-1,
309 resMgr->loadPixmap("MED", iconName),
318 return actionId(action);
322 MEDModule::addActionInPopupMenu(int actionId,const QString& menus,const QString& rule)
324 // _GBO_ for a fine customization of the rule (for example with a
325 // test on the type of the selected object), see the LIGHT module:
326 // implement "LightApp_Selection* createSelection() const;"
328 QtxPopupMgr* mgr = this->popupMgr();
329 this->action( actionId )->setIconVisibleInMenu(true);
330 if (! menus.isEmpty())
331 mgr->insert ( this->action( actionId ), menus, parentId, 0 );
333 mgr->insert ( this->action( actionId ), parentId, 0 );
334 mgr->setRule( this->action( actionId ), rule, QtxPopupMgr::VisibleRule );
337 MEDCALC::MEDPresentationViewMode
338 MEDModule::getSelectedViewMode()
340 return _presentationController->getSelectedViewMode();
343 MEDCALC::MEDPresentationColorMap
344 MEDModule::getSelectedColorMap()
346 return _presentationController->getSelectedColorMap();
350 MEDModule::itemClickGeneric(const QModelIndex & index, std::string & name, int & fieldId, int & presId) const
352 DataObjectList dol = getApp()->objectBrowser()->getSelected();
355 SalomeApp_DataObject* item = dynamic_cast<SalomeApp_DataObject*>(dol[0]);
358 SalomeApp_DataModel *model = dynamic_cast<SalomeApp_DataModel*>(dataModel());
362 if (item->componentDataType().toStdString() != "MED")
364 _PTR(SObject) obj = item->object();
365 _PTR(GenericAttribute) anAttribute;
367 if (! obj->FindAttribute(anAttribute, "AttributeName"))
369 _PTR(AttributeName) attrName(anAttribute);
370 name = attrName->Value();
372 if (! obj->FindAttribute(anAttribute, "AttributeParameter"))
374 _PTR(AttributeParameter) attrParam(anAttribute);
375 if (! attrParam->IsSet(IS_PRESENTATION, PT_BOOLEAN)
376 || ! attrParam->GetBool(IS_PRESENTATION)) { // Not a presentation
379 if (!attrParam->IsSet(FIELD_ID, PT_INTEGER))
381 fieldId = attrParam->GetInt(FIELD_ID);
382 if (!attrParam->IsSet(PRESENTATION_ID, PT_INTEGER))
384 presId = attrParam->GetInt(PRESENTATION_ID);
389 MEDModule::onClick(const QModelIndex & index)
393 if (!itemClickGeneric(index, name, fieldId, presId))
396 STDLOG("Presentation selection (activate view)");
397 std::ostringstream oss;
398 oss << fieldId << " / " << presId;
399 STDLOG(" - Field id / pres id: " + oss.str());
400 STDLOG(" - Presentation name: " + name);
402 _presManager->activateView(presId);
406 MEDModule::onDblClick(const QModelIndex& index)
410 if (!itemClickGeneric(index, name, fieldId, presId))
413 STDLOG("Presentation edition: NOT IMPLEMENTED YET");
414 STDLOG(" Presention infos:");
415 // STDLOG(" - Component: " + item->componentDataType().toStdString());
416 // STDLOG(" - Item entry: " + item->entry().toStdString());
417 // STDLOG(" - Item name: " + item->name().toStdString());
418 std::ostringstream oss;
420 STDLOG(" - Field id: " + oss.str());
421 STDLOG(" - Presentation name: " + name);
424 // get edited values from a popup widget
426 // call presentation edit function