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