Salome HOME
Updated copyright comment
[modules/smesh.git] / src / SMESHClient / SMESH_Client.cxx
index 73ad16111c6d62fc1f33011195dc58f3ffa54dc4..f5251c2ff46e8c38fb17f26817689ea5fc07888c 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2024  CEA, EDF, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 #include "SMESH_Mesh.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
@@ -46,6 +49,7 @@
 #endif
 
 #include <stdexcept>
+#include <memory>
 
 #ifndef EXCEPTION
 #define EXCEPTION(TYPE, MSG) {\
 }
 #endif
 
-#ifdef _DEBUG_
-static int MYDEBUG = 0;
-#else
-static int MYDEBUG = 0;
-#endif
-
 namespace
 {
   using std::runtime_error;
@@ -88,14 +86,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],
@@ -111,13 +109,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],
@@ -133,16 +131,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],
@@ -159,13 +157,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]);
@@ -180,13 +178,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],
@@ -202,13 +200,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],
@@ -225,16 +223,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++];
       }
@@ -252,16 +250,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++];
       }
@@ -279,13 +277,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],
@@ -302,13 +300,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],
@@ -326,7 +324,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;
@@ -414,10 +412,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++];
       }
@@ -745,34 +743,34 @@ namespace
   //=======================================================================
   //function : ChangePolyhedronNodes
   //=======================================================================
-  inline void ChangePolyhedronNodes (SMDS_Mesh* theMesh,
+  inline void ChangePolyhedronNodes (SMDS_Mesh*            theMesh,
                                      SMESH::log_array_var& theSeq,
-                                     CORBA::Long theId)
+                                     CORBA::Long           theId)
   {
-    // const SMESH::long_array& anIndexes = theSeq[theId].indexes;
-    // CORBA::Long iind = 0, aNbElems = theSeq[theId].number;
-
-    // for (CORBA::Long anElemId = 0; anElemId < aNbElems; anElemId++)
-    // {
-    //   // find element
-    //   const SMDS_MeshElement* elem = FindElement(theMesh, anIndexes[iind++]);
-    //   // nb nodes
-    //   int nbNodes = anIndexes[iind++];
-    //   // nodes
-    //   std::vector<const SMDS_MeshNode*> aNodes (nbNodes);
-    //   for (int iNode = 0; iNode < nbNodes; iNode++) {
-    //     aNodes[iNode] = FindNode(theMesh, anIndexes[iind++]);
-    //   }
-    //   // nb faces
-    //   int nbFaces = anIndexes[iind++];
-    //   // quantities
-    //   std::vector<int> quantities (nbFaces);
-    //   for (int iFace = 0; iFace < nbFaces; iFace++) {
-    //     quantities[iFace] = anIndexes[iind++];
-    //   }
-    //   // change
-    //   theMesh->ChangePolyhedronNodes(elem, aNodes, quantities);
-    // }
+    const SMESH::long_array& anIndexes = theSeq[theId].indexes;
+    CORBA::Long iind = 0, aNbElems = theSeq[theId].number;
+
+    for (CORBA::Long anElemId = 0; anElemId < aNbElems; anElemId++)
+    {
+      // find element
+      const SMDS_MeshElement* elem = FindElement(theMesh, anIndexes[iind++]);
+      // nb nodes
+      int nbNodes = anIndexes[iind++];
+      // nodes
+      std::vector<const SMDS_MeshNode*> aNodes (nbNodes);
+      for (int iNode = 0; iNode < nbNodes; iNode++) {
+        aNodes[iNode] = FindNode(theMesh, anIndexes[iind++]);
+      }
+      // nb faces
+      int nbFaces = anIndexes[iind++];
+      // quantities
+      std::vector<int> quantities (nbFaces);
+      for (int iFace = 0; iFace < nbFaces; iFace++) {
+        quantities[iFace] = anIndexes[iind++];
+      }
+      // change
+      theMesh->ChangePolyhedronNodes(elem, aNodes, quantities);
+    }
   }
 }
 
@@ -783,15 +781,24 @@ SMESH_Client::GetSMESHGen(CORBA::ORB_ptr theORB,
 {
   static SMESH::SMESH_Gen_var aMeshGen;
 
-  if(CORBA::is_nil(aMeshGen.in())){
+  if(CORBA::is_nil(aMeshGen.in()))
+  {
 #ifdef WIN32
     long aClientPID = (long)_getpid();
 #else
     long aClientPID =  (long)getpid();
 #endif
 
-    SALOME_NamingService aNamingService(theORB);
-    SALOME_LifeCycleCORBA aLifeCycleCORBA(&aNamingService);
+    std::unique_ptr<SALOME_NamingService_Abstract> aNamingService;
+    if(getSSLMode())
+    {
+      aNamingService.reset(new SALOME_Fake_NamingService);
+    }
+    else
+    {
+      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);
 
@@ -802,7 +809,6 @@ SMESH_Client::GetSMESHGen(CORBA::ORB_ptr theORB,
     aMeshGen->SetEmbeddedMode((aClientPID == aServerPID) && (aClientHostName == aServerHostName.in()));
   }
   theIsEmbeddedMode = aMeshGen->IsEmbeddedMode();
-
   return aMeshGen;
 }
 
@@ -817,19 +823,19 @@ SMESH_Client::SMESH_Client(CORBA::ORB_ptr theORB,
   mySMESHDSMesh(NULL),
   mySMDSMesh(NULL)
 {
-  if ( MYDEBUG ) MESSAGE("SMESH_Client::SMESH_Client");
+  MESSAGE("SMESH_Client::SMESH_Client");
   myMeshServer->Register();
 
   CORBA::Boolean anIsEmbeddedMode;
   GetSMESHGen(theORB,anIsEmbeddedMode);
   if(anIsEmbeddedMode){
-    if ( MYDEBUG ) MESSAGE("Info: The same process, update mesh by pointer ");
+    MESSAGE("Info: The same process, update mesh by pointer ");
     // just set client mesh pointer to server mesh pointer
     //SMESH_Mesh* aMesh = reinterpret_cast<SMESH_Mesh*>(theMesh->GetMeshPtr());
     CORBA::LongLong pointeur = theMesh->GetMeshPtr();
-    if( MYDEBUG ) MESSAGE("SMESH_Client::SMESH_Client pointeur "<<pointeur);
+    MESSAGE("SMESH_Client::SMESH_Client pointeur "<<pointeur);
     SMESH_Mesh* aMesh = reinterpret_cast<SMESH_Mesh*> (pointeur);
-    if ( MYDEBUG ) MESSAGE("SMESH_Client::SMESH_Client aMesh "<<aMesh);
+    MESSAGE("SMESH_Client::SMESH_Client aMesh "<<aMesh);
     //if(aMesh->GetMeshDS()->IsEmbeddedMode()){
     if(anIsEmbeddedMode){
       mySMESHDSMesh = aMesh->GetMeshDS();
@@ -887,18 +893,18 @@ SMESH_Client::Update(bool theIsClear)
   bool anIsModified = true;
   if(mySMESHDSMesh)
   {
-    if ( MYDEBUG ) MESSAGE("Update mySMESHDSMesh");
+    MESSAGE("Update mySMESHDSMesh");
     SMESHDS_Script* aScript = mySMESHDSMesh->GetScript();
     anIsModified = aScript->IsModified();
     aScript->SetModified(false);
   }
   else
   {
-    if ( MYDEBUG ) MESSAGE("Update CORBA");
+    MESSAGE("Update CORBA");
     SMESH::log_array_var aSeq = myMeshServer->GetLog( theIsClear );
     CORBA::Long aLength = aSeq->length();
     anIsModified = aLength > 0;
-    if ( MYDEBUG ) MESSAGE( "Update: length of the script is "<<aLength );
+    MESSAGE( "Update: length of the script is "<<aLength );
 
     if ( !anIsModified )
       return false;
@@ -1009,7 +1015,7 @@ SMESH_Client::Update(bool theIsClear)
       INFOS("Unknown exception was cought !!!");
     }
 
-    if ( MYDEBUG && mySMDSMesh )
+    if (mySMDSMesh )
     {
       MESSAGE("Update - mySMDSMesh->NbNodes() = "<<mySMDSMesh->NbNodes());
       MESSAGE("Update - mySMDSMesh->Nb0DElements() = "<<mySMDSMesh->Nb0DElements());