Salome HOME
Update copyrights
[modules/homard.git] / src / HOMARDGUI / HomardQtCommun.cxx
index 188b6ed665bdc65e2f9054b04a8e314341e1fab5..20043f32185f49fa9c4a5b04d3a3f784eeee3fb0 100644 (file)
@@ -1,9 +1,9 @@
-// Copyright (C) 2011-2013  CEA/DEN, EDF R&D
+// Copyright (C) 2011-2019  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 #include <qfiledialog.h>
 #include <qstring.h>
 #include <stdlib.h>
+#ifndef WIN32
 #include <unistd.h>
+#endif
 #include <sys/stat.h>
 
 
 #include "SalomeApp_Tools.h"
 
 using namespace std;
-extern "C"
-{
-#include <med.h>
-}
 
+#include <med.h>
 
 // ============================================================================
 QString HOMARD_QT_COMMUN::SelectionArbreEtude(QString commentaire, int option )
@@ -48,13 +47,13 @@ QString HOMARD_QT_COMMUN::SelectionArbreEtude(QString commentaire, int option )
 // . si le commentaire est une chaine vide, on ne tient pas compte du type de l'objet
 //   et on retourne le nom de cet objet
 // . sinon :
-//   . si l'objet est du type defini par commentaitr, retourne le nom de cet objet
+//   . si l'objet est du type defini par commentaire, retourne le nom de cet objet
 //   . sinon on retourne une QString("")
 // option :
 // . Si option = 0, ce n'est pas grave de ne rien trouver ; aucun message n'est emis
 // . Si option = 1, ce n'est pas grave de ne rien trouver mais on emet un message
 {
-  MESSAGE("SelectionArbreEtude : commentaire = " << commentaire.toStdString().c_str() << " et option = " << option);
+//   MESSAGE("SelectionArbreEtude : commentaire = " << commentaire.toStdString().c_str() << " et option = " << option);
   int nbSel = HOMARD_UTILS::IObjectCount() ;
   if ( nbSel == 0 )
   {
@@ -75,7 +74,8 @@ QString HOMARD_QT_COMMUN::SelectionArbreEtude(QString commentaire, int option )
   Handle(SALOME_InteractiveObject) aIO = HOMARD_UTILS::firstIObject();
   if ( aIO->hasEntry() )
   {
-    _PTR(Study) aStudy = HOMARD_UTILS::GetActiveStudyDocument();
+//     MESSAGE("aIO->getEntry() = " << aIO->getEntry());
+    _PTR(Study) aStudy = HOMARD_UTILS::getStudy();
     _PTR(SObject) aSO ( aStudy->FindObjectID( aIO->getEntry() ) );
     _PTR(GenericAttribute) anAttr;
     if (aSO->FindAttribute(anAttr, "AttributeComment") )
@@ -84,9 +84,9 @@ QString HOMARD_QT_COMMUN::SelectionArbreEtude(QString commentaire, int option )
       {
         _PTR(AttributeComment) attributComment = anAttr;
         QString aComment= QString(attributComment->Value().data());
-        MESSAGE("... aComment = " << aComment.toStdString().c_str());
+//         MESSAGE("... aComment = " << aComment.toStdString().c_str());
         int iaux = aComment.lastIndexOf(commentaire);
-        MESSAGE("... iaux = " << iaux);
+//         MESSAGE("... iaux = " << iaux);
         if ( iaux !=0  )
         {
           QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
@@ -127,7 +127,7 @@ QString HOMARD_QT_COMMUN::SelectionCasEtude()
   Handle(SALOME_InteractiveObject) aIO = HOMARD_UTILS::firstIObject();
   if ( aIO->hasEntry() )
   {
-       _PTR(Study) aStudy = HOMARD_UTILS::GetActiveStudyDocument();
+       _PTR(Study) aStudy = HOMARD_UTILS::getStudy();
        _PTR(SObject) aSO ( aStudy->FindObjectID( aIO->getEntry() ) );
         _PTR(SObject) aSObjCas = aSO->GetFather();
        _PTR(GenericAttribute) anAttr;
@@ -142,7 +142,7 @@ QString HOMARD_QT_COMMUN::SelectionCasEtude()
 }
 
 // =======================================================================
-QString HOMARD_QT_COMMUN::PushNomFichier(bool avertir)
+QString HOMARD_QT_COMMUN::PushNomFichier(bool avertir, QString TypeFichier)
 // =======================================================================
 // Gestion les boutons qui permettent  de
 // 1) retourne le nom d'un fichier par une fenetre de dialogue si aucun
@@ -150,24 +150,36 @@ QString HOMARD_QT_COMMUN::PushNomFichier(bool avertir)
 // 2) retourne le nom du fichier asocie a l objet
 //    selectionne dans l arbre d etude
 {
-  MESSAGE("PushNomFichier");
-  QString aFile=QString::null;
+//   MESSAGE("PushNomFichier avec avertir "<<avertir<<" et TypeFichier = "<<TypeFichier.toStdString().c_str());
+  QString aFile = QString::null;
+//
+  // A. Filtre
+  QString filtre  ;
+//
+  if ( TypeFichier == "med" )     { filtre = QString("Med") ; }
+  else if ( TypeFichier == "py" ) { filtre = QString("Python") ; }
+  else                            { filtre = TypeFichier ; }
+//
+  if ( TypeFichier != "" ) { filtre += QString(" files (*.") + TypeFichier + QString(");;") ; }
+//
+  filtre += QString("all (*) ") ;
+//
+  // B. Selection
   int nbSel = HOMARD_UTILS::IObjectCount() ;
+//   MESSAGE("nbSel ="<<nbSel);
+  // B.1. Rien n'est selectionne
   if ( nbSel == 0 )
   {
-    aFile = QFileDialog::getOpenFileName(0,QString("File Selection"),QString("") ,QString("Med files (*.med);;all (*) ") );
+//     aFile = QFileDialog::getOpenFileName(0, QObject::tr("HOM_SELECT_FILE_0"), QString(""), QString("Med files (*.med);;all (*) ") );
+    aFile = QFileDialog::getOpenFileName(0, QObject::tr("HOM_SELECT_FILE_0"), QString(""), filtre );
   }
-  if (nbSel > 1)
-  {
-    QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
-                              QObject::tr("HOM_SELECT_FILE_2") );
-  }
-  if (nbSel == 1)
+  // B.2. Un objet est selectionne
+  else if (nbSel == 1)
   {
     Handle(SALOME_InteractiveObject) aIO = HOMARD_UTILS::firstIObject();
     if ( aIO->hasEntry() )
     {
-      _PTR(Study) aStudy = HOMARD_UTILS::GetActiveStudyDocument();
+      _PTR(Study) aStudy = HOMARD_UTILS::getStudy();
       _PTR(SObject) aSO ( aStudy->FindObjectID( aIO->getEntry() ) );
       _PTR(GenericAttribute) anAttr;
       _PTR(AttributeFileType) aFileType;
@@ -189,30 +201,32 @@ QString HOMARD_QT_COMMUN::PushNomFichier(bool avertir)
     {
       if ( avertir ) {
         QMessageBox::warning( 0, QObject::tr("HOM_WARNING"),
-                                QObject::tr("HOM_SELECT_STUDY") );
-      }
-      aFile = QFileDialog::getOpenFileName();
-      if (!aFile.isEmpty())
-      {
-        aFile=aFile;
+                                 QObject::tr("HOM_SELECT_STUDY") );
       }
+      aFile = QFileDialog::getOpenFileName(0, QObject::tr("HOM_SELECT_FILE_0"), QString(""), filtre );
     }
   }
-  return aFile;
+  // B.3. Bizarre
+  else
+  {
+    QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
+                              QObject::tr("HOM_SELECT_FILE_2") );
+  }
 
+  return aFile;
 }
 // =======================================================================
-int HOMARD_QT_COMMUN::OuvrirFichier(QString aFile)
+med_idt HOMARD_QT_COMMUN::OuvrirFichier(QString aFile)
 // =======================================================================
 // renvoie le medId associe au fichier Med apres ouverture
 {
-  med_int medIdt = MEDfileOpen(aFile.toStdString().c_str(),MED_ACC_RDONLY);
+  med_idt medIdt = MEDfileOpen(aFile.toStdString().c_str(),MED_ACC_RDONLY);
   if (medIdt <0)
   {
     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
                               QObject::tr("HOM_MED_FILE_1") );
   }
-  return (int) medIdt;
+  return medIdt;
 }
 
 // ======================================================
@@ -221,7 +235,7 @@ QString HOMARD_QT_COMMUN::LireNomMaillage(QString aFile)
 {
   QString nomMaillage = "" ;
   int erreur = 0 ;
-  med_int medIdt ;
+  med_idt medIdt ;
   while ( erreur == 0 )
   {
     //  Ouverture du fichier
@@ -247,7 +261,7 @@ QString HOMARD_QT_COMMUN::LireNomMaillage(QString aFile)
       break ;
     }
 
-    nomMaillage = HOMARD_QT_COMMUN::LireNomMaillage(medIdt,1);
+    nomMaillage = HOMARD_QT_COMMUN::LireNomMaillage2(medIdt,1);
     break ;
   }
   // Fermeture du fichier
@@ -256,7 +270,7 @@ QString HOMARD_QT_COMMUN::LireNomMaillage(QString aFile)
   return nomMaillage;
 }
 // =======================================================================
-QString HOMARD_QT_COMMUN::LireNomMaillage(int medIdt ,int meshId)
+QString HOMARD_QT_COMMUN::LireNomMaillage2(med_idt medIdt ,int meshId)
 // =======================================================================
 {
   QString NomMaillage=QString::null;
@@ -306,7 +320,7 @@ std::list<QString> HOMARD_QT_COMMUN::GetListeChamps(QString aFile)
   std::list<QString> ListeChamp ;
 
   med_err erreur = 0 ;
-  med_int medIdt ;
+  med_idt medIdt ;
 
   while ( erreur == 0 )
   {
@@ -370,7 +384,7 @@ std::list<QString> HOMARD_QT_COMMUN::GetListeComposants(QString aFile, QString a
   std::list<QString> ListeComposants;
 
   med_err erreur = 0 ;
-  med_int medIdt ;
+  med_idt medIdt ;
 
   while ( erreur == 0 )
   {