source: trunk/MagicSoft/Mars/meventdisp/MGEvtDisplay.cc@ 1521

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