]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EVE/alice-macros/SplitGLView.C
protect against missing pt in track references
[u/mrichter/AliRoot.git] / EVE / alice-macros / SplitGLView.C
CommitLineData
e9b9f7d2 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"
68ca2fe7 38#include "TGLOverlayButton.h"
e9b9f7d2 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
54const char *filetypes[] = {
55 "ROOT files", "*.root",
56 "All files", "*",
57 0, 0
58};
59
60const char *rcfiletypes[] = {
61 "All files", "*",
62 0, 0
63};
64
65////////////////////////////////////////////////////////////////////////////////
66class TGShapedToolTip : public TGShapedFrame {
67
68private:
69 TGShapedToolTip(const TGShapedToolTip&); // Not implemented
70 TGShapedToolTip& operator=(const TGShapedToolTip&); // Not implemented
71
72protected:
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
82public:
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////////////////////////////////////////////////////////////////////////////////
104class HtmlObjTable : public TObject {
105public: // 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
121public:
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////////////////////////////////////////////////////////////////////////////////
133class HtmlSummary {
134public: // 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
145public:
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////////////////////////////////////////////////////////////////////////////////
161class SplitGLView : public TGMainFrame {
162
163public:
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
171private:
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
193public:
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);
68ca2fe7 204 void SwapToMainView(TGLViewerBase *viewer);
e9b9f7d2 205 void ToggleOrthoRotate();
206 void ToggleOrthoDolly();
68ca2fe7 207 void UnDock(TGLViewerBase *viewer);
e9b9f7d2 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
218TEveProjectionManager *gRPhiMgr = 0;
219TEveProjectionManager *gRhoZMgr = 0;
220
221ClassImp(TGShapedToolTip)
222ClassImp(HtmlObjTable)
223ClassImp(HtmlSummary)
224ClassImp(SplitGLView)
225
226HtmlSummary *SplitGLView::fgHtmlSummary = 0;
227TGHtml *SplitGLView::fgHtml = 0;
228
229//______________________________________________________________________________
230TGShapedToolTip::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//______________________________________________________________________________
258TGShapedToolTip::~TGShapedToolTip()
259{
260 // Destructor.
261
262 if (fHist)
263 delete fHist;
264 if (fEc)
265 delete fEc;
266}
267
268//______________________________________________________________________________
269void TGShapedToolTip::CloseWindow()
270{
271 // Close shaped window.
272
273 DeleteWindow();
274}
275
276//______________________________________________________________________________
277void 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//______________________________________________________________________________
300void 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//______________________________________________________________________________
318void 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//______________________________________________________________________________
333void 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//______________________________________________________________________________
355void 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//______________________________________________________________________________
367void TGShapedToolTip::SetTextColor(const char *col)
368{
369 // Set text color.
370
371 fTextCol = col;
372 if (IsMapped())
373 Refresh();
374}
375
376//______________________________________________________________________________
377void 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//______________________________________________________________________________
390void 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//______________________________________________________________________________
414HtmlObjTable::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//______________________________________________________________________________
426HtmlObjTable::~HtmlObjTable()
427{
428 // Destructor.
429
430 delete [] fValues;
431 delete [] fLabels;
432}
433
434//______________________________________________________________________________
435void 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//______________________________________________________________________________
451void 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//______________________________________________________________________________
472void 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//______________________________________________________________________________
488void 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//______________________________________________________________________________
520HtmlSummary::HtmlSummary(const char *title) : fNTables(0), fTitle(title)
521{
522 // Constructor.
523
524 fObjTables = new TOrdCollection();
525}
526
527//______________________________________________________________________________
528HtmlSummary::~HtmlSummary()
529{
530 // Destructor.
531
532 Reset();
533}
534
535//______________________________________________________________________________
536HtmlObjTable *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//______________________________________________________________________________
553void 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//______________________________________________________________________________
565void HtmlSummary::Reset(Option_t *)
566{
567 // Reset (delete) the table list;
568
569 delete fObjTables; fObjTables = 0;
570 fNTables = 0;
571}
572
573//______________________________________________________________________________
574void 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//______________________________________________________________________________
587void 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//______________________________________________________________________________
601void 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