AliEveEventManager
[u/mrichter/AliRoot.git] / EVE / EveBase / AliEveEventManagerEditor.cxx
1 // @(#)root/eve:$Id$
2 // Author: Matevz Tadel 2007
3
4 /**************************************************************************
5  * Copyright(c) 1998-2008, 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 "AliEveEventManagerEditor.h"
11 #include "AliEveEventManager.h"
12
13 #include "TVirtualPad.h"
14 #include "TColor.h"
15
16 #include <TEveGValuators.h>
17 #include <TGButton.h>
18 #include <TGTextView.h>
19 #include <TGLabel.h>
20
21 //______________________________________________________________________________
22 // GUI editor for AliEveEventManager.
23 //
24
25 ClassImp(AliEveEventManagerEditor)
26
27 //______________________________________________________________________________
28 AliEveEventManagerEditor::AliEveEventManagerEditor(const TGWindow *p, Int_t width, Int_t height,
29              UInt_t options, Pixel_t back) :
30   TGedFrame(p, width, height, options | kVerticalFrame, back),
31   fM(0),
32   fAutoLoad(0),
33   fAutoLoadTime(0),
34   fNextEvent(0),
35   fPrevEvent(0),
36   fLastEvent(0),
37   fRefresh(0),
38   fEventInfo(0)
39 {
40   // Constructor.
41
42   MakeTitle("AliEveEventManager");
43
44   // Create widgets
45   {
46     fAutoLoadTime = new TEveGValuator(this, "Autoload time:", 110, 0);
47     fAutoLoadTime->SetShowSlider(kFALSE);
48     fAutoLoadTime->SetNELength(4);
49     fAutoLoadTime->Build();
50     fAutoLoadTime->SetLimits(0, 1000);
51     fAutoLoadTime->SetToolTip("Automatic event loading time in seconds");
52     fAutoLoadTime->Connect("ValueSet(Double_t)",
53                            "AliEveEventManagerEditor", this, "DoSetAutoLoadTime()");
54
55     fAutoLoad = new TGCheckButton(fAutoLoadTime,"Autoload");
56     fAutoLoad->SetToolTipText("Automatic event loading (online)");
57     fAutoLoadTime->AddFrame(fAutoLoad, new TGLayoutHints(kLHintsLeft, 12, 0, 2, 0));
58     fAutoLoad->Connect("Toggled(Bool_t)",
59                        "AliEveEventManagerEditor", this, "DoSetAutoLoad()");
60     AddFrame(fAutoLoadTime);
61   }
62   {
63     TGHorizontalFrame* f = new TGHorizontalFrame(this);
64     fPrevEvent = new TGTextButton(f, "Previous Event");
65     fPrevEvent->SetWidth(100);
66     fPrevEvent->ChangeOptions(fPrevEvent->GetOptions() | kFixedWidth);
67     f->AddFrame(fPrevEvent, new TGLayoutHints(kLHintsNormal, 0,4,0,0));
68     fPrevEvent->Connect("Clicked()",
69                         "AliEveEventManagerEditor", this, "DoPrevEvent()");
70     fNextEvent = new TGTextButton(f, "Next Event");
71     fNextEvent->SetWidth(100);
72     fNextEvent->ChangeOptions(fNextEvent->GetOptions() | kFixedWidth);
73     f->AddFrame(fNextEvent, new TGLayoutHints(kLHintsNormal, 4,0,0,0));
74     fNextEvent->Connect("Clicked()",
75                         "AliEveEventManagerEditor", this, "DoNextEvent()");
76     AddFrame(f, new TGLayoutHints(kLHintsExpandX, 8,8,8,0));
77   }
78   {
79     TGHorizontalFrame* f = new TGHorizontalFrame(this);
80     fLastEvent = new TGTextButton(f, "Last Event");
81     fLastEvent->SetWidth(100);
82     fLastEvent->ChangeOptions(fLastEvent->GetOptions() | kFixedWidth);
83     f->AddFrame(fLastEvent, new TGLayoutHints(kLHintsNormal, 0,4,0,0));
84     fLastEvent->Connect("Clicked()",
85                         "AliEveEventManagerEditor", this, "DoLastEvent()");
86     fRefresh = new TGTextButton(f, "Refresh");
87     fRefresh->SetWidth(100);
88     fRefresh->ChangeOptions(fRefresh->GetOptions() | kFixedWidth);
89     f->AddFrame(fRefresh, new TGLayoutHints(kLHintsNormal, 4,0,0,0));
90     fRefresh->Connect("Clicked()",
91                         "AliEveEventManagerEditor", this, "DoRefresh()");
92     AddFrame(f, new TGLayoutHints(kLHintsExpandX, 8,8,8,0));
93   }
94
95   {
96     TGVerticalFrame* f = new TGVerticalFrame(this);
97
98     TGLabel *eventInfoLabel = new TGLabel(f, "Event Information:");
99     f->AddFrame(eventInfoLabel, new TGLayoutHints(kLHintsNormal, 0,0,6,2));
100
101     fEventInfo = new TGTextView(f, 200, 300);
102     f->AddFrame(fEventInfo, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
103
104     AddFrame(f, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
105   }
106 }
107
108 /******************************************************************************/
109
110 void AliEveEventManagerEditor::SetModel(TObject* obj)
111 {
112   // Set model object.
113
114   fM = dynamic_cast<AliEveEventManager*>(obj);
115
116   // Set values of widgets
117   fAutoLoadTime->SetValue(fM->GetAutoLoadTime());
118   fAutoLoadTime->SetEnabled(fM->GetAutoLoad());
119   fAutoLoad->SetState(fM->GetAutoLoad() ? kButtonDown : kButtonUp);
120
121   fPrevEvent->SetEnabled(!fM->GetIsOnline()); 
122
123   fEventInfo->LoadBuffer(fM->GetEventInfoVertical());
124 }
125
126 /******************************************************************************/
127
128 // Implements callback/slot methods
129
130 //______________________________________________________________________________
131 void AliEveEventManagerEditor::DoSetAutoLoad()
132 {
133   // Set the auto-load flag
134   //
135   fM->SetAutoLoad(fAutoLoad->IsOn());
136   Update();
137 }
138
139 //______________________________________________________________________________
140 void AliEveEventManagerEditor::DoSetAutoLoadTime()
141 {
142   // Set the auto-load time in seconds
143   //
144   fM->SetAutoLoadTime(fAutoLoadTime->GetValue());
145   fM->SetAutoLoad(fAutoLoad->IsOn());
146   Update();
147 }
148
149 //______________________________________________________________________________
150 void AliEveEventManagerEditor::DoPrevEvent()
151 {
152   // Load previous event
153   fM->PrevEvent();
154 }
155
156 //______________________________________________________________________________
157 void AliEveEventManagerEditor::DoNextEvent()
158 {
159   // Load next event
160   fM->NextEvent();
161 }
162
163 //______________________________________________________________________________
164 void AliEveEventManagerEditor::DoLastEvent()
165 {
166   // Load last event
167   fM->GotoEvent(-1);
168 }
169
170 //______________________________________________________________________________
171 void AliEveEventManagerEditor::DoRefresh()
172 {
173   // Refresh / reopen data-files
174   Int_t ev = fM->GetEventId();
175   fM->Close();
176   fM->Open();
177   fM->GotoEvent(ev);
178 }
179
180
181 /******************************************************************************/
182 // AliEveEventManagerWindow
183 /******************************************************************************/
184
185 //______________________________________________________________________________
186 //
187 // Horizontal GUI for AliEveEventManager, to be placed in the
188 // bottom part of ROOT browser.
189
190 ClassImp(AliEveEventManagerWindow)
191
192 AliEveEventManagerWindow::AliEveEventManagerWindow() :
193   TGMainFrame(gClient->GetRoot(), 400, 100, kVerticalFrame),
194   fFirstEvent(0),
195   fPrevEvent(0),
196   fNextEvent(0),
197   fLastEvent(0),
198   fEventId  (0),
199   fInfoLabel(0),
200   fEventInfo(0)
201 {
202   // Constructor.
203
204   {
205     Int_t width = 50;
206
207     TGHorizontalFrame* f = new TGHorizontalFrame(this);
208     fFirstEvent = new TGTextButton(f, "First");
209     fFirstEvent->SetWidth(width);
210     fFirstEvent->ChangeOptions(fFirstEvent->GetOptions() | kFixedWidth);
211     f->AddFrame(fFirstEvent, new TGLayoutHints(kLHintsNormal, 2,2,0,0));
212     fFirstEvent->Connect("Clicked()",
213                          "AliEveEventManagerWindow", this, "DoFirstEvent()");
214     fPrevEvent = new TGTextButton(f, "Prev");
215     fPrevEvent->SetWidth(width);
216     fPrevEvent->ChangeOptions(fPrevEvent->GetOptions() | kFixedWidth);
217     f->AddFrame(fPrevEvent, new TGLayoutHints(kLHintsNormal, 2,2,0,0));
218     fPrevEvent->Connect("Clicked()",
219                         "AliEveEventManagerWindow", this, "DoPrevEvent()");
220
221     fEventId = new TGNumberEntry(f, 0, 5, -1,TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative,
222                                  TGNumberFormat::kNELLimitMinMax, 0, 10000);
223     f->AddFrame(fEventId, new TGLayoutHints(kLHintsNormal, 10, 5, 0, 0));
224     fEventId->Connect("ValueSet(Long_t)",
225                       "AliEveEventManagerWindow", this, "DoSetEvent()");
226     fInfoLabel = new TGLabel(f);
227     f->AddFrame(fInfoLabel, new TGLayoutHints(kLHintsNormal, 5, 10, 4, 0));
228
229     fNextEvent = new TGTextButton(f, "Next");
230     fNextEvent->SetWidth(width);
231     fNextEvent->ChangeOptions(fNextEvent->GetOptions() | kFixedWidth);
232     f->AddFrame(fNextEvent, new TGLayoutHints(kLHintsNormal, 2,2,0,0));
233     fNextEvent->Connect("Clicked()",
234                         "AliEveEventManagerWindow", this, "DoNextEvent()");
235     fLastEvent = new TGTextButton(f, "Last");
236     fLastEvent->SetWidth(width);
237     fLastEvent->ChangeOptions(fLastEvent->GetOptions() | kFixedWidth);
238     f->AddFrame(fLastEvent, new TGLayoutHints(kLHintsNormal, 2,2,0,0));
239     fLastEvent->Connect("Clicked()",
240                         "AliEveEventManagerWindow", this, "DoLastEvent()");
241     AddFrame(f, new TGLayoutHints(kLHintsExpandX, 0,0,2,2));
242   }
243
244   {
245     TGHorizontalFrame* f = new TGHorizontalFrame(this);
246     fEventInfo = new TGTextView(f, 800, 600);
247     f->AddFrame(fEventInfo, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY));
248     AddFrame(f, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0,0,2,2));
249   }
250
251   gAliEveEvent->Connect("NewEventLoaded()",
252                         "AliEveEventManagerWindow", this, "Update()");
253
254   SetCleanup(kDeepCleanup);
255   Layout();
256   MapSubwindows();
257   MapWindow();
258 }
259
260 //______________________________________________________________________________
261 AliEveEventManagerWindow::~AliEveEventManagerWindow()
262 {
263   // Destructor.
264
265   gAliEveEvent->Disconnect("NewEventLoaded()", this);
266 }
267
268 //______________________________________________________________________________
269 void AliEveEventManagerWindow::DoFirstEvent()
270 {
271   // Load previous event
272   gAliEveEvent->GotoEvent(0);
273 }
274
275 //______________________________________________________________________________
276 void AliEveEventManagerWindow::DoPrevEvent()
277 {
278   // Load previous event
279   gAliEveEvent->PrevEvent();
280 }
281
282 //______________________________________________________________________________
283 void AliEveEventManagerWindow::DoNextEvent()
284 {
285   // Load next event
286   gAliEveEvent->NextEvent();
287 }
288
289 //______________________________________________________________________________
290 void AliEveEventManagerWindow::DoLastEvent()
291 {
292   // Load previous event
293   gAliEveEvent->GotoEvent(-1);
294 }
295
296 //______________________________________________________________________________
297 void AliEveEventManagerWindow::DoSetEvent()
298 {
299   // Set current event
300   gAliEveEvent->GotoEvent((Int_t) fEventId->GetNumber());
301 }
302
303 //______________________________________________________________________________
304 void AliEveEventManagerWindow::Update()
305 {
306   // Update current event, number of available events.
307
308   fEventId->SetNumber(gAliEveEvent->GetEventId());
309   fInfoLabel->SetText(Form("/ %d", gAliEveEvent->GetMaxEventId()));
310
311   fEventInfo->LoadBuffer(gAliEveEvent->GetEventInfoHorizontal());
312
313   Layout();
314 }