1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
18 // See http://www.salome-platform.org/
20 // File : SALOMEDS_AttributeTreeNode.cxx
21 // Author : Sergey RUIN
24 #include "SALOMEDS_AttributeTreeNode.hxx"
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>
33 #include "SALOMEDSImpl_AttributeTreeNode.hxx"
34 #include "SALOMEDS_AttributeTreeNode.hxx"
36 SALOMEDS_AttributeTreeNode::SALOMEDS_AttributeTreeNode(const Handle(SALOMEDSImpl_AttributeTreeNode)& theAttr)
37 :SALOMEDS_GenericAttribute(theAttr)
40 SALOMEDS_AttributeTreeNode::SALOMEDS_AttributeTreeNode(SALOMEDS::AttributeTreeNode_ptr theAttr)
41 :SALOMEDS_GenericAttribute(theAttr)
44 SALOMEDS_AttributeTreeNode::~SALOMEDS_AttributeTreeNode()
47 void SALOMEDS_AttributeTreeNode::SetFather(const _PTR(AttributeTreeNode)& value)
49 SALOMEDS_AttributeTreeNode* aTN = dynamic_cast<SALOMEDS_AttributeTreeNode*>(value.get());
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);
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);
63 bool SALOMEDS_AttributeTreeNode::HasFather()
67 Handle(SALOMEDSImpl_AttributeTreeNode) aNode = Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_local_impl);
68 ret = aNode->HasFather();
71 SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
72 ret = aNode->HasFather();
77 _PTR(AttributeTreeNode) SALOMEDS_AttributeTreeNode::GetFather()
79 SALOMEDSClient_AttributeTreeNode* aTN = NULL;
81 Handle(SALOMEDSImpl_AttributeTreeNode) aNode = Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_local_impl);
82 aTN = new SALOMEDS_AttributeTreeNode(aNode->GetFather());
85 SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
86 aTN = new SALOMEDS_AttributeTreeNode(aNode->GetFather());
88 return _PTR(AttributeTreeNode)(aTN);
91 void SALOMEDS_AttributeTreeNode::SetPrevious(const _PTR(AttributeTreeNode)& value)
93 SALOMEDS_AttributeTreeNode* aTN = dynamic_cast<SALOMEDS_AttributeTreeNode*>(value.get());
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);
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);
107 bool SALOMEDS_AttributeTreeNode::HasPrevious()
111 Handle(SALOMEDSImpl_AttributeTreeNode) aNode = Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_local_impl);
112 ret = aNode->HasPrevious();
115 SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
116 ret = aNode->HasPrevious();
121 _PTR(AttributeTreeNode) SALOMEDS_AttributeTreeNode::GetPrevious()
123 SALOMEDSClient_AttributeTreeNode* aTN = NULL;
125 Handle(SALOMEDSImpl_AttributeTreeNode) aNode = Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_local_impl);
126 aTN = new SALOMEDS_AttributeTreeNode(aNode->GetPrevious());
129 SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
130 aTN = new SALOMEDS_AttributeTreeNode(aNode->GetPrevious());
132 return _PTR(AttributeTreeNode)(aTN);
135 void SALOMEDS_AttributeTreeNode::SetNext(const _PTR(AttributeTreeNode)& value)
137 SALOMEDS_AttributeTreeNode* aTN = dynamic_cast<SALOMEDS_AttributeTreeNode*>(value.get());
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);
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);
151 bool SALOMEDS_AttributeTreeNode::HasNext()
155 Handle(SALOMEDSImpl_AttributeTreeNode) aNode = Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_local_impl);
156 ret = aNode->HasNext();
159 SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
160 ret = aNode->HasNext();
165 _PTR(AttributeTreeNode) SALOMEDS_AttributeTreeNode::GetNext()
167 SALOMEDSClient_AttributeTreeNode* aTN = NULL;
169 Handle(SALOMEDSImpl_AttributeTreeNode) aNode = Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_local_impl);
170 aTN = new SALOMEDS_AttributeTreeNode(aNode->GetNext());
173 SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
174 aTN = new SALOMEDS_AttributeTreeNode(aNode->GetNext());
176 return _PTR(AttributeTreeNode)(aTN);
179 void SALOMEDS_AttributeTreeNode::SetFirst(const _PTR(AttributeTreeNode)& value)
181 SALOMEDS_AttributeTreeNode* aTN = dynamic_cast<SALOMEDS_AttributeTreeNode*>(value.get());
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);
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);
195 bool SALOMEDS_AttributeTreeNode::HasFirst()
199 Handle(SALOMEDSImpl_AttributeTreeNode) aNode = Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_local_impl);
200 ret = aNode->HasFirst();
203 SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
204 ret = aNode->HasFirst();
209 _PTR(AttributeTreeNode) SALOMEDS_AttributeTreeNode::GetFirst()
211 SALOMEDSClient_AttributeTreeNode* aTN = NULL;
213 Handle(SALOMEDSImpl_AttributeTreeNode) aNode = Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_local_impl);
214 aTN = new SALOMEDS_AttributeTreeNode(aNode->GetFirst());
217 SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
218 aTN = new SALOMEDS_AttributeTreeNode(aNode->GetFirst());
220 return _PTR(AttributeTreeNode)(aTN);
223 void SALOMEDS_AttributeTreeNode::SetTreeID(const std::string& value)
226 Handle(SALOMEDSImpl_AttributeTreeNode) aNode = Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_local_impl);
227 aNode->SetTreeID(Standard_GUID((char*)value.c_str()));
230 SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
231 aNode->SetTreeID(value.c_str());
235 std::string SALOMEDS_AttributeTreeNode::GetTreeID()
237 TCollection_AsciiString aGUID;
239 Handle(SALOMEDSImpl_AttributeTreeNode) aNode = Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_local_impl);
241 aNode->GetTreeID().ToCString(guid);
242 aGUID = TCollection_AsciiString(guid);
245 SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
246 aGUID = TCollection_AsciiString(aNode->GetTreeID());
249 return std::string(aGUID.ToCString());
252 void SALOMEDS_AttributeTreeNode::Append(const _PTR(AttributeTreeNode)& value)
254 SALOMEDS_AttributeTreeNode* aTN = dynamic_cast<SALOMEDS_AttributeTreeNode*>(value.get());
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);
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);
268 void SALOMEDS_AttributeTreeNode::Prepend(const _PTR(AttributeTreeNode)& value)
270 SALOMEDS_AttributeTreeNode* aTN = dynamic_cast<SALOMEDS_AttributeTreeNode*>(value.get());
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);
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);
284 void SALOMEDS_AttributeTreeNode::InsertBefore(const _PTR(AttributeTreeNode)& value)
286 SALOMEDS_AttributeTreeNode* aTN = dynamic_cast<SALOMEDS_AttributeTreeNode*>(value.get());
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);
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);
300 void SALOMEDS_AttributeTreeNode::InsertAfter(const _PTR(AttributeTreeNode)& value)
302 SALOMEDS_AttributeTreeNode* aTN = dynamic_cast<SALOMEDS_AttributeTreeNode*>(value.get());
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);
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);
316 void SALOMEDS_AttributeTreeNode::Remove()
318 if(_isLocal) Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_local_impl)->Remove();
319 else SALOMEDS::AttributeTreeNode::_narrow(_corba_impl)->Remove();
322 int SALOMEDS_AttributeTreeNode::Depth()
325 if(_isLocal) aDepth = Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_local_impl)->Depth();
326 else aDepth = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl)->Depth();
330 bool SALOMEDS_AttributeTreeNode::IsRoot()
333 if(_isLocal) ret = Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_local_impl)->IsRoot();
334 else ret = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl)->IsRoot();
338 bool SALOMEDS_AttributeTreeNode::IsDescendant(const _PTR(AttributeTreeNode)& value)
341 SALOMEDS_AttributeTreeNode* aTN = dynamic_cast<SALOMEDS_AttributeTreeNode*>(value.get());
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);
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);
356 bool SALOMEDS_AttributeTreeNode::IsFather(const _PTR(AttributeTreeNode)& value)
359 SALOMEDS_AttributeTreeNode* aTN = dynamic_cast<SALOMEDS_AttributeTreeNode*>(value.get());
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);
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);
374 bool SALOMEDS_AttributeTreeNode::IsChild(const _PTR(AttributeTreeNode)& value)
377 SALOMEDS_AttributeTreeNode* aTN = dynamic_cast<SALOMEDS_AttributeTreeNode*>(value.get());
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);
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);
392 std::string SALOMEDS_AttributeTreeNode::Label()
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());