Salome HOME
Add presentation in datasource tree
[modules/med.git] / src / MEDCalc / gui / DatasourceController.cxx
1 // Copyright (C) 2007-2015  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 "DatasourceController.hxx"
23 #include "DatasourceConstants.hxx"
24
25 #include "MEDFactoryClient.hxx"
26 #include "QtHelper.hxx"
27
28 #include CORBA_CLIENT_HEADER(SALOMEDS)
29 #include <SUIT_FileDlg.h>
30 #include <SUIT_Desktop.h>
31
32 #include <QStringList>
33 #include <QString>
34 #include <QMessageBox>
35
36 #include "DlgAlias.hxx"
37
38 //
39 // ==============================================================
40 // Datasource controller
41 // ==============================================================
42 //
43 DatasourceController::DatasourceController(StandardApp_Module * salomeModule)
44   : _fieldSeriesEntries()
45 {
46   STDLOG("Creating a DatasourceController");
47   _salomeModule = salomeModule;
48   _studyEditor = new SALOME_AppStudyEditor(_salomeModule->getApp());
49
50   _dlgChangeUnderlyingMesh = new DlgChangeUnderlyingMesh(_studyEditor);
51   connect(_dlgChangeUnderlyingMesh,SIGNAL(inputValidated()),
52           this, SLOT(OnChangeUnderlyingMeshInputValidated()));
53
54   _dlgInterpolateField = new DlgInterpolateField(_studyEditor);
55   connect(_dlgInterpolateField,SIGNAL(inputValidated()),
56           this, SLOT(OnInterpolateFieldInputValidated()));
57
58 }
59
60 DatasourceController::~DatasourceController() {
61   STDLOG("Deleting the DatasourceController");
62   delete _studyEditor;
63 }
64
65 void DatasourceController::createActions() {
66   //
67   // Main actions (toolbar and menubar)
68   //
69   QString label   = tr("LAB_ADD_DATA_SOURCE");
70   QString tooltip = tr("TIP_ADD_DATA_SOURCE");
71   QString icon    = tr("ICO_DATASOURCE_ADD");
72   int actionId;
73   actionId = _salomeModule->createStandardAction(label,this, SLOT(OnAddDatasource()),icon,tooltip);
74   _salomeModule->addActionInToolbar(actionId);
75
76   // This action has to be placed in the general file menu with the label "Import MED file"
77   int menuId = _salomeModule->createMenu( tr( "MEN_FILE" ), -1,  1 );
78   _salomeModule->addActionInMenubar(actionId, menuId);
79
80   label   = tr("LAB_ADD_IMAGE_SOURCE");
81   tooltip = tr("TIP_ADD_IMAGE_SOURCE");
82   icon    = tr("ICO_IMAGE_ADD");
83   actionId = _salomeModule->createStandardAction(label,this, SLOT(OnAddImagesource()),icon,tooltip);
84   _salomeModule->addActionInToolbar(actionId);
85
86   //
87   // Actions for popup menu only
88   //
89   // Expand field timeseries
90   label = tr("LAB_EXPAND_FIELD");
91   icon  = tr("ICO_DATASOURCE_EXPAND_FIELD");
92   actionId = _salomeModule->createStandardAction(label,this,SLOT(OnExpandField()),icon);
93   _salomeModule->addActionInPopupMenu(actionId);
94
95   // Create a view submenu with usual visualization functions
96   label = tr("LAB_VISUALIZE_SCALARMAP");
97   icon  = tr("ICO_DATASOURCE_VIEW");
98   actionId = _salomeModule->createStandardAction(label,this,SLOT(OnVisualizeScalarMap()),icon);
99   _salomeModule->addActionInPopupMenu(actionId, tr("LAB_VISUALIZE"));
100
101   // Use in workspace
102   label = tr("LAB_USE_IN_WORKSPACE");
103   icon  = tr("ICO_DATASOURCE_USE");
104   actionId = _salomeModule->createStandardAction(label,this,SLOT(OnUseInWorkspace()),icon);
105   _salomeModule->addActionInPopupMenu(actionId);
106
107   // Change underlying mesh (note that this action creates a new field in
108   // the workspace that corresponds to a copy of the selected field
109   // modified by the change of the underlying mesh.
110   label = tr("LAB_CHANGE_MESH");
111   icon  = tr("ICO_DATASOURCE_CHANGE_MESH");
112   actionId = _salomeModule->createStandardAction(label,this,SLOT(OnChangeUnderlyingMesh()),icon);
113   _salomeModule->addActionInPopupMenu(actionId);
114
115   label = tr("LAB_INTERPOLATE_FIELD");
116   icon  = tr("ICO_DATASOURCE_INTERPOLATE_FIELD");
117   actionId = _salomeModule->createStandardAction(label,this,SLOT(OnInterpolateField()),icon);
118   _salomeModule->addActionInPopupMenu(actionId);
119 }
120
121 /**
122  * This function adds the specified MED file as a datasource in the
123  * dataspace. Technically speaking, the engine loads the
124  * meta-information concerning med data from the file, gives this
125  * informations to the GUI, and the GUI creates a tree view of these
126  * data in the study object browser.
127  */
128 // This function emits a signal that will be caught by workspace to delegate command (datasource creation) to python console.
129 void
130 DatasourceController::addDatasource(const char* filename)
131 {
132   DatasourceEvent* event = new DatasourceEvent();
133   event->eventtype = DatasourceEvent::EVENT_ADD_DATASOURCE;
134   event->objectalias = filename;
135   emit datasourceSignal(event);
136 }
137 // After above data source creation, python console emits a signal, forwarded by workspace, to update the GUI
138 void
139 DatasourceController::updateTreeViewWithNewDatasource(const MEDCALC::DatasourceHandler* datasourceHandler)
140 {
141   if (!datasourceHandler) {
142     return;
143   }
144
145   // We need a studyEditor updated on the active study
146   _studyEditor->updateActiveStudy();
147
148   // Create a datasource SObject as a father of the module root
149   SALOMEDS::SComponent_var root = _studyEditor->findRoot(QCHARSTAR(_salomeModule->moduleName()));
150   SALOMEDS::SObject_var soDatasource = _studyEditor->newObject(root);
151   _studyEditor->setName(soDatasource,datasourceHandler->name);
152   _studyEditor->setIcon(soDatasource,tr("ICO_DATASOURCE").toStdString().c_str());
153   _studyEditor->setParameterInt(soDatasource,OBJECT_ID,datasourceHandler->id);
154
155   // We can add the meshes as children of the datasource
156   MEDCALC::MeshHandlerList * meshHandlerList =
157     MEDFactoryClient::getDataManager()->getMeshList(datasourceHandler->id);
158
159   for(CORBA::ULong iMesh=0; iMesh<meshHandlerList->length(); iMesh++) {
160     MEDCALC::MeshHandler meshHandler = (*meshHandlerList)[iMesh];
161     SALOMEDS::SObject_var soMesh = _studyEditor->newObject(soDatasource);
162     _studyEditor->setName(soMesh,meshHandler.name);
163     _studyEditor->setIcon(soMesh,tr("ICO_DATASOURCE_MESH").toStdString().c_str());
164     _studyEditor->setParameterInt(soMesh,OBJECT_ID,meshHandler.id);
165     _studyEditor->setParameterBool(soMesh,OBJECT_IS_IN_WORKSPACE,false);
166
167     // We add the field timeseries defined on this mesh, as children
168     // of the mesh SObject
169     MEDCALC::FieldseriesHandlerList * fieldseriesHandlerList =
170       MEDFactoryClient::getDataManager()->getFieldseriesListOnMesh(meshHandler.id);
171
172     for(CORBA::ULong iFieldseries=0; iFieldseries<fieldseriesHandlerList->length(); iFieldseries++) {
173       MEDCALC::FieldseriesHandler fieldseriesHandler = (*fieldseriesHandlerList)[iFieldseries];
174       SALOMEDS::SObject_var soFieldseries = _studyEditor->newObject(soMesh);
175       _fieldSeriesEntries[fieldseriesHandler.id] = soFieldseries->GetID();
176
177       std::string label(fieldseriesHandler.name);
178       label +=" ("+std::string(XmedDataObject::mapTypeOfFieldLabel[fieldseriesHandler.type])+")";
179       _studyEditor->setName(soFieldseries,label.c_str());
180
181       _studyEditor->setIcon(soFieldseries,tr("ICO_DATASOURCE_FIELD").toStdString().c_str());
182       _studyEditor->setParameterInt(soFieldseries,OBJECT_ID,fieldseriesHandler.id);
183       _studyEditor->setParameterBool(soFieldseries,OBJECT_IS_IN_WORKSPACE,false);
184     }
185   }
186 }
187
188 void
189 DatasourceController::updateTreeViewWithNewPresentation(long fieldId, long presentationId)
190 {
191   if (presentationId < 0) {
192     std::cerr << "Unknown presentation\n";
193     return;
194   }
195
196   if (_fieldSeriesEntries.find(fieldId) == _fieldSeriesEntries.end()) {
197     std::cerr << "Field not found\n";
198     return;
199   }
200   std::string entry = _fieldSeriesEntries[fieldId];
201   SALOMEDS::SObject_ptr soFieldseries = _studyEditor->findObject(entry.c_str());
202   if (soFieldseries->IsNull()) {
203     std::cerr << "Entry not found\n";
204     return;
205   }
206
207   std::string name = MEDFactoryClient::getPresentationManager()->getPresentationProperty(presentationId, "name");
208   SALOMEDS::SObject_var soPresentation = _studyEditor->newObject(soFieldseries);
209   _studyEditor->setName(soPresentation, tr(name.c_str()).toStdString().c_str());
210   _studyEditor->setIcon(soPresentation, tr("ICO_MED_PRESENTATION").toStdString().c_str());
211 }
212
213 void DatasourceController::OnAddDatasource()
214 {
215   // Dialog to get the filename where the input data are read from
216   QStringList filter;
217   filter.append(tr("FILE_FILTER_MED"));
218
219   QString anInitialPath = "";
220   if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
221     anInitialPath = QDir::currentPath();
222
223   QStringList filenames = SUIT_FileDlg::getOpenFileNames( _salomeModule->getApp()->desktop(),
224                                                           anInitialPath,
225                                                           filter,
226                                                           tr("IMPORT_MED_FIELDS") );
227
228   if ( filenames.count() <= 0 ) return;
229   for ( QStringList::ConstIterator itFile = filenames.begin();
230         itFile != filenames.end(); ++itFile ) {
231     QString filename = *itFile;
232     this->addDatasource(QCHARSTAR(filename));
233     _salomeModule->updateObjBrowser(true);
234   }
235 }
236
237 #include "DlgImageToMed.hxx"
238 //#include <stdio.h>
239 //#include <stdlib.h>
240 void DatasourceController::OnAddImagesource()
241 {
242
243   DlgImageToMed dialog;
244   dialog.setAutoLoaded(true);
245   int choice = dialog.exec();
246   if ( choice == QDialog::Rejected ) {
247     // The user decides to cancel the operation
248     return;
249   }
250
251   QString imageFilename = dialog.getImageFilepath();
252   /*
253   QString medFilename   = dialog.getMedFilepath();
254   bool autoLoad         = dialog.isAutoLoaded();
255
256   std::string ROOT_DIR(getenv("MED_ROOT_DIR"));
257   std::string command(ROOT_DIR+"/bin/salome/med/image2med.py");
258   command += " -i "+QS2S(imageFilename);
259   command += " -m "+QS2S(medFilename);
260   int error = system(command.c_str());
261   if ( error != 0 ) {
262     QMessageBox::critical(_salomeModule->getApp()->desktop(),
263            tr("Operation failed"),
264            tr("The creation of med data from the image file failed"));
265     return;
266   }
267
268   if ( autoLoad ) {
269     this->addDatasource(QCHARSTAR(medFilename));
270     _salomeModule->updateObjBrowser(true);
271   }
272   */
273
274   DatasourceEvent* event = new DatasourceEvent();
275   event->eventtype = DatasourceEvent::EVENT_ADD_IMAGE_AS_DATASOURCE;
276   event->objectalias = imageFilename;
277   emit datasourceSignal(event);
278 }
279
280 void DatasourceController::OnExpandField()
281 {
282   // We need a studyEditor updated on the active study
283   _studyEditor->updateActiveStudy();
284
285   // Get the selected objects in the study (SObject)
286   SALOME_StudyEditor::SObjectList * listOfSObject = _studyEditor->getSelectedObjects();
287   for (int i=0; i<listOfSObject->size(); i++) {
288     SALOMEDS::SObject_var soFieldseries = listOfSObject->at(i);
289
290     // First retrieve the fieldseries id associated to this study object
291     long fieldseriesId = _studyEditor->getParameterInt(soFieldseries,OBJECT_ID);
292     STDLOG("Expand the field timeseries "<<fieldseriesId);
293
294     // If fieldseriesId equals -1, then it means that it is not a
295     // fieldseries managed by the MED module, and we stop this
296     // function process.
297     if ( fieldseriesId < 0 )
298       continue;
299     // _GBO_ A better correction should be to no display the
300     // contextual menu if the selected object is not conform
301
302     // Then retrieve the list of fields in this timeseries
303     MEDCALC::FieldHandlerList * fieldHandlerList =
304       MEDFactoryClient::getDataManager()->getFieldListInFieldseries(fieldseriesId);
305
306     // Finally, create an entry for each of the field
307     for(CORBA::ULong iField=0; iField<fieldHandlerList->length(); iField++) {
308       MEDCALC::FieldHandler fieldHandler = (*fieldHandlerList)[iField];
309       SALOMEDS::SObject_var soField = _studyEditor->newObject(soFieldseries);
310       std::string label("it="); label += ToString(fieldHandler.iteration);
311       _studyEditor->setName(soField,label.c_str());
312       _studyEditor->setParameterInt(soField, OBJECT_ID, fieldHandler.id);
313       _studyEditor->setParameterBool(soField,OBJECT_IS_IN_WORKSPACE,false);
314     }
315   }
316   _salomeModule->updateObjBrowser(true);
317 }
318
319 void DatasourceController::visualize(DatasourceEvent::EventType eventType) {
320   // We need a _studyEditor updated on the active study
321   _studyEditor->updateActiveStudy();
322
323   // Get the selected objects in the study (SObject)
324   SALOME_StudyEditor::SObjectList * listOfSObject = _studyEditor->getSelectedObjects();
325
326   // For each object, emit a signal to the workspace to request a
327   // visualisation using the tui command (so that the user can see how
328   // to make a view of an object from the tui console).
329   for (int i=0; i<listOfSObject->size(); i++) {
330     SALOMEDS::SObject_var soField = listOfSObject->at(i);
331     int fieldId = _studyEditor->getParameterInt(soField,OBJECT_ID);
332     // If fieldId equals -1, then it means that it is not a field
333     // managed by the MED module, and we stop this function process.
334     if ( fieldId < 0 )
335       continue;
336
337     MEDCALC::FieldHandler * fieldHandler = MEDFactoryClient::getDataManager()->getFieldHandler(fieldId);
338     if (! fieldHandler) {
339       QMessageBox::warning(_salomeModule->getApp()->desktop(),
340          tr("Operation not allowed"),
341          tr("No field is defined"));
342       return;
343     }
344
345     DatasourceEvent * event = new DatasourceEvent();
346     event->eventtype = eventType;
347     XmedDataObject * dataObject = new XmedDataObject();
348     dataObject->setFieldHandler(*fieldHandler);
349     event->objectdata  = dataObject;
350     emit datasourceSignal(event);
351   }
352 }
353
354 void DatasourceController::OnVisualizeScalarMap() {
355   this->visualize(DatasourceEvent::EVENT_VIEW_OBJECT_SCALAR_MAP);
356 }
357
358 void DatasourceController::OnUseInWorkspace() {
359   // We need a studyEditor updated on the active study
360   _studyEditor->updateActiveStudy();
361
362   // Get the selected objects in the study (SObject)
363   SALOME_StudyEditor::SObjectList * listOfSObject = _studyEditor->getSelectedObjects();
364   if ( listOfSObject->size() == 1 ) {
365     // In this case we ask the name of the variable for the python
366     // console
367
368     // >>>
369     // _GBO_ Note that it works only for a single field but the
370     // XmedDataObject will be improved to deal with mesh, timeseries
371     // and single field in a futur version. We suppose here that a
372     // single field has been selected.
373     // <<<
374
375     SALOMEDS::SObject_var soField = listOfSObject->at(0);
376
377     bool isInWorkspace = _studyEditor->getParameterBool(soField,OBJECT_IS_IN_WORKSPACE);
378     if ( isInWorkspace ) {
379       QMessageBox::warning(_salomeModule->getApp()->desktop(),
380          tr("Operation not allowed"),
381          tr("This field is already defined in the workspace"));
382       return;
383     }
384
385     int fieldId = _studyEditor->getParameterInt(soField,OBJECT_ID);
386
387     // If fieldId equals -1, then it means that it is not a field
388     // managed by the MED module, and we stop this function process.
389     if ( fieldId < 0 ) {
390       QMessageBox::warning(_salomeModule->getApp()->desktop(),
391          tr("Operation not allowed"),
392          tr("This element is not a field object"));
393       return;
394     }
395
396     MEDCALC::FieldHandler * fieldHandler =
397       MEDFactoryClient::getDataManager()->getFieldHandler(fieldId);
398
399     if (! fieldHandler) {
400       QMessageBox::warning(_salomeModule->getApp()->desktop(),
401          tr("Operation not allowed"),
402          tr("No field is defined"));
403       return;
404     }
405
406     QString alias(fieldHandler->fieldname);
407     DlgAlias dialog;
408     dialog.setAlias(alias);
409     int choice = dialog.exec();
410     if ( choice == QDialog::Rejected ) {
411       // The user decides to cancel the operation
412       return;
413     }
414     alias = dialog.getAlias();
415
416     DatasourceEvent * event = new DatasourceEvent();
417     event->eventtype = DatasourceEvent::EVENT_USE_OBJECT;
418     XmedDataObject * dataObject = new XmedDataObject();
419     dataObject->setFieldHandler(*fieldHandler);
420     event->objectdata  = dataObject;
421     event->objectalias = alias;
422     emit datasourceSignal(event);
423     // Tag the item to prevent double import
424     //    _studyEditor->setParameterBool(soField,OBJECT_IS_IN_WORKSPACE,true);
425     // Tag the field as persistent on the server. It means that a
426     // saving of the workspace will save at least this field (maybe it
427     // should be an option?)
428     MEDFactoryClient::getDataManager()->markAsPersistent(fieldId, true);
429   }
430   else {
431     // In this case, we don't ask the user to specify an alias for
432     // each item, we just import the whole set of items.
433     for (int i=0; i<listOfSObject->size(); i++) {
434       SALOMEDS::SObject_var soField = listOfSObject->at(i);
435
436       bool isInWorkspace = _studyEditor->getParameterBool(soField,OBJECT_IS_IN_WORKSPACE);
437       if ( !isInWorkspace ) {
438         int fieldId = _studyEditor->getParameterInt(soField,OBJECT_ID);
439         MEDCALC::FieldHandler * fieldHandler =
440           MEDFactoryClient::getDataManager()->getFieldHandler(fieldId);
441         DatasourceEvent * event = new DatasourceEvent();
442         event->eventtype = DatasourceEvent::EVENT_IMPORT_OBJECT;
443         XmedDataObject * dataObject = new XmedDataObject();
444         dataObject->setFieldHandler(*fieldHandler);
445         event->objectdata  = dataObject;
446         emit datasourceSignal(event);
447         // Note that this signal is processed by the WorkspaceController
448
449         // Tag the item to prevent double import
450         //        _studyEditor->setParameterBool(soField,OBJECT_IS_IN_WORKSPACE,true);
451         // Tag the field as persistent on the server. It means that a
452         // saving of the workspace will save at least this field (maybe it
453         // should be an option?)
454         MEDFactoryClient::getDataManager()->markAsPersistent(fieldId, true);
455       }
456       else {
457         STDLOG("The field "<<_studyEditor->getName(soField)<<
458                " is already defined in the workspace");
459       }
460     }
461   }
462 }
463
464 void DatasourceController::OnChangeUnderlyingMesh() {
465   // We need a studyEditor updated on the active study
466   _studyEditor->updateActiveStudy();
467
468   // Get the selected objects in the study (SObject). In cas of a
469   // multiple selection, we consider only the first item. At least one
470   // item must be selected.
471   SALOME_StudyEditor::SObjectList * listOfSObject = _studyEditor->getSelectedObjects();
472   if ( listOfSObject->size() > 0 ) {
473     SALOMEDS::SObject_var soField = listOfSObject->at(0);
474     int fieldId = _studyEditor->getParameterInt(soField,OBJECT_ID);
475     // _GBO_ : the dialog should not be modal, so that we can choose a
476     // mesh in the browser. Then we have to emit a signal from the
477     // dialog.accept, connected to a slot of the DatasourceControler
478     _dlgChangeUnderlyingMesh->setFieldId(fieldId);
479     Qt::WindowFlags flags = _dlgChangeUnderlyingMesh->windowFlags();
480     _dlgChangeUnderlyingMesh->setWindowFlags(flags | Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint);
481     _dlgChangeUnderlyingMesh->open();
482   }
483 }
484
485 void DatasourceController::OnChangeUnderlyingMeshInputValidated() {
486   int meshId = _dlgChangeUnderlyingMesh->getMeshId();
487   STDLOG("meshId = " << ToString(meshId));
488   int fieldId = _dlgChangeUnderlyingMesh->getFieldId();
489   MEDCALC::FieldHandler * fieldHandler =
490     MEDFactoryClient::getDataManager()->getFieldHandler(fieldId);
491
492   // We don't modify the original field but create first a duplicate
493   MEDCALC::FieldHandler * duplicate = MEDFactoryClient::getCalculator()->dup(*fieldHandler);
494   MEDFactoryClient::getDataManager()->changeUnderlyingMesh(duplicate->id, meshId);
495
496   // Request once more the duplicate to update the meta-data on this
497   // client side
498   duplicate = MEDFactoryClient::getDataManager()->getFieldHandler(duplicate->id);
499
500   // >>>
501   // WARN: the following is a temporary code for test purpose
502   // Automatically add in ws
503   DatasourceEvent * event = new DatasourceEvent();
504   event->eventtype = DatasourceEvent::EVENT_IMPORT_OBJECT;
505   XmedDataObject * dataObject = new XmedDataObject();
506   dataObject->setFieldHandler(*duplicate);
507   event->objectdata = dataObject;
508   emit datasourceSignal(event);
509   // Note that this signal is processed by the WorkspaceController
510
511   // Tag the item to prevent double import
512   //_studyEditor->setParameterBool(soField,OBJECT_IS_IN_WORKSPACE,true);
513 }
514
515 void DatasourceController::OnInterpolateField() {
516   // We need a studyEditor updated on the active study
517   _studyEditor->updateActiveStudy();
518
519   // Get the selected objects in the study (SObject). In case of a
520   // multiple selection, we consider only the first item. At least one
521   // item must be selected.
522   SALOME_StudyEditor::SObjectList * listOfSObject = _studyEditor->getSelectedObjects();
523   if ( listOfSObject->size() > 0 ) {
524     SALOMEDS::SObject_var soField = listOfSObject->at(0);
525     int fieldId = _studyEditor->getParameterInt(soField,OBJECT_ID);
526     // _GBO_ : the dialog should not be modal, so that we can choose a
527     // mesh in the browser. Then we have to emit a signal from the
528     // dialog.accept, connected to a slot of the DatasourceControler
529     _dlgInterpolateField->setFieldId(fieldId);
530     Qt::WindowFlags flags = _dlgInterpolateField->windowFlags();
531     _dlgInterpolateField->setWindowFlags(flags | Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint);
532     _dlgInterpolateField->open();
533   }
534 }
535
536 void DatasourceController::OnInterpolateFieldInputValidated() {
537   MEDCALC::InterpolationParameters params;
538   params.precision = _dlgInterpolateField->getPrecision();
539   STDLOG("precision = " << params.precision);
540   params.defaultValue = _dlgInterpolateField->getDefaultValue();
541   STDLOG("defaultValue = " << params.defaultValue);
542   params.reverse = _dlgInterpolateField->getReverse();
543   STDLOG("reverse = " << params.reverse);
544   params.intersectionType = _dlgInterpolateField->getIntersectionType().c_str();
545   STDLOG("intersectionType = " << params.intersectionType);
546   params.method = _dlgInterpolateField->getMethod().c_str();
547   STDLOG("method = " << params.method);
548   params.nature = _dlgInterpolateField->getFieldNature().c_str();
549   STDLOG("nature = " << params.nature);
550
551   int meshId = _dlgInterpolateField->getMeshId();
552   STDLOG("meshId = " << ToString(meshId));
553   int fieldId = _dlgInterpolateField->getFieldId();
554   MEDCALC::FieldHandler* fieldHandler = MEDFactoryClient::getDataManager()->getFieldHandler(fieldId);
555
556   // We don't modify the original field but create first a duplicate
557   // MEDCALC::FieldHandler* duplicate = MEDFactoryClient::getCalculator()->dup(*fieldHandler);
558   //MEDFactoryClient::getDataManager()->changeUnderlyingMesh(duplicate->id, meshId);
559   MEDCALC::FieldHandler* result = NULL;
560   try {
561     result = MEDFactoryClient::getDataManager()->interpolateField(fieldId, meshId, params);
562   }
563   catch(...) {
564     STDLOG("Unable to process field interpolation; please check interpolation parameters");
565     QMessageBox::critical(_salomeModule->getApp()->desktop(),
566                           tr("Operation failed"),
567                           tr("Unable to process field interpolation; please check interpolation parameters"));
568     return;
569   }
570
571   // Request once more the duplicate to update the meta-data on this
572   // client side
573   // duplicate = MEDFactoryClient::getDataManager()->getFieldHandler(duplicate->id);
574
575   // >>>
576   // WARN: the following is a temporary code for test purpose
577   // Automatically add in ws
578   DatasourceEvent * event = new DatasourceEvent();
579   event->eventtype = DatasourceEvent::EVENT_IMPORT_OBJECT;
580   XmedDataObject * dataObject = new XmedDataObject();
581   dataObject->setFieldHandler(*result);
582   event->objectdata = dataObject;
583   emit datasourceSignal(event);
584   // Note that this signal is processed by the WorkspaceController
585
586   // // Tag the item to prevent double import
587   // //_studyEditor->setParameterBool(soField,OBJECT_IS_IN_WORKSPACE,true);
588 }
589
590 void
591 DatasourceController::processWorkspaceEvent(const MEDCALC::MedEvent* event)
592 {
593   if ( event->type == MEDCALC::EVENT_ADD_DATASOURCE ) {
594     MEDCALC::DatasourceHandler* datasourceHandler = MEDFactoryClient::getDataManager()->getDatasourceHandler(event->filename);
595     this->updateTreeViewWithNewDatasource(datasourceHandler);
596     _salomeModule->updateObjBrowser(true);
597   }
598   else if ( event->type == MEDCALC::EVENT_ADD_PRESENTATION ) {
599     this->updateTreeViewWithNewPresentation(event->dataId, event->presentationId);
600     _salomeModule->updateObjBrowser(true);
601   }
602 }