Salome HOME
Copyright update 2022
[modules/smesh.git] / src / SMESHClient / SMESH_Client.cxx
index 66d071a07614ca97a4f69e2d2a655bb1930979ea..1cb0456812bc63b7d1678b21ab6fd2d1713556e9 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2020  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2022  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 #include "SMESHDS_Mesh.hxx"
 #include "SMESHDS_Script.hxx"
 #include "SMESH_Mesh.hxx"
-#include "SMESH_Component_Generator.hxx"
 
 #include "SALOME_NamingService.hxx"
+#include "SALOME_Fake_NamingService.hxx"
 #include "SALOME_LifeCycleCORBA.hxx"
 
 #include <SALOMEconfig.h>
+#include <smIdType.hxx>
 #include CORBA_SERVER_HEADER(SALOME_Component)
 #include CORBA_SERVER_HEADER(SALOME_Exception)
 
 #include "Basics_Utils.hxx"
+#include "KernelBasis.hxx"
 #include "utilities.h"
 
 #ifdef WIN32
@@ -47,6 +49,7 @@
 #endif
 
 #include <stdexcept>
+#include <memory>
 
 #ifndef EXCEPTION
 #define EXCEPTION(TYPE, MSG) {\
@@ -89,14 +92,14 @@ namespace
   //=======================================================================
   inline void AddNodesWithID(SMDS_Mesh* theMesh,
                              SMESH::log_array_var& theSeq,
-                             CORBA::Long theId)
+                             SMESH::smIdType theId)
   {
     const SMESH::double_array& aCoords = theSeq[theId].coords;
     const SMESH::long_array& anIndexes = theSeq[theId].indexes;
-    CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
-    if(3*aNbElems != (CORBA::Long) aCoords.length())
+    SMESH::smIdType anElemId = 0, aNbElems = theSeq[theId].number;
+    if(3*aNbElems != (SMESH::smIdType) aCoords.length())
       EXCEPTION(runtime_error,"AddNodesWithID - 3*aNbElems != aCoords.length()");
-    for(CORBA::Long aCoordId = 0; anElemId < aNbElems; anElemId++, aCoordId+=3){
+    for(SMESH::smIdType aCoordId = 0; anElemId < aNbElems; anElemId++, aCoordId+=3){
       SMDS_MeshElement* anElem = theMesh->AddNodeWithID(aCoords[aCoordId],
                                                         aCoords[aCoordId+1],
                                                         aCoords[aCoordId+2],
@@ -112,13 +115,13 @@ namespace
   //=======================================================================
   inline void Add0DElementsWithID(SMDS_Mesh* theMesh,
                                   SMESH::log_array_var& theSeq,
-                                  CORBA::Long theId)
+                                  SMESH::smIdType theId)
   {
     const SMESH::long_array& anIndexes = theSeq[theId].indexes;
-    CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
-    if (2*aNbElems != (CORBA::Long) anIndexes.length())
+    SMESH::smIdType anElemId = 0, aNbElems = theSeq[theId].number;
+    if (2*aNbElems != (SMESH::smIdType) anIndexes.length())
       EXCEPTION(runtime_error,"AddEdgeWithID - 2*aNbElems != aCoords.length()");
-    CORBA::Long anIndexId = 0;
+    SMESH::smIdType anIndexId = 0;
     for (; anElemId < aNbElems; anElemId++, anIndexId+=2)
     {
       SMDS_MeshElement* anElem = theMesh->Add0DElementWithID(anIndexes[anIndexId+1],
@@ -134,16 +137,16 @@ namespace
   //=======================================================================
   inline void AddBallsWithID(SMDS_Mesh*            theMesh,
                              SMESH::log_array_var& theSeq,
-                             CORBA::Long           theId)
+                             SMESH::smIdType       theId)
   {
     const SMESH::double_array& aDiameter = theSeq[theId].coords;
     const SMESH::long_array& anIndexes   = theSeq[theId].indexes;
-    CORBA::Long anElemId = 0, aNbElems   = theSeq[theId].number;
-    if (2*aNbElems != (CORBA::Long) anIndexes.length() )
+    SMESH::smIdType anElemId = 0, aNbElems   = theSeq[theId].number;
+    if (2*aNbElems != (SMESH::smIdType) anIndexes.length() )
       EXCEPTION(runtime_error,"AddEdgeWithID - 2*aNbElems != anIndexes.length()");
-    if (aNbElems != (CORBA::Long) aDiameter.length())
+    if (aNbElems != (SMESH::smIdType) aDiameter.length())
       EXCEPTION(runtime_error,"AddEdgeWithID - aNbElems != aDiameter.length()");
-    CORBA::Long anIndexId = 0;
+    SMESH::smIdType anIndexId = 0;
     for (; anElemId < aNbElems; anElemId++, anIndexId+=2)
     {
       SMDS_MeshElement* anElem = theMesh->AddBallWithID(anIndexes[anIndexId+1],
@@ -160,13 +163,13 @@ namespace
   //=======================================================================
   inline void AddEdgesWithID(SMDS_Mesh* theMesh,
                              SMESH::log_array_var& theSeq,
-                             CORBA::Long theId)
+                             SMESH::smIdType theId)
   {
     const SMESH::long_array& anIndexes = theSeq[theId].indexes;
-    CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
-    if(3*aNbElems != (CORBA::Long) anIndexes.length())
+    SMESH::smIdType anElemId = 0, aNbElems = theSeq[theId].number;
+    if(3*aNbElems != (SMESH::smIdType) anIndexes.length())
       EXCEPTION(runtime_error,"AddEdgeWithID - 3*aNbElems != aCoords.length()");
-    for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=3){
+    for(SMESH::smIdType anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=3){
       SMDS_MeshElement* anElem = theMesh->AddEdgeWithID(anIndexes[anIndexId+1],
                                                         anIndexes[anIndexId+2],
                                                         anIndexes[anIndexId]);
@@ -181,13 +184,13 @@ namespace
   //=======================================================================
   inline void AddTriasWithID(SMDS_Mesh* theMesh,
                              SMESH::log_array_var& theSeq,
-                             CORBA::Long theId)
+                             SMESH::smIdType theId)
   {
     const SMESH::long_array& anIndexes = theSeq[theId].indexes;
-    CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
-    if(4*aNbElems != (CORBA::Long) anIndexes.length())
+    SMESH::smIdType anElemId = 0, aNbElems = theSeq[theId].number;
+    if(4*aNbElems != (SMESH::smIdType) anIndexes.length())
       EXCEPTION(runtime_error,"AddTriasWithID - 4*aNbElems != anIndexes.length()");
-    for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=4){
+    for(SMESH::smIdType anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=4){
       SMDS_MeshElement* anElem = theMesh->AddFaceWithID(anIndexes[anIndexId+1],
                                                         anIndexes[anIndexId+2],
                                                         anIndexes[anIndexId+3],
@@ -203,13 +206,13 @@ namespace
   //=======================================================================
   inline void AddQuadsWithID(SMDS_Mesh* theMesh,
                              SMESH::log_array_var theSeq,
-                             CORBA::Long theId)
+                             SMESH::smIdType theId)
   {
     const SMESH::long_array& anIndexes = theSeq[theId].indexes;
-    CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
-    if(5*aNbElems != (CORBA::Long) anIndexes.length())
+    SMESH::smIdType anElemId = 0, aNbElems = theSeq[theId].number;
+    if(5*aNbElems != (SMESH::smIdType) anIndexes.length())
       EXCEPTION(runtime_error,"AddQuadsWithID - 4*aNbElems != anIndexes.length()");
-    for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=5){
+    for(SMESH::smIdType anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=5){
       SMDS_MeshElement* anElem = theMesh->AddFaceWithID(anIndexes[anIndexId+1],
                                                         anIndexes[anIndexId+2],
                                                         anIndexes[anIndexId+3],
@@ -226,16 +229,16 @@ namespace
   //=======================================================================
   inline void AddPolygonsWithID(SMDS_Mesh* theMesh,
                                 SMESH::log_array_var& theSeq,
-                                CORBA::Long theId)
+                                SMESH::smIdType theId)
   {
     const SMESH::long_array& anIndexes = theSeq[theId].indexes;
-    CORBA::Long anIndexId = 0, aNbElems = theSeq[theId].number;
+    SMESH::smIdType anIndexId = 0, aNbElems = theSeq[theId].number;
 
-    for (CORBA::Long anElemId = 0; anElemId < aNbElems; anElemId++) {
-      int aFaceId = anIndexes[anIndexId++];
+    for (SMESH::smIdType anElemId = 0; anElemId < aNbElems; anElemId++) {
+      smIdType aFaceId = anIndexes[anIndexId++];
 
       int aNbNodes = anIndexes[anIndexId++];
-      std::vector<int> nodes_ids (aNbNodes);
+      std::vector<smIdType> nodes_ids (aNbNodes);
       for (int i = 0; i < aNbNodes; i++) {
         nodes_ids[i] = anIndexes[anIndexId++];
       }
@@ -253,16 +256,16 @@ namespace
   //=======================================================================
   inline void AddQuadPolygonsWithID(SMDS_Mesh* theMesh,
                                     SMESH::log_array_var& theSeq,
-                                    CORBA::Long theId)
+                                    SMESH::smIdType theId)
   {
     const SMESH::long_array& anIndexes = theSeq[theId].indexes;
-    CORBA::Long anIndexId = 0, aNbElems = theSeq[theId].number;
+    SMESH::smIdType anIndexId = 0, aNbElems = theSeq[theId].number;
 
-    for (CORBA::Long anElemId = 0; anElemId < aNbElems; anElemId++) {
-      int aFaceId = anIndexes[anIndexId++];
+    for (SMESH::smIdType anElemId = 0; anElemId < aNbElems; anElemId++) {
+      smIdType aFaceId = anIndexes[anIndexId++];
 
       int aNbNodes = anIndexes[anIndexId++];
-      std::vector<int> nodes_ids (aNbNodes);
+      std::vector<smIdType> nodes_ids (aNbNodes);
       for (int i = 0; i < aNbNodes; i++) {
         nodes_ids[i] = anIndexes[anIndexId++];
       }
@@ -280,13 +283,13 @@ namespace
   //=======================================================================
   inline void AddTetrasWithID(SMDS_Mesh* theMesh,
                               SMESH::log_array_var& theSeq,
-                              CORBA::Long theId)
+                              SMESH::smIdType theId)
   {
     const SMESH::long_array& anIndexes = theSeq[theId].indexes;
-    CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
-    if(5*aNbElems != (CORBA::Long) anIndexes.length())
+    SMESH::smIdType anElemId = 0, aNbElems = theSeq[theId].number;
+    if(5*aNbElems != (SMESH::smIdType) anIndexes.length())
       EXCEPTION(runtime_error,"AddTetrasWithID - 5*aNbElems != anIndexes.length()");
-    for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=5){
+    for(SMESH::smIdType anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=5){
       SMDS_MeshElement* anElem = theMesh->AddVolumeWithID(anIndexes[anIndexId+1],
                                                           anIndexes[anIndexId+2],
                                                           anIndexes[anIndexId+3],
@@ -303,13 +306,13 @@ namespace
   //=======================================================================
   inline void AddPiramidsWithID(SMDS_Mesh* theMesh,
                                 SMESH::log_array_var& theSeq,
-                                CORBA::Long theId)
+                                SMESH::smIdType theId)
   {
     const SMESH::long_array& anIndexes = theSeq[theId].indexes;
-    CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
-    if(6*aNbElems != (CORBA::Long) anIndexes.length())
+    SMESH::smIdType anElemId = 0, aNbElems = theSeq[theId].number;
+    if(6*aNbElems != (SMESH::smIdType) anIndexes.length())
       EXCEPTION(runtime_error,"AddPiramidsWithID - 6*aNbElems != anIndexes.length()");
-    for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=6){
+    for(SMESH::smIdType anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=6){
       SMDS_MeshElement* anElem = theMesh->AddVolumeWithID(anIndexes[anIndexId+1],
                                                           anIndexes[anIndexId+2],
                                                           anIndexes[anIndexId+3],
@@ -327,7 +330,7 @@ namespace
   //=======================================================================
   inline void AddPrismsWithID(SMDS_Mesh* theMesh,
                               SMESH::log_array_var& theSeq,
-                              CORBA::Long theId)
+                              SMESH::smIdType theId)
   {
     const SMESH::long_array& anIndexes = theSeq[theId].indexes;
     CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
@@ -415,10 +418,10 @@ namespace
     CORBA::Long anIndexId = 0, aNbElems = theSeq[theId].number;
 
     for (CORBA::Long anElemId = 0; anElemId < aNbElems; anElemId++) {
-      int aFaceId = anIndexes[anIndexId++];
+      smIdType aFaceId = anIndexes[anIndexId++];
 
       int aNbNodes = anIndexes[anIndexId++];
-      std::vector<int> nodes_ids (aNbNodes);
+      std::vector<smIdType> nodes_ids (aNbNodes);
       for (int i = 0; i < aNbNodes; i++) {
         nodes_ids[i] = anIndexes[anIndexId++];
       }
@@ -786,31 +789,30 @@ SMESH_Client::GetSMESHGen(CORBA::ORB_ptr theORB,
 
   if(CORBA::is_nil(aMeshGen.in()))
   {
-    Engines::EngineComponent_var isCompoInSSLMode = GetSMESHInstanceHasThis();
-    if( CORBA::is_nil(isCompoInSSLMode) )
-    {
 #ifdef WIN32
-      long aClientPID = (long)_getpid();
+    long aClientPID = (long)_getpid();
 #else
-      long aClientPID =  (long)getpid();
+    long aClientPID =  (long)getpid();
 #endif
 
-      SALOME_NamingService aNamingService(theORB);
-      SALOME_LifeCycleCORBA aLifeCycleCORBA(&aNamingService);
-      Engines::EngineComponent_var aComponent = aLifeCycleCORBA.FindOrLoad_Component("FactoryServer","SMESH");
-      aMeshGen = SMESH::SMESH_Gen::_narrow(aComponent);
-
-      std::string aClientHostName = Kernel_Utils::GetHostname();
-      Engines::Container_var aServerContainer = aMeshGen->GetContainerRef();
-      CORBA::String_var aServerHostName = aServerContainer->getHostName();
-      CORBA::Long aServerPID = aServerContainer->getPID();
-      aMeshGen->SetEmbeddedMode((aClientPID == aServerPID) && (aClientHostName == aServerHostName.in()));
+    std::unique_ptr<SALOME_NamingService_Abstract> aNamingService;
+    if(getSSLMode())
+    {
+      aNamingService.reset(new SALOME_Fake_NamingService);
     }
     else
     {
-      aMeshGen = SMESH::SMESH_Gen::_narrow(isCompoInSSLMode);
+      aNamingService.reset(new SALOME_NamingService(theORB));
     }
-    
+    SALOME_LifeCycleCORBA aLifeCycleCORBA(aNamingService.get());
+    Engines::EngineComponent_var aComponent = aLifeCycleCORBA.FindOrLoad_Component("FactoryServer","SMESH");
+    aMeshGen = SMESH::SMESH_Gen::_narrow(aComponent);
+
+    std::string aClientHostName = Kernel_Utils::GetHostname();
+    Engines::Container_var aServerContainer = aMeshGen->GetContainerRef();
+    CORBA::String_var aServerHostName = aServerContainer->getHostName();
+    CORBA::Long aServerPID = aServerContainer->getPID();
+    aMeshGen->SetEmbeddedMode((aClientPID == aServerPID) && (aClientHostName == aServerHostName.in()));
   }
   theIsEmbeddedMode = aMeshGen->IsEmbeddedMode();
   return aMeshGen;