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"
51 //! The only instance of the reference to engine
52 MED_ORB::MED_Gen_var MEDModule::myEngine;
54 MEDModule::MEDModule() :
55 SalomeApp_Module("MED"), _studyEditor(0), _datasourceController(0), _workspaceController(0),
56 _presentationController(0), _processingController(0)
58 // Note also that we can't use the getApp() function here because
59 // the initialize(...) function has not been called yet.
61 init(); // internal initialization
64 MEDModule::~MEDModule()
68 if (_datasourceController)
69 delete _datasourceController;
70 //if (_workspaceController)
71 // delete _workspaceController;
72 if (_presentationController)
73 delete _presentationController;
74 if (_processingController)
75 delete _processingController;
81 init(); // initialize engine, if necessary
88 // initialize MED module engine (load, if necessary)
89 if ( CORBA::is_nil( myEngine ) ) {
90 Engines::EngineComponent_var comp =
91 SalomeApp_Application::lcc()->FindOrLoad_Component( "FactoryServer", "MED" );
92 myEngine = MED_ORB::MED_Gen::_narrow( comp );
96 //void MEDModule::onEventLoopStarted()
98 // if(!getApp()->isMainEventLoopStarted())
100 // QTimer::singleShot(100, this, SLOT(onEventLoopStarted()));
106 MEDModule::initialize( CAM_Application* app )
108 // call the parent implementation
109 SalomeApp_Module::initialize( app );
111 if (app && app->desktop()) {
112 connect((QObject*) (getApp()->objectBrowser()->treeView()), SIGNAL(doubleClicked(const QModelIndex&)),
113 this, SLOT(onDblClick(const QModelIndex&)));
116 // The following initializes the GUI widget and associated actions
117 this->createModuleWidgets();
118 this->createModuleActions();
122 MEDModule::engineIOR() const
124 init(); // initialize engine, if necessary
125 CORBA::String_var anIOR = getApp()->orb()->object_to_string( myEngine.in() );
126 return QString( anIOR.in() );
130 MEDModule::iconName() const
132 return tr("ICO_MED_SMALL");
136 MEDModule::windows( QMap<int, int>& theMap ) const
138 // want Object browser, in the left area
139 theMap.insert( SalomeApp_Application::WT_ObjectBrowser,
140 Qt::LeftDockWidgetArea );
141 #ifndef DISABLE_PYCONSOLE
142 // want Python console, in the bottom area
143 theMap.insert( SalomeApp_Application::WT_PyConsole,
144 Qt::BottomDockWidgetArea );
149 MEDModule::viewManagers( QStringList& list ) const
151 #ifndef DISABLE_PVVIEWER
152 list.append( PVViewer_Viewer::Type() );
157 MEDModule::createPreferences()
159 int genTab = addPreference(tr("PREF_TAB_GENERAL"));
161 int themeGroup = addPreference(tr("PREF_THEME_GROUP"), genTab);
162 setPreferenceProperty(themeGroup, "columns", 2);
163 int icons = addPreference(tr("PREF_ICONS"), themeGroup, LightApp_Preferences::Selector, "MEDCalc", "icons" );
164 QStringList iconsThemes;
165 iconsThemes.append(tr("PREF_ICON_THEME_MODERN"));
166 iconsThemes.append(tr("PREF_ICON_THEME_CLASSIC"));
167 QList<QVariant> indices;
170 setPreferenceProperty(icons, "strings", iconsThemes);
171 setPreferenceProperty(icons, "indexes", indices);
175 MEDModule::activateModule( SUIT_Study* theStudy )
177 if ( CORBA::is_nil( myEngine ) )
180 // call parent implementation
181 bool bOk = SalomeApp_Module::activateModule( theStudy );
186 setMenuShown( true );
188 setToolShown( true );
190 //this->createStudyComponent(theStudy);
191 _workspaceController->showDockWidgets(true);
192 _presentationController->showDockWidgets(true);
193 //this->setDockLayout(StandardApp_Module::DOCKLAYOUT_LEFT_VLARGE);
195 // Mark the start of the main event loop - important for test playback:
196 // QObject::connect(getApp(), SIGNAL(activated(SUIT_Application *)), this, SLOT(onEventLoopStarted(SUIT_Application *)));
197 // QTimer::singleShot(0, this, SLOT(onEventLoopStarted()));
199 // return the activation status
204 MEDModule::deactivateModule( SUIT_Study* theStudy )
206 _workspaceController->showDockWidgets(false);
207 _presentationController->showDockWidgets(false);
208 //this->unsetDockLayout();
211 setMenuShown( false );
213 setToolShown( false );
215 // call parent implementation and return the activation status
216 return SalomeApp_Module::deactivateModule( theStudy );
220 // =====================================================================
221 // This part add custom widgets (a dockwidget containing a tree view
222 // in this example) and add special actions in the toolbox of the
224 // =====================================================================
228 * This function implements the interface StandardApp_Module. It
229 * creates the widgets specific for this module, in particular the
230 * workspace widget and the dataspace widget.
233 MEDModule::createModuleWidgets() {
234 _studyEditor = new SALOME_AppStudyEditor(getApp());
235 _datasourceController = new DatasourceController(this);
236 _workspaceController = new WorkspaceController(this);
237 _xmedDataModel = new XmedDataModel();
238 _workspaceController->setDataModel(_xmedDataModel);
239 _presentationController = new PresentationController(this);
240 _processingController = new ProcessingController(this);
241 #ifdef MED_HAS_QTTESTING
242 _testController = new TestController(this);
245 connect(_datasourceController, SIGNAL(datasourceSignal(const DatasourceEvent*)),
246 _workspaceController, SLOT(processDatasourceEvent(const DatasourceEvent*)));
248 connect(_presentationController, SIGNAL(presentationSignal(const PresentationEvent*)),
249 _workspaceController, SLOT(processPresentationEvent(const PresentationEvent*)));
251 connect(_processingController, SIGNAL(processingSignal(const ProcessingEvent*)),
252 _workspaceController, SLOT(processProcessingEvent(const ProcessingEvent*)));
254 connect(_workspaceController, SIGNAL(workspaceSignal(const MEDCALC::MedEvent*)),
255 _datasourceController, SLOT(processWorkspaceEvent(const MEDCALC::MedEvent*)));
257 connect(_workspaceController, SIGNAL(workspaceSignal(const MEDCALC::MedEvent*)),
258 _presentationController, SLOT(processWorkspaceEvent(const MEDCALC::MedEvent*)));
260 #ifdef MED_HAS_QTTESTING
261 connect(_workspaceController, SIGNAL(workspaceSignal(const MEDCALC::MedEvent*)),
262 _testController, SLOT(processWorkspaceEvent(const MEDCALC::MedEvent*)));
267 MEDModule::createModuleActions() {
268 _datasourceController->createActions();
269 _workspaceController->createActions();
270 _presentationController->createActions();
271 _processingController->createActions();
272 #ifdef MED_HAS_QTTESTING
273 _testController->createActions();
278 MEDModule::createStandardAction(const QString& label,
280 const char* slotmember,
281 const QString& iconName,
282 const QString& tooltip)
284 SUIT_Desktop* dsk = getApp()->desktop();
285 SUIT_ResourceMgr* resMgr = getApp()->resourceMgr();
287 // If the tooltip is not defined, we choose instead the label text.
288 QString effToolTip(tooltip);
289 if ( effToolTip.isEmpty() )
293 if (iconName.isEmpty())
296 ico = QIcon(resMgr->loadPixmap("MED", iconName));
298 QAction* action = createAction(-1,
309 return actionId(action);
313 MEDModule::addActionInPopupMenu(int actionId,const QString& menus,const QString& rule)
315 // _GBO_ for a fine customization of the rule (for example with a
316 // test on the type of the selected object), see the LIGTH module:
317 // implement "LightApp_Selection* createSelection() const;"
319 QtxPopupMgr* mgr = this->popupMgr();
320 this->action( actionId )->setIconVisibleInMenu(true);
321 if (! menus.isEmpty())
322 mgr->insert ( this->action( actionId ), menus, parentId, 0 );
324 mgr->insert ( this->action( actionId ), parentId, 0 );
325 mgr->setRule( this->action( actionId ), rule, QtxPopupMgr::VisibleRule );
328 MEDCALC::MEDPresentationViewMode
329 MEDModule::getSelectedViewMode()
331 return _presentationController->getSelectedViewMode();
334 MEDCALC::MEDPresentationColorMap
335 MEDModule::getSelectedColorMap()
337 return _presentationController->getSelectedColorMap();
341 MEDModule::onDblClick(const QModelIndex& index)
343 DataObjectList dol = getApp()->objectBrowser()->getSelected();
346 SalomeApp_DataObject* item = dynamic_cast<SalomeApp_DataObject*>(dol[0]);
349 SalomeApp_DataModel *model = dynamic_cast<SalomeApp_DataModel*>(dataModel());
353 if (item->componentDataType().toStdString() != "MED")
355 _PTR(SObject) obj = item->object();
356 _PTR(GenericAttribute) anAttribute;
358 if (! obj->FindAttribute(anAttribute, "AttributeName"))
360 _PTR(AttributeName) attrName(anAttribute);
361 std::string name = attrName->Value();
363 if (! obj->FindAttribute(anAttribute, "AttributeParameter"))
365 _PTR(AttributeParameter) attrParam(anAttribute);
366 if (! attrParam->IsSet(IS_PRESENTATION, PT_BOOLEAN)
367 || ! attrParam->GetBool(IS_PRESENTATION)) { // Not a presentation
370 if (!attrParam->IsSet(FIELD_ID, PT_INTEGER))
372 int fieldId = attrParam->GetInt(FIELD_ID);
374 STDLOG("Presentation edition: NOT IMPLEMENTED YET");
375 STDLOG(" Presention infos:");
376 STDLOG(" - Component: " + item->componentDataType().toStdString());
377 STDLOG(" - Item entry: " + item->entry().toStdString());
378 STDLOG(" - Item name: " + item->name().toStdString());
379 std::ostringstream oss;
381 STDLOG(" - Field id: " + oss.str());
382 STDLOG(" - Presentation name: " + name);
385 // get edited values from a popup widget
387 // call presentation edit function
392 MEDModule::requestSALOMETermination() const
394 STDLOG("Requesting SALOME termination!!");
395 SUIT_Session::session()->closeSession( SUIT_Session::DONT_SAVE, 1 ); // killServers = True
399 //bool MEDModule::hasMainEventLoopStarted() const
401 // return _eventLoopStarted;