From c9cf46fbd6a8d5091139e6b484c5482ee797e346 Mon Sep 17 00:00:00 2001 From: nicolas Date: Tue, 24 Sep 2013 15:21:09 +0000 Subject: [PATCH] =?utf8?q?Destruction=20des=20sch=C3=83=C2=A9mas?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- doc/en/tui_create_yacs.rst | 16 +++++++++ doc/fr/tui_create_yacs.rst | 18 ++++++++-- idl/HOMARD_YACS.idl | 3 ++ src/HOMARD/HOMARD_YACS.cxx | 10 ++++++ src/HOMARD/HOMARD_YACS.hxx | 4 +++ src/HOMARD/YACSDriver.cxx | 12 +++---- src/HOMARD/YACSDriver.hxx | 4 +-- src/HOMARDGUI/HOMARDGUI.cxx | 37 ++++++++++++------- src/HOMARD_I/HOMARD_Gen_i.cxx | 65 ++++++++++++++++++++++------------ src/HOMARD_I/HOMARD_Gen_i.hxx | 2 +- src/HOMARD_I/HOMARD_YACS_i.cxx | 24 ++++++++++--- src/HOMARD_I/HOMARD_YACS_i.hxx | 4 ++- 12 files changed, 147 insertions(+), 52 deletions(-) diff --git a/doc/en/tui_create_yacs.rst b/doc/en/tui_create_yacs.rst index dd581745..5790fb86 100644 --- a/doc/en/tui_create_yacs.rst +++ b/doc/en/tui_create_yacs.rst @@ -62,6 +62,10 @@ General methods | **Write()** | | Writes the schema into the file ``schema.xml``, in the | | directory of the case | +| Writes the schema into the file of the schema | +| By default, it is the file ``schema.xml``, in the | +| directory of the case. If ``WriteOnFile`` was used before | +| the writings are into this new file. | | | | Returns an integer: | | * 0: the writing is done | @@ -162,6 +166,18 @@ Informations about the schema | Returns the name of the MED file of the very first mesh | | for the computation | +---------------------------------------------------------------+ +| .. module:: SetXMLFile | +| | +| **SetXMLFile(xml_file)** | +| Defines the xml file | +| | +| - ``mesh_file`` : the name of the xml file | ++---------------------------------------------------------------+ +| .. module:: GetXMLFile | +| | +| **GetXMLFile()** | +| Returns the name of the xml file | ++---------------------------------------------------------------+ Example diff --git a/doc/fr/tui_create_yacs.rst b/doc/fr/tui_create_yacs.rst index 81b2c425..ec627f77 100644 --- a/doc/fr/tui_create_yacs.rst +++ b/doc/fr/tui_create_yacs.rst @@ -60,8 +60,10 @@ G | .. module:: Write | | | | **Write()** | -| Ecrit le schéma dans le fichier ``schema.xml``, dans le | -| répertoire du cas | +| Ecrit le schéma dans le fichier lié au schéma | +| Par défaut, c'est le fichier ``schema.xml``, dans le | +| répertoire du cas. Si ``WriteOnFile`` a été utilisé | +| auparavant, l'écriture a lieu dans le nouveau fichier. | | | | Retourne un entier : | | * 0 : écriture réussie | @@ -160,6 +162,18 @@ Informations sur le sch | Retourne le nom du fichier MED du tout premier maillage | | de calcul | +---------------------------------------------------------------+ +| .. module:: SetXMLFile | +| | +| **SetXMLFile(xml_file)** | +| Définit le fichier xml pour l'écriture | +| | +| - ``xml_file`` : le nom du fichier xml | ++---------------------------------------------------------------+ +| .. module:: GetXMLFile | +| | +| **GetXMLFile()** | +| Retourne le nom du fichier xml | ++---------------------------------------------------------------+ Exemple diff --git a/idl/HOMARD_YACS.idl b/idl/HOMARD_YACS.idl index 60574ac4..fa8f5286 100644 --- a/idl/HOMARD_YACS.idl +++ b/idl/HOMARD_YACS.idl @@ -58,6 +58,9 @@ module HOMARD void SetScriptFile(in string ScriptFile) raises (SALOME::SALOME_Exception); string GetScriptFile() raises (SALOME::SALOME_Exception); + void SetXMLFile(in string XMLFile) raises (SALOME::SALOME_Exception); + string GetXMLFile() raises (SALOME::SALOME_Exception); + long Write() raises (SALOME::SALOME_Exception); long WriteOnFile( in string YACSFile ) raises (SALOME::SALOME_Exception); diff --git a/src/HOMARD/HOMARD_YACS.cxx b/src/HOMARD/HOMARD_YACS.cxx index b8eb074d..67f04c2a 100644 --- a/src/HOMARD/HOMARD_YACS.cxx +++ b/src/HOMARD/HOMARD_YACS.cxx @@ -135,6 +135,16 @@ std::string HOMARD_YACS::GetScriptFile() const return _ScriptFile; } //============================================================================= +void HOMARD_YACS::SetXMLFile( const char* XMLFile ) +{ + _XMLFile = std::string( XMLFile ); +} +//============================================================================= +std::string HOMARD_YACS::GetXMLFile() const +{ + return _XMLFile; +} +//============================================================================= //============================================================================= // Liens avec les autres structures //============================================================================= diff --git a/src/HOMARD/HOMARD_YACS.hxx b/src/HOMARD/HOMARD_YACS.hxx index af331722..7b771a7c 100644 --- a/src/HOMARD/HOMARD_YACS.hxx +++ b/src/HOMARD/HOMARD_YACS.hxx @@ -62,6 +62,9 @@ public: void SetScriptFile( const char* ScriptFile ); std::string GetScriptFile() const; + void SetXMLFile( const char* XMLFile ); + std::string GetXMLFile() const; + // Liens avec les autres structures void SetCaseName( const char* NomCas ); std::string GetCaseName() const; @@ -76,6 +79,7 @@ private: std::string _MeshFile; std::string _ScriptFile; int _Type; + std::string _XMLFile; }; #endif diff --git a/src/HOMARD/YACSDriver.cxx b/src/HOMARD/YACSDriver.cxx index 50a32dd9..01b1f453 100644 --- a/src/HOMARD/YACSDriver.cxx +++ b/src/HOMARD/YACSDriver.cxx @@ -31,15 +31,15 @@ //============================================================================= //============================================================================= -YACSDriver::YACSDriver(const std::string YACSFile, const std::string DirName): - _YACSFile( "" ), _DirName( "" ), +YACSDriver::YACSDriver(const std::string XMLFile, const std::string DirName): + _XMLFile( "" ), _DirName( "" ), _Texte( "" ), _Texte_parametres( "" ), _noeud_1( "CreateHypothesis" ), _bLu( false ) { - MESSAGE("YACSFile = "<DeleteCase(_ObjectName.toStdString().c_str(), 1); } + { homardGen->DeleteBoundary(_ObjectName.toStdString().c_str()); } catch( SALOME::SALOME_Exception& S_ex ) { QMessageBox::critical( 0, QObject::tr("HOM_ERROR"), @@ -407,11 +407,11 @@ bool HOMARDGUI::OnGUIEvent (int theCommandID) return false; } } - // Suppression d'une iteration - else if (HOMARD_UTILS::isIter(obj)) + // Suppression d'un cas + else if (HOMARD_UTILS::isCase(obj)) { try - { homardGen->DeleteIteration(_ObjectName.toStdString().c_str(), 1); } + { homardGen->DeleteCase(_ObjectName.toStdString().c_str(), 1); } catch( SALOME::SALOME_Exception& S_ex ) { QMessageBox::critical( 0, QObject::tr("HOM_ERROR"), @@ -433,11 +433,11 @@ bool HOMARDGUI::OnGUIEvent (int theCommandID) return false; } } - // Suppression d'une zone - else if (HOMARD_UTILS::isZone(obj)) + // Suppression d'une iteration + else if (HOMARD_UTILS::isIter(obj)) { try - { homardGen->DeleteZone(_ObjectName.toStdString().c_str()); } + { homardGen->DeleteIteration(_ObjectName.toStdString().c_str(), 1); } catch( SALOME::SALOME_Exception& S_ex ) { QMessageBox::critical( 0, QObject::tr("HOM_ERROR"), @@ -446,11 +446,24 @@ bool HOMARDGUI::OnGUIEvent (int theCommandID) return false; } } - // Suppression d'une frontiere - else if ( HOMARD_UTILS::isBoundaryDi(obj) or HOMARD_UTILS::isBoundaryAn(obj) ) + // Suppression d'un schema YACS + else if (HOMARD_UTILS::isYACS(obj)) { try - { homardGen->DeleteBoundary(_ObjectName.toStdString().c_str()); } + { homardGen->DeleteYACS(_ObjectName.toStdString().c_str(), 1); } + catch( SALOME::SALOME_Exception& S_ex ) + { + QMessageBox::critical( 0, QObject::tr("HOM_ERROR"), + QObject::tr(CORBA::string_dup(S_ex.details.text)) ); + getApp()->updateObjectBrowser(); + return false; + } + } + // Suppression d'une zone + else if (HOMARD_UTILS::isZone(obj)) + { + try + { homardGen->DeleteZone(_ObjectName.toStdString().c_str()); } catch( SALOME::SALOME_Exception& S_ex ) { QMessageBox::critical( 0, QObject::tr("HOM_ERROR"), diff --git a/src/HOMARD_I/HOMARD_Gen_i.cxx b/src/HOMARD_I/HOMARD_Gen_i.cxx index 82d78b0c..f075f85b 100755 --- a/src/HOMARD_I/HOMARD_Gen_i.cxx +++ b/src/HOMARD_I/HOMARD_Gen_i.cxx @@ -455,7 +455,6 @@ CORBA::Long HOMARD_Gen_i::DeleteYACS(const char* nomYACS, CORBA::Long Option) { // Option = 0 : On ne supprime pas le fichier du schema associe // Option = 1 : On supprime le fichier du schema associe - // Pour detruire une iteration courante MESSAGE ( "DeleteYACS : nomYACS = " << nomYACS << ", avec option = " << Option ); HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS]; if (CORBA::is_nil(myYACS)) @@ -466,7 +465,21 @@ CORBA::Long HOMARD_Gen_i::DeleteYACS(const char* nomYACS, CORBA::Long Option) throw SALOME::SALOME_Exception(es); return 1 ; }; - ASSERT("Programmer le menage du fichier"!=0); + // Suppression eventuelle du fichier XML + if ( Option == 1 ) + { + std::string nomFichier = myYACS->GetXMLFile(); + std::string commande = "rm -rf " + nomFichier ; + MESSAGE ( "commande = " << commande ); + if ((system(commande.c_str())) != 0) + { + SALOME::ExceptionStruct es; + es.type = SALOME::BAD_PARAM; + es.text = "The xml file for the schema YACS cannot be removed." ; + throw SALOME::SALOME_Exception(es); + return 2 ; + } + } // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete myContextMap[GetCurrentStudyID()]._mesYACSs.erase(nomYACS); SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(nomYACS, ComponentDataType()); @@ -629,7 +642,7 @@ void HOMARD_Gen_i::InvalideIterOption(const char* nomIter, CORBA::Long Option) }; std::string nomDir = myIteration->GetDirName(); std::string nomFichier = myIteration->GetMeshFile(); - std::string commande= "rm -rf " + std::string(nomDir); + std::string commande = "rm -rf " + std::string(nomDir); if ( Option == 1 ) { commande = commande + ";rm -rf " + std::string(nomFichier) ; } MESSAGE ( "commande = " << commande ); if ((system(commande.c_str())) != 0) @@ -2690,7 +2703,7 @@ char* HOMARD_Gen_i::ComputeDirManagement(HOMARD::HOMARD_Cas_var myCase, HOMARD:: if (etatMenage == 1) { MESSAGE (". Menage du repertoire DirCompute = " << DirCompute.str()); - std::string commande= "rm -rf " + DirCompute.str()+"/*" ; + std::string commande = "rm -rf " + DirCompute.str()+"/*" ; int codret = system(commande.c_str()); if (codret != 0) { @@ -3029,10 +3042,10 @@ SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy, aResultSO = PublishCaseInStudy(theStudy, aStudyBuilder, aCase, theName); else if(!aHypo->_is_nil()) aResultSO = PublishHypotheseInStudy(theStudy, aStudyBuilder, aHypo, theName); - else if(!aZone->_is_nil()) - aResultSO = PublishZoneInStudy(theStudy, aStudyBuilder, aZone, theName); else if(!aYACS->_is_nil()) aResultSO = PublishYACSInStudy(theStudy, aStudyBuilder, aYACS, theName); + else if(!aZone->_is_nil()) + aResultSO = PublishZoneInStudy(theStudy, aStudyBuilder, aZone, theName); aStudyBuilder->CommitCommand(); @@ -3647,11 +3660,20 @@ HOMARD::HOMARD_YACS_ptr HOMARD_Gen_i::CreateYACSSchema (const char* nomYACS, con PublishCaseUnderYACS(nomYACS, nomCas); // D. Caracterisation + // D.1. Options myYACS->SetDirName( DirName ) ; myYACS->SetMeshFile( MeshFile ) ; myYACS->SetScriptFile( ScriptFile ) ; myYACS->SetCaseName( nomCas ) ; + // D.2. Defaut + // D.2.1. Type constant myYACS->SetType( 1 ) ; + // D.2.2. Fichier de sauvegarde dans le repertoire du cas + HOMARD::HOMARD_Cas_ptr caseyacs = GetCase(nomCas) ; + std::string dirnamecase = caseyacs->GetDirName() ; + std::string XMLFile ; + XMLFile = dirnamecase + "/schema.xml" ; + myYACS->SetXMLFile( XMLFile.c_str() ) ; return HOMARD::HOMARD_YACS::_duplicate(myYACS); } @@ -3664,23 +3686,20 @@ CORBA::Long HOMARD_Gen_i::YACSWrite(const char* nomYACS) // Le repertoire du cas HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS]; ASSERT(!CORBA::is_nil(myYACS)); - std::string casename = myYACS->GetCaseName() ; - HOMARD::HOMARD_Cas_ptr caseyacs = GetCase(casename.c_str()) ; - std::string dirnamecase = caseyacs->GetDirName() ; -// Le nom par defaut du fichier du schema - std::string YACSFile ; - YACSFile = dirnamecase + "/schema.xml" ; +// Le nom du fichier du schema + std::string XMLFile ; + XMLFile = myYACS->GetXMLFile() ; - int codret = YACSWriteOnFile(nomYACS, YACSFile.c_str()) ; + int codret = YACSWriteOnFile(nomYACS, XMLFile.c_str()) ; return codret ; } //============================================================================= -// Ecriture d'un schema YACS +// Ecriture d'un schema YACS sur un fichier donne //============================================================================= -CORBA::Long HOMARD_Gen_i::YACSWriteOnFile(const char* nomYACS, const char* YACSFile) +CORBA::Long HOMARD_Gen_i::YACSWriteOnFile(const char* nomYACS, const char* XMLFile) { - INFOS ( "YACSWriteOnFile : Ecriture de " << nomYACS << " sur " << YACSFile ); + INFOS ( "YACSWriteOnFile : Ecriture de " << nomYACS << " sur " << XMLFile ); // A. Prealable int codret = 0; @@ -3747,8 +3766,8 @@ CORBA::Long HOMARD_Gen_i::YACSWriteOnFile(const char* nomYACS, const char* YACSF // F. Le fichier du schema de reference // HOMARD_ROOT_DIR : repertoire ou se trouve le module HOMARD - std::string YACSFile_base ; - if ( getenv("HOMARD_ROOT_DIR") != NULL ) { YACSFile_base = getenv("HOMARD_ROOT_DIR") ; } + std::string XMLFile_base ; + if ( getenv("HOMARD_ROOT_DIR") != NULL ) { XMLFile_base = getenv("HOMARD_ROOT_DIR") ; } else { SALOME::ExceptionStruct es ; @@ -3758,13 +3777,13 @@ CORBA::Long HOMARD_Gen_i::YACSWriteOnFile(const char* nomYACS, const char* YACSF throw SALOME::SALOME_Exception(es); return 0; } - YACSFile_base += "/share/salome/resources/homard/yacs_01." + _LangueShort + ".xml" ; + XMLFile_base += "/share/salome/resources/homard/yacs_01." + _LangueShort + ".xml" ; // if ( _Langue == - MESSAGE("YACSFile_base ="<GetScriptFile().c_str() ); } //============================================================================= +void HOMARD_YACS_i::SetXMLFile( const char* XMLFile ) +{ + ASSERT( myHomardYACS ); + MESSAGE ( "SetXMLFile : SetXMLFile = " << XMLFile ); + myHomardYACS->SetXMLFile( XMLFile ); +} +//============================================================================= +char* HOMARD_YACS_i::GetXMLFile() +{ + ASSERT( myHomardYACS ); + return CORBA::string_dup( myHomardYACS->GetXMLFile().c_str() ); +} +//============================================================================= //============================================================================= // Liens avec les autres structures //============================================================================= @@ -178,21 +191,22 @@ char* HOMARD_YACS_i::GetCaseName() //============================================================================= CORBA::Long HOMARD_YACS_i::Write() { - MESSAGE ( "Write : ecriture du schema"); // char* nomYACS = GetName() ; return _gen_i->YACSWrite(nomYACS) ; } //============================================================================= -CORBA::Long HOMARD_YACS_i::WriteOnFile( const char* YACSFile ) +CORBA::Long HOMARD_YACS_i::WriteOnFile( const char* XMLFile ) { - MESSAGE ( "WriteOnFile : ecriture du schema sur " << YACSFile ); + MESSAGE ( "WriteOnFile : ecriture du schema sur " << XMLFile ); ASSERT( myHomardYACS ); // +// Memorisation du fichier associe + SetXMLFile( XMLFile ) ; +// // Nom du schema char* nomYACS = GetName() ; - MESSAGE ( "WriteOnFile : ecriture du schema " << nomYACS); - return _gen_i->YACSWriteOnFile(nomYACS, YACSFile) ; + return _gen_i->YACSWriteOnFile(nomYACS, XMLFile) ; } //============================================================================= //============================================================================= diff --git a/src/HOMARD_I/HOMARD_YACS_i.hxx b/src/HOMARD_I/HOMARD_YACS_i.hxx index 4a26544a..f3c2fc4a 100644 --- a/src/HOMARD_I/HOMARD_YACS_i.hxx +++ b/src/HOMARD_I/HOMARD_YACS_i.hxx @@ -77,9 +77,11 @@ public: void SetScriptFile( const char* ScriptFile ); char* GetScriptFile(); + void SetXMLFile( const char* XMLFile ); + char* GetXMLFile(); CORBA::Long Write() ; - CORBA::Long WriteOnFile( const char* YACSFile ) ; + CORBA::Long WriteOnFile( const char* XMLFile ) ; // Liens avec les autres structures void SetCaseName( const char* NomCas ); -- 2.39.2