fdc2f5fc7505b317448ab21b6cee29cb5e415a11
[u/mrichter/AliRoot.git] / EVE / EveBase / AliEveConfigManager.cxx
1 // $Id$
2 // Author: Matevz Tadel 2009
3
4 /**************************************************************************
5  * Copyright(c) 1998-2009, ALICE Experiment at CERN, all rights reserved. *
6  * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for          *
7  * full copyright notice.                                                 *
8  **************************************************************************/
9
10 #include "AliEveConfigManager.h"
11
12 #include <AliEveMultiView.h>
13 #include <TEveManager.h>
14 #include <TEveBrowser.h>
15 #include <TEveWindow.h>
16 #include <TGFileDialog.h>
17 #include <TGMenu.h>
18
19 #include "AliEveEventManager.h"
20 #include "AliEveMacroExecutor.h"
21 #include "AliEveMacroExecutorWindow.h"
22 #include "AliEveMacro.h"
23
24 class AliEveMacroExecutor;
25 class TEveProjectionManager;
26 class TEveGeoShape;
27 class TEveUtil;
28
29 #include <TSystem.h>
30 #include <TPRegexp.h>
31 #include <RVersion.h>
32
33 //______________________________________________________________________________
34 // Full description of AliEveConfigManager
35 //
36
37 ClassImp(AliEveConfigManager)
38
39 AliEveConfigManager* AliEveConfigManager::fgMaster = 0;
40
41 namespace
42 {
43  enum EAliEveMenu_e
44  {
45    kAEMDefault, kAEMScreen, kAEMProjector, kAEMNotransparency, kAEMTransparentDark, kAEMTransparentLight, kAEMTransparentMonoDark, kAEMTransparentMonoLight, kAEMGreen, kAEMBright, kAEMYellow, kAEMTpc, kAEMAll, kAEM3d, kAEMRphi, kAEMRhoz, kAEMAllhr, kAEM3dhr, kAEMRphihr, kAEMRhozhr, kAEMSavemacros, kAEMLoadmacros, kAEMSave, kAEMOpen, kAEMSetDefault
46  };
47 }
48  
49 //______________________________________________________________________________
50 AliEveConfigManager* AliEveConfigManager::InitializeMaster()
51 {
52   // Get main instance.
53
54   static const TEveException kEH("AliEveConfigManager::InitializeMaster ");
55
56   if (fgMaster)
57     throw kEH + "Master already initialized.";
58
59   fgMaster = new AliEveConfigManager;
60   return fgMaster;
61 }
62
63 //______________________________________________________________________________
64 AliEveConfigManager* AliEveConfigManager::GetMaster()
65 {
66   // Get main instance.
67
68   static const TEveException kEH("AliEveConfigManager::GetMaster ");
69
70   if (!fgMaster)
71     throw kEH + "Master not initialized.";
72
73   return fgMaster;
74 }
75
76 //______________________________________________________________________________
77 AliEveConfigManager::AliEveConfigManager() :
78   TObject(),
79   fAliEvePopup(0),
80   fAliEveGeometries(0),
81   fAliEvePictures(0),
82   fAliEvePicturesHR(0),
83   fAliEveDataSelection(0),
84   fAliEveVizDBs(0),
85   fLoadCheck(kFALSE)
86 {
87   // Constructor.
88   // Expected TEveManager is already initialized.
89
90
91   fAliEveGeometries = new TGPopupMenu(gClient->GetRoot());
92   fAliEveGeometries->AddEntry("&Default", kAEMDefault);
93   fAliEveGeometries->AddEntry("&Screen", kAEMScreen);
94   fAliEveGeometries->AddEntry("&Projector", kAEMProjector);
95
96   fAliEveGeometries->AddSeparator();
97
98   fAliEveGeometries->AddEntry("&Low transparency", kAEMNotransparency);
99
100   fAliEveGeometries->AddSeparator();
101
102   fAliEveGeometries->AddEntry("&Transparent screen", kAEMTransparentDark);
103   fAliEveGeometries->AddEntry("&Transparent projector", kAEMTransparentLight);
104   fAliEveGeometries->AddEntry("&Transparent mono dark", kAEMTransparentMonoDark);
105   fAliEveGeometries->AddEntry("&Transparent mono light", kAEMTransparentMonoLight);
106
107   fAliEveGeometries->AddSeparator();
108
109   fAliEveGeometries->AddEntry("&First collision setup", kAEMGreen);
110   fAliEveGeometries->AddEntry("&Bright", kAEMBright);
111
112   fAliEveGeometries->AddSeparator();
113
114   fAliEveGeometries->AddEntry("&TPC Yellow", kAEMYellow);
115   fAliEveGeometries->AddEntry("&TPC Blue", kAEMTpc);
116
117   fAliEveGeometries->AddSeparator();
118
119   fAliEvePictures = new TGPopupMenu(gClient->GetRoot());
120
121   fAliEvePictures->AddEntry("&Save all views", kAEMAll);
122   fAliEvePictures->AddEntry("&Save 3D View",   kAEM3d);
123   fAliEvePictures->AddEntry("&Save RPhi View", kAEMRphi);
124   fAliEvePictures->AddEntry("&Save RhoZ View", kAEMRhoz);
125
126   fAliEvePictures->AddSeparator();
127
128   fAliEvePicturesHR = new TGPopupMenu(gClient->GetRoot());
129
130   fAliEvePicturesHR->AddEntry("&Save all views HR", kAEMAllhr);
131   fAliEvePicturesHR->AddEntry("&Save 3D View HR",   kAEM3dhr);
132   fAliEvePicturesHR->AddEntry("&Save RPhi View HR", kAEMRphihr);
133   fAliEvePicturesHR->AddEntry("&Save RhoZ View HR", kAEMRhozhr);
134
135   fAliEvePicturesHR->AddSeparator();
136
137   fAliEveDataSelection = new TGPopupMenu(gClient->GetRoot());
138
139   fAliEveDataSelection->AddEntry("&Save Data Selection macros", kAEMSavemacros);
140   fAliEveDataSelection->AddEntry("&Load Data Selection macros",   kAEMLoadmacros);
141
142   fAliEveDataSelection->AddSeparator();
143
144   fAliEveVizDBs = new TGPopupMenu(gClient->GetRoot());
145
146   fAliEveVizDBs->AddEntry("&Save VizDB", kAEMSave);
147   fAliEveVizDBs->AddEntry("&Load VizDB", kAEMOpen);
148
149   fAliEveVizDBs->AddSeparator();
150
151   fAliEvePopup = new TGPopupMenu(gClient->GetRoot());
152   fAliEvePopup->AddEntry("&Set Default Settings", kAEMSetDefault);
153   fAliEvePopup->AddSeparator();
154   fAliEvePopup->AddPopup("&Geometries/VizDBs", fAliEveGeometries);
155   fAliEvePopup->AddSeparator();
156   fAliEvePopup->AddPopup("&Pictures", fAliEvePictures);
157   fAliEvePopup->AddSeparator();
158   fAliEvePopup->AddPopup("&PicturesHR", fAliEvePicturesHR);
159   fAliEvePopup->AddSeparator();
160   fAliEvePopup->AddPopup("&VizDBs",  fAliEveVizDBs);
161   fAliEvePopup->AddSeparator();
162   fAliEvePopup->AddPopup("&DataSelection", fAliEveDataSelection);
163   fAliEvePopup->AddSeparator();
164
165   fAliEvePopup->Connect("Activated(Int_t)", "AliEveConfigManager",
166                         this, "AliEvePopupHandler(Int_t)");
167   fLoadCheck = kFALSE;
168
169 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,25,4)
170   TGMenuBar *mBar = gEve->GetBrowser()->GetMenuBar();
171   mBar->AddPopup("&AliEve", fAliEvePopup, new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0));
172   gEve->GetBrowser()->GetTopMenuFrame()->Layout();
173 #else
174   // Uber hack as TRootBrowser does not provede manu-bar getter.
175   TGFrameElement   *xxFE = (TGFrameElement*)   gEve->GetBrowser()->GetList()->First();
176   TGCompositeFrame *xxCF = (TGCompositeFrame*) xxFE->fFrame;
177   xxFE = (TGFrameElement*)   xxCF->GetList()->First();
178   xxCF = (TGCompositeFrame*) xxFE->fFrame;
179   xxFE = (TGFrameElement*)   xxCF->GetList()->First();
180   xxCF = (TGCompositeFrame*) xxFE->fFrame;
181   xxFE = (TGFrameElement*)   xxCF->GetList()->First();
182   TGMenuBar *mBar = (TGMenuBar*) xxFE->fFrame;
183   mBar->AddPopup("&AliEve", fAliEvePopup, new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0));
184   ((TGCompositeFrame*)mBar->GetParent()->GetParent())->Layout();
185 #endif
186 }
187
188 //==============================================================================
189
190 #include <iostream>
191 #include <fstream>
192 #include <string>
193 #include <sstream>
194
195 using namespace std;
196
197 namespace
198 {
199 const char *gMacroSaveAsTypes[] = {"CINT Macro", "*.C",
200                                    0, 0}; //for saving/loading macros
201
202 const char *gPictureSaveAsTypes[] = {"PNG Image", "*.png",
203                                    0, 0}; //for saving pictures
204
205 }
206
207 void AliEveConfigManager::AliEvePopupHandler(Int_t id)
208 {
209   // Handle user selections from AliEve popup.
210
211   static const TEveException kEH("AliEveConfigManager::AliEvePopupHandler ");
212
213   switch (id)
214   {
215
216     case kAEMDefault: //default geometry and VizDB
217     {
218       AliEveMultiView *mv = AliEveMultiView::Instance();
219
220       mv->DestroyAllGeometries(); //destroy RPhi and Rhoz geometries before putting new
221
222       gEve->LoadVizDB("geom_gentle_default.C", kTRUE, kTRUE); //loading geometry
223
224       gEve->LoadVizDB("VizDB_scan.C", kTRUE, kTRUE); //loading VizDB
225
226       if(!gEve->GetViewers()->UseLightColorSet())
227         gEve->GetViewers()->SwitchColorSet(); //white background
228
229       gEve->FullRedraw3D();   
230       
231       break;
232     }
233
234     case kAEMScreen: //default geometry with black background
235     {
236       AliEveMultiView *mv = AliEveMultiView::Instance();
237
238       mv->DestroyAllGeometries();
239
240       gEve->LoadVizDB("geom_gentle_default.C", kTRUE, kTRUE);
241
242       gEve->LoadVizDB("VizDB_scan_screen.C", kTRUE, kTRUE);
243
244       if(gEve->GetViewers()->UseLightColorSet())
245         gEve->GetViewers()->SwitchColorSet();
246
247       gEve->FullRedraw3D();    
248
249       break;
250     }
251
252     case kAEMProjector: //default geometry with white background
253     {
254       AliEveMultiView *mv = AliEveMultiView::Instance();
255
256       mv->DestroyAllGeometries();
257
258       gEve->LoadVizDB("geom_gentle_projector.C", kTRUE, kTRUE);
259
260       gEve->LoadVizDB("VizDB_scan_projector.C", kTRUE, kTRUE);
261
262       if(!gEve->GetViewers()->UseLightColorSet())
263         gEve->GetViewers()->SwitchColorSet();
264
265       gEve->FullRedraw3D();    
266
267       break;
268     }
269
270     case kAEMNotransparency: //default geometry with low transparency (5%)
271     {
272       AliEveMultiView *mv = AliEveMultiView::Instance();
273
274       mv->DestroyAllGeometries();
275
276       gEve->LoadVizDB("geom_gentle_notransparency.C", kTRUE, kTRUE);
277
278       gEve->LoadVizDB("VizDB_scan.C", kTRUE, kTRUE);
279
280       if(!gEve->GetViewers()->UseLightColorSet())
281         gEve->GetViewers()->SwitchColorSet();
282
283       gEve->FullRedraw3D();    
284
285       break;
286     }
287
288
289     case kAEMTransparentDark: //default geometry with black background, high transparency (80%)
290     {
291       AliEveMultiView *mv = AliEveMultiView::Instance();
292
293       mv->DestroyAllGeometries();
294
295       gEve->LoadVizDB("geom_gentle_transparent.C", kTRUE, kTRUE);
296
297       gEve->LoadVizDB("VizDB_scan_transparentdark.C", kTRUE, kTRUE);
298
299       if(gEve->GetViewers()->UseLightColorSet())
300         gEve->GetViewers()->SwitchColorSet();
301
302       gEve->FullRedraw3D();   
303
304       break;
305     }
306
307     case kAEMTransparentLight: //default geometry with white background, high transparency (80%)
308     {
309       AliEveMultiView *mv = AliEveMultiView::Instance();
310
311       mv->DestroyAllGeometries();
312
313       gEve->LoadVizDB("geom_gentle_transparent.C", kTRUE, kTRUE);
314
315       gEve->LoadVizDB("VizDB_scan_transparentlight.C", kTRUE, kTRUE);
316
317       if(!gEve->GetViewers()->UseLightColorSet())
318         gEve->GetViewers()->SwitchColorSet();
319
320       gEve->FullRedraw3D();    
321
322       break;
323     }
324
325     case kAEMTransparentMonoDark:
326     {
327       AliEveMultiView *mv = AliEveMultiView::Instance();
328
329       mv->DestroyAllGeometries();
330
331       gEve->LoadVizDB("geom_gentle_transparentdark.C", kTRUE, kTRUE);
332
333       gEve->LoadVizDB("VizDB_scan_transparentdark.C", kTRUE, kTRUE);
334
335       if(gEve->GetViewers()->UseLightColorSet())
336         gEve->GetViewers()->SwitchColorSet();
337
338       gEve->FullRedraw3D();   
339
340       break;
341     }
342
343     case kAEMTransparentMonoLight:
344     {
345       AliEveMultiView *mv = AliEveMultiView::Instance();
346
347       mv->DestroyAllGeometries();
348
349       gEve->LoadVizDB("geom_gentle_transparentlight.C", kTRUE, kTRUE);
350
351       gEve->LoadVizDB("VizDB_scan_transparentlight.C", kTRUE, kTRUE);
352
353       if(!gEve->GetViewers()->UseLightColorSet())
354         gEve->GetViewers()->SwitchColorSet();
355
356       gEve->FullRedraw3D();    
357
358       break;
359     }
360
361     case kAEMGreen:
362     {
363       AliEveMultiView *mv = AliEveMultiView::Instance();
364
365       mv->DestroyAllGeometries();
366
367       gEve->LoadVizDB("geom_gentle_green.C", kTRUE, kTRUE);
368
369       gEve->LoadVizDB("VizDB_scan.C", kTRUE, kTRUE);
370
371       if(!gEve->GetViewers()->UseLightColorSet())
372         gEve->GetViewers()->SwitchColorSet();
373
374       gEve->FullRedraw3D();    
375
376       break;
377     }
378
379     case kAEMBright:
380     {
381       AliEveMultiView *mv = AliEveMultiView::Instance();
382
383       mv->DestroyAllGeometries();
384
385       gEve->LoadVizDB("geom_gentle_bright.C", kTRUE, kTRUE);
386
387       gEve->LoadVizDB("VizDB_scan.C", kTRUE, kTRUE);
388
389       if(gEve->GetViewers()->UseLightColorSet())
390         gEve->GetViewers()->SwitchColorSet();
391
392       gEve->FullRedraw3D();
393
394       break;
395     }
396
397     case kAEMYellow:
398     {
399       AliEveMultiView *mv = AliEveMultiView::Instance();
400
401       mv->DestroyAllGeometries();
402
403       gEve->LoadVizDB("geom_gentle_yellow.C", kTRUE, kTRUE);
404
405       gEve->LoadVizDB("VizDB_scan_yellow.C", kTRUE, kTRUE);
406
407       if(!gEve->GetViewers()->UseLightColorSet())
408         gEve->GetViewers()->SwitchColorSet();
409
410       gEve->FullRedraw3D();    
411
412       break;
413     }
414
415     case kAEMTpc:
416     {
417       AliEveMultiView *mv = AliEveMultiView::Instance();
418
419       mv->DestroyAllGeometries();
420
421       gEve->LoadVizDB("geom_gentle_tpc.C", kTRUE, kTRUE);
422
423       gEve->LoadVizDB("VizDB_scan_tpc.C", kTRUE, kTRUE);
424
425       if(!gEve->GetViewers()->UseLightColorSet())
426         gEve->GetViewers()->SwitchColorSet();
427
428       gEve->FullRedraw3D();
429
430       break;
431     }
432
433     case kAEMAll: //saving pictures from all three viewers
434     {
435       
436      TGFileInfo fi;
437      fi.fFileTypes   = gPictureSaveAsTypes;
438      fi.fIniDir      = StrDup(""); // current directory
439      fi.fFileTypeIdx = 0;
440      fi.fOverwrite   = kTRUE;
441      new TGFileDialog(gClient->GetDefaultRoot(),
442      gEve->GetMainWindow(), kFDSave, &fi); // dialog 
443      if (!fi.fFilename) return;
444
445      TPMERegexp filere(".*/([^/]+$)");
446      if (filere.Match(fi.fFilename) != 2)
447      {
448        Warning("AliEvePopupHandler", "file '%s' bad.", fi.fFilename);
449        return;
450      }
451
452      TString file1(filere[1]);
453      TString file2(filere[1]);
454      TString file3(filere[1]);
455      
456      if (!file1.EndsWith(".png"))
457        file1 += "_3D.png"; // adding extensions
458        
459      if (!file2.EndsWith(".png"))
460        file2 += "_RPhi.png"; // adding extensions
461        
462      if (!file3.EndsWith(".png"))
463        file3 += "_RhoZ.png"; // adding extensions
464
465      gSystem->ChangeDirectory(fi.fIniDir);
466       
467      printf("Saving...\n");
468
469      TEveViewerList *viewers = gEve->GetViewers();
470      TEveElement::List_i i = viewers->BeginChildren();
471      i++;
472      TEveViewer* view3d = ((TEveViewer*)*i);
473      view3d->GetGLViewer()->SavePicture(file1); // saving pictures
474      i++;
475      TEveViewer* viewrphi = ((TEveViewer*)*i);
476      viewrphi->GetGLViewer()->SavePicture(file2); // saving pictures
477      i++;
478      TEveViewer* viewrhoz = ((TEveViewer*)*i);
479      viewrhoz->GetGLViewer()->SavePicture(file3); // saving pictures
480      
481      printf("Done.\n"); 
482       
483       break;
484     }
485     
486     case kAEM3d: // saving only 3d view
487     {
488       
489      TGFileInfo fi;
490      fi.fFileTypes   = gPictureSaveAsTypes;
491      fi.fIniDir      = StrDup(""); // current directory
492      fi.fFileTypeIdx = 0;
493      fi.fOverwrite   = kTRUE;
494      new TGFileDialog(gClient->GetDefaultRoot(),
495      gEve->GetMainWindow(), kFDSave, &fi);
496      if (!fi.fFilename) return;
497
498      TPMERegexp filere(".*/([^/]+$)");
499      if (filere.Match(fi.fFilename) != 2)
500      {
501        Warning("AliEvePopupHandler", "file '%s' bad.", fi.fFilename);
502        return;
503      }
504
505      TString file1(filere[1]);
506      
507      if (!file1.EndsWith(".png"))
508        file1 += ".png";
509
510      gSystem->ChangeDirectory(fi.fIniDir);
511       
512      printf("Saving...\n");
513
514      TEveViewerList *viewers = gEve->GetViewers();
515      TEveElement::List_i i = viewers->BeginChildren();
516      i++;
517      TEveViewer* view3d = ((TEveViewer*)*i);
518      view3d->GetGLViewer()->SavePicture(file1);
519      
520      printf("Done.\n"); 
521       
522       break;
523     }
524     
525      case kAEMRphi: // saving only RPhi view
526     {
527       
528      TGFileInfo fi;
529      fi.fFileTypes   = gPictureSaveAsTypes;
530      fi.fIniDir      = StrDup(""); // current directory
531      fi.fFileTypeIdx = 0;
532      fi.fOverwrite   = kTRUE;
533      new TGFileDialog(gClient->GetDefaultRoot(),
534      gEve->GetMainWindow(), kFDSave, &fi);
535      if (!fi.fFilename) return;
536
537      TPMERegexp filere(".*/([^/]+$)");
538      if (filere.Match(fi.fFilename) != 2)
539      {
540        Warning("AliEvePopupHandler", "file '%s' bad.", fi.fFilename);
541        return;
542      }
543
544      TString file1(filere[1]);
545      
546      if (!file1.EndsWith(".png"))
547        file1 += ".png";
548      
549      gSystem->ChangeDirectory(fi.fIniDir);
550       
551      printf("Saving...\n");
552
553      TEveViewerList *viewers = gEve->GetViewers();
554      TEveElement::List_i i = viewers->BeginChildren();
555      i++;
556      i++;
557      TEveViewer* viewrphi = ((TEveViewer*)*i);
558      viewrphi->GetGLViewer()->SavePicture(file1);
559      
560      printf("Done.\n"); 
561       
562       break;
563     }
564     
565      case kAEMRhoz: // saving only RhoZ view
566     {
567     
568      TGFileInfo fi;
569      fi.fFileTypes   = gPictureSaveAsTypes;
570      fi.fIniDir      = StrDup(""); // current directory
571      fi.fFileTypeIdx = 0;
572      fi.fOverwrite   = kTRUE;
573      new TGFileDialog(gClient->GetDefaultRoot(),
574      gEve->GetMainWindow(), kFDSave, &fi);
575      if (!fi.fFilename) return;
576
577      TPMERegexp filere(".*/([^/]+$)");
578      if (filere.Match(fi.fFilename) != 2)
579      {
580        Warning("AliEvePopupHandler", "file '%s' bad.", fi.fFilename);
581        return;
582      }
583
584      TString file1(filere[1]);
585        
586      if (!file1.EndsWith(".png"))
587        file1 += ".png";
588
589      gSystem->ChangeDirectory(fi.fIniDir);
590      
591      printf("Saving...\n");
592
593      TEveViewerList *viewers = gEve->GetViewers();
594      TEveElement::List_i i = viewers->BeginChildren();
595      i++;
596      i++;
597      i++;
598      TEveViewer* viewrhoz = ((TEveViewer*)*i);
599      viewrhoz->GetGLViewer()->SavePicture(file1);
600      
601      printf("Done.\n"); 
602       
603       break;
604     }
605
606     case kAEMAllhr: // saving all three views in high resolution
607     {
608       
609      TGFileInfo fi;
610      fi.fFileTypes   = gPictureSaveAsTypes;
611      fi.fIniDir      = StrDup(""); // current directory
612      fi.fFileTypeIdx = 0;
613      fi.fOverwrite   = kTRUE;
614      new TGFileDialog(gClient->GetDefaultRoot(),
615      gEve->GetMainWindow(), kFDSave, &fi);
616      if (!fi.fFilename) return;
617
618      TPMERegexp filere(".*/([^/]+$)");
619      if (filere.Match(fi.fFilename) != 2)
620      {
621        Warning("AliEvePopupHandler", "file '%s' bad.", fi.fFilename);
622        return;
623      }
624
625      TString file1(filere[1]);
626      TString file2(filere[1]);
627      TString file3(filere[1]);
628      
629      if (!file1.EndsWith(".png"))
630        file1 += "_3D.png";
631        
632      if (!file2.EndsWith(".png"))
633        file2 += "_RPhi.png";
634        
635      if (!file3.EndsWith(".png"))
636        file3 += "_RhoZ.png";
637
638      gSystem->ChangeDirectory(fi.fIniDir);
639       
640      printf("Saving...\n");
641
642      TEveViewerList *viewers = gEve->GetViewers();
643      TEveElement::List_i i = viewers->BeginChildren();
644      i++;
645      TEveViewer* view3d = ((TEveViewer*)*i);
646      view3d->GetGLViewer()->SavePictureScale(file1,4.0); // getting high resolution
647      i++;
648      TEveViewer* viewrphi = ((TEveViewer*)*i);
649      viewrphi->GetGLViewer()->SavePictureScale(file2,4.0);
650      i++;
651      TEveViewer* viewrhoz = ((TEveViewer*)*i);
652      viewrhoz->GetGLViewer()->SavePictureScale(file3,4.0);
653      
654      printf("Done.\n"); 
655       
656       break;
657     }
658     
659     case kAEM3dhr: // saving only 3d view in high resolution
660     {
661       
662      TGFileInfo fi;
663      fi.fFileTypes   = gPictureSaveAsTypes;
664      fi.fIniDir      = StrDup(""); // current directory
665      fi.fFileTypeIdx = 0;
666      fi.fOverwrite   = kTRUE;
667      new TGFileDialog(gClient->GetDefaultRoot(),
668      gEve->GetMainWindow(), kFDSave, &fi);
669      if (!fi.fFilename) return;
670
671      TPMERegexp filere(".*/([^/]+$)");
672      if (filere.Match(fi.fFilename) != 2)
673      {
674        Warning("AliEvePopupHandler", "file '%s' bad.", fi.fFilename);
675        return;
676      }
677
678      TString file1(filere[1]);
679      
680      if (!file1.EndsWith(".png"))
681        file1 += ".png";
682
683      gSystem->ChangeDirectory(fi.fIniDir);
684       
685      printf("Saving...\n");
686
687      TEveViewerList *viewers = gEve->GetViewers();
688      TEveElement::List_i i = viewers->BeginChildren();
689      i++;
690      TEveViewer* view3d = ((TEveViewer*)*i);
691      view3d->GetGLViewer()->SavePictureScale(file1,4.0);
692      
693      printf("Done.\n"); 
694       
695       break;
696     }
697     
698      case kAEMRphihr: // saving only RPhi view in high resolution
699     {
700       
701      TGFileInfo fi;
702      fi.fFileTypes   = gPictureSaveAsTypes;
703      fi.fIniDir      = StrDup(""); // current directory
704      fi.fFileTypeIdx = 0;
705      fi.fOverwrite   = kTRUE;
706      new TGFileDialog(gClient->GetDefaultRoot(),
707      gEve->GetMainWindow(), kFDSave, &fi);
708      if (!fi.fFilename) return;
709
710      TPMERegexp filere(".*/([^/]+$)");
711      if (filere.Match(fi.fFilename) != 2)
712      {
713        Warning("AliEvePopupHandler", "file '%s' bad.", fi.fFilename);
714        return;
715      }
716
717      TString file1(filere[1]);
718      
719      if (!file1.EndsWith(".png"))
720        file1 += ".png";
721      
722      gSystem->ChangeDirectory(fi.fIniDir);
723       
724      printf("Saving...\n");
725
726      TEveViewerList *viewers = gEve->GetViewers();
727      TEveElement::List_i i = viewers->BeginChildren();
728      i++;
729      i++;
730      TEveViewer* viewrphi = ((TEveViewer*)*i);
731      viewrphi->GetGLViewer()->SavePictureScale(file1,4.0);
732      
733      printf("Done.\n"); 
734       
735       break;
736     }
737     
738      case kAEMRhozhr: // saving only RhoZ view in high resolution
739     {
740     
741      TGFileInfo fi;
742      fi.fFileTypes   = gPictureSaveAsTypes;
743      fi.fIniDir      = StrDup(""); // current directory
744      fi.fFileTypeIdx = 0;
745      fi.fOverwrite   = kTRUE;
746      new TGFileDialog(gClient->GetDefaultRoot(),
747      gEve->GetMainWindow(), kFDSave, &fi);
748      if (!fi.fFilename) return;
749
750      TPMERegexp filere(".*/([^/]+$)");
751      if (filere.Match(fi.fFilename) != 2)
752      {
753        Warning("AliEvePopupHandler", "file '%s' bad.", fi.fFilename);
754        return;
755      }
756
757      TString file1(filere[1]);
758        
759      if (!file1.EndsWith(".png"))
760        file1 += ".png";
761
762      gSystem->ChangeDirectory(fi.fIniDir);
763      
764      printf("Saving...\n");
765
766      TEveViewerList *viewers = gEve->GetViewers();
767      TEveElement::List_i i = viewers->BeginChildren();
768      i++;
769      i++;
770      i++;
771      TEveViewer* viewrhoz = ((TEveViewer*)*i);
772      viewrhoz->GetGLViewer()->SavePictureScale(file1,4.0);
773      
774      printf("Done.\n"); 
775       
776       break;
777     }
778
779      case kAEMSavemacros:// Saving Data Selection macros
780     {
781
782       AliEveMacroExecutor *exec = AliEveEventManager::GetMaster()->GetExecutor();
783
784       exec->SaveAddedMacros();
785
786       break;
787     }
788  
789    case kAEMLoadmacros://Loading Data Selection macros
790     {
791
792       TEveBrowser *browser = gEve->GetBrowser();
793       browser->ShowCloseTab(kFALSE);
794
795       if(fLoadCheck)
796         browser->RemoveTab(TRootBrowser::kRight, 5);//remove the tab with previous DataSelection window
797       else
798         browser->RemoveTab(TRootBrowser::kRight, 2);
799
800
801       TGFileInfo fi;
802       fi.fFileTypes   = gMacroSaveAsTypes;
803       fi.fIniDir      = StrDup(""); // current directory
804       fi.fFileTypeIdx = 0;
805       fi.fOverwrite   = kTRUE;
806       new TGFileDialog(gClient->GetDefaultRoot(), gEve->GetMainWindow(), kFDOpen, &fi);//dialog
807       if (!fi.fFilename) return;
808
809       TPMERegexp filere(".*/([^/]+$)");
810       if (filere.Match(fi.fFilename) != 2)
811       {
812         Warning("AliEvePopupHandler", "file '%s' bad.", fi.fFilename);
813         return;
814       }
815       printf("Loading...\n");
816
817       TString file(filere[1]);
818       gSystem->ChangeDirectory(fi.fIniDir);
819
820       TEveUtil::Macro(file);//run macro
821
822       AliEveEventManager *eman = AliEveEventManager::GetMaster();//reload event (gEve->Refresh() crashes)
823       Int_t ev = eman->GetEventId();
824       eman->Close();
825       eman->Open();
826       eman->GotoEvent(ev);
827
828       printf("Done.\n");
829
830       fLoadCheck = kTRUE;
831
832       break;
833
834     }
835
836     case kAEMSave://saving VizDB
837     {
838       TGFileInfo fi;
839       fi.fFileTypes   = gMacroSaveAsTypes;
840       fi.fIniDir      = StrDup(""); // current directory
841       fi.fFileTypeIdx = 0;
842       fi.fOverwrite   = kTRUE;
843       new TGFileDialog(gClient->GetDefaultRoot(), gEve->GetMainWindow(), kFDSave, &fi);
844       if (!fi.fFilename) return;
845
846       TPMERegexp filere(".*/([^/]+$)");
847       if (filere.Match(fi.fFilename) != 2)
848       {
849         Warning("AliEvePopupHandler", "file '%s' bad.", fi.fFilename);
850         return;
851       }
852       printf("Saving...\n");
853
854       TString file(filere[1]);
855       if (!file.EndsWith(".C"))
856         file += ".C";
857       gSystem->ChangeDirectory(fi.fIniDir);
858       gEve->SaveVizDB(file);
859
860 //Last line "gEve->SaveVizDB(file);" gives macro with many unnecessary
861 //lines like "x038->SetMinPt(0);" tahat are not interpreted properly later
862
863       string text;
864       string all;
865
866       ifstream myfile1(file);
867       if(myfile1.is_open())
868         {
869         while(!myfile1.eof())
870           {
871             getline(myfile1,text);
872             TString check(text);
873             if(!(check.EndsWith("MinPt(0);")||check.EndsWith("MaxPt(0);")
874                ||check.EndsWith("LimPt(0);")||check.EndsWith("MinP(0);")
875                ||check.EndsWith("MaxP(0);")||check.EndsWith("LimP(0);")))
876               {
877               all += text; //Cut off unnecessary lines and bring everything together
878               all += "\n";
879               }
880           }
881         myfile1.close();
882         }
883
884       ofstream myfile2(file); //Replacing old file with the one without "bad" lines
885       myfile2 << all;
886       myfile2.close();
887
888       printf("Done.\n");
889       break;
890
891     }
892
893     case kAEMOpen://Opening VizDB
894     {
895       TGFileInfo fi;
896       fi.fFileTypes   = gMacroSaveAsTypes;
897       fi.fIniDir      = StrDup(""); // current directory
898       fi.fFileTypeIdx = 0;
899       fi.fOverwrite   = kTRUE;
900       new TGFileDialog(gClient->GetDefaultRoot(), gEve->GetMainWindow(), kFDOpen, &fi);
901       if (!fi.fFilename) return;
902
903       TPMERegexp filere(".*/([^/]+$)");
904       if (filere.Match(fi.fFilename) != 2)
905       {
906         Warning("AliEvePopupHandler", "file '%s' bad.", fi.fFilename);
907         return;
908       }
909       printf("Opening...\n");
910
911       TString file(filere[1]);
912
913       gSystem->ChangeDirectory(fi.fIniDir);
914
915       gEve->LoadVizDB(file, kTRUE, kTRUE);
916
917       gEve->Redraw3D(kTRUE);
918
919       printf("Done.\n");
920       break;
921
922     }
923
924     case kAEMSetDefault://Restore default settings
925     {
926
927       printf("Setting...\n");
928
929       TEveBrowser *browser = gEve->GetBrowser();
930       browser->ShowCloseTab(kFALSE);
931
932       if(fLoadCheck)
933         browser->RemoveTab(TRootBrowser::kRight, 5);//remove the tab with previous DataSelection window
934       else
935         browser->RemoveTab(TRootBrowser::kRight, 2);
936
937       TEveUtil::Macro("geom_gentle_default.C");
938       gEve->LoadVizDB("VizDB_scan.C", kTRUE, kTRUE);
939       TEveUtil::Macro("DataSelection_init.C");
940
941       if(!gEve->GetViewers()->UseLightColorSet())
942         gEve->GetViewers()->SwitchColorSet(); //white background
943
944       AliEveEventManager *eman = AliEveEventManager::GetMaster();//reload event (gEve->Refresh() crashes)
945       Int_t ev = eman->GetEventId();
946       eman->Close();
947       eman->Open();
948       eman->GotoEvent(ev);
949
950       printf("Done.\n");
951
952       fLoadCheck = kTRUE;
953
954       gEve->Redraw3D(kTRUE);
955
956
957     }
958
959     default:
960     {
961       Warning(kEH, "Unknown menu entry.");
962       break;
963     }
964   }
965 }