1 // File : SALOMEDS_SObject_i.cxx
2 // Author : Sergey RUIN
8 #include "SALOMEDS_SObject_i.hxx"
9 #include "SALOMEDS_SComponent_i.hxx"
10 #include "SALOMEDS_GenericAttribute_i.hxx"
11 #include "SALOMEDS_StudyManager_i.hxx"
12 #include "SALOMEDS.hxx"
13 #include "SALOMEDSImpl_GenericAttribute.hxx"
14 #include "SALOMEDSImpl_SComponent.hxx"
15 #include "SALOMEDSImpl_Study.hxx"
16 #include "SALOMEDSImpl_AttributeIOR.hxx"
19 #include <TCollection_AsciiString.hxx>
20 #include <TCollection_ExtendedString.hxx>
21 #include <TColStd_HSequenceOfTransient.hxx>
27 #include <sys/types.h>
35 SALOMEDS::SObject_ptr SALOMEDS_SObject_i::New(const Handle(SALOMEDSImpl_SObject)& theImpl, CORBA::ORB_ptr theORB)
37 SALOMEDS_SObject_i* so_servant = new SALOMEDS_SObject_i(theImpl, theORB);
38 SALOMEDS::SObject_var so = SALOMEDS::SObject::_narrow(so_servant->_this());
44 //============================================================================
45 /*! Function : constructor
48 //============================================================================
49 SALOMEDS_SObject_i::SALOMEDS_SObject_i(const Handle(SALOMEDSImpl_SObject)& impl, CORBA::ORB_ptr orb)
52 _orb = CORBA::ORB::_duplicate(orb);
53 //SALOME::GenericObj_i::myPOA = SALOMEDS_StudyManager_i::GetPOA(GetStudy());
57 //============================================================================
58 /*! Function : destructor
61 //============================================================================
62 SALOMEDS_SObject_i::~SALOMEDS_SObject_i()
66 //============================================================================
70 //============================================================================
71 char* SALOMEDS_SObject_i::GetID()
73 SALOMEDS::Locker lock;
74 return CORBA::string_dup(_impl->GetID().ToCString());
77 //============================================================================
78 /*! Function : GetFatherComponent
81 //============================================================================
82 SALOMEDS::SComponent_ptr SALOMEDS_SObject_i::GetFatherComponent()
84 SALOMEDS::Locker lock;
85 SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (_impl->GetFatherComponent(), _orb);
89 //============================================================================
90 /*! Function : GetFather
93 //============================================================================
94 SALOMEDS::SObject_ptr SALOMEDS_SObject_i::GetFather()
96 SALOMEDS::Locker lock;
97 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (_impl->GetFather(), _orb);
101 //============================================================================
105 //============================================================================
106 SALOMEDS::Study_ptr SALOMEDS_SObject_i::GetStudy()
108 SALOMEDS::Locker lock;
109 Handle(SALOMEDSImpl_Study) aStudy = _impl->GetStudy();
110 if(aStudy.IsNull()) {
111 MESSAGE("Problem GetStudy");
112 return SALOMEDS::Study::_nil();
115 TCollection_AsciiString IOR = aStudy->GetTransientReference();
116 CORBA::Object_var obj = _orb->string_to_object(IOR.ToCString());
117 SALOMEDS::Study_var Study = SALOMEDS::Study::_narrow(obj) ;
118 ASSERT(!CORBA::is_nil(Study));
119 return SALOMEDS::Study::_duplicate(Study);
122 //============================================================================
123 /*! Function : FindAttribute
124 * Purpose : Find attribute of given type on this SObject
126 //============================================================================
127 CORBA::Boolean SALOMEDS_SObject_i::FindAttribute (SALOMEDS::GenericAttribute_out anAttribute,
128 const char* aTypeOfAttribute)
130 SALOMEDS::Locker lock;
131 Handle(TDF_Attribute) anAttr;
132 if(_impl->FindAttribute(anAttr, (char*)aTypeOfAttribute)) {
133 anAttribute = SALOMEDS::GenericAttribute::_duplicate(SALOMEDS_GenericAttribute_i::CreateAttribute(anAttr, _orb));
134 return Standard_True;
137 return Standard_False;
140 //============================================================================
141 /*! Function : GetAllAttributes
142 * Purpose : Returns list of all attributes for this sobject
144 //============================================================================
146 SALOMEDS::ListOfAttributes* SALOMEDS_SObject_i::GetAllAttributes()
148 SALOMEDS::Locker lock;
149 Handle(TColStd_HSequenceOfTransient) aSeq = _impl->GetAllAttributes();
150 SALOMEDS::ListOfAttributes_var SeqOfAttr = new SALOMEDS::ListOfAttributes;
151 Standard_Integer length = aSeq->Length();
153 SeqOfAttr->length(length);
156 for(int i = 1; i<= length; i++) {
157 Handle(SALOMEDSImpl_GenericAttribute) anAttr = Handle(SALOMEDSImpl_GenericAttribute)::DownCast(aSeq->Value(i));
158 SALOMEDS::GenericAttribute_var anAttribute;
159 anAttribute = SALOMEDS::GenericAttribute::_duplicate(SALOMEDS_GenericAttribute_i::CreateAttribute(anAttr, _orb));
160 if (!CORBA::is_nil(anAttribute)) {
161 SeqOfAttr[i - 1] = anAttribute;
165 return SeqOfAttr._retn();
169 //============================================================================
170 /*! Function : ReferencedObject
173 //============================================================================
174 CORBA::Boolean SALOMEDS_SObject_i::ReferencedObject(SALOMEDS::SObject_out obj)
176 SALOMEDS::Locker lock;
177 Handle(SALOMEDSImpl_SObject) aRefObj;
178 if(!_impl->ReferencedObject(aRefObj)) return false;
180 obj = SALOMEDS_SObject_i::New (aRefObj, _orb);
184 //============================================================================
185 /*! Function : FindSubObject
188 //============================================================================
189 CORBA::Boolean SALOMEDS_SObject_i::FindSubObject(long atag, SALOMEDS::SObject_out obj)
191 SALOMEDS::Locker lock;
192 Handle(SALOMEDSImpl_SObject) aSubObj;
193 if(!_impl->FindSubObject(atag, aSubObj)) return false;
195 obj = SALOMEDS_SObject_i::New (aSubObj, _orb);
200 //============================================================================
202 * Purpose : gets a name
204 //============================================================================
205 char* SALOMEDS_SObject_i::Name()
207 SALOMEDS::Locker lock;
208 return CORBA::string_dup(_impl->Name().ToCString());
211 //============================================================================
213 * Purpose : sets a name
215 //============================================================================
216 void SALOMEDS_SObject_i::Name(const char* name)
218 SALOMEDS::Locker lock;
219 TCollection_AsciiString aName((char*)name);
223 //============================================================================
227 //============================================================================
228 CORBA::Short SALOMEDS_SObject_i::Tag()
230 SALOMEDS::Locker lock;
234 //============================================================================
238 //============================================================================
239 CORBA::Short SALOMEDS_SObject_i::Depth()
241 SALOMEDS::Locker lock;
242 return _impl->Depth();
245 //============================================================================
246 /*! Function : GetObject
249 //============================================================================
250 CORBA::Object_ptr SALOMEDS_SObject_i::GetObject()
252 SALOMEDS::Locker lock;
253 CORBA::Object_ptr obj = CORBA::Object::_nil();
255 TCollection_AsciiString IOR = _impl->GetIOR();
256 char* c_ior = CORBA::string_dup(IOR.ToCString());
257 obj = _orb->string_to_object(c_ior);
258 CORBA::string_free(c_ior);
263 //============================================================================
264 /*! Function : GetName
267 //============================================================================
268 char* SALOMEDS_SObject_i::GetName()
270 SALOMEDS::Locker lock;
271 CORBA::String_var aStr = CORBA::string_dup(_impl->GetName().ToCString());
275 //============================================================================
276 /*! Function : GetComment
279 //============================================================================
280 char* SALOMEDS_SObject_i::GetComment()
282 SALOMEDS::Locker lock;
283 CORBA::String_var aStr = CORBA::string_dup(_impl->GetComment().ToCString());
287 //============================================================================
288 /*! Function : GetIOR
291 //============================================================================
292 char* SALOMEDS_SObject_i::GetIOR()
294 SALOMEDS::Locker lock;
295 CORBA::String_var aStr = CORBA::string_dup(_impl->GetIOR().ToCString());
299 //===========================================================================
301 //===========================================================================
302 long SALOMEDS_SObject_i::GetLocalImpl(const char* theHostname, CORBA::Long thePID, CORBA::Boolean& isLocal)
305 long pid = (long)_getpid();
307 long pid = (long)getpid();
309 isLocal = (strcmp(theHostname, GetHostname().c_str()) == 0 && pid == thePID)?1:0;
310 SALOMEDSImpl_SObject* local_impl = _impl.operator->();
311 return ((long)local_impl);