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