1 // File : SALOMEDSClient_StudyManager.cxx
2 // Author : Sergey RUIN
6 #include "SALOMEDS_StudyManager.hxx"
8 #include "SALOMEDSImpl_Study.hxx"
9 #include "SALOMEDS_Study.hxx"
10 #include "SALOMEDS_SObject.hxx"
11 #include "SALOMEDS_Driver_i.hxx"
13 #include "Utils_ORB_INIT.hxx"
14 #include "Utils_SINGLETON.hxx"
19 #include <sys/types.h>
24 #include <TCollection_AsciiString.hxx>
25 #include <TColStd_HSequenceOfTransient.hxx>
31 SALOMEDS_Driver_i* GetDriver(const Handle(SALOMEDSImpl_SObject)& theObject, CORBA::ORB_ptr orb);
33 SALOMEDS_StudyManager::SALOMEDS_StudyManager(SALOMEDS::StudyManager_ptr theManager)
37 long pid = (long)_getpid();
39 long pid = (long)getpid();
42 long addr = theManager->GetLocalImpl(GetHostname().c_str(), pid, _isLocal);
44 _local_impl = ((SALOMEDSImpl_StudyManager*)(addr));
45 _corba_impl = SALOMEDS::StudyManager::_duplicate(theManager);
49 _corba_impl = SALOMEDS::StudyManager::_duplicate(theManager);
55 SALOMEDS_StudyManager::SALOMEDS_StudyManager()
59 SALOME_NamingService namingService(_orb);
60 CORBA::Object_var obj = namingService.Resolve( "/myStudyManager" );
61 SALOMEDS::StudyManager_var theManager = SALOMEDS::StudyManager::_narrow( obj );
62 ASSERT( !CORBA::is_nil(theManager) );
65 long pid = (long)_getpid();
67 long pid = (long)getpid();
70 long addr = theManager->GetLocalImpl(GetHostname().c_str(), pid, _isLocal);
72 _local_impl = ((SALOMEDSImpl_StudyManager*)(addr));
73 _corba_impl = SALOMEDS::StudyManager::_duplicate(theManager);
77 _corba_impl = SALOMEDS::StudyManager::_duplicate(theManager);
81 SALOMEDS_StudyManager::~SALOMEDS_StudyManager()
85 _PTR(Study) SALOMEDS_StudyManager::NewStudy(const std::string& study_name)
87 SALOMEDSClient_Study* aStudy = NULL;
90 Handle(SALOMEDSImpl_Study) aStudy_impl = _local_impl->NewStudy((char*)study_name.c_str());
91 if(aStudy_impl.IsNull()) return _PTR(Study)(aStudy);
92 aStudy = new SALOMEDS_Study(aStudy_impl);
95 SALOMEDS::Study_var aStudy_impl = _corba_impl->NewStudy((char*)study_name.c_str());
96 if(CORBA::is_nil(aStudy_impl)) return _PTR(Study)(aStudy);
97 aStudy = new SALOMEDS_Study(aStudy_impl);
100 return _PTR(Study)(aStudy);
103 _PTR(Study) SALOMEDS_StudyManager::Open(const std::string& theStudyUrl)
105 SALOMEDSClient_Study* aStudy = NULL;
108 Handle(SALOMEDSImpl_Study) aStudy_impl = _local_impl->Open((char*)theStudyUrl.c_str());
109 if(aStudy_impl.IsNull()) return _PTR(Study)(aStudy);
110 aStudy = new SALOMEDS_Study(aStudy_impl);
113 SALOMEDS::Study_var aStudy_impl = _corba_impl->Open((char*)theStudyUrl.c_str());
114 if(CORBA::is_nil(aStudy_impl)) return _PTR(Study)(aStudy);
116 aStudy = new SALOMEDS_Study(aStudy_impl.in());
119 return _PTR(Study)(aStudy);
122 void SALOMEDS_StudyManager::Close(const _PTR(Study)& theStudy)
124 //SRN: Pure CORBA close as it does more cleaning then the local one
125 SALOMEDS::Study_var aStudy = _corba_impl->GetStudyByID(theStudy->StudyId());
126 _corba_impl->Close(aStudy);
129 void SALOMEDS_StudyManager::Save(const _PTR(Study)& theStudy, bool theMultiFile)
131 //SRN: Pure CORBA save as the save operation require CORBA in any case
132 SALOMEDS::Study_var aStudy = _corba_impl->GetStudyByID(theStudy->StudyId());
133 _corba_impl->Save(aStudy, theMultiFile);
136 void SALOMEDS_StudyManager::SaveASCII(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 _corba_impl->SaveASCII(aStudy, theMultiFile);
143 void SALOMEDS_StudyManager::SaveAs(const std::string& theUrl, 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 _corba_impl->SaveAs((char*)theUrl.c_str(), aStudy, theMultiFile);
150 void SALOMEDS_StudyManager::SaveAsASCII(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 _corba_impl->SaveAsASCII((char*)theUrl.c_str(), aStudy, theMultiFile);
157 std::vector<std::string> SALOMEDS_StudyManager::GetOpenStudies()
159 std::vector<std::string> aVector;
163 Handle(TColStd_HSequenceOfTransient) aSeq = _local_impl->GetOpenStudies();
164 aLength = aSeq->Length();
165 for(i = 1; i <= aLength; i++)
166 aVector.push_back(Handle(SALOMEDSImpl_Study)::DownCast(aSeq->Value(i))->Name().ToCString());
169 SALOMEDS::ListOfOpenStudies_var aSeq = _corba_impl->GetOpenStudies();
170 aLength = aSeq->length();
171 for(i = 0; i < aLength; i++)
172 aVector.push_back(aSeq[i].in());
177 _PTR(Study) SALOMEDS_StudyManager::GetStudyByName(const std::string& theStudyName)
179 SALOMEDSClient_Study* aStudy = NULL;
181 Handle(SALOMEDSImpl_Study) aStudy_impl = _local_impl->GetStudyByName((char*)theStudyName.c_str());
182 if(aStudy_impl.IsNull()) return _PTR(Study)(aStudy);
183 aStudy = new SALOMEDS_Study(aStudy_impl);
186 SALOMEDS::Study_var aStudy_impl = _corba_impl->GetStudyByName((char*)theStudyName.c_str());
187 if(CORBA::is_nil(aStudy_impl)) return _PTR(Study)(aStudy);
188 aStudy = new SALOMEDS_Study(aStudy_impl);
190 return _PTR(Study)(aStudy);
193 _PTR(Study) SALOMEDS_StudyManager::GetStudyByID(int theStudyID)
195 SALOMEDSClient_Study* aStudy = NULL;
197 Handle(SALOMEDSImpl_Study) aStudy_impl = _local_impl->GetStudyByID(theStudyID);
198 if(aStudy_impl.IsNull()) return _PTR(Study)(aStudy);
199 aStudy = new SALOMEDS_Study(aStudy_impl);
202 SALOMEDS::Study_var aStudy_impl = _corba_impl->GetStudyByID(theStudyID);
203 if(CORBA::is_nil(aStudy_impl)) return _PTR(Study)(aStudy);
204 aStudy = new SALOMEDS_Study(aStudy_impl);
206 return _PTR(Study)(aStudy);
209 bool SALOMEDS_StudyManager::CanCopy(const _PTR(SObject)& theSO)
211 SALOMEDS_SObject* aSO = dynamic_cast<SALOMEDS_SObject*>(theSO.get());
215 Handle(SALOMEDSImpl_SObject) aSO_impl = aSO->GetLocalImpl();
216 SALOMEDS_Driver_i* aDriver = GetDriver(aSO_impl, _orb);
217 ret = _local_impl->CanCopy(aSO_impl, aDriver);
221 ret = _corba_impl->CanCopy(aSO->GetCORBAImpl());
227 bool SALOMEDS_StudyManager::Copy(const _PTR(SObject)& theSO)
229 SALOMEDS_SObject* aSO = dynamic_cast<SALOMEDS_SObject*>(theSO.get());
232 Handle(SALOMEDSImpl_SObject) aSO_impl = aSO->GetLocalImpl();
233 SALOMEDS_Driver_i* aDriver = GetDriver(aSO_impl, _orb);
234 ret = _local_impl->Copy(aSO_impl, aDriver);
238 ret = _corba_impl->Copy(aSO->GetCORBAImpl());
243 bool SALOMEDS_StudyManager::CanPaste(const _PTR(SObject)& theSO)
245 SALOMEDS_SObject* aSO = dynamic_cast<SALOMEDS_SObject*>(theSO.get());
249 Handle(SALOMEDSImpl_SObject) aSO_impl = aSO->GetLocalImpl();
250 SALOMEDS_Driver_i* aDriver = GetDriver(aSO_impl, _orb);
251 ret = _local_impl->CanPaste(aSO_impl, aDriver);
255 ret = _corba_impl->CanPaste(aSO->GetCORBAImpl());
261 _PTR(SObject) SALOMEDS_StudyManager::Paste(const _PTR(SObject)& theSO)
263 SALOMEDS_SObject* aSO = dynamic_cast<SALOMEDS_SObject*>(theSO.get());
264 SALOMEDSClient_SObject* aResult = NULL;
267 Handle(SALOMEDSImpl_SObject) aSO_impl = aSO->GetLocalImpl();
268 SALOMEDS_Driver_i* aDriver = GetDriver(aSO_impl, _orb);
269 Handle(SALOMEDSImpl_SObject) aNewSO = _local_impl->Paste(aSO_impl, aDriver);
271 if(aNewSO.IsNull()) return _PTR(SObject)(aResult);
272 aResult = new SALOMEDS_SObject(aNewSO);
275 SALOMEDS::SObject_ptr aNewSO = _corba_impl->Paste(aSO->GetCORBAImpl());
276 if(CORBA::is_nil(aNewSO)) return _PTR(SObject)(aResult);
277 aResult = new SALOMEDS_SObject(aNewSO);
280 return _PTR(SObject)(aResult);
284 void SALOMEDS_StudyManager::init_orb()
286 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
287 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
288 _orb = init(0 , 0 ) ;
291 SALOMEDS_Driver_i* GetDriver(const Handle(SALOMEDSImpl_SObject)& theObject, CORBA::ORB_ptr orb)
293 SALOMEDS_Driver_i* driver = NULL;
295 Handle(SALOMEDSImpl_SComponent) aSCO = theObject->GetFatherComponent();
297 TCollection_AsciiString IOREngine = aSCO->GetIOR();
298 if(!IOREngine.IsEmpty()) {
299 CORBA::Object_var obj = orb->string_to_object(IOREngine.ToCString());
300 SALOMEDS::Driver_var Engine = SALOMEDS::Driver::_narrow(obj) ;
301 driver = new SALOMEDS_Driver_i(Engine, orb);