Salome HOME
b2ab3b7d6a75e7c55d9fc4be84d25033bd3098ef
[modules/smesh.git] / src / SMESHGUI / MG_ADAPTGUI.cxx
1 // Copyright (C) 2007-2020  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  file : MG_ADAPTGUI.cxx
23
24 #include "MG_ADAPTGUI.hxx"
25
26 #include "SUIT_Desktop.h"
27 #include "SUIT_Application.h"
28 #include "SUIT_Session.h"
29
30 #include "SalomeApp_Application.h"
31 #include "SalomeApp_Module.h"
32 #include "SalomeApp_Study.h"
33 #include <SUIT_MessageBox.h>
34 #include <LightApp_SelectionMgr.h>
35 #include <SUIT_OverrideCursor.h>
36 #include <SUIT_ResourceMgr.h>
37 #include <SVTK_ViewWindow.h>
38 #include <SALOME_ListIO.hxx>
39 #include <SUIT_FileDlg.h>
40 #include <QApplication>
41 #include <QButtonGroup>
42 #include <QGridLayout>
43 #include <QGroupBox>
44 #include <QHBoxLayout>
45 #include <QKeyEvent>
46 #include <QLabel>
47 #include <QLineEdit>
48 #include <QCheckBox>
49 #include <QPushButton>
50 #include <QRadioButton>
51 #include <QTabWidget>
52 #include <QVBoxLayout>
53 #include <QDoubleSpinBox>
54 #include <QSpinBox>
55 #include <QTreeWidget>
56 #include <QTreeWidgetItem>
57 #include <QSpacerItem>
58 #include <QString>
59 #include <QHeaderView>
60 #include <QItemDelegate>
61 #include <QFileDialog>
62 #include <QMessageBox>
63 #include <QComboBox>
64
65 #include <vtkPoints.h>
66 #include <vtkUnstructuredGrid.h>
67 #include <vtkIdList.h>
68 #include <vtkCellArray.h>
69 #include <vtkUnsignedCharArray.h>
70 #include <vtkDataSetMapper.h>
71 #include <VTKViewer_CellLocationsArray.h>
72 #include <vtkProperty.h>
73
74 #include <ElCLib.hxx>
75 // SALOME KERNEL includes
76 #include <SALOMEDS_SComponent.hxx>
77 #include <SALOMEDS_SObject.hxx>
78 #include <SALOMEDS_Study.hxx>
79 #include <SALOMEDS_wrap.hxx>
80 #include "SalomeApp_Tools.h"
81 #include <SALOMEconfig.h>
82 #include <med.h>
83 #include <utilities.h>
84
85 #include <TCollection_AsciiString.hxx>
86
87
88 const int SPACING = 6;            // layout spacing
89 const int MARGIN  = 9;            // layout margin
90
91 //=================================================================================
92 // function : SMESHGUI_MgAdaptDlg()
93 // purpose  :
94 //=================================================================================
95 SMESHGUI_MgAdaptDlg::SMESHGUI_MgAdaptDlg( SalomeApp_Module* theModule, SMESH::MG_ADAPT_ptr myModel, QWidget* parent, bool isCreation )
96     : mySMESHGUI( theModule ), QDialog(parent)
97 {
98   //~model = new MgAdapt(*myModel);
99   model = SMESH::MG_ADAPT::_duplicate(myModel);
100   myData = model->getData();
101   buildDlg();
102   if (!isCreation) readParamsFromHypo();
103 }
104
105 void SMESHGUI_MgAdaptDlg::buildDlg()
106 {
107   setModal( false );
108   setAttribute( Qt::WA_DeleteOnClose, true );
109   setWindowTitle( tr( "ADAPT_PREF_MG_ADAPT" ) );
110   setSizeGripEnabled( true );
111
112   myTabWidget = new QTabWidget( this );
113
114   // Arguments
115
116   myArgs = new SMESHGUI_MgAdaptArguments( myTabWidget );
117   SMESH::str_array* str = model->getOptionValuesStrVec();
118   SMESH::str_array* str2 = model->getCustomOptionValuesStrVec();
119   std::vector<std::string> s;
120   for (int i = 0; i< str->length(); i++) s.push_back( (*str)[i].in());
121   for (int j = str->length(); j< str2->length(); j++) s.push_back((*str2)[ j - str->length() ].in() );
122   //~str.insert( str.end(), str2.begin(), str2.end() );
123
124   myAdvOpt = new MgAdaptAdvWidget(myTabWidget, &s);
125
126   int argsTab = myTabWidget->addTab( myArgs, tr( "Args" ) );
127   int advTab = myTabWidget->addTab( myAdvOpt, tr( "ADVOP" ) );
128
129   myAdvOpt->workingDirectoryLabel         ->setText (tr( "WORKING_DIR" ));
130   myAdvOpt->workingDirectoryPushButton    ->setText (tr( "SELECT_DIR" ));
131   myAdvOpt->keepWorkingFilesCheck         ->setText (tr( "KEEP_WORKING_FILES" ));
132   myAdvOpt->verboseLevelLabel             ->setText (tr( "VERBOSE_LEVEL" ));
133   myAdvOpt->removeLogOnSuccessCheck       ->setText (tr( "REMOVE_LOG_ON_SUCCESS" ));
134   myAdvOpt->logInFileCheck                ->setText (tr( "LOG_IN_FILE" ));
135   myAdvOpt->logGroupBox                   ->setTitle(tr( "LOG_GROUP_TITLE" ));
136
137   // buttons
138   QPushButton* okBtn = new QPushButton( tr( "SMESH_BUT_OK" ), this );
139   okBtn->setAutoDefault( true );
140   okBtn->setDefault( true );
141   okBtn->setFocus();
142   QPushButton* buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), this);
143   buttonApply->setAutoDefault(true);
144   QPushButton* buttonApplyAndClose = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), this);
145   buttonApplyAndClose->setAutoDefault(true);
146   QPushButton* cancelBtn = new QPushButton( tr( "SMESH_BUT_CANCEL" ), this );
147   cancelBtn->setAutoDefault( true );
148   QPushButton* helpBtn = new QPushButton( tr( "SMESH_BUT_HELP" ), this );
149   helpBtn->setAutoDefault( true );
150
151   QHBoxLayout* btnLayout = new QHBoxLayout;
152   btnLayout->setSpacing( SPACING );
153   btnLayout->setMargin( 0 );
154   btnLayout->addWidget( buttonApplyAndClose );
155   btnLayout->addStretch( 10 );
156   btnLayout->addWidget( buttonApply );
157   btnLayout->addStretch( 10 );
158   btnLayout->addWidget( okBtn );
159   btnLayout->addStretch( 10 );
160   btnLayout->addWidget( cancelBtn );
161   btnLayout->addStretch( 10 );
162   btnLayout->addWidget( helpBtn );
163   okBtn->hide(); // tab 1
164
165   QVBoxLayout* l = new QVBoxLayout ( this );
166   l->setMargin( MARGIN );
167   l->setSpacing( SPACING );
168   l->addWidget( myTabWidget );
169   l->addStretch();
170   l->addLayout( btnLayout );
171
172
173   connect( okBtn,       SIGNAL(clicked()),              this, SLOT( clickOnOk() ) );
174   connect( helpBtn,     SIGNAL(clicked()),              this, SLOT( clickOnHelp() ) );
175   connect(cancelBtn,    SIGNAL(clicked()),              this, SLOT(reject()));
176   connect(buttonApply,  SIGNAL(clicked()),              this,SLOT(clickOnApply()));
177   connect(buttonApplyAndClose,     SIGNAL(clicked()),   this,SLOT(clickOnOk()));
178   connect(myArgs, SIGNAL(meshDimSignal(ADAPTATION_MODE)), myAdvOpt, SLOT( onMeshDimChanged(ADAPTATION_MODE))  );
179 }
180
181
182 //=================================================================================
183 // function : ~SMESHGUI_MgAdaptDlg()
184 // purpose  : Destroys the object and frees any allocated resources
185 //=================================================================================
186 SMESHGUI_MgAdaptDlg::~SMESHGUI_MgAdaptDlg()
187 {
188     //~delete model;
189 }
190
191 //~void SMESHGUI_MgAdaptDlg::setModel(MgAdapt* mg)
192 //~{
193     //~model = mg;
194 //~}
195 SMESH::MG_ADAPT_ptr SMESHGUI_MgAdaptDlg::getModel() const
196 {
197   return model;
198 }
199 /*!
200 \brief Perform clean-up actions on the dialog box closing.
201 */
202 bool SMESHGUI_MgAdaptDlg::clickOnApply()
203 {
204   readParamsFromWidgets();
205   return true;
206 }
207 void SMESHGUI_MgAdaptDlg::clickOnOk()
208 {
209   clickOnApply();
210   reject();
211 }
212 void SMESHGUI_MgAdaptDlg::reject()
213 {
214   QDialog::reject();
215 }
216 bool SMESHGUI_MgAdaptDlg::readParamsFromHypo( ) const
217 {
218   bool ret = true;
219   myArgs->aMedfile->setChecked(myData->fromMedFile) ;
220   if (myData->fromMedFile)
221   {
222
223     *(myArgs->myFileInDir) = QString(myData->myFileInDir) ;
224     myArgs->selectMedFileLineEdit->setText(QString(myData->myMeshFileIn)) ;
225     // myData->myInMeshName = // TODO
226
227   }
228   else
229   {
230     myArgs->aBrowserObject->setText(QString(myData->myInMeshName));
231     //~ myArgs->myFileInDir =""; // TODO
232     //~ myArgs->selectMedFileLineEdit->setText(); // TODO
233   }
234   myArgs->meshNameLineEdit->setText(QString(myData->myOutMeshName));
235   myArgs->medFileCheckBox->setChecked(myData->myMeshOutMed);
236
237   if(myData->myMeshOutMed)
238   {
239     *(myArgs->myFileOutDir) = QString(myData->myFileOutDir);
240     myArgs->selectOutMedFileLineEdit->setText(QString(myData->myMeshFileOut));
241   }
242   else
243   {
244     *(myArgs->myFileOutDir) = QString(""); //TODO
245   }
246
247   myArgs->publishOut->setChecked(myData->myPublish);
248
249   myArgs->localButton->setChecked(myData->myUseLocalMap);
250   myArgs->backgroundButton->setChecked(myData->myUseBackgroundMap);
251   myArgs->constantButton->setChecked(myData->myUseConstantValue);
252
253   if (myData->myUseConstantValue)
254   {
255     myArgs->dvalue->setValue(myData->myConstantValue);
256   }
257   else
258   {
259     myArgs->dvalue->setValue(0.0);
260   }
261
262   if (myData->myUseBackgroundMap)
263   {
264
265     *(myArgs->myFileSizeMapDir) = QString(myData->myFileSizeMapDir) ;
266     myArgs->selectMedFileBackgroundLineEdit->setText(QString(myData->myMeshFileBackground));
267   }
268   else
269   {
270     *(myArgs->myFileSizeMapDir) = QString("") ;  //TODO
271     myArgs->selectMedFileBackgroundLineEdit->setText(""); //TODO
272   }
273
274   myArgs->fieldNameCmb->setCurrentText(QString(myData->myFieldName));
275   myArgs->noTimeStep->setChecked(myData->myUseNoTimeStep);
276   myArgs->lastTimeStep->setChecked( myData->myUseLastTimeStep);
277   myArgs->chosenTimeStep->setChecked(myData->myUseChosenTimeStep);
278   if (myData->myUseChosenTimeStep)
279   {
280     myArgs->rankSpinBox->setValue(myData->myRank);
281     myArgs->timeStep->setValue(myData->myTimeStep);
282   }
283
284   myAdvOpt->workingDirectoryLineEdit->setText(QString(myData->myWorkingDir));
285   myAdvOpt->logInFileCheck->setChecked(myData->myPrintLogInFile);
286
287   myAdvOpt->verboseLevelSpin->setValue(myData->myVerboseLevel);
288   myAdvOpt->removeLogOnSuccessCheck->setChecked(myData->myRemoveLogOnSuccess);
289   myAdvOpt->keepWorkingFilesCheck->setChecked(myData->myKeepFiles);
290
291   return ret;
292
293 }
294
295
296 bool SMESHGUI_MgAdaptDlg::readParamsFromWidgets()
297 {
298   bool ret = true;
299   SMESH::MgAdaptHypothesisData* aData = new SMESH::MgAdaptHypothesisData();
300   aData->fromMedFile = myArgs->aMedfile->isChecked();
301   if (aData->fromMedFile)
302   {
303
304     aData->myFileInDir = CORBA::string_dup(myArgs->myFileInDir->toStdString().c_str());
305     aData->myMeshFileIn = CORBA::string_dup(myArgs->selectMedFileLineEdit->text().toStdString().c_str());
306       // aData->myInMeshName = // TODO
307   }
308   else // TODO browser
309   {
310     aData->myInMeshName = CORBA::string_dup(myArgs->aBrowserObject->text().toStdString().c_str());
311     aData->myFileInDir = CORBA::string_dup(myAdvOpt->workingDirectoryLineEdit->text().toStdString().c_str());
312
313     TCollection_AsciiString aGenericName = (char*)aData->myFileInDir;
314     TCollection_AsciiString aGenericName2 = "MgAdapt_";
315     aGenericName2 += getpid();
316     aGenericName2 += "_";
317     aGenericName2 += Abs((Standard_Integer)(long) aGenericName.ToCString());
318     aGenericName2 += ".med";
319     aGenericName+=aGenericName2;
320     emit myArgs->toExportMED(aGenericName.ToCString());
321     aData->myMeshFileIn = aGenericName2.ToCString();
322   }
323   aData->myOutMeshName = CORBA::string_dup(myArgs->meshNameLineEdit->text().toStdString().c_str());
324   aData->myMeshOutMed = myArgs->medFileCheckBox->isChecked();
325   if(aData->myMeshOutMed)
326   {
327     aData->myFileOutDir = CORBA::string_dup(myArgs->myFileOutDir->toStdString().c_str());
328     aData->myMeshFileOut = CORBA::string_dup(myArgs->selectOutMedFileLineEdit->text().toStdString().c_str());
329
330   }
331   else
332   {
333     aData->myMeshFileOut = "";
334   }
335
336   aData->myPublish = myArgs->publishOut->isChecked();
337
338
339   aData->myUseLocalMap = myArgs->localButton->isChecked();
340   aData->myUseBackgroundMap = myArgs->backgroundButton->isChecked();
341   aData->myUseConstantValue = myArgs->constantButton->isChecked();
342   if (aData->myUseConstantValue)
343   {
344     aData->myConstantValue = myArgs->dvalue->value();
345   }
346   else
347   {
348     aData->myConstantValue = 0.0;
349   }
350   if (aData->myUseBackgroundMap)
351   {
352     aData->myFileSizeMapDir = CORBA::string_dup(myArgs->myFileSizeMapDir->toStdString().c_str());
353     aData->myMeshFileBackground = CORBA::string_dup(myArgs->selectMedFileBackgroundLineEdit->text().toStdString().c_str());
354   }
355   else
356   {
357     aData->myMeshFileBackground = "";
358   }
359
360   aData->myFieldName = CORBA::string_dup(myArgs->fieldNameCmb->currentText().toStdString().c_str());
361   aData->myUseNoTimeStep = myArgs->noTimeStep->isChecked();
362   aData->myUseLastTimeStep = myArgs->lastTimeStep->isChecked();
363   aData->myUseChosenTimeStep = myArgs->chosenTimeStep->isChecked();
364   if (aData->myUseChosenTimeStep)
365   {
366     aData->myRank = myArgs->rankSpinBox->value();
367     aData->myTimeStep = myArgs->timeStep->value();
368
369   }
370
371   aData->myWorkingDir = CORBA::string_dup(myAdvOpt->workingDirectoryLineEdit->text().toStdString().c_str());
372   aData->myPrintLogInFile = myAdvOpt->logInFileCheck->isChecked();
373   aData->myVerboseLevel = myAdvOpt->verboseLevelSpin->value();
374   aData->myRemoveLogOnSuccess = myAdvOpt->removeLogOnSuccessCheck->isChecked();
375   aData->myKeepFiles = myAdvOpt->keepWorkingFilesCheck->isChecked();
376   model->setData(*aData);
377   QString msg;
378   checkParams(msg);
379   delete aData;
380   return ret;
381 }
382 bool SMESHGUI_MgAdaptDlg::storeParamsToHypo( const SMESH::MgAdaptHypothesisData& ) const
383 {
384
385 }
386 /*!
387   \brief Show help page
388 */
389 void SMESHGUI_MgAdaptDlg::clickOnHelp()
390 {
391   // QString aHelpFile;
392   // if ( myTabWidget->currentIndex() == MinDistance ) {
393   //   aHelpFile = "measurements.html#min-distance-anchor";
394   // } else if ( myTabWidget->currentIndex() == BoundingBox ) {
395   //   aHelpFile = "measurements.html#bounding-box-anchor";
396   // } else if ( myTabWidget->currentWidget() == myAngle ) {
397   //   aHelpFile = "measurements.html#angle-anchor";
398   // } else {
399   //   aHelpFile = "measurements.html#basic-properties-anchor";
400   // }
401
402   // SMESH::ShowHelpFile( aHelpFile );
403 }
404 bool SMESHGUI_MgAdaptDlg::checkParams(QString& msg)
405 {
406   if ( !QFileInfo( myAdvOpt->workingDirectoryLineEdit->text().trimmed() ).isWritable() )
407   {
408     SUIT_MessageBox::warning( this,
409                               tr( "SMESH_WRN_WARNING" ),
410                               tr( "GHS3D_PERMISSION_DENIED" ) );
411     return false;
412   }
413
414
415   myAdvOpt->myOptionTable->setFocus();
416   QApplication::instance()->processEvents();
417
418   QString name, value;
419   bool isDefault, ok = true;
420   int iRow = 0, nbRows = myAdvOpt->myOptionTable->topLevelItemCount();
421   for ( ; iRow < nbRows; ++iRow )
422   {
423     QTreeWidgetItem* row = myAdvOpt->myOptionTable->topLevelItem( iRow );
424     myAdvOpt->GetOptionAndValue( row, name, value, isDefault );
425
426     if ( name.simplified().isEmpty() )
427         continue; // invalid custom option
428
429     if ( isDefault ) // not selected option
430         value.clear();
431
432     try
433     {
434       model->setOptionValue( name.toLatin1().constData(), value.toLatin1().constData() );
435     }
436     catch ( const SALOME::SALOME_Exception& ex )
437     {
438       msg = ex.details.text.in();
439       ok = false;
440       break;
441     }
442   }
443
444   return ok;
445 }
446
447 //=================================================================================
448 // function : SMESHGUI_MgAdaptArguments()
449 // purpose  :
450 //=================================================================================
451 SMESHGUI_MgAdaptArguments::SMESHGUI_MgAdaptArguments( QWidget* parent )
452     :QWidget(parent)
453 {
454
455   myFileInDir = new QString("");
456   myFileOutDir = new QString("");
457   myFileSizeMapDir = new QString("");
458   if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
459   {
460     *myFileInDir = QDir::currentPath();
461     *myFileOutDir = QDir::currentPath();
462     *myFileSizeMapDir = QDir::currentPath();
463   }
464   else
465   {
466     *myFileInDir = SUIT_FileDlg::getLastVisitedPath();
467     *myFileOutDir = SUIT_FileDlg::getLastVisitedPath();
468     *myFileSizeMapDir = SUIT_FileDlg::getLastVisitedPath();
469   }
470
471   meshDim = 0;
472   // Mesh in
473   aMeshIn = new QGroupBox( tr( "MeshIn" ), this );
474   aMedfile       = new QRadioButton( tr( "MEDFile" ),    aMeshIn );
475   aBrowser       = new QRadioButton( tr( "Browser" ), aMeshIn );
476   aBrowserObject       = new QLineEdit(  aMeshIn );
477   selectMedFilebutton = new QPushButton("", aMeshIn);
478   selectMedFileLineEdit      = new QLineEdit(  aMeshIn );
479
480   meshIn = new QGridLayout( aMeshIn );
481
482   meshIn->setMargin( MARGIN );
483   meshIn->setSpacing( SPACING );
484   meshIn->addWidget( aMedfile,     0, 0, 1,1 );
485   meshIn->addWidget( aBrowser,     0, 1,1,1);
486   meshIn->addWidget( aBrowserObject,     0, 2, 1, 1 );
487   meshIn->addWidget( selectMedFilebutton,  1, 0,1, 1);
488   meshIn->addWidget( selectMedFileLineEdit,  1, 1, 1, 1 );
489   hspacer = new QSpacerItem(188, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
490
491   meshInGroup = new QButtonGroup( this );
492   meshInGroup->addButton( aMedfile,   0 );
493   meshInGroup->addButton( aBrowser,   1 );
494
495   //Mesh out
496
497   aMeshOut = new QGroupBox( tr( "MeshOut" ), this );
498   meshName = new QLabel(tr("MeshName"), aMeshOut);
499   secondHspacer = new QSpacerItem(100, 30);
500   meshNameLineEdit = new QLineEdit(aMeshOut) ;
501   medFileCheckBox = new QCheckBox(tr("MEDFile"), aMeshOut);
502   selectOutMedFilebutton = new QPushButton("", aMeshOut);
503   thirdHspacer = new QSpacerItem(188, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
504   selectOutMedFileLineEdit = new QLineEdit(aMeshOut) ;
505   publishOut = new  QCheckBox(tr("Publish_MG_ADAPT"), aMeshOut);
506
507   meshOut = new QGridLayout( aMeshOut );
508
509   meshOut->setMargin( MARGIN );
510   meshOut->setSpacing( SPACING );
511   meshOut->addWidget( meshName,  0, 0, 1,1 );
512   meshOut->addItem( secondHspacer,  0, 1, 1, 1 );
513   meshOut->addWidget( meshNameLineEdit, 0, 2,1,1);
514   meshOut->addWidget( medFileCheckBox,  1, 0,1,1 );
515   meshOut->addWidget( selectOutMedFilebutton,  1, 1,1,1 );
516   meshOut->addWidget( selectOutMedFileLineEdit,  1, 2,1,1);
517   meshOut->addWidget( publishOut,  2, 0,1,1 );
518
519   //size map definition
520
521   sizeMapDefinition  = new QGroupBox(tr("SIZE_MAP_DEF"), this);
522   localButton = new QRadioButton(tr("LOCAL_MG_ADAPT"), sizeMapDefinition);
523   backgroundButton = new QRadioButton(tr("BACKGRND_MG_ADAPT"), sizeMapDefinition);
524   constantButton = new QRadioButton(tr("CNST_MG_ADAPT"), sizeMapDefinition);
525   medFileBackground = new QLabel(tr("MED_FILE_BCKG"), sizeMapDefinition);
526   selectMedFileBackgroundbutton = new QPushButton(tr(""), sizeMapDefinition);
527   selectMedFileBackgroundLineEdit = new QLineEdit(sizeMapDefinition);
528   valueLabel = new QLabel(tr("VALUE_MG_ADAPT"), sizeMapDefinition);
529   dvalue = new QDoubleSpinBox(sizeMapDefinition);
530   sizeMapDefGroup = new QButtonGroup( this );
531   sizeMapDefGroup->addButton( localButton,   0 );
532   sizeMapDefGroup->addButton( backgroundButton,   1 );
533   sizeMapDefGroup->addButton( constantButton,   2 );
534
535   sizeMapDefGroupLayout = new QGridLayout(sizeMapDefinition);
536   sizeMapDefGroupLayout->addWidget(localButton, 0,0);
537   sizeMapDefGroupLayout->addWidget(backgroundButton, 0,1);
538   sizeMapDefGroupLayout->addWidget(constantButton, 0,2);
539   sizeMapDefGroupLayout->addWidget(medFileBackground, 1,0);
540   sizeMapDefGroupLayout->addWidget(selectMedFileBackgroundbutton, 1,1);
541   sizeMapDefGroupLayout->addWidget(selectMedFileBackgroundLineEdit, 1,2);
542   sizeMapDefGroupLayout->addWidget(valueLabel, 2,0);
543   sizeMapDefGroupLayout->addWidget(dvalue, 2,1);
544
545   // size Map field
546   sizeMapField = new QGroupBox(tr("SIZE_MAP_FIELD"), this);
547   fieldName = new QLabel(tr("MG_ADAPT_FIELD_NAME"), sizeMapField);
548   fieldNameCmb = new QComboBox(sizeMapField);
549   noTimeStep = new QRadioButton(tr("MG_ADAPT_NO_T_ST"), sizeMapField);
550   lastTimeStep = new QRadioButton(tr("MG_ADAPT_L_ST"), sizeMapField);
551   chosenTimeStep = new QRadioButton(tr("MG_ADAPT_CH_ST"), sizeMapField);
552   timeStepLabel = new QLabel(tr("MG_ADAPT_TSTP"), sizeMapField);
553   timeStep = new QSpinBox(sizeMapField);
554   //~timeStep->setMinimum(-1);
555   rankLabel = new QLabel(tr("MG_ADAPT_RANK"), sizeMapField);
556   rankSpinBox = new QSpinBox(sizeMapField);
557   rankSpinBox->setMinimum(-1);
558
559   timeStepGroup = new QButtonGroup(this);
560   timeStepGroup->addButton(noTimeStep, 0);
561   timeStepGroup->addButton(lastTimeStep, 1);
562   timeStepGroup->addButton(chosenTimeStep, 2);
563
564   sizeMapFieldGroupLayout = new QGridLayout(sizeMapField);
565
566   sizeMapFieldGroupLayout->addWidget(fieldName, 0,0);
567   sizeMapFieldGroupLayout->addWidget(fieldNameCmb, 0,1);
568   sizeMapFieldGroupLayout->addWidget(noTimeStep, 1,0);
569   sizeMapFieldGroupLayout->addWidget(lastTimeStep, 1,1);
570   sizeMapFieldGroupLayout->addWidget(chosenTimeStep, 1,2);
571   sizeMapFieldGroupLayout->addWidget(timeStepLabel, 2,0);
572   sizeMapFieldGroupLayout->addWidget(timeStep, 2,1);
573   sizeMapFieldGroupLayout->addWidget(rankLabel, 2,2);
574   sizeMapFieldGroupLayout->addWidget(rankSpinBox, 2,3);
575
576   QGridLayout* argumentsLayout = new QGridLayout( this );
577   argumentsLayout->setMargin( MARGIN );
578   argumentsLayout->setSpacing( SPACING );
579
580   argumentsLayout->addWidget( aMeshIn,  0, 0, 1, 3 );
581   argumentsLayout->addWidget( aMeshOut, 1, 0, 1, 3 );
582   argumentsLayout->addWidget( sizeMapDefinition, 2, 0, 1, 3 );
583   argumentsLayout->addWidget( sizeMapField, 3, 0, 1, 3 );
584   argumentsLayout->setColumnStretch( 1, 5 );
585   argumentsLayout->setRowStretch( 4, 5 );
586
587   // Initial state
588   setMode( Mesh, Local);
589   medFileCheckBox->setChecked(true);
590   visibleTimeStepRankLabel (false);
591
592   // Connections
593   connect( meshInGroup,            SIGNAL( buttonClicked( int ) ),  this, SLOT( modeChanged( int ) ) );
594   connect( sizeMapDefGroup,        SIGNAL( buttonClicked( int ) ),  this, SLOT( sizeMapDefChanged( int ) ) );
595   connect( selectMedFilebutton,    SIGNAL( pressed(  ) ),           this, SLOT( onSelectMedFilebuttonClicked(  ) ) );
596   connect( medFileCheckBox,        SIGNAL (stateChanged(int)),      this, SLOT(onMedFileCheckBox(int) ) );
597   connect( publishOut,             SIGNAL (stateChanged(int)),      this, SLOT(onPublishOut(int) ) );
598   connect( selectOutMedFilebutton, SIGNAL( pressed()),              this, SLOT(onSelectOutMedFilebutton()));
599   connect( selectMedFileBackgroundbutton, SIGNAL(pressed()),        this, SLOT(onSelectMedFileBackgroundbutton()) );
600   connect( timeStepGroup,          SIGNAL( buttonClicked( int ) ),  this, SLOT( timeStepGroupChanged( int ) ) );
601   emit updateSelection();
602 }
603
604 //=================================================================================
605 // function : ~SMESHGUI_MgAdaptArguments()
606 // purpose  : Destroys the object and frees any allocated resources
607 //=================================================================================
608 SMESHGUI_MgAdaptArguments::~SMESHGUI_MgAdaptArguments()
609 {
610 }
611
612 void SMESHGUI_MgAdaptArguments::onNoTimeStep(bool disableOther)
613 {
614   noTimeStep->setChecked(true);
615
616   visibleTimeStepRankLabel (false);
617   rankSpinBox->setValue(-2);
618   timeStep->setValue(-2);
619
620   lastTimeStep->setDisabled(disableOther);
621   chosenTimeStep->setDisabled(disableOther);
622 }
623 void SMESHGUI_MgAdaptArguments::onLastTimeStep(bool disableOther)
624 {
625   lastTimeStep->setChecked(true);
626
627   visibleTimeStepRankLabel (false);
628   rankSpinBox->setValue(-1);
629   timeStep->setValue(-1);
630   noTimeStep->setDisabled(disableOther);
631 }
632 void SMESHGUI_MgAdaptArguments::onChosenTimeStep(bool disableOther, int vmax)
633 {
634   chosenTimeStep->setChecked(true);
635
636   visibleTimeStepRankLabel (true);
637   rankSpinBox->setValue(0);
638   timeStep->setValue(0);
639   if (vmax) timeStep->setMaximum(vmax);
640 }
641
642 void SMESHGUI_MgAdaptArguments::visibleTimeStepRankLabel(bool visible)
643 {
644   rankLabel->setVisible(visible);
645   rankSpinBox->setVisible(visible);
646
647   timeStepLabel->setVisible(visible);
648   timeStep->setVisible(visible);
649 }
650
651 void SMESHGUI_MgAdaptArguments::onSelectOutMedFilebutton()
652 {
653
654   QString filtre = QString("Med") ;
655   filtre += QString(" files (*.") + QString("med") + QString(");;");
656   QString fileName = QFileDialog::getSaveFileName(this, tr("SAVE_MED"), QString(""), filtre);
657   QFileInfo myFileInfo(fileName);
658   selectOutMedFileLineEdit->setText(myFileInfo.fileName());
659   *myFileOutDir = myFileInfo.path();
660
661 }
662 void SMESHGUI_MgAdaptArguments::onSelectMedFileBackgroundbutton()
663 {
664   QString fileName0 = selectMedFileBackgroundbutton->text().trimmed();
665
666   QString fileName = getMedFileName(false);
667   if (fileName != QString::null)
668   {
669     myFieldList = GetListeChamps(fileName);
670     if (myFieldList.empty())
671     {
672       fileName = fileName0;
673       fieldNameCmb->clear();
674     }
675     else
676     {
677       // fill field name Combobox
678       fieldNameCmb->clear();
679       std::map<QString, int>::const_iterator it;
680       for ( it=myFieldList.begin() ; it != myFieldList.end(); it++)
681       {
682         fieldNameCmb->insertItem(0,QString(it->first));
683         int typeStepInField = it->second > 2 ?  2 : it->second ;
684         timeStepGroupChanged(typeStepInField, false);
685       }
686     }
687   }
688   else
689   {
690     fileName = fileName0;
691     fieldNameCmb->clear();
692   }
693
694   QFileInfo myFileInfo(fileName);
695   *myFileSizeMapDir = myFileInfo.path();
696   selectMedFileBackgroundLineEdit->setText(myFileInfo.fileName());
697
698 }
699 void SMESHGUI_MgAdaptArguments::onMedFileCheckBox(int state)
700 {
701   if (state == Qt::Checked)
702   {
703     selectOutMedFilebutton->show();
704     selectOutMedFileLineEdit->show();
705     selectOutMedFilebutton->setEnabled(true);
706     selectOutMedFileLineEdit->setEnabled(true);
707   }
708   else
709   {
710     selectOutMedFilebutton->setEnabled(false);
711     selectOutMedFileLineEdit->setEnabled(false);
712     publishOut->setChecked(true);
713   }
714 }
715 void SMESHGUI_MgAdaptArguments::onPublishOut(int state)
716 {
717   if (state == Qt::Unchecked)
718   {
719     medFileCheckBox->setChecked(true);
720   }
721 }
722
723 void SMESHGUI_MgAdaptArguments::onSelectMedFilebuttonClicked()
724 {
725   // bool keep = false;
726   QString fileName0 = selectMedFileLineEdit->text().trimmed();
727
728   QString fileName = getMedFileName(false);
729   if(fileName != QString::null)
730   {
731     QString aMeshName = lireNomMaillage(fileName.trimmed(), meshDim);
732     if (aMeshName == QString::null )
733     {
734       QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
735                                 QObject::tr("MG_ADAPT_MED_FILE_2") );
736       fileName = fileName0;
737     }
738     else
739     {
740       meshNameLineEdit->setText(aMeshName);
741       ADAPTATION_MODE aMode = meshDim == 3 ? ADAPTATION_MODE::BOTH : ADAPTATION_MODE::SURFACE; // and when dimesh 3 without 2D mesh?
742       emit meshDimSignal(aMode);
743     }
744   }
745   else
746   {
747       return;
748   }
749
750   QFileInfo myFileInfo(fileName);
751   *myFileInDir = myFileInfo.path();
752   *myFileOutDir = myFileInfo.path();
753   selectMedFileLineEdit->setText(myFileInfo.fileName());
754   QString outF = fileName == QString::null ? myFileInfo.fileName() :
755   QString( remove_extension(myFileInfo.fileName().toStdString() ).c_str() )+ QString(".adapt.med");
756   selectOutMedFileLineEdit->setText(outF);
757   onLocalSelected(myFileInfo.filePath());
758
759 }
760
761 void SMESHGUI_MgAdaptArguments::onLocalSelected(QString filePath)
762 {
763   myFieldList = GetListeChamps(filePath, false);
764   if (myFieldList.empty())
765   {
766     if (localButton->isChecked())
767     {
768       fieldNameCmb->clear();
769     }
770   }
771   else
772   {
773     // fill field name Combobox
774     fieldNameCmb->clear();
775     std::map<QString, int>::const_iterator it;
776     for ( it = myFieldList.begin() ; it != myFieldList.end(); it++)
777     {
778       fieldNameCmb->insertItem(0,QString(it->first));
779       // Je ne comprends pas le rapport entre pas de temps et apparition d'un nouveau champ... GN
780       int typeStepInField = it->second > 2 ?  2 : it->second ;
781 //             std::cout << "SMESHGUI_MgAdaptArguments::onLocalSelected typeStepInField : " << typeStepInField << std::endl;
782       timeStepGroupChanged(typeStepInField, false);
783     }
784   }
785 }
786 // =======================================================================
787 // Gestion les boutons qui permettent  de
788 // 1) retourne le nom d'un fichier par une fenetre de dialogue si aucun
789 //    objet est selectionne dans l arbre d etude
790 // 2) retourne le nom du fichier asocie a l objet
791 //    selectionne dans l arbre d etude
792 // =======================================================================
793 QString SMESHGUI_MgAdaptArguments::getMedFileName(bool avertir)
794 {
795
796   QString aFile = QString::null;
797   QString filtre = QString("Med") ;
798   filtre += QString(" files (*.") + QString("med") + QString(");;");
799   aFile = SUIT_FileDlg::getOpenFileName(0, QObject::tr("MG_ADAPT_SELECT_FILE_0"), QString(""), filtre );
800
801   return aFile;
802
803 }
804 void SMESHGUI_MgAdaptArguments::setMode(const Mode theMode, const SIZEMAP theSizeMap )
805 {
806   QRadioButton* aButton = qobject_cast<QRadioButton*>( meshInGroup->button( theMode ) );
807   QRadioButton* bButton = qobject_cast<QRadioButton*>( sizeMapDefGroup->button( theSizeMap ) );
808   if ( aButton )
809   {
810     aButton->setChecked( true );
811     modeChanged( theMode );
812   }
813   if ( bButton )
814   {
815     bButton->setChecked( true );
816     sizeMapDefChanged( theSizeMap );
817   }
818 }
819
820 void SMESHGUI_MgAdaptArguments::modeChanged( int theMode )
821 {
822   clear();
823   if(theMode == Mesh)
824   {
825     aBrowserObject->hide();
826     selectMedFileLineEdit->show();
827     selectMedFilebutton->show();
828     localButton->setEnabled(true);
829   }
830   else
831   {
832     selectMedFileLineEdit->hide();
833     selectMedFilebutton->hide();
834     localButton->setEnabled(false);
835     aBrowserObject->show();
836     sizeMapDefChanged(Background);
837     emit updateSelection();
838   }
839 }
840
841 void SMESHGUI_MgAdaptArguments::sizeMapDefChanged( int  theSizeMap )
842 {
843   fieldNameCmb->clear();
844   if(theSizeMap == Local)
845   {
846     localButton->setEnabled(true);
847     localButton->setChecked(true);
848     medFileBackground->hide();
849     selectMedFileBackgroundbutton->hide();
850     selectMedFileBackgroundLineEdit->hide();
851     selectMedFileBackgroundLineEdit->clear();
852     valueLabel->hide();
853     dvalue->hide();
854
855     sizeMapField->setEnabled(true);
856     if (!selectMedFileLineEdit->text().isEmpty())
857     {
858       QFileInfo myFileInfo(QDir(*myFileInDir), selectMedFileLineEdit->text());
859       onLocalSelected(myFileInfo.filePath());
860     }
861   }
862   else if (theSizeMap == Background)
863   {
864     medFileBackground->show();
865     backgroundButton->setChecked(true);
866     selectMedFileBackgroundbutton->show();
867     selectMedFileBackgroundLineEdit->show();
868     valueLabel->hide();
869     dvalue->hide();
870     sizeMapField->setEnabled(true);
871
872   }
873   else
874   {
875     medFileBackground->hide();
876     constantButton->setChecked(true);
877     selectMedFileBackgroundbutton->hide();
878     selectMedFileBackgroundLineEdit->clear();
879     selectMedFileBackgroundLineEdit->hide();
880     valueLabel->show();
881     dvalue->show();
882     sizeMapField->setEnabled(false);
883   }
884 }
885 void SMESHGUI_MgAdaptArguments::timeStepGroupChanged(int timeStepType, bool disableOther, int vmax)
886 {
887   switch (timeStepType)
888   {
889   case 0 :
890     onNoTimeStep(disableOther);
891     break;
892   case 1 :
893     onLastTimeStep(disableOther);
894     break;
895   case 2 :
896     onChosenTimeStep(disableOther, vmax);
897   default:
898     break;
899   }
900 }
901
902 void SMESHGUI_MgAdaptArguments::clear()
903 {
904   selectMedFileLineEdit->clear();
905   aBrowserObject->clear();
906
907   meshNameLineEdit->clear();
908   selectOutMedFileLineEdit->clear();
909 }
910 med_int SMESHGUI_MgAdaptArguments::getMeshDim() const
911 {
912   return meshDim;
913 }
914 QWidget* ItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &o, const QModelIndex &index) const
915 {
916   bool editable = index.data( EDITABLE_ROLE ).toInt();
917   return editable ? QItemDelegate::createEditor( parent, o, index ) : 0;
918 }
919
920 //////////////////////////////////////////
921 // MgAdaptAdvWidget
922 //////////////////////////////////////////
923
924 MgAdaptAdvWidget::MgAdaptAdvWidget( QWidget* parent, std::vector <std::string>* options, Qt::WindowFlags f )
925   : QWidget( parent, f ), myOptions(options)
926 {
927   setupWidget();
928   myOptionTable->header()->setSectionResizeMode( QHeaderView::ResizeToContents );
929   myOptionTable->setItemDelegate( new ItemDelegate( myOptionTable ) );
930
931   for ( int i = 0, nb = myOptions->size(); i < nb; ++i )
932   {
933     AddOption( (*myOptions)[i].c_str() );
934   }
935
936   connect( myOptionTable, SIGNAL( itemChanged(QTreeWidgetItem *, int)), SLOT( itemChanged(QTreeWidgetItem *, int )));
937   connect( addBtn,        SIGNAL(clicked()),       this, SLOT( onAddOption() ) );
938   connect(workingDirectoryPushButton, SIGNAL(pressed()),  this, SLOT(_onWorkingDirectoryPushButton()));
939 }
940
941 MgAdaptAdvWidget::~MgAdaptAdvWidget()
942 {
943 }
944
945 void MgAdaptAdvWidget::AddOption( const char* option, bool isCustom )
946 {
947   QString name, value;
948   bool isDefault = false;
949   if ( option )
950   {
951     QStringList name_value_type = QString(option).split( ":", QString::KeepEmptyParts );
952     if ( name_value_type.size() > 0 )
953         name = name_value_type[0];
954     if ( name_value_type.size() > 1 )
955         value = name_value_type[1];
956     if ( name_value_type.size() > 2 )
957         isDefault = !name_value_type[2].toInt();
958   }
959   QTreeWidget* table = myOptionTable;
960   //table->setExpanded( true );
961
962   QTreeWidgetItem* row;
963   if (optionTreeWidgetItem.size())
964   {
965     std::map<QString, QTreeWidgetItem *>::iterator it = optionTreeWidgetItem.find(name);
966     if(it != optionTreeWidgetItem.end()) return; // option exist
967     else
968     {
969       row = getNewQTreeWidgetItem(table, option, name, isCustom);
970     }
971   }
972   else
973   {
974     row = getNewQTreeWidgetItem(table, option, name, isCustom);
975   }
976   row->setText( 0, tr( name.toLatin1().constData() ));
977   row->setText( 1, tr( value.toLatin1().constData() ));
978   row->setCheckState( 0, isDefault ? Qt::Unchecked : Qt::Checked);
979   row->setData( NAME_COL, PARAM_NAME, name );
980
981   if ( isCustom )
982   {
983     myOptionTable->scrollToItem( row );
984     myOptionTable->setCurrentItem( row );
985     myOptionTable->editItem( row, NAME_COL );
986   }
987 }
988
989 QTreeWidgetItem* MgAdaptAdvWidget::getNewQTreeWidgetItem(QTreeWidget* table, const char* option, QString& name, bool isCustom)
990 {
991   QTreeWidgetItem* row = new QTreeWidgetItem( table );
992   row->setData( NAME_COL, EDITABLE_ROLE, int( isCustom && !option ));
993   row->setFlags( row->flags() | Qt::ItemIsEditable );
994   optionTreeWidgetItem.insert(std::pair <QString, QTreeWidgetItem*> (name, row));
995
996   return row;
997 }
998
999 void MgAdaptAdvWidget::onAddOption()
1000 {
1001   AddOption( NULL, true );
1002 }
1003 void MgAdaptAdvWidget::GetOptionAndValue( QTreeWidgetItem * tblRow,
1004         QString&          option,
1005         QString&          value,
1006         bool&             isDefault)
1007 {
1008   option    = tblRow->data( NAME_COL, PARAM_NAME ).toString();
1009   value     = tblRow->text( VALUE_COL );
1010   isDefault = ! tblRow->checkState( NAME_COL );
1011
1012 }
1013
1014 void MgAdaptAdvWidget::itemChanged(QTreeWidgetItem* tblRow, int column)
1015 {
1016   if ( tblRow )
1017   {
1018     myOptionTable->blockSignals( true );
1019
1020     tblRow->setData( VALUE_COL, EDITABLE_ROLE, int( tblRow->checkState( NAME_COL )));
1021
1022     int c = tblRow->checkState( NAME_COL ) ? 0 : 150;
1023     tblRow->setForeground( VALUE_COL, QBrush( QColor( c, c, c )));
1024
1025     if ( column == NAME_COL && tblRow->data( NAME_COL, EDITABLE_ROLE ).toInt() ) // custom table
1026     {
1027       tblRow->setData( NAME_COL, PARAM_NAME, tblRow->text( NAME_COL ));
1028     }
1029
1030     myOptionTable->blockSignals( false );
1031   }
1032 }
1033 void MgAdaptAdvWidget::setupWidget()
1034 {
1035   if (this->objectName().isEmpty())
1036       this->setObjectName(QString(tr("MG-ADAPT-ADV")));
1037   this->resize(337, 369);
1038   gridLayout_4 = new QGridLayout(this);
1039   gridLayout_4->setObjectName(QString("gridLayout_4"));
1040   myOptionTable = new MgAdaptAdvWidgetTreeWidget(this);
1041   QFont font;
1042   font.setBold(false);
1043   font.setWeight(50);
1044   QTreeWidgetItem *__qtreewidgetitem = new QTreeWidgetItem();
1045   __qtreewidgetitem->setFont(1, font);
1046   __qtreewidgetitem->setFont(0, font);
1047   __qtreewidgetitem->setText(1, tr("OPTION_VALUE_COLUMN"));
1048   __qtreewidgetitem->setText(0, tr("OPTION_NAME_COLUMN"));
1049   myOptionTable->setHeaderItem(__qtreewidgetitem);
1050   myOptionTable->setObjectName(QString("myOptionTable"));
1051   myOptionTable->setEditTriggers(QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed);
1052   myOptionTable->setTabKeyNavigation(true);
1053
1054   gridLayout_4->addWidget(myOptionTable, 0, 0, 1, 2);
1055
1056   addBtn = new QPushButton(this);
1057   addBtn->setObjectName(QString("addBtn"));
1058
1059   gridLayout_4->addWidget(addBtn, 1, 0, 1, 1);
1060
1061   horizontalSpacer = new QSpacerItem(188, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
1062
1063   gridLayout_4->addItem(horizontalSpacer, 1, 1, 1, 1);
1064
1065   logGroupBox = new QGroupBox(this);
1066   logGroupBox->setObjectName(QString("logGroupBox"));
1067   gridLayout_2 = new QGridLayout(logGroupBox);
1068   gridLayout_2->setObjectName(QString("gridLayout_2"));
1069   gridLayout = new QGridLayout();
1070   gridLayout->setObjectName(QString("gridLayout"));
1071   workingDirectoryLabel = new QLabel(logGroupBox);
1072   workingDirectoryLabel->setObjectName(QString("workingDirectoryLabel"));
1073
1074   gridLayout->addWidget(workingDirectoryLabel, 0, 0, 1, 1);
1075
1076   workingDirectoryLineEdit = new QLineEdit(logGroupBox);
1077   workingDirectoryLineEdit->setObjectName(QString("workingDirectoryLineEdit"));
1078
1079   gridLayout->addWidget(workingDirectoryLineEdit, 0, 1, 1, 1);
1080
1081   workingDirectoryPushButton = new QPushButton(logGroupBox);
1082   workingDirectoryPushButton->setObjectName(QString("workingDirectoryPushButton"));
1083
1084   gridLayout->addWidget(workingDirectoryPushButton, 0, 2, 1, 1);
1085
1086   verboseLevelLabel = new QLabel(logGroupBox);
1087   verboseLevelLabel->setObjectName(QString("verboseLevelLabel"));
1088
1089   gridLayout->addWidget(verboseLevelLabel, 1, 0, 1, 1);
1090
1091   verboseLevelSpin = new QSpinBox(logGroupBox);
1092   verboseLevelSpin->setObjectName(QString("verboseLevelSpin"));
1093
1094   gridLayout->addWidget(verboseLevelSpin, 1, 1, 1, 1);
1095
1096
1097   gridLayout_2->addLayout(gridLayout, 0, 0, 1, 1);
1098
1099   horizontalLayout = new QHBoxLayout();
1100   horizontalLayout->setObjectName(QString("horizontalLayout"));
1101   logInFileCheck = new QCheckBox(logGroupBox);
1102   logInFileCheck->setObjectName(QString("logInFileCheck"));
1103   logInFileCheck->setChecked(true);
1104
1105   horizontalLayout->addWidget(logInFileCheck);
1106
1107   removeLogOnSuccessCheck = new QCheckBox(logGroupBox);
1108   removeLogOnSuccessCheck->setObjectName(QString("removeLogOnSuccessCheck"));
1109   removeLogOnSuccessCheck->setChecked(true);
1110
1111   horizontalLayout->addWidget(removeLogOnSuccessCheck);
1112
1113
1114   gridLayout_2->addLayout(horizontalLayout, 1, 0, 1, 1);
1115
1116   keepWorkingFilesCheck = new QCheckBox(logGroupBox);
1117   keepWorkingFilesCheck->setObjectName(QString("keepWorkingFilesCheck"));
1118   keepWorkingFilesCheck->setAutoExclusive(false);
1119
1120   gridLayout_2->addWidget(keepWorkingFilesCheck, 2, 0, 1, 1);
1121
1122
1123   gridLayout_4->addWidget(logGroupBox, 3, 0, 1, 2);
1124
1125 }
1126 void MgAdaptAdvWidget::_onWorkingDirectoryPushButton()
1127 {
1128   QString aDirName=QFileDialog::getExistingDirectory ();
1129   if (!(aDirName.isEmpty()))workingDirectoryLineEdit->setText(aDirName);
1130 }
1131 void MgAdaptAdvWidget::onMeshDimChanged(ADAPTATION_MODE aMode)
1132 {
1133 /* default adaptation mode
1134   * assume that if meshDim == 2 -->adaptation surface
1135   * if meshDim == 3 and  if there is not 2D mesh -->VOLUME
1136   * else BOTH
1137   */
1138
1139   QString adaptation("adaptation"), value;
1140   switch(aMode)
1141   {
1142     case ADAPTATION_MODE::SURFACE:
1143     {
1144       value ="surface";
1145       setOptionValue(adaptation, value);
1146       break;
1147     }
1148     case ADAPTATION_MODE::BOTH :
1149     {
1150       value = "both";
1151       setOptionValue(adaptation, value);
1152       break;
1153     }
1154     case ADAPTATION_MODE::VOLUME :
1155     {
1156       value = "volume";
1157       setOptionValue(adaptation, value);
1158       break;
1159     }
1160   }
1161 }
1162 void MgAdaptAdvWidget::setOptionValue(QString& option, QString& value)
1163 {
1164   std::map<QString, QTreeWidgetItem *>::iterator it = optionTreeWidgetItem.find(option);
1165   if (it != optionTreeWidgetItem.end())
1166   {
1167     it->second->setText( 0, tr( option.toLatin1().constData() ));
1168     it->second->setText( 1, tr( value.toLatin1().constData() ));
1169     it->second->setCheckState( 0,  Qt::Checked );
1170     it->second->setData( NAME_COL, PARAM_NAME, option );
1171     myOptionTable->editItem( it->second, NAME_COL );
1172   }
1173 }
1174 namespace
1175 {
1176 bool isEditable( const QModelIndex& index )
1177 {
1178   return index.isValid() &&
1179           index.flags() & Qt::ItemIsEditable &&
1180           index.flags() & Qt::ItemIsEnabled &&
1181           ( !index.data( Qt::UserRole + 1 ).isValid() || index.data( Qt::UserRole + 1 ).toInt() != 0 );
1182 }
1183 }
1184
1185 MgAdaptAdvWidgetTreeWidget::MgAdaptAdvWidgetTreeWidget( QWidget* parent )
1186     : QTreeWidget( parent )
1187 {
1188 }
1189
1190 QModelIndex MgAdaptAdvWidgetTreeWidget::moveCursor( CursorAction action, Qt::KeyboardModifiers modifiers )
1191 {
1192   QModelIndex current = currentIndex();
1193   int column = current.column();
1194   if ( action == MoveNext )
1195   {
1196     if ( column < columnCount()-1 )
1197     {
1198       QModelIndex next = current.sibling( current.row(), column+1 );
1199       if ( isEditable( next ) ) return next;
1200     }
1201     else
1202     {
1203       QModelIndex next = current.sibling( current.row()+1, 0 );
1204       if ( isEditable( next ) ) return next;
1205     }
1206   }
1207   else if ( action == MovePrevious )
1208   {
1209     if ( column == 0 ) {
1210       QModelIndex next = current.sibling( current.row()-1, columnCount()-1 );
1211       if ( isEditable( next ) ) return next;
1212     }
1213     else {
1214       QModelIndex next = current.sibling( current.row(), column-1 );
1215        if ( isEditable( next ) ) return next;
1216     }
1217   }
1218   return QTreeWidget::moveCursor( action, modifiers );
1219 }
1220
1221 void MgAdaptAdvWidgetTreeWidget::keyPressEvent( QKeyEvent* e )
1222 {
1223   switch ( e->key() )
1224   {
1225     case Qt::Key_F2:
1226     {
1227       QModelIndex index = currentIndex();
1228       if ( !isEditable( index ) ) {
1229         for ( int i = 0; i < columnCount(); i++ ) {
1230           QModelIndex sibling = index.sibling( index.row(), i );
1231           if ( isEditable( sibling ) ) {
1232             if ( !edit( sibling, EditKeyPressed, e ) ) e->ignore();
1233           }
1234         }
1235       }
1236     }
1237     break;
1238     default:
1239       break;
1240   }
1241   QTreeWidget::keyPressEvent( e );
1242 }
1243
1244
1245 // =======================================================================
1246 // renvoie le medId associe au fichier Med apres ouverture
1247 // =======================================================================
1248 med_idt OuvrirFichier(QString aFile)
1249 {
1250   med_idt medIdt = MEDfileOpen(aFile.toStdString().c_str(),MED_ACC_RDONLY);
1251   if (medIdt <0)
1252   {
1253     QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
1254                               QObject::tr("MG_ADAPT_MED_FILE_1") );
1255   }
1256   return medIdt;
1257 }
1258
1259 // ======================================================
1260 // ========================================================
1261 QString lireNomMaillage(QString aFile, med_int& meshdim)
1262 {
1263   QString nomMaillage = QString::null ;
1264   int erreur = 0 ;
1265   med_idt medIdt ;
1266
1267   //  Ouverture du fichier
1268   medIdt = OuvrirFichier(aFile);
1269   if ( medIdt < 0 )
1270   {
1271     erreur = 1 ;
1272     return nomMaillage;
1273   }
1274   med_int numberOfMeshes = MEDnMesh(medIdt) ;
1275   if (numberOfMeshes == 0 )
1276   {
1277     QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
1278                               QObject::tr("MG_ADAPT_MED_FILE_2") );
1279     erreur = 2 ;
1280     return nomMaillage;
1281   }
1282   if (numberOfMeshes > 1 )
1283   {
1284     QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
1285                               QObject::tr("MG_ADAPT_MED_FILE_3") );
1286     erreur = 3 ;
1287     return nomMaillage;
1288   }
1289
1290   nomMaillage = lireNomMaillage2(medIdt,1, meshdim);
1291   // Fermeture du fichier
1292   if ( medIdt > 0 ) MEDfileClose(medIdt);
1293
1294   return nomMaillage;
1295 }
1296
1297 // =======================================================================
1298 // =======================================================================
1299 QString lireNomMaillage2(med_idt medIdt,int meshId, med_int& meshdim )
1300 {
1301   QString NomMaillage=QString::null;
1302   char meshname[MED_NAME_SIZE+1];
1303   med_int spacedim;
1304   med_mesh_type meshtype;
1305   char descriptionription[MED_COMMENT_SIZE+1];
1306   char dtunit[MED_SNAME_SIZE+1];
1307   med_sorting_type sortingtype;
1308   med_int nstep;
1309   med_axis_type axistype;
1310   int naxis = MEDmeshnAxis(medIdt,1);
1311   char *axisname=new char[naxis*MED_SNAME_SIZE+1];
1312   char *axisunit=new char[naxis*MED_SNAME_SIZE+1];
1313   med_err aRet = MEDmeshInfo(medIdt,
1314                               meshId,
1315                               meshname,
1316                               &spacedim,
1317                               &meshdim,
1318                               &meshtype,
1319                               descriptionription,
1320                               dtunit,
1321                               &sortingtype,
1322                               &nstep,
1323                               &axistype,
1324                               axisname,
1325                               axisunit);
1326
1327   if ( aRet < 0 ) {
1328     QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"), \
1329                               QObject::tr("MG_ADAPT_MED_FILE_4") );
1330   }
1331   else            {
1332     NomMaillage=QString(meshname);
1333   }
1334
1335   delete[] axisname ;
1336   delete[] axisunit ;
1337
1338   return NomMaillage;
1339 }
1340
1341 // =======================================================================
1342 std::map<QString, int> GetListeChamps(QString aFile, bool errorMessage)
1343 // =======================================================================
1344 {
1345 // Il faut voir si plusieurs maillages
1346
1347   MESSAGE("GetListeChamps");
1348   std::map<QString, int> ListeChamp ;
1349
1350   med_err erreur = 0 ;
1351   med_idt medIdt ;
1352
1353   while ( erreur == 0 )
1354   {
1355     // Ouverture du fichier
1356     SCRUTE(aFile.toStdString());
1357     medIdt = OuvrirFichier(aFile);
1358     if ( medIdt < 0 )
1359     {
1360       erreur = 1 ;
1361       break ;
1362     }
1363     // Lecture du nombre de champs
1364     med_int ncha = MEDnField(medIdt) ;
1365     if (ncha < 1 )
1366     {
1367       if(errorMessage)
1368       {
1369         QMessageBox::critical( 0, QObject::tr("_ERROR"),
1370                                   QObject::tr("HOM_MED_FILE_5") );
1371       }
1372       erreur = 2 ;
1373       break ;
1374     }
1375     // Lecture des caracteristiques des champs
1376     for (int i=0; i< ncha; i++)
1377     {
1378 //       Lecture du nombre de composantes
1379       med_int ncomp = MEDfieldnComponent(medIdt,i+1);
1380 //       Lecture du type du champ, des noms des composantes et du nom de l'unite
1381       char nomcha  [MED_NAME_SIZE+1];
1382       char meshname[MED_NAME_SIZE+1];
1383       char * comp = (char*) malloc(ncomp*MED_SNAME_SIZE+1);
1384       char * unit = (char*) malloc(ncomp*MED_SNAME_SIZE+1);
1385       char dtunit[MED_SNAME_SIZE+1];
1386       med_bool local;
1387       med_field_type typcha;
1388       med_int nbofcstp;
1389       erreur = MEDfieldInfo(medIdt,i+1,nomcha,meshname,&local,&typcha,comp,unit,dtunit,&nbofcstp) ;
1390       free(comp);
1391       free(unit);
1392       if ( erreur < 0 )
1393       {
1394         if(errorMessage)
1395         {
1396           QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
1397                                     QObject::tr("MG_ADAPT_MED_FILE_6") );
1398         }
1399         break ;
1400       }
1401
1402       ListeChamp.insert(std::pair<QString, int> (QString(nomcha), nbofcstp));
1403
1404     }
1405     break ;
1406   }
1407     // Fermeture du fichier
1408   if ( medIdt > 0 ) MEDfileClose(medIdt);
1409
1410   return ListeChamp;
1411 }
1412
1413 std::string remove_extension(const std::string& filename)
1414 {
1415   size_t lastdot = filename.find_last_of(".");
1416   if (lastdot == std::string::npos) return filename;
1417   return filename.substr(0, lastdot);
1418 }
1419