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>
88 const int SPACING = 6; // layout spacing
89 const int MARGIN = 9; // layout margin
91 //=================================================================================
92 // function : SMESHGUI_MgAdaptDlg()
94 //=================================================================================
95 SMESHGUI_MgAdaptDlg::SMESHGUI_MgAdaptDlg( SalomeApp_Module* theModule, SMESH::MG_ADAPT_ptr myModel, QWidget* parent, bool isCreation )
96 : mySMESHGUI( theModule ), QDialog(parent)
98 //~model = new MgAdapt(*myModel);
99 model = SMESH::MG_ADAPT::_duplicate(myModel);
100 myData = model->getData();
102 if (!isCreation) readParamsFromHypo();
105 void SMESHGUI_MgAdaptDlg::buildDlg()
108 setAttribute( Qt::WA_DeleteOnClose, true );
109 setWindowTitle( tr( "ADAPT_PREF_MG_ADAPT" ) );
110 setSizeGripEnabled( true );
112 myTabWidget = new QTabWidget( this );
116 myArgs = new SMESHGUI_MgAdaptArguments( myTabWidget );
117 SMESH::str_array* str = model->getOptionValuesStrVec();
118 SMESH::str_array* str2 = model->getCustomOptionValuesStrVec();
119 std::vector<std::string> s;
120 for (int i = 0; i< str->length(); i++) s.push_back( (*str)[i].in());
121 for (int j = str->length(); j< str2->length(); j++) s.push_back((*str2)[ j - str->length() ].in() );
122 //~str.insert( str.end(), str2.begin(), str2.end() );
124 myAdvOpt = new MgAdaptAdvWidget(myTabWidget, &s);
126 int argsTab = myTabWidget->addTab( myArgs, tr( "Args" ) );
127 int advTab = myTabWidget->addTab( myAdvOpt, tr( "ADVOP" ) );
129 myAdvOpt->workingDirectoryLabel ->setText (tr( "WORKING_DIR" ));
130 myAdvOpt->workingDirectoryPushButton ->setText (tr( "SELECT_DIR" ));
131 myAdvOpt->keepWorkingFilesCheck ->setText (tr( "KEEP_WORKING_FILES" ));
132 myAdvOpt->verboseLevelLabel ->setText (tr( "VERBOSE_LEVEL" ));
133 myAdvOpt->removeLogOnSuccessCheck ->setText (tr( "REMOVE_LOG_ON_SUCCESS" ));
134 myAdvOpt->logInFileCheck ->setText (tr( "LOG_IN_FILE" ));
135 myAdvOpt->logGroupBox ->setTitle(tr( "LOG_GROUP_TITLE" ));
138 QPushButton* okBtn = new QPushButton( tr( "SMESH_BUT_OK" ), this );
139 okBtn->setAutoDefault( true );
140 okBtn->setDefault( true );
142 QPushButton* buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), this);
143 buttonApply->setAutoDefault(true);
144 QPushButton* buttonApplyAndClose = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), this);
145 buttonApplyAndClose->setAutoDefault(true);
146 QPushButton* cancelBtn = new QPushButton( tr( "SMESH_BUT_CANCEL" ), this );
147 cancelBtn->setAutoDefault( true );
148 QPushButton* helpBtn = new QPushButton( tr( "SMESH_BUT_HELP" ), this );
149 helpBtn->setAutoDefault( true );
151 QHBoxLayout* btnLayout = new QHBoxLayout;
152 btnLayout->setSpacing( SPACING );
153 btnLayout->setMargin( 0 );
154 btnLayout->addWidget( buttonApplyAndClose );
155 btnLayout->addStretch( 10 );
156 btnLayout->addWidget( buttonApply );
157 btnLayout->addStretch( 10 );
158 btnLayout->addWidget( okBtn );
159 btnLayout->addStretch( 10 );
160 btnLayout->addWidget( cancelBtn );
161 btnLayout->addStretch( 10 );
162 btnLayout->addWidget( helpBtn );
163 okBtn->hide(); // tab 1
165 QVBoxLayout* l = new QVBoxLayout ( this );
166 l->setMargin( MARGIN );
167 l->setSpacing( SPACING );
168 l->addWidget( myTabWidget );
170 l->addLayout( btnLayout );
173 connect( okBtn, SIGNAL(clicked()), this, SLOT( clickOnOk() ) );
174 connect( helpBtn, SIGNAL(clicked()), this, SLOT( clickOnHelp() ) );
175 connect(cancelBtn, SIGNAL(clicked()), this, SLOT(reject()));
176 connect(buttonApply, SIGNAL(clicked()), this,SLOT(clickOnApply()));
177 connect(buttonApplyAndClose, SIGNAL(clicked()), this,SLOT(clickOnOk()));
178 connect(myArgs, SIGNAL(meshDimSignal(ADAPTATION_MODE)), myAdvOpt, SLOT( onMeshDimChanged(ADAPTATION_MODE)) );
182 //=================================================================================
183 // function : ~SMESHGUI_MgAdaptDlg()
184 // purpose : Destroys the object and frees any allocated resources
185 //=================================================================================
186 SMESHGUI_MgAdaptDlg::~SMESHGUI_MgAdaptDlg()
191 //~void SMESHGUI_MgAdaptDlg::setModel(MgAdapt* mg)
195 SMESH::MG_ADAPT_ptr SMESHGUI_MgAdaptDlg::getModel() const
200 \brief Perform clean-up actions on the dialog box closing.
202 bool SMESHGUI_MgAdaptDlg::clickOnApply()
204 readParamsFromWidgets();
207 void SMESHGUI_MgAdaptDlg::clickOnOk()
212 void SMESHGUI_MgAdaptDlg::reject()
216 bool SMESHGUI_MgAdaptDlg::readParamsFromHypo( ) const
219 myArgs->aMedfile->setChecked(myData->fromMedFile) ;
220 if (myData->fromMedFile)
223 *(myArgs->myFileInDir) = QString(myData->myFileInDir) ;
224 myArgs->selectMedFileLineEdit->setText(QString(myData->myMeshFileIn)) ;
225 // myData->myInMeshName = // TODO
230 myArgs->aBrowserObject->setText(QString(myData->myInMeshName));
231 //~ myArgs->myFileInDir =""; // TODO
232 //~ myArgs->selectMedFileLineEdit->setText(); // TODO
234 myArgs->meshNameLineEdit->setText(QString(myData->myOutMeshName));
235 myArgs->medFileCheckBox->setChecked(myData->myMeshOutMed);
237 if(myData->myMeshOutMed)
239 *(myArgs->myFileOutDir) = QString(myData->myFileOutDir);
240 myArgs->selectOutMedFileLineEdit->setText(QString(myData->myMeshFileOut));
244 *(myArgs->myFileOutDir) = QString(""); //TODO
247 myArgs->publishOut->setChecked(myData->myPublish);
249 myArgs->localButton->setChecked(myData->myUseLocalMap);
250 myArgs->backgroundButton->setChecked(myData->myUseBackgroundMap);
251 myArgs->constantButton->setChecked(myData->myUseConstantValue);
253 if (myData->myUseConstantValue)
255 myArgs->dvalue->setValue(myData->myConstantValue);
259 myArgs->dvalue->setValue(0.0);
262 if (myData->myUseBackgroundMap)
265 *(myArgs->myFileSizeMapDir) = QString(myData->myFileSizeMapDir) ;
266 myArgs->selectMedFileBackgroundLineEdit->setText(QString(myData->myMeshFileBackground));
270 *(myArgs->myFileSizeMapDir) = QString("") ; //TODO
271 myArgs->selectMedFileBackgroundLineEdit->setText(""); //TODO
274 myArgs->fieldNameCmb->setCurrentText(QString(myData->myFieldName));
275 myArgs->noTimeStep->setChecked(myData->myUseNoTimeStep);
276 myArgs->lastTimeStep->setChecked( myData->myUseLastTimeStep);
277 myArgs->chosenTimeStep->setChecked(myData->myUseChosenTimeStep);
278 if (myData->myUseChosenTimeStep)
280 myArgs->rankSpinBox->setValue(myData->myRank);
281 myArgs->timeStep->setValue(myData->myTimeStep);
284 myAdvOpt->workingDirectoryLineEdit->setText(QString(myData->myWorkingDir));
285 myAdvOpt->logInFileCheck->setChecked(myData->myPrintLogInFile);
287 myAdvOpt->verboseLevelSpin->setValue(myData->myVerboseLevel);
288 myAdvOpt->removeLogOnSuccessCheck->setChecked(myData->myRemoveLogOnSuccess);
289 myAdvOpt->keepWorkingFilesCheck->setChecked(myData->myKeepFiles);
296 bool SMESHGUI_MgAdaptDlg::readParamsFromWidgets()
299 SMESH::MgAdaptHypothesisData* aData = new SMESH::MgAdaptHypothesisData();
300 aData->fromMedFile = myArgs->aMedfile->isChecked();
301 if (aData->fromMedFile)
304 aData->myFileInDir = CORBA::string_dup(myArgs->myFileInDir->toStdString().c_str());
305 aData->myMeshFileIn = CORBA::string_dup(myArgs->selectMedFileLineEdit->text().toStdString().c_str());
306 // aData->myInMeshName = // TODO
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 aData->myOutMeshName = CORBA::string_dup(myArgs->meshNameLineEdit->text().toStdString().c_str());
324 aData->myMeshOutMed = myArgs->medFileCheckBox->isChecked();
325 if(aData->myMeshOutMed)
327 aData->myFileOutDir = CORBA::string_dup(myArgs->myFileOutDir->toStdString().c_str());
328 aData->myMeshFileOut = CORBA::string_dup(myArgs->selectOutMedFileLineEdit->text().toStdString().c_str());
333 aData->myMeshFileOut = "";
336 aData->myPublish = myArgs->publishOut->isChecked();
339 aData->myUseLocalMap = myArgs->localButton->isChecked();
340 aData->myUseBackgroundMap = myArgs->backgroundButton->isChecked();
341 aData->myUseConstantValue = myArgs->constantButton->isChecked();
342 if (aData->myUseConstantValue)
344 aData->myConstantValue = myArgs->dvalue->value();
348 aData->myConstantValue = 0.0;
350 if (aData->myUseBackgroundMap)
352 aData->myFileSizeMapDir = CORBA::string_dup(myArgs->myFileSizeMapDir->toStdString().c_str());
353 aData->myMeshFileBackground = CORBA::string_dup(myArgs->selectMedFileBackgroundLineEdit->text().toStdString().c_str());
357 aData->myMeshFileBackground = "";
360 aData->myFieldName = CORBA::string_dup(myArgs->fieldNameCmb->currentText().toStdString().c_str());
361 aData->myUseNoTimeStep = myArgs->noTimeStep->isChecked();
362 aData->myUseLastTimeStep = myArgs->lastTimeStep->isChecked();
363 aData->myUseChosenTimeStep = myArgs->chosenTimeStep->isChecked();
364 if (aData->myUseChosenTimeStep)
366 aData->myRank = myArgs->rankSpinBox->value();
367 aData->myTimeStep = myArgs->timeStep->value();
371 aData->myWorkingDir = CORBA::string_dup(myAdvOpt->workingDirectoryLineEdit->text().toStdString().c_str());
372 aData->myPrintLogInFile = myAdvOpt->logInFileCheck->isChecked();
373 aData->myVerboseLevel = myAdvOpt->verboseLevelSpin->value();
374 aData->myRemoveLogOnSuccess = myAdvOpt->removeLogOnSuccessCheck->isChecked();
375 aData->myKeepFiles = myAdvOpt->keepWorkingFilesCheck->isChecked();
376 model->setData(*aData);
382 bool SMESHGUI_MgAdaptDlg::storeParamsToHypo( const SMESH::MgAdaptHypothesisData& ) const
387 \brief Show help page
389 void SMESHGUI_MgAdaptDlg::clickOnHelp()
391 // QString aHelpFile;
392 // if ( myTabWidget->currentIndex() == MinDistance ) {
393 // aHelpFile = "measurements.html#min-distance-anchor";
394 // } else if ( myTabWidget->currentIndex() == BoundingBox ) {
395 // aHelpFile = "measurements.html#bounding-box-anchor";
396 // } else if ( myTabWidget->currentWidget() == myAngle ) {
397 // aHelpFile = "measurements.html#angle-anchor";
399 // aHelpFile = "measurements.html#basic-properties-anchor";
402 // SMESH::ShowHelpFile( aHelpFile );
404 bool SMESHGUI_MgAdaptDlg::checkParams(QString& msg)
406 if ( !QFileInfo( myAdvOpt->workingDirectoryLineEdit->text().trimmed() ).isWritable() )
408 SUIT_MessageBox::warning( this,
409 tr( "SMESH_WRN_WARNING" ),
410 tr( "GHS3D_PERMISSION_DENIED" ) );
415 myAdvOpt->myOptionTable->setFocus();
416 QApplication::instance()->processEvents();
419 bool isDefault, ok = true;
420 int iRow = 0, nbRows = myAdvOpt->myOptionTable->topLevelItemCount();
421 for ( ; iRow < nbRows; ++iRow )
423 QTreeWidgetItem* row = myAdvOpt->myOptionTable->topLevelItem( iRow );
424 myAdvOpt->GetOptionAndValue( row, name, value, isDefault );
426 if ( name.simplified().isEmpty() )
427 continue; // invalid custom option
429 if ( isDefault ) // not selected option
434 model->setOptionValue( name.toLatin1().constData(), value.toLatin1().constData() );
436 catch ( const SALOME::SALOME_Exception& ex )
438 msg = ex.details.text.in();
447 //=================================================================================
448 // function : SMESHGUI_MgAdaptArguments()
450 //=================================================================================
451 SMESHGUI_MgAdaptArguments::SMESHGUI_MgAdaptArguments( QWidget* parent )
455 myFileInDir = new QString("");
456 myFileOutDir = new QString("");
457 myFileSizeMapDir = new QString("");
458 if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
460 *myFileInDir = QDir::currentPath();
461 *myFileOutDir = QDir::currentPath();
462 *myFileSizeMapDir = QDir::currentPath();
466 *myFileInDir = SUIT_FileDlg::getLastVisitedPath();
467 *myFileOutDir = SUIT_FileDlg::getLastVisitedPath();
468 *myFileSizeMapDir = SUIT_FileDlg::getLastVisitedPath();
473 aMeshIn = new QGroupBox( tr( "MeshIn" ), this );
474 aMedfile = new QRadioButton( tr( "MEDFile" ), aMeshIn );
475 aBrowser = new QRadioButton( tr( "Browser" ), aMeshIn );
476 aBrowserObject = new QLineEdit( aMeshIn );
477 selectMedFilebutton = new QPushButton("", aMeshIn);
478 selectMedFileLineEdit = new QLineEdit( aMeshIn );
480 meshIn = new QGridLayout( aMeshIn );
482 meshIn->setMargin( MARGIN );
483 meshIn->setSpacing( SPACING );
484 meshIn->addWidget( aMedfile, 0, 0, 1,1 );
485 meshIn->addWidget( aBrowser, 0, 1,1,1);
486 meshIn->addWidget( aBrowserObject, 0, 2, 1, 1 );
487 meshIn->addWidget( selectMedFilebutton, 1, 0,1, 1);
488 meshIn->addWidget( selectMedFileLineEdit, 1, 1, 1, 1 );
489 hspacer = new QSpacerItem(188, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
491 meshInGroup = new QButtonGroup( this );
492 meshInGroup->addButton( aMedfile, 0 );
493 meshInGroup->addButton( aBrowser, 1 );
497 aMeshOut = new QGroupBox( tr( "MeshOut" ), this );
498 meshName = new QLabel(tr("MeshName"), aMeshOut);
499 secondHspacer = new QSpacerItem(100, 30);
500 meshNameLineEdit = new QLineEdit(aMeshOut) ;
501 medFileCheckBox = new QCheckBox(tr("MEDFile"), aMeshOut);
502 selectOutMedFilebutton = new QPushButton("", aMeshOut);
503 thirdHspacer = new QSpacerItem(188, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
504 selectOutMedFileLineEdit = new QLineEdit(aMeshOut) ;
505 publishOut = new QCheckBox(tr("Publish_MG_ADAPT"), aMeshOut);
507 meshOut = new QGridLayout( aMeshOut );
509 meshOut->setMargin( MARGIN );
510 meshOut->setSpacing( SPACING );
511 meshOut->addWidget( meshName, 0, 0, 1,1 );
512 meshOut->addItem( secondHspacer, 0, 1, 1, 1 );
513 meshOut->addWidget( meshNameLineEdit, 0, 2,1,1);
514 meshOut->addWidget( medFileCheckBox, 1, 0,1,1 );
515 meshOut->addWidget( selectOutMedFilebutton, 1, 1,1,1 );
516 meshOut->addWidget( selectOutMedFileLineEdit, 1, 2,1,1);
517 meshOut->addWidget( publishOut, 2, 0,1,1 );
519 //size map definition
521 sizeMapDefinition = new QGroupBox(tr("SIZE_MAP_DEF"), this);
522 localButton = new QRadioButton(tr("LOCAL_MG_ADAPT"), sizeMapDefinition);
523 backgroundButton = new QRadioButton(tr("BACKGRND_MG_ADAPT"), sizeMapDefinition);
524 constantButton = new QRadioButton(tr("CNST_MG_ADAPT"), sizeMapDefinition);
525 medFileBackground = new QLabel(tr("MED_FILE_BCKG"), sizeMapDefinition);
526 selectMedFileBackgroundbutton = new QPushButton(tr(""), sizeMapDefinition);
527 selectMedFileBackgroundLineEdit = new QLineEdit(sizeMapDefinition);
528 valueLabel = new QLabel(tr("VALUE_MG_ADAPT"), sizeMapDefinition);
529 dvalue = new QDoubleSpinBox(sizeMapDefinition);
530 sizeMapDefGroup = new QButtonGroup( this );
531 sizeMapDefGroup->addButton( localButton, 0 );
532 sizeMapDefGroup->addButton( backgroundButton, 1 );
533 sizeMapDefGroup->addButton( constantButton, 2 );
535 sizeMapDefGroupLayout = new QGridLayout(sizeMapDefinition);
536 sizeMapDefGroupLayout->addWidget(localButton, 0,0);
537 sizeMapDefGroupLayout->addWidget(backgroundButton, 0,1);
538 sizeMapDefGroupLayout->addWidget(constantButton, 0,2);
539 sizeMapDefGroupLayout->addWidget(medFileBackground, 1,0);
540 sizeMapDefGroupLayout->addWidget(selectMedFileBackgroundbutton, 1,1);
541 sizeMapDefGroupLayout->addWidget(selectMedFileBackgroundLineEdit, 1,2);
542 sizeMapDefGroupLayout->addWidget(valueLabel, 2,0);
543 sizeMapDefGroupLayout->addWidget(dvalue, 2,1);
546 sizeMapField = new QGroupBox(tr("SIZE_MAP_FIELD"), this);
547 fieldName = new QLabel(tr("MG_ADAPT_FIELD_NAME"), sizeMapField);
548 fieldNameCmb = new QComboBox(sizeMapField);
549 noTimeStep = new QRadioButton(tr("MG_ADAPT_NO_T_ST"), sizeMapField);
550 lastTimeStep = new QRadioButton(tr("MG_ADAPT_L_ST"), sizeMapField);
551 chosenTimeStep = new QRadioButton(tr("MG_ADAPT_CH_ST"), sizeMapField);
552 timeStepLabel = new QLabel(tr("MG_ADAPT_TSTP"), sizeMapField);
553 timeStep = new QSpinBox(sizeMapField);
554 //~timeStep->setMinimum(-1);
555 rankLabel = new QLabel(tr("MG_ADAPT_RANK"), sizeMapField);
556 rankSpinBox = new QSpinBox(sizeMapField);
557 rankSpinBox->setMinimum(-1);
559 timeStepGroup = new QButtonGroup(this);
560 timeStepGroup->addButton(noTimeStep, 0);
561 timeStepGroup->addButton(lastTimeStep, 1);
562 timeStepGroup->addButton(chosenTimeStep, 2);
564 sizeMapFieldGroupLayout = new QGridLayout(sizeMapField);
566 sizeMapFieldGroupLayout->addWidget(fieldName, 0,0);
567 sizeMapFieldGroupLayout->addWidget(fieldNameCmb, 0,1);
568 sizeMapFieldGroupLayout->addWidget(noTimeStep, 1,0);
569 sizeMapFieldGroupLayout->addWidget(lastTimeStep, 1,1);
570 sizeMapFieldGroupLayout->addWidget(chosenTimeStep, 1,2);
571 sizeMapFieldGroupLayout->addWidget(timeStepLabel, 2,0);
572 sizeMapFieldGroupLayout->addWidget(timeStep, 2,1);
573 sizeMapFieldGroupLayout->addWidget(rankLabel, 2,2);
574 sizeMapFieldGroupLayout->addWidget(rankSpinBox, 2,3);
576 QGridLayout* argumentsLayout = new QGridLayout( this );
577 argumentsLayout->setMargin( MARGIN );
578 argumentsLayout->setSpacing( SPACING );
580 argumentsLayout->addWidget( aMeshIn, 0, 0, 1, 3 );
581 argumentsLayout->addWidget( aMeshOut, 1, 0, 1, 3 );
582 argumentsLayout->addWidget( sizeMapDefinition, 2, 0, 1, 3 );
583 argumentsLayout->addWidget( sizeMapField, 3, 0, 1, 3 );
584 argumentsLayout->setColumnStretch( 1, 5 );
585 argumentsLayout->setRowStretch( 4, 5 );
588 setMode( Mesh, Local);
589 medFileCheckBox->setChecked(true);
590 visibleTimeStepRankLabel (false);
593 connect( meshInGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( modeChanged( int ) ) );
594 connect( sizeMapDefGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( sizeMapDefChanged( int ) ) );
595 connect( selectMedFilebutton, SIGNAL( pressed( ) ), this, SLOT( onSelectMedFilebuttonClicked( ) ) );
596 connect( medFileCheckBox, SIGNAL (stateChanged(int)), this, SLOT(onMedFileCheckBox(int) ) );
597 connect( publishOut, SIGNAL (stateChanged(int)), this, SLOT(onPublishOut(int) ) );
598 connect( selectOutMedFilebutton, SIGNAL( pressed()), this, SLOT(onSelectOutMedFilebutton()));
599 connect( selectMedFileBackgroundbutton, SIGNAL(pressed()), this, SLOT(onSelectMedFileBackgroundbutton()) );
600 connect( timeStepGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( timeStepGroupChanged( int ) ) );
601 emit updateSelection();
604 //=================================================================================
605 // function : ~SMESHGUI_MgAdaptArguments()
606 // purpose : Destroys the object and frees any allocated resources
607 //=================================================================================
608 SMESHGUI_MgAdaptArguments::~SMESHGUI_MgAdaptArguments()
612 void SMESHGUI_MgAdaptArguments::onNoTimeStep(bool disableOther)
614 noTimeStep->setChecked(true);
616 visibleTimeStepRankLabel (false);
617 rankSpinBox->setValue(-2);
618 timeStep->setValue(-2);
620 lastTimeStep->setDisabled(disableOther);
621 chosenTimeStep->setDisabled(disableOther);
623 void SMESHGUI_MgAdaptArguments::onLastTimeStep(bool disableOther)
625 lastTimeStep->setChecked(true);
627 visibleTimeStepRankLabel (false);
628 rankSpinBox->setValue(-1);
629 timeStep->setValue(-1);
630 noTimeStep->setDisabled(disableOther);
632 void SMESHGUI_MgAdaptArguments::onChosenTimeStep(bool disableOther, int vmax)
634 chosenTimeStep->setChecked(true);
636 visibleTimeStepRankLabel (true);
637 rankSpinBox->setValue(0);
638 timeStep->setValue(0);
639 if (vmax) timeStep->setMaximum(vmax);
642 void SMESHGUI_MgAdaptArguments::visibleTimeStepRankLabel(bool visible)
644 rankLabel->setVisible(visible);
645 rankSpinBox->setVisible(visible);
647 timeStepLabel->setVisible(visible);
648 timeStep->setVisible(visible);
651 void SMESHGUI_MgAdaptArguments::onSelectOutMedFilebutton()
654 QString filtre = QString("Med") ;
655 filtre += QString(" files (*.") + QString("med") + QString(");;");
656 QString fileName = QFileDialog::getSaveFileName(this, tr("SAVE_MED"), QString(""), filtre);
657 QFileInfo myFileInfo(fileName);
658 selectOutMedFileLineEdit->setText(myFileInfo.fileName());
659 *myFileOutDir = myFileInfo.path();
662 void SMESHGUI_MgAdaptArguments::onSelectMedFileBackgroundbutton()
664 QString fileName0 = selectMedFileBackgroundbutton->text().trimmed();
666 QString fileName = getMedFileName(false);
667 if (fileName != QString::null)
669 myFieldList = GetListeChamps(fileName);
670 if (myFieldList.empty())
672 fileName = fileName0;
673 fieldNameCmb->clear();
677 // fill field name Combobox
678 fieldNameCmb->clear();
679 std::map<QString, int>::const_iterator it;
680 for ( it=myFieldList.begin() ; it != myFieldList.end(); it++)
682 fieldNameCmb->insertItem(0,QString(it->first));
683 int typeStepInField = it->second > 2 ? 2 : it->second ;
684 timeStepGroupChanged(typeStepInField, false);
690 fileName = fileName0;
691 fieldNameCmb->clear();
694 QFileInfo myFileInfo(fileName);
695 *myFileSizeMapDir = myFileInfo.path();
696 selectMedFileBackgroundLineEdit->setText(myFileInfo.fileName());
699 void SMESHGUI_MgAdaptArguments::onMedFileCheckBox(int state)
701 if (state == Qt::Checked)
703 selectOutMedFilebutton->show();
704 selectOutMedFileLineEdit->show();
705 selectOutMedFilebutton->setEnabled(true);
706 selectOutMedFileLineEdit->setEnabled(true);
710 selectOutMedFilebutton->setEnabled(false);
711 selectOutMedFileLineEdit->setEnabled(false);
712 publishOut->setChecked(true);
715 void SMESHGUI_MgAdaptArguments::onPublishOut(int state)
717 if (state == Qt::Unchecked)
719 medFileCheckBox->setChecked(true);
723 void SMESHGUI_MgAdaptArguments::onSelectMedFilebuttonClicked()
725 // bool keep = false;
726 QString fileName0 = selectMedFileLineEdit->text().trimmed();
728 QString fileName = getMedFileName(false);
729 if(fileName != QString::null)
731 QString aMeshName = lireNomMaillage(fileName.trimmed(), meshDim);
732 if (aMeshName == QString::null )
734 QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
735 QObject::tr("MG_ADAPT_MED_FILE_2") );
736 fileName = fileName0;
740 meshNameLineEdit->setText(aMeshName);
741 ADAPTATION_MODE aMode = meshDim == 3 ? ADAPTATION_MODE::BOTH : ADAPTATION_MODE::SURFACE; // and when dimesh 3 without 2D mesh?
742 emit meshDimSignal(aMode);
750 QFileInfo myFileInfo(fileName);
751 *myFileInDir = myFileInfo.path();
752 *myFileOutDir = myFileInfo.path();
753 selectMedFileLineEdit->setText(myFileInfo.fileName());
754 QString outF = fileName == QString::null ? myFileInfo.fileName() :
755 QString( remove_extension(myFileInfo.fileName().toStdString() ).c_str() )+ QString(".adapt.med");
756 selectOutMedFileLineEdit->setText(outF);
757 onLocalSelected(myFileInfo.filePath());
761 void SMESHGUI_MgAdaptArguments::onLocalSelected(QString filePath)
763 myFieldList = GetListeChamps(filePath, false);
764 if (myFieldList.empty())
766 if (localButton->isChecked())
768 fieldNameCmb->clear();
773 // fill field name Combobox
774 fieldNameCmb->clear();
775 std::map<QString, int>::const_iterator it;
776 for ( it = myFieldList.begin() ; it != myFieldList.end(); it++)
778 fieldNameCmb->insertItem(0,QString(it->first));
779 // Je ne comprends pas le rapport entre pas de temps et apparition d'un nouveau champ... GN
780 int typeStepInField = it->second > 2 ? 2 : it->second ;
781 // std::cout << "SMESHGUI_MgAdaptArguments::onLocalSelected typeStepInField : " << typeStepInField << std::endl;
782 timeStepGroupChanged(typeStepInField, false);
786 // =======================================================================
787 // Gestion les boutons qui permettent de
788 // 1) retourne le nom d'un fichier par une fenetre de dialogue si aucun
789 // objet est selectionne dans l arbre d etude
790 // 2) retourne le nom du fichier asocie a l objet
791 // selectionne dans l arbre d etude
792 // =======================================================================
793 QString SMESHGUI_MgAdaptArguments::getMedFileName(bool avertir)
796 QString aFile = QString::null;
797 QString filtre = QString("Med") ;
798 filtre += QString(" files (*.") + QString("med") + QString(");;");
799 aFile = SUIT_FileDlg::getOpenFileName(0, QObject::tr("MG_ADAPT_SELECT_FILE_0"), QString(""), filtre );
804 void SMESHGUI_MgAdaptArguments::setMode(const Mode theMode, const SIZEMAP theSizeMap )
806 QRadioButton* aButton = qobject_cast<QRadioButton*>( meshInGroup->button( theMode ) );
807 QRadioButton* bButton = qobject_cast<QRadioButton*>( sizeMapDefGroup->button( theSizeMap ) );
810 aButton->setChecked( true );
811 modeChanged( theMode );
815 bButton->setChecked( true );
816 sizeMapDefChanged( theSizeMap );
820 void SMESHGUI_MgAdaptArguments::modeChanged( int theMode )
825 aBrowserObject->hide();
826 selectMedFileLineEdit->show();
827 selectMedFilebutton->show();
828 localButton->setEnabled(true);
832 selectMedFileLineEdit->hide();
833 selectMedFilebutton->hide();
834 localButton->setEnabled(false);
835 aBrowserObject->show();
836 sizeMapDefChanged(Background);
837 emit updateSelection();
841 void SMESHGUI_MgAdaptArguments::sizeMapDefChanged( int theSizeMap )
843 fieldNameCmb->clear();
844 if(theSizeMap == Local)
846 localButton->setEnabled(true);
847 localButton->setChecked(true);
848 medFileBackground->hide();
849 selectMedFileBackgroundbutton->hide();
850 selectMedFileBackgroundLineEdit->hide();
851 selectMedFileBackgroundLineEdit->clear();
855 sizeMapField->setEnabled(true);
856 if (!selectMedFileLineEdit->text().isEmpty())
858 QFileInfo myFileInfo(QDir(*myFileInDir), selectMedFileLineEdit->text());
859 onLocalSelected(myFileInfo.filePath());
862 else if (theSizeMap == Background)
864 medFileBackground->show();
865 backgroundButton->setChecked(true);
866 selectMedFileBackgroundbutton->show();
867 selectMedFileBackgroundLineEdit->show();
870 sizeMapField->setEnabled(true);
875 medFileBackground->hide();
876 constantButton->setChecked(true);
877 selectMedFileBackgroundbutton->hide();
878 selectMedFileBackgroundLineEdit->clear();
879 selectMedFileBackgroundLineEdit->hide();
882 sizeMapField->setEnabled(false);
885 void SMESHGUI_MgAdaptArguments::timeStepGroupChanged(int timeStepType, bool disableOther, int vmax)
887 switch (timeStepType)
890 onNoTimeStep(disableOther);
893 onLastTimeStep(disableOther);
896 onChosenTimeStep(disableOther, vmax);
902 void SMESHGUI_MgAdaptArguments::clear()
904 selectMedFileLineEdit->clear();
905 aBrowserObject->clear();
907 meshNameLineEdit->clear();
908 selectOutMedFileLineEdit->clear();
910 med_int SMESHGUI_MgAdaptArguments::getMeshDim() const
914 QWidget* ItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &o, const QModelIndex &index) const
916 bool editable = index.data( EDITABLE_ROLE ).toInt();
917 return editable ? QItemDelegate::createEditor( parent, o, index ) : 0;
920 //////////////////////////////////////////
922 //////////////////////////////////////////
924 MgAdaptAdvWidget::MgAdaptAdvWidget( QWidget* parent, std::vector <std::string>* options, Qt::WindowFlags f )
925 : QWidget( parent, f ), myOptions(options)
928 myOptionTable->header()->setSectionResizeMode( QHeaderView::ResizeToContents );
929 myOptionTable->setItemDelegate( new ItemDelegate( myOptionTable ) );
931 for ( int i = 0, nb = myOptions->size(); i < nb; ++i )
933 AddOption( (*myOptions)[i].c_str() );
936 connect( myOptionTable, SIGNAL( itemChanged(QTreeWidgetItem *, int)), SLOT( itemChanged(QTreeWidgetItem *, int )));
937 connect( addBtn, SIGNAL(clicked()), this, SLOT( onAddOption() ) );
938 connect(workingDirectoryPushButton, SIGNAL(pressed()), this, SLOT(_onWorkingDirectoryPushButton()));
941 MgAdaptAdvWidget::~MgAdaptAdvWidget()
945 void MgAdaptAdvWidget::AddOption( const char* option, bool isCustom )
948 bool isDefault = false;
951 QStringList name_value_type = QString(option).split( ":", QString::KeepEmptyParts );
952 if ( name_value_type.size() > 0 )
953 name = name_value_type[0];
954 if ( name_value_type.size() > 1 )
955 value = name_value_type[1];
956 if ( name_value_type.size() > 2 )
957 isDefault = !name_value_type[2].toInt();
959 QTreeWidget* table = myOptionTable;
960 //table->setExpanded( true );
962 QTreeWidgetItem* row;
963 if (optionTreeWidgetItem.size())
965 std::map<QString, QTreeWidgetItem *>::iterator it = optionTreeWidgetItem.find(name);
966 if(it != optionTreeWidgetItem.end()) return; // option exist
969 row = getNewQTreeWidgetItem(table, option, name, isCustom);
974 row = getNewQTreeWidgetItem(table, option, name, isCustom);
976 row->setText( 0, tr( name.toLatin1().constData() ));
977 row->setText( 1, tr( value.toLatin1().constData() ));
978 row->setCheckState( 0, isDefault ? Qt::Unchecked : Qt::Checked);
979 row->setData( NAME_COL, PARAM_NAME, name );
983 myOptionTable->scrollToItem( row );
984 myOptionTable->setCurrentItem( row );
985 myOptionTable->editItem( row, NAME_COL );
989 QTreeWidgetItem* MgAdaptAdvWidget::getNewQTreeWidgetItem(QTreeWidget* table, const char* option, QString& name, bool isCustom)
991 QTreeWidgetItem* row = new QTreeWidgetItem( table );
992 row->setData( NAME_COL, EDITABLE_ROLE, int( isCustom && !option ));
993 row->setFlags( row->flags() | Qt::ItemIsEditable );
994 optionTreeWidgetItem.insert(std::pair <QString, QTreeWidgetItem*> (name, row));
999 void MgAdaptAdvWidget::onAddOption()
1001 AddOption( NULL, true );
1003 void MgAdaptAdvWidget::GetOptionAndValue( QTreeWidgetItem * tblRow,
1008 option = tblRow->data( NAME_COL, PARAM_NAME ).toString();
1009 value = tblRow->text( VALUE_COL );
1010 isDefault = ! tblRow->checkState( NAME_COL );
1014 void MgAdaptAdvWidget::itemChanged(QTreeWidgetItem* tblRow, int column)
1018 myOptionTable->blockSignals( true );
1020 tblRow->setData( VALUE_COL, EDITABLE_ROLE, int( tblRow->checkState( NAME_COL )));
1022 int c = tblRow->checkState( NAME_COL ) ? 0 : 150;
1023 tblRow->setForeground( VALUE_COL, QBrush( QColor( c, c, c )));
1025 if ( column == NAME_COL && tblRow->data( NAME_COL, EDITABLE_ROLE ).toInt() ) // custom table
1027 tblRow->setData( NAME_COL, PARAM_NAME, tblRow->text( NAME_COL ));
1030 myOptionTable->blockSignals( false );
1033 void MgAdaptAdvWidget::setupWidget()
1035 if (this->objectName().isEmpty())
1036 this->setObjectName(QString(tr("MG-ADAPT-ADV")));
1037 this->resize(337, 369);
1038 gridLayout_4 = new QGridLayout(this);
1039 gridLayout_4->setObjectName(QString("gridLayout_4"));
1040 myOptionTable = new MgAdaptAdvWidgetTreeWidget(this);
1042 font.setBold(false);
1044 QTreeWidgetItem *__qtreewidgetitem = new QTreeWidgetItem();
1045 __qtreewidgetitem->setFont(1, font);
1046 __qtreewidgetitem->setFont(0, font);
1047 __qtreewidgetitem->setText(1, tr("OPTION_VALUE_COLUMN"));
1048 __qtreewidgetitem->setText(0, tr("OPTION_NAME_COLUMN"));
1049 myOptionTable->setHeaderItem(__qtreewidgetitem);
1050 myOptionTable->setObjectName(QString("myOptionTable"));
1051 myOptionTable->setEditTriggers(QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed);
1052 myOptionTable->setTabKeyNavigation(true);
1054 gridLayout_4->addWidget(myOptionTable, 0, 0, 1, 2);
1056 addBtn = new QPushButton(this);
1057 addBtn->setObjectName(QString("addBtn"));
1059 gridLayout_4->addWidget(addBtn, 1, 0, 1, 1);
1061 horizontalSpacer = new QSpacerItem(188, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
1063 gridLayout_4->addItem(horizontalSpacer, 1, 1, 1, 1);
1065 logGroupBox = new QGroupBox(this);
1066 logGroupBox->setObjectName(QString("logGroupBox"));
1067 gridLayout_2 = new QGridLayout(logGroupBox);
1068 gridLayout_2->setObjectName(QString("gridLayout_2"));
1069 gridLayout = new QGridLayout();
1070 gridLayout->setObjectName(QString("gridLayout"));
1071 workingDirectoryLabel = new QLabel(logGroupBox);
1072 workingDirectoryLabel->setObjectName(QString("workingDirectoryLabel"));
1074 gridLayout->addWidget(workingDirectoryLabel, 0, 0, 1, 1);
1076 workingDirectoryLineEdit = new QLineEdit(logGroupBox);
1077 workingDirectoryLineEdit->setObjectName(QString("workingDirectoryLineEdit"));
1079 gridLayout->addWidget(workingDirectoryLineEdit, 0, 1, 1, 1);
1081 workingDirectoryPushButton = new QPushButton(logGroupBox);
1082 workingDirectoryPushButton->setObjectName(QString("workingDirectoryPushButton"));
1084 gridLayout->addWidget(workingDirectoryPushButton, 0, 2, 1, 1);
1086 verboseLevelLabel = new QLabel(logGroupBox);
1087 verboseLevelLabel->setObjectName(QString("verboseLevelLabel"));
1089 gridLayout->addWidget(verboseLevelLabel, 1, 0, 1, 1);
1091 verboseLevelSpin = new QSpinBox(logGroupBox);
1092 verboseLevelSpin->setObjectName(QString("verboseLevelSpin"));
1094 gridLayout->addWidget(verboseLevelSpin, 1, 1, 1, 1);
1097 gridLayout_2->addLayout(gridLayout, 0, 0, 1, 1);
1099 horizontalLayout = new QHBoxLayout();
1100 horizontalLayout->setObjectName(QString("horizontalLayout"));
1101 logInFileCheck = new QCheckBox(logGroupBox);
1102 logInFileCheck->setObjectName(QString("logInFileCheck"));
1103 logInFileCheck->setChecked(true);
1105 horizontalLayout->addWidget(logInFileCheck);
1107 removeLogOnSuccessCheck = new QCheckBox(logGroupBox);
1108 removeLogOnSuccessCheck->setObjectName(QString("removeLogOnSuccessCheck"));
1109 removeLogOnSuccessCheck->setChecked(true);
1111 horizontalLayout->addWidget(removeLogOnSuccessCheck);
1114 gridLayout_2->addLayout(horizontalLayout, 1, 0, 1, 1);
1116 keepWorkingFilesCheck = new QCheckBox(logGroupBox);
1117 keepWorkingFilesCheck->setObjectName(QString("keepWorkingFilesCheck"));
1118 keepWorkingFilesCheck->setAutoExclusive(false);
1120 gridLayout_2->addWidget(keepWorkingFilesCheck, 2, 0, 1, 1);
1123 gridLayout_4->addWidget(logGroupBox, 3, 0, 1, 2);
1126 void MgAdaptAdvWidget::_onWorkingDirectoryPushButton()
1128 QString aDirName=QFileDialog::getExistingDirectory ();
1129 if (!(aDirName.isEmpty()))workingDirectoryLineEdit->setText(aDirName);
1131 void MgAdaptAdvWidget::onMeshDimChanged(ADAPTATION_MODE aMode)
1133 /* default adaptation mode
1134 * assume that if meshDim == 2 -->adaptation surface
1135 * if meshDim == 3 and if there is not 2D mesh -->VOLUME
1139 QString adaptation("adaptation"), value;
1142 case ADAPTATION_MODE::SURFACE:
1145 setOptionValue(adaptation, value);
1148 case ADAPTATION_MODE::BOTH :
1151 setOptionValue(adaptation, value);
1154 case ADAPTATION_MODE::VOLUME :
1157 setOptionValue(adaptation, value);
1162 void MgAdaptAdvWidget::setOptionValue(QString& option, QString& value)
1164 std::map<QString, QTreeWidgetItem *>::iterator it = optionTreeWidgetItem.find(option);
1165 if (it != optionTreeWidgetItem.end())
1167 it->second->setText( 0, tr( option.toLatin1().constData() ));
1168 it->second->setText( 1, tr( value.toLatin1().constData() ));
1169 it->second->setCheckState( 0, Qt::Checked );
1170 it->second->setData( NAME_COL, PARAM_NAME, option );
1171 myOptionTable->editItem( it->second, NAME_COL );
1176 bool isEditable( const QModelIndex& index )
1178 return index.isValid() &&
1179 index.flags() & Qt::ItemIsEditable &&
1180 index.flags() & Qt::ItemIsEnabled &&
1181 ( !index.data( Qt::UserRole + 1 ).isValid() || index.data( Qt::UserRole + 1 ).toInt() != 0 );
1185 MgAdaptAdvWidgetTreeWidget::MgAdaptAdvWidgetTreeWidget( QWidget* parent )
1186 : QTreeWidget( parent )
1190 QModelIndex MgAdaptAdvWidgetTreeWidget::moveCursor( CursorAction action, Qt::KeyboardModifiers modifiers )
1192 QModelIndex current = currentIndex();
1193 int column = current.column();
1194 if ( action == MoveNext )
1196 if ( column < columnCount()-1 )
1198 QModelIndex next = current.sibling( current.row(), column+1 );
1199 if ( isEditable( next ) ) return next;
1203 QModelIndex next = current.sibling( current.row()+1, 0 );
1204 if ( isEditable( next ) ) return next;
1207 else if ( action == MovePrevious )
1209 if ( column == 0 ) {
1210 QModelIndex next = current.sibling( current.row()-1, columnCount()-1 );
1211 if ( isEditable( next ) ) return next;
1214 QModelIndex next = current.sibling( current.row(), column-1 );
1215 if ( isEditable( next ) ) return next;
1218 return QTreeWidget::moveCursor( action, modifiers );
1221 void MgAdaptAdvWidgetTreeWidget::keyPressEvent( QKeyEvent* e )
1227 QModelIndex index = currentIndex();
1228 if ( !isEditable( index ) ) {
1229 for ( int i = 0; i < columnCount(); i++ ) {
1230 QModelIndex sibling = index.sibling( index.row(), i );
1231 if ( isEditable( sibling ) ) {
1232 if ( !edit( sibling, EditKeyPressed, e ) ) e->ignore();
1241 QTreeWidget::keyPressEvent( e );
1245 // =======================================================================
1246 // renvoie le medId associe au fichier Med apres ouverture
1247 // =======================================================================
1248 med_idt OuvrirFichier(QString aFile)
1250 med_idt medIdt = MEDfileOpen(aFile.toStdString().c_str(),MED_ACC_RDONLY);
1253 QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
1254 QObject::tr("MG_ADAPT_MED_FILE_1") );
1259 // ======================================================
1260 // ========================================================
1261 QString lireNomMaillage(QString aFile, med_int& meshdim)
1263 QString nomMaillage = QString::null ;
1267 // Ouverture du fichier
1268 medIdt = OuvrirFichier(aFile);
1274 med_int numberOfMeshes = MEDnMesh(medIdt) ;
1275 if (numberOfMeshes == 0 )
1277 QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
1278 QObject::tr("MG_ADAPT_MED_FILE_2") );
1282 if (numberOfMeshes > 1 )
1284 QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
1285 QObject::tr("MG_ADAPT_MED_FILE_3") );
1290 nomMaillage = lireNomMaillage2(medIdt,1, meshdim);
1291 // Fermeture du fichier
1292 if ( medIdt > 0 ) MEDfileClose(medIdt);
1297 // =======================================================================
1298 // =======================================================================
1299 QString lireNomMaillage2(med_idt medIdt,int meshId, med_int& meshdim )
1301 QString NomMaillage=QString::null;
1302 char meshname[MED_NAME_SIZE+1];
1304 med_mesh_type meshtype;
1305 char descriptionription[MED_COMMENT_SIZE+1];
1306 char dtunit[MED_SNAME_SIZE+1];
1307 med_sorting_type sortingtype;
1309 med_axis_type axistype;
1310 int naxis = MEDmeshnAxis(medIdt,1);
1311 char *axisname=new char[naxis*MED_SNAME_SIZE+1];
1312 char *axisunit=new char[naxis*MED_SNAME_SIZE+1];
1313 med_err aRet = MEDmeshInfo(medIdt,
1328 QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"), \
1329 QObject::tr("MG_ADAPT_MED_FILE_4") );
1332 NomMaillage=QString(meshname);
1341 // =======================================================================
1342 std::map<QString, int> GetListeChamps(QString aFile, bool errorMessage)
1343 // =======================================================================
1345 // Il faut voir si plusieurs maillages
1347 MESSAGE("GetListeChamps");
1348 std::map<QString, int> ListeChamp ;
1350 med_err erreur = 0 ;
1353 while ( erreur == 0 )
1355 // Ouverture du fichier
1356 SCRUTE(aFile.toStdString());
1357 medIdt = OuvrirFichier(aFile);
1363 // Lecture du nombre de champs
1364 med_int ncha = MEDnField(medIdt) ;
1369 QMessageBox::critical( 0, QObject::tr("_ERROR"),
1370 QObject::tr("HOM_MED_FILE_5") );
1375 // Lecture des caracteristiques des champs
1376 for (int i=0; i< ncha; i++)
1378 // Lecture du nombre de composantes
1379 med_int ncomp = MEDfieldnComponent(medIdt,i+1);
1380 // Lecture du type du champ, des noms des composantes et du nom de l'unite
1381 char nomcha [MED_NAME_SIZE+1];
1382 char meshname[MED_NAME_SIZE+1];
1383 char * comp = (char*) malloc(ncomp*MED_SNAME_SIZE+1);
1384 char * unit = (char*) malloc(ncomp*MED_SNAME_SIZE+1);
1385 char dtunit[MED_SNAME_SIZE+1];
1387 med_field_type typcha;
1389 erreur = MEDfieldInfo(medIdt,i+1,nomcha,meshname,&local,&typcha,comp,unit,dtunit,&nbofcstp) ;
1396 QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
1397 QObject::tr("MG_ADAPT_MED_FILE_6") );
1402 ListeChamp.insert(std::pair<QString, int> (QString(nomcha), nbofcstp));
1407 // Fermeture du fichier
1408 if ( medIdt > 0 ) MEDfileClose(medIdt);
1413 std::string remove_extension(const std::string& filename)
1415 size_t lastdot = filename.find_last_of(".");
1416 if (lastdot == std::string::npos) return filename;
1417 return filename.substr(0, lastdot);