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