2 #include "TApplication.h"
6 #include "TGSplitter.h"
9 #include "TGeoManager.h"
12 #include "TGStatusBar.h"
13 #include "TGFileDialog.h"
15 #include "TGLPhysicalShape.h"
16 #include "TGLLogicalShape.h"
19 #include "Riostream.h"
21 #include "TGListTree.h"
22 #include "TOrdCollection.h"
27 #include "TEveManager.h"
28 #include "TEveViewer.h"
29 #include "TEveBrowser.h"
30 #include "TEveProjectionManager.h"
31 #include "TEveGeoNode.h"
32 #include "TEveEventManager.h"
33 #include "TEveTrack.h"
34 #include "TEveSelection.h"
36 #include "TRootEmbeddedCanvas.h"
37 #include "TGSplitFrame.h"
38 #include "TGLEmbeddedViewer.h"
39 #include "TGShapedFrame.h"
50 #include <TWin32SplashThread.h>
53 const char *filetypes[] = {
54 "ROOT files", "*.root",
59 const char *rcfiletypes[] = {
64 ////////////////////////////////////////////////////////////////////////////////
65 class TGShapedToolTip : public TGShapedFrame {
68 TGShapedToolTip(const TGShapedToolTip&); // Not implemented
69 TGShapedToolTip& operator=(const TGShapedToolTip&); // Not implemented
72 Int_t fTextX, fTextY, fTextH;
75 TRootEmbeddedCanvas *fEc; // embedded canvas for histogram
76 TH1 *fHist; // user histogram
77 TString fText; // info (as tool tip) text
79 virtual void DoRedraw() {}
82 TGShapedToolTip(const char *picname, Int_t cx=0, Int_t cy=0, Int_t cw=0,
83 Int_t ch=0, Int_t tx=0, Int_t ty=0, Int_t th=0,
84 const char *col="#ffffff");
85 virtual ~TGShapedToolTip();
87 virtual void CloseWindow();
88 void CreateCanvas(Int_t cx, Int_t cy, Int_t cw, Int_t ch);
89 void CreateCanvas(Int_t cw, Int_t ch, TGLayoutHints *hints);
90 TH1 *GetHisto() const { return fHist; }
91 const char *GetText() const { return fText.Data(); }
93 void SetHisto(TH1 *hist);
94 void SetText(const char *text);
95 void SetTextColor(const char *col);
96 void SetTextAttributes(Int_t tx, Int_t ty, Int_t th, const char *col=0);
97 void Show(Int_t x, Int_t y, const char *text = 0, TH1 *hist = 0);
99 ClassDef(TGShapedToolTip, 0) // Shaped composite frame
102 ////////////////////////////////////////////////////////////////////////////////
103 class HtmlObjTable : public TObject {
104 public: // make them public for shorter code
107 Int_t fNValues; // number of values
108 Int_t fNFields; // number of fields
113 TString fHtml; // HTML output code
121 HtmlObjTable(const char *name, Int_t nfields, Int_t nvals, Bool_t exp=kTRUE);
122 virtual ~HtmlObjTable();
124 void SetLabel(Int_t col, const char *label) { fLabels[col] = label; }
125 void SetValue(Int_t col, Int_t row, Float_t val) { fValues[col].SetAt(val, row); }
126 TString Html() const { return fHtml; }
128 ClassDef(HtmlObjTable, 0);
131 ////////////////////////////////////////////////////////////////////////////////
133 public: // make them public for shorter code
135 TOrdCollection *fObjTables; // ->array of object tables
136 TString fHtml; // output HTML string
137 TString fTitle; // page title
138 TString fHeader; // HTML header
139 TString fFooter; // HTML footer
145 HtmlSummary(const char *title);
146 virtual ~HtmlSummary();
148 HtmlObjTable *AddTable(const char *name, Int_t nfields, Int_t nvals,
149 Bool_t exp=kTRUE, Option_t *opt="");
150 HtmlObjTable *GetTable(Int_t at) const { return (HtmlObjTable *)fObjTables->At(at); }
152 void Clear(Option_t *option="");
153 void Reset(Option_t *option="");
154 TString Html() const { return fHtml; }
156 ClassDef(HtmlSummary, 0);
159 ////////////////////////////////////////////////////////////////////////////////
160 class SplitGLView : public TGMainFrame {
164 kFileOpen, kFileExit, kFileLoadConfig, kFileSaveConfig,
165 kHelpAbout, kGLPerspYOZ, kGLPerspXOZ, kGLPerspXOY, kGLXOY,
166 kGLXOZ, kGLZOY, kGLOrthoRotate, kGLOrthoDolly, kSceneUpdate,
167 kSceneUpdateAll, kSummaryUpdate
171 TEvePad *fPad; // pad used as geometry container
172 TGSplitFrame *fSplitFrame; // main (first) split frame
173 TGLEmbeddedViewer *fViewer0; // main GL viewer
174 TGLEmbeddedViewer *fViewer1; // first GL viewer
175 TGLEmbeddedViewer *fViewer2; // second GL viewer
176 TGLEmbeddedViewer *fActViewer; // actual (active) GL viewer
177 static HtmlSummary *fgHtmlSummary; // summary HTML table
178 static TGHtml *fgHtml;
179 TGMenuBar *fMenuBar; // main menu bar
180 TGPopupMenu *fMenuFile; // 'File' popup menu
181 TGPopupMenu *fMenuHelp; // 'Help' popup menu
182 TGPopupMenu *fMenuCamera; // 'Camera' popup menu
183 TGPopupMenu *fMenuScene; // 'Scene' popup menu
184 TGStatusBar *fStatusBar; // status bar
185 TGShapedToolTip *fShapedToolTip; // shaped tooltip
188 TEveViewer *fViewer[3];
189 TEveProjectionManager *fRPhiMgr;
190 TEveProjectionManager *fRhoZMgr;
193 SplitGLView(const TGWindow *p=0, UInt_t w=800, UInt_t h=600, Bool_t embed=kFALSE);
194 virtual ~SplitGLView();
196 void ItemClicked(TGListTreeItem *item, Int_t btn, Int_t x, Int_t y);
197 void HandleMenu(Int_t id);
198 void OnClicked(TObject *obj);
199 void OnMouseIdle(TGLPhysicalShape *shape, UInt_t posx, UInt_t posy);
200 void OnMouseOver(TGLPhysicalShape *shape);
201 void OnViewerActivated();
202 void OpenFile(const char *fname);
203 void ToggleOrthoRotate();
204 void ToggleOrthoDolly();
205 void SwapToMainView();
206 void LoadConfig(const char *fname);
207 void SaveConfig(const char *fname);
208 static void UpdateSummary();
210 TEveProjectionManager *GetRPhiMgr() const { return fRPhiMgr; }
211 TEveProjectionManager *GetRhoZMgr() const { return fRhoZMgr; }
213 ClassDef(SplitGLView, 0)
216 TEveProjectionManager *gRPhiMgr = 0;
217 TEveProjectionManager *gRhoZMgr = 0;
219 ClassImp(TGShapedToolTip)
220 ClassImp(HtmlObjTable)
221 ClassImp(HtmlSummary)
222 ClassImp(SplitGLView)
224 HtmlSummary *SplitGLView::fgHtmlSummary = 0;
225 TGHtml *SplitGLView::fgHtml = 0;
227 //______________________________________________________________________________
228 TGShapedToolTip::TGShapedToolTip(const char *pname, Int_t cx, Int_t cy, Int_t cw,
229 Int_t ch, Int_t tx, Int_t ty, Int_t th,
231 TGShapedFrame(pname, gClient->GetDefaultRoot(), 400, 300, kTempFrame |
232 kHorizontalFrame), fEc(0), fHist(0)
234 // Shaped window constructor
236 fTextX = tx; fTextY = ty; fTextH = th;
240 fTextCol = "0x000000";
242 // create the embedded canvas
243 if ((cx > 0) && (cy > 0) && (cw > 0) && (ch > 0)) {
244 Int_t lhRight = fWidth-cx-cw;
245 Int_t lhBottom = fHeight-cy-ch;
246 fEc = new TRootEmbeddedCanvas("ec", this, cw, ch, 0);
247 AddFrame(fEc, new TGLayoutHints(kLHintsTop | kLHintsLeft, cx,
248 lhRight, cy, lhBottom));
252 Resize(fBgnd->GetWidth(), fBgnd->GetHeight());
255 //______________________________________________________________________________
256 TGShapedToolTip::~TGShapedToolTip()
266 //______________________________________________________________________________
267 void TGShapedToolTip::CloseWindow()
269 // Close shaped window.
274 //______________________________________________________________________________
275 void TGShapedToolTip::Refresh()
277 // Redraw the window with current attributes.
279 const char *str = fText.Data();
280 char *string = strdup(str);
281 Int_t nlines = 0, size = fTextH;
282 TString fp = gEnv->GetValue("Root.TTFontPath", "");
283 TString ar = fp + "/arial.ttf";
284 char *s = strtok((char *)string, "\n");
285 TImage *img = (TImage*)fImage->Clone("img");
286 img->DrawText(fTextX, fTextY+(nlines*size), s, size, fTextCol, ar);
287 while ((s = strtok(0, "\n"))) {
289 img->DrawText(fTextX, fTextY+(nlines*size), s, size, fTextCol, ar);
291 img->PaintImage(fId, 0, 0, 0, 0, 0, 0, "opaque");
297 //______________________________________________________________________________
298 void TGShapedToolTip::CreateCanvas(Int_t cx, Int_t cy, Int_t cw, Int_t ch)
301 // create the embedded canvas
302 Int_t lhRight = fWidth-cx-cw;
303 Int_t lhBottom = fHeight-cy-ch;
304 fEc = new TRootEmbeddedCanvas("ec", this, cw, ch, 0);
305 AddFrame(fEc, new TGLayoutHints(kLHintsTop | kLHintsLeft, cx,
306 lhRight, cy, lhBottom));
309 Resize(fBgnd->GetWidth(), fBgnd->GetHeight());
315 //______________________________________________________________________________
316 void TGShapedToolTip::CreateCanvas(Int_t cw, Int_t ch, TGLayoutHints *hints)
318 // Create the embedded canvas.
320 fEc = new TRootEmbeddedCanvas("ec", this, cw, ch, 0);
321 AddFrame(fEc, hints);
324 Resize(fBgnd->GetWidth(), fBgnd->GetHeight());
330 //______________________________________________________________________________
331 void TGShapedToolTip::SetHisto(TH1 *hist)
333 // Set which histogram has to be displayed in the embedded canvas.
339 fEc->GetCanvas()->Clear();
341 fHist = (TH1 *)hist->Clone();
343 fEc->GetCanvas()->SetBorderMode(0);
344 fEc->GetCanvas()->SetFillColor(10);
345 fEc->GetCanvas()->cd();
347 fEc->GetCanvas()->Update();
352 //______________________________________________________________________________
353 void TGShapedToolTip::SetText(const char *text)
355 // Set which text has to be displayed.
364 //______________________________________________________________________________
365 void TGShapedToolTip::SetTextColor(const char *col)
374 //______________________________________________________________________________
375 void TGShapedToolTip::SetTextAttributes(Int_t tx, Int_t ty, Int_t th,
378 // Set text attributes (position, size and color).
380 fTextX = tx; fTextY = ty; fTextH = th;
387 //______________________________________________________________________________
388 void TGShapedToolTip::Show(Int_t x, Int_t y, const char *text, TH1 *hist)
390 // Show (popup) the shaped window at location x,y and possibly
391 // set the text and histogram to be displayed.
400 // end of demo code -------------------------------------------
402 fEc->GetCanvas()->SetBorderMode(0);
403 fEc->GetCanvas()->SetFillColor(10);
404 fEc->GetCanvas()->cd();
406 fEc->GetCanvas()->Update();
411 //______________________________________________________________________________
412 HtmlObjTable::HtmlObjTable(const char *name, Int_t nfields, Int_t nvals, Bool_t exp) :
413 fName(name), fNValues(nvals), fNFields(nfields), fExpand(exp)
417 fValues = new TArrayF[fNFields];
418 for (int i=0;i<fNFields;i++)
419 fValues[i].Set(nvals);
420 fLabels = new TString[fNFields];
423 //______________________________________________________________________________
424 HtmlObjTable::~HtmlObjTable()
432 //______________________________________________________________________________
433 void HtmlObjTable::Build()
437 fHtml = "<table width=100% border=1 cellspacing=0 cellpadding=0 bgcolor=f0f0f0> ",
440 if (fExpand && (fNFields > 0) && (fNValues > 0)) {
448 //______________________________________________________________________________
449 void HtmlObjTable::BuildTitle()
451 // Build table title.
453 fHtml += "<tr><td colspan=";
454 fHtml += Form("%d>", fNFields+1);
455 fHtml += "<table width=100% border=0 cellspacing=2 cellpadding=0 bgcolor=6e6ea0>";
456 fHtml += "<tr><td align=left>";
457 fHtml += "<font face=Verdana size=3 color=ffffff><b><i>";
459 fHtml += "</i></b></font></td>";
461 fHtml += "<td align=right> ";
462 fHtml += "<font face=Verdana size=3 color=ffffff><b><i>";
463 fHtml += Form("Size = %d", fNValues);
464 fHtml += "</i></b></font></td></tr>";
466 fHtml += "</td></tr>";
469 //______________________________________________________________________________
470 void HtmlObjTable::BuildLabels()
472 // Build table labels.
475 fHtml += "<tr bgcolor=c0c0ff>";
476 fHtml += "<th> </th>"; // for the check boxes
477 for (i=0;i<fNFields;i++) {
480 fHtml += " </th>"; // for the check boxes
485 //______________________________________________________________________________
486 void HtmlObjTable::BuildTable()
488 // Build part of table with values.
490 for (int i = 0; i < fNValues; i++) {
492 fHtml += "<tr bgcolor=e0e0ff>";
494 fHtml += "<tr bgcolor=ffffff>";
496 TString name = fName;
497 name.ReplaceAll(" ", "_");
499 fHtml += "<td bgcolor=d0d0ff align=\"center\">";
500 fHtml += "<input type=\"checkbox\" name=\"";
502 fHtml += Form("[%d]\">",i);
505 for (int j = 0; j < fNFields; j++) {
506 fHtml += "<td width=";
507 fHtml += Form("%d%%", 100/fNFields);
508 fHtml += " align=\"center\"";
510 fHtml += Form("%1.4f", fValues[j][i]);
517 //______________________________________________________________________________
518 HtmlSummary::HtmlSummary(const char *title) : fNTables(0), fTitle(title)
522 fObjTables = new TOrdCollection();
525 //______________________________________________________________________________
526 HtmlSummary::~HtmlSummary()
533 //______________________________________________________________________________
534 HtmlObjTable *HtmlSummary::AddTable(const char *name, Int_t nfields, Int_t nvals,
535 Bool_t exp, Option_t *option)
537 // Add a new table in our list of tables.
539 TString opt = option;
541 HtmlObjTable *table = new HtmlObjTable(name, nfields, nvals, exp);
543 if (opt.Contains("first"))
544 fObjTables->AddFirst(table);
546 fObjTables->Add(table);
550 //______________________________________________________________________________
551 void HtmlSummary::Clear(Option_t *option)
553 // Clear the table list.
555 if (option && option[0] == 'D')
556 fObjTables->Delete(option);
558 fObjTables->Clear(option);
562 //______________________________________________________________________________
563 void HtmlSummary::Reset(Option_t *)
565 // Reset (delete) the table list;
567 delete fObjTables; fObjTables = 0;
571 //______________________________________________________________________________
572 void HtmlSummary::Build()
574 // Build the summary.
577 for (int i=0;i<fNTables;i++) {
578 GetTable(i)->Build();
579 fHtml += GetTable(i)->Html();
584 //______________________________________________________________________________
585 void HtmlSummary::MakeHeader()
589 fHeader = "<html><head><title>";
591 fHeader += "</title></head><body>";
592 fHeader += "<center><h2><font color=#2222ee><i>";
594 fHeader += "</i></font></h2></center>";
598 //______________________________________________________________________________
599 void HtmlSummary::MakeFooter()
603 fFooter = "<br><p><br><center><strong><font size=2 color=#2222ee>";
604 fFooter += "Example of using Html widget to display tabular data";
606 fFooter += "© 2007-2008 Bertrand Bellenot";
607 fFooter += "</font></strong></center></body></html>";
611 //______________________________________________________________________________
612 SplitGLView::SplitGLView(const TGWindow *p, UInt_t w, UInt_t h, Bool_t embed) :
613 TGMainFrame(p, w, h), fActViewer(0), fShapedToolTip(0), fIsEmbedded(embed)
615 // Main frame constructor.
619 TGHorizontalFrame *hfrm;
620 TGPictureButton *button;
622 // create the "file" popup menu
623 fMenuFile = new TGPopupMenu(gClient->GetRoot());
624 fMenuFile->AddEntry("&Open...", kFileOpen);
625 fMenuFile->AddSeparator();
626 fMenuFile->AddEntry( "&Update Summary", kSummaryUpdate);
627 fMenuFile->AddSeparator();
628 fMenuFile->AddEntry("&Load Config...", kFileLoadConfig);
629 fMenuFile->AddEntry("&Save Config...", kFileSaveConfig);
630 fMenuFile->AddSeparator();
631 fMenuFile->AddEntry("E&xit", kFileExit);
633 // create the "camera" popup menu
634 fMenuCamera = new TGPopupMenu(gClient->GetRoot());
635 fMenuCamera->AddEntry("Perspective (Floor XOZ)", kGLPerspXOZ);
636 fMenuCamera->AddEntry("Perspective (Floor YOZ)", kGLPerspYOZ);
637 fMenuCamera->AddEntry("Perspective (Floor XOY)", kGLPerspXOY);
638 fMenuCamera->AddEntry("Orthographic (XOY)", kGLXOY);
639 fMenuCamera->AddEntry("Orthographic (XOZ)", kGLXOZ);
640 fMenuCamera->AddEntry("Orthographic (ZOY)", kGLZOY);
641 fMenuCamera->AddSeparator();
642 fMenuCamera->AddEntry("Ortho allow rotate", kGLOrthoRotate);
643 fMenuCamera->AddEntry("Ortho allow dolly", kGLOrthoDolly);
645 fMenuScene = new TGPopupMenu(gClient->GetRoot());
646 fMenuScene->AddEntry("&Update Current", kSceneUpdate);
647 fMenuScene->AddEntry("Update &All", kSceneUpdateAll);
649 // create the "help" popup menu
650 fMenuHelp = new TGPopupMenu(gClient->GetRoot());
651 fMenuHelp->AddEntry("&About", kHelpAbout);
653 // create the main menu bar
654 fMenuBar = new TGMenuBar(this, 1, 1, kHorizontalFrame);
655 fMenuBar->AddPopup("&File", fMenuFile, new TGLayoutHints(kLHintsTop |
656 kLHintsLeft, 0, 4, 0, 0));
657 fMenuBar->AddPopup("&Camera", fMenuCamera, new TGLayoutHints(kLHintsTop |
658 kLHintsLeft, 0, 4, 0, 0));
659 fMenuBar->AddPopup("&Scene", fMenuScene, new TGLayoutHints(kLHintsTop |
660 kLHintsLeft, 0, 4, 0, 0));
661 fMenuBar->AddPopup("&Help", fMenuHelp, new TGLayoutHints(kLHintsTop |
664 AddFrame(fMenuBar, new TGLayoutHints(kLHintsTop | kLHintsExpandX));
666 // connect menu signals to our menu handler slot
667 fMenuFile->Connect("Activated(Int_t)", "SplitGLView", this,
668 "HandleMenu(Int_t)");
669 fMenuCamera->Connect("Activated(Int_t)", "SplitGLView", this,
670 "HandleMenu(Int_t)");
671 fMenuScene->Connect("Activated(Int_t)", "SplitGLView", this,
672 "HandleMenu(Int_t)");
673 fMenuHelp->Connect("Activated(Int_t)", "SplitGLView", this,
674 "HandleMenu(Int_t)");
676 if (fIsEmbedded && gEve) {
677 // use status bar from the browser
678 fStatusBar = gEve->GetBrowser()->GetStatusBar();
681 // create the status bar
682 Int_t parts[] = {45, 15, 10, 30};
683 fStatusBar = new TGStatusBar(this, 50, 10);
684 fStatusBar->SetParts(parts, 4);
685 AddFrame(fStatusBar, new TGLayoutHints(kLHintsBottom | kLHintsExpandX,
689 // create eve pad (our geometry container)
690 fPad = new TEvePad();
692 // create the split frames
693 fSplitFrame = new TGSplitFrame(this, 800, 600);
694 AddFrame(fSplitFrame, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
696 fSplitFrame->VSplit(796);
697 // then split each part again (this will make four parts)
698 fSplitFrame->GetFirst()->HSplit(300);
699 fSplitFrame->GetFirst()->GetSecond()->VSplit(400);
701 // get top (main) split frame
702 frm = fSplitFrame->GetFirst()->GetFirst();
703 // create (embed) a GL viewer inside
704 fViewer0 = new TGLEmbeddedViewer(frm, fPad);
705 frm->AddFrame(fViewer0->GetFrame(), new TGLayoutHints(kLHintsExpandX |
707 // set the camera to perspective (XOZ) for this viewer
708 fViewer0->SetCurrentCamera(TGLViewer::kCameraPerspXOZ);
709 // connect signal we are interested to
710 fViewer0->Connect("MouseOver(TGLPhysicalShape*)", "SplitGLView", this,
711 "OnMouseOver(TGLPhysicalShape*)");
712 fViewer0->Connect("Activated()", "SplitGLView", this,
713 "OnViewerActivated()");
714 fViewer0->Connect("MouseIdle(TGLPhysicalShape*,UInt_t,UInt_t)",
716 "OnMouseIdle(TGLPhysicalShape*,UInt_t,UInt_t)");
717 fViewer0->Connect("Clicked(TObject*)", "SplitGLView", this,
718 "OnClicked(TObject*)");
719 fViewer[0] = new TEveViewer("SplitGLViewer[0]");
720 fViewer[0]->SetGLViewer(fViewer0);
721 fViewer[0]->IncDenyDestroy();
722 if (fIsEmbedded && gEve) {
723 fViewer[0]->AddScene(gEve->GetGlobalScene());
724 fViewer[0]->AddScene(gEve->GetEventScene());
725 gEve->AddElement(fViewer[0], gEve->GetViewers());
726 s = gEve->SpawnNewScene("Rho-Z Projection");
728 fRhoZMgr = new TEveProjectionManager();
729 gEve->AddElement(fRhoZMgr, (TEveElement *)s);
730 gEve->AddToListTree(fRhoZMgr, kTRUE);
733 // get bottom left split frame
734 frm = fSplitFrame->GetFirst()->GetSecond()->GetFirst();
736 hfrm = new TGHorizontalFrame(frm);
737 button= new TGPictureButton(hfrm, gClient->GetPicture("$ALICE_ROOT/EVE/alice-data/swap.png"));
738 button->SetToolTipText("Swap to big view");
739 hfrm->AddFrame(button);
740 button->Connect("Clicked()","SplitGLView",this,"SwapToMainView()");
742 // create (embed) a GL viewer inside
743 fViewer1 = new TGLEmbeddedViewer(hfrm, fPad);
744 hfrm->AddFrame(fViewer1->GetFrame(), new TGLayoutHints(kLHintsExpandX |
746 frm->AddFrame(hfrm, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
748 // set the camera to orthographic (XOY) for this viewer
749 fViewer1->SetCurrentCamera(TGLViewer::kCameraOrthoXOY);
750 // connect signal we are interested to
751 fViewer1->Connect("MouseOver(TGLPhysicalShape*)", "SplitGLView", this,
752 "OnMouseOver(TGLPhysicalShape*)");
753 fViewer1->Connect("Activated()", "SplitGLView", this,
754 "OnViewerActivated()");
755 fViewer1->Connect("MouseIdle(TGLPhysicalShape*,UInt_t,UInt_t)",
757 "OnMouseIdle(TGLPhysicalShape*,UInt_t,UInt_t)");
758 fViewer1->Connect("Clicked(TObject*)", "SplitGLView", this,
759 "OnClicked(TObject*)");
760 fViewer[1] = new TEveViewer("SplitGLViewer[1]");
761 fViewer[1]->SetGLViewer(fViewer1);
762 fViewer[1]->IncDenyDestroy();
763 if (fIsEmbedded && gEve) {
764 fRhoZMgr->ImportElements((TEveElement *)gEve->GetGlobalScene());
765 fRhoZMgr->ImportElements((TEveElement *)gEve->GetEventScene());
766 fRhoZMgr->SetProjection(TEveProjection::kPT_RhoZ);
767 fViewer[1]->AddScene(s);
768 gEve->AddElement(fViewer[1], gEve->GetViewers());
771 s = gEve->SpawnNewScene("R-Phi Projection");
773 fRPhiMgr = new TEveProjectionManager();
774 gEve->AddElement(fRPhiMgr, (TEveElement *)s);
775 gEve->AddToListTree(fRPhiMgr, kTRUE);
778 // get bottom center split frame
779 frm = fSplitFrame->GetFirst()->GetSecond()->GetSecond();
780 // create (embed) a GL viewer inside
781 hfrm = new TGHorizontalFrame(frm);
782 button= new TGPictureButton(hfrm, gClient->GetPicture("$ALICE_ROOT/EVE/alice-data/swap.png"));
783 button->SetToolTipText("Swap to big view");
784 hfrm->AddFrame(button);
785 button->Connect("Clicked()","SplitGLView",this,"SwapToMainView()");
787 // create (embed) a GL viewer inside
788 fViewer2 = new TGLEmbeddedViewer(hfrm, fPad);
789 hfrm->AddFrame(fViewer2->GetFrame(), new TGLayoutHints(kLHintsExpandX |
791 frm->AddFrame(hfrm, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
793 // set the camera to orthographic (XOY) for this viewer
794 fViewer2->SetCurrentCamera(TGLViewer::kCameraOrthoXOY);
795 // connect signal we are interested to
796 fViewer2->Connect("MouseOver(TGLPhysicalShape*)", "SplitGLView", this,
797 "OnMouseOver(TGLPhysicalShape*)");
798 fViewer2->Connect("Activated()", "SplitGLView", this,
799 "OnViewerActivated()");
800 fViewer2->Connect("MouseIdle(TGLPhysicalShape*,UInt_t,UInt_t)",
802 "OnMouseIdle(TGLPhysicalShape*,UInt_t,UInt_t)");
803 fViewer2->Connect("Clicked(TObject*)", "SplitGLView", this,
804 "OnClicked(TObject*)");
805 fViewer[2] = new TEveViewer("SplitGLViewer[2]");
806 fViewer[2]->SetGLViewer(fViewer2);
807 fViewer[2]->IncDenyDestroy();
808 if (fIsEmbedded && gEve) {
809 fRPhiMgr->ImportElements((TEveElement *)gEve->GetGlobalScene());
810 fRPhiMgr->ImportElements((TEveElement *)gEve->GetEventScene());
811 fRPhiMgr->SetProjection(TEveProjection::kPT_RPhi);
812 fViewer[2]->AddScene(s);
813 gEve->AddElement(fViewer[2], gEve->GetViewers());
817 // get bottom right split frame
818 frm = fSplitFrame->GetSecond();
820 hfrm = new TGHorizontalFrame(frm);
821 button= new TGPictureButton(hfrm, gClient->GetPicture("$ALICE_ROOT/EVE/alice-data/swap.png"));
822 button->SetToolTipText("Swap to big view");
823 hfrm->AddFrame(button);
824 button->Connect("Clicked()","SplitGLView",this,"SwapToMainView()");
825 fgHtmlSummary = new HtmlSummary("Alice Event Display Summary Table");
826 fgHtml = new TGHtml(hfrm, 100, 100, -1);
827 hfrm->AddFrame(fgHtml, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
828 frm->AddFrame(hfrm, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
830 if (fIsEmbedded && gEve) {
831 gEve->GetListTree()->Connect("Clicked(TGListTreeItem*, Int_t, Int_t, Int_t)",
832 "SplitGLView", this, "ItemClicked(TGListTreeItem*, Int_t, Int_t, Int_t)");
835 fShapedToolTip = new TGShapedToolTip("$ALICE_ROOT/EVE/alice-data/Default.png", 120, 22, 160, 110,
836 23, 115, 12, "#ffff80");
837 Resize(GetDefaultSize());
841 fSplitFrame->Layout();
842 // !!!! LoadConfig(".everc");
845 //______________________________________________________________________________
846 SplitGLView::~SplitGLView()
848 // Clean up main frame...
851 fMenuFile->Disconnect("Activated(Int_t)", this, "HandleMenu(Int_t)");
852 fMenuCamera->Disconnect("Activated(Int_t)", this, "HandleMenu(Int_t)");
853 fMenuScene->Disconnect("Activated(Int_t)", this, "HandleMenu(Int_t)");
854 fMenuHelp->Disconnect("Activated(Int_t)", this, "HandleMenu(Int_t)");
855 fViewer0->Disconnect("MouseOver(TGLPhysicalShape*)", this,
856 "OnMouseOver(TGLPhysicalShape*)");
857 fViewer0->Disconnect("Activated()", this, "OnViewerActivated()");
858 fViewer0->Disconnect("MouseIdle(TGLPhysicalShape*,UInt_t,UInt_t)",
859 this, "OnMouseIdle(TGLPhysicalShape*,UInt_t,UInt_t)");
860 fViewer1->Disconnect("MouseOver(TGLPhysicalShape*)", this,
861 "OnMouseOver(TGLPhysicalShape*)");
862 fViewer1->Disconnect("Activated()", this, "OnViewerActivated()");
863 fViewer1->Disconnect("MouseIdle(TGLPhysicalShape*,UInt_t,UInt_t)",
864 this, "OnMouseIdle(TGLPhysicalShape*,UInt_t,UInt_t)");
865 fViewer2->Disconnect("MouseOver(TGLPhysicalShape*)", this,
866 "OnMouseOver(TGLPhysicalShape*)");
867 fViewer2->Disconnect("Activated()", this, "OnViewerActivated()");
868 fViewer2->Disconnect("MouseIdle(TGLPhysicalShape*,UInt_t,UInt_t)",
869 this, "OnMouseIdle(TGLPhysicalShape*,UInt_t,UInt_t)");
875 delete fShapedToolTip;
889 gApplication->Terminate(0);
893 //______________________________________________________________________________
894 void SplitGLView::HandleMenu(Int_t id)
896 // Handle menu items.
898 static TString rcdir(".");
899 static TString rcfile(".everc");
905 static TString dir(".");
907 fi.fFileTypes = filetypes;
908 fi.fIniDir = StrDup(dir);
909 new TGFileDialog(gClient->GetRoot(), this, kFDOpen, &fi);
911 OpenFile(fi.fFilename);
916 case kFileLoadConfig:
919 fi.fFileTypes = rcfiletypes;
920 fi.fIniDir = StrDup(rcdir);
921 fi.fFilename = StrDup(rcfile);
922 new TGFileDialog(gClient->GetRoot(), this, kFDOpen, &fi);
924 rcfile = fi.fFilename;
925 LoadConfig(fi.fFilename);
931 case kFileSaveConfig:
934 fi.fFileTypes = rcfiletypes;
935 fi.fIniDir = StrDup(rcdir);
936 fi.fFilename = StrDup(rcfile);
937 new TGFileDialog(gClient->GetRoot(), this, kFDSave, &fi);
939 rcfile = fi.fFilename;
940 SaveConfig(fi.fFilename);
952 fActViewer->SetCurrentCamera(TGLViewer::kCameraPerspYOZ);
956 fActViewer->SetCurrentCamera(TGLViewer::kCameraPerspXOZ);
960 fActViewer->SetCurrentCamera(TGLViewer::kCameraPerspXOY);
964 fActViewer->SetCurrentCamera(TGLViewer::kCameraOrthoXOY);
968 fActViewer->SetCurrentCamera(TGLViewer::kCameraOrthoXOZ);
972 fActViewer->SetCurrentCamera(TGLViewer::kCameraOrthoZOY);
983 fActViewer->UpdateScene();
987 case kSceneUpdateAll:
988 fViewer0->UpdateScene();
989 fViewer1->UpdateScene();
990 fViewer2->UpdateScene();
1005 rootx = gSystem->Getenv("ROOTSYS");
1006 if (!rootx.IsNull()) rootx += "/bin";
1008 rootx += "/root -a &";
1009 gSystem->Exec(rootx);
1012 new TWin32SplashThread(kTRUE);
1015 sprintf(str, "About ROOT %s...", gROOT->GetVersion());
1016 hd = new TRootHelpDialog(this, str, 600, 400);
1017 hd->SetText(gHelpAbout);
1029 //______________________________________________________________________________
1030 void SplitGLView::OnClicked(TObject *obj)
1032 // Handle click events in GL viewer
1035 fStatusBar->SetText(Form("User clicked on: \"%s\"", obj->GetName()), 1);
1037 fStatusBar->SetText("", 1);
1040 //______________________________________________________________________________
1041 void SplitGLView::OnMouseIdle(TGLPhysicalShape *shape, UInt_t posx, UInt_t posy)
1043 // Slot used to handle "OnMouseIdle" signal coming from any GL viewer.
1044 // We receive a pointer on the physical shape in which the mouse cursor is
1045 // and the actual cursor position (x,y)
1050 static TH1F *h1f = 0;
1051 TFormula *form1 = new TFormula("form1","abs(sin(x)/x)");
1052 form1->Update(); // silent warning about unused variable...
1053 TF1 *sqroot = new TF1("sqroot","x*gaus(0) + [3]*form1",0,10);
1054 sqroot->SetParameters(10,4,1,20);
1056 h1f = new TH1F("h1f","",50,0,10);
1058 h1f->SetFillColor(45);
1060 h1f->FillRandom("sqroot",200);
1062 if (fShapedToolTip) {
1063 fShapedToolTip->UnmapWindow();
1065 if (shape && shape->GetLogical() && shape->GetLogical()->GetExternal()) {
1066 // get the actual viewer who actually emitted the signal
1067 TGLEmbeddedViewer *actViewer = dynamic_cast<TGLEmbeddedViewer*>((TQObject*)gTQSender);
1068 // then translate coordinates from the root (screen) coordinates
1069 // to the actual frame (viewer) ones
1070 gVirtualX->TranslateCoordinates(actViewer->GetFrame()->GetId(),
1071 gClient->GetDefaultRoot()->GetId(), posx, posy, x, y,
1073 // Then display our tooltip at this x,y location
1074 if (fShapedToolTip) {
1075 fShapedToolTip->Show(x+5, y+5, Form("%s\n \n%s",
1076 shape->GetLogical()->GetExternal()->IsA()->GetName(),
1077 shape->GetLogical()->GetExternal()->GetName()), h1f);
1082 //______________________________________________________________________________
1083 void SplitGLView::OnMouseOver(TGLPhysicalShape *shape)
1085 // Slot used to handle "OnMouseOver" signal coming from any GL viewer.
1086 // We receive a pointer on the physical shape in which the mouse cursor is.
1088 // display informations on the physical shape in the status bar
1089 if (shape && shape->GetLogical() && shape->GetLogical()->GetExternal())
1090 fStatusBar->SetText(Form("Mouse Over: \"%s\"",
1091 shape->GetLogical()->GetExternal()->GetName()), 0);
1093 fStatusBar->SetText("", 0);
1096 //______________________________________________________________________________
1097 void SplitGLView::OnViewerActivated()
1099 // Slot used to handle "Activated" signal coming from any GL viewer.
1100 // Used to know which GL viewer is active.
1102 static Pixel_t green = 0;
1103 // set the actual GL viewer frame to default color
1104 if (fActViewer && fActViewer->GetFrame())
1105 fActViewer->GetFrame()->ChangeBackground(GetDefaultFrameBackground());
1107 // change the actual GL viewer to the one who emitted the signal
1108 // fActViewer = (TGLEmbeddedViewer *)gTQSender;
1109 fActViewer = dynamic_cast<TGLEmbeddedViewer*>((TQObject*)gTQSender);
1111 if (fActViewer == 0) {
1112 printf ("dyncast failed ...\n");
1116 // get the highlight color (only once)
1118 gClient->GetColorByName("green", green);
1120 // set the new actual GL viewer frame to highlight color
1121 if (fActViewer->GetFrame())
1122 fActViewer->GetFrame()->ChangeBackground(green);
1124 // update menu entries to match actual viewer's options
1125 if (fActViewer->GetOrthoXOYCamera()->GetDollyToZoom() &&
1126 fActViewer->GetOrthoXOZCamera()->GetDollyToZoom() &&
1127 fActViewer->GetOrthoZOYCamera()->GetDollyToZoom())
1128 fMenuCamera->UnCheckEntry(kGLOrthoDolly);
1130 fMenuCamera->CheckEntry(kGLOrthoDolly);
1132 if (fActViewer->GetOrthoXOYCamera()->GetEnableRotate() &&
1133 fActViewer->GetOrthoXOYCamera()->GetEnableRotate() &&
1134 fActViewer->GetOrthoXOYCamera()->GetEnableRotate())
1135 fMenuCamera->CheckEntry(kGLOrthoRotate);
1137 fMenuCamera->UnCheckEntry(kGLOrthoRotate);
1140 //______________________________________________________________________________
1141 void SplitGLView::OpenFile(const char *fname)
1143 // Open a Root file to display a geometry in the GL viewers.
1145 TString filename = fname;
1146 // check if the file type is correct
1147 if (!filename.EndsWith(".root")) {
1148 new TGMsgBox(gClient->GetRoot(), this, "OpenFile",
1149 Form("The file \"%s\" is not a root file!", fname),
1150 kMBIconExclamation, kMBOk);
1153 // check if the root file contains a geometry
1154 if (TGeoManager::Import(fname) == 0) {
1155 new TGMsgBox(gClient->GetRoot(), this, "OpenFile",
1156 Form("The file \"%s\" does't contain a geometry", fname),
1157 kMBIconExclamation, kMBOk);
1160 gGeoManager->DefaultColors();
1161 // delete previous primitives (if any)
1162 fPad->GetListOfPrimitives()->Delete();
1163 // and add the geometry to eve pad (container)
1164 fPad->GetListOfPrimitives()->Add(gGeoManager->GetTopVolume());
1165 // paint the geometry in each GL viewer
1166 fViewer0->PadPaint(fPad);
1167 fViewer1->PadPaint(fPad);
1168 fViewer2->PadPaint(fPad);
1171 //______________________________________________________________________________
1172 void SplitGLView::ToggleOrthoRotate()
1174 // Toggle state of the 'Ortho allow rotate' menu entry.
1176 if (fMenuCamera->IsEntryChecked(kGLOrthoRotate))
1177 fMenuCamera->UnCheckEntry(kGLOrthoRotate);
1179 fMenuCamera->CheckEntry(kGLOrthoRotate);
1180 Bool_t state = fMenuCamera->IsEntryChecked(kGLOrthoRotate);
1182 fActViewer->GetOrthoXOYCamera()->SetEnableRotate(state);
1183 fActViewer->GetOrthoXOYCamera()->SetEnableRotate(state);
1184 fActViewer->GetOrthoXOYCamera()->SetEnableRotate(state);
1188 //______________________________________________________________________________
1189 void SplitGLView::ToggleOrthoDolly()
1191 // Toggle state of the 'Ortho allow dolly' menu entry.
1193 if (fMenuCamera->IsEntryChecked(kGLOrthoDolly))
1194 fMenuCamera->UnCheckEntry(kGLOrthoDolly);
1196 fMenuCamera->CheckEntry(kGLOrthoDolly);
1197 Bool_t state = ! fMenuCamera->IsEntryChecked(kGLOrthoDolly);
1199 fActViewer->GetOrthoXOYCamera()->SetDollyToZoom(state);
1200 fActViewer->GetOrthoXOZCamera()->SetDollyToZoom(state);
1201 fActViewer->GetOrthoZOYCamera()->SetDollyToZoom(state);
1205 //______________________________________________________________________________
1206 void SplitGLView::ItemClicked(TGListTreeItem *item, Int_t, Int_t, Int_t)
1208 // Item has been clicked, based on mouse button do:
1210 static const TEveException eh("SplitGLView::ItemClicked ");
1211 TEveElement* re = (TEveElement*)item->GetUserData();
1213 TObject* obj = re->GetObject(eh);
1214 if (obj->InheritsFrom("TEveViewer")) {
1215 TGLViewer *v = ((TEveViewer *)obj)->GetGLViewer();
1217 if (v->InheritsFrom("TGLEmbeddedViewer")) {
1218 TGLEmbeddedViewer *ev = (TGLEmbeddedViewer *)v;
1219 gVirtualX->SetInputFocus(ev->GetGLWindow()->GetContainer()->GetId());
1224 //______________________________________________________________________________
1225 void SplitGLView::LoadConfig(const char *fname)
1228 Int_t height, width;
1229 TEnv *env = new TEnv(fname);
1231 Int_t mainheight = env->GetValue("MainView.Height", 434);
1232 Int_t blwidth = env->GetValue("Bottom.Left.Width", 266);
1233 Int_t bcwidth = env->GetValue("Bottom.Center.Width", 266);
1234 Int_t brwidth = env->GetValue("Bottom.Right.Width", 266);
1235 Int_t top_height = env->GetValue("Right.Tab.Height", 0);
1236 Int_t bottom_height = env->GetValue("Bottom.Tab.Height", 0);
1238 if (fIsEmbedded && gEve) {
1239 Int_t sel = env->GetValue("Eve.Selection", gEve->GetSelection()->GetPickToSelect());
1240 Int_t hi = env->GetValue("Eve.Highlight", gEve->GetHighlight()->GetPickToSelect());
1241 gEve->GetBrowser()->EveMenu(9+sel);
1242 gEve->GetBrowser()->EveMenu(13+hi);
1244 width = env->GetValue("Eve.Width", (Int_t)gEve->GetBrowser()->GetWidth());
1245 height = env->GetValue("Eve.Height", (Int_t)gEve->GetBrowser()->GetHeight());
1246 gEve->GetBrowser()->Resize(width, height);
1249 // top (main) split frame
1250 width = fSplitFrame->GetFirst()->GetWidth();
1251 fSplitFrame->GetFirst()->Resize(width, mainheight);
1252 // bottom left split frame
1253 height = fSplitFrame->GetSecond()->GetFirst()->GetHeight();
1254 fSplitFrame->GetSecond()->GetFirst()->Resize(blwidth, height);
1255 // bottom center split frame
1256 height = fSplitFrame->GetSecond()->GetSecond()->GetFirst()->GetHeight();
1257 fSplitFrame->GetSecond()->GetSecond()->GetFirst()->Resize(bcwidth, height);
1258 // bottom right split frame
1259 height = fSplitFrame->GetSecond()->GetSecond()->GetSecond()->GetHeight();
1260 fSplitFrame->GetSecond()->GetSecond()->GetSecond()->Resize(brwidth, height);
1262 fSplitFrame->Layout();
1264 if (fIsEmbedded && gEve) {
1265 width = ((TGCompositeFrame *)gEve->GetBrowser()->GetTabBottom()->GetParent())->GetWidth();
1266 ((TGCompositeFrame *)gEve->GetBrowser()->GetTabBottom()->GetParent())->Resize(width, bottom_height);
1267 width = ((TGCompositeFrame *)gEve->GetBrowser()->GetTabRight()->GetParent())->GetWidth();
1268 ((TGCompositeFrame *)gEve->GetBrowser()->GetTabRight()->GetParent())->Resize(width, top_height);
1272 //______________________________________________________________________________
1273 void SplitGLView::SaveConfig(const char *fname)
1276 Int_t bottom_height = 0;
1277 Int_t top_height = 0;
1279 TEnv *env = new TEnv(fname);
1281 if (fIsEmbedded && gEve) {
1282 env->SetValue("Eve.Width", (Int_t)gEve->GetBrowser()->GetWidth());
1283 env->SetValue("Eve.Height", (Int_t)gEve->GetBrowser()->GetHeight());
1285 // get top (main) split frame
1286 frm = fSplitFrame->GetFirst();
1287 env->SetValue("MainView.Height", (Int_t)frm->GetHeight());
1288 // get bottom left split frame
1289 frm = fSplitFrame->GetSecond()->GetFirst();
1290 env->SetValue("Bottom.Left.Width", (Int_t)frm->GetWidth());
1291 // get bottom center split frame
1292 frm = fSplitFrame->GetSecond()->GetSecond()->GetFirst();
1293 env->SetValue("Bottom.Center.Width", (Int_t)frm->GetWidth());
1294 // get bottom right split frame
1295 frm = fSplitFrame->GetSecond()->GetSecond()->GetSecond();
1296 env->SetValue("Bottom.Right.Width", (Int_t)frm->GetWidth());
1297 if (fIsEmbedded && gEve) {
1298 top_height = (Int_t)((TGCompositeFrame *)gEve->GetBrowser()->GetTabRight()->GetParent())->GetHeight();
1299 env->SetValue("Right.Tab.Height", top_height);
1300 bottom_height = (Int_t)((TGCompositeFrame *)gEve->GetBrowser()->GetTabBottom()->GetParent())->GetHeight();
1301 env->SetValue("Bottom.Tab.Height", bottom_height);
1303 env->SetValue("Eve.Selection", gEve->GetSelection()->GetPickToSelect());
1304 env->SetValue("Eve.Highlight", gEve->GetHighlight()->GetPickToSelect());
1307 env->SaveLevel(kEnvLocal);
1309 if (!gSystem->AccessPathName(Form("%s.new", fname))) {
1310 gSystem->Exec(Form("del %s", fname));
1311 gSystem->Rename(Form("%s.new", fname), fname);
1316 //______________________________________________________________________________
1317 void SplitGLView::SwapToMainView()
1319 TGPictureButton *src = (TGPictureButton*)gTQSender;
1320 TGCompositeFrame *parent = (TGCompositeFrame *)(src->GetParent());
1321 TGFrame *source = dynamic_cast<TGFrameElement*>(parent->GetList()->Last())->fFrame;
1322 if (!source) return;
1324 TGSplitFrame *dest = fSplitFrame->GetFirst()->GetFirst();
1326 TGFrame *prev = (TGFrame *)(dest->GetFrame());
1328 if ((source != prev) && (source != dest))
1329 TGSplitFrame::SwitchFrames(source, dest, prev);
1332 //______________________________________________________________________________
1333 void SplitGLView::UpdateSummary()
1335 // Update summary of current event.
1337 TEveElement::List_i i;
1338 TEveElement::List_i j;
1341 HtmlObjTable *table;
1342 TEveEventManager *mgr = gEve ? gEve->GetCurrentEvent() : 0;
1344 fgHtmlSummary->Clear("D");
1345 for (i=mgr->BeginChildren(); i!=mgr->EndChildren(); ++i)
1347 el = ((TEveElement*)(*i));
1348 if (el->IsA() == TEvePointSet::Class()) {
1349 TEvePointSet *ps = (TEvePointSet *)el;
1350 TString ename = ps->GetElementName();
1351 TString etitle = ps->GetElementTitle();
1352 //ename.Remove(ename.First('\''));
1353 //etitle.Remove(0, 2);
1354 Int_t nel = atoi(etitle.Data());
1355 table = fgHtmlSummary->AddTable(ename, 0, nel);
1357 else if (el->IsA() == TEveTrackList::Class()) {
1358 TEveTrackList *tracks = (TEveTrackList *)el;
1359 TString ename = tracks->GetElementName();
1360 // ename.Remove(ename.First('\''));
1361 table = fgHtmlSummary->AddTable(ename.Data(), 5,
1362 tracks->GetNChildren(), kTRUE, "first");
1363 table->SetLabel(0, "Momentum");
1364 table->SetLabel(1, "P_t");
1365 table->SetLabel(2, "Phi");
1366 table->SetLabel(3, "Theta");
1367 table->SetLabel(4, "Eta");
1369 for (j=tracks->BeginChildren(); j!=tracks->EndChildren(); ++j) {
1370 Float_t p = ((TEveTrack*)(*j))->GetMomentum().Mag();
1371 table->SetValue(0, k, p);
1372 Float_t pt = ((TEveTrack*)(*j))->GetMomentum().Perp();
1373 table->SetValue(1, k, pt);
1374 Float_t phi = ((TEveTrack*)(*j))->GetMomentum().Phi();
1375 table->SetValue(2, k, phi);
1376 Float_t theta = ((TEveTrack*)(*j))->GetMomentum().Theta();
1377 table->SetValue(3, k, theta);
1378 Float_t eta = ((TEveTrack*)(*j))->GetMomentum().Eta();
1379 table->SetValue(4, k, eta);
1384 fgHtmlSummary->Build();
1386 fgHtml->ParseText((char*)fgHtmlSummary->Html().Data());
1394 #pragma link C++ class SplitGLView;