Salome HOME
Make it work in HOMARD standalone case
[modules/homard.git] / src / HOMARD_I / HOMARD_Gen_i.cxx
index b1cbfbea63891166c3d7bcb00f9718dc31fb8c3b..63d70304335357ac524ab836fb67e71dccc3187c 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2011-2019  CEA/DEN, EDF R&D
+// Copyright (C) 2011-2020  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
 
 #include "utilities.h"
 #include "Basics_Utils.hxx"
+#include "Basics_DirUtils.hxx"
 #include "Utils_SINGLETON.hxx"
 #include "Utils_CorbaException.hxx"
 #include "SALOMEDS_Tool.hxx"
 #include "SALOME_LifeCycleCORBA.hxx"
 #include "SALOMEconfig.h"
 #include <SMESH_Gen_i.hxx>
-#include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
-#include CORBA_CLIENT_HEADER(SMESH_Gen)
 
 #include <cmath>
 #include <stdlib.h>
@@ -91,19 +90,15 @@ HOMARD_Gen_i::HOMARD_Gen_i( CORBA::ORB_ptr orb,
                             PortableServer::POA_ptr poa,
                             PortableServer::ObjectId * contId,
                             const char *instanceName,
-                            const char *interfaceName) :
-Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
+                            const char *interfaceName,
+                            bool checkNS) :
+Engines_Component_i(orb, poa, contId, instanceName, interfaceName, false, checkNS)
 {
-  MESSAGE("constructor");
+  MESSAGE("constructor de HOMARD_Gen_i");
   _thisObj = this;
   _id = _poa->activate_object(_thisObj);
 
-  myHomard = new ::HOMARD_Gen();
-  _NS = SINGLETON_<SALOME_NamingService>::Instance();
-  ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting());
-  _NS->init_orb(_orb);
-
-  myStudy = SALOMEDS::Study::_duplicate( SMESH_Gen_i::getStudyServant() );
+  myHomard = new ::HOMARD_Gen;
 
   _tag_gene = 0 ;
   _tag_boun = 0 ;
@@ -144,9 +139,7 @@ void HOMARD_Gen_i::UpdateStudy()
     homardFather = myBuilder->NewComponent(ComponentDataType());
     SALOMEDS::GenericAttribute_var anAttr = myBuilder->FindOrCreateAttribute(homardFather,"AttributeName");
     SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
-    CORBA::Object_var objVarN = _NS->Resolve("/Kernel/ModulCatalog");
-    SALOME_ModuleCatalog::ModuleCatalog_var Catalogue =
-                SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
+    SALOME_ModuleCatalog::ModuleCatalog_var Catalogue = this->getModuleCatalog();
     SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent(ComponentDataType());
     if (!Comp->_is_nil())
     {
@@ -1105,8 +1098,8 @@ HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::GetZone(const char* ZoneName)
 //=============================================================================
 void HOMARD_Gen_i::MeshInfo(const char* nomCas, const char* MeshName, const char* MeshFile, const char* DirName, CORBA::Long Qual, CORBA::Long Diam, CORBA::Long Conn, CORBA::Long Tail, CORBA::Long Inte)
 {
-  INFOS ( "MeshInfo : nomCas = " << nomCas << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile  );
-  INFOS ( "Qual = " << Qual << ", Diam = " << Diam << ", Conn = " << Conn << ", Tail = " << Tail << ", Inte = " << Inte  );
+  MESSAGE ( "MeshInfo : nomCas = " << nomCas << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile  );
+  MESSAGE ( "Qual = " << Qual << ", Diam = " << Diam << ", Conn = " << Conn << ", Tail = " << Tail << ", Inte = " << Inte  );
   IsValidStudy () ;
 
 // Creation du cas
@@ -1225,7 +1218,7 @@ HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromIteration(const char* nomCas,
 // DirNameStart : nom du répertoire contenant l'iteration de reprise
 //
 {
-  INFOS ( "CreateCaseFromIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart );
+  MESSAGE ( "CreateCaseFromIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart );
   std::string nomDirWork = getenv("PWD") ;
   int codret ;
 
@@ -1446,7 +1439,7 @@ HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromCaseLastIteration(const char*
 // DirNameStart : nom du répertoire du cas contenant l'iteration de reprise
 //
 {
-  INFOS ( "CreateCaseFromCaseLastIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart );
+  MESSAGE ( "CreateCaseFromCaseLastIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart );
 
   std::string DirNameStartIter = CreateCase1(DirNameStart, -1) ;
 
@@ -1463,7 +1456,7 @@ HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromCaseIteration(const char* nom
 // Number : numero de l'iteration de depart
 //
 {
-  INFOS ( "CreateCaseFromCaseIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart << ", Number = " << Number );
+  MESSAGE ( "CreateCaseFromCaseIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart << ", Number = " << Number );
   if ( Number < 0 )
   {
     SALOME::ExceptionStruct es;
@@ -1748,7 +1741,7 @@ HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCase0(const char* nomCas, const char*
 //=============================================================================
 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::CreateHypothesis(const char* nomHypothesis)
 {
-  INFOS ( "CreateHypothesis : nomHypothesis = " << nomHypothesis );
+  MESSAGE ( "CreateHypothesis : nomHypothesis = " << nomHypothesis );
   IsValidStudy () ;
 
   // A. Controle du nom :
@@ -1792,7 +1785,7 @@ HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::CreateHypothesis(const char* nomHypo
 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::CreateIteration(const char* NomIteration, const char* nomIterParent)
 //=============================================================================
 {
-  INFOS ("CreateIteration : NomIteration  = " << NomIteration << ", nomIterParent = " << nomIterParent);
+  MESSAGE ("CreateIteration : NomIteration  = " << NomIteration << ", nomIterParent = " << nomIterParent);
   IsValidStudy () ;
 
   HOMARD::HOMARD_Iteration_var myIterationParent = myStudyContext._mesIterations[nomIterParent];
@@ -1918,7 +1911,7 @@ HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundary(const char* BoundaryNam
 //=============================================================================
 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryCAO(const char* BoundaryName, const char* CAOFile)
 {
-  INFOS ("CreateBoundaryCAO : BoundaryName  = " << BoundaryName << ", CAOFile = " << CAOFile );
+  MESSAGE ("CreateBoundaryCAO : BoundaryName  = " << BoundaryName << ", CAOFile = " << CAOFile );
   HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, -1);
   myBoundary->SetDataFile( CAOFile ) ;
 
@@ -1927,7 +1920,7 @@ HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryCAO(const char* Boundary
 //=============================================================================
 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryDi(const char* BoundaryName, const char* MeshName, const char* MeshFile)
 {
-  INFOS ("CreateBoundaryDi : BoundaryName  = " << BoundaryName << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile );
+  MESSAGE ("CreateBoundaryDi : BoundaryName  = " << BoundaryName << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile );
   HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 0);
   myBoundary->SetDataFile( MeshFile ) ;
   myBoundary->SetMeshName( MeshName ) ;
@@ -1940,7 +1933,7 @@ HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryCylinder(const char* Bou
                                       CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
                                       CORBA::Double Rayon)
 {
-  INFOS ("CreateBoundaryCylinder : BoundaryName  = " << BoundaryName ) ;
+  MESSAGE ("CreateBoundaryCylinder : BoundaryName  = " << BoundaryName ) ;
 //
   SALOME::ExceptionStruct es;
   int error = 0 ;
@@ -1968,7 +1961,7 @@ HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundarySphere(const char* Bound
                                       CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
                                       CORBA::Double Rayon)
 {
-  INFOS ("CreateBoundarySphere : BoundaryName  = " << BoundaryName ) ;
+  MESSAGE ("CreateBoundarySphere : BoundaryName  = " << BoundaryName ) ;
 //
   SALOME::ExceptionStruct es;
   int error = 0 ;
@@ -1992,7 +1985,7 @@ HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryConeA(const char* Bounda
                                       CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe, CORBA::Double Angle,
                                       CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre)
 {
-  INFOS ("CreateBoundaryConeA : BoundaryName  = " << BoundaryName ) ;
+  MESSAGE ("CreateBoundaryConeA : BoundaryName  = " << BoundaryName ) ;
 //
   SALOME::ExceptionStruct es;
   int error = 0 ;
@@ -2020,7 +2013,7 @@ HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryConeR(const char* Bounda
                                       CORBA::Double Xcentre1, CORBA::Double Ycentre1, CORBA::Double Zcentre1, CORBA::Double Rayon1,
                                       CORBA::Double Xcentre2, CORBA::Double Ycentre2, CORBA::Double Zcentre2, CORBA::Double Rayon2)
 {
-  INFOS ("CreateBoundaryConeR : BoundaryName  = " << BoundaryName ) ;
+  MESSAGE ("CreateBoundaryConeR : BoundaryName  = " << BoundaryName ) ;
 //
   SALOME::ExceptionStruct es;
   int error = 0 ;
@@ -2053,7 +2046,7 @@ HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryTorus(const char* Bounda
                                       CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
                                       CORBA::Double RayonRev, CORBA::Double RayonPri)
 {
-  INFOS ("CreateBoundaryTorus : BoundaryName  = " << BoundaryName ) ;
+  MESSAGE ("CreateBoundaryTorus : BoundaryName  = " << BoundaryName ) ;
 //
   SALOME::ExceptionStruct es;
   int error = 0 ;
@@ -2109,7 +2102,7 @@ HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox(const char* ZoneName,
                                       CORBA::Double Ymini, CORBA::Double Ymaxi,
                                       CORBA::Double Zmini, CORBA::Double Zmaxi)
 {
-  INFOS ("CreateZoneBox : ZoneName  = " << ZoneName ) ;
+  MESSAGE ("CreateZoneBox : ZoneName  = " << ZoneName ) ;
 //
   SALOME::ExceptionStruct es;
   int error = 0 ;
@@ -2138,7 +2131,7 @@ HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox(const char* ZoneName,
 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneSphere(const char* ZoneName,
                                       CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre, CORBA::Double Rayon)
 {
-  INFOS ("CreateZoneSphere : ZoneName  = " << ZoneName ) ;
+  MESSAGE ("CreateZoneSphere : ZoneName  = " << ZoneName ) ;
 //
   SALOME::ExceptionStruct es;
   int error = 0 ;
@@ -2163,7 +2156,7 @@ HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneCylinder(const char* ZoneName,
                                       CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
                                       CORBA::Double Rayon, CORBA::Double Haut)
 {
-  INFOS ("CreateZoneCylinder : ZoneName  = " << ZoneName ) ;
+  MESSAGE ("CreateZoneCylinder : ZoneName  = " << ZoneName ) ;
 //
   SALOME::ExceptionStruct es;
   int error = 0 ;
@@ -2195,7 +2188,7 @@ HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZonePipe(const char* ZoneName,
                                       CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
                                       CORBA::Double Rayon, CORBA::Double Haut, CORBA::Double Rayonint)
 {
-  INFOS ("CreateZonePipe : ZoneName  = " << ZoneName ) ;
+  MESSAGE ("CreateZonePipe : ZoneName  = " << ZoneName ) ;
 //
   SALOME::ExceptionStruct es;
   int error = 0 ;
@@ -2230,7 +2223,7 @@ HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox2D(const char* ZoneName,
                                       CORBA::Double Vmini, CORBA::Double Vmaxi,
                                       CORBA::Long Orient)
 {
-  INFOS ("CreateZoneBox2D : ZoneName  = " << ZoneName ) ;
+  MESSAGE ("CreateZoneBox2D : ZoneName  = " << ZoneName ) ;
 //   MESSAGE ("Umini = " << Umini << ", Umaxi =" << Umaxi ) ;
 //   MESSAGE ("Vmini = " << Vmini << ", Vmaxi =" << Vmaxi ) ;
 //   MESSAGE ("Orient = " << Orient ) ;
@@ -2290,7 +2283,7 @@ HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDisk(const char* ZoneName,
                                       CORBA::Double Rayon,
                                       CORBA::Long Orient)
 {
-  INFOS ("CreateZoneDisk : ZoneName  = " << ZoneName ) ;
+  MESSAGE ("CreateZoneDisk : ZoneName  = " << ZoneName ) ;
 //
   SALOME::ExceptionStruct es;
   int error = 0 ;
@@ -2335,7 +2328,7 @@ HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDiskWithHole(const char* ZoneNam
                                       CORBA::Double Rayon, CORBA::Double Rayonint,
                                       CORBA::Long Orient)
 {
-  INFOS ("CreateZoneDiskWithHole : ZoneName  = " << ZoneName ) ;
+  MESSAGE ("CreateZoneDiskWithHole : ZoneName  = " << ZoneName ) ;
 //
   SALOME::ExceptionStruct es;
   int error = 0 ;
@@ -2642,7 +2635,7 @@ CORBA::Long HOMARD_Gen_i::Compute(const char* NomIteration, CORBA::Long etatMena
   {
     if ( ( modeHOMARD == 1 ) && ( BoundaryOption % 5 == 0 ) && (codretexec == 0) )
     {
-      INFOS ( "Suivi de frontière CAO" );
+      MESSAGE ( "Suivi de frontière CAO" );
       codret = ComputeCAO(myCase, myIteration, Option1, Option2) ;
     }
   }
@@ -4001,8 +3994,9 @@ void HOMARD_Gen_i::PublishResultInSmesh(const char* NomFich, CORBA::Long Option)
 
 // On enregistre le fichier
   MESSAGE( "Enregistrement du fichier");
-  SALOME_LifeCycleCORBA* myLCC = new SALOME_LifeCycleCORBA(_NS);
-  SMESH::SMESH_Gen_var aSmeshEngine = SMESH::SMESH_Gen::_narrow(myLCC->FindOrLoad_Component("FactoryServer","SMESH"));
+  //
+  SMESH::SMESH_Gen_var aSmeshEngine = this->retrieveSMESHInst();
+  //
   ASSERT(!CORBA::is_nil(aSmeshEngine));
   aSmeshEngine->UpdateStudy();
   SMESH::DriverMED_ReadStatus theStatus;
@@ -4182,11 +4176,11 @@ void HOMARD_Gen_i::PublishFileUnderYACS(const char* nomYACS, const char* NomFich
 //=============================================================================
 HOMARD::HOMARD_YACS_ptr HOMARD_Gen_i::CreateYACSSchema (const char* nomYACS, const char* nomCas, const char* ScriptFile, const char* DirName, const char* MeshFile)
 {
-  INFOS ( "CreateYACSSchema : Schema YACS " << nomYACS );
-  INFOS ( ". nomCas     : " << nomCas);
-  INFOS ( ". ScriptFile : " << ScriptFile);
-  INFOS ( ". DirName    : " << DirName);
-  INFOS ( ". MeshFile   : " << MeshFile);
+  MESSAGE ( "CreateYACSSchema : Schema YACS " << nomYACS );
+  MESSAGE ( ". nomCas     : " << nomCas);
+  MESSAGE ( ". ScriptFile : " << ScriptFile);
+  MESSAGE ( ". DirName    : " << DirName);
+  MESSAGE ( ". MeshFile   : " << MeshFile);
 
   // A. Controle du nom :
   if ((myStudyContext._mesYACSs).find(nomYACS) != (myStudyContext._mesYACSs).end())
@@ -4249,7 +4243,7 @@ HOMARD::HOMARD_YACS_ptr HOMARD_Gen_i::CreateYACSSchema (const char* nomYACS, con
 //=============================================================================
 CORBA::Long HOMARD_Gen_i::YACSWrite(const char* nomYACS)
 {
-  INFOS ( "YACSWrite : Ecriture de " << nomYACS );
+  MESSAGE ( "YACSWrite : Ecriture de " << nomYACS );
 // Le répertoire du cas
   HOMARD::HOMARD_YACS_var myYACS = myStudyContext._mesYACSs[nomYACS];
   ASSERT(!CORBA::is_nil(myYACS));
@@ -4266,7 +4260,7 @@ CORBA::Long HOMARD_Gen_i::YACSWrite(const char* nomYACS)
 //=============================================================================
 CORBA::Long HOMARD_Gen_i::YACSWriteOnFile(const char* nomYACS, const char* XMLFile)
 {
-  INFOS ( "YACSWriteOnFile : Ecriture de " << nomYACS << " sur " << XMLFile );
+  MESSAGE ( "YACSWriteOnFile : Ecriture de " << nomYACS << " sur " << XMLFile );
 
   // A. Prealable
   int codret = 0;
@@ -4579,7 +4573,7 @@ SALOMEDS::TMPFile* HOMARD_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
   // HOMARD data file name
   std::string aFileName = "";
   if (isMultiFile)
-    aFileName = SALOMEDS_Tool::GetNameFromPath(Kernel_Utils::encode(SMESH_Gen_i::getStudyServant()->URL()));
+    aFileName = SALOMEDS_Tool::GetNameFromPath(Kernel_Utils::encode(myStudy->URL()));
   aFileName += "_HOMARD.dat";
 
   // initialize sequence of file names
@@ -4703,7 +4697,7 @@ CORBA::Boolean HOMARD_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
   // HOMARD data file name
   std::string aFileName = "";
   if (isMultiFile)
-    aFileName = SALOMEDS_Tool::GetNameFromPath(Kernel_Utils::encode(SMESH_Gen_i::getStudyServant()->URL()));
+    aFileName = SALOMEDS_Tool::GetNameFromPath(Kernel_Utils::encode(myStudy->URL()));
   aFileName = tmpDir + aFileName + "_HOMARD.dat";
 
   StudyContext& context = myStudyContext;
@@ -4965,7 +4959,7 @@ Engines::TMPFile* HOMARD_Gen_i::DumpPython(CORBA::Boolean isPublished,
    MESSAGE ("Entree dans DumpPython");
    isValidScript=1;
 
-   SALOMEDS::SObject_var aSO = SMESH_Gen_i::getStudyServant()->FindComponent("HOMARD");
+   SALOMEDS::SObject_var aSO = myStudy->FindComponent("HOMARD");
    if(CORBA::is_nil(aSO))
       return new Engines::TMPFile(0);
 
@@ -5134,7 +5128,7 @@ Engines::TMPFile* HOMARD_Gen_i::DumpPython(CORBA::Boolean isPublished,
 void HOMARD_Gen_i::IsValidStudy( )
 {
 //   MESSAGE( "IsValidStudy" );
-  if (CORBA::is_nil(SMESH_Gen_i::getStudyServant()))
+  if (CORBA::is_nil(myStudy))
   {
     SALOME::ExceptionStruct es;
     es.type = SALOME::BAD_PARAM;
@@ -5260,7 +5254,7 @@ void HOMARD_Gen_i::SetPreferences( )
   if ( ok )
   {
     std::string PrefFile ;
-    PrefFile  = getenv("HOME") ;
+    PrefFile  = Kernel_Utils::HomePath() ;
     PrefFile += "/.config/salome/SalomeApprc." + salome_version ;
     MESSAGE ( "PrefFile = "<<PrefFile ) ;
 
@@ -5414,18 +5408,3 @@ CORBA::Long HOMARD_Gen_i::GetYACSConvergenceType()
   return _YACSTypeTest ;
 }
 
-//=============================================================================
-extern "C"
-{
-  HOMARDENGINE_EXPORT
-  PortableServer::ObjectId* HOMARDEngine_factory(CORBA::ORB_ptr orb,
-                                                 PortableServer::POA_ptr poa,
-                                                 PortableServer::ObjectId* contId,
-                                                 const char* instanceName,
-                                                 const char* interfaceName)
-  {
-    MESSAGE("PortableServer::ObjectId* HOMARDEngine_factory()");
-    HOMARD_Gen_i* myHOMARD_Gen = new HOMARD_Gen_i(orb, poa, contId, instanceName, interfaceName);
-    return myHOMARD_Gen->getId();
-  }
-}