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