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