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