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