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