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->HSplit(350);
697 // split bottom part vartically
698 fSplitFrame->GetSecond()->VSplit(400);
700 // get top (main) split frame
701 frm = fSplitFrame->GetFirst();
702 // create (embed) a GL viewer inside
703 fViewer0 = new TGLEmbeddedViewer(frm, fPad);
704 frm->AddFrame(fViewer0->GetFrame(), new TGLayoutHints(kLHintsExpandX |
706 // set the camera to perspective (XOZ) for this viewer
707 fViewer0->SetCurrentCamera(TGLViewer::kCameraPerspXOZ);
708 // connect signal we are interested to
709 fViewer0->Connect("MouseOver(TGLPhysicalShape*)", "SplitGLView", this,
710 "OnMouseOver(TGLPhysicalShape*)");
711 fViewer0->Connect("Activated()", "SplitGLView", this,
712 "OnViewerActivated()");
713 fViewer0->Connect("MouseIdle(TGLPhysicalShape*,UInt_t,UInt_t)",
715 "OnMouseIdle(TGLPhysicalShape*,UInt_t,UInt_t)");
716 fViewer0->Connect("Clicked(TObject*)", "SplitGLView", this,
717 "OnClicked(TObject*)");
718 fViewer[0] = new TEveViewer("SplitGLViewer[0]");
719 fViewer[0]->SetGLViewer(fViewer0);
720 fViewer[0]->IncDenyDestroy();
721 if (fIsEmbedded && gEve) {
722 fViewer[0]->AddScene(gEve->GetGlobalScene());
723 fViewer[0]->AddScene(gEve->GetEventScene());
724 gEve->AddElement(fViewer[0], gEve->GetViewers());
725 s = gEve->SpawnNewScene("Rho-Z Projection");
727 fRhoZMgr = new TEveProjectionManager();
728 gEve->AddElement(fRhoZMgr, (TEveElement *)s);
729 gEve->AddToListTree(fRhoZMgr, kFALSE);
732 // get bottom left split frame
733 frm = fSplitFrame->GetSecond()->GetFirst();
735 hfrm = new TGHorizontalFrame(frm);
736 button= new TGPictureButton(hfrm, gClient->GetPicture("$ALICE_ROOT/EVE/alice-data/swap.png"));
737 button->SetToolTipText("Swap to big view");
738 hfrm->AddFrame(button);
739 button->Connect("Clicked()","SplitGLView",this,"SwapToMainView()");
741 // create (embed) a GL viewer inside
742 fViewer1 = new TGLEmbeddedViewer(hfrm, fPad);
743 hfrm->AddFrame(fViewer1->GetFrame(), new TGLayoutHints(kLHintsExpandX |
745 frm->AddFrame(hfrm, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
747 // set the camera to orthographic (XOY) for this viewer
748 fViewer1->SetCurrentCamera(TGLViewer::kCameraOrthoXOY);
749 // connect signal we are interested to
750 fViewer1->Connect("MouseOver(TGLPhysicalShape*)", "SplitGLView", this,
751 "OnMouseOver(TGLPhysicalShape*)");
752 fViewer1->Connect("Activated()", "SplitGLView", this,
753 "OnViewerActivated()");
754 fViewer1->Connect("MouseIdle(TGLPhysicalShape*,UInt_t,UInt_t)",
756 "OnMouseIdle(TGLPhysicalShape*,UInt_t,UInt_t)");
757 fViewer1->Connect("Clicked(TObject*)", "SplitGLView", this,
758 "OnClicked(TObject*)");
759 fViewer[1] = new TEveViewer("SplitGLViewer[1]");
760 fViewer[1]->SetGLViewer(fViewer1);
761 fViewer[1]->IncDenyDestroy();
762 if (fIsEmbedded && gEve) {
763 fRhoZMgr->ImportElements((TEveElement *)gEve->GetGlobalScene());
764 fRhoZMgr->ImportElements((TEveElement *)gEve->GetEventScene());
765 fRhoZMgr->SetProjection(TEveProjection::kPT_RhoZ);
766 fViewer[1]->AddScene(s);
767 gEve->AddElement(fViewer[1], gEve->GetViewers());
770 s = gEve->SpawnNewScene("R-Phi Projection");
772 fRPhiMgr = new TEveProjectionManager();
773 gEve->AddElement(fRPhiMgr, (TEveElement *)s);
774 gEve->AddToListTree(fRPhiMgr, kFALSE);
777 // get bottom right frame
778 frm = fSplitFrame->GetSecond()->GetSecond();
779 // create (embed) a GL viewer inside
780 hfrm = new TGHorizontalFrame(frm);
781 button= new TGPictureButton(hfrm, gClient->GetPicture("$ALICE_ROOT/EVE/alice-data/swap.png"));
782 button->SetToolTipText("Swap to big view");
783 hfrm->AddFrame(button);
784 button->Connect("Clicked()","SplitGLView",this,"SwapToMainView()");
786 // create (embed) a GL viewer inside
787 fViewer2 = new TGLEmbeddedViewer(hfrm, fPad);
788 hfrm->AddFrame(fViewer2->GetFrame(), new TGLayoutHints(kLHintsExpandX |
790 frm->AddFrame(hfrm, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
792 // set the camera to orthographic (XOY) for this viewer
793 fViewer2->SetCurrentCamera(TGLViewer::kCameraOrthoXOY);
794 // connect signal we are interested to
795 fViewer2->Connect("MouseOver(TGLPhysicalShape*)", "SplitGLView", this,
796 "OnMouseOver(TGLPhysicalShape*)");
797 fViewer2->Connect("Activated()", "SplitGLView", this,
798 "OnViewerActivated()");
799 fViewer2->Connect("MouseIdle(TGLPhysicalShape*,UInt_t,UInt_t)",
801 "OnMouseIdle(TGLPhysicalShape*,UInt_t,UInt_t)");
802 fViewer2->Connect("Clicked(TObject*)", "SplitGLView", this,
803 "OnClicked(TObject*)");
804 fViewer[2] = new TEveViewer("SplitGLViewer[2]");
805 fViewer[2]->SetGLViewer(fViewer2);
806 fViewer[2]->IncDenyDestroy();
807 if (fIsEmbedded && gEve) {
808 fRPhiMgr->ImportElements((TEveElement *)gEve->GetGlobalScene());
809 fRPhiMgr->ImportElements((TEveElement *)gEve->GetEventScene());
810 fRPhiMgr->SetProjection(TEveProjection::kPT_RPhi);
811 fViewer[2]->AddScene(s);
812 gEve->AddElement(fViewer[2], gEve->GetViewers());
817 // Summary view ... incomplete
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));
831 if (fIsEmbedded && gEve) {
832 gEve->GetListTree()->Connect("Clicked(TGListTreeItem*, Int_t, Int_t, Int_t)",
833 "SplitGLView", this, "ItemClicked(TGListTreeItem*, Int_t, Int_t, Int_t)");
836 fShapedToolTip = new TGShapedToolTip("$ALICE_ROOT/EVE/alice-data/Default.png", 120, 22, 160, 110,
837 23, 115, 12, "#ffff80");
838 Resize(GetDefaultSize());
842 fSplitFrame->Layout();
843 // !!!! LoadConfig(".everc");
846 //______________________________________________________________________________
847 SplitGLView::~SplitGLView()
849 // Clean up main frame...
852 fMenuFile->Disconnect("Activated(Int_t)", this, "HandleMenu(Int_t)");
853 fMenuCamera->Disconnect("Activated(Int_t)", this, "HandleMenu(Int_t)");
854 fMenuScene->Disconnect("Activated(Int_t)", this, "HandleMenu(Int_t)");
855 fMenuHelp->Disconnect("Activated(Int_t)", this, "HandleMenu(Int_t)");
856 fViewer0->Disconnect("MouseOver(TGLPhysicalShape*)", this,
857 "OnMouseOver(TGLPhysicalShape*)");
858 fViewer0->Disconnect("Activated()", this, "OnViewerActivated()");
859 fViewer0->Disconnect("MouseIdle(TGLPhysicalShape*,UInt_t,UInt_t)",
860 this, "OnMouseIdle(TGLPhysicalShape*,UInt_t,UInt_t)");
861 fViewer1->Disconnect("MouseOver(TGLPhysicalShape*)", this,
862 "OnMouseOver(TGLPhysicalShape*)");
863 fViewer1->Disconnect("Activated()", this, "OnViewerActivated()");
864 fViewer1->Disconnect("MouseIdle(TGLPhysicalShape*,UInt_t,UInt_t)",
865 this, "OnMouseIdle(TGLPhysicalShape*,UInt_t,UInt_t)");
866 fViewer2->Disconnect("MouseOver(TGLPhysicalShape*)", this,
867 "OnMouseOver(TGLPhysicalShape*)");
868 fViewer2->Disconnect("Activated()", this, "OnViewerActivated()");
869 fViewer2->Disconnect("MouseIdle(TGLPhysicalShape*,UInt_t,UInt_t)",
870 this, "OnMouseIdle(TGLPhysicalShape*,UInt_t,UInt_t)");
876 delete fShapedToolTip;
890 gApplication->Terminate(0);
894 //______________________________________________________________________________
895 void SplitGLView::HandleMenu(Int_t id)
897 // Handle menu items.
899 static TString rcdir(".");
900 static TString rcfile(".everc");
906 static TString dir(".");
908 fi.fFileTypes = filetypes;
909 fi.fIniDir = StrDup(dir);
910 new TGFileDialog(gClient->GetRoot(), this, kFDOpen, &fi);
912 OpenFile(fi.fFilename);
917 case kFileLoadConfig:
920 fi.fFileTypes = rcfiletypes;
921 fi.fIniDir = StrDup(rcdir);
922 fi.fFilename = StrDup(rcfile);
923 new TGFileDialog(gClient->GetRoot(), this, kFDOpen, &fi);
925 rcfile = fi.fFilename;
926 LoadConfig(fi.fFilename);
932 case kFileSaveConfig:
935 fi.fFileTypes = rcfiletypes;
936 fi.fIniDir = StrDup(rcdir);
937 fi.fFilename = StrDup(rcfile);
938 new TGFileDialog(gClient->GetRoot(), this, kFDSave, &fi);
940 rcfile = fi.fFilename;
941 SaveConfig(fi.fFilename);
953 fActViewer->SetCurrentCamera(TGLViewer::kCameraPerspYOZ);
957 fActViewer->SetCurrentCamera(TGLViewer::kCameraPerspXOZ);
961 fActViewer->SetCurrentCamera(TGLViewer::kCameraPerspXOY);
965 fActViewer->SetCurrentCamera(TGLViewer::kCameraOrthoXOY);
969 fActViewer->SetCurrentCamera(TGLViewer::kCameraOrthoXOZ);
973 fActViewer->SetCurrentCamera(TGLViewer::kCameraOrthoZOY);
984 fActViewer->UpdateScene();
988 case kSceneUpdateAll:
989 fViewer0->UpdateScene();
990 fViewer1->UpdateScene();
991 fViewer2->UpdateScene();
1006 rootx = gSystem->Getenv("ROOTSYS");
1007 if (!rootx.IsNull()) rootx += "/bin";
1009 rootx += "/root -a &";
1010 gSystem->Exec(rootx);
1013 new TWin32SplashThread(kTRUE);
1016 sprintf(str, "About ROOT %s...", gROOT->GetVersion());
1017 hd = new TRootHelpDialog(this, str, 600, 400);
1018 hd->SetText(gHelpAbout);
1030 //______________________________________________________________________________
1031 void SplitGLView::OnClicked(TObject *obj)
1033 // Handle click events in GL viewer
1036 fStatusBar->SetText(Form("User clicked on: \"%s\"", obj->GetName()), 1);
1038 fStatusBar->SetText("", 1);
1041 //______________________________________________________________________________
1042 void SplitGLView::OnMouseIdle(TGLPhysicalShape *shape, UInt_t posx, UInt_t posy)
1044 // Slot used to handle "OnMouseIdle" signal coming from any GL viewer.
1045 // We receive a pointer on the physical shape in which the mouse cursor is
1046 // and the actual cursor position (x,y)
1051 static TH1F *h1f = 0;
1052 TFormula *form1 = new TFormula("form1","abs(sin(x)/x)");
1053 form1->Update(); // silent warning about unused variable...
1054 TF1 *sqroot = new TF1("sqroot","x*gaus(0) + [3]*form1",0,10);
1055 sqroot->SetParameters(10,4,1,20);
1057 h1f = new TH1F("h1f","",50,0,10);
1059 h1f->SetFillColor(45);
1061 h1f->FillRandom("sqroot",200);
1063 if (fShapedToolTip) {
1064 fShapedToolTip->UnmapWindow();
1066 if (shape && shape->GetLogical() && shape->GetLogical()->GetExternal()) {
1067 // get the actual viewer who actually emitted the signal
1068 TGLEmbeddedViewer *actViewer = dynamic_cast<TGLEmbeddedViewer*>((TQObject*)gTQSender);
1069 // then translate coordinates from the root (screen) coordinates
1070 // to the actual frame (viewer) ones
1071 gVirtualX->TranslateCoordinates(actViewer->GetFrame()->GetId(),
1072 gClient->GetDefaultRoot()->GetId(), posx, posy, x, y,
1074 // Then display our tooltip at this x,y location
1075 if (fShapedToolTip) {
1076 fShapedToolTip->Show(x+5, y+5, Form("%s\n \n%s",
1077 shape->GetLogical()->GetExternal()->IsA()->GetName(),
1078 shape->GetLogical()->GetExternal()->GetName()), h1f);
1083 //______________________________________________________________________________
1084 void SplitGLView::OnMouseOver(TGLPhysicalShape *shape)
1086 // Slot used to handle "OnMouseOver" signal coming from any GL viewer.
1087 // We receive a pointer on the physical shape in which the mouse cursor is.
1089 // display informations on the physical shape in the status bar
1090 if (shape && shape->GetLogical() && shape->GetLogical()->GetExternal())
1091 fStatusBar->SetText(Form("Mouse Over: \"%s\"",
1092 shape->GetLogical()->GetExternal()->GetName()), 0);
1094 fStatusBar->SetText("", 0);
1097 //______________________________________________________________________________
1098 void SplitGLView::OnViewerActivated()
1100 // Slot used to handle "Activated" signal coming from any GL viewer.
1101 // Used to know which GL viewer is active.
1103 static Pixel_t green = 0;
1104 // set the actual GL viewer frame to default color
1105 if (fActViewer && fActViewer->GetFrame())
1106 fActViewer->GetFrame()->ChangeBackground(GetDefaultFrameBackground());
1108 // change the actual GL viewer to the one who emitted the signal
1109 // fActViewer = (TGLEmbeddedViewer *)gTQSender;
1110 fActViewer = dynamic_cast<TGLEmbeddedViewer*>((TQObject*)gTQSender);
1112 if (fActViewer == 0) {
1113 printf ("dyncast failed ...\n");
1117 // get the highlight color (only once)
1119 gClient->GetColorByName("green", green);
1121 // set the new actual GL viewer frame to highlight color
1122 if (fActViewer->GetFrame())
1123 fActViewer->GetFrame()->ChangeBackground(green);
1125 // update menu entries to match actual viewer's options
1126 if (fActViewer->GetOrthoXOYCamera()->GetDollyToZoom() &&
1127 fActViewer->GetOrthoXOZCamera()->GetDollyToZoom() &&
1128 fActViewer->GetOrthoZOYCamera()->GetDollyToZoom())
1129 fMenuCamera->UnCheckEntry(kGLOrthoDolly);
1131 fMenuCamera->CheckEntry(kGLOrthoDolly);
1133 if (fActViewer->GetOrthoXOYCamera()->GetEnableRotate() &&
1134 fActViewer->GetOrthoXOYCamera()->GetEnableRotate() &&
1135 fActViewer->GetOrthoXOYCamera()->GetEnableRotate())
1136 fMenuCamera->CheckEntry(kGLOrthoRotate);
1138 fMenuCamera->UnCheckEntry(kGLOrthoRotate);
1141 //______________________________________________________________________________
1142 void SplitGLView::OpenFile(const char *fname)
1144 // Open a Root file to display a geometry in the GL viewers.
1146 TString filename = fname;
1147 // check if the file type is correct
1148 if (!filename.EndsWith(".root")) {
1149 new TGMsgBox(gClient->GetRoot(), this, "OpenFile",
1150 Form("The file \"%s\" is not a root file!", fname),
1151 kMBIconExclamation, kMBOk);
1154 // check if the root file contains a geometry
1155 if (TGeoManager::Import(fname) == 0) {
1156 new TGMsgBox(gClient->GetRoot(), this, "OpenFile",
1157 Form("The file \"%s\" does't contain a geometry", fname),
1158 kMBIconExclamation, kMBOk);
1161 gGeoManager->DefaultColors();
1162 // delete previous primitives (if any)
1163 fPad->GetListOfPrimitives()->Delete();
1164 // and add the geometry to eve pad (container)
1165 fPad->GetListOfPrimitives()->Add(gGeoManager->GetTopVolume());
1166 // paint the geometry in each GL viewer
1167 fViewer0->PadPaint(fPad);
1168 fViewer1->PadPaint(fPad);
1169 fViewer2->PadPaint(fPad);
1172 //______________________________________________________________________________
1173 void SplitGLView::ToggleOrthoRotate()
1175 // Toggle state of the 'Ortho allow rotate' menu entry.
1177 if (fMenuCamera->IsEntryChecked(kGLOrthoRotate))
1178 fMenuCamera->UnCheckEntry(kGLOrthoRotate);
1180 fMenuCamera->CheckEntry(kGLOrthoRotate);
1181 Bool_t state = fMenuCamera->IsEntryChecked(kGLOrthoRotate);
1183 fActViewer->GetOrthoXOYCamera()->SetEnableRotate(state);
1184 fActViewer->GetOrthoXOYCamera()->SetEnableRotate(state);
1185 fActViewer->GetOrthoXOYCamera()->SetEnableRotate(state);
1189 //______________________________________________________________________________
1190 void SplitGLView::ToggleOrthoDolly()
1192 // Toggle state of the 'Ortho allow dolly' menu entry.
1194 if (fMenuCamera->IsEntryChecked(kGLOrthoDolly))
1195 fMenuCamera->UnCheckEntry(kGLOrthoDolly);
1197 fMenuCamera->CheckEntry(kGLOrthoDolly);
1198 Bool_t state = ! fMenuCamera->IsEntryChecked(kGLOrthoDolly);
1200 fActViewer->GetOrthoXOYCamera()->SetDollyToZoom(state);
1201 fActViewer->GetOrthoXOZCamera()->SetDollyToZoom(state);
1202 fActViewer->GetOrthoZOYCamera()->SetDollyToZoom(state);
1206 //______________________________________________________________________________
1207 void SplitGLView::ItemClicked(TGListTreeItem *item, Int_t, Int_t, Int_t)
1209 // Item has been clicked, based on mouse button do:
1211 static const TEveException eh("SplitGLView::ItemClicked ");
1212 TEveElement* re = (TEveElement*)item->GetUserData();
1214 TObject* obj = re->GetObject(eh);
1215 if (obj->InheritsFrom("TEveViewer")) {
1216 TGLViewer *v = ((TEveViewer *)obj)->GetGLViewer();
1218 if (v->InheritsFrom("TGLEmbeddedViewer")) {
1219 TGLEmbeddedViewer *ev = (TGLEmbeddedViewer *)v;
1220 gVirtualX->SetInputFocus(ev->GetGLWidget()->GetId());
1225 //______________________________________________________________________________
1226 void SplitGLView::LoadConfig(const char *fname)
1229 Int_t height, width;
1230 TEnv *env = new TEnv(fname);
1232 Int_t mainheight = env->GetValue("MainView.Height", 434);
1233 Int_t blwidth = env->GetValue("Bottom.Left.Width", 266);
1234 Int_t bcwidth = env->GetValue("Bottom.Center.Width", 266);
1235 Int_t brwidth = env->GetValue("Bottom.Right.Width", 266);
1236 Int_t top_height = env->GetValue("Right.Tab.Height", 0);
1237 Int_t bottom_height = env->GetValue("Bottom.Tab.Height", 0);
1239 if (fIsEmbedded && gEve) {
1240 Int_t sel = env->GetValue("Eve.Selection", gEve->GetSelection()->GetPickToSelect());
1241 Int_t hi = env->GetValue("Eve.Highlight", gEve->GetHighlight()->GetPickToSelect());
1242 gEve->GetBrowser()->EveMenu(9+sel);
1243 gEve->GetBrowser()->EveMenu(13+hi);
1245 width = env->GetValue("Eve.Width", (Int_t)gEve->GetBrowser()->GetWidth());
1246 height = env->GetValue("Eve.Height", (Int_t)gEve->GetBrowser()->GetHeight());
1247 gEve->GetBrowser()->Resize(width, height);
1250 // top (main) split frame
1251 width = fSplitFrame->GetFirst()->GetWidth();
1252 fSplitFrame->GetFirst()->Resize(width, mainheight);
1253 // bottom left split frame
1254 height = fSplitFrame->GetSecond()->GetFirst()->GetHeight();
1255 fSplitFrame->GetSecond()->GetFirst()->Resize(blwidth, height);
1256 // bottom center split frame
1257 height = fSplitFrame->GetSecond()->GetSecond()->GetFirst()->GetHeight();
1258 fSplitFrame->GetSecond()->GetSecond()->GetFirst()->Resize(bcwidth, height);
1259 // bottom right split frame
1260 height = fSplitFrame->GetSecond()->GetSecond()->GetSecond()->GetHeight();
1261 fSplitFrame->GetSecond()->GetSecond()->GetSecond()->Resize(brwidth, height);
1263 fSplitFrame->Layout();
1265 if (fIsEmbedded && gEve) {
1266 width = ((TGCompositeFrame *)gEve->GetBrowser()->GetTabBottom()->GetParent())->GetWidth();
1267 ((TGCompositeFrame *)gEve->GetBrowser()->GetTabBottom()->GetParent())->Resize(width, bottom_height);
1268 width = ((TGCompositeFrame *)gEve->GetBrowser()->GetTabRight()->GetParent())->GetWidth();
1269 ((TGCompositeFrame *)gEve->GetBrowser()->GetTabRight()->GetParent())->Resize(width, top_height);
1273 //______________________________________________________________________________
1274 void SplitGLView::SaveConfig(const char *fname)
1277 Int_t bottom_height = 0;
1278 Int_t top_height = 0;
1280 TEnv *env = new TEnv(fname);
1282 if (fIsEmbedded && gEve) {
1283 env->SetValue("Eve.Width", (Int_t)gEve->GetBrowser()->GetWidth());
1284 env->SetValue("Eve.Height", (Int_t)gEve->GetBrowser()->GetHeight());
1286 // get top (main) split frame
1287 frm = fSplitFrame->GetFirst();
1288 env->SetValue("MainView.Height", (Int_t)frm->GetHeight());
1289 // get bottom left split frame
1290 frm = fSplitFrame->GetSecond()->GetFirst();
1291 env->SetValue("Bottom.Left.Width", (Int_t)frm->GetWidth());
1292 // get bottom center split frame
1293 frm = fSplitFrame->GetSecond()->GetSecond()->GetFirst();
1294 env->SetValue("Bottom.Center.Width", (Int_t)frm->GetWidth());
1295 // get bottom right split frame
1296 frm = fSplitFrame->GetSecond()->GetSecond()->GetSecond();
1297 env->SetValue("Bottom.Right.Width", (Int_t)frm->GetWidth());
1298 if (fIsEmbedded && gEve) {
1299 top_height = (Int_t)((TGCompositeFrame *)gEve->GetBrowser()->GetTabRight()->GetParent())->GetHeight();
1300 env->SetValue("Right.Tab.Height", top_height);
1301 bottom_height = (Int_t)((TGCompositeFrame *)gEve->GetBrowser()->GetTabBottom()->GetParent())->GetHeight();
1302 env->SetValue("Bottom.Tab.Height", bottom_height);
1304 env->SetValue("Eve.Selection", gEve->GetSelection()->GetPickToSelect());
1305 env->SetValue("Eve.Highlight", gEve->GetHighlight()->GetPickToSelect());
1308 env->SaveLevel(kEnvLocal);
1310 if (!gSystem->AccessPathName(Form("%s.new", fname))) {
1311 gSystem->Exec(Form("del %s", fname));
1312 gSystem->Rename(Form("%s.new", fname), fname);
1317 //______________________________________________________________________________
1318 void SplitGLView::SwapToMainView()
1320 TGPictureButton *src = (TGPictureButton*)gTQSender;
1321 TGCompositeFrame *parent = (TGCompositeFrame *)(src->GetParent());
1322 TGFrame *source = dynamic_cast<TGFrameElement*>(parent->GetList()->Last())->fFrame;
1323 if (!source) return;
1325 TGSplitFrame *dest = fSplitFrame->GetFirst();
1327 TGFrame *prev = (TGFrame *)(dest->GetFrame());
1329 if ((source != prev) && (source != dest))
1330 TGSplitFrame::SwitchFrames(source, dest, prev);
1333 //______________________________________________________________________________
1334 void SplitGLView::UpdateSummary()
1336 // Update summary of current event.
1337 // Currently unused.
1340 TEveElement::List_i i;
1341 TEveElement::List_i j;
1344 HtmlObjTable *table;
1345 TEveEventManager *mgr = gEve ? gEve->GetCurrentEvent() : 0;
1347 fgHtmlSummary->Clear("D");
1348 for (i=mgr->BeginChildren(); i!=mgr->EndChildren(); ++i)
1350 el = ((TEveElement*)(*i));
1351 if (el->IsA() == TEvePointSet::Class()) {
1352 TEvePointSet *ps = (TEvePointSet *)el;
1353 TString ename = ps->GetElementName();
1354 TString etitle = ps->GetElementTitle();
1355 //ename.Remove(ename.First('\''));
1356 //etitle.Remove(0, 2);
1357 Int_t nel = atoi(etitle.Data());
1358 table = fgHtmlSummary->AddTable(ename, 0, nel);
1360 else if (el->IsA() == TEveTrackList::Class()) {
1361 TEveTrackList *tracks = (TEveTrackList *)el;
1362 TString ename = tracks->GetElementName();
1363 // ename.Remove(ename.First('\''));
1364 table = fgHtmlSummary->AddTable(ename.Data(), 5,
1365 tracks->NumChildren(), kTRUE, "first");
1366 table->SetLabel(0, "Momentum");
1367 table->SetLabel(1, "P_t");
1368 table->SetLabel(2, "Phi");
1369 table->SetLabel(3, "Theta");
1370 table->SetLabel(4, "Eta");
1372 for (j=tracks->BeginChildren(); j!=tracks->EndChildren(); ++j) {
1373 Float_t p = ((TEveTrack*)(*j))->GetMomentum().Mag();
1374 table->SetValue(0, k, p);
1375 Float_t pt = ((TEveTrack*)(*j))->GetMomentum().Perp();
1376 table->SetValue(1, k, pt);
1377 Float_t phi = ((TEveTrack*)(*j))->GetMomentum().Phi();
1378 table->SetValue(2, k, phi);
1379 Float_t theta = ((TEveTrack*)(*j))->GetMomentum().Theta();
1380 table->SetValue(3, k, theta);
1381 Float_t eta = ((TEveTrack*)(*j))->GetMomentum().Eta();
1382 table->SetValue(4, k, eta);
1387 fgHtmlSummary->Build();
1389 fgHtml->ParseText((char*)fgHtmlSummary->Html().Data());
1397 #pragma link C++ class SplitGLView;