Logo ROOT   6.12/07
Reference Guide
TStructViewerGUI.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 "TStructViewerGUI.h"
13 #include <TRandom.h>
14 #include "TStructViewer.h"
15 #include "TStructNodeEditor.h"
16 #include "TStructNodeProperty.h"
17 #include "TStructNode.h"
18 #include <TCanvas.h>
19 #include <RQ_OBJECT.h>
20 #include <TGLLogicalShape.h>
21 #include <TGLPhysicalShape.h>
22 #include <TGLWidget.h>
23 #include <TGButtonGroup.h>
24 #include <TGSplitter.h>
25 #include <TList.h>
26 #include <TClass.h>
27 #include <TDataMember.h>
28 #include <TExMap.h>
29 #include <TPolyLine3D.h>
30 #include <TObjArray.h>
31 #include <TColor.h>
32 #include <TGTab.h>
33 #include <TGeoManager.h>
34 #include <TGeoMatrix.h>
35 #include <TMath.h>
36 #include <TROOT.h>
37 #include <TApplication.h>
38 
40 
41 //________________________________________________________________________
42 //////////////////////////////////////////////////////////////////////////
43 //
44 // TStructViewerGUI is main window of TStructViewer. It provides graphical
45 // interface. In the window we can find panel with tabs and frame with
46 // GLViewer. Tab "Info" serves information about node and is used to naviagate
47 // backward and forward. Second tab "Options" is used to set few options
48 // such as links visibility, scaling method or setting a pointer.
49 // Last tab "Editor" is tab when the TStructNodeEditor is placed.
50 //
51 //////////////////////////////////////////////////////////////////////////
52 
55 
56 ////////////////////////////////////////////////////////////////////////////////
57 /// Constructs window with "w" as width, "h" as height and given parent "p". Argument "parent" is a pointer to TStructViewer which contains this GUI.
58 /// This constructor build window with all controls, build map with colors, init OpenGL Viewer and create TGeoVolumes.
59 
61  : TGMainFrame(p, w, h, kHorizontalFrame)
62 {
63  fParent = parent;
64  fNodePtr = nodePtr;
65 
66  fMaxSlices = 10;
67  fMouseX = 0;
68  fMouseY = 0;
69  fSelectedObject = NULL;
70  fMaxRatio = 0;
71  fColors = colors;
72 
73  if (!gGeoManager) new TGeoManager("tmp","tmp");
74  if (!fgMedium) {
75  fgMedium = new TGeoMedium("MED",1,new TGeoMaterial("Mat", 26.98,13,2.7));
76  }
77 
79  //////////////////////////////////////////////////////////////////////////
80  // layout
81  //////////////////////////////////////////////////////////////////////////
82  TGVerticalFrame* leftFrame = new TGVerticalFrame(this, 200, 200, kFixedWidth);
83  this->AddFrame(leftFrame, new TGLayoutHints(kFixedWidth, 1, 1, 1, 1));
84  TGTab* tabs = new TGTab(leftFrame);
85  TGLayoutHints* expandX = new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 5,5,5,5);
86  //////////////////////////////////////////////////////////////////////////
87  // INFO
88  //////////////////////////////////////////////////////////////////////////
89  TGCompositeFrame* infoFrame = tabs->AddTab("Info");
90  TGGroupFrame* fInfoMenu = new TGGroupFrame(infoFrame, "Info");
91  fNodeNameLabel = new TGLabel(fInfoMenu, "Name:");
92  fInfoMenu->AddFrame(fNodeNameLabel, expandX);
93  fNodeTypelabel = new TGLabel(fInfoMenu, "Type:");
94  fInfoMenu->AddFrame(fNodeTypelabel, expandX);
95  fMembersCountLabel = new TGLabel(fInfoMenu, "Members:");
96  fInfoMenu->AddFrame(fMembersCountLabel, expandX);
97  fAllMembersCountLabel = new TGLabel(fInfoMenu, "All members:");
98  fInfoMenu->AddFrame(fAllMembersCountLabel, expandX);
99  fLevelLabel = new TGLabel(fInfoMenu, "Level:");
100  fInfoMenu->AddFrame(fLevelLabel, expandX);
101  fSizeLabel = new TGLabel(fInfoMenu, "Size:");
102  fInfoMenu->AddFrame(fSizeLabel, expandX);
103  fTotalSizeLabel = new TGLabel(fInfoMenu, "Total size:");
104  fInfoMenu->AddFrame(fTotalSizeLabel, expandX);
105  infoFrame->AddFrame(fInfoMenu, expandX);
106 
107  //////////////////////////////////////////////////////////////////////////
108  // OPTIONS
109  //////////////////////////////////////////////////////////////////////////
110  TGCompositeFrame* options = tabs->AddTab("Options");
111 
112  fShowLinksCheckButton = new TGCheckButton(options, "Show links");
113  fShowLinksCheckButton->Connect("Toggled(Bool_t)", "TStructViewerGUI", this, "ShowLinksToggled(Bool_t)");
116 
117  TGVButtonGroup* scaleByGroup = new TGVButtonGroup(options, "Scale by");
118  fScaleBySizeButton = new TGRadioButton(scaleByGroup, "Size");
119  fScaleBySizeButton->Connect("Clicked()", "TStructViewerGUI", this, "ScaleByChangedSlot()");
121  fScaleByMembersButton = new TGRadioButton(scaleByGroup, "Members count");
122  fScaleByMembersButton->Connect("Clicked()", "TStructViewerGUI", this, "ScaleByChangedSlot()");
123  options->AddFrame(scaleByGroup, expandX);
124 
125  TGHorizontalFrame* defaultColorFrame = new TGHorizontalFrame(options);
126  options->AddFrame(defaultColorFrame, expandX);
127  TGLabel* defColorlabel = new TGLabel(defaultColorFrame, "Default color");
128  defaultColorFrame->AddFrame(defColorlabel, expandX);
129  TGColorSelect* defColorSelect = new TGColorSelect(defaultColorFrame, GetDefaultColor()->GetPixel());
130  defColorSelect->Connect("ColorSelected(Pixel_t)", "TStructViewerGUI", this, "ColorSelectedSlot(Pixel_t)");
131  defaultColorFrame->AddFrame(defColorSelect);
132 
133  TGHorizontalFrame* boxHeightFrame = new TGHorizontalFrame(options);
134  options->AddFrame(boxHeightFrame, expandX);
135  TGLabel* boxHeightLabel = new TGLabel(boxHeightFrame, "Box height:");
136  boxHeightFrame->AddFrame(boxHeightLabel, expandX);
137  fBoxHeightEntry = new TGNumberEntry(boxHeightFrame, 0.1);
139  fBoxHeightEntry->Connect("ValueSet(Long_t)", "TStructViewerGUI", this, "BoxHeightValueSetSlot(Long_t)");
140  boxHeightFrame->AddFrame(fBoxHeightEntry);
141 
142  TGHorizontalFrame* levelDistanceFrame = new TGHorizontalFrame(options);
143  options->AddFrame(levelDistanceFrame, expandX);
144  TGLabel* lvlDistLabel = new TGLabel(levelDistanceFrame, "Distance between levels");
145  levelDistanceFrame->AddFrame(lvlDistLabel, expandX);
146  fLevelDistanceEntry = new TGNumberEntry(levelDistanceFrame, 1.1);
148  fLevelDistanceEntry->Connect("ValueSet(Long_t)", "TStructViewerGUI", this, "LevelDistValueSetSlot(Long_t)");
149  levelDistanceFrame->AddFrame(fLevelDistanceEntry);
150 
151  fAutoRefesh = new TGCheckButton(options, "Auto refresh");
152  fAutoRefesh->SetOn();
153  fAutoRefesh->Connect("Toggled(Bool_t)", "TStructViewerGUI", this, "AutoRefreshButtonSlot(Bool_t)");
154  options->AddFrame(fAutoRefesh, expandX);
155 
156  TGLabel* pointerLabel = new TGLabel(options, "Pointer:");
157  options->AddFrame(pointerLabel, expandX);
158  fPointerTextEntry = new TGTextEntry(options, "0x0000000");
159  options->AddFrame(fPointerTextEntry, expandX);
160  TGLabel* fPointerTypeLabel = new TGLabel(options, "Pointer Type:");
161  options->AddFrame(fPointerTypeLabel, expandX);
162  fPointerTypeTextEntry = new TGTextEntry(options, "TObject");
163  options->AddFrame(fPointerTypeTextEntry, expandX);
164  TGTextButton* setPointerButton = new TGTextButton(options, "Set pointer");
165  setPointerButton->Connect("Clicked()", "TStructViewerGUI", this, "SetPointerButtonSlot()");
166  options->AddFrame(setPointerButton, expandX);
167 
168  //////////////////////////////////////////////////////////////////////////
169  // EDITOR
170  //////////////////////////////////////////////////////////////////////////
171  TGCompositeFrame* editTab = tabs->AddTab("Editor");
172  fEditor = new TStructNodeEditor(fColors, editTab);
173  fEditor->Connect("Update(Bool_t)", "TStructViewerGUI", this, "Update(Bool_t)");
174  editTab->AddFrame(fEditor, expandX);
175 
176  leftFrame->AddFrame(tabs, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 1,1,1,1));
177 
178  TGVSplitter* splitter = new TGVSplitter(this);
179  splitter->SetFrame(leftFrame, true);
180  this->AddFrame(splitter, new TGLayoutHints(kLHintsLeft | kLHintsExpandY));
181 
182  //////////////////////////////////////////////////////////////////////////
183  // NAVIGATE
184  //////////////////////////////////////////////////////////////////////////
185  fUndoButton = new TGTextButton(leftFrame, "Undo");
186  fUndoButton->Connect("Clicked()", "TStructViewerGUI", this, "UndoButtonSlot()");
187  fUndoButton->SetEnabled(false);
188  leftFrame->AddFrame(fUndoButton, expandX);
189 
190  fRedoButton = new TGTextButton(leftFrame, "Redo");
191  fRedoButton->Connect("Clicked()", "TStructViewerGUI", this, "RedoButtonSlot()");
192  fRedoButton->SetEnabled(false);
193  leftFrame->AddFrame(fRedoButton, expandX);
194 
195  TGTextButton* resetCameraButton = new TGTextButton(leftFrame, "Reset camera");
196  leftFrame->AddFrame(resetCameraButton, expandX);
197  resetCameraButton->Connect("Clicked()", "TStructViewerGUI", this, "ResetButtonSlot()");
198 
199  TGTextButton* updateButton = new TGTextButton(leftFrame, "Update");
200  updateButton->Connect("Clicked()", "TStructViewerGUI", this, "UpdateButtonSlot()");
201  leftFrame->AddFrame(updateButton, expandX);
202 
203  TGTextButton* quitButton = new TGTextButton(leftFrame, "Quit");
204  leftFrame->AddFrame(quitButton, expandX);
205  quitButton->Connect("Clicked()", "TApplication", gApplication, "Terminate()");
206 
207  fTopVolume = gGeoManager->MakeBox("TOPVolume", fgMedium,100, 100, 100);
210 
211  fCanvas = new TCanvas("", "", 0, 0);
212  // drawing after creating canvas to avoid drawing in default canvas
213  fGLViewer = new TGLEmbeddedViewer(this, fCanvas);
216  fGLViewer->Connect("MouseOver(TGLPhysicalShape*)", "TStructViewerGUI", this, "MouseOverSlot(TGLPhysicalShape*)");
217  fGLViewer->GetGLWidget()->Connect("ProcessedEvent(Event_t*)", "TStructViewerGUI", this, "GLWidgetProcessedEventSlot(Event_t*))");
218  fGLViewer->Connect("DoubleClicked()", "TStructViewerGUI", this, "DoubleClickedSlot()");
220  Update();
222 
223  SetWindowName("Struct Viewer");
224  MapSubwindows();
225  this->SetWMSizeHints(w, h, 2000, 2000, 0, 0);
227  MapWindow();
228 
229  fToolTip = new TGToolTip(0, 0, "ToolTip", 500);
230 }
231 
232 ////////////////////////////////////////////////////////////////////////////////
233 /// Destructor
234 
236 {
237  delete fCanvas;
238 }
239 
240 ////////////////////////////////////////////////////////////////////////////////
241 /// Activated when user chage condition
242 
244 {
245  if (on) {
246  Update();
247  }
248 }
249 
250 ////////////////////////////////////////////////////////////////////////////////
251 /// Emmited when user changes height of boxes
252 
254 {
255  if(fAutoRefesh->IsOn()) {
256  Update();
257  }
258 }
259 
260 ////////////////////////////////////////////////////////////////////////////////
261 /// Recursive method to calculating nodes posistion in 3D space
262 
264 {
265  // choose scaling method
268  } else if (fScaleByMembersButton->GetState() == kButtonDown) {
270  }
271  Float_t ratio = (Float_t)((parent->GetLevel()+1.0) / parent->GetLevel());
272 
273  // changing the angle between parent object and daughters
274  // if center of parent is 0 that is real piramid
275  parent->SetWidth(1);
276  parent->SetHeight(1);
277  parent->SetX(-parent->GetWidth()/2);
278  parent->SetY(-parent->GetHeight()/2);
279 
280  fMaxRatio = parent->GetVolumeRatio();
281 
282  // sorting list of members by size or number of members
283  parent->GetMembers()->Sort(kSortDescending);
284  Divide(parent->GetMembers(), (parent->GetX()) *ratio, (parent->GetX() + parent->GetWidth())* ratio, (parent->GetY())* ratio, (parent->GetY() + parent->GetHeight())*ratio);
285 
286  // sclale all the objects
287  Scale(parent);
288 }
289 
290 ////////////////////////////////////////////////////////////////////////////////
291 /// Check if all of nodes can be displayed on scene. Hides redendant nodes.
292 
294 {
295  UInt_t object = 0;
296 
297  TList queue;
298  queue.Add(parent);
299  TStructNode* node;
300 
301  while ((node = (TStructNode*) queue.First() )) {
302  object++;
303 
304  if (object > fNodePtr->GetMaxObjects() || node->GetLevel() - fNodePtr->GetLevel() >= fNodePtr->GetMaxLevel()) {
305  break;
306  }
307 
308  node->SetVisible(true);
309 
310  queue.AddAll(node->GetMembers());
311  queue.RemoveFirst();
312 
313  fVisibleObjects.Add(node);
314  }
315 
316  TIter it(&fVisibleObjects);
317  TStructNode* member;
318  while ((node = (TStructNode*) it() )) {
319  if(node->GetLevel() - fNodePtr->GetLevel() == fNodePtr->GetMaxLevel()-1 && node->GetMembersCount() > 0) {
320  node->SetCollapsed(true);
321  continue;
322  }
323 
324  TIter memIt(node->GetMembers());
325  while ((member = (TStructNode*) memIt() )) {
326  if(member->IsVisible() == false) {
327  node->SetCollapsed(true);
328  break;
329  }
330  }
331  }
332 }
333 
334 ////////////////////////////////////////////////////////////////////////////////
335 /// Delete window
336 
338 {
339  DeleteWindow();
340 }
341 
342 ////////////////////////////////////////////////////////////////////////////////
343 /// Slot for default color selsect.
344 /// Sets default colot to "pixel"
345 
347 {
349  if(prop) {
350  prop->SetColor(pixel);
351  Update();
352  }
353 }
354 
355 ////////////////////////////////////////////////////////////////////////////////
356 /// Divides rectangle where the outlining box is placed.
357 
359 {
360  if (list->GetSize() > 1) { // spliting node into two lists
361  ULong_t sum1 = 0, sum = 0;
362 
363  TStructNode* node;
364  TList list1, list2;
365  TIter it(list);
366 
367  while((node = (TStructNode*) it() )) {
368  sum += node->GetVolume();
369  }
370  it.Reset();
371  while((node = (TStructNode*) it() )) {
372  if(sum1 >= sum/2.0) {
373  list2.Add(node);
374  } else {
375  sum1 += node->GetVolume();
376  list1.Add(node);
377  }
378  }
379 
380  if (!sum) return;
381  Float_t ratio = (float)sum1/sum;
382 
383  Float_t width = x2 - x1;
384  Float_t height = y2 - y1;
385  if (width < height) { // vertical split
386  Float_t split = y1 + ratio * height;
387  Divide(&list1, x1, x2, y1, split);
388  Divide(&list2, x1, x2, split, y2);
389  } else { // horizontal
390  Float_t split = x1 + ratio * width;
391  Divide(&list1, x1, split, y1, y2);
392  Divide(&list2, split, x2, y1, y2);
393  }
394  } else if (list->GetSize() == 1) { // divide place to node
395  TStructNode* node = (TStructNode*)(list->First());
396 
397  node->SetWidth(x2 - x1);
398  node->SetHeight(y2 - y1);
399  node->SetX(x1);
400  node->SetY(y1);
401 
402  if (node->GetVolumeRatio() > fMaxRatio) {
403  fMaxRatio = node->GetVolumeRatio();
404  }
405 
406  Float_t ratio = (Float_t)((node->GetLevel()+1.0)/node->GetLevel());
407  node->GetMembers()->Sort(kSortDescending);
408  Divide(node->GetMembers(), x1*ratio, x2*ratio, y1*ratio, y2*ratio);
409  }
410 }
411 
412 ////////////////////////////////////////////////////////////////////////////////
413 /// Activated when user double click on objects on 3D scene. Sets clicked node to top node
414 /// and updates scene with camers reset.
415 
417 {
418  if (fSelectedObject) {
419  if(fSelectedObject == fNodePtr) {
420  return;
421  }
422 
425  fUndoButton->SetEnabled(true);
426 
427  Update(kTRUE);
428  }
429 }
430 ////////////////////////////////////////////////////////////////////////////////
431 /// Check limits and draws nodes and links
432 
434 {
435  fVolumes.Clear();
437 
440 
443  }
444 
446 }
447 
448 ////////////////////////////////////////////////////////////////////////////////
449 /// Recursive method to draw links
450 
452 {
453  if(parent->GetLevel() - fNodePtr->GetLevel() >= fNodePtr->GetMaxLevel()) {
454  return;
455  }
456 
457  if(parent->IsCollapsed()) {
458  return;
459  }
460 
461  TIter it(parent->GetMembers());
462  TStructNode* node;
463  while((node = (TStructNode*) it())) {
464  TPolyLine3D *l = new TPolyLine3D(2);
465  l->SetPoint(0 ,node->GetCenter(), node->GetMiddle(), -(node->GetLevel() * fLevelDistanceEntry->GetNumber()));
466  l->SetPoint(1 ,parent->GetCenter(), parent->GetMiddle(), -(parent->GetLevel() * fLevelDistanceEntry->GetNumber()));
467 
468  l->SetLineColor(GetColor(node));
469  l->SetLineWidth(1);
470  l->Draw();
471 
472  if(!node->IsCollapsed()) {
473  DrawLink(node);
474  }
475  }
476 }
477 
478 ////////////////////////////////////////////////////////////////////////////////
479 /// Creates and draws TGeoVolume from given "node"
480 
482 {
483  TGeoVolume* vol;
484 
485  /*if(node->IsCollapsed())
486  {
487  //float r = (node->GetWidth() < node->GetHeight() ? 0.5 * node->GetWidth() : 0.5 * node->GetHeight());
488  //vol = gGeoManager->MakeTorus(node->GetName(),TStructNode::GetMedium(), 0.75*r, 0, r/4);
489 
490  vol = gGeoManager->MakeBox(TString(node->GetName()) + "up",TStructNode::GetMedium(), 0.45*node->GetWidth(), 0.45*node->GetHeight(), (node->GetWidth() < node->GetHeight() ? 0.45 * node->GetWidth() : 0.45 * node->GetHeight()));
491  Double_t max = TMath::Max(0.22 * node->GetWidth(), 0.22 * node->GetHeight());
492  TGeoVolume* subvol = gGeoManager->MakeTrd2(node->GetName(), TStructNode::GetMedium(), 0, 0.45 * node->GetWidth(), 0, 0.45 * node->GetHeight(), max);
493  subvol->SetLineColor(GetColor(node));
494  subvol->SetNumber((Int_t)node);
495  TGeoTranslation* subtrans = new TGeoTranslation("subtranslation", 0, 0, -max);
496  vol->AddNodeOverlap(subvol, 1, subtrans);
497 
498  subvol = gGeoManager->MakeTrd2(TString(node->GetName()) + "down", TStructNode::GetMedium(), 0.45 * node->GetWidth(), 0, 0.45 * node->GetHeight(), 0, max);
499  subvol->SetLineColor(GetColor(node));
500  subvol->SetNumber((Int_t)node);
501  subtrans = new TGeoTranslation("subtranslation", 0, 0, max);
502  vol->AddNodeOverlap(subvol, 1, subtrans);
503  }
504  else*/ if(node->GetNodeType() == kCollection) {
505  vol = gGeoManager->MakeBox(Form("%s_%d", node->GetName(), fgCounter++), fgMedium, 0.45*node->GetWidth(), 0.45*node->GetHeight(), fBoxHeightEntry->GetNumber());
506  // subboxes
507  Float_t slices = (Float_t)(node->GetMembersCount());
508  if (slices > fMaxSlices) {
509  slices = (Float_t)fMaxSlices;
510  }
511 
512  for (Float_t i = -(slices-1)/2; i < slices/2; i++) {
513  TGeoVolume* sub = gGeoManager->MakeBox(Form("%s_%d", node->GetName(), fgCounter++), fgMedium,0.45*node->GetWidth() * 0.7 / slices, 0.45*node->GetHeight(), fBoxHeightEntry->GetNumber());
514  sub->SetLineColor(GetColor(node));
515  fVolumes.Add((Long_t)sub, (Long_t)node);
516  TGeoTranslation* subtrans = new TGeoTranslation("subtranslation", i * node->GetWidth() / slices, 0, 0);
517  vol->AddNodeOverlap(sub, 1, subtrans);
518  }
519  } else {
520  vol = gGeoManager->MakeBox(Form("%s_%d", node->GetName(), fgCounter++), fgMedium, 0.45*node->GetWidth(), 0.45*node->GetHeight(), fBoxHeightEntry->GetNumber());
521  }
522 
523  vol->SetLineColor(GetColor(node));
524  vol->SetLineWidth(1);
525 
526  TGeoTranslation* trans = new TGeoTranslation("translation", node->GetCenter(), node->GetMiddle(), -(node->GetLevel() * fLevelDistanceEntry->GetNumber()));
527  fVolumes.Add((Long_t)vol, (Long_t)node);
528 
529  fTopVolume->AddNode(vol,1, trans);
530 }
531 
532 ////////////////////////////////////////////////////////////////////////////////
533 /// Recursive method to draw GeoVolumes
534 
536 {
537  if(parent->GetLevel() - fNodePtr->GetLevel() >= fNodePtr->GetMaxLevel()) {
538  return;
539  }
540 
541  DrawNode(parent);
542 
543  if(parent->IsCollapsed()) {
544  return;
545  }
546 
547  TIter nextVis(parent->GetMembers());
548  TStructNode* node;
549  while((node = (TStructNode*)nextVis())) {
550  DrawVolumes(node);
551  }
552 }
553 
554 ////////////////////////////////////////////////////////////////////////////////
555 /// Returns pointer to property associated with node "node". If property is not found
556 /// then it returns default property
557 
559 {
560  TIter it(fColors);
561  TStructNodeProperty* prop;
562  while ((prop = (TStructNodeProperty*) it() )) {
563  TString propName(prop->GetName());
564  if (propName.EndsWith("+")) {
565 
566  if (TClass* cl = TClass::GetClass(node->GetTypeName())) {
567  propName.Remove(propName.Length()-1, 1);
568  if (cl->InheritsFrom(propName.Data())) {
569  return prop;
570  }
571  }
572  } else {
573  if (propName == TString(node->GetTypeName())) {
574  return prop;
575  }
576  }
577  }
578 
579  return (TStructNodeProperty*)fColors->Last();
580 }
581 
582 //________________________________________________________________________`
584 {
585  // Returns canvas used to keep TGeoVolumes
586 
587  return fCanvas;
588 }
589 ////////////////////////////////////////////////////////////////////////////////
590 /// Returns color form fColors for given "node"
591 
593 {
595  if (prop) {
596  return prop->GetColor().GetNumber();
597  }
598 
599  return 2;
600 }
601 
602 ////////////////////////////////////////////////////////////////////////////////
603 /// Return default color for nodes
604 
606 {
607  return ((TStructNodeProperty*)(fColors->Last()));
608 }
609 
610 ////////////////////////////////////////////////////////////////////////////////
611 /// Returns true if links are visible, otherwise return false.
612 
614 {
616  return true;
617  } else {
618  return false;
619  }
620 }
621 
622 ////////////////////////////////////////////////////////////////////////////////
623 /// Returns top node pointer
624 
626 {
627  return fNodePtr;
628 }
629 
630 ////////////////////////////////////////////////////////////////////////////////
631 /// Handle events. Sets fMouseX and fMouseY when user move a mouse over viewer and hides ToolTip
632 
634 {
635  switch (event->fType) {
636  case kMotionNotify:
637  fMouseX = event->fXRoot + 15;
638  fMouseY = event->fYRoot + 15;
639  break;
640 
641  case kButtonPress:
642  fToolTip->Hide();
643  if (fSelectedObject) {
646  }
647  break;
648 
649  default:
650  break;
651  }
652 }
653 
654 ////////////////////////////////////////////////////////////////////////////////
655 /// Emmited when user changes distance between levels
656 
658 {
659  if(fAutoRefesh->IsOn()) {
660  Update(kTRUE);
661  }
662 }
663 
664 ////////////////////////////////////////////////////////////////////////////////
665 /// MouseOver slot. Activated when user out mouse over object on scene.
666 /// Sets ToolTip and updates labels
667 
669 {
670  fToolTip->Hide();
671  fSelectedObject = NULL;
672  if (shape && shape->GetLogical()) {
673  fSelectedObject = (TStructNode*)(shape->GetLogical()->ID());
674  if (fSelectedObject) {
676  fSelectedObject = NULL;
677  return;
678  }
679  Long_t shapeID = (Long_t)(shape->GetLogical()->ID());
680  Long_t volValue = (Long_t)fVolumes.GetValue(shapeID);
681  fSelectedObject = (TStructNode*)volValue;
682 
685  fToolTip->Reset();
687  }
688  }
689 }
690 
691 ////////////////////////////////////////////////////////////////////////////////
692 /// Activated when user click Redo button. Repeat last Undo action.
693 
695 {
697  fUndoButton->SetEnabled(true);
700  if (!fRedoList.First()) {
701  fRedoButton->SetEnabled(false);
702  }
703  Update(kTRUE);
705 }
706 
707 ////////////////////////////////////////////////////////////////////////////////
708 /// Resets camera
709 
711 {
714 }
715 
716 ////////////////////////////////////////////////////////////////////////////////
717 /// Recursive method to scaling all modes on scene. We have to scale nodes to get real ratio between nodes.
718 /// Uses fMaxRatio.
719 
721 {
722  // newRatio = sqrt(ratio/maxratio)
724  // set left top conner in the center
725  parent->SetX(parent->GetX() + parent->GetWidth()/2);
726  parent->SetY(parent->GetY() + parent->GetHeight()/2);
727  // set new size
728  Float_t min = (Float_t)TMath::Min(parent->GetWidth(), parent->GetHeight());
729  parent->SetWidth(parent->GetWidth() * newRatio);
730  parent->SetHeight(parent->GetHeight() * newRatio);
731  // fit the ratio -> height to width
732  Float_t sqrt = (Float_t)(TMath::Sqrt(parent->GetWidth() * parent->GetHeight()));
733  // it's a square
734  if (min > sqrt) {
735  parent->SetWidth(sqrt);
736  parent->SetHeight(sqrt);
737  } else { // it's rectangle
738  if (parent->GetHeight() > parent->GetWidth()) {
739  parent->SetWidth(min);
740  parent->SetHeight(sqrt * sqrt / min);
741  } else {
742  parent->SetWidth(sqrt * sqrt / min);
743  parent->SetHeight(min);
744  }
745  }
746  // move left top corner
747  parent->SetX(parent->GetX() - parent->GetWidth()/2);
748  parent->SetY(parent->GetY() - parent->GetHeight()/2);
749 
750  // scale others nodes
751  TStructNode* node;
752  TIter it(parent->GetMembers());
753  while ((node = (TStructNode*) it() )) {
754  Scale(node);
755  }
756 }
757 
758 ////////////////////////////////////////////////////////////////////////////////
759 /// Sets top node pointer and updates view
760 
762 {
763  fNodePtr = val;
764  Update(kTRUE);
765 }
766 
767 ////////////////////////////////////////////////////////////////////////////////
768 /// Sets links visibility to "visible"
769 
771 {
772  if (visible) {
774  } else {
776  }
777 }
778 
779 ////////////////////////////////////////////////////////////////////////////////
780 /// Sets pointer given in fPointerTestEntry to the main pointer
781 
783 {
784  void* obj = (void*)gROOT->ProcessLine(fPointerTextEntry->GetText());
786 }
787 
788 ////////////////////////////////////////////////////////////////////////////////
789 /// Changes links visibility and refresh view.
790 
792 {
793  if (fAutoRefesh->IsOn()) {
794  Update();
795  }
796 }
797 
798 ////////////////////////////////////////////////////////////////////////////////
799 /// Shows hidden nodes
800 
802 {
803  TStructNode* node;
804  TIter it(&fVisibleObjects);
805 
806  while ((node = (TStructNode*) it() )) {
807  node->SetCollapsed(false);
808  node->SetVisible(false);
809  }
810 
812 }
813 
814 ////////////////////////////////////////////////////////////////////////////////
815 /// Updates view. Clear all the nodes, call draw function and update scene. Doesn't reset camera.
816 
818 {
819  if (!fNodePtr) {
820  return;
821  }
822 
825  Draw();
828 
829  if(resetCamera) {
831  }
832 }
833 
834 ////////////////////////////////////////////////////////////////////////////////
835 /// Update button slot. Updates scene
836 
838 {
839  Update();
840 }
841 
842 ////////////////////////////////////////////////////////////////////////////////
843 /// Refresh information in labels when user put mouse over object
844 
846 {
847  fNodeNameLabel->SetText(node->GetName());
849 
850  TString name = "Members: ";
851  name += node->GetMembersCount();
853  name = "All members: ";
854  name += node->GetAllMembersCount();
856  name = "Level: ";
857  name += node->GetLevel();
858  fLevelLabel->SetText(name);
859  name = "Size: ";
860  name += node->GetSize();
861  fSizeLabel->SetText(name);
862  name = "Total size: ";
863  name += node->GetTotalSize();
864  fTotalSizeLabel->SetText(name);
865 }
866 
867 ////////////////////////////////////////////////////////////////////////////////
868 /// UndoButton Slot. Activated when user press Undo button. Restore last top node pointer.
869 
871 {
873  fRedoButton->SetEnabled(true);
876  if (!fUndoList.First()) {
877  fUndoButton->SetEnabled(false);
878  }
879  Update(kTRUE);
881 }
882 
883 ////////////////////////////////////////////////////////////////////////////////
884 /// Activated when user press radio button
885 
887 {
888  if (fAutoRefesh->IsOn()) {
889  Update();
890  }
891 }
virtual void Clear(Option_t *="")
Definition: TObject.h:100
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition: TAttLine.h:43
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:587
TGCompositeFrame * GetFrame() const
void Add(ULong64_t hash, Long64_t key, Long64_t value)
Add an (key,value) pair to the table. The key should be unique.
Definition: TExMap.cxx:87
void SetNodePtr(TStructNode *val)
Sets top node pointer and updates view.
static long int sum(long int i)
Definition: Factory.cxx:2173
TGTextEntry * fPointerTypeTextEntry
Float_t GetWidth() const
Returns width of outlining box.
void CalculatePosistion(TStructNode *parent)
Recursive method to calculating nodes posistion in 3D space.
void Update(Bool_t resetCamera=false)
Updates view. Clear all the nodes, call draw function and update scene. Doesn&#39;t reset camera...
virtual void PadPaint(TVirtualPad *pad)
Entry point for updating viewer contents via VirtualViewer3D interface.
Definition: TGLViewer.cxx:306
The manager class for any TGeo geometry.
Definition: TGeoManager.h:38
void SetLinksVisibility(Bool_t val)
Sets links visibility to "visible".
TList * GetListOfPrimitives() const
Definition: TPad.h:240
void ScaleByChangedSlot()
Activated when user press radio button.
Definition: TGTab.h:62
float Float_t
Definition: RtypesCore.h:53
Float_t GetCenter() const
Returns center of outlining box on x-axis.
const char Option_t
Definition: RtypesCore.h:62
void SetWindowName(const char *name=0)
Set window name. This is typically done via the window manager.
Definition: TGFrame.cxx:1746
ULong_t GetVolume() const
Returns size or number of members.
void SetY(Float_t y)
Sets Y coordinate to "y".
Float_t GetRelativeVolumeRatio()
Returns ratio - relative volume to area taken by utlining box.
void Reset()
Reset tool tip popup delay timer.
Definition: TGToolTip.cxx:259
virtual void RemoveLast()
Remove the last object of the list.
Definition: TList.cxx:905
REAL splitter
Definition: triangle.c:616
UInt_t GetMaxLevel() const
Returns maximum number of leves displayed when the node is top node on scene.
void SetText(const char *new_text)
Set new tool tip text.
Definition: TGToolTip.cxx:386
TGNumberEntry * fBoxHeightEntry
TH1 * h
Definition: legend2.C:5
TColor GetColor() const
Returns color of class.
TGeoVolume, TGeoVolumeMulti, TGeoVolumeAssembly are the volume classes.
Definition: TGeoVolume.h:48
void ResetCurrentCamera()
Resets position/rotation of current camera to default values.
Definition: TGLViewer.cxx:360
virtual void AddNodeOverlap(TGeoVolume *vol, Int_t copy_no, TGeoMatrix *mat=0, Option_t *option="")
Add a TGeoNode to the list of nodes.
virtual void SetFrame(TGFrame *frame, Bool_t left)
Set frame to be resized.
Definition: TGSplitter.cxx:140
virtual TObject * Last() const
Return the last object in the list. Returns 0 when list is empty.
Definition: TList.cxx:689
virtual void AddAll(const TCollection *col)
Add all objects from collection col to this collection.
TGToolTip * fToolTip
Class describing translations.
Definition: TGeoMatrix.h:121
#define gROOT
Definition: TROOT.h:402
void SetTopVolume(TGeoVolume *vol)
Set the top volume and corresponding node as starting point of the geometry.
Basic string class.
Definition: TString.h:125
TStructNodeProperty * FindNodeProperty(TStructNode *node)
Returns pointer to property associated with node "node".
Base class describing materials.
Definition: TGeoMaterial.h:29
void ColorSelectedSlot(Pixel_t pixel)
Slot for default color selsect.
TGRadioButton * fScaleByMembersButton
Short_t Min(Short_t a, Short_t b)
Definition: TMathBase.h:168
int Int_t
Definition: RtypesCore.h:41
A 3-dimensional polyline.
Definition: TPolyLine3D.h:31
bool Bool_t
Definition: RtypesCore.h:59
ULong_t GetSize() const
Returns size of node.
virtual void SetLimits(ELimit limits=TGNumberFormat::kNELNoLimits, Double_t min=0, Double_t max=1)
UInt_t GetMaxObjects() const
Returns maximum number of objects displayed when the node is top node on scene.
void Hide()
Hide tool tip window.
Definition: TGToolTip.cxx:246
TGLabel * fNodeTypelabel
R__EXTERN TApplication * gApplication
Definition: TApplication.h:165
void ShowLinksToggled(Bool_t on)
Changes links visibility and refresh view.
void Reset()
Definition: TCollection.h:250
Minimal GL-viewer that can be embedded in a standard ROOT frames.
Concrete physical shape - a GL drawable.
Bool_t GetLinksVisibility() const
Returns true if links are visible, otherwise return false.
TList * GetMembers() const
Returns list with pointers to daughter nodes.
~TStructViewerGUI()
Destructor.
TGLabel * fMembersCountLabel
virtual void Sort(Bool_t order=kSortAscending)
Sort linked list.
Definition: TList.cxx:933
Float_t GetX() const
Returns X coordinate.
void UpdateLabels(TStructNode *node)
Refresh information in labels when user put mouse over object.
double sqrt(double)
static const double x2[5]
TGTextButton * fUndoButton
ULong_t Pixel_t
Definition: GuiTypes.h:39
void Class()
Definition: Class.C:29
TGeoVolume * MakeBox(const char *name, TGeoMedium *medium, Double_t dx, Double_t dy, Double_t dz)
Make in one step a volume pointing to a box shape with given medium.
virtual void SetText(TGString *newText)
Set new text in label.
Definition: TGLabel.cxx:177
void SetWMSizeHints(UInt_t wmin, UInt_t hmin, UInt_t wmax, UInt_t hmax, UInt_t winc, UInt_t hinc)
Give the window manager minimum and maximum size hints.
Definition: TGFrame.cxx:1862
void Divide(TList *list, Float_t x1, Float_t x2, Float_t y1, Float_t y2)
Divides rectangle where the outlining box is placed.
void CloseWindow()
Delete window.
virtual Bool_t IsOn() const
Definition: TGButton.h:311
TStructNodeEditor * fEditor
void Scale(TStructNode *parent)
Recursive method to scaling all modes on scene.
void UpdateButtonSlot()
Update button slot. Updates scene.
void SetWidth(Float_t w)
Sets width of outlining box to "w".
static TGeoMedium * fgMedium
virtual EButtonState GetState() const
Definition: TGButton.h:112
void SetPosition(Int_t x, Int_t y)
Set popup position within specified frame (as specified in the ctor).
Definition: TGToolTip.cxx:405
const Bool_t kSortDescending
Definition: TList.h:38
Float_t GetMiddle() const
Returns center of outlining box on y-axis.
void DrawLink(TStructNode *parent)
Recursive method to draw links.
virtual void AddNode(TGeoVolume *vol, Int_t copy_no, TGeoMatrix *mat=0, Option_t *option="")
Add a TGeoNode to the list of nodes.
Definition: TGeoVolume.cxx:984
void UpdateScene(Bool_t redraw=kTRUE)
Force update of pad-scenes.
Definition: TGLViewer.cxx:338
A doubly linked list.
Definition: TList.h:44
bool IsVisible() const
Returns true if node is visible.
static UInt_t fgCounter
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TAttLine.h:40
TGCheckButton * fAutoRefesh
Bool_t Connect(const char *signal, const char *receiver_class, void *receiver, const char *slot)
Non-static method is used to connect from the signal of this object to the receiver slot...
Definition: TQObject.cxx:867
TString GetTypeName() const
Returns name of class.
const char * GetName() const
Returns name of object.
void GLWidgetProcessedEventSlot(Event_t *event)
Handle events. Sets fMouseX and fMouseY when user move a mouse over viewer and hides ToolTip...
Long64_t GetValue(ULong64_t hash, Long64_t key)
Return the value belonging to specified key and hash value.
Definition: TExMap.cxx:173
virtual TObject * First() const
Return the first object in the list. Returns 0 when list is empty.
Definition: TList.cxx:655
TStructNodeProperty * GetDefaultColor()
Return default color for nodes.
void SetCollapsed(Bool_t collapsed)
Sets collapsing of node to "collapse".
void DrawNode(TStructNode *node)
Creates and draws TGeoVolume from given "node".
EGEventType fType
Definition: GuiTypes.h:174
virtual TGDimension GetDefaultSize() const
std::cout << fWidth << "x" << fHeight << std::endl;
Definition: TGFrame.h:375
void UnCheckMaxObjects()
Shows hidden nodes.
ENodeType GetNodeType() const
Returns type of node.
virtual TGCompositeFrame * AddTab(TGString *text)
Add a tab to the tab widget.
Definition: TGTab.cxx:341
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:443
void SetVisible(bool visible)
Sets visibility of node to "visible".
TStructViewer * fParent
unsigned int UInt_t
Definition: RtypesCore.h:42
Float_t GetY() const
Returns Y coordinate.
char * Form(const char *fmt,...)
void SetHeight(Float_t h)
Sets width of outlining box to "w".
UInt_t GetLevel() const
Returns actual level of node.
TGLabel * fNodeNameLabel
ULong_t GetTotalSize() const
Returns total size of allocated memory in bytes.
TGTextButton * fRedoButton
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:75
TGLabel * fAllMembersCountLabel
TGLEmbeddedViewer * fGLViewer
TGeoVolume * fTopVolume
Float_t GetHeight() const
Returns height of outlining box.
virtual void Draw(Option_t *option="")
Draw this 3-D polyline with its current attributes.
const char * GetText() const
Definition: TGTextEntry.h:134
TString & Remove(Ssiz_t pos)
Definition: TString.h:619
long Long_t
Definition: RtypesCore.h:50
Color * colors
Definition: X3DBuffer.c:19
The Canvas class.
Definition: TCanvas.h:31
TGRadioButton * fScaleBySizeButton
void Draw(Option_t *option="")
Check limits and draws nodes and links.
virtual void SetPoint(Int_t point, Double_t x, Double_t y, Double_t z)
Set point n to x, y, z.
static const double x1[5]
static void SetScaleBy(EScalingType type)
Sets scaling by to "type".
#define ClassImp(name)
Definition: Rtypes.h:359
R__EXTERN TGeoManager * gGeoManager
Definition: TGeoManager.h:559
virtual void SetCleanup(Int_t mode=kLocalCleanup)
Turn on automatic cleanup of child frames in dtor.
Definition: TGFrame.cxx:1054
virtual void SetEnabled(Bool_t e=kTRUE)
Set enabled or disabled state of button.
Definition: TGButton.cxx:409
TStructNode * GetNodePtr() const
Returns top node pointer.
void SetResetCamerasOnUpdate(Bool_t v)
Definition: TGLViewer.h:360
virtual Double_t GetNumber() const
void RedoButtonSlot()
Activated when user click Redo button. Repeat last Undo action.
unsigned long ULong_t
Definition: RtypesCore.h:51
void ClearNodes()
Definition: TGeoVolume.h:103
void SetCurrentCamera(ECameraType camera)
Set current active camera - &#39;cameraType&#39; one of: kCameraPerspX, kCameraPerspY, kCameraPerspZ, kCameraOrthoXOY, kCameraOrthoXOZ, kCameraOrthoZOY, kCameraOrthoXnOY, kCameraOrthoXnOZ, kCameraOrthoZnOY.
Definition: TGLViewer.cxx:1794
static void GetPixel(int y, int width, Byte_t *scline)
Get pixels in line y and put in array scline.
Definition: TGWin32.cxx:4288
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1099
void DrawVolumes(TStructNode *visObj)
Recursive method to draw GeoVolumes.
virtual void SetOn(Bool_t on=kTRUE, Bool_t emit=kFALSE)
Definition: TGButton.h:120
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
Definition: TClass.cxx:2887
virtual void Clear(Option_t *option="")
Remove all objects from the list.
Definition: TList.cxx:399
TGNumberEntry * fLevelDistanceEntry
Media are used to store properties related to tracking and which are useful only when using geometry ...
Definition: TGeoMedium.h:23
void SetColor(const TColor &color)
Sets the color to "color".
virtual void MapSubwindows()
Map all sub windows that are part of the composite frame.
Definition: TGFrame.cxx:1146
virtual void SetLineColor(Color_t lcolor)
Set the line color.
TGTextEntry * fPointerTextEntry
void SetNsegments(Int_t nseg)
Set number of segments for approximating circles in drawing.
void AutoRefreshButtonSlot(Bool_t on)
Activated when user chage condition.
void BoxHeightValueSetSlot(Long_t h)
Emmited when user changes height of boxes.
void CheckMaxObjects(TStructNode *parent)
Check if all of nodes can be displayed on scene. Hides redendant nodes.
virtual void Add(TObject *obj)
Definition: TList.h:87
auto * l
Definition: textangle.C:4
virtual void MapWindow()
Definition: TGFrame.h:251
ULong_t GetAllMembersCount() const
Returns number of all members in node.
Definition: TStructNode.cxx:95
void SetPointer(void *ptr, const char *clname=NULL)
Set main pointer of class "clname".
TStructNode * fSelectedObject
Int_t GetNumber() const
Definition: TColor.h:54
TStructViewerGUI(TStructViewer *parent, TStructNode *nodePtr, TList *colors, const TGWindow *p=NULL, UInt_t w=800, UInt_t h=600)
Constructs window with "w" as width, "h" as height and given parent "p".
TStructNode * fNodePtr
Int_t GetColor(TStructNode *node)
Returns color form fColors for given "node".
void ResetButtonSlot()
Resets camera.
Float_t GetVolumeRatio()
Returns ratio - volme of node to area taken by outlining box.
virtual void SetState(EButtonState state, Bool_t emit=kFALSE)
Set check button state.
Definition: TGButton.cxx:1200
Double_t Sqrt(Double_t x)
Definition: TMath.h:590
TGLabel * fTotalSizeLabel
virtual Int_t GetSize() const
Definition: TCollection.h:180
TGCheckButton * fShowLinksCheckButton
void SetPointerButtonSlot()
Sets pointer given in fPointerTestEntry to the main pointer.
virtual void DeleteWindow()
Delete window.
Definition: TGFrame.cxx:258
void SetX(Float_t x)
Sets X coordinate to "x".
Bool_t IsCollapsed() const
Returns true if node is colllapsed.
void DoubleClickedSlot()
Activated when user double click on objects on 3D scene.
const Bool_t kTRUE
Definition: RtypesCore.h:87
void LevelDistValueSetSlot(Long_t dist)
Emmited when user changes distance between levels.
TObject * ID() const
void SetModel(TObject *obj)
Pick up the used node attributes.
void MouseOverSlot(TGLPhysicalShape *shape)
MouseOver slot.
ULong_t GetMembersCount() const
Returns numbers of members of node.
char name[80]
Definition: TGX11.cxx:109
void UndoButtonSlot()
UndoButton Slot. Activated when user press Undo button. Restore last top node pointer.
const TGLLogicalShape * GetLogical() const
virtual void RemoveFirst()
TGLWidget * GetGLWidget()
Definition: TGLViewer.h:225