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);
600 visibleTimeStepRankLabel (false);
603 connect( meshInGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( modeChanged( int ) ) );
604 connect( sizeMapDefGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( sizeMapDefChanged( int ) ) );
605 connect( selectMedFilebutton, SIGNAL( pressed( ) ), this, SLOT( onSelectMedFilebuttonClicked( ) ) );
606 connect(medFileCheckBox, SIGNAL (stateChanged(int)), this, SLOT(onMedFileCheckBox(int) ) );
607 connect(publishOut, SIGNAL (stateChanged(int)), this, SLOT(onPublishOut(int) ) );
608 connect(selectOutMedFilebutton, SIGNAL( pressed()), this, SLOT(onSelectOutMedFilebutton()));
609 connect(selectMedFileBackgroundbutton, SIGNAL(pressed()), this, SLOT(onSelectMedFileBackgroundbutton()) );
610 connect( timeStepGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( timeStepGroupChanged( int ) ) );
611 emit updateSelection();
614 //=================================================================================
615 // function : ~SMESHGUI_MgAdaptArguments()
616 // purpose : Destroys the object and frees any allocated resources
617 //=================================================================================
618 SMESHGUI_MgAdaptArguments::~SMESHGUI_MgAdaptArguments()
622 void SMESHGUI_MgAdaptArguments::onNoTimeStep(bool disableOther)
624 noTimeStep->setChecked(true);
626 visibleTimeStepRankLabel (false);
627 rankSpinBox->setValue(-2);
628 timeStep->setValue(-2);
630 lastTimeStep->setDisabled(disableOther);
631 chosenTimeStep->setDisabled(disableOther);
633 void SMESHGUI_MgAdaptArguments::onLastTimeStep(bool disableOther)
635 lastTimeStep->setChecked(true);
637 visibleTimeStepRankLabel (false);
638 rankSpinBox->setValue(-1);
639 timeStep->setValue(-1);
640 noTimeStep->setDisabled(disableOther);
642 void SMESHGUI_MgAdaptArguments::onChosenTimeStep(bool disableOther, int max)
644 chosenTimeStep->setChecked(true);
646 visibleTimeStepRankLabel (true);
647 rankSpinBox->setValue(0);
648 timeStep->setValue(0);
649 if (max) timeStep->setMaximum(max);
652 void SMESHGUI_MgAdaptArguments::visibleTimeStepRankLabel(bool visible)
654 rankLabel->setVisible(visible);
655 rankSpinBox->setVisible(visible);
657 timeStepLabel->setVisible(visible);
658 timeStep->setVisible(visible);
661 void SMESHGUI_MgAdaptArguments::onSelectOutMedFilebutton()
664 QString filtre = QString("Med") ;
665 filtre += QString(" files (*.") + QString("med") + QString(");;");
666 QString fileName = QFileDialog::getSaveFileName(this, tr("SAVE_MED"),
667 QString(""), filtre);
668 QFileInfo myFileInfo(fileName);
669 selectOutMedFileLineEdit->setText(myFileInfo.fileName());
670 *myFileOutDir = myFileInfo.path();
673 void SMESHGUI_MgAdaptArguments::onSelectMedFileBackgroundbutton()
675 QString fileName0 = selectMedFileBackgroundbutton->text().trimmed();
677 QString fileName = getMedFileName(false);
678 if (fileName != QString::null)
680 myFieldList = GetListeChamps(fileName);
681 if (myFieldList.empty())
683 fileName = fileName0;
684 fieldNameCmb->clear();
688 // fill field name Combobox
689 fieldNameCmb->clear();
690 std::map<QString, int>::const_iterator it;
691 for ( it=myFieldList.begin() ; it != myFieldList.end(); it++)
693 fieldNameCmb->insertItem(0,QString(it->first));
694 int typeStepInField = it->second > 2 ? 2 : it->second ;
695 timeStepGroupChanged(typeStepInField, true);
703 fileName = fileName0;
704 fieldNameCmb->clear();
707 QFileInfo myFileInfo(fileName);
708 *myFileSizeMapDir = myFileInfo.path();
709 selectMedFileBackgroundLineEdit->setText(myFileInfo.fileName());
712 void SMESHGUI_MgAdaptArguments::onMedFileCheckBox(int state)
714 if (state == Qt::Checked)
716 selectOutMedFilebutton->show();
717 selectOutMedFileLineEdit->show();
718 selectOutMedFilebutton->setEnabled(true);
719 selectOutMedFileLineEdit->setEnabled(true);
723 selectOutMedFilebutton->setEnabled(false);
724 selectOutMedFileLineEdit->setEnabled(false);
725 publishOut->setChecked(true);
728 void SMESHGUI_MgAdaptArguments::onPublishOut(int state)
730 if (state == Qt::Unchecked)
732 medFileCheckBox->setChecked(true);
736 void SMESHGUI_MgAdaptArguments::onSelectMedFilebuttonClicked()
738 // bool keep = false;
739 QString fileName0 = selectMedFileLineEdit->text().trimmed();
741 QString fileName = getMedFileName(false);
742 if(fileName != QString::null)
744 QString aMeshName = lireNomMaillage(fileName.trimmed(), meshDim);
745 if (aMeshName == QString::null )
747 QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
748 QObject::tr("MG_ADAPT_MED_FILE_2") );
749 fileName = fileName0;
753 meshNameLineEdit->setText(aMeshName);
754 ADAPTATION_MODE aMode = meshDim == 3 ? ADAPTATION_MODE::BOTH : ADAPTATION_MODE::SURFACE; // and when dimesh 3 without 2D mesh?
755 emit meshDimSignal(aMode);
765 QFileInfo myFileInfo(fileName);
766 *myFileInDir = myFileInfo.path();
767 *myFileOutDir = myFileInfo.path();
768 selectMedFileLineEdit->setText(myFileInfo.fileName());
769 QString outF = fileName == QString::null ? myFileInfo.fileName() :
770 QString( remove_extension(myFileInfo.fileName().toStdString() ).c_str() )+ QString(".adapt.med");
771 selectOutMedFileLineEdit->setText(outF);
772 onLocalSelected(myFileInfo.filePath());
776 void SMESHGUI_MgAdaptArguments::onLocalSelected(QString filePath)
778 myFieldList = GetListeChamps(filePath, false);
779 if (myFieldList.empty())
781 if (localButton->isChecked())
783 fieldNameCmb->clear();
789 // fill field name Combobox
790 fieldNameCmb->clear();
791 std::map<QString, int>::const_iterator it;
792 for ( it = myFieldList.begin() ; it != myFieldList.end(); it++)
794 fieldNameCmb->insertItem(0,QString(it->first));
795 int typeStepInField = it->second > 2 ? 2 : it->second ;
796 timeStepGroupChanged(typeStepInField, true);
801 // =======================================================================
802 // Gestion les boutons qui permettent de
803 // 1) retourne le nom d'un fichier par une fenetre de dialogue si aucun
804 // objet est selectionne dans l arbre d etude
805 // 2) retourne le nom du fichier asocie a l objet
806 // selectionne dans l arbre d etude
807 // =======================================================================
808 QString SMESHGUI_MgAdaptArguments::getMedFileName(bool avertir)
811 QString aFile = QString::null;
812 QString filtre = QString("Med") ;
813 filtre += QString(" files (*.") + QString("med") + QString(");;");
814 aFile = SUIT_FileDlg::getOpenFileName(0, QObject::tr("MG_ADAPT_SELECT_FILE_0"), QString(""), filtre );
819 void SMESHGUI_MgAdaptArguments::setMode(const Mode theMode, const SIZEMAP theSizeMap )
821 QRadioButton* aButton = qobject_cast<QRadioButton*>( meshInGroup->button( theMode ) );
822 QRadioButton* bButton = qobject_cast<QRadioButton*>( sizeMapDefGroup->button( theSizeMap ) );
824 aButton->setChecked( true );
825 modeChanged( theMode );
828 bButton->setChecked( true );
829 sizeMapDefChanged( theSizeMap );
833 void SMESHGUI_MgAdaptArguments::modeChanged( int theMode )
838 aBrowserObject->hide();
839 selectMedFileLineEdit->show();
840 selectMedFilebutton->show();
841 localButton->setEnabled(true);
845 selectMedFileLineEdit->hide();
846 selectMedFilebutton->hide();
847 localButton->setEnabled(false);
848 aBrowserObject->show();
849 sizeMapDefChanged(Background);
850 emit updateSelection();
857 void SMESHGUI_MgAdaptArguments::sizeMapDefChanged( int theSizeMap )
859 fieldNameCmb->clear();
860 if(theSizeMap == Local)
862 localButton->setEnabled(true);
863 localButton->setChecked(true);
864 medFileBackground->hide();
865 selectMedFileBackgroundbutton->hide();
866 selectMedFileBackgroundLineEdit->hide();
867 selectMedFileBackgroundLineEdit->clear();
871 sizeMapField->setEnabled(true);
872 if (!selectMedFileLineEdit->text().isEmpty())
874 QFileInfo myFileInfo(QDir(*myFileInDir), selectMedFileLineEdit->text());
875 onLocalSelected(myFileInfo.filePath());
878 else if (theSizeMap == Background)
880 medFileBackground->show();
881 backgroundButton->setChecked(true);
882 selectMedFileBackgroundbutton->show();
883 selectMedFileBackgroundLineEdit->show();
886 sizeMapField->setEnabled(true);
891 medFileBackground->hide();
892 constantButton->setChecked(true);
893 selectMedFileBackgroundbutton->hide();
894 selectMedFileBackgroundLineEdit->clear();
895 selectMedFileBackgroundLineEdit->hide();
898 sizeMapField->setEnabled(false);
904 void SMESHGUI_MgAdaptArguments::timeStepGroupChanged(int timeStepType, bool disableOther, int max)
906 switch (timeStepType)
909 onNoTimeStep(disableOther);
912 onLastTimeStep(disableOther);
915 onChosenTimeStep(disableOther, max);
921 void SMESHGUI_MgAdaptArguments::clear()
923 selectMedFileLineEdit->clear();
924 aBrowserObject->clear();
926 meshNameLineEdit->clear();
927 selectOutMedFileLineEdit->clear();
929 med_int SMESHGUI_MgAdaptArguments::getMeshDim() const
933 QWidget* ItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &o, const QModelIndex &index) const
935 bool editable = index.data( EDITABLE_ROLE ).toInt();
936 return editable ? QItemDelegate::createEditor( parent, o, index ) : 0;
939 //////////////////////////////////////////
941 //////////////////////////////////////////
943 MgAdaptAdvWidget::MgAdaptAdvWidget( QWidget* parent, std::vector <std::string>* options, Qt::WindowFlags f )
944 : QWidget( parent, f ), myOptions(options)
947 myOptionTable->header()->setSectionResizeMode( QHeaderView::ResizeToContents );
948 myOptionTable->setItemDelegate( new ItemDelegate( myOptionTable ) );
950 for ( int i = 0, nb = myOptions->size(); i < nb; ++i )
952 AddOption( (*myOptions)[i].c_str() );
955 connect( myOptionTable, SIGNAL( itemChanged(QTreeWidgetItem *, int)), SLOT( itemChanged(QTreeWidgetItem *, int )));
956 connect( addBtn, SIGNAL( clicked() ), this, SLOT( onAddOption() ) );
957 connect(workingDirectoryPushButton, SIGNAL(pressed()), this, SLOT(_onWorkingDirectoryPushButton()));
960 MgAdaptAdvWidget::~MgAdaptAdvWidget()
964 void MgAdaptAdvWidget::AddOption( const char* option, bool isCustom )
969 bool isDefault = false;
972 QStringList name_value_type = QString(option).split( ":", QString::KeepEmptyParts );
973 if ( name_value_type.size() > 0 )
974 name = name_value_type[0];
975 if ( name_value_type.size() > 1 )
976 value = name_value_type[1];
977 if ( name_value_type.size() > 2 )
978 isDefault = !name_value_type[2].toInt();
981 QTreeWidget* table = myOptionTable;
982 //table->setExpanded( true );
984 QTreeWidgetItem* row;
985 if (optionTreeWidgetItem.size())
987 std::map<QString, QTreeWidgetItem *>::iterator it = optionTreeWidgetItem.find(name);
988 if(it != optionTreeWidgetItem.end()) return; // option exist
991 row = getNewQTreeWidgetItem(table, option, name, isCustom);
996 row = getNewQTreeWidgetItem(table, option, name, isCustom);
998 row->setText( 0, tr( name.toLatin1().constData() ));
999 row->setText( 1, tr( value.toLatin1().constData() ));
1000 row->setCheckState( 0, isDefault ? Qt::Unchecked : Qt::Checked);
1001 row->setData( NAME_COL, PARAM_NAME, name );
1005 myOptionTable->scrollToItem( row );
1006 myOptionTable->setCurrentItem( row );
1007 myOptionTable->editItem( row, NAME_COL );
1011 QTreeWidgetItem* MgAdaptAdvWidget::getNewQTreeWidgetItem(QTreeWidget* table, const char* option, QString& name, bool isCustom)
1013 QTreeWidgetItem* row = new QTreeWidgetItem( table );
1014 row->setData( NAME_COL, EDITABLE_ROLE, int( isCustom && !option ));
1015 row->setFlags( row->flags() | Qt::ItemIsEditable );
1016 optionTreeWidgetItem.insert(std::pair <QString, QTreeWidgetItem*> (name, row));
1021 void MgAdaptAdvWidget::onAddOption()
1023 AddOption( NULL, true );
1025 void MgAdaptAdvWidget::GetOptionAndValue( QTreeWidgetItem * tblRow,
1030 option = tblRow->data( NAME_COL, PARAM_NAME ).toString();
1031 value = tblRow->text( VALUE_COL );
1032 isDefault = ! tblRow->checkState( NAME_COL );
1037 void MgAdaptAdvWidget::itemChanged(QTreeWidgetItem* tblRow, int column)
1041 myOptionTable->blockSignals( true );
1043 tblRow->setData( VALUE_COL, EDITABLE_ROLE, int( tblRow->checkState( NAME_COL )));
1045 int c = tblRow->checkState( NAME_COL ) ? 0 : 150;
1046 tblRow->setForeground( VALUE_COL, QBrush( QColor( c, c, c )));
1048 if ( column == NAME_COL && tblRow->data( NAME_COL, EDITABLE_ROLE ).toInt() ) // custom table
1050 tblRow->setData( NAME_COL, PARAM_NAME, tblRow->text( NAME_COL ));
1053 myOptionTable->blockSignals( false );
1056 void MgAdaptAdvWidget::setupWidget()
1058 if (this->objectName().isEmpty())
1059 this->setObjectName(QString(tr("MG-ADAPT-ADV")));
1060 this->resize(337, 369);
1061 gridLayout_4 = new QGridLayout(this);
1062 gridLayout_4->setObjectName(QString("gridLayout_4"));
1063 myOptionTable = new MgAdaptAdvWidgetTreeWidget(this);
1065 font.setBold(false);
1067 QTreeWidgetItem *__qtreewidgetitem = new QTreeWidgetItem();
1068 __qtreewidgetitem->setFont(1, font);
1069 __qtreewidgetitem->setFont(0, font);
1070 __qtreewidgetitem->setText(1, tr("OPTION_VALUE_COLUMN"));
1071 __qtreewidgetitem->setText(0, tr("OPTION_NAME_COLUMN"));
1072 myOptionTable->setHeaderItem(__qtreewidgetitem);
1073 myOptionTable->setObjectName(QString("myOptionTable"));
1074 myOptionTable->setEditTriggers(QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed);
1075 myOptionTable->setTabKeyNavigation(true);
1077 gridLayout_4->addWidget(myOptionTable, 0, 0, 1, 2);
1079 addBtn = new QPushButton(this);
1080 addBtn->setObjectName(QString("addBtn"));
1082 gridLayout_4->addWidget(addBtn, 1, 0, 1, 1);
1084 horizontalSpacer = new QSpacerItem(188, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
1086 gridLayout_4->addItem(horizontalSpacer, 1, 1, 1, 1);
1088 logGroupBox = new QGroupBox(this);
1089 logGroupBox->setObjectName(QString("logGroupBox"));
1090 gridLayout_2 = new QGridLayout(logGroupBox);
1091 gridLayout_2->setObjectName(QString("gridLayout_2"));
1092 gridLayout = new QGridLayout();
1093 gridLayout->setObjectName(QString("gridLayout"));
1094 workingDirectoryLabel = new QLabel(logGroupBox);
1095 workingDirectoryLabel->setObjectName(QString("workingDirectoryLabel"));
1097 gridLayout->addWidget(workingDirectoryLabel, 0, 0, 1, 1);
1099 workingDirectoryLineEdit = new QLineEdit(logGroupBox);
1100 workingDirectoryLineEdit->setObjectName(QString("workingDirectoryLineEdit"));
1102 gridLayout->addWidget(workingDirectoryLineEdit, 0, 1, 1, 1);
1104 workingDirectoryPushButton = new QPushButton(logGroupBox);
1105 workingDirectoryPushButton->setObjectName(QString("workingDirectoryPushButton"));
1107 gridLayout->addWidget(workingDirectoryPushButton, 0, 2, 1, 1);
1109 verboseLevelLabel = new QLabel(logGroupBox);
1110 verboseLevelLabel->setObjectName(QString("verboseLevelLabel"));
1112 gridLayout->addWidget(verboseLevelLabel, 1, 0, 1, 1);
1114 verboseLevelSpin = new QSpinBox(logGroupBox);
1115 verboseLevelSpin->setObjectName(QString("verboseLevelSpin"));
1117 gridLayout->addWidget(verboseLevelSpin, 1, 1, 1, 1);
1120 gridLayout_2->addLayout(gridLayout, 0, 0, 1, 1);
1122 horizontalLayout = new QHBoxLayout();
1123 horizontalLayout->setObjectName(QString("horizontalLayout"));
1124 logInFileCheck = new QCheckBox(logGroupBox);
1125 logInFileCheck->setObjectName(QString("logInFileCheck"));
1126 logInFileCheck->setChecked(true);
1128 horizontalLayout->addWidget(logInFileCheck);
1130 removeLogOnSuccessCheck = new QCheckBox(logGroupBox);
1131 removeLogOnSuccessCheck->setObjectName(QString("removeLogOnSuccessCheck"));
1132 removeLogOnSuccessCheck->setChecked(true);
1134 horizontalLayout->addWidget(removeLogOnSuccessCheck);
1137 gridLayout_2->addLayout(horizontalLayout, 1, 0, 1, 1);
1139 keepWorkingFilesCheck = new QCheckBox(logGroupBox);
1140 keepWorkingFilesCheck->setObjectName(QString("keepWorkingFilesCheck"));
1141 keepWorkingFilesCheck->setAutoExclusive(false);
1143 gridLayout_2->addWidget(keepWorkingFilesCheck, 2, 0, 1, 1);
1146 gridLayout_4->addWidget(logGroupBox, 3, 0, 1, 2);
1149 // retranslateUi(this);
1151 // QMetaObject::connectSlotsByName(this);
1154 void MgAdaptAdvWidget::_onWorkingDirectoryPushButton()
1156 QString aDirName=QFileDialog::getExistingDirectory ();
1157 if (!(aDirName.isEmpty()))workingDirectoryLineEdit->setText(aDirName);
1159 void MgAdaptAdvWidget::onMeshDimChanged(ADAPTATION_MODE aMode)
1161 /* default adaptation mode
1162 * assume that if meshDim == 2 -->adaptation surface
1163 * if meshDim == 3 and if there is not 2D mesh -->VOLUME
1167 QString adaptation("adaptation"), value;
1170 case ADAPTATION_MODE::SURFACE:
1173 setOptionValue(adaptation, value);
1176 case ADAPTATION_MODE::BOTH :
1179 setOptionValue(adaptation, value);
1182 case ADAPTATION_MODE::VOLUME :
1185 setOptionValue(adaptation, value);
1190 void MgAdaptAdvWidget::setOptionValue(QString& option, QString& value)
1193 std::map<QString, QTreeWidgetItem *>::iterator it = optionTreeWidgetItem.find(option);
1194 if (it != optionTreeWidgetItem.end())
1196 it->second->setText( 0, tr( option.toLatin1().constData() ));
1197 it->second->setText( 1, tr( value.toLatin1().constData() ));
1198 it->second->setCheckState( 0, Qt::Checked );
1199 it->second->setData( NAME_COL, PARAM_NAME, option );
1200 myOptionTable->editItem( it->second, NAME_COL );
1205 bool isEditable( const QModelIndex& index )
1207 return index.isValid() &&
1208 index.flags() & Qt::ItemIsEditable &&
1209 index.flags() & Qt::ItemIsEnabled &&
1210 ( !index.data( Qt::UserRole + 1 ).isValid() || index.data( Qt::UserRole + 1 ).toInt() != 0 );
1214 MgAdaptAdvWidgetTreeWidget::MgAdaptAdvWidgetTreeWidget( QWidget* parent )
1215 : QTreeWidget( parent )
1219 QModelIndex MgAdaptAdvWidgetTreeWidget::moveCursor( CursorAction action, Qt::KeyboardModifiers modifiers )
1221 QModelIndex current = currentIndex();
1222 int column = current.column();
1223 if ( action == MoveNext ) {
1224 if ( column < columnCount()-1 ) {
1225 QModelIndex next = current.sibling( current.row(), column+1 );
1226 if ( isEditable( next ) )
1230 QModelIndex next = current.sibling( current.row()+1, 0 );
1231 if ( isEditable( next ) )
1235 else if ( action == MovePrevious ) {
1236 if ( column == 0 ) {
1237 QModelIndex next = current.sibling( current.row()-1, columnCount()-1 );
1238 if ( isEditable( next ) )
1242 QModelIndex next = current.sibling( current.row(), column-1 );
1243 if ( isEditable( next ) )
1247 return QTreeWidget::moveCursor( action, modifiers );
1250 void MgAdaptAdvWidgetTreeWidget::keyPressEvent( QKeyEvent* e )
1252 switch ( e->key() ) {
1255 QModelIndex index = currentIndex();
1256 if ( !isEditable( index ) ) {
1257 for ( int i = 0; i < columnCount(); i++ ) {
1258 QModelIndex sibling = index.sibling( index.row(), i );
1259 if ( isEditable( sibling ) ) {
1260 if ( !edit( sibling, EditKeyPressed, e ) )
1270 QTreeWidget::keyPressEvent( e );
1274 // =======================================================================
1275 // renvoie le medId associe au fichier Med apres ouverture
1276 // =======================================================================
1277 med_idt OuvrirFichier(QString aFile)
1279 med_idt medIdt = MEDfileOpen(aFile.toStdString().c_str(),MED_ACC_RDONLY);
1282 QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
1283 QObject::tr("MG_ADAPT_MED_FILE_1") );
1288 // ======================================================
1289 // ========================================================
1290 QString lireNomMaillage(QString aFile, med_int& meshdim)
1292 QString nomMaillage = QString::null ;
1296 // Ouverture du fichier
1297 medIdt = OuvrirFichier(aFile);
1303 med_int numberOfMeshes = MEDnMesh(medIdt) ;
1304 if (numberOfMeshes == 0 )
1306 QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
1307 QObject::tr("MG_ADAPT_MED_FILE_2") );
1311 if (numberOfMeshes > 1 )
1313 QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
1314 QObject::tr("MG_ADAPT_MED_FILE_3") );
1319 nomMaillage = lireNomMaillage2(medIdt,1, meshdim);
1320 // Fermeture du fichier
1321 if ( medIdt > 0 ) MEDfileClose(medIdt);
1326 // =======================================================================
1327 // =======================================================================
1328 QString lireNomMaillage2(med_idt medIdt,int meshId, med_int& meshdim )
1330 QString NomMaillage=QString::null;
1331 char meshname[MED_NAME_SIZE+1];
1333 med_mesh_type meshtype;
1334 char descriptionription[MED_COMMENT_SIZE+1];
1335 char dtunit[MED_SNAME_SIZE+1];
1336 med_sorting_type sortingtype;
1338 med_axis_type axistype;
1339 int naxis = MEDmeshnAxis(medIdt,1);
1340 char *axisname=new char[naxis*MED_SNAME_SIZE+1];
1341 char *axisunit=new char[naxis*MED_SNAME_SIZE+1];
1342 med_err aRet = MEDmeshInfo(medIdt,
1357 QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"), \
1358 QObject::tr("MG_ADAPT_MED_FILE_4") );
1361 NomMaillage=QString(meshname);
1372 // =======================================================================
1373 std::map<QString, int> GetListeChamps(QString aFile, bool errorMessage)
1374 // =======================================================================
1376 // Il faut voir si plusieurs maillages
1378 MESSAGE("GetListeChamps");
1379 std::map<QString, int> ListeChamp ;
1381 med_err erreur = 0 ;
1384 while ( erreur == 0 )
1386 // Ouverture du fichier
1387 SCRUTE(aFile.toStdString());
1388 medIdt = OuvrirFichier(aFile);
1394 // Lecture du nombre de champs
1395 med_int ncha = MEDnField(medIdt) ;
1400 QMessageBox::critical( 0, QObject::tr("_ERROR"),
1401 QObject::tr("HOM_MED_FILE_5") );
1406 // Lecture des caracteristiques des champs
1407 for (int i=0; i< ncha; i++)
1409 // Lecture du nombre de composantes
1410 med_int ncomp = MEDfieldnComponent(medIdt,i+1);
1411 // Lecture du type du champ, des noms des composantes et du nom de l'unite
1412 char nomcha [MED_NAME_SIZE+1];
1413 char meshname[MED_NAME_SIZE+1];
1414 char * comp = (char*) malloc(ncomp*MED_SNAME_SIZE+1);
1415 char * unit = (char*) malloc(ncomp*MED_SNAME_SIZE+1);
1416 char dtunit[MED_SNAME_SIZE+1];
1418 med_field_type typcha;
1420 erreur = MEDfieldInfo(medIdt,i+1,nomcha,meshname,&local,&typcha,comp,unit,dtunit,&nbofcstp) ;
1427 QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
1428 QObject::tr("MG_ADAPT_MED_FILE_6") );
1433 ListeChamp.insert(std::pair<QString, int> (QString(nomcha), nbofcstp));
1438 // Fermeture du fichier
1439 if ( medIdt > 0 ) MEDfileClose(medIdt);
1444 std::string remove_extension(const std::string& filename) {
1445 size_t lastdot = filename.find_last_of(".");
1446 if (lastdot == std::string::npos) return filename;
1447 return filename.substr(0, lastdot);