Salome HOME
insertion de la documentation en anglais - phase 1
[modules/homard.git] / src / HOMARD_I / HOMARD_Cas_i.cxx
index 7d75ff308a95aeca18a7ed1ca4d9d43bc1b062df..91e7e5e6ba2165bdb1520878e71146c1f0d5b636 100755 (executable)
@@ -1,4 +1,4 @@
-// Copyright (C) 2011-2012  CEA/DEN, EDF R&D
+// Copyright (C) 2011-2013  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
 //
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+// Remarques :
+// L'ordre de description des fonctions est le meme dans tous les fichiers
+// HOMARD_aaaa.idl, HOMARD_aaaa.hxx, HOMARD_aaaa.cxx, HOMARD_aaaa_i.hxx, HOMARD_aaaa_i.cxx :
+// 1. Les generalites : Name, Delete, DumpPython, Dump, Restore
+// 2. Les caracteristiques
+// 3. Le lien avec les autres structures
+//
+// Quand les 2 fonctions Setxxx et Getxxx sont presentes, Setxxx est decrit en premier
+//
 
 #include "HOMARD_Cas_i.hxx"
 #include "HOMARD_Gen_i.hxx"
@@ -24,6 +33,7 @@
 
 #include "utilities.h"
 #include <vector>
+#include <sys/stat.h>
 
 //=============================================================================
 /*!
@@ -59,86 +69,168 @@ HOMARD_Cas_i::HOMARD_Cas_i( CORBA::ORB_ptr orb,
 HOMARD_Cas_i::~HOMARD_Cas_i()
 {
 }
-
 //=============================================================================
-/*!
- */
 //=============================================================================
-void HOMARD_Cas_i::SetDirName( const char* NomDir )
-{
-  ASSERT( myHomardCas );
-  myHomardCas->SetDirName( NomDir );
-}
-
+// Generalites
 //=============================================================================
-/*!
- */
 //=============================================================================
-void HOMARD_Cas_i::SetName( const char* NomCas )
+void HOMARD_Cas_i::SetName( const char* Name )
 {
   ASSERT( myHomardCas );
-  myHomardCas->SetName( NomCas );
+  myHomardCas->SetName( Name );
 }
-
-//=============================================================================
-/*!
- */
 //=============================================================================
 char* HOMARD_Cas_i::GetName()
 {
   ASSERT( myHomardCas );
   return CORBA::string_dup( myHomardCas->GetName().c_str() );
 }
-
 //=============================================================================
-/*!
- */
+CORBA::Long  HOMARD_Cas_i::Delete( CORBA::Long Option )
+{
+  ASSERT( myHomardCas );
+  char* CaseName = GetName() ;
+  MESSAGE ( "Delete : destruction du cas " << CaseName << ", Option = " << Option );
+  return _gen_i->DeleteCase(CaseName, Option) ;
+}
 //=============================================================================
 char* HOMARD_Cas_i::GetDumpPython()
 {
   ASSERT( myHomardCas );
   return CORBA::string_dup( myHomardCas->GetDumpPython().c_str() );
 }
-
+//=============================================================================
+std::string HOMARD_Cas_i::Dump() const
+{
+  return HOMARD::Dump( *myHomardCas );
+}
+//=============================================================================
+bool HOMARD_Cas_i::Restore( const std::string& stream )
+{
+  return HOMARD::Restore( *myHomardCas, stream );
+}
+//=============================================================================
+//=============================================================================
+// Caracteristiques
+//=============================================================================
+//=============================================================================
+void HOMARD_Cas_i::SetDirName( const char* NomDir )
+{
+  ASSERT( myHomardCas );
+  int codret ;
+  // A. recuperation du nom ; on ne fait rien si c'est le meme
+  char* oldrep = GetDirName() ;
+  MESSAGE ( "SetDirName : passage de oldrep = "<< oldrep << " a NomDir = "<<NomDir);
+  if ( oldrep == NomDir ) { return ; }
+  // B. Changement/creation du repertoire
+  codret = myHomardCas->SetDirName( NomDir );
+  if ( codret != 0 )
+  {
+    SALOME::ExceptionStruct es;
+    es.type = SALOME::BAD_PARAM;
+    std::string text ;
+    if ( codret == 1 ) { text = "The directory for the case cannot be modified because some iterations are already defined." ; }
+    else               { text = "The directory for the case cannot be reached." ; }
+    es.text = CORBA::string_dup(text.c_str());
+    throw SALOME::SALOME_Exception(es);
+  }
+  // C. En cas de reprise, deplacement du point de depart
+  if ( GetState() != 0 )
+  {
+    MESSAGE ( "etat : " << GetState() ) ;
+    // C.1. Nom local du repertoire de l'iteration de depart dans le repertoire actuel du cas
+    HOMARD::HOMARD_Iteration_ptr Iter = GetIter0() ;
+    char* DirNameIter = Iter->GetDirNameLoc() ;
+    MESSAGE ( "SetDirName : nom actuel pour le repertoire de l iteration, DirNameIter = "<< DirNameIter);
+    // C.2. Recherche d'un nom local pour l'iteration de depart dans le futur repertoire du cas
+    char* nomDirIter = _gen_i->CreateDirNameIter(NomDir, 0 );
+    MESSAGE ( "SetDirName : nom futur pour le repertoire de l iteration, nomDirIter = "<< nomDirIter);
+    // C.3. Creation du futur repertoire local pour l'iteration de depart
+    std::string nomDirIterTotal ;
+    nomDirIterTotal = std::string(NomDir) + "/" + std::string(nomDirIter) ;
+    if (mkdir(nomDirIterTotal.c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
+    {
+      MESSAGE ( "nomDirIterTotal : " << nomDirIterTotal ) ;
+      SALOME::ExceptionStruct es;
+      es.type = SALOME::BAD_PARAM;
+      std::string text = "The directory for the starting iteration cannot be created." ;
+      es.text = CORBA::string_dup(text.c_str());
+      throw SALOME::SALOME_Exception(es);
+    }
+    // C.4. Deplacement du contenu du repertoire
+    std::string oldnomDirIterTotal ;
+    oldnomDirIterTotal = std::string(oldrep) + "/" + std::string(DirNameIter) ;
+    std::string commande = "mv " + std::string(oldnomDirIterTotal) + "/*" + " " + std::string(nomDirIterTotal) ;
+    codret = system(commande.c_str()) ;
+    if ( codret != 0 )
+    {
+      SALOME::ExceptionStruct es;
+      es.type = SALOME::BAD_PARAM;
+      std::string text = "The starting point for the case cannot be moved into the new directory." ;
+      es.text = CORBA::string_dup(text.c_str());
+      throw SALOME::SALOME_Exception(es);
+    }
+    commande = "rm -rf " + std::string(oldnomDirIterTotal) ;
+    codret = system(commande.c_str()) ;
+    if ( codret != 0 )
+    {
+      SALOME::ExceptionStruct es;
+      es.type = SALOME::BAD_PARAM;
+      std::string text = "The starting point for the case cannot be deleted." ;
+      es.text = CORBA::string_dup(text.c_str());
+      throw SALOME::SALOME_Exception(es);
+    }
+    // C.5. Memorisation du nom du repertoire de l'iteration
+    Iter->SetDirNameLoc(nomDirIter) ;
+  }
+  return ;
+}
 //=============================================================================
 char* HOMARD_Cas_i::GetDirName()
 {
   ASSERT( myHomardCas );
   return CORBA::string_dup( myHomardCas->GetDirName().c_str() );
 }
-
 //=============================================================================
-void HOMARD_Cas_i::SetConfType( CORBA::Long ConfType )
+CORBA::Long HOMARD_Cas_i::GetState()
 {
   ASSERT( myHomardCas );
-  myHomardCas->SetConfType( ConfType );
+// Nom de l'iteration initiale
+  char* Iter0Name = GetIter0Name() ;
+  HOMARD::HOMARD_Iteration_ptr Iter = _gen_i->GetIteration(Iter0Name) ;
+  int state = Iter->GetNumber() ;
+  return state ;
 }
 //=============================================================================
-CORBA::Long HOMARD_Cas_i::GetNumber()
+CORBA::Long HOMARD_Cas_i::GetNumberofIter()
 {
   ASSERT( myHomardCas );
-  return myHomardCas->GetNumber();
+  return myHomardCas->GetNumberofIter();
 }
-
 //=============================================================================
-CORBA::Long HOMARD_Cas_i::GetConfType()
+void HOMARD_Cas_i::SetConfType( CORBA::Long ConfType )
 {
   ASSERT( myHomardCas );
-  return myHomardCas->GetConfType();
+  myHomardCas->SetConfType( ConfType );
 }
-
 //=============================================================================
-void HOMARD_Cas_i::AddIteration( const char* NomIteration )
+CORBA::Long HOMARD_Cas_i::GetConfType()
 {
   ASSERT( myHomardCas );
-  myHomardCas->AddIteration( NomIteration );
+  return myHomardCas->GetConfType();
 }
-
 //=============================================================================
-char* HOMARD_Cas_i::GetIter0Name()
+void HOMARD_Cas_i::SetBoundingBox( const HOMARD::extrema& LesExtrema )
 {
   ASSERT( myHomardCas );
-  return CORBA::string_dup( myHomardCas->GetIter0Name().c_str() );
+  std::vector<double> VExtrema;
+  ASSERT( LesExtrema.length() == 10 );
+  VExtrema.resize( LesExtrema.length() );
+  for ( int i = 0; i < LesExtrema.length(); i++ )
+  {
+    VExtrema[i] = LesExtrema[i];
+  }
+  myHomardCas->SetBoundingBox( VExtrema );
 }
 //=============================================================================
 HOMARD::extrema* HOMARD_Cas_i::GetBoundingBox()
@@ -155,20 +247,6 @@ HOMARD::extrema* HOMARD_Cas_i::GetBoundingBox()
   return aResult._retn();
 }
 //=============================================================================
-void HOMARD_Cas_i::SetBoundingBox( const HOMARD::extrema& LesExtrema )
-{
-  ASSERT( myHomardCas );
-  std::vector<double> VExtrema;
-  ASSERT( LesExtrema.length() == 10 );
-  VExtrema.resize( LesExtrema.length() );
-  for ( int i = 0; i < LesExtrema.length(); i++ )
-  {
-    VExtrema[i] = LesExtrema[i];
-  }
-
-  myHomardCas->SetBoundingBox( VExtrema );
-}
-//=============================================================================
 void HOMARD_Cas_i::AddGroup( const char* Group)
 {
   ASSERT( myHomardCas );
@@ -183,7 +261,6 @@ void HOMARD_Cas_i::SetGroups( const HOMARD::ListGroupType& ListGroup )
   {
     ListString.push_back(std::string(ListGroup[i]));
   }
-
   myHomardCas->SetGroups( ListString );
 }
 //=============================================================================
@@ -201,31 +278,47 @@ HOMARD::ListGroupType* HOMARD_Cas_i::GetGroups()
   }
   return aResult._retn();
 }
-
 //=============================================================================
-void HOMARD_Cas_i::AddBoundaryGroup( const char* Boundary, const char* Group)
+void HOMARD_Cas_i::AddBoundaryGroup( const char* BoundaryName, const char* Group)
 {
-  MESSAGE ("AddBoundaryGroup");
+  MESSAGE ("AddBoundaryGroup : BoundaryName = "<< BoundaryName << ", Group = " << Group );
   ASSERT( myHomardCas );
-  myHomardCas->AddBoundaryGroup( Boundary, Group );
+  // La frontiere est-elle deja enregistree pour ce cas ?
+  const std::list<std::string>& ListBoundaryGroup = myHomardCas->GetBoundaryGroup();
+  std::list<std::string>::const_iterator it;
+  int existe = 0;
+  for ( it = ListBoundaryGroup.begin(); it != ListBoundaryGroup.end(); it++ )
+  {
+    if ( *it == BoundaryName )
+    { existe = 1 ; }
+    it++ ;
+  }
+  // Enregistrement de la frontiere dans la reference du cas
+  myHomardCas->AddBoundaryGroup( BoundaryName, Group );
+  // Pour une nouvelle frontiere, publication dans l'arbre d'etudes sous le cas
+  if ( existe == 0 )
+  {
+    char* CaseName = GetName() ;
+    MESSAGE ( "AddBoundaryGroup : insertion de la frontiere dans l'arbre de " << CaseName );
+    _gen_i->PublishBoundaryUnderCase(CaseName, BoundaryName) ;
+  }
 }
 //=============================================================================
 HOMARD::ListBoundaryGroupType* HOMARD_Cas_i::GetBoundaryGroup()
 {
   MESSAGE ("GetBoundaryGroup");
   ASSERT(myHomardCas );
-  const std::list<std::string>& ListString = myHomardCas->GetBoundaryGroup();
+  const std::list<std::string>& ListBoundaryGroup = myHomardCas->GetBoundaryGroup();
   HOMARD::ListBoundaryGroupType_var aResult = new HOMARD::ListBoundaryGroupType();
-  aResult->length( ListString.size() );
+  aResult->length( ListBoundaryGroup.size() );
   std::list<std::string>::const_iterator it;
   int i = 0;
-  for ( it = ListString.begin(); it != ListString.end(); it++ )
+  for ( it = ListBoundaryGroup.begin(); it != ListBoundaryGroup.end(); it++ )
   {
     aResult[i++] = CORBA::string_dup( (*it).c_str() );
   }
   return aResult._retn();
 }
-
 //=============================================================================
 void HOMARD_Cas_i::SetPyram( CORBA::Long Pyram )
 {
@@ -241,13 +334,85 @@ CORBA::Long HOMARD_Cas_i::GetPyram()
   return myHomardCas->GetPyram();
 }
 //=============================================================================
-std::string HOMARD_Cas_i::Dump() const
+void HOMARD_Cas_i::MeshInfo(CORBA::Long Qual, CORBA::Long Diam, CORBA::Long Conn, CORBA::Long Tail, CORBA::Long Inte)
 {
-  return HOMARD::Dump( *myHomardCas );
+  MESSAGE ( "MeshInfo : information sur le maillage initial du cas" );
+  ASSERT( myHomardCas );
+//
+// Nom de l'iteration
+  char* IterName = GetIter0Name() ;
+  CORBA::Long etatMenage = -1 ;
+  CORBA::Long modeHOMARD = 7 ;
+  CORBA::Long Option1 = 1 ;
+  CORBA::Long Option2 = 1 ;
+  if ( Qual != 0 ) { modeHOMARD = modeHOMARD*5 ; }
+  if ( Diam != 0 ) { modeHOMARD = modeHOMARD*19 ; }
+  if ( Conn != 0 ) { modeHOMARD = modeHOMARD*11 ; }
+  if ( Tail != 0 ) { modeHOMARD = modeHOMARD*13 ; }
+  if ( Inte != 0 ) { modeHOMARD = modeHOMARD*3 ; }
+  CORBA::Long codret = _gen_i->Compute(IterName, etatMenage, modeHOMARD, Option1, Option2) ;
+  MESSAGE ( "MeshInfo : codret = " << codret );
+  return ;
 }
-
 //=============================================================================
-bool HOMARD_Cas_i::Restore( const std::string& stream )
+//=============================================================================
+// Liens avec les autres structures
+//=============================================================================
+//=============================================================================
+char* HOMARD_Cas_i::GetIter0Name()
 {
-  return HOMARD::Restore( *myHomardCas, stream );
+  ASSERT( myHomardCas );
+  return CORBA::string_dup( myHomardCas->GetIter0Name().c_str() );
+}
+//=============================================================================
+HOMARD::HOMARD_Iteration_ptr HOMARD_Cas_i::GetIter0()
+{
+// Nom de l'iteration initiale
+  char* Iter0Name = GetIter0Name() ;
+  MESSAGE ( "GetIter0 : Iter0Name      = " << Iter0Name );
+  return _gen_i->GetIteration(Iter0Name) ;
+}
+//=============================================================================
+HOMARD::HOMARD_Iteration_ptr HOMARD_Cas_i::NextIteration( const char* IterName )
+{
+// Nom de l'iteration parent
+  char* NomIterParent = GetIter0Name() ;
+  MESSAGE ( "NextIteration : IterName      = " << IterName );
+  MESSAGE ( "NextIteration : NomIterParent = " << NomIterParent );
+  return _gen_i->CreateIteration(IterName, NomIterParent) ;
+}
+//=============================================================================
+HOMARD::HOMARD_Iteration_ptr HOMARD_Cas_i::LastIteration( )
+{
+  HOMARD::HOMARD_Iteration_ptr Iter ;
+  HOMARD::listeIterFilles_var ListeIterFilles ;
+  char* IterName ;
+// Iteration initiale du cas
+  IterName = GetIter0Name() ;
+// On va explorer la descendance de cette iteration initiale
+// jusqu'a trouver celle qui n'a pas de filles
+  int nbiterfilles = 1 ;
+  while ( nbiterfilles == 1 )
+  {
+// L'iteration associee
+//     MESSAGE ( ".. IterName = " << IterName );
+    Iter = _gen_i->GetIteration(IterName) ;
+// Les filles de cette iteration
+    ListeIterFilles = Iter->GetIterations() ;
+    nbiterfilles = ListeIterFilles->length() ;
+//     MESSAGE ( ".. nbiterfilles = " << nbiterfilles );
+// S'il y a au moins 2 filles, arret : on ne sait pas faire
+    ASSERT( nbiterfilles <= 1 ) ;
+// S'il y a une fille unique, on recupere le nom de la fille et on recommence
+    if ( nbiterfilles == 1 )
+    { IterName = ListeIterFilles[0] ; }
+  }
+//
+  return Iter ;
+}
+//=============================================================================
+void HOMARD_Cas_i::AddIteration( const char* NomIteration )
+{
+  ASSERT( myHomardCas );
+  myHomardCas->AddIteration( NomIteration );
 }