]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/alice-macros/SplitGLView.C
Merge the following revisions between 29371 and 30342 from
[u/mrichter/AliRoot.git] / EVE / alice-macros / SplitGLView.C
1
2 #include "TApplication.h"
3 #include "TSystem.h"
4 #include "TGFrame.h"
5 #include "TGLayout.h"
6 #include "TGSplitter.h"
7 #include "TGLWidget.h"
8 #include "TEvePad.h"
9 #include "TGeoManager.h"
10 #include "TString.h"
11 #include "TGMenu.h"
12 #include "TGStatusBar.h"
13 #include "TGFileDialog.h"
14 #include "TGMsgBox.h"
15 #include "TGLPhysicalShape.h"
16 #include "TGLLogicalShape.h"
17 #include "HelpText.h"
18 #include "TClass.h"
19 #include "Riostream.h"
20 #include "TEnv.h"
21 #include "TGListTree.h"
22 #include "TOrdCollection.h"
23 #include "TArrayF.h"
24 #include "TGHtml.h"
25 #include "TPRegexp.h"
26
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"
35
36 #include "TRootEmbeddedCanvas.h"
37 #include "TGSplitFrame.h"
38 #include "TGLOverlayButton.h"
39 #include "TGLEmbeddedViewer.h"
40 #include "TGShapedFrame.h"
41 #include "TGButton.h"
42 #include "TGTab.h"
43 #include "TEnv.h"
44
45 #include "TCanvas.h"
46 #include "TFormula.h"
47 #include "TF1.h"
48 #include "TH1F.h"
49
50 #ifdef WIN32
51 #include <TWin32SplashThread.h>
52 #endif
53
54 const char *filetypes[] = { 
55    "ROOT files",    "*.root",
56    "All files",     "*",
57    0,               0 
58 };
59
60 const char *rcfiletypes[] = { 
61    "All files",     "*",
62    0,               0 
63 };
64
65 ////////////////////////////////////////////////////////////////////////////////
66 class TGShapedToolTip : public TGShapedFrame {
67
68 private:
69    TGShapedToolTip(const TGShapedToolTip&); // Not implemented
70    TGShapedToolTip& operator=(const TGShapedToolTip&); // Not implemented
71
72 protected:
73    Int_t                 fTextX, fTextY, fTextH;
74    TString               fTextCol;
75
76    TRootEmbeddedCanvas  *fEc;       // embedded canvas for histogram
77    TH1                  *fHist;     // user histogram
78    TString               fText;     // info (as tool tip) text
79
80    virtual void          DoRedraw() {}
81
82 public:
83    TGShapedToolTip(const char *picname, Int_t cx=0, Int_t cy=0, Int_t cw=0, 
84                    Int_t ch=0, Int_t tx=0, Int_t ty=0, Int_t th=0, 
85                    const char *col="#ffffff");
86    virtual ~TGShapedToolTip();
87
88    virtual void   CloseWindow();
89    void           CreateCanvas(Int_t cx, Int_t cy, Int_t cw, Int_t ch);
90    void           CreateCanvas(Int_t cw, Int_t ch, TGLayoutHints *hints);
91    TH1           *GetHisto() const { return fHist; }
92    const char    *GetText() const { return fText.Data(); }
93    void           Refresh();
94    void           SetHisto(TH1 *hist);
95    void           SetText(const char *text);
96    void           SetTextColor(const char *col);
97    void           SetTextAttributes(Int_t tx, Int_t ty, Int_t th, const char *col=0);
98    void           Show(Int_t x, Int_t y, const char *text = 0, TH1 *hist = 0);
99
100    ClassDef(TGShapedToolTip, 0) // Shaped composite frame
101 };
102
103 ////////////////////////////////////////////////////////////////////////////////
104 class HtmlObjTable : public TObject {
105 public:                     // make them public for shorter code
106
107    TString   fName;
108    Int_t     fNValues;      // number of values
109    Int_t     fNFields;      // number of fields
110    TArrayF  *fValues;
111    TString  *fLabels;
112    Bool_t    fExpand;
113
114    TString   fHtml;         // HTML output code
115
116    void Build();
117    void BuildTitle();
118    void BuildLabels();
119    void BuildTable();
120
121 public:
122    HtmlObjTable(const char *name, Int_t nfields, Int_t nvals, Bool_t exp=kTRUE);
123    virtual ~HtmlObjTable();
124
125    void     SetLabel(Int_t col, const char *label) { fLabels[col] = label; }
126    void     SetValue(Int_t col, Int_t row, Float_t val) { fValues[col].SetAt(val, row); }
127    TString  Html() const { return fHtml; }
128
129    ClassDef(HtmlObjTable, 0);
130 };
131
132 ////////////////////////////////////////////////////////////////////////////////
133 class HtmlSummary {
134 public:                           // make them public for shorter code
135    Int_t           fNTables;
136    TOrdCollection *fObjTables;    // ->array of object tables
137    TString         fHtml;         // output HTML string
138    TString         fTitle;        // page title
139    TString         fHeader;       // HTML header
140    TString         fFooter;       // HTML footer
141
142    void     MakeHeader();
143    void     MakeFooter();
144
145 public:
146    HtmlSummary(const char *title);
147    virtual ~HtmlSummary();
148
149    HtmlObjTable  *AddTable(const char *name, Int_t nfields, Int_t nvals, 
150                            Bool_t exp=kTRUE, Option_t *opt="");
151    HtmlObjTable  *GetTable(Int_t at) const { return (HtmlObjTable *)fObjTables->At(at); }
152    void           Build();
153    void           Clear(Option_t *option="");
154    void           Reset(Option_t *option="");
155    TString        Html() const { return fHtml; }
156
157    ClassDef(HtmlSummary, 0);
158 };
159
160 ////////////////////////////////////////////////////////////////////////////////
161 class SplitGLView : public TGMainFrame {
162
163 public:
164    enum EMyCommands {
165       kFileOpen, kFileExit, kFileLoadConfig, kFileSaveConfig,
166       kHelpAbout, kGLPerspYOZ, kGLPerspXOZ, kGLPerspXOY, kGLXOY,
167       kGLXOZ, kGLZOY, kGLOrthoRotate, kGLOrthoDolly, kSceneUpdate, 
168       kSceneUpdateAll, kSummaryUpdate
169    };
170
171 private:
172    TEvePad               *fPad;           // pad used as geometry container
173    TGSplitFrame          *fSplitFrame;    // main (first) split frame
174    TGLEmbeddedViewer     *fViewer0;       // main GL viewer
175    TGLEmbeddedViewer     *fViewer1;       // first GL viewer
176    TGLEmbeddedViewer     *fViewer2;       // second GL viewer
177    TGLEmbeddedViewer     *fActViewer;     // actual (active) GL viewer
178    static HtmlSummary    *fgHtmlSummary;  // summary HTML table
179    static TGHtml         *fgHtml;
180    TGMenuBar             *fMenuBar;       // main menu bar
181    TGPopupMenu           *fMenuFile;      // 'File' popup menu
182    TGPopupMenu           *fMenuHelp;      // 'Help' popup menu
183    TGPopupMenu           *fMenuCamera;    // 'Camera' popup menu
184    TGPopupMenu           *fMenuScene;     // 'Scene' popup menu
185    TGStatusBar           *fStatusBar;     // status bar
186    TGShapedToolTip       *fShapedToolTip; // shaped tooltip
187    Bool_t                 fIsEmbedded;
188
189    TEveViewer            *fViewer[3];
190    TEveProjectionManager *fRPhiMgr;
191    TEveProjectionManager *fRhoZMgr;
192
193 public:
194    SplitGLView(const TGWindow *p=0, UInt_t w=800, UInt_t h=600, Bool_t embed=kFALSE);
195    virtual ~SplitGLView();
196
197    void           ItemClicked(TGListTreeItem *item, Int_t btn, Int_t x, Int_t y);
198    void           HandleMenu(Int_t id);
199    void           OnClicked(TObject *obj);
200    void           OnMouseIdle(TGLPhysicalShape *shape, UInt_t posx, UInt_t posy);
201    void           OnMouseOver(TGLPhysicalShape *shape);
202    void           OnViewerActivated();
203    void           OpenFile(const char *fname);
204    void           SwapToMainView(TGLViewerBase *viewer);
205    void           ToggleOrthoRotate();
206    void           ToggleOrthoDolly();
207    void           UnDock(TGLViewerBase *viewer);
208    void           LoadConfig(const char *fname);
209    void           SaveConfig(const char *fname);
210    static void    UpdateSummary();
211
212    TEveProjectionManager *GetRPhiMgr() const { return fRPhiMgr; }
213    TEveProjectionManager *GetRhoZMgr() const { return fRhoZMgr; }
214
215    ClassDef(SplitGLView, 0)
216 };
217
218 TEveProjectionManager *gRPhiMgr = 0;
219 TEveProjectionManager *gRhoZMgr = 0;
220
221 ClassImp(TGShapedToolTip)
222 ClassImp(HtmlObjTable)
223 ClassImp(HtmlSummary)
224 ClassImp(SplitGLView)
225
226 HtmlSummary *SplitGLView::fgHtmlSummary = 0;
227 TGHtml *SplitGLView::fgHtml = 0;
228
229 //______________________________________________________________________________
230 TGShapedToolTip::TGShapedToolTip(const char *pname, Int_t cx, Int_t cy, Int_t cw, 
231                              Int_t ch, Int_t tx, Int_t ty, Int_t th, 
232                              const char *col) : 
233    TGShapedFrame(pname, gClient->GetDefaultRoot(), 400, 300, kTempFrame | 
234                  kHorizontalFrame), fEc(0), fHist(0)
235 {
236    // Shaped window constructor
237
238    fTextX = tx; fTextY = ty; fTextH = th;
239    if (col)
240       fTextCol = col;
241    else
242       fTextCol = "0x000000";
243
244    // create the embedded canvas
245    if ((cx > 0) && (cy > 0) && (cw > 0) && (ch > 0)) {
246       Int_t lhRight  = fWidth-cx-cw;
247       Int_t lhBottom = fHeight-cy-ch;
248       fEc = new TRootEmbeddedCanvas("ec", this, cw, ch, 0);
249       AddFrame(fEc, new TGLayoutHints(kLHintsTop | kLHintsLeft, cx, 
250                                       lhRight, cy, lhBottom));
251    }
252    MapSubwindows();
253    Resize();
254    Resize(fBgnd->GetWidth(), fBgnd->GetHeight());
255 }
256
257 //______________________________________________________________________________
258 TGShapedToolTip::~TGShapedToolTip() 
259 {
260    // Destructor.
261
262    if (fHist)
263       delete fHist;
264    if (fEc)
265       delete fEc;
266 }
267
268 //______________________________________________________________________________
269 void TGShapedToolTip::CloseWindow() 
270 {
271    // Close shaped window.
272    
273    DeleteWindow();
274 }
275
276 //______________________________________________________________________________
277 void TGShapedToolTip::Refresh()
278 {
279    // Redraw the window with current attributes.
280
281    const char *str = fText.Data();
282    char *string = strdup(str);
283    Int_t nlines = 0, size = fTextH;
284    TString fp = gEnv->GetValue("Root.TTFontPath", "");
285    TString ar = fp + "/arial.ttf";
286    char *s = strtok((char *)string, "\n");
287    TImage *img = (TImage*)fImage->Clone("img");
288    img->DrawText(fTextX, fTextY+(nlines*size), s, size, fTextCol, ar);
289    while ((s = strtok(0, "\n"))) {
290       nlines++;
291       img->DrawText(fTextX, fTextY+(nlines*size), s, size, fTextCol, ar);
292    }
293    img->PaintImage(fId, 0, 0, 0, 0, 0, 0, "opaque");
294    free(string);
295    delete img;
296    gVirtualX->Update();
297 }
298
299 //______________________________________________________________________________
300 void TGShapedToolTip::CreateCanvas(Int_t cx, Int_t cy, Int_t cw, Int_t ch)
301 {
302
303    // create the embedded canvas
304    Int_t lhRight  = fWidth-cx-cw;
305    Int_t lhBottom = fHeight-cy-ch;
306    fEc = new TRootEmbeddedCanvas("ec", this, cw, ch, 0);
307    AddFrame(fEc, new TGLayoutHints(kLHintsTop | kLHintsLeft, cx, 
308                                    lhRight, cy, lhBottom));
309    MapSubwindows();
310    Resize();
311    Resize(fBgnd->GetWidth(), fBgnd->GetHeight());
312    if (IsMapped()) {
313       Refresh();
314    }
315 }
316
317 //______________________________________________________________________________
318 void TGShapedToolTip::CreateCanvas(Int_t cw, Int_t ch, TGLayoutHints *hints)
319 {
320    // Create the embedded canvas.
321
322    fEc = new TRootEmbeddedCanvas("ec", this, cw, ch, 0);
323    AddFrame(fEc, hints);
324    MapSubwindows();
325    Resize();
326    Resize(fBgnd->GetWidth(), fBgnd->GetHeight());
327    if (IsMapped()) {
328       Refresh();
329    }
330 }
331
332 //______________________________________________________________________________
333 void TGShapedToolTip::SetHisto(TH1 *hist)
334 {
335    // Set which histogram has to be displayed in the embedded canvas.
336
337    if (hist) {
338       if (fHist) {
339          delete fHist;
340          if (fEc)
341             fEc->GetCanvas()->Clear();
342       }
343       fHist = (TH1 *)hist->Clone();
344       if (fEc) {
345          fEc->GetCanvas()->SetBorderMode(0);
346          fEc->GetCanvas()->SetFillColor(10);
347          fEc->GetCanvas()->cd();
348          fHist->Draw();
349          fEc->GetCanvas()->Update();
350       }
351    }
352 }
353
354 //______________________________________________________________________________
355 void TGShapedToolTip::SetText(const char *text)
356 {
357    // Set which text has to be displayed.
358
359    if (text) {
360       fText = text;
361    }
362    if (IsMapped())
363       Refresh();
364 }
365
366 //______________________________________________________________________________
367 void TGShapedToolTip::SetTextColor(const char *col)
368 {
369    // Set text color.
370
371    fTextCol = col;
372    if (IsMapped())
373       Refresh();
374 }
375
376 //______________________________________________________________________________
377 void TGShapedToolTip::SetTextAttributes(Int_t tx, Int_t ty, Int_t th, 
378                                         const char *col)
379 {
380    // Set text attributes (position, size and color).
381
382    fTextX = tx; fTextY = ty; fTextH = th;
383    if (col)
384       fTextCol = col;
385    if (IsMapped())
386       Refresh();
387 }
388
389 //______________________________________________________________________________
390 void TGShapedToolTip::Show(Int_t x, Int_t y, const char *text, TH1 *hist)
391 {
392    // Show (popup) the shaped window at location x,y and possibly
393    // set the text and histogram to be displayed.
394
395    Move(x, y);
396    MapWindow();
397
398    if (text)
399       SetText(text);
400    if (hist)
401       SetHisto(hist);
402    // end of demo code -------------------------------------------
403    if (fHist) {
404       fEc->GetCanvas()->SetBorderMode(0);
405       fEc->GetCanvas()->SetFillColor(10);
406       fEc->GetCanvas()->cd();
407       fHist->Draw();
408       fEc->GetCanvas()->Update();
409    }
410    Refresh();
411 }
412
413 //______________________________________________________________________________
414 HtmlObjTable::HtmlObjTable(const char *name, Int_t nfields, Int_t nvals, Bool_t exp) : 
415    fName(name), fNValues(nvals), fNFields(nfields), fExpand(exp)
416 {
417    // Constructor.
418
419    fValues = new TArrayF[fNFields];
420    for (int i=0;i<fNFields;i++)
421       fValues[i].Set(nvals);
422    fLabels = new TString[fNFields];
423 }
424
425 //______________________________________________________________________________
426 HtmlObjTable::~HtmlObjTable()
427 {
428    // Destructor.
429
430    delete [] fValues;
431    delete [] fLabels;
432 }
433
434 //______________________________________________________________________________
435 void HtmlObjTable::Build()
436 {
437    // Build HTML code.
438
439    fHtml = "<table width=100% border=1 cellspacing=0 cellpadding=0 bgcolor=f0f0f0> ",
440
441    BuildTitle();
442    if (fExpand && (fNFields > 0) && (fNValues > 0)) {
443       BuildLabels();
444       BuildTable();
445    }
446
447    fHtml += "</table>";
448 }
449
450 //______________________________________________________________________________
451 void HtmlObjTable::BuildTitle()
452 {
453    // Build table title.
454    
455    fHtml += "<tr><td colspan=";
456    fHtml += Form("%d>", fNFields+1);
457    fHtml += "<table width=100% border=0 cellspacing=2 cellpadding=0 bgcolor=6e6ea0>";
458    fHtml += "<tr><td align=left>";
459    fHtml += "<font face=Verdana size=3 color=ffffff><b><i>";
460    fHtml += fName;
461    fHtml += "</i></b></font></td>";
462    fHtml += "<td>";
463    fHtml += "<td align=right> ";
464    fHtml += "<font face=Verdana size=3 color=ffffff><b><i>";
465    fHtml += Form("Size = %d", fNValues);
466    fHtml += "</i></b></font></td></tr>";
467    fHtml += "</table>";
468    fHtml += "</td></tr>";
469 }
470
471 //______________________________________________________________________________
472 void HtmlObjTable::BuildLabels()
473 {
474    // Build table labels.
475
476    Int_t i;
477    fHtml += "<tr bgcolor=c0c0ff>";
478    fHtml += "<th> </th>"; // for the check boxes
479    for (i=0;i<fNFields;i++) {
480       fHtml += "<th> ";
481       fHtml += fLabels[i];
482       fHtml += " </th>"; // for the check boxes
483    }
484    fHtml += "</tr>";
485 }
486
487 //______________________________________________________________________________
488 void HtmlObjTable::BuildTable()
489 {
490    // Build part of table with values.
491
492    for (int i = 0; i < fNValues; i++) {
493       if (i%2)
494          fHtml += "<tr bgcolor=e0e0ff>";
495       else
496          fHtml += "<tr bgcolor=ffffff>";
497       
498       TString name = fName;
499       name.ReplaceAll(" ", "_");
500       // checkboxes
501       fHtml += "<td bgcolor=d0d0ff align=\"center\">";
502       fHtml += "<input type=\"checkbox\" name=\"";
503       fHtml += name;
504       fHtml += Form("[%d]\">",i);
505       fHtml += "</td>";
506
507       for (int j = 0; j < fNFields; j++) {
508          fHtml += "<td width=";
509          fHtml += Form("%d%%", 100/fNFields);
510          fHtml += " align=\"center\"";
511          fHtml += ">";
512          fHtml += Form("%1.4f", fValues[j][i]);
513          fHtml += "</td>";
514       }
515       fHtml += "</tr> ";
516    }
517 }
518
519 //______________________________________________________________________________
520 HtmlSummary::HtmlSummary(const char *title) : fNTables(0), fTitle(title)
521 {
522    // Constructor.
523
524    fObjTables = new TOrdCollection();
525 }
526
527 //______________________________________________________________________________
528 HtmlSummary::~HtmlSummary()
529 {
530    // Destructor.
531
532    Reset();
533 }
534
535 //______________________________________________________________________________
536 HtmlObjTable *HtmlSummary::AddTable(const char *name, Int_t nfields, Int_t nvals,
537                                     Bool_t exp, Option_t *option)
538 {
539    // Add a new table in our list of tables.
540
541    TString opt = option;
542    opt.ToLower();
543    HtmlObjTable *table = new HtmlObjTable(name, nfields, nvals, exp);
544    fNTables++;
545    if (opt.Contains("first"))
546       fObjTables->AddFirst(table);
547    else
548       fObjTables->Add(table);
549    return table;
550 }
551
552 //______________________________________________________________________________
553 void HtmlSummary::Clear(Option_t *option)
554 {
555    // Clear the table list.
556
557    if (option && option[0] == 'D')
558       fObjTables->Delete(option);
559    else
560       fObjTables->Clear(option);
561    fNTables = 0;
562 }
563
564 //______________________________________________________________________________
565 void HtmlSummary::Reset(Option_t *)
566 {
567    // Reset (delete) the table list;
568
569    delete fObjTables; fObjTables = 0;
570    fNTables = 0;
571 }
572
573 //______________________________________________________________________________
574 void HtmlSummary::Build()
575 {
576    // Build the summary.
577
578    MakeHeader();
579    for (int i=0;i<fNTables;i++) {
580       GetTable(i)->Build();
581       fHtml += GetTable(i)->Html();
582    }
583    MakeFooter();
584 }
585
586 //______________________________________________________________________________
587 void HtmlSummary::MakeHeader()
588 {
589    // Make HTML header.
590
591    fHeader  = "<html><head><title>";
592    fHeader += fTitle;
593    fHeader += "</title></head><body>";
594    fHeader += "<center><h2><font color=#2222ee><i>";
595    fHeader += fTitle;
596    fHeader += "</i></font></h2></center>";
597    fHtml    = fHeader;
598 }
599
600 //______________________________________________________________________________
601 void HtmlSummary::MakeFooter()
602 {
603    // Make HTML footer.
604
605    fFooter  = "<br><p><br><center><strong><font size=2 color=#2222ee>";
606    fFooter += "Example of using Html widget to display tabular data";
607    fFooter += "<br>";
608    fFooter += "© 2007-2008 Bertrand Bellenot";
609    fFooter += "</font></strong></center></body></html>";  
610    fHtml   += fFooter;
611 }
612
613 //______________________________________________________________________________
614 SplitGLView::SplitGLView(const TGWindow *p, UInt_t w, UInt_t h, Bool_t embed) :
615    TGMainFrame(p, w, h), fActViewer(0), fShapedToolTip(0), fIsEmbedded(embed)
616 {
617    // Main frame constructor.
618
619    TGSplitFrame    *frm    = 0;
620    TEveScene       *s      = 0;
621
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);
632
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);
644
645    fMenuScene = new TGPopupMenu(gClient->GetRoot());
646    fMenuScene->AddEntry("&Update Current", kSceneUpdate);
647    fMenuScene->AddEntry("Update &All", kSceneUpdateAll);
648
649    // create the "help" popup menu
650    fMenuHelp = new TGPopupMenu(gClient->GetRoot());
651    fMenuHelp->AddEntry("&About", kHelpAbout);
652
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 | 
662                                                             kLHintsRight));
663
664    AddFrame(fMenuBar, new TGLayoutHints(kLHintsTop | kLHintsExpandX));
665
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)");
675    
676    if (fIsEmbedded && gEve) {
677       // use status bar from the browser
678       fStatusBar = gEve->GetBrowser()->GetStatusBar();
679    }
680    else {
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, 
686                                              0, 0, 10, 0));
687    }
688
689    // create eve pad (our geometry container)
690    fPad = new TEvePad();
691
692    // create the split frames
693    fSplitFrame = new TGSplitFrame(this, 800, 600);
694    AddFrame(fSplitFrame, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
695    // split horizontaly
696    fSplitFrame->HSplit(350);
697    // split bottom part vartically
698    fSplitFrame->GetSecond()->VSplit(400);
699
700    TGLOverlayButton *but1, *but2, *but3, *but4, *but5, *but6;
701    // get top (main) split frame
702    frm = fSplitFrame->GetFirst();
703    // create (embed) a GL viewer inside
704    fViewer0 = new TGLEmbeddedViewer(frm, fPad);
705    but1 = new TGLOverlayButton(fViewer0, "Swap", 10.0, -10.0, 55.0, 16.0);
706    but1->Connect("Clicked(TGLViewerBase*)", "SplitGLView", this, "SwapToMainView(TGLViewerBase*)");
707    but2 = new TGLOverlayButton(fViewer0, "Undock", 70.0, -10.0, 55.0, 16.0);
708    but2->Connect("Clicked(TGLViewerBase*)", "SplitGLView", this, "UnDock(TGLViewerBase*)");
709    frm->AddFrame(fViewer0->GetFrame(), new TGLayoutHints(kLHintsExpandX | 
710                                                          kLHintsExpandY));
711    // set the camera to perspective (XOZ) for this viewer
712    fViewer0->SetCurrentCamera(TGLViewer::kCameraPerspXOZ);
713    // connect signal we are interested to
714    fViewer0->Connect("MouseOver(TGLPhysicalShape*)", "SplitGLView", this, 
715                      "OnMouseOver(TGLPhysicalShape*)");
716    fViewer0->Connect("Activated()", "SplitGLView", this, 
717                      "OnViewerActivated()");
718    fViewer0->Connect("MouseIdle(TGLPhysicalShape*,UInt_t,UInt_t)", 
719                      "SplitGLView", this, 
720                      "OnMouseIdle(TGLPhysicalShape*,UInt_t,UInt_t)");
721    fViewer0->Connect("Clicked(TObject*)", "SplitGLView", this, 
722                      "OnClicked(TObject*)");
723    fViewer[0] = new TEveViewer("SplitGLViewer[0]");
724    fViewer[0]->SetGLViewer(fViewer0, fViewer0->GetFrame());
725    fViewer[0]->IncDenyDestroy();
726    if (fIsEmbedded && gEve) {
727       fViewer[0]->AddScene(gEve->GetGlobalScene());
728       fViewer[0]->AddScene(gEve->GetEventScene());
729       gEve->AddElement(fViewer[0], gEve->GetViewers());
730       s = gEve->SpawnNewScene("Rho-Z Projection");
731       // projections
732       fRhoZMgr = new TEveProjectionManager();
733       gEve->AddElement(fRhoZMgr, (TEveElement *)s);
734       gEve->AddToListTree(fRhoZMgr, kFALSE);
735    }
736
737    // get bottom left split frame
738    frm = fSplitFrame->GetSecond()->GetFirst();
739
740    // create (embed) a GL viewer inside
741    fViewer1 = new TGLEmbeddedViewer(frm, fPad);
742    but3 = new TGLOverlayButton(fViewer1, "Swap", 10.0, -10.0, 55.0, 16.0);
743    but3->Connect("Clicked(TGLViewerBase*)", "SplitGLView", this, "SwapToMainView(TGLViewerBase*)");
744    but4 = new TGLOverlayButton(fViewer1, "Undock", 70.0, -10.0, 55.0, 16.0);
745    but4->Connect("Clicked(TGLViewerBase*)", "SplitGLView", this, "UnDock(TGLViewerBase*)");
746    frm->AddFrame(fViewer1->GetFrame(), new TGLayoutHints(kLHintsExpandX | 
747                    kLHintsExpandY));
748
749    // set the camera to orthographic (XOY) for this viewer
750    fViewer1->SetCurrentCamera(TGLViewer::kCameraOrthoXOY);
751    // connect signal we are interested to
752    fViewer1->Connect("MouseOver(TGLPhysicalShape*)", "SplitGLView", this, 
753                      "OnMouseOver(TGLPhysicalShape*)");
754    fViewer1->Connect("Activated()", "SplitGLView", this, 
755                      "OnViewerActivated()");
756    fViewer1->Connect("MouseIdle(TGLPhysicalShape*,UInt_t,UInt_t)", 
757                      "SplitGLView", this, 
758                      "OnMouseIdle(TGLPhysicalShape*,UInt_t,UInt_t)");
759    fViewer1->Connect("Clicked(TObject*)", "SplitGLView", this, 
760                      "OnClicked(TObject*)");
761    fViewer[1] = new TEveViewer("SplitGLViewer[1]");
762    fViewer[1]->SetGLViewer(fViewer1, fViewer1->GetFrame());
763    fViewer[1]->IncDenyDestroy();
764    if (fIsEmbedded && gEve) {
765       fRhoZMgr->ImportElements((TEveElement *)gEve->GetGlobalScene());
766       fRhoZMgr->ImportElements((TEveElement *)gEve->GetEventScene());
767       fRhoZMgr->SetProjection(TEveProjection::kPT_RhoZ);
768       fViewer[1]->AddScene(s);
769       gEve->AddElement(fViewer[1], gEve->GetViewers());
770       gRhoZMgr = fRhoZMgr;
771
772       s = gEve->SpawnNewScene("R-Phi Projection");
773       // projections
774       fRPhiMgr = new TEveProjectionManager();
775       gEve->AddElement(fRPhiMgr, (TEveElement *)s);
776       gEve->AddToListTree(fRPhiMgr, kFALSE);
777    }
778
779    // get bottom right frame
780    frm = fSplitFrame->GetSecond()->GetSecond();
781    // create (embed) a GL viewer inside
782    fViewer2 = new TGLEmbeddedViewer(frm, fPad);
783    but5 = new TGLOverlayButton(fViewer2, "Swap", 10.0, -10.0, 55.0, 16.0);
784    but5->Connect("Clicked(TGLViewerBase*)", "SplitGLView", this, "SwapToMainView(TGLViewerBase*)");
785    but6 = new TGLOverlayButton(fViewer2, "Undock", 70.0, -10.0, 55.0, 16.0);
786    but6->Connect("Clicked(TGLViewerBase*)", "SplitGLView", this, "UnDock(TGLViewerBase*)");
787    frm->AddFrame(fViewer2->GetFrame(), new TGLayoutHints(kLHintsExpandX | 
788                    kLHintsExpandY));
789
790    // set the camera to orthographic (XOY) for this viewer
791    fViewer2->SetCurrentCamera(TGLViewer::kCameraOrthoXOY);
792    // connect signal we are interested to
793    fViewer2->Connect("MouseOver(TGLPhysicalShape*)", "SplitGLView", this, 
794                      "OnMouseOver(TGLPhysicalShape*)");
795    fViewer2->Connect("Activated()", "SplitGLView", this, 
796                      "OnViewerActivated()");
797    fViewer2->Connect("MouseIdle(TGLPhysicalShape*,UInt_t,UInt_t)", 
798                      "SplitGLView", this, 
799                      "OnMouseIdle(TGLPhysicalShape*,UInt_t,UInt_t)");
800    fViewer2->Connect("Clicked(TObject*)", "SplitGLView", this, 
801                      "OnClicked(TObject*)");
802    fViewer[2] = new TEveViewer("SplitGLViewer[2]");
803    fViewer[2]->SetGLViewer(fViewer2, fViewer2->GetFrame());
804    fViewer[2]->IncDenyDestroy();
805    if (fIsEmbedded && gEve) {
806       fRPhiMgr->ImportElements((TEveElement *)gEve->GetGlobalScene());
807       fRPhiMgr->ImportElements((TEveElement *)gEve->GetEventScene());
808       fRPhiMgr->SetProjection(TEveProjection::kPT_RPhi);
809       fViewer[2]->AddScene(s);
810       gEve->AddElement(fViewer[2], gEve->GetViewers());
811       gRPhiMgr = fRPhiMgr;
812    }
813
814    /*
815    // Summary view ... incomplete
816    frm = fSplitFrame->GetSecond();
817
818    hfrm  = new TGHorizontalFrame(frm);
819    button= new TGPictureButton(hfrm, gClient->GetPicture("$ALICE_ROOT/EVE/alice-data/swap.png"));
820    button->SetToolTipText("Swap to big view");
821    hfrm->AddFrame(button);
822    button->Connect("Clicked()","SplitGLView",this,"SwapToMainView()");
823    fgHtmlSummary = new HtmlSummary("Alice Event Display Summary Table");
824    fgHtml = new TGHtml(hfrm, 100, 100, -1);
825    hfrm->AddFrame(fgHtml, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
826    frm->AddFrame(hfrm, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
827    */
828
829    if (fIsEmbedded && gEve) {
830       gEve->GetListTree()->Connect("Clicked(TGListTreeItem*, Int_t, Int_t, Int_t)",
831                                    "SplitGLView", this, "ItemClicked(TGListTreeItem*, Int_t, Int_t, Int_t)");
832    }
833
834    fShapedToolTip = new TGShapedToolTip("$ALICE_ROOT/EVE/alice-data/Default.png", 120, 22, 160, 110, 
835                                         23, 115, 12, "#ffff80");
836    Resize(GetDefaultSize());
837    MapSubwindows();
838    MapWindow();
839
840    fSplitFrame->Layout();
841    // !!!! LoadConfig(".everc");
842 }
843
844 //______________________________________________________________________________
845 SplitGLView::~SplitGLView()
846 {
847    // Clean up main frame...
848    // Cleanup();
849    
850    fMenuFile->Disconnect("Activated(Int_t)", this, "HandleMenu(Int_t)");
851    fMenuCamera->Disconnect("Activated(Int_t)", this, "HandleMenu(Int_t)");
852    fMenuScene->Disconnect("Activated(Int_t)", this, "HandleMenu(Int_t)");
853    fMenuHelp->Disconnect("Activated(Int_t)", this, "HandleMenu(Int_t)");
854    fViewer0->Disconnect("MouseOver(TGLPhysicalShape*)", this, 
855                          "OnMouseOver(TGLPhysicalShape*)");
856    fViewer0->Disconnect("Activated()", this, "OnViewerActivated()");
857    fViewer0->Disconnect("MouseIdle(TGLPhysicalShape*,UInt_t,UInt_t)", 
858                          this, "OnMouseIdle(TGLPhysicalShape*,UInt_t,UInt_t)");
859    fViewer1->Disconnect("MouseOver(TGLPhysicalShape*)", this, 
860                          "OnMouseOver(TGLPhysicalShape*)");
861    fViewer1->Disconnect("Activated()", this, "OnViewerActivated()");
862    fViewer1->Disconnect("MouseIdle(TGLPhysicalShape*,UInt_t,UInt_t)", 
863                          this, "OnMouseIdle(TGLPhysicalShape*,UInt_t,UInt_t)");
864    fViewer2->Disconnect("MouseOver(TGLPhysicalShape*)", this, 
865                          "OnMouseOver(TGLPhysicalShape*)");
866    fViewer2->Disconnect("Activated()", this, "OnViewerActivated()");
867    fViewer2->Disconnect("MouseIdle(TGLPhysicalShape*,UInt_t,UInt_t)", 
868                          this, "OnMouseIdle(TGLPhysicalShape*,UInt_t,UInt_t)");
869    if (!fIsEmbedded) {
870       delete fViewer[0];
871       delete fViewer[1];
872       delete fViewer[2];
873    }
874    delete fShapedToolTip;
875    delete fMenuFile;
876    delete fMenuScene;
877    delete fMenuCamera;
878    delete fMenuHelp;
879    if (!fIsEmbedded)
880       delete fMenuBar;
881    delete fViewer0;
882    delete fViewer1;
883    delete fViewer2;
884    delete fSplitFrame;
885    delete fPad;
886    if (!fIsEmbedded) {
887       delete fStatusBar;
888       gApplication->Terminate(0);
889    }
890 }
891
892 //______________________________________________________________________________
893 void SplitGLView::HandleMenu(Int_t id)
894 {
895    // Handle menu items.
896
897    static TString rcdir(".");
898    static TString rcfile(".everc");
899
900    switch (id) {
901
902       case kFileOpen:
903          {
904             static TString dir(".");
905             TGFileInfo fi;
906             fi.fFileTypes = filetypes;
907             fi.fIniDir    = StrDup(dir);
908             new TGFileDialog(gClient->GetRoot(), this, kFDOpen, &fi);
909             if (fi.fFilename)
910                OpenFile(fi.fFilename);
911             dir = fi.fIniDir;
912          }
913          break;
914
915       case kFileLoadConfig:
916          {
917             TGFileInfo fi;
918             fi.fFileTypes = rcfiletypes;
919             fi.fIniDir    = StrDup(rcdir);
920             fi.fFilename  = StrDup(rcfile);
921             new TGFileDialog(gClient->GetRoot(), this, kFDOpen, &fi);
922             if (fi.fFilename) {
923                rcfile = fi.fFilename;
924                LoadConfig(fi.fFilename);
925             }
926             rcdir = fi.fIniDir;
927          }
928          break;
929
930       case kFileSaveConfig:
931          {
932             TGFileInfo fi;
933             fi.fFileTypes = rcfiletypes;
934             fi.fIniDir    = StrDup(rcdir);
935             fi.fFilename  = StrDup(rcfile);
936             new TGFileDialog(gClient->GetRoot(), this, kFDSave, &fi);
937             if (fi.fFilename) {
938                rcfile = fi.fFilename;
939                SaveConfig(fi.fFilename);
940             }
941             rcdir = fi.fIniDir;
942          }
943          break;
944
945       case kFileExit:
946          CloseWindow();
947          break;
948
949       case kGLPerspYOZ:
950          if (fActViewer)
951             fActViewer->SetCurrentCamera(TGLViewer::kCameraPerspYOZ);
952          break;
953       case kGLPerspXOZ:
954          if (fActViewer)
955             fActViewer->SetCurrentCamera(TGLViewer::kCameraPerspXOZ);
956          break;
957       case kGLPerspXOY:
958          if (fActViewer)
959             fActViewer->SetCurrentCamera(TGLViewer::kCameraPerspXOY);
960          break;
961       case kGLXOY:
962          if (fActViewer)
963             fActViewer->SetCurrentCamera(TGLViewer::kCameraOrthoXOY);
964          break;
965       case kGLXOZ:
966          if (fActViewer)
967             fActViewer->SetCurrentCamera(TGLViewer::kCameraOrthoXOZ);
968          break;
969       case kGLZOY:
970          if (fActViewer)
971             fActViewer->SetCurrentCamera(TGLViewer::kCameraOrthoZOY);
972          break;
973       case kGLOrthoRotate:
974          ToggleOrthoRotate();
975          break;
976       case kGLOrthoDolly:
977          ToggleOrthoDolly();
978          break;
979
980       case kSceneUpdate:
981          if (fActViewer)
982             fActViewer->UpdateScene();
983          UpdateSummary();
984          break;
985
986       case kSceneUpdateAll:
987          fViewer0->UpdateScene();
988          fViewer1->UpdateScene();
989          fViewer2->UpdateScene();
990          UpdateSummary();
991          break;
992
993       case kSummaryUpdate:
994          UpdateSummary();
995          break;
996
997       case kHelpAbout:
998          {
999 #ifdef R__UNIX
1000             TString rootx;
1001 # ifdef ROOTBINDIR
1002             rootx = ROOTBINDIR;
1003 # else
1004             rootx = gSystem->Getenv("ROOTSYS");
1005             if (!rootx.IsNull()) rootx += "/bin";
1006 # endif
1007             rootx += "/root -a &";
1008             gSystem->Exec(rootx);
1009 #else
1010 #ifdef WIN32
1011             new TWin32SplashThread(kTRUE);
1012 #else
1013             char str[32];
1014             sprintf(str, "About ROOT %s...", gROOT->GetVersion());
1015             hd = new TRootHelpDialog(this, str, 600, 400);
1016             hd->SetText(gHelpAbout);
1017             hd->Popup();
1018 #endif
1019 #endif
1020          }
1021          break;
1022
1023       default:
1024          break;
1025    }
1026 }
1027
1028 //______________________________________________________________________________
1029 void SplitGLView::OnClicked(TObject *obj)
1030 {
1031    // Handle click events in GL viewer
1032
1033    if (obj)
1034       fStatusBar->SetText(Form("User clicked on: \"%s\"", obj->GetName()), 1);
1035    else
1036       fStatusBar->SetText("", 1);
1037 }
1038
1039 //______________________________________________________________________________
1040 void SplitGLView::OnMouseIdle(TGLPhysicalShape *shape, UInt_t posx, UInt_t posy)
1041 {
1042    // Slot used to handle "OnMouseIdle" signal coming from any GL viewer.
1043    // We receive a pointer on the physical shape in which the mouse cursor is
1044    // and the actual cursor position (x,y)
1045
1046    Window_t wtarget;
1047    Int_t    x = 0, y = 0;
1048
1049    static TH1F *h1f = 0;
1050    TFormula *form1 = new TFormula("form1","abs(sin(x)/x)");
1051    form1->Update(); // silent warning about unused variable...
1052    TF1 *sqroot = new TF1("sqroot","x*gaus(0) + [3]*form1",0,10);
1053    sqroot->SetParameters(10,4,1,20);
1054    if (h1f == 0)
1055       h1f = new TH1F("h1f","",50,0,10);
1056    h1f->Reset();
1057    h1f->SetFillColor(45);
1058    h1f->SetStats(0);
1059    h1f->FillRandom("sqroot",200);
1060
1061    if (fShapedToolTip) {
1062       fShapedToolTip->UnmapWindow();
1063    }
1064    if (shape && shape->GetLogical() && shape->GetLogical()->GetExternal()) {
1065       // get the actual viewer who actually emitted the signal
1066       TGLEmbeddedViewer *actViewer = dynamic_cast<TGLEmbeddedViewer*>((TQObject*)gTQSender);
1067       // then translate coordinates from the root (screen) coordinates 
1068       // to the actual frame (viewer) ones
1069       gVirtualX->TranslateCoordinates(actViewer->GetFrame()->GetId(),
1070                gClient->GetDefaultRoot()->GetId(), posx, posy, x, y,
1071                wtarget);
1072       // Then display our tooltip at this x,y location
1073       if (fShapedToolTip) {
1074          fShapedToolTip->Show(x+5, y+5, Form("%s\n     \n%s",
1075                               shape->GetLogical()->GetExternal()->IsA()->GetName(), 
1076                               shape->GetLogical()->GetExternal()->GetName()), h1f);
1077       }
1078    }
1079 }
1080
1081 //______________________________________________________________________________
1082 void SplitGLView::OnMouseOver(TGLPhysicalShape *shape)
1083 {
1084    // Slot used to handle "OnMouseOver" signal coming from any GL viewer.
1085    // We receive a pointer on the physical shape in which the mouse cursor is.
1086
1087    // display informations on the physical shape in the status bar
1088    if (shape && shape->GetLogical() && shape->GetLogical()->GetExternal())
1089       fStatusBar->SetText(Form("Mouse Over: \"%s\"", 
1090          shape->GetLogical()->GetExternal()->GetName()), 0);
1091    else
1092       fStatusBar->SetText("", 0);
1093 }
1094
1095 //______________________________________________________________________________
1096 void SplitGLView::OnViewerActivated()
1097 {
1098    // Slot used to handle "Activated" signal coming from any GL viewer.
1099    // Used to know which GL viewer is active.
1100
1101    static Pixel_t green = 0;
1102    // set the actual GL viewer frame to default color
1103    if (fActViewer && fActViewer->GetFrame())
1104       fActViewer->GetFrame()->ChangeBackground(GetDefaultFrameBackground());
1105
1106    // change the actual GL viewer to the one who emitted the signal
1107    // fActViewer = (TGLEmbeddedViewer *)gTQSender;
1108    fActViewer = dynamic_cast<TGLEmbeddedViewer*>((TQObject*)gTQSender);
1109
1110    if (fActViewer == 0) {
1111       printf ("dyncast failed ...\n");
1112       return;
1113    }
1114
1115    // get the highlight color (only once)
1116    if (green == 0) {
1117       gClient->GetColorByName("green", green);
1118    }
1119    // set the new actual GL viewer frame to highlight color
1120    if (fActViewer->GetFrame())
1121       fActViewer->GetFrame()->ChangeBackground(green);
1122
1123    // update menu entries to match actual viewer's options
1124    if (fActViewer->GetOrthoXOYCamera()->GetDollyToZoom() &&
1125        fActViewer->GetOrthoXOZCamera()->GetDollyToZoom() &&
1126        fActViewer->GetOrthoZOYCamera()->GetDollyToZoom())
1127       fMenuCamera->UnCheckEntry(kGLOrthoDolly);
1128    else
1129       fMenuCamera->CheckEntry(kGLOrthoDolly);
1130
1131    if (fActViewer->GetOrthoXOYCamera()->GetEnableRotate() &&
1132        fActViewer->GetOrthoXOYCamera()->GetEnableRotate() &&
1133        fActViewer->GetOrthoXOYCamera()->GetEnableRotate())
1134       fMenuCamera->CheckEntry(kGLOrthoRotate);
1135    else
1136       fMenuCamera->UnCheckEntry(kGLOrthoRotate);
1137 }
1138
1139 //______________________________________________________________________________
1140 void SplitGLView::OpenFile(const char *fname)
1141 {
1142    // Open a Root file to display a geometry in the GL viewers.
1143
1144    TString filename = fname;
1145    // check if the file type is correct
1146    if (!filename.EndsWith(".root")) {
1147       new TGMsgBox(gClient->GetRoot(), this, "OpenFile",
1148                    Form("The file \"%s\" is not a root file!", fname),
1149                    kMBIconExclamation, kMBOk);
1150       return;
1151    }
1152    // check if the root file contains a geometry
1153    if (TGeoManager::Import(fname) == 0) {
1154       new TGMsgBox(gClient->GetRoot(), this, "OpenFile",
1155                    Form("The file \"%s\" does't contain a geometry", fname),
1156                    kMBIconExclamation, kMBOk);
1157       return;
1158    }
1159    gGeoManager->DefaultColors();
1160    // delete previous primitives (if any)
1161    fPad->GetListOfPrimitives()->Delete();
1162    // and add the geometry to eve pad (container)
1163    fPad->GetListOfPrimitives()->Add(gGeoManager->GetTopVolume());
1164    // paint the geometry in each GL viewer
1165    fViewer0->PadPaint(fPad);
1166    fViewer1->PadPaint(fPad);
1167    fViewer2->PadPaint(fPad);
1168 }
1169
1170 //______________________________________________________________________________
1171 void SplitGLView::ToggleOrthoRotate()
1172 {
1173    // Toggle state of the 'Ortho allow rotate' menu entry.
1174
1175    if (fMenuCamera->IsEntryChecked(kGLOrthoRotate))
1176       fMenuCamera->UnCheckEntry(kGLOrthoRotate);
1177    else
1178       fMenuCamera->CheckEntry(kGLOrthoRotate);
1179    Bool_t state = fMenuCamera->IsEntryChecked(kGLOrthoRotate);
1180    if (fActViewer) {
1181       fActViewer->GetOrthoXOYCamera()->SetEnableRotate(state);
1182       fActViewer->GetOrthoXOYCamera()->SetEnableRotate(state);
1183       fActViewer->GetOrthoXOYCamera()->SetEnableRotate(state);
1184    }
1185 }
1186
1187 //______________________________________________________________________________
1188 void SplitGLView::ToggleOrthoDolly()
1189 {
1190    // Toggle state of the 'Ortho allow dolly' menu entry.
1191
1192    if (fMenuCamera->IsEntryChecked(kGLOrthoDolly))
1193       fMenuCamera->UnCheckEntry(kGLOrthoDolly);
1194    else
1195       fMenuCamera->CheckEntry(kGLOrthoDolly);
1196    Bool_t state = ! fMenuCamera->IsEntryChecked(kGLOrthoDolly);
1197    if (fActViewer) {
1198       fActViewer->GetOrthoXOYCamera()->SetDollyToZoom(state);
1199       fActViewer->GetOrthoXOZCamera()->SetDollyToZoom(state);
1200       fActViewer->GetOrthoZOYCamera()->SetDollyToZoom(state);
1201    }
1202 }
1203
1204 //______________________________________________________________________________
1205 void SplitGLView::ItemClicked(TGListTreeItem *item, Int_t, Int_t, Int_t)
1206 {
1207    // Item has been clicked, based on mouse button do:
1208
1209    static const TEveException eh("SplitGLView::ItemClicked ");
1210    TEveElement* re = (TEveElement*)item->GetUserData();
1211    if(re == 0) return;
1212    TObject* obj = re->GetObject(eh);
1213    if (obj->InheritsFrom("TEveViewer")) {
1214       TGLViewer *v = ((TEveViewer *)obj)->GetGLViewer();
1215       //v->Activated();
1216       if (v->InheritsFrom("TGLEmbeddedViewer")) {
1217          TGLEmbeddedViewer *ev = (TGLEmbeddedViewer *)v;
1218          gVirtualX->SetInputFocus(ev->GetGLWidget()->GetId());
1219       }
1220    }
1221 }
1222
1223 //______________________________________________________________________________
1224 void SplitGLView::LoadConfig(const char *fname)
1225 {
1226
1227    Int_t height, width;
1228    TEnv *env = new TEnv(fname);
1229
1230    Int_t mainheight = env->GetValue("MainView.Height", 434);
1231    Int_t blwidth    = env->GetValue("Bottom.Left.Width", 266);
1232    Int_t bcwidth    = env->GetValue("Bottom.Center.Width", 266);
1233    Int_t brwidth    = env->GetValue("Bottom.Right.Width", 266);
1234    Int_t top_height = env->GetValue("Right.Tab.Height", 0);
1235    Int_t bottom_height = env->GetValue("Bottom.Tab.Height", 0);
1236
1237    if (fIsEmbedded && gEve) {
1238       Int_t sel = env->GetValue("Eve.Selection", gEve->GetSelection()->GetPickToSelect());
1239       Int_t hi = env->GetValue("Eve.Highlight", gEve->GetHighlight()->GetPickToSelect());
1240       gEve->GetBrowser()->EveMenu(9+sel);
1241       gEve->GetBrowser()->EveMenu(13+hi);
1242
1243       width  = env->GetValue("Eve.Width", (Int_t)gEve->GetBrowser()->GetWidth());
1244       height = env->GetValue("Eve.Height", (Int_t)gEve->GetBrowser()->GetHeight());
1245       gEve->GetBrowser()->Resize(width, height);
1246    }
1247
1248    // top (main) split frame
1249    width = fSplitFrame->GetFirst()->GetWidth();
1250    fSplitFrame->GetFirst()->Resize(width, mainheight);
1251    // bottom left split frame
1252    height = fSplitFrame->GetSecond()->GetFirst()->GetHeight();
1253    fSplitFrame->GetSecond()->GetFirst()->Resize(blwidth, height);
1254    // bottom center split frame
1255    height = fSplitFrame->GetSecond()->GetSecond()->GetFirst()->GetHeight();
1256    fSplitFrame->GetSecond()->GetSecond()->GetFirst()->Resize(bcwidth, height);
1257    // bottom right split frame
1258    height = fSplitFrame->GetSecond()->GetSecond()->GetSecond()->GetHeight();
1259    fSplitFrame->GetSecond()->GetSecond()->GetSecond()->Resize(brwidth, height);
1260
1261    fSplitFrame->Layout();
1262
1263    if (fIsEmbedded && gEve) {
1264       width = ((TGCompositeFrame *)gEve->GetBrowser()->GetTabBottom()->GetParent())->GetWidth();
1265       ((TGCompositeFrame *)gEve->GetBrowser()->GetTabBottom()->GetParent())->Resize(width, bottom_height);
1266       width = ((TGCompositeFrame *)gEve->GetBrowser()->GetTabRight()->GetParent())->GetWidth();
1267       ((TGCompositeFrame *)gEve->GetBrowser()->GetTabRight()->GetParent())->Resize(width, top_height);
1268    }
1269 }
1270
1271 //______________________________________________________________________________
1272 void SplitGLView::SaveConfig(const char *fname)
1273 {
1274
1275    Int_t bottom_height = 0;
1276    Int_t top_height = 0;
1277    TGSplitFrame *frm;
1278    TEnv *env = new TEnv(fname);
1279
1280    if (fIsEmbedded && gEve) {
1281       env->SetValue("Eve.Width", (Int_t)gEve->GetBrowser()->GetWidth());
1282       env->SetValue("Eve.Height", (Int_t)gEve->GetBrowser()->GetHeight());
1283    }
1284    // get top (main) split frame
1285    frm = fSplitFrame->GetFirst();
1286    env->SetValue("MainView.Height", (Int_t)frm->GetHeight());
1287    // get bottom left split frame
1288    frm = fSplitFrame->GetSecond()->GetFirst();
1289    env->SetValue("Bottom.Left.Width", (Int_t)frm->GetWidth());
1290    // get bottom center split frame
1291    frm = fSplitFrame->GetSecond()->GetSecond()->GetFirst();
1292    env->SetValue("Bottom.Center.Width", (Int_t)frm->GetWidth());
1293    // get bottom right split frame
1294    frm = fSplitFrame->GetSecond()->GetSecond()->GetSecond();
1295    env->SetValue("Bottom.Right.Width", (Int_t)frm->GetWidth());
1296    if (fIsEmbedded && gEve) {
1297       top_height = (Int_t)((TGCompositeFrame *)gEve->GetBrowser()->GetTabRight()->GetParent())->GetHeight();
1298       env->SetValue("Right.Tab.Height", top_height);
1299       bottom_height = (Int_t)((TGCompositeFrame *)gEve->GetBrowser()->GetTabBottom()->GetParent())->GetHeight();
1300       env->SetValue("Bottom.Tab.Height", bottom_height);
1301
1302       env->SetValue("Eve.Selection", gEve->GetSelection()->GetPickToSelect());
1303       env->SetValue("Eve.Highlight", gEve->GetHighlight()->GetPickToSelect());
1304    }
1305
1306    env->SaveLevel(kEnvLocal);
1307 #ifdef R__WIN32
1308    if (!gSystem->AccessPathName(Form("%s.new", fname))) {
1309       gSystem->Exec(Form("del %s", fname));
1310       gSystem->Rename(Form("%s.new", fname), fname);
1311    }
1312 #endif
1313 }
1314
1315 //______________________________________________________________________________
1316 void SplitGLView::SwapToMainView(TGLViewerBase *viewer)
1317 {
1318    // Swap frame embedded in a splitframe to the main view (slot method).
1319
1320    TGCompositeFrame *parent = 0;
1321    if (!fSplitFrame->GetFirst()->GetFrame())
1322       return;
1323    if (viewer == 0) {
1324       TGPictureButton *src = (TGPictureButton*)gTQSender;
1325       parent = (TGCompositeFrame *)src->GetParent();
1326       while (parent && !parent->InheritsFrom("TGSplitFrame")) {
1327          parent = (TGCompositeFrame *)parent->GetParent();
1328       }
1329    }
1330    else {
1331       TGCompositeFrame *src = ((TGLEmbeddedViewer *)viewer)->GetFrame();
1332       if (!src) return;
1333       TGLOverlayButton *but = (TGLOverlayButton *)((TQObject *)gTQSender);
1334       but->ResetState();
1335       parent = (TGCompositeFrame *)src->GetParent();
1336    }
1337    if (parent && parent->InheritsFrom("TGSplitFrame"))
1338       ((TGSplitFrame *)parent)->SwitchToMain();
1339 }
1340
1341 //______________________________________________________________________________
1342 void SplitGLView::UnDock(TGLViewerBase *viewer)
1343 {
1344    // Undock frame embedded in a splitframe (slot method).
1345
1346    TGCompositeFrame *src = ((TGLEmbeddedViewer *)viewer)->GetFrame();
1347    if (!src) return;
1348    TGLOverlayButton *but = (TGLOverlayButton *)((TQObject *)gTQSender);
1349    but->ResetState();
1350    TGCompositeFrame *parent = (TGCompositeFrame *)src->GetParent();
1351    if (parent && parent->InheritsFrom("TGSplitFrame"))
1352       ((TGSplitFrame *)parent)->ExtractFrame();
1353 }
1354
1355 //______________________________________________________________________________
1356 void SplitGLView::UpdateSummary()
1357 {
1358    // Update summary of current event.
1359    // Currently unused.
1360    return;
1361
1362    TEveElement::List_i i;
1363    TEveElement::List_i j;
1364    Int_t k;
1365    TEveElement *el;
1366    HtmlObjTable *table;
1367    TEveEventManager *mgr = gEve ? gEve->GetCurrentEvent() : 0;
1368    if (mgr) {
1369       fgHtmlSummary->Clear("D");
1370       for (i=mgr->BeginChildren(); i!=mgr->EndChildren(); ++i)
1371       {
1372          el = ((TEveElement*)(*i));
1373          if (el->IsA() == TEvePointSet::Class()) {
1374             TEvePointSet *ps = (TEvePointSet *)el;
1375             TString ename  = ps->GetElementName();
1376             TString etitle = ps->GetElementTitle();
1377             //ename.Remove(ename.First('\''));
1378             //etitle.Remove(0, 2);
1379             Int_t nel = atoi(etitle.Data());
1380             table = fgHtmlSummary->AddTable(ename, 0, nel);
1381          }
1382          else if (el->IsA() == TEveTrackList::Class()) {
1383             TEveTrackList *tracks = (TEveTrackList *)el;
1384             TString ename  = tracks->GetElementName();
1385             // ename.Remove(ename.First('\''));
1386             table = fgHtmlSummary->AddTable(ename.Data(), 5, 
1387                                             tracks->NumChildren(), kTRUE, "first");
1388             table->SetLabel(0, "Momentum");
1389             table->SetLabel(1, "P_t");
1390             table->SetLabel(2, "Phi");
1391             table->SetLabel(3, "Theta");
1392             table->SetLabel(4, "Eta");
1393             k=0;
1394             for (j=tracks->BeginChildren(); j!=tracks->EndChildren(); ++j) {
1395                Float_t p     = ((TEveTrack*)(*j))->GetMomentum().Mag();
1396                table->SetValue(0, k, p);
1397                Float_t pt    = ((TEveTrack*)(*j))->GetMomentum().Perp();
1398                table->SetValue(1, k, pt);
1399                Float_t phi   = ((TEveTrack*)(*j))->GetMomentum().Phi();
1400                table->SetValue(2, k, phi);
1401                Float_t theta = ((TEveTrack*)(*j))->GetMomentum().Theta();
1402                table->SetValue(3, k, theta);
1403                Float_t eta   = ((TEveTrack*)(*j))->GetMomentum().Eta();
1404                table->SetValue(4, k, eta);
1405                ++k;
1406             }
1407          }
1408       }
1409       fgHtmlSummary->Build();
1410       fgHtml->Clear();
1411       fgHtml->ParseText((char*)fgHtmlSummary->Html().Data());
1412       fgHtml->Layout();
1413    }
1414 }
1415
1416 // Linkdef
1417 #ifdef __CINT__
1418
1419 #pragma link C++ class SplitGLView;
1420
1421 #endif