]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EVE/alice-macros/SplitGLView.C
Removing from the constructor the unnecessary calculation of the DCA between the...
[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"
38#include "TGLEmbeddedViewer.h"
39#include "TGShapedFrame.h"
40#include "TGButton.h"
41#include "TGTab.h"
42#include "TEnv.h"
43
44#include "TCanvas.h"
45#include "TFormula.h"
46#include "TF1.h"
47#include "TH1F.h"
48
49#ifdef WIN32
50#include <TWin32SplashThread.h>
51#endif
52
53const char *filetypes[] = {
54 "ROOT files", "*.root",
55 "All files", "*",
56 0, 0
57};
58
59const char *rcfiletypes[] = {
60 "All files", "*",
61 0, 0
62};
63
64////////////////////////////////////////////////////////////////////////////////
65class TGShapedToolTip : public TGShapedFrame {
66
67private:
68 TGShapedToolTip(const TGShapedToolTip&); // Not implemented
69 TGShapedToolTip& operator=(const TGShapedToolTip&); // Not implemented
70
71protected:
72 Int_t fTextX, fTextY, fTextH;
73 TString fTextCol;
74
75 TRootEmbeddedCanvas *fEc; // embedded canvas for histogram
76 TH1 *fHist; // user histogram
77 TString fText; // info (as tool tip) text
78
79 virtual void DoRedraw() {}
80
81public:
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();
86
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(); }
92 void Refresh();
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);
98
99 ClassDef(TGShapedToolTip, 0) // Shaped composite frame
100};
101
102////////////////////////////////////////////////////////////////////////////////
103class HtmlObjTable : public TObject {
104public: // make them public for shorter code
105
106 TString fName;
107 Int_t fNValues; // number of values
108 Int_t fNFields; // number of fields
109 TArrayF *fValues;
110 TString *fLabels;
111 Bool_t fExpand;
112
113 TString fHtml; // HTML output code
114
115 void Build();
116 void BuildTitle();
117 void BuildLabels();
118 void BuildTable();
119
120public:
121 HtmlObjTable(const char *name, Int_t nfields, Int_t nvals, Bool_t exp=kTRUE);
122 virtual ~HtmlObjTable();
123
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; }
127
128 ClassDef(HtmlObjTable, 0);
129};
130
131////////////////////////////////////////////////////////////////////////////////
132class HtmlSummary {
133public: // make them public for shorter code
134 Int_t fNTables;
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
140
141 void MakeHeader();
142 void MakeFooter();
143
144public:
145 HtmlSummary(const char *title);
146 virtual ~HtmlSummary();
147
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); }
151 void Build();
152 void Clear(Option_t *option="");
153 void Reset(Option_t *option="");
154 TString Html() const { return fHtml; }
155
156 ClassDef(HtmlSummary, 0);
157};
158
159////////////////////////////////////////////////////////////////////////////////
160class SplitGLView : public TGMainFrame {
161
162public:
163 enum EMyCommands {
164 kFileOpen, kFileExit, kFileLoadConfig, kFileSaveConfig,
165 kHelpAbout, kGLPerspYOZ, kGLPerspXOZ, kGLPerspXOY, kGLXOY,
166 kGLXOZ, kGLZOY, kGLOrthoRotate, kGLOrthoDolly, kSceneUpdate,
167 kSceneUpdateAll, kSummaryUpdate
168 };
169
170private:
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
186 Bool_t fIsEmbedded;
187
188 TEveViewer *fViewer[3];
189 TEveProjectionManager *fRPhiMgr;
190 TEveProjectionManager *fRhoZMgr;
191
192public:
193 SplitGLView(const TGWindow *p=0, UInt_t w=800, UInt_t h=600, Bool_t embed=kFALSE);
194 virtual ~SplitGLView();
195
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();
209
210 TEveProjectionManager *GetRPhiMgr() const { return fRPhiMgr; }
211 TEveProjectionManager *GetRhoZMgr() const { return fRhoZMgr; }
212
213 ClassDef(SplitGLView, 0)
214};
215
216TEveProjectionManager *gRPhiMgr = 0;
217TEveProjectionManager *gRhoZMgr = 0;
218
219ClassImp(TGShapedToolTip)
220ClassImp(HtmlObjTable)
221ClassImp(HtmlSummary)
222ClassImp(SplitGLView)
223
224HtmlSummary *SplitGLView::fgHtmlSummary = 0;
225TGHtml *SplitGLView::fgHtml = 0;
226
227//______________________________________________________________________________
228TGShapedToolTip::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,
230 const char *col) :
231 TGShapedFrame(pname, gClient->GetDefaultRoot(), 400, 300, kTempFrame |
232 kHorizontalFrame), fEc(0), fHist(0)
233{
234 // Shaped window constructor
235
236 fTextX = tx; fTextY = ty; fTextH = th;
237 if (col)
238 fTextCol = col;
239 else
240 fTextCol = "0x000000";
241
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));
249 }
250 MapSubwindows();
251 Resize();
252 Resize(fBgnd->GetWidth(), fBgnd->GetHeight());
253}
254
255//______________________________________________________________________________
256TGShapedToolTip::~TGShapedToolTip()
257{
258 // Destructor.
259
260 if (fHist)
261 delete fHist;
262 if (fEc)
263 delete fEc;
264}
265
266//______________________________________________________________________________
267void TGShapedToolTip::CloseWindow()
268{
269 // Close shaped window.
270
271 DeleteWindow();
272}
273
274//______________________________________________________________________________
275void TGShapedToolTip::Refresh()
276{
277 // Redraw the window with current attributes.
278
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"))) {
288 nlines++;
289 img->DrawText(fTextX, fTextY+(nlines*size), s, size, fTextCol, ar);
290 }
291 img->PaintImage(fId, 0, 0, 0, 0, 0, 0, "opaque");
292 free(string);
293 delete img;
294 gVirtualX->Update();
295}
296
297//______________________________________________________________________________
298void TGShapedToolTip::CreateCanvas(Int_t cx, Int_t cy, Int_t cw, Int_t ch)
299{
300
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));
307 MapSubwindows();
308 Resize();
309 Resize(fBgnd->GetWidth(), fBgnd->GetHeight());
310 if (IsMapped()) {
311 Refresh();
312 }
313}
314
315//______________________________________________________________________________
316void TGShapedToolTip::CreateCanvas(Int_t cw, Int_t ch, TGLayoutHints *hints)
317{
318 // Create the embedded canvas.
319
320 fEc = new TRootEmbeddedCanvas("ec", this, cw, ch, 0);
321 AddFrame(fEc, hints);
322 MapSubwindows();
323 Resize();
324 Resize(fBgnd->GetWidth(), fBgnd->GetHeight());
325 if (IsMapped()) {
326 Refresh();
327 }
328}
329
330//______________________________________________________________________________
331void TGShapedToolTip::SetHisto(TH1 *hist)
332{
333 // Set which histogram has to be displayed in the embedded canvas.
334
335 if (hist) {
336 if (fHist) {
337 delete fHist;
338 if (fEc)
339 fEc->GetCanvas()->Clear();
340 }
341 fHist = (TH1 *)hist->Clone();
342 if (fEc) {
343 fEc->GetCanvas()->SetBorderMode(0);
344 fEc->GetCanvas()->SetFillColor(10);
345 fEc->GetCanvas()->cd();
346 fHist->Draw();
347 fEc->GetCanvas()->Update();
348 }
349 }
350}
351
352//______________________________________________________________________________
353void TGShapedToolTip::SetText(const char *text)
354{
355 // Set which text has to be displayed.
356
357 if (text) {
358 fText = text;
359 }
360 if (IsMapped())
361 Refresh();
362}
363
364//______________________________________________________________________________
365void TGShapedToolTip::SetTextColor(const char *col)
366{
367 // Set text color.
368
369 fTextCol = col;
370 if (IsMapped())
371 Refresh();
372}
373
374//______________________________________________________________________________
375void TGShapedToolTip::SetTextAttributes(Int_t tx, Int_t ty, Int_t th,
376 const char *col)
377{
378 // Set text attributes (position, size and color).
379
380 fTextX = tx; fTextY = ty; fTextH = th;
381 if (col)
382 fTextCol = col;
383 if (IsMapped())
384 Refresh();
385}
386
387//______________________________________________________________________________
388void TGShapedToolTip::Show(Int_t x, Int_t y, const char *text, TH1 *hist)
389{
390 // Show (popup) the shaped window at location x,y and possibly
391 // set the text and histogram to be displayed.
392
393 Move(x, y);
394 MapWindow();
395
396 if (text)
397 SetText(text);
398 if (hist)
399 SetHisto(hist);
400 // end of demo code -------------------------------------------
401 if (fHist) {
402 fEc->GetCanvas()->SetBorderMode(0);
403 fEc->GetCanvas()->SetFillColor(10);
404 fEc->GetCanvas()->cd();
405 fHist->Draw();
406 fEc->GetCanvas()->Update();
407 }
408 Refresh();
409}
410
411//______________________________________________________________________________
412HtmlObjTable::HtmlObjTable(const char *name, Int_t nfields, Int_t nvals, Bool_t exp) :
413 fName(name), fNValues(nvals), fNFields(nfields), fExpand(exp)
414{
415 // Constructor.
416
417 fValues = new TArrayF[fNFields];
418 for (int i=0;i<fNFields;i++)
419 fValues[i].Set(nvals);
420 fLabels = new TString[fNFields];
421}
422
423//______________________________________________________________________________
424HtmlObjTable::~HtmlObjTable()
425{
426 // Destructor.
427
428 delete [] fValues;
429 delete [] fLabels;
430}
431
432//______________________________________________________________________________
433void HtmlObjTable::Build()
434{
435 // Build HTML code.
436
437 fHtml = "<table width=100% border=1 cellspacing=0 cellpadding=0 bgcolor=f0f0f0> ",
438
439 BuildTitle();
440 if (fExpand && (fNFields > 0) && (fNValues > 0)) {
441 BuildLabels();
442 BuildTable();
443 }
444
445 fHtml += "</table>";
446}
447
448//______________________________________________________________________________
449void HtmlObjTable::BuildTitle()
450{
451 // Build table title.
452
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>";
458 fHtml += fName;
459 fHtml += "</i></b></font></td>";
460 fHtml += "<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>";
465 fHtml += "</table>";
466 fHtml += "</td></tr>";
467}
468
469//______________________________________________________________________________
470void HtmlObjTable::BuildLabels()
471{
472 // Build table labels.
473
474 Int_t i;
475 fHtml += "<tr bgcolor=c0c0ff>";
476 fHtml += "<th> </th>"; // for the check boxes
477 for (i=0;i<fNFields;i++) {
478 fHtml += "<th> ";
479 fHtml += fLabels[i];
480 fHtml += " </th>"; // for the check boxes
481 }
482 fHtml += "</tr>";
483}
484
485//______________________________________________________________________________
486void HtmlObjTable::BuildTable()
487{
488 // Build part of table with values.
489
490 for (int i = 0; i < fNValues; i++) {
491 if (i%2)
492 fHtml += "<tr bgcolor=e0e0ff>";
493 else
494 fHtml += "<tr bgcolor=ffffff>";
495
496 TString name = fName;
497 name.ReplaceAll(" ", "_");
498 // checkboxes
499 fHtml += "<td bgcolor=d0d0ff align=\"center\">";
500 fHtml += "<input type=\"checkbox\" name=\"";
501 fHtml += name;
502 fHtml += Form("[%d]\">",i);
503 fHtml += "</td>";
504
505 for (int j = 0; j < fNFields; j++) {
506 fHtml += "<td width=";
507 fHtml += Form("%d%%", 100/fNFields);
508 fHtml += " align=\"center\"";
509 fHtml += ">";
510 fHtml += Form("%1.4f", fValues[j][i]);
511 fHtml += "</td>";
512 }
513 fHtml += "</tr> ";
514 }
515}
516
517//______________________________________________________________________________
518HtmlSummary::HtmlSummary(const char *title) : fNTables(0), fTitle(title)
519{
520 // Constructor.
521
522 fObjTables = new TOrdCollection();
523}
524
525//______________________________________________________________________________
526HtmlSummary::~HtmlSummary()
527{
528 // Destructor.
529
530 Reset();
531}
532
533//______________________________________________________________________________
534HtmlObjTable *HtmlSummary::AddTable(const char *name, Int_t nfields, Int_t nvals,
535 Bool_t exp, Option_t *option)
536{
537 // Add a new table in our list of tables.
538
539 TString opt = option;
540 opt.ToLower();
541 HtmlObjTable *table = new HtmlObjTable(name, nfields, nvals, exp);
542 fNTables++;
543 if (opt.Contains("first"))
544 fObjTables->AddFirst(table);
545 else
546 fObjTables->Add(table);
547 return table;
548}
549
550//______________________________________________________________________________
551void HtmlSummary::Clear(Option_t *option)
552{
553 // Clear the table list.
554
555 if (option && option[0] == 'D')
556 fObjTables->Delete(option);
557 else
558 fObjTables->Clear(option);
559 fNTables = 0;
560}
561
562//______________________________________________________________________________
563void HtmlSummary::Reset(Option_t *)
564{
565 // Reset (delete) the table list;
566
567 delete fObjTables; fObjTables = 0;
568 fNTables = 0;
569}
570
571//______________________________________________________________________________
572void HtmlSummary::Build()
573{
574 // Build the summary.
575
576 MakeHeader();
577 for (int i=0;i<fNTables;i++) {
578 GetTable(i)->Build();
579 fHtml += GetTable(i)->Html();
580 }
581 MakeFooter();
582}
583
584//______________________________________________________________________________
585void HtmlSummary::MakeHeader()
586{
587 // Make HTML header.
588
589 fHeader = "<html><head><title>";
590 fHeader += fTitle;
591 fHeader += "</title></head><body>";
592 fHeader += "<center><h2><font color=#2222ee><i>";
593 fHeader += fTitle;
594 fHeader += "</i></font></h2></center>";
595 fHtml = fHeader;
596}
597
598//______________________________________________________________________________
599void HtmlSummary::MakeFooter()
600{
601 // Make HTML footer.
602
603 fFooter = "<br><p><br><center><strong><font size=2 color=#2222ee>";
604 fFooter += "Example of using Html widget to display tabular data";
605 fFooter += "<br>";
606