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>
33 SALOMEDS_SObject::SALOMEDS_SObject(SALOMEDS::SObject_ptr theSObject)
36 long pid = (long)_getpid();
38 long pid = (long)getpid();
41 long addr = theSObject->GetLocalImpl(GetHostname().c_str(), pid, _isLocal);
43 _local_impl = ((SALOMEDSImpl_SObject*)(addr));
44 _corba_impl = SALOMEDS::SObject::_duplicate(theSObject);
48 _corba_impl = SALOMEDS::SObject::_duplicate(theSObject);
54 SALOMEDS_SObject::SALOMEDS_SObject(const Handle(SALOMEDSImpl_SObject)& theSObject)
57 _corba_impl = SALOMEDS::SObject::_nil();
58 _local_impl = theSObject;
63 SALOMEDS_SObject::~SALOMEDS_SObject()
66 _corba_impl->Destroy();
70 std::string SALOMEDS_SObject::GetID()
73 if(_isLocal) aValue = _local_impl->GetID().ToCString();
74 else aValue = _corba_impl->GetID();
78 _PTR(SComponent) SALOMEDS_SObject::GetFatherComponent()
81 Handle(SALOMEDSImpl_SComponent) aSCO = Handle(SALOMEDSImpl_SComponent)::DownCast(_local_impl->GetFatherComponent());
82 return _PTR(SComponent)(new SALOMEDS_SComponent(aSCO));
84 return _PTR(SComponent)(new SALOMEDS_SComponent(_corba_impl->GetFatherComponent()));
87 _PTR(SObject) SALOMEDS_SObject::GetFather()
89 if(_isLocal) return _PTR(SObject)(new SALOMEDS_SObject(_local_impl->GetFather()));
90 return _PTR(SObject)(new SALOMEDS_SObject(_corba_impl->GetFather()));
93 bool SALOMEDS_SObject::FindAttribute(_PTR(GenericAttribute)& anAttribute, const std::string& aTypeOfAttribute)
97 Handle(SALOMEDSImpl_GenericAttribute) anAttr;
98 ret = _local_impl->FindAttribute(anAttr, (char*)aTypeOfAttribute.c_str());
99 if(ret) anAttribute = _PTR(GenericAttribute)(SALOMEDS_GenericAttribute::CreateAttribute(anAttr));
102 SALOMEDS::GenericAttribute_var anAttr;
103 ret = _corba_impl->FindAttribute(anAttr.out(), aTypeOfAttribute.c_str());
104 if(ret) anAttribute = _PTR(GenericAttribute)(SALOMEDS_GenericAttribute::CreateAttribute(anAttr));
110 bool SALOMEDS_SObject::ReferencedObject(_PTR(SObject)& theObject)
114 Handle(SALOMEDSImpl_SObject) aSO;
115 ret = _local_impl->ReferencedObject(aSO);
116 if(ret) theObject = _PTR(SObject)(new SALOMEDS_SObject(aSO));
119 SALOMEDS::SObject_var aSO;
120 ret = _corba_impl->ReferencedObject(aSO.out());
121 if(ret) theObject = _PTR(SObject)(new SALOMEDS_SObject(aSO));
128 bool SALOMEDS_SObject::FindSubObject(int theTag, _PTR(SObject)& theObject)
132 Handle(SALOMEDSImpl_SObject) aSO;
133 ret = _local_impl->FindSubObject(theTag, aSO);
134 if(ret) theObject = _PTR(SObject)(new SALOMEDS_SObject(aSO));
137 SALOMEDS::SObject_var aSO;
138 ret = _corba_impl->FindSubObject(theTag, aSO.out());
139 if(ret) theObject = _PTR(SObject)(new SALOMEDS_SObject(aSO));
145 _PTR(Study) SALOMEDS_SObject::GetStudy()
147 if(_isLocal) return _PTR(Study)(new SALOMEDS_Study(_local_impl->GetStudy()));
148 return _PTR(Study)(new SALOMEDS_Study(_corba_impl->GetStudy()));
151 std::string SALOMEDS_SObject::Name()
154 if(_isLocal) aName = _local_impl->Name().ToCString();
155 else aName = _corba_impl->Name();
160 void SALOMEDS_SObject::Name(const std::string& theName)
162 if(_isLocal) _local_impl->Name((char*)theName.c_str());
163 else _corba_impl->Name(theName.c_str());
166 vector<_PTR(GenericAttribute)> SALOMEDS_SObject::GetAllAttributes()
168 vector<_PTR(GenericAttribute)> aVector;
170 SALOMEDSClient_GenericAttribute* anAttr;
173 Handle(TColStd_HSequenceOfTransient) aSeq = _local_impl->GetAllAttributes();
174 aLength = aSeq->Length();
175 for(int i = 1; i <= aLength; i++) {
176 anAttr = SALOMEDS_GenericAttribute::CreateAttribute(Handle(SALOMEDSImpl_GenericAttribute)::DownCast(aSeq->Value(i)));
177 aVector.push_back(_PTR(GenericAttribute)(anAttr));
181 SALOMEDS::ListOfAttributes_var aSeq = _corba_impl->GetAllAttributes();
182 aLength = aSeq->length();
183 for(int i = 0; i < aLength; i++) {
184 anAttr = SALOMEDS_GenericAttribute::CreateAttribute(aSeq[i]);
185 aVector.push_back(_PTR(GenericAttribute)(anAttr));
192 std::string SALOMEDS_SObject::GetName()
195 if(_isLocal) aName = _local_impl->GetName().ToCString();
196 else aName = _corba_impl->GetName();
201 std::string SALOMEDS_SObject::GetComment()
203 std::string aComment;
204 if(_isLocal) aComment = _local_impl->GetComment().ToCString();
205 else aComment = _corba_impl->GetComment();
210 std::string SALOMEDS_SObject::GetIOR()
213 if(_isLocal) anIOR = _local_impl->GetIOR().ToCString();
214 else anIOR = _corba_impl->GetIOR();
219 int SALOMEDS_SObject::Tag()
221 if(_isLocal) return _local_impl->Tag();
222 return _corba_impl->Tag();
225 int SALOMEDS_SObject::Depth()
227 if(_isLocal) return _local_impl->Depth();
228 return _corba_impl->Depth();
231 CORBA::Object_ptr SALOMEDS_SObject::GetObject()
233 CORBA::Object_var obj;
235 std::string anIOR = GetIOR();
236 obj = _orb->string_to_object(anIOR.c_str());
240 obj = _corba_impl->GetObject();
244 return CORBA::Object::_nil();
247 SALOMEDS::SObject_ptr SALOMEDS_SObject::GetSObject()
250 if(!CORBA::is_nil(_corba_impl)) return _corba_impl;
251 SALOMEDS::SObject_var aSO = SALOMEDS_SObject_i::New(_local_impl, _orb);
257 return SALOMEDS::SObject::_nil();
261 void SALOMEDS_SObject::init_orb()
263 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
264 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
265 _orb = init(0 , 0 ) ;