1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : SALOMEDSClient_StudyManager.cxx
24 // Author : Sergey RUIN
27 #include "SALOMEDS_StudyManager.hxx"
29 #include "SALOMEDS.hxx"
30 #include "SALOMEDS_Study.hxx"
31 #include "SALOMEDS_SObject.hxx"
32 #include "SALOMEDS_Driver_i.hxx"
34 #include "SALOMEDSImpl_Study.hxx"
36 #include "Utils_ORB_INIT.hxx"
37 #include "Utils_SINGLETON.hxx"
38 #include "utilities.h"
40 #include "Basics_Utils.hxx"
45 #include <sys/types.h>
49 SALOMEDS_Driver_i* GetDriver(const SALOMEDSImpl_SObject& theObject, CORBA::ORB_ptr orb);
51 SALOMEDS_StudyManager::SALOMEDS_StudyManager(SALOMEDS::StudyManager_ptr theManager)
55 long pid = (long)_getpid();
57 long pid = (long)getpid();
60 CORBA::LongLong addr = theManager->GetLocalImpl(Kernel_Utils::GetHostname().c_str(), pid, _isLocal);
62 _local_impl = reinterpret_cast<SALOMEDSImpl_StudyManager*>(addr);
63 _corba_impl = SALOMEDS::StudyManager::_duplicate(theManager);
67 _corba_impl = SALOMEDS::StudyManager::_duplicate(theManager);
73 SALOMEDS_StudyManager::SALOMEDS_StudyManager()
77 SALOME_NamingService namingService(_orb);
78 CORBA::Object_var obj = namingService.Resolve( "/myStudyManager" );
79 SALOMEDS::StudyManager_var theManager = SALOMEDS::StudyManager::_narrow( obj );
80 ASSERT( !CORBA::is_nil(theManager) );
83 long pid = (long)_getpid();
85 long pid = (long)getpid();
88 CORBA::LongLong addr = theManager->GetLocalImpl(Kernel_Utils::GetHostname().c_str(), pid, _isLocal);
90 _local_impl = reinterpret_cast<SALOMEDSImpl_StudyManager*>(addr);
91 _corba_impl = SALOMEDS::StudyManager::_duplicate(theManager);
95 _corba_impl = SALOMEDS::StudyManager::_duplicate(theManager);
99 SALOMEDS_StudyManager::~SALOMEDS_StudyManager()
103 _PTR(Study) SALOMEDS_StudyManager::NewStudy(const std::string& study_name)
105 //SRN: Pure CORBA NewStudy as it does more initialization than the local one
106 SALOMEDSClient_Study* aStudy = NULL;
108 SALOMEDS::Study_var aStudy_impl = _corba_impl->NewStudy((char*)study_name.c_str());
109 if(CORBA::is_nil(aStudy_impl)) return _PTR(Study)(aStudy);
110 aStudy = new SALOMEDS_Study(aStudy_impl);
112 return _PTR(Study)(aStudy);
115 _PTR(Study) SALOMEDS_StudyManager::Open(const std::string& theStudyUrl)
117 //SRN: Pure CORBA Open as it does more initialization than the local one
118 SALOMEDSClient_Study* aStudy = NULL;
120 std::wstring wtheStudyUrl = std::wstring(theStudyUrl.begin(), theStudyUrl.end());
121 SALOMEDS::Study_var aStudy_impl = _corba_impl->Open((wchar_t*)theStudyUrl.c_str());
122 if(CORBA::is_nil(aStudy_impl)) return _PTR(Study)(aStudy);
124 aStudy = new SALOMEDS_Study(aStudy_impl.in());
126 return _PTR(Study)(aStudy);
129 void SALOMEDS_StudyManager::Close(const _PTR(Study)& theStudy)
131 //SRN: Pure CORBA close as it does more cleaning than the local one
132 SALOMEDS::Study_var aStudy = _corba_impl->GetStudyByID(theStudy->StudyId());
133 _corba_impl->Close(aStudy);
136 bool SALOMEDS_StudyManager::Save(const _PTR(Study)& theStudy, bool theMultiFile)
138 //SRN: Pure CORBA save as the save operation require CORBA in any case
139 SALOMEDS::Study_var aStudy = _corba_impl->GetStudyByID(theStudy->StudyId());
140 return _corba_impl->Save(aStudy, theMultiFile);
143 bool SALOMEDS_StudyManager::SaveASCII(const _PTR(Study)& theStudy, bool theMultiFile)
145 //SRN: Pure CORBA save as the save operation require CORBA in any case
146 SALOMEDS::Study_var aStudy = _corba_impl->GetStudyByID(theStudy->StudyId());
147 return _corba_impl->SaveASCII(aStudy, theMultiFile);
150 bool SALOMEDS_StudyManager::SaveAs(const std::string& theUrl, const _PTR(Study)& theStudy, bool theMultiFile)
152 //SRN: Pure CORBA save as the save operation require CORBA in any case
153 SALOMEDS::Study_var aStudy = _corba_impl->GetStudyByID(theStudy->StudyId());
154 return _corba_impl->SaveAs((char*)theUrl.c_str(), aStudy, theMultiFile);
157 bool SALOMEDS_StudyManager::SaveAsASCII(const std::string& theUrl, const _PTR(Study)& theStudy, bool theMultiFile)
159 //SRN: Pure CORBA save as the save operation require CORBA in any case
160 SALOMEDS::Study_var aStudy = _corba_impl->GetStudyByID(theStudy->StudyId());
161 return _corba_impl->SaveAsASCII((char*)theUrl.c_str(), aStudy, theMultiFile);
164 std::vector<std::string> SALOMEDS_StudyManager::GetOpenStudies()
166 std::vector<std::string> aVector;
170 SALOMEDS::Locker lock;
172 std::vector<SALOMEDSImpl_Study*> aSeq = _local_impl->GetOpenStudies();
173 aLength = aSeq.size();
174 for(i = 0; i < aLength; i++)
175 aVector.push_back(aSeq[i]->Name());
178 SALOMEDS::ListOfOpenStudies_var aSeq = _corba_impl->GetOpenStudies();
179 aLength = aSeq->length();
180 for(i = 0; i < aLength; i++)
181 aVector.push_back(aSeq[i].in());
186 _PTR(Study) SALOMEDS_StudyManager::GetStudyByName(const std::string& theStudyName)
188 SALOMEDSClient_Study* aStudy = NULL;
190 SALOMEDS::Locker lock;
192 SALOMEDSImpl_Study* aStudy_impl = _local_impl->GetStudyByName(theStudyName);
193 if(!aStudy_impl) return _PTR(Study)(aStudy);
194 aStudy = new SALOMEDS_Study(aStudy_impl);
197 SALOMEDS::Study_var aStudy_impl = _corba_impl->GetStudyByName((char*)theStudyName.c_str());
198 if(CORBA::is_nil(aStudy_impl)) return _PTR(Study)(aStudy);
199 aStudy = new SALOMEDS_Study(aStudy_impl);
201 return _PTR(Study)(aStudy);
204 _PTR(Study) SALOMEDS_StudyManager::GetStudyByID(int theStudyID)
206 SALOMEDSClient_Study* aStudy = NULL;
208 SALOMEDS::Locker lock;
210 SALOMEDSImpl_Study* aStudy_impl = _local_impl->GetStudyByID(theStudyID);
211 if(!aStudy_impl) return _PTR(Study)(aStudy);
212 aStudy = new SALOMEDS_Study(aStudy_impl);
215 SALOMEDS::Study_var aStudy_impl = _corba_impl->GetStudyByID(theStudyID);
216 if(CORBA::is_nil(aStudy_impl)) return _PTR(Study)(aStudy);
217 aStudy = new SALOMEDS_Study(aStudy_impl);
219 return _PTR(Study)(aStudy);
222 bool SALOMEDS_StudyManager::CanCopy(const _PTR(SObject)& theSO)
224 SALOMEDS_SObject* aSO = dynamic_cast<SALOMEDS_SObject*>(theSO.get());
228 SALOMEDS::Locker lock;
230 SALOMEDSImpl_SObject aSO_impl = *(aSO->GetLocalImpl());
231 SALOMEDS_Driver_i* aDriver = GetDriver(aSO_impl, _orb);
232 ret = _local_impl->CanCopy(aSO_impl, aDriver);
236 ret = _corba_impl->CanCopy(aSO->GetCORBAImpl());
242 bool SALOMEDS_StudyManager::Copy(const _PTR(SObject)& theSO)
244 SALOMEDS_SObject* aSO = dynamic_cast<SALOMEDS_SObject*>(theSO.get());
247 SALOMEDS::Locker lock;
249 SALOMEDSImpl_SObject aSO_impl = *(aSO->GetLocalImpl());
250 SALOMEDS_Driver_i* aDriver = GetDriver(aSO_impl, _orb);
251 ret = _local_impl->Copy(aSO_impl, aDriver);
255 ret = _corba_impl->Copy(aSO->GetCORBAImpl());
260 bool SALOMEDS_StudyManager::CanPaste(const _PTR(SObject)& theSO)
262 SALOMEDS_SObject* aSO = dynamic_cast<SALOMEDS_SObject*>(theSO.get());
266 SALOMEDS::Locker lock;
268 SALOMEDSImpl_SObject aSO_impl = *(aSO->GetLocalImpl());
269 SALOMEDS_Driver_i* aDriver = GetDriver(aSO_impl, _orb);
270 ret = _local_impl->CanPaste(aSO_impl, aDriver);
274 ret = _corba_impl->CanPaste(aSO->GetCORBAImpl());
280 _PTR(SObject) SALOMEDS_StudyManager::Paste(const _PTR(SObject)& theSO)
282 SALOMEDS_SObject* aSO = dynamic_cast<SALOMEDS_SObject*>(theSO.get());
283 SALOMEDSClient_SObject* aResult = NULL;
286 SALOMEDS::Locker lock;
288 SALOMEDSImpl_SObject aSO_impl = *(aSO->GetLocalImpl());
289 SALOMEDS_Driver_i* aDriver = GetDriver(aSO_impl, _orb);
290 SALOMEDSImpl_SObject aNewSO = _local_impl->Paste(aSO_impl, aDriver);
292 if(aNewSO.IsNull()) return _PTR(SObject)(aResult);
293 aResult = new SALOMEDS_SObject(aNewSO);
296 SALOMEDS::SObject_ptr aNewSO = _corba_impl->Paste(aSO->GetCORBAImpl());
297 if(CORBA::is_nil(aNewSO)) return _PTR(SObject)(aResult);
298 aResult = new SALOMEDS_SObject(aNewSO);
301 return _PTR(SObject)(aResult);
305 void SALOMEDS_StudyManager::init_orb()
307 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance();
308 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
312 SALOMEDS_Driver_i* GetDriver(const SALOMEDSImpl_SObject& theObject, CORBA::ORB_ptr orb)
314 SALOMEDS_Driver_i* driver = NULL;
316 SALOMEDSImpl_SComponent aSCO = theObject.GetFatherComponent();
318 std::string IOREngine = aSCO.GetIOR();
319 if(!IOREngine.empty()) {
320 CORBA::Object_var obj = orb->string_to_object(IOREngine.c_str());
321 Engines::EngineComponent_var Engine = Engines::EngineComponent::_narrow(obj) ;
322 driver = new SALOMEDS_Driver_i(Engine, orb);