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/
20 // File : SALOMEDS_Study.cxx
21 // Author : Sergey RUIN
26 #include "utilities.h"
28 #include "SALOMEDS_Study.hxx"
29 #include "SALOMEDS_SComponent.hxx"
30 #include "SALOMEDSImpl_SComponent.hxx"
31 #include "SALOMEDS_SObject.hxx"
32 #include "SALOMEDSImpl_SObject.hxx"
33 #include "SALOMEDS_StudyBuilder.hxx"
34 #include "SALOMEDSImpl_StudyBuilder.hxx"
35 #include "SALOMEDS_ChildIterator.hxx"
36 #include "SALOMEDSImpl_ChildIterator.hxx"
37 #include "SALOMEDS_SComponentIterator.hxx"
38 #include "SALOMEDSImpl_SComponentIterator.hxx"
39 #include "SALOMEDS_AttributeStudyProperties.hxx"
40 #include "SALOMEDSImpl_AttributeStudyProperties.hxx"
41 #include "SALOMEDS_UseCaseBuilder.hxx"
42 #include "SALOMEDSImpl_UseCaseBuilder.hxx"
44 #include "SALOMEDS_Driver_i.hxx"
45 #include "SALOMEDS_Study_i.hxx"
47 #include <TCollection_AsciiString.hxx>
48 #include <TColStd_HSequenceOfAsciiString.hxx>
49 #include <TColStd_HSequenceOfTransient.hxx>
51 #include "Utils_ORB_INIT.hxx"
52 #include "Utils_SINGLETON.hxx"
57 #include <sys/types.h>
65 SALOMEDS_Study::SALOMEDS_Study(const Handle(SALOMEDSImpl_Study)& theStudy)
68 _local_impl = theStudy;
69 _corba_impl = SALOMEDS::Study::_nil();
73 SALOMEDS_Study::SALOMEDS_Study(SALOMEDS::Study_ptr theStudy)
76 long pid = (long)_getpid();
78 long pid = (long)getpid();
81 long addr = theStudy->GetLocalImpl(GetHostname().c_str(), pid, _isLocal);
83 _local_impl = ((SALOMEDSImpl_Study*)(addr));
84 _corba_impl = SALOMEDS::Study::_duplicate(theStudy);
88 _corba_impl = SALOMEDS::Study::_duplicate(theStudy);
94 SALOMEDS_Study::~SALOMEDS_Study()
98 std::string SALOMEDS_Study::GetPersistentReference()
101 if(_isLocal) aRef = _local_impl->GetPersistentReference().ToCString();
102 else aRef = _corba_impl->GetPersistentReference();
106 std::string SALOMEDS_Study::GetTransientReference()
109 if(_isLocal) aRef = _local_impl->GetTransientReference().ToCString();
110 else aRef = _corba_impl->GetTransientReference();
114 bool SALOMEDS_Study::IsEmpty()
117 if(_isLocal) ret = _local_impl->IsEmpty();
118 else ret = _corba_impl->IsEmpty();
122 _PTR(SComponent) SALOMEDS_Study::FindComponent (const std::string& aComponentName)
124 SALOMEDSClient_SComponent* aSCO = NULL;
126 Handle(SALOMEDSImpl_SComponent) aSCO_impl =_local_impl->FindComponent((char*)aComponentName.c_str());
127 if(aSCO_impl.IsNull()) return _PTR(SComponent)(aSCO);
128 aSCO = new SALOMEDS_SComponent(aSCO_impl);
131 SALOMEDS::SComponent_var aSCO_impl = _corba_impl->FindComponent((char*)aComponentName.c_str());
132 if(CORBA::is_nil(aSCO_impl)) return _PTR(SComponent)(aSCO);
133 aSCO = new SALOMEDS_SComponent(aSCO_impl);
135 return _PTR(SComponent)(aSCO);
138 _PTR(SComponent) SALOMEDS_Study::FindComponentID(const std::string& aComponentID)
140 SALOMEDSClient_SComponent* aSCO = NULL;
142 Handle(SALOMEDSImpl_SComponent) aSCO_impl =_local_impl->FindComponentID((char*)aComponentID.c_str());
143 if(aSCO_impl.IsNull()) return _PTR(SComponent)(aSCO);
144 aSCO = new SALOMEDS_SComponent(aSCO_impl);
147 SALOMEDS::SComponent_var aSCO_impl = _corba_impl->FindComponentID((char*)aComponentID.c_str());
148 if(CORBA::is_nil(aSCO_impl)) return _PTR(SComponent)(aSCO);
149 aSCO = new SALOMEDS_SComponent(aSCO_impl);
151 return _PTR(SComponent)(aSCO);
155 _PTR(SObject) SALOMEDS_Study::FindObject(const std::string& anObjectName)
157 SALOMEDSClient_SObject* aSO = NULL;
160 Handle(SALOMEDSImpl_SObject) aSO_impl = _local_impl->FindObject((char*)anObjectName.c_str());
161 if(aSO_impl.IsNull()) return _PTR(SObject)(aSO);
162 Handle(SALOMEDSImpl_SComponent) aSCO_impl = Handle(SALOMEDSImpl_SComponent)::DownCast(aSO_impl);
163 if(!aSCO_impl.IsNull()) return _PTR(SObject)(new SALOMEDS_SComponent(aSCO_impl));
164 aSO = new SALOMEDS_SObject(aSO_impl);
167 SALOMEDS::SObject_var aSO_impl = _corba_impl->FindObject((char*)anObjectName.c_str());
168 if(CORBA::is_nil(aSO_impl)) return _PTR(SObject)(aSO);
169 SALOMEDS::SComponent_var aSCO_impl = SALOMEDS::SComponent::_narrow(aSO_impl);
170 if(!CORBA::is_nil(aSCO_impl)) return _PTR(SObject)(new SALOMEDS_SComponent(aSCO_impl));
171 aSO = new SALOMEDS_SObject(aSO_impl);
174 return _PTR(SObject)(aSO);
177 std::vector<_PTR(SObject)> SALOMEDS_Study::FindObjectByName(const std::string& anObjectName,
178 const std::string& aComponentName)
180 std::vector<_PTR(SObject)> aVector;
184 Handle(TColStd_HSequenceOfTransient) aSeq = _local_impl->FindObjectByName((char*)anObjectName.c_str(), (char*)aComponentName.c_str());
185 aLength = aSeq->Length();
186 for(i = 1; i<= aLength; i++)
187 aVector.push_back(_PTR(SObject)(new SALOMEDS_SObject(Handle(SALOMEDSImpl_SObject)::DownCast(aSeq->Value(i)))));
190 SALOMEDS::Study::ListOfSObject_var aSeq = _corba_impl->FindObjectByName((char*)anObjectName.c_str(),
191 (char*)aComponentName.c_str());
192 aLength = aSeq->length();
193 for(i = 0; i< aLength; i++) aVector.push_back(_PTR(SObject)(new SALOMEDS_SObject(aSeq[i])));
199 _PTR(SObject) SALOMEDS_Study::FindObjectID(const std::string& anObjectID)
201 SALOMEDSClient_SObject* aSO = NULL;
203 Handle(SALOMEDSImpl_SObject) aSO_impl = _local_impl->FindObjectID((char*)anObjectID.c_str());
204 if(aSO_impl.IsNull()) return _PTR(SObject)(aSO);
205 return _PTR(SObject)(new SALOMEDS_SObject(aSO_impl));
208 SALOMEDS::SObject_var aSO_impl = _corba_impl->FindObjectID((char*)anObjectID.c_str());
209 if(CORBA::is_nil(aSO_impl)) return _PTR(SObject)(aSO);
210 return _PTR(SObject)(new SALOMEDS_SObject(aSO_impl));
212 return _PTR(SObject)(aSO);
215 _PTR(SObject) SALOMEDS_Study::CreateObjectID(const std::string& anObjectID)
217 SALOMEDSClient_SObject* aSO = NULL;
218 if(_isLocal) aSO = new SALOMEDS_SObject(_local_impl->CreateObjectID((char*)anObjectID.c_str()));
219 else aSO = new SALOMEDS_SObject(_corba_impl->CreateObjectID((char*)anObjectID.c_str()));
220 return _PTR(SObject)(aSO);
223 _PTR(SObject) SALOMEDS_Study::FindObjectIOR(const std::string& anObjectIOR)
225 SALOMEDSClient_SObject* aSO = NULL;
227 Handle(SALOMEDSImpl_SObject) aSO_impl = _local_impl->FindObjectIOR((char*)anObjectIOR.c_str());
228 if(aSO_impl.IsNull()) return _PTR(SObject)(aSO);
229 aSO = new SALOMEDS_SObject(aSO_impl);
232 SALOMEDS::SObject_var aSO_impl = _corba_impl->FindObjectIOR((char*)anObjectIOR.c_str());
233 if(CORBA::is_nil(aSO_impl)) return _PTR(SObject)(aSO);
234 aSO = new SALOMEDS_SObject(aSO_impl);
236 return _PTR(SObject)(aSO);
239 _PTR(SObject) SALOMEDS_Study::FindObjectByPath(const std::string& thePath)
241 SALOMEDSClient_SObject* aSO = NULL;
243 Handle(SALOMEDSImpl_SObject) aSO_impl = _local_impl->FindObjectByPath((char*)thePath.c_str());
244 if(aSO_impl.IsNull()) return _PTR(SObject)(aSO);
245 aSO = new SALOMEDS_SObject(aSO_impl);
248 SALOMEDS::SObject_var aSO_impl = _corba_impl->FindObjectByPath((char*)thePath.c_str());
249 if(CORBA::is_nil(aSO_impl)) return _PTR(SObject)(aSO);
250 aSO = new SALOMEDS_SObject(aSO_impl);
252 return _PTR(SObject)(aSO);
255 std::string SALOMEDS_Study::GetObjectPath(const _PTR(SObject)& theSO)
257 SALOMEDS_SObject* aSO = dynamic_cast<SALOMEDS_SObject*>(theSO.get());
259 if(_isLocal) aPath = _local_impl->GetObjectPath(aSO->GetLocalImpl()).ToCString();
260 else aPath = _corba_impl->GetObjectPath(aSO->GetCORBAImpl());
264 void SALOMEDS_Study::SetContext(const std::string& thePath)
266 if(_isLocal) _local_impl->SetContext((char*)thePath.c_str());
267 else _corba_impl->SetContext((char*)thePath.c_str());
270 std::string SALOMEDS_Study::GetContext()
273 if(_isLocal) aPath = _local_impl->GetContext().ToCString();
274 else aPath = _corba_impl->GetContext();
278 std::vector<std::string> SALOMEDS_Study::GetObjectNames(const std::string& theContext)
280 std::vector<std::string> aVector;
283 Handle(TColStd_HSequenceOfAsciiString) aSeq = _local_impl->GetObjectNames((char*)theContext.c_str());
284 aLength = aSeq->Length();
285 for(i = 1; i<=aLength; i++) aVector.push_back(aSeq->Value(i).ToCString());
288 SALOMEDS::ListOfStrings_var aSeq = _corba_impl->GetObjectNames((char*)theContext.c_str());
289 aLength = aSeq->length();
290 for(i = 0; i<aLength; i++) aVector.push_back(std::string((std::string)aSeq[i].in()));
295 std::vector<std::string> SALOMEDS_Study::GetDirectoryNames(const std::string& theContext)
297 std::vector<std::string> aVector;
300 Handle(TColStd_HSequenceOfAsciiString) aSeq = _local_impl->GetDirectoryNames((char*)theContext.c_str());
301 aLength = aSeq->Length();
302 for(i = 1; i<=aLength; i++) aVector.push_back(aSeq->Value(i).ToCString());
305 SALOMEDS::ListOfStrings_var aSeq = _corba_impl->GetDirectoryNames((char*)theContext.c_str());
306 aLength = aSeq->length();
307 for(i = 0; i<aLength; i++) aVector.push_back((char*)aSeq[i].in());
312 std::vector<std::string> SALOMEDS_Study::GetFileNames(const std::string& theContext)
314 std::vector<std::string> aVector;
317 Handle(TColStd_HSequenceOfAsciiString) aSeq = _local_impl->GetFileNames((char*)theContext.c_str());
318 aLength = aSeq->Length();
319 for(i = 1; i<=aLength; i++) aVector.push_back(aSeq->Value(i).ToCString());
322 SALOMEDS::ListOfStrings_var aSeq = _corba_impl->GetFileNames((char*)theContext.c_str());
323 aLength = aSeq->length();
325 for(i = 0; i<aLength; i++) aVector.push_back((char*)aSeq[i].in());
330 std::vector<std::string> SALOMEDS_Study::GetComponentNames(const std::string& theContext)
332 std::vector<std::string> aVector;
335 Handle(TColStd_HSequenceOfAsciiString) aSeq = _local_impl->GetComponentNames((char*)theContext.c_str());
336 aLength = aSeq->Length();
337 for(i = 1; i<=aLength; i++) aVector.push_back(aSeq->Value(i).ToCString());
340 SALOMEDS::ListOfStrings_var aSeq = _corba_impl->GetComponentNames((char*)theContext.c_str());
341 aLength = aSeq->length();
342 for(i = 0; i<aLength; i++) aVector.push_back((char*)aSeq[i].in());
347 _PTR(ChildIterator) SALOMEDS_Study::NewChildIterator(const _PTR(SObject)& theSO)
349 SALOMEDS_SObject* aSO = dynamic_cast<SALOMEDS_SObject*>(theSO.get());
350 SALOMEDSClient_ChildIterator* aCI = NULL;
352 Handle(SALOMEDSImpl_ChildIterator) aCIimpl = _local_impl->NewChildIterator(aSO->GetLocalImpl());
353 aCI = new SALOMEDS_ChildIterator(aCIimpl);
356 SALOMEDS::ChildIterator_var aCIimpl = _corba_impl->NewChildIterator(aSO->GetCORBAImpl());
357 aCI = new SALOMEDS_ChildIterator(aCIimpl);
360 return _PTR(ChildIterator)(aCI);
363 _PTR(SComponentIterator) SALOMEDS_Study::NewComponentIterator()
365 SALOMEDSClient_SComponentIterator* aCI = NULL;
367 SALOMEDSImpl_SComponentIterator aCIimpl = _local_impl->NewComponentIterator();
368 aCI = new SALOMEDS_SComponentIterator(aCIimpl);
371 SALOMEDS::SComponentIterator_var aCIimpl = _corba_impl->NewComponentIterator();
372 aCI = new SALOMEDS_SComponentIterator(aCIimpl);
375 return _PTR(SComponentIterator)(aCI);
378 _PTR(StudyBuilder) SALOMEDS_Study::NewBuilder()
380 SALOMEDSClient_StudyBuilder* aSB = NULL;
382 Handle(SALOMEDSImpl_StudyBuilder) aSBimpl = _local_impl->NewBuilder();
383 aSB = new SALOMEDS_StudyBuilder(aSBimpl);
386 SALOMEDS::StudyBuilder_var aSBimpl = _corba_impl->NewBuilder();
387 aSB = new SALOMEDS_StudyBuilder(aSBimpl);
390 return _PTR(StudyBuilder)(aSB);
393 std::string SALOMEDS_Study::Name()
396 if(_isLocal) aName = _local_impl->Name().ToCString();
397 else aName = _corba_impl->Name();
401 void SALOMEDS_Study::Name(const std::string& theName)
403 if(_isLocal) _local_impl->Name((char*)theName.c_str());
404 else _corba_impl->Name((char*)theName.c_str());
407 bool SALOMEDS_Study::IsSaved()
410 if(_isLocal) isSaved = _local_impl->IsSaved();
411 else isSaved = _corba_impl->IsSaved();
415 void SALOMEDS_Study::IsSaved(bool save)
417 if(_isLocal) _local_impl->IsSaved(save);
418 else _corba_impl->IsSaved(save);
421 bool SALOMEDS_Study::IsModified()
424 if(_isLocal) isModified = _local_impl->IsModified();
425 else isModified = _corba_impl->IsModified();
429 std::string SALOMEDS_Study::URL()
432 if(_isLocal) aURL = _local_impl->URL().ToCString();
433 else aURL = _corba_impl->URL();
437 void SALOMEDS_Study::URL(const std::string& url)
439 if(_isLocal) _local_impl->URL((char*)url.c_str());
440 else _corba_impl->URL((char*)url.c_str());
443 int SALOMEDS_Study::StudyId()
446 if(_isLocal) anID = _local_impl->StudyId();
447 else anID = _corba_impl->StudyId();
451 void SALOMEDS_Study::StudyId(int id)
453 if(_isLocal) _local_impl->StudyId(id);
454 else _corba_impl->StudyId(id);
457 std::vector<_PTR(SObject)> SALOMEDS_Study::FindDependances(const _PTR(SObject)& theSO)
459 std::vector<_PTR(SObject)> aVector;
460 SALOMEDS_SObject* aSO = dynamic_cast<SALOMEDS_SObject*>(theSO.get());
463 Handle(TColStd_HSequenceOfTransient) aSeq = _local_impl->FindDependances(aSO->GetLocalImpl());
464 if ( !aSeq.IsNull() )
466 aLength = aSeq->Length();
467 for(i=1; i<=aLength; i++)
468 aVector.push_back(_PTR(SObject)(
469 new SALOMEDS_SObject(Handle(SALOMEDSImpl_SObject)::DownCast(aSeq->Value(i)))));
473 SALOMEDS::Study::ListOfSObject_var aSeq = _corba_impl->FindDependances(aSO->GetCORBAImpl());
474 aLength = aSeq->length();
475 for(i=0; i<aLength; i++) aVector.push_back(_PTR(SObject)(new SALOMEDS_SObject(aSeq[i])));
480 _PTR(AttributeStudyProperties) SALOMEDS_Study::GetProperties()
482 SALOMEDSClient_AttributeStudyProperties* aProp;
483 if(_isLocal) aProp = new SALOMEDS_AttributeStudyProperties(_local_impl->GetProperties());
484 else aProp = new SALOMEDS_AttributeStudyProperties(_corba_impl->GetProperties());
485 return _PTR(AttributeStudyProperties)(aProp);
488 std::string SALOMEDS_Study::GetLastModificationDate()
491 if(_isLocal) aDate = _local_impl->GetLastModificationDate().ToCString();
492 else aDate = _corba_impl->GetLastModificationDate();
496 std::vector<std::string> SALOMEDS_Study::GetModificationsDate()
498 std::vector<std::string> aVector;
501 Handle(TColStd_HSequenceOfAsciiString) aSeq = _local_impl->GetModificationsDate();
502 aLength = aSeq->Length();
503 for(i=1; i<=aLength; i++) aVector.push_back(aSeq->Value(i).ToCString());
506 SALOMEDS::ListOfDates_var aSeq = _corba_impl->GetModificationsDate();
507 aLength = aSeq->length();
508 for(i=0; i<aLength; i++) aVector.push_back((char*)aSeq[i].in());
513 _PTR(UseCaseBuilder) SALOMEDS_Study::GetUseCaseBuilder()
515 SALOMEDSClient_UseCaseBuilder* aUB = NULL;
517 Handle(SALOMEDSImpl_UseCaseBuilder) aUBimpl = _local_impl->GetUseCaseBuilder();
518 aUB = new SALOMEDS_UseCaseBuilder(aUBimpl);
521 SALOMEDS::UseCaseBuilder_var aUBimpl = _corba_impl->GetUseCaseBuilder();
522 aUB = new SALOMEDS_UseCaseBuilder(aUBimpl);
525 return _PTR(UseCaseBuilder)(aUB);
528 void SALOMEDS_Study::Close()
530 if(_isLocal) _local_impl->Close();
531 else _corba_impl->Close();
534 void SALOMEDS_Study::EnableUseCaseAutoFilling(bool isEnabled)
536 if(_isLocal) _local_impl->EnableUseCaseAutoFilling(isEnabled);
537 else _corba_impl->EnableUseCaseAutoFilling(isEnabled);
540 bool SALOMEDS_Study::DumpStudy(const std::string& thePath, const std::string& theBaseName, bool isPublished)
544 SALOMEDS_DriverFactory_i* aFactory = new SALOMEDS_DriverFactory_i(_orb);
545 ret = _local_impl->DumpStudy((char*)thePath.c_str(), (char*)theBaseName.c_str(), isPublished, aFactory);
548 else ret = _corba_impl->DumpStudy((char*)thePath.c_str(), (char*)theBaseName.c_str(), isPublished);
552 std::string SALOMEDS_Study::ConvertObjectToIOR(CORBA::Object_ptr theObject)
554 return _orb->object_to_string(theObject);
557 CORBA::Object_ptr SALOMEDS_Study::ConvertIORToObject(const std::string& theIOR)
559 return _orb->string_to_object(theIOR.c_str());
562 void SALOMEDS_Study::init_orb()
564 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
565 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
566 _orb = init(0 , 0 ) ;
569 SALOMEDS::Study_ptr SALOMEDS_Study::GetStudy()
572 if(!CORBA::is_nil(_corba_impl)) return _corba_impl;
573 std::string anIOR = _local_impl->GetTransientReference().ToCString();
574 SALOMEDS::Study_var aStudy;
575 if(!_local_impl->IsError() && anIOR != "") {
576 aStudy = SALOMEDS::Study::_narrow(_orb->string_to_object(anIOR.c_str()));
579 SALOMEDS_Study_i *aStudy_servant = new SALOMEDS_Study_i(_local_impl, _orb);
580 aStudy = aStudy_servant->_this();
581 _local_impl->SetTransientReference(_orb->object_to_string(aStudy));
583 return aStudy._retn();
589 return SALOMEDS::Study::_nil();