source: tags/Mars-V0.5/meventdisp/MGEvtDisplay.cc

Last change on this file was 1030, checked in by tbretz, 23 years ago
*** empty log message ***
File size: 15.7 KB
Line 
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 <TGMenu.h> // TGPopupMenu
31#include <TCanvas.h> // TCanvas::Print
32#include <TGLabel.h> // TGLabel
33#include <TGButton.h> // TGPictureButton
34#include <TGMsgBox.h> // TGMsgBox
35#include <TGTextEntry.h> // TGTextEntry
36#include <TGFileDialog.h> // TGFileDialog
37#include <TRootEmbeddedCanvas.h> // TRootEmbeddedCanvas
38
39#include <TG3DLine.h> // TGHorizontal3DLine
40 // use TGSplitter instead for root<3.00
41
42#include "MParList.h"
43#include "MTaskList.h"
44#include "MEvtLoop.h"
45#include "MReadTree.h"
46
47ClassImp(MGEvtDisplay);
48
49enum MGCamDisplayCommand
50{
51 kEvtPrev,
52 kEvtNext,
53 kEvtNumber,
54
55 kFileSaveAs,
56 kFileSaveAsRoot,
57 kFileSaveAsC,
58 kFileSaveAsPS,
59 kFileSaveAsEPS,
60 kFileSaveAsGIF,
61 kFilePrint,
62 kClose
63};
64
65// --------------------------------------------------------------------------
66//
67// Return a pointer to the parameter list.
68//
69MParList *MGEvtDisplay::GetParList() const
70{
71 return fEvtLoop->GetParList();
72}
73
74// --------------------------------------------------------------------------
75//
76// Return a pointer to the task list.
77//
78MTaskList *MGEvtDisplay::GetTaskList() const
79{
80 return (MTaskList*)GetParList()->FindObject("MTaskList");
81}
82
83// --------------------------------------------------------------------------
84//
85// Return a pointer to the reader task (MReadTree)
86//
87MReadTree *MGEvtDisplay::GetReader() const
88{
89 return (MReadTree*)GetTaskList()->FindObject("MReadTree");
90}
91
92// --------------------------------------------------------------------------
93//
94// Add the top part of the frame: This is filename and treename display
95//
96void MGEvtDisplay::AddTopFramePart1(TGVerticalFrame *frame,
97 const char *filename,
98 const char *treename)
99{
100 //
101 // --- the top1 part of the window ---
102 //
103 TGHorizontalFrame *top1 = new TGHorizontalFrame(frame, 300, 100);
104 fList->Add(top1);
105
106 //
107 // create gui elements
108 //
109 TGLabel *lfile = new TGLabel(top1, new TGString("File:"));
110 TGLabel *file = new TGLabel(top1, new TGString(filename));
111 TGLabel *ltree = new TGLabel(top1, new TGString("Tree:"));
112 TGLabel *tree = new TGLabel(top1, new TGString(treename));
113
114 fList->Add(lfile);
115 fList->Add(file);
116 fList->Add(ltree);
117 fList->Add(tree);
118
119 //
120 // layout and add gui elements in/to frame
121 //
122 TGLayoutHints *laystd = new TGLayoutHints(kLHintsLeft, 10, 10, 10, 10);
123 fList->Add(laystd);
124
125 top1->AddFrame(lfile, laystd);
126 top1->AddFrame(file, laystd);
127 top1->AddFrame(ltree, laystd);
128 top1->AddFrame(tree, laystd);
129
130 //
131 // layout and add frame
132 //
133 TGLayoutHints *laytop1 = new TGLayoutHints(kLHintsTop);
134 fList->Add(laytop1);
135
136 frame->AddFrame(top1, laytop1);
137}
138
139// --------------------------------------------------------------------------
140//
141// Add the second part of the top frame: This are the event number controls
142//
143void MGEvtDisplay::AddTopFramePart2(TGVerticalFrame *frame)
144{
145 //
146 // --- the top2 part of the window ---
147 //
148 TGHorizontalFrame *top2 = new TGHorizontalFrame(frame, 300, 100);
149 fList->Add(top2);
150
151 //
152 // Create the gui elements
153 //
154 TGTextButton *prevevt = new TGTextButton(top2, "<< Previous Event", kEvtPrev);
155 prevevt->Associate(this);
156
157 TGLabel *evtnr = new TGLabel(top2, new TGString("Event: "));
158
159 fTxtEvtNr = new TGTextEntry(top2, new TGTextBuffer(100), kEvtNumber);
160 fTxtEvtNr->Resize(60, fTxtEvtNr->GetDefaultHeight());
161 fTxtEvtNr->Associate(this);
162
163 fNumOfEvts = new TGLabel(top2, "out of Events.");
164
165 TGTextButton *nextevt = new TGTextButton (top2, "Next Event >>", kEvtNext);
166 nextevt->Associate(this);
167
168 //
169 // Add gui elements to 'atotodel'
170 //
171 fList->Add(prevevt);
172 fList->Add(evtnr);
173 fList->Add(fTxtEvtNr);
174 fList->Add(fNumOfEvts);
175 fList->Add(nextevt);
176
177 //
178 // add the gui elements to the frame
179 //
180 TGLayoutHints *laystd = new TGLayoutHints(kLHintsLeft|kLHintsCenterY, 10, 10, 10, 10);
181
182 fList->Add(laystd);
183
184 top2->AddFrame(prevevt, laystd);
185 top2->AddFrame(evtnr, laystd);
186 top2->AddFrame(fTxtEvtNr, laystd);
187 top2->AddFrame(fNumOfEvts, laystd);
188 top2->AddFrame(nextevt, laystd);
189
190 frame->AddFrame(top2, new TGLayoutHints(kLHintsCenterX));
191}
192
193// --------------------------------------------------------------------------
194//
195// Add the mid frame: This are the two tabs with the canvas in the right one
196//
197void MGEvtDisplay::AddMidFrame(TGHorizontalFrame *frame)
198{
199 //
200 // create tab control
201 //
202 TGTab *tabs = new TGTab(frame, 300, 300);
203
204 //
205 // Create Tab1
206 //
207 fTab1 = tabs->AddTab("Setup");
208
209 //
210 // Crete second gui elemet for tab1 (TGVertical Frame)
211 //
212 TGLayoutHints *laytabs = new TGLayoutHints(kLHintsNormal|kLHintsExpandY, 10, 10, 10, 10);
213 frame->AddFrame(tabs, laytabs);
214
215 //
216 // Create second part of frame
217 //
218 TGTab *tabdisp = new TGTab(frame, 300, 300);
219
220 TGCompositeFrame *tab2 = tabdisp->AddTab("Event Display");
221
222 TRootEmbeddedCanvas *canvas = new TRootEmbeddedCanvas("EventDisplay", tab2, 400, 400);
223
224 TGLayoutHints *laycanvas = new TGLayoutHints(kLHintsCenterX|kLHintsCenterY|kLHintsExpandX|kLHintsExpandY);
225 tab2->AddFrame(canvas, laycanvas);
226
227 fCanvas = canvas->GetCanvas();
228
229 //
230 // Add second part to frame
231 //
232 TGLayoutHints *laydisp = new TGLayoutHints(kLHintsNormal|kLHintsExpandY|kLHintsExpandX, 10, 10, 10, 10);
233 frame->AddFrame(tabdisp, laydisp);
234
235 //
236 // Now add all gui elements to 'autodel'-list
237 //
238 fList->Add(tabdisp);
239 fList->Add(canvas);
240 fList->Add(laycanvas);
241 fList->Add(laydisp);
242 fList->Add(laytabs);
243}
244
245// --------------------------------------------------------------------------
246//
247// Add the low frame: These are the buttons Print and Close
248//
249void MGEvtDisplay::AddLowFrame(TGHorizontalFrame *frame)
250{
251 TGTextButton *but = new TGTextButton(frame, "Close", kClose);
252
253 but->Associate(this);
254
255 fList->Add(but);
256
257 TGLayoutHints *laybut = new TGLayoutHints(kLHintsLeft, 10, 10, 10, 10);
258 fList->Add(laybut);
259
260 frame->AddFrame(but, laybut);
261}
262
263// --------------------------------------------------------------------------
264//
265// Create and setup all the three frames and build the window interieur
266//
267void MGEvtDisplay::AddFrames(const char *filename, const char *treename)
268{
269 //
270 // Create the frame elements and add gui elements to it
271 //
272 TGVerticalFrame *frametop = new TGVerticalFrame(this, 300, 100);
273 fList->Add(frametop);
274
275 AddTopFramePart1(frametop, filename, treename);
276 AddTopFramePart2(frametop);
277
278 TGLayoutHints *laytop = new TGLayoutHints(kLHintsTop|kLHintsCenterX);
279 fList->Add(laytop);
280
281 // -----
282
283 TGHorizontalFrame *framemid = new TGHorizontalFrame(this, 300, 100);
284 fList->Add(framemid);
285
286 AddMidFrame(framemid);
287
288 TGLayoutHints *laymid = new TGLayoutHints(kLHintsExpandY|kLHintsExpandX);
289 fList->Add(laymid);
290
291 //
292 // add frame elements to 'autodel'
293 //
294 TGHorizontal3DLine *line1 = new TGHorizontal3DLine(this);
295 TGHorizontal3DLine *line2 = new TGHorizontal3DLine(this);
296 fList->Add(line1);
297 fList->Add(line2);
298
299 TGLayoutHints *layline = new TGLayoutHints(kLHintsTop|kLHintsExpandX);
300 fList->Add(layline);
301
302 // -----
303 TGHorizontalFrame *framelow = new TGHorizontalFrame(this, 300, 100);
304 fList->Add(framelow);
305
306 AddLowFrame(framelow);
307
308 TGLayoutHints *laylow = new TGLayoutHints(kLHintsTop);
309 fList->Add(laylow);
310
311 //
312 // Layout frame elements and add elements to frame
313 //
314 AddFrame(frametop, laytop);
315 AddFrame(line1, layline);
316 AddFrame(framemid, laymid);
317 AddFrame(line2, layline);
318 AddFrame(framelow, laylow);
319}
320
321// --------------------------------------------------------------------------
322//
323// Constructor
324//
325void MGEvtDisplay::AddMenuBar()
326{
327 //
328 // Add all GUI elements and update the event counter
329 //
330 TGLayoutHints *laymenubar = new TGLayoutHints(kLHintsTop|kLHintsLeft|kLHintsExpandX, 2, 2, 2, 2);
331 TGLayoutHints *laymenuitem = new TGLayoutHints(kLHintsTop|kLHintsLeft, 0, 4, 0, 0);
332 TGLayoutHints *laylinesep = new TGLayoutHints(kLHintsTop|kLHintsExpandX);
333
334 fList->Add(laymenubar);
335 fList->Add(laymenuitem);
336 fList->Add(laylinesep);
337
338 TGPopupMenu *filemenu = new TGPopupMenu(gClient->GetRoot());
339 filemenu->AddEntry("Save &As...", kFileSaveAs);
340 filemenu->AddEntry("Save As display.&ps", kFileSaveAsPS);
341 filemenu->AddEntry("Save As display.&eps", kFileSaveAsEPS);
342 filemenu->AddEntry("Save As display.&gif", kFileSaveAsGIF);
343 filemenu->AddEntry("Save As display.&C", kFileSaveAsC);
344 filemenu->AddEntry("Save As display.&root", kFileSaveAsRoot);
345 filemenu->AddSeparator();
346 filemenu->AddEntry("&Print...", kFilePrint);
347 filemenu->AddSeparator();
348 filemenu->AddEntry("E&xit", kClose);
349 filemenu->Associate(this);
350
351 TGMenuBar *menubar = new TGMenuBar(this, 1, 1, kHorizontalFrame);
352 menubar->AddPopup("File", filemenu, laymenuitem);
353 AddFrame(menubar, laymenubar);
354
355 TGHorizontal3DLine *linesep = new TGHorizontal3DLine(this);
356 AddFrame(linesep, laylinesep);
357
358 fList->Add(filemenu);
359 fList->Add(menubar);
360 fList->Add(linesep);
361}
362
363MGEvtDisplay::MGEvtDisplay(const char *fname, const char *tname,
364 const TGWindow *p, const TGWindow *main,
365 UInt_t w, UInt_t h)
366 : TGTransientFrame(p, main, w, h), fInitOk(kFALSE)
367{
368 //
369 // create an autodelete-list for the gui elements
370 //
371 fList = new TList;
372 fList->SetOwner();
373
374 //
375 // Setup an empty job, with a reader task only.
376 // All tasks and parameter containers are deleted automatically
377 // (via SetOwner())
378 //
379 MTaskList *tlist = new MTaskList;
380 tlist->SetOwner();
381
382 MReadTree *read = new MReadTree(tname, fname);
383 tlist->AddToList(read);
384
385 MParList *plist = new MParList;
386 plist->SetOwner();
387 plist->AddToList(tlist);
388
389 fEvtLoop = new MEvtLoop;
390 fEvtLoop->SetOwner();
391 fEvtLoop->SetParList(plist);
392
393 AddMenuBar();
394 AddFrames(fname, tname);
395}
396
397// --------------------------------------------------------------------------
398//
399// Destructs the graphical members and the eventloop members
400//
401MGEvtDisplay::~MGEvtDisplay()
402{
403 fEvtLoop->PostProcess();
404 delete fEvtLoop;
405
406 delete fList;
407}
408
409// --------------------------------------------------------------------------
410//
411// The close message is generated by the window manager when its close
412// window menu item is selected.
413//
414void MGEvtDisplay::CloseWindow()
415{
416 delete this;
417}
418
419// --------------------------------------------------------------------------
420//
421// Checks if the event number is valid, and if so reads the new event
422// and updates the display
423//
424void MGEvtDisplay::ReadinEvent()
425{
426 if (GetTaskList()->Process())
427 {
428 GetReader()->DecEventNum();
429 UpdateDisplay();
430 }
431
432 fTxtEvtNr->SetText(Form("%d", GetReader()->GetEventNum()+1));
433}
434
435void MGEvtDisplay::ReadFirstEvent()
436{
437 fInitOk = fEvtLoop->PreProcess();
438
439 if (fInitOk)
440 ReadinEvent();
441
442 TGString *txt = new TGString(Form("out of %d Events", GetReader()->GetEntries()));
443 fNumOfEvts->SetText(txt);
444}
445
446// --------------------------------------------------------------------------
447//
448// Opens a save as dialog, and tries to store the canvas
449// in the given output format
450//
451void MGEvtDisplay::SaveAsDialog() const
452{
453 static const char *gSaveAsTypes[] =
454 {
455 "PostScript", "*.ps",
456 "Encapsulated PostScript", "*.eps",
457 "Gif files", "*.gif",
458 "Macro files", "*.C",
459 "ROOT files", "*.root",
460 "All files", "*",
461 NULL, NULL
462 };
463
464 static TString dir(".");
465
466 TGFileInfo fi;
467
468 fi.fFileTypes = gSaveAsTypes;
469 fi.fIniDir = StrDup(dir);
470
471 new TGFileDialog(fClient->GetRoot(), this, kFDSave, &fi);
472
473 if (!fi.fFilename)
474 return;
475
476 dir = fi.fIniDir;
477
478 if (strstr(fi.fFilename, ".root") ||
479 strstr(fi.fFilename, ".ps") ||
480 strstr(fi.fFilename, ".eps") ||
481 strstr(fi.fFilename, ".gif"))
482 {
483 fCanvas->SaveAs(fi.fFilename);
484 return;
485 }
486 if (strstr(fi.fFilename, ".C"))
487 {
488 fCanvas->SaveSource(fi.fFilename);
489 return;
490 }
491 Warning("SaveAsDialog", "Unknown Extension: %s", fi.fFilename);
492}
493
494// --------------------------------------------------------------------------
495//
496// ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
497//
498// Processes information from all GUI items.
499// Selecting an item usually generates an event with 4 parameters.
500// The first two are packed into msg (first and second bytes).
501// The other two are parm1 and parm2.
502//
503Bool_t MGEvtDisplay::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
504{
505 if (GET_MSG(msg)!=kC_TEXTENTRY && GET_MSG(msg)!=kC_COMMAND)
506 return kTRUE;
507
508 switch(GET_SUBMSG(msg))
509 {
510 case kTE_ENTER:
511 case kCM_BUTTON:
512 if (parm1==kClose)
513 {
514 CloseWindow();
515 return kTRUE;
516 }
517
518 if (!fInitOk)
519 return kTRUE;
520
521 switch(GET_SUBMSG(msg))
522 {
523 case kTE_ENTER:
524 if (GetReader()->SetEventNum(atoi(fTxtEvtNr->GetText())-1))
525 ReadinEvent();
526 return kTRUE;
527
528 case kCM_BUTTON:
529 switch (parm1)
530 {
531 case kEvtPrev:
532 if (GetReader()->DecEventNum())
533 ReadinEvent();
534 return kTRUE;
535
536 case kEvtNext:
537 if (GetReader()->IncEventNum())
538 ReadinEvent();
539 return kTRUE;
540 }
541 return kTRUE;
542 }
543 return kTRUE;
544
545 case kCM_MENU:
546 switch (parm1)
547 {
548 case kFileSaveAs:
549 SaveAsDialog();
550 return kTRUE;
551 case kFileSaveAsRoot:
552 fCanvas->SaveAs("display.root");
553 return kTRUE;
554 case kFileSaveAsC:
555 // FIXME: The line opening the canvas is wrong.
556 fCanvas->SaveSource("display.C");
557 return kTRUE;
558 case kFileSaveAsPS:
559 fCanvas->SaveAs("display.ps");
560 return kTRUE;
561 case kFileSaveAsEPS:
562 fCanvas->SaveAs("display.eps");
563 return kTRUE;
564 case kFileSaveAsGIF:
565 fCanvas->SaveAs("display.gif");
566 return kTRUE;
567 case kFilePrint:
568 fCanvas->Print();
569 return kTRUE;
570 case kClose:
571 CloseWindow();
572 return kTRUE;
573 }
574 return kTRUE;
575 }
576 return kTRUE;
577}
Note: See TracBrowser for help on using the repository browser.