Salome HOME
Exit procedure added in tests. Not killing all servers yet.
[modules/med.git] / src / MEDCalc / gui / WorkspaceController.cxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // Author : Guillaume Boulant (EDF)
21
22 #include "WorkspaceController.hxx"
23 #include "QtHelper.hxx"
24 #include "MEDFactoryClient.hxx"
25 #include "MEDModule.hxx"
26 #include "XmedDataModel.hxx"
27 #include "DlgAlias.hxx"
28
29 #include <SALOMEconfig.h>
30 #include CORBA_CLIENT_HEADER(MEDEventListener)
31
32 #include <SalomeApp_Application.h>
33 #include <SALOME_LifeCycleCORBA.hxx>
34 #include <SUIT_FileDlg.h>
35 #include <SUIT_Desktop.h>
36 #include <SUIT_ResourceMgr.h>
37
38 #include <QTimer>
39
40 /*!
41  * This class defines a DockWidget plugged in the SALOME application,
42  * and containing a tree view for rendering a hierarchical data
43  * model. This datamodel contains the objects used in the workspace.
44  */
45 WorkspaceController::WorkspaceController(MEDModule* salomeModule)
46   : TreeGuiManager(salomeModule->getApp(), "Workspace")
47 {
48   _salomeModule = salomeModule;
49   getDockWidgets()->getDockWidget()->setObjectName("medWorkspaceDock");
50
51   this->tabifyDockWidgets(false);
52
53   // -------------------------------------------------------------
54   // Setup the MEDEventListener to manage notification from the
55   // python console.
56
57   // We create a MEDEventListener CORBA object inside this GUI class
58   // with the role of listening events coming from the python console
59   // (or even the components if needed). The events arising in the
60   // python console are send as CORBA request to this CORBA
61   // servant. Then this object can process the event by notifying the
62   // GUI of something to update for example (using signals and slots
63   // of course).
64   _medEventListener = MEDEventListener_i::getInstance();
65   MEDCALC::MEDEventListener_ptr medEventListenerServant = _medEventListener->_this();
66
67   // We store the IOR inside the MEDDataManager to share this data
68   // with other parts of the application, in particular the python
69   // console that could retrieve this IOR using the
70   // getEventListenerIOR() function of the MEDDataManager.
71   SalomeApp_Application* salomeApp = salomeModule->getApp();
72   const char* medEventListenerIOR =
73     salomeApp->orb()->object_to_string(medEventListenerServant);
74   MEDFactoryClient::getDataManager()->setEventListenerIOR(medEventListenerIOR);
75
76   // Connect the signals emitted from the MEDEventListener to slot of
77   // this class.
78   connect(_medEventListener, SIGNAL(medEventSignal(const MEDCALC::MedEvent*)),
79     this, SLOT(processMedEvent(const MEDCALC::MedEvent*)));
80   // >>> WARN:
81   // Note that this class must be mocked (Q_OBJECT + moc file
82   // generated from header file) so that to be able to connect a
83   // signal to a slot of this class.
84
85   // -------------------------------------------------------------
86   // Customize the treeview rendering the datamodel with specific
87   // action for the popup menu
88   this->getDataTreeView()->clearActions();
89   _actionIds.display    = this->getDataTreeView()->addAction(tr("VISUALIZE_SCALAR_MAP"));
90   _actionIds.useInTui   = this->getDataTreeView()->addAction(tr("USE_IN_CONSOLE"));
91   _actionIds.exportToPv = this->getDataTreeView()->addAction(tr("EXPORT_TO_PARAVIS"));
92   _actionIds.save       = this->getDataTreeView()->addAction(tr("SAVE_AS_MED"));
93   _actionIds.remove     = this->getDataTreeView()->addAction(tr("REMOVE_FROM_WORKSPACE"));
94
95   // -------------------------------------------------------------
96   // Initialize the python console. Note that this must be done at
97   // last because the setup will try to initiate a connection to the
98   // event listener.
99   _consoleDriver = new XmedConsoleDriver(salomeModule);
100   _consoleDriver->setup();
101 }
102
103 WorkspaceController::~WorkspaceController() {
104   STDLOG("WorkspaceController::~WorkspaceController()");
105   MEDEventListener_i::release();
106 }
107
108 /**
109  * This creates the GUI actions for driving the Workspace. The
110  * WorkspaceController creates itself this actions and implements the
111  * connected slots.
112  */
113 void WorkspaceController::createActions() {
114   QWidget* dsk = _salomeModule->getApp()->desktop();
115   SUIT_ResourceMgr* resMgr = _salomeModule->getApp()->resourceMgr();
116   int toolbarId = _salomeModule->createTool("Workspace", "WorkspaceToolbar");
117
118   QString label   = tr("LAB_SAVE_WORKSPACE");
119   QString tooltip = tr("TIP_SAVE_WORKSPACE");
120   QString icon    = tr("ICO_WORKSPACE_SAVE");
121   int actionId = _salomeModule->createStandardAction(label,this,SLOT(OnSaveWorkspace()),icon,tooltip);
122   _salomeModule->createTool(actionId, toolbarId);
123
124   label   = tr("LAB_CLEAN_WORKSPACE");
125   tooltip = tr("TIP_CLEAN_WORKSPACE");
126   icon    = tr("ICO_WORKSPACE_CLEAN");
127   actionId = _salomeModule->createStandardAction(label,this,SLOT(OnCleanWorkspace()),icon,tooltip);
128   _salomeModule->createTool(actionId, toolbarId);
129 }
130
131 /*!
132  * Implementation of the slot processItemList inherited from TreeGuiManager
133  */
134 void WorkspaceController::processItemList(QStringList itemNameIdList, int actionId) {
135   if ( actionId == _actionIds.display ) {
136     STDLOG("WorkspaceController::processItemList: display");
137     this->_viewItemList(itemNameIdList);
138   }
139   else if ( actionId == _actionIds.useInTui ) {
140     STDLOG("WorkspaceController::processItemList: use");
141     this->_importItemList(itemNameIdList);
142   }
143   else if ( actionId == _actionIds.exportToPv ) {
144     STDLOG("WorkspaceController::processItemList: export");
145     this->_exportItemList(itemNameIdList);
146   }
147   else if ( actionId == _actionIds.save ) {
148     STDLOG("WorkspaceController::processItemList: save");
149     this->_saveItemList(itemNameIdList);
150   }
151   else if ( actionId == _actionIds.remove ) {
152     STDLOG("WorkspaceController::processItemList: remove");
153     this->_removeItemList(itemNameIdList);
154   }
155   else {
156     STDLOG("WorkspaceController::processItemList: ERR : action unknown ");
157   }
158 }
159
160 /*!
161  * This function import in the console all the fields associated to
162  * the model items of the specified list. "Import a fields" means
163  * "define a field proxy variable in the python context to manipulate
164  * the real field in the database".
165  */
166 void WorkspaceController::_importItemList(QStringList itemNameIdList) {
167   LOG("WorkspaceController: signal received : display item list "<<itemNameIdList);
168   QStringList::const_iterator it;
169   for (it = itemNameIdList.constBegin(); it != itemNameIdList.constEnd(); ++it) {
170     QString itemNameId = *it;
171     this->_importItem(itemNameId);
172   }
173 }
174
175 /*!
176  * This function is the unit function used to import field in the
177  * console (see _importItemList).
178  */
179 void WorkspaceController::_importItem(QString itemNameId) {
180   XmedDataModel* dataModel = (XmedDataModel*)this->getDataModel();
181   if ( dataModel == NULL ) {
182     LOG("No data model associated to this tree view");
183     return;
184   }
185
186   // We can request the dataModel to obtain the dataObject associated
187   // to this item (iteNameId is a TreeView id, Qt stuff only).
188   XmedDataObject* dataObject =
189     (XmedDataObject*)dataModel->getDataObject(QS2S(itemNameId));
190
191   if ( dataObject == NULL ) {
192     LOG("WorkspaceController: WARN! No data object associated to the item "<<itemNameId);
193     return;
194   }
195
196   // Then, we can request this data object to obtain the associated
197   // FieldHandler.
198   MEDCALC::FieldHandler* fieldHandler = dataObject->getFieldHandler();
199   STDLOG("Field: mesh="<<fieldHandler->meshname<<" name="<<fieldHandler->fieldname);
200
201   // Finally, we can import the field
202   bool askForOptions = true;
203   _importFieldIntoConsole(fieldHandler, askForOptions);
204 }
205
206 /**
207  * This function import the specified field into the tui console. This
208  * means to define a field proxy variable in the python context to
209  * manipulate the field. We can raise a gui to specify some import
210  * options or simply specify the alias (i.e. the name of the python
211  * variable).
212  */
213 void WorkspaceController::_importFieldIntoConsole(MEDCALC::FieldHandler* fieldHandler,
214               bool askForOptions,
215               const char* alias)
216 {
217   STDLOG("alias="<<alias);
218
219   // By default, the alias is the name of the field
220   QString*effectiveAlias;
221   if ( alias == NULL ) {
222     effectiveAlias = new QString(fieldHandler->fieldname);
223   }
224   else {
225     effectiveAlias = new QString(alias);
226   }
227
228   // We can propose to the user to specify some additionnal
229   // informations concerning what must be imported.
230   //
231   // In this version, we just ask the alias the field will be
232   // manipulated with. The default alias is the field name. This alias
233   // should be asked to the user to get a short name to manipulate.
234   if ( askForOptions ) {
235     DlgAlias dialog;
236     dialog.setAlias(*effectiveAlias);
237     int choice = dialog.exec();
238     if ( choice == QDialog::Rejected ) {
239       // The user decides to cancel the operation
240       return;
241     }
242     *effectiveAlias = dialog.getAlias();
243   }
244
245   //
246   // Then, the list of python commands can be written and executed to
247   // define the field in the console
248   //
249   QStringList commands;
250   commands+=QString("%1=medcalc.newFieldProxy(fieldHandlerId=%2)")
251     .arg(*effectiveAlias)
252     .arg(fieldHandler->id);
253
254   _consoleDriver->exec(commands);
255 }
256
257 /*!
258  * This function is a Qt slot connected to the signal medEventSignal
259  * emitted from the MEDEventListener. It processes events coming from
260  * the python console.
261  */
262 void WorkspaceController::processMedEvent(const MEDCALC::MedEvent* event) {
263   STDLOG("WorkspaceController::processMedEvent");
264   STDLOG("dataId  :"<<event->dataId);
265
266   XmedDataModel* dataModel = (XmedDataModel*)this->getDataModel();
267   if ( dataModel == NULL ) {
268     STDLOG("No data model associated to this tree view");
269     return;
270   }
271
272   if ( event->type == MEDCALC::EVENT_UPDATE_FIELD ) {
273     std::cout << "WorkspaceController::processMedEvent[MEDCALC::EVENT_UPDATE_FIELD]: Not implemented yet";
274   }
275   else if ( event->type == MEDCALC::EVENT_PUT_IN_WORKSPACE ) {
276     STDLOG("add new field");
277     MEDCALC::FieldHandler* fieldHandler =
278       MEDFactoryClient::getDataManager()->getFieldHandler(event->dataId);
279
280     XmedDataObject* dataObject = (XmedDataObject*)dataModel->newDataObject();
281     dataObject->setFieldHandler(*fieldHandler);
282     this->getDataTreeModel()->addData(dataObject);
283   }
284   else if ( event->type == MEDCALC::EVENT_REMOVE_FROM_WORKSPACE ) {
285     STDLOG("remove field");
286     std::map<string, DataObject*>::iterator itr = dataModel->begin();
287     for ( ; itr != dataModel->end(); ++itr) {
288       XmedDataObject* obj = dynamic_cast<XmedDataObject*>(itr->second);
289       if (obj->getFieldHandler()->id == event->dataId) {
290         std::string itemNameId = obj->getNameId();
291         this->getDataTreeModel()->removeData(obj);
292         dataModel->removeDataObject(itemNameId);
293         return;
294       }
295     }
296   }
297   else if ( event->type == MEDCALC::EVENT_CLEAN_WORKSPACE ) {
298     STDLOG("clean workspace");
299     std::map<string, DataObject*>::iterator itr = dataModel->begin();
300     for ( ; itr != dataModel->end(); ++itr) {
301       XmedDataObject* obj = dynamic_cast<XmedDataObject*>(itr->second);
302       std::string itemNameId = obj->getNameId();
303       this->getDataTreeModel()->removeData(obj);
304       dataModel->removeDataObject(itemNameId);
305     }
306   }
307   else if ( event->type == MEDCALC::EVENT_ADD_DATASOURCE ) {
308     emit workspaceSignal(event); // forward to DatasourceController
309   }
310   else if ( event->type == MEDCALC::EVENT_ADD_PRESENTATION ) {
311     emit workspaceSignal(event); // forward to DatasourceController
312   }
313   else if ( event->type == MEDCALC::EVENT_PLAY_TEST ) {
314     emit workspaceSignal(event); // forward to TestController
315   }
316   else if ( event->type == MEDCALC::EVENT_QUIT_SALOME ) {
317     emit workspaceSignal(event); // forward to TestController
318   }
319 }
320
321 /*!
322  * This function save a list of fields in a med file. The med file
323  * name is requested to the user using a file chooser dialog box
324  */
325 void WorkspaceController::_saveItemList(QStringList itemNameIdList) {
326   XmedDataProcessor* dataProcessor = new XmedDataProcessor(this->getDataModel());
327   dataProcessor->process(itemNameIdList);
328   MEDCALC::FieldIdList_var fieldIdList = dataProcessor->getResultingFieldIdList();
329   delete dataProcessor;
330
331   QStringList filter;
332   filter.append(tr("FILE_FILTER_MED"));
333   QString filename = SUIT_FileDlg::getFileName(_salomeModule->getApp()->desktop(),
334                                                "",
335                                                filter,
336                                                tr("SAVE_SELECTED_FIELDS"),
337                                                false);
338
339   if ( filename.isEmpty() ) return;
340
341   MEDFactoryClient::getDataManager()->saveFields(QCHARSTAR(filename), fieldIdList);
342 }
343
344 /*!
345  * This function remove the selected item from workspace.
346  */
347 void WorkspaceController::_removeItemList(QStringList itemNameIdList) {
348   XmedDataModel* dataModel = (XmedDataModel*)this->getDataModel();
349   if ( dataModel == NULL ) {
350     LOG("No data model associated to this tree view");
351     return;
352   }
353
354   // __GBO__: In this version, we consider only the first field in the selection
355   QString itemNameId = itemNameIdList[0];
356
357   // We can request the dataModel to obtain the dataObject associated
358   // to this item (iteNameId is a TreeView id, Qt stuff only).
359   XmedDataObject* dataObject =
360     (XmedDataObject*)dataModel->getDataObject(QS2S(itemNameId));
361
362   if ( dataObject == NULL ) {
363     LOG("WorkspaceController: WARN! No data object associated to the item "<<itemNameId);
364     return;
365   }
366
367   // Then, we can request this data object to obtain the associated
368   // FieldHandler.
369   MEDCALC::FieldHandler* fieldHandler = dataObject->getFieldHandler();
370   STDLOG("Field: mesh="<<fieldHandler->meshname<<" name="<<fieldHandler->fieldname);
371
372   // Remove the field variable from console
373   QStringList commands;
374   commands+=QString("removeFromWorkspace(accessField(%1))").arg(fieldHandler->id);
375   _consoleDriver->exec(commands);
376
377   // Finally, we can remove the field from tree data model and tree view
378   this->getDataTreeModel()->removeData(dataObject);
379   dataModel->removeDataObject(QS2S(itemNameId));
380 }
381
382 /**
383  * This function export the list of specified field item to PARAVIS
384  * module. This consists in create a med file gathering the selected
385  * items, then to import this file in PARAVIS, and finally to create a
386  * scalar map of the first item to start the job.
387  */
388 void WorkspaceController::_exportItemList(QStringList itemNameIdList) {
389   XmedDataProcessor* dataProcessor = new XmedDataProcessor(this->getDataModel());
390   dataProcessor->process(itemNameIdList);
391   MEDCALC::FieldIdList_var fieldIdList = dataProcessor->getResultingFieldIdList();
392   delete dataProcessor;
393
394   // _GBO_ We use a temporary file to proceed with this export to
395   // paravis. I'm sure it could be better in a futur version or when I
396   // will get a better understanding of paravis API.
397   const char* tmpfilename = "/tmp/medcalc_export2paravis.med";
398   MEDFactoryClient::getDataManager()->saveFields(tmpfilename, fieldIdList);
399
400   // We import the whole file but create a scalar map for the first
401   // selected field only (it's just an export to continue the job in
402   // paravis)
403   XmedDataModel* dataModel = (XmedDataModel*)this->getDataModel();
404   if ( dataModel == NULL ) {
405     STDLOG("No data model associated to this tree view");
406     return;
407   }
408   QString itemNameId = itemNameIdList[0];
409   XmedDataObject* dataObject = (XmedDataObject*)dataModel->getDataObject(QS2S(itemNameId));
410   if ( dataObject == NULL ) {
411     LOG("WorkspaceController: WARN! No data object associated to the item "<<itemNameId);
412     return;
413   }
414   MEDCALC::FieldHandler* fieldHandler = dataObject->getFieldHandler();
415   QStringList commands;
416   /*
417   commands+=QString("from xmed.driver_pvis import pvis_scalarmap");
418   commands+=QString("pvis_scalarmap('%1','%2','%3',%4,%5)")
419     .arg(tmpfilename)
420     .arg(QString(fieldHandler->meshname))
421     .arg(QString(fieldHandler->fieldname))
422     .arg(fieldHandler->type)
423     .arg(fieldHandler->iteration);
424   */
425   commands += "print 'Not implemented yet'";
426   _consoleDriver->exec(commands);
427
428 }
429
430 /*!
431  * This function sends a request to the SALOME data visualisation
432  * (module VISU or PARAVIS) for displaying a scalar map of the fields
433  * associated to the model items in the specified list.
434  *
435  */
436 void WorkspaceController::_viewItemList(QStringList itemNameIdList) {
437
438   // __GBO__: In this version, we consider only the first field in the selection
439   QString itemNameId = itemNameIdList[0];
440
441   XmedDataModel* dataModel = (XmedDataModel*)this->getDataModel();
442   if ( dataModel == NULL ) {
443     LOG("No data model associated to this tree view");
444     return;
445   }
446
447   // We can request the dataModel to obtain the dataObject associated
448   // to this item (iteNameId is a TreeView id, Qt stuff only).
449   XmedDataObject* dataObject =
450     (XmedDataObject*)dataModel->getDataObject(QS2S(itemNameId));
451   if ( dataObject == NULL ) {
452     LOG("WorkspaceController: WARN! No data object associated to the item "<<itemNameId);
453     return;
454   }
455
456   // Then, we can request this data object to obtain the associated
457   // FieldHandler.
458   MEDCALC::FieldHandler* fieldHandler = dataObject->getFieldHandler();
459
460   // And finally, we can create the set of medcalc instructions to
461   // generate the scalar map on this field.
462   QStringList commands;
463   //commands+=QString("view(accessField(%1))").arg(fieldHandler->id);
464   commands += "print 'Not implemented yet'";
465   _consoleDriver->exec(commands);
466 }
467
468 /**
469  * This slot can process the event coming from the
470  * DatasourceController. The connection between the datasource signal
471  * and this slot is realized by the main class MEDModule.
472  */
473 void WorkspaceController::processDatasourceEvent(const DatasourceEvent* event) {
474   XmedDataModel* dataModel = (XmedDataModel*)this->getDataModel();
475   if ( dataModel == NULL ) {
476     STDLOG("No data model associated to this tree view");
477     return;
478   }
479
480   // >>>
481   // __GBO__ To know what to do we should test the type, because the
482   // object could be a mesh, a timeseries or a single field. We test
483   // here the case of a single field. Moreover, there could have
484   // options such that "change the underlying mesh".
485   // <<<
486
487   XmedDataObject* dataObject = event->objectdata;
488
489   if ( event->eventtype == DatasourceEvent::EVENT_IMPORT_OBJECT ) {
490     std::cout << "IMPORT object in workspace: " << dataObject->toString() << std::endl;
491     STDLOG("IMPORT object in workspace:\n"<<dataObject->toString());
492     // _GBO_ QUESTION: tag automatically the object as a peristant object ??
493     // We first add the data object to the internal data model
494     dataModel->addDataObject(dataObject);
495     // Then we request the tree view to consider this new object
496     this->getDataTreeModel()->addData(dataObject);
497   }
498   else if ( event->eventtype == DatasourceEvent::EVENT_USE_OBJECT ) {
499     STDLOG("USE object in workspace:\n"<<dataObject->toString());
500     // We first add the data object to the internal data model
501     dataModel->addDataObject(dataObject);
502     // Then we request the tree view to consider this new object
503     this->getDataTreeModel()->addData(dataObject);
504
505     // We define a proxy for this object in the tui console.
506     STDLOG("Define a proxy variable in the console with name : "<<QCHARSTAR(event->objectalias));
507     bool askForOptions = false;
508     _importFieldIntoConsole(dataObject->getFieldHandler(),
509           askForOptions,
510           QCHARSTAR(event->objectalias));
511   }
512   else if ( event->eventtype == DatasourceEvent::EVENT_ADD_DATASOURCE ) {
513     QStringList commands;
514     commands += QString("medcalc.LoadDataSource('%1')").arg(event->objectalias);
515     _consoleDriver->exec(commands);
516   }
517   else if ( event->eventtype == DatasourceEvent::EVENT_ADD_IMAGE_AS_DATASOURCE ) {
518     QStringList commands;
519     commands += QString("medcalc.LoadImageAsDataSource('%1')").arg(event->objectalias);
520     _consoleDriver->exec(commands);
521   }
522   else {
523     STDLOG("The event "<<event->eventtype<<" is not implemented yet");
524   }
525 }
526
527 QString
528 WorkspaceController::_getViewMode()
529 {
530   MEDCALC::MEDPresentationViewMode viewMode = _salomeModule->getSelectedViewMode();
531   switch(viewMode) {
532   case MEDCALC::VIEW_MODE_REPLACE: return "MEDCALC.VIEW_MODE_REPLACE";
533   case MEDCALC::VIEW_MODE_OVERLAP: return "MEDCALC.VIEW_MODE_OVERLAP";
534   case MEDCALC::VIEW_MODE_NEW_LAYOUT: return "MEDCALC.VIEW_MODE_NEW_LAYOUT";
535   case MEDCALC::VIEW_MODE_SPLIT_VIEW: return "MEDCALC.VIEW_MODE_SPLIT_VIEW";
536   }
537   return QString();
538 }
539
540 QString
541 WorkspaceController::_getColorMap()
542 {
543   MEDCALC::MEDPresentationColorMap colorMap = _salomeModule->getSelectedColorMap();
544   switch(colorMap) {
545   case MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW: return "MEDCALC.COLOR_MAP_BLUE_TO_RED_RAINBOW";
546   case MEDCALC::COLOR_MAP_COOL_TO_WARM: return "MEDCALC.COLOR_MAP_COOL_TO_WARM";
547   }
548   return QString();
549 }
550
551 /**
552  * This slot can process the event coming from the
553  * DatasourceController. The connection between the datasource signal
554  * and this slot is realized by the main class MEDModule.
555  */
556 void WorkspaceController::processPresentationEvent(const PresentationEvent* event) {
557   XmedDataModel* dataModel = (XmedDataModel*)this->getDataModel();
558   if ( dataModel == NULL ) {
559     STDLOG("No data model associated to this tree view");
560     return;
561   }
562
563   // >>>
564   // __GBO__ To know what to do we should test the type, because the
565   // object could be a mesh, a timeseries or a single field. We test
566   // here the case of a single field. Moreover, there could have
567   // options such that "change the underlying mesh".
568   // <<<
569
570   XmedDataObject* dataObject = event->objectdata;
571
572   // --> Send commands to SALOME Python console
573   if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_SCALAR_MAP ) {
574     QString viewMode = _getViewMode();
575     //QString displayedInfo = ; // from PresentationController combobox
576     //QString scalarBarRange = ; // from PresentationController spinbox
577     QString colorMap = _getColorMap();
578     MEDCALC::FieldHandler* fieldHandler = dataObject->getFieldHandler();
579     QStringList commands;
580     commands += QString("medcalc.MakeScalarMap(accessField(%1), %2, colorMap=%3)").arg(fieldHandler->id).arg(viewMode).arg(colorMap);
581     _consoleDriver->exec(commands);
582   }
583   else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_CONTOUR ) {
584     QString viewMode = _getViewMode();
585     MEDCALC::FieldHandler* fieldHandler = dataObject->getFieldHandler();
586     QStringList commands;
587     commands += QString("medcalc.MakeContour(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode);
588     _consoleDriver->exec(commands);
589   }
590   else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_VECTOR_FIELD ) {
591     QString viewMode = _getViewMode();
592     MEDCALC::FieldHandler* fieldHandler = dataObject->getFieldHandler();
593     QStringList commands;
594     commands += QString("medcalc.MakeVectorField(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode);
595     _consoleDriver->exec(commands);
596   }
597   else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_SLICES ) {
598     QString viewMode = _getViewMode();
599     MEDCALC::FieldHandler* fieldHandler = dataObject->getFieldHandler();
600     QStringList commands;
601     commands += QString("medcalc.MakeSlices(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode);
602     _consoleDriver->exec(commands);
603   }
604   else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_DEFLECTION_SHAPE ) {
605     QString viewMode = _getViewMode();
606     MEDCALC::FieldHandler* fieldHandler = dataObject->getFieldHandler();
607     QStringList commands;
608     commands += QString("medcalc.MakeDeflectionShape(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode);
609     _consoleDriver->exec(commands);
610   }
611   else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_POINT_SPRITE ) {
612     QString viewMode = _getViewMode();
613     MEDCALC::FieldHandler* fieldHandler = dataObject->getFieldHandler();
614     QStringList commands;
615     commands += QString("medcalc.MakePointSprite(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode);
616     _consoleDriver->exec(commands);
617   }
618   else {
619     STDLOG("The event "<<event->eventtype<<" is not implemented yet");
620   }
621 }
622
623 void
624 WorkspaceController::processProcessingEvent(const ProcessingEvent* event)
625 {
626   XmedDataModel* dataModel = (XmedDataModel*)this->getDataModel();
627   if ( dataModel == NULL ) {
628     STDLOG("No data model associated to this tree view");
629     return;
630   }
631
632   // >>>
633   // __GBO__ To know what to do we should test the type, because the
634   // object could be a mesh, a timeseries or a single field. We test
635   // here the case of a single field. Moreover, there could have
636   // options such that "change the underlying mesh".
637   // <<<
638
639   XmedDataObject* dataObject = event->objectdata;
640
641   if ( event->eventtype == ProcessingEvent::EVENT_IMPORT_OBJECT ) {
642     std::cout << "IMPORT object in workspace: " << dataObject->toString() << std::endl;
643     STDLOG("IMPORT object in workspace:\n"<<dataObject->toString());
644     // _GBO_ QUESTION: tag automatically the object as a peristant object ??
645     // We first add the data object to the internal data model
646     dataModel->addDataObject(dataObject);
647     // Then we request the tree view to consider this new object
648     this->getDataTreeModel()->addData(dataObject);
649   }
650 }
651
652 void WorkspaceController::OnSaveWorkspace() {
653
654   // Dialog to get the filename where the workspace must be saved into
655   QStringList filter;
656   filter.append(tr("FILE_FILTER_MED"));
657
658   QString filename = SUIT_FileDlg::getFileName(_salomeModule->getApp()->desktop(),
659                                                "",
660                                                filter,
661                                                tr("SAVE_WORKSPACE_DATA"),
662                                                false);
663
664   if ( filename.isEmpty() ) return;
665
666   STDLOG("OnWorkspaceSave: save the workspace in the file " << QCHARSTAR(filename));
667   QStringList commands;
668   commands+=QString("saveWorkspace('%1')").arg(filename);
669   _consoleDriver->exec(commands);
670 }
671
672 #include <QMessageBox>
673 void WorkspaceController::OnCleanWorkspace() {
674   // Remove field from console
675   QStringList commands;
676   commands += QString("cleanWorkspace()");
677   _consoleDriver->exec(commands);
678 }