1 // Copyright (C) 2007-2023 CEA, EDF, 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, or (at your option) any later version.
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
23 // File : SALOMEDS_UseCaseBuilder_i.cxx
24 // Author : Sergey RUIN
27 #include "SALOMEDS_UseCaseBuilder_i.hxx"
28 #include "SALOMEDS_UseCaseIterator_i.hxx"
29 #include "SALOMEDS_SObject_i.hxx"
30 #include "SALOMEDS_Study_i.hxx"
31 #include "SALOMEDS.hxx"
33 #include "utilities.h"
35 //============================================================================
36 /*! Function : constructor
39 //============================================================================
40 SALOMEDS_UseCaseBuilder_i::SALOMEDS_UseCaseBuilder_i(SALOMEDSImpl_UseCaseBuilder* theImpl,
42 GenericObj_i(SALOMEDS_Study_i::GetThePOA())
44 _orb = CORBA::ORB::_duplicate(orb);
48 //============================================================================
49 /*! Function : destructor
52 //============================================================================
53 SALOMEDS_UseCaseBuilder_i::~SALOMEDS_UseCaseBuilder_i()
57 //============================================================================
59 \brief Get default POA for the servant object.
61 This function is implicitly called from "_this()" function.
62 Default POA can be set via the constructor.
64 \return reference to the default POA for the servant
66 //============================================================================
67 PortableServer::POA_ptr SALOMEDS_UseCaseBuilder_i::_default_POA()
69 myPOA = PortableServer::POA::_duplicate(SALOMEDS_Study_i::GetThePOA());
70 //MESSAGE("SALOMEDS_UseCaseBuilder_i::_default_POA: " << myPOA);
71 return PortableServer::POA::_duplicate(myPOA);
75 //============================================================================
79 //============================================================================
80 CORBA::Boolean SALOMEDS_UseCaseBuilder_i::Append(SALOMEDS::SObject_ptr theObject)
82 SALOMEDS::Locker lock;
83 if(!_impl || theObject->_is_nil()) return 0;
84 CORBA::String_var id = theObject->GetID();
85 return _impl->Append(_impl->GetSObject( id.in() ));
88 //============================================================================
92 //============================================================================
93 CORBA::Boolean SALOMEDS_UseCaseBuilder_i::Remove(SALOMEDS::SObject_ptr theObject)
95 SALOMEDS::Locker lock;
96 if(!_impl || theObject->_is_nil()) return 0;
97 CORBA::String_var id = theObject->GetID();
98 return _impl->Remove(_impl->GetSObject( id.in() ));
102 //============================================================================
103 /*! Function : AppendTo
106 //============================================================================
107 CORBA::Boolean SALOMEDS_UseCaseBuilder_i::AppendTo(SALOMEDS::SObject_ptr theFather,
108 SALOMEDS::SObject_ptr theObject)
110 SALOMEDS::Locker lock;
111 if(!_impl || theFather->_is_nil() || theObject->_is_nil()) return 0;
112 CORBA::String_var idF = theFather->GetID();
113 CORBA::String_var idO = theObject->GetID();
114 return _impl->AppendTo(_impl->GetSObject(idF.in()), _impl->GetSObject( idO.in()));
117 //============================================================================
118 /*! Function : GetIndexInFather
121 //============================================================================
122 CORBA::Long SALOMEDS_UseCaseBuilder_i::GetIndexInFather(SALOMEDS::SObject_ptr theFather,
123 SALOMEDS::SObject_ptr theObject)
125 SALOMEDS::Locker lock;
126 if(!_impl || theFather->_is_nil() || theObject->_is_nil()) return -1;
127 CORBA::String_var idF = theFather->GetID();
128 CORBA::String_var idO = theObject->GetID();
129 return _impl->GetIndexInFather(_impl->GetSObject(idF.in()), _impl->GetSObject( idO.in()));
132 //============================================================================
133 /*! Function : InsertBefore
136 //============================================================================
137 CORBA::Boolean SALOMEDS_UseCaseBuilder_i::InsertBefore(SALOMEDS::SObject_ptr theFirst,
138 SALOMEDS::SObject_ptr theNext)
140 SALOMEDS::Locker lock;
141 if(!_impl || theFirst->_is_nil() || theNext->_is_nil()) return 0;
142 CORBA::String_var idF = theFirst->GetID();
143 CORBA::String_var idN = theNext->GetID();
144 return _impl->InsertBefore(_impl->GetSObject(idF.in()), _impl->GetSObject(idN.in()));
148 //============================================================================
149 /*! Function : SetCurrentObject
152 //============================================================================
153 CORBA::Boolean SALOMEDS_UseCaseBuilder_i::SetCurrentObject(SALOMEDS::SObject_ptr theObject)
155 SALOMEDS::Locker lock;
156 if(!_impl || theObject->_is_nil()) return 0;
157 CORBA::String_var id = theObject->GetID();
158 return _impl->SetCurrentObject(_impl->GetSObject( id.in()));
161 //============================================================================
162 /*! Function : SetRootCurrent
165 //============================================================================
166 CORBA::Boolean SALOMEDS_UseCaseBuilder_i::SetRootCurrent()
168 SALOMEDS::Locker lock;
170 return _impl->SetRootCurrent();
173 //============================================================================
174 /*! Function : HasChildren
177 //============================================================================
178 CORBA::Boolean SALOMEDS_UseCaseBuilder_i::HasChildren(SALOMEDS::SObject_ptr theObject)
180 SALOMEDS::Locker lock;
182 CORBA::String_var id = theObject->GetID();
183 return _impl->HasChildren(_impl->GetSObject( id.in()));
186 //============================================================================
187 /*! Function : SortChildren
190 //============================================================================
191 CORBA::Boolean SALOMEDS_UseCaseBuilder_i::SortChildren(SALOMEDS::SObject_ptr theObject, CORBA::Boolean theAscendingOrder)
193 SALOMEDS::Locker lock;
195 CORBA::String_var id = theObject->GetID();
196 return _impl->SortChildren(_impl->GetSObject( id.in()), theAscendingOrder);
199 //============================================================================
200 /*! Function : GetFather
203 //============================================================================
204 SALOMEDS::SObject_ptr SALOMEDS_UseCaseBuilder_i::GetFather(SALOMEDS::SObject_ptr theObject)
206 SALOMEDS::Locker lock;
208 if(!_impl) return NULL;
209 CORBA::String_var id = theObject->GetID();
210 SALOMEDSImpl_SObject aSO = _impl->GetFather(_impl->GetSObject( id.in()));
211 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
215 //============================================================================
216 /*! Function : SetName
219 //============================================================================
220 CORBA::Boolean SALOMEDS_UseCaseBuilder_i::SetName(const char* theName)
222 SALOMEDS::Locker lock;
224 return _impl->SetName(theName);
228 //============================================================================
229 /*! Function : GetCurrentObject
232 //============================================================================
233 SALOMEDS::SObject_ptr SALOMEDS_UseCaseBuilder_i::GetCurrentObject()
235 SALOMEDS::Locker lock;
237 if(!_impl) return NULL;
238 SALOMEDSImpl_SObject aSO = _impl->GetCurrentObject();
239 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
243 //============================================================================
244 /*! Function : GetName
247 //============================================================================
248 char* SALOMEDS_UseCaseBuilder_i::GetName()
250 SALOMEDS::Locker lock;
251 return CORBA::string_dup(_impl->GetName().c_str());
254 //============================================================================
255 /*! Function : IsUseCase
258 //============================================================================
259 CORBA::Boolean SALOMEDS_UseCaseBuilder_i::IsUseCase(SALOMEDS::SObject_ptr theObject)
261 SALOMEDS::Locker lock;
263 if(!_impl || theObject->_is_nil()) return false;
264 CORBA::String_var id = theObject->GetID();
265 return _impl->IsUseCase(_impl->GetSObject( id.in() ));
268 //============================================================================
269 /*! Function : IsUseCaseNode
272 //============================================================================
273 CORBA::Boolean SALOMEDS_UseCaseBuilder_i::IsUseCaseNode(SALOMEDS::SObject_ptr theObject)
275 SALOMEDS::Locker lock;
277 if(!_impl || theObject->_is_nil()) return false;
278 CORBA::String_var id = theObject->GetID();
279 return _impl->IsUseCaseNode(_impl->GetSObject( id.in() ));
282 //============================================================================
283 /*! Function : NewUseCase
286 //============================================================================
287 SALOMEDS::SObject_ptr SALOMEDS_UseCaseBuilder_i::AddUseCase(const char* theName)
289 SALOMEDS::Locker lock;
291 if(!_impl) return SALOMEDS::SObject::_nil();
292 SALOMEDSImpl_SObject aSO = _impl->AddUseCase((char*)theName);
293 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
297 //============================================================================
298 /*! Function : GetUseCaseIterator
299 * Purpose : Creates a new UseCase iterator, if anObject is null all use cases are iterated
301 //============================================================================
302 SALOMEDS::UseCaseIterator_ptr SALOMEDS_UseCaseBuilder_i::GetUseCaseIterator(SALOMEDS::SObject_ptr theObject)
304 SALOMEDS::Locker lock;
306 if(!_impl) return SALOMEDS::UseCaseIterator::_nil();
307 SALOMEDSImpl_UseCaseIterator anItr;
308 if(!CORBA::is_nil(theObject)) {
309 CORBA::String_var id = theObject->GetID();
310 anItr = _impl->GetUseCaseIterator(_impl->GetSObject( id.in()));
312 else anItr = _impl->GetUseCaseIterator(SALOMEDSImpl_SObject());
313 SALOMEDS_UseCaseIterator_i* aServant = new SALOMEDS_UseCaseIterator_i(anItr, _orb);
314 SALOMEDS::UseCaseIterator_var anIterator = aServant->_this();
315 return anIterator._retn();