TStructNode.cxx

Go to the documentation of this file.
00001 // @(#)root/gviz3d:$Id: TStructNode.cxx 29985 2009-08-31 16:05:21Z brun $
00002 // Author: Tomasz Sosnicki   18/09/09
00003 
00004 /************************************************************************
00005 * Copyright (C) 1995-2009, Rene Brun and Fons Rademakers.               *
00006 * All rights reserved.                                                  *
00007 *                                                                       *
00008 * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010 *************************************************************************/
00011 
00012 #include "TStructNode.h"
00013 #include <TList.h>
00014 #include <TGeoManager.h>
00015 
00016 ClassImp(TStructNode);
00017 
00018 //________________________________________________________________________
00019 //////////////////////////////////////////////////////////////////////////
00020 //
00021 // TStructNode - class which represent a node. Node has all information 
00022 // about some pointer. It keeps information such as name of object, type, 
00023 // size of pointers class, size of node and daughter nodes, number of child 
00024 // nodes. It is also used to store information needed to draw TGeoVolume.
00025 // It is for example x, y and z coordinates.
00026 // Condition fVisible tells us that node is visible and should be drawn.
00027 // fCollapsed tells us that we can see daughter nodes.
00028 // 
00029 //////////////////////////////////////////////////////////////////////////
00030 
00031 EScalingType TStructNode::fgScalBy = kMembers;
00032 
00033 //________________________________________________________________________
00034 TStructNode::TStructNode(TString name, TString typeName, void* pointer, TStructNode* parent, ULong_t size, ENodeType type)
00035 {
00036    // Constructs node with name "name" of class "typeName" and given parent "parent" which represents pointer "pointer". 
00037    // Size of node is set to "size" and type is set to "type"
00038 
00039    fName = name;
00040    fTypeName = typeName;
00041    fTotalSize = fSize = size;
00042    fMembers = new TList();
00043    fMembersCount = fAllMembersCount = 1;
00044    fLevel = 1;
00045    fX = fY = fWidth = fHeight = 0;
00046    fParent = parent;
00047    if (parent) {
00048       fLevel = parent->GetLevel()+1;
00049       parent->fMembers->Add(this);
00050    }
00051 
00052    fNodeType = type;
00053    fPointer = pointer;
00054    fCollapsed = false;
00055    fVisible = false;
00056    fMaxLevel = 3;
00057    fMaxObjects = 100;
00058 }
00059 
00060 //________________________________________________________________________
00061 TStructNode::~TStructNode()
00062 {
00063    // Destructs list of nodes
00064 
00065    delete fMembers;
00066 }
00067 
00068 //________________________________________________________________________
00069 Int_t TStructNode::Compare(const TObject* obj) const
00070 {
00071    // Overrided method. Compare to objects of TStructNode class.
00072 
00073    TStructNode* node = (TStructNode*)obj;
00074    
00075    if (GetVolume() < node->GetVolume()) {
00076       return -1;
00077    }
00078    if(GetVolume() > node->GetVolume()) {
00079       return 1;
00080    }
00081    
00082    if (this > node) {
00083       return 1;
00084    }
00085    if (this < node) {
00086       return -1;
00087    }
00088 
00089    return 0;
00090 }
00091 
00092 //________________________________________________________________________
00093 ULong_t TStructNode::GetAllMembersCount() const
00094 {
00095    // Returns number of all members in node
00096 
00097    return fAllMembersCount;
00098 }
00099 
00100 //________________________________________________________________________
00101 Float_t TStructNode::GetCenter() const
00102 {
00103    // Returns center of outlining box on x-axis
00104    return (fX + fWidth /2);
00105 }
00106 
00107 //________________________________________________________________________
00108 Float_t TStructNode::GetHeight() const
00109 {
00110    // Returns height of outlining box
00111 
00112    return fHeight;
00113 }
00114 
00115 //________________________________________________________________________
00116 UInt_t TStructNode::GetLevel() const
00117 {
00118    // Returns actual level of node
00119 
00120    return fLevel;
00121 }
00122 
00123 //________________________________________________________________________
00124 const char* TStructNode::GetName() const
00125 {
00126    // Returns name of object
00127    return fName.Data();
00128 }
00129 
00130 //________________________________________________________________________
00131 ENodeType TStructNode::GetNodeType() const
00132 {
00133    // Returns type of node
00134 
00135    return fNodeType;
00136 }
00137 
00138 //________________________________________________________________________
00139 UInt_t TStructNode::GetMaxLevel() const
00140 {
00141    // Returns maximum number of leves displayed when the node is top node on scene
00142 
00143    return fMaxLevel;
00144 }
00145 
00146 //________________________________________________________________________
00147 UInt_t TStructNode::GetMaxObjects() const
00148 {
00149    // Returns maximum number of objects displayed when the node is top node on scene
00150    return fMaxObjects;
00151 }
00152 
00153 //________________________________________________________________________
00154 TList* TStructNode::GetMembers() const
00155 {
00156    // Returns list with pointers to daughter nodes.
00157 
00158    return fMembers;
00159 }
00160 
00161 //________________________________________________________________________
00162 ULong_t TStructNode::GetMembersCount() const
00163 {
00164    // Returns numbers of members of node
00165 
00166    return fMembersCount;
00167 }
00168 
00169 //________________________________________________________________________
00170 Float_t TStructNode::GetMiddle() const
00171 {
00172    // Returns center of outlining box on y-axis
00173 
00174    return (fY + fHeight/2);
00175 }
00176 
00177 //________________________________________________________________________
00178 TStructNode* TStructNode::GetParent() const
00179 {
00180    // Returns pointer to parent node
00181 
00182    return fParent;
00183 }
00184 
00185 //________________________________________________________________________
00186 void* TStructNode::GetPointer() const
00187 {
00188    // Returns main pointer
00189    return fPointer;
00190 }
00191 
00192 //________________________________________________________________________
00193 ULong_t TStructNode::GetRelativeMembersCount() const
00194 {
00195    // Returns relative numbers of members. If node is collapsed, then method returns number of all members, 
00196    // it's node and its daughters, otherwise it returns number of members of node
00197 
00198    if (fCollapsed) {
00199       return fAllMembersCount;
00200    }
00201    return fMembersCount;
00202 }
00203 
00204 //________________________________________________________________________
00205 ULong_t TStructNode::GetRelativeSize() const
00206 {
00207    // Returns relative size of node. If node is collapsed, then function returns size of node and dauthers, 
00208    // otherwise returns size of node only.
00209 
00210    if (fCollapsed) {
00211       return fTotalSize;
00212    }
00213    return fSize;
00214 }
00215 
00216 //________________________________________________________________________
00217 ULong_t TStructNode::GetRelativeVolume() const
00218 {
00219    // Returns size or number of members. If ScaleBy is set to kMembers and node is collapsed, then it 
00220    // returns all number of members. If node isn't collapsed it returns number of members.
00221    // If Scaleby is set to kSize and node is collapsed, then it returns total size of node and daughters,
00222    // else it returns size of node, otherwise it returns 0.
00223 
00224    if (fgScalBy == kMembers) {
00225       if (fCollapsed) {
00226          return GetAllMembersCount();
00227       } else {
00228          return GetMembersCount();
00229       }
00230    } else if (fgScalBy == kSize) {
00231       if (fCollapsed) {
00232          return GetTotalSize();
00233       } else {
00234          return GetSize();
00235       }
00236    } else {
00237       return 0;
00238    }
00239 }
00240 
00241 //________________________________________________________________________
00242 Float_t TStructNode::GetRelativeVolumeRatio()
00243 {
00244    // Returns ratio - relative volume to area taken by utlining box.
00245 
00246    return ((Float_t)(GetRelativeVolume())/(fWidth*fHeight));
00247 }
00248 
00249 //________________________________________________________________________
00250 ULong_t TStructNode::GetSize() const
00251 {
00252    // Returns size of node
00253 
00254    return fSize;
00255 }
00256 
00257 //________________________________________________________________________
00258 ULong_t TStructNode::GetTotalSize() const
00259 {
00260    // Returns total size of allocated memory in bytes
00261 
00262    return fTotalSize;
00263 }
00264 
00265 //________________________________________________________________________
00266 TString TStructNode::GetTypeName() const
00267 {
00268    // Returns name of class
00269 
00270    return fTypeName;
00271 }
00272 
00273 //________________________________________________________________________
00274 ULong_t TStructNode::GetVolume() const
00275 {
00276    // Returns size or number of members. If ScaleBy is set to kMembers it returns all number of members.
00277    // If Scaleby is set to kSize then it returns total size of node and daughters, otherwise it returns 0.
00278 
00279    if (fgScalBy == kMembers) {
00280       return GetAllMembersCount();
00281    } else if (fgScalBy == kSize) {
00282       return GetTotalSize();
00283    } else {
00284       return 0;
00285    }
00286 
00287 }
00288 
00289 //________________________________________________________________________
00290 Float_t TStructNode::GetVolumeRatio()
00291 {
00292    // Returns ratio - volme of node to area taken by outlining box
00293 
00294    return ((Float_t)(GetVolume())/(fWidth*fHeight));
00295 }
00296 
00297 //________________________________________________________________________
00298 Float_t TStructNode::GetWidth() const
00299 {
00300    // Returns width of outlining box
00301 
00302    return fWidth;
00303 }
00304 
00305 //________________________________________________________________________
00306 Float_t TStructNode::GetX() const
00307 {
00308    // Returns X coordinate
00309 
00310    return fX;
00311 }
00312 
00313 //________________________________________________________________________
00314 Float_t TStructNode::GetY() const
00315 {
00316    // Returns Y coordinate
00317 
00318    return fY;
00319 }
00320 
00321 //________________________________________________________________________
00322 Bool_t TStructNode::IsCollapsed() const
00323 {
00324    // Returns true if node is colllapsed
00325 
00326    return fCollapsed;
00327 }
00328 
00329 //________________________________________________________________________
00330 Bool_t TStructNode::IsSortable() const
00331 {
00332    // Returns true, because we have overrided method Compare
00333 
00334    return kTRUE;
00335 }
00336 
00337 //________________________________________________________________________
00338 bool TStructNode::IsVisible() const
00339 {
00340    // Returns true if node is visible
00341 
00342    return fVisible;
00343 }
00344 
00345 //________________________________________________________________________
00346 void TStructNode::SetAllMembersCount(ULong_t number)
00347 {
00348    // Sets numbers of all members to "number"
00349 
00350    fAllMembersCount = number;
00351 }
00352 
00353 //________________________________________________________________________
00354 void TStructNode::SetCollapsed(Bool_t collapse)
00355 {
00356    // Sets collapsing of node to "collapse"
00357 
00358    fCollapsed = collapse;
00359 }
00360 
00361 //________________________________________________________________________
00362 void TStructNode::SetHeight(Float_t val)
00363 {
00364    // Sets width of outlining box to "w"
00365 
00366    fHeight = val;
00367 }
00368 
00369 //________________________________________________________________________
00370 void TStructNode::SetMaxLevel(UInt_t level)
00371 {
00372    // Sets maximum number of leves displayed when the node is top node on scene
00373 
00374    fMaxLevel = level;
00375 }
00376 
00377 //________________________________________________________________________
00378 void TStructNode::SetMaxObjects(UInt_t max)
00379 {
00380    // Sets maximum number of objects displayed when the node is top node on scene
00381 
00382    fMaxObjects = max;
00383 }
00384 
00385 //________________________________________________________________________
00386 void TStructNode::SetMembers(TList* list)
00387 {
00388    // Sets list of dauther nodes to "list"
00389 
00390    fMembers = list;
00391 }
00392 
00393 //________________________________________________________________________
00394 void TStructNode::SetMembersCount(ULong_t number)
00395 {
00396    // Sets number of members to "number"
00397    fMembersCount = number;
00398 }
00399 
00400 //________________________________________________________________________
00401 void TStructNode::SetNodeType(ENodeType type)
00402 {
00403    // Sets type of node to "type"
00404 
00405    fNodeType = type;
00406 }
00407 
00408 //________________________________________________________________________
00409 void TStructNode::SetPointer(void* pointer)
00410 {
00411    // Sets main pointer to "pointer"
00412 
00413    fPointer = pointer;
00414 }
00415 
00416 //________________________________________________________________________
00417 void TStructNode::SetScaleBy(EScalingType type)
00418 {
00419    // Sets scaling by to "type"
00420 
00421    fgScalBy = type;
00422 }
00423 
00424 //________________________________________________________________________
00425 void TStructNode::SetSize(ULong_t size)
00426 {
00427    // Sets size of node to "size"
00428 
00429    fSize = size;
00430 }
00431 
00432 //________________________________________________________________________
00433 void TStructNode::SetTotalSize(ULong_t size)
00434 {
00435    // Sets total size  of allocated memory in bytes to value "size"
00436 
00437    fTotalSize = size;
00438 }
00439 
00440 //________________________________________________________________________
00441 void TStructNode::SetVisible(bool visible)
00442 {
00443    // Sets visibility of node to "visible"
00444 
00445    fVisible = visible;
00446 }
00447 
00448 //________________________________________________________________________
00449 void TStructNode::SetWidth(Float_t w)
00450 {
00451    // Sets width of outlining box to "w"
00452 
00453    fWidth = w;
00454 }
00455 
00456 //________________________________________________________________________
00457 void TStructNode::SetX(Float_t x)
00458 {
00459    // Sets X coordinate to "x"
00460 
00461    fX = x;
00462 }
00463 
00464 //________________________________________________________________________
00465 void TStructNode::SetY(Float_t y)
00466 {
00467    // Sets Y coordinate to "y"
00468 
00469    fY = y;
00470 }

Generated on Tue Jul 5 14:19:17 2011 for ROOT_528-00b_version by  doxygen 1.5.1