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"
38 #include <TCollection_AsciiString.hxx>
39 #include <TCollection_ExtendedString.hxx>
40 #include <TColStd_HSequenceOfTransient.hxx>
46 #include <sys/types.h>
54 SALOMEDS::SObject_ptr SALOMEDS_SObject_i::New(const Handle(SALOMEDSImpl_SObject)& theImpl, CORBA::ORB_ptr theORB)
56 SALOMEDS_SObject_i* so_servant = new SALOMEDS_SObject_i(theImpl, theORB);
57 SALOMEDS::SObject_var so = SALOMEDS::SObject::_narrow(so_servant->_this());
63 //============================================================================
64 /*! Function : constructor
67 //============================================================================
68 SALOMEDS_SObject_i::SALOMEDS_SObject_i(const Handle(SALOMEDSImpl_SObject)& impl, CORBA::ORB_ptr orb)
71 _orb = CORBA::ORB::_duplicate(orb);
72 //SALOME::GenericObj_i::myPOA = SALOMEDS_StudyManager_i::GetPOA(GetStudy());
76 //============================================================================
77 /*! Function : destructor
80 //============================================================================
81 SALOMEDS_SObject_i::~SALOMEDS_SObject_i()
85 //============================================================================
89 //============================================================================
90 char* SALOMEDS_SObject_i::GetID()
92 SALOMEDS::Locker lock;
93 return CORBA::string_dup(_impl->GetID().ToCString());
96 //============================================================================
97 /*! Function : GetFatherComponent
100 //============================================================================
101 SALOMEDS::SComponent_ptr SALOMEDS_SObject_i::GetFatherComponent()
103 SALOMEDS::Locker lock;
104 SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (_impl->GetFatherComponent(), _orb);
108 //============================================================================
109 /*! Function : GetFather
112 //============================================================================
113 SALOMEDS::SObject_ptr SALOMEDS_SObject_i::GetFather()
115 SALOMEDS::Locker lock;
116 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (_impl->GetFather(), _orb);
120 //============================================================================
124 //============================================================================
125 SALOMEDS::Study_ptr SALOMEDS_SObject_i::GetStudy()
127 SALOMEDS::Locker lock;
128 Handle(SALOMEDSImpl_Study) aStudy = _impl->GetStudy();
129 if(aStudy.IsNull()) {
130 MESSAGE("Problem GetStudy");
131 return SALOMEDS::Study::_nil();
134 TCollection_AsciiString IOR = aStudy->GetTransientReference();
135 CORBA::Object_var obj = _orb->string_to_object(IOR.ToCString());
136 SALOMEDS::Study_var Study = SALOMEDS::Study::_narrow(obj) ;
137 ASSERT(!CORBA::is_nil(Study));
138 return SALOMEDS::Study::_duplicate(Study);
141 //============================================================================
142 /*! Function : FindAttribute
143 * Purpose : Find attribute of given type on this SObject
145 //============================================================================
146 CORBA::Boolean SALOMEDS_SObject_i::FindAttribute (SALOMEDS::GenericAttribute_out anAttribute,
147 const char* aTypeOfAttribute)
149 SALOMEDS::Locker lock;
150 Handle(TDF_Attribute) anAttr;
151 if(_impl->FindAttribute(anAttr, (char*)aTypeOfAttribute)) {
152 anAttribute = SALOMEDS::GenericAttribute::_duplicate(SALOMEDS_GenericAttribute_i::CreateAttribute(anAttr, _orb));
153 return Standard_True;
156 return Standard_False;
159 //============================================================================
160 /*! Function : GetAllAttributes
161 * Purpose : Returns list of all attributes for this sobject
163 //============================================================================
165 SALOMEDS::ListOfAttributes* SALOMEDS_SObject_i::GetAllAttributes()
167 SALOMEDS::Locker lock;
168 Handle(TColStd_HSequenceOfTransient) aSeq = _impl->GetAllAttributes();
169 SALOMEDS::ListOfAttributes_var SeqOfAttr = new SALOMEDS::ListOfAttributes;
170 Standard_Integer length = aSeq->Length();
172 SeqOfAttr->length(length);
175 for(int i = 1; i<= length; i++) {
176 Handle(SALOMEDSImpl_GenericAttribute) anAttr = Handle(SALOMEDSImpl_GenericAttribute)::DownCast(aSeq->Value(i));
177 SALOMEDS::GenericAttribute_var anAttribute;
178 anAttribute = SALOMEDS::GenericAttribute::_duplicate(SALOMEDS_GenericAttribute_i::CreateAttribute(anAttr, _orb));
179 if (!CORBA::is_nil(anAttribute)) {
180 SeqOfAttr[i - 1] = anAttribute;
184 return SeqOfAttr._retn();
188 //============================================================================
189 /*! Function : ReferencedObject
192 //============================================================================
193 CORBA::Boolean SALOMEDS_SObject_i::ReferencedObject(SALOMEDS::SObject_out obj)
195 SALOMEDS::Locker lock;
196 Handle(SALOMEDSImpl_SObject) aRefObj;
197 if(!_impl->ReferencedObject(aRefObj)) return false;
199 obj = SALOMEDS_SObject_i::New (aRefObj, _orb);
203 //============================================================================
204 /*! Function : FindSubObject
207 //============================================================================
208 CORBA::Boolean SALOMEDS_SObject_i::FindSubObject(CORBA::Long atag, SALOMEDS::SObject_out obj)
210 SALOMEDS::Locker lock;
211 Handle(SALOMEDSImpl_SObject) aSubObj;
212 if(!_impl->FindSubObject(atag, aSubObj)) return false;
214 obj = SALOMEDS_SObject_i::New (aSubObj, _orb);
219 //============================================================================
221 * Purpose : gets a name
223 //============================================================================
224 char* SALOMEDS_SObject_i::Name()
226 SALOMEDS::Locker lock;
227 return CORBA::string_dup(_impl->Name().ToCString());
230 //============================================================================
232 * Purpose : sets a name
234 //============================================================================
235 void SALOMEDS_SObject_i::Name(const char* name)
237 SALOMEDS::Locker lock;
238 TCollection_AsciiString aName((char*)name);
242 //============================================================================
246 //============================================================================
247 CORBA::Short SALOMEDS_SObject_i::Tag()
249 SALOMEDS::Locker lock;
253 //============================================================================
257 //============================================================================
258 CORBA::Short SALOMEDS_SObject_i::Depth()
260 SALOMEDS::Locker lock;
261 return _impl->Depth();
264 //============================================================================
265 /*! Function : GetObject
268 //============================================================================
269 CORBA::Object_ptr SALOMEDS_SObject_i::GetObject()
271 SALOMEDS::Locker lock;
272 CORBA::Object_ptr obj = CORBA::Object::_nil();
274 TCollection_AsciiString IOR = _impl->GetIOR();
275 char* c_ior = CORBA::string_dup(IOR.ToCString());
276 obj = _orb->string_to_object(c_ior);
277 CORBA::string_free(c_ior);
282 //============================================================================
283 /*! Function : GetName
286 //============================================================================
287 char* SALOMEDS_SObject_i::GetName()
289 SALOMEDS::Locker lock;
290 CORBA::String_var aStr = CORBA::string_dup(_impl->GetName().ToCString());
294 //============================================================================
295 /*! Function : GetComment
298 //============================================================================
299 char* SALOMEDS_SObject_i::GetComment()
301 SALOMEDS::Locker lock;
302 CORBA::String_var aStr = CORBA::string_dup(_impl->GetComment().ToCString());
306 //============================================================================
307 /*! Function : GetIOR
310 //============================================================================
311 char* SALOMEDS_SObject_i::GetIOR()
313 SALOMEDS::Locker lock;
314 CORBA::String_var aStr = CORBA::string_dup(_impl->GetIOR().ToCString());
318 //===========================================================================
320 //===========================================================================
321 CORBA::Long SALOMEDS_SObject_i::GetLocalImpl(const char* theHostname, CORBA::Long thePID, CORBA::Boolean& isLocal)
324 long pid = (long)_getpid();
326 long pid = (long)getpid();
328 isLocal = (strcmp(theHostname, GetHostname().c_str()) == 0 && pid == thePID)?1:0;
329 SALOMEDSImpl_SObject* local_impl = _impl.operator->();
330 return ((long)local_impl);