| 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-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 "MReadMarsFile.h"
|
|---|
| 46 |
|
|---|
| 47 | ClassImp(MGEvtDisplay);
|
|---|
| 48 |
|
|---|
| 49 | enum 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 | //
|
|---|
| 69 | MParList *MGEvtDisplay::GetParList() const
|
|---|
| 70 | {
|
|---|
| 71 | return fEvtLoop->GetParList();
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 | // --------------------------------------------------------------------------
|
|---|
| 75 | //
|
|---|
| 76 | // Return a pointer to the task list.
|
|---|
| 77 | //
|
|---|
| 78 | MTaskList *MGEvtDisplay::GetTaskList() const
|
|---|
| 79 | {
|
|---|
| 80 | return (MTaskList*)GetParList()->FindObject("MTaskList");
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | // --------------------------------------------------------------------------
|
|---|
| 84 | //
|
|---|
| 85 | // Return a pointer to the reader task (MReadTree)
|
|---|
| 86 | //
|
|---|
| 87 | MReadTree *MGEvtDisplay::GetReader() const
|
|---|
| 88 | {
|
|---|
| 89 | return (MReadTree*)GetTaskList()->FindObject("MReadMarsFile");
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 | // --------------------------------------------------------------------------
|
|---|
| 93 | //
|
|---|
| 94 | // Add the top part of the frame: This is filename and treename display
|
|---|
| 95 | //
|
|---|
| 96 | void 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 | //
|
|---|
| 143 | void 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 | //
|
|---|
| 197 | void 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 | //
|
|---|
| 249 | void 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 | //
|
|---|
| 267 | void 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 | //
|
|---|
| 325 | void 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.p&s", 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 |
|
|---|
| 363 | MGEvtDisplay::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 | MReadMarsFile *read = new MReadMarsFile(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 | SetWMSizeHints(450, 400, 1000, 1000, 10, 10);
|
|---|
| 397 | Move(rand()%100+50, rand()%100+50);
|
|---|
| 398 | }
|
|---|
| 399 |
|
|---|
| 400 | // --------------------------------------------------------------------------
|
|---|
| 401 | //
|
|---|
| 402 | // Destructs the graphical members and the eventloop members
|
|---|
| 403 | //
|
|---|
| 404 | MGEvtDisplay::~MGEvtDisplay()
|
|---|
| 405 | {
|
|---|
| 406 | fEvtLoop->PostProcess();
|
|---|
| 407 | delete fEvtLoop;
|
|---|
| 408 |
|
|---|
| 409 | delete fList;
|
|---|
| 410 | }
|
|---|
| 411 |
|
|---|
| 412 | // --------------------------------------------------------------------------
|
|---|
| 413 | //
|
|---|
| 414 | // The close message is generated by the window manager when its close
|
|---|
| 415 | // window menu item is selected.
|
|---|
| 416 | //
|
|---|
| 417 | void MGEvtDisplay::CloseWindow()
|
|---|
| 418 | {
|
|---|
| 419 | delete this;
|
|---|
| 420 | }
|
|---|
| 421 |
|
|---|
| 422 | // --------------------------------------------------------------------------
|
|---|
| 423 | //
|
|---|
| 424 | // Checks if the event number is valid, and if so reads the new event
|
|---|
| 425 | // and updates the display
|
|---|
| 426 | //
|
|---|
| 427 | void MGEvtDisplay::ReadinEvent()
|
|---|
| 428 | {
|
|---|
| 429 | if (GetTaskList()->Process())
|
|---|
| 430 | {
|
|---|
| 431 | GetReader()->DecEventNum();
|
|---|
| 432 | UpdateDisplay();
|
|---|
| 433 | }
|
|---|
| 434 |
|
|---|
| 435 | fTxtEvtNr->SetText(Form("%d", GetReader()->GetEventNum()+1));
|
|---|
| 436 | }
|
|---|
| 437 |
|
|---|
| 438 | void MGEvtDisplay::ReadFirstEvent()
|
|---|
| 439 | {
|
|---|
| 440 | fInitOk = fEvtLoop->PreProcess();
|
|---|
| 441 |
|
|---|
| 442 | if (fInitOk)
|
|---|
| 443 | ReadinEvent();
|
|---|
| 444 |
|
|---|
| 445 | TGString *txt = new TGString(Form("out of %d Events", GetReader()->GetEntries()));
|
|---|
| 446 | fNumOfEvts->SetText(txt);
|
|---|
| 447 | }
|
|---|
| 448 |
|
|---|
| 449 | // --------------------------------------------------------------------------
|
|---|
| 450 | //
|
|---|
| 451 | // Opens a save as dialog, and tries to store the canvas
|
|---|
| 452 | // in the given output format
|
|---|
| 453 | //
|
|---|
| 454 | void MGEvtDisplay::SaveAsDialog() const
|
|---|
| 455 | {
|
|---|
| 456 | static const char *gSaveAsTypes[] =
|
|---|
| 457 | {
|
|---|
| 458 | "PostScript", "*.ps",
|
|---|
| 459 | "Encapsulated PostScript", "*.eps",
|
|---|
| 460 | "Gif files", "*.gif",
|
|---|
| 461 | "Macro files", "*.C",
|
|---|
| 462 | "ROOT files", "*.root",
|
|---|
| 463 | "All files", "*",
|
|---|
| 464 | NULL, NULL
|
|---|
| 465 | };
|
|---|
| 466 |
|
|---|
| 467 | static TString dir(".");
|
|---|
| 468 |
|
|---|
| 469 | TGFileInfo fi; // fFileName and fIniDir deleted in ~TGFileInfo
|
|---|
| 470 |
|
|---|
| 471 | fi.fFileTypes = gSaveAsTypes;
|
|---|
| 472 | fi.fIniDir = StrDup(dir);
|
|---|
| 473 |
|
|---|
| 474 | new TGFileDialog(fClient->GetRoot(), this, kFDSave, &fi);
|
|---|
| 475 |
|
|---|
| 476 | if (!fi.fFilename)
|
|---|
| 477 | return;
|
|---|
| 478 |
|
|---|
| 479 | dir = fi.fIniDir;
|
|---|
| 480 |
|
|---|
| 481 | if (strstr(fi.fFilename, ".root") ||
|
|---|
| 482 | strstr(fi.fFilename, ".ps") ||
|
|---|
| 483 | strstr(fi.fFilename, ".eps") ||
|
|---|
| 484 | strstr(fi.fFilename, ".gif"))
|
|---|
| 485 | {
|
|---|
| 486 | fCanvas->SaveAs(fi.fFilename);
|
|---|
| 487 | return;
|
|---|
| 488 | }
|
|---|
| 489 | if (strstr(fi.fFilename, ".C"))
|
|---|
| 490 | {
|
|---|
| 491 | fCanvas->SaveSource(fi.fFilename);
|
|---|
| 492 | return;
|
|---|
| 493 | }
|
|---|
| 494 | Warning("SaveAsDialog", "Unknown Extension: %s", fi.fFilename);
|
|---|
| 495 | }
|
|---|
| 496 |
|
|---|
| 497 | // --------------------------------------------------------------------------
|
|---|
| 498 | //
|
|---|
| 499 | // ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
|
|---|
| 500 | //
|
|---|
| 501 | // Processes information from all GUI items.
|
|---|
| 502 | // Selecting an item usually generates an event with 4 parameters.
|
|---|
| 503 | // The first two are packed into msg (first and second bytes).
|
|---|
| 504 | // The other two are parm1 and parm2.
|
|---|
| 505 | //
|
|---|
| 506 | Bool_t MGEvtDisplay::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
|
|---|
| 507 | {
|
|---|
| 508 | if (GET_MSG(msg)!=kC_TEXTENTRY && GET_MSG(msg)!=kC_COMMAND)
|
|---|
| 509 | return kTRUE;
|
|---|
| 510 |
|
|---|
| 511 | switch(GET_SUBMSG(msg))
|
|---|
| 512 | {
|
|---|
| 513 | case kTE_ENTER:
|
|---|
| 514 | case kCM_BUTTON:
|
|---|
| 515 | if (parm1==kClose)
|
|---|
| 516 | {
|
|---|
| 517 | CloseWindow();
|
|---|
| 518 | return kTRUE;
|
|---|
| 519 | }
|
|---|
| 520 |
|
|---|
| 521 | if (!fInitOk)
|
|---|
| 522 | return kTRUE;
|
|---|
| 523 |
|
|---|
| 524 | switch(GET_SUBMSG(msg))
|
|---|
| 525 | {
|
|---|
| 526 | case kTE_ENTER:
|
|---|
| 527 | if (GetReader()->SetEventNum(atoi(fTxtEvtNr->GetText())-1))
|
|---|
| 528 | ReadinEvent();
|
|---|
| 529 | return kTRUE;
|
|---|
| 530 |
|
|---|
| 531 | case kCM_BUTTON:
|
|---|
| 532 | switch (parm1)
|
|---|
| 533 | {
|
|---|
| 534 | case kEvtPrev:
|
|---|
| 535 | if (GetReader()->DecEventNum())
|
|---|
| 536 | ReadinEvent();
|
|---|
| 537 | return kTRUE;
|
|---|
| 538 |
|
|---|
| 539 | case kEvtNext:
|
|---|
| 540 | if (GetReader()->IncEventNum())
|
|---|
| 541 | ReadinEvent();
|
|---|
| 542 | return kTRUE;
|
|---|
| 543 | }
|
|---|
| 544 | return kTRUE;
|
|---|
| 545 | }
|
|---|
| 546 | return kTRUE;
|
|---|
| 547 |
|
|---|
| 548 | case kCM_MENU:
|
|---|
| 549 | switch (parm1)
|
|---|
| 550 | {
|
|---|
| 551 | case kFileSaveAs:
|
|---|
| 552 | SaveAsDialog();
|
|---|
| 553 | return kTRUE;
|
|---|
| 554 | case kFileSaveAsRoot:
|
|---|
| 555 | fCanvas->SaveAs("display.root");
|
|---|
| 556 | return kTRUE;
|
|---|
| 557 | case kFileSaveAsC:
|
|---|
| 558 | // FIXME: The line opening the canvas is wrong.
|
|---|
| 559 | fCanvas->SaveSource("display.C");
|
|---|
| 560 | return kTRUE;
|
|---|
| 561 | case kFileSaveAsPS:
|
|---|
| 562 | fCanvas->SaveAs("display.ps");
|
|---|
| 563 | return kTRUE;
|
|---|
| 564 | case kFileSaveAsEPS:
|
|---|
| 565 | fCanvas->SaveAs("display.eps");
|
|---|
| 566 | return kTRUE;
|
|---|
| 567 | case kFileSaveAsGIF:
|
|---|
| 568 | fCanvas->SaveAs("display.gif");
|
|---|
| 569 | return kTRUE;
|
|---|
| 570 | case kFilePrint:
|
|---|
| 571 | fCanvas->Print();
|
|---|
| 572 | return kTRUE;
|
|---|
| 573 | case kClose:
|
|---|
| 574 | CloseWindow();
|
|---|
| 575 | return kTRUE;
|
|---|
| 576 | }
|
|---|
| 577 | return kTRUE;
|
|---|
| 578 | }
|
|---|
| 579 | return kTRUE;
|
|---|
| 580 | }
|
|---|