Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

exotkTree_TreeNode.cxx

Go to the documentation of this file.
00001 
00002 //   exotkTree_TreeNode.cxx
00004 //    Copyright (C) 2001  Stephane Routelous
00005 //
00006 //    This file is part of exoTK.
00007 //
00008 //    exoTK is free software; you can redistribute it and/or modify
00009 //    it under the terms of the GNU General Public License as published by
00010 //    the Free Software Foundation; either version 2 of the License, or
00011 //    (at your option) any later version.
00012 //
00013 //    exoTK is distributed in the hope that it will be useful,
00014 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 //    GNU General Public License for more details.
00017 //
00018 //    You should have received a copy of the GNU General Public License
00019 //    along with exoTK; if not, write to the Free Software
00020 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 
00028 #include <exotkTree_TreeNode.hxx>
00029 #ifndef  _exotkTree_ListIteratorOfListOfTreeNode_HeaderFile
00030 #include <exotkTree_ListIteratorOfListOfTreeNode.hxx>
00031 #endif
00032 #ifndef  _exotkTree_Tree_HeaderFile
00033 #include <exotkTree_Tree.hxx>
00034 #endif
00035 
00036 //
00037 IMPLEMENT_STANDARD_HANDLE(exotkTree_TreeNode, MMgt_TShared)
00038 IMPLEMENT_STANDARD_RTTI(exotkTree_TreeNode, MMgt_TShared)
00039 //
00040 // Foreach ancestors, we add a IMPLEMENT_STANDARD_SUPERTYPE and 
00041 // a IMPLEMENT_STANDARD_SUPERTYPE_ARRAY_ENTRY macro.
00042 // We must respect the order: from the direct ancestor class
00043 // to the base class.
00044 //
00045 
00046 IMPLEMENT_STANDARD_TYPE(exotkTree_TreeNode)
00047 IMPLEMENT_STANDARD_SUPERTYPE(MMgt_TShared) 
00048 IMPLEMENT_STANDARD_SUPERTYPE(Standard_Transient)
00049 IMPLEMENT_STANDARD_SUPERTYPE_ARRAY()
00050 IMPLEMENT_STANDARD_SUPERTYPE_ARRAY_ENTRY(MMgt_TShared)
00051 IMPLEMENT_STANDARD_SUPERTYPE_ARRAY_ENTRY(Standard_Transient)
00052 IMPLEMENT_STANDARD_SUPERTYPE_ARRAY_END()
00053 IMPLEMENT_STANDARD_TYPE_END(exotkTree_TreeNode)
00054 
00055 
00056 //==================================================================================
00057 // Function name        : exotkTree_TreeNode::exotkTree_TreeNode
00058 //==================================================================================
00059 // Written by       : Stephane Routelous - 2001-11-07 19:47:42
00060 // Description      : 
00061 // Return type          : 
00062 //==================================================================================
00063 exotkTree_TreeNode::exotkTree_TreeNode()
00064 {
00065         myIsChecked = Standard_False;
00066 }
00067 
00068 
00069 //==================================================================================
00070 // Function name        : exotkTree_TreeNode::~exotkTree_TreeNode
00071 //==================================================================================
00072 // Written by       : Stephane Routelous - 2001-11-07 19:47:44
00073 // Description      : 
00074 // Return type          : 
00075 //==================================================================================
00076 exotkTree_TreeNode::~exotkTree_TreeNode()
00077 {
00078         SetTree(Handle_exotkTree_Tree());
00079         SetParent(Handle_exotkTree_TreeNode());
00080         SetData(Handle_Standard_Transient());
00081 }
00082 
00083 //==================================================================================
00084 // Function name        : exotkTree_TreeNode::SetData
00085 //==================================================================================
00086 // Written by       : Stephane Routelous - 2001-11-07 19:47:45
00087 // Description      : 
00088 // Return type          : void 
00089 //==================================================================================
00090 // Argument         : const Handle_Standard_Transient& aData
00091 void exotkTree_TreeNode::SetData(const Handle_Standard_Transient& aData)
00092 {
00093         myData = aData;
00094 }
00095 
00096 //==================================================================================
00097 // Function name        : exotkTree_TreeNode::SetChecked
00098 //==================================================================================
00099 // Written by       : Stephane Routelous - 2001-11-07 19:47:47
00100 // Description      : 
00101 // Return type          : Standard_Boolean 
00102 //==================================================================================
00103 // Argument         : const Standard_Boolean aCheckStatus
00104 Standard_Boolean exotkTree_TreeNode::SetChecked(const Standard_Boolean aCheckStatus)
00105 {
00106         Standard_Boolean theOldStatus = myIsChecked;
00107         myIsChecked = aCheckStatus;
00108         return theOldStatus;
00109 }
00110 
00111 //==================================================================================
00112 // Function name        : exotkTree_TreeNode::IsChecked
00113 //==================================================================================
00114 // Written by       : Stephane Routelous - 2001-11-07 19:47:49
00115 // Description      : 
00116 // Return type          : Standard_Boolean 
00117 //==================================================================================
00118 Standard_Boolean exotkTree_TreeNode::IsChecked()
00119 {
00120         return myIsChecked;
00121 }
00122 
00123 
00124 //==================================================================================
00125 // Function name        : exotkTree_TreeNode::Data
00126 //==================================================================================
00127 // Written by       : Stephane Routelous - 2001-11-07 19:47:51
00128 // Description      : 
00129 // Return type          : Handle_Standard_Transient 
00130 //==================================================================================
00131 Handle_Standard_Transient exotkTree_TreeNode::Data()
00132 {
00133         return myData;
00134 }
00135 
00136 //==================================================================================
00137 // Function name        : exotkTree_TreeNode::HasData
00138 //==================================================================================
00139 // Written by       : Stephane Routelous - 2001-11-07 19:47:52
00140 // Description      : 
00141 // Return type          : Standard_Boolean 
00142 //==================================================================================
00143 Standard_Boolean exotkTree_TreeNode::HasData()
00144 {
00145         return (!myData.IsNull());
00146 }
00147 
00148 //==================================================================================
00149 // Function name        : exotkTree_TreeNode::IsRoot
00150 //==================================================================================
00151 // Written by       : Stephane Routelous - 2001-11-07 19:47:54
00152 // Description      : 
00153 // Return type          : Standard_Boolean 
00154 //==================================================================================
00155 Standard_Boolean exotkTree_TreeNode::IsRoot()
00156 {
00157         return (myParent.IsNull() && !myTree.IsNull());
00158 }
00159 
00160 //==================================================================================
00161 // Function name        : exotkTree_TreeNode::HasChildren
00162 //==================================================================================
00163 // Written by       : Stephane Routelous - 2001-11-07 19:47:55
00164 // Description      : 
00165 // Return type          : Standard_Boolean 
00166 //==================================================================================
00167 Standard_Boolean exotkTree_TreeNode::HasChildren()
00168 {
00169         return (!myChildren.IsEmpty());
00170 }
00171 
00172 //==================================================================================
00173 // Function name        : exotkTree_TreeNode::Children
00174 //==================================================================================
00175 // Written by       : Stephane Routelous - 2001-11-07 19:47:57
00176 // Description      : 
00177 // Return type          : void 
00178 //==================================================================================
00179 // Argument         : exotkTree_ListOfTreeNode& aChildList
00180 void exotkTree_TreeNode::Children(exotkTree_ListOfTreeNode& aChildList)
00181 {
00182         aChildList = myChildren;
00183 }
00184 
00185 //==================================================================================
00186 // Function name        : exotkTree_TreeNode::HasParent
00187 //==================================================================================
00188 // Written by       : Stephane Routelous - 2001-11-07 19:47:59
00189 // Description      : 
00190 // Return type          : Standard_Boolean 
00191 //==================================================================================
00192 Standard_Boolean exotkTree_TreeNode::HasParent()
00193 {
00194         return (!myParent.IsNull());
00195 }
00196 
00197 //==================================================================================
00198 // Function name        : exotkTree_TreeNode::Parent
00199 //==================================================================================
00200 // Written by       : Stephane Routelous - 2001-11-07 19:48:01
00201 // Description      : 
00202 // Return type          : Handle_exotkTree_TreeNode 
00203 //==================================================================================
00204 Handle_exotkTree_TreeNode exotkTree_TreeNode::Parent()
00205 {
00206         return myParent;
00207 }
00208 
00209 //==================================================================================
00210 // Function name        : exotkTree_TreeNode::SetParent
00211 //==================================================================================
00212 // Written by       : Stephane Routelous - 2001-11-07 19:48:03
00213 // Description      : 
00214 // Return type          : void 
00215 //==================================================================================
00216 // Argument         : const Handle_exotkTree_TreeNode& aParent
00217 void exotkTree_TreeNode::SetParent(const Handle_exotkTree_TreeNode& aParent)
00218 {
00219         myParent = aParent;
00220 }
00221 
00222 //==================================================================================
00223 // Function name        : exotkTree_TreeNode::SetTree
00224 //==================================================================================
00225 // Written by       : Stephane Routelous - 2001-11-07 19:48:05
00226 // Description      : 
00227 // Return type          : void 
00228 //==================================================================================
00229 // Argument         : const Handle_exotkTree_Tree& aTree
00230 void exotkTree_TreeNode::SetTree(const Handle_exotkTree_Tree& aTree)
00231 {
00232         myTree = aTree;
00233 }
00234 
00235 //==================================================================================
00236 // Function name        : exotkTree_TreeNode::Tree
00237 //==================================================================================
00238 // Written by       : Stephane Routelous - 2001-11-07 19:48:06
00239 // Description      : 
00240 // Return type          : Handle_exotkTree_Tree 
00241 //==================================================================================
00242 Handle_exotkTree_Tree exotkTree_TreeNode::Tree()
00243 {
00244         return myTree;
00245 }
00246 
00247 //==================================================================================
00248 // Function name        : exotkTree_TreeNode::HasTree
00249 //==================================================================================
00250 // Written by       : Stephane Routelous - 2001-11-07 19:48:08
00251 // Description      : 
00252 // Return type          : Standard_Boolean 
00253 //==================================================================================
00254 Standard_Boolean exotkTree_TreeNode::HasTree()
00255 {
00256         return (!myTree.IsNull());
00257 }
00258 
00259 //==================================================================================
00260 // Function name        : exotkTree_TreeNode::SetName
00261 //==================================================================================
00262 // Written by       : Stephane Routelous - 2001-11-07 19:48:10
00263 // Description      : 
00264 // Return type          : TCollection_AsciiString 
00265 //==================================================================================
00266 // Argument         : const TCollection_AsciiString& aName
00267 TCollection_AsciiString exotkTree_TreeNode::SetName(const TCollection_AsciiString& aName)
00268 {
00269         TCollection_AsciiString theOldName = myName;
00270         myName = aName;
00271         return theOldName;
00272 }
00273 
00274 //==================================================================================
00275 // Function name        : exotkTree_TreeNode::Name
00276 //==================================================================================
00277 // Written by       : Stephane Routelous - 2001-11-07 19:48:12
00278 // Description      : 
00279 // Return type          : TCollection_AsciiString 
00280 //==================================================================================
00281 TCollection_AsciiString exotkTree_TreeNode::Name()
00282 {
00283         return myName;
00284 }
00285 
00286 //==================================================================================
00287 // Function name        : exotkTree_TreeNode::FindChild
00288 //==================================================================================
00289 // Written by       : Stephane Routelous - 2001-11-07 19:48:14
00290 // Description      : 
00291 // Return type          : Standard_Boolean 
00292 //==================================================================================
00293 // Argument         : const TCollection_AsciiString& aNodeToFind
00294 // Argument         : Handle_exotkTree_TreeNode& aFoundNode
00295 Standard_Boolean exotkTree_TreeNode::FindChild(const TCollection_AsciiString& aNodeToFind, Handle_exotkTree_TreeNode& aFoundNode)
00296 {
00297         if (!HasChildren())
00298                 return Standard_False;
00299         
00300         exotkTree_ListIteratorOfListOfTreeNode theIterator;
00301         Standard_Boolean theChildIsFound = Standard_False;
00302         for (theIterator.Initialize(myChildren); theIterator.More() && !theChildIsFound; theIterator.Next())
00303         {
00304                 if (theIterator.Value()->Name() == aNodeToFind)
00305                 {
00306                         theChildIsFound = Standard_True;
00307                         aFoundNode = theIterator.Value();
00308                 }
00309         }
00310         
00311         return theChildIsFound;
00312 }
00313 
00314 
00315 //==================================================================================
00316 // Function name        : exotkTree_TreeNode::FindChild
00317 //==================================================================================
00318 // Written by       : Stephane Routelous - 2001-11-07 19:48:16
00319 // Description      : 
00320 // Return type          : Standard_Boolean 
00321 //==================================================================================
00322 // Argument         : const Handle_exotkTree_TreeNode& aNodeToFind
00323 // Argument         : exotkTree_ListIteratorOfListOfTreeNode& anIterator
00324 Standard_Boolean exotkTree_TreeNode::FindChild(const Handle_exotkTree_TreeNode& aNodeToFind, exotkTree_ListIteratorOfListOfTreeNode& anIterator)
00325 {
00326         if (!HasChildren())
00327                 return Standard_False;
00328         
00329         Standard_Boolean theChildIsFound = Standard_False;
00330         for (anIterator.Initialize(myChildren); anIterator.More() && !theChildIsFound; anIterator.Next())
00331         {
00332                 if (anIterator.Value() == aNodeToFind)
00333                 {
00334                         theChildIsFound = Standard_True;
00335                 }
00336         }
00337         
00338         return theChildIsFound;
00339 }
00340 
00341 //==================================================================================
00342 // Function name        : exotkTree_TreeNode::FindChild
00343 //==================================================================================
00344 // Written by       : Stephane Routelous - 2001-11-07 19:48:18
00345 // Description      : 
00346 // Return type          : Standard_Boolean 
00347 //==================================================================================
00348 // Argument         : const TCollection_AsciiString& aNodeToFind
00349 // Argument         : exotkTree_ListIteratorOfListOfTreeNode& anIterator
00350 Standard_Boolean exotkTree_TreeNode::FindChild(const TCollection_AsciiString& aNodeToFind, exotkTree_ListIteratorOfListOfTreeNode& anIterator)
00351 {
00352         if (!HasChildren())
00353                 return Standard_False;
00354         
00355         Standard_Boolean theChildIsFound = Standard_False;
00356         for (anIterator.Initialize(myChildren); anIterator.More() && !theChildIsFound; anIterator.Next())
00357         {
00358                 if (anIterator.Value()->Name() == aNodeToFind)
00359                 {
00360                         theChildIsFound = Standard_True;
00361                 }
00362         }
00363         
00364         return theChildIsFound;
00365 }
00366 
00367 //==================================================================================
00368 // Function name        : exotkTree_TreeNode::InsertChildAfter
00369 //==================================================================================
00370 // Written by       : Stephane Routelous - 2001-11-07 19:48:21
00371 // Description      : 
00372 // Return type          : Standard_Boolean 
00373 //==================================================================================
00374 // Argument         : const Handle_exotkTree_TreeNode& aChildToInsert
00375 // Argument         : const Handle_exotkTree_TreeNode& After
00376 Standard_Boolean exotkTree_TreeNode::InsertChildAfter(const Handle_exotkTree_TreeNode& aChildToInsert, const Handle_exotkTree_TreeNode& After)
00377 {
00378         if (!HasChildren())
00379                 return Standard_False;
00380         
00381         if (aChildToInsert->HasParent())
00382                 return Standard_False;
00383         
00384         
00385         exotkTree_ListIteratorOfListOfTreeNode theIterator;
00386         
00387         if (!FindChild(After, theIterator))
00388                 return Standard_False;
00389         
00390         myChildren.InsertAfter(aChildToInsert, theIterator);
00391         aChildToInsert->SetParent(this);
00392         if ( !myTree.IsNull() )
00393         {
00394                 myTree->UpdateNode(this);
00395         }
00396         
00397         return Standard_True;
00398 }
00399 
00400 //==================================================================================
00401 // Function name        : exotkTree_TreeNode::InsertChildBefore
00402 //==================================================================================
00403 // Written by       : Stephane Routelous - 2001-11-07 19:48:23
00404 // Description      : 
00405 // Return type          : Standard_Boolean 
00406 //==================================================================================
00407 // Argument         : const Handle_exotkTree_TreeNode& aChildToInsert
00408 // Argument         : const Handle_exotkTree_TreeNode& Before
00409 Standard_Boolean exotkTree_TreeNode::InsertChildBefore(const Handle_exotkTree_TreeNode& aChildToInsert, const Handle_exotkTree_TreeNode& Before)
00410 {
00411         if (!HasChildren())
00412                 return Standard_False;
00413         
00414         if (aChildToInsert->HasParent())
00415                 return Standard_False;
00416         
00417         
00418         exotkTree_ListIteratorOfListOfTreeNode theIterator;
00419         
00420         if (!FindChild(Before, theIterator))
00421                 return Standard_False;
00422         
00423         myChildren.InsertBefore(aChildToInsert, theIterator);
00424         aChildToInsert->SetParent(this);
00425         if ( !myTree.IsNull() )
00426         {
00427                 myTree->UpdateNode(this);
00428         }
00429         
00430         return Standard_True;
00431 }
00432 
00433 //==================================================================================
00434 // Function name        : exotkTree_TreeNode::InsertChildAfter
00435 //==================================================================================
00436 // Written by       : Stephane Routelous - 2001-11-07 19:48:25
00437 // Description      : 
00438 // Return type          : Standard_Boolean 
00439 //==================================================================================
00440 // Argument         : const Handle_exotkTree_TreeNode& aChildToInsert
00441 // Argument         : const TCollection_AsciiString& After
00442 Standard_Boolean exotkTree_TreeNode::InsertChildAfter(const Handle_exotkTree_TreeNode& aChildToInsert, const TCollection_AsciiString& After)
00443 {
00444         if (!HasChildren())
00445                 return Standard_False;
00446         
00447         if (aChildToInsert->HasParent())
00448                 return Standard_False;
00449         
00450         
00451         exotkTree_ListIteratorOfListOfTreeNode theIterator;
00452         
00453         if (!FindChild(After, theIterator))
00454                 return Standard_False;
00455         
00456         myChildren.InsertAfter(aChildToInsert, theIterator);
00457         aChildToInsert->SetParent(this);
00458                 if ( !myTree.IsNull() )
00459         {
00460                 myTree->UpdateNode(this);
00461         }
00462 
00463         return Standard_True;
00464 }
00465 
00466 
00467 //==================================================================================
00468 // Function name        : exotkTree_TreeNode::InsertChildBefore
00469 //==================================================================================
00470 // Written by       : Stephane Routelous - 2001-11-07 19:48:27
00471 // Description      : 
00472 // Return type          : Standard_Boolean 
00473 //==================================================================================
00474 // Argument         : const Handle_exotkTree_TreeNode& aChildToInsert
00475 // Argument         : const TCollection_AsciiString& Before
00476 Standard_Boolean exotkTree_TreeNode::InsertChildBefore(const Handle_exotkTree_TreeNode& aChildToInsert, const TCollection_AsciiString& Before)
00477 {
00478         if (!HasChildren())
00479                 return Standard_False;
00480         
00481         if (aChildToInsert->HasParent())
00482                 return Standard_False;
00483         
00484         
00485         exotkTree_ListIteratorOfListOfTreeNode theIterator;
00486         
00487         if (!FindChild(Before, theIterator))
00488                 return Standard_False;
00489         
00490         myChildren.InsertBefore(aChildToInsert, theIterator);
00491         aChildToInsert->SetParent(this);
00492         if ( !myTree.IsNull() )
00493         {
00494                 myTree->UpdateNode(this);
00495         }
00496         
00497         return Standard_True;
00498 }
00499 
00500 
00501 //==================================================================================
00502 // Function name        : exotkTree_TreeNode::AppendChild
00503 //==================================================================================
00504 // Written by       : Stephane Routelous - 2001-11-07 19:48:30
00505 // Description      : 
00506 // Return type          : Standard_Boolean 
00507 //==================================================================================
00508 // Argument         : const Handle_exotkTree_TreeNode &aChildToAppend
00509 Standard_Boolean exotkTree_TreeNode::AppendChild(const Handle_exotkTree_TreeNode &aChildToAppend)
00510 {
00511         if (aChildToAppend->HasParent())
00512                 return Standard_False;
00513         
00514         myChildren.Append(aChildToAppend);
00515         aChildToAppend->SetParent(this);
00516         if ( !myTree.IsNull() )
00517         {
00518                 myTree->NotifyInsertItem(this,aChildToAppend,Handle_exotkTree_TreeNode());
00519         }
00520         return Standard_True;
00521 }
00522 
00523 //==================================================================================
00524 // Function name        : exotkTree_TreeNode::PrependChild
00525 //==================================================================================
00526 // Written by       : Stephane Routelous - 2001-11-07 19:48:32
00527 // Description      : 
00528 // Return type          : Standard_Boolean 
00529 //==================================================================================
00530 // Argument         : const Handle_exotkTree_TreeNode &aChildToPrepend
00531 Standard_Boolean exotkTree_TreeNode::PrependChild(const Handle_exotkTree_TreeNode &aChildToPrepend)
00532 {
00533         if (aChildToPrepend->HasParent())
00534                 return Standard_False;
00535         
00536         myChildren.Prepend(aChildToPrepend);
00537         aChildToPrepend->SetParent(this);
00538         if ( !myTree.IsNull() )
00539         {
00540                 myTree->UpdateNode(this);
00541         }
00542         return Standard_True;
00543 }
00544 
00545 
00546 //==================================================================================
00547 // Function name        : exotkTree_TreeNode::FirstChild
00548 //==================================================================================
00549 // Written by       : Stephane Routelous - 2002-01-12 22:42:49
00550 // Description      : 
00551 // Return type          : Handle_exotkTree_TreeNode 
00552 //==================================================================================
00553 Handle_exotkTree_TreeNode exotkTree_TreeNode::FirstChild()
00554 {
00555         Handle_exotkTree_TreeNode theFirstChild;
00556         if ( HasChildren() )
00557         {
00558                 theFirstChild = myChildren.First();
00559         }
00560         return theFirstChild;
00561 }
00562 
00563 //==================================================================================
00564 // Function name        : exotkTree_TreeNode::LastChild
00565 //==================================================================================
00566 // Written by       : Stephane Routelous - 2002-01-12 22:45:00
00567 // Description      : 
00568 // Return type          : Handle_exotkTree_TreeNode 
00569 //==================================================================================
00570 Handle_exotkTree_TreeNode exotkTree_TreeNode::LastChild()
00571 {
00572         Handle_exotkTree_TreeNode theLastChild;
00573         if ( HasChildren() )
00574         {
00575                 theLastChild = myChildren.Last();
00576         }
00577         return theLastChild;
00578 }

Generated on Wed Jan 23 12:16:45 2002 for exotk by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001