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