Salome HOME
Rename Engines::Component to Engines::EngineComponent
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_UseCaseBuilder.cxx
1 //  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  File   : SALOMEDS_UseCaseBuilder.cxx
24 //  Author : Sergey RUIN
25 //  Module : SALOME
26 //
27 #include "SALOMEDS_UseCaseBuilder.hxx"
28
29 #include "SALOMEDS.hxx"
30 #include "SALOMEDS_SObject.hxx"
31 #include "SALOMEDS_UseCaseIterator.hxx"
32
33 #include "SALOMEDSImpl_SObject.hxx"
34 #include "SALOMEDSImpl_UseCaseIterator.hxx"
35
36 #include <string>
37
38 SALOMEDS_UseCaseBuilder::SALOMEDS_UseCaseBuilder(SALOMEDSImpl_UseCaseBuilder* theBuilder)
39 {
40   _isLocal = true;
41   _local_impl = theBuilder;
42   _corba_impl = SALOMEDS::UseCaseBuilder::_nil();
43 }
44
45 SALOMEDS_UseCaseBuilder::SALOMEDS_UseCaseBuilder(SALOMEDS::UseCaseBuilder_ptr theBuilder)
46 {
47   _isLocal = false;
48   _local_impl = NULL;
49   _corba_impl = SALOMEDS::UseCaseBuilder::_duplicate(theBuilder);
50 }
51
52 SALOMEDS_UseCaseBuilder::~SALOMEDS_UseCaseBuilder()
53 {
54   if(!_isLocal) _corba_impl->Destroy(); 
55 }  
56
57 bool SALOMEDS_UseCaseBuilder::Append(const _PTR(SObject)& theObject)
58 {
59   bool ret;
60   SALOMEDS_SObject* obj = dynamic_cast<SALOMEDS_SObject*>(theObject.get());
61   if (_isLocal) {
62     SALOMEDS::Locker lock;
63     ret = _local_impl->Append(*(obj->GetLocalImpl()));
64   }
65   else ret = _corba_impl->Append(obj->GetCORBAImpl());
66   return ret;
67 }
68
69 bool SALOMEDS_UseCaseBuilder::Remove(const _PTR(SObject)& theObject)
70 {
71   bool ret;
72   SALOMEDS_SObject* obj = dynamic_cast<SALOMEDS_SObject*>(theObject.get());
73   if (_isLocal) {
74     SALOMEDS::Locker lock;
75     ret = _local_impl->Remove(*(obj->GetLocalImpl()));
76   }
77   else ret = _corba_impl->Remove(obj->GetCORBAImpl());
78   return ret;
79 }
80
81 bool SALOMEDS_UseCaseBuilder::AppendTo(const _PTR(SObject)& theFather, _PTR(SObject) theObject)
82 {
83   bool ret;
84   SALOMEDS_SObject* father = dynamic_cast<SALOMEDS_SObject*>(theFather.get());
85   SALOMEDS_SObject* obj = dynamic_cast<SALOMEDS_SObject*>(theObject.get());
86   if (_isLocal) {
87     SALOMEDS::Locker lock;
88     ret = _local_impl->AppendTo(*(father->GetLocalImpl()), *(obj->GetLocalImpl()));
89   }
90   else ret = _corba_impl->AppendTo(father->GetCORBAImpl(), obj->GetCORBAImpl());
91   return ret;
92 }
93
94 bool SALOMEDS_UseCaseBuilder::InsertBefore(const _PTR(SObject)& theFirst, _PTR(SObject) theNext)
95 {
96   bool ret;
97   SALOMEDS_SObject* first = dynamic_cast<SALOMEDS_SObject*>(theFirst.get());
98   SALOMEDS_SObject* next = dynamic_cast<SALOMEDS_SObject*>(theNext.get());
99   if (_isLocal) {
100     SALOMEDS::Locker lock;
101     ret = _local_impl->InsertBefore(*(first->GetLocalImpl()), *(next->GetLocalImpl()));
102   }
103   else ret = _corba_impl->InsertBefore(first->GetCORBAImpl(), next->GetCORBAImpl());
104   return ret;
105 }
106
107 bool SALOMEDS_UseCaseBuilder::SetCurrentObject(const _PTR(SObject)& theObject)
108 {
109   bool ret;
110   SALOMEDS_SObject* obj = dynamic_cast<SALOMEDS_SObject*>(theObject.get());
111   if (_isLocal) {
112     SALOMEDS::Locker lock;
113     ret = _local_impl->SetCurrentObject(*(obj->GetLocalImpl()));
114   }
115   else ret = _corba_impl->SetCurrentObject(obj->GetCORBAImpl());
116   return ret;
117 }
118
119 bool SALOMEDS_UseCaseBuilder::SetRootCurrent()
120 {
121   bool ret;
122   if (_isLocal) {
123     SALOMEDS::Locker lock;
124     ret = _local_impl->SetRootCurrent();
125   }
126   else ret = _corba_impl->SetRootCurrent();
127   return ret;
128 }
129
130 bool SALOMEDS_UseCaseBuilder::HasChildren(const _PTR(SObject)& theObject)
131 {
132   bool ret;
133   SALOMEDS_SObject* obj = dynamic_cast<SALOMEDS_SObject*>(theObject.get());
134   if (_isLocal) {
135     SALOMEDS::Locker lock;
136     ret = _local_impl->HasChildren(*(obj->GetLocalImpl()));
137   }
138   else ret = _corba_impl->HasChildren(obj->GetCORBAImpl());
139   return ret;
140 }
141
142 bool SALOMEDS_UseCaseBuilder::IsUseCase(const _PTR(SObject)& theObject)
143 {
144   bool ret;
145   SALOMEDS_SObject* obj = dynamic_cast<SALOMEDS_SObject*>(theObject.get());
146   if (_isLocal) {
147     SALOMEDS::Locker lock;
148     ret = _local_impl->IsUseCase(*(obj->GetLocalImpl()));
149   }
150   else ret = _corba_impl->IsUseCase(obj->GetCORBAImpl());
151   return ret;
152 }
153
154 bool SALOMEDS_UseCaseBuilder::SetName(const std::string& theName)
155 {
156   bool ret;
157   if (_isLocal) {
158     SALOMEDS::Locker lock;
159     ret = _local_impl->SetName(theName);
160   }
161   else ret = _corba_impl->SetName((char*)theName.c_str());
162   return ret;
163 }
164
165 _PTR(SObject) SALOMEDS_UseCaseBuilder::GetCurrentObject()
166 {
167   SALOMEDS_SObject* obj = NULL;
168   if (_isLocal) {
169     SALOMEDS::Locker lock;
170     obj = new SALOMEDS_SObject(_local_impl->GetCurrentObject());
171   }
172   else obj = new SALOMEDS_SObject(_corba_impl->GetCurrentObject());
173   return _PTR(SObject)(obj);
174 }
175
176 std::string SALOMEDS_UseCaseBuilder::GetName()
177 {
178   std::string aName;
179   if (_isLocal) {
180     SALOMEDS::Locker lock;
181     aName = _local_impl->GetName();
182   }
183   else aName = _corba_impl->GetName();
184   return aName;
185 }
186
187 _PTR(SObject) SALOMEDS_UseCaseBuilder::AddUseCase(const std::string& theName)
188 {
189   SALOMEDS_SObject* obj = NULL;
190   if (_isLocal) {
191     SALOMEDS::Locker lock;
192     obj = new SALOMEDS_SObject(_local_impl->AddUseCase(theName));
193   }
194   else obj = new SALOMEDS_SObject(_corba_impl->AddUseCase((char*)theName.c_str()));
195   return _PTR(SObject)(obj);
196 }
197
198 _PTR(UseCaseIterator) SALOMEDS_UseCaseBuilder::GetUseCaseIterator(const _PTR(SObject)& theObject) 
199 {
200   SALOMEDS_UseCaseIterator* it = NULL;
201   SALOMEDS_SObject* obj = (theObject)?dynamic_cast<SALOMEDS_SObject*>(theObject.get()):NULL;
202   if (_isLocal) {
203     SALOMEDS::Locker lock;
204     if(obj)
205       it = new SALOMEDS_UseCaseIterator(_local_impl->GetUseCaseIterator(*(obj->GetLocalImpl())));
206     else 
207       it = new SALOMEDS_UseCaseIterator(_local_impl->GetUseCaseIterator(SALOMEDSImpl_SObject()));
208   }
209   else {
210     if(obj)
211       it = new SALOMEDS_UseCaseIterator(_corba_impl->GetUseCaseIterator(obj->GetCORBAImpl()));
212     else
213       it = new SALOMEDS_UseCaseIterator(_corba_impl->GetUseCaseIterator(SALOMEDS::SObject::_nil()));
214   }
215   return _PTR(UseCaseIterator)(it);
216 }