Salome HOME
Merge branch 'rbe/evol-job-newparams'
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_StudyManager.cxx
index 9374f0bcae850ca5717f6fd93a7c8e7f9d3f4cb9..3ffa83174d3350ddf8e389b3ce6eb8e657b330cd 100644 (file)
@@ -1,18 +1,44 @@
+// Copyright (C) 2007-2014  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
+//
+// 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
+//
+
 //  File   : SALOMEDSClient_StudyManager.cxx
 //  Author : Sergey RUIN
 //  Module : SALOME
-
-
+//
 #include "SALOMEDS_StudyManager.hxx"
 
-#include "SALOMEDSImpl_Study.hxx"
+#include "SALOMEDS.hxx"
 #include "SALOMEDS_Study.hxx"
 #include "SALOMEDS_SObject.hxx"
 #include "SALOMEDS_Driver_i.hxx"
+#include "SALOMEDS_SimanStudy.hxx"
+
+#include "SALOMEDSImpl_Study.hxx"
 
 #include "Utils_ORB_INIT.hxx" 
 #include "Utils_SINGLETON.hxx" 
 
+#include "Basics_Utils.hxx"
+
 #ifdef WIN32
 #include <process.h>
 #else
 #include <unistd.h>
 #endif
 
-#include <string>
-#include <TCollection_AsciiString.hxx> 
-#include <TColStd_HSequenceOfTransient.hxx>
-
-#include "OpUtil.hxx"
-
-using namespace std; 
-
-SALOMEDS_Driver_i* GetDriver(const Handle(SALOMEDSImpl_SObject)& theObject, CORBA::ORB_ptr orb);
+SALOMEDS_Driver_i* GetDriver(const SALOMEDSImpl_SObject& theObject, CORBA::ORB_ptr orb);
 
 SALOMEDS_StudyManager::SALOMEDS_StudyManager(SALOMEDS::StudyManager_ptr theManager)
 {
@@ -39,9 +57,9 @@ SALOMEDS_StudyManager::SALOMEDS_StudyManager(SALOMEDS::StudyManager_ptr theManag
   long pid =  (long)getpid();
 #endif  
 
-  long addr = theManager->GetLocalImpl(GetHostname().c_str(), pid, _isLocal);
+  CORBA::LongLong addr = theManager->GetLocalImpl(Kernel_Utils::GetHostname().c_str(), pid, _isLocal);
   if(_isLocal) {
-    _local_impl = ((SALOMEDSImpl_StudyManager*)(addr));
+    _local_impl = reinterpret_cast<SALOMEDSImpl_StudyManager*>(addr);
     _corba_impl = SALOMEDS::StudyManager::_duplicate(theManager);
   }
   else {
@@ -67,9 +85,9 @@ SALOMEDS_StudyManager::SALOMEDS_StudyManager()
   long pid =  (long)getpid();
 #endif  
 
-  long addr = theManager->GetLocalImpl(GetHostname().c_str(), pid, _isLocal);
+  CORBA::LongLong addr = theManager->GetLocalImpl(Kernel_Utils::GetHostname().c_str(), pid, _isLocal);
   if(_isLocal) {
-    _local_impl = ((SALOMEDSImpl_StudyManager*)(addr));
+    _local_impl = reinterpret_cast<SALOMEDSImpl_StudyManager*>(addr);
     _corba_impl = SALOMEDS::StudyManager::_duplicate(theManager);
   }
   else {
@@ -88,7 +106,7 @@ _PTR(Study) SALOMEDS_StudyManager::NewStudy(const std::string& study_name)
   SALOMEDSClient_Study* aStudy = NULL;
 
   SALOMEDS::Study_var aStudy_impl = _corba_impl->NewStudy((char*)study_name.c_str());
-  if(CORBA::is_nil(aStudy_impl)) return _PTR(Study)(aStudy); 
+  if(CORBA::is_nil(aStudy_impl)) return _PTR(Study)(aStudy);
   aStudy = new SALOMEDS_Study(aStudy_impl);
 
   return _PTR(Study)(aStudy);
@@ -100,7 +118,7 @@ _PTR(Study) SALOMEDS_StudyManager::Open(const std::string& theStudyUrl)
   SALOMEDSClient_Study* aStudy = NULL;
 
   SALOMEDS::Study_var aStudy_impl = _corba_impl->Open((char*)theStudyUrl.c_str());
-  if(CORBA::is_nil(aStudy_impl)) return  _PTR(Study)(aStudy); 
+  if(CORBA::is_nil(aStudy_impl)) return  _PTR(Study)(aStudy);
     
   aStudy = new SALOMEDS_Study(aStudy_impl.in());
 
@@ -114,32 +132,32 @@ void SALOMEDS_StudyManager::Close(const _PTR(Study)& theStudy)
   _corba_impl->Close(aStudy);
 }
  
-void SALOMEDS_StudyManager::Save(const _PTR(Study)& theStudy, bool theMultiFile)
+bool SALOMEDS_StudyManager::Save(const _PTR(Study)& theStudy, bool theMultiFile)
 {
   //SRN: Pure CORBA save as the save operation require CORBA in any case 
   SALOMEDS::Study_var aStudy = _corba_impl->GetStudyByID(theStudy->StudyId());
-  _corba_impl->Save(aStudy, theMultiFile);
+  return _corba_impl->Save(aStudy, theMultiFile);
 }
  
-void SALOMEDS_StudyManager::SaveASCII(const _PTR(Study)& theStudy, bool theMultiFile)
+bool SALOMEDS_StudyManager::SaveASCII(const _PTR(Study)& theStudy, bool theMultiFile)
 {
   //SRN: Pure CORBA save as the save operation require CORBA in any case 
   SALOMEDS::Study_var aStudy = _corba_impl->GetStudyByID(theStudy->StudyId());
-  _corba_impl->SaveASCII(aStudy, theMultiFile);
+  return _corba_impl->SaveASCII(aStudy, theMultiFile);
 }
  
-void SALOMEDS_StudyManager::SaveAs(const std::string& theUrl,  const _PTR(Study)& theStudy, bool theMultiFile)
+bool SALOMEDS_StudyManager::SaveAs(const std::string& theUrl,  const _PTR(Study)& theStudy, bool theMultiFile)
 {
   //SRN: Pure CORBA save as the save operation require CORBA in any case 
   SALOMEDS::Study_var aStudy = _corba_impl->GetStudyByID(theStudy->StudyId());
-  _corba_impl->SaveAs((char*)theUrl.c_str(), aStudy, theMultiFile);
+  return _corba_impl->SaveAs((char*)theUrl.c_str(), aStudy, theMultiFile);
 }
  
-void SALOMEDS_StudyManager::SaveAsASCII(const std::string& theUrl,  const _PTR(Study)& theStudy, bool theMultiFile)
+bool SALOMEDS_StudyManager::SaveAsASCII(const std::string& theUrl,  const _PTR(Study)& theStudy, bool theMultiFile)
 {
   //SRN: Pure CORBA save as the save operation require CORBA in any case 
   SALOMEDS::Study_var aStudy = _corba_impl->GetStudyByID(theStudy->StudyId());
-  _corba_impl->SaveAsASCII((char*)theUrl.c_str(), aStudy, theMultiFile);
+  return _corba_impl->SaveAsASCII((char*)theUrl.c_str(), aStudy, theMultiFile);
 }
 
 std::vector<std::string> SALOMEDS_StudyManager::GetOpenStudies()
@@ -147,11 +165,13 @@ std::vector<std::string> SALOMEDS_StudyManager::GetOpenStudies()
   std::vector<std::string> aVector;
   int aLength, i;
 
-  if(_isLocal) {
-    Handle(TColStd_HSequenceOfTransient) aSeq = _local_impl->GetOpenStudies();
-    aLength = aSeq->Length();
-    for(i = 1; i <= aLength; i++) 
-      aVector.push_back(Handle(SALOMEDSImpl_Study)::DownCast(aSeq->Value(i))->Name().ToCString());
+  if (_isLocal) {
+    SALOMEDS::Locker lock;
+
+    std::vector<SALOMEDSImpl_Study*> aSeq = _local_impl->GetOpenStudies();
+    aLength = aSeq.size();
+    for(i = 0; i < aLength; i++) 
+      aVector.push_back(aSeq[i]->Name());
   }
   else {
     SALOMEDS::ListOfOpenStudies_var aSeq = _corba_impl->GetOpenStudies();
@@ -161,18 +181,20 @@ std::vector<std::string> SALOMEDS_StudyManager::GetOpenStudies()
   }
   return aVector;
 }
+
 _PTR(Study) SALOMEDS_StudyManager::GetStudyByName(const std::string& theStudyName) 
 {
   SALOMEDSClient_Study* aStudy = NULL;
-  if(_isLocal) {
-    Handle(SALOMEDSImpl_Study) aStudy_impl = _local_impl->GetStudyByName((char*)theStudyName.c_str());
-    if(aStudy_impl.IsNull()) return _PTR(Study)(aStudy);
+  if (_isLocal) {
+    SALOMEDS::Locker lock;
+
+    SALOMEDSImpl_Study* aStudy_impl = _local_impl->GetStudyByName(theStudyName);
+    if(!aStudy_impl) return _PTR(Study)(aStudy);
     aStudy = new SALOMEDS_Study(aStudy_impl);
   }
   else  {
     SALOMEDS::Study_var aStudy_impl = _corba_impl->GetStudyByName((char*)theStudyName.c_str());
-    if(CORBA::is_nil(aStudy_impl)) return _PTR(Study)(aStudy); 
+    if(CORBA::is_nil(aStudy_impl)) return _PTR(Study)(aStudy);
     aStudy = new SALOMEDS_Study(aStudy_impl);
   }
   return _PTR(Study)(aStudy);
@@ -181,26 +203,30 @@ _PTR(Study) SALOMEDS_StudyManager::GetStudyByName(const std::string& theStudyNam
 _PTR(Study) SALOMEDS_StudyManager::GetStudyByID(int theStudyID) 
 {
   SALOMEDSClient_Study* aStudy = NULL;
-  if(_isLocal) {
-    Handle(SALOMEDSImpl_Study) aStudy_impl = _local_impl->GetStudyByID(theStudyID);
-    if(aStudy_impl.IsNull()) return _PTR(Study)(aStudy);
+  if (_isLocal) {
+    SALOMEDS::Locker lock;
+
+    SALOMEDSImpl_Study* aStudy_impl = _local_impl->GetStudyByID(theStudyID);
+    if(!aStudy_impl) return _PTR(Study)(aStudy);
     aStudy = new SALOMEDS_Study(aStudy_impl);
   }
   else { 
     SALOMEDS::Study_var aStudy_impl = _corba_impl->GetStudyByID(theStudyID);
-    if(CORBA::is_nil(aStudy_impl)) return _PTR(Study)(aStudy); 
+    if(CORBA::is_nil(aStudy_impl)) return _PTR(Study)(aStudy);
     aStudy = new SALOMEDS_Study(aStudy_impl);
   }
-  return _PTR(Study)(aStudy); 
+  return _PTR(Study)(aStudy);
 }
+
 bool SALOMEDS_StudyManager::CanCopy(const _PTR(SObject)& theSO)
 {
   SALOMEDS_SObject* aSO = dynamic_cast<SALOMEDS_SObject*>(theSO.get());
   bool ret;
 
-  if(_isLocal) {
-    Handle(SALOMEDSImpl_SObject) aSO_impl = aSO->GetLocalImpl();
+  if (_isLocal) {
+    SALOMEDS::Locker lock;
+
+    SALOMEDSImpl_SObject aSO_impl = *(aSO->GetLocalImpl());
     SALOMEDS_Driver_i* aDriver = GetDriver(aSO_impl, _orb);
     ret = _local_impl->CanCopy(aSO_impl, aDriver);
     delete aDriver;
@@ -211,13 +237,15 @@ bool SALOMEDS_StudyManager::CanCopy(const _PTR(SObject)& theSO)
 
   return ret;
 }
+
 bool SALOMEDS_StudyManager::Copy(const _PTR(SObject)& theSO)
 {
   SALOMEDS_SObject* aSO = dynamic_cast<SALOMEDS_SObject*>(theSO.get());
   bool ret;
-  if(_isLocal) {
-    Handle(SALOMEDSImpl_SObject) aSO_impl = aSO->GetLocalImpl();
+  if (_isLocal) {
+    SALOMEDS::Locker lock;
+
+    SALOMEDSImpl_SObject aSO_impl = *(aSO->GetLocalImpl());
     SALOMEDS_Driver_i* aDriver = GetDriver(aSO_impl, _orb);
     ret = _local_impl->Copy(aSO_impl, aDriver);
     delete aDriver;
@@ -227,14 +255,16 @@ bool SALOMEDS_StudyManager::Copy(const _PTR(SObject)& theSO)
   }
   return ret;
 }
+
 bool SALOMEDS_StudyManager::CanPaste(const _PTR(SObject)& theSO)
 {
   SALOMEDS_SObject* aSO = dynamic_cast<SALOMEDS_SObject*>(theSO.get());
   bool ret;
 
-  if(_isLocal) {
-    Handle(SALOMEDSImpl_SObject) aSO_impl = aSO->GetLocalImpl();
+  if (_isLocal) {
+    SALOMEDS::Locker lock;
+
+    SALOMEDSImpl_SObject aSO_impl = *(aSO->GetLocalImpl());
     SALOMEDS_Driver_i* aDriver = GetDriver(aSO_impl, _orb);
     ret = _local_impl->CanPaste(aSO_impl, aDriver);
     delete aDriver;
@@ -245,16 +275,18 @@ bool SALOMEDS_StudyManager::CanPaste(const _PTR(SObject)& theSO)
 
   return ret;
 }
+
 _PTR(SObject) SALOMEDS_StudyManager::Paste(const _PTR(SObject)& theSO)
 {
   SALOMEDS_SObject* aSO = dynamic_cast<SALOMEDS_SObject*>(theSO.get());
   SALOMEDSClient_SObject* aResult = NULL;
 
-  if(_isLocal) {
-    Handle(SALOMEDSImpl_SObject) aSO_impl = aSO->GetLocalImpl();
+  if (_isLocal) {
+    SALOMEDS::Locker lock;
+
+    SALOMEDSImpl_SObject aSO_impl = *(aSO->GetLocalImpl());
     SALOMEDS_Driver_i* aDriver = GetDriver(aSO_impl, _orb);
-    Handle(SALOMEDSImpl_SObject) aNewSO = _local_impl->Paste(aSO_impl, aDriver);
+    SALOMEDSImpl_SObject aNewSO = _local_impl->Paste(aSO_impl, aDriver);
     delete aDriver;
     if(aNewSO.IsNull()) return _PTR(SObject)(aResult);
     aResult = new SALOMEDS_SObject(aNewSO);
@@ -271,24 +303,45 @@ _PTR(SObject) SALOMEDS_StudyManager::Paste(const _PTR(SObject)& theSO)
 
 void SALOMEDS_StudyManager::init_orb()
 {
-  ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
-  ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()); 
-  _orb = init(0 , 0 ) ;     
+  ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance();
+  ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
+  _orb = init(0 , 0 );
 }
 
-SALOMEDS_Driver_i* GetDriver(const Handle(SALOMEDSImpl_SObject)& theObject, CORBA::ORB_ptr orb)
+SALOMEDS_Driver_i* GetDriver(const SALOMEDSImpl_SObject& theObject, CORBA::ORB_ptr orb)
 {
   SALOMEDS_Driver_i* driver = NULL;
   
-  Handle(SALOMEDSImpl_SComponent) aSCO = theObject->GetFatherComponent();
+  SALOMEDSImpl_SComponent aSCO = theObject.GetFatherComponent();
   if(!aSCO.IsNull()) {
-    TCollection_AsciiString IOREngine = aSCO->GetIOR();
-    if(!IOREngine.IsEmpty()) {
-      CORBA::Object_var obj = orb->string_to_object(IOREngine.ToCString());
-      SALOMEDS::Driver_var Engine = SALOMEDS::Driver::_narrow(obj) ;
+    std::string IOREngine = aSCO.GetIOR();
+    if(!IOREngine.empty()) {
+      CORBA::Object_var obj = orb->string_to_object(IOREngine.c_str());
+      Engines::EngineComponent_var Engine = Engines::EngineComponent::_narrow(obj) ;
       driver = new SALOMEDS_Driver_i(Engine, orb);
     }
-  }  
+  }
 
   return driver;
 }
+
+_PTR(SimanStudy) SALOMEDS_StudyManager::GetSimanStudy()
+{
+  SALOMEDSClient_SimanStudy* aSiman = NULL;
+  /*if (_isLocal) {
+    SALOMEDS::Locker lock;
+
+    SALOMEDSImpl_SimanStudy* aSiman_impl = _local_impl->GetSimanStudy();
+    if(!aSiman_impl) return _PTR(SimanStudy)(aSiman);
+    aSiman = new SALOMEDS_SimanStudy(aSiman_impl);
+  }
+  else { 
+    SALOMEDS::SimanStudy_var aSiman_impl = _corba_impl->GetSimanStudy();
+    if(CORBA::is_nil(aSiman_impl)) return _PTR(SimanStudy)(aSiman);
+    aSiman = new SALOMEDS_SimanStudy(aSiman_impl);
+  }*/
+  SALOMEDS::SimanStudy_var aSiman_impl = _corba_impl->GetSimanStudy();
+  if(CORBA::is_nil(aSiman_impl)) return _PTR(SimanStudy)(aSiman);
+  aSiman = new SALOMEDS_SimanStudy(aSiman_impl);
+  return _PTR(SimanStudy)(aSiman);
+}