1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : SALOMEDS_SObject_i.cxx
23 // 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"
36 #include "Basics_Utils.hxx"
43 #include <sys/types.h>
49 SALOMEDS::SObject_ptr SALOMEDS_SObject_i::New(const SALOMEDSImpl_SObject& theImpl, CORBA::ORB_ptr theORB)
51 SALOMEDS_SObject_i* so_servant = new SALOMEDS_SObject_i(theImpl, theORB);
52 SALOMEDS::SObject_var so = SALOMEDS::SObject::_narrow(so_servant->_this());
58 //============================================================================
59 /*! Function : constructor
62 //============================================================================
63 SALOMEDS_SObject_i::SALOMEDS_SObject_i(const SALOMEDSImpl_SObject& impl, CORBA::ORB_ptr orb)
66 if(impl.IsComponent()) {
67 SALOMEDSImpl_SComponent sco = impl;
68 _impl = sco.GetPersistentCopy();
71 _impl = impl.GetPersistentCopy();
74 _orb = CORBA::ORB::_duplicate(orb);
75 //SALOME::GenericObj_i::myPOA = SALOMEDS_StudyManager_i::GetPOA(GetStudy());
79 //============================================================================
80 /*! Function : destructor
83 //============================================================================
84 SALOMEDS_SObject_i::~SALOMEDS_SObject_i()
86 if(_impl) delete _impl;
90 //============================================================================
94 //============================================================================
95 char* SALOMEDS_SObject_i::GetID()
97 SALOMEDS::Locker lock;
98 return CORBA::string_dup(_impl->GetID().c_str());
101 //============================================================================
102 /*! Function : GetFatherComponent
105 //============================================================================
106 SALOMEDS::SComponent_ptr SALOMEDS_SObject_i::GetFatherComponent()
108 SALOMEDS::Locker lock;
109 SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (_impl->GetFatherComponent(), _orb);
113 //============================================================================
114 /*! Function : GetFather
117 //============================================================================
118 SALOMEDS::SObject_ptr SALOMEDS_SObject_i::GetFather()
120 SALOMEDS::Locker lock;
121 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (_impl->GetFather(), _orb);
125 //============================================================================
129 //============================================================================
130 SALOMEDS::Study_ptr SALOMEDS_SObject_i::GetStudy()
132 SALOMEDS::Locker lock;
133 SALOMEDSImpl_Study* aStudy = _impl->GetStudy();
135 MESSAGE("Problem GetStudy");
136 return SALOMEDS::Study::_nil();
139 string IOR = aStudy->GetTransientReference();
140 CORBA::Object_var obj = _orb->string_to_object(IOR.c_str());
141 SALOMEDS::Study_var Study = SALOMEDS::Study::_narrow(obj) ;
142 ASSERT(!CORBA::is_nil(Study));
143 return SALOMEDS::Study::_duplicate(Study);
146 //============================================================================
147 /*! Function : FindAttribute
148 * Purpose : Find attribute of given type on this SObject
150 //============================================================================
151 CORBA::Boolean SALOMEDS_SObject_i::FindAttribute (SALOMEDS::GenericAttribute_out anAttribute,
152 const char* aTypeOfAttribute)
154 SALOMEDS::Locker lock;
155 DF_Attribute* anAttr = NULL;
156 if(_impl->FindAttribute(anAttr, (char*)aTypeOfAttribute)) {
157 anAttribute = SALOMEDS::GenericAttribute::_duplicate(SALOMEDS_GenericAttribute_i::CreateAttribute(anAttr, _orb));
164 //============================================================================
165 /*! Function : GetAllAttributes
166 * Purpose : Returns list of all attributes for this sobject
168 //============================================================================
170 SALOMEDS::ListOfAttributes* SALOMEDS_SObject_i::GetAllAttributes()
172 SALOMEDS::Locker lock;
173 vector<DF_Attribute*> aSeq = _impl->GetAllAttributes();
174 SALOMEDS::ListOfAttributes_var SeqOfAttr = new SALOMEDS::ListOfAttributes;
175 int length = aSeq.size();
177 SeqOfAttr->length(length);
180 for(int i = 0; i < length; i++) {
181 SALOMEDSImpl_GenericAttribute* anAttr = dynamic_cast<SALOMEDSImpl_GenericAttribute*>(aSeq[i]);
182 SALOMEDS::GenericAttribute_var anAttribute;
183 anAttribute = SALOMEDS::GenericAttribute::_duplicate(SALOMEDS_GenericAttribute_i::CreateAttribute(anAttr, _orb));
184 if (!CORBA::is_nil(anAttribute)) {
185 SeqOfAttr[i] = anAttribute;
189 return SeqOfAttr._retn();
193 //============================================================================
194 /*! Function : ReferencedObject
197 //============================================================================
198 CORBA::Boolean SALOMEDS_SObject_i::ReferencedObject(SALOMEDS::SObject_out obj)
200 SALOMEDS::Locker lock;
201 SALOMEDSImpl_SObject aRefObj;
202 if(!_impl->ReferencedObject(aRefObj)) return false;
204 obj = SALOMEDS_SObject_i::New (aRefObj, _orb);
208 //============================================================================
209 /*! Function : FindSubObject
212 //============================================================================
213 CORBA::Boolean SALOMEDS_SObject_i::FindSubObject(CORBA::Long atag, SALOMEDS::SObject_out obj)
215 SALOMEDS::Locker lock;
216 SALOMEDSImpl_SObject aSubObj;
217 if(!_impl->FindSubObject(atag, aSubObj)) return false;
219 obj = SALOMEDS_SObject_i::New (aSubObj, _orb);
224 //============================================================================
226 * Purpose : gets a name
228 //============================================================================
229 char* SALOMEDS_SObject_i::Name()
231 SALOMEDS::Locker lock;
232 return CORBA::string_dup(_impl->Name().c_str());
235 //============================================================================
237 * Purpose : sets a name
239 //============================================================================
240 void SALOMEDS_SObject_i::Name(const char* name)
242 SALOMEDS::Locker lock;
243 string aName((char*)name);
247 //============================================================================
251 //============================================================================
252 CORBA::Short SALOMEDS_SObject_i::Tag()
254 SALOMEDS::Locker lock;
258 //============================================================================
262 //============================================================================
263 CORBA::Short SALOMEDS_SObject_i::Depth()
265 SALOMEDS::Locker lock;
266 return _impl->Depth();
269 //============================================================================
270 /*! Function : GetObject
273 //============================================================================
274 CORBA::Object_ptr SALOMEDS_SObject_i::GetObject()
276 SALOMEDS::Locker lock;
277 CORBA::Object_ptr obj = CORBA::Object::_nil();
279 string IOR = _impl->GetIOR();
280 char* c_ior = CORBA::string_dup(IOR.c_str());
281 obj = _orb->string_to_object(c_ior);
282 CORBA::string_free(c_ior);
287 //============================================================================
288 /*! Function : GetName
291 //============================================================================
292 char* SALOMEDS_SObject_i::GetName()
294 SALOMEDS::Locker lock;
295 CORBA::String_var aStr = CORBA::string_dup(_impl->GetName().c_str());
299 //============================================================================
300 /*! Function : GetComment
303 //============================================================================
304 char* SALOMEDS_SObject_i::GetComment()
306 SALOMEDS::Locker lock;
307 CORBA::String_var aStr = CORBA::string_dup(_impl->GetComment().c_str());
311 //============================================================================
312 /*! Function : GetIOR
315 //============================================================================
316 char* SALOMEDS_SObject_i::GetIOR()
318 SALOMEDS::Locker lock;
319 CORBA::String_var aStr = CORBA::string_dup(_impl->GetIOR().c_str());
323 //===========================================================================
325 //===========================================================================
326 CORBA::LongLong SALOMEDS_SObject_i::GetLocalImpl(const char* theHostname, CORBA::Long thePID, CORBA::Boolean& isLocal)
329 long pid = (long)_getpid();
331 long pid = (long)getpid();
333 isLocal = (strcmp(theHostname, Kernel_Utils::GetHostname().c_str()) == 0 && pid == thePID)?1:0;
334 return reinterpret_cast<CORBA::LongLong>(_impl);