Salome HOME
Updated copyright comment
[modules/homard.git] / src / HOMARDGUI / MonCreateYACS.cxx
index 6612fba40e8ae121ae653c92e59920896522a7fd..fc7e15923131827bb0d47e8380ec78044abc55e3 100644 (file)
@@ -1,9 +1,9 @@
-// Copyright (C) 2011-2012  CEA/DEN, EDF R&D
+// Copyright (C) 2011-2024  CEA, EDF
 //
 // 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
@@ -17,9 +17,8 @@
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
-using namespace std;
-
 #include "MonCreateYACS.h"
+#include "HOMARD.hxx"
 
 #include <QFileDialog>
 #include <QMessageBox>
@@ -29,36 +28,70 @@ using namespace std;
 #include "HomardQtCommun.h"
 #include <utilities.h>
 
+#ifdef WIN32
+#include <direct.h>
+#endif
+using namespace std;
 
-// -----------------------------------------------------------------------------------------
+// ----------------------------------------------------------------------
+MonCreateYACS::MonCreateYACS (bool modal, HOMARD::HOMARD_Gen_var myHomardGen0, QString CaseName ):
+// ----------------------------------------------------------------------
 /* Constructs a MonCreateYACS
  * Sets attributes to default values
  */
-// -----------------------------------------------------------------------------------------
-MonCreateYACS::MonCreateYACS (QWidget* parent, bool modal, HOMARD::HOMARD_Gen_var myHomardGen, QString CaseName )
-    :
-    Ui_CreateYACS(),
-    _aCaseName(CaseName),
-    _aFileNameScript(""),
-    _aDirName(""),
-    _aFileNameMesh("")
-{
-  MESSAGE("Debut du constructeur de MonCreateYACS");
-  _myHomardGen=HOMARD::HOMARD_Gen::_duplicate(myHomardGen);
-  setupUi(this);
-  setModal(modal);
+// ----------------------------------------------------------------------
+  Ui_CreateYACS(),
+  _aCaseName(CaseName),
+  _aScriptFile(""),
+  _aDirName(""),
+  _aMeshFile(""),
+  _Type(1)
+  // Les valeurs de _Type, _MaxIter, _MaxNode, _MaxElem doivent etre les memes que celles dans HOMARD_Gen_i::CreateYACSSchema
+  // et doivent correspondre aux defauts des boutons
+  {
+//     MESSAGE("Debut du constructeur de MonCreateYACS");
+    myHomardGen=HOMARD::HOMARD_Gen::_duplicate(myHomardGen0);
+    setupUi(this);
+    if ( modal ) { setWindowModality(Qt::WindowModal); }
+    else         { setWindowModality(Qt::NonModal); }
 
-  InitConnect();
+    InitConnect();
+
+    SetNewName() ;
+
+    if (_aCaseName != QString("")) { SetCaseName(); }
+    else                           { setWindowModality(Qt::NonModal); /* permet selection du cas dans l arbre d etude */}
+//
+//  Les valeurs definies dans les preferences
+    _MaxIter = myHomardGen->GetYACSMaxIter();
+    _MaxNode = myHomardGen->GetYACSMaxNode();
+    _MaxElem = myHomardGen->GetYACSMaxElem();
+    MESSAGE ("Valeur par defaut de MaxIter = " << _MaxIter<<", MaxNode = "<< _MaxNode<<", MaxElem = "<< _MaxElem);
+    SpinBoxMaxIter->setValue(_MaxIter) ;
+    SpinBoxMaxNode->setValue(_MaxNode) ;
+    SpinBoxMaxElem->setValue(_MaxElem) ;
+//
+    adjustSize();
+  }
 
-  if (_aCaseName != QString(""))
-    { SetCaseName(); }
-  else
-    {setModal(false); /* permet selection du cas dans l arbre d etude */}
+// ----------------------------------------------------------------------
+MonCreateYACS::MonCreateYACS(HOMARD::HOMARD_Gen_var myHomardGen0,
+                             QString caseName):
+// ----------------------------------------------------------------------
+// Constructeur appele par MonEditYACS
+//
+myHomardGen(myHomardGen0),
+_Name (""),
+Chgt (false)
+{
+//       MESSAGE("Debut du constructeur de MonCreateYACS appele par MonEditYACS");
+  setupUi(this) ;
 
+  setWindowModality(Qt::WindowModal);
+  InitConnect() ;
+//
   adjustSize();
-  MESSAGE("Fin du constructeur de MonCreateYACS");
 }
-
 // ------------------------------------------------------------------------
 MonCreateYACS::~MonCreateYACS()
 // ------------------------------------------------------------------------
@@ -70,12 +103,12 @@ void MonCreateYACS::InitConnect()
 // ------------------------------------------------------------------------
 {
     connect( PBCaseName,     SIGNAL(pressed()), this, SLOT(SetCaseName()));
-    connect( PushDir,        SIGNAL(pressed()), this, SLOT(SetDirName()));
-    connect( PushFile,       SIGNAL(pressed()), this, SLOT(SetFileNameScript()));
-    connect( PushFile_2,     SIGNAL(pressed()), this, SLOT(SetFileNameMesh()));
+    connect( PBScriptFile,   SIGNAL(pressed()), this, SLOT(SetScriptFile()));
+    connect( PBDir,          SIGNAL(pressed()), this, SLOT(SetDirName()));
+    connect( PBMeshFile,     SIGNAL(pressed()), this, SLOT(SetMeshFile()));
 
-    connect( RBStatic,       SIGNAL(clicked()), this, SLOT(FromIteration()));
-    connect( RBTransient,    SIGNAL(clicked()), this, SLOT(FromCase()));
+    connect( RBConstant,     SIGNAL(clicked()), this, SLOT(SetConstant()));
+    connect( RBVariable,     SIGNAL(clicked()), this, SLOT(SetVariable()));
 
     connect( buttonOk,       SIGNAL(pressed()), this, SLOT(PushOnOK()));
     connect( buttonApply,    SIGNAL(pressed()), this, SLOT(PushOnApply()));
@@ -88,14 +121,8 @@ bool MonCreateYACS::PushOnApply()
 {
   MESSAGE("PushOnApply");
 
-  if ( _aCaseName == QString (""))
-  {
-    QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
-                              QObject::tr("HOM_CASE_NAME") );
-    return false;
-  }
 // Le fichier du script
-  QString aFileName=LEFileNameScript->text().trimmed();
+  QString aFileName=LEScriptFile->text().trimmed();
   if (aFileName ==QString(""))
   {
     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
@@ -111,13 +138,18 @@ bool MonCreateYACS::PushOnApply()
                               QObject::tr("HOM_CASE_DIRECTORY_4") );
     return false;
   }
-  if ((aDirName != _aDirName) and (_myHomardGen->VerifieDir( aDirName.toStdString().c_str()) == false))
-  {
-    QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
-                              QObject::tr("HOM_CASE_DIRECTORY_2") );
-    return false;
+  if ( aDirName != _aDirName)
+  { QString CaseNameDir = myHomardGen->VerifieDir( aDirName.toStdString().c_str()) ;
+    if ( CaseNameDir != "" )
+    {
+      QString texte ;
+      texte = QObject::tr("HOM_CASE_DIRECTORY_2") + CaseNameDir ;
+      QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
+                                texte );
+      return false;
+    }
   }
-  if (chdir(aDirName.toStdString().c_str()) != 0)
+  if (CHDIR(aDirName.toStdString().c_str()) != 0)
   {
     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
                               QObject::tr("HOM_CASE_DIRECTORY_3") );
@@ -125,7 +157,7 @@ bool MonCreateYACS::PushOnApply()
   }
 
 // Le fichier du tout premier maillage
-  aFileName=LEFileNameMesh->text().trimmed();
+  aFileName=LEMeshFile->text().trimmed();
   if (aFileName ==QString(""))
   {
     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
@@ -140,23 +172,124 @@ bool MonCreateYACS::PushOnApply()
     return false;
   }
 
-  HOMARD_UTILS::updateObjBrowser();
-  MESSAGE ("_aCaseName.toStdString " << _aCaseName.toStdString() );
+  bool bOK = CreateOrUpdate() ;
+
+  if ( bOK ) { HOMARD_UTILS::updateObjBrowser() ; }
+
+  return bOK;
+}
+// ---------------------------------------------------
+bool MonCreateYACS:: CreateOrUpdate()
+//----------------------------------------------------
+//  Creation ou modification du schema
+{
+  MESSAGE("CreateOrUpdate");
+  bool bOK = true ;
+
+  // 1. Verification des donnees
+  // 1.1. Le cas
+  if ( _aCaseName == QString (""))
+  {
+    QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
+                              QObject::tr("HOM_CASE_NAME") );
+    return false;
+  }
+  // 1.2. Les donnees
+  QString aScriptFile=LEScriptFile->text().trimmed();
+  if ( aScriptFile != _aScriptFile )
+  {
+    _aScriptFile = aScriptFile ;
+    Chgt = true ;
+  }
+  QString aDirName=LEDirName->text().trimmed();
+  if ( aDirName != _aDirName )
+  {
+    _aDirName = aDirName ;
+    Chgt = true ;
+  }
+  QString aMeshFile=LEMeshFile->text().trimmed();
+  if ( aMeshFile != _aMeshFile )
+  {
+    _aMeshFile = aMeshFile ;
+    Chgt = true ;
+  }
+
+  // 2. Creation de l'objet CORBA
+  try
+  {
+    _Name=LEName->text().trimmed();
+    aYACS=myHomardGen->CreateYACSSchema(CORBA::string_dup(_Name.toStdString().c_str()), CORBA::string_dup(_aCaseName.toStdString().c_str()), CORBA::string_dup(_aScriptFile.toStdString().c_str()), CORBA::string_dup(_aDirName.toStdString().c_str()), CORBA::string_dup(_aMeshFile.toStdString().c_str()));
+  }
+  catch( SALOME::SALOME_Exception& S_ex )
+  {
+    QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
+                              QObject::tr(CORBA::string_dup(S_ex.details.text)) );
+    bOK = false;
+  }
+
+  // 3. Options
+  if ( bOK )
+  {
+  // 3.1. Le type du schema
+    aYACS->SetType(_Type) ;
 
-  return true;
+  // 3.2. Les maximums
+    _MaxIter = SpinBoxMaxIter->value() ;
+    aYACS->SetMaxIter(_MaxIter) ;
+
+    _MaxNode = SpinBoxMaxNode->value() ;
+    aYACS->SetMaxNode(_MaxNode) ;
+
+    _MaxElem = SpinBoxMaxElem->value() ;
+    aYACS->SetMaxElem(_MaxElem) ;
+
+  }
+
+  // 4. Ecriture du fichier
+  if ( bOK )
+  {
+    int codret = aYACS->Write() ;
+    if ( codret != 0 ) { bOK = false ; }
+  }
+
+  return bOK;
 }
 // ---------------------------
 void MonCreateYACS::PushOnOK()
 // ---------------------------
 {
   bool bOK = PushOnApply();
-  if ( bOK )  this->close();
+  if ( bOK ) this->close();
 }
 //------------------------------
 void MonCreateYACS::PushOnHelp()
 //-------------------------------
 {
-  HOMARD_UTILS::PushOnHelp(QString("gui_create_case.html"), QString(""));
+  std::string LanguageShort = myHomardGen->GetLanguageShort();
+  HOMARD_UTILS::PushOnHelp(QString("yacs.html"), QString(""), QString(LanguageShort.c_str()));
+}
+// -------------------------------------------------
+void MonCreateYACS::SetNewName()
+// --------------------------------------------------
+{
+
+  HOMARD::listeYACSs_var MyObjects = myHomardGen->GetAllYACSsName();
+  int num = 0; QString aName="";
+  while (aName == QString("") )
+  {
+    aName.setNum(num+1) ;
+    aName.insert(0, QString("YACS_")) ;
+    for ( int i=0; i<MyObjects->length(); i++)
+    {
+      if ( aName ==  QString(MyObjects[i]))
+      {
+        num ++ ;
+        aName = "" ;
+        break ;
+      }
+   }
+  }
+  LEName->setText(aName);
 }
 // ------------------------------------------------------------------------
 void MonCreateYACS::SetCaseName()
@@ -168,8 +301,6 @@ void MonCreateYACS::SetCaseName()
     _aCaseName=HOMARD_QT_COMMUN::SelectionArbreEtude(QString("CasHomard"), 1);
     if (_aCaseName == QString("")) { raise();return;};
   }
-/*  MESSAGE ("appel de GetCase avec _aCaseName = " << _aCaseName.toStdString() );*/
-  aCase = _myHomardGen->GetCase(_aCaseName.toStdString().c_str());
   LECaseName->setText(_aCaseName);
 }
 // ------------------------------------------------------------------------
@@ -180,20 +311,32 @@ void MonCreateYACS::SetDirName()
   if (!(aDirName.isEmpty()))LEDirName->setText(aDirName);
 }
 // ------------------------------------------------------------------------
-void MonCreateYACS::SetFileNameScript()
+void MonCreateYACS::SetScriptFile()
 // ------------------------------------------------------------------------
 {
-  QString fileName0 = LEFileNameScript->text().trimmed();
-  QString fileName = HOMARD_QT_COMMUN::PushNomFichier(false);
+  QString fileName0 = LEScriptFile->text().trimmed();
+  QString fileName = HOMARD_QT_COMMUN::PushNomFichier( false, QString("py") ) ;
   if (fileName.isEmpty()) fileName = fileName0 ;
-  LEFileNameScript->setText(fileName);
+  LEScriptFile->setText(fileName);
 }
 // ------------------------------------------------------------------------
-void MonCreateYACS::SetFileNameMesh()
+void MonCreateYACS::SetMeshFile()
 // ------------------------------------------------------------------------
 {
-  QString fileName0 = LEFileNameMesh->text().trimmed();
-  QString fileName = HOMARD_QT_COMMUN::PushNomFichier(false);
+  QString fileName0 = LEMeshFile->text().trimmed();
+  QString fileName = HOMARD_QT_COMMUN::PushNomFichier( false, QString("med") ) ;
   if (fileName.isEmpty()) fileName = fileName0 ;
-  LEFileNameMesh->setText(fileName);
+  LEMeshFile->setText(fileName);
+}
+// ------------------------------------------------------------------------
+void MonCreateYACS::SetConstant()
+// ------------------------------------------------------------------------
+{
+  _Type = 1 ;
+}
+// ------------------------------------------------------------------------
+void MonCreateYACS::SetVariable()
+// ------------------------------------------------------------------------
+{
+  _Type = 2 ;
 }