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/ or email : webmaster.salome@opencascade.com
20 // File : SALOMEDS_AttributeTreeNode.cxx
21 // Author : Sergey RUIN
24 #include "SALOMEDS_AttributeTreeNode.hxx"
25 #include "SALOMEDS.hxx"
29 #include <TCollection_AsciiString.hxx>
30 #include <TCollection_ExtendedString.hxx>
31 #include <Standard_GUID.hxx>
32 #include <TDF_Label.hxx>
33 #include <TDF_Tool.hxx>
35 #include "SALOMEDSImpl_AttributeTreeNode.hxx"
36 #include "SALOMEDS_AttributeTreeNode.hxx"
38 SALOMEDS_AttributeTreeNode::SALOMEDS_AttributeTreeNode(const Handle(SALOMEDSImpl_AttributeTreeNode)& theAttr)
39 :SALOMEDS_GenericAttribute(theAttr)
42 SALOMEDS_AttributeTreeNode::SALOMEDS_AttributeTreeNode(SALOMEDS::AttributeTreeNode_ptr theAttr)
43 :SALOMEDS_GenericAttribute(theAttr)
46 SALOMEDS_AttributeTreeNode::~SALOMEDS_AttributeTreeNode()
49 void SALOMEDS_AttributeTreeNode::SetFather(const _PTR(AttributeTreeNode)& value)
51 SALOMEDS_AttributeTreeNode* aTN = dynamic_cast<SALOMEDS_AttributeTreeNode*>(value.get());
54 SALOMEDS::Locker lock;
55 Handle(SALOMEDSImpl_AttributeTreeNode) aNode, aFather;
56 aNode = Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_local_impl);
57 aFather = Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(aTN->_local_impl);
58 aNode->SetFather(aFather);
61 SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
62 SALOMEDS::AttributeTreeNode_var aFather = SALOMEDS::AttributeTreeNode::_narrow(aTN->_corba_impl);
63 aNode->SetFather(aFather);
67 bool SALOMEDS_AttributeTreeNode::HasFather()
71 SALOMEDS::Locker lock;
72 Handle(SALOMEDSImpl_AttributeTreeNode) aNode =
73 Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_local_impl);
74 ret = aNode->HasFather();
77 SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
78 ret = aNode->HasFather();
83 _PTR(AttributeTreeNode) SALOMEDS_AttributeTreeNode::GetFather()
85 SALOMEDSClient_AttributeTreeNode* aTN = NULL;
87 SALOMEDS::Locker lock;
88 Handle(SALOMEDSImpl_AttributeTreeNode) aNode =
89 Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_local_impl);
90 aTN = new SALOMEDS_AttributeTreeNode(aNode->GetFather());
93 SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
94 aTN = new SALOMEDS_AttributeTreeNode(aNode->GetFather());
96 return _PTR(AttributeTreeNode)(aTN);
99 void SALOMEDS_AttributeTreeNode::SetPrevious(const _PTR(AttributeTreeNode)& value)
101 SALOMEDS_AttributeTreeNode* aTN = dynamic_cast<SALOMEDS_AttributeTreeNode*>(value.get());
104 SALOMEDS::Locker lock;
105 Handle(SALOMEDSImpl_AttributeTreeNode) aNode, aPrev;
106 aNode = Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_local_impl);
107 aPrev = Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(aTN->_local_impl);
108 aNode->SetPrevious(aPrev);
111 SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
112 SALOMEDS::AttributeTreeNode_var aPrev = SALOMEDS::AttributeTreeNode::_narrow(aTN->_corba_impl);
113 aNode->SetPrevious(aPrev);
117 bool SALOMEDS_AttributeTreeNode::HasPrevious()
121 SALOMEDS::Locker lock;
122 Handle(SALOMEDSImpl_AttributeTreeNode) aNode =
123 Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_local_impl);
124 ret = aNode->HasPrevious();
127 SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
128 ret = aNode->HasPrevious();
133 _PTR(AttributeTreeNode) SALOMEDS_AttributeTreeNode::GetPrevious()
135 SALOMEDSClient_AttributeTreeNode* aTN = NULL;
137 SALOMEDS::Locker lock;
138 Handle(SALOMEDSImpl_AttributeTreeNode) aNode =
139 Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_local_impl);
140 aTN = new SALOMEDS_AttributeTreeNode(aNode->GetPrevious());
143 SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
144 aTN = new SALOMEDS_AttributeTreeNode(aNode->GetPrevious());
146 return _PTR(AttributeTreeNode)(aTN);
149 void SALOMEDS_AttributeTreeNode::SetNext(const _PTR(AttributeTreeNode)& value)
151 SALOMEDS_AttributeTreeNode* aTN = dynamic_cast<SALOMEDS_AttributeTreeNode*>(value.get());
154 SALOMEDS::Locker lock;
155 Handle(SALOMEDSImpl_AttributeTreeNode) aNode, aNext;
156 aNode = Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_local_impl);
157 aNext = Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(aTN->_local_impl);
158 aNode->SetNext(aNext);
161 SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
162 SALOMEDS::AttributeTreeNode_var aNext = SALOMEDS::AttributeTreeNode::_narrow(aTN->_corba_impl);
163 aNode->SetNext(aNext);
167 bool SALOMEDS_AttributeTreeNode::HasNext()
171 SALOMEDS::Locker lock;
172 Handle(SALOMEDSImpl_AttributeTreeNode) aNode =
173 Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_local_impl);
174 ret = aNode->HasNext();
177 SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
178 ret = aNode->HasNext();
183 _PTR(AttributeTreeNode) SALOMEDS_AttributeTreeNode::GetNext()
185 SALOMEDSClient_AttributeTreeNode* aTN = NULL;
187 SALOMEDS::Locker lock;
188 Handle(SALOMEDSImpl_AttributeTreeNode) aNode =
189 Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_local_impl);
190 aTN = new SALOMEDS_AttributeTreeNode(aNode->GetNext());
193 SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
194 aTN = new SALOMEDS_AttributeTreeNode(aNode->GetNext());
196 return _PTR(AttributeTreeNode)(aTN);
199 void SALOMEDS_AttributeTreeNode::SetFirst(const _PTR(AttributeTreeNode)& value)
201 SALOMEDS_AttributeTreeNode* aTN = dynamic_cast<SALOMEDS_AttributeTreeNode*>(value.get());
204 SALOMEDS::Locker lock;
205 Handle(SALOMEDSImpl_AttributeTreeNode) aNode, aFirst;
206 aNode = Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_local_impl);
207 aFirst = Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(aTN->_local_impl);
208 aNode->SetFirst(aFirst);
211 SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
212 SALOMEDS::AttributeTreeNode_var aFirst = SALOMEDS::AttributeTreeNode::_narrow(aTN->_corba_impl);
213 aNode->SetFirst(aFirst);
217 bool SALOMEDS_AttributeTreeNode::HasFirst()
221 SALOMEDS::Locker lock;
222 Handle(SALOMEDSImpl_AttributeTreeNode) aNode =
223 Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_local_impl);
224 ret = aNode->HasFirst();
227 SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
228 ret = aNode->HasFirst();
233 _PTR(AttributeTreeNode) SALOMEDS_AttributeTreeNode::GetFirst()
235 SALOMEDSClient_AttributeTreeNode* aTN = NULL;
237 SALOMEDS::Locker lock;
238 Handle(SALOMEDSImpl_AttributeTreeNode) aNode =
239 Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_local_impl);
240 aTN = new SALOMEDS_AttributeTreeNode(aNode->GetFirst());
243 SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
244 aTN = new SALOMEDS_AttributeTreeNode(aNode->GetFirst());
246 return _PTR(AttributeTreeNode)(aTN);
249 void SALOMEDS_AttributeTreeNode::SetTreeID(const std::string& value)
253 SALOMEDS::Locker lock;
254 Handle(SALOMEDSImpl_AttributeTreeNode) aNode =
255 Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_local_impl);
256 aNode->SetTreeID(Standard_GUID((char*)value.c_str()));
259 SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
260 aNode->SetTreeID(value.c_str());
264 std::string SALOMEDS_AttributeTreeNode::GetTreeID()
266 TCollection_AsciiString aGUID;
268 SALOMEDS::Locker lock;
269 Handle(SALOMEDSImpl_AttributeTreeNode) aNode =
270 Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_local_impl);
272 aNode->GetTreeID().ToCString(guid);
273 aGUID = TCollection_AsciiString(guid);
276 SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
277 aGUID = TCollection_AsciiString(aNode->GetTreeID());
280 return std::string(aGUID.ToCString());
283 void SALOMEDS_AttributeTreeNode::Append(const _PTR(AttributeTreeNode)& value)
285 SALOMEDS_AttributeTreeNode* aTN = dynamic_cast<SALOMEDS_AttributeTreeNode*>(value.get());
288 SALOMEDS::Locker lock;
289 Handle(SALOMEDSImpl_AttributeTreeNode) aNode, anOther;
290 aNode = Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_local_impl);
291 anOther = Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(aTN->_local_impl);
292 aNode->Append(anOther);
295 SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
296 SALOMEDS::AttributeTreeNode_var anOther = SALOMEDS::AttributeTreeNode::_narrow(aTN->_corba_impl);
297 aNode->Append(anOther);
301 void SALOMEDS_AttributeTreeNode::Prepend(const _PTR(AttributeTreeNode)& value)
303 SALOMEDS_AttributeTreeNode* aTN = dynamic_cast<SALOMEDS_AttributeTreeNode*>(value.get());
306 SALOMEDS::Locker lock;
307 Handle(SALOMEDSImpl_AttributeTreeNode) aNode, anOther;
308 aNode = Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_local_impl);
309 anOther = Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(aTN->_local_impl);
310 aNode->Prepend(anOther);
313 SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
314 SALOMEDS::AttributeTreeNode_var anOther = SALOMEDS::AttributeTreeNode::_narrow(aTN->_corba_impl);
315 aNode->Prepend(anOther);
319 void SALOMEDS_AttributeTreeNode::InsertBefore(const _PTR(AttributeTreeNode)& value)
321 SALOMEDS_AttributeTreeNode* aTN = dynamic_cast<SALOMEDS_AttributeTreeNode*>(value.get());
324 SALOMEDS::Locker lock;
325 Handle(SALOMEDSImpl_AttributeTreeNode) aNode, anOther;
326 aNode = Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_local_impl);
327 anOther = Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(aTN->_local_impl);
328 aNode->InsertBefore(anOther);
331 SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
332 SALOMEDS::AttributeTreeNode_var anOther = SALOMEDS::AttributeTreeNode::_narrow(aTN->_corba_impl);
333 aNode->InsertBefore(anOther);
337 void SALOMEDS_AttributeTreeNode::InsertAfter(const _PTR(AttributeTreeNode)& value)
339 SALOMEDS_AttributeTreeNode* aTN = dynamic_cast<SALOMEDS_AttributeTreeNode*>(value.get());
342 SALOMEDS::Locker lock;
343 Handle(SALOMEDSImpl_AttributeTreeNode) aNode, anOther;
344 aNode = Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_local_impl);
345 anOther = Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(aTN->_local_impl);
346 aNode->InsertAfter(anOther);
349 SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
350 SALOMEDS::AttributeTreeNode_var anOther = SALOMEDS::AttributeTreeNode::_narrow(aTN->_corba_impl);
351 aNode->InsertAfter(anOther);
355 void SALOMEDS_AttributeTreeNode::Remove()
359 SALOMEDS::Locker lock;
360 Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_local_impl)->Remove();
362 else SALOMEDS::AttributeTreeNode::_narrow(_corba_impl)->Remove();
365 int SALOMEDS_AttributeTreeNode::Depth()
369 SALOMEDS::Locker lock;
370 aDepth = Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_local_impl)->Depth();
372 else aDepth = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl)->Depth();
376 bool SALOMEDS_AttributeTreeNode::IsRoot()
380 SALOMEDS::Locker lock;
381 ret = Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_local_impl)->IsRoot();
383 else ret = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl)->IsRoot();
387 bool SALOMEDS_AttributeTreeNode::IsDescendant(const _PTR(AttributeTreeNode)& value)
390 SALOMEDS_AttributeTreeNode* aTN = dynamic_cast<SALOMEDS_AttributeTreeNode*>(value.get());
392 SALOMEDS::Locker lock;
393 Handle(SALOMEDSImpl_AttributeTreeNode) aNode, anOther;
394 aNode = Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_local_impl);
395 anOther = Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(aTN->_local_impl);
396 ret = aNode->IsDescendant(anOther);
399 SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
400 SALOMEDS::AttributeTreeNode_var anOther = SALOMEDS::AttributeTreeNode::_narrow(aTN->_corba_impl);
401 ret = aNode->IsDescendant(anOther);
406 bool SALOMEDS_AttributeTreeNode::IsFather(const _PTR(AttributeTreeNode)& value)
409 SALOMEDS_AttributeTreeNode* aTN = dynamic_cast<SALOMEDS_AttributeTreeNode*>(value.get());
411 SALOMEDS::Locker lock;
412 Handle(SALOMEDSImpl_AttributeTreeNode) aNode, anOther;
413 aNode = Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_local_impl);
414 anOther = Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(aTN->_local_impl);
415 ret = aNode->IsFather(anOther);
418 SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
419 SALOMEDS::AttributeTreeNode_var anOther = SALOMEDS::AttributeTreeNode::_narrow(aTN->_corba_impl);
420 ret = aNode->IsFather(anOther);
425 bool SALOMEDS_AttributeTreeNode::IsChild(const _PTR(AttributeTreeNode)& value)
428 SALOMEDS_AttributeTreeNode* aTN = dynamic_cast<SALOMEDS_AttributeTreeNode*>(value.get());
430 SALOMEDS::Locker lock;
431 Handle(SALOMEDSImpl_AttributeTreeNode) aNode, anOther;
432 aNode = Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_local_impl);
433 anOther = Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(aTN->_local_impl);
434 ret = aNode->IsChild(anOther);
437 SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
438 SALOMEDS::AttributeTreeNode_var anOther = SALOMEDS::AttributeTreeNode::_narrow(aTN->_corba_impl);
439 ret = aNode->IsChild(anOther);
444 std::string SALOMEDS_AttributeTreeNode::Label()
448 SALOMEDS::Locker lock;
449 TCollection_AsciiString anAsciiLabel;
450 TDF_Tool::Entry(_local_impl->Label(), anAsciiLabel);
451 aLabel = std::string(anAsciiLabel.ToCString());
453 else aLabel = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl)->Label();