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 "SMESH_Actor.h"
34 #include <SUIT_MessageBox.h>
35 //~#include <SMESH_TypeFilter.hxx>
36 //~#include <SMESH_MeshAlgos.hxx>
37 //~#include <SMESH_LogicalFilter.hxx>
38 //~#include <SMDS_Mesh.hxx>
39 //~#include <SMDS_MeshNode.hxx>
40 #include <LightApp_SelectionMgr.h>
41 #include <SUIT_OverrideCursor.h>
42 #include <SUIT_ResourceMgr.h>
43 #include <SVTK_ViewWindow.h>
44 #include <SALOME_ListIO.hxx>
45 #include <SUIT_FileDlg.h>
46 #include <QApplication>
47 #include <QButtonGroup>
48 #include <QGridLayout>
50 #include <QHBoxLayout>
55 #include <QPushButton>
56 #include <QRadioButton>
58 #include <QVBoxLayout>
59 #include <QDoubleSpinBox>
61 #include <QTreeWidget>
62 #include <QTreeWidgetItem>
63 #include <QSpacerItem>
65 #include <QHeaderView>
66 #include <QItemDelegate>
67 #include <QFileDialog>
68 #include <QMessageBox>
71 #include <vtkPoints.h>
72 #include <vtkUnstructuredGrid.h>
73 #include <vtkIdList.h>
74 #include <vtkCellArray.h>
75 #include <vtkUnsignedCharArray.h>
76 #include <vtkDataSetMapper.h>
77 #include <VTKViewer_CellLocationsArray.h>
78 #include <vtkProperty.h>
81 // SALOME KERNEL includes
82 #include <SALOMEDS_SComponent.hxx>
83 #include <SALOMEDS_SObject.hxx>
84 #include <SALOMEDS_Study.hxx>
85 #include <SALOMEDS_wrap.hxx>
86 #include "SalomeApp_Tools.h"
87 #include <SALOMEconfig.h>
89 #include <utilities.h>
91 #include <TCollection_AsciiString.hxx>
94 const int SPACING = 6; // layout spacing
95 const int MARGIN = 9; // layout margin
97 //=================================================================================
98 // function : SMESHGUI_MgAdaptDlg()
100 //=================================================================================
101 SMESHGUI_MgAdaptDlg::SMESHGUI_MgAdaptDlg( SalomeApp_Module* theModule, SMESH::MG_ADAPT_ptr myModel, QWidget* parent, bool isCreation )
102 : mySMESHGUI( theModule ), QDialog(parent)
104 //~model = new MgAdapt(*myModel);
105 model = SMESH::MG_ADAPT::_duplicate(myModel);
106 myData = model->getData();
108 if (!isCreation) readParamsFromHypo();
111 void SMESHGUI_MgAdaptDlg::buildDlg()
114 setAttribute( Qt::WA_DeleteOnClose, true );
115 setWindowTitle( tr( "ADAPT_PREF_MG_ADAPT" ) );
116 setSizeGripEnabled( true );
119 myTabWidget = new QTabWidget( this );
123 myArgs = new SMESHGUI_MgAdaptArguments( myTabWidget );
124 SMESH::str_array* str = model->getOptionValuesStrVec();
125 SMESH::str_array* str2 = model->getCustomOptionValuesStrVec();
126 std::vector<std::string> s;
127 for (int i = 0; i< str->length(); i++) s.push_back( (*str)[i].in());
128 for (int j = str->length(); j< str2->length(); j++) s.push_back((*str2)[ j - str->length() ].in() );
129 //~str.insert( str.end(), str2.begin(), str2.end() );
131 myAdvOpt = new MgAdaptAdvWidget(myTabWidget, &s);
133 int argsTab = myTabWidget->addTab( myArgs, tr( "Args" ) );
134 int advTab = myTabWidget->addTab( myAdvOpt, tr( "ADVOP" ) );
136 myAdvOpt->workingDirectoryLabel ->setText (tr( "WORKING_DIR" ));
137 myAdvOpt->workingDirectoryPushButton ->setText (tr( "SELECT_DIR" ));
138 myAdvOpt->keepWorkingFilesCheck ->setText (tr( "KEEP_WORKING_FILES" ));
139 myAdvOpt->verboseLevelLabel ->setText (tr( "VERBOSE_LEVEL" ));
140 myAdvOpt->removeLogOnSuccessCheck ->setText (tr( "REMOVE_LOG_ON_SUCCESS" ));
141 myAdvOpt->logInFileCheck ->setText (tr( "LOG_IN_FILE" ));
142 myAdvOpt->logGroupBox ->setTitle(tr( "LOG_GROUP_TITLE" ));
145 QPushButton* okBtn = new QPushButton( tr( "SMESH_BUT_OK" ), this );
146 okBtn->setAutoDefault( true );
147 okBtn->setDefault( true );
149 QPushButton* buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), this);
150 buttonApply->setAutoDefault(true);
151 QPushButton* buttonApplyAndClose = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), this);
152 buttonApplyAndClose->setAutoDefault(true);
153 QPushButton* cancelBtn = new QPushButton( tr( "SMESH_BUT_CANCEL" ), this );
154 cancelBtn->setAutoDefault( true );
155 QPushButton* helpBtn = new QPushButton( tr( "SMESH_BUT_HELP" ), this );
156 helpBtn->setAutoDefault( true );
158 QHBoxLayout* btnLayout = new QHBoxLayout;
159 btnLayout->setSpacing( SPACING );
160 btnLayout->setMargin( 0 );
161 btnLayout->addWidget( buttonApplyAndClose );
162 btnLayout->addStretch( 10 );
163 btnLayout->addWidget( buttonApply );
164 btnLayout->addStretch( 10 );
165 btnLayout->addWidget( okBtn );
166 btnLayout->addStretch( 10 );
167 btnLayout->addWidget( cancelBtn );
168 btnLayout->addStretch( 10 );
169 btnLayout->addWidget( helpBtn );
170 okBtn->hide(); // tab 1
172 QVBoxLayout* l = new QVBoxLayout ( this );
173 l->setMargin( MARGIN );
174 l->setSpacing( SPACING );
175 l->addWidget( myTabWidget );
177 l->addLayout( btnLayout );
180 connect( okBtn, SIGNAL( clicked() ), this, SLOT( clickOnOk() ) );
181 connect( helpBtn, SIGNAL( clicked() ), this, SLOT( clickOnHelp() ) );
182 connect(cancelBtn, SIGNAL(clicked()), this, SLOT(reject()));
183 connect(buttonApply, SIGNAL(clicked()), this,SLOT(clickOnApply()));
184 connect(buttonApplyAndClose, SIGNAL(clicked()), this,SLOT(clickOnOk()));
185 connect(myArgs, SIGNAL(meshDimSignal(ADAPTATION_MODE)), myAdvOpt, SLOT( onMeshDimChanged(ADAPTATION_MODE)) );
189 //=================================================================================
190 // function : ~SMESHGUI_MgAdaptDlg()
191 // purpose : Destroys the object and frees any allocated resources
192 //=================================================================================
193 SMESHGUI_MgAdaptDlg::~SMESHGUI_MgAdaptDlg()
198 //~void SMESHGUI_MgAdaptDlg::setModel(MgAdapt* mg)
202 SMESH::MG_ADAPT_ptr SMESHGUI_MgAdaptDlg::getModel() const
207 \brief Perform clean-up actions on the dialog box closing.
209 bool SMESHGUI_MgAdaptDlg::clickOnApply()
211 readParamsFromWidgets();
214 void SMESHGUI_MgAdaptDlg::clickOnOk()
219 void SMESHGUI_MgAdaptDlg::reject()
223 bool SMESHGUI_MgAdaptDlg::readParamsFromHypo( ) const
226 myArgs->aMedfile->setChecked(myData->fromMedFile) ;
227 if (myData->fromMedFile)
230 *(myArgs->myFileInDir) = QString(myData->myFileInDir) ;
231 myArgs->selectMedFileLineEdit->setText(QString(myData->myMeshFileIn)) ;
232 // myData->myInMeshName = // TODO
237 myArgs->aBrowserObject->setText(QString(myData->myInMeshName));
238 //~ myArgs->myFileInDir =""; // TODO
239 //~ myArgs->selectMedFileLineEdit->setText(); // TODO
241 myArgs->meshNameLineEdit->setText(QString(myData->myOutMeshName));
242 myArgs->medFileCheckBox->setChecked(myData->myMeshOutMed);
244 if(myData->myMeshOutMed)
246 *(myArgs->myFileOutDir) = QString(myData->myFileOutDir);
247 myArgs->selectOutMedFileLineEdit->setText(QString(myData->myMeshFileOut));
252 *(myArgs->myFileOutDir) = QString(""); //TODO
255 myArgs->publishOut->setChecked(myData->myPublish);
257 myArgs->localButton->setChecked(myData->myUseLocalMap);
258 myArgs->backgroundButton->setChecked(myData->myUseBackgroundMap);
259 myArgs->constantButton->setChecked(myData->myUseConstantValue);
261 if (myData->myUseConstantValue)
263 myArgs->dvalue->setValue(myData->myConstantValue);
267 myArgs->dvalue->setValue(0.0);
270 if (myData->myUseBackgroundMap)
273 *(myArgs->myFileSizeMapDir) = QString(myData->myFileSizeMapDir) ;
274 myArgs->selectMedFileBackgroundLineEdit->setText(QString(myData->myMeshFileBackground));
278 *(myArgs->myFileSizeMapDir) = QString("") ; //TODO
279 myArgs->selectMedFileBackgroundLineEdit->setText(""); //TODO
282 myArgs->fieldNameCmb->setCurrentText(QString(myData->myFieldName));
283 myArgs->noTimeStep->setChecked(myData->myUseNoTimeStep);
284 myArgs->lastTimeStep->setChecked( myData->myUseLastTimeStep);
285 myArgs->chosenTimeStep->setChecked(myData->myUseChosenTimeStep);
286 if (myData->myUseChosenTimeStep)
288 myArgs->rankSpinBox->setValue(myData->myRank);
289 myArgs->timeStep->setValue(myData->myTimeStep);
292 myAdvOpt->workingDirectoryLineEdit->setText(QString(myData->myWorkingDir));
293 myAdvOpt->logInFileCheck->setChecked(myData->myPrintLogInFile);
295 myAdvOpt->verboseLevelSpin->setValue(myData->myVerboseLevel);
296 myAdvOpt->removeLogOnSuccessCheck->setChecked(myData->myRemoveLogOnSuccess);
297 myAdvOpt->keepWorkingFilesCheck->setChecked(myData->myKeepFiles);
304 bool SMESHGUI_MgAdaptDlg::readParamsFromWidgets()
307 SMESH::MgAdaptHypothesisData* aData = new SMESH::MgAdaptHypothesisData();
308 aData->fromMedFile = myArgs->aMedfile->isChecked();
309 if (aData->fromMedFile)
312 aData->myFileInDir = CORBA::string_dup(myArgs->myFileInDir->toStdString().c_str());
313 aData->myMeshFileIn = CORBA::string_dup(myArgs->selectMedFileLineEdit->text().toStdString().c_str());
314 // aData->myInMeshName = // TODO
318 aData->myInMeshName = CORBA::string_dup(myArgs->aBrowserObject->text().toStdString().c_str());
319 aData->myFileInDir = CORBA::string_dup(myAdvOpt->workingDirectoryLineEdit->text().toStdString().c_str());
321 TCollection_AsciiString aGenericName = (char*)aData->myFileInDir;
322 TCollection_AsciiString aGenericName2 = "MgAdapt_";
323 aGenericName2 += getpid();
324 aGenericName2 += "_";
325 aGenericName2 += Abs((Standard_Integer)(long) aGenericName.ToCString());
326 aGenericName2 += ".med";
327 aGenericName+=aGenericName2;
328 emit myArgs->toExportMED(aGenericName.ToCString());
329 aData->myMeshFileIn = aGenericName2.ToCString();
331 aData->myOutMeshName = CORBA::string_dup(myArgs->meshNameLineEdit->text().toStdString().c_str());
332 aData->myMeshOutMed = myArgs->medFileCheckBox->isChecked();
333 if(aData->myMeshOutMed)
335 aData->myFileOutDir = CORBA::string_dup(myArgs->myFileOutDir->toStdString().c_str());
336 aData->myMeshFileOut = CORBA::string_dup(myArgs->selectOutMedFileLineEdit->text().toStdString().c_str());
341 aData->myMeshFileOut = "";
344 aData->myPublish = myArgs->publishOut->isChecked();
347 aData->myUseLocalMap = myArgs->localButton->isChecked();
348 aData->myUseBackgroundMap = myArgs->backgroundButton->isChecked();
349 aData->myUseConstantValue = myArgs->constantButton->isChecked();
350 if (aData->myUseConstantValue)
352 aData->myConstantValue = myArgs->dvalue->value();
356 aData->myConstantValue = 0.0;
358 if (aData->myUseBackgroundMap)
360 aData->myFileSizeMapDir = CORBA::string_dup(myArgs->myFileSizeMapDir->toStdString().c_str());
361 aData->myMeshFileBackground = CORBA::string_dup(myArgs->selectMedFileBackgroundLineEdit->text().toStdString().c_str());
365 aData->myMeshFileBackground = "";
368 aData->myFieldName = CORBA::string_dup(myArgs->fieldNameCmb->currentText().toStdString().c_str());
369 aData->myUseNoTimeStep = myArgs->noTimeStep->isChecked();
370 aData->myUseLastTimeStep = myArgs->lastTimeStep->isChecked();
371 aData->myUseChosenTimeStep = myArgs->chosenTimeStep->isChecked();
372 if (aData->myUseChosenTimeStep)
374 aData->myRank = myArgs->rankSpinBox->value();
375 aData->myTimeStep = myArgs->timeStep->value();
380 aData->myWorkingDir = CORBA::string_dup(myAdvOpt->workingDirectoryLineEdit->text().toStdString().c_str());
381 aData->myPrintLogInFile = myAdvOpt->logInFileCheck->isChecked();
382 aData->myVerboseLevel = myAdvOpt->verboseLevelSpin->value();
383 aData->myRemoveLogOnSuccess = myAdvOpt->removeLogOnSuccessCheck->isChecked();
384 aData->myKeepFiles = myAdvOpt->keepWorkingFilesCheck->isChecked();
385 model->setData(*aData);
391 bool SMESHGUI_MgAdaptDlg::storeParamsToHypo( const SMESH::MgAdaptHypothesisData& ) const
396 \brief Show help page
398 void SMESHGUI_MgAdaptDlg::clickOnHelp()
400 // QString aHelpFile;
401 // if ( myTabWidget->currentIndex() == MinDistance ) {
402 // aHelpFile = "measurements.html#min-distance-anchor";
403 // } else if ( myTabWidget->currentIndex() == BoundingBox ) {
404 // aHelpFile = "measurements.html#bounding-box-anchor";
405 // } else if ( myTabWidget->currentWidget() == myAngle ) {
406 // aHelpFile = "measurements.html#angle-anchor";
408 // aHelpFile = "measurements.html#basic-properties-anchor";
411 // SMESH::ShowHelpFile( aHelpFile );
413 bool SMESHGUI_MgAdaptDlg::checkParams(QString& msg)
415 if ( !QFileInfo( myAdvOpt->workingDirectoryLineEdit->text().trimmed() ).isWritable() ) {
416 SUIT_MessageBox::warning( this,
417 tr( "SMESH_WRN_WARNING" ),
418 tr( "GHS3D_PERMISSION_DENIED" ) );
423 myAdvOpt->myOptionTable->setFocus();
424 QApplication::instance()->processEvents();
427 bool isDefault, ok = true;
428 int iRow = 0, nbRows = myAdvOpt->myOptionTable->topLevelItemCount();
429 for ( ; iRow < nbRows; ++iRow )
431 QTreeWidgetItem* row = myAdvOpt->myOptionTable->topLevelItem( iRow );
432 myAdvOpt->GetOptionAndValue( row, name, value, isDefault );
434 if ( name.simplified().isEmpty() )
435 continue; // invalid custom option
437 if ( isDefault ) // not selected option
441 model->setOptionValue( name.toLatin1().constData(), value.toLatin1().constData() );
443 catch ( const SALOME::SALOME_Exception& ex )
445 msg = ex.details.text.in();
455 //=================================================================================
456 // function : SMESHGUI_MgAdaptArguments()
458 //=================================================================================
459 SMESHGUI_MgAdaptArguments::SMESHGUI_MgAdaptArguments( QWidget* parent )
464 myFileInDir = new QString("");
465 myFileOutDir = new QString("");
466 myFileSizeMapDir = new QString("");
467 if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
469 *myFileInDir = QDir::currentPath();
470 *myFileOutDir = QDir::currentPath();
471 *myFileSizeMapDir = QDir::currentPath();
475 *myFileInDir = SUIT_FileDlg::getLastVisitedPath();
476 *myFileOutDir = SUIT_FileDlg::getLastVisitedPath();
477 *myFileSizeMapDir = SUIT_FileDlg::getLastVisitedPath();
482 aMeshIn = new QGroupBox( tr( "MeshIn" ), this );
483 aMedfile = new QRadioButton( tr( "MEDFile" ), aMeshIn );
484 aBrowser = new QRadioButton( tr( "Browser" ), aMeshIn );
485 aBrowserObject = new QLineEdit( aMeshIn );
486 selectMedFilebutton = new QPushButton("", aMeshIn);
487 selectMedFileLineEdit = new QLineEdit( aMeshIn );
489 meshIn = new QGridLayout( aMeshIn );
491 meshIn->setMargin( MARGIN );
492 meshIn->setSpacing( SPACING );
493 meshIn->addWidget( aMedfile, 0, 0, 1,1 );
494 meshIn->addWidget( aBrowser, 0, 1,1,1);
495 meshIn->addWidget( aBrowserObject, 0, 2, 1, 1 );
496 meshIn->addWidget( selectMedFilebutton, 1, 0,1, 1);
497 meshIn->addWidget( selectMedFileLineEdit, 1, 1, 1, 1 );
498 hspacer = new QSpacerItem(188, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
500 meshInGroup = new QButtonGroup( this );
501 meshInGroup->addButton( aMedfile, 0 );
502 meshInGroup->addButton( aBrowser, 1 );
506 aMeshOut = new QGroupBox( tr( "MeshOut" ), this );
507 meshName = new QLabel(tr("MeshName"), aMeshOut);
508 secondHspacer = new QSpacerItem(100, 30);
509 meshNameLineEdit = new QLineEdit(aMeshOut) ;
510 medFileCheckBox = new QCheckBox(tr("MEDFile"), aMeshOut);
511 selectOutMedFilebutton = new QPushButton("", aMeshOut);
512 thirdHspacer = new QSpacerItem(188, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
513 selectOutMedFileLineEdit = new QLineEdit(aMeshOut) ;
514 publishOut = new QCheckBox(tr("Publish_MG_ADAPT"), aMeshOut);
516 meshOut = new QGridLayout( aMeshOut );
518 meshOut->setMargin( MARGIN );
519 meshOut->setSpacing( SPACING );
520 meshOut->addWidget( meshName, 0, 0, 1,1 );
521 meshOut->addItem( secondHspacer, 0, 1, 1, 1 );
522 meshOut->addWidget( meshNameLineEdit, 0, 2,1,1);
523 meshOut->addWidget( medFileCheckBox, 1, 0,1,1 );
524 meshOut->addWidget( selectOutMedFilebutton, 1, 1,1,1 );
525 meshOut->addWidget( selectOutMedFileLineEdit, 1, 2,1,1);
526 meshOut->addWidget( publishOut, 2, 0,1,1 );
528 //size map definition
530 sizeMapDefinition = new QGroupBox(tr("SIZE_MAP_DEF"), this);
531 localButton = new QRadioButton(tr("LOCAL_MG_ADAPT"), sizeMapDefinition);
532 backgroundButton = new QRadioButton(tr("BACKGRND_MG_ADAPT"), sizeMapDefinition);
533 constantButton = new QRadioButton(tr("CNST_MG_ADAPT"), sizeMapDefinition);
534 medFileBackground = new QLabel(tr("MED_FILE_BCKG"), sizeMapDefinition);
535 selectMedFileBackgroundbutton = new QPushButton(tr(""), sizeMapDefinition);
536 selectMedFileBackgroundLineEdit = new QLineEdit(sizeMapDefinition);
537 valueLabel = new QLabel(tr("VALUE_MG_ADAPT"), sizeMapDefinition);
538 dvalue = new QDoubleSpinBox(sizeMapDefinition);
539 sizeMapDefGroup = new QButtonGroup( this );
540 sizeMapDefGroup->addButton( localButton, 0 );
541 sizeMapDefGroup->addButton( backgroundButton, 1 );
542 sizeMapDefGroup->addButton( constantButton, 2 );
544 sizeMapDefGroupLayout = new QGridLayout(sizeMapDefinition);
545 sizeMapDefGroupLayout->addWidget(localButton, 0,0);
546 sizeMapDefGroupLayout->addWidget(backgroundButton, 0,1);
547 sizeMapDefGroupLayout->addWidget(constantButton, 0,2);
548 sizeMapDefGroupLayout->addWidget(medFileBackground, 1,0);
549 sizeMapDefGroupLayout->addWidget(selectMedFileBackgroundbutton, 1,1);
550 sizeMapDefGroupLayout->addWidget(selectMedFileBackgroundLineEdit, 1,2);
551 sizeMapDefGroupLayout->addWidget(valueLabel, 2,0);
552 sizeMapDefGroupLayout->addWidget(dvalue, 2,1);
555 sizeMapField = new QGroupBox(tr("SIZE_MAP_FIELD"), this);
556 fieldName = new QLabel(tr("MG_ADAPT_FIELD_NAME"), sizeMapField);
557 fieldNameCmb = new QComboBox(sizeMapField);
558 noTimeStep = new QRadioButton(tr("MG_ADAPT_NO_T_ST"), sizeMapField);
559 lastTimeStep = new QRadioButton(tr("MG_ADAPT_L_ST"), sizeMapField);
560 chosenTimeStep = new QRadioButton(tr("MG_ADAPT_CH_ST"), sizeMapField);
561 timeStepLabel = new QLabel(tr("MG_ADAPT_TSTP"), sizeMapField);
562 timeStep = new QSpinBox(sizeMapField);
563 //~timeStep->setMinimum(-1);
564 rankLabel = new QLabel(tr("MG_ADAPT_RANK"), sizeMapField);
565 rankSpinBox = new QSpinBox(sizeMapField);
566 rankSpinBox->setMinimum(-1);
568 timeStepGroup = new QButtonGroup(this);
569 timeStepGroup->addButton(noTimeStep, 0);
570 timeStepGroup->addButton(lastTimeStep, 1);
571 timeStepGroup->addButton(chosenTimeStep, 2);
573 sizeMapFieldGroupLayout = new QGridLayout(sizeMapField);
575 sizeMapFieldGroupLayout->addWidget(fieldName, 0,0);
576 sizeMapFieldGroupLayout->addWidget(fieldNameCmb, 0,1);
577 sizeMapFieldGroupLayout->addWidget(noTimeStep, 1,0);
578 sizeMapFieldGroupLayout->addWidget(lastTimeStep, 1,1);
579 sizeMapFieldGroupLayout->addWidget(chosenTimeStep, 1,2);
580 sizeMapFieldGroupLayout->addWidget(timeStepLabel, 2,0);
581 sizeMapFieldGroupLayout->addWidget(timeStep, 2,1);
582 sizeMapFieldGroupLayout->addWidget(rankLabel, 2,2);
583 sizeMapFieldGroupLayout->addWidget(rankSpinBox, 2,3);
586 QGridLayout* argumentsLayout = new QGridLayout( this );
587 argumentsLayout->setMargin( MARGIN );
588 argumentsLayout->setSpacing( SPACING );
590 argumentsLayout->addWidget( aMeshIn, 0, 0, 1, 3 );
591 argumentsLayout->addWidget( aMeshOut, 1, 0, 1, 3 );
592 argumentsLayout->addWidget( sizeMapDefinition, 2, 0, 1, 3 );
593 argumentsLayout->addWidget( sizeMapField, 3, 0, 1, 3 );
594 argumentsLayout->setColumnStretch( 1, 5 );
595 argumentsLayout->setRowStretch( 4, 5 );
598 setMode( Mesh, Local);
599 medFileCheckBox->setChecked(true);
602 connect( meshInGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( modeChanged( int ) ) );
603 connect( sizeMapDefGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( sizeMapDefChanged( int ) ) );
604 connect( selectMedFilebutton, SIGNAL( pressed( ) ), this, SLOT( onSelectMedFilebuttonClicked( ) ) );
605 connect(medFileCheckBox, SIGNAL (stateChanged(int)), this, SLOT(onMedFileCheckBox(int) ) );
606 connect(publishOut, SIGNAL (stateChanged(int)), this, SLOT(onPublishOut(int) ) );
607 connect(selectOutMedFilebutton, SIGNAL( pressed()), this, SLOT(onSelectOutMedFilebutton()));
608 connect(selectMedFileBackgroundbutton, SIGNAL(pressed()), this, SLOT(onSelectMedFileBackgroundbutton()) );
609 connect( timeStepGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( timeStepGroupChanged( int ) ) );
610 emit updateSelection();
613 //=================================================================================
614 // function : ~SMESHGUI_MgAdaptArguments()
615 // purpose : Destroys the object and frees any allocated resources
616 //=================================================================================
617 SMESHGUI_MgAdaptArguments::~SMESHGUI_MgAdaptArguments()
621 void SMESHGUI_MgAdaptArguments::onNoTimeStep(bool disableOther)
623 noTimeStep->setChecked(true);
625 rankLabel->setVisible(0);
626 rankSpinBox->setVisible(0);
627 rankSpinBox->setValue(-2);
629 timeStepLabel->setVisible(0);
630 timeStep->setVisible(0);
631 timeStep->setValue(-2);
633 lastTimeStep->setDisabled(disableOther);
634 chosenTimeStep->setDisabled(disableOther);
638 void SMESHGUI_MgAdaptArguments::onLastTimeStep(bool disableOther)
640 lastTimeStep->setChecked(true);
642 rankLabel->setVisible(0);
643 rankSpinBox->setVisible(0);
644 rankSpinBox->setValue(-1);
646 timeStepLabel->setVisible(0);
647 timeStep->setVisible(0);
648 timeStep->setValue(-1);
649 noTimeStep->setDisabled(disableOther);
652 void SMESHGUI_MgAdaptArguments::onChosenTimeStep(bool disableOther, int max)
654 chosenTimeStep->setChecked(true);
656 rankLabel->setVisible(1);
657 rankSpinBox->setVisible(1);
658 rankSpinBox->setValue(0);
660 timeStepLabel->setVisible(1);
661 timeStep->setVisible(1);
662 timeStep->setValue(0);
663 if (max) timeStep->setMaximum(max);
667 void SMESHGUI_MgAdaptArguments::onSelectOutMedFilebutton()
670 QString filtre = QString("Med") ;
671 filtre += QString(" files (*.") + QString("med") + QString(");;");
672 QString fileName = QFileDialog::getSaveFileName(this, tr("SAVE_MED"),
673 QString(""), filtre);
674 QFileInfo myFileInfo(fileName);
675 selectOutMedFileLineEdit->setText(myFileInfo.fileName());
676 *myFileOutDir = myFileInfo.path();
679 void SMESHGUI_MgAdaptArguments::onSelectMedFileBackgroundbutton()
681 QString fileName0 = selectMedFileBackgroundbutton->text().trimmed();
683 QString fileName = getMedFileName(false);
684 if (fileName != QString::null)
686 myFieldList = GetListeChamps(fileName);
687 if (myFieldList.empty())
689 fileName = fileName0;
690 fieldNameCmb->clear();
694 // fill field name Combobox
695 fieldNameCmb->clear();
696 std::map<QString, int>::const_iterator it;
697 for ( it=myFieldList.begin() ; it != myFieldList.end(); it++)
699 fieldNameCmb->insertItem(0,QString(it->first));
700 int typeStepInField = it->second > 2 ? 2 : it->second ;
701 timeStepGroupChanged(typeStepInField, true);
709 fileName = fileName0;
710 fieldNameCmb->clear();
713 QFileInfo myFileInfo(fileName);
714 *myFileSizeMapDir = myFileInfo.path();
715 selectMedFileBackgroundLineEdit->setText(myFileInfo.fileName());
718 void SMESHGUI_MgAdaptArguments::onMedFileCheckBox(int state)
720 if (state == Qt::Checked)
722 selectOutMedFilebutton->show();
723 selectOutMedFileLineEdit->show();
724 selectOutMedFilebutton->setEnabled(true);
725 selectOutMedFileLineEdit->setEnabled(true);
729 selectOutMedFilebutton->setEnabled(false);
730 selectOutMedFileLineEdit->setEnabled(false);
731 publishOut->setChecked(true);
734 void SMESHGUI_MgAdaptArguments::onPublishOut(int state)
736 if (state == Qt::Unchecked)
738 medFileCheckBox->setChecked(true);
742 void SMESHGUI_MgAdaptArguments::onSelectMedFilebuttonClicked()
744 // bool keep = false;
745 QString fileName0 = selectMedFileLineEdit->text().trimmed();
747 QString fileName = getMedFileName(false);
748 if(fileName != QString::null)
750 QString aMeshName = lireNomMaillage(fileName.trimmed(), meshDim);
751 if (aMeshName == QString::null )
753 QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
754 QObject::tr("MG_ADAPT_MED_FILE_2") );
755 fileName = fileName0;
759 meshNameLineEdit->setText(aMeshName);
760 ADAPTATION_MODE aMode = meshDim == 3 ? ADAPTATION_MODE::BOTH : ADAPTATION_MODE::SURFACE; // and when dimesh 3 without 2D mesh?
761 emit meshDimSignal(aMode);
771 QFileInfo myFileInfo(fileName);
772 *myFileInDir = myFileInfo.path();
773 *myFileOutDir = myFileInfo.path();
774 selectMedFileLineEdit->setText(myFileInfo.fileName());
775 QString outF = fileName == QString::null ? myFileInfo.fileName() :
776 QString( remove_extension(myFileInfo.fileName().toStdString() ).c_str() )+ QString(".adapt.med");
777 selectOutMedFileLineEdit->setText(outF);
778 onLocalSelected(myFileInfo.filePath());
782 void SMESHGUI_MgAdaptArguments::onLocalSelected(QString filePath)
784 myFieldList = GetListeChamps(filePath, false);
785 if (myFieldList.empty())
787 if (localButton->isChecked())
789 fieldNameCmb->clear();
795 // fill field name Combobox
796 fieldNameCmb->clear();
797 std::map<QString, int>::const_iterator it;
798 for ( it = myFieldList.begin() ; it != myFieldList.end(); it++)
800 fieldNameCmb->insertItem(0,QString(it->first));
801 int typeStepInField = it->second > 2 ? 2 : it->second ;
802 timeStepGroupChanged(typeStepInField, true);
807 // =======================================================================
808 // Gestion les boutons qui permettent de
809 // 1) retourne le nom d'un fichier par une fenetre de dialogue si aucun
810 // objet est selectionne dans l arbre d etude
811 // 2) retourne le nom du fichier asocie a l objet
812 // selectionne dans l arbre d etude
813 // =======================================================================
814 QString SMESHGUI_MgAdaptArguments::getMedFileName(bool avertir)
817 QString aFile = QString::null;
818 QString filtre = QString("Med") ;
819 filtre += QString(" files (*.") + QString("med") + QString(");;");
820 aFile = SUIT_FileDlg::getOpenFileName(0, QObject::tr("MG_ADAPT_SELECT_FILE_0"), QString(""), filtre );
825 void SMESHGUI_MgAdaptArguments::setMode(const Mode theMode, const SIZEMAP theSizeMap )
827 QRadioButton* aButton = qobject_cast<QRadioButton*>( meshInGroup->button( theMode ) );
828 QRadioButton* bButton = qobject_cast<QRadioButton*>( sizeMapDefGroup->button( theSizeMap ) );
830 aButton->setChecked( true );
831 modeChanged( theMode );
834 bButton->setChecked( true );
835 sizeMapDefChanged( theSizeMap );
839 void SMESHGUI_MgAdaptArguments::modeChanged( int theMode )
844 aBrowserObject->hide();
845 selectMedFileLineEdit->show();
846 selectMedFilebutton->show();
847 localButton->setEnabled(true);
851 selectMedFileLineEdit->hide();
852 selectMedFilebutton->hide();
853 localButton->setEnabled(false);
854 aBrowserObject->show();
855 sizeMapDefChanged(Background);
856 emit updateSelection();
863 void SMESHGUI_MgAdaptArguments::sizeMapDefChanged( int theSizeMap )
865 fieldNameCmb->clear();
866 if(theSizeMap == Local)
868 localButton->setEnabled(true);
869 localButton->setChecked(true);
870 medFileBackground->hide();
871 selectMedFileBackgroundbutton->hide();
872 selectMedFileBackgroundLineEdit->hide();
873 selectMedFileBackgroundLineEdit->clear();
877 sizeMapField->setEnabled(true);
878 if (!selectMedFileLineEdit->text().isEmpty())
880 QFileInfo myFileInfo(QDir(*myFileInDir), selectMedFileLineEdit->text());
881 onLocalSelected(myFileInfo.filePath());
884 else if (theSizeMap == Background)
886 medFileBackground->show();
887 backgroundButton->setChecked(true);
888 selectMedFileBackgroundbutton->show();
889 selectMedFileBackgroundLineEdit->show();
892 sizeMapField->setEnabled(true);
897 medFileBackground->hide();
898 constantButton->setChecked(true);
899 selectMedFileBackgroundbutton->hide();
900 selectMedFileBackgroundLineEdit->clear();
901 selectMedFileBackgroundLineEdit->hide();
904 sizeMapField->setEnabled(false);
910 void SMESHGUI_MgAdaptArguments::timeStepGroupChanged(int timeStepType, bool disableOther, int max)
912 switch (timeStepType)
915 onNoTimeStep(disableOther);
918 onLastTimeStep(disableOther);
921 onChosenTimeStep(disableOther, max);
927 void SMESHGUI_MgAdaptArguments::clear()
929 selectMedFileLineEdit->clear();
930 aBrowserObject->clear();
932 meshNameLineEdit->clear();
933 selectOutMedFileLineEdit->clear();
935 med_int SMESHGUI_MgAdaptArguments::getMeshDim() const
939 QWidget* ItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &o, const QModelIndex &index) const
941 bool editable = index.data( EDITABLE_ROLE ).toInt();
942 return editable ? QItemDelegate::createEditor( parent, o, index ) : 0;
945 //////////////////////////////////////////
947 //////////////////////////////////////////
949 MgAdaptAdvWidget::MgAdaptAdvWidget( QWidget* parent, std::vector <std::string>* options, Qt::WindowFlags f )
950 : QWidget( parent, f ), myOptions(options)
953 myOptionTable->header()->setSectionResizeMode( QHeaderView::ResizeToContents );
954 myOptionTable->setItemDelegate( new ItemDelegate( myOptionTable ) );
956 for ( int i = 0, nb = myOptions->size(); i < nb; ++i )
958 AddOption( (*myOptions)[i].c_str() );
961 connect( myOptionTable, SIGNAL( itemChanged(QTreeWidgetItem *, int)), SLOT( itemChanged(QTreeWidgetItem *, int )));
962 connect( addBtn, SIGNAL( clicked() ), this, SLOT( onAddOption() ) );
963 connect(workingDirectoryPushButton, SIGNAL(pressed()), this, SLOT(_onWorkingDirectoryPushButton()));
966 MgAdaptAdvWidget::~MgAdaptAdvWidget()
970 void MgAdaptAdvWidget::AddOption( const char* option, bool isCustom )
975 bool isDefault = false;
978 QStringList name_value_type = QString(option).split( ":", QString::KeepEmptyParts );
979 if ( name_value_type.size() > 0 )
980 name = name_value_type[0];
981 if ( name_value_type.size() > 1 )
982 value = name_value_type[1];
983 if ( name_value_type.size() > 2 )
984 isDefault = !name_value_type[2].toInt();
987 QTreeWidget* table = myOptionTable;
988 //table->setExpanded( true );
990 QTreeWidgetItem* row;
991 if (optionTreeWidgetItem.size())
993 std::map<QString, QTreeWidgetItem *>::iterator it = optionTreeWidgetItem.find(name);
994 if(it != optionTreeWidgetItem.end()) return; // option exist
997 row = getNewQTreeWidgetItem(table, option, name, isCustom);
1002 row = getNewQTreeWidgetItem(table, option, name, isCustom);
1004 row->setText( 0, tr( name.toLatin1().constData() ));
1005 row->setText( 1, tr( value.toLatin1().constData() ));
1006 row->setCheckState( 0, isDefault ? Qt::Unchecked : Qt::Checked);
1007 row->setData( NAME_COL, PARAM_NAME, name );
1011 myOptionTable->scrollToItem( row );
1012 myOptionTable->setCurrentItem( row );
1013 myOptionTable->editItem( row, NAME_COL );
1017 QTreeWidgetItem* MgAdaptAdvWidget::getNewQTreeWidgetItem(QTreeWidget* table, const char* option, QString& name, bool isCustom)
1019 QTreeWidgetItem* row = new QTreeWidgetItem( table );
1020 row->setData( NAME_COL, EDITABLE_ROLE, int( isCustom && !option ));
1021 row->setFlags( row->flags() | Qt::ItemIsEditable );
1022 optionTreeWidgetItem.insert(std::pair <QString, QTreeWidgetItem*> (name, row));
1027 void MgAdaptAdvWidget::onAddOption()
1029 AddOption( NULL, true );
1031 void MgAdaptAdvWidget::GetOptionAndValue( QTreeWidgetItem * tblRow,
1036 option = tblRow->data( NAME_COL, PARAM_NAME ).toString();
1037 value = tblRow->text( VALUE_COL );
1038 isDefault = ! tblRow->checkState( NAME_COL );
1043 void MgAdaptAdvWidget::itemChanged(QTreeWidgetItem* tblRow, int column)
1047 myOptionTable->blockSignals( true );
1049 tblRow->setData( VALUE_COL, EDITABLE_ROLE, int( tblRow->checkState( NAME_COL )));
1051 int c = tblRow->checkState( NAME_COL ) ? 0 : 150;
1052 tblRow->setForeground( VALUE_COL, QBrush( QColor( c, c, c )));
1054 if ( column == NAME_COL && tblRow->data( NAME_COL, EDITABLE_ROLE ).toInt() ) // custom table
1056 tblRow->setData( NAME_COL, PARAM_NAME, tblRow->text( NAME_COL ));
1059 myOptionTable->blockSignals( false );
1062 void MgAdaptAdvWidget::setupWidget()
1064 if (this->objectName().isEmpty())
1065 this->setObjectName(QString(tr("MG-ADAPT-ADV")));
1066 this->resize(337, 369);
1067 gridLayout_4 = new QGridLayout(this);
1068 gridLayout_4->setObjectName(QString("gridLayout_4"));
1069 myOptionTable = new MgAdaptAdvWidgetTreeWidget(this);
1071 font.setBold(false);
1073 QTreeWidgetItem *__qtreewidgetitem = new QTreeWidgetItem();
1074 __qtreewidgetitem->setFont(1, font);
1075 __qtreewidgetitem->setFont(0, font);
1076 __qtreewidgetitem->setText(1, tr("OPTION_VALUE_COLUMN"));
1077 __qtreewidgetitem->setText(0, tr("OPTION_NAME_COLUMN"));
1078 myOptionTable->setHeaderItem(__qtreewidgetitem);
1079 myOptionTable->setObjectName(QString("myOptionTable"));
1080 myOptionTable->setEditTriggers(QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed);
1081 myOptionTable->setTabKeyNavigation(true);
1083 gridLayout_4->addWidget(myOptionTable, 0, 0, 1, 2);
1085 addBtn = new QPushButton(this);
1086 addBtn->setObjectName(QString("addBtn"));
1088 gridLayout_4->addWidget(addBtn, 1, 0, 1, 1);
1090 horizontalSpacer = new QSpacerItem(188, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
1092 gridLayout_4->addItem(horizontalSpacer, 1, 1, 1, 1);
1094 logGroupBox = new QGroupBox(this);
1095 logGroupBox->setObjectName(QString("logGroupBox"));
1096 gridLayout_2 = new QGridLayout(logGroupBox);
1097 gridLayout_2->setObjectName(QString("gridLayout_2"));
1098 gridLayout = new QGridLayout();
1099 gridLayout->setObjectName(QString("gridLayout"));
1100 workingDirectoryLabel = new QLabel(logGroupBox);
1101 workingDirectoryLabel->setObjectName(QString("workingDirectoryLabel"));
1103 gridLayout->addWidget(workingDirectoryLabel, 0, 0, 1, 1);
1105 workingDirectoryLineEdit = new QLineEdit(logGroupBox);
1106 workingDirectoryLineEdit->setObjectName(QString("workingDirectoryLineEdit"));
1108 gridLayout->addWidget(workingDirectoryLineEdit, 0, 1, 1, 1);
1110 workingDirectoryPushButton = new QPushButton(logGroupBox);
1111 workingDirectoryPushButton->setObjectName(QString("workingDirectoryPushButton"));
1113 gridLayout->addWidget(workingDirectoryPushButton, 0, 2, 1, 1);
1115 verboseLevelLabel = new QLabel(logGroupBox);
1116 verboseLevelLabel->setObjectName(QString("verboseLevelLabel"));
1118 gridLayout->addWidget(verboseLevelLabel, 1, 0, 1, 1);
1120 verboseLevelSpin = new QSpinBox(logGroupBox);
1121 verboseLevelSpin->setObjectName(QString("verboseLevelSpin"));
1123 gridLayout->addWidget(verboseLevelSpin, 1, 1, 1, 1);
1126 gridLayout_2->addLayout(gridLayout, 0, 0, 1, 1);
1128 horizontalLayout = new QHBoxLayout();
1129 horizontalLayout->setObjectName(QString("horizontalLayout"));
1130 logInFileCheck = new QCheckBox(logGroupBox);
1131 logInFileCheck->setObjectName(QString("logInFileCheck"));
1132 logInFileCheck->setChecked(true);
1134 horizontalLayout->addWidget(logInFileCheck);
1136 removeLogOnSuccessCheck = new QCheckBox(logGroupBox);
1137 removeLogOnSuccessCheck->setObjectName(QString("removeLogOnSuccessCheck"));
1138 removeLogOnSuccessCheck->setChecked(true);
1140 horizontalLayout->addWidget(removeLogOnSuccessCheck);
1143 gridLayout_2->addLayout(horizontalLayout, 1, 0, 1, 1);
1145 keepWorkingFilesCheck = new QCheckBox(logGroupBox);
1146 keepWorkingFilesCheck->setObjectName(QString("keepWorkingFilesCheck"));
1147 keepWorkingFilesCheck->setAutoExclusive(false);
1149 gridLayout_2->addWidget(keepWorkingFilesCheck, 2, 0, 1, 1);
1152 gridLayout_4->addWidget(logGroupBox, 3, 0, 1, 2);
1155 // retranslateUi(this);
1157 // QMetaObject::connectSlotsByName(this);
1160 void MgAdaptAdvWidget::_onWorkingDirectoryPushButton()
1162 QString aDirName=QFileDialog::getExistingDirectory ();
1163 if (!(aDirName.isEmpty()))workingDirectoryLineEdit->setText(aDirName);
1165 void MgAdaptAdvWidget::onMeshDimChanged(ADAPTATION_MODE aMode)
1167 /* default adaptation mode
1168 * assume that if meshDim == 2 -->adaptation surface
1169 * if meshDim == 3 and if there is not 2D mesh -->VOLUME
1173 QString adaptation("adaptation"), value;
1176 case ADAPTATION_MODE::SURFACE:
1179 setOptionValue(adaptation, value);
1182 case ADAPTATION_MODE::BOTH :
1185 setOptionValue(adaptation, value);
1188 case ADAPTATION_MODE::VOLUME :
1191 setOptionValue(adaptation, value);
1196 void MgAdaptAdvWidget::setOptionValue(QString& option, QString& value)
1199 std::map<QString, QTreeWidgetItem *>::iterator it = optionTreeWidgetItem.find(option);
1200 if (it != optionTreeWidgetItem.end())
1202 it->second->setText( 0, tr( option.toLatin1().constData() ));
1203 it->second->setText( 1, tr( value.toLatin1().constData() ));
1204 it->second->setCheckState( 0, Qt::Checked );
1205 it->second->setData( NAME_COL, PARAM_NAME, option );
1206 myOptionTable->editItem( it->second, NAME_COL );
1211 bool isEditable( const QModelIndex& index )
1213 return index.isValid() &&
1214 index.flags() & Qt::ItemIsEditable &&
1215 index.flags() & Qt::ItemIsEnabled &&
1216 ( !index.data( Qt::UserRole + 1 ).isValid() || index.data( Qt::UserRole + 1 ).toInt() != 0 );
1220 MgAdaptAdvWidgetTreeWidget::MgAdaptAdvWidgetTreeWidget( QWidget* parent )
1221 : QTreeWidget( parent )
1225 QModelIndex MgAdaptAdvWidgetTreeWidget::moveCursor( CursorAction action, Qt::KeyboardModifiers modifiers )
1227 QModelIndex current = currentIndex();
1228 int column = current.column();
1229 if ( action == MoveNext ) {
1230 if ( column < columnCount()-1 ) {
1231 QModelIndex next = current.sibling( current.row(), column+1 );
1232 if ( isEditable( next ) )
1236 QModelIndex next = current.sibling( current.row()+1, 0 );
1237 if ( isEditable( next ) )
1241 else if ( action == MovePrevious ) {
1242 if ( column == 0 ) {
1243 QModelIndex next = current.sibling( current.row()-1, columnCount()-1 );
1244 if ( isEditable( next ) )
1248 QModelIndex next = current.sibling( current.row(), column-1 );
1249 if ( isEditable( next ) )
1253 return QTreeWidget::moveCursor( action, modifiers );
1256 void MgAdaptAdvWidgetTreeWidget::keyPressEvent( QKeyEvent* e )
1258 switch ( e->key() ) {
1261 QModelIndex index = currentIndex();
1262 if ( !isEditable( index ) ) {
1263 for ( int i = 0; i < columnCount(); i++ ) {
1264 QModelIndex sibling = index.sibling( index.row(), i );
1265 if ( isEditable( sibling ) ) {
1266 if ( !edit( sibling, EditKeyPressed, e ) )
1276 QTreeWidget::keyPressEvent( e );
1280 // =======================================================================
1281 // renvoie le medId associe au fichier Med apres ouverture
1282 // =======================================================================
1283 med_idt OuvrirFichier(QString aFile)
1285 med_idt medIdt = MEDfileOpen(aFile.toStdString().c_str(),MED_ACC_RDONLY);
1288 QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
1289 QObject::tr("MG_ADAPT_MED_FILE_1") );
1294 // ======================================================
1295 // ========================================================
1296 QString lireNomMaillage(QString aFile, med_int& meshdim)
1298 QString nomMaillage = QString::null ;
1302 // Ouverture du fichier
1303 medIdt = OuvrirFichier(aFile);
1309 med_int numberOfMeshes = MEDnMesh(medIdt) ;
1310 if (numberOfMeshes == 0 )
1312 QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
1313 QObject::tr("MG_ADAPT_MED_FILE_2") );
1317 if (numberOfMeshes > 1 )
1319 QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
1320 QObject::tr("MG_ADAPT_MED_FILE_3") );
1325 nomMaillage = lireNomMaillage2(medIdt,1, meshdim);
1326 // Fermeture du fichier
1327 if ( medIdt > 0 ) MEDfileClose(medIdt);
1332 // =======================================================================
1333 // =======================================================================
1334 QString lireNomMaillage2(med_idt medIdt,int meshId, med_int& meshdim )
1336 QString NomMaillage=QString::null;
1337 char meshname[MED_NAME_SIZE+1];
1339 med_mesh_type meshtype;
1340 char descriptionription[MED_COMMENT_SIZE+1];
1341 char dtunit[MED_SNAME_SIZE+1];
1342 med_sorting_type sortingtype;
1344 med_axis_type axistype;
1345 int naxis = MEDmeshnAxis(medIdt,1);
1346 char *axisname=new char[naxis*MED_SNAME_SIZE+1];
1347 char *axisunit=new char[naxis*MED_SNAME_SIZE+1];
1348 med_err aRet = MEDmeshInfo(medIdt,
1363 QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"), \
1364 QObject::tr("MG_ADAPT_MED_FILE_4") );
1367 NomMaillage=QString(meshname);
1378 // =======================================================================
1379 std::map<QString, int> GetListeChamps(QString aFile, bool errorMessage)
1380 // =======================================================================
1382 // Il faut voir si plusieurs maillages
1384 MESSAGE("GetListeChamps");
1385 std::map<QString, int> ListeChamp ;
1387 med_err erreur = 0 ;
1390 while ( erreur == 0 )
1392 // Ouverture du fichier
1393 SCRUTE(aFile.toStdString());
1394 medIdt = OuvrirFichier(aFile);
1400 // Lecture du nombre de champs
1401 med_int ncha = MEDnField(medIdt) ;
1406 QMessageBox::critical( 0, QObject::tr("_ERROR"),
1407 QObject::tr("HOM_MED_FILE_5") );
1412 // Lecture des caracteristiques des champs
1413 for (int i=0; i< ncha; i++)
1415 // Lecture du nombre de composantes
1416 med_int ncomp = MEDfieldnComponent(medIdt,i+1);
1417 // Lecture du type du champ, des noms des composantes et du nom de l'unite
1418 char nomcha [MED_NAME_SIZE+1];
1419 char meshname[MED_NAME_SIZE+1];
1420 char * comp = (char*) malloc(ncomp*MED_SNAME_SIZE+1);
1421 char * unit = (char*) malloc(ncomp*MED_SNAME_SIZE+1);
1422 char dtunit[MED_SNAME_SIZE+1];
1424 med_field_type typcha;
1426 erreur = MEDfieldInfo(medIdt,i+1,nomcha,meshname,&local,&typcha,comp,unit,dtunit,&nbofcstp) ;
1433 QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
1434 QObject::tr("MG_ADAPT_MED_FILE_6") );
1439 ListeChamp.insert(std::pair<QString, int> (QString(nomcha), nbofcstp));
1444 // Fermeture du fichier
1445 if ( medIdt > 0 ) MEDfileClose(medIdt);
1450 std::string remove_extension(const std::string& filename) {
1451 size_t lastdot = filename.find_last_of(".");
1452 if (lastdot == std::string::npos) return filename;
1453 return filename.substr(0, lastdot);