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"
49 //! The only instance of the reference to engine
50 MED_ORB::MED_Gen_var MEDModule::myEngine;
52 MEDModule::MEDModule() :
53 SalomeApp_Module("MED"), _studyEditor(0), _datasourceController(0), _workspaceController(0), _presentationController(0), _processingController(0)
55 // Note also that we can't use the getApp() function here because
56 // the initialize(...) function has not been called yet.
58 init(); // internal initialization
61 MEDModule::~MEDModule()
65 if (_datasourceController)
66 delete _datasourceController;
67 //if (_workspaceController)
68 // delete _workspaceController;
69 if (_presentationController)
70 delete _presentationController;
71 if (_processingController)
72 delete _processingController;
78 init(); // initialize engine, if necessary
85 // initialize MED module engine (load, if necessary)
86 if ( CORBA::is_nil( myEngine ) ) {
87 Engines::EngineComponent_var comp =
88 SalomeApp_Application::lcc()->FindOrLoad_Component( "FactoryServer", "MED" );
89 myEngine = MED_ORB::MED_Gen::_narrow( comp );
94 MEDModule::initialize( CAM_Application* app )
96 // call the parent implementation
97 SalomeApp_Module::initialize( app );
99 if (app && app->desktop()) {
100 connect((QObject*) (getApp()->objectBrowser()->treeView()), SIGNAL(doubleClicked(const QModelIndex&)),
101 this, SLOT(onDblClick(const QModelIndex&)));
104 // The following initializes the GUI widget and associated actions
105 this->createModuleWidgets();
106 this->createModuleActions();
110 MEDModule::engineIOR() const
112 init(); // initialize engine, if necessary
113 CORBA::String_var anIOR = getApp()->orb()->object_to_string( myEngine.in() );
114 return QString( anIOR.in() );
118 MEDModule::iconName() const
120 return tr("ICO_MED_SMALL");
124 MEDModule::windows( QMap<int, int>& theMap ) const
126 // want Object browser, in the left area
127 theMap.insert( SalomeApp_Application::WT_ObjectBrowser,
128 Qt::LeftDockWidgetArea );
129 #ifndef DISABLE_PYCONSOLE
130 // want Python console, in the bottom area
131 theMap.insert( SalomeApp_Application::WT_PyConsole,
132 Qt::BottomDockWidgetArea );
137 MEDModule::viewManagers( QStringList& list ) const
139 #ifndef DISABLE_PVVIEWER
140 list.append( PVViewer_Viewer::Type() );
145 MEDModule::createPreferences()
147 int genTab = addPreference(tr("PREF_TAB_GENERAL"));
149 int themeGroup = addPreference(tr("PREF_THEME_GROUP"), genTab);
150 setPreferenceProperty(themeGroup, "columns", 2);
151 int icons = addPreference(tr("PREF_ICONS"), themeGroup, LightApp_Preferences::Selector, "MEDCalc", "icons" );
152 QStringList iconsThemes;
153 iconsThemes.append(tr("PREF_ICON_THEME_MODERN"));
154 iconsThemes.append(tr("PREF_ICON_THEME_CLASSIC"));
155 QList<QVariant> indices;
158 setPreferenceProperty(icons, "strings", iconsThemes);
159 setPreferenceProperty(icons, "indexes", indices);
163 MEDModule::activateModule( SUIT_Study* theStudy )
165 if ( CORBA::is_nil( myEngine ) )
168 // call parent implementation
169 bool bOk = SalomeApp_Module::activateModule( theStudy );
174 setMenuShown( true );
176 setToolShown( true );
178 //this->createStudyComponent(theStudy);
179 _workspaceController->showDockWidgets(true);
180 _presentationController->showDockWidgets(true);
181 //this->setDockLayout(StandardApp_Module::DOCKLAYOUT_LEFT_VLARGE);
183 // return the activation status
188 MEDModule::deactivateModule( SUIT_Study* theStudy )
190 _workspaceController->showDockWidgets(false);
191 _presentationController->showDockWidgets(false);
192 //this->unsetDockLayout();
195 setMenuShown( false );
197 setToolShown( false );
199 // call parent implementation and return the activation status
200 return SalomeApp_Module::deactivateModule( theStudy );
204 // =====================================================================
205 // This part add custom widgets (a dockwidget containing a tree view
206 // in this example) and add special actions in the toolbox of the
208 // =====================================================================
212 * This function implements the interface StandardApp_Module. It
213 * creates the widgets specific for this module, in particular the
214 * workspace widget and the dataspace widget.
217 MEDModule::createModuleWidgets() {
218 _studyEditor = new SALOME_AppStudyEditor(getApp());
219 _datasourceController = new DatasourceController(this);
220 _workspaceController = new WorkspaceController(this);
221 _xmedDataModel = new XmedDataModel();
222 _workspaceController->setDataModel(_xmedDataModel);
223 _presentationController = new PresentationController(this);
224 _processingController = new ProcessingController(this);
225 #ifdef MED_HAS_QTTESTING
226 _testController = new TestController(this);
229 connect(_datasourceController, SIGNAL(datasourceSignal(const DatasourceEvent*)),
230 _workspaceController, SLOT(processDatasourceEvent(const DatasourceEvent*)));
232 connect(_presentationController, SIGNAL(presentationSignal(const PresentationEvent*)),
233 _workspaceController, SLOT(processPresentationEvent(const PresentationEvent*)));
235 connect(_processingController, SIGNAL(processingSignal(const ProcessingEvent*)),
236 _workspaceController, SLOT(processProcessingEvent(const ProcessingEvent*)));
238 connect(_workspaceController, SIGNAL(workspaceSignal(const MEDCALC::MedEvent*)),
239 _datasourceController, SLOT(processWorkspaceEvent(const MEDCALC::MedEvent*)));
241 connect(_workspaceController, SIGNAL(workspaceSignal(const MEDCALC::MedEvent*)),
242 _presentationController, SLOT(processWorkspaceEvent(const MEDCALC::MedEvent*)));
244 #ifdef MED_HAS_QTTESTING
245 connect(_workspaceController, SIGNAL(workspaceSignal(const MEDCALC::MedEvent*)),
246 _testController, SLOT(processWorkspaceEvent(const MEDCALC::MedEvent*)));
251 MEDModule::createModuleActions() {
252 _datasourceController->createActions();
253 _workspaceController->createActions();
254 _presentationController->createActions();
255 _processingController->createActions();
256 #ifdef MED_HAS_QTTESTING
257 _testController->createActions();
262 MEDModule::createStandardAction(const QString& label,
264 const char* slotmember,
265 const QString& iconName,
266 const QString& tooltip)
268 SUIT_Desktop* dsk = getApp()->desktop();
269 SUIT_ResourceMgr* resMgr = getApp()->resourceMgr();
271 // If the tooltip is not defined, we choose instead the label text.
272 QString effToolTip(tooltip);
273 if ( effToolTip.isEmpty() )
277 if (iconName.isEmpty())
280 ico = QIcon(resMgr->loadPixmap("MED", iconName));
282 QAction* action = createAction(-1,
293 return actionId(action);
297 MEDModule::addActionInPopupMenu(int actionId,const QString& menus,const QString& rule)
299 // _GBO_ for a fine customization of the rule (for example with a
300 // test on the type of the selected object), see the LIGTH module:
301 // implement "LightApp_Selection* createSelection() const;"
303 QtxPopupMgr* mgr = this->popupMgr();
304 this->action( actionId )->setIconVisibleInMenu(true);
305 if (! menus.isEmpty())
306 mgr->insert ( this->action( actionId ), menus, parentId, 0 );
308 mgr->insert ( this->action( actionId ), parentId, 0 );
309 mgr->setRule( this->action( actionId ), rule, QtxPopupMgr::VisibleRule );
312 MEDCALC::MEDPresentationViewMode
313 MEDModule::getSelectedViewMode()
315 return _presentationController->getSelectedViewMode();
318 MEDCALC::MEDPresentationColorMap
319 MEDModule::getSelectedColorMap()
321 return _presentationController->getSelectedColorMap();
325 MEDModule::onDblClick(const QModelIndex& index)
327 DataObjectList dol = getApp()->objectBrowser()->getSelected();
330 SalomeApp_DataObject* item = dynamic_cast<SalomeApp_DataObject*>(dol[0]);
333 SalomeApp_DataModel *model = dynamic_cast<SalomeApp_DataModel*>(dataModel());
337 if (item->componentDataType().toStdString() != "MED")
339 _PTR(SObject) obj = item->object();
340 _PTR(GenericAttribute) anAttribute;
342 if (! obj->FindAttribute(anAttribute, "AttributeName"))
344 _PTR(AttributeName) attrName(anAttribute);
345 std::string name = attrName->Value();
347 if (! obj->FindAttribute(anAttribute, "AttributeParameter"))
349 _PTR(AttributeParameter) attrParam(anAttribute);
350 if (! attrParam->IsSet(IS_PRESENTATION, PT_BOOLEAN)
351 || ! attrParam->GetBool(IS_PRESENTATION)) { // Not a presentation
354 if (!attrParam->IsSet(FIELD_ID, PT_INTEGER))
356 int fieldId = attrParam->GetInt(FIELD_ID);
358 STDLOG("Presentation edition: NOT IMPLEMENTED YET");
359 STDLOG(" Presention infos:");
360 STDLOG(" - Component: " + item->componentDataType().toStdString());
361 STDLOG(" - Item entry: " + item->entry().toStdString());
362 STDLOG(" - Item name: " + item->name().toStdString());
363 std::ostringstream oss;
365 STDLOG(" - Field id: " + oss.str());
366 STDLOG(" - Presentation name: " + name);
371 MEDModule::onPlayTest(const char * filename)