GGS(GenericGEANT4Simulation)Software  2.6.0
 All Data Structures Namespaces Files Functions Variables Typedefs Macros
Application.cpp
1 #include "TEveBrowser.h"
2 #include "TEveViewer.h"
3 #include "TGLLightSet.h"
4 
5 #include "application/Application.h"
6 
7 
8 EDApplication::EDApplication(int argc, char** argv) : TApplication("GGSLeonard", &argc, argv, 0, -1), _MainWindow(0), _FileManager(0) {
9  static const std::string routineName("EDApplication::EDApplication");
10 
11  gApplication = this;
12  _fileLoaded = _fileToBeLoaded = "";
13 
14  _FileManager = new GGSFileManager();
15 
16  HandleArgs();
17  if( args.flag_debug ) GGSSmartLog::verboseLevel = GGSSmartLog::DEBUG; // Print only DEBUG messages or more important
18 
19  InitGUI();
20 
21  if( args.infilename ){
22  _fileToBeLoaded = args.infilename;
23  LoadRootFile();
24  }
25 
26  if( _FileManager->FileIsLoaded() ){
27  _MainWindow->SetFileName(_fileLoaded);
28  _FileManager->ReadEvent(0);
29  }
30 
31 }
32 
33 EDApplication::~EDApplication(){
34 
35  delete _FileManager;
36  delete _MainWindow;
37  delete _GeoManager;
38 
39 }
40 
41 
42 void EDApplication::NextEvent(){
43  static const std::string routineName("EDApplication::NextEvent");
44 
45  _FileManager->NextEvent();
46  _evtLoaded = _FileManager->GetNevent();
47  _MainWindow->SetEventNumber( _evtLoaded+1 );
48 
49 }
50 
51 void EDApplication::PrevEvent(){
52  static const std::string routineName("EDApplication::PrevEvent");
53 
54  _FileManager->PrevEvent();
55  _evtLoaded = _FileManager->GetNevent();
56  _MainWindow->SetEventNumber( _evtLoaded+1 );
57 
58 }
59 
60 void EDApplication::LoadEvent(){
61  static const std::string routineName("EDApplication::LoadEvent");
62 
63  if( _evtToBeLoaded == _evtLoaded ) return;
64 
65  _FileManager->ReadEvent( _evtToBeLoaded );
66  _evtLoaded = _evtToBeLoaded;
67  _MainWindow->SetEventNumber( _evtLoaded+1 );
68 
69 }
70 
71 void EDApplication::SetFileToBeLoaded(char* text){
72  _fileToBeLoaded = text;
73 }
74 
75 void EDApplication::SetEventToBeLoaded(char* text){
76  _evtToBeLoaded = atoi(text) - 1;
77  if( _evtToBeLoaded < 0 ) _evtToBeLoaded = 0;
78 }
79 
80 void EDApplication::SetDisplayDetector(char* det){
81  static const std::string routineName("EDApplication::SetDisplayDetector");
82 
83  Bool_t s = kTRUE;
84  if(gTQSender){ //check that this is coming from a signal
85  TGCheckButton *but = (TGCheckButton*) gTQSender;
86  s = but->IsDown();
87  }
88 
89  _MainWindow->SetDisplayDetector(det, s);
90 }
91 
92 void EDApplication::SetDisplayPartHits(Bool_t s){
93  _MainWindow->SetDisplayPartHits(s);
94 }
95 
96 void EDApplication::LoadRootFile(){
97  static const std::string routineName("EDApplication::LoadRootFile");
98 
99  if( !_fileToBeLoaded.CompareTo(_fileLoaded) ) return;
100 
101  _FileManager->Load( _fileToBeLoaded );
102  _fileLoaded = _fileToBeLoaded;
103 
104  if( _MainWindow && _FileManager->FileIsLoaded() ){
105  _MainWindow->SetFileName(_fileLoaded);
106  _MainWindow->UpdateFileEntries();
107  _MainWindow->CreateMaps();
108  _FileManager->ReadEvent(0, true);
109  _MainWindow->SetEventNumber(0);
110  }
111 
112 }
113 
114 void EDApplication::HandleArgs(){
115 
116  int parse_status = argp_parse(&argp, Argc(), Argv(), 0, 0, &args);
117  if( parse_status ) exit(42);
118 
119 }
120 
121 void EDApplication::InitGUI(){
122 
123  TEveUtil::SetupEnvironment();
124  TEveUtil::SetupGUI();
125  _MainWindow = new MainWindow();
126  if( !args.flag_debug ){
127  _MainWindow->GetBrowser()->HideBottomTab();
128  }
129 
130  LoadGeometry();
131 
132 }
133 
134 
135 void EDApplication::LoadGeometry(){
136  static const std::string routineName("EDApplication::EDApplication");
137 
138  _GeoManager = new LeonardGeoManager( _MainWindow->GetGeometry(args.geofilename) );
139 
140  _GeoManager->DefaultColors();
141 
142  _MainWindow->AddGlobalElement( _GeoManager->GetEveGeoTopNode() );
143  _GeoManager->GetEveGeoTopNode()->ExpandIntoListTreesRecursively();
144 
145  _MainWindow->FullRedraw3D(kTRUE);
146 
147  _MainWindow->GetDefaultGLViewer()->GetClipSet()->SetClipType(TGLClip::EType(2));
148 
149  _MainWindow->GetDefaultGLViewer()->ResetCameras();
150  _MainWindow->GetDefaultGLViewer()->CurrentCamera().RotateRad(-TMath::Pi()/6, -9*TMath::Pi()/12);
151  _MainWindow->GetDefaultGLViewer()->GetLightSet()->SetUseSpecular(false);
152 }
153 
154 
155 int EDApplication::ParseArgs(int key, char* arg, struct argp_state* state){
156 
157  struct arguments* a = (struct arguments*) state->input;
158 
159  switch(key)
160  {
161  case 'd':
162  {
163  a->flag_debug = kTRUE;
164  break;
165  }
166  case 'i':
167  {
168  a->infilename = arg;
169  break;
170  }
171  case 'g':
172  {
173  a->geofilename = arg;
174  break;
175  }
176  case ARGP_KEY_ARG:
177  {
178  argp_failure(state, 1, 0, "No arguments requested");
179  break;
180  }
181  case ARGP_KEY_INIT:
182  {
183  a->infilename = NULL;
184  a->geofilename = NULL;
185  a->flag_debug = false;
186  break;
187  }
188  case ARGP_KEY_END:
189  {
190  if( !a->geofilename ) argp_failure(state, 1, 0, "No geometry file specified \nUse -G flag to provide VGM geometry");
191  std::cout << std::endl;
192  break;
193  }
194  }
195 
196  return 0;
197 
198 }
199 
200 // -- Static for cli parsing
201 struct argp_option EDApplication::options[] = {
202  {"debug" , 'd', 0 , 0, "Enable Debug Info", 0},
203  {"input-file" , 'i', "FILE", 0, "Input file", 0},
204  {"geometry" , 'g', "FILE", 0, "Geometry file", 0},
205  {0, 0, 0, 0, 0, 0}
206 };
207 struct argp EDApplication::argp = {options, EDApplication::ParseArgs, 0, 0, 0, 0, 0};