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