1 | /* ======================================================================== *\
|
---|
2 | !
|
---|
3 | ! *
|
---|
4 | ! * This file is part of MARS, the MAGIC Analysis and Reconstruction
|
---|
5 | ! * Software. It is distributed to you in the hope that it can be a useful
|
---|
6 | ! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
|
---|
7 | ! * It is distributed WITHOUT ANY WARRANTY.
|
---|
8 | ! *
|
---|
9 | ! * Permission to use, copy, modify and distribute this software and its
|
---|
10 | ! * documentation for any purpose is hereby granted without fee,
|
---|
11 | ! * provided that the above copyright notice appear in all copies and
|
---|
12 | ! * that both that copyright notice and this permission notice appear
|
---|
13 | ! * in supporting documentation. It is provided "as is" without express
|
---|
14 | ! * or implied warranty.
|
---|
15 | ! *
|
---|
16 | !
|
---|
17 | !
|
---|
18 | ! Author(s): Thomas Bretz 10/2001 (tbretz@uni-sw.gwdg.de)
|
---|
19 | !
|
---|
20 | ! Copyright: MAGIC Software Development, 2000-2001
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | #include "MGEvtDisplay.h"
|
---|
26 |
|
---|
27 | #include <stdlib.h> // atoi
|
---|
28 |
|
---|
29 | #include <TGTab.h> // TGTab
|
---|
30 | #include <TGLabel.h> // TGLabel
|
---|
31 | #include <TGButton.h> // TGPictureButton
|
---|
32 | #include <TGMsgBox.h> // TGMsgBox
|
---|
33 | #include <TGTextEntry.h> // TGTextEntry
|
---|
34 | #include <TRootEmbeddedCanvas.h> // TRootEmbeddedCanvas
|
---|
35 |
|
---|
36 | #include <TG3DLine.h> // TGHorizontal3DLine
|
---|
37 | // use TGSplitter instead for root<3.00
|
---|
38 |
|
---|
39 | #include "MParList.h"
|
---|
40 | #include "MTaskList.h"
|
---|
41 | #include "MEvtLoop.h"
|
---|
42 | #include "MReadTree.h"
|
---|
43 |
|
---|
44 | ClassImp(MGEvtDisplay);
|
---|
45 |
|
---|
46 | enum MGCamDisplayCommand
|
---|
47 | {
|
---|
48 | M_PREVEVT,
|
---|
49 | M_NEXTEVT,
|
---|
50 | M_EVTNUMBER,
|
---|
51 |
|
---|
52 | M_PRINT,
|
---|
53 | M_CLOSE
|
---|
54 | };
|
---|
55 |
|
---|
56 | // --------------------------------------------------------------------------
|
---|
57 | //
|
---|
58 | // Return a pointer to the parameter list.
|
---|
59 | //
|
---|
60 | MParList *MGEvtDisplay::GetParList() const
|
---|
61 | {
|
---|
62 | return fEvtLoop->GetParList();
|
---|
63 | }
|
---|
64 |
|
---|
65 | // --------------------------------------------------------------------------
|
---|
66 | //
|
---|
67 | // Return a pointer to the task list.
|
---|
68 | //
|
---|
69 | MTaskList *MGEvtDisplay::GetTaskList() const
|
---|
70 | {
|
---|
71 | return (MTaskList*)GetParList()->FindObject("MTaskList");
|
---|
72 | }
|
---|
73 |
|
---|
74 | // --------------------------------------------------------------------------
|
---|
75 | //
|
---|
76 | // Return a pointer to the reader task (MReadTree)
|
---|
77 | //
|
---|
78 | MReadTree *MGEvtDisplay::GetReader() const
|
---|
79 | {
|
---|
80 | return (MReadTree*)GetTaskList()->FindObject("MReadTree");
|
---|
81 | }
|
---|
82 |
|
---|
83 | // --------------------------------------------------------------------------
|
---|
84 | //
|
---|
85 | // Add the top part of the frame: This is filename and treename display
|
---|
86 | //
|
---|
87 | void MGEvtDisplay::AddTopFramePart1(TGVerticalFrame *frame,
|
---|
88 | const char *filename,
|
---|
89 | const char *treename)
|
---|
90 | {
|
---|
91 | //
|
---|
92 | // --- the top1 part of the window ---
|
---|
93 | //
|
---|
94 | TGHorizontalFrame *top1 = new TGHorizontalFrame(frame, 300, 100);
|
---|
95 | fList->Add(top1);
|
---|
96 |
|
---|
97 | //
|
---|
98 | // create gui elements
|
---|
99 | //
|
---|
100 | TGLabel *lfile = new TGLabel(top1, new TGString("File:"));
|
---|
101 | TGLabel *file = new TGLabel(top1, new TGString(filename));
|
---|
102 | TGLabel *ltree = new TGLabel(top1, new TGString("Tree:"));
|
---|
103 | TGLabel *tree = new TGLabel(top1, new TGString(treename));
|
---|
104 |
|
---|
105 | fList->Add(lfile);
|
---|
106 | fList->Add(file);
|
---|
107 | fList->Add(ltree);
|
---|
108 | fList->Add(tree);
|
---|
109 |
|
---|
110 | //
|
---|
111 | // layout and add gui elements in/to frame
|
---|
112 | //
|
---|
113 | TGLayoutHints *laystd = new TGLayoutHints(kLHintsLeft, 10, 10, 10, 10);
|
---|
114 | fList->Add(laystd);
|
---|
115 |
|
---|
116 | top1->AddFrame(lfile, laystd);
|
---|
117 | top1->AddFrame(file, laystd);
|
---|
118 | top1->AddFrame(ltree, laystd);
|
---|
119 | top1->AddFrame(tree, laystd);
|
---|
120 |
|
---|
121 | //
|
---|
122 | // layout and add frame
|
---|
123 | //
|
---|
124 | TGLayoutHints *laytop1 = new TGLayoutHints(kLHintsTop);
|
---|
125 | fList->Add(laytop1);
|
---|
126 |
|
---|
127 | frame->AddFrame(top1, laytop1);
|
---|
128 | }
|
---|
129 |
|
---|
130 | // --------------------------------------------------------------------------
|
---|
131 | //
|
---|
132 | // Show the correct number of events
|
---|
133 | //
|
---|
134 | void MGEvtDisplay::UpdateNumOfEvts()
|
---|
135 | {
|
---|
136 | char txt[100];
|
---|
137 | sprintf(txt, "out of %d Events", GetReader()->GetEntries());
|
---|
138 |
|
---|
139 | fNumOfEvts->SetText(new TGString(txt));
|
---|
140 | }
|
---|
141 |
|
---|
142 | // --------------------------------------------------------------------------
|
---|
143 | //
|
---|
144 | // Add the second part of the top frame: This are the event number controls
|
---|
145 | //
|
---|
146 | void MGEvtDisplay::AddTopFramePart2(TGVerticalFrame *frame)
|
---|
147 | {
|
---|
148 | //
|
---|
149 | // --- the top2 part of the window ---
|
---|
150 | //
|
---|
151 | TGHorizontalFrame *top2 = new TGHorizontalFrame(frame, 300, 100);
|
---|
152 | fList->Add(top2);
|
---|
153 |
|
---|
154 | //
|
---|
155 | // Create the gui elements
|
---|
156 | //
|
---|
157 | TGTextButton *prevevt = new TGTextButton(top2, "<< Previous Event", M_PREVEVT);
|
---|
158 | prevevt->Associate(this);
|
---|
159 |
|
---|
160 | TGLabel *evtnr = new TGLabel(top2, new TGString("Event: "));
|
---|
161 |
|
---|
162 | fTxtEvtNr = new TGTextEntry(top2, new TGTextBuffer(100), M_EVTNUMBER);
|
---|
163 | fTxtEvtNr->Resize(60, fTxtEvtNr->GetDefaultHeight());
|
---|
164 | fTxtEvtNr->Associate(this);
|
---|
165 |
|
---|
166 | fNumOfEvts = new TGLabel(top2, "out of Events.");
|
---|
167 |
|
---|
168 | TGTextButton *nextevt = new TGTextButton (top2, "Next Event >>", M_NEXTEVT);
|
---|
169 | nextevt->Associate(this);
|
---|
170 |
|
---|
171 | //
|
---|
172 | // Add gui elements to 'atotodel'
|
---|
173 | //
|
---|
174 | fList->Add(prevevt);
|
---|
175 | fList->Add(evtnr);
|
---|
176 | fList->Add(fTxtEvtNr);
|
---|
177 | fList->Add(fNumOfEvts);
|
---|
178 | fList->Add(nextevt);
|
---|
179 |
|
---|
180 | //
|
---|
181 | // add the gui elements to the frame
|
---|
182 | //
|
---|
183 | TGLayoutHints *laystd = new TGLayoutHints(kLHintsLeft|kLHintsCenterY, 10, 10, 10, 10);
|
---|
184 |
|
---|
185 | fList->Add(laystd);
|
---|
186 |
|
---|
187 | top2->AddFrame(prevevt, laystd);
|
---|
188 | top2->AddFrame(evtnr, laystd);
|
---|
189 | top2->AddFrame(fTxtEvtNr, laystd);
|
---|
190 | top2->AddFrame(fNumOfEvts, laystd);
|
---|
191 | top2->AddFrame(nextevt, laystd);
|
---|
192 |
|
---|
193 | frame->AddFrame(top2, new TGLayoutHints(kLHintsCenterX));
|
---|
194 | }
|
---|
195 |
|
---|
196 | // --------------------------------------------------------------------------
|
---|
197 | //
|
---|
198 | // Add the mid frame: This are the two tabs with the canvas in the right one
|
---|
199 | //
|
---|
200 | void MGEvtDisplay::AddMidFrame(TGHorizontalFrame *frame)
|
---|
201 | {
|
---|
202 | //
|
---|
203 | // create tab control
|
---|
204 | //
|
---|
205 | TGTab *tabs = new TGTab(frame, 300, 300);
|
---|
206 |
|
---|
207 | //
|
---|
208 | // Create Tab1
|
---|
209 | //
|
---|
210 | fTab1 = tabs->AddTab("Setup");
|
---|
211 |
|
---|
212 | //
|
---|
213 | // Crete second gui elemet for tab1 (TGVertical Frame)
|
---|
214 | //
|
---|
215 | TGLayoutHints *laytabs = new TGLayoutHints(kLHintsNormal|kLHintsExpandY, 10, 10, 10, 10);
|
---|
216 | frame->AddFrame(tabs, laytabs);
|
---|
217 |
|
---|
218 | //
|
---|
219 | // Create second part of frame
|
---|
220 | //
|
---|
221 | TGTab *tabdisp = new TGTab(frame, 300, 300);
|
---|
222 |
|
---|
223 | TGCompositeFrame *tab2 = tabdisp->AddTab("Event Display");
|
---|
224 |
|
---|
225 | TRootEmbeddedCanvas *canvas = new TRootEmbeddedCanvas("EventDisplay", tab2, 400, 400);
|
---|
226 |
|
---|
227 | TGLayoutHints *laycanvas = new TGLayoutHints(kLHintsCenterX|kLHintsCenterY|kLHintsExpandX|kLHintsExpandY);
|
---|
228 | tab2->AddFrame(canvas, laycanvas);
|
---|
229 |
|
---|
230 | fCanvas = canvas->GetCanvas();
|
---|
231 |
|
---|
232 | //
|
---|
233 | // Add second part to frame
|
---|
234 | //
|
---|
235 | TGLayoutHints *laydisp = new TGLayoutHints(kLHintsNormal|kLHintsExpandY|kLHintsExpandX, 10, 10, 10, 10);
|
---|
236 | frame->AddFrame(tabdisp, laydisp);
|
---|
237 |
|
---|
238 | //
|
---|
239 | // Now add all gui elements to 'autodel'-list
|
---|
240 | //
|
---|
241 | fList->Add(tabdisp);
|
---|
242 | fList->Add(canvas);
|
---|
243 | fList->Add(laycanvas);
|
---|
244 | fList->Add(laydisp);
|
---|
245 | fList->Add(laytabs);
|
---|
246 | }
|
---|
247 |
|
---|
248 | // --------------------------------------------------------------------------
|
---|
249 | //
|
---|
250 | // Add the low frame: These are the buttons Print and Close
|
---|
251 | //
|
---|
252 | void MGEvtDisplay::AddLowFrame(TGHorizontalFrame *frame)
|
---|
253 | {
|
---|
254 | TGTextButton *but1 = new TGTextButton(frame, "Print", M_PRINT);
|
---|
255 | TGTextButton *but2 = new TGTextButton(frame, "Close", M_CLOSE);
|
---|
256 |
|
---|
257 | but1->Associate(this);
|
---|
258 | but2->Associate(this);
|
---|
259 |
|
---|
260 | fList->Add(but1);
|
---|
261 | fList->Add(but2);
|
---|
262 |
|
---|
263 | TGLayoutHints *laybut = new TGLayoutHints(kLHintsLeft, 10, 10, 10, 10);
|
---|
264 | fList->Add(laybut);
|
---|
265 |
|
---|
266 | frame->AddFrame(but1, laybut);
|
---|
267 | frame->AddFrame(but2, laybut);
|
---|
268 | }
|
---|
269 |
|
---|
270 | // --------------------------------------------------------------------------
|
---|
271 | //
|
---|
272 | // Create and setup all the three frames and build the window interieur
|
---|
273 | //
|
---|
274 | void MGEvtDisplay::AddFrames(const char *filename, const char *treename)
|
---|
275 | {
|
---|
276 | //
|
---|
277 | // Create the frame elements and add gui elements to it
|
---|
278 | //
|
---|
279 | TGVerticalFrame *frametop = new TGVerticalFrame(this, 300, 100);
|
---|
280 | fList->Add(frametop);
|
---|
281 |
|
---|
282 | AddTopFramePart1(frametop, filename, treename);
|
---|
283 | AddTopFramePart2(frametop);
|
---|
284 |
|
---|
285 | TGLayoutHints *laytop = new TGLayoutHints(kLHintsTop|kLHintsCenterX);
|
---|
286 | fList->Add(laytop);
|
---|
287 |
|
---|
288 | // -----
|
---|
289 |
|
---|
290 | TGHorizontalFrame *framemid = new TGHorizontalFrame(this, 300, 100);
|
---|
291 | fList->Add(framemid);
|
---|
292 |
|
---|
293 | AddMidFrame(framemid);
|
---|
294 |
|
---|
295 | TGLayoutHints *laymid = new TGLayoutHints(kLHintsExpandY|kLHintsExpandX);
|
---|
296 | fList->Add(laymid);
|
---|
297 |
|
---|
298 | //
|
---|
299 | // add frame elements to 'autodel'
|
---|
300 | //
|
---|
301 | TGHorizontal3DLine *line1 = new TGHorizontal3DLine(this);
|
---|
302 | TGHorizontal3DLine *line2 = new TGHorizontal3DLine(this);
|
---|
303 | fList->Add(line1);
|
---|
304 | fList->Add(line2);
|
---|
305 |
|
---|
306 | TGLayoutHints *layline = new TGLayoutHints(kLHintsTop|kLHintsExpandX);
|
---|
307 | fList->Add(layline);
|
---|
308 |
|
---|
309 | // -----
|
---|
310 | TGHorizontalFrame *framelow = new TGHorizontalFrame(this, 300, 100);
|
---|
311 | fList->Add(framelow);
|
---|
312 |
|
---|
313 | AddLowFrame(framelow);
|
---|
314 |
|
---|
315 | TGLayoutHints *laylow = new TGLayoutHints(kLHintsTop);
|
---|
316 | fList->Add(laylow);
|
---|
317 |
|
---|
318 | //
|
---|
319 | // Layout frame elements and add elements to frame
|
---|
320 | //
|
---|
321 | AddFrame(frametop, laytop);
|
---|
322 | AddFrame(line1, layline);
|
---|
323 | AddFrame(framemid, laymid);
|
---|
324 | AddFrame(line2, layline);
|
---|
325 | AddFrame(framelow, laylow);
|
---|
326 | }
|
---|
327 |
|
---|
328 | // --------------------------------------------------------------------------
|
---|
329 | //
|
---|
330 | // Constructor
|
---|
331 | //
|
---|
332 | MGEvtDisplay::MGEvtDisplay(const char *fname, const char *tname,
|
---|
333 | const TGWindow *p, const TGWindow *main,
|
---|
334 | UInt_t w, UInt_t h)
|
---|
335 | : TGTransientFrame(p, main, w, h), fInitOk(kFALSE)
|
---|
336 | {
|
---|
337 | //
|
---|
338 | // create an autodelete-list for the gui elements
|
---|
339 | //
|
---|
340 | fList = new TList;
|
---|
341 | fList->SetOwner();
|
---|
342 |
|
---|
343 | //
|
---|
344 | // Setup an empty job, with a reader task only.
|
---|
345 | // All tasks and parameter containers are deleted automatically
|
---|
346 | // (via SetOwner())
|
---|
347 | //
|
---|
348 |
|
---|
349 | MTaskList *tlist = new MTaskList;
|
---|
350 | tlist->SetOwner();
|
---|
351 |
|
---|
352 | MReadTree *read = new MReadTree(tname, fname);
|
---|
353 | tlist->AddToList(read);
|
---|
354 |
|
---|
355 | MParList *plist = new MParList();
|
---|
356 | plist->SetOwner();
|
---|
357 | plist->AddToList(tlist);
|
---|
358 |
|
---|
359 | fEvtLoop = new MEvtLoop;
|
---|
360 | fEvtLoop->SetOwner();
|
---|
361 | fEvtLoop->SetParList(plist);
|
---|
362 |
|
---|
363 | //
|
---|
364 | // Add all GUI elements and update the event counter
|
---|
365 | //
|
---|
366 | AddFrames(fname, tname);
|
---|
367 | UpdateEventCounter();
|
---|
368 | }
|
---|
369 |
|
---|
370 |
|
---|
371 | // --------------------------------------------------------------------------
|
---|
372 | //
|
---|
373 | // Destructs the graphical members and the eventloop members
|
---|
374 | //
|
---|
375 | MGEvtDisplay::~MGEvtDisplay()
|
---|
376 | {
|
---|
377 | delete fList;
|
---|
378 |
|
---|
379 | fEvtLoop->PostProcess();
|
---|
380 | delete fEvtLoop;
|
---|
381 | }
|
---|
382 |
|
---|
383 | // --------------------------------------------------------------------------
|
---|
384 | //
|
---|
385 | // The close message is generated by the window manager when its close
|
---|
386 | // window menu item is selected.
|
---|
387 | //
|
---|
388 | void MGEvtDisplay::CloseWindow()
|
---|
389 | {
|
---|
390 | delete this;
|
---|
391 | }
|
---|
392 |
|
---|
393 | // --------------------------------------------------------------------------
|
---|
394 | //
|
---|
395 | // Checks if the event number is valid, and if so reads the new event
|
---|
396 | // and updates the display
|
---|
397 | //
|
---|
398 | void MGEvtDisplay::ReadinEvent(UInt_t iEvt)
|
---|
399 | {
|
---|
400 | if (!fInitOk)
|
---|
401 | return;
|
---|
402 |
|
---|
403 | Int_t buttons = 4;
|
---|
404 | Int_t retval = 0;
|
---|
405 |
|
---|
406 | // first check if the new event is in the range of possible events
|
---|
407 |
|
---|
408 | if (iEvt >= GetReader()->GetEntries())
|
---|
409 | {
|
---|
410 | new TGMsgBox(gClient->GetRoot(), this,
|
---|
411 | "WARNING!",
|
---|
412 | "The event number is out of range!!!",
|
---|
413 | kMBIconExclamation, buttons, &retval);
|
---|
414 | }
|
---|
415 | else
|
---|
416 | {
|
---|
417 | GetReader()->SetEventNum(iEvt);
|
---|
418 |
|
---|
419 | if (GetTaskList()->Process())
|
---|
420 | UpdateDisplay();
|
---|
421 | }
|
---|
422 |
|
---|
423 | UpdateEventCounter();
|
---|
424 | }
|
---|
425 |
|
---|
426 | // --------------------------------------------------------------------------
|
---|
427 | //
|
---|
428 | // Update the event counter
|
---|
429 | //
|
---|
430 | void MGEvtDisplay::UpdateEventCounter()
|
---|
431 | {
|
---|
432 | char txt[256];
|
---|
433 |
|
---|
434 | sprintf(txt, "%d", GetReader()->GetEventNum());
|
---|
435 |
|
---|
436 | fTxtEvtNr->SetText(txt);
|
---|
437 | }
|
---|
438 |
|
---|
439 | // --------------------------------------------------------------------------
|
---|
440 | //
|
---|
441 | // ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
|
---|
442 | //
|
---|
443 | // Processes information from all GUI items.
|
---|
444 | // Selecting an item usually generates an event with 4 parameters.
|
---|
445 | // The first two are packed into msg (first and second bytes).
|
---|
446 | // The other two are parm1 and parm2.
|
---|
447 | //
|
---|
448 | Bool_t MGEvtDisplay::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
|
---|
449 | {
|
---|
450 | switch(GET_MSG(msg))
|
---|
451 | {
|
---|
452 | case kC_COMMAND:
|
---|
453 | switch(GET_SUBMSG(msg))
|
---|
454 | {
|
---|
455 | case kCM_BUTTON:
|
---|
456 | switch (parm1)
|
---|
457 | {
|
---|
458 | case M_PREVEVT:
|
---|
459 | //
|
---|
460 | // '-2' is because MReadTree::Process increases the
|
---|
461 | // Event number by one - this is the natural behaviour
|
---|
462 | // after reading one event
|
---|
463 | //
|
---|
464 | ReadinEvent(GetReader()->GetEventNum()-2);
|
---|
465 | return kTRUE;
|
---|
466 |
|
---|
467 | case M_NEXTEVT:
|
---|
468 | //
|
---|
469 | // '+0' is because MReadTree::Process increases the
|
---|
470 | // Event number by one - this is the natural behaviour
|
---|
471 | // after reading one event
|
---|
472 | //
|
---|
473 | ReadinEvent(GetReader()->GetEventNum());
|
---|
474 | return kTRUE;
|
---|
475 |
|
---|
476 | case M_CLOSE:
|
---|
477 | CloseWindow();
|
---|
478 | return kTRUE;
|
---|
479 | }
|
---|
480 | return kTRUE;
|
---|
481 | }
|
---|
482 | return kTRUE;
|
---|
483 |
|
---|
484 | case kC_TEXTENTRY:
|
---|
485 | if (GET_SUBMSG(msg) == kTE_ENTER)
|
---|
486 | ReadinEvent(atoi(fTxtEvtNr->GetText())-1);
|
---|
487 | return kTRUE;
|
---|
488 | }
|
---|
489 |
|
---|
490 | return kTRUE;
|
---|
491 | }
|
---|