Salome HOME
Copyright update 2021
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_Client.cxx
index a0cc035ce59a4e905716b5a6cabcb7682d7da5c2..c3fccc7b0122a25dac0e5b3aff6022ea5188fca0 100644 (file)
@@ -1,46 +1,47 @@
-//  SALOME SALOMEDS : data structure of SALOME and sources of Salome data server 
+// Copyright (C) 2007-2021  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
 //
-//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
-// 
-//  This library is free software; you can redistribute it and/or 
-//  modify it under the terms of the GNU Lesser General Public 
-//  License as published by the Free Software Foundation; either 
-//  version 2.1 of the License. 
-// 
-//  This library is distributed in the hope that it will be useful, 
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
-//  Lesser General Public License for more details. 
-// 
-//  You should have received a copy of the GNU Lesser General Public 
-//  License along with this library; if not, write to the Free Software 
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
-// 
-//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
 //
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
 //
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+//  SALOME SALOMEDS : data structure of SALOME and sources of Salome data server 
 //  File   : SALOMEDS_Client.cxx
 //  Author : Yves FRICAUD
 //  Module : SALOME
 //  $Header$
-
+//
 #include <SALOMEconfig.h>
 #include CORBA_SERVER_HEADER(SALOMEDS)
-#include "SALOMEDS_StudyManager_i.hxx"
-#include "utilities.h"
 #include "SALOMEDS_AttributeName_i.hxx"
-using namespace std;
+#include "SALOME_KernelServices.hxx"
+#include "Basics_Utils.hxx"
+#include "utilities.h"
+#include "HDFOI.hxx"
 
 //============================================================================
 /*! Function :
  *  Purpose  : 
  */
 //============================================================================
-static void DumpComponent(SALOMEDS::Study_ptr Study,SALOMEDS::SObject_ptr SO,Standard_Integer offset) {
+static void DumpComponent(SALOMEDS::SObject_ptr SO, int offset) {
   SALOMEDS::SObject_var RefSO;
-  SALOMEDS::ChildIterator_var it = Study->NewChildIterator(SO);
+  SALOMEDS::ChildIterator_var it = KERNEL::getStudyServant()->NewChildIterator(SO);
   for (; it->More();it->Next()){
     SALOMEDS::SObject_var CSO= it->Value();
     SALOMEDS::GenericAttribute_var anAttr;
@@ -48,16 +49,16 @@ static void DumpComponent(SALOMEDS::Study_ptr Study,SALOMEDS::SObject_ptr SO,Sta
     {
       SALOMEDS::AttributeName_var Name = SALOMEDS::AttributeName::_narrow(anAttr);
       CORBA::String_var Val = Name->Value();
-      for (Standard_Integer i = 1; i <= offset ; i++) 
-       MESSAGE("--");
+      for (int i = 1; i <= offset ; i++) 
+        MESSAGE("--");
       MESSAGE(">"<<CSO->GetID()<<Val);
     }
     if (CSO->ReferencedObject(RefSO)) {
-      for (Standard_Integer i = 1; i <= offset ; i++) 
-       MESSAGE(" ");
+      for (int i = 1; i <= offset ; i++) 
+        MESSAGE(" ");
       MESSAGE("*Reference"<<RefSO->GetID());
     }
-    DumpComponent(Study,CSO,offset+2);
+    DumpComponent(CSO,offset+2);
   }
 }
 
@@ -66,17 +67,18 @@ static void DumpComponent(SALOMEDS::Study_ptr Study,SALOMEDS::SObject_ptr SO,Sta
  *  Purpose  : 
  */
 //============================================================================
-static void DumpStudy (SALOMEDS::Study_ptr Study) {
+static void DumpStudy() {
   MESSAGE("Explore Study and Write name of each object if it exists");
   
-  Standard_CString name;
-  SALOMEDS::SComponentIterator_var itcomp = Study->NewComponentIterator();
-  Standard_Integer offset = 1;
+  char* name;
+  SALOME_UNUSED(name); // unused in release mode
+  SALOMEDS::SComponentIterator_var itcomp = KERNEL::getStudyServant()->NewComponentIterator();
+  int offset = 1;
   for (; itcomp->More(); itcomp->Next()) {
     SALOMEDS::SComponent_var SC = itcomp->Value();
     name = SC->ComponentDataType();
     MESSAGE("-> ComponentDataType is "<<name);  
-    DumpComponent(Study,SC,offset);
+    DumpComponent(SC,offset);
   }
 }
 
@@ -85,17 +87,17 @@ static void DumpStudy (SALOMEDS::Study_ptr Study) {
  *  Purpose  : 
  */
 //============================================================================
-static void Test(SALOMEDS::StudyManager_ptr myStudyMgr )
+static void Test()
 {
   try {
-  Standard_CString name;
-  MESSAGE("Create New Study Study1");
-  SALOMEDS::Study_var myStudy = myStudyMgr->NewStudy("Study1");
+  char* name;
+  SALOME_UNUSED(name); // unused in release mode
+
+  SALOMEDS::Study_var myStudy = KERNEL::getStudyServant();
+
   MESSAGE("Create Builder ");
   SALOMEDS::StudyBuilder_var StudyBuild = myStudy->NewBuilder();
 
-
   // Create new components
   SALOMEDS::GenericAttribute_var anAttr;
   SALOMEDS::AttributeName_var Name;
@@ -186,62 +188,35 @@ static void Test(SALOMEDS::StudyManager_ptr myStudyMgr )
   Name->SetValue("mesh_cylinder_0");
   StudyBuild->CommitCommand();
 
-  MESSAGE("Test GetStudy");
-  SALOMEDS::Study_var stu = mesh_cylinder->GetStudy();
-  MESSAGE ("-> Study Name is "<<stu->Name());
-
-  DumpStudy(myStudy);
+  DumpStudy();
 
   StudyBuild->Undo();
   // Study should have no trace of object mesh_cylinder
-  DumpStudy(myStudy);
-
-  //myStudyMgr->Open ((char*)name);
-  //MESSAGE("Name " << name);
-
-  // GetOpenStudies
-  MESSAGE("GetOpenStudies list");
-  SALOMEDS::ListOfOpenStudies_var _list_open_studies =  myStudyMgr->GetOpenStudies();
-
-  for (unsigned int ind = 0; ind < _list_open_studies->length();ind++)
-    {
-      MESSAGE("Open studies list : " << _list_open_studies[ind]);  
-    }
-
-
-  // GetStudyByName
-  SALOMEDS::Study_var myStudy1 =myStudyMgr->GetStudyByName(_list_open_studies[0]);
-  MESSAGE("GetStudyByName done");
+  DumpStudy();
   
   // Save as
-  myStudyMgr->SaveAs("/home/edeville/Study1.hdf",myStudy1, false);
+  myStudy->SaveAs(Kernel_Utils::decode("/home/edeville/Study1.hdf"), false, false);
 
   // Get Persistent Reference of the study test
-  name = myStudy1->GetPersistentReference();
+  name = myStudy->GetPersistentReference();
   MESSAGE("Persitent Reference of the study " << name);
 
-  // Get Transient Reference of the study test
-  name = myStudy1->GetTransientReference();
-  MESSAGE("Transient Reference of the study " << name);
-
   // FindComponent Test
-  SALOMEDS::SComponent_var compo = myStudy1->FindComponent("GEOM");
+  SALOMEDS::SComponent_var compo = myStudy->FindComponent("GEOM");
   // Get ComponentDataType test
   MESSAGE("Find ComponentDataType of compo");
   name = compo->ComponentDataType();
-  MESSAGE("-> ComponentDataType is "<<name);  
+  MESSAGE("-> ComponentDataType is "<<name);
 
-  
   // FindComponentID Test
-  SALOMEDS::SComponent_var compo1 = myStudy1->FindComponentID("0:1:2");
+  SALOMEDS::SComponent_var compo1 = myStudy->FindComponentID("0:1:2");
   // Get ComponentDataType test
   MESSAGE("Find ComponentDataType of compo1");
   name = compo1->ComponentDataType();
-  MESSAGE("-> ComponentDataType is "<<name);  
-
+  MESSAGE("-> ComponentDataType is "<<name);
+  
   // FindObject Test
-  SALOMEDS::SObject_var objn = myStudy1->FindObject("cylinder_0");
+  SALOMEDS::SObject_var objn = myStudy->FindObject("cylinder_0");
  // Test FindAttribute function : get AttributeName attribute
   MESSAGE("Find Name in object objn");
   if (objn->FindAttribute(anAttr, "AttributeName")) {
@@ -254,7 +229,7 @@ static void Test(SALOMEDS::StudyManager_ptr myStudyMgr )
   }
 
   // FindObjectID Test
-  SALOMEDS::SObject_var obj = myStudy1->FindObjectID("0:1:2:1:1");
+  SALOMEDS::SObject_var obj = myStudy->FindObjectID("0:1:2:1:1");
  // Test FindAttribute function : get AttributeName attribute
   MESSAGE("Find Name in object obj");
   if (obj->FindAttribute(anAttr, "AttributeName")) {
@@ -265,7 +240,7 @@ static void Test(SALOMEDS::StudyManager_ptr myStudyMgr )
   else {
     MESSAGE("-> Name is not found");
   }
-  //DumpStudy(myStudy1);
+  //DumpStudy();
   }
   catch(HDFexception)
     {
@@ -280,30 +255,22 @@ int main(int argc, char** argv)
   try {
     // Initialise the ORB.
 #if OMNIORB_VERSION >= 4
-    const char* options[][2] = { { "giopMaxMsgSize", "104857600" }, { 0, 0 } };
-    CORBA::ORB_var orb = CORBA::ORB_init( argc , argv , "omniORB4", options) ;
+    CORBA::ORB_var orb = CORBA::ORB_init( argc, argv, "omniORB4" ) ;
 #else
-    CORBA::ORB_var orb = CORBA::ORB_init(argc, argv, "omniORB3");
-    omniORB::MaxMessageSize(100 * 1024 * 1024);
+    CORBA::ORB_var orb = CORBA::ORB_init( argc, argv, "omniORB3" );
 #endif
     
     // Obtain a reference to the root POA.
     CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
     PortableServer::POA_var poa = PortableServer::POA::_narrow(obj);
 
-    SALOME_NamingService * salomens = new SALOME_NamingService(orb);
-
-    MESSAGE("Find StudyManager ");
-    CORBA::Object_ptr obj2 = salomens->Resolve("myStudyManager");
-    SALOMEDS::StudyManager_var myStudyMgr = SALOMEDS::StudyManager::_narrow(obj2);
-
     // Obtain a POAManager, and tell the POA to start accepting
     // requests on its objects.
     PortableServer::POAManager_var pman = poa->the_POAManager();
     pman->activate();
 
     // Test basic services
-    Test(myStudyMgr);
+    Test();
 
     orb->run();
     orb->destroy();
@@ -314,7 +281,7 @@ int main(int argc, char** argv)
   catch(CORBA::Exception&) {
     MESSAGE( "Caught CORBA::Exception." )
   }
-  catch(omniORB::fatalException& fe) {
+  catch(omniORB::fatalException& fe) { //!< TODO: unused variable
     MESSAGE( "Caught omniORB::fatalException:" )
     MESSAGE( "  file: " << fe.file() )
     MESSAGE( "  line: " << fe.line() )