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 );
113 myTabWidget = new QTabWidget( this );
117 myArgs = new SMESHGUI_MgAdaptArguments( myTabWidget );
118 SMESH::str_array* str = model->getOptionValuesStrVec();
119 SMESH::str_array* str2 = model->getCustomOptionValuesStrVec();
120 std::vector<std::string> s;
121 for (int i = 0; i< str->length(); i++) s.push_back( (*str)[i].in());
122 for (int j = str->length(); j< str2->length(); j++) s.push_back((*str2)[ j - str->length() ].in() );
123 //~str.insert( str.end(), str2.begin(), str2.end() );
125 myAdvOpt = new MgAdaptAdvWidget(myTabWidget, &s);
127 int argsTab = myTabWidget->addTab( myArgs, tr( "Args" ) );
128 int advTab = myTabWidget->addTab( myAdvOpt, tr( "ADVOP" ) );
130 myAdvOpt->workingDirectoryLabel ->setText (tr( "WORKING_DIR" ));
131 myAdvOpt->workingDirectoryPushButton ->setText (tr( "SELECT_DIR" ));
132 myAdvOpt->keepWorkingFilesCheck ->setText (tr( "KEEP_WORKING_FILES" ));
133 myAdvOpt->verboseLevelLabel ->setText (tr( "VERBOSE_LEVEL" ));
134 myAdvOpt->removeLogOnSuccessCheck ->setText (tr( "REMOVE_LOG_ON_SUCCESS" ));
135 myAdvOpt->logInFileCheck ->setText (tr( "LOG_IN_FILE" ));
136 myAdvOpt->logGroupBox ->setTitle(tr( "LOG_GROUP_TITLE" ));
139 QPushButton* okBtn = new QPushButton( tr( "SMESH_BUT_OK" ), this );
140 okBtn->setAutoDefault( true );
141 okBtn->setDefault( true );
143 QPushButton* buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), this);
144 buttonApply->setAutoDefault(true);
145 QPushButton* buttonApplyAndClose = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), this);
146 buttonApplyAndClose->setAutoDefault(true);
147 QPushButton* cancelBtn = new QPushButton( tr( "SMESH_BUT_CANCEL" ), this );
148 cancelBtn->setAutoDefault( true );
149 QPushButton* helpBtn = new QPushButton( tr( "SMESH_BUT_HELP" ), this );
150 helpBtn->setAutoDefault( true );
152 QHBoxLayout* btnLayout = new QHBoxLayout;
153 btnLayout->setSpacing( SPACING );
154 btnLayout->setMargin( 0 );
155 btnLayout->addWidget( buttonApplyAndClose );
156 btnLayout->addStretch( 10 );
157 btnLayout->addWidget( buttonApply );
158 btnLayout->addStretch( 10 );
159 btnLayout->addWidget( okBtn );
160 btnLayout->addStretch( 10 );
161 btnLayout->addWidget( cancelBtn );
162 btnLayout->addStretch( 10 );
163 btnLayout->addWidget( helpBtn );
164 okBtn->hide(); // tab 1
166 QVBoxLayout* l = new QVBoxLayout ( this );
167 l->setMargin( MARGIN );
168 l->setSpacing( SPACING );
169 l->addWidget( myTabWidget );
171 l->addLayout( btnLayout );
174 connect( okBtn, SIGNAL( clicked() ), this, SLOT( clickOnOk() ) );
175 connect( helpBtn, SIGNAL( clicked() ), this, SLOT( clickOnHelp() ) );
176 connect(cancelBtn, SIGNAL(clicked()), this, SLOT(reject()));
177 connect(buttonApply, SIGNAL(clicked()), this,SLOT(clickOnApply()));
178 connect(buttonApplyAndClose, SIGNAL(clicked()), this,SLOT(clickOnOk()));
179 connect(myArgs, SIGNAL(meshDimSignal(ADAPTATION_MODE)), myAdvOpt, SLOT( onMeshDimChanged(ADAPTATION_MODE)) );
183 //=================================================================================
184 // function : ~SMESHGUI_MgAdaptDlg()
185 // purpose : Destroys the object and frees any allocated resources
186 //=================================================================================
187 SMESHGUI_MgAdaptDlg::~SMESHGUI_MgAdaptDlg()
192 //~void SMESHGUI_MgAdaptDlg::setModel(MgAdapt* mg)
196 SMESH::MG_ADAPT_ptr SMESHGUI_MgAdaptDlg::getModel() const
201 \brief Perform clean-up actions on the dialog box closing.
203 bool SMESHGUI_MgAdaptDlg::clickOnApply()
205 readParamsFromWidgets();
208 void SMESHGUI_MgAdaptDlg::clickOnOk()
213 void SMESHGUI_MgAdaptDlg::reject()
217 bool SMESHGUI_MgAdaptDlg::readParamsFromHypo( ) const
220 myArgs->aMedfile->setChecked(myData->fromMedFile) ;
221 if (myData->fromMedFile)
224 *(myArgs->myFileInDir) = QString(myData->myFileInDir) ;
225 myArgs->selectMedFileLineEdit->setText(QString(myData->myMeshFileIn)) ;
226 // myData->myInMeshName = // TODO
231 myArgs->aBrowserObject->setText(QString(myData->myInMeshName));
232 //~ myArgs->myFileInDir =""; // TODO
233 //~ myArgs->selectMedFileLineEdit->setText(); // TODO
235 myArgs->meshNameLineEdit->setText(QString(myData->myOutMeshName));
236 myArgs->medFileCheckBox->setChecked(myData->myMeshOutMed);
238 if(myData->myMeshOutMed)
240 *(myArgs->myFileOutDir) = QString(myData->myFileOutDir);
241 myArgs->selectOutMedFileLineEdit->setText(QString(myData->myMeshFileOut));
246 *(myArgs->myFileOutDir) = QString(""); //TODO
249 myArgs->publishOut->setChecked(myData->myPublish);
251 myArgs->localButton->setChecked(myData->myUseLocalMap);
252 myArgs->backgroundButton->setChecked(myData->myUseBackgroundMap);
253 myArgs->constantButton->setChecked(myData->myUseConstantValue);
255 if (myData->myUseConstantValue)
257 myArgs->dvalue->setValue(myData->myConstantValue);
261 myArgs->dvalue->setValue(0.0);
264 if (myData->myUseBackgroundMap)
267 *(myArgs->myFileSizeMapDir) = QString(myData->myFileSizeMapDir) ;
268 myArgs->selectMedFileBackgroundLineEdit->setText(QString(myData->myMeshFileBackground));
272 *(myArgs->myFileSizeMapDir) = QString("") ; //TODO
273 myArgs->selectMedFileBackgroundLineEdit->setText(""); //TODO
276 myArgs->fieldNameCmb->setCurrentText(QString(myData->myFieldName));
277 myArgs->noTimeStep->setChecked(myData->myUseNoTimeStep);
278 myArgs->lastTimeStep->setChecked( myData->myUseLastTimeStep);
279 myArgs->chosenTimeStep->setChecked(myData->myUseChosenTimeStep);
280 if (myData->myUseChosenTimeStep)
282 myArgs->rankSpinBox->setValue(myData->myRank);
283 myArgs->timeStep->setValue(myData->myTimeStep);
286 myAdvOpt->workingDirectoryLineEdit->setText(QString(myData->myWorkingDir));
287 myAdvOpt->logInFileCheck->setChecked(myData->myPrintLogInFile);
289 myAdvOpt->verboseLevelSpin->setValue(myData->myVerboseLevel);
290 myAdvOpt->removeLogOnSuccessCheck->setChecked(myData->myRemoveLogOnSuccess);
291 myAdvOpt->keepWorkingFilesCheck->setChecked(myData->myKeepFiles);
298 bool SMESHGUI_MgAdaptDlg::readParamsFromWidgets()
301 SMESH::MgAdaptHypothesisData* aData = new SMESH::MgAdaptHypothesisData();
302 aData->fromMedFile = myArgs->aMedfile->isChecked();
303 if (aData->fromMedFile)
306 aData->myFileInDir = CORBA::string_dup(myArgs->myFileInDir->toStdString().c_str());
307 aData->myMeshFileIn = CORBA::string_dup(myArgs->selectMedFileLineEdit->text().toStdString().c_str());
308 // aData->myInMeshName = // TODO
312 aData->myInMeshName = CORBA::string_dup(myArgs->aBrowserObject->text().toStdString().c_str());
313 aData->myFileInDir = CORBA::string_dup(myAdvOpt->workingDirectoryLineEdit->text().toStdString().c_str());
315 TCollection_AsciiString aGenericName = (char*)aData->myFileInDir;
316 TCollection_AsciiString aGenericName2 = "MgAdapt_";
317 aGenericName2 += getpid();
318 aGenericName2 += "_";
319 aGenericName2 += Abs((Standard_Integer)(long) aGenericName.ToCString());
320 aGenericName2 += ".med";
321 aGenericName+=aGenericName2;
322 emit myArgs->toExportMED(aGenericName.ToCString());
323 aData->myMeshFileIn = aGenericName2.ToCString();
325 aData->myOutMeshName = CORBA::string_dup(myArgs->meshNameLineEdit->text().toStdString().c_str());
326 aData->myMeshOutMed = myArgs->medFileCheckBox->isChecked();
327 if(aData->myMeshOutMed)
329 aData->myFileOutDir = CORBA::string_dup(myArgs->myFileOutDir->toStdString().c_str());
330 aData->myMeshFileOut = CORBA::string_dup(myArgs->selectOutMedFileLineEdit->text().toStdString().c_str());
335 aData->myMeshFileOut = "";
338 aData->myPublish = myArgs->publishOut->isChecked();
341 aData->myUseLocalMap = myArgs->localButton->isChecked();
342 aData->myUseBackgroundMap = myArgs->backgroundButton->isChecked();
343 aData->myUseConstantValue = myArgs->constantButton->isChecked();
344 if (aData->myUseConstantValue)
346 aData->myConstantValue = myArgs->dvalue->value();
350 aData->myConstantValue = 0.0;
352 if (aData->myUseBackgroundMap)
354 aData->myFileSizeMapDir = CORBA::string_dup(myArgs->myFileSizeMapDir->toStdString().c_str());
355 aData->myMeshFileBackground = CORBA::string_dup(myArgs->selectMedFileBackgroundLineEdit->text().toStdString().c_str());
359 aData->myMeshFileBackground = "";
362 aData->myFieldName = CORBA::string_dup(myArgs->fieldNameCmb->currentText().toStdString().c_str());
363 aData->myUseNoTimeStep = myArgs->noTimeStep->isChecked();
364 aData->myUseLastTimeStep = myArgs->lastTimeStep->isChecked();
365 aData->myUseChosenTimeStep = myArgs->chosenTimeStep->isChecked();
366 if (aData->myUseChosenTimeStep)
368 aData->myRank = myArgs->rankSpinBox->value();
369 aData->myTimeStep = myArgs->timeStep->value();
374 aData->myWorkingDir = CORBA::string_dup(myAdvOpt->workingDirectoryLineEdit->text().toStdString().c_str());
375 aData->myPrintLogInFile = myAdvOpt->logInFileCheck->isChecked();
376 aData->myVerboseLevel = myAdvOpt->verboseLevelSpin->value();
377 aData->myRemoveLogOnSuccess = myAdvOpt->removeLogOnSuccessCheck->isChecked();
378 aData->myKeepFiles = myAdvOpt->keepWorkingFilesCheck->isChecked();
379 model->setData(*aData);
385 bool SMESHGUI_MgAdaptDlg::storeParamsToHypo( const SMESH::MgAdaptHypothesisData& ) const
390 \brief Show help page
392 void SMESHGUI_MgAdaptDlg::clickOnHelp()
394 // QString aHelpFile;
395 // if ( myTabWidget->currentIndex() == MinDistance ) {
396 // aHelpFile = "measurements.html#min-distance-anchor";
397 // } else if ( myTabWidget->currentIndex() == BoundingBox ) {
398 // aHelpFile = "measurements.html#bounding-box-anchor";
399 // } else if ( myTabWidget->currentWidget() == myAngle ) {
400 // aHelpFile = "measurements.html#angle-anchor";
402 // aHelpFile = "measurements.html#basic-properties-anchor";
405 // SMESH::ShowHelpFile( aHelpFile );
407 bool SMESHGUI_MgAdaptDlg::checkParams(QString& msg)
409 if ( !QFileInfo( myAdvOpt->workingDirectoryLineEdit->text().trimmed() ).isWritable() ) {
410 SUIT_MessageBox::warning( this,
411 tr( "SMESH_WRN_WARNING" ),
412 tr( "GHS3D_PERMISSION_DENIED" ) );
417 myAdvOpt->myOptionTable->setFocus();
418 QApplication::instance()->processEvents();
421 bool isDefault, ok = true;
422 int iRow = 0, nbRows = myAdvOpt->myOptionTable->topLevelItemCount();
423 for ( ; iRow < nbRows; ++iRow )
425 QTreeWidgetItem* row = myAdvOpt->myOptionTable->topLevelItem( iRow );
426 myAdvOpt->GetOptionAndValue( row, name, value, isDefault );
428 if ( name.simplified().isEmpty() )
429 continue; // invalid custom option
431 if ( isDefault ) // not selected option
435 model->setOptionValue( name.toLatin1().constData(), value.toLatin1().constData() );
437 catch ( const SALOME::SALOME_Exception& ex )
439 msg = ex.details.text.in();
449 //=================================================================================
450 // function : SMESHGUI_MgAdaptArguments()
452 //=================================================================================
453 SMESHGUI_MgAdaptArguments::SMESHGUI_MgAdaptArguments( QWidget* parent )
458 myFileInDir = new QString("");
459 myFileOutDir = new QString("");
460 myFileSizeMapDir = new QString("");
461 if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
463 *myFileInDir = QDir::currentPath();
464 *myFileOutDir = QDir::currentPath();
465 *myFileSizeMapDir = QDir::currentPath();
469 *myFileInDir = SUIT_FileDlg::getLastVisitedPath();
470 *myFileOutDir = SUIT_FileDlg::getLastVisitedPath();
471 *myFileSizeMapDir = SUIT_FileDlg::getLastVisitedPath();
476 aMeshIn = new QGroupBox( tr( "MeshIn" ), this );
477 aMedfile = new QRadioButton( tr( "MEDFile" ), aMeshIn );
478 aBrowser = new QRadioButton( tr( "Browser" ), aMeshIn );
479 aBrowserObject = new QLineEdit( aMeshIn );
480 selectMedFilebutton = new QPushButton("", aMeshIn);
481 selectMedFileLineEdit = new QLineEdit( aMeshIn );
483 meshIn = new QGridLayout( aMeshIn );
485 meshIn->setMargin( MARGIN );
486 meshIn->setSpacing( SPACING );
487 meshIn->addWidget( aMedfile, 0, 0, 1,1 );
488 meshIn->addWidget( aBrowser, 0, 1,1,1);
489 meshIn->addWidget( aBrowserObject, 0, 2, 1, 1 );
490 meshIn->addWidget( selectMedFilebutton, 1, 0,1, 1);
491 meshIn->addWidget( selectMedFileLineEdit, 1, 1, 1, 1 );
492 hspacer = new QSpacerItem(188, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
494 meshInGroup = new QButtonGroup( this );
495 meshInGroup->addButton( aMedfile, 0 );
496 meshInGroup->addButton( aBrowser, 1 );
500 aMeshOut = new QGroupBox( tr( "MeshOut" ), this );
501 meshName = new QLabel(tr("MeshName"), aMeshOut);
502 secondHspacer = new QSpacerItem(100, 30);
503 meshNameLineEdit = new QLineEdit(aMeshOut) ;
504 medFileCheckBox = new QCheckBox(tr("MEDFile"), aMeshOut);
505 selectOutMedFilebutton = new QPushButton("", aMeshOut);
506 thirdHspacer = new QSpacerItem(188, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
507 selectOutMedFileLineEdit = new QLineEdit(aMeshOut) ;
508 publishOut = new QCheckBox(tr("Publish_MG_ADAPT"), aMeshOut);
510 meshOut = new QGridLayout( aMeshOut );
512 meshOut->setMargin( MARGIN );
513 meshOut->setSpacing( SPACING );
514 meshOut->addWidget( meshName, 0, 0, 1,1 );
515 meshOut->addItem( secondHspacer, 0, 1, 1, 1 );
516 meshOut->addWidget( meshNameLineEdit, 0, 2,1,1);
517 meshOut->addWidget( medFileCheckBox, 1, 0,1,1 );
518 meshOut->addWidget( selectOutMedFilebutton, 1, 1,1,1 );
519 meshOut->addWidget( selectOutMedFileLineEdit, 1, 2,1,1);
520 meshOut->addWidget( publishOut, 2, 0,1,1 );
522 //size map definition
524 sizeMapDefinition = new QGroupBox(tr("SIZE_MAP_DEF"), this);
525 localButton = new QRadioButton(tr("LOCAL_MG_ADAPT"), sizeMapDefinition);
526 backgroundButton = new QRadioButton(tr("BACKGRND_MG_ADAPT"), sizeMapDefinition);
527 constantButton = new QRadioButton(tr("CNST_MG_ADAPT"), sizeMapDefinition);
528 medFileBackground = new QLabel(tr("MED_FILE_BCKG"), sizeMapDefinition);
529 selectMedFileBackgroundbutton = new QPushButton(tr(""), sizeMapDefinition);
530 selectMedFileBackgroundLineEdit = new QLineEdit(sizeMapDefinition);
531 valueLabel = new QLabel(tr("VALUE_MG_ADAPT"), sizeMapDefinition);
532 dvalue = new QDoubleSpinBox(sizeMapDefinition);
533 sizeMapDefGroup = new QButtonGroup( this );
534 sizeMapDefGroup->addButton( localButton, 0 );
535 sizeMapDefGroup->addButton( backgroundButton, 1 );
536 sizeMapDefGroup->addButton( constantButton, 2 );
538 sizeMapDefGroupLayout = new QGridLayout(sizeMapDefinition);
539 sizeMapDefGroupLayout->addWidget(localButton, 0,0);
540 sizeMapDefGroupLayout->addWidget(backgroundButton, 0,1);
541 sizeMapDefGroupLayout->addWidget(constantButton, 0,2);
542 sizeMapDefGroupLayout->addWidget(medFileBackground, 1,0);
543 sizeMapDefGroupLayout->addWidget(selectMedFileBackgroundbutton, 1,1);
544 sizeMapDefGroupLayout->addWidget(selectMedFileBackgroundLineEdit, 1,2);
545 sizeMapDefGroupLayout->addWidget(valueLabel, 2,0);
546 sizeMapDefGroupLayout->addWidget(dvalue, 2,1);
549 sizeMapField = new QGroupBox(tr("SIZE_MAP_FIELD"), this);
550 fieldName = new QLabel(tr("MG_ADAPT_FIELD_NAME"), sizeMapField);
551 fieldNameCmb = new QComboBox(sizeMapField);
552 noTimeStep = new QRadioButton(tr("MG_ADAPT_NO_T_ST"), sizeMapField);
553 lastTimeStep = new QRadioButton(tr("MG_ADAPT_L_ST"), sizeMapField);
554 chosenTimeStep = new QRadioButton(tr("MG_ADAPT_CH_ST"), sizeMapField);
555 timeStepLabel = new QLabel(tr("MG_ADAPT_TSTP"), sizeMapField);
556 timeStep = new QSpinBox(sizeMapField);
557 //~timeStep->setMinimum(-1);
558 rankLabel = new QLabel(tr("MG_ADAPT_RANK"), sizeMapField);
559 rankSpinBox = new QSpinBox(sizeMapField);
560 rankSpinBox->setMinimum(-1);
562 timeStepGroup = new QButtonGroup(this);
563 timeStepGroup->addButton(noTimeStep, 0);
564 timeStepGroup->addButton(lastTimeStep, 1);
565 timeStepGroup->addButton(chosenTimeStep, 2);
567 sizeMapFieldGroupLayout = new QGridLayout(sizeMapField);
569 sizeMapFieldGroupLayout->addWidget(fieldName, 0,0);
570 sizeMapFieldGroupLayout->addWidget(fieldNameCmb, 0,1);
571 sizeMapFieldGroupLayout->addWidget(noTimeStep, 1,0);
572 sizeMapFieldGroupLayout->addWidget(lastTimeStep, 1,1);
573 sizeMapFieldGroupLayout->addWidget(chosenTimeStep, 1,2);
574 sizeMapFieldGroupLayout->addWidget(timeStepLabel, 2,0);
575 sizeMapFieldGroupLayout->addWidget(timeStep, 2,1);
576 sizeMapFieldGroupLayout->addWidget(rankLabel, 2,2);
577 sizeMapFieldGroupLayout->addWidget(rankSpinBox, 2,3);
580 QGridLayout* argumentsLayout = new QGridLayout( this );
581 argumentsLayout->setMargin( MARGIN );
582 argumentsLayout->setSpacing( SPACING );
584 argumentsLayout->addWidget( aMeshIn, 0, 0, 1, 3 );
585 argumentsLayout->addWidget( aMeshOut, 1, 0, 1, 3 );
586 argumentsLayout->addWidget( sizeMapDefinition, 2, 0, 1, 3 );
587 argumentsLayout->addWidget( sizeMapField, 3, 0, 1, 3 );
588 argumentsLayout->setColumnStretch( 1, 5 );
589 argumentsLayout->setRowStretch( 4, 5 );
592 setMode( Mesh, Local);
593 medFileCheckBox->setChecked(true);
594 visibleTimeStepRankLabel (false);
597 connect( meshInGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( modeChanged( int ) ) );
598 connect( sizeMapDefGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( sizeMapDefChanged( int ) ) );
599 connect( selectMedFilebutton, SIGNAL( pressed( ) ), this, SLOT( onSelectMedFilebuttonClicked( ) ) );
600 connect( medFileCheckBox, SIGNAL (stateChanged(int)), this, SLOT(onMedFileCheckBox(int) ) );
601 connect( publishOut, SIGNAL (stateChanged(int)), this, SLOT(onPublishOut(int) ) );
602 connect( selectOutMedFilebutton, SIGNAL( pressed()), this, SLOT(onSelectOutMedFilebutton()));
603 connect( selectMedFileBackgroundbutton, SIGNAL(pressed()), this, SLOT(onSelectMedFileBackgroundbutton()) );
604 connect( timeStepGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( timeStepGroupChanged( int ) ) );
605 emit updateSelection();
608 //=================================================================================
609 // function : ~SMESHGUI_MgAdaptArguments()
610 // purpose : Destroys the object and frees any allocated resources
611 //=================================================================================
612 SMESHGUI_MgAdaptArguments::~SMESHGUI_MgAdaptArguments()
616 void SMESHGUI_MgAdaptArguments::onNoTimeStep(bool disableOther)
618 noTimeStep->setChecked(true);
620 visibleTimeStepRankLabel (false);
621 rankSpinBox->setValue(-2);
622 timeStep->setValue(-2);
624 lastTimeStep->setDisabled(disableOther);
625 chosenTimeStep->setDisabled(disableOther);
627 void SMESHGUI_MgAdaptArguments::onLastTimeStep(bool disableOther)
629 lastTimeStep->setChecked(true);
631 visibleTimeStepRankLabel (false);
632 rankSpinBox->setValue(-1);
633 timeStep->setValue(-1);
634 noTimeStep->setDisabled(disableOther);
636 void SMESHGUI_MgAdaptArguments::onChosenTimeStep(bool disableOther, int vmax)
638 chosenTimeStep->setChecked(true);
640 visibleTimeStepRankLabel (true);
641 rankSpinBox->setValue(0);
642 timeStep->setValue(0);
643 if (vmax) timeStep->setMaximum(vmax);
646 void SMESHGUI_MgAdaptArguments::visibleTimeStepRankLabel(bool visible)
648 rankLabel->setVisible(visible);
649 rankSpinBox->setVisible(visible);
651 timeStepLabel->setVisible(visible);
652 timeStep->setVisible(visible);
655 void SMESHGUI_MgAdaptArguments::onSelectOutMedFilebutton()
658 QString filtre = QString("Med") ;
659 filtre += QString(" files (*.") + QString("med") + QString(");;");
660 QString fileName = QFileDialog::getSaveFileName(this, tr("SAVE_MED"),
661 QString(""), filtre);
662 QFileInfo myFileInfo(fileName);
663 selectOutMedFileLineEdit->setText(myFileInfo.fileName());
664 *myFileOutDir = myFileInfo.path();
667 void SMESHGUI_MgAdaptArguments::onSelectMedFileBackgroundbutton()
669 QString fileName0 = selectMedFileBackgroundbutton->text().trimmed();
671 QString fileName = getMedFileName(false);
672 if (fileName != QString::null)
674 myFieldList = GetListeChamps(fileName);
675 if (myFieldList.empty())
677 fileName = fileName0;
678 fieldNameCmb->clear();
682 // fill field name Combobox
683 fieldNameCmb->clear();
684 std::map<QString, int>::const_iterator it;
685 for ( it=myFieldList.begin() ; it != myFieldList.end(); it++)
687 fieldNameCmb->insertItem(0,QString(it->first));
688 int typeStepInField = it->second > 2 ? 2 : it->second ;
689 timeStepGroupChanged(typeStepInField, false);
697 fileName = fileName0;
698 fieldNameCmb->clear();
701 QFileInfo myFileInfo(fileName);
702 *myFileSizeMapDir = myFileInfo.path();
703 selectMedFileBackgroundLineEdit->setText(myFileInfo.fileName());
706 void SMESHGUI_MgAdaptArguments::onMedFileCheckBox(int state)
708 if (state == Qt::Checked)
710 selectOutMedFilebutton->show();
711 selectOutMedFileLineEdit->show();
712 selectOutMedFilebutton->setEnabled(true);
713 selectOutMedFileLineEdit->setEnabled(true);
717 selectOutMedFilebutton->setEnabled(false);
718 selectOutMedFileLineEdit->setEnabled(false);
719 publishOut->setChecked(true);
722 void SMESHGUI_MgAdaptArguments::onPublishOut(int state)
724 if (state == Qt::Unchecked)
726 medFileCheckBox->setChecked(true);
730 void SMESHGUI_MgAdaptArguments::onSelectMedFilebuttonClicked()
732 // bool keep = false;
733 QString fileName0 = selectMedFileLineEdit->text().trimmed();
735 QString fileName = getMedFileName(false);
736 if(fileName != QString::null)
738 QString aMeshName = lireNomMaillage(fileName.trimmed(), meshDim);
739 if (aMeshName == QString::null )
741 QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
742 QObject::tr("MG_ADAPT_MED_FILE_2") );
743 fileName = fileName0;
747 meshNameLineEdit->setText(aMeshName);
748 ADAPTATION_MODE aMode = meshDim == 3 ? ADAPTATION_MODE::BOTH : ADAPTATION_MODE::SURFACE; // and when dimesh 3 without 2D mesh?
749 emit meshDimSignal(aMode);
759 QFileInfo myFileInfo(fileName);
760 *myFileInDir = myFileInfo.path();
761 *myFileOutDir = myFileInfo.path();
762 selectMedFileLineEdit->setText(myFileInfo.fileName());
763 QString outF = fileName == QString::null ? myFileInfo.fileName() :
764 QString( remove_extension(myFileInfo.fileName().toStdString() ).c_str() )+ QString(".adapt.med");
765 selectOutMedFileLineEdit->setText(outF);
766 onLocalSelected(myFileInfo.filePath());
770 void SMESHGUI_MgAdaptArguments::onLocalSelected(QString filePath)
772 myFieldList = GetListeChamps(filePath, false);
773 if (myFieldList.empty())
775 if (localButton->isChecked())
777 fieldNameCmb->clear();
783 // fill field name Combobox
784 fieldNameCmb->clear();
785 std::map<QString, int>::const_iterator it;
786 for ( it = myFieldList.begin() ; it != myFieldList.end(); it++)
788 fieldNameCmb->insertItem(0,QString(it->first));
789 // Je ne comprends pas le rapport entre pas de temps et apparition d'un nouveau champ... GN
790 int typeStepInField = it->second > 2 ? 2 : it->second ;
791 // std::cout << "SMESHGUI_MgAdaptArguments::onLocalSelected typeStepInField : " << typeStepInField << std::endl;
792 timeStepGroupChanged(typeStepInField, false);
797 // =======================================================================
798 // Gestion les boutons qui permettent de
799 // 1) retourne le nom d'un fichier par une fenetre de dialogue si aucun
800 // objet est selectionne dans l arbre d etude
801 // 2) retourne le nom du fichier asocie a l objet
802 // selectionne dans l arbre d etude
803 // =======================================================================
804 QString SMESHGUI_MgAdaptArguments::getMedFileName(bool avertir)
807 QString aFile = QString::null;
808 QString filtre = QString("Med") ;
809 filtre += QString(" files (*.") + QString("med") + QString(");;");
810 aFile = SUIT_FileDlg::getOpenFileName(0, QObject::tr("MG_ADAPT_SELECT_FILE_0"), QString(""), filtre );
815 void SMESHGUI_MgAdaptArguments::setMode(const Mode theMode, const SIZEMAP theSizeMap )
817 QRadioButton* aButton = qobject_cast<QRadioButton*>( meshInGroup->button( theMode ) );
818 QRadioButton* bButton = qobject_cast<QRadioButton*>( sizeMapDefGroup->button( theSizeMap ) );
820 aButton->setChecked( true );
821 modeChanged( theMode );
824 bButton->setChecked( true );
825 sizeMapDefChanged( theSizeMap );
829 void SMESHGUI_MgAdaptArguments::modeChanged( int theMode )
834 aBrowserObject->hide();
835 selectMedFileLineEdit->show();
836 selectMedFilebutton->show();
837 localButton->setEnabled(true);
841 selectMedFileLineEdit->hide();
842 selectMedFilebutton->hide();
843 localButton->setEnabled(false);
844 aBrowserObject->show();
845 sizeMapDefChanged(Background);
846 emit updateSelection();
853 void SMESHGUI_MgAdaptArguments::sizeMapDefChanged( int theSizeMap )
855 fieldNameCmb->clear();
856 if(theSizeMap == Local)
858 localButton->setEnabled(true);
859 localButton->setChecked(true);
860 medFileBackground->hide();
861 selectMedFileBackgroundbutton->hide();
862 selectMedFileBackgroundLineEdit->hide();
863 selectMedFileBackgroundLineEdit->clear();
867 sizeMapField->setEnabled(true);
868 if (!selectMedFileLineEdit->text().isEmpty())
870 QFileInfo myFileInfo(QDir(*myFileInDir), selectMedFileLineEdit->text());
871 onLocalSelected(myFileInfo.filePath());
874 else if (theSizeMap == Background)
876 medFileBackground->show();
877 backgroundButton->setChecked(true);
878 selectMedFileBackgroundbutton->show();
879 selectMedFileBackgroundLineEdit->show();
882 sizeMapField->setEnabled(true);
887 medFileBackground->hide();
888 constantButton->setChecked(true);
889 selectMedFileBackgroundbutton->hide();
890 selectMedFileBackgroundLineEdit->clear();
891 selectMedFileBackgroundLineEdit->hide();
894 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 )
965 bool isDefault = false;
968 QStringList name_value_type = QString(option).split( ":", QString::KeepEmptyParts );
969 if ( name_value_type.size() > 0 )
970 name = name_value_type[0];
971 if ( name_value_type.size() > 1 )
972 value = name_value_type[1];
973 if ( name_value_type.size() > 2 )
974 isDefault = !name_value_type[2].toInt();
977 QTreeWidget* table = myOptionTable;
978 //table->setExpanded( true );
980 QTreeWidgetItem* row;
981 if (optionTreeWidgetItem.size())
983 std::map<QString, QTreeWidgetItem *>::iterator it = optionTreeWidgetItem.find(name);
984 if(it != optionTreeWidgetItem.end()) return; // option exist
987 row = getNewQTreeWidgetItem(table, option, name, isCustom);
992 row = getNewQTreeWidgetItem(table, option, name, isCustom);
994 row->setText( 0, tr( name.toLatin1().constData() ));
995 row->setText( 1, tr( value.toLatin1().constData() ));
996 row->setCheckState( 0, isDefault ? Qt::Unchecked : Qt::Checked);
997 row->setData( NAME_COL, PARAM_NAME, name );
1001 myOptionTable->scrollToItem( row );
1002 myOptionTable->setCurrentItem( row );
1003 myOptionTable->editItem( row, NAME_COL );
1007 QTreeWidgetItem* MgAdaptAdvWidget::getNewQTreeWidgetItem(QTreeWidget* table, const char* option, QString& name, bool isCustom)
1009 QTreeWidgetItem* row = new QTreeWidgetItem( table );
1010 row->setData( NAME_COL, EDITABLE_ROLE, int( isCustom && !option ));
1011 row->setFlags( row->flags() | Qt::ItemIsEditable );
1012 optionTreeWidgetItem.insert(std::pair <QString, QTreeWidgetItem*> (name, row));
1017 void MgAdaptAdvWidget::onAddOption()
1019 AddOption( NULL, true );
1021 void MgAdaptAdvWidget::GetOptionAndValue( QTreeWidgetItem * tblRow,
1026 option = tblRow->data( NAME_COL, PARAM_NAME ).toString();
1027 value = tblRow->text( VALUE_COL );
1028 isDefault = ! tblRow->checkState( NAME_COL );
1033 void MgAdaptAdvWidget::itemChanged(QTreeWidgetItem* tblRow, int column)
1037 myOptionTable->blockSignals( true );
1039 tblRow->setData( VALUE_COL, EDITABLE_ROLE, int( tblRow->checkState( NAME_COL )));
1041 int c = tblRow->checkState( NAME_COL ) ? 0 : 150;
1042 tblRow->setForeground( VALUE_COL, QBrush( QColor( c, c, c )));
1044 if ( column == NAME_COL && tblRow->data( NAME_COL, EDITABLE_ROLE ).toInt() ) // custom table
1046 tblRow->setData( NAME_COL, PARAM_NAME, tblRow->text( NAME_COL ));
1049 myOptionTable->blockSignals( false );
1052 void MgAdaptAdvWidget::setupWidget()
1054 if (this->objectName().isEmpty())
1055 this->setObjectName(QString(tr("MG-ADAPT-ADV")));
1056 this->resize(337, 369);
1057 gridLayout_4 = new QGridLayout(this);
1058 gridLayout_4->setObjectName(QString("gridLayout_4"));
1059 myOptionTable = new MgAdaptAdvWidgetTreeWidget(this);
1061 font.setBold(false);
1063 QTreeWidgetItem *__qtreewidgetitem = new QTreeWidgetItem();
1064 __qtreewidgetitem->setFont(1, font);
1065 __qtreewidgetitem->setFont(0, font);
1066 __qtreewidgetitem->setText(1, tr("OPTION_VALUE_COLUMN"));
1067 __qtreewidgetitem->setText(0, tr("OPTION_NAME_COLUMN"));
1068 myOptionTable->setHeaderItem(__qtreewidgetitem);
1069 myOptionTable->setObjectName(QString("myOptionTable"));
1070 myOptionTable->setEditTriggers(QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed);
1071 myOptionTable->setTabKeyNavigation(true);
1073 gridLayout_4->addWidget(myOptionTable, 0, 0, 1, 2);
1075 addBtn = new QPushButton(this);
1076 addBtn->setObjectName(QString("addBtn"));
1078 gridLayout_4->addWidget(addBtn, 1, 0, 1, 1);
1080 horizontalSpacer = new QSpacerItem(188, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
1082 gridLayout_4->addItem(horizontalSpacer, 1, 1, 1, 1);
1084 logGroupBox = new QGroupBox(this);
1085 logGroupBox->setObjectName(QString("logGroupBox"));
1086 gridLayout_2 = new QGridLayout(logGroupBox);
1087 gridLayout_2->setObjectName(QString("gridLayout_2"));
1088 gridLayout = new QGridLayout();
1089 gridLayout->setObjectName(QString("gridLayout"));
1090 workingDirectoryLabel = new QLabel(logGroupBox);
1091 workingDirectoryLabel->setObjectName(QString("workingDirectoryLabel"));
1093 gridLayout->addWidget(workingDirectoryLabel, 0, 0, 1, 1);
1095 workingDirectoryLineEdit = new QLineEdit(logGroupBox);
1096 workingDirectoryLineEdit->setObjectName(QString("workingDirectoryLineEdit"));
1098 gridLayout->addWidget(workingDirectoryLineEdit, 0, 1, 1, 1);
1100 workingDirectoryPushButton = new QPushButton(logGroupBox);
1101 workingDirectoryPushButton->setObjectName(QString("workingDirectoryPushButton"));
1103 gridLayout->addWidget(workingDirectoryPushButton, 0, 2, 1, 1);
1105 verboseLevelLabel = new QLabel(logGroupBox);
1106 verboseLevelLabel->setObjectName(QString("verboseLevelLabel"));
1108 gridLayout->addWidget(verboseLevelLabel, 1, 0, 1, 1);
1110 verboseLevelSpin = new QSpinBox(logGroupBox);
1111 verboseLevelSpin->setObjectName(QString("verboseLevelSpin"));
1113 gridLayout->addWidget(verboseLevelSpin, 1, 1, 1, 1);
1116 gridLayout_2->addLayout(gridLayout, 0, 0, 1, 1);
1118 horizontalLayout = new QHBoxLayout();
1119 horizontalLayout->setObjectName(QString("horizontalLayout"));
1120 logInFileCheck = new QCheckBox(logGroupBox);
1121 logInFileCheck->setObjectName(QString("logInFileCheck"));
1122 logInFileCheck->setChecked(true);
1124 horizontalLayout->addWidget(logInFileCheck);
1126 removeLogOnSuccessCheck = new QCheckBox(logGroupBox);
1127 removeLogOnSuccessCheck->setObjectName(QString("removeLogOnSuccessCheck"));
1128 removeLogOnSuccessCheck->setChecked(true);
1130 horizontalLayout->addWidget(removeLogOnSuccessCheck);
1133 gridLayout_2->addLayout(horizontalLayout, 1, 0, 1, 1);
1135 keepWorkingFilesCheck = new QCheckBox(logGroupBox);
1136 keepWorkingFilesCheck->setObjectName(QString("keepWorkingFilesCheck"));
1137 keepWorkingFilesCheck->setAutoExclusive(false);
1139 gridLayout_2->addWidget(keepWorkingFilesCheck, 2, 0, 1, 1);
1142 gridLayout_4->addWidget(logGroupBox, 3, 0, 1, 2);
1145 // retranslateUi(this);
1147 // QMetaObject::connectSlotsByName(this);
1150 void MgAdaptAdvWidget::_onWorkingDirectoryPushButton()
1152 QString aDirName=QFileDialog::getExistingDirectory ();
1153 if (!(aDirName.isEmpty()))workingDirectoryLineEdit->setText(aDirName);
1155 void MgAdaptAdvWidget::onMeshDimChanged(ADAPTATION_MODE aMode)
1157 /* default adaptation mode
1158 * assume that if meshDim == 2 -->adaptation surface
1159 * if meshDim == 3 and if there is not 2D mesh -->VOLUME
1163 QString adaptation("adaptation"), value;
1166 case ADAPTATION_MODE::SURFACE:
1169 setOptionValue(adaptation, value);
1172 case ADAPTATION_MODE::BOTH :
1175 setOptionValue(adaptation, value);
1178 case ADAPTATION_MODE::VOLUME :
1181 setOptionValue(adaptation, value);
1186 void MgAdaptAdvWidget::setOptionValue(QString& option, QString& value)
1189 std::map<QString, QTreeWidgetItem *>::iterator it = optionTreeWidgetItem.find(option);
1190 if (it != optionTreeWidgetItem.end())
1192 it->second->setText( 0, tr( option.toLatin1().constData() ));
1193 it->second->setText( 1, tr( value.toLatin1().constData() ));
1194 it->second->setCheckState( 0, Qt::Checked );
1195 it->second->setData( NAME_COL, PARAM_NAME, option );
1196 myOptionTable->editItem( it->second, NAME_COL );
1201 bool isEditable( const QModelIndex& index )
1203 return index.isValid() &&
1204 index.flags() & Qt::ItemIsEditable &&
1205 index.flags() & Qt::ItemIsEnabled &&
1206 ( !index.data( Qt::UserRole + 1 ).isValid() || index.data( Qt::UserRole + 1 ).toInt() != 0 );
1210 MgAdaptAdvWidgetTreeWidget::MgAdaptAdvWidgetTreeWidget( QWidget* parent )
1211 : QTreeWidget( parent )
1215 QModelIndex MgAdaptAdvWidgetTreeWidget::moveCursor( CursorAction action, Qt::KeyboardModifiers modifiers )
1217 QModelIndex current = currentIndex();
1218 int column = current.column();
1219 if ( action == MoveNext ) {
1220 if ( column < columnCount()-1 ) {
1221 QModelIndex next = current.sibling( current.row(), column+1 );
1222 if ( isEditable( next ) )
1226 QModelIndex next = current.sibling( current.row()+1, 0 );
1227 if ( isEditable( next ) )
1231 else if ( action == MovePrevious ) {
1232 if ( column == 0 ) {
1233 QModelIndex next = current.sibling( current.row()-1, columnCount()-1 );
1234 if ( isEditable( next ) )
1238 QModelIndex next = current.sibling( current.row(), column-1 );
1239 if ( isEditable( next ) )
1243 return QTreeWidget::moveCursor( action, modifiers );
1246 void MgAdaptAdvWidgetTreeWidget::keyPressEvent( QKeyEvent* e )
1248 switch ( e->key() ) {
1251 QModelIndex index = currentIndex();
1252 if ( !isEditable( index ) ) {
1253 for ( int i = 0; i < columnCount(); i++ ) {
1254 QModelIndex sibling = index.sibling( index.row(), i );
1255 if ( isEditable( sibling ) ) {
1256 if ( !edit( sibling, EditKeyPressed, e ) )
1266 QTreeWidget::keyPressEvent( e );
1270 // =======================================================================
1271 // renvoie le medId associe au fichier Med apres ouverture
1272 // =======================================================================
1273 med_idt OuvrirFichier(QString aFile)
1275 med_idt medIdt = MEDfileOpen(aFile.toStdString().c_str(),MED_ACC_RDONLY);
1278 QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
1279 QObject::tr("MG_ADAPT_MED_FILE_1") );
1284 // ======================================================
1285 // ========================================================
1286 QString lireNomMaillage(QString aFile, med_int& meshdim)
1288 QString nomMaillage = QString::null ;
1292 // Ouverture du fichier
1293 medIdt = OuvrirFichier(aFile);
1299 med_int numberOfMeshes = MEDnMesh(medIdt) ;
1300 if (numberOfMeshes == 0 )
1302 QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
1303 QObject::tr("MG_ADAPT_MED_FILE_2") );
1307 if (numberOfMeshes > 1 )
1309 QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
1310 QObject::tr("MG_ADAPT_MED_FILE_3") );
1315 nomMaillage = lireNomMaillage2(medIdt,1, meshdim);
1316 // Fermeture du fichier
1317 if ( medIdt > 0 ) MEDfileClose(medIdt);
1322 // =======================================================================
1323 // =======================================================================
1324 QString lireNomMaillage2(med_idt medIdt,int meshId, med_int& meshdim )
1326 QString NomMaillage=QString::null;
1327 char meshname[MED_NAME_SIZE+1];
1329 med_mesh_type meshtype;
1330 char descriptionription[MED_COMMENT_SIZE+1];
1331 char dtunit[MED_SNAME_SIZE+1];
1332 med_sorting_type sortingtype;
1334 med_axis_type axistype;
1335 int naxis = MEDmeshnAxis(medIdt,1);
1336 char *axisname=new char[naxis*MED_SNAME_SIZE+1];
1337 char *axisunit=new char[naxis*MED_SNAME_SIZE+1];
1338 med_err aRet = MEDmeshInfo(medIdt,
1353 QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"), \
1354 QObject::tr("MG_ADAPT_MED_FILE_4") );
1357 NomMaillage=QString(meshname);
1368 // =======================================================================
1369 std::map<QString, int> GetListeChamps(QString aFile, bool errorMessage)
1370 // =======================================================================
1372 // Il faut voir si plusieurs maillages
1374 MESSAGE("GetListeChamps");
1375 std::map<QString, int> ListeChamp ;
1377 med_err erreur = 0 ;
1380 while ( erreur == 0 )
1382 // Ouverture du fichier
1383 SCRUTE(aFile.toStdString());
1384 medIdt = OuvrirFichier(aFile);
1390 // Lecture du nombre de champs
1391 med_int ncha = MEDnField(medIdt) ;
1396 QMessageBox::critical( 0, QObject::tr("_ERROR"),
1397 QObject::tr("HOM_MED_FILE_5") );
1402 // Lecture des caracteristiques des champs
1403 for (int i=0; i< ncha; i++)
1405 // Lecture du nombre de composantes
1406 med_int ncomp = MEDfieldnComponent(medIdt,i+1);
1407 // Lecture du type du champ, des noms des composantes et du nom de l'unite
1408 char nomcha [MED_NAME_SIZE+1];
1409 char meshname[MED_NAME_SIZE+1];
1410 char * comp = (char*) malloc(ncomp*MED_SNAME_SIZE+1);
1411 char * unit = (char*) malloc(ncomp*MED_SNAME_SIZE+1);
1412 char dtunit[MED_SNAME_SIZE+1];
1414 med_field_type typcha;
1416 erreur = MEDfieldInfo(medIdt,i+1,nomcha,meshname,&local,&typcha,comp,unit,dtunit,&nbofcstp) ;
1423 QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
1424 QObject::tr("MG_ADAPT_MED_FILE_6") );
1429 ListeChamp.insert(std::pair<QString, int> (QString(nomcha), nbofcstp));
1434 // Fermeture du fichier
1435 if ( medIdt > 0 ) MEDfileClose(medIdt);
1440 std::string remove_extension(const std::string& filename) {
1441 size_t lastdot = filename.find_last_of(".");
1442 if (lastdot == std::string::npos) return filename;
1443 return filename.substr(0, lastdot);