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, MgAdapt* myModel, QWidget* parent, bool isCreation )
102 : mySMESHGUI( theModule ), QDialog(parent)
104 model = new MgAdapt(*myModel);
105 myData = model->getData();
107 if (!isCreation) readParamsFromHypo();
110 void SMESHGUI_MgAdaptDlg::buildDlg()
113 setAttribute( Qt::WA_DeleteOnClose, true );
114 setWindowTitle( tr( "ADAPT_PREF_MG_ADAPT" ) );
115 setSizeGripEnabled( true );
118 myTabWidget = new QTabWidget( this );
122 myArgs = new SMESHGUI_MgAdaptArguments( myTabWidget );
123 std::vector <std::string> str = model->getOptionValuesStrVec();
124 std::vector <std::string> str2 = model->getCustomOptionValuesStrVec();
125 str.insert( str.end(), str2.begin(), str2.end() );
127 myAdvOpt = new MgAdaptAdvWidget(myTabWidget, &str);
128 int argsTab = myTabWidget->addTab( myArgs, tr( "Args" ) );
129 int advTab = myTabWidget->addTab( myAdvOpt, tr( "ADVOP" ) );
131 myAdvOpt->workingDirectoryLabel ->setText (tr( "WORKING_DIR" ));
132 myAdvOpt->workingDirectoryPushButton ->setText (tr( "SELECT_DIR" ));
133 myAdvOpt->keepWorkingFilesCheck ->setText (tr( "KEEP_WORKING_FILES" ));
134 myAdvOpt->verboseLevelLabel ->setText (tr( "VERBOSE_LEVEL" ));
135 myAdvOpt->removeLogOnSuccessCheck ->setText (tr( "REMOVE_LOG_ON_SUCCESS" ));
136 myAdvOpt->logInFileCheck ->setText (tr( "LOG_IN_FILE" ));
137 myAdvOpt->logGroupBox ->setTitle(tr( "LOG_GROUP_TITLE" ));
140 QPushButton* okBtn = new QPushButton( tr( "SMESH_BUT_OK" ), this );
141 okBtn->setAutoDefault( true );
142 okBtn->setDefault( true );
144 QPushButton* buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), this);
145 buttonApply->setAutoDefault(true);
146 QPushButton* buttonApplyAndClose = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), this);
147 buttonApplyAndClose->setAutoDefault(true);
148 QPushButton* cancelBtn = new QPushButton( tr( "SMESH_BUT_CANCEL" ), this );
149 cancelBtn->setAutoDefault( true );
150 QPushButton* helpBtn = new QPushButton( tr( "SMESH_BUT_HELP" ), this );
151 helpBtn->setAutoDefault( true );
153 QHBoxLayout* btnLayout = new QHBoxLayout;
154 btnLayout->setSpacing( SPACING );
155 btnLayout->setMargin( 0 );
156 btnLayout->addWidget( buttonApplyAndClose );
157 btnLayout->addStretch( 10 );
158 btnLayout->addWidget( buttonApply );
159 btnLayout->addStretch( 10 );
160 btnLayout->addWidget( okBtn );
161 btnLayout->addStretch( 10 );
162 btnLayout->addWidget( cancelBtn );
163 btnLayout->addStretch( 10 );
164 btnLayout->addWidget( helpBtn );
165 okBtn->hide(); // tab 1
167 QVBoxLayout* l = new QVBoxLayout ( this );
168 l->setMargin( MARGIN );
169 l->setSpacing( SPACING );
170 l->addWidget( myTabWidget );
172 l->addLayout( btnLayout );
175 connect( okBtn, SIGNAL( clicked() ), this, SLOT( clickOnOk() ) );
176 connect( helpBtn, SIGNAL( clicked() ), this, SLOT( clickOnHelp() ) );
177 connect(cancelBtn, SIGNAL(clicked()), this, SLOT(reject()));
178 connect(buttonApply, SIGNAL(clicked()), this,SLOT(clickOnApply()));
179 connect(buttonApplyAndClose, SIGNAL(clicked()), this,SLOT(clickOnOk()));
180 connect(myArgs, SIGNAL(meshDimSignal(ADAPTATION_MODE)), myAdvOpt, SLOT( onMeshDimChanged(ADAPTATION_MODE)) );
184 //=================================================================================
185 // function : ~SMESHGUI_MgAdaptDlg()
186 // purpose : Destroys the object and frees any allocated resources
187 //=================================================================================
188 SMESHGUI_MgAdaptDlg::~SMESHGUI_MgAdaptDlg()
193 void SMESHGUI_MgAdaptDlg::setModel(MgAdapt* mg)
197 MgAdapt* SMESHGUI_MgAdaptDlg::getModel() const
202 \brief Perform clean-up actions on the dialog box closing.
204 bool SMESHGUI_MgAdaptDlg::clickOnApply()
206 readParamsFromWidgets();
209 void SMESHGUI_MgAdaptDlg::clickOnOk()
214 void SMESHGUI_MgAdaptDlg::reject()
218 bool SMESHGUI_MgAdaptDlg::readParamsFromHypo( ) const
221 myArgs->aMedfile->setChecked(myData->fromMedFile) ;
222 if (myData->fromMedFile)
225 *(myArgs->myFileInDir) = QString(myData->myFileInDir.c_str()) ;
226 myArgs->selectMedFileLineEdit->setText(myData->myMeshFileIn.c_str()) ;
227 // myData->myInMeshName = // TODO
232 myArgs->aBrowserObject->setText(myData->myInMeshName.c_str());
233 //~ myArgs->myFileInDir =""; // TODO
234 //~ myArgs->selectMedFileLineEdit->setText(); // TODO
236 myArgs->meshNameLineEdit->setText(myData->myOutMeshName.c_str());
237 myArgs->medFileCheckBox->setChecked(myData->myMeshOutMed);
239 if(myData->myMeshOutMed)
241 *(myArgs->myFileOutDir) = QString(myData->myFileOutDir.c_str());
242 myArgs->selectOutMedFileLineEdit->setText(myData->myMeshFileOut.c_str());
247 *(myArgs->myFileOutDir) = QString(""); //TODO
250 myArgs->publishOut->setChecked(myData->myPublish);
252 myArgs->localButton->setChecked(myData->myUseLocalMap);
253 myArgs->backgroundButton->setChecked(myData->myUseBackgroundMap);
254 myArgs->constantButton->setChecked(myData->myUseConstantValue);
256 if (myData->myUseConstantValue)
258 myArgs->dvalue->setValue(myData->myConstantValue);
262 myArgs->dvalue->setValue(0.0);
265 if (myData->myUseBackgroundMap)
268 *(myArgs->myFileSizeMapDir) = QString(myData->myFileSizeMapDir.c_str()) ;
269 myArgs->selectMedFileBackgroundLineEdit->setText(myData->myMeshFileBackground.c_str());
273 *(myArgs->myFileSizeMapDir) = QString("") ; //TODO
274 myArgs->selectMedFileBackgroundLineEdit->setText(""); //TODO
277 myArgs->fieldNameCmb->setCurrentText(myData->myFieldName.c_str());
278 myArgs->noTimeStep->setChecked(myData->myUseNoTimeStep);
279 myArgs->lastTimeStep->setChecked( myData->myUseLastTimeStep);
280 myArgs->chosenTimeStep->setChecked(myData->myUseChosenTimeStep);
281 if (myData->myUseChosenTimeStep)
283 myArgs->rankSpinBox->setValue(myData->myRank);
284 myArgs->timeStep->setValue(myData->myTimeStep);
287 myAdvOpt->workingDirectoryLineEdit->setText(myData->myWorkingDir.c_str());
288 myAdvOpt->logInFileCheck->setChecked(myData->myPrintLogInFile);
290 myAdvOpt->verboseLevelSpin->setValue(myData->myVerboseLevel);
291 myAdvOpt->removeLogOnSuccessCheck->setChecked(myData->myRemoveLogOnSuccess);
292 myAdvOpt->keepWorkingFilesCheck->setChecked(myData->myKeepFiles);
299 bool SMESHGUI_MgAdaptDlg::readParamsFromWidgets()
302 MgAdaptHypothesisData* aData = new MgAdaptHypothesisData();
303 aData->fromMedFile = myArgs->aMedfile->isChecked();
304 if (aData->fromMedFile)
307 aData->myFileInDir = myArgs->myFileInDir->toStdString();
308 aData->myMeshFileIn = myArgs->selectMedFileLineEdit->text().toStdString();
309 // aData->myInMeshName = // TODO
313 aData->myInMeshName = myArgs->aBrowserObject->text().toStdString();
314 aData->myFileInDir = myAdvOpt->workingDirectoryLineEdit->text().toStdString();
316 TCollection_AsciiString aGenericName = (char*)aData->myFileInDir.c_str();
317 TCollection_AsciiString aGenericName2 = "MgAdapt_";
318 aGenericName2 += getpid();
319 aGenericName2 += "_";
320 aGenericName2 += Abs((Standard_Integer)(long) aGenericName.ToCString());
321 aGenericName2 += ".med";
322 aGenericName+=aGenericName2;
323 emit myArgs->toExportMED(aGenericName.ToCString());
324 aData->myMeshFileIn = aGenericName2.ToCString();
326 aData->myOutMeshName = myArgs->meshNameLineEdit->text().toStdString();
327 aData->myMeshOutMed = myArgs->medFileCheckBox->isChecked();
328 if(aData->myMeshOutMed)
330 aData->myFileOutDir = myArgs->myFileOutDir->toStdString();
331 aData->myMeshFileOut = myArgs->selectOutMedFileLineEdit->text().toStdString();
336 aData->myMeshFileOut = "";
339 aData->myPublish = myArgs->publishOut->isChecked();
342 aData->myUseLocalMap = myArgs->localButton->isChecked();
343 aData->myUseBackgroundMap = myArgs->backgroundButton->isChecked();
344 aData->myUseConstantValue = myArgs->constantButton->isChecked();
345 if (aData->myUseConstantValue)
347 aData->myConstantValue = myArgs->dvalue->value();
351 aData->myConstantValue = 0.0;
353 if (aData->myUseBackgroundMap)
355 aData->myFileSizeMapDir = myArgs->myFileSizeMapDir->toStdString();
356 aData->myMeshFileBackground = myArgs->selectMedFileBackgroundLineEdit->text().toStdString();
360 aData->myMeshFileBackground = "";
363 aData->myFieldName = myArgs->fieldNameCmb->currentText().toStdString();
364 aData->myUseNoTimeStep = myArgs->noTimeStep->isChecked();
365 aData->myUseLastTimeStep = myArgs->lastTimeStep->isChecked();
366 aData->myUseChosenTimeStep = myArgs->chosenTimeStep->isChecked();
367 if (aData->myUseChosenTimeStep)
369 aData->myRank = myArgs->rankSpinBox->value();
370 aData->myTimeStep = myArgs->timeStep->value();
375 aData->myWorkingDir = myAdvOpt->workingDirectoryLineEdit->text().toStdString();
376 aData->myPrintLogInFile = myAdvOpt->logInFileCheck->isChecked();
377 aData->myVerboseLevel = myAdvOpt->verboseLevelSpin->value();
378 aData->myRemoveLogOnSuccess = myAdvOpt->removeLogOnSuccessCheck->isChecked();
379 aData->myKeepFiles = myAdvOpt->keepWorkingFilesCheck->isChecked();
380 model->setData(aData);
386 bool SMESHGUI_MgAdaptDlg::storeParamsToHypo( const MgAdaptHypothesisData& ) const
391 \brief Show help page
393 void SMESHGUI_MgAdaptDlg::clickOnHelp()
395 // QString aHelpFile;
396 // if ( myTabWidget->currentIndex() == MinDistance ) {
397 // aHelpFile = "measurements.html#min-distance-anchor";
398 // } else if ( myTabWidget->currentIndex() == BoundingBox ) {
399 // aHelpFile = "measurements.html#bounding-box-anchor";
400 // } else if ( myTabWidget->currentWidget() == myAngle ) {
401 // aHelpFile = "measurements.html#angle-anchor";
403 // aHelpFile = "measurements.html#basic-properties-anchor";
406 // SMESH::ShowHelpFile( aHelpFile );
408 bool SMESHGUI_MgAdaptDlg::checkParams(QString& msg)
410 if ( !QFileInfo( myAdvOpt->workingDirectoryLineEdit->text().trimmed() ).isWritable() ) {
411 SUIT_MessageBox::warning( this,
412 tr( "SMESH_WRN_WARNING" ),
413 tr( "GHS3D_PERMISSION_DENIED" ) );
418 myAdvOpt->myOptionTable->setFocus();
419 QApplication::instance()->processEvents();
422 bool isDefault, ok = true;
423 int iRow = 0, nbRows = myAdvOpt->myOptionTable->topLevelItemCount();
424 for ( ; iRow < nbRows; ++iRow )
426 QTreeWidgetItem* row = myAdvOpt->myOptionTable->topLevelItem( iRow );
427 myAdvOpt->GetOptionAndValue( row, name, value, isDefault );
429 if ( name.simplified().isEmpty() )
430 continue; // invalid custom option
432 if ( isDefault ) // not selected option
436 model->setOptionValue( name.toLatin1().constData(), value.toLatin1().constData() );
438 catch ( const SALOME::SALOME_Exception& ex )
440 msg = ex.details.text.in();
450 //=================================================================================
451 // function : SMESHGUI_MgAdaptArguments()
453 //=================================================================================
454 SMESHGUI_MgAdaptArguments::SMESHGUI_MgAdaptArguments( QWidget* parent )
459 myFileInDir = new QString("");
460 myFileOutDir = new QString("");
461 myFileSizeMapDir = new QString("");
462 if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
464 *myFileInDir = QDir::currentPath();
465 *myFileOutDir = QDir::currentPath();
466 *myFileSizeMapDir = QDir::currentPath();
470 *myFileInDir = SUIT_FileDlg::getLastVisitedPath();
471 *myFileOutDir = SUIT_FileDlg::getLastVisitedPath();
472 *myFileSizeMapDir = SUIT_FileDlg::getLastVisitedPath();
477 aMeshIn = new QGroupBox( tr( "MeshIn" ), this );
478 aMedfile = new QRadioButton( tr( "MEDFile" ), aMeshIn );
479 aBrowser = new QRadioButton( tr( "Browser" ), aMeshIn );
480 aBrowserObject = new QLineEdit( aMeshIn );
481 selectMedFilebutton = new QPushButton("", aMeshIn);
482 selectMedFileLineEdit = new QLineEdit( aMeshIn );
484 meshIn = new QGridLayout( aMeshIn );
486 meshIn->setMargin( MARGIN );
487 meshIn->setSpacing( SPACING );
488 meshIn->addWidget( aMedfile, 0, 0, 1,1 );
489 meshIn->addWidget( aBrowser, 0, 1,1,1);
490 meshIn->addWidget( aBrowserObject, 0, 2, 1, 1 );
491 meshIn->addWidget( selectMedFilebutton, 1, 0,1, 1);
492 meshIn->addWidget( selectMedFileLineEdit, 1, 1, 1, 1 );
493 hspacer = new QSpacerItem(188, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
495 meshInGroup = new QButtonGroup( this );
496 meshInGroup->addButton( aMedfile, 0 );
497 meshInGroup->addButton( aBrowser, 1 );
501 aMeshOut = new QGroupBox( tr( "MeshOut" ), this );
502 meshName = new QLabel(tr("MeshName"), aMeshOut);
503 secondHspacer = new QSpacerItem(100, 30);
504 meshNameLineEdit = new QLineEdit(aMeshOut) ;
505 medFileCheckBox = new QCheckBox(tr("MEDFile"), aMeshOut);
506 selectOutMedFilebutton = new QPushButton("", aMeshOut);
507 thirdHspacer = new QSpacerItem(188, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
508 selectOutMedFileLineEdit = new QLineEdit(aMeshOut) ;
509 publishOut = new QCheckBox(tr("Publish_MG_ADAPT"), aMeshOut);
511 meshOut = new QGridLayout( aMeshOut );
513 meshOut->setMargin( MARGIN );
514 meshOut->setSpacing( SPACING );
515 meshOut->addWidget( meshName, 0, 0, 1,1 );
516 meshOut->addItem( secondHspacer, 0, 1, 1, 1 );
517 meshOut->addWidget( meshNameLineEdit, 0, 2,1,1);
518 meshOut->addWidget( medFileCheckBox, 1, 0,1,1 );
519 meshOut->addWidget( selectOutMedFilebutton, 1, 1,1,1 );
520 meshOut->addWidget( selectOutMedFileLineEdit, 1, 2,1,1);
521 meshOut->addWidget( publishOut, 2, 0,1,1 );
523 //size map definition
525 sizeMapDefinition = new QGroupBox(tr("SIZE_MAP_DEF"), this);
526 localButton = new QRadioButton(tr("LOCAL_MG_ADAPT"), sizeMapDefinition);
527 backgroundButton = new QRadioButton(tr("BACKGRND_MG_ADAPT"), sizeMapDefinition);
528 constantButton = new QRadioButton(tr("CNST_MG_ADAPT"), sizeMapDefinition);
529 medFileBackground = new QLabel(tr("MED_FILE_BCKG"), sizeMapDefinition);
530 selectMedFileBackgroundbutton = new QPushButton(tr(""), sizeMapDefinition);
531 selectMedFileBackgroundLineEdit = new QLineEdit(sizeMapDefinition);
532 valueLabel = new QLabel(tr("VALUE_MG_ADAPT"), sizeMapDefinition);
533 dvalue = new QDoubleSpinBox(sizeMapDefinition);
534 sizeMapDefGroup = new QButtonGroup( this );
535 sizeMapDefGroup->addButton( localButton, 0 );
536 sizeMapDefGroup->addButton( backgroundButton, 1 );
537 sizeMapDefGroup->addButton( constantButton, 2 );
539 sizeMapDefGroupLayout = new QGridLayout(sizeMapDefinition);
540 sizeMapDefGroupLayout->addWidget(localButton, 0,0);
541 sizeMapDefGroupLayout->addWidget(backgroundButton, 0,1);
542 sizeMapDefGroupLayout->addWidget(constantButton, 0,2);
543 sizeMapDefGroupLayout->addWidget(medFileBackground, 1,0);
544 sizeMapDefGroupLayout->addWidget(selectMedFileBackgroundbutton, 1,1);
545 sizeMapDefGroupLayout->addWidget(selectMedFileBackgroundLineEdit, 1,2);
546 sizeMapDefGroupLayout->addWidget(valueLabel, 2,0);
547 sizeMapDefGroupLayout->addWidget(dvalue, 2,1);
550 sizeMapField = new QGroupBox(tr("SIZE_MAP_FIELD"), this);
551 fieldName = new QLabel(tr("MG_ADAPT_FIELD_NAME"), sizeMapField);
552 fieldNameCmb = new QComboBox(sizeMapField);
553 noTimeStep = new QRadioButton(tr("MG_ADAPT_NO_T_ST"), sizeMapField);
554 lastTimeStep = new QRadioButton(tr("MG_ADAPT_L_ST"), sizeMapField);
555 chosenTimeStep = new QRadioButton(tr("MG_ADAPT_CH_ST"), sizeMapField);
556 timeStepLabel = new QLabel(tr("MG_ADAPT_TSTP"), sizeMapField);
557 timeStep = new QSpinBox(sizeMapField);
558 //~timeStep->setMinimum(-1);
559 rankLabel = new QLabel(tr("MG_ADAPT_RANK"), sizeMapField);
560 rankSpinBox = new QSpinBox(sizeMapField);
561 rankSpinBox->setMinimum(-1);
563 timeStepGroup = new QButtonGroup(this);
564 timeStepGroup->addButton(noTimeStep, 0);
565 timeStepGroup->addButton(lastTimeStep, 1);
566 timeStepGroup->addButton(chosenTimeStep, 2);
568 sizeMapFieldGroupLayout = new QGridLayout(sizeMapField);
570 sizeMapFieldGroupLayout->addWidget(fieldName, 0,0);
571 sizeMapFieldGroupLayout->addWidget(fieldNameCmb, 0,1);
572 sizeMapFieldGroupLayout->addWidget(noTimeStep, 1,0);
573 sizeMapFieldGroupLayout->addWidget(lastTimeStep, 1,1);
574 sizeMapFieldGroupLayout->addWidget(chosenTimeStep, 1,2);
575 sizeMapFieldGroupLayout->addWidget(timeStepLabel, 2,0);
576 sizeMapFieldGroupLayout->addWidget(timeStep, 2,1);
577 sizeMapFieldGroupLayout->addWidget(rankLabel, 2,2);
578 sizeMapFieldGroupLayout->addWidget(rankSpinBox, 2,3);
581 QGridLayout* argumentsLayout = new QGridLayout( this );
582 argumentsLayout->setMargin( MARGIN );
583 argumentsLayout->setSpacing( SPACING );
585 argumentsLayout->addWidget( aMeshIn, 0, 0, 1, 3 );
586 argumentsLayout->addWidget( aMeshOut, 1, 0, 1, 3 );
587 argumentsLayout->addWidget( sizeMapDefinition, 2, 0, 1, 3 );
588 argumentsLayout->addWidget( sizeMapField, 3, 0, 1, 3 );
589 argumentsLayout->setColumnStretch( 1, 5 );
590 argumentsLayout->setRowStretch( 4, 5 );
593 setMode( Mesh, Local);
594 medFileCheckBox->setChecked(true);
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 rankLabel->setVisible(0);
621 rankSpinBox->setVisible(0);
622 rankSpinBox->setValue(-2);
624 timeStepLabel->setVisible(0);
625 timeStep->setVisible(0);
626 timeStep->setValue(-2);
628 lastTimeStep->setDisabled(disableOther);
629 chosenTimeStep->setDisabled(disableOther);
633 void SMESHGUI_MgAdaptArguments::onLastTimeStep(bool disableOther)
635 lastTimeStep->setChecked(true);
637 rankLabel->setVisible(0);
638 rankSpinBox->setVisible(0);
639 rankSpinBox->setValue(-1);
641 timeStepLabel->setVisible(0);
642 timeStep->setVisible(0);
643 timeStep->setValue(-1);
644 noTimeStep->setDisabled(disableOther);
647 void SMESHGUI_MgAdaptArguments::onChosenTimeStep(bool disableOther, int max)
649 chosenTimeStep->setChecked(true);
651 rankLabel->setVisible(1);
652 rankSpinBox->setVisible(1);
653 rankSpinBox->setValue(0);
655 timeStepLabel->setVisible(1);
656 timeStep->setVisible(1);
657 timeStep->setValue(0);
658 if (max) timeStep->setMaximum(max);
662 void SMESHGUI_MgAdaptArguments::onSelectOutMedFilebutton()
665 QString filtre = QString("Med") ;
666 filtre += QString(" files (*.") + QString("med") + QString(");;");
667 QString fileName = QFileDialog::getSaveFileName(this, tr("SAVE_MED"),
668 QString(""), filtre);
669 QFileInfo myFileInfo(fileName);
670 selectOutMedFileLineEdit->setText(myFileInfo.fileName());
671 *myFileOutDir = myFileInfo.path();
674 void SMESHGUI_MgAdaptArguments::onSelectMedFileBackgroundbutton()
676 QString fileName0 = selectMedFileBackgroundbutton->text().trimmed();
678 QString fileName = getMedFileName(false);
679 if (fileName != QString::null)
681 myFieldList = GetListeChamps(fileName);
682 if (myFieldList.empty())
684 fileName = fileName0;
685 fieldNameCmb->clear();
689 // fill field name Combobox
690 fieldNameCmb->clear();
691 std::map<QString, int>::const_iterator it;
692 for ( it=myFieldList.begin() ; it != myFieldList.end(); it++)
694 fieldNameCmb->insertItem(0,QString(it->first));
695 int typeStepInField = it->second > 2 ? 2 : it->second ;
696 timeStepGroupChanged(typeStepInField, true);
704 fileName = fileName0;
705 fieldNameCmb->clear();
708 QFileInfo myFileInfo(fileName);
709 *myFileSizeMapDir = myFileInfo.path();
710 selectMedFileBackgroundLineEdit->setText(myFileInfo.fileName());
713 void SMESHGUI_MgAdaptArguments::onMedFileCheckBox(int state)
715 if (state == Qt::Checked)
717 selectOutMedFilebutton->show();
718 selectOutMedFileLineEdit->show();
719 selectOutMedFilebutton->setEnabled(true);
720 selectOutMedFileLineEdit->setEnabled(true);
724 selectOutMedFilebutton->setEnabled(false);
725 selectOutMedFileLineEdit->setEnabled(false);
726 publishOut->setChecked(true);
729 void SMESHGUI_MgAdaptArguments::onPublishOut(int state)
731 if (state == Qt::Unchecked)
733 medFileCheckBox->setChecked(true);
737 void SMESHGUI_MgAdaptArguments::onSelectMedFilebuttonClicked()
739 // bool keep = false;
740 QString fileName0 = selectMedFileLineEdit->text().trimmed();
742 QString fileName = getMedFileName(false);
743 if(fileName != QString::null)
745 QString aMeshName = lireNomMaillage(fileName.trimmed(), meshDim);
746 if (aMeshName == QString::null )
748 QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
749 QObject::tr("MG_ADAPT_MED_FILE_2") );
750 fileName = fileName0;
754 meshNameLineEdit->setText(aMeshName);
755 ADAPTATION_MODE aMode = meshDim == 3 ? ADAPTATION_MODE::BOTH : ADAPTATION_MODE::SURFACE; // and when dimesh 3 without 2D mesh?
756 emit meshDimSignal(aMode);
766 QFileInfo myFileInfo(fileName);
767 *myFileInDir = myFileInfo.path();
768 *myFileOutDir = myFileInfo.path();
769 selectMedFileLineEdit->setText(myFileInfo.fileName());
770 QString outF = fileName == QString::null ? myFileInfo.fileName() :
771 QString( remove_extension(myFileInfo.fileName().toStdString() ).c_str() )+ QString(".adapt.med");
772 selectOutMedFileLineEdit->setText(outF);
773 onLocalSelected(myFileInfo.filePath());
777 void SMESHGUI_MgAdaptArguments::onLocalSelected(QString filePath)
779 myFieldList = GetListeChamps(filePath, false);
780 if (myFieldList.empty())
782 if (localButton->isChecked())
784 fieldNameCmb->clear();
790 // fill field name Combobox
791 fieldNameCmb->clear();
792 std::map<QString, int>::const_iterator it;
793 for ( it = myFieldList.begin() ; it != myFieldList.end(); it++)
795 fieldNameCmb->insertItem(0,QString(it->first));
796 int typeStepInField = it->second > 2 ? 2 : it->second ;
797 timeStepGroupChanged(typeStepInField, true);
802 // =======================================================================
803 // Gestion les boutons qui permettent de
804 // 1) retourne le nom d'un fichier par une fenetre de dialogue si aucun
805 // objet est selectionne dans l arbre d etude
806 // 2) retourne le nom du fichier asocie a l objet
807 // selectionne dans l arbre d etude
808 // =======================================================================
809 QString SMESHGUI_MgAdaptArguments::getMedFileName(bool avertir)
812 QString aFile = QString::null;
813 QString filtre = QString("Med") ;
814 filtre += QString(" files (*.") + QString("med") + QString(");;");
815 aFile = SUIT_FileDlg::getOpenFileName(0, QObject::tr("MG_ADAPT_SELECT_FILE_0"), QString(""), filtre );
820 void SMESHGUI_MgAdaptArguments::setMode(const Mode theMode, const SIZEMAP theSizeMap )
822 QRadioButton* aButton = qobject_cast<QRadioButton*>( meshInGroup->button( theMode ) );
823 QRadioButton* bButton = qobject_cast<QRadioButton*>( sizeMapDefGroup->button( theSizeMap ) );
825 aButton->setChecked( true );
826 modeChanged( theMode );
829 bButton->setChecked( true );
830 sizeMapDefChanged( theSizeMap );
834 void SMESHGUI_MgAdaptArguments::modeChanged( int theMode )
839 aBrowserObject->hide();
840 selectMedFileLineEdit->show();
841 selectMedFilebutton->show();
842 localButton->setEnabled(true);
846 selectMedFileLineEdit->hide();
847 selectMedFilebutton->hide();
848 localButton->setEnabled(false);
849 aBrowserObject->show();
850 sizeMapDefChanged(Background);
851 emit updateSelection();
858 void SMESHGUI_MgAdaptArguments::sizeMapDefChanged( int theSizeMap )
860 fieldNameCmb->clear();
861 if(theSizeMap == Local)
863 localButton->setEnabled(true);
864 localButton->setChecked(true);
865 medFileBackground->hide();
866 selectMedFileBackgroundbutton->hide();
867 selectMedFileBackgroundLineEdit->hide();
868 selectMedFileBackgroundLineEdit->clear();
872 sizeMapField->setEnabled(true);
873 if (!selectMedFileLineEdit->text().isEmpty())
875 QFileInfo myFileInfo(QDir(*myFileInDir), selectMedFileLineEdit->text());
876 onLocalSelected(myFileInfo.filePath());
879 else if (theSizeMap == Background)
881 medFileBackground->show();
882 backgroundButton->setChecked(true);
883 selectMedFileBackgroundbutton->show();
884 selectMedFileBackgroundLineEdit->show();
887 sizeMapField->setEnabled(true);
892 medFileBackground->hide();
893 constantButton->setChecked(true);
894 selectMedFileBackgroundbutton->hide();
895 selectMedFileBackgroundLineEdit->clear();
896 selectMedFileBackgroundLineEdit->hide();
899 sizeMapField->setEnabled(false);
905 void SMESHGUI_MgAdaptArguments::timeStepGroupChanged(int timeStepType, bool disableOther, int max)
907 switch (timeStepType)
910 onNoTimeStep(disableOther);
913 onLastTimeStep(disableOther);
916 onChosenTimeStep(disableOther, max);
922 void SMESHGUI_MgAdaptArguments::clear()
924 selectMedFileLineEdit->clear();
925 aBrowserObject->clear();
927 meshNameLineEdit->clear();
928 selectOutMedFileLineEdit->clear();
930 med_int SMESHGUI_MgAdaptArguments::getMeshDim() const
934 QWidget* ItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &o, const QModelIndex &index) const
936 bool editable = index.data( EDITABLE_ROLE ).toInt();
937 return editable ? QItemDelegate::createEditor( parent, o, index ) : 0;
940 //////////////////////////////////////////
942 //////////////////////////////////////////
944 MgAdaptAdvWidget::MgAdaptAdvWidget( QWidget* parent, std::vector <std::string>* options, Qt::WindowFlags f )
945 : QWidget( parent, f ), myOptions(options)
948 myOptionTable->header()->setSectionResizeMode( QHeaderView::ResizeToContents );
949 myOptionTable->setItemDelegate( new ItemDelegate( myOptionTable ) );
951 for ( int i = 0, nb = myOptions->size(); i < nb; ++i )
953 AddOption( (*myOptions)[i].c_str() );
956 connect( myOptionTable, SIGNAL( itemChanged(QTreeWidgetItem *, int)), SLOT( itemChanged(QTreeWidgetItem *, int )));
957 connect( addBtn, SIGNAL( clicked() ), this, SLOT( onAddOption() ) );
958 connect(workingDirectoryPushButton, SIGNAL(pressed()), this, SLOT(_onWorkingDirectoryPushButton()));
961 MgAdaptAdvWidget::~MgAdaptAdvWidget()
965 void MgAdaptAdvWidget::AddOption( const char* option, bool isCustom )
970 bool isDefault = false;
973 QStringList name_value_type = QString(option).split( ":", QString::KeepEmptyParts );
974 if ( name_value_type.size() > 0 )
975 name = name_value_type[0];
976 if ( name_value_type.size() > 1 )
977 value = name_value_type[1];
978 if ( name_value_type.size() > 2 )
979 isDefault = !name_value_type[2].toInt();
982 QTreeWidget* table = myOptionTable;
983 //table->setExpanded( true );
985 QTreeWidgetItem* row;
986 if (optionTreeWidgetItem.size())
988 std::map<QString, QTreeWidgetItem *>::iterator it = optionTreeWidgetItem.find(name);
989 if(it != optionTreeWidgetItem.end()) return; // option exist
992 row = getNewQTreeWidgetItem(table, option, name, isCustom);
997 row = getNewQTreeWidgetItem(table, option, name, isCustom);
999 row->setText( 0, tr( name.toLatin1().constData() ));
1000 row->setText( 1, tr( value.toLatin1().constData() ));
1001 row->setCheckState( 0, isDefault ? Qt::Unchecked : Qt::Checked);
1002 row->setData( NAME_COL, PARAM_NAME, name );
1006 myOptionTable->scrollToItem( row );
1007 myOptionTable->setCurrentItem( row );
1008 myOptionTable->editItem( row, NAME_COL );
1012 QTreeWidgetItem* MgAdaptAdvWidget::getNewQTreeWidgetItem(QTreeWidget* table, const char* option, QString& name, bool isCustom)
1014 QTreeWidgetItem* row = new QTreeWidgetItem( table );
1015 row->setData( NAME_COL, EDITABLE_ROLE, int( isCustom && !option ));
1016 row->setFlags( row->flags() | Qt::ItemIsEditable );
1017 optionTreeWidgetItem.insert(std::pair <QString, QTreeWidgetItem*> (name, row));
1022 void MgAdaptAdvWidget::onAddOption()
1024 AddOption( NULL, true );
1026 void MgAdaptAdvWidget::GetOptionAndValue( QTreeWidgetItem * tblRow,
1031 option = tblRow->data( NAME_COL, PARAM_NAME ).toString();
1032 value = tblRow->text( VALUE_COL );
1033 isDefault = ! tblRow->checkState( NAME_COL );
1038 void MgAdaptAdvWidget::itemChanged(QTreeWidgetItem* tblRow, int column)
1042 myOptionTable->blockSignals( true );
1044 tblRow->setData( VALUE_COL, EDITABLE_ROLE, int( tblRow->checkState( NAME_COL )));
1046 int c = tblRow->checkState( NAME_COL ) ? 0 : 150;
1047 tblRow->setForeground( VALUE_COL, QBrush( QColor( c, c, c )));
1049 if ( column == NAME_COL && tblRow->data( NAME_COL, EDITABLE_ROLE ).toInt() ) // custom table
1051 tblRow->setData( NAME_COL, PARAM_NAME, tblRow->text( NAME_COL ));
1054 myOptionTable->blockSignals( false );
1057 void MgAdaptAdvWidget::setupWidget()
1059 if (this->objectName().isEmpty())
1060 this->setObjectName(QString(tr("MG-ADAPT-ADV")));
1061 this->resize(337, 369);
1062 gridLayout_4 = new QGridLayout(this);
1063 gridLayout_4->setObjectName(QString("gridLayout_4"));
1064 myOptionTable = new MgAdaptAdvWidgetTreeWidget(this);
1066 font.setBold(false);
1068 QTreeWidgetItem *__qtreewidgetitem = new QTreeWidgetItem();
1069 __qtreewidgetitem->setFont(1, font);
1070 __qtreewidgetitem->setFont(0, font);
1071 __qtreewidgetitem->setText(1, tr("OPTION_VALUE_COLUMN"));
1072 __qtreewidgetitem->setText(0, tr("OPTION_NAME_COLUMN"));
1073 myOptionTable->setHeaderItem(__qtreewidgetitem);
1074 myOptionTable->setObjectName(QString("myOptionTable"));
1075 myOptionTable->setEditTriggers(QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed);
1076 myOptionTable->setTabKeyNavigation(true);
1078 gridLayout_4->addWidget(myOptionTable, 0, 0, 1, 2);
1080 addBtn = new QPushButton(this);
1081 addBtn->setObjectName(QString("addBtn"));
1083 gridLayout_4->addWidget(addBtn, 1, 0, 1, 1);
1085 horizontalSpacer = new QSpacerItem(188, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
1087 gridLayout_4->addItem(horizontalSpacer, 1, 1, 1, 1);
1089 logGroupBox = new QGroupBox(this);
1090 logGroupBox->setObjectName(QString("logGroupBox"));
1091 gridLayout_2 = new QGridLayout(logGroupBox);
1092 gridLayout_2->setObjectName(QString("gridLayout_2"));
1093 gridLayout = new QGridLayout();
1094 gridLayout->setObjectName(QString("gridLayout"));
1095 workingDirectoryLabel = new QLabel(logGroupBox);
1096 workingDirectoryLabel->setObjectName(QString("workingDirectoryLabel"));
1098 gridLayout->addWidget(workingDirectoryLabel, 0, 0, 1, 1);
1100 workingDirectoryLineEdit = new QLineEdit(logGroupBox);
1101 workingDirectoryLineEdit->setObjectName(QString("workingDirectoryLineEdit"));
1103 gridLayout->addWidget(workingDirectoryLineEdit, 0, 1, 1, 1);
1105 workingDirectoryPushButton = new QPushButton(logGroupBox);
1106 workingDirectoryPushButton->setObjectName(QString("workingDirectoryPushButton"));
1108 gridLayout->addWidget(workingDirectoryPushButton, 0, 2, 1, 1);
1110 verboseLevelLabel = new QLabel(logGroupBox);
1111 verboseLevelLabel->setObjectName(QString("verboseLevelLabel"));
1113 gridLayout->addWidget(verboseLevelLabel, 1, 0, 1, 1);
1115 verboseLevelSpin = new QSpinBox(logGroupBox);
1116 verboseLevelSpin->setObjectName(QString("verboseLevelSpin"));
1118 gridLayout->addWidget(verboseLevelSpin, 1, 1, 1, 1);
1121 gridLayout_2->addLayout(gridLayout, 0, 0, 1, 1);
1123 horizontalLayout = new QHBoxLayout();
1124 horizontalLayout->setObjectName(QString("horizontalLayout"));
1125 logInFileCheck = new QCheckBox(logGroupBox);
1126 logInFileCheck->setObjectName(QString("logInFileCheck"));
1127 logInFileCheck->setChecked(true);
1129 horizontalLayout->addWidget(logInFileCheck);
1131 removeLogOnSuccessCheck = new QCheckBox(logGroupBox);
1132 removeLogOnSuccessCheck->setObjectName(QString("removeLogOnSuccessCheck"));
1133 removeLogOnSuccessCheck->setChecked(true);
1135 horizontalLayout->addWidget(removeLogOnSuccessCheck);
1138 gridLayout_2->addLayout(horizontalLayout, 1, 0, 1, 1);
1140 keepWorkingFilesCheck = new QCheckBox(logGroupBox);
1141 keepWorkingFilesCheck->setObjectName(QString("keepWorkingFilesCheck"));
1142 keepWorkingFilesCheck->setAutoExclusive(false);
1144 gridLayout_2->addWidget(keepWorkingFilesCheck, 2, 0, 1, 1);
1147 gridLayout_4->addWidget(logGroupBox, 3, 0, 1, 2);
1150 // retranslateUi(this);
1152 // QMetaObject::connectSlotsByName(this);
1155 void MgAdaptAdvWidget::_onWorkingDirectoryPushButton()
1157 QString aDirName=QFileDialog::getExistingDirectory ();
1158 if (!(aDirName.isEmpty()))workingDirectoryLineEdit->setText(aDirName);
1160 void MgAdaptAdvWidget::onMeshDimChanged(ADAPTATION_MODE aMode)
1162 /* default adaptation mode
1163 * assume that if meshDim == 2 -->adaptation surface
1164 * if meshDim == 3 and if there is not 2D mesh -->VOLUME
1168 QString adaptation("adaptation"), value;
1171 case ADAPTATION_MODE::SURFACE:
1174 setOptionValue(adaptation, value);
1177 case ADAPTATION_MODE::BOTH :
1180 setOptionValue(adaptation, value);
1183 case ADAPTATION_MODE::VOLUME :
1186 setOptionValue(adaptation, value);
1191 void MgAdaptAdvWidget::setOptionValue(QString& option, QString& value)
1194 std::map<QString, QTreeWidgetItem *>::iterator it = optionTreeWidgetItem.find(option);
1195 if (it != optionTreeWidgetItem.end())
1197 it->second->setText( 0, tr( option.toLatin1().constData() ));
1198 it->second->setText( 1, tr( value.toLatin1().constData() ));
1199 it->second->setCheckState( 0, Qt::Checked );
1200 it->second->setData( NAME_COL, PARAM_NAME, option );
1201 myOptionTable->editItem( it->second, NAME_COL );
1206 bool isEditable( const QModelIndex& index )
1208 return index.isValid() &&
1209 index.flags() & Qt::ItemIsEditable &&
1210 index.flags() & Qt::ItemIsEnabled &&
1211 ( !index.data( Qt::UserRole + 1 ).isValid() || index.data( Qt::UserRole + 1 ).toInt() != 0 );
1215 MgAdaptAdvWidgetTreeWidget::MgAdaptAdvWidgetTreeWidget( QWidget* parent )
1216 : QTreeWidget( parent )
1220 QModelIndex MgAdaptAdvWidgetTreeWidget::moveCursor( CursorAction action, Qt::KeyboardModifiers modifiers )
1222 QModelIndex current = currentIndex();
1223 int column = current.column();
1224 if ( action == MoveNext ) {
1225 if ( column < columnCount()-1 ) {
1226 QModelIndex next = current.sibling( current.row(), column+1 );
1227 if ( isEditable( next ) )
1231 QModelIndex next = current.sibling( current.row()+1, 0 );
1232 if ( isEditable( next ) )
1236 else if ( action == MovePrevious ) {
1237 if ( column == 0 ) {
1238 QModelIndex next = current.sibling( current.row()-1, columnCount()-1 );
1239 if ( isEditable( next ) )
1243 QModelIndex next = current.sibling( current.row(), column-1 );
1244 if ( isEditable( next ) )
1248 return QTreeWidget::moveCursor( action, modifiers );
1251 void MgAdaptAdvWidgetTreeWidget::keyPressEvent( QKeyEvent* e )
1253 switch ( e->key() ) {
1256 QModelIndex index = currentIndex();
1257 if ( !isEditable( index ) ) {
1258 for ( int i = 0; i < columnCount(); i++ ) {
1259 QModelIndex sibling = index.sibling( index.row(), i );
1260 if ( isEditable( sibling ) ) {
1261 if ( !edit( sibling, EditKeyPressed, e ) )
1271 QTreeWidget::keyPressEvent( e );
1275 // =======================================================================
1276 // renvoie le medId associe au fichier Med apres ouverture
1277 // =======================================================================
1278 med_idt OuvrirFichier(QString aFile)
1280 med_idt medIdt = MEDfileOpen(aFile.toStdString().c_str(),MED_ACC_RDONLY);
1283 QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
1284 QObject::tr("MG_ADAPT_MED_FILE_1") );
1289 // ======================================================
1290 // ========================================================
1291 QString lireNomMaillage(QString aFile, med_int& meshdim)
1293 QString nomMaillage = QString::null ;
1297 // Ouverture du fichier
1298 medIdt = OuvrirFichier(aFile);
1304 med_int numberOfMeshes = MEDnMesh(medIdt) ;
1305 if (numberOfMeshes == 0 )
1307 QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
1308 QObject::tr("MG_ADAPT_MED_FILE_2") );
1312 if (numberOfMeshes > 1 )
1314 QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
1315 QObject::tr("MG_ADAPT_MED_FILE_3") );
1320 nomMaillage = lireNomMaillage2(medIdt,1, meshdim);
1321 // Fermeture du fichier
1322 if ( medIdt > 0 ) MEDfileClose(medIdt);
1327 // =======================================================================
1328 // =======================================================================
1329 QString lireNomMaillage2(med_idt medIdt,int meshId, med_int& meshdim )
1331 QString NomMaillage=QString::null;
1332 char meshname[MED_NAME_SIZE+1];
1334 med_mesh_type meshtype;
1335 char descriptionription[MED_COMMENT_SIZE+1];
1336 char dtunit[MED_SNAME_SIZE+1];
1337 med_sorting_type sortingtype;
1339 med_axis_type axistype;
1340 int naxis = MEDmeshnAxis(medIdt,1);
1341 char *axisname=new char[naxis*MED_SNAME_SIZE+1];
1342 char *axisunit=new char[naxis*MED_SNAME_SIZE+1];
1343 med_err aRet = MEDmeshInfo(medIdt,
1358 QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"), \
1359 QObject::tr("MG_ADAPT_MED_FILE_4") );
1362 NomMaillage=QString(meshname);
1373 // =======================================================================
1374 std::map<QString, int> GetListeChamps(QString aFile, bool errorMessage)
1375 // =======================================================================
1377 // Il faut voir si plusieurs maillages
1379 MESSAGE("GetListeChamps");
1380 std::map<QString, int> ListeChamp ;
1382 med_err erreur = 0 ;
1385 while ( erreur == 0 )
1387 // Ouverture du fichier
1388 SCRUTE(aFile.toStdString());
1389 medIdt = OuvrirFichier(aFile);
1395 // Lecture du nombre de champs
1396 med_int ncha = MEDnField(medIdt) ;
1401 QMessageBox::critical( 0, QObject::tr("_ERROR"),
1402 QObject::tr("HOM_MED_FILE_5") );
1407 // Lecture des caracteristiques des champs
1408 for (int i=0; i< ncha; i++)
1410 // Lecture du nombre de composantes
1411 med_int ncomp = MEDfieldnComponent(medIdt,i+1);
1412 // Lecture du type du champ, des noms des composantes et du nom de l'unite
1413 char nomcha [MED_NAME_SIZE+1];
1414 char meshname[MED_NAME_SIZE+1];
1415 char * comp = (char*) malloc(ncomp*MED_SNAME_SIZE+1);
1416 char * unit = (char*) malloc(ncomp*MED_SNAME_SIZE+1);
1417 char dtunit[MED_SNAME_SIZE+1];
1419 med_field_type typcha;
1421 erreur = MEDfieldInfo(medIdt,i+1,nomcha,meshname,&local,&typcha,comp,unit,dtunit,&nbofcstp) ;
1428 QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
1429 QObject::tr("MG_ADAPT_MED_FILE_6") );
1434 ListeChamp.insert(std::pair<QString, int> (QString(nomcha), nbofcstp));
1439 // Fermeture du fichier
1440 if ( medIdt > 0 ) MEDfileClose(medIdt);
1445 std::string remove_extension(const std::string& filename) {
1446 size_t lastdot = filename.find_last_of(".");
1447 if (lastdot == std::string::npos) return filename;
1448 return filename.substr(0, lastdot);