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&)));
111 // The following initializes the GUI widget and associated actions
112 this->createModuleWidgets();
113 this->createModuleActions();
117 MEDModule::engineIOR() const
119 init(); // initialize engine, if necessary
120 CORBA::String_var anIOR = getApp()->orb()->object_to_string( myEngine.in() );
121 return QString( anIOR.in() );
125 MEDModule::iconName() const
127 return tr("ICO_MED_SMALL");
131 MEDModule::windows( QMap<int, int>& theMap ) const
133 // want Object browser, in the left area
134 theMap.insert( SalomeApp_Application::WT_ObjectBrowser,
135 Qt::LeftDockWidgetArea );
136 #ifndef DISABLE_PYCONSOLE
137 // want Python console, in the bottom area
138 theMap.insert( SalomeApp_Application::WT_PyConsole,
139 Qt::BottomDockWidgetArea );
144 MEDModule::viewManagers( QStringList& list ) const
146 #ifndef DISABLE_PVVIEWER
147 list.append( PVViewer_Viewer::Type() );
152 MEDModule::createPreferences()
154 int genTab = addPreference(tr("PREF_TAB_GENERAL"));
156 int themeGroup = addPreference(tr("PREF_THEME_GROUP"), genTab);
157 setPreferenceProperty(themeGroup, "columns", 2);
158 int icons = addPreference(tr("PREF_ICONS"), themeGroup, LightApp_Preferences::Selector, "MEDCalc", "icons" );
159 QStringList iconsThemes;
160 iconsThemes.append(tr("PREF_ICON_THEME_MODERN"));
161 iconsThemes.append(tr("PREF_ICON_THEME_CLASSIC"));
162 QList<QVariant> indices;
165 setPreferenceProperty(icons, "strings", iconsThemes);
166 setPreferenceProperty(icons, "indexes", indices);
170 MEDModule::activateModule( SUIT_Study* theStudy )
172 if ( CORBA::is_nil( myEngine ) )
175 // call parent implementation
176 bool bOk = SalomeApp_Module::activateModule( theStudy );
181 setMenuShown( true );
183 setToolShown( true );
185 //this->createStudyComponent(theStudy);
186 _workspaceController->showDockWidgets(true);
187 _presentationController->showDockWidgets(true);
188 //this->setDockLayout(StandardApp_Module::DOCKLAYOUT_LEFT_VLARGE);
190 // return the activation status
195 MEDModule::deactivateModule( SUIT_Study* theStudy )
197 _workspaceController->showDockWidgets(false);
198 _presentationController->showDockWidgets(false);
199 //this->unsetDockLayout();
202 setMenuShown( false );
204 setToolShown( false );
206 // call parent implementation and return the activation status
207 return SalomeApp_Module::deactivateModule( theStudy );
211 // =====================================================================
212 // This part add custom widgets (a dockwidget containing a tree view
213 // in this example) and add special actions in the toolbox of the
215 // =====================================================================
219 * This function implements the interface StandardApp_Module. It
220 * creates the widgets specific for this module, in particular the
221 * workspace widget and the dataspace widget.
224 MEDModule::createModuleWidgets() {
225 _studyEditor = new SALOME_AppStudyEditor(getApp());
226 _datasourceController = new DatasourceController(this);
227 _workspaceController = new WorkspaceController(this);
228 _xmedDataModel = new XmedDataModel();
229 _workspaceController->setDataModel(_xmedDataModel);
230 _presentationController = new PresentationController(this);
231 _processingController = new ProcessingController(this);
233 connect(_datasourceController, SIGNAL(datasourceSignal(const DatasourceEvent*)),
234 _workspaceController, SLOT(processDatasourceEvent(const DatasourceEvent*)));
236 connect(_presentationController, SIGNAL(presentationSignal(const PresentationEvent*)),
237 _workspaceController, SLOT(processPresentationEvent(const PresentationEvent*)));
239 connect(_processingController, SIGNAL(processingSignal(const ProcessingEvent*)),
240 _workspaceController, SLOT(processProcessingEvent(const ProcessingEvent*)));
242 connect(_workspaceController, SIGNAL(workspaceSignal(const MEDCALC::MedEvent*)),
243 _datasourceController, SLOT(processWorkspaceEvent(const MEDCALC::MedEvent*)));
245 connect(_workspaceController, SIGNAL(workspaceSignal(const MEDCALC::MedEvent*)),
246 _presentationController, SLOT(processWorkspaceEvent(const MEDCALC::MedEvent*)));
248 // Now that the workspace controller is created, ParaView core application has normally been started,
249 // and hidden GUI elements have been created. We can fire the VCR toolbar activation:
254 MEDModule::initToolbars()
256 // VCR and Time toolbars:
257 SUIT_Desktop* dsk = getApp()->desktop();
258 _pvGuiElements = PVViewer_GUIElements::GetInstance(dsk);
260 _pvGuiElements->getVCRToolbar(); // make sure VCR toolbar is built
261 _pvGuiElements->setToolBarVisible(false);
262 _pvGuiElements->setVCRTimeToolBarVisible(true);
264 // Emit signal in order to make sure that animation scene is set - same trick as in PARAVIS module activation
265 QMetaObject::invokeMethod( pqPVApplicationCore::instance()->animationManager(),
266 "activeSceneChanged",
267 Q_ARG( pqAnimationScene*, pqPVApplicationCore::instance()->animationManager()->getActiveScene() ) );
271 MEDModule::createModuleActions() {
272 _datasourceController->createActions();
273 _workspaceController->createActions();
274 _presentationController->createActions();
275 _processingController->createActions();
279 MEDModule::createStandardAction(const QString& label,
281 const char* slotmember,
282 const QString& iconName,
283 const QString& tooltip)
285 SUIT_Desktop* dsk = getApp()->desktop();
286 SUIT_ResourceMgr* resMgr = getApp()->resourceMgr();
288 // If the tooltip is not defined, we choose instead the label text.
289 QString effToolTip(tooltip);
290 if ( effToolTip.isEmpty() )
293 QAction* action = createAction(-1,
295 resMgr->loadPixmap("MED", iconName),
304 return actionId(action);
308 MEDModule::addActionInPopupMenu(int actionId,const QString& menus,const QString& rule)
310 // _GBO_ for a fine customization of the rule (for example with a
311 // test on the type of the selected object), see the LIGTH module:
312 // implement "LightApp_Selection* createSelection() const;"
314 QtxPopupMgr* mgr = this->popupMgr();
315 this->action( actionId )->setIconVisibleInMenu(true);
316 if (! menus.isEmpty())
317 mgr->insert ( this->action( actionId ), menus, parentId, 0 );
319 mgr->insert ( this->action( actionId ), parentId, 0 );
320 mgr->setRule( this->action( actionId ), rule, QtxPopupMgr::VisibleRule );
323 MEDCALC::MEDPresentationViewMode
324 MEDModule::getSelectedViewMode()
326 return _presentationController->getSelectedViewMode();
329 MEDCALC::MEDPresentationColorMap
330 MEDModule::getSelectedColorMap()
332 return _presentationController->getSelectedColorMap();
336 MEDModule::onDblClick(const QModelIndex& index)
338 DataObjectList dol = getApp()->objectBrowser()->getSelected();
341 SalomeApp_DataObject* item = dynamic_cast<SalomeApp_DataObject*>(dol[0]);
344 SalomeApp_DataModel *model = dynamic_cast<SalomeApp_DataModel*>(dataModel());
348 if (item->componentDataType().toStdString() != "MED")
350 _PTR(SObject) obj = item->object();
351 _PTR(GenericAttribute) anAttribute;
353 if (! obj->FindAttribute(anAttribute, "AttributeName"))
355 _PTR(AttributeName) attrName(anAttribute);
356 std::string name = attrName->Value();
358 if (! obj->FindAttribute(anAttribute, "AttributeParameter"))
360 _PTR(AttributeParameter) attrParam(anAttribute);
361 if (! attrParam->IsSet(IS_PRESENTATION, PT_BOOLEAN)
362 || ! attrParam->GetBool(IS_PRESENTATION)) { // Not a presentation
365 if (!attrParam->IsSet(FIELD_ID, PT_INTEGER))
367 int fieldId = attrParam->GetInt(FIELD_ID);
369 STDLOG("Presentation edition: NOT IMPLEMENTED YET");
370 STDLOG(" Presention infos:");
371 STDLOG(" - Component: " + item->componentDataType().toStdString());
372 STDLOG(" - Item entry: " + item->entry().toStdString());
373 STDLOG(" - Item name: " + item->name().toStdString());
374 std::ostringstream oss;
376 STDLOG(" - Field id: " + oss.str());
377 STDLOG(" - Presentation name: " + name);
380 // get edited values from a popup widget
382 // call presentation edit function