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 "SUIT_Desktop.h"
27 #include "SUIT_Application.h"
28 #include "SUIT_Session.h"
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>
44 #include <QHBoxLayout>
49 #include <QPushButton>
50 #include <QRadioButton>
52 #include <QVBoxLayout>
53 #include <QDoubleSpinBox>
55 #include <QTreeWidget>
56 #include <QTreeWidgetItem>
57 #include <QSpacerItem>
59 #include <QHeaderView>
60 #include <QItemDelegate>
61 #include <QFileDialog>
62 #include <QMessageBox>
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>
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>
83 #include <utilities.h>
85 #include <TCollection_AsciiString.hxx>
87 const int SPACING = 6; // layout spacing
88 const int MARGIN = 9; // layout margin
90 //=================================================================================
91 // function : SMESHGUI_MgAdaptDlg()
93 //=================================================================================
94 SMESHGUI_MgAdaptDlg::SMESHGUI_MgAdaptDlg( SalomeApp_Module* theModule, SMESH::MG_ADAPT_ptr myModel, QWidget* parent, bool isCreation )
95 : mySMESHGUI( theModule ), QDialog(parent)
97 //~model = new MgAdapt(*myModel);
98 model = SMESH::MG_ADAPT::_duplicate(myModel);
99 myData = model->getData();
101 if (!isCreation) readParamsFromHypo();
104 void SMESHGUI_MgAdaptDlg::buildDlg()
107 setAttribute( Qt::WA_DeleteOnClose, true );
108 setWindowTitle( tr( "ADAPT_PREF_MG_ADAPT" ) );
109 setSizeGripEnabled( true );
111 myTabWidget = new QTabWidget( this );
115 myArgs = new SMESHGUI_MgAdaptArguments( myTabWidget );
116 SMESH::str_array* str = model->getOptionValuesStrVec();
117 SMESH::str_array* str2 = model->getCustomOptionValuesStrVec();
118 std::vector<std::string> s;
119 for (int i = 0; i< str->length(); i++) s.push_back( (*str)[i].in());
120 for (int j = str->length(); j< str2->length(); j++) s.push_back((*str2)[ j - str->length() ].in() );
121 //~str.insert( str.end(), str2.begin(), str2.end() );
123 myAdvOpt = new MgAdaptAdvWidget(myTabWidget, &s);
125 int argsTab = myTabWidget->addTab( myArgs, tr( "Args" ) );
126 int advTab = myTabWidget->addTab( myAdvOpt, tr( "ADVOP" ) );
128 myAdvOpt->workingDirectoryLabel ->setText (tr( "WORKING_DIR" ));
129 myAdvOpt->workingDirectoryPushButton ->setText (tr( "SELECT_DIR" ));
130 myAdvOpt->keepWorkingFilesCheck ->setText (tr( "KEEP_WORKING_FILES" ));
131 myAdvOpt->verboseLevelLabel ->setText (tr( "VERBOSE_LEVEL" ));
132 myAdvOpt->removeLogOnSuccessCheck ->setText (tr( "REMOVE_LOG_ON_SUCCESS" ));
133 myAdvOpt->logInFileCheck ->setText (tr( "LOG_IN_FILE" ));
134 myAdvOpt->logGroupBox ->setTitle(tr( "LOG_GROUP_TITLE" ));
137 QPushButton* buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), this);
138 buttonOk->setAutoDefault(false);
139 QPushButton* buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), this);
140 buttonApply->setAutoDefault(false);
141 QPushButton* buttonCancel = new QPushButton( tr( "SMESH_BUT_CANCEL" ), this );
142 buttonCancel->setAutoDefault( false );
143 QPushButton* buttonHelp = new QPushButton( tr( "SMESH_BUT_HELP" ), this );
144 buttonHelp->setAutoDefault( false );
146 QHBoxLayout* btnLayout = new QHBoxLayout;
147 btnLayout->setSpacing( SPACING );
148 btnLayout->setMargin( 0 );
149 btnLayout->addWidget( buttonOk );
150 btnLayout->addStretch( 10 );
151 btnLayout->addWidget( buttonApply );
152 btnLayout->addStretch( 10 );
153 btnLayout->addWidget( buttonCancel );
154 btnLayout->addStretch( 10 );
155 btnLayout->addWidget( buttonHelp );
157 QVBoxLayout* l = new QVBoxLayout ( this );
158 l->setMargin( MARGIN );
159 l->setSpacing( SPACING );
160 l->addWidget( myTabWidget );
162 l->addLayout( btnLayout );
164 connect( buttonOk, SIGNAL(pressed()), this, SLOT(PushOnOK()));
165 connect( buttonApply, SIGNAL(pressed()), this, SLOT(PushOnApply()));
166 connect( buttonCancel, SIGNAL(pressed()), this, SLOT(close()));
167 connect( buttonHelp, SIGNAL(pressed()), this, SLOT(PushOnHelp()));
169 connect( myArgs, SIGNAL(meshDimSignal(ADAPTATION_MODE)), myAdvOpt, SLOT( onMeshDimChanged(ADAPTATION_MODE)) );
173 //=================================================================================
174 // function : ~SMESHGUI_MgAdaptDlg()
175 // purpose : Destroys the object and frees any allocated resources
176 //=================================================================================
177 SMESHGUI_MgAdaptDlg::~SMESHGUI_MgAdaptDlg()
182 //~void SMESHGUI_MgAdaptDlg::setModel(MgAdapt* mg)
186 SMESH::MG_ADAPT_ptr SMESHGUI_MgAdaptDlg::getModel() const
191 \brief Perform clean-up actions on the dialog box closing.
193 bool SMESHGUI_MgAdaptDlg::PushOnApply()
195 bool ret = readParamsFromWidgets();
198 void SMESHGUI_MgAdaptDlg::PushOnOK()
200 bool ret = PushOnApply();
203 void SMESHGUI_MgAdaptDlg::reject()
207 bool SMESHGUI_MgAdaptDlg::readParamsFromHypo( ) const
210 myArgs->aMedfile->setChecked(myData->fromMedFile) ;
211 if (myData->fromMedFile)
214 *(myArgs->myFileInDir) = QString(myData->myFileInDir) ;
215 myArgs->selectMedFileLineEdit->setText(QString(myData->myMeshFileIn)) ;
216 // myData->myInMeshName = // TODO
221 myArgs->aBrowserObject->setText(QString(myData->myInMeshName));
222 //~ myArgs->myFileInDir =""; // TODO
223 //~ myArgs->selectMedFileLineEdit->setText(); // TODO
225 myArgs->meshNameLineEdit->setText(QString(myData->myOutMeshName));
226 myArgs->medFileCheckBox->setChecked(myData->myMeshOutMed);
228 if(myData->myMeshOutMed)
230 *(myArgs->myFileOutDir) = QString(myData->myFileOutDir);
231 myArgs->selectOutMedFileLineEdit->setText(QString(myData->myMeshFileOut));
235 *(myArgs->myFileOutDir) = QString(""); //TODO
238 myArgs->publishOut->setChecked(myData->myPublish);
240 myArgs->localButton->setChecked(myData->myUseLocalMap);
241 myArgs->backgroundButton->setChecked(myData->myUseBackgroundMap);
242 myArgs->constantButton->setChecked(myData->myUseConstantValue);
244 if (myData->myUseConstantValue)
246 myArgs->dvalue->setValue(myData->myConstantValue);
250 myArgs->dvalue->setValue(0.0);
253 if (myData->myUseBackgroundMap)
256 *(myArgs->myFileSizeMapDir) = QString(myData->myFileSizeMapDir) ;
257 myArgs->selectMedFileBackgroundLineEdit->setText(QString(myData->myMeshFileBackground));
261 *(myArgs->myFileSizeMapDir) = QString("") ; //TODO
262 myArgs->selectMedFileBackgroundLineEdit->setText(""); //TODO
265 myArgs->fieldNameCmb->setCurrentText(QString(myData->myFieldName));
266 myArgs->noTimeStep->setChecked(myData->myUseNoTimeStep);
267 myArgs->lastTimeStep->setChecked( myData->myUseLastTimeStep);
268 myArgs->chosenTimeStep->setChecked(myData->myUseChosenTimeStep);
269 if (myData->myUseChosenTimeStep)
271 myArgs->rankSpinBox->setValue(myData->myRank);
272 myArgs->timeStep->setValue(myData->myTimeStep);
275 myAdvOpt->workingDirectoryLineEdit->setText(QString(myData->myWorkingDir));
276 myAdvOpt->logInFileCheck->setChecked(myData->myPrintLogInFile);
278 myAdvOpt->verboseLevelSpin->setValue(myData->myVerboseLevel);
279 myAdvOpt->removeLogOnSuccessCheck->setChecked(myData->myRemoveLogOnSuccess);
280 myAdvOpt->keepWorkingFilesCheck->setChecked(myData->myKeepFiles);
286 bool SMESHGUI_MgAdaptDlg::readParamsFromWidgets()
288 MESSAGE ("readParamsFromWidgets") ;
290 SMESH::MgAdaptHypothesisData* aData = new SMESH::MgAdaptHypothesisData();
293 // 1. Fichier du maillage de départ
294 aData->fromMedFile = myArgs->aMedfile->isChecked();
295 if (aData->fromMedFile)
297 aData->myFileInDir = CORBA::string_dup(myArgs->myFileInDir->toStdString().c_str());
298 aData->myMeshFileIn = CORBA::string_dup(myArgs->selectMedFileLineEdit->text().toStdString().c_str());
299 // aData->myInMeshName = // TODO
303 QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
304 QObject::tr("MG_ADAPT_MED_FILE_4") );
307 // aData->myInMeshName = CORBA::string_dup(myArgs->aBrowserObject->text().toStdString().c_str());
308 // aData->myFileInDir = CORBA::string_dup(myAdvOpt->workingDirectoryLineEdit->text().toStdString().c_str());
310 // TCollection_AsciiString aGenericName = (char*)aData->myFileInDir;
311 // TCollection_AsciiString aGenericName2 = "MgAdapt_";
312 // aGenericName2 += getpid();
313 // aGenericName2 += "_";
314 // aGenericName2 += Abs((Standard_Integer)(long) aGenericName.ToCString());
315 // aGenericName2 += ".med";
316 // aGenericName+=aGenericName2;
317 // emit myArgs->toExportMED(aGenericName.ToCString());
318 // aData->myMeshFileIn = aGenericName2.ToCString();
320 // 2. Fichier du maillage de sortie
321 aData->myOutMeshName = CORBA::string_dup(myArgs->meshNameLineEdit->text().toStdString().c_str());
322 aData->myMeshOutMed = myArgs->medFileCheckBox->isChecked();
323 if(aData->myMeshOutMed)
325 aData->myFileOutDir = CORBA::string_dup(myArgs->myFileOutDir->toStdString().c_str());
326 aData->myMeshFileOut = CORBA::string_dup(myArgs->selectOutMedFileLineEdit->text().toStdString().c_str());
330 aData->myMeshFileOut = "";
332 aData->myPublish = myArgs->publishOut->isChecked();
334 // 3. Type de carte de tailles
335 aData->myUseLocalMap = myArgs->localButton->isChecked();
336 aData->myUseBackgroundMap = myArgs->backgroundButton->isChecked();
337 aData->myUseConstantValue = myArgs->constantButton->isChecked();
339 if (aData->myUseConstantValue)
341 aData->myConstantValue = myArgs->dvalue->value();
345 aData->myConstantValue = 0.0;
347 // 3.2. Arrière-plan
348 if (aData->myUseBackgroundMap)
350 aData->myFileSizeMapDir = CORBA::string_dup(myArgs->myFileSizeMapDir->toStdString().c_str());
351 aData->myMeshFileBackground = CORBA::string_dup(myArgs->selectMedFileBackgroundLineEdit->text().toStdString().c_str());
355 aData->myMeshFileBackground = "";
359 if ( ! aData->myUseConstantValue )
361 if ( strlen(myArgs->fieldNameCmb->currentText().toStdString().c_str()) == 0 )
363 QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
364 QObject::tr("MG_ADAPT_MED_FILE_5") );
369 aData->myFieldName = CORBA::string_dup(myArgs->fieldNameCmb->currentText().toStdString().c_str());
370 aData->myUseNoTimeStep = myArgs->noTimeStep->isChecked();
371 aData->myUseLastTimeStep = myArgs->lastTimeStep->isChecked();
372 aData->myUseChosenTimeStep = myArgs->chosenTimeStep->isChecked();
373 if (aData->myUseChosenTimeStep)
375 aData->myRank = myArgs->rankSpinBox->value();
376 aData->myTimeStep = myArgs->timeStep->value();
381 // 5. Options avancées
382 aData->myWorkingDir = CORBA::string_dup(myAdvOpt->workingDirectoryLineEdit->text().toStdString().c_str());
383 aData->myPrintLogInFile = myAdvOpt->logInFileCheck->isChecked();
384 aData->myVerboseLevel = myAdvOpt->verboseLevelSpin->value();
385 aData->myRemoveLogOnSuccess = myAdvOpt->removeLogOnSuccessCheck->isChecked();
386 aData->myKeepFiles = myAdvOpt->keepWorkingFilesCheck->isChecked();
387 model->setData(*aData);
398 bool SMESHGUI_MgAdaptDlg::storeParamsToHypo( const SMESH::MgAdaptHypothesisData& ) const
402 \brief Show help page
404 void SMESHGUI_MgAdaptDlg::PushOnHelp()
406 // QString aHelpFile;
407 // if ( myTabWidget->currentIndex() == MinDistance ) {
408 // aHelpFile = "measurements.html#min-distance-anchor";
409 // } else if ( myTabWidget->currentIndex() == BoundingBox ) {
410 // aHelpFile = "measurements.html#bounding-box-anchor";
411 // } else if ( myTabWidget->currentWidget() == myAngle ) {
412 // aHelpFile = "measurements.html#angle-anchor";
414 // aHelpFile = "measurements.html#basic-properties-anchor";
417 // SMESH::ShowHelpFile( aHelpFile );
419 bool SMESHGUI_MgAdaptDlg::checkParams(QString& msg)
421 if ( !QFileInfo( myAdvOpt->workingDirectoryLineEdit->text().trimmed() ).isWritable() )
423 SUIT_MessageBox::warning( this,
424 tr( "SMESH_WRN_WARNING" ),
425 tr( "NO_PERMISSION" ) );
430 myAdvOpt->myOptionTable->setFocus();
431 QApplication::instance()->processEvents();
434 bool isDefault, ok = true;
435 int iRow = 0, nbRows = myAdvOpt->myOptionTable->topLevelItemCount();
436 for ( ; iRow < nbRows; ++iRow )
438 QTreeWidgetItem* row = myAdvOpt->myOptionTable->topLevelItem( iRow );
439 myAdvOpt->GetOptionAndValue( row, name, value, isDefault );
441 if ( name.simplified().isEmpty() )
442 continue; // invalid custom option
444 if ( isDefault ) // not selected option
449 model->setOptionValue( name.toLatin1().constData(), value.toLatin1().constData() );
451 catch ( const SALOME::SALOME_Exception& ex )
453 msg = ex.details.text.in();
462 //=================================================================================
463 // function : SMESHGUI_MgAdaptArguments()
465 //=================================================================================
466 SMESHGUI_MgAdaptArguments::SMESHGUI_MgAdaptArguments( QWidget* parent )
470 myFileInDir = new QString("");
471 myFileOutDir = new QString("");
472 myFileSizeMapDir = new QString("");
473 if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
475 *myFileInDir = QDir::currentPath();
476 *myFileOutDir = QDir::currentPath();
477 *myFileSizeMapDir = QDir::currentPath();
481 *myFileInDir = SUIT_FileDlg::getLastVisitedPath();
482 *myFileOutDir = SUIT_FileDlg::getLastVisitedPath();
483 *myFileSizeMapDir = SUIT_FileDlg::getLastVisitedPath();
488 aMeshIn = new QGroupBox( tr( "MeshIn" ), this );
489 aMedfile = new QRadioButton( tr( "MEDFile" ), aMeshIn );
490 aBrowser = new QRadioButton( tr( "Browser" ), aMeshIn );
491 aBrowserObject = new QLineEdit( aMeshIn );
492 selectMedFilebutton = new QPushButton("", aMeshIn);
493 selectMedFileLineEdit = new QLineEdit( aMeshIn );
495 meshIn = new QGridLayout( aMeshIn );
497 meshIn->setMargin( MARGIN );
498 meshIn->setSpacing( SPACING );
499 meshIn->addWidget( aMedfile, 0, 0, 1,1 );
500 meshIn->addWidget( aBrowser, 0, 1,1,1);
501 meshIn->addWidget( aBrowserObject, 0, 2, 1, 1 );
502 meshIn->addWidget( selectMedFilebutton, 1, 0,1, 1);
503 meshIn->addWidget( selectMedFileLineEdit, 1, 1, 1, 1 );
504 hspacer = new QSpacerItem(188, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
506 meshInGroup = new QButtonGroup( this );
507 meshInGroup->addButton( aMedfile, 0 );
508 meshInGroup->addButton( aBrowser, 1 );
512 aMeshOut = new QGroupBox( tr( "MeshOut" ), this );
513 meshName = new QLabel(tr("MeshName"), aMeshOut);
514 secondHspacer = new QSpacerItem(100, 30);
515 meshNameLineEdit = new QLineEdit(aMeshOut) ;
516 medFileCheckBox = new QCheckBox(tr("MEDFile"), aMeshOut);
517 selectOutMedFilebutton = new QPushButton("", aMeshOut);
518 thirdHspacer = new QSpacerItem(188, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
519 selectOutMedFileLineEdit = new QLineEdit(aMeshOut) ;
520 publishOut = new QCheckBox(tr("Publish_MG_ADAPT"), aMeshOut);
522 meshOut = new QGridLayout( aMeshOut );
524 meshOut->setMargin( MARGIN );
525 meshOut->setSpacing( SPACING );
526 meshOut->addWidget( meshName, 0, 0, 1,1 );
527 meshOut->addItem( secondHspacer, 0, 1, 1, 1 );
528 meshOut->addWidget( meshNameLineEdit, 0, 2,1,1);
529 meshOut->addWidget( medFileCheckBox, 1, 0,1,1 );
530 meshOut->addWidget( selectOutMedFilebutton, 1, 1,1,1 );
531 meshOut->addWidget( selectOutMedFileLineEdit, 1, 2,1,1);
532 meshOut->addWidget( publishOut, 2, 0,1,1 );
534 //size map definition
536 sizeMapDefinition = new QGroupBox(tr("SIZE_MAP_DEF"), this);
537 localButton = new QRadioButton(tr("LOCAL_MG_ADAPT"), sizeMapDefinition);
538 backgroundButton = new QRadioButton(tr("BACKGRND_MG_ADAPT"), sizeMapDefinition);
539 constantButton = new QRadioButton(tr("CNST_MG_ADAPT"), sizeMapDefinition);
540 medFileBackground = new QLabel(tr("MED_FILE_BCKG"), sizeMapDefinition);
541 selectMedFileBackgroundbutton = new QPushButton(tr(""), sizeMapDefinition);
542 selectMedFileBackgroundLineEdit = new QLineEdit(sizeMapDefinition);
543 valueLabel = new QLabel(tr("VALUE_MG_ADAPT"), sizeMapDefinition);
544 dvalue = new QDoubleSpinBox(sizeMapDefinition);
545 sizeMapDefGroup = new QButtonGroup( this );
546 sizeMapDefGroup->addButton( localButton, 0 );
547 sizeMapDefGroup->addButton( backgroundButton, 1 );
548 sizeMapDefGroup->addButton( constantButton, 2 );
550 sizeMapDefGroupLayout = new QGridLayout(sizeMapDefinition);
551 sizeMapDefGroupLayout->addWidget(localButton, 0,0);
552 sizeMapDefGroupLayout->addWidget(backgroundButton, 0,1);
553 sizeMapDefGroupLayout->addWidget(constantButton, 0,2);
554 sizeMapDefGroupLayout->addWidget(medFileBackground, 1,0);
555 sizeMapDefGroupLayout->addWidget(selectMedFileBackgroundbutton, 1,1);
556 sizeMapDefGroupLayout->addWidget(selectMedFileBackgroundLineEdit, 1,2);
557 sizeMapDefGroupLayout->addWidget(valueLabel, 2,0);
558 sizeMapDefGroupLayout->addWidget(dvalue, 2,1);
561 sizeMapField = new QGroupBox(tr("SIZE_MAP_FIELD"), this);
562 fieldName = new QLabel(tr("MG_ADAPT_FIELD_NAME"), sizeMapField);
563 fieldNameCmb = new QComboBox(sizeMapField);
564 noTimeStep = new QRadioButton(tr("MG_ADAPT_NO_T_ST"), sizeMapField);
565 lastTimeStep = new QRadioButton(tr("MG_ADAPT_L_ST"), sizeMapField);
566 chosenTimeStep = new QRadioButton(tr("MG_ADAPT_CH_ST"), sizeMapField);
567 timeStepLabel = new QLabel(tr("MG_ADAPT_TSTP"), sizeMapField);
568 timeStep = new QSpinBox(sizeMapField);
569 //~timeStep->setMinimum(-1);
570 rankLabel = new QLabel(tr("MG_ADAPT_RANK"), sizeMapField);
571 rankSpinBox = new QSpinBox(sizeMapField);
572 rankSpinBox->setMinimum(-1);
574 timeStepGroup = new QButtonGroup(this);
575 timeStepGroup->addButton(noTimeStep, 0);
576 timeStepGroup->addButton(lastTimeStep, 1);
577 timeStepGroup->addButton(chosenTimeStep, 2);
579 sizeMapFieldGroupLayout = new QGridLayout(sizeMapField);
581 sizeMapFieldGroupLayout->addWidget(fieldName, 0,0);
582 sizeMapFieldGroupLayout->addWidget(fieldNameCmb, 0,1);
583 sizeMapFieldGroupLayout->addWidget(noTimeStep, 1,0);
584 sizeMapFieldGroupLayout->addWidget(lastTimeStep, 1,1);
585 sizeMapFieldGroupLayout->addWidget(chosenTimeStep, 1,2);
586 sizeMapFieldGroupLayout->addWidget(timeStepLabel, 2,0);
587 sizeMapFieldGroupLayout->addWidget(timeStep, 2,1);
588 sizeMapFieldGroupLayout->addWidget(rankLabel, 2,2);
589 sizeMapFieldGroupLayout->addWidget(rankSpinBox, 2,3);
591 QGridLayout* argumentsLayout = new QGridLayout( this );
592 argumentsLayout->setMargin( MARGIN );
593 argumentsLayout->setSpacing( SPACING );
595 argumentsLayout->addWidget( aMeshIn, 0, 0, 1, 3 );
596 argumentsLayout->addWidget( aMeshOut, 1, 0, 1, 3 );
597 argumentsLayout->addWidget( sizeMapDefinition, 2, 0, 1, 3 );
598 argumentsLayout->addWidget( sizeMapField, 3, 0, 1, 3 );
599 argumentsLayout->setColumnStretch( 1, 5 );
600 argumentsLayout->setRowStretch( 4, 5 );
603 setMode( Mesh, Local);
604 medFileCheckBox->setChecked(true);
605 visibleTimeStepRankLabel (false);
608 connect( meshInGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( modeChanged( int ) ) );
609 connect( sizeMapDefGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( sizeMapDefChanged( int ) ) );
610 connect( selectMedFilebutton, SIGNAL( pressed( ) ), this, SLOT( onSelectMedFilebuttonClicked( ) ) );
611 connect( medFileCheckBox, SIGNAL (stateChanged(int)), this, SLOT(onMedFileCheckBox(int) ) );
612 connect( publishOut, SIGNAL (stateChanged(int)), this, SLOT(onPublishOut(int) ) );
613 connect( selectOutMedFilebutton, SIGNAL( pressed()), this, SLOT(onSelectOutMedFilebutton()));
614 connect( selectMedFileBackgroundbutton, SIGNAL(pressed()), this, SLOT(onSelectMedFileBackgroundbutton()) );
615 connect( timeStepGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( timeStepGroupChanged( int ) ) );
616 emit updateSelection();
619 //=================================================================================
620 // function : ~SMESHGUI_MgAdaptArguments()
621 // purpose : Destroys the object and frees any allocated resources
622 //=================================================================================
623 SMESHGUI_MgAdaptArguments::~SMESHGUI_MgAdaptArguments()
627 void SMESHGUI_MgAdaptArguments::onNoTimeStep(bool disableOther)
629 noTimeStep->setChecked(true);
631 visibleTimeStepRankLabel (false);
632 rankSpinBox->setValue(-2);
633 timeStep->setValue(-2);
635 lastTimeStep->setDisabled(disableOther);
636 chosenTimeStep->setDisabled(disableOther);
638 void SMESHGUI_MgAdaptArguments::onLastTimeStep(bool disableOther)
640 lastTimeStep->setChecked(true);
642 visibleTimeStepRankLabel (false);
643 rankSpinBox->setValue(-1);
644 timeStep->setValue(-1);
645 noTimeStep->setDisabled(disableOther);
647 void SMESHGUI_MgAdaptArguments::onChosenTimeStep(bool disableOther, int vmax)
649 chosenTimeStep->setChecked(true);
651 visibleTimeStepRankLabel (true);
652 rankSpinBox->setValue(0);
653 timeStep->setValue(0);
654 if (vmax) timeStep->setMaximum(vmax);
657 void SMESHGUI_MgAdaptArguments::visibleTimeStepRankLabel(bool visible)
659 rankLabel->setVisible(visible);
660 rankSpinBox->setVisible(visible);
662 timeStepLabel->setVisible(visible);
663 timeStep->setVisible(visible);
666 void SMESHGUI_MgAdaptArguments::onSelectOutMedFilebutton()
669 QString filtre = QString("Med") ;
670 filtre += QString(" files (*.") + QString("med") + QString(");;");
671 QString fileName = QFileDialog::getSaveFileName(this, tr("SAVE_MED"), QString(""), filtre);
672 QFileInfo myFileInfo(fileName);
673 selectOutMedFileLineEdit->setText(myFileInfo.fileName());
674 *myFileOutDir = myFileInfo.path();
677 void SMESHGUI_MgAdaptArguments::onSelectMedFileBackgroundbutton()
679 QString fileName0 = selectMedFileBackgroundbutton->text().trimmed();
681 QString fileName = getMedFileName(false);
682 if (fileName != QString::null)
684 myFieldList = GetListeChamps(fileName);
685 if (myFieldList.empty())
687 fileName = fileName0;
688 fieldNameCmb->clear();
692 // fill field name Combobox
693 fieldNameCmb->clear();
694 std::map<QString, int>::const_iterator it;
695 for ( it=myFieldList.begin() ; it != myFieldList.end(); it++)
697 fieldNameCmb->insertItem(0,QString(it->first));
698 int typeStepInField = it->second > 2 ? 2 : it->second ;
699 timeStepGroupChanged(typeStepInField, false);
705 fileName = fileName0;
706 fieldNameCmb->clear();
709 QFileInfo myFileInfo(fileName);
710 *myFileSizeMapDir = myFileInfo.path();
711 selectMedFileBackgroundLineEdit->setText(myFileInfo.fileName());
714 void SMESHGUI_MgAdaptArguments::onMedFileCheckBox(int state)
716 if (state == Qt::Checked)
718 selectOutMedFilebutton->show();
719 selectOutMedFileLineEdit->show();
720 selectOutMedFilebutton->setEnabled(true);
721 selectOutMedFileLineEdit->setEnabled(true);
725 selectOutMedFilebutton->setEnabled(false);
726 selectOutMedFileLineEdit->setEnabled(false);
727 publishOut->setChecked(true);
730 void SMESHGUI_MgAdaptArguments::onPublishOut(int state)
732 if (state == Qt::Unchecked)
734 medFileCheckBox->setChecked(true);
738 void SMESHGUI_MgAdaptArguments::onSelectMedFilebuttonClicked()
740 // bool keep = false;
741 QString fileName0 = selectMedFileLineEdit->text().trimmed();
743 QString fileName = getMedFileName(false);
744 if(fileName != QString::null)
746 QString aMeshName = lireNomMaillage(fileName.trimmed(), meshDim);
747 if (aMeshName == QString::null )
749 QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
750 QObject::tr("MG_ADAPT_MED_FILE_2") );
751 fileName = fileName0;
755 meshNameLineEdit->setText(aMeshName);
756 ADAPTATION_MODE aMode = meshDim == 3 ? ADAPTATION_MODE::BOTH : ADAPTATION_MODE::SURFACE; // and when dimesh 3 without 2D mesh?
757 emit meshDimSignal(aMode);
765 QFileInfo myFileInfo(fileName);
766 *myFileInDir = myFileInfo.path();
767 *myFileOutDir = myFileInfo.path();
768 selectMedFileLineEdit->setText(myFileInfo.fileName());
769 QString outF = fileName == QString::null ? myFileInfo.fileName() :
770 QString( remove_extension(myFileInfo.fileName().toStdString() ).c_str() )+ QString(".adapt.med");
771 selectOutMedFileLineEdit->setText(outF);
772 onLocalSelected(myFileInfo.filePath());
776 void SMESHGUI_MgAdaptArguments::onLocalSelected(QString filePath)
778 myFieldList = GetListeChamps(filePath, false);
779 if (myFieldList.empty())
781 if (localButton->isChecked())
783 fieldNameCmb->clear();
788 // fill field name Combobox
789 fieldNameCmb->clear();
790 std::map<QString, int>::const_iterator it;
791 for ( it = myFieldList.begin() ; it != myFieldList.end(); it++)
793 fieldNameCmb->insertItem(0,QString(it->first));
794 // Je ne comprends pas le rapport entre pas de temps et apparition d'un nouveau champ... GN
795 int typeStepInField = it->second > 2 ? 2 : it->second ;
796 // std::cout << "SMESHGUI_MgAdaptArguments::onLocalSelected typeStepInField : " << typeStepInField << std::endl;
797 timeStepGroupChanged(typeStepInField, false);
801 // =======================================================================
802 // Gestion les boutons qui permettent de
803 // 1) retourne le nom d'un fichier par une fenetre de dialogue si aucun
804 // objet est selectionne dans l arbre d etude
805 // 2) retourne le nom du fichier asocie a l objet
806 // selectionne dans l arbre d etude
807 // =======================================================================
808 QString SMESHGUI_MgAdaptArguments::getMedFileName(bool avertir)
811 QString aFile = QString::null;
812 QString filtre = QString("Med") ;
813 filtre += QString(" files (*.") + QString("med") + QString(");;");
814 aFile = SUIT_FileDlg::getOpenFileName(0, QObject::tr("MG_ADAPT_SELECT_FILE_0"), QString(""), filtre );
819 void SMESHGUI_MgAdaptArguments::setMode(const Mode theMode, const SIZEMAP theSizeMap )
821 QRadioButton* aButton = qobject_cast<QRadioButton*>( meshInGroup->button( theMode ) );
822 QRadioButton* bButton = qobject_cast<QRadioButton*>( sizeMapDefGroup->button( theSizeMap ) );
825 aButton->setChecked( true );
826 modeChanged( theMode );
830 bButton->setChecked( true );
831 sizeMapDefChanged( theSizeMap );
835 void SMESHGUI_MgAdaptArguments::modeChanged( int theMode )
840 aBrowserObject->hide();
841 selectMedFileLineEdit->show();
842 selectMedFilebutton->show();
843 localButton->setEnabled(true);
847 selectMedFileLineEdit->hide();
848 selectMedFilebutton->hide();
849 localButton->setEnabled(false);
850 aBrowserObject->show();
851 sizeMapDefChanged(Background);
852 emit updateSelection();
856 void SMESHGUI_MgAdaptArguments::sizeMapDefChanged( int theSizeMap )
858 fieldNameCmb->clear();
859 if(theSizeMap == Local)
861 localButton->setEnabled(true);
862 localButton->setChecked(true);
863 medFileBackground->hide();
864 selectMedFileBackgroundbutton->hide();
865 selectMedFileBackgroundLineEdit->hide();
866 selectMedFileBackgroundLineEdit->clear();
870 sizeMapField->setEnabled(true);
871 if (!selectMedFileLineEdit->text().isEmpty())
873 QFileInfo myFileInfo(QDir(*myFileInDir), selectMedFileLineEdit->text());
874 onLocalSelected(myFileInfo.filePath());
877 else if (theSizeMap == Background)
879 medFileBackground->show();
880 backgroundButton->setChecked(true);
881 selectMedFileBackgroundbutton->show();
882 selectMedFileBackgroundLineEdit->show();
885 sizeMapField->setEnabled(true);
890 medFileBackground->hide();
891 constantButton->setChecked(true);
892 selectMedFileBackgroundbutton->hide();
893 selectMedFileBackgroundLineEdit->clear();
894 selectMedFileBackgroundLineEdit->hide();
897 sizeMapField->setEnabled(false);
900 void SMESHGUI_MgAdaptArguments::timeStepGroupChanged(int timeStepType, bool disableOther, int vmax)
902 switch (timeStepType)
905 onNoTimeStep(disableOther);
908 onLastTimeStep(disableOther);
911 onChosenTimeStep(disableOther, vmax);
917 void SMESHGUI_MgAdaptArguments::clear()
919 selectMedFileLineEdit->clear();
920 aBrowserObject->clear();
922 meshNameLineEdit->clear();
923 selectOutMedFileLineEdit->clear();
925 med_int SMESHGUI_MgAdaptArguments::getMeshDim() const
929 QWidget* ItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &o, const QModelIndex &index) const
931 bool editable = index.data( EDITABLE_ROLE ).toInt();
932 return editable ? QItemDelegate::createEditor( parent, o, index ) : 0;
935 //////////////////////////////////////////
937 //////////////////////////////////////////
939 MgAdaptAdvWidget::MgAdaptAdvWidget( QWidget* parent, std::vector <std::string>* options, Qt::WindowFlags f )
940 : QWidget( parent, f ), myOptions(options)
943 myOptionTable->header()->setSectionResizeMode( QHeaderView::ResizeToContents );
944 myOptionTable->setItemDelegate( new ItemDelegate( myOptionTable ) );
946 for ( int i = 0, nb = myOptions->size(); i < nb; ++i )
948 AddOption( (*myOptions)[i].c_str() );
951 connect( myOptionTable, SIGNAL( itemChanged(QTreeWidgetItem *, int)), SLOT( itemChanged(QTreeWidgetItem *, int )));
952 connect( addBtn, SIGNAL(clicked()), this, SLOT( onAddOption() ) );
953 connect(workingDirectoryPushButton, SIGNAL(pressed()), this, SLOT(_onWorkingDirectoryPushButton()));
956 MgAdaptAdvWidget::~MgAdaptAdvWidget()
960 void MgAdaptAdvWidget::AddOption( const char* option, bool isCustom )
963 bool isDefault = false;
966 QStringList name_value_type = QString(option).split( ":", QString::KeepEmptyParts );
967 if ( name_value_type.size() > 0 )
968 name = name_value_type[0];
969 if ( name_value_type.size() > 1 )
970 value = name_value_type[1];
971 if ( name_value_type.size() > 2 )
972 isDefault = !name_value_type[2].toInt();
974 QTreeWidget* table = myOptionTable;
975 //table->setExpanded( true );
977 QTreeWidgetItem* row;
978 if (optionTreeWidgetItem.size())
980 std::map<QString, QTreeWidgetItem *>::iterator it = optionTreeWidgetItem.find(name);
981 if(it != optionTreeWidgetItem.end()) return; // option exist
984 row = getNewQTreeWidgetItem(table, option, name, isCustom);
989 row = getNewQTreeWidgetItem(table, option, name, isCustom);
991 row->setText( 0, tr( name.toLatin1().constData() ));
992 row->setText( 1, tr( value.toLatin1().constData() ));
993 row->setCheckState( 0, isDefault ? Qt::Unchecked : Qt::Checked);
994 row->setData( NAME_COL, PARAM_NAME, name );
998 myOptionTable->scrollToItem( row );
999 myOptionTable->setCurrentItem( row );
1000 myOptionTable->editItem( row, NAME_COL );
1004 QTreeWidgetItem* MgAdaptAdvWidget::getNewQTreeWidgetItem(QTreeWidget* table, const char* option, QString& name, bool isCustom)
1006 QTreeWidgetItem* row = new QTreeWidgetItem( table );
1007 row->setData( NAME_COL, EDITABLE_ROLE, int( isCustom && !option ));
1008 row->setFlags( row->flags() | Qt::ItemIsEditable );
1009 optionTreeWidgetItem.insert(std::pair <QString, QTreeWidgetItem*> (name, row));
1014 void MgAdaptAdvWidget::onAddOption()
1016 AddOption( NULL, true );
1018 void MgAdaptAdvWidget::GetOptionAndValue( QTreeWidgetItem * tblRow,
1023 option = tblRow->data( NAME_COL, PARAM_NAME ).toString();
1024 value = tblRow->text( VALUE_COL );
1025 isDefault = ! tblRow->checkState( NAME_COL );
1029 void MgAdaptAdvWidget::itemChanged(QTreeWidgetItem* tblRow, int column)
1033 myOptionTable->blockSignals( true );
1035 tblRow->setData( VALUE_COL, EDITABLE_ROLE, int( tblRow->checkState( NAME_COL )));
1037 int c = tblRow->checkState( NAME_COL ) ? 0 : 150;
1038 tblRow->setForeground( VALUE_COL, QBrush( QColor( c, c, c )));
1040 if ( column == NAME_COL && tblRow->data( NAME_COL, EDITABLE_ROLE ).toInt() ) // custom table
1042 tblRow->setData( NAME_COL, PARAM_NAME, tblRow->text( NAME_COL ));
1045 myOptionTable->blockSignals( false );
1048 void MgAdaptAdvWidget::setupWidget()
1050 if (this->objectName().isEmpty())
1051 this->setObjectName(QString(tr("MG-ADAPT-ADV")));
1052 this->resize(337, 369);
1053 gridLayout_4 = new QGridLayout(this);
1054 gridLayout_4->setObjectName(QString("gridLayout_4"));
1055 myOptionTable = new MgAdaptAdvWidgetTreeWidget(this);
1057 font.setBold(false);
1059 QTreeWidgetItem *__qtreewidgetitem = new QTreeWidgetItem();
1060 __qtreewidgetitem->setFont(1, font);
1061 __qtreewidgetitem->setFont(0, font);
1062 __qtreewidgetitem->setText(1, tr("OPTION_VALUE_COLUMN"));
1063 __qtreewidgetitem->setText(0, tr("OPTION_NAME_COLUMN"));
1064 myOptionTable->setHeaderItem(__qtreewidgetitem);
1065 myOptionTable->setObjectName(QString("myOptionTable"));
1066 myOptionTable->setEditTriggers(QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed);
1067 myOptionTable->setTabKeyNavigation(true);
1069 gridLayout_4->addWidget(myOptionTable, 0, 0, 1, 2);
1071 addBtn = new QPushButton(this);
1072 addBtn->setObjectName(QString("addBtn"));
1074 gridLayout_4->addWidget(addBtn, 1, 0, 1, 1);
1076 horizontalSpacer = new QSpacerItem(188, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
1078 gridLayout_4->addItem(horizontalSpacer, 1, 1, 1, 1);
1080 logGroupBox = new QGroupBox(this);
1081 logGroupBox->setObjectName(QString("logGroupBox"));
1082 gridLayout_2 = new QGridLayout(logGroupBox);
1083 gridLayout_2->setObjectName(QString("gridLayout_2"));
1084 gridLayout = new QGridLayout();
1085 gridLayout->setObjectName(QString("gridLayout"));
1086 workingDirectoryLabel = new QLabel(logGroupBox);
1087 workingDirectoryLabel->setObjectName(QString("workingDirectoryLabel"));
1089 gridLayout->addWidget(workingDirectoryLabel, 0, 0, 1, 1);
1091 workingDirectoryLineEdit = new QLineEdit(logGroupBox);
1092 workingDirectoryLineEdit->setObjectName(QString("workingDirectoryLineEdit"));
1094 gridLayout->addWidget(workingDirectoryLineEdit, 0, 1, 1, 1);
1096 workingDirectoryPushButton = new QPushButton(logGroupBox);
1097 workingDirectoryPushButton->setObjectName(QString("workingDirectoryPushButton"));
1099 gridLayout->addWidget(workingDirectoryPushButton, 0, 2, 1, 1);
1101 verboseLevelLabel = new QLabel(logGroupBox);
1102 verboseLevelLabel->setObjectName(QString("verboseLevelLabel"));
1104 gridLayout->addWidget(verboseLevelLabel, 1, 0, 1, 1);
1106 verboseLevelSpin = new QSpinBox(logGroupBox);
1107 verboseLevelSpin->setObjectName(QString("verboseLevelSpin"));
1109 gridLayout->addWidget(verboseLevelSpin, 1, 1, 1, 1);
1112 gridLayout_2->addLayout(gridLayout, 0, 0, 1, 1);
1114 horizontalLayout = new QHBoxLayout();
1115 horizontalLayout->setObjectName(QString("horizontalLayout"));
1116 logInFileCheck = new QCheckBox(logGroupBox);
1117 logInFileCheck->setObjectName(QString("logInFileCheck"));
1118 logInFileCheck->setChecked(true);
1120 horizontalLayout->addWidget(logInFileCheck);
1122 removeLogOnSuccessCheck = new QCheckBox(logGroupBox);
1123 removeLogOnSuccessCheck->setObjectName(QString("removeLogOnSuccessCheck"));
1124 removeLogOnSuccessCheck->setChecked(true);
1126 horizontalLayout->addWidget(removeLogOnSuccessCheck);
1129 gridLayout_2->addLayout(horizontalLayout, 1, 0, 1, 1);
1131 keepWorkingFilesCheck = new QCheckBox(logGroupBox);
1132 keepWorkingFilesCheck->setObjectName(QString("keepWorkingFilesCheck"));
1133 keepWorkingFilesCheck->setAutoExclusive(false);
1135 gridLayout_2->addWidget(keepWorkingFilesCheck, 2, 0, 1, 1);
1138 gridLayout_4->addWidget(logGroupBox, 3, 0, 1, 2);
1141 void MgAdaptAdvWidget::_onWorkingDirectoryPushButton()
1143 QString aDirName=QFileDialog::getExistingDirectory ();
1144 if (!(aDirName.isEmpty()))workingDirectoryLineEdit->setText(aDirName);
1146 void MgAdaptAdvWidget::onMeshDimChanged(ADAPTATION_MODE aMode)
1148 /* default adaptation mode
1149 * assume that if meshDim == 2 -->adaptation surface
1150 * if meshDim == 3 and if there is not 2D mesh -->VOLUME
1154 QString adaptation("adaptation"), value;
1157 case ADAPTATION_MODE::SURFACE:
1160 setOptionValue(adaptation, value);
1163 case ADAPTATION_MODE::BOTH :
1166 setOptionValue(adaptation, value);
1169 case ADAPTATION_MODE::VOLUME :
1172 setOptionValue(adaptation, value);
1177 void MgAdaptAdvWidget::setOptionValue(QString& option, QString& value)
1179 std::map<QString, QTreeWidgetItem *>::iterator it = optionTreeWidgetItem.find(option);
1180 if (it != optionTreeWidgetItem.end())
1182 it->second->setText( 0, tr( option.toLatin1().constData() ));
1183 it->second->setText( 1, tr( value.toLatin1().constData() ));
1184 it->second->setCheckState( 0, Qt::Checked );
1185 it->second->setData( NAME_COL, PARAM_NAME, option );
1186 myOptionTable->editItem( it->second, NAME_COL );
1191 bool isEditable( const QModelIndex& index )
1193 return index.isValid() &&
1194 index.flags() & Qt::ItemIsEditable &&
1195 index.flags() & Qt::ItemIsEnabled &&
1196 ( !index.data( Qt::UserRole + 1 ).isValid() || index.data( Qt::UserRole + 1 ).toInt() != 0 );
1200 MgAdaptAdvWidgetTreeWidget::MgAdaptAdvWidgetTreeWidget( QWidget* parent )
1201 : QTreeWidget( parent )
1205 QModelIndex MgAdaptAdvWidgetTreeWidget::moveCursor( CursorAction action, Qt::KeyboardModifiers modifiers )
1207 QModelIndex current = currentIndex();
1208 int column = current.column();
1209 if ( action == MoveNext )
1211 if ( column < columnCount()-1 )
1213 QModelIndex next = current.sibling( current.row(), column+1 );
1214 if ( isEditable( next ) ) return next;
1218 QModelIndex next = current.sibling( current.row()+1, 0 );
1219 if ( isEditable( next ) ) return next;
1222 else if ( action == MovePrevious )
1224 if ( column == 0 ) {
1225 QModelIndex next = current.sibling( current.row()-1, columnCount()-1 );
1226 if ( isEditable( next ) ) return next;
1229 QModelIndex next = current.sibling( current.row(), column-1 );
1230 if ( isEditable( next ) ) return next;
1233 return QTreeWidget::moveCursor( action, modifiers );
1236 void MgAdaptAdvWidgetTreeWidget::keyPressEvent( QKeyEvent* e )
1242 QModelIndex index = currentIndex();
1243 if ( !isEditable( index ) ) {
1244 for ( int i = 0; i < columnCount(); i++ ) {
1245 QModelIndex sibling = index.sibling( index.row(), i );
1246 if ( isEditable( sibling ) ) {
1247 if ( !edit( sibling, EditKeyPressed, e ) ) e->ignore();
1256 QTreeWidget::keyPressEvent( e );
1260 // =======================================================================
1261 // renvoie le medId associe au fichier Med apres ouverture
1262 // =======================================================================
1263 med_idt OuvrirFichier(QString aFile)
1265 med_idt medIdt = MEDfileOpen(aFile.toStdString().c_str(),MED_ACC_RDONLY);
1268 QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
1269 QObject::tr("MG_ADAPT_MED_FILE_1") );
1274 // ======================================================
1275 // ========================================================
1276 QString lireNomMaillage(QString aFile, med_int& meshdim)
1278 QString nomMaillage = QString::null ;
1282 // Ouverture du fichier
1283 medIdt = OuvrirFichier(aFile);
1289 med_int numberOfMeshes = MEDnMesh(medIdt) ;
1290 if (numberOfMeshes == 0 )
1292 QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
1293 QObject::tr("MG_ADAPT_MED_FILE_2") );
1297 if (numberOfMeshes > 1 )
1299 QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
1300 QObject::tr("MG_ADAPT_MED_FILE_3") );
1305 nomMaillage = lireNomMaillage2(medIdt,1, meshdim);
1306 // Fermeture du fichier
1307 if ( medIdt > 0 ) MEDfileClose(medIdt);
1312 // =======================================================================
1313 // =======================================================================
1314 QString lireNomMaillage2(med_idt medIdt,int meshId, med_int& meshdim )
1316 QString NomMaillage=QString::null;
1317 char meshname[MED_NAME_SIZE+1];
1319 med_mesh_type meshtype;
1320 char descriptionription[MED_COMMENT_SIZE+1];
1321 char dtunit[MED_SNAME_SIZE+1];
1322 med_sorting_type sortingtype;
1324 med_axis_type axistype;
1325 int naxis = MEDmeshnAxis(medIdt,1);
1326 char *axisname=new char[naxis*MED_SNAME_SIZE+1];
1327 char *axisunit=new char[naxis*MED_SNAME_SIZE+1];
1328 med_err aRet = MEDmeshInfo(medIdt,
1343 QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"), \
1344 QObject::tr("MG_ADAPT_MED_FILE_4") );
1347 NomMaillage=QString(meshname);
1356 // =======================================================================
1357 std::map<QString, int> GetListeChamps(QString aFile, bool errorMessage)
1358 // =======================================================================
1360 // Il faut voir si plusieurs maillages
1362 MESSAGE("GetListeChamps");
1363 std::map<QString, int> ListeChamp ;
1365 med_err erreur = 0 ;
1368 while ( erreur == 0 )
1370 // Ouverture du fichier
1371 SCRUTE(aFile.toStdString());
1372 medIdt = OuvrirFichier(aFile);
1378 // Lecture du nombre de champs
1379 med_int ncha = MEDnField(medIdt) ;
1384 QMessageBox::critical( 0, QObject::tr("_ERROR"),
1385 QObject::tr("HOM_MED_FILE_5") );
1390 // Lecture des caracteristiques des champs
1391 for (int i=0; i< ncha; i++)
1393 // Lecture du nombre de composantes
1394 med_int ncomp = MEDfieldnComponent(medIdt,i+1);
1395 // Lecture du type du champ, des noms des composantes et du nom de l'unite
1396 char nomcha [MED_NAME_SIZE+1];
1397 char meshname[MED_NAME_SIZE+1];
1398 char * comp = (char*) malloc(ncomp*MED_SNAME_SIZE+1);
1399 char * unit = (char*) malloc(ncomp*MED_SNAME_SIZE+1);
1400 char dtunit[MED_SNAME_SIZE+1];
1402 med_field_type typcha;
1404 erreur = MEDfieldInfo(medIdt,i+1,nomcha,meshname,&local,&typcha,comp,unit,dtunit,&nbofcstp) ;
1411 QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
1412 QObject::tr("MG_ADAPT_MED_FILE_6") );
1417 ListeChamp.insert(std::pair<QString, int> (QString(nomcha), nbofcstp));
1422 // Fermeture du fichier
1423 if ( medIdt > 0 ) MEDfileClose(medIdt);
1428 std::string remove_extension(const std::string& filename)
1430 size_t lastdot = filename.find_last_of(".");
1431 if (lastdot == std::string::npos) return filename;
1432 return filename.substr(0, lastdot);