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"
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>
36 #include "SALOMEDSImpl_AttributeTreeNode.hxx"
37 #include "SALOMEDS_AttributeTreeNode.hxx"
39 SALOMEDS_AttributeTreeNode::SALOMEDS_AttributeTreeNode(const Handle(SALOMEDSImpl_AttributeTreeNode)& theAttr)
40 :SALOMEDS_GenericAttribute(theAttr)
43 SALOMEDS_AttributeTreeNode::SALOMEDS_AttributeTreeNode(SALOMEDS::AttributeTreeNode_ptr theAttr)
44 :SALOMEDS_GenericAttribute(theAttr)
47 SALOMEDS_AttributeTreeNode::~SALOMEDS_AttributeTreeNode()
50 void SALOMEDS_AttributeTreeNode::SetFather(const _PTR(AttributeTreeNode)& value)
52 SALOMEDS_AttributeTreeNode* aTN = dynamic_cast<SALOMEDS_AttributeTreeNode*>(value.get());
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);
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);
68 bool SALOMEDS_AttributeTreeNode::HasFather()
72 SALOMEDS::Locker lock;
73 Handle(SALOMEDSImpl_AttributeTreeNode) aNode =
74 Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_local_impl);
75 ret = aNode->HasFather();
78 SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
79 ret = aNode->HasFather();
84 _PTR(AttributeTreeNode) SALOMEDS_AttributeTreeNode::GetFather()
86 SALOMEDSClient_AttributeTreeNode* aTN = NULL;
88 SALOMEDS::Locker lock;
89 Handle(SALOMEDSImpl_AttributeTreeNode) aNode =
90 Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_local_impl);
91 aTN = new SALOMEDS_AttributeTreeNode(aNode->GetFather());
94 SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
95 aTN = new SALOMEDS_AttributeTreeNode(aNode->GetFather());
97 return _PTR(AttributeTreeNode)(aTN);
100 void SALOMEDS_AttributeTreeNode::SetPrevious(const _PTR(AttributeTreeNode)& value)
102 SALOMEDS_AttributeTreeNode* aTN = dynamic_cast<SALOMEDS_AttributeTreeNode*>(value.get());
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);
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);
118 bool SALOMEDS_AttributeTreeNode::HasPrevious()
122 SALOMEDS::Locker lock;
123 Handle(SALOMEDSImpl_AttributeTreeNode) aNode =
124 Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_local_impl);
125 ret = aNode->HasPrevious();
128 SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
129 ret = aNode->HasPrevious();
134 _PTR(AttributeTreeNode) SALOMEDS_AttributeTreeNode::GetPrevious()
136 SALOMEDSClient_AttributeTreeNode* aTN = NULL;
138 SALOMEDS::Locker lock;
139 Handle(SALOMEDSImpl_AttributeTreeNode) aNode =
140 Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_local_impl);
141 aTN = new SALOMEDS_AttributeTreeNode(aNode->GetPrevious());
144 SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
145 aTN = new SALOMEDS_AttributeTreeNode(aNode->GetPrevious());
147 return _PTR(AttributeTreeNode)(aTN);
150 void SALOMEDS_AttributeTreeNode::SetNext(const _PTR(AttributeTreeNode)& value)
152 SALOMEDS_AttributeTreeNode* aTN = dynamic_cast<SALOMEDS_AttributeTreeNode*>(value.get());
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);
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);
168 bool SALOMEDS_AttributeTreeNode::HasNext()
172 SALOMEDS::Locker lock;
173 Handle(SALOMEDSImpl_AttributeTreeNode) aNode =
174 Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_local_impl);
175 ret = aNode->HasNext();
178 SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
179 ret = aNode->HasNext();
184 _PTR(AttributeTreeNode) SALOMEDS_AttributeTreeNode::GetNext()
186 SALOMEDSClient_AttributeTreeNode* aTN = NULL;
188 SALOMEDS::Locker lock;
189 Handle(SALOMEDSImpl_AttributeTreeNode) aNode =
190 Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_local_impl);
191 aTN = new SALOMEDS_AttributeTreeNode(aNode->GetNext());
194 SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
195 aTN = new SALOMEDS_AttributeTreeNode(aNode->GetNext());
197 return _PTR(AttributeTreeNode)(aTN);
200 void SALOMEDS_AttributeTreeNode::SetFirst(const _PTR(AttributeTreeNode)& value)
202 SALOMEDS_AttributeTreeNode* aTN = dynamic_cast<SALOMEDS_AttributeTreeNode*>(value.get());
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);
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);
218 bool SALOMEDS_AttributeTreeNode::HasFirst()
222 SALOMEDS::Locker lock;
223 Handle(SALOMEDSImpl_AttributeTreeNode) aNode =
224 Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_local_impl);
225 ret = aNode->HasFirst();
228 SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
229 ret = aNode->HasFirst();
234 _PTR(AttributeTreeNode) SALOMEDS_AttributeTreeNode::GetFirst()
236 SALOMEDSClient_AttributeTreeNode* aTN = NULL;
238 SALOMEDS::Locker lock;
239 Handle(SALOMEDSImpl_AttributeTreeNode) aNode =
240 Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_local_impl);
241 aTN = new SALOMEDS_AttributeTreeNode(aNode->GetFirst());
244 SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
245 aTN = new SALOMEDS_AttributeTreeNode(aNode->GetFirst());
247 return _PTR(AttributeTreeNode)(aTN);
250 void SALOMEDS_AttributeTreeNode::SetTreeID(const std::string& value)
252 if(!Standard_GUID::CheckGUIDFormat((char*)value.c_str())) throw invalid_argument("Invalid GUID");
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()));
262 SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
263 aNode->SetTreeID(value.c_str());
267 std::string SALOMEDS_AttributeTreeNode::GetTreeID()
269 TCollection_AsciiString aGUID;
271 SALOMEDS::Locker lock;
272 Handle(SALOMEDSImpl_AttributeTreeNode) aNode =
273 Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_local_impl);
275 aNode->GetTreeID().ToCString(guid);
276 aGUID = TCollection_AsciiString(guid);
279 SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
280 aGUID = TCollection_AsciiString(aNode->GetTreeID());
283 return std::string(aGUID.ToCString());
286 void SALOMEDS_AttributeTreeNode::Append(const _PTR(AttributeTreeNode)& value)
288 SALOMEDS_AttributeTreeNode* aTN = dynamic_cast<SALOMEDS_AttributeTreeNode*>(value.get());
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);
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);
304 void SALOMEDS_AttributeTreeNode::Prepend(const _PTR(AttributeTreeNode)& value)
306 SALOMEDS_AttributeTreeNode* aTN = dynamic_cast<SALOMEDS_AttributeTreeNode*>(value.get());
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);
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);
322 void SALOMEDS_AttributeTreeNode::InsertBefore(const _PTR(AttributeTreeNode)& value)
324 SALOMEDS_AttributeTreeNode* aTN = dynamic_cast<SALOMEDS_AttributeTreeNode*>(value.get());
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);
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);
340 void SALOMEDS_AttributeTreeNode::InsertAfter(const _PTR(AttributeTreeNode)& value)
342 SALOMEDS_AttributeTreeNode* aTN = dynamic_cast<SALOMEDS_AttributeTreeNode*>(value.get());
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);
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);
358 void SALOMEDS_AttributeTreeNode::Remove()
362 SALOMEDS::Locker lock;
363 Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_local_impl)->Remove();
365 else SALOMEDS::AttributeTreeNode::_narrow(_corba_impl)->Remove();
368 int SALOMEDS_AttributeTreeNode::Depth()
372 SALOMEDS::Locker lock;
373 aDepth = Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_local_impl)->Depth();
375 else aDepth = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl)->Depth();
379 bool SALOMEDS_AttributeTreeNode::IsRoot()
383 SALOMEDS::Locker lock;
384 ret = Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_local_impl)->IsRoot();
386 else ret = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl)->IsRoot();
390 bool SALOMEDS_AttributeTreeNode::IsDescendant(const _PTR(AttributeTreeNode)& value)
393 SALOMEDS_AttributeTreeNode* aTN = dynamic_cast<SALOMEDS_AttributeTreeNode*>(value.get());
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);
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);
409 bool SALOMEDS_AttributeTreeNode::IsFather(const _PTR(AttributeTreeNode)& value)
412 SALOMEDS_AttributeTreeNode* aTN = dynamic_cast<SALOMEDS_AttributeTreeNode*>(value.get());
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);
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);
428 bool SALOMEDS_AttributeTreeNode::IsChild(const _PTR(AttributeTreeNode)& value)
431 SALOMEDS_AttributeTreeNode* aTN = dynamic_cast<SALOMEDS_AttributeTreeNode*>(value.get());
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);
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);
447 std::string SALOMEDS_AttributeTreeNode::Label()
451 SALOMEDS::Locker lock;
452 TCollection_AsciiString anAsciiLabel;
453 TDF_Tool::Entry(_local_impl->Label(), anAsciiLabel);
454 aLabel = std::string(anAsciiLabel.ToCString());
456 else aLabel = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl)->Label();