1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : SALOMEDSClient_StudyManager.cxx
21 // Author : Sergey RUIN
25 #include "SALOMEDS_StudyManager.hxx"
27 #include "SALOMEDS.hxx"
28 #include "SALOMEDS_Study.hxx"
29 #include "SALOMEDS_SObject.hxx"
31 #include "SALOMEDS_Driver_i.hxx"
33 #include "SALOMEDSImpl_Study.hxx"
35 #include "Utils_ORB_INIT.hxx"
36 #include "Utils_SINGLETON.hxx"
41 #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(GetHostname().c_str(), pid, _isLocal);
62 _local_impl = ((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(GetHostname().c_str(), pid, _isLocal);
90 _local_impl = ((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 SALOMEDS::Study_var aStudy_impl = _corba_impl->Open((char*)theStudyUrl.c_str());
121 if(CORBA::is_nil(aStudy_impl)) return _PTR(Study)(aStudy);
123 aStudy = new SALOMEDS_Study(aStudy_impl.in());
125 return _PTR(Study)(aStudy);
128 void SALOMEDS_StudyManager::Close(const _PTR(Study)& theStudy)
130 //SRN: Pure CORBA close as it does more cleaning than the local one
131 SALOMEDS::Study_var aStudy = _corba_impl->GetStudyByID(theStudy->StudyId());
132 _corba_impl->Close(aStudy);
135 bool SALOMEDS_StudyManager::Save(const _PTR(Study)& theStudy, bool theMultiFile)
137 //SRN: Pure CORBA save as the save operation require CORBA in any case
138 SALOMEDS::Study_var aStudy = _corba_impl->GetStudyByID(theStudy->StudyId());
139 return _corba_impl->Save(aStudy, theMultiFile);
142 bool SALOMEDS_StudyManager::SaveASCII(const _PTR(Study)& theStudy, bool theMultiFile)
144 //SRN: Pure CORBA save as the save operation require CORBA in any case
145 SALOMEDS::Study_var aStudy = _corba_impl->GetStudyByID(theStudy->StudyId());
146 return _corba_impl->SaveASCII(aStudy, theMultiFile);
149 bool SALOMEDS_StudyManager::SaveAs(const std::string& theUrl, const _PTR(Study)& theStudy, bool theMultiFile)
151 //SRN: Pure CORBA save as the save operation require CORBA in any case
152 SALOMEDS::Study_var aStudy = _corba_impl->GetStudyByID(theStudy->StudyId());
153 return _corba_impl->SaveAs((char*)theUrl.c_str(), aStudy, theMultiFile);
156 bool SALOMEDS_StudyManager::SaveAsASCII(const std::string& theUrl, const _PTR(Study)& theStudy, bool theMultiFile)
158 //SRN: Pure CORBA save as the save operation require CORBA in any case
159 SALOMEDS::Study_var aStudy = _corba_impl->GetStudyByID(theStudy->StudyId());
160 return _corba_impl->SaveAsASCII((char*)theUrl.c_str(), aStudy, theMultiFile);
163 std::vector<std::string> SALOMEDS_StudyManager::GetOpenStudies()
165 std::vector<std::string> aVector;
169 SALOMEDS::Locker lock;
171 vector<SALOMEDSImpl_Study*> aSeq = _local_impl->GetOpenStudies();
172 aLength = aSeq.size();
173 for(i = 0; i < aLength; i++)
174 aVector.push_back(aSeq[i]->Name());
177 SALOMEDS::ListOfOpenStudies_var aSeq = _corba_impl->GetOpenStudies();
178 aLength = aSeq->length();
179 for(i = 0; i < aLength; i++)
180 aVector.push_back(aSeq[i].in());
185 _PTR(Study) SALOMEDS_StudyManager::GetStudyByName(const std::string& theStudyName)
187 SALOMEDSClient_Study* aStudy = NULL;
189 SALOMEDS::Locker lock;
191 SALOMEDSImpl_Study* aStudy_impl = _local_impl->GetStudyByName(theStudyName);
192 if(!aStudy_impl) return _PTR(Study)(aStudy);
193 aStudy = new SALOMEDS_Study(aStudy_impl);
196 SALOMEDS::Study_var aStudy_impl = _corba_impl->GetStudyByName((char*)theStudyName.c_str());
197 if(CORBA::is_nil(aStudy_impl)) return _PTR(Study)(aStudy);
198 aStudy = new SALOMEDS_Study(aStudy_impl);
200 return _PTR(Study)(aStudy);
203 _PTR(Study) SALOMEDS_StudyManager::GetStudyByID(int theStudyID)
205 SALOMEDSClient_Study* aStudy = NULL;
207 SALOMEDS::Locker lock;
209 SALOMEDSImpl_Study* aStudy_impl = _local_impl->GetStudyByID(theStudyID);
210 if(!aStudy_impl) return _PTR(Study)(aStudy);
211 aStudy = new SALOMEDS_Study(aStudy_impl);
214 SALOMEDS::Study_var aStudy_impl = _corba_impl->GetStudyByID(theStudyID);
215 if(CORBA::is_nil(aStudy_impl)) return _PTR(Study)(aStudy);
216 aStudy = new SALOMEDS_Study(aStudy_impl);
218 return _PTR(Study)(aStudy);
221 bool SALOMEDS_StudyManager::CanCopy(const _PTR(SObject)& theSO)
223 SALOMEDS_SObject* aSO = dynamic_cast<SALOMEDS_SObject*>(theSO.get());
227 SALOMEDS::Locker lock;
229 SALOMEDSImpl_SObject aSO_impl = *(aSO->GetLocalImpl());
230 SALOMEDS_Driver_i* aDriver = GetDriver(aSO_impl, _orb);
231 ret = _local_impl->CanCopy(aSO_impl, aDriver);
235 ret = _corba_impl->CanCopy(aSO->GetCORBAImpl());
241 bool SALOMEDS_StudyManager::Copy(const _PTR(SObject)& theSO)
243 SALOMEDS_SObject* aSO = dynamic_cast<SALOMEDS_SObject*>(theSO.get());
246 SALOMEDS::Locker lock;
248 SALOMEDSImpl_SObject aSO_impl = *(aSO->GetLocalImpl());
249 SALOMEDS_Driver_i* aDriver = GetDriver(aSO_impl, _orb);
250 ret = _local_impl->Copy(aSO_impl, aDriver);
254 ret = _corba_impl->Copy(aSO->GetCORBAImpl());
259 bool SALOMEDS_StudyManager::CanPaste(const _PTR(SObject)& theSO)
261 SALOMEDS_SObject* aSO = dynamic_cast<SALOMEDS_SObject*>(theSO.get());
265 SALOMEDS::Locker lock;
267 SALOMEDSImpl_SObject aSO_impl = *(aSO->GetLocalImpl());
268 SALOMEDS_Driver_i* aDriver = GetDriver(aSO_impl, _orb);
269 ret = _local_impl->CanPaste(aSO_impl, aDriver);
273 ret = _corba_impl->CanPaste(aSO->GetCORBAImpl());
279 _PTR(SObject) SALOMEDS_StudyManager::Paste(const _PTR(SObject)& theSO)
281 SALOMEDS_SObject* aSO = dynamic_cast<SALOMEDS_SObject*>(theSO.get());
282 SALOMEDSClient_SObject* aResult = NULL;
285 SALOMEDS::Locker lock;
287 SALOMEDSImpl_SObject aSO_impl = *(aSO->GetLocalImpl());
288 SALOMEDS_Driver_i* aDriver = GetDriver(aSO_impl, _orb);
289 SALOMEDSImpl_SObject aNewSO = _local_impl->Paste(aSO_impl, aDriver);
291 if(aNewSO.IsNull()) return _PTR(SObject)(aResult);
292 aResult = new SALOMEDS_SObject(aNewSO);
295 SALOMEDS::SObject_ptr aNewSO = _corba_impl->Paste(aSO->GetCORBAImpl());
296 if(CORBA::is_nil(aNewSO)) return _PTR(SObject)(aResult);
297 aResult = new SALOMEDS_SObject(aNewSO);
300 return _PTR(SObject)(aResult);
304 void SALOMEDS_StudyManager::init_orb()
306 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance();
307 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
311 SALOMEDS_Driver_i* GetDriver(const SALOMEDSImpl_SObject& theObject, CORBA::ORB_ptr orb)
313 SALOMEDS_Driver_i* driver = NULL;
315 SALOMEDSImpl_SComponent aSCO = theObject.GetFatherComponent();
317 string IOREngine = aSCO.GetIOR();
318 if(!IOREngine.empty()) {
319 CORBA::Object_var obj = orb->string_to_object(IOREngine.c_str());
320 SALOMEDS::Driver_var Engine = SALOMEDS::Driver::_narrow(obj) ;
321 driver = new SALOMEDS_Driver_i(Engine, orb);