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