Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TStructNode.cxx
Go to the documentation of this file.
1 // @(#)root/gviz3d:$Id$
2 // Author: Tomasz Sosnicki 18/09/09
3 
4 /************************************************************************
5 * Copyright (C) 1995-2009, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11 
12 #include "TStructNode.h"
13 #include <TList.h>
14 #include <TGeoManager.h>
15 
16 ClassImp(TStructNode);
17 
18 //________________________________________________________________________
19 //////////////////////////////////////////////////////////////////////////
20 //
21 // TStructNode - class which represent a node. Node has all information
22 // about some pointer. It keeps information such as name of object, type,
23 // size of pointers class, size of node and daughter nodes, number of child
24 // nodes. It is also used to store information needed to draw TGeoVolume.
25 // It is for example x, y and z coordinates.
26 // Condition fVisible tells us that node is visible and should be drawn.
27 // fCollapsed tells us that we can see daughter nodes.
28 //
29 //////////////////////////////////////////////////////////////////////////
30 
31 EScalingType TStructNode::fgScalBy = kMembers;
32 
33 ////////////////////////////////////////////////////////////////////////////////
34 /// Constructs node with name "name" of class "typeName" and given parent "parent" which represents pointer "pointer".
35 /// Size of node is set to "size" and type is set to "type"
36 
37 TStructNode::TStructNode(TString name, TString typeName, void* pointer, TStructNode* parent, ULong_t size, ENodeType type)
38 {
39  fName = name;
40  fTypeName = typeName;
41  fTotalSize = fSize = size;
42  fMembers = new TList();
43  fMembersCount = fAllMembersCount = 1;
44  fLevel = 1;
45  fX = fY = fWidth = fHeight = 0;
46  fParent = parent;
47  if (parent) {
48  fLevel = parent->GetLevel()+1;
49  parent->fMembers->Add(this);
50  }
51 
52  fNodeType = type;
53  fPointer = pointer;
54  fCollapsed = false;
55  fVisible = false;
56  fMaxLevel = 3;
57  fMaxObjects = 100;
58 }
59 
60 ////////////////////////////////////////////////////////////////////////////////
61 /// Destructs list of nodes
62 
63 TStructNode::~TStructNode()
64 {
65  delete fMembers;
66 }
67 
68 ////////////////////////////////////////////////////////////////////////////////
69 /// Overrided method. Compare to objects of TStructNode class.
70 
71 Int_t TStructNode::Compare(const TObject* obj) const
72 {
73  TStructNode* node = (TStructNode*)obj;
74 
75  if (GetVolume() < node->GetVolume()) {
76  return -1;
77  }
78  if(GetVolume() > node->GetVolume()) {
79  return 1;
80  }
81 
82  if (this > node) {
83  return 1;
84  }
85  if (this < node) {
86  return -1;
87  }
88 
89  return 0;
90 }
91 
92 ////////////////////////////////////////////////////////////////////////////////
93 /// Returns number of all members in node
94 
95 ULong_t TStructNode::GetAllMembersCount() const
96 {
97  return fAllMembersCount;
98 }
99 
100 ////////////////////////////////////////////////////////////////////////////////
101 /// Returns center of outlining box on x-axis
102 
103 Float_t TStructNode::GetCenter() const
104 {
105  return (fX + fWidth /2);
106 }
107 
108 ////////////////////////////////////////////////////////////////////////////////
109 /// Returns height of outlining box
110 
111 Float_t TStructNode::GetHeight() const
112 {
113  return fHeight;
114 }
115 
116 ////////////////////////////////////////////////////////////////////////////////
117 /// Returns actual level of node
118 
119 UInt_t TStructNode::GetLevel() const
120 {
121  return fLevel;
122 }
123 
124 ////////////////////////////////////////////////////////////////////////////////
125 /// Returns name of object
126 
127 const char* TStructNode::GetName() const
128 {
129  return fName.Data();
130 }
131 
132 ////////////////////////////////////////////////////////////////////////////////
133 /// Returns type of node
134 
135 ENodeType TStructNode::GetNodeType() const
136 {
137  return fNodeType;
138 }
139 
140 ////////////////////////////////////////////////////////////////////////////////
141 /// Returns maximum number of leves displayed when the node is top node on scene
142 
143 UInt_t TStructNode::GetMaxLevel() const
144 {
145  return fMaxLevel;
146 }
147 
148 ////////////////////////////////////////////////////////////////////////////////
149 /// Returns maximum number of objects displayed when the node is top node on scene
150 
151 UInt_t TStructNode::GetMaxObjects() const
152 {
153  return fMaxObjects;
154 }
155 
156 ////////////////////////////////////////////////////////////////////////////////
157 /// Returns list with pointers to daughter nodes.
158 
159 TList* TStructNode::GetMembers() const
160 {
161  return fMembers;
162 }
163 
164 ////////////////////////////////////////////////////////////////////////////////
165 /// Returns numbers of members of node
166 
167 ULong_t TStructNode::GetMembersCount() const
168 {
169  return fMembersCount;
170 }
171 
172 ////////////////////////////////////////////////////////////////////////////////
173 /// Returns center of outlining box on y-axis
174 
175 Float_t TStructNode::GetMiddle() const
176 {
177  return (fY + fHeight/2);
178 }
179 
180 ////////////////////////////////////////////////////////////////////////////////
181 /// Returns pointer to parent node
182 
183 TStructNode* TStructNode::GetParent() const
184 {
185  return fParent;
186 }
187 
188 ////////////////////////////////////////////////////////////////////////////////
189 /// Returns main pointer
190 
191 void* TStructNode::GetPointer() const
192 {
193  return fPointer;
194 }
195 
196 ////////////////////////////////////////////////////////////////////////////////
197 /// Returns relative numbers of members. If node is collapsed, then method returns number of all members,
198 /// it's node and its daughters, otherwise it returns number of members of node
199 
200 ULong_t TStructNode::GetRelativeMembersCount() const
201 {
202  if (fCollapsed) {
203  return fAllMembersCount;
204  }
205  return fMembersCount;
206 }
207 
208 ////////////////////////////////////////////////////////////////////////////////
209 /// Returns relative size of node. If node is collapsed, then function returns size of node and dauthers,
210 /// otherwise returns size of node only.
211 
212 ULong_t TStructNode::GetRelativeSize() const
213 {
214  if (fCollapsed) {
215  return fTotalSize;
216  }
217  return fSize;
218 }
219 
220 ////////////////////////////////////////////////////////////////////////////////
221 /// Returns size or number of members. If ScaleBy is set to kMembers and node is collapsed, then it
222 /// returns all number of members. If node isn't collapsed it returns number of members.
223 /// If Scaleby is set to kSize and node is collapsed, then it returns total size of node and daughters,
224 /// else it returns size of node, otherwise it returns 0.
225 
226 ULong_t TStructNode::GetRelativeVolume() const
227 {
228  if (fgScalBy == kMembers) {
229  if (fCollapsed) {
230  return GetAllMembersCount();
231  } else {
232  return GetMembersCount();
233  }
234  } else if (fgScalBy == kSize) {
235  if (fCollapsed) {
236  return GetTotalSize();
237  } else {
238  return GetSize();
239  }
240  } else {
241  return 0;
242  }
243 }
244 
245 ////////////////////////////////////////////////////////////////////////////////
246 /// Returns ratio - relative volume to area taken by utlining box.
247 
248 Float_t TStructNode::GetRelativeVolumeRatio()
249 {
250  return ((Float_t)(GetRelativeVolume())/(fWidth*fHeight));
251 }
252 
253 ////////////////////////////////////////////////////////////////////////////////
254 /// Returns size of node
255 
256 ULong_t TStructNode::GetSize() const
257 {
258  return fSize;
259 }
260 
261 ////////////////////////////////////////////////////////////////////////////////
262 /// Returns total size of allocated memory in bytes
263 
264 ULong_t TStructNode::GetTotalSize() const
265 {
266  return fTotalSize;
267 }
268 
269 ////////////////////////////////////////////////////////////////////////////////
270 /// Returns name of class
271 
272 TString TStructNode::GetTypeName() const
273 {
274  return fTypeName;
275 }
276 
277 ////////////////////////////////////////////////////////////////////////////////
278 /// Returns size or number of members. If ScaleBy is set to kMembers it returns all number of members.
279 /// If Scaleby is set to kSize then it returns total size of node and daughters, otherwise it returns 0.
280 
281 ULong_t TStructNode::GetVolume() const
282 {
283  if (fgScalBy == kMembers) {
284  return GetAllMembersCount();
285  } else if (fgScalBy == kSize) {
286  return GetTotalSize();
287  } else {
288  return 0;
289  }
290 
291 }
292 
293 ////////////////////////////////////////////////////////////////////////////////
294 /// Returns ratio - volme of node to area taken by outlining box
295 
296 Float_t TStructNode::GetVolumeRatio()
297 {
298  return ((Float_t)(GetVolume())/(fWidth*fHeight));
299 }
300 
301 ////////////////////////////////////////////////////////////////////////////////
302 /// Returns width of outlining box
303 
304 Float_t TStructNode::GetWidth() const
305 {
306  return fWidth;
307 }
308 
309 ////////////////////////////////////////////////////////////////////////////////
310 /// Returns X coordinate
311 
312 Float_t TStructNode::GetX() const
313 {
314  return fX;
315 }
316 
317 ////////////////////////////////////////////////////////////////////////////////
318 /// Returns Y coordinate
319 
320 Float_t TStructNode::GetY() const
321 {
322  return fY;
323 }
324 
325 ////////////////////////////////////////////////////////////////////////////////
326 /// Returns true if node is colllapsed
327 
328 Bool_t TStructNode::IsCollapsed() const
329 {
330  return fCollapsed;
331 }
332 
333 ////////////////////////////////////////////////////////////////////////////////
334 /// Returns true, because we have overrided method Compare
335 
336 Bool_t TStructNode::IsSortable() const
337 {
338  return kTRUE;
339 }
340 
341 ////////////////////////////////////////////////////////////////////////////////
342 /// Returns true if node is visible
343 
344 bool TStructNode::IsVisible() const
345 {
346  return fVisible;
347 }
348 
349 ////////////////////////////////////////////////////////////////////////////////
350 /// Sets numbers of all members to "number"
351 
352 void TStructNode::SetAllMembersCount(ULong_t number)
353 {
354  fAllMembersCount = number;
355 }
356 
357 ////////////////////////////////////////////////////////////////////////////////
358 /// Sets collapsing of node to "collapse"
359 
360 void TStructNode::SetCollapsed(Bool_t collapse)
361 {
362  fCollapsed = collapse;
363 }
364 
365 ////////////////////////////////////////////////////////////////////////////////
366 /// Sets width of outlining box to "w"
367 
368 void TStructNode::SetHeight(Float_t val)
369 {
370  fHeight = val;
371 }
372 
373 ////////////////////////////////////////////////////////////////////////////////
374 /// Sets maximum number of leves displayed when the node is top node on scene
375 
376 void TStructNode::SetMaxLevel(UInt_t level)
377 {
378  fMaxLevel = level;
379 }
380 
381 ////////////////////////////////////////////////////////////////////////////////
382 /// Sets maximum number of objects displayed when the node is top node on scene
383 
384 void TStructNode::SetMaxObjects(UInt_t max)
385 {
386  fMaxObjects = max;
387 }
388 
389 ////////////////////////////////////////////////////////////////////////////////
390 /// Sets list of dauther nodes to "list"
391 
392 void TStructNode::SetMembers(TList* list)
393 {
394  fMembers = list;
395 }
396 
397 ////////////////////////////////////////////////////////////////////////////////
398 /// Sets number of members to "number"
399 
400 void TStructNode::SetMembersCount(ULong_t number)
401 {
402  fMembersCount = number;
403 }
404 
405 ////////////////////////////////////////////////////////////////////////////////
406 /// Sets type of node to "type"
407 
408 void TStructNode::SetNodeType(ENodeType type)
409 {
410  fNodeType = type;
411 }
412 
413 ////////////////////////////////////////////////////////////////////////////////
414 /// Sets main pointer to "pointer"
415 
416 void TStructNode::SetPointer(void* pointer)
417 {
418  fPointer = pointer;
419 }
420 
421 ////////////////////////////////////////////////////////////////////////////////
422 /// Sets scaling by to "type"
423 
424 void TStructNode::SetScaleBy(EScalingType type)
425 {
426  fgScalBy = type;
427 }
428 
429 ////////////////////////////////////////////////////////////////////////////////
430 /// Sets size of node to "size"
431 
432 void TStructNode::SetSize(ULong_t size)
433 {
434  fSize = size;
435 }
436 
437 ////////////////////////////////////////////////////////////////////////////////
438 /// Sets total size of allocated memory in bytes to value "size"
439 
440 void TStructNode::SetTotalSize(ULong_t size)
441 {
442  fTotalSize = size;
443 }
444 
445 ////////////////////////////////////////////////////////////////////////////////
446 /// Sets visibility of node to "visible"
447 
448 void TStructNode::SetVisible(bool visible)
449 {
450  fVisible = visible;
451 }
452 
453 ////////////////////////////////////////////////////////////////////////////////
454 /// Sets width of outlining box to "w"
455 
456 void TStructNode::SetWidth(Float_t w)
457 {
458  fWidth = w;
459 }
460 
461 ////////////////////////////////////////////////////////////////////////////////
462 /// Sets X coordinate to "x"
463 
464 void TStructNode::SetX(Float_t x)
465 {
466  fX = x;
467 }
468 
469 ////////////////////////////////////////////////////////////////////////////////
470 /// Sets Y coordinate to "y"
471 
472 void TStructNode::SetY(Float_t y)
473 {
474  fY = y;
475 }