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/ or email : webmaster.salome@opencascade.com
20 // File : SALOMEDS_SObject_i.cxx
21 // Author : Sergey RUIN
26 #include "utilities.h"
27 #include "SALOMEDS_SObject_i.hxx"
28 #include "SALOMEDS_SComponent_i.hxx"
29 #include "SALOMEDS_GenericAttribute_i.hxx"
30 #include "SALOMEDS_StudyManager_i.hxx"
31 #include "SALOMEDS.hxx"
32 #include "SALOMEDSImpl_GenericAttribute.hxx"
33 #include "SALOMEDSImpl_SComponent.hxx"
34 #include "SALOMEDSImpl_Study.hxx"
35 #include "SALOMEDSImpl_AttributeIOR.hxx"
42 #include <sys/types.h>
50 SALOMEDS::SObject_ptr SALOMEDS_SObject_i::New(const SALOMEDSImpl_SObject& theImpl, CORBA::ORB_ptr theORB)
52 SALOMEDS_SObject_i* so_servant = new SALOMEDS_SObject_i(theImpl, theORB);
53 SALOMEDS::SObject_var so = SALOMEDS::SObject::_narrow(so_servant->_this());
59 //============================================================================
60 /*! Function : constructor
63 //============================================================================
64 SALOMEDS_SObject_i::SALOMEDS_SObject_i(const SALOMEDSImpl_SObject& impl, CORBA::ORB_ptr orb)
67 if(impl.IsComponent()) {
68 SALOMEDSImpl_SComponent sco = impl;
69 _impl = sco.GetPersistentCopy();
72 _impl = impl.GetPersistentCopy();
75 _orb = CORBA::ORB::_duplicate(orb);
76 //SALOME::GenericObj_i::myPOA = SALOMEDS_StudyManager_i::GetPOA(GetStudy());
80 //============================================================================
81 /*! Function : destructor
84 //============================================================================
85 SALOMEDS_SObject_i::~SALOMEDS_SObject_i()
87 if(_impl) delete _impl;
91 //============================================================================
95 //============================================================================
96 char* SALOMEDS_SObject_i::GetID()
98 SALOMEDS::Locker lock;
99 return CORBA::string_dup(_impl->GetID().c_str());
102 //============================================================================
103 /*! Function : GetFatherComponent
106 //============================================================================
107 SALOMEDS::SComponent_ptr SALOMEDS_SObject_i::GetFatherComponent()
109 SALOMEDS::Locker lock;
110 SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (_impl->GetFatherComponent(), _orb);
114 //============================================================================
115 /*! Function : GetFather
118 //============================================================================
119 SALOMEDS::SObject_ptr SALOMEDS_SObject_i::GetFather()
121 SALOMEDS::Locker lock;
122 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (_impl->GetFather(), _orb);
126 //============================================================================
130 //============================================================================
131 SALOMEDS::Study_ptr SALOMEDS_SObject_i::GetStudy()
133 SALOMEDS::Locker lock;
134 SALOMEDSImpl_Study* aStudy = _impl->GetStudy();
136 MESSAGE("Problem GetStudy");
137 return SALOMEDS::Study::_nil();
140 string IOR = aStudy->GetTransientReference();
141 CORBA::Object_var obj = _orb->string_to_object(IOR.c_str());
142 SALOMEDS::Study_var Study = SALOMEDS::Study::_narrow(obj) ;
143 ASSERT(!CORBA::is_nil(Study));
144 return SALOMEDS::Study::_duplicate(Study);
147 //============================================================================
148 /*! Function : FindAttribute
149 * Purpose : Find attribute of given type on this SObject
151 //============================================================================
152 CORBA::Boolean SALOMEDS_SObject_i::FindAttribute (SALOMEDS::GenericAttribute_out anAttribute,
153 const char* aTypeOfAttribute)
155 SALOMEDS::Locker lock;
156 DF_Attribute* anAttr = NULL;
157 if(_impl->FindAttribute(anAttr, (char*)aTypeOfAttribute)) {
158 anAttribute = SALOMEDS::GenericAttribute::_duplicate(SALOMEDS_GenericAttribute_i::CreateAttribute(anAttr, _orb));
165 //============================================================================
166 /*! Function : GetAllAttributes
167 * Purpose : Returns list of all attributes for this sobject
169 //============================================================================
171 SALOMEDS::ListOfAttributes* SALOMEDS_SObject_i::GetAllAttributes()
173 SALOMEDS::Locker lock;
174 vector<DF_Attribute*> aSeq = _impl->GetAllAttributes();
175 SALOMEDS::ListOfAttributes_var SeqOfAttr = new SALOMEDS::ListOfAttributes;
176 int length = aSeq.size();
178 SeqOfAttr->length(length);
181 for(int i = 0; i < length; i++) {
182 SALOMEDSImpl_GenericAttribute* anAttr = dynamic_cast<SALOMEDSImpl_GenericAttribute*>(aSeq[i]);
183 SALOMEDS::GenericAttribute_var anAttribute;
184 anAttribute = SALOMEDS::GenericAttribute::_duplicate(SALOMEDS_GenericAttribute_i::CreateAttribute(anAttr, _orb));
185 if (!CORBA::is_nil(anAttribute)) {
186 SeqOfAttr[i] = anAttribute;
190 return SeqOfAttr._retn();
194 //============================================================================
195 /*! Function : ReferencedObject
198 //============================================================================
199 CORBA::Boolean SALOMEDS_SObject_i::ReferencedObject(SALOMEDS::SObject_out obj)
201 SALOMEDS::Locker lock;
202 SALOMEDSImpl_SObject aRefObj;
203 if(!_impl->ReferencedObject(aRefObj)) return false;
205 obj = SALOMEDS_SObject_i::New (aRefObj, _orb);
209 //============================================================================
210 /*! Function : FindSubObject
213 //============================================================================
214 CORBA::Boolean SALOMEDS_SObject_i::FindSubObject(CORBA::Long atag, SALOMEDS::SObject_out obj)
216 SALOMEDS::Locker lock;
217 SALOMEDSImpl_SObject aSubObj;
218 if(!_impl->FindSubObject(atag, aSubObj)) return false;
220 obj = SALOMEDS_SObject_i::New (aSubObj, _orb);
225 //============================================================================
227 * Purpose : gets a name
229 //============================================================================
230 char* SALOMEDS_SObject_i::Name()
232 SALOMEDS::Locker lock;
233 return CORBA::string_dup(_impl->Name().c_str());
236 //============================================================================
238 * Purpose : sets a name
240 //============================================================================
241 void SALOMEDS_SObject_i::Name(const char* name)
243 SALOMEDS::Locker lock;
244 string aName((char*)name);
248 //============================================================================
252 //============================================================================
253 CORBA::Short SALOMEDS_SObject_i::Tag()
255 SALOMEDS::Locker lock;
259 //============================================================================
263 //============================================================================
264 CORBA::Short SALOMEDS_SObject_i::Depth()
266 SALOMEDS::Locker lock;
267 return _impl->Depth();
270 //============================================================================
271 /*! Function : GetObject
274 //============================================================================
275 CORBA::Object_ptr SALOMEDS_SObject_i::GetObject()
277 SALOMEDS::Locker lock;
278 CORBA::Object_ptr obj = CORBA::Object::_nil();
280 string IOR = _impl->GetIOR();
281 char* c_ior = CORBA::string_dup(IOR.c_str());
282 obj = _orb->string_to_object(c_ior);
283 CORBA::string_free(c_ior);
288 //============================================================================
289 /*! Function : GetName
292 //============================================================================
293 char* SALOMEDS_SObject_i::GetName()
295 SALOMEDS::Locker lock;
296 CORBA::String_var aStr = CORBA::string_dup(_impl->GetName().c_str());
300 //============================================================================
301 /*! Function : GetComment
304 //============================================================================
305 char* SALOMEDS_SObject_i::GetComment()
307 SALOMEDS::Locker lock;
308 CORBA::String_var aStr = CORBA::string_dup(_impl->GetComment().c_str());
312 //============================================================================
313 /*! Function : GetIOR
316 //============================================================================
317 char* SALOMEDS_SObject_i::GetIOR()
319 SALOMEDS::Locker lock;
320 CORBA::String_var aStr = CORBA::string_dup(_impl->GetIOR().c_str());
324 //===========================================================================
326 //===========================================================================
327 CORBA::LongLong SALOMEDS_SObject_i::GetLocalImpl(const char* theHostname, CORBA::Long thePID, CORBA::Boolean& isLocal)
330 long pid = (long)_getpid();
332 long pid = (long)getpid();
334 isLocal = (strcmp(theHostname, GetHostname().c_str()) == 0 && pid == thePID)?1:0;
335 return ((CORBA::LongLong)(void*)_impl);