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"
50 #include <pqAnimationManager.h>
51 #include <pqPVApplicationCore.h>
54 //! The only instance of the reference to engine
55 MED_ORB::MED_Gen_var MEDModule::myEngine;
57 MEDModule::MEDModule() :
58 SalomeApp_Module("MED"), _studyEditor(0),
59 _datasourceController(0), _workspaceController(0), _presentationController(0),
60 _processingController(0), _pvGuiElements(0)
62 // Note also that we can't use the getApp() function here because
63 // the initialize(...) function has not been called yet.
65 init(); // internal initialization
68 MEDModule::~MEDModule()
72 if (_datasourceController)
73 delete _datasourceController;
74 //if (_workspaceController)
75 // delete _workspaceController;
76 if (_presentationController)
77 delete _presentationController;
78 if (_processingController)
79 delete _processingController;
85 init(); // initialize engine, if necessary
92 // initialize MED module engine (load, if necessary)
93 if ( CORBA::is_nil( myEngine ) ) {
94 Engines::EngineComponent_var comp =
95 SalomeApp_Application::lcc()->FindOrLoad_Component( "FactoryServer", "MED" );
96 myEngine = MED_ORB::MED_Gen::_narrow( comp );
101 MEDModule::initialize( CAM_Application* app )
103 // call the parent implementation
104 SalomeApp_Module::initialize( app );
106 if (app && app->desktop()) {
107 connect((QObject*) (getApp()->objectBrowser()->treeView()), SIGNAL(doubleClicked(const QModelIndex&)),
108 this, SLOT(onDblClick(const QModelIndex&)));
109 connect((QObject*) (getApp()->objectBrowser()->treeView()), SIGNAL(clicked(const QModelIndex&)),
110 this, SLOT(onClick(const QModelIndex&)));
113 // The following initializes the GUI widget and associated actions
114 this->createModuleWidgets();
115 this->createModuleActions();
119 MEDModule::engineIOR() const
121 init(); // initialize engine, if necessary
122 CORBA::String_var anIOR = getApp()->orb()->object_to_string( myEngine.in() );
123 return QString( anIOR.in() );
127 MEDModule::iconName() const
129 return tr("ICO_MED_SMALL");
133 MEDModule::windows( QMap<int, int>& theMap ) const
135 // want Object browser, in the left area
136 theMap.insert( SalomeApp_Application::WT_ObjectBrowser,
137 Qt::LeftDockWidgetArea );
138 #ifndef DISABLE_PYCONSOLE
139 // want Python console, in the bottom area
140 theMap.insert( SalomeApp_Application::WT_PyConsole,
141 Qt::BottomDockWidgetArea );
146 MEDModule::viewManagers( QStringList& list ) const
148 #ifndef DISABLE_PVVIEWER
149 list.append( PVViewer_Viewer::Type() );
154 MEDModule::createPreferences()
156 int genTab = addPreference(tr("PREF_TAB_GENERAL"));
158 int themeGroup = addPreference(tr("PREF_THEME_GROUP"), genTab);
159 setPreferenceProperty(themeGroup, "columns", 2);
160 int icons = addPreference(tr("PREF_ICONS"), themeGroup, LightApp_Preferences::Selector, "MEDCalc", "icons" );
161 QStringList iconsThemes;
162 iconsThemes.append(tr("PREF_ICON_THEME_MODERN"));
163 iconsThemes.append(tr("PREF_ICON_THEME_CLASSIC"));
164 QList<QVariant> indices;
167 setPreferenceProperty(icons, "strings", iconsThemes);
168 setPreferenceProperty(icons, "indexes", indices);
172 MEDModule::activateModule( SUIT_Study* theStudy )
174 if ( CORBA::is_nil( myEngine ) )
177 // call parent implementation
178 bool bOk = SalomeApp_Module::activateModule( theStudy );
183 setMenuShown( true );
185 setToolShown( true );
187 //this->createStudyComponent(theStudy);
188 _workspaceController->showDockWidgets(true);
189 _presentationController->showDockWidgets(true);
190 //this->setDockLayout(StandardApp_Module::DOCKLAYOUT_LEFT_VLARGE);
192 // return the activation status
197 MEDModule::deactivateModule( SUIT_Study* theStudy )
199 _workspaceController->showDockWidgets(false);
200 _presentationController->showDockWidgets(false);
201 //this->unsetDockLayout();
204 setMenuShown( false );
206 setToolShown( false );
208 // call parent implementation and return the activation status
209 return SalomeApp_Module::deactivateModule( theStudy );
213 // =====================================================================
214 // This part add custom widgets (a dockwidget containing a tree view
215 // in this example) and add special actions in the toolbox of the
217 // =====================================================================
221 * This function implements the interface StandardApp_Module. It
222 * creates the widgets specific for this module, in particular the
223 * workspace widget and the dataspace widget.
226 MEDModule::createModuleWidgets() {
227 _studyEditor = new SALOME_AppStudyEditor(getApp());
228 _datasourceController = new DatasourceController(this);
229 _workspaceController = new WorkspaceController(this);
230 _xmedDataModel = new XmedDataModel();
231 _workspaceController->setDataModel(_xmedDataModel);
232 _presentationController = new PresentationController(this);
233 _processingController = new ProcessingController(this);
235 connect(_datasourceController, SIGNAL(datasourceSignal(const DatasourceEvent*)),
236 _workspaceController, SLOT(processDatasourceEvent(const DatasourceEvent*)));
238 connect(_presentationController, SIGNAL(presentationSignal(const PresentationEvent*)),
239 _workspaceController, SLOT(processPresentationEvent(const PresentationEvent*)));
241 connect(_processingController, SIGNAL(processingSignal(const ProcessingEvent*)),
242 _workspaceController, SLOT(processProcessingEvent(const ProcessingEvent*)));
244 connect(_workspaceController, SIGNAL(workspaceSignal(const MEDCALC::MedEvent*)),
245 _datasourceController, SLOT(processWorkspaceEvent(const MEDCALC::MedEvent*)));
247 connect(_workspaceController, SIGNAL(workspaceSignal(const MEDCALC::MedEvent*)),
248 _presentationController, SLOT(processWorkspaceEvent(const MEDCALC::MedEvent*)));
250 // Now that the workspace controller is created, ParaView core application has normally been started,
251 // and hidden GUI elements have been created. We can fire the VCR toolbar activation:
256 MEDModule::initToolbars()
258 // VCR and Time toolbars:
259 SUIT_Desktop* dsk = getApp()->desktop();
260 _pvGuiElements = PVViewer_GUIElements::GetInstance(dsk);
262 _pvGuiElements->getVCRToolbar(); // make sure VCR toolbar is built
263 _pvGuiElements->setToolBarVisible(false);
264 _pvGuiElements->setVCRTimeToolBarVisible(true);
266 // Emit signal in order to make sure that animation scene is set - same trick as in PARAVIS module activation
267 QMetaObject::invokeMethod( pqPVApplicationCore::instance()->animationManager(),
268 "activeSceneChanged",
269 Q_ARG( pqAnimationScene*, pqPVApplicationCore::instance()->animationManager()->getActiveScene() ) );
273 MEDModule::createModuleActions() {
274 _datasourceController->createActions();
275 _workspaceController->createActions();
276 _presentationController->createActions();
277 _processingController->createActions();
281 MEDModule::createStandardAction(const QString& label,
283 const char* slotmember,
284 const QString& iconName,
285 const QString& tooltip)
287 SUIT_Desktop* dsk = getApp()->desktop();
288 SUIT_ResourceMgr* resMgr = getApp()->resourceMgr();
290 // If the tooltip is not defined, we choose instead the label text.
291 QString effToolTip(tooltip);
292 if ( effToolTip.isEmpty() )
295 QAction* action = createAction(-1,
297 resMgr->loadPixmap("MED", iconName),
306 return actionId(action);
310 MEDModule::addActionInPopupMenu(int actionId,const QString& menus,const QString& rule)
312 // _GBO_ for a fine customization of the rule (for example with a
313 // test on the type of the selected object), see the LIGHT module:
314 // implement "LightApp_Selection* createSelection() const;"
316 QtxPopupMgr* mgr = this->popupMgr();
317 this->action( actionId )->setIconVisibleInMenu(true);
318 if (! menus.isEmpty())
319 mgr->insert ( this->action( actionId ), menus, parentId, 0 );
321 mgr->insert ( this->action( actionId ), parentId, 0 );
322 mgr->setRule( this->action( actionId ), rule, QtxPopupMgr::VisibleRule );
325 MEDCALC::MEDPresentationViewMode
326 MEDModule::getSelectedViewMode()
328 return _presentationController->getSelectedViewMode();
331 MEDCALC::MEDPresentationColorMap
332 MEDModule::getSelectedColorMap()
334 return _presentationController->getSelectedColorMap();
338 MEDModule::itemClickGeneric(const QModelIndex & index, std::string & name, int & fieldId, int & presId) const
340 DataObjectList dol = getApp()->objectBrowser()->getSelected();
343 SalomeApp_DataObject* item = dynamic_cast<SalomeApp_DataObject*>(dol[0]);
346 SalomeApp_DataModel *model = dynamic_cast<SalomeApp_DataModel*>(dataModel());
350 if (item->componentDataType().toStdString() != "MED")
352 _PTR(SObject) obj = item->object();
353 _PTR(GenericAttribute) anAttribute;
355 if (! obj->FindAttribute(anAttribute, "AttributeName"))
357 _PTR(AttributeName) attrName(anAttribute);
358 name = attrName->Value();
360 if (! obj->FindAttribute(anAttribute, "AttributeParameter"))
362 _PTR(AttributeParameter) attrParam(anAttribute);
363 if (! attrParam->IsSet(IS_PRESENTATION, PT_BOOLEAN)
364 || ! attrParam->GetBool(IS_PRESENTATION)) { // Not a presentation
367 if (!attrParam->IsSet(FIELD_ID, PT_INTEGER))
369 fieldId = attrParam->GetInt(FIELD_ID);
370 if (!attrParam->IsSet(PRESENTATION_ID, PT_INTEGER))
372 presId = attrParam->GetInt(PRESENTATION_ID);
377 MEDModule::onClick(const QModelIndex & index)
381 if (!itemClickGeneric(index, name, fieldId, presId))
384 STDLOG("Presentation selection (should activate view): NOT IMPLEMENTED YET");
385 STDLOG(" Presention infos:");
386 std::ostringstream oss;
387 oss << fieldId << " / " << presId;
388 STDLOG(" - Field id / pres id: " + oss.str());
389 STDLOG(" - Presentation name: " + name);
391 // TODO: activate corresponding view
396 MEDModule::onDblClick(const QModelIndex& index)
400 if (!itemClickGeneric(index, name, fieldId, presId))
403 STDLOG("Presentation edition: NOT IMPLEMENTED YET");
404 STDLOG(" Presention infos:");
405 // STDLOG(" - Component: " + item->componentDataType().toStdString());
406 // STDLOG(" - Item entry: " + item->entry().toStdString());
407 // STDLOG(" - Item name: " + item->name().toStdString());
408 std::ostringstream oss;
410 STDLOG(" - Field id: " + oss.str());
411 STDLOG(" - Presentation name: " + name);
414 // get edited values from a popup widget
416 // call presentation edit function