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_UseCaseBuilder.cxx
21 // Author : Sergey RUIN
26 #include "SALOMEDS_UseCaseBuilder.hxx"
28 #include "SALOMEDS.hxx"
29 #include "SALOMEDS_SObject.hxx"
30 #include "SALOMEDS_UseCaseIterator.hxx"
32 #include "SALOMEDSImpl_SObject.hxx"
33 #include "SALOMEDSImpl_UseCaseIterator.hxx"
35 #include <TCollection_AsciiString.hxx>
40 SALOMEDS_UseCaseBuilder::SALOMEDS_UseCaseBuilder(const Handle(SALOMEDSImpl_UseCaseBuilder)& theBuilder)
43 _local_impl = theBuilder;
44 _corba_impl = SALOMEDS::UseCaseBuilder::_nil();
47 SALOMEDS_UseCaseBuilder::SALOMEDS_UseCaseBuilder(SALOMEDS::UseCaseBuilder_ptr theBuilder)
51 _corba_impl = SALOMEDS::UseCaseBuilder::_duplicate(theBuilder);
54 SALOMEDS_UseCaseBuilder::~SALOMEDS_UseCaseBuilder()
56 if(!_isLocal) _corba_impl->Destroy();
59 bool SALOMEDS_UseCaseBuilder::Append(const _PTR(SObject)& theObject)
62 SALOMEDS_SObject* obj = dynamic_cast<SALOMEDS_SObject*>(theObject.get());
64 SALOMEDS::Locker lock;
65 ret = _local_impl->Append(obj->GetLocalImpl());
67 else ret = _corba_impl->Append(obj->GetCORBAImpl());
71 bool SALOMEDS_UseCaseBuilder::Remove(const _PTR(SObject)& theObject)
74 SALOMEDS_SObject* obj = dynamic_cast<SALOMEDS_SObject*>(theObject.get());
76 SALOMEDS::Locker lock;
77 ret = _local_impl->Remove(obj->GetLocalImpl());
79 else ret = _corba_impl->Remove(obj->GetCORBAImpl());
83 bool SALOMEDS_UseCaseBuilder::AppendTo(const _PTR(SObject)& theFather, _PTR(SObject) theObject)
86 SALOMEDS_SObject* father = dynamic_cast<SALOMEDS_SObject*>(theFather.get());
87 SALOMEDS_SObject* obj = dynamic_cast<SALOMEDS_SObject*>(theObject.get());
89 SALOMEDS::Locker lock;
90 ret = _local_impl->AppendTo(father->GetLocalImpl(), obj->GetLocalImpl());
92 else ret = _corba_impl->AppendTo(father->GetCORBAImpl(), obj->GetCORBAImpl());
96 bool SALOMEDS_UseCaseBuilder::InsertBefore(const _PTR(SObject)& theFirst, _PTR(SObject) theNext)
99 SALOMEDS_SObject* first = dynamic_cast<SALOMEDS_SObject*>(theFirst.get());
100 SALOMEDS_SObject* next = dynamic_cast<SALOMEDS_SObject*>(theNext.get());
102 SALOMEDS::Locker lock;
103 ret = _local_impl->InsertBefore(first->GetLocalImpl(), next->GetLocalImpl());
105 else ret = _corba_impl->InsertBefore(first->GetCORBAImpl(), next->GetCORBAImpl());
109 bool SALOMEDS_UseCaseBuilder::SetCurrentObject(const _PTR(SObject)& theObject)
112 SALOMEDS_SObject* obj = dynamic_cast<SALOMEDS_SObject*>(theObject.get());
114 SALOMEDS::Locker lock;
115 ret = _local_impl->SetCurrentObject(obj->GetLocalImpl());
117 else ret = _corba_impl->SetCurrentObject(obj->GetCORBAImpl());
121 bool SALOMEDS_UseCaseBuilder::SetRootCurrent()
125 SALOMEDS::Locker lock;
126 ret = _local_impl->SetRootCurrent();
128 else ret = _corba_impl->SetRootCurrent();
132 bool SALOMEDS_UseCaseBuilder::HasChildren(const _PTR(SObject)& theObject)
135 SALOMEDS_SObject* obj = dynamic_cast<SALOMEDS_SObject*>(theObject.get());
137 SALOMEDS::Locker lock;
138 ret = _local_impl->HasChildren(obj->GetLocalImpl());
140 else ret = _corba_impl->HasChildren(obj->GetCORBAImpl());
144 bool SALOMEDS_UseCaseBuilder::IsUseCase(const _PTR(SObject)& theObject)
147 SALOMEDS_SObject* obj = dynamic_cast<SALOMEDS_SObject*>(theObject.get());
149 SALOMEDS::Locker lock;
150 ret = _local_impl->IsUseCase(obj->GetLocalImpl());
152 else ret = _corba_impl->IsUseCase(obj->GetCORBAImpl());
156 bool SALOMEDS_UseCaseBuilder::SetName(const std::string& theName)
160 SALOMEDS::Locker lock;
161 ret = _local_impl->SetName((char*)theName.c_str());
163 else ret = _corba_impl->SetName((char*)theName.c_str());
167 _PTR(SObject) SALOMEDS_UseCaseBuilder::GetCurrentObject()
169 SALOMEDS_SObject* obj = NULL;
171 SALOMEDS::Locker lock;
172 obj = new SALOMEDS_SObject(_local_impl->GetCurrentObject());
174 else obj = new SALOMEDS_SObject(_corba_impl->GetCurrentObject());
175 return _PTR(SObject)(obj);
178 std::string SALOMEDS_UseCaseBuilder::GetName()
182 SALOMEDS::Locker lock;
183 aName = _local_impl->GetName().ToCString();
185 else aName = _corba_impl->GetName();
189 _PTR(SObject) SALOMEDS_UseCaseBuilder::AddUseCase(const std::string& theName)
191 SALOMEDS_SObject* obj = NULL;
193 SALOMEDS::Locker lock;
194 obj = new SALOMEDS_SObject(_local_impl->AddUseCase((char*)theName.c_str()));
196 else obj = new SALOMEDS_SObject(_corba_impl->AddUseCase((char*)theName.c_str()));
197 return _PTR(SObject)(obj);
200 _PTR(UseCaseIterator) SALOMEDS_UseCaseBuilder::GetUseCaseIterator(const _PTR(SObject)& theObject)
202 SALOMEDS_UseCaseIterator* it = NULL;
203 SALOMEDS_SObject* obj = (theObject)?dynamic_cast<SALOMEDS_SObject*>(theObject.get()):NULL;
205 SALOMEDS::Locker lock;
207 it = new SALOMEDS_UseCaseIterator(_local_impl->GetUseCaseIterator(obj->GetLocalImpl()));
209 it = new SALOMEDS_UseCaseIterator(_local_impl->GetUseCaseIterator(NULL));
213 it = new SALOMEDS_UseCaseIterator(_corba_impl->GetUseCaseIterator(obj->GetCORBAImpl()));
215 it = new SALOMEDS_UseCaseIterator(_corba_impl->GetUseCaseIterator(SALOMEDS::SObject::_nil()));
217 return _PTR(UseCaseIterator)(it);