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

exotkTree_Tree.cxx

Go to the documentation of this file.
00001 
00002 //   exotkTree_Tree.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_Tree.hxx>
00029 
00030 #ifndef  _TCollection_AsciiString_HeaderFile
00031 #include <TCollection_AsciiString.hxx>
00032 #endif
00033 #ifndef  _exotkTree_TreeNode_HeaderFile
00034 #include <exotkTree_TreeNode.hxx>
00035 #endif
00036 #ifndef  _exotkTree_ListIteratorOfListOfTreeNode_HeaderFile
00037 #include <exotkTree_ListIteratorOfListOfTreeNode.hxx>
00038 #endif
00039 #ifndef  _exotkTree_TreeUpdator_HeaderFile
00040 #include <exotkTree_TreeUpdator.hxx>
00041 #endif
00042 
00043 
00044 //
00045 IMPLEMENT_STANDARD_HANDLE(exotkTree_Tree, MMgt_TShared)
00046 IMPLEMENT_STANDARD_RTTI(exotkTree_Tree, MMgt_TShared)
00047 //
00048 // Foreach ancestors, we add a IMPLEMENT_STANDARD_SUPERTYPE and 
00049 // a IMPLEMENT_STANDARD_SUPERTYPE_ARRAY_ENTRY macro.
00050 // We must respect the order: from the direct ancestor class
00051 // to the base class.
00052 //
00053 
00054 IMPLEMENT_STANDARD_TYPE(exotkTree_Tree)
00055 IMPLEMENT_STANDARD_SUPERTYPE(MMgt_TShared) 
00056 IMPLEMENT_STANDARD_SUPERTYPE(Standard_Transient)
00057 IMPLEMENT_STANDARD_SUPERTYPE_ARRAY()
00058 IMPLEMENT_STANDARD_SUPERTYPE_ARRAY_ENTRY(MMgt_TShared)
00059 IMPLEMENT_STANDARD_SUPERTYPE_ARRAY_ENTRY(Standard_Transient)
00060 IMPLEMENT_STANDARD_SUPERTYPE_ARRAY_END()
00061 IMPLEMENT_STANDARD_TYPE_END(exotkTree_Tree)
00062 
00063 //==================================================================================
00064 // Function name        : exotkTree_Tree::exotkTree_Tree
00065 //==================================================================================
00066 // Written by       : Stephane Routelous - 2001-11-07 19:47:16
00067 // Description      : 
00068 // Return type          : 
00069 //==================================================================================
00070 exotkTree_Tree::exotkTree_Tree()
00071 {
00072 
00073 }
00074 
00075 
00076 //==================================================================================
00077 // Function name        : exotkTree_Tree::~exotkTree_Tree
00078 //==================================================================================
00079 // Written by       : Stephane Routelous - 2001-11-07 19:47:18
00080 // Description      : 
00081 // Return type          : 
00082 //==================================================================================
00083 exotkTree_Tree::~exotkTree_Tree()
00084 {
00085 
00086 }
00087 
00088 
00089 //==================================================================================
00090 // Function name        : exotkTree_Tree::Root
00091 //==================================================================================
00092 // Written by       : Stephane Routelous - 2001-11-07 19:47:20
00093 // Description      : 
00094 // Return type          : Handle_exotkTree_TreeNode 
00095 //==================================================================================
00096 Handle_exotkTree_TreeNode exotkTree_Tree::Root()
00097 {
00098         return myRoot;
00099 }
00100 
00101 
00102 //==================================================================================
00103 // Function name        : exotkTree_Tree::SetRoot
00104 //==================================================================================
00105 // Written by       : Stephane Routelous - 2001-11-07 19:47:22
00106 // Description      : 
00107 // Return type          : void 
00108 //==================================================================================
00109 // Argument         : const Handle_exotkTree_TreeNode &aRoot
00110 void exotkTree_Tree::SetRoot(const Handle_exotkTree_TreeNode &aRoot)
00111 {
00112         myRoot = aRoot;
00113 }
00114 
00115 //==================================================================================
00116 // Function name        : exotkTree_Tree::SetData
00117 //==================================================================================
00118 // Written by       : Stephane Routelous - 2001-11-07 19:47:24
00119 // Description      : 
00120 // Return type          : void 
00121 //==================================================================================
00122 // Argument         : const Handle_Standard_Transient& aData
00123 void exotkTree_Tree::SetData(const Handle_Standard_Transient& aData)
00124 {
00125         myData = aData;
00126 }
00127 
00128 //==================================================================================
00129 // Function name        : exotkTree_Tree::Data
00130 //==================================================================================
00131 // Written by       : Stephane Routelous - 2001-11-07 19:47:26
00132 // Description      : 
00133 // Return type          : Handle_Standard_Transient 
00134 //==================================================================================
00135 Handle_Standard_Transient exotkTree_Tree::Data()
00136 {
00137         return myData;
00138 }
00139 
00140 //==================================================================================
00141 // Function name        : exotkTree_Tree::HasData
00142 //==================================================================================
00143 // Written by       : Stephane Routelous - 2001-11-07 19:47:28
00144 // Description      : 
00145 // Return type          : Standard_Boolean 
00146 //==================================================================================
00147 Standard_Boolean exotkTree_Tree::HasData()
00148 {
00149         return ( !myData.IsNull() );
00150 }
00151 
00152 //==================================================================================
00153 // Function name        : exotkTree_Tree::Dump
00154 //==================================================================================
00155 // Written by       : Stephane Routelous - 2001-11-07 19:47:30
00156 // Description      : 
00157 // Return type          : TCollection_AsciiString 
00158 //==================================================================================
00159 TCollection_AsciiString exotkTree_Tree::Dump()
00160 {
00161         TCollection_AsciiString theString;
00162         if ( !myRoot.IsNull() )
00163         {
00164                 theString += DumpRec(myRoot);
00165         }
00166         else
00167         {
00168                 theString += "No Root";
00169         }
00170         return theString;
00171 }
00172 
00173 //==================================================================================
00174 // Function name        : exotkTree_Tree::DumpRec
00175 //==================================================================================
00176 // Written by       : Stephane Routelous - 2001-11-07 19:47:32
00177 // Description      : 
00178 // Return type          : TCollection_AsciiString 
00179 //==================================================================================
00180 // Argument         : const Handle_exotkTree_TreeNode& aNode
00181 // Argument         : const Standard_Integer level
00182 TCollection_AsciiString exotkTree_Tree::DumpRec(const Handle_exotkTree_TreeNode& aNode,const Standard_Integer level)
00183 {
00184         TCollection_AsciiString theString;
00185         for ( int i = 0 ; i <= level ; i++ )
00186         {
00187                 theString +="  ";
00188         }
00189         Handle_Standard_Type theType = aNode->DynamicType();
00190         theString += TCollection_AsciiString("\\") + aNode->Name() + TCollection_AsciiString("\t") + theType->Name() + TCollection_AsciiString("\r\n");
00191         exotkTree_ListIteratorOfListOfTreeNode iter;
00192         exotkTree_ListOfTreeNode list;
00193         aNode->Children(list);
00194         for ( iter.Initialize(list) ; iter.More() ; iter.Next() )
00195         {
00196                 int i = level+1;
00197                 theString += DumpRec(iter.Value(),i);
00198         }
00199         return theString;
00200 }
00201 
00202 
00203 //==================================================================================
00204 // Function name        : exotkTree_Tree::AddUpdator
00205 //==================================================================================
00206 // Written by       : Stephane Routelous - 2002-01-01 23:19:00
00207 // Description      : 
00208 // Return type          : Standard_Boolean 
00209 //==================================================================================
00210 // Argument         : exotkTree_TreeUpdator* anUpdatorToAdd
00211 Standard_Boolean exotkTree_Tree::AddUpdator(exotkTree_TreeUpdator* anUpdatorToAdd)
00212 {
00213         if ( anUpdatorToAdd==NULL)
00214                 return Standard_False;
00215         
00216         if ( UpdatorExists(anUpdatorToAdd) )
00217                 return Standard_False;
00218         else
00219                 myUpdators.insert(myUpdators.end(),anUpdatorToAdd);
00220 
00221         return Standard_True;
00222 }
00223 
00224 
00225 //==================================================================================
00226 // Function name        : exotkTree_Tree::RemoveUpdator
00227 //==================================================================================
00228 // Written by       : Stephane Routelous - 2002-01-01 23:19:02
00229 // Description      : 
00230 // Return type          : Standard_Boolean 
00231 //==================================================================================
00232 // Argument         : exotkTree_TreeUpdator *anUpdatorToRemove
00233 Standard_Boolean exotkTree_Tree::RemoveUpdator(exotkTree_TreeUpdator *anUpdatorToRemove)
00234 {
00235         if ( anUpdatorToRemove==NULL)
00236                 return Standard_False;
00237         
00238         Standard_Boolean theUpdatorIsRemoved = Standard_False;
00239 
00240         std::list<exotkTree_TreeUpdator*>::iterator theIterator;
00241         for ( theIterator = myUpdators.begin() ;( theIterator != myUpdators.end() ) && ( !theUpdatorIsRemoved ) ;++theIterator)
00242         {
00243                 exotkTree_TreeUpdator* theCurrentUpdator = *theIterator;
00244                 if ( theCurrentUpdator == anUpdatorToRemove )
00245                 {
00246                         myUpdators.erase(theIterator);
00247                         theUpdatorIsRemoved = Standard_True;
00248                 }
00249         }
00250 
00251 
00252         return theUpdatorIsRemoved;
00253 }
00254 
00255 
00256 //==================================================================================
00257 // Function name        : exotkTree_Tree::UpdatorExists
00258 //==================================================================================
00259 // Written by       : Stephane Routelous - 2002-01-01 23:19:04
00260 // Description      : 
00261 // Return type          : Standard_Boolean 
00262 //==================================================================================
00263 // Argument         : exotkTree_TreeUpdator *anUpdatorToCheck
00264 Standard_Boolean exotkTree_Tree::UpdatorExists(exotkTree_TreeUpdator *anUpdatorToCheck)
00265 {
00266         Standard_Boolean theUpdatorExists = Standard_False;
00267 
00268         std::list<exotkTree_TreeUpdator*>::iterator theIterator;
00269         for ( theIterator = myUpdators.begin() ;( theIterator != myUpdators.end() ) && ( !theUpdatorExists ) ;++theIterator)
00270         {
00271                 exotkTree_TreeUpdator* theCurrentUpdator = *theIterator;
00272                 if ( theCurrentUpdator == anUpdatorToCheck )
00273                 {
00274                         theUpdatorExists = Standard_True;
00275                 }
00276         }
00277 
00278         return theUpdatorExists;
00279 }
00280 
00281 
00282 //==================================================================================
00283 // Function name        : exotkTree_Tree::Expand
00284 //==================================================================================
00285 // Written by       : Stephane Routelous - 2002-01-01 23:34:54
00286 // Description      : 
00287 // Return type          : Standard_Boolean 
00288 //==================================================================================
00289 // Argument         : const Handle_exotkTree_TreeNode &aNodeToExpand
00290 // Argument         : const Standard_Boolean Recursive
00291 Standard_Boolean exotkTree_Tree::Expand(const Handle_exotkTree_TreeNode &aNodeToExpand,const Standard_Boolean Recursive)
00292 {
00293         Standard_Boolean theSuccess = Standard_False;
00294         std::list<exotkTree_TreeUpdator*>::iterator theIterator;
00295         for ( theIterator = myUpdators.begin() ; theIterator != myUpdators.end()  ;++theIterator)
00296         {
00297                 exotkTree_TreeUpdator* theCurrentUpdator = *theIterator;
00298                 if ( theCurrentUpdator->ExpandNode(aNodeToExpand,Recursive) )
00299                 {
00300                         theSuccess = Standard_True;
00301                 }
00302         }
00303         return theSuccess;
00304 }
00305 
00306 //==================================================================================
00307 // Function name        : exotkTree_Tree::Collapse
00308 //==================================================================================
00309 // Written by       : Stephane Routelous - 2002-01-01 23:34:55
00310 // Description      : 
00311 // Return type          : Standard_Boolean 
00312 //==================================================================================
00313 // Argument         : const Handle_exotkTree_TreeNode& aNodeToCollapse
00314 Standard_Boolean exotkTree_Tree::Collapse(const Handle_exotkTree_TreeNode& aNodeToCollapse)
00315 {
00316         Standard_Boolean theSuccess = Standard_False;
00317         std::list<exotkTree_TreeUpdator*>::iterator theIterator;
00318         for ( theIterator = myUpdators.begin() ; theIterator != myUpdators.end() ;++theIterator)
00319         {
00320                 exotkTree_TreeUpdator* theCurrentUpdator = *theIterator;
00321                 if ( theCurrentUpdator->CollapseNode(aNodeToCollapse) )
00322                 {
00323                         theSuccess = Standard_True;
00324                 }
00325         }
00326         return theSuccess;
00327 }
00328 
00329 //==================================================================================
00330 // Function name        : exotkTree_Tree::ToggleExpansion
00331 //==================================================================================
00332 // Written by       : Stephane Routelous - 2002-01-01 23:34:57
00333 // Description      : 
00334 // Return type          : Standard_Boolean 
00335 //==================================================================================
00336 // Argument         : const Handle_exotkTree_TreeNode& aNodeToToggle
00337 // Argument         : const Standard_Boolean Recursive
00338 Standard_Boolean exotkTree_Tree::ToggleExpansion(const Handle_exotkTree_TreeNode& aNodeToToggle,const Standard_Boolean Recursive)
00339 {
00340         Standard_Boolean theSuccess = Standard_False;
00341         std::list<exotkTree_TreeUpdator*>::iterator theIterator;
00342         for ( theIterator = myUpdators.begin() ; theIterator != myUpdators.end() ;++theIterator)
00343         {
00344                 exotkTree_TreeUpdator* theCurrentUpdator = *theIterator;
00345                 if ( theCurrentUpdator->ToggleExpansion(aNodeToToggle,Recursive) )
00346                 {
00347                         theSuccess = Standard_True;
00348                 }
00349         }
00350         return theSuccess;
00351 }
00352 
00353 
00354 //==================================================================================
00355 // Function name        : exotkTree_Tree::SetVisible
00356 //==================================================================================
00357 // Written by       : Stephane Routelous - 2002-01-01 23:35:51
00358 // Description      : 
00359 // Return type          : Standard_Boolean 
00360 //==================================================================================
00361 // Argument         : const Handle_exotkTree_TreeNode& aNode
00362 Standard_Boolean exotkTree_Tree::SetVisible(const Handle_exotkTree_TreeNode& aNode)
00363 {
00364         Standard_Boolean theSuccess = Standard_False;
00365         std::list<exotkTree_TreeUpdator*>::iterator theIterator;
00366         for ( theIterator = myUpdators.begin() ; theIterator != myUpdators.end() ;++theIterator)
00367         {
00368                 exotkTree_TreeUpdator* theCurrentUpdator = *theIterator;
00369                 if ( theCurrentUpdator->SetVisible(aNode) )
00370                 {
00371                         theSuccess = Standard_True;
00372                 }
00373         }
00374         return theSuccess;
00375 }
00376 
00377 
00378 //==================================================================================
00379 // Function name        : exotkTree_Tree::UpdateNode
00380 //==================================================================================
00381 // Written by       : Stephane Routelous - 2002-01-12 21:44:37
00382 // Description      : 
00383 // Return type          : Standard_Boolean 
00384 //==================================================================================
00385 // Argument         : const Handle_exotkTree_TreeNode &aNodeToUpdate
00386 Standard_Boolean exotkTree_Tree::UpdateNode(const Handle_exotkTree_TreeNode &aNodeToUpdate)
00387 {
00388         Standard_Boolean theSuccess = Standard_False;
00389         std::list<exotkTree_TreeUpdator*>::iterator theIterator;
00390         for ( theIterator = myUpdators.begin() ; theIterator != myUpdators.end() ;++theIterator)
00391         {
00392                 exotkTree_TreeUpdator* theCurrentUpdator = *theIterator;
00393                 if ( theCurrentUpdator->UpdateNode(aNodeToUpdate) )
00394                 {
00395                         theSuccess = Standard_True;
00396                 }
00397         }
00398         return theSuccess;
00399 }
00400 
00401 void exotkTree_Tree::NotifyInsertItem(const Handle_exotkTree_TreeNode& aParentNode,const Handle_exotkTree_TreeNode& anInsertedNode,const Handle_exotkTree_TreeNode& aPositionNode)
00402 {
00403         std::list<exotkTree_TreeUpdator*>::iterator theIterator;
00404         for ( theIterator = myUpdators.begin() ; theIterator != myUpdators.end() ;++theIterator)
00405         {
00406                 exotkTree_TreeUpdator* theCurrentUpdator = *theIterator;
00407                 theCurrentUpdator->NotifyInsertItem(aParentNode,anInsertedNode,aPositionNode);
00408         }
00409 }
00410 

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