Salome HOME
#23999 EDF 22760 - integration of dev in SMESH (from branch 'gni/adaptation')
[modules/smesh.git] / src / SMESHGUI / MG_ADAPTGUI.cxx
index c1df37aa722ed4b2228521c3eca02aec7d08b7eb..b8ee3c879dc7afdb90ccc7456503fb8161c7937d 100644 (file)
@@ -487,13 +487,14 @@ SMESHGUI_MgAdaptArguments::SMESHGUI_MgAdaptArguments( QWidget* parent )
   }
 
   meshDim = 0;
+  meshDimBG = 0;
   // Mesh in
   aMeshIn = new QGroupBox( tr( "MeshIn" ), this );
   aMedfile       = new QRadioButton( tr( "MEDFile" ),    aMeshIn );
   aBrowser       = new QRadioButton( tr( "Browser" ), aMeshIn );
   aBrowserObject = new QLineEdit(  aMeshIn );
-  selectMedFilebutton = new QPushButton("", aMeshIn);
-  selectMedFileLineEdit      = new QLineEdit(  aMeshIn );
+  selectMedFilebutton = new QPushButton("...", aMeshIn);
+  selectMedFileLineEdit = new QLineEdit(  aMeshIn );
 
   meshIn = new QGridLayout( aMeshIn );
 
@@ -517,7 +518,7 @@ SMESHGUI_MgAdaptArguments::SMESHGUI_MgAdaptArguments( QWidget* parent )
   secondHspacer = new QSpacerItem(100, 30);
   meshNameLineEdit = new QLineEdit(aMeshOut) ;
   medFileCheckBox = new QCheckBox(tr("MEDFile"), aMeshOut);
-  selectOutMedFilebutton = new QPushButton("", aMeshOut);
+  selectOutMedFilebutton = new QPushButton("...", aMeshOut);
   thirdHspacer = new QSpacerItem(188, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
   selectOutMedFileLineEdit = new QLineEdit(aMeshOut) ;
   publishOut = new  QCheckBox(tr("Publish_MG_ADAPT"), aMeshOut);
@@ -541,7 +542,7 @@ SMESHGUI_MgAdaptArguments::SMESHGUI_MgAdaptArguments( QWidget* parent )
   backgroundButton = new QRadioButton(tr("BACKGRND_MG_ADAPT"), sizeMapDefinition);
   constantButton = new QRadioButton(tr("CNST_MG_ADAPT"), sizeMapDefinition);
   medFileBackground = new QLabel(tr("MED_FILE_BCKG"), sizeMapDefinition);
-  selectMedFileBackgroundbutton = new QPushButton(tr(""), sizeMapDefinition);
+  selectMedFileBackgroundbutton = new QPushButton("...", sizeMapDefinition);
   selectMedFileBackgroundLineEdit = new QLineEdit(sizeMapDefinition);
   valueLabel = new QLabel(tr("VALUE_MG_ADAPT"), sizeMapDefinition);
   dvalue = new QDoubleSpinBox(sizeMapDefinition);
@@ -701,6 +702,10 @@ void SMESHGUI_MgAdaptArguments::onSelectMedFileBackgroundbutton()
         int typeStepInField = it->second > 2 ?  2 : it->second ;
         timeStepGroupChanged(typeStepInField, false);
       }
+      // Dimension du maillage de fonds
+      MEDCoupling::MCAuto<MEDCoupling::MEDFileData> mfd = MEDCoupling::MEDFileData::New(fileName.toStdString());
+      meshDimBG = mfd->getMeshes()->getMeshAtPos(0)->getMeshDimension() ;
+      valueAdaptation ();
     }
   }
   else
@@ -756,8 +761,9 @@ void SMESHGUI_MgAdaptArguments::onSelectMedFilebuttonClicked()
     else
     {
       meshNameLineEdit->setText(aMeshName);
-      ADAPTATION_MODE aMode = meshDim == 3 ? ADAPTATION_MODE::BOTH : ADAPTATION_MODE::SURFACE; // and when dimesh 3 without 2D mesh?
-      emit meshDimSignal(aMode);
+      valueAdaptation ();
+//       ADAPTATION_MODE aMode = meshDim == 3 ? ADAPTATION_MODE::BOTH : ADAPTATION_MODE::SURFACE; // and when dimesh 3 without 2D mesh?
+//       emit meshDimSignal(aMode);
     }
   }
   else
@@ -776,6 +782,20 @@ void SMESHGUI_MgAdaptArguments::onSelectMedFilebuttonClicked()
 
 }
 
+void SMESHGUI_MgAdaptArguments::valueAdaptation()
+{
+  ADAPTATION_MODE aMode ;
+  if ( meshDimBG < 3 )
+  {
+    aMode = meshDim == 3 ? ADAPTATION_MODE::BOTH : ADAPTATION_MODE::SURFACE;
+  }
+  else
+  {
+    aMode = ADAPTATION_MODE::BOTH;
+  }
+  emit meshDimSignal(aMode);
+}
+
 void SMESHGUI_MgAdaptArguments::onLocalSelected(QString filePath)
 {
   myFieldList = GetListeChamps(filePath, false);
@@ -886,7 +906,6 @@ void SMESHGUI_MgAdaptArguments::sizeMapDefChanged( int  theSizeMap )
     valueLabel->hide();
     dvalue->hide();
     sizeMapField->setEnabled(true);
-
   }
   else
   {
@@ -899,6 +918,8 @@ void SMESHGUI_MgAdaptArguments::sizeMapDefChanged( int  theSizeMap )
     dvalue->show();
     sizeMapField->setEnabled(false);
   }
+  meshDimBG = 0;
+  valueAdaptation();
 }
 void SMESHGUI_MgAdaptArguments::timeStepGroupChanged(int timeStepType, bool disableOther, int vmax)
 {
@@ -925,10 +946,10 @@ void SMESHGUI_MgAdaptArguments::clear()
   meshNameLineEdit->clear();
   selectOutMedFileLineEdit->clear();
 }
-med_int SMESHGUI_MgAdaptArguments::getMeshDim() const
-{
-  return meshDim;
-}
+// med_int SMESHGUI_MgAdaptArguments::getMeshDim() const
+// {
+//   return meshDim;
+// }
 QWidget* ItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &o, const QModelIndex &index) const
 {
   bool editable = index.data( EDITABLE_ROLE ).toInt();
@@ -1072,6 +1093,7 @@ void MgAdaptAdvWidget::setupWidget()
   gridLayout_4->addWidget(myOptionTable, 0, 0, 1, 2);
 
   addBtn = new QPushButton(this);
+  addBtn->setText(QApplication::translate("SMESH_AdvOptionsWdg", "ADD_OPTION_BTN", Q_NULLPTR));
   addBtn->setObjectName(QString("addBtn"));
 
   gridLayout_4->addWidget(addBtn, 1, 0, 1, 1);
@@ -1149,7 +1171,7 @@ void MgAdaptAdvWidget::_onWorkingDirectoryPushButton()
 void MgAdaptAdvWidget::onMeshDimChanged(ADAPTATION_MODE aMode)
 {
 /* default adaptation mode
-  * assume that if meshDim == 2 -->adaptation surface
+  * assume that if meshDim == 2 and no 3D backgrounmesh-->adaptation surface
   * if meshDim == 3 and  if there is not 2D mesh -->VOLUME
   * else BOTH
   */
@@ -1259,65 +1281,54 @@ void MgAdaptAdvWidgetTreeWidget::keyPressEvent( QKeyEvent* e )
   QTreeWidget::keyPressEvent( e );
 }
 
-
-// =======================================================================
-// renvoie le medId associe au fichier Med apres ouverture
-// =======================================================================
-med_idt OuvrirFichier(QString aFile)
-{
-  med_idt medIdt = MEDfileOpen(aFile.toStdString().c_str(),MED_ACC_RDONLY);
-  if (medIdt <0)
-  {
-    QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
-                              QObject::tr("MG_ADAPT_MED_FILE_1") );
-  }
-  return medIdt;
-}
-
 // ======================================================
 // ========================================================
 QString lireNomMaillage(QString aFile, med_int& meshdim)
 {
   QString nomMaillage = QString::null ;
 
-  std::vector<std::string> listMeshesNames = MEDCoupling::GetMeshNames(aFile.toStdString());
-
-  std::size_t numberOfMeshes(listMeshesNames.size());
-//   std::cout << "numberOfMeshes:" << numberOfMeshes << std::endl;
-  if (numberOfMeshes == 0 )
-  {
-    QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
-                              QObject::tr("MG_ADAPT_MED_FILE_2") );
-    return nomMaillage;
-  }
-  if (numberOfMeshes > 1 )
+  while ( true )
   {
-    QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
-                              QObject::tr("MG_ADAPT_MED_FILE_3") );
-    return nomMaillage;
-  }
+    std::vector<std::string> listMeshesNames = MEDCoupling::GetMeshNames(aFile.toStdString());
+
+    std::size_t numberOfMeshes(listMeshesNames.size());
+  //   std::cout << "numberOfMeshes:" << numberOfMeshes << std::endl;
+    if (numberOfMeshes == 0 )
+    {
+      QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
+                                QObject::tr("MG_ADAPT_MED_FILE_2") );
+      break ;
+    }
+    if (numberOfMeshes > 1 )
+    {
+      QMessageBox::critical( 0, QObject::tr("MG_ADAPT_ERROR"),
+                                QObject::tr("MG_ADAPT_MED_FILE_3") );
+      break ;
+    }
 
-//   std::cout << "numberOfMeshes:" << numberOfMeshes << std::endl;
-  std::cout << "nomMaillage:" << listMeshesNames[0] << std::endl;
-  nomMaillage = QString(listMeshesNames[0].c_str());
+//     std::cout << "nomMaillage:" << listMeshesNames[0] << std::endl;
+    nomMaillage = QString(listMeshesNames[0].c_str());
+
+    // Dimension du maillage
+    MEDCoupling::MCAuto<MEDCoupling::MEDFileData> mfd = MEDCoupling::MEDFileData::New(aFile.toStdString());
+    meshdim = mfd->getMeshes()->getMeshAtPos(0)->getMeshDimension() ;
+//     std::cout << "meshdim:" << meshdim << std::endl;
+
+    break ;
+  }
 
   return nomMaillage;
 }
 
-// =======================================================================
-
 // =======================================================================
 std::map<QString, int> GetListeChamps(QString aFile, bool errorMessage)
 // =======================================================================
 {
 // Il faut voir si plusieurs maillages
 
-  MESSAGE("GetListeChamps");
   std::map<QString, int> ListeChamp ;
 
-  med_err erreur = 0 ;
-
-  while ( erreur == 0 )
+  while ( true )
   {
     MEDCoupling::MCAuto<MEDCoupling::MEDFileData> mfd = MEDCoupling::MEDFileData::New(aFile.toStdString());
     std::vector<std::string> listFieldsNames(mfd->getFields()->getFieldsNames());
@@ -1329,9 +1340,9 @@ std::map<QString, int> GetListeChamps(QString aFile, bool errorMessage)
         QMessageBox::critical( 0, QObject::tr("_ERROR"),
                                   QObject::tr("HOM_MED_FILE_5") );
       }
-      erreur = 2 ;
       break ;
     }
+    // nbofcstp inutile pour le moment
     med_int nbofcstp = 1;
     for(std::size_t j=0;j<jaux;j++)
     {
@@ -1344,7 +1355,9 @@ std::map<QString, int> GetListeChamps(QString aFile, bool errorMessage)
   return ListeChamp;
 }
 
+// =======================================================================
 std::string remove_extension(const std::string& filename)
+// =======================================================================
 {
   size_t lastdot = filename.find_last_of(".");
   if (lastdot == std::string::npos) return filename;