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_SObject.hxx
21 // Author : Sergey RUIN
27 #include <TCollection_AsciiString.hxx>
28 #include <TColStd_HSequenceOfTransient.hxx>
30 #include "SALOMEDS_SObject.hxx"
31 #include "SALOMEDS_SComponent.hxx"
32 #include "SALOMEDSImpl_SComponent.hxx"
33 #include "SALOMEDS_GenericAttribute.hxx"
34 #include "SALOMEDSImpl_GenericAttribute.hxx"
35 #include "SALOMEDS_Study.hxx"
36 #include "SALOMEDSImpl_Study.hxx"
38 #include "Utils_ORB_INIT.hxx"
39 #include "Utils_SINGLETON.hxx"
44 #include <sys/types.h>
49 #include "utilities.h"
53 SALOMEDS_SObject::SALOMEDS_SObject(SALOMEDS::SObject_ptr theSObject)
56 long pid = (long)_getpid();
58 long pid = (long)getpid();
61 long addr = theSObject->GetLocalImpl(GetHostname().c_str(), pid, _isLocal);
63 _local_impl = ((SALOMEDSImpl_SObject*)(addr));
64 _corba_impl = SALOMEDS::SObject::_duplicate(theSObject);
68 _corba_impl = SALOMEDS::SObject::_duplicate(theSObject);
74 SALOMEDS_SObject::SALOMEDS_SObject(const Handle(SALOMEDSImpl_SObject)& theSObject)
77 _corba_impl = SALOMEDS::SObject::_nil();
78 _local_impl = theSObject;
83 SALOMEDS_SObject::~SALOMEDS_SObject()
86 _corba_impl->Destroy();
90 std::string SALOMEDS_SObject::GetID()
93 if(_isLocal) aValue = _local_impl->GetID().ToCString();
94 else aValue = _corba_impl->GetID();
98 _PTR(SComponent) SALOMEDS_SObject::GetFatherComponent()
101 Handle(SALOMEDSImpl_SComponent) aSCO = Handle(SALOMEDSImpl_SComponent)::DownCast(_local_impl->GetFatherComponent());
102 return _PTR(SComponent)(new SALOMEDS_SComponent(aSCO));
104 return _PTR(SComponent)(new SALOMEDS_SComponent(_corba_impl->GetFatherComponent()));
107 _PTR(SObject) SALOMEDS_SObject::GetFather()
109 if(_isLocal) return _PTR(SObject)(new SALOMEDS_SObject(_local_impl->GetFather()));
110 return _PTR(SObject)(new SALOMEDS_SObject(_corba_impl->GetFather()));
113 bool SALOMEDS_SObject::FindAttribute(_PTR(GenericAttribute)& anAttribute, const std::string& aTypeOfAttribute)
117 Handle(SALOMEDSImpl_GenericAttribute) anAttr;
118 ret = _local_impl->FindAttribute(anAttr, (char*)aTypeOfAttribute.c_str());
119 if(ret) anAttribute = _PTR(GenericAttribute)(SALOMEDS_GenericAttribute::CreateAttribute(anAttr));
122 SALOMEDS::GenericAttribute_var anAttr;
123 ret = _corba_impl->FindAttribute(anAttr.out(), aTypeOfAttribute.c_str());
124 if(ret) anAttribute = _PTR(GenericAttribute)(SALOMEDS_GenericAttribute::CreateAttribute(anAttr));
130 bool SALOMEDS_SObject::ReferencedObject(_PTR(SObject)& theObject)
134 Handle(SALOMEDSImpl_SObject) aSO;
135 ret = _local_impl->ReferencedObject(aSO);
136 if(ret) theObject = _PTR(SObject)(new SALOMEDS_SObject(aSO));
139 SALOMEDS::SObject_var aSO;
140 ret = _corba_impl->ReferencedObject(aSO.out());
141 if(ret) theObject = _PTR(SObject)(new SALOMEDS_SObject(aSO));
148 bool SALOMEDS_SObject::FindSubObject(int theTag, _PTR(SObject)& theObject)
152 Handle(SALOMEDSImpl_SObject) aSO;
153 ret = _local_impl->FindSubObject(theTag, aSO);
154 if(ret) theObject = _PTR(SObject)(new SALOMEDS_SObject(aSO));
157 SALOMEDS::SObject_var aSO;
158 ret = _corba_impl->FindSubObject(theTag, aSO.out());
159 if(ret) theObject = _PTR(SObject)(new SALOMEDS_SObject(aSO));
165 _PTR(Study) SALOMEDS_SObject::GetStudy()
167 if(_isLocal) return _PTR(Study)(new SALOMEDS_Study(_local_impl->GetStudy()));
168 return _PTR(Study)(new SALOMEDS_Study(_corba_impl->GetStudy()));
171 std::string SALOMEDS_SObject::Name()
174 if(_isLocal) aName = _local_impl->Name().ToCString();
175 else aName = _corba_impl->Name();
180 void SALOMEDS_SObject::Name(const std::string& theName)
182 if(_isLocal) _local_impl->Name((char*)theName.c_str());
183 else _corba_impl->Name(theName.c_str());
186 vector<_PTR(GenericAttribute)> SALOMEDS_SObject::GetAllAttributes()
188 vector<_PTR(GenericAttribute)> aVector;
190 SALOMEDSClient_GenericAttribute* anAttr;
193 Handle(TColStd_HSequenceOfTransient) aSeq = _local_impl->GetAllAttributes();
194 aLength = aSeq->Length();
195 for(int i = 1; i <= aLength; i++) {
196 anAttr = SALOMEDS_GenericAttribute::CreateAttribute(Handle(SALOMEDSImpl_GenericAttribute)::DownCast(aSeq->Value(i)));
197 aVector.push_back(_PTR(GenericAttribute)(anAttr));
201 SALOMEDS::ListOfAttributes_var aSeq = _corba_impl->GetAllAttributes();
202 aLength = aSeq->length();
203 for(int i = 0; i < aLength; i++) {
204 anAttr = SALOMEDS_GenericAttribute::CreateAttribute(aSeq[i]);
205 aVector.push_back(_PTR(GenericAttribute)(anAttr));
212 std::string SALOMEDS_SObject::GetName()
215 if(_isLocal) aName = _local_impl->GetName().ToCString();
216 else aName = _corba_impl->GetName();
221 std::string SALOMEDS_SObject::GetComment()
223 std::string aComment;
224 if(_isLocal) aComment = _local_impl->GetComment().ToCString();
225 else aComment = _corba_impl->GetComment();
230 std::string SALOMEDS_SObject::GetIOR()
233 if(_isLocal) anIOR = _local_impl->GetIOR().ToCString();
234 else anIOR = _corba_impl->GetIOR();
239 int SALOMEDS_SObject::Tag()
241 if(_isLocal) return _local_impl->Tag();
242 return _corba_impl->Tag();
245 int SALOMEDS_SObject::Depth()
247 if(_isLocal) return _local_impl->Depth();
248 return _corba_impl->Depth();
251 CORBA::Object_ptr SALOMEDS_SObject::GetObject()
253 CORBA::Object_var obj;
255 std::string anIOR = GetIOR();
257 obj = _orb->string_to_object(anIOR.c_str());
261 obj = _corba_impl->GetObject();
265 return CORBA::Object::_nil();
268 SALOMEDS::SObject_ptr SALOMEDS_SObject::GetSObject()
271 if(!CORBA::is_nil(_corba_impl)) return _corba_impl;
272 SALOMEDS::SObject_var aSO = SALOMEDS_SObject_i::New(_local_impl, _orb);
278 return SALOMEDS::SObject::_nil();
282 void SALOMEDS_SObject::init_orb()
284 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
285 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
286 _orb = init(0 , 0 ) ;