1 // File : SALOMEDS_SObject.hxx
2 // Author : Sergey RUIN
8 #include <TCollection_AsciiString.hxx>
9 #include <TColStd_HSequenceOfTransient.hxx>
11 #include "SALOMEDS_SObject.hxx"
12 #include "SALOMEDS_SComponent.hxx"
13 #include "SALOMEDSImpl_SComponent.hxx"
14 #include "SALOMEDS_GenericAttribute.hxx"
15 #include "SALOMEDSImpl_GenericAttribute.hxx"
16 #include "SALOMEDS_Study.hxx"
17 #include "SALOMEDSImpl_Study.hxx"
19 #include "Utils_ORB_INIT.hxx"
20 #include "Utils_SINGLETON.hxx"
25 #include <sys/types.h>
30 #include "utilities.h"
34 SALOMEDS_SObject::SALOMEDS_SObject(SALOMEDS::SObject_ptr theSObject)
37 long pid = (long)_getpid();
39 long pid = (long)getpid();
42 long addr = theSObject->GetLocalImpl(GetHostname().c_str(), pid, _isLocal);
44 _local_impl = ((SALOMEDSImpl_SObject*)(addr));
45 _corba_impl = SALOMEDS::SObject::_duplicate(theSObject);
49 _corba_impl = SALOMEDS::SObject::_duplicate(theSObject);
55 SALOMEDS_SObject::SALOMEDS_SObject(const Handle(SALOMEDSImpl_SObject)& theSObject)
58 _corba_impl = SALOMEDS::SObject::_nil();
59 _local_impl = theSObject;
64 SALOMEDS_SObject::~SALOMEDS_SObject()
67 _corba_impl->Destroy();
71 std::string SALOMEDS_SObject::GetID()
74 if(_isLocal) aValue = _local_impl->GetID().ToCString();
75 else aValue = _corba_impl->GetID();
79 _PTR(SComponent) SALOMEDS_SObject::GetFatherComponent()
82 Handle(SALOMEDSImpl_SComponent) aSCO = Handle(SALOMEDSImpl_SComponent)::DownCast(_local_impl->GetFatherComponent());
83 return _PTR(SComponent)(new SALOMEDS_SComponent(aSCO));
85 return _PTR(SComponent)(new SALOMEDS_SComponent(_corba_impl->GetFatherComponent()));
88 _PTR(SObject) SALOMEDS_SObject::GetFather()
90 if(_isLocal) return _PTR(SObject)(new SALOMEDS_SObject(_local_impl->GetFather()));
91 return _PTR(SObject)(new SALOMEDS_SObject(_corba_impl->GetFather()));
94 bool SALOMEDS_SObject::FindAttribute(_PTR(GenericAttribute)& anAttribute, const std::string& aTypeOfAttribute)
98 Handle(SALOMEDSImpl_GenericAttribute) anAttr;
99 ret = _local_impl->FindAttribute(anAttr, (char*)aTypeOfAttribute.c_str());
100 if(ret) anAttribute = _PTR(GenericAttribute)(SALOMEDS_GenericAttribute::CreateAttribute(anAttr));
103 SALOMEDS::GenericAttribute_var anAttr;
104 ret = _corba_impl->FindAttribute(anAttr.out(), aTypeOfAttribute.c_str());
105 if(ret) anAttribute = _PTR(GenericAttribute)(SALOMEDS_GenericAttribute::CreateAttribute(anAttr));
111 bool SALOMEDS_SObject::ReferencedObject(_PTR(SObject)& theObject)
115 Handle(SALOMEDSImpl_SObject) aSO;
116 ret = _local_impl->ReferencedObject(aSO);
117 if(ret) theObject = _PTR(SObject)(new SALOMEDS_SObject(aSO));
120 SALOMEDS::SObject_var aSO;
121 ret = _corba_impl->ReferencedObject(aSO.out());
122 if(ret) theObject = _PTR(SObject)(new SALOMEDS_SObject(aSO));
129 bool SALOMEDS_SObject::FindSubObject(int theTag, _PTR(SObject)& theObject)
133 Handle(SALOMEDSImpl_SObject) aSO;
134 ret = _local_impl->FindSubObject(theTag, aSO);
135 if(ret) theObject = _PTR(SObject)(new SALOMEDS_SObject(aSO));
138 SALOMEDS::SObject_var aSO;
139 ret = _corba_impl->FindSubObject(theTag, aSO.out());
140 if(ret) theObject = _PTR(SObject)(new SALOMEDS_SObject(aSO));
146 _PTR(Study) SALOMEDS_SObject::GetStudy()
148 if(_isLocal) return _PTR(Study)(new SALOMEDS_Study(_local_impl->GetStudy()));
149 return _PTR(Study)(new SALOMEDS_Study(_corba_impl->GetStudy()));
152 std::string SALOMEDS_SObject::Name()
155 if(_isLocal) aName = _local_impl->Name().ToCString();
156 else aName = _corba_impl->Name();
161 void SALOMEDS_SObject::Name(const std::string& theName)
163 if(_isLocal) _local_impl->Name((char*)theName.c_str());
164 else _corba_impl->Name(theName.c_str());
167 vector<_PTR(GenericAttribute)> SALOMEDS_SObject::GetAllAttributes()
169 vector<_PTR(GenericAttribute)> aVector;
171 SALOMEDSClient_GenericAttribute* anAttr;
174 Handle(TColStd_HSequenceOfTransient) aSeq = _local_impl->GetAllAttributes();
175 aLength = aSeq->Length();
176 for(int i = 1; i <= aLength; i++) {
177 anAttr = SALOMEDS_GenericAttribute::CreateAttribute(Handle(SALOMEDSImpl_GenericAttribute)::DownCast(aSeq->Value(i)));
178 aVector.push_back(_PTR(GenericAttribute)(anAttr));
182 SALOMEDS::ListOfAttributes_var aSeq = _corba_impl->GetAllAttributes();
183 aLength = aSeq->length();
184 for(int i = 0; i < aLength; i++) {
185 anAttr = SALOMEDS_GenericAttribute::CreateAttribute(aSeq[i]);
186 aVector.push_back(_PTR(GenericAttribute)(anAttr));
193 std::string SALOMEDS_SObject::GetName()
196 if(_isLocal) aName = _local_impl->GetName().ToCString();
197 else aName = _corba_impl->GetName();
202 std::string SALOMEDS_SObject::GetComment()
204 std::string aComment;
205 if(_isLocal) aComment = _local_impl->GetComment().ToCString();
206 else aComment = _corba_impl->GetComment();
211 std::string SALOMEDS_SObject::GetIOR()
214 if(_isLocal) anIOR = _local_impl->GetIOR().ToCString();
215 else anIOR = _corba_impl->GetIOR();
220 int SALOMEDS_SObject::Tag()
222 if(_isLocal) return _local_impl->Tag();
223 return _corba_impl->Tag();
226 int SALOMEDS_SObject::Depth()
228 if(_isLocal) return _local_impl->Depth();
229 return _corba_impl->Depth();
232 CORBA::Object_ptr SALOMEDS_SObject::GetObject()
234 CORBA::Object_var obj;
236 std::string anIOR = GetIOR();
238 obj = _orb->string_to_object(anIOR.c_str());
242 obj = _corba_impl->GetObject();
246 return CORBA::Object::_nil();
249 SALOMEDS::SObject_ptr SALOMEDS_SObject::GetSObject()
252 if(!CORBA::is_nil(_corba_impl)) return _corba_impl;
253 SALOMEDS::SObject_var aSO = SALOMEDS_SObject_i::New(_local_impl, _orb);
259 return SALOMEDS::SObject::_nil();
263 void SALOMEDS_SObject::init_orb()
265 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
266 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
267 _orb = init(0 , 0 ) ;