Salome HOME
Removed includes and libraries of OCC
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_AttributeTreeNode.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/ or email : webmaster.salome@opencascade.com
19 //
20 //  File   : SALOMEDS_AttributeTreeNode.cxx
21 //  Author : Sergey RUIN
22 //  Module : SALOME
23
24 #include "SALOMEDS_AttributeTreeNode.hxx"
25 #include "SALOMEDS.hxx"
26
27 #include <string>
28 #include <stdexcept>
29
30 #include "SALOMEDSImpl_AttributeTreeNode.hxx"
31 #include "SALOMEDS_AttributeTreeNode.hxx"
32
33 using namespace std;
34
35 SALOMEDS_AttributeTreeNode::SALOMEDS_AttributeTreeNode(SALOMEDSImpl_AttributeTreeNode* theAttr)
36 :SALOMEDS_GenericAttribute(theAttr)
37 {}
38
39 SALOMEDS_AttributeTreeNode::SALOMEDS_AttributeTreeNode(SALOMEDS::AttributeTreeNode_ptr theAttr)
40 :SALOMEDS_GenericAttribute(theAttr)
41 {}
42
43 SALOMEDS_AttributeTreeNode::~SALOMEDS_AttributeTreeNode()
44 {}
45
46 void SALOMEDS_AttributeTreeNode::SetFather(const _PTR(AttributeTreeNode)& value)
47 {
48   SALOMEDS_AttributeTreeNode* aTN = dynamic_cast<SALOMEDS_AttributeTreeNode*>(value.get());
49   if (_isLocal) {
50     CheckLocked();
51     SALOMEDS::Locker lock;
52     SALOMEDSImpl_AttributeTreeNode *aNode, *aFather;
53     aNode = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(_local_impl);
54     aFather = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(aTN->_local_impl);
55     aNode->SetFather(aFather);
56   }
57   else {
58     SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
59     SALOMEDS::AttributeTreeNode_var aFather = SALOMEDS::AttributeTreeNode::_narrow(aTN->_corba_impl);
60     aNode->SetFather(aFather);
61   }
62 }
63
64 bool SALOMEDS_AttributeTreeNode::HasFather()
65 {
66   bool ret;
67   if (_isLocal) {
68     SALOMEDS::Locker lock;
69     SALOMEDSImpl_AttributeTreeNode* aNode = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(_local_impl);
70     ret = aNode->HasFather();
71   }
72   else {
73     SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
74     ret = aNode->HasFather();
75   }
76   return ret;
77 }
78
79 _PTR(AttributeTreeNode) SALOMEDS_AttributeTreeNode::GetFather()
80 {
81   SALOMEDSClient_AttributeTreeNode* aTN  = NULL;
82   if (_isLocal) {
83     SALOMEDS::Locker lock;
84     SALOMEDSImpl_AttributeTreeNode* aNode = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(_local_impl);
85     aTN = new SALOMEDS_AttributeTreeNode(aNode->GetFather());
86   }
87   else {
88     SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
89     aTN = new SALOMEDS_AttributeTreeNode(aNode->GetFather());
90   }
91   return _PTR(AttributeTreeNode)(aTN);
92 }
93
94 void SALOMEDS_AttributeTreeNode::SetPrevious(const _PTR(AttributeTreeNode)& value)
95 {
96   SALOMEDS_AttributeTreeNode* aTN = dynamic_cast<SALOMEDS_AttributeTreeNode*>(value.get());
97   if (_isLocal) {
98     CheckLocked();
99     SALOMEDS::Locker lock;
100     SALOMEDSImpl_AttributeTreeNode *aNode, *aPrev;
101     aNode = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(_local_impl);
102     aPrev = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(aTN->_local_impl);
103     aNode->SetPrevious(aPrev);
104   }
105   else {
106     SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
107     SALOMEDS::AttributeTreeNode_var aPrev = SALOMEDS::AttributeTreeNode::_narrow(aTN->_corba_impl);
108     aNode->SetPrevious(aPrev);
109   }
110 }
111
112 bool SALOMEDS_AttributeTreeNode::HasPrevious()
113 {
114   bool ret;
115   if (_isLocal) {
116     SALOMEDS::Locker lock;
117     SALOMEDSImpl_AttributeTreeNode* aNode = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(_local_impl);
118     ret = aNode->HasPrevious();
119   }
120   else {
121     SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
122     ret = aNode->HasPrevious();
123   }
124   return ret;
125 }
126
127 _PTR(AttributeTreeNode) SALOMEDS_AttributeTreeNode::GetPrevious()
128 {
129   SALOMEDSClient_AttributeTreeNode* aTN = NULL;
130   if (_isLocal) {
131     SALOMEDS::Locker lock;
132     SALOMEDSImpl_AttributeTreeNode* aNode = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(_local_impl);
133     aTN = new SALOMEDS_AttributeTreeNode(aNode->GetPrevious());
134   }
135   else {
136     SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
137     aTN = new SALOMEDS_AttributeTreeNode(aNode->GetPrevious());
138   }
139   return _PTR(AttributeTreeNode)(aTN);
140 }
141
142 void SALOMEDS_AttributeTreeNode::SetNext(const _PTR(AttributeTreeNode)& value)
143 {
144   SALOMEDS_AttributeTreeNode* aTN = dynamic_cast<SALOMEDS_AttributeTreeNode*>(value.get());
145   if (_isLocal) {
146     CheckLocked();
147     SALOMEDS::Locker lock;
148     SALOMEDSImpl_AttributeTreeNode  *aNode, *aNext;
149     aNode = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(_local_impl);
150     aNext = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(aTN->_local_impl);
151     aNode->SetNext(aNext);
152   }
153   else {
154     SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
155     SALOMEDS::AttributeTreeNode_var aNext = SALOMEDS::AttributeTreeNode::_narrow(aTN->_corba_impl);
156     aNode->SetNext(aNext);
157   }
158 }
159
160 bool SALOMEDS_AttributeTreeNode::HasNext()
161 {
162   bool ret;
163   if (_isLocal) {
164     SALOMEDS::Locker lock;
165     SALOMEDSImpl_AttributeTreeNode* aNode = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(_local_impl);
166     ret = aNode->HasNext();
167   }
168   else {
169     SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
170     ret = aNode->HasNext();
171   }
172   return ret;
173 }
174
175 _PTR(AttributeTreeNode) SALOMEDS_AttributeTreeNode::GetNext()
176 {
177   SALOMEDSClient_AttributeTreeNode* aTN = NULL;
178   if (_isLocal) {
179     SALOMEDS::Locker lock;
180     SALOMEDSImpl_AttributeTreeNode* aNode = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(_local_impl);
181     aTN = new SALOMEDS_AttributeTreeNode(aNode->GetNext());
182   }
183   else {
184     SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
185     aTN = new SALOMEDS_AttributeTreeNode(aNode->GetNext());
186   }
187   return _PTR(AttributeTreeNode)(aTN);
188 }
189
190 void SALOMEDS_AttributeTreeNode::SetFirst(const _PTR(AttributeTreeNode)& value)
191 {
192   SALOMEDS_AttributeTreeNode* aTN = dynamic_cast<SALOMEDS_AttributeTreeNode*>(value.get());
193   if (_isLocal) {
194     CheckLocked();
195     SALOMEDS::Locker lock;
196     SALOMEDSImpl_AttributeTreeNode *aNode, *aFirst;
197     aNode = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(_local_impl);
198     aFirst = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(aTN->_local_impl);
199     aNode->SetFirst(aFirst);
200   }
201   else {
202     SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
203     SALOMEDS::AttributeTreeNode_var aFirst = SALOMEDS::AttributeTreeNode::_narrow(aTN->_corba_impl);
204     aNode->SetFirst(aFirst);
205   }
206 }
207
208 bool SALOMEDS_AttributeTreeNode::HasFirst()
209 {
210   bool ret;
211   if (_isLocal) {
212     SALOMEDS::Locker lock;
213     SALOMEDSImpl_AttributeTreeNode* aNode = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(_local_impl);
214     ret = aNode->HasFirst();
215   }
216   else {
217     SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
218     ret = aNode->HasFirst();
219   }
220   return ret;
221 }
222
223 _PTR(AttributeTreeNode) SALOMEDS_AttributeTreeNode::GetFirst()
224 {
225   SALOMEDSClient_AttributeTreeNode* aTN = NULL;
226   if (_isLocal) {
227     SALOMEDS::Locker lock;
228     SALOMEDSImpl_AttributeTreeNode* aNode = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(_local_impl);
229     aTN = new SALOMEDS_AttributeTreeNode(aNode->GetFirst());
230   }
231   else {
232     SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
233     aTN = new SALOMEDS_AttributeTreeNode(aNode->GetFirst());
234   }
235   return _PTR(AttributeTreeNode)(aTN);
236 }
237
238 void SALOMEDS_AttributeTreeNode::SetTreeID(const std::string& value)
239 {
240   if (_isLocal) {
241     CheckLocked();
242     SALOMEDS::Locker lock;
243     SALOMEDSImpl_AttributeTreeNode* aNode = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(_local_impl);
244     aNode->SetTreeID(value);
245   }
246   else {
247     SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
248     aNode->SetTreeID(value.c_str());
249   }
250 }
251
252 std::string SALOMEDS_AttributeTreeNode::GetTreeID()
253 {
254   string aGUID;
255   if (_isLocal) {
256     SALOMEDS::Locker lock;
257     SALOMEDSImpl_AttributeTreeNode* aNode = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(_local_impl);
258     aGUID = aNode->GetTreeID();
259   }
260   else {
261     SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
262     aGUID = aNode->GetTreeID();
263   }
264
265   return aGUID;
266 }
267
268 void SALOMEDS_AttributeTreeNode::Append(const _PTR(AttributeTreeNode)& value)
269 {
270   SALOMEDS_AttributeTreeNode* aTN = dynamic_cast<SALOMEDS_AttributeTreeNode*>(value.get());
271   if (_isLocal) {
272     CheckLocked();
273     SALOMEDS::Locker lock;
274     SALOMEDSImpl_AttributeTreeNode *aNode, *anOther;
275     aNode = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(_local_impl);
276     anOther = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(aTN->_local_impl);
277     aNode->Append(anOther);
278   }
279   else {
280     SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
281     SALOMEDS::AttributeTreeNode_var anOther = SALOMEDS::AttributeTreeNode::_narrow(aTN->_corba_impl);
282     aNode->Append(anOther);
283   }
284 }
285
286 void SALOMEDS_AttributeTreeNode::Prepend(const _PTR(AttributeTreeNode)& value)
287 {
288   SALOMEDS_AttributeTreeNode* aTN = dynamic_cast<SALOMEDS_AttributeTreeNode*>(value.get());
289   if (_isLocal) {
290     CheckLocked();
291     SALOMEDS::Locker lock;
292     SALOMEDSImpl_AttributeTreeNode *aNode, *anOther;
293     aNode = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(_local_impl);
294     anOther = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(aTN->_local_impl);
295     aNode->Prepend(anOther);
296   }
297   else {
298     SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
299     SALOMEDS::AttributeTreeNode_var anOther = SALOMEDS::AttributeTreeNode::_narrow(aTN->_corba_impl);
300     aNode->Prepend(anOther);
301   }
302 }
303
304 void SALOMEDS_AttributeTreeNode::InsertBefore(const _PTR(AttributeTreeNode)& value)
305 {
306   SALOMEDS_AttributeTreeNode* aTN = dynamic_cast<SALOMEDS_AttributeTreeNode*>(value.get());
307   if (_isLocal) {
308     CheckLocked();
309     SALOMEDS::Locker lock;
310     SALOMEDSImpl_AttributeTreeNode *aNode, *anOther;
311     aNode = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(_local_impl);
312     anOther = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(aTN->_local_impl);
313     aNode->InsertBefore(anOther);
314   }
315   else {
316     SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
317     SALOMEDS::AttributeTreeNode_var anOther = SALOMEDS::AttributeTreeNode::_narrow(aTN->_corba_impl);
318     aNode->InsertBefore(anOther);
319   }
320 }
321
322 void SALOMEDS_AttributeTreeNode::InsertAfter(const _PTR(AttributeTreeNode)& value)
323 {
324   SALOMEDS_AttributeTreeNode* aTN = dynamic_cast<SALOMEDS_AttributeTreeNode*>(value.get());
325   if (_isLocal) {
326     CheckLocked();
327     SALOMEDS::Locker lock;
328     SALOMEDSImpl_AttributeTreeNode *aNode, *anOther;
329     aNode = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(_local_impl);
330     anOther = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(aTN->_local_impl);
331     aNode->InsertAfter(anOther);
332   }
333   else {
334     SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
335     SALOMEDS::AttributeTreeNode_var anOther = SALOMEDS::AttributeTreeNode::_narrow(aTN->_corba_impl);
336     aNode->InsertAfter(anOther);
337   }
338 }
339
340 void SALOMEDS_AttributeTreeNode::Remove()
341 {
342   if (_isLocal) {
343     CheckLocked();
344     SALOMEDS::Locker lock;
345     dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(_local_impl)->Remove();
346   }
347   else SALOMEDS::AttributeTreeNode::_narrow(_corba_impl)->Remove();
348 }
349
350 int SALOMEDS_AttributeTreeNode::Depth()
351 {
352   int aDepth;
353   if (_isLocal) {
354     SALOMEDS::Locker lock;
355     aDepth = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(_local_impl)->Depth();
356   }
357   else aDepth =  SALOMEDS::AttributeTreeNode::_narrow(_corba_impl)->Depth();
358   return aDepth;
359 }
360
361 bool SALOMEDS_AttributeTreeNode::IsRoot()
362 {
363   bool ret;
364   if (_isLocal) {
365     SALOMEDS::Locker lock;
366     ret = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(_local_impl)->IsRoot();
367   }
368   else ret =  SALOMEDS::AttributeTreeNode::_narrow(_corba_impl)->IsRoot();
369   return ret;
370 }
371
372 bool SALOMEDS_AttributeTreeNode::IsDescendant(const _PTR(AttributeTreeNode)& value)
373 {
374   bool ret;
375   SALOMEDS_AttributeTreeNode* aTN = dynamic_cast<SALOMEDS_AttributeTreeNode*>(value.get());
376   if (_isLocal) {
377     SALOMEDS::Locker lock;
378     SALOMEDSImpl_AttributeTreeNode *aNode, *anOther;
379     aNode = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(_local_impl);
380     anOther = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(aTN->_local_impl);
381     ret = aNode->IsDescendant(anOther);
382   }
383   else {
384     SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
385     SALOMEDS::AttributeTreeNode_var anOther = SALOMEDS::AttributeTreeNode::_narrow(aTN->_corba_impl);
386     ret = aNode->IsDescendant(anOther);
387   }  
388   return ret;
389 }
390
391 bool SALOMEDS_AttributeTreeNode::IsFather(const _PTR(AttributeTreeNode)& value)
392 {
393   bool ret;
394   SALOMEDS_AttributeTreeNode* aTN = dynamic_cast<SALOMEDS_AttributeTreeNode*>(value.get());
395   if (_isLocal) {
396     SALOMEDS::Locker lock;
397     SALOMEDSImpl_AttributeTreeNode *aNode, *anOther;
398     aNode = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(_local_impl);
399     anOther = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(aTN->_local_impl);
400     ret = aNode->IsFather(anOther);
401   }
402   else {
403     SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
404     SALOMEDS::AttributeTreeNode_var anOther = SALOMEDS::AttributeTreeNode::_narrow(aTN->_corba_impl);
405     ret = aNode->IsFather(anOther);
406   }  
407   return ret;  
408 }
409
410 bool SALOMEDS_AttributeTreeNode::IsChild(const _PTR(AttributeTreeNode)& value)
411 {
412   bool ret;
413   SALOMEDS_AttributeTreeNode* aTN = dynamic_cast<SALOMEDS_AttributeTreeNode*>(value.get());
414   if (_isLocal) {
415     SALOMEDS::Locker lock;
416     SALOMEDSImpl_AttributeTreeNode *aNode, *anOther;
417     aNode = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(_local_impl);
418     anOther = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(aTN->_local_impl);
419     ret = aNode->IsChild(anOther);
420   }
421   else {
422     SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
423     SALOMEDS::AttributeTreeNode_var anOther = SALOMEDS::AttributeTreeNode::_narrow(aTN->_corba_impl);
424     ret = aNode->IsChild(anOther);
425   }  
426   return ret;  
427 }
428
429 std::string SALOMEDS_AttributeTreeNode::Label()
430 {
431   string aLabel;
432   if (_isLocal) {
433     SALOMEDS::Locker lock;
434     aLabel = _local_impl->Label().Entry();
435   }
436   else aLabel = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl)->Label();
437   return aLabel;
438 }