1 // Copyright (C) 2007-2020 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // file : MG_ADAPTGUI.cxx
24 #include "MG_ADAPTGUI.hxx"
26 #include "MEDFileData.hxx"
27 #include "MEDLoader.hxx"
29 #include "SUIT_Desktop.h"
30 #include "SUIT_Application.h"
31 #include "SUIT_Session.h"
33 #include "SalomeApp_Application.h"
34 #include "SalomeApp_Module.h"
35 #include "SalomeApp_Study.h"
36 #include <SUIT_MessageBox.h>
37 #include <LightApp_SelectionMgr.h>
38 #include <SUIT_OverrideCursor.h>
39 #include <SUIT_ResourceMgr.h>
40 #include <SVTK_ViewWindow.h>
41 #include <SALOME_ListIO.hxx>
42 #include <SUIT_FileDlg.h>
43 #include <QApplication>
44 #include <QButtonGroup>
45 #include <QGridLayout>
47 #include <QHBoxLayout>
52 #include <QPushButton>
53 #include <QRadioButton>
55 #include <QVBoxLayout>
56 #include <QDoubleSpinBox>
58 #include <QTreeWidget>
59 #include <QTreeWidgetItem>
60 #include <QSpacerItem>
62 #include <QHeaderView>
63 #include <QItemDelegate>
64 #include <QFileDialog>
65 #include <QMessageBox>
68 #include <vtkPoints.h>
69 #include <vtkUnstructuredGrid.h>
70 #include <vtkIdList.h>
71 #include <vtkCellArray.h>
72 #include <vtkUnsignedCharArray.h>
73 #include <vtkDataSetMapper.h>
74 #include <VTKViewer_CellLocationsArray.h>
75 #include <vtkProperty.h>
78 // SALOME KERNEL includes
79 #include <SALOMEDS_SComponent.hxx>
80 #include <SALOMEDS_SObject.hxx>
81 #include <SALOMEDS_Study.hxx>
82 #include <SALOMEDS_wrap.hxx>
83 #include "SalomeApp_Tools.h"
84 #include <SALOMEconfig.h>
86 #include <utilities.h>
88 #include <TCollection_AsciiString.hxx>
90 const int SPACING = 6; // layout spacing
91 const int MARGIN = 9; // layout margin
93 //=================================================================================
94 // function : SMESHGUI_MgAdaptDlg()
96 //=================================================================================
97 SMESHGUI_MgAdaptDlg::SMESHGUI_MgAdaptDlg( SalomeApp_Module* theModule, SMESH::MG_ADAPT_ptr myModel, QWidget* parent, bool isCreation )
98 : mySMESHGUI( theModule ), QDialog(parent)
100 //~model = new MgAdapt(*myModel);
101 model = SMESH::MG_ADAPT::_duplicate(myModel);
102 myData = model->getData();
104 if (!isCreation) readParamsFromHypo();
107 void SMESHGUI_MgAdaptDlg::buildDlg()
110 setAttribute( Qt::WA_DeleteOnClose, true );
111 setWindowTitle( tr( "ADAPT_PREF_MG_ADAPT" ) );
112 setSizeGripEnabled( true );
114 myTabWidget = new QTabWidget( this );
118 myArgs = new SMESHGUI_MgAdaptArguments( myTabWidget );
119 SMESH::str_array* str = model->getOptionValuesStrVec();
120 SMESH::str_array* str2 = model->getCustomOptionValuesStrVec();
121 std::vector<std::string> s;
122 for (int i = 0; i< str->length(); i++) s.push_back( (*str)[i].in());
123 for (int j = str->length(); j< str2->length(); j++) s.push_back((*str2)[ j - str->length() ].in() );
124 //~str.insert( str.end(), str2.begin(), str2.end() );
126 myAdvOpt = new MgAdaptAdvWidget(myTabWidget, &s);
128 int argsTab = myTabWidget->addTab( myArgs, tr( "Args" ) );
129 int advTab = myTabWidget->addTab( myAdvOpt, tr( "ADVOP" ) );
131 myAdvOpt->workingDirectoryLabel ->setText (tr( "WORKING_DIR" ));
132 myAdvOpt->workingDirectoryPushButton ->setText (tr( "SELECT_DIR" ));
133 myAdvOpt->keepWorkingFilesCheck ->setText (tr( "KEEP_WORKING_FILES" ));
134 myAdvOpt->verboseLevelLabel ->setText (tr( "VERBOSE_LEVEL" ));
135 myAdvOpt->removeLogOnSuccessCheck ->setText (tr( "REMOVE_LOG_ON_SUCCESS" ));
136 myAdvOpt->logInFileCheck ->setText (tr( "LOG_IN_FILE" ));
137 myAdvOpt->logGroupBox ->setTitle(tr( "LOG_GROUP_TITLE" ));
140 QPushButton* buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), this);
141 buttonOk->setAutoDefault(false);
142 QPushButton* buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), this);
143 buttonApply->setAutoDefault(false);
144 QPushButton* buttonCancel = new QPushButton( tr( "SMESH_BUT_CANCEL" ), this );
145 buttonCancel->setAutoDefault( false );
146 QPushButton* buttonHelp = new QPushButton( tr( "SMESH_BUT_HELP" ), this );
147 buttonHelp->setAutoDefault( false );
149 QHBoxLayout* btnLayout = new QHBoxLayout;
150 btnLayout->setSpacing( SPACING );
151 btnLayout->setMargin( 0 );
152 btnLayout->addWidget( buttonOk );
153 btnLayout->addStretch( 10 );
154 btnLayout->addWidget( buttonApply );
155 btnLayout->addStretch( 10 );
156 btnLayout->addWidget( buttonCancel );
157 btnLayout->addStretch( 10 );
158 btnLayout->addWidget( buttonHelp );
160 QVBoxLayout* l = new QVBoxLayout ( this );
161 l->setMargin( MARGIN );
162 l->setSpacing( SPACING );
163 l->addWidget( myTabWidget );
165 l->addLayout( btnLayout );
167 connect( buttonOk, SIGNAL(pressed()), this, SLOT(PushOnOK()));
168 connect( buttonApply, SIGNAL(pressed()), this, SLOT(PushOnApply()));
169 connect( buttonCancel, SIGNAL(pressed()), this, SLOT(close()));
170 connect( buttonHelp, SIGNAL(pressed()), this, SLOT(PushOnHelp()));
172 connect( myArgs, SIGNAL(meshDimSignal(ADAPTATION_MODE)), myAdvOpt, SLOT( onMeshDimChanged(ADAPTATION_MODE)) );
176 //=================================================================================
177 // function : ~SMESHGUI_MgAdaptDlg()
178 // purpose : Destroys the object and frees any allocated resources
179 //=================================================================================
180 SMESHGUI_MgAdaptDlg::~SMESHGUI_MgAdaptDlg()
185 //~void SMESHGUI_MgAdaptDlg::setModel(MgAdapt* mg)
189 SMESH::MG_ADAPT_ptr SMESHGUI_MgAdaptDlg::getModel() const
194 \brief Perform clean-up actions on the dialog box closing.
196 bool SMESHGUI_MgAdaptDlg::PushOnApply()
198 bool ret = readParamsFromWidgets();
201 void SMESHGUI_MgAdaptDlg::PushOnOK()
203 bool ret = PushOnApply();
206 void SMESHGUI_MgAdaptDlg::reject()
210 bool SMESHGUI_MgAdaptDlg::readParamsFromHypo( ) const
213 myArgs->aMedfile->setChecked(myData->fromMedFile) ;
214 if (myData->fromMedFile)
217 *(myArgs->myFileInDir) = QString(myData->myFileInDir) ;
218 myArgs->selectMedFileLineEdit->setText(QString(myData->myMeshFileIn)) ;
219 // myData->myInMeshName = // TODO
224 myArgs->aBrowserObject->setText(QString(myData->myInMeshName));
225 //~ myArgs->myFileInDir =""; // TODO
226 //~ myArgs->selectMedFileLineEdit->setText(); // TODO
228 myArgs->meshNameLineEdit->setText(QString(myData->myOutMeshName));
229 myArgs->medFileCheckBox->setChecked(myData->myMeshOutMed);
231 if(myData->myMeshOutMed)
233 *(myArgs->myFileOutDir) = QString(myData->myFileOutDir);
234 myArgs->selectOutMedFileLineEdit->setText(QString(myData->myMeshFileOut));
238 *(myArgs->myFileOutDir) = QString(""); //TODO
241 myArgs->publishOut->setChecked(myData->myPublish);
243 myArgs->localButton->setChecked(myData->myUseLocalMap);
244 myArgs->backgroundButton->setChecked(myData->myUseBackgroundMap);
245 myArgs->constantButton->setChecked(myData->myUseConstantValue);
247 if (myData->myUseConstantValue)
249 myArgs->dvalue->setValue(myData->myConstantValue);
253 myArgs->dvalue->setValue(0.0);
256 if (myData->myUseBackgroundMap)
259 *(myArgs->myFileSizeMapDir) = QString(myData->myFileSizeMapDir) ;
260 myArgs->selectMedFileBackgroundLineEdit->setText(QString(myData->myMeshFileBackground));
264 *(myArgs->myFileSizeMapDir) = QString("") ; //TODO
265 myArgs->selectMedFileBackgroundLineEdit->setText(""); //TODO
268 myArgs->fieldNameCmb->setCurrentText(QString(myData->myFieldName));
269 myArgs->noTimeStep->setChecked(myData->myUseNoTimeStep);
270 myArgs->lastTimeStep->setChecked( myData->myUseLastTimeStep);
271 myArgs->chosenTimeStep->setChecked(myData->myUseChosenTimeStep);
272 if (myData->myUseChosenTimeStep)
274 myArgs->rankSpinBox->setValue(myData->myRank);
275 myArgs->timeStep->setValue(myData->myTimeStep);
278 myAdvOpt->workingDirectoryLineEdit->setText(QString(myData->myWorkingDir));
279 myAdvOpt->logInFileCheck->setChecked(myData->myPrintLogInFile);
281 myAdvOpt->verboseLevelSpin->setValue(myData->myVerboseLevel);
282 myAdvOpt->removeLogOnSuccessCheck->setChecked(myData->myRemoveLogOnSuccess);
283 myAdvOpt->keepWorkingFilesCheck->setChecked(myData->myKeepFiles);
289 bool SMESHGUI_MgAdaptDlg::readParamsFromWidgets()
291 MESSAGE ("readParamsFromWidgets") ;
293 SMESH::MgAdaptHypothesisData* aData = new SMESH::MgAdaptHypothesisData();
296 // 1. Fichier du maillage de départ
297 aData->fromMedFile = myArgs->aMedfile->isChecked();
298 if (aData->fromMedFile)
300 aData->myFileInDir = CORBA::string_dup(myArgs->myFileInDir->toStdString().c_str());
301 aData->myMeshFileIn = CORBA::string_dup(myArgs->selectMedFileLineEdit->text().toStdString().c_str());
302 // aData->myInMeshName = // TODO
306 QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
307 QObject::tr("MG_ADAPT_MED_FILE_4") );
310 // aData->myInMeshName = CORBA::string_dup(myArgs->aBrowserObject->text().toStdString().c_str());
311 // aData->myFileInDir = CORBA::string_dup(myAdvOpt->workingDirectoryLineEdit->text().toStdString().c_str());
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();
323 // 2. Fichier du maillage de sortie
324 aData->myOutMeshName = CORBA::string_dup(myArgs->meshNameLineEdit->text().toStdString().c_str());
325 aData->myMeshOutMed = myArgs->medFileCheckBox->isChecked();
326 if(aData->myMeshOutMed)
328 aData->myFileOutDir = CORBA::string_dup(myArgs->myFileOutDir->toStdString().c_str());
329 aData->myMeshFileOut = CORBA::string_dup(myArgs->selectOutMedFileLineEdit->text().toStdString().c_str());
333 aData->myMeshFileOut = "";
335 aData->myPublish = myArgs->publishOut->isChecked();
337 // 3. Type de carte de tailles
338 aData->myUseLocalMap = myArgs->localButton->isChecked();
339 aData->myUseBackgroundMap = myArgs->backgroundButton->isChecked();
340 aData->myUseConstantValue = myArgs->constantButton->isChecked();
342 if (aData->myUseConstantValue)
344 aData->myConstantValue = myArgs->dvalue->value();
348 aData->myConstantValue = 0.0;
351 if (aData->myUseBackgroundMap)
353 aData->myFileSizeMapDir = CORBA::string_dup(myArgs->myFileSizeMapDir->toStdString().c_str());
354 aData->myMeshFileBackground = CORBA::string_dup(myArgs->selectMedFileBackgroundLineEdit->text().toStdString().c_str());
358 aData->myMeshFileBackground = "";
362 if ( ! aData->myUseConstantValue )
364 if ( strlen(myArgs->fieldNameCmb->currentText().toStdString().c_str()) == 0 )
366 QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
367 QObject::tr("MG_ADAPT_MED_FILE_5") );
372 aData->myFieldName = CORBA::string_dup(myArgs->fieldNameCmb->currentText().toStdString().c_str());
373 aData->myUseNoTimeStep = myArgs->noTimeStep->isChecked();
374 aData->myUseLastTimeStep = myArgs->lastTimeStep->isChecked();
375 aData->myUseChosenTimeStep = myArgs->chosenTimeStep->isChecked();
376 if (aData->myUseChosenTimeStep)
378 aData->myRank = myArgs->rankSpinBox->value();
379 aData->myTimeStep = myArgs->timeStep->value();
384 // 5. Options avancées
385 aData->myWorkingDir = CORBA::string_dup(myAdvOpt->workingDirectoryLineEdit->text().toStdString().c_str());
386 aData->myPrintLogInFile = myAdvOpt->logInFileCheck->isChecked();
387 aData->myVerboseLevel = myAdvOpt->verboseLevelSpin->value();
388 aData->myRemoveLogOnSuccess = myAdvOpt->removeLogOnSuccessCheck->isChecked();
389 aData->myKeepFiles = myAdvOpt->keepWorkingFilesCheck->isChecked();
390 model->setData(*aData);
401 bool SMESHGUI_MgAdaptDlg::storeParamsToHypo( const SMESH::MgAdaptHypothesisData& ) const
405 \brief Show help page
407 void SMESHGUI_MgAdaptDlg::PushOnHelp()
409 // QString aHelpFile;
410 // if ( myTabWidget->currentIndex() == MinDistance ) {
411 // aHelpFile = "measurements.html#min-distance-anchor";
412 // } else if ( myTabWidget->currentIndex() == BoundingBox ) {
413 // aHelpFile = "measurements.html#bounding-box-anchor";
414 // } else if ( myTabWidget->currentWidget() == myAngle ) {
415 // aHelpFile = "measurements.html#angle-anchor";
417 // aHelpFile = "measurements.html#basic-properties-anchor";
420 // SMESH::ShowHelpFile( aHelpFile );
422 bool SMESHGUI_MgAdaptDlg::checkParams(QString& msg)
424 if ( !QFileInfo( myAdvOpt->workingDirectoryLineEdit->text().trimmed() ).isWritable() )
426 SUIT_MessageBox::warning( this,
427 tr( "SMESH_WRN_WARNING" ),
428 tr( "NO_PERMISSION" ) );
433 myAdvOpt->myOptionTable->setFocus();
434 QApplication::instance()->processEvents();
437 bool isDefault, ok = true;
438 int iRow = 0, nbRows = myAdvOpt->myOptionTable->topLevelItemCount();
439 for ( ; iRow < nbRows; ++iRow )
441 QTreeWidgetItem* row = myAdvOpt->myOptionTable->topLevelItem( iRow );
442 myAdvOpt->GetOptionAndValue( row, name, value, isDefault );
444 if ( name.simplified().isEmpty() )
445 continue; // invalid custom option
447 if ( isDefault ) // not selected option
452 model->setOptionValue( name.toLatin1().constData(), value.toLatin1().constData() );
454 catch ( const SALOME::SALOME_Exception& ex )
456 msg = ex.details.text.in();
465 //=================================================================================
466 // function : SMESHGUI_MgAdaptArguments()
468 //=================================================================================
469 SMESHGUI_MgAdaptArguments::SMESHGUI_MgAdaptArguments( QWidget* parent )
473 myFileInDir = new QString("");
474 myFileOutDir = new QString("");
475 myFileSizeMapDir = new QString("");
476 if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
478 *myFileInDir = QDir::currentPath();
479 *myFileOutDir = QDir::currentPath();
480 *myFileSizeMapDir = QDir::currentPath();
484 *myFileInDir = SUIT_FileDlg::getLastVisitedPath();
485 *myFileOutDir = SUIT_FileDlg::getLastVisitedPath();
486 *myFileSizeMapDir = SUIT_FileDlg::getLastVisitedPath();
492 aMeshIn = new QGroupBox( tr( "MeshIn" ), this );
493 aMedfile = new QRadioButton( tr( "MEDFile" ), aMeshIn );
494 aBrowser = new QRadioButton( tr( "Browser" ), aMeshIn );
495 aBrowserObject = new QLineEdit( aMeshIn );
496 selectMedFilebutton = new QPushButton("", aMeshIn);
497 selectMedFileLineEdit = new QLineEdit( aMeshIn );
499 meshIn = new QGridLayout( aMeshIn );
501 meshIn->setMargin( MARGIN );
502 meshIn->setSpacing( SPACING );
503 meshIn->addWidget( aMedfile, 0, 0, 1,1 );
504 meshIn->addWidget( aBrowser, 0, 1,1,1);
505 meshIn->addWidget( aBrowserObject, 0, 2, 1, 1 );
506 meshIn->addWidget( selectMedFilebutton, 1, 0,1, 1);
507 meshIn->addWidget( selectMedFileLineEdit, 1, 1, 1, 1 );
508 hspacer = new QSpacerItem(188, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
510 meshInGroup = new QButtonGroup( this );
511 meshInGroup->addButton( aMedfile, 0 );
512 meshInGroup->addButton( aBrowser, 1 );
516 aMeshOut = new QGroupBox( tr( "MeshOut" ), this );
517 meshName = new QLabel(tr("MeshName"), aMeshOut);
518 secondHspacer = new QSpacerItem(100, 30);
519 meshNameLineEdit = new QLineEdit(aMeshOut) ;
520 medFileCheckBox = new QCheckBox(tr("MEDFile"), aMeshOut);
521 selectOutMedFilebutton = new QPushButton("", aMeshOut);
522 thirdHspacer = new QSpacerItem(188, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
523 selectOutMedFileLineEdit = new QLineEdit(aMeshOut) ;
524 publishOut = new QCheckBox(tr("Publish_MG_ADAPT"), aMeshOut);
526 meshOut = new QGridLayout( aMeshOut );
528 meshOut->setMargin( MARGIN );
529 meshOut->setSpacing( SPACING );
530 meshOut->addWidget( meshName, 0, 0, 1,1 );
531 meshOut->addItem( secondHspacer, 0, 1, 1, 1 );
532 meshOut->addWidget( meshNameLineEdit, 0, 2,1,1);
533 meshOut->addWidget( medFileCheckBox, 1, 0,1,1 );
534 meshOut->addWidget( selectOutMedFilebutton, 1, 1,1,1 );
535 meshOut->addWidget( selectOutMedFileLineEdit, 1, 2,1,1);
536 meshOut->addWidget( publishOut, 2, 0,1,1 );
538 //size map definition
540 sizeMapDefinition = new QGroupBox(tr("SIZE_MAP_DEF"), this);
541 localButton = new QRadioButton(tr("LOCAL_MG_ADAPT"), sizeMapDefinition);
542 backgroundButton = new QRadioButton(tr("BACKGRND_MG_ADAPT"), sizeMapDefinition);
543 constantButton = new QRadioButton(tr("CNST_MG_ADAPT"), sizeMapDefinition);
544 medFileBackground = new QLabel(tr("MED_FILE_BCKG"), sizeMapDefinition);
545 selectMedFileBackgroundbutton = new QPushButton(tr(""), sizeMapDefinition);
546 selectMedFileBackgroundLineEdit = new QLineEdit(sizeMapDefinition);
547 valueLabel = new QLabel(tr("VALUE_MG_ADAPT"), sizeMapDefinition);
548 dvalue = new QDoubleSpinBox(sizeMapDefinition);
549 sizeMapDefGroup = new QButtonGroup( this );
550 sizeMapDefGroup->addButton( localButton, 0 );
551 sizeMapDefGroup->addButton( backgroundButton, 1 );
552 sizeMapDefGroup->addButton( constantButton, 2 );
554 sizeMapDefGroupLayout = new QGridLayout(sizeMapDefinition);
555 sizeMapDefGroupLayout->addWidget(localButton, 0,0);
556 sizeMapDefGroupLayout->addWidget(backgroundButton, 0,1);
557 sizeMapDefGroupLayout->addWidget(constantButton, 0,2);
558 sizeMapDefGroupLayout->addWidget(medFileBackground, 1,0);
559 sizeMapDefGroupLayout->addWidget(selectMedFileBackgroundbutton, 1,1);
560 sizeMapDefGroupLayout->addWidget(selectMedFileBackgroundLineEdit, 1,2);
561 sizeMapDefGroupLayout->addWidget(valueLabel, 2,0);
562 sizeMapDefGroupLayout->addWidget(dvalue, 2,1);
565 sizeMapField = new QGroupBox(tr("SIZE_MAP_FIELD"), this);
566 fieldName = new QLabel(tr("MG_ADAPT_FIELD_NAME"), sizeMapField);
567 fieldNameCmb = new QComboBox(sizeMapField);
568 noTimeStep = new QRadioButton(tr("MG_ADAPT_NO_T_ST"), sizeMapField);
569 lastTimeStep = new QRadioButton(tr("MG_ADAPT_L_ST"), sizeMapField);
570 chosenTimeStep = new QRadioButton(tr("MG_ADAPT_CH_ST"), sizeMapField);
571 timeStepLabel = new QLabel(tr("MG_ADAPT_TSTP"), sizeMapField);
572 timeStep = new QSpinBox(sizeMapField);
573 timeStep->setMinimum(-1);
574 rankLabel = new QLabel(tr("MG_ADAPT_RANK"), sizeMapField);
575 rankSpinBox = new QSpinBox(sizeMapField);
576 rankSpinBox->setMinimum(-1);
578 timeStepGroup = new QButtonGroup(this);
579 timeStepGroup->addButton(noTimeStep, 0);
580 timeStepGroup->addButton(lastTimeStep, 1);
581 timeStepGroup->addButton(chosenTimeStep, 2);
583 sizeMapFieldGroupLayout = new QGridLayout(sizeMapField);
585 sizeMapFieldGroupLayout->addWidget(fieldName, 0,0);
586 sizeMapFieldGroupLayout->addWidget(fieldNameCmb, 0,1);
587 sizeMapFieldGroupLayout->addWidget(noTimeStep, 1,0);
588 sizeMapFieldGroupLayout->addWidget(lastTimeStep, 1,1);
589 sizeMapFieldGroupLayout->addWidget(chosenTimeStep, 1,2);
590 sizeMapFieldGroupLayout->addWidget(timeStepLabel, 2,0);
591 sizeMapFieldGroupLayout->addWidget(timeStep, 2,1);
592 sizeMapFieldGroupLayout->addWidget(rankLabel, 2,2);
593 sizeMapFieldGroupLayout->addWidget(rankSpinBox, 2,3);
595 QGridLayout* argumentsLayout = new QGridLayout( this );
596 argumentsLayout->setMargin( MARGIN );
597 argumentsLayout->setSpacing( SPACING );
599 argumentsLayout->addWidget( aMeshIn, 0, 0, 1, 3 );
600 argumentsLayout->addWidget( aMeshOut, 1, 0, 1, 3 );
601 argumentsLayout->addWidget( sizeMapDefinition, 2, 0, 1, 3 );
602 argumentsLayout->addWidget( sizeMapField, 3, 0, 1, 3 );
603 argumentsLayout->setColumnStretch( 1, 5 );
604 argumentsLayout->setRowStretch( 4, 5 );
607 setMode( Mesh, Local);
608 medFileCheckBox->setChecked(true);
609 visibleTimeStepRankLabel (false);
612 connect( meshInGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( modeChanged( int ) ) );
613 connect( sizeMapDefGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( sizeMapDefChanged( int ) ) );
614 connect( selectMedFilebutton, SIGNAL( pressed( ) ), this, SLOT( onSelectMedFilebuttonClicked( ) ) );
615 connect( medFileCheckBox, SIGNAL (stateChanged(int)), this, SLOT(onMedFileCheckBox(int) ) );
616 connect( publishOut, SIGNAL (stateChanged(int)), this, SLOT(onPublishOut(int) ) );
617 connect( selectOutMedFilebutton, SIGNAL( pressed()), this, SLOT(onSelectOutMedFilebutton()));
618 connect( selectMedFileBackgroundbutton, SIGNAL(pressed()), this, SLOT(onSelectMedFileBackgroundbutton()) );
619 connect( timeStepGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( timeStepGroupChanged( int ) ) );
620 emit updateSelection();
623 //=================================================================================
624 // function : ~SMESHGUI_MgAdaptArguments()
625 // purpose : Destroys the object and frees any allocated resources
626 //=================================================================================
627 SMESHGUI_MgAdaptArguments::~SMESHGUI_MgAdaptArguments()
631 void SMESHGUI_MgAdaptArguments::onNoTimeStep(bool disableOther)
633 noTimeStep->setChecked(true);
635 visibleTimeStepRankLabel (false);
636 rankSpinBox->setValue(-2);
637 timeStep->setValue(-2);
639 lastTimeStep->setDisabled(disableOther);
640 chosenTimeStep->setDisabled(disableOther);
642 void SMESHGUI_MgAdaptArguments::onLastTimeStep(bool disableOther)
644 lastTimeStep->setChecked(true);
646 visibleTimeStepRankLabel (false);
647 rankSpinBox->setValue(-1);
648 timeStep->setValue(-1);
649 noTimeStep->setDisabled(disableOther);
651 void SMESHGUI_MgAdaptArguments::onChosenTimeStep(bool disableOther, int vmax)
653 chosenTimeStep->setChecked(true);
655 visibleTimeStepRankLabel (true);
656 rankSpinBox->setValue(-1);
657 timeStep->setValue(-1);
658 if (vmax) timeStep->setMaximum(vmax);
661 void SMESHGUI_MgAdaptArguments::visibleTimeStepRankLabel(bool visible)
663 rankLabel->setVisible(visible);
664 rankSpinBox->setVisible(visible);
666 timeStepLabel->setVisible(visible);
667 timeStep->setVisible(visible);
670 void SMESHGUI_MgAdaptArguments::onSelectOutMedFilebutton()
673 QString filtre = QString("Med") ;
674 filtre += QString(" files (*.") + QString("med") + QString(");;");
675 QString fileName = QFileDialog::getSaveFileName(this, tr("SAVE_MED"), QString(""), filtre);
676 QFileInfo myFileInfo(fileName);
677 selectOutMedFileLineEdit->setText(myFileInfo.fileName());
678 *myFileOutDir = myFileInfo.path();
681 void SMESHGUI_MgAdaptArguments::onSelectMedFileBackgroundbutton()
683 QString fileName0 = selectMedFileBackgroundbutton->text().trimmed();
685 QString fileName = getMedFileName(false);
686 if (fileName != QString::null)
688 myFieldList = GetListeChamps(fileName);
689 if (myFieldList.empty())
691 fileName = fileName0;
692 fieldNameCmb->clear();
696 // fill field name Combobox
697 fieldNameCmb->clear();
698 std::map<QString, int>::const_iterator it;
699 for ( it=myFieldList.begin() ; it != myFieldList.end(); it++)
701 fieldNameCmb->insertItem(0,QString(it->first));
702 int typeStepInField = it->second > 2 ? 2 : it->second ;
703 timeStepGroupChanged(typeStepInField, false);
705 // Dimension du maillage de fonds
706 MEDCoupling::MCAuto<MEDCoupling::MEDFileData> mfd = MEDCoupling::MEDFileData::New(fileName.toStdString());
707 meshDimBG = mfd->getMeshes()->getMeshAtPos(0)->getMeshDimension() ;
713 fileName = fileName0;
714 fieldNameCmb->clear();
717 QFileInfo myFileInfo(fileName);
718 *myFileSizeMapDir = myFileInfo.path();
719 selectMedFileBackgroundLineEdit->setText(myFileInfo.fileName());
722 void SMESHGUI_MgAdaptArguments::onMedFileCheckBox(int state)
724 if (state == Qt::Checked)
726 selectOutMedFilebutton->show();
727 selectOutMedFileLineEdit->show();
728 selectOutMedFilebutton->setEnabled(true);
729 selectOutMedFileLineEdit->setEnabled(true);
733 selectOutMedFilebutton->setEnabled(false);
734 selectOutMedFileLineEdit->setEnabled(false);
735 publishOut->setChecked(true);
738 void SMESHGUI_MgAdaptArguments::onPublishOut(int state)
740 if (state == Qt::Unchecked)
742 medFileCheckBox->setChecked(true);
746 void SMESHGUI_MgAdaptArguments::onSelectMedFilebuttonClicked()
748 // bool keep = false;
749 QString fileName0 = selectMedFileLineEdit->text().trimmed();
751 QString fileName = getMedFileName(false);
752 if(fileName != QString::null)
754 QString aMeshName = lireNomMaillage(fileName.trimmed(), meshDim);
755 if (aMeshName == QString::null )
757 QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
758 QObject::tr("MG_ADAPT_MED_FILE_2") );
759 fileName = fileName0;
763 meshNameLineEdit->setText(aMeshName);
765 // ADAPTATION_MODE aMode = meshDim == 3 ? ADAPTATION_MODE::BOTH : ADAPTATION_MODE::SURFACE; // and when dimesh 3 without 2D mesh?
766 // emit meshDimSignal(aMode);
774 QFileInfo myFileInfo(fileName);
775 *myFileInDir = myFileInfo.path();
776 *myFileOutDir = myFileInfo.path();
777 selectMedFileLineEdit->setText(myFileInfo.fileName());
778 QString outF = fileName == QString::null ? myFileInfo.fileName() :
779 QString( remove_extension(myFileInfo.fileName().toStdString() ).c_str() )+ QString(".adapt.med");
780 selectOutMedFileLineEdit->setText(outF);
781 onLocalSelected(myFileInfo.filePath());
785 void SMESHGUI_MgAdaptArguments::valueAdaptation()
787 ADAPTATION_MODE aMode ;
790 aMode = meshDim == 3 ? ADAPTATION_MODE::BOTH : ADAPTATION_MODE::SURFACE;
794 aMode = ADAPTATION_MODE::BOTH;
796 emit meshDimSignal(aMode);
799 void SMESHGUI_MgAdaptArguments::onLocalSelected(QString filePath)
801 myFieldList = GetListeChamps(filePath, false);
802 if (myFieldList.empty())
804 if (localButton->isChecked())
806 fieldNameCmb->clear();
811 // fill field name Combobox
812 fieldNameCmb->clear();
813 std::map<QString, int>::const_iterator it;
814 for ( it = myFieldList.begin() ; it != myFieldList.end(); it++)
816 fieldNameCmb->insertItem(0,QString(it->first));
817 // Je ne comprends pas le rapport entre pas de temps et apparition d'un nouveau champ... GN
818 int typeStepInField = it->second > 2 ? 2 : it->second ;
819 // std::cout << "SMESHGUI_MgAdaptArguments::onLocalSelected typeStepInField : " << typeStepInField << std::endl;
820 timeStepGroupChanged(typeStepInField, false);
824 // =======================================================================
825 // Gestion les boutons qui permettent de
826 // 1) retourne le nom d'un fichier par une fenetre de dialogue si aucun
827 // objet est selectionne dans l arbre d etude
828 // 2) retourne le nom du fichier asocie a l objet
829 // selectionne dans l arbre d etude
830 // =======================================================================
831 QString SMESHGUI_MgAdaptArguments::getMedFileName(bool avertir)
834 QString aFile = QString::null;
835 QString filtre = QString("Med") ;
836 filtre += QString(" files (*.") + QString("med") + QString(");;");
837 aFile = SUIT_FileDlg::getOpenFileName(0, QObject::tr("MG_ADAPT_SELECT_FILE_0"), QString(""), filtre );
842 void SMESHGUI_MgAdaptArguments::setMode(const Mode theMode, const SIZEMAP theSizeMap )
844 QRadioButton* aButton = qobject_cast<QRadioButton*>( meshInGroup->button( theMode ) );
845 QRadioButton* bButton = qobject_cast<QRadioButton*>( sizeMapDefGroup->button( theSizeMap ) );
848 aButton->setChecked( true );
849 modeChanged( theMode );
853 bButton->setChecked( true );
854 sizeMapDefChanged( theSizeMap );
858 void SMESHGUI_MgAdaptArguments::modeChanged( int theMode )
863 aBrowserObject->hide();
864 selectMedFileLineEdit->show();
865 selectMedFilebutton->show();
866 localButton->setEnabled(true);
870 selectMedFileLineEdit->hide();
871 selectMedFilebutton->hide();
872 localButton->setEnabled(false);
873 aBrowserObject->show();
874 sizeMapDefChanged(Background);
875 emit updateSelection();
879 void SMESHGUI_MgAdaptArguments::sizeMapDefChanged( int theSizeMap )
881 fieldNameCmb->clear();
882 if(theSizeMap == Local)
884 localButton->setEnabled(true);
885 localButton->setChecked(true);
886 medFileBackground->hide();
887 selectMedFileBackgroundbutton->hide();
888 selectMedFileBackgroundLineEdit->hide();
889 selectMedFileBackgroundLineEdit->clear();
893 sizeMapField->setEnabled(true);
894 if (!selectMedFileLineEdit->text().isEmpty())
896 QFileInfo myFileInfo(QDir(*myFileInDir), selectMedFileLineEdit->text());
897 onLocalSelected(myFileInfo.filePath());
900 else if (theSizeMap == Background)
902 medFileBackground->show();
903 backgroundButton->setChecked(true);
904 selectMedFileBackgroundbutton->show();
905 selectMedFileBackgroundLineEdit->show();
908 sizeMapField->setEnabled(true);
912 medFileBackground->hide();
913 constantButton->setChecked(true);
914 selectMedFileBackgroundbutton->hide();
915 selectMedFileBackgroundLineEdit->clear();
916 selectMedFileBackgroundLineEdit->hide();
919 sizeMapField->setEnabled(false);
924 void SMESHGUI_MgAdaptArguments::timeStepGroupChanged(int timeStepType, bool disableOther, int vmax)
926 switch (timeStepType)
929 onNoTimeStep(disableOther);
932 onLastTimeStep(disableOther);
935 onChosenTimeStep(disableOther, vmax);
941 void SMESHGUI_MgAdaptArguments::clear()
943 selectMedFileLineEdit->clear();
944 aBrowserObject->clear();
946 meshNameLineEdit->clear();
947 selectOutMedFileLineEdit->clear();
949 // med_int SMESHGUI_MgAdaptArguments::getMeshDim() const
953 QWidget* ItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &o, const QModelIndex &index) const
955 bool editable = index.data( EDITABLE_ROLE ).toInt();
956 return editable ? QItemDelegate::createEditor( parent, o, index ) : 0;
959 //////////////////////////////////////////
961 //////////////////////////////////////////
963 MgAdaptAdvWidget::MgAdaptAdvWidget( QWidget* parent, std::vector <std::string>* options, Qt::WindowFlags f )
964 : QWidget( parent, f ), myOptions(options)
967 myOptionTable->header()->setSectionResizeMode( QHeaderView::ResizeToContents );
968 myOptionTable->setItemDelegate( new ItemDelegate( myOptionTable ) );
970 for ( int i = 0, nb = myOptions->size(); i < nb; ++i )
972 AddOption( (*myOptions)[i].c_str() );
975 connect( myOptionTable, SIGNAL( itemChanged(QTreeWidgetItem *, int)), SLOT( itemChanged(QTreeWidgetItem *, int )));
976 connect( addBtn, SIGNAL(clicked()), this, SLOT( onAddOption() ) );
977 connect(workingDirectoryPushButton, SIGNAL(pressed()), this, SLOT(_onWorkingDirectoryPushButton()));
980 MgAdaptAdvWidget::~MgAdaptAdvWidget()
984 void MgAdaptAdvWidget::AddOption( const char* option, bool isCustom )
987 bool isDefault = false;
990 QStringList name_value_type = QString(option).split( ":", QString::KeepEmptyParts );
991 if ( name_value_type.size() > 0 )
992 name = name_value_type[0];
993 if ( name_value_type.size() > 1 )
994 value = name_value_type[1];
995 if ( name_value_type.size() > 2 )
996 isDefault = !name_value_type[2].toInt();
998 QTreeWidget* table = myOptionTable;
999 //table->setExpanded( true );
1001 QTreeWidgetItem* row;
1002 if (optionTreeWidgetItem.size())
1004 std::map<QString, QTreeWidgetItem *>::iterator it = optionTreeWidgetItem.find(name);
1005 if(it != optionTreeWidgetItem.end()) return; // option exist
1008 row = getNewQTreeWidgetItem(table, option, name, isCustom);
1013 row = getNewQTreeWidgetItem(table, option, name, isCustom);
1015 row->setText( 0, tr( name.toLatin1().constData() ));
1016 row->setText( 1, tr( value.toLatin1().constData() ));
1017 row->setCheckState( 0, isDefault ? Qt::Unchecked : Qt::Checked);
1018 row->setData( NAME_COL, PARAM_NAME, name );
1022 myOptionTable->scrollToItem( row );
1023 myOptionTable->setCurrentItem( row );
1024 myOptionTable->editItem( row, NAME_COL );
1028 QTreeWidgetItem* MgAdaptAdvWidget::getNewQTreeWidgetItem(QTreeWidget* table, const char* option, QString& name, bool isCustom)
1030 QTreeWidgetItem* row = new QTreeWidgetItem( table );
1031 row->setData( NAME_COL, EDITABLE_ROLE, int( isCustom && !option ));
1032 row->setFlags( row->flags() | Qt::ItemIsEditable );
1033 optionTreeWidgetItem.insert(std::pair <QString, QTreeWidgetItem*> (name, row));
1038 void MgAdaptAdvWidget::onAddOption()
1040 AddOption( NULL, true );
1042 void MgAdaptAdvWidget::GetOptionAndValue( QTreeWidgetItem * tblRow,
1047 option = tblRow->data( NAME_COL, PARAM_NAME ).toString();
1048 value = tblRow->text( VALUE_COL );
1049 isDefault = ! tblRow->checkState( NAME_COL );
1053 void MgAdaptAdvWidget::itemChanged(QTreeWidgetItem* tblRow, int column)
1057 myOptionTable->blockSignals( true );
1059 tblRow->setData( VALUE_COL, EDITABLE_ROLE, int( tblRow->checkState( NAME_COL )));
1061 int c = tblRow->checkState( NAME_COL ) ? 0 : 150;
1062 tblRow->setForeground( VALUE_COL, QBrush( QColor( c, c, c )));
1064 if ( column == NAME_COL && tblRow->data( NAME_COL, EDITABLE_ROLE ).toInt() ) // custom table
1066 tblRow->setData( NAME_COL, PARAM_NAME, tblRow->text( NAME_COL ));
1069 myOptionTable->blockSignals( false );
1072 void MgAdaptAdvWidget::setupWidget()
1074 if (this->objectName().isEmpty())
1075 this->setObjectName(QString(tr("MG-ADAPT-ADV")));
1076 this->resize(337, 369);
1077 gridLayout_4 = new QGridLayout(this);
1078 gridLayout_4->setObjectName(QString("gridLayout_4"));
1079 myOptionTable = new MgAdaptAdvWidgetTreeWidget(this);
1081 font.setBold(false);
1083 QTreeWidgetItem *__qtreewidgetitem = new QTreeWidgetItem();
1084 __qtreewidgetitem->setFont(1, font);
1085 __qtreewidgetitem->setFont(0, font);
1086 __qtreewidgetitem->setText(1, tr("OPTION_VALUE_COLUMN"));
1087 __qtreewidgetitem->setText(0, tr("OPTION_NAME_COLUMN"));
1088 myOptionTable->setHeaderItem(__qtreewidgetitem);
1089 myOptionTable->setObjectName(QString("myOptionTable"));
1090 myOptionTable->setEditTriggers(QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed);
1091 myOptionTable->setTabKeyNavigation(true);
1093 gridLayout_4->addWidget(myOptionTable, 0, 0, 1, 2);
1095 addBtn = new QPushButton(this);
1096 addBtn->setObjectName(QString("addBtn"));
1098 gridLayout_4->addWidget(addBtn, 1, 0, 1, 1);
1100 horizontalSpacer = new QSpacerItem(188, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
1102 gridLayout_4->addItem(horizontalSpacer, 1, 1, 1, 1);
1104 logGroupBox = new QGroupBox(this);
1105 logGroupBox->setObjectName(QString("logGroupBox"));
1106 gridLayout_2 = new QGridLayout(logGroupBox);
1107 gridLayout_2->setObjectName(QString("gridLayout_2"));
1108 gridLayout = new QGridLayout();
1109 gridLayout->setObjectName(QString("gridLayout"));
1110 workingDirectoryLabel = new QLabel(logGroupBox);
1111 workingDirectoryLabel->setObjectName(QString("workingDirectoryLabel"));
1113 gridLayout->addWidget(workingDirectoryLabel, 0, 0, 1, 1);
1115 workingDirectoryLineEdit = new QLineEdit(logGroupBox);
1116 workingDirectoryLineEdit->setObjectName(QString("workingDirectoryLineEdit"));
1118 gridLayout->addWidget(workingDirectoryLineEdit, 0, 1, 1, 1);
1120 workingDirectoryPushButton = new QPushButton(logGroupBox);
1121 workingDirectoryPushButton->setObjectName(QString("workingDirectoryPushButton"));
1123 gridLayout->addWidget(workingDirectoryPushButton, 0, 2, 1, 1);
1125 verboseLevelLabel = new QLabel(logGroupBox);
1126 verboseLevelLabel->setObjectName(QString("verboseLevelLabel"));
1128 gridLayout->addWidget(verboseLevelLabel, 1, 0, 1, 1);
1130 verboseLevelSpin = new QSpinBox(logGroupBox);
1131 verboseLevelSpin->setObjectName(QString("verboseLevelSpin"));
1133 gridLayout->addWidget(verboseLevelSpin, 1, 1, 1, 1);
1136 gridLayout_2->addLayout(gridLayout, 0, 0, 1, 1);
1138 horizontalLayout = new QHBoxLayout();
1139 horizontalLayout->setObjectName(QString("horizontalLayout"));
1140 logInFileCheck = new QCheckBox(logGroupBox);
1141 logInFileCheck->setObjectName(QString("logInFileCheck"));
1142 logInFileCheck->setChecked(true);
1144 horizontalLayout->addWidget(logInFileCheck);
1146 removeLogOnSuccessCheck = new QCheckBox(logGroupBox);
1147 removeLogOnSuccessCheck->setObjectName(QString("removeLogOnSuccessCheck"));
1148 removeLogOnSuccessCheck->setChecked(true);
1150 horizontalLayout->addWidget(removeLogOnSuccessCheck);
1153 gridLayout_2->addLayout(horizontalLayout, 1, 0, 1, 1);
1155 keepWorkingFilesCheck = new QCheckBox(logGroupBox);
1156 keepWorkingFilesCheck->setObjectName(QString("keepWorkingFilesCheck"));
1157 keepWorkingFilesCheck->setAutoExclusive(false);
1159 gridLayout_2->addWidget(keepWorkingFilesCheck, 2, 0, 1, 1);
1162 gridLayout_4->addWidget(logGroupBox, 3, 0, 1, 2);
1165 void MgAdaptAdvWidget::_onWorkingDirectoryPushButton()
1167 QString aDirName=QFileDialog::getExistingDirectory ();
1168 if (!(aDirName.isEmpty()))workingDirectoryLineEdit->setText(aDirName);
1170 void MgAdaptAdvWidget::onMeshDimChanged(ADAPTATION_MODE aMode)
1172 /* default adaptation mode
1173 * assume that if meshDim == 2 and no 3D backgrounmesh-->adaptation surface
1174 * if meshDim == 3 and if there is not 2D mesh -->VOLUME
1178 QString adaptation("adaptation"), value;
1181 case ADAPTATION_MODE::SURFACE:
1184 setOptionValue(adaptation, value);
1187 case ADAPTATION_MODE::BOTH :
1190 setOptionValue(adaptation, value);
1193 case ADAPTATION_MODE::VOLUME :
1196 setOptionValue(adaptation, value);
1201 void MgAdaptAdvWidget::setOptionValue(QString& option, QString& value)
1203 std::map<QString, QTreeWidgetItem *>::iterator it = optionTreeWidgetItem.find(option);
1204 if (it != optionTreeWidgetItem.end())
1206 it->second->setText( 0, tr( option.toLatin1().constData() ));
1207 it->second->setText( 1, tr( value.toLatin1().constData() ));
1208 it->second->setCheckState( 0, Qt::Checked );
1209 it->second->setData( NAME_COL, PARAM_NAME, option );
1210 myOptionTable->editItem( it->second, NAME_COL );
1215 bool isEditable( const QModelIndex& index )
1217 return index.isValid() &&
1218 index.flags() & Qt::ItemIsEditable &&
1219 index.flags() & Qt::ItemIsEnabled &&
1220 ( !index.data( Qt::UserRole + 1 ).isValid() || index.data( Qt::UserRole + 1 ).toInt() != 0 );
1224 MgAdaptAdvWidgetTreeWidget::MgAdaptAdvWidgetTreeWidget( QWidget* parent )
1225 : QTreeWidget( parent )
1229 QModelIndex MgAdaptAdvWidgetTreeWidget::moveCursor( CursorAction action, Qt::KeyboardModifiers modifiers )
1231 QModelIndex current = currentIndex();
1232 int column = current.column();
1233 if ( action == MoveNext )
1235 if ( column < columnCount()-1 )
1237 QModelIndex next = current.sibling( current.row(), column+1 );
1238 if ( isEditable( next ) ) return next;
1242 QModelIndex next = current.sibling( current.row()+1, 0 );
1243 if ( isEditable( next ) ) return next;
1246 else if ( action == MovePrevious )
1248 if ( column == 0 ) {
1249 QModelIndex next = current.sibling( current.row()-1, columnCount()-1 );
1250 if ( isEditable( next ) ) return next;
1253 QModelIndex next = current.sibling( current.row(), column-1 );
1254 if ( isEditable( next ) ) return next;
1257 return QTreeWidget::moveCursor( action, modifiers );
1260 void MgAdaptAdvWidgetTreeWidget::keyPressEvent( QKeyEvent* e )
1266 QModelIndex index = currentIndex();
1267 if ( !isEditable( index ) ) {
1268 for ( int i = 0; i < columnCount(); i++ ) {
1269 QModelIndex sibling = index.sibling( index.row(), i );
1270 if ( isEditable( sibling ) ) {
1271 if ( !edit( sibling, EditKeyPressed, e ) ) e->ignore();
1280 QTreeWidget::keyPressEvent( e );
1283 // ======================================================
1284 // ========================================================
1285 QString lireNomMaillage(QString aFile, med_int& meshdim)
1287 QString nomMaillage = QString::null ;
1291 std::vector<std::string> listMeshesNames = MEDCoupling::GetMeshNames(aFile.toStdString());
1293 std::size_t numberOfMeshes(listMeshesNames.size());
1294 // std::cout << "numberOfMeshes:" << numberOfMeshes << std::endl;
1295 if (numberOfMeshes == 0 )
1297 QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
1298 QObject::tr("MG_ADAPT_MED_FILE_2") );
1301 if (numberOfMeshes > 1 )
1303 QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
1304 QObject::tr("MG_ADAPT_MED_FILE_3") );
1308 // std::cout << "nomMaillage:" << listMeshesNames[0] << std::endl;
1309 nomMaillage = QString(listMeshesNames[0].c_str());
1311 // Dimension du maillage
1312 MEDCoupling::MCAuto<MEDCoupling::MEDFileData> mfd = MEDCoupling::MEDFileData::New(aFile.toStdString());
1313 meshdim = mfd->getMeshes()->getMeshAtPos(0)->getMeshDimension() ;
1314 // std::cout << "meshdim:" << meshdim << std::endl;
1322 // =======================================================================
1323 std::map<QString, int> GetListeChamps(QString aFile, bool errorMessage)
1324 // =======================================================================
1326 // Il faut voir si plusieurs maillages
1328 std::map<QString, int> ListeChamp ;
1332 MEDCoupling::MCAuto<MEDCoupling::MEDFileData> mfd = MEDCoupling::MEDFileData::New(aFile.toStdString());
1333 std::vector<std::string> listFieldsNames(mfd->getFields()->getFieldsNames());
1334 std::size_t jaux(listFieldsNames.size());
1339 QMessageBox::critical( 0, QObject::tr("_ERROR"),
1340 QObject::tr("HOM_MED_FILE_5") );
1344 // nbofcstp inutile pour le moment
1345 med_int nbofcstp = 1;
1346 for(std::size_t j=0;j<jaux;j++)
1348 // std::cout << listFieldsNames[j] << std::endl;
1349 ListeChamp.insert(std::pair<QString, int> (QString(listFieldsNames[j].c_str()), nbofcstp));
1357 // =======================================================================
1358 std::string remove_extension(const std::string& filename)
1359 // =======================================================================
1361 size_t lastdot = filename.find_last_of(".");
1362 if (lastdot == std::string::npos) return filename;
1363 return filename.substr(0, lastdot);