source: trunk/Mars/mbase/MStatusDisplay.cc@ 9853

Last change on this file since 9853 was 9598, checked in by tbretz, 14 years ago
*** empty log message ***
File size: 99.0 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, 4/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2003-2008
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MStatusDisplay
28//
29// This status display can be used (and is used) to display results in
30// a tabbed window. The window can be written to and read from a root file
31// (see Read and Write) or printed as a postscript file (see SaveAsPS).
32//
33// To write gif files of C-Macros use SaveAsGif()/SaveAsPNG() or SaveAsC().
34// Direct printing to the default printer (via lpr) can be done by
35// PrintPS().
36//
37// It has also to half status lines which can be used to display the status
38// or something going on. Together with the status lines it has a progress
39// bar which can display the progress of a job or loop.
40// Access the progress bar by GetProgressBar()
41//
42// To add a new tab and get a pointer to the newly created TCanvas
43// use AddTab.
44//
45// If you have a MStatusDisplay and you are not sure whether it was
46// destroyed by the user meanwhile use:
47// gROOT->GetListOfSpecials()->FindObject(pointer);
48// Each MStatusDisplay is added to list list by its constructor and
49// removed from the list by the destructor.
50//
51// You can redirect an output to a MLog-logstream by calling SetLogStream().
52// To disable redirction call SetLogStream(NULL)
53//
54// Because updates to the tabs are only done/displayed if a tab is active
55// using the gui doesn't make things slower (<1%) if the first (legend
56// tab) is displayed. This gives you the possibility to look into
57// the current progress of a loop without loosing more time than the
58// single update of the tab.
59//
60/////////////////////////////////////////////////////////////////////////////
61#include "MStatusDisplay.h"
62
63#include <errno.h>
64#include <stdlib.h> // mktemp (Ubunto 8.10)
65
66#include <fstream> // fstream
67
68#include <TH1.h> // TH1::AddDirectory
69#include <TPDF.h> // TPDF
70#include <TSVG.h> // TSVG
71#include <TEnv.h> // TEnv
72#include <TLine.h> // TLine
73#include <TMath.h>
74#include <TText.h> // TText
75#include <TFile.h> // gFile
76#include <TFrame.h> // TFrame
77#include <TStyle.h> // gStyle
78#include <TCanvas.h> // TCanvas
79#include <TSystem.h> // gSystem
80#include <TDatime.h> // TDatime
81#include <TRandom.h> // TRandom
82#include <TRegexp.h> // TRegexp
83#include <TThread.h> // TThread::Self()
84#include <TBrowser.h> // TBrowser
85#include <TObjArray.h> // TObjArray
86#include <TPostScript.h> // TPostScript
87#include <TMethodCall.h> // TMethodCall
88
89#include <TInterpreter.h> // gInterpreter
90
91#include <TGTab.h> // TGTab
92#include <TGLabel.h> // TGLabel
93#include <TG3DLine.h> // TGHorizontal3DLine
94#include <TGButton.h> // TGPictureButton
95#include <TGTextView.h> // TGTextView
96#include <TGComboBox.h> // TGComboBox
97#include <TGStatusBar.h> // TGStatusBar
98#include <TGFileDialog.h> // TGFileDialog
99#include <TGProgressBar.h> // TGHProgressBar
100#include <TGTextEditDialogs.h> // TGPrintDialog
101#include <TRootEmbeddedCanvas.h> // TRootEmbeddedCanvas
102
103#include "MString.h"
104
105#include "MLog.h" // MLog
106#include "MLogManip.h" // inf, warn, err
107
108#include "MGList.h" // MGList
109#include "MGMenu.h" // MGMenu, TGMenu
110#include "MSearch.h" // MSearch
111#include "MParContainer.h" // MParContainer::GetDescriptor
112#include "MStatusArray.h" // MStatusArray
113
114#if ROOT_VERSION_CODE <= ROOT_VERSION(5,22,00)
115#include "../mhbase/MH.h"
116#endif
117
118#undef DEBUG
119//#define DEBUG
120
121ClassImp(MStatusDisplay);
122
123using namespace std;
124
125// ------------ Workaround for a non working TGTextView::Search -------------
126#if ROOT_VERSION_CODE < ROOT_VERSION(3,02,05)
127class MGTextView : public TGTextView
128{
129public:
130 MGTextView(const TGWindow *parent, UInt_t w, UInt_t h, Int_t id = -1,
131 UInt_t sboptions = 0, ULong_t back = GetWhitePixel()) :
132 TGTextView(parent, w, h, id, sboptions, back) {}
133 MGTextView(const TGWindow *parent, UInt_t w, UInt_t h, TGText *text,
134 Int_t id = -1, UInt_t sboptions = 0, ULong_t back = GetWhitePixel()) :
135 TGTextView(parent, w, h, text, id, sboptions, back) {}
136 MGTextView(const TGWindow *parent, UInt_t w, UInt_t h, const char *string,
137 Int_t id = -1, UInt_t sboptions = 0, ULong_t back = GetWhitePixel()) :
138 TGTextView(parent, w, h, string, id, sboptions, back) {}
139
140 void Mark(Long_t xPos, Long_t yPos) { TGTextView::Mark(xPos, yPos); }
141 void UnMark() { TGTextView::UnMark(); }
142
143 Bool_t Search(const char *string, Bool_t direction, Bool_t caseSensitive)
144 {
145 // Taken from TGTextView::Search and modified.
146
147 TGLongPosition pos, pos2;
148 pos2.fX = pos2.fY = 0;
149 if (fIsMarked) {
150 if (!direction)
151 {
152 pos2.fX = fMarkedStart.fX;
153 pos2.fY = fMarkedStart.fY;
154 }
155 else
156 {
157 pos2.fX = fMarkedEnd.fX + 1;
158 pos2.fY = fMarkedEnd.fY;
159 }
160 }
161 if (!fText->Search(&pos, pos2, string, direction, caseSensitive))
162 return kFALSE;
163 UnMark();
164 fIsMarked = kTRUE;
165 fMarkedStart.fY = fMarkedEnd.fY = pos.fY;
166 fMarkedStart.fX = pos.fX;
167 fMarkedEnd.fX = fMarkedStart.fX + strlen(string);
168 pos.fY = ToObjYCoord(fVisible.fY);
169 if ((fMarkedStart.fY < pos.fY) ||
170 (ToScrYCoord(fMarkedStart.fY) >= (Int_t)fCanvas->GetHeight()))
171 pos.fY = fMarkedStart.fY;
172 pos.fX = ToObjXCoord(fVisible.fX, pos.fY);
173 if ((fMarkedStart.fX < pos.fX) ||
174 (ToScrXCoord(fMarkedStart.fX, pos.fY) >= (Int_t)fCanvas->GetWidth()))
175 pos.fX = fMarkedStart.fX;
176
177 SetVsbPosition((ToScrYCoord(pos.fY) + fVisible.fY)/fScrollVal.fY);
178 SetHsbPosition((ToScrXCoord(pos.fX, pos.fY) + fVisible.fX)/fScrollVal.fX);
179 DrawRegion(0, (Int_t)ToScrYCoord(fMarkedStart.fY), fCanvas->GetWidth(),
180 UInt_t(ToScrYCoord(fMarkedEnd.fY+1) - ToScrYCoord(fMarkedEnd.fY)));
181
182 return kTRUE;
183 }
184};
185#else
186#define MGTextView TGTextView
187#endif
188
189// --------------------------------------------------------------------------
190
191TGCompositeFrame *MStatusDisplay::GetTabContainer(const char *name) const
192{
193#if ROOT_VERSION_CODE < ROOT_VERSION(4,03,05)
194 if (!fTab)
195 return 0;
196
197 TGFrameElement *el;
198 TGTabElement *tab = 0;
199 TGCompositeFrame *comp = 0;
200
201 TIter next(fTab->GetList());
202 next(); // skip first container
203
204 while ((el = (TGFrameElement *) next())) {
205 el = (TGFrameElement *) next();
206 comp = (TGCompositeFrame *) el->fFrame;
207 next();
208 tab = (TGTabElement *)el->fFrame;
209 if (name == tab->GetText()->GetString()) {
210 return comp;
211 }
212 }
213
214 return 0;
215#else
216 return fTab ? fTab->GetTabContainer(name) : 0;
217#endif
218}
219
220TGTabElement *MStatusDisplay::GetTabTab(const char *name) const
221{
222#if ROOT_VERSION_CODE < ROOT_VERSION(4,03,05)
223 if (!fTab)
224 return 0;
225
226 TGFrameElement *el;
227 TGTabElement *tab = 0;
228
229 TIter next(fTab->GetList());
230 next(); // skip first container
231
232 while ((el = (TGFrameElement *) next())) {
233 next();
234 tab = (TGTabElement *)el->fFrame;
235 if (name == tab->GetText()->GetString()) {
236 return tab;
237 }
238 }
239
240 return 0;
241#else
242 return fTab ? fTab->GetTabTab(name) : 0;
243#endif
244}
245// --------------------------------------------------------------------------
246
247
248// --------------------------------------------------------------------------
249//
250// Add menu bar to the GUI
251//
252void MStatusDisplay::AddMenuBar()
253{
254 //
255 // File Menu
256 //
257 MGPopupMenu *filemenu = new MGPopupMenu(gClient->GetRoot());
258 filemenu->AddEntry("New &Canvas", kFileCanvas);
259 filemenu->AddEntry("New &Browser", kFileBrowser);
260 filemenu->AddEntry("New &Tab", kFileTab);
261 filemenu->AddSeparator();
262
263 const TString fname(MString::Format("Save %s.", gROOT->GetName()));
264 MGPopupMenu *savemenu = new MGPopupMenu(gClient->GetRoot());
265 savemenu->AddEntry(MString::Format("%s&ps", fname.Data()), kFileSaveAsPS);
266 savemenu->AddEntry(MString::Format("%sp&df", fname.Data()), kFileSaveAsPDF);
267 savemenu->AddEntry(MString::Format("%s&svg", fname.Data()), kFileSaveAsSVG);
268 savemenu->AddSeparator();
269 savemenu->AddEntry(MString::Format("%sp&ng", fname.Data()), kFileSaveAsPNG);
270 savemenu->AddEntry(MString::Format("%s&gif", fname.Data()), kFileSaveAsGIF);
271 savemenu->AddEntry(MString::Format("%s&jpg", fname.Data()), kFileSaveAsJPG);
272 savemenu->AddEntry(MString::Format("%s&xpm", fname.Data()), kFileSaveAsXPM);
273 savemenu->AddEntry(MString::Format("%s&tiff",fname.Data()), kFileSaveAsTIFF);
274 savemenu->AddEntry(MString::Format("%s&bmp", fname.Data()), kFileSaveAsBMP);
275 savemenu->AddEntry(MString::Format("%sx&ml", fname.Data()), kFileSaveAsXML);
276 savemenu->AddEntry(MString::Format("%scs&v", fname.Data()), kFileSaveAsCSV);
277 savemenu->AddSeparator();
278 savemenu->AddEntry(MString::Format("%s&C", fname.Data()), kFileSaveAsC);
279 savemenu->AddEntry(MString::Format("%s&root", fname.Data()), kFileSaveAsRoot);
280 savemenu->AddEntry(MString::Format("%s&root (plain)", fname.Data()), kFileSaveAsPlainRoot);
281 savemenu->Associate(this);
282
283 filemenu->AddEntry("&Open...", kFileOpen);
284 filemenu->AddPopup("&Save", savemenu);
285 filemenu->AddEntry("Save &As...", kFileSaveAs);
286 filemenu->AddSeparator();
287 filemenu->AddEntry("&Reset", kFileReset);
288 filemenu->AddSeparator();
289 filemenu->AddEntry("&Print", kFilePrint);
290 filemenu->AddSeparator();
291 filemenu->AddEntry("C&lose", kFileClose);
292 filemenu->AddEntry("E&xit", kFileExit);
293 filemenu->Associate(this);
294
295 //
296 // Tab Menu
297 //
298 MGPopupMenu *tabmenu = new MGPopupMenu(gClient->GetRoot());
299 tabmenu->AddEntry("Next [&+]", kTabNext);
300 tabmenu->AddEntry("Previous [&-]", kTabPrevious);
301 tabmenu->AddSeparator();
302
303 const TString fname2(MString::Format("Save %s-i.", gROOT->GetName()));
304 MGPopupMenu *savemenu2 = new MGPopupMenu(gClient->GetRoot());
305 savemenu2->AddEntry(MString::Format("%s&ps", fname2.Data()), kTabSaveAsPS);
306 savemenu2->AddEntry(MString::Format("%sp&df", fname2.Data()), kTabSaveAsPDF);
307 savemenu2->AddEntry(MString::Format("%s&svg", fname2.Data()), kTabSaveAsSVG);
308 savemenu2->AddSeparator();
309 savemenu2->AddEntry(MString::Format("%sp&ng", fname2.Data()), kTabSaveAsPNG);
310 savemenu2->AddEntry(MString::Format("%s&gif", fname2.Data()), kTabSaveAsGIF);
311 savemenu2->AddEntry(MString::Format("%s&jpg", fname2.Data()), kTabSaveAsJPG);
312 savemenu2->AddEntry(MString::Format("%s&xpm", fname2.Data()), kTabSaveAsXPM);
313 savemenu2->AddEntry(MString::Format("%s&tiff",fname2.Data()), kTabSaveAsTIFF);
314 savemenu2->AddEntry(MString::Format("%s&bmp", fname2.Data()), kTabSaveAsBMP);
315 savemenu2->AddEntry(MString::Format("%sx&ml", fname2.Data()), kTabSaveAsXML);
316 savemenu2->AddEntry(MString::Format("%scs&v", fname2.Data()), kTabSaveAsCSV);
317 savemenu2->AddSeparator();
318 savemenu2->AddEntry(MString::Format("%s&C", fname2.Data()), kTabSaveAsC);
319 savemenu2->AddEntry(MString::Format("%s&root", fname2.Data()), kTabSaveAsRoot);
320 savemenu2->Associate(this);
321
322 tabmenu->AddPopup("&Save", savemenu2);
323 tabmenu->AddEntry("Save tab &As...", kTabSaveAs);
324 tabmenu->AddSeparator();
325 tabmenu->AddEntry("&Remove", kTabRemove);
326 tabmenu->AddSeparator();
327 tabmenu->AddEntry("&Print", kTabPrint);
328 tabmenu->Associate(this);
329
330 //
331 // Loop Menu
332 //
333 MGPopupMenu *loopmenu = new MGPopupMenu(gClient->GetRoot());
334 loopmenu->AddEntry("&Pause", kLoopPause);
335 loopmenu->AddEntry("Single S&tep", kLoopStep);
336 loopmenu->AddSeparator();
337 loopmenu->AddEntry("&Stop", kLoopStop);
338 loopmenu->Associate(this);
339
340 loopmenu->DisableEntry(kLoopStep);
341
342 //
343 // Loop Menu
344 //
345 MGPopupMenu *sizemenu = new MGPopupMenu(gClient->GetRoot());
346 sizemenu->AddEntry("Fit to 640x&480", kSize640);
347 sizemenu->AddEntry("Fit to 768x&576", kSize768);
348 sizemenu->AddEntry("Fit to 800x&600", kSize800);
349 sizemenu->AddEntry("Fit to 960x7&20", kSize960);
350 sizemenu->AddEntry("Fit to 1024x&768", kSize1024);
351 sizemenu->AddEntry("Fit to 1152x&864", kSize1152);
352 sizemenu->AddEntry("Fit to 1280x&1024", kSize1280);
353 sizemenu->AddEntry("Fit to 1400x1050", kSize1400);
354 sizemenu->AddEntry("Fit to 1600x1200", kSize1600);
355 sizemenu->AddEntry("Fit to &Desktop", kSizeOptimum);
356 sizemenu->Associate(this);
357
358 //
359 // Log Menu
360 //
361 MGPopupMenu *logmenu = new MGPopupMenu(gClient->GetRoot());
362 logmenu->AddEntry("&Copy Selected", kLogCopy);
363 logmenu->AddEntry("Cl&ear all", kLogClear);
364 logmenu->AddSeparator();
365 logmenu->AddEntry("Select &All", kLogSelect);
366 logmenu->AddSeparator();
367 logmenu->AddEntry("&Find...", kLogFind);
368 logmenu->AddSeparator();
369 logmenu->AddEntry("&Save", kLogSave);
370 logmenu->AddEntry("Save &append", kLogAppend);
371 logmenu->AddSeparator();
372 logmenu->AddEntry("&Print", kLogPrint);
373 logmenu->Associate(this);
374
375 //
376 // Menu Bar
377 //
378 TGLayoutHints *layitem = new TGLayoutHints(kLHintsNormal, 0, 4, 0, 0);
379 fList->Add(layitem);
380
381 fMenuBar = new MGMenuBar(this, 1, 1, kHorizontalFrame);
382 fMenuBar->AddPopup("&File", filemenu, layitem);
383 fMenuBar->AddPopup("Lo&g", logmenu, layitem);
384 fMenuBar->AddPopup("&Size", sizemenu, layitem);
385 fMenuBar->AddPopup("&Tab", tabmenu, layitem);
386 fMenuBar->AddPopup("&Loop", loopmenu, layitem);
387 fMenuBar->BindKeys(this);
388 AddFrame(fMenuBar);
389
390 //
391 // Line below menu bar
392 //
393 TGLayoutHints *laylinesep = new TGLayoutHints(kLHintsTop|kLHintsExpandX);
394 fList->Add(laylinesep);
395
396 TGHorizontal3DLine *linesep = new TGHorizontal3DLine(this);
397 AddFrame(linesep, laylinesep);
398
399 //
400 // Add everything to autodel list
401 //
402 fList->Add(savemenu);
403 fList->Add(savemenu2);
404 fList->Add(filemenu);
405 fList->Add(loopmenu);
406 fList->Add(sizemenu);
407 fList->Add(fMenuBar);
408 fList->Add(tabmenu);
409 fList->Add(logmenu);
410 fList->Add(linesep);
411}
412
413// --------------------------------------------------------------------------
414//
415// Adds an empty TGCompositeFrame which might be filled by the user
416//
417void MStatusDisplay::AddUserFrame()
418{
419 TGLayoutHints *lay=new TGLayoutHints(kLHintsExpandX);
420 fList->Add(lay);
421
422 fUserFrame = new TGCompositeFrame(this, 1, 1);
423 AddFrame(fUserFrame, lay);
424 fList->Add(fUserFrame);
425}
426
427// --------------------------------------------------------------------------
428//
429// Add the title tab
430//
431void MStatusDisplay::AddMarsTab()
432{
433 // Create Tab1
434 TGCompositeFrame *f = fTab->AddTab("-=MARS=-");
435
436 // Add list of tabs
437
438 TGComboBox *filter = new TGComboBox(f, kTabs);
439 fList->Add(filter);
440 filter->Associate(this);
441 filter->AddEntry("-=MARS=-", 0);
442 filter->Select(0);
443
444
445 TGLayoutHints *lay3 = new TGLayoutHints(kLHintsCenterX|kLHintsTop, 10, 10, 10, 5);
446 fList->Add(lay3);
447 f->AddFrame(filter, lay3);
448
449 // Add MARS version
450 TGLabel *l = new TGLabel(f, MString::Format("Official Release: V%s", MARSVER));
451 fList->Add(l);
452
453 filter->SetWidth(5*l->GetWidth()/4);
454 filter->SetHeight(4*l->GetHeight()/3);
455 filter->GetListBox()->SetHeight(l->GetHeight()*16);
456
457 TGLayoutHints *layb = new TGLayoutHints(kLHintsCenterX|kLHintsTop, 10, 10, 5, 5);
458 fList->Add(layb);
459 f->AddFrame(l, layb);
460
461 // Add root version
462 l = new TGLabel(f, MString::Format("Using ROOT v%s", ROOT_RELEASE));
463 fList->Add(l);
464
465 TGLayoutHints *lay = new TGLayoutHints(kLHintsCenterX|kLHintsTop);
466 fList->Add(lay);
467 f->AddFrame(l, lay);
468
469 // Add Mars logo picture
470 const TGPicture *pic2 = fList->GetPicture("marslogo.xpm");
471 if (pic2)
472 {
473 TGPictureButton *mars = new TGPictureButton(f, pic2, kPicMars);
474 fList->Add(mars);
475 mars->Associate(this);
476
477 TGLayoutHints *lay2 = new TGLayoutHints(kLHintsCenterX|kLHintsCenterY, 10, 10, 5, 5);
478 fList->Add(lay2);
479 f->AddFrame(mars, lay2);
480 }
481
482 // Add date and time
483 l = new TGLabel(f, TDatime().AsString());
484 fList->Add(l);
485 f->AddFrame(l, lay);
486
487 // Add copyright notice
488 l = new TGLabel(f, MString::Format("(c) MARS Software Development, 2000-%d", TDatime().GetYear()));
489 fList->Add(l);
490 f->AddFrame(l, layb);
491
492 TGLayoutHints *layc = new TGLayoutHints(kLHintsCenterX|kLHintsTop, 10, 10, 0, 5);
493 fList->Add(layc);
494
495 const char *txt = "<< Thomas Bretz >>";
496 l = new TGLabel(f, txt);
497 fList->Add(l);
498 f->AddFrame(l, layc);
499}
500
501// --------------------------------------------------------------------------
502//
503// Adds the logbook tab to the GUI if it was not added previously.
504//
505// The logbook is updated four times a second only if the tab is visible.
506//
507// You can redirect an output to a MLog-logstream by calling SetLogStream().
508// To disable redirction call SetLogStream(NULL)
509//
510// if enable==kFALSE the stdout is disabled/enabled. Otherwise stdout
511// is ignored.
512//
513void MStatusDisplay::SetLogStream(MLog *log, Bool_t enable)
514{
515 if (gROOT->IsBatch())
516 return;
517
518 if (log && fLogBox==NULL)
519 {
520 fLogIdx = fTab->GetNumberOfTabs();
521
522 // Create Tab1
523 TGCompositeFrame *f = AddRawTab("-Logbook-");//fTab->AddTab("-Logbook-");
524
525 // Create Text View
526 fLogBox = new MGTextView(f, 1, 1); // , -1, 0, TGFrame::GetDefaultFrameBackground());
527 if (fFont)
528 fLogBox->SetFont(fFont);
529 //fLogBox->Associate(this);
530
531 // Add List box to the tab
532 TGLayoutHints *lay = new TGLayoutHints(kLHintsNormal|kLHintsExpandX|kLHintsExpandY,2,2,2,2);
533 f->AddFrame(fLogBox, lay);
534
535 // layout and map tab
536 Layout();
537 MapSubwindows();
538
539 // make it visible
540 // FIXME: This is a workaround, because TApplication::Run is not
541 // thread safe against ProcessEvents. We assume, that if
542 // we are not in the Main-Thread ProcessEvents() is
543 // called by the TApplication Event Loop...
544 if (!TThread::Self()/*gApplication->InheritsFrom(TRint::Class())*/)
545 gClient->ProcessEventsFor(fTab);
546 }
547
548 if (log)
549 {
550 fLog = log;
551
552 log->SetOutputGui(fLogBox, kTRUE);
553 log->EnableOutputDevice(MLog::eGui);
554 if (!enable)
555 log->DisableOutputDevice(MLog::eStdout);
556
557 fLogTimer.Start();
558 }
559 else
560 {
561 fLogTimer.Stop();
562
563 fLog->DisableOutputDevice(MLog::eGui);
564 fLog->SetOutputGui(NULL);
565 if (!enable)
566 fLog->EnableOutputDevice(MLog::eStdout);
567
568 fLog = &gLog;
569 }
570}
571
572// --------------------------------------------------------------------------
573//
574// Add the Tabs and the predifined Tabs to the GUI
575//
576void MStatusDisplay::AddTabs()
577{
578 fTab = new TGTab(this, 300, 300);
579
580 AddMarsTab();
581
582 // Add fTab to Frame
583 TGLayoutHints *laytabs = new TGLayoutHints(kLHintsNormal|kLHintsExpandX|kLHintsExpandY, 5, 5, 5);
584 AddFrame(fTab, laytabs);
585
586 fList->Add(fTab);
587 fList->Add(laytabs);
588}
589
590// --------------------------------------------------------------------------
591//
592// Add the progress bar to the GUI. The Progress Bar range is set to
593// (0,1) as default.
594//
595void MStatusDisplay::AddProgressBar()
596{
597 TGLayoutHints *laybar=new TGLayoutHints(kLHintsExpandX, 5, 5, 5, 5);
598 fList->Add(laybar);
599
600 fBar=new TGHProgressBar(this);
601 fBar->SetRange(0, 1);
602 fBar->ShowPosition();
603 AddFrame(fBar, laybar);
604 fList->Add(fBar);
605}
606
607// --------------------------------------------------------------------------
608//
609// Set the progress bar position between 0 and 1. The Progress bar range
610// is assumed to be (0,1)
611//
612void MStatusDisplay::SetProgressBarPosition(Float_t p, Bool_t upd)
613{
614 if (!gClient || gROOT->IsBatch())
615 return;
616
617 fBar->SetPosition(p);
618 if (upd)
619 gClient->ProcessEventsFor(fBar);
620}
621
622// --------------------------------------------------------------------------
623//
624// Adds the status bar to the GUI
625//
626void MStatusDisplay::AddStatusBar()
627{
628 fStatusBar = new TGStatusBar(this, 1, 1);
629
630 //
631 // Divide it like the 'Golden Cut' (goldener Schnitt)
632 //
633 // 1-a a
634 // 1: ------|----
635 //
636 // a/(1-a) = (1-a)/1
637 // a^2+a-1 = 0
638 // a = (-1+-sqrt(1+4))/2 = sqrt(5)/2-1/2 = 0.618
639 //
640 Int_t p[] = {38-2, 62-8, 10};
641
642 fStatusBar->SetParts(p, 3);
643
644 TGLayoutHints *layb = new TGLayoutHints(kLHintsNormal|kLHintsExpandX, 5, 4, 0, 3);
645 AddFrame(fStatusBar, layb);
646
647 fList->Add(fStatusBar);
648 fList->Add(layb);
649}
650
651// --------------------------------------------------------------------------
652//
653// Change the text in the status line 1
654//
655void MStatusDisplay::SetStatusLine(const char *txt, Int_t i)
656{
657 if (gROOT->IsBatch())
658 return;
659 fStatusBar->SetText(txt, i);
660
661 // FIXME: This is a workaround, because TApplication::Run is not
662 // thread safe against ProcessEvents. We assume, that if
663 // we are not in the Main-Thread ProcessEvents() is
664 // called by the TApplication Event Loop...
665 if (!TThread::Self()/*gApplication->InheritsFrom(TRint::Class())*/)
666 gClient->ProcessEventsFor(fStatusBar);
667}
668
669// --------------------------------------------------------------------------
670//
671// Display information about the name of a container
672//
673void MStatusDisplay::SetStatusLine2(const MParContainer &cont)
674{
675 SetStatusLine2(MString::Format("%s: %s", cont.GetDescriptor().Data(), cont.GetTitle()));
676}
677
678// --------------------------------------------------------------------------
679//
680// Get TGPopupMenu as defined by name from fMenuBar
681//
682TGPopupMenu *MStatusDisplay::GetPopup(const char *name)
683{
684 if (!fMenuBar)
685 return 0;
686
687 TGPopupMenu *m = fMenuBar->GetPopup(name);
688 if (!m)
689 {
690 *fLog << warn << name << " doesn't exist in menu bar." << endl;
691 return 0;
692 }
693
694 return m;
695}
696
697// --------------------------------------------------------------------------
698//
699// Default constructor. Opens a window with a progress bar. Get a pointer
700// to the bar by calling GetBar. This pointer can be used for the
701// eventloop.
702//
703// Be carefull: killing or closing the window while the progress meter
704// is still in use may cause segmentation faults. Please kill the window
705// always by deleting the corresponding object.
706//
707// You can give either width or height. (Set the value not given to -1)
708// The other value is calculated accordingly. If width and height are
709// given height is ignored. If width=height=0 an optimum size from
710// the desktop size is calculated.
711//
712// Update time default: 10s
713//
714MStatusDisplay::MStatusDisplay(Int_t w, Int_t h, Long_t t)
715: TGMainFrame((TGWindow*)((gClient?gClient:new TGClient),NULL), 1, 1), fName("MStatusDisplay"), fLog(&gLog), fBar(NULL), fTab(NULL), fTimer(this, t, kTRUE), fStatus(kLoopNone), fLogIdx(-1), fLogTimer(this, 250, kTRUE), fLogBox(NULL), fIsLocked(0)
716{
717 // p==NULL means: Take gClient->GetRoot() if not in batch mode
718 // see TGWindow::TGWindow()
719
720 // Make sure that the display is removed via RecursiveRemove
721 // from whereever possible.
722 SetBit(kMustCleanup);
723
724 //
725 // This is a possibility for the user to check whether this
726 // object has already been deleted. It will be removed
727 // from the list in the destructor.
728 //
729 gROOT->GetListOfSpecials()->Add(this);
730
731 fFont = gVirtualX->LoadQueryFont("7x13bold");
732 fMutex = new TMutex;
733
734 //
735 // In case we are in batch mode use a list of canvases
736 // instead of the Root Embedded Canvases in the TGTab
737 //
738 fBatch = new TList;
739 fBatch->SetOwner();
740
741 //
742 // Create a list handling GUI widgets
743 //
744 fList = new MGList;
745 fList->SetOwner();
746
747 //
748 // Create the layout hint for the root embedded canavses
749 //
750 fLayCanvas = new TGLayoutHints(kLHintsExpandX|kLHintsExpandY);
751 fList->Add(fLayCanvas);
752
753 //
754 // Add Widgets (from top to bottom)
755 //
756 // In newer root versions gClient!=NULL in batch mode!
757 if (!gClient || !gClient->GetRoot() || gROOT->IsBatch()) // BATCH MODE
758 {
759 Resize(644, 484);
760 return;
761 }
762
763 AddMenuBar();
764 AddUserFrame();
765 AddTabs();
766 AddProgressBar();
767 AddStatusBar();
768
769 //
770 // set the smallest and biggest size of the Main frame
771 // and move it to its appearance position
772 SetWMSizeHints(566, 476, 2048, 1536, 1, 1);
773 MoveResize(rand()%100+566, rand()%100+476, 566, 476);
774 if (h>0)
775 SetDisplayHeight(h);
776 if (w>0)
777 SetDisplayWidth(w);
778 if (w==0 && h==0)
779 SetOptimumSize();
780
781 //
782 // Now do an automatic layout of the widgets and display the window
783 //
784 Layout();
785 MapSubwindows();
786
787 SetWindowName("Status Display");
788 SetIconName("Status Display");
789
790 MapWindow();
791
792 UpdateMemory();
793
794 // FIXME: This is a workaround, because TApplication::Run is not
795 // thread safe against ProcessEvents. We assume, that if
796 // we are not in the Main-Thread ProcessEvents() is
797 // called by the TApplication Event Loop...
798 if (!TThread::Self()/*gApplication->InheritsFrom(TRint::Class())*/)
799 gSystem->ProcessEvents();
800}
801
802// --------------------------------------------------------------------------
803//
804// Destruct the window with all its tiles. Also the Progress Bar object
805// is deleted.
806//
807MStatusDisplay::~MStatusDisplay()
808{
809 fTimer.Stop();
810
811#if ROOT_VERSION_CODE < ROOT_VERSION(3,10,01)
812 fTab = NULL; // See HandleEvent
813#endif
814
815 //
816 // Delete object from global object table so it cannot
817 // be deleted by chance a second time
818 //
819 gInterpreter->DeleteGlobal(this);
820
821 //
822 // This is a possibility for the user to check whether this
823 // object has already been deleted. It has been added
824 // to the list in the constructor.
825 //
826 gROOT->GetListOfSpecials()->Remove(this);
827
828 SetLogStream(NULL);
829
830 //
831 // Delete the list of objects corresponding to this object
832 //
833 delete fList;
834
835 //
836 // Delete the list of canvases used in batch mode
837 // instead of the Root Embedded Canvases in the TGTab
838 //
839 delete fBatch;
840
841 //
842 // Delete the font used for the logging window
843 //
844 if (fFont)
845 gVirtualX->DeleteFont(fFont);
846
847 //
848 // Delete mutex
849 //
850 delete fMutex;
851}
852
853// --------------------------------------------------------------------------
854//
855// Takes a TGCompositeFrame as argument. Searches for the first
856// TRootEmbeddedCanvas which is contained by it and returns a pointer
857// to the corresponding TCanvas. If it isn't found NULL is returned.
858//
859TRootEmbeddedCanvas *MStatusDisplay::GetEmbeddedCanvas(TGCompositeFrame &cf)
860{
861 TIter Next(cf.GetList());
862
863 TGFrameElement *f;
864 while ((f=(TGFrameElement*)Next()))
865 if (f->fFrame->InheritsFrom(TRootEmbeddedCanvas::Class()))
866 return (TRootEmbeddedCanvas*)f->fFrame;
867
868 return NULL;
869}
870
871// --------------------------------------------------------------------------
872//
873// Takes a TGCompositeFrame as argument. Searches for the first
874// TRootEmbeddedCanvas which is contained by it and returns a pointer
875// to the corresponding TCanvas. If it isn't found NULL is returned.
876//
877TCanvas *MStatusDisplay::GetCanvas(TGCompositeFrame &cf)
878{
879 TRootEmbeddedCanvas *ec = GetEmbeddedCanvas(cf);
880 return ec ? ec->GetCanvas() : NULL;
881}
882
883// --------------------------------------------------------------------------
884//
885// Returns the range of tabs containing valid canvases for the condition
886// num.
887//
888void MStatusDisplay::GetCanvasRange(Int_t &from, Int_t &to, Int_t num) const
889{
890 const Int_t max = gROOT->IsBatch() ? fBatch->GetSize()+1 : fTab->GetNumberOfTabs();
891
892 from = num<0 ? 1 : num;
893 to = num<0 ? max : num+1;
894}
895
896// --------------------------------------------------------------------------
897//
898// Returns GetCanvas of the i-th Tab.
899//
900TCanvas *MStatusDisplay::GetCanvas(int i) const
901{
902 if (gROOT->IsBatch())
903 return (TCanvas*)fBatch->At(i-1);
904
905 if (i<0 || i>=fTab->GetNumberOfTabs())
906 {
907 *fLog << warn << "MStatusDisplay::GetCanvas: Out of range." << endl;
908 return NULL;
909 }
910
911 return GetCanvas(*fTab->GetTabContainer(i));
912}
913
914// --------------------------------------------------------------------------
915//
916// Returns j-th pad of the i-th Tab.
917// Sets the pad to fill an entire window.
918//
919// This function can be used if single pad's out of an MStatusDisplay
920// have to be stored to file.
921//
922// ATTENTION: This function modifies the requested tab in MStatusDisplay itself!
923//
924TVirtualPad *MStatusDisplay::GetFullPad(const Int_t i, const Int_t j)
925{
926 if (!GetCanvas(i))
927 {
928 *fLog << warn << "MStatusDisplay::GetFullPad: i-th canvas not dound." << endl;
929 return NULL;
930 }
931
932 TVirtualPad *vpad = GetCanvas(i)->GetPad(j);
933 if (!vpad)
934 {
935 *fLog << warn << "MStatusDisplay::GetFullPad: Pad is out of range." << endl;
936 return NULL;
937 }
938
939 vpad->SetPad(0.,0.,1.,1.);
940 return vpad;
941}
942
943// --------------------------------------------------------------------------
944//
945// Searches for a TRootEmbeddedCanvas in the TGCompositeFramme of the
946// Tab with the name 'name'. Returns the corresponding TCanvas or
947// NULL if something isn't found.
948//
949TCanvas *MStatusDisplay::GetCanvas(const TString &name) const
950{
951 if (gROOT->IsBatch())
952 return (TCanvas*)fBatch->FindObject(name);
953
954 TGFrameElement *f;
955 TIter Next(fTab->GetList());
956 while ((f=(TGFrameElement*)Next()))
957 {
958 TObject *frame = f->fFrame;
959 if (!frame->InheritsFrom(TGTabElement::Class()))
960 continue;
961
962 TGTabElement *tab = (TGTabElement*)frame;
963 if (tab->GetString()==name)
964 break;
965 }
966
967 // Search for the next TGCompositeFrame in the list
968 while ((f=(TGFrameElement*)Next()))
969 {
970 TObject *frame = f->fFrame;
971 if (frame->InheritsFrom(TGCompositeFrame::Class()))
972 return GetCanvas(*(TGCompositeFrame*)frame);
973 }
974
975 return NULL;
976}
977
978// --------------------------------------------------------------------------
979//
980// Calls TCanvas::cd(), for the canvas returned by GetCanvas.
981//
982Bool_t MStatusDisplay::CdCanvas(const TString &name)
983{
984 TCanvas *c = GetCanvas(name);
985 if (!c)
986 return kFALSE;
987
988 c->cd();
989 return kTRUE;
990}
991
992// --------------------------------------------------------------------------
993//
994// Return the number of user added tabs (not that in batch mode this
995// exclude tabs without a canvas)
996//
997Int_t MStatusDisplay::GetNumTabs() const
998{
999 return gROOT->IsBatch() ? fBatch->GetEntries() : fTab->GetNumberOfTabs()-1;
1000}
1001
1002TGCompositeFrame *MStatusDisplay::AddRawTab(const char *name)
1003{
1004 // Add new tab
1005 TGCompositeFrame *f = fTab->AddTab(name);
1006
1007 TGComboBox *box = (TGComboBox*)fList->FindWidget(kTabs);
1008 box->AddEntry(name, box->GetListBox()->GetNumberOfEntries());
1009
1010 // layout and map new tab
1011 Layout();
1012 MapSubwindows();
1013 Layout();
1014
1015 UpdateMemory();
1016
1017 // display new tab in the main frame
1018 // FIXME: This is a workaround, because TApplication::Run is not
1019 // thread safe against ProcessEvents. We assume, that if
1020 // we are not in the Main-Thread ProcessEvents() is
1021 // called by the TApplication Event Loop...
1022 if (!TThread::Self()/*gApplication->InheritsFrom(TRint::Class())*/)
1023 gClient->ProcessEventsFor(fTab);
1024
1025 *fLog << inf3 << "Adding Raw Tab '" << name << "' (" << f->GetWidth() << "x";
1026 *fLog << f->GetHeight() << ")" << endl;
1027
1028 // return pointer to new canvas
1029 return f;
1030}
1031
1032// --------------------------------------------------------------------------
1033//
1034// This function was connected to all created canvases. It is used
1035// to redirect GetObjectInfo into our own status bar.
1036//
1037// The 'connection' is done in AddTab
1038//
1039void MStatusDisplay::EventInfo(Int_t /*event*/, Int_t px, Int_t py, TObject *selected)
1040{
1041 // Writes the event status in the status bar parts
1042 if (!selected)
1043 return;
1044
1045 TCanvas *c = (TCanvas*)gTQSender;
1046
1047 TVirtualPad* save=gPad;
1048
1049 gPad = c ? c->GetSelectedPad() : NULL;
1050
1051 if (gPad)
1052 {
1053 // Find the object which will get picked by the GetObjectInfo
1054 // due to buffer overflows in many root-versions
1055 // in TH1 and TProfile we have to work around and implement
1056 // our own GetObjectInfo which make everything a bit more
1057 // complicated.
1058#if ROOT_VERSION_CODE > ROOT_VERSION(5,22,00)
1059 SetStatusLine2(selected->GetObjectInfo(px,py));
1060#else
1061 TObjLink *link=0;
1062 static_cast<TPad*>(gPad)->Pick(px, py, link);
1063
1064 const TObject *o = link ? link->GetObject() : 0;
1065 if (o)
1066 SetStatusLine2(MH::GetObjectInfo(px, py, *o));
1067#endif
1068 }
1069
1070 gPad=save;
1071}
1072
1073// --------------------------------------------------------------------------
1074//
1075// Adds a new tab with the name 'name'. Adds a TRootEmbeddedCanvas to the
1076// tab and returns a reference to the corresponding TCanvas.
1077//
1078TCanvas &MStatusDisplay::AddTab(const char *name, const char *title)
1079{
1080 /*
1081 if (GetCanvas(name))
1082 {
1083 *fLog << warn;
1084 *fLog << "WARNING - A canvas '" << name << "' is already existing in the Status Display." << endl;
1085 *fLog << " This can cause unexpected crahes!" << endl;
1086 }*/
1087
1088 if (gROOT->IsBatch())
1089 {
1090 // 4 = 2*default border width of a canvas
1091 const UInt_t cw = GetWidth();
1092 const UInt_t ch = 2*cw/3 + 25; // 25: Menu, etc
1093
1094 // The constructor of TCanvas adds the canvas to the global list
1095 // of canvases gROOT->GetListOfCanvases(). If a canvas with an
1096 // identical name exists already in this list, the canvas is
1097 // deleted. In normal operation this might make sense and doesn't harm
1098 // because the embedded canvases behave different.
1099 // By creating the canvas without a name it is made sure that no
1100 // older canvas/tab vanished silently from the system (deleted from
1101 // the construtor). To make the handling of our canvases nevertheless
1102 // work well the name is set later. The list of canvases is also
1103 // part of the list of cleanups, thus fBatch need not to be added
1104 // to the list of cleanups.
1105 TCanvas *c = new TCanvas("", title?title:"", -cw, ch);
1106 c->SetName(name);
1107 c->SetFillColor(10); // White
1108 c->SetFrameBorderMode(0);
1109 c->SetBorderMode(0);
1110 fBatch->Add(c);
1111
1112 *fLog << inf3 << "Adding Canvas '" << name << "' (" << c->GetWw() << "x";
1113 *fLog << c->GetWh() << ", TCanvas=" << c << ")" << endl;
1114
1115 // Remove the canvas from the global list to make sure it is
1116 // not found by gROOT->FindObject
1117 //gROOT->GetListOfCanvases()->Remove(c);
1118 //gROOT->GetListOfCleanups()->Add(c);
1119
1120 return *c;
1121 }
1122
1123 // Add new tab
1124 TGCompositeFrame *f = fTab->AddTab(name);
1125
1126 // create root embedded canvas and add it to the tab
1127 TRootEmbeddedCanvas *ec = new TRootEmbeddedCanvas(name, f, f->GetWidth(), f->GetHeight(), kSunkenFrame);
1128 f->AddFrame(ec, fLayCanvas);
1129 fList->Add(ec);
1130
1131 // set background and border mode of the canvas
1132 TCanvas &c = *ec->GetCanvas();
1133
1134 if (title)
1135 c.SetTitle(title);
1136
1137 c.SetFillColor(10); // White
1138 c.SetFrameBorderMode(0);
1139 c.SetBorderMode(0);
1140
1141 // If kNoContextMenu set set kNoContextMenu of the canvas
1142 if (TestBit(kNoContextMenu))
1143 c.SetBit(kNoContextMenu);
1144
1145 // Connect all TCanvas::ProcessedEvent to this->EventInfo
1146 // This means, that after TCanvas has processed an event
1147 // EventInfo of this class is called, see TCanvas::HandleInput
1148 c.Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)",
1149 "MStatusDisplay", this, "EventInfo(Int_t,Int_t,Int_t,TObject*)");
1150
1151 // Make sure that root itself doesn't try to call GetObjectInfo
1152 // This is now handled from EventsInfo. This is necessary
1153 // due to the buffer overflow bug in GetObjectInfo of
1154 // TProfile and TH1
1155 c.ResetBit(TCanvas::kShowEventStatus);
1156
1157 // Remove the canvas from the global list to make sure it is
1158 // not found by gROOT->FindObject
1159 //gROOT->GetListOfCanvases()->Remove(&c);
1160 //gROOT->GetListOfCleanups()->Add(&c);
1161
1162 TGComboBox *box = (TGComboBox*)fList->FindWidget(kTabs);
1163 box->AddEntry(name, box->GetListBox()->GetNumberOfEntries());
1164
1165 // layout and map new tab
1166 Layout(); // seems to layout the TGCompositeFrame
1167 MapSubwindows(); // maps the TGCompositeFrame
1168 Layout(); // layout the embedded canvas in the frame
1169
1170 UpdateMemory();
1171
1172 // display new tab in the main frame
1173 // FIXME: This is a workaround, because TApplication::Run is not
1174 // thread safe against ProcessEvents. We assume, that if
1175 // we are not in the Main-Thread ProcessEvents() is
1176 // called by the TApplication Event Loop...
1177 if (!TThread::Self()/*gApplication->InheritsFrom(TRint::Class())*/)
1178 gClient->ProcessEventsFor(fTab);
1179
1180 *fLog << inf3 << "Adding Tab '" << name << "' (" << f->GetWidth() << "x";
1181 *fLog << f->GetHeight() << ", TCanvas=" << &c << ")" << endl;
1182
1183 // return pointer to new canvas
1184 return c;
1185}
1186
1187// --------------------------------------------------------------------------
1188//
1189// Update a canvas in a tab, takes the corresponding TGCompositeFrame
1190// as an argument. This is necessary, because not all functions
1191// changing the contents of a canvas or pad can call SetModified()
1192// for the corresponding tab. If this is not called correctly the
1193// tab won't be updated calling TCanvas::Update(). So we simply
1194// redraw it by our own (instead we could recursively call
1195// TPad::Modified() for everything contained by the TCanvas and
1196// call TCanvas::Update() afterwards)
1197//
1198void MStatusDisplay::UpdateTab(TGCompositeFrame *f)
1199{
1200 if (!f)
1201 return;
1202
1203 TCanvas *c=GetCanvas(*f);
1204 if (!c)
1205 return;
1206
1207 //
1208 // If we are in a multithreaded environment (gThreadXAR) we
1209 // have to make sure, that thus function is called from
1210 // the main thread.
1211 //
1212 if (gThreadXAR)
1213 {
1214 // Tell the X-Requester how to call this method
1215 TString str = MString::Format("%d", (ULong_t)f);
1216
1217 TMethodCall call(IsA(), "UpdateTab", "NULL");
1218 void *arr[4] = { NULL, &call, this, (void*)(const char*)str };
1219
1220 // If this is not the main thread return
1221 if (((*gThreadXAR)("METH", 4, arr, NULL)))
1222 return;
1223 }
1224
1225 //
1226 // Secure calls to update the tabs against itself, at least
1227 // c->Paint() or c->Flush() may crash X (bad drawable).
1228 // This makes sure, that a X call is not interuppted by
1229 // another X-call which was started from an gui interrrupt
1230 // in the same thread
1231 //
1232 const Int_t rc = fMutex->TryLock();
1233 if (rc==13)
1234 gLog << warn << "MStatusDisplay::UpdateTab - mutex is already locked by this thread." << endl;
1235
1236 if (rc)
1237 return;
1238
1239#if ROOT_VERSION_CODE < ROOT_VERSION(3,10,02)
1240 TPad *padsav = (TPad*)gPad;
1241 if (!gPad)
1242 c->cd();
1243#endif
1244
1245 if (!c->IsBatch())
1246 c->FeedbackMode(kFALSE); // Goto double buffer mode
1247
1248 //
1249 // Doing this ourself gives us the possibility to repaint
1250 // the canvas in any case (Paint() instead of PaintModified())
1251 //
1252 c->Paint(); // Repaint all pads
1253 c->Flush(); // Copy all pad pixmaps to the screen
1254
1255#if ROOT_VERSION_CODE < ROOT_VERSION(3,10,02)
1256 if (padsav)
1257 padsav->cd();
1258 else
1259 gPad=NULL;
1260#endif
1261
1262 //c->SetCursor(kCross);
1263
1264 // Old version
1265 //c->Modified();
1266 //c->Update();
1267 //c->Paint();
1268
1269 fMutex->UnLock();
1270}
1271
1272TString MStatusDisplay::PrintDialog(TString &p, TString &c, TString &t, const char *ext)
1273{
1274 // If not in batch mode open a user dialog
1275 if (!gROOT->IsBatch())
1276 {
1277 char *cprinter = StrDup(p);
1278 char *ccmd = StrDup(c);
1279
1280 Int_t rc=0;
1281 new TGPrintDialog(fClient->GetRoot(), this, 400, 150, &cprinter, &ccmd, &rc);
1282 if (rc)
1283 {
1284 p = cprinter; // default has been changed
1285 c = ccmd;
1286 }
1287
1288 delete [] cprinter;
1289 delete [] ccmd;
1290
1291 if (!rc)
1292 return "";
1293 }
1294
1295 if (c.Contains("%f") && ext)
1296 {
1297 // Get temporary file name
1298 TString name = "mars";
1299
1300 FILE *f = gSystem->TempFileName(name, t);
1301 if (!f)
1302 {
1303 *fLog << warn << "MStatusDisplay::PrintDialog: Couldn't create temporary file in " << t << endl;
1304 SetStatusLine2("failed!");
1305 return "";
1306 }
1307 fclose(f);
1308
1309 // remove temp file
1310 gSystem->Unlink(name);
1311 name += ".";
1312 name += ext;
1313
1314 t = name;
1315 }
1316
1317 // compile command
1318 TString cmd(c);
1319
1320 // if sprinter.IsNull we assume that everything around %p can
1321 // be omitted and the program uses some kind of default
1322 if (p.IsNull())
1323 {
1324 TString sub;
1325 while (1)
1326 {
1327 sub = TString(cmd(TRegexp(" .*%p.* "))).Strip(TString::kBoth);
1328 if (sub.IsNull())
1329 break;
1330
1331 cmd.ReplaceAll(sub, "");
1332 }
1333 }
1334
1335 cmd.ReplaceAll("%p", p);
1336 cmd.ReplaceAll("%f", t);
1337
1338 return cmd;
1339}
1340
1341// --------------------------------------------------------------------------
1342//
1343// Saves the given canvas (pad) or all pads (num<0) as a temporary
1344// postscript file and prints it.
1345//
1346// The default command line c is: lpr -P%p %f
1347// %p: printer name
1348// %f: temporary file name
1349//
1350// The default printer name p is: <empty>
1351//
1352// Both can be changed in .rootrc by:
1353// PrintPS.Printer
1354// PrintPS.Command
1355//
1356// Ant the location of the temporary file t can by changed by
1357// Print.Directory
1358// the default is the system default directory (normally /tmp)
1359//
1360Int_t MStatusDisplay::PrintPS(Int_t num, const char *p, const char *c, const char *t)
1361{
1362 static TString sprinter = gEnv->GetValue("PrintPS.Printer", p&&*p?p:"");
1363 static TString scmd = gEnv->GetValue("PrintPS.Command", c&&*c?c:"lpr -P%p %f");
1364
1365 TString tmp = gEnv->GetValue("Print.Directory", t&&*t?t:gSystem->TempDirectory());
1366
1367 TString cmd = PrintDialog(sprinter, scmd, tmp, "ps");
1368 if (cmd.IsNull())
1369 return 0;
1370
1371 // set status lines
1372 SetStatusLine1("Printing...");
1373 SetStatusLine2("");
1374
1375 // print to temporary file
1376 const Int_t pages = SaveAsPS(num, tmp);
1377
1378 // check
1379 if (!pages)
1380 {
1381 *fLog << warn << "MStatusDisplay::Print: Sorry, couldn't save file as temporary postscript!" << endl;
1382 SetStatusLine2("Failed!");
1383 return 0;
1384 }
1385
1386 // execute command
1387 *fLog << dbg << "Executing: " << cmd << endl;
1388 gSystem->Exec(cmd);
1389
1390 // remove temporary file
1391 gSystem->Unlink(tmp);
1392
1393 SetStatusLine2(MString::Format("Done (%dpage(s))", pages));
1394
1395 return pages;
1396}
1397
1398// --------------------------------------------------------------------------
1399//
1400// Remove tab no i if this tab contains a TRootEmbeddedCanvas
1401//
1402void MStatusDisplay::RemoveTab(int i)
1403{
1404 TGCompositeFrame *f = fTab->GetTabContainer(i);
1405 if (!f)
1406 return;
1407
1408 TRootEmbeddedCanvas *ec = GetEmbeddedCanvas(*f);
1409 if (!ec)
1410 return;
1411
1412 TCanvas *c = ec->GetCanvas();
1413 if (!c)
1414 return;
1415
1416 // Repair the "Workaround" being in the RecursiveRemove list
1417 // but not in a list checked by gROOT->FindObject
1418 //gROOT->GetListOfCleanups()->Remove(c);
1419 //gROOT->GetListOfCanvases()->Add(c);
1420
1421 // FIXME: Due to our workaround this is necessary for a successfull deletion
1422 //c->cd();
1423
1424 const TString name(c->GetName());
1425
1426 f->RemoveFrame(ec);
1427 delete fList->Remove(ec);
1428
1429 fTab->RemoveTab(i);
1430 fTab->SetTab(0);
1431
1432 TGComboBox *box = (TGComboBox*)fList->FindWidget(kTabs);
1433 box->RemoveEntry(i);
1434 for (int j=i; j<box->GetListBox()->GetNumberOfEntries(); j++)
1435 {
1436 TGTextLBEntry *entry = (TGTextLBEntry *)box->GetListBox()->Select(j+1, kFALSE);
1437 box->AddEntry(entry->GetText()->GetString(), j);
1438 box->RemoveEntry(j+1);
1439 }
1440 box->GetListBox()->Select(0);
1441
1442 // Looks strange...
1443 // const Int_t n = fTab->GetNumberOfTabs();
1444 // fTab->SetTab(i<=n-1 ? i : i-1);
1445
1446 // layout and map new tab
1447 Layout(); // seems to layout the TGCompositeFrame
1448 MapSubwindows(); // maps the TGCompositeFrame
1449 Layout(); // layout the embedded canvas in the frame
1450
1451 UpdateMemory();
1452
1453 // display new tab in the main frame
1454 // FIXME: This is a workaround, because TApplication::Run is not
1455 // thread safe against ProcessEvents. We assume, that if
1456 // we are not in the Main-Thread ProcessEvents() is
1457 // called by the TApplication Event Loop...
1458 if (!TThread::Self()/*gApplication->InheritsFrom(TRint::Class())*/)
1459 gClient->ProcessEventsFor(fTab);
1460
1461 *fLog << inf << "Removed Tab #" << i << " '" << name << "'" << endl;
1462}
1463
1464// --------------------------------------------------------------------------
1465//
1466// Use this to check whether the MStatusDisplay still contains the
1467// TCanvas c. It could be removed meanwhile by menu usage.
1468//
1469Bool_t MStatusDisplay::HasCanvas(const TCanvas *c) const
1470{
1471 if (!c)
1472 return kFALSE;
1473
1474 // If you encounter unexpected crashes here, check if
1475 // a canvas is existing twice in the list or has been
1476 // deleted by accident. (Check AddTab)
1477
1478 if (gROOT->IsBatch())
1479 return (Bool_t)fBatch->FindObject(c);
1480
1481 for (int i=1; i<fTab->GetNumberOfTabs(); i++)
1482 if (c==GetCanvas(i))
1483 return kTRUE;
1484 return kFALSE;
1485}
1486
1487/*
1488 if (...)
1489 fMenu->AddPopup("&CaOs", fCaOs, NULL);
1490 else
1491 fMenu->RemovePopup("CaOs");
1492 fMenu->Resize(fMenu->GetDefaultSize());
1493 MapSubwindows();
1494 MapWindow();
1495 */
1496
1497void MStatusDisplay::Reset()
1498{
1499 if (gROOT->IsBatch())
1500 {
1501 fBatch->Delete();
1502 return;
1503 }
1504
1505 for (int i=fTab->GetNumberOfTabs()-1; i>0; i--)
1506 RemoveTab(i);
1507}
1508
1509Bool_t MStatusDisplay::SaveLogAsPS(const char *n) const
1510{
1511 TString name(n);
1512 AddExtension(name, "ps");
1513
1514 // Code taken from TGTextEdit::Print
1515 const TString pipe = MString::Format("a2ps -o%s", name.Data());
1516 FILE *p = gSystem->OpenPipe(pipe, "w");
1517 if (!p)
1518 {
1519 *fLog << err << "ERROR - Couldn't open pipe " << pipe << ": " << strerror(errno) << endl;
1520 return kFALSE;
1521 }
1522
1523 TGText *text = fLogBox->GetText();
1524
1525 char *buf1, *buf2;
1526 Long_t len;
1527 ULong_t i = 0;
1528 TGLongPosition pos;
1529
1530 Bool_t rc = kTRUE;
1531
1532 pos.fX = pos.fY = 0;
1533 while (pos.fY < text->RowCount())
1534 {
1535 len = text->GetLineLength(pos.fY);
1536 buf1 = text->GetLine(pos, len);
1537 buf2 = new char[len + 2];
1538 strncpy(buf2, buf1, (UInt_t)len);
1539 buf2[len] = '\n';
1540 buf2[len+1] = '\0';
1541 while (buf2[i] != '\0') {
1542 if (buf2[i] == '\t') {
1543 ULong_t j = i+1;
1544 while (buf2[j] == 16 && buf2[j] != '\0')
1545 j++;
1546 strcpy(buf2+i+1, buf2+j);
1547 }
1548 i++;
1549 }
1550
1551 const UInt_t len = sizeof(char)*(strlen(buf2)+1);
1552
1553 const size_t ret = fwrite(buf2, len, 1, p);
1554 delete [] buf1;
1555 delete [] buf2;
1556
1557 if (ret!=1)
1558 {
1559 *fLog << err << "ERROR - fwrite to pipe " << pipe << " failed: " << strerror(errno) << endl;
1560 rc = kFALSE;
1561 break;
1562 }
1563
1564 pos.fY++;
1565 }
1566 gSystem->ClosePipe(p);
1567 return kTRUE;
1568}
1569
1570// --------------------------------------------------------------------------
1571//
1572// Print the log text.
1573//
1574// The default command line c is: a2ps -P%p
1575// %p: printer name
1576//
1577// The default printer name p is: <empty>
1578//
1579// Both can be changed in .rootrc by:
1580// PrintText.Printer
1581// PrintText.Command
1582//
1583Bool_t MStatusDisplay::PrintLog(const char *p, const char *c)
1584{
1585 static TString sprinter = gEnv->GetValue("PrintText.Printer", p&&*p?p:"");
1586 static TString scmd = gEnv->GetValue("PrintText.Command", c&&*c?c:"a2ps -P%p");
1587
1588 TString tmp;
1589 TString cmd = PrintDialog(sprinter, scmd, tmp);
1590 if (cmd.IsNull())
1591 return kFALSE;
1592
1593 // set status lines
1594 SetStatusLine1("Printing...");
1595 SetStatusLine2("");
1596
1597 // print to temporary file
1598 if (!SaveLogAsPS(cmd))
1599 {
1600 *fLog << warn << "MStatusDisplay::PrintLog: Sorry, couldn't create postscript!" << endl;
1601 SetStatusLine2("Failed!");
1602 return kFALSE;
1603 }
1604
1605 // execute command
1606 *fLog << dbg << "Executing: " << cmd << endl;
1607 gSystem->Exec(cmd);
1608
1609 SetStatusLine2("Done.");
1610
1611 return kTRUE;
1612}
1613
1614// --------------------------------------------------------------------------
1615//
1616// Process the kC_COMMAND, kCM_MENU messages
1617//
1618Bool_t MStatusDisplay::ProcessMessageCommandMenu(Long_t id)
1619{
1620 switch (id)
1621 {
1622 case kLoopPause:
1623 {
1624 TGPopupMenu *m = GetPopup("Loop");
1625 if (!m)
1626 return kTRUE;
1627
1628 if (fStatus==kLoopNone)
1629 {
1630 fStatus = (Status_t)kLoopPause;
1631 m->CheckEntry(kLoopPause);
1632 m->EnableEntry(kLoopStep);
1633 return kTRUE;
1634 }
1635 if (fStatus==kLoopPause)
1636 {
1637 fStatus = (Status_t)kLoopNone;
1638 m->UnCheckEntry(kLoopPause);
1639 m->DisableEntry(kLoopStep);
1640 return kTRUE;
1641 }
1642 }
1643 return kTRUE;
1644
1645 case kLoopStep:
1646 fStatus = (Status_t)kLoopStep;
1647 return kTRUE;
1648
1649 case kLoopStop:
1650 case kFileClose:
1651 case kFileExit:
1652 if (id==kFileExit || id==kFileClose)
1653 if (Close())
1654 delete this;
1655 fStatus = (Status_t)id;
1656 return kTRUE;
1657
1658 case kFileCanvas:
1659 new TCanvas;
1660 return kTRUE;
1661
1662 case kFileBrowser:
1663 new TBrowser;
1664 return kTRUE;
1665
1666 case kFileTab:
1667 AddTab(MString::Format("%d", fTab->GetNumberOfTabs()));
1668 return kTRUE;
1669
1670 case kFileReset:
1671 Reset();
1672 return kTRUE;
1673
1674 case kFileOpen:
1675 Open();
1676 return kTRUE;
1677
1678 case kFileSaveAs:
1679 SaveAs();
1680 return kTRUE;
1681
1682 case kFileSaveAsPS:
1683 SaveAsPS();
1684 return kTRUE;
1685
1686 case kFileSaveAsPDF:
1687 SaveAsPDF();
1688 return kTRUE;
1689
1690 case kFileSaveAsSVG:
1691 SaveAsSVG();
1692 return kTRUE;
1693
1694 case kFileSaveAsPNG:
1695 SaveAsPNG();
1696 return kTRUE;
1697
1698 case kFileSaveAsGIF:
1699 SaveAsGIF();
1700 return kTRUE;
1701
1702 case kFileSaveAsXPM:
1703 SaveAsXPM();
1704 return kTRUE;
1705
1706 case kFileSaveAsJPG:
1707 SaveAsJPG();
1708 return kTRUE;
1709
1710 case kFileSaveAsTIFF:
1711 SaveAsTIFF();
1712 return kTRUE;
1713
1714 case kFileSaveAsBMP:
1715 SaveAsBMP();
1716 return kTRUE;
1717
1718 case kFileSaveAsXML:
1719 SaveAsXML();
1720 return kTRUE;
1721
1722 case kFileSaveAsCSV:
1723 SaveAsCSV();
1724 return kTRUE;
1725
1726 case kFileSaveAsC:
1727 SaveAsC();
1728 return kTRUE;
1729
1730 case kFileSaveAsRoot:
1731 SaveAsRoot();
1732 return kTRUE;
1733
1734 case kFileSaveAsPlainRoot:
1735 SaveAsPlainRoot(kTRUE);
1736 return kTRUE;
1737
1738 case kFilePrint:
1739 PrintPS();
1740 return kTRUE;
1741
1742 case kTabSaveAs:
1743 SaveAs(fTab->GetCurrent());
1744 return kTRUE;
1745
1746 case kTabSaveAsPS:
1747 SaveAsPS(fTab->GetCurrent());
1748 return kTRUE;
1749
1750 case kTabSaveAsPDF:
1751 SaveAsPDF(fTab->GetCurrent());
1752 return kTRUE;
1753
1754 case kTabSaveAsSVG:
1755 SaveAsSVG(fTab->GetCurrent());
1756 return kTRUE;
1757
1758 case kTabSaveAsPNG:
1759 SaveAsPNG(fTab->GetCurrent());
1760 return kTRUE;
1761
1762 case kTabSaveAsGIF:
1763 SaveAsGIF(fTab->GetCurrent());
1764 return kTRUE;
1765
1766 case kTabSaveAsXPM:
1767 SaveAsXPM(fTab->GetCurrent());
1768 return kTRUE;
1769
1770 case kTabSaveAsJPG:
1771 SaveAsJPG(fTab->GetCurrent());
1772 return kTRUE;
1773
1774 case kTabSaveAsTIFF:
1775 SaveAsTIFF(fTab->GetCurrent());
1776 return kTRUE;
1777
1778 case kTabSaveAsBMP:
1779 SaveAsBMP(fTab->GetCurrent());
1780 return kTRUE;
1781
1782 case kTabSaveAsXML:
1783 SaveAsXML(fTab->GetCurrent());
1784 return kTRUE;
1785
1786 case kTabSaveAsCSV:
1787 SaveAsCSV(fTab->GetCurrent());
1788 return kTRUE;
1789
1790 case kTabSaveAsC:
1791 SaveAsC(fTab->GetCurrent());
1792 return kTRUE;
1793
1794 case kTabSaveAsPlainRoot:
1795 SaveAsPlainRoot(fTab->GetCurrent());
1796 return kTRUE;
1797
1798 case kTabSaveAsRoot:
1799 SaveAsRoot(fTab->GetCurrent());
1800 return kTRUE;
1801
1802 case kTabPrint:
1803 PrintPS(fTab->GetCurrent());
1804 return kTRUE;
1805
1806 case kTabNext:
1807 fTab->SetTab(fTab->GetCurrent()+1);
1808 return kTRUE;
1809
1810 case kTabPrevious:
1811 fTab->SetTab(fTab->GetCurrent()-1);
1812 return kTRUE;
1813
1814 case kTabRemove:
1815 RemoveTab(fTab->GetCurrent());
1816 return kTRUE;
1817
1818 case kSize640:
1819 SetDisplaySize(640, 480);
1820 return kTRUE;
1821 case kSize768:
1822 SetDisplaySize(768, 576);
1823 return kTRUE;
1824 case kSize800:
1825 SetDisplaySize(800, 600);
1826 return kTRUE;
1827 case kSize960:
1828 SetDisplaySize(960, 720);
1829 return kTRUE;
1830 case kSize1024:
1831 SetDisplaySize(1024, 768);
1832 return kTRUE;
1833 case kSize1152:
1834 SetDisplaySize(1152, 864);
1835 return kTRUE;
1836 case kSize1280:
1837 SetDisplaySize(1280, 1024);
1838 return kTRUE;
1839 case kSize1400:
1840 SetDisplaySize(1400, 1050);
1841 return kTRUE;
1842 case kSize1600:
1843 SetDisplaySize(1600, 1200);
1844 return kTRUE;
1845 case kSizeOptimum:
1846 SetOptimumSize();
1847 return kTRUE;
1848
1849 case kLogClear:
1850 fLogBox->Clear();
1851 return kTRUE;
1852 case kLogCopy:
1853 fLogBox->Copy();
1854 return kTRUE;
1855 case kLogSelect:
1856 fLogBox->SelectAll();
1857 return kTRUE;
1858 case kLogFind:
1859 new MSearch(this);
1860 return kTRUE;
1861 case kLogSave:
1862 SetStatusLine1("Saving log...");
1863 SetStatusLine2("");
1864 *fLog << inf << "Saving log... " << flush;
1865 if (fLogBox->GetText()->Save(MString::Format("%s.log", gROOT->GetName())))
1866 {
1867 *fLog << "done." << endl;
1868 SetStatusLine2("done.");
1869 }
1870 else
1871 {
1872 *fLog << "failed!" << endl;
1873 SetStatusLine2("Failed!");
1874 }
1875 return kTRUE;
1876
1877 case kLogAppend:
1878 SetStatusLine1("Appending log...");
1879 SetStatusLine2("");
1880 *fLog << inf << "Appending log... " << flush;
1881 if (fLogBox->GetText()->Append(MString::Format("%s.log", gROOT->GetName())))
1882 {
1883 *fLog << "done." << endl;
1884 SetStatusLine2("done.");
1885 }
1886 else
1887 {
1888 *fLog << "failed!" << endl;
1889 SetStatusLine2("Failed!");
1890 }
1891 return kTRUE;
1892
1893 case kLogPrint:
1894 PrintLog();
1895 return kTRUE;
1896#ifdef DEBUG
1897 default:
1898 cout << "Command-Menu #" << id << endl;
1899#endif
1900 }
1901 return kTRUE;
1902
1903}
1904
1905// --------------------------------------------------------------------------
1906//
1907// Process the kC_COMMAND messages
1908//
1909Bool_t MStatusDisplay::ProcessMessageCommand(Long_t submsg, Long_t mp1, Long_t mp2)
1910{
1911 switch (submsg)
1912 {
1913 case kCM_MENU: // 1
1914 return ProcessMessageCommandMenu(mp1); // mp2=userdata
1915 case kCM_TAB: // 8
1916 /*
1917 for (int i=0; i<fTab->GetNumberOfTabs(); i++)
1918 fTab->GetTabContainer(i)->UnmapWindow();
1919 */
1920 UpdateTab(fTab->GetTabContainer(mp1));
1921 //fTab->GetTabContainer(mp1)->MapWindow();
1922
1923 /*
1924 if (mp1>0)
1925 fMenu->AddPopup("&CaOs", fCaOs, NULL);
1926 else
1927 fMenu->RemovePopup("CaOs");
1928 fMenu->Resize(fMenu->GetDefaultSize());
1929 MapSubwindows();
1930 MapWindow();
1931 */
1932 return kTRUE;
1933 case kCM_COMBOBOX: // 7
1934 if (mp1==kTabs)
1935 fTab->SetTab(mp2);
1936 return kTRUE;
1937#ifdef DEBUG
1938 case kCM_MENUSELECT: // 2
1939 cout << "Command-Menuselect #" << mp1 << " (UserData=" << (void*)mp2 << ")" << endl;
1940 return kTRUE;
1941
1942 case kCM_BUTTON: // 3
1943 cout << "Command-Button." << endl;
1944 return kTRUE;
1945
1946 case kCM_CHECKBUTTON: // 4
1947 cout << "Command-CheckButton." << endl;
1948 return kTRUE;
1949
1950 case kCM_RADIOBUTTON: // 5
1951 cout << "Command-RadioButton." << endl;
1952 return kTRUE;
1953
1954 case kCM_LISTBOX: // 6
1955 cout << "Command-Listbox #" << mp1 << " (LineId #" << mp2 << ")" << endl;
1956 return kTRUE;
1957 default:
1958 cout << "Command: " << "Submsg:" << submsg << " Mp1=" << mp1 << " Mp2=" << mp2 << endl;
1959#endif
1960 }
1961 return kTRUE;
1962}
1963
1964// --------------------------------------------------------------------------
1965//
1966// Process the kC_TEXTVIEW messages
1967//
1968Bool_t MStatusDisplay::ProcessMessageTextview(Long_t /*submsg*/, Long_t /*mp1*/, Long_t /*mp2*/)
1969{
1970 // kC_TEXTVIEW, kTXT_ISMARKED, widget id, [true|false] //
1971 // kC_TEXTVIEW, kTXT_DATACHANGE, widget id, 0 //
1972 // kC_TEXTVIEW, kTXT_CLICK2, widget id, position (y << 16) | x) //
1973 // kC_TEXTVIEW, kTXT_CLICK3, widget id, position (y << 16) | x) //
1974 // kC_TEXTVIEW, kTXT_F3, widget id, true //
1975 // kC_TEXTVIEW, kTXT_OPEN, widget id, 0 //
1976 // kC_TEXTVIEW, kTXT_CLOSE, widget id, 0 //
1977 // kC_TEXTVIEW, kTXT_SAVE, widget id, 0 //
1978#ifdef DEBUG
1979 switch (submsg)
1980 {
1981 case kTXT_ISMARKED:
1982 cout << "Textview-IsMarked #" << mp1 << " " << (mp2?"yes":"no") << endl;
1983 return kTRUE;
1984
1985 case kTXT_DATACHANGE:
1986 cout << "Textview-DataChange #" << mp1 << endl;
1987 return kTRUE;
1988
1989 case kTXT_CLICK2:
1990 cout << "Textview-Click2 #" << mp1 << " x=" << (mp2&0xffff) << " y= " << (mp2>>16) << endl;
1991 return kTRUE;
1992
1993 case kTXT_CLICK3:
1994 cout << "Textview-Click3 #" << mp1 << " x=" << (mp2&0xffff) << " y= " << (mp2>>16) << endl;
1995 return kTRUE;
1996
1997 case kTXT_F3:
1998 cout << "Textview-F3 #" << mp1 << endl;
1999 return kTRUE;
2000
2001 case kTXT_OPEN:
2002 cout << "Textview-Open #" << mp1 << endl;
2003 return kTRUE;
2004
2005 case kTXT_CLOSE:
2006 cout << "Textview-Close #" << mp1 << endl;
2007 return kTRUE;
2008
2009 case kTXT_SAVE:
2010 cout << "Textview-Save #" << mp1 << endl;
2011 return kTRUE;
2012
2013 default:
2014 cout << "Textview: " << "Submsg:" << submsg << " Mp1=" << mp1 << " Mp2=" << mp2 << endl;
2015 }
2016#endif
2017 return kTRUE;
2018}
2019
2020// --------------------------------------------------------------------------
2021//
2022// Process the kC_USER messages
2023//
2024Bool_t MStatusDisplay::ProcessMessageUser(Long_t submsg, Long_t mp1, Long_t mp2)
2025{
2026 // kS_START, case sensitive | backward<<1, char *txt
2027 switch (submsg)
2028 {
2029 case kS_START:
2030 fLogBox->Search((char*)mp2, !(mp1&2>>1), mp1&1);
2031 return kTRUE;
2032#ifdef DEBUG
2033 default:
2034 cout << "User: " << "Submsg:" << submsg << " Mp1=" << mp1 << " Mp2=" << mp2 << endl;
2035#endif
2036 }
2037 return kTRUE;
2038}
2039
2040// --------------------------------------------------------------------------
2041//
2042// Process the messages from the GUI
2043//
2044Bool_t MStatusDisplay::ProcessMessage(Long_t msg, Long_t mp1, Long_t mp2)
2045{
2046 // Can be found in WidgetMessageTypes.h
2047#ifdef DEBUG
2048 cout << "Msg: " << GET_MSG(msg) << " Submsg:" << GET_SUBMSG(msg);
2049 cout << " Mp1=" << mp1 << " Mp2=" << mp2 << endl;
2050#endif
2051 switch (GET_MSG(msg))
2052 {
2053 case kC_COMMAND: // 1
2054 return ProcessMessageCommand(GET_SUBMSG(msg), mp1, mp2);
2055
2056 case kC_TEXTVIEW: // 9
2057 return ProcessMessageTextview(GET_SUBMSG(msg), mp1, mp2);
2058
2059 case kC_USER: // 1001
2060 return ProcessMessageUser(GET_SUBMSG(msg), mp1, mp2);
2061 }
2062#ifdef DEBUG
2063 cout << "Msg: " << GET_MSG(msg) << " Submsg:" << GET_SUBMSG(msg);
2064 cout << " Mp1=" << mp1 << " Mp2=" << mp2 << endl;
2065#endif
2066 return kTRUE;
2067}
2068
2069Bool_t MStatusDisplay::Close()
2070{
2071 // Got close message for this MainFrame. Calls parent CloseWindow()
2072 // (which destroys the window) and terminate the application.
2073 // The close message is generated by the window manager when its close
2074 // window menu item is selected.
2075
2076 // CloseWindow must be overwritten because otherwise CloseWindow
2077 // and the destructor are calling DestroyWindow which seems to be
2078 // in conflict with the TRootEmbeddedCanvas.
2079
2080 // FIXME: Make sure that the Status Display is deleted from every
2081 // where (eg Eventloop) first!
2082
2083 //gLog << dbg << fName << " is on heap: " << (int)IsOnHeap() << endl;
2084
2085 if (TestBit(kExitLoopOnExit) || TestBit(kExitLoopOnClose))
2086 {
2087 //gLog << dbg << "CloseWindow() calling ExitLoop." << endl;
2088 gSystem->ExitLoop();
2089 }
2090
2091 if (fIsLocked<=0 && IsOnHeap())
2092 return kTRUE;
2093
2094 fStatus = kFileExit;
2095 return kFALSE;
2096}
2097
2098void MStatusDisplay::CloseWindow()
2099{
2100 if (Close())
2101 delete this;
2102}
2103
2104// --------------------------------------------------------------------------
2105//
2106// Calls SetBit(kNoContextMenu) for all TCanvas objects found in the
2107// Tabs.
2108//
2109void MStatusDisplay::SetNoContextMenu(Bool_t flag)
2110{
2111 if (fIsLocked>1 || gROOT->IsBatch())
2112 return;
2113
2114 flag ? SetBit(kNoContextMenu) : ResetBit(kNoContextMenu);
2115
2116 for (int i=1; i<fTab->GetNumberOfTabs(); i++)
2117 {
2118 TCanvas *c = GetCanvas(i);
2119 if (c)
2120 flag ? c->SetBit(kNoContextMenu) : c->ResetBit(kNoContextMenu);
2121 }
2122}
2123
2124// --------------------------------------------------------------------------
2125//
2126// Update the memory display in the status bar
2127//
2128void MStatusDisplay::UpdateMemory() const
2129{
2130 const TString path = MString::Format("/proc/%d/status", gSystem->GetPid());
2131 if (gSystem->AccessPathName(path, kFileExists))
2132 return;
2133
2134 TEnv env(path);
2135 const UInt_t kb = env.GetValue("VmSize", 0);
2136 if (kb==0)
2137 return;
2138
2139 char type = 'k';
2140 Float_t val = kb;
2141
2142 if (val>999)
2143 {
2144 type = 'M';
2145 val /= 1000;
2146 }
2147 if (val>999)
2148 {
2149 type = 'G';
2150 val /= 1000;
2151 }
2152 const TString txt = MString::Format("%.1f%c", val, type);
2153 fStatusBar->SetText(txt, 2);
2154}
2155
2156// --------------------------------------------------------------------------
2157//
2158// Updates the canvas (if existing) in the currenly displayed Tab.
2159// The update intervall is controlled by StartUpdate and StopUpdate
2160//
2161Bool_t MStatusDisplay::HandleTimer(TTimer *timer)
2162{
2163 if (gROOT->IsBatch())
2164 return kTRUE;
2165
2166 UpdateMemory();
2167
2168 const Int_t c = fTab->GetCurrent();
2169
2170 // Skip Legend Tab
2171 if (c==0)
2172 return kTRUE;
2173
2174 // Update a canvas tab (if visible)
2175 if (timer==&fTimer && c!=fLogIdx)
2176 {
2177 UpdateTab(fTab->GetCurrentContainer());
2178 return kTRUE;
2179 }
2180
2181 // update the logbook tab (if visible)
2182 if (timer==&fLogTimer && c==fLogIdx)
2183 {
2184 fLog->UpdateGui();
2185
2186 /*
2187 if (!fLogBox->TestBit(kHasChanged))
2188 return kTRUE;
2189
2190 fLogBox->ResetBit(kHasChanged);
2191 */
2192 return kTRUE;
2193 }
2194
2195 return kTRUE;
2196}
2197
2198// --------------------------------------------------------------------------
2199//
2200// Find an object in a canvas (uses MStatusArray as helper)
2201//
2202void MStatusDisplay::PrintContent(Option_t *o) const
2203{
2204 MStatusArray(*this).Print(o);
2205}
2206
2207// --------------------------------------------------------------------------
2208//
2209// Find an object in a canvas (uses MStatusArray as helper)
2210//
2211TObject *MStatusDisplay::FindObjectInCanvas(const char *obj, const char *base, const char *canv) const
2212{
2213 return MStatusArray(*this).FindObjectInCanvas(obj, base, canv);
2214}
2215
2216// --------------------------------------------------------------------------
2217//
2218// Draws a clone of a canvas into a new canvas. Taken from TCanvas.
2219//
2220void MStatusDisplay::DrawClonePad(TCanvas &newc, TCanvas &oldc) const
2221{
2222 //copy pad attributes
2223 newc.Range(oldc.GetX1(),oldc.GetY1(),oldc.GetX2(),oldc.GetY2());
2224 newc.SetTickx(oldc.GetTickx());
2225 newc.SetTicky(oldc.GetTicky());
2226 newc.SetGridx(oldc.GetGridx());
2227 newc.SetGridy(oldc.GetGridy());
2228 newc.SetLogx(oldc.GetLogx());
2229 newc.SetLogy(oldc.GetLogy());
2230 newc.SetLogz(oldc.GetLogz());
2231 newc.SetBorderSize(oldc.GetBorderSize());
2232 newc.SetBorderMode(oldc.GetBorderMode());
2233 ((TAttLine&)oldc).Copy((TAttLine&)newc);
2234 ((TAttFill&)oldc).Copy((TAttFill&)newc);
2235 ((TAttPad&)oldc).Copy((TAttPad&)newc);
2236
2237 // This must be there: Otherwise GetDrawOption() won't work
2238 TVirtualPad *padsav = gPad;
2239 oldc.cd();
2240
2241 const Bool_t store = TH1::AddDirectoryStatus();
2242 TH1::AddDirectory(kFALSE);
2243
2244 //copy primitives
2245 TObject *obj;
2246 TIter next(oldc.GetListOfPrimitives());
2247 while ((obj=next()))
2248 {
2249 // Old line - I think it is not necessary anymore because of the cd()
2250 //gROOT->SetSelectedPad(&newc);
2251
2252 // Now make a clone of the object
2253 TObject *clone = obj->Clone();
2254
2255 // Clone also important bits (FIXME: Is this correct)
2256 clone->SetBit(obj->TestBits(kCannotPick|kNoContextMenu));
2257
2258 // Now make sure that the clones are deleted at a later time
2259 clone->SetBit(kCanDelete|kMustCleanup);
2260
2261 // FIXME: This is a workaround for the problem with the MAstroCatalog in
2262 // MHFalseSource. It doesn't harm. We'll still try to find the reason
2263 //if (clone->IsA()==TPad::Class())
2264 // gROOT->GetListOfCleanups()->Add(clone);
2265
2266 // Add the clone and its draw-option to the current pad
2267 TVirtualPad *save2 = gPad;
2268 gPad = &oldc; // Don't do this before Clone()!
2269 newc.GetListOfPrimitives()->Add(clone, obj->GetDrawOption());
2270 gPad = save2;
2271 }
2272 newc.Modified();
2273 newc.Update();
2274
2275 TH1::AddDirectory(store);
2276
2277 padsav->cd();
2278}
2279
2280// --------------------------------------------------------------------------
2281//
2282// Display the contexts of a TObjArray in the display (all canvases)
2283//
2284Bool_t MStatusDisplay::Display(const TObjArray &list, const char *tab)
2285{
2286 TIter Next(&list);
2287
2288 TObject *o=Next();
2289 if (!o)
2290 {
2291 *fLog << err << "MStatusDisplay::Display: No entry in TObjArray." << endl;
2292 return kFALSE;
2293 }
2294
2295 // The first entry in the list is a TNamed which is expected to
2296 // contain the status display title.
2297 fTitle = o->GetTitle();
2298
2299 TCanvas *c;
2300 while ((c=(TCanvas*)Next()))
2301 //if (!GetCanvas(c->GetName()))
2302 if (c->InheritsFrom(TCanvas::Class()))
2303 if (!tab || c->GetName()==(TString)tab)
2304 DrawClonePad(AddTab(c->GetName(), c->GetTitle()), *c);
2305
2306 return kTRUE;
2307}
2308
2309// --------------------------------------------------------------------------
2310//
2311// Reads the contents of a saved MStatusDisplay from a file.
2312//
2313Int_t MStatusDisplay::Read(const char *name, const char *tab)
2314{
2315 if (!gFile)
2316 {
2317 *fLog << warn << "MStatusDisplay::Read: No file found. Please create a TFile first." << endl;
2318 return 0;
2319 }
2320
2321 if (!gFile->IsOpen())
2322 {
2323 *fLog << warn << "MStatusDisplay::Read: File not open. Please open the TFile first." << endl;
2324 return 0;
2325 }
2326
2327 MStatusArray list;
2328
2329 const Int_t n = list.Read(name);
2330
2331 //
2332 // If no status display was found with this name try to find canvases
2333 // in the file and display them instead.
2334 //
2335 if (n==0)
2336 {
2337 // Either read the title from the file or create our own
2338 TNamed *n=0;
2339 gFile->GetObject("Title", n); // FIXME: Is the list allowed to take ownership?
2340 list.Add(n ? n : new TNamed(GetName(), GetTitle()));
2341
2342 const Bool_t store = TH1::AddDirectoryStatus();
2343 TH1::AddDirectory(kFALSE);
2344
2345 TIter Next(gFile->GetListOfKeys());
2346 TObject *key = 0;
2347 while ((key=Next()))
2348 {
2349 MStatusArray *arr=0;
2350 gFile->GetObject(key->GetName(), arr);
2351 if (arr)
2352 {
2353 Display(*arr, tab);
2354 n++;
2355 continue;
2356 }
2357
2358 if (tab && key->GetName()!=(TString)tab)
2359 continue;
2360
2361 TCanvas *c=0;
2362 gFile->GetObject(key->GetName(), c);
2363
2364 // If key doesn't correspond to a TCanvas create a new canvas
2365 // and draw the object itself instead.
2366 if (!c)
2367 {
2368 TObject *obj = gFile->Get(key->GetName());
2369
2370 if (MParContainer::Overwrites(TObject::Class(), *obj, "Draw") ||
2371 MParContainer::Overwrites(TObject::Class(), *obj, "Paint"))
2372 {
2373 AddTab(key->GetName(), key->GetTitle());
2374 obj->SetBit(kCanDelete);
2375 obj->Draw();
2376 }
2377 // FIXME: Is the object deleted?
2378 continue;
2379 }
2380
2381 // Add the canvas to the list
2382 c->SetTitle(gFile->GetName());
2383 list.Add(c);
2384 }
2385
2386 TH1::AddDirectory(store);
2387
2388 if (list.GetEntries()<=1)
2389 {
2390 *fLog << warn << "MStatusDisplay::Read: No drawable objects read from " << gFile->GetName() << endl;
2391 return 0;
2392 }
2393
2394 *fLog << inf << "MStatusDisplay: " << list.GetEntries()-1 << " canvases directly read from file." << endl;
2395 }
2396
2397
2398 if (!Display(list, tab))
2399 {
2400 *fLog << err << "MStatusDisplay::Display: No entries found." << endl;
2401 return 0;
2402 }
2403
2404 if (n==0)
2405 return list.GetEntries();
2406
2407 *fLog << inf << "MStatusDisplay: Key " << name << " with " << n << " keys read from file." << endl;
2408 return n;
2409}
2410
2411// --------------------------------------------------------------------------
2412//
2413// Add all canvases to the MStatusArray
2414//
2415void MStatusDisplay::FillArray(MStatusArray &list, Int_t num) const
2416{
2417 Int_t from, to;
2418 GetCanvasRange(from, to, num);
2419
2420 TCanvas *c;
2421 for (int i=from; i<to; i++)
2422 if ((c = GetCanvas(i)))
2423 list.Add(c);
2424}
2425
2426// --------------------------------------------------------------------------
2427//
2428// Writes the contents of a MStatusDisplay to a file.
2429//
2430Int_t MStatusDisplay::Write(Int_t num, const char *name, Option_t *opt) const
2431{
2432 if (!gFile)
2433 {
2434 *fLog << warn << "MStatusDisplay::Write: No file found. Please create a TFile first." << endl;
2435 return 0;
2436 }
2437
2438 if (!gFile->IsOpen())
2439 {
2440 *fLog << warn << "MStatusDisplay::Write: File not open. Please open the TFile first." << endl;
2441 return 0;
2442 }
2443
2444 if (!gFile->IsWritable())
2445 {
2446 *fLog << warn << "MStatusDisplay::Write: File not writable." << endl;
2447 return 0;
2448 }
2449
2450 if (num==0)
2451 {
2452 *fLog << warn << "MStatusDisplay::Write: Tab doesn't contain an embedded Canvas... skipped." << endl;
2453 return 0;
2454 }
2455
2456 if (!gROOT->IsBatch() && num>=fTab->GetNumberOfTabs())
2457 {
2458 *fLog << warn << "MStatusDisplay::Write: Tab doesn't exist... skipped." << endl;
2459 return 0;
2460 }
2461 if (gROOT->IsBatch() && num>fBatch->GetSize())
2462 {
2463 *fLog << warn << "MStatusDisplay::Write: Tab doesn't exist... skipped." << endl;
2464 return 0;
2465 }
2466
2467 Int_t n = 0; // Number of keys written
2468
2469 TNamed named("Title", fTitle.Data());
2470
2471 if (TString(opt)=="plain")
2472 {
2473 // Get canvas range to store
2474 Int_t from, to;
2475 GetCanvasRange(from, to, num);
2476
2477 n += named.Write();
2478
2479 TCanvas *c;
2480 for (int i=from; i<to; i++)
2481 if ((c = GetCanvas(i)))
2482 n += c->Write();
2483 }
2484 else
2485 {
2486 // Be careful: So far Display() assumes that the TNamed
2487 // is the first entry in the list
2488 MStatusArray list;
2489 list.Add(&named);
2490
2491 FillArray(list, num);
2492
2493 n += list.Write(name, kSingleKey);
2494 }
2495
2496 *fLog << inf << "MStatusDisplay: " << n << " keys written to file as key " << name << "." << endl;
2497
2498 return n;
2499}
2500
2501// --------------------------------------------------------------------------
2502//
2503// Use this to start the synchronous (GUI eventloop driven) tab update.
2504// Can also be used to change the update intervall. If millisec<0
2505// the intervall given in SetUpdateTime is used. If the intervall in
2506// SetUpdateTime is <0 nothing is done. (Call SetUpdateTime(-1) to
2507// disable the automatic update in a MEventloop.
2508//
2509void MStatusDisplay::StartUpdate(Int_t millisec)
2510{
2511 if (fIsLocked>1)
2512 return;
2513
2514 if (fTimer.GetTime()<TTime(0))
2515 return;
2516 fTimer.Start(millisec);
2517}
2518
2519// --------------------------------------------------------------------------
2520//
2521// Stops the automatic GUI update
2522//
2523void MStatusDisplay::StopUpdate()
2524{
2525 if (fIsLocked>1)
2526 return;
2527
2528 fTimer.Stop();
2529}
2530
2531// --------------------------------------------------------------------------
2532//
2533// Set the update interval for the GUI update, see StartUpdate.
2534//
2535void MStatusDisplay::SetUpdateTime(Long_t t)
2536{
2537 fTimer.SetTime(t);
2538}
2539
2540// --------------------------------------------------------------------------
2541//
2542// If the filename name doesn't end with ext, ext is added to the end.
2543// If name.IsNull() "status" is assumed and the a number (>0) is added
2544// as "status-6".
2545// The extension is returned.
2546//
2547const TString &MStatusDisplay::AddExtension(TString &name, const TString &ext, Int_t num) const
2548{
2549 if (name.IsNull())
2550 {
2551 name = gROOT->GetName();
2552 if (num>0)
2553 {
2554 name += "-";
2555 name += num;
2556 }
2557 }
2558
2559 if (name.EndsWith("."+ext))
2560 return ext;
2561
2562 name += ".";
2563 name += ext;
2564
2565 return ext;
2566}
2567
2568Bool_t MStatusDisplay::CheckTabForCanvas(int num) const
2569{
2570 if (gROOT->IsBatch())
2571 return (num>0 && num<=fBatch->GetSize()) || num<0;
2572
2573 if (num>=fTab->GetNumberOfTabs())
2574 {
2575 *fLog << warn << "Tab #" << num << " doesn't exist..." << endl;
2576 return kFALSE;
2577 }
2578 if (num==0)
2579 {
2580 *fLog << warn << "Tab #" << num << " doesn't contain an embedded canvas..." << endl;
2581 return kFALSE;
2582 }
2583 if (fTab->GetNumberOfTabs()<2 || !gPad)
2584 {
2585 *fLog << warn << "Sorry, you must have at least one existing canvas (gPad!=NULL)" << endl;
2586 return kFALSE;
2587 }
2588 return kTRUE;
2589}
2590
2591// --------------------------------------------------------------------------
2592//
2593// Insert the following two lines into the postscript header:
2594//
2595// %%DocumentPaperSizes: a4
2596// %%Orientation: Landscape
2597//
2598void MStatusDisplay::UpdatePSHeader(const TString &name) const
2599{
2600 const TString newstr("%%DocumentPaperSizes: a4\n%%Orientation: Landscape\n");
2601
2602 TString tmp(name+"XXXXXX");
2603
2604 // FIXME: Use mkstemp instead
2605 if (!mktemp(const_cast<char*>(tmp.Data())))
2606 {
2607 *fLog << err << "ERROR - MStatusDisplay::UpdatePSHeader: mktemp failed." << endl;
2608 return;
2609 }
2610
2611 ifstream fin(name);
2612 ofstream fout(tmp);
2613 if (!fout)
2614 {
2615 *fLog << err << "Cannot open file " << name << ": " << strerror(errno) << endl;
2616 return;
2617 }
2618
2619 char c;
2620
2621 TString str;
2622 fin >> str >> c; // Read "%!PS-Adobe-2.0\n"
2623 fout << str << endl << newstr;
2624
2625 // Doing it in blocks seems not to gain much for small (MB) files
2626 while (fin)
2627 {
2628 fin.read(&c, 1);
2629 fout.write(&c, 1);
2630 }
2631
2632 gSystem->Unlink(name);
2633 gSystem->Rename(tmp, name);
2634}
2635
2636// --------------------------------------------------------------------------
2637//
2638void MStatusDisplay::PSToolsRange(TVirtualPS &vps, Float_t psw, Float_t psh) const
2639{
2640 if (vps.InheritsFrom(TPostScript::Class()))
2641 static_cast<TPostScript&>(vps).Range(psw, psh);
2642 // if (vps.InheritsFrom(TPDF::Class()))
2643 // static_cast<TPDF&>(vps).Range(psw*0.69, psh*0.69);
2644 // if (vps.InheritsFrom(TSVG::Class()))
2645 // static_cast<TSVG&>(vps).Range(psw, psh);
2646}
2647
2648// --------------------------------------------------------------------------
2649//
2650void MStatusDisplay::PSToolsTextNDC(TVirtualPS &vps, Double_t u, Double_t v, const char *string) const
2651{
2652 if (vps.InheritsFrom(TPostScript::Class()))
2653 static_cast<TPostScript&>(vps).TextNDC(u, v, string);
2654 if (vps.InheritsFrom(TPDF::Class()))
2655 static_cast<TPDF&>(vps).TextNDC(u, v, string);
2656 // if (vps.InheritsFrom(TSVG::Class()))
2657 // static_cast<TSVG&>(vps).TextNDC(u, v, string);
2658}
2659
2660// --------------------------------------------------------------------------
2661//
2662Int_t MStatusDisplay::InitWriteDisplay(Int_t num, TString &name, const TString &ext)
2663{
2664 SetStatusLine1(MString::Format("Writing %s file...",ext.Data()));
2665 SetStatusLine2("Please be patient!");
2666
2667 if (!CheckTabForCanvas(num))
2668 {
2669 SetStatusLine2("Failed!");
2670 return 0;
2671 }
2672
2673 AddExtension(name, ext, num);
2674
2675 if (num<0)
2676 *fLog << inf << "Open " << ext << "-File: " << name << endl;
2677
2678 return num;
2679}
2680
2681// --------------------------------------------------------------------------
2682//
2683TCanvas *MStatusDisplay::InitWriteTab(Int_t num, TString &name)
2684{
2685 const Int_t i = TMath::Abs(num);
2686
2687 TCanvas *c = GetCanvas(i);
2688 if (!c)
2689 {
2690 if (num<0)
2691 *fLog << inf << " - ";
2692 *fLog << "Tab #" << i << " doesn't contain an embedded Canvas... skipped." << endl;
2693 return 0;
2694 }
2695
2696 SetStatusLine2(MString::Format("Tab #%d", i));
2697
2698 //
2699 // Paint canvas into root file
2700 //
2701 if (num<0 && !name.IsNull())
2702 {
2703 Bool_t found = kFALSE;
2704 if (name.Index("%%%%name%%%%")>=0)
2705 {
2706 name.ReplaceAll("%%name%%", c->GetName());
2707 found = kTRUE;
2708 }
2709
2710 if (name.Index("%%%%title%%%%")>=0)
2711 {
2712 name.ReplaceAll("%%title%%", c->GetTitle());
2713 found = kTRUE;
2714 }
2715
2716 if (name.Index("%%%%tab%%%%")>=0)
2717 {
2718 name.ReplaceAll("%%tab%%", MString::Format("%d", i));
2719 found = kTRUE;
2720 }
2721
2722 if (!found)
2723 name.Insert(name.Last('.'), MString::Format("-%d", i));
2724 }
2725
2726 if (num<0)
2727 *fLog << inf << " - ";
2728 *fLog << inf << "Writing Tab #" << i;
2729
2730 if (!name.IsNull())
2731 *fLog << " to " << name;
2732
2733 *fLog << ": " << c->GetName() << "... " << flush;
2734
2735 return c;
2736}
2737
2738// This is a stupid workaround to get rid of the damned clipping
2739// of the text. Who the hell needs clipping?
2740class MyCanvas : public TCanvas
2741{
2742public:
2743 void Scale(Double_t val)
2744 {
2745 fAbsXlowNDC = -val;
2746 fAbsYlowNDC = -val;
2747 fAbsWNDC = 1+2*val;
2748 fAbsHNDC = 1+2*val;
2749 }
2750};
2751
2752// --------------------------------------------------------------------------
2753//
2754// Write some VGF (vector graphics format). Currently PS, PDF and SVG
2755// is available. Specified by ext.
2756//
2757// In case of num<0 all tabs are written into the VGF file. If num>0
2758// the canvas in the corresponding tab is written to the file.
2759// Name is the name of the file (with or without extension).
2760//
2761// Returns the number of pages written.
2762//
2763// To write all tabs you can also use SaveAsVGF(name, ext)
2764//
2765// If the third argument is given a bottom line is drawn with the text
2766// under it. If no argument is given a bottom line is drawn if
2767// fTitle (SetTitle) is not empty.
2768//
2769Int_t MStatusDisplay::SaveAsVGF(Int_t num, TString name, const TString addon, const TString ext)
2770{
2771 num = InitWriteDisplay(num, name, ext);
2772 if (num==0)
2773 return 0;
2774
2775 TPad *padsav = (TPad*)gPad;
2776 TVirtualPS *psave = gVirtualPS;
2777
2778 TDatime d;
2779
2780 Int_t type = -1;
2781
2782 TVirtualPS *ps =0;
2783 if (!ext.CompareTo("ps", TString::kIgnoreCase))
2784 {
2785 gStyle->SetColorModelPS(1);
2786 ps = new TPostScript(name, 112);
2787 type = 1;
2788 }
2789 if (!ext.CompareTo("pdf", TString::kIgnoreCase))
2790 {
2791 ps = new TPDF(name, 112);
2792 type = 2;
2793 }
2794 if (!ext.CompareTo("svg", TString::kIgnoreCase))
2795 {
2796 ps = new TSVG(name, 112);
2797 type = 3;
2798 }
2799
2800 if (!ps)
2801 {
2802 *fLog << err << "Extension " << ext << " unknown..." << endl;
2803 SetStatusLine2("Failed!");
2804 return 0;
2805 }
2806
2807 ps->SetBit(TPad::kPrintingPS);
2808 if (type==1)
2809 ps->PrintFast(13, "/nan {1} def ");
2810
2811 gVirtualPS = ps;
2812
2813 //
2814 // Create some GUI elements for a page legend
2815 //
2816 TLine line;
2817
2818 int page = 1;
2819
2820 //
2821 // Maintain tab numbers
2822 //
2823 Int_t from, to;
2824 GetCanvasRange(from, to, num);
2825
2826 for (int i=from; i<to; i++)
2827 {
2828 TCanvas *c = InitWriteTab(num<0?-i:i);
2829 if (c==0)
2830 continue;
2831
2832 //
2833 // Init page and page size, make sure, that the canvas in the file
2834 // has the same Aspect Ratio than on the screen.
2835 //
2836 if (type==1 || i>from)
2837 ps->NewPage();
2838
2839 //
2840 // 28 is used here to scale the canvas into a height of 28,
2841 // such that the page title can be set above the canvas...
2842 //
2843 Float_t psw = 28.0; // A4 - width (29.7)
2844 Float_t psh = 21.0; // A4 - height (21.0)
2845
2846 const Float_t cw = c->GetWw();
2847 const Float_t ch = c->GetWh();
2848
2849 if (psw/psh>cw/ch)
2850 psw = cw/ch*psh;
2851 else
2852 psh = ch/cw*psw;
2853
2854 PSToolsRange(*ps, psw, psh);
2855
2856 //
2857 // Clone canvas and change background color and schedule for
2858 // deletion
2859 //
2860
2861 //const Bool_t store = c->IsBatch();
2862 //c->SetBatch(kTRUE);
2863 c->Paint();
2864 //c->SetBatch(store);
2865
2866 //
2867 // Change/fix the canvas coordinate system for the overlaying text.
2868 // This is necessary because root clip everything away which is
2869 // outside a predefined area, which is (0,0)/(1,1)
2870 //
2871 const Double_t height = 0.015; // Text height
2872 const Double_t off = 0.005; // Line offset from text
2873
2874 const Double_t bot = height+off;
2875 const Double_t top = 1-bot;
2876
2877 static_cast<MyCanvas*>(c)->Scale(bot);
2878
2879 // If gPad is not set to c all follwing commands will
2880 // get the wrong numbers for alignment
2881 gPad = c;
2882
2883 // Separator Lines
2884 line.PaintLineNDC(0.01, top, 0.99, top);
2885 line.PaintLineNDC(0.01, bot, 0.99, bot);
2886
2887 //
2888 // Print overlaying text (NDC = %)
2889 //
2890 // align phi col font size (11=left top)
2891 const TString txt(addon.IsNull() ? fTitle : addon);
2892
2893 // Text Attributes
2894 TAttText(11, 0, kBlack, 22, height).Copy(*ps);
2895
2896 // Text on top
2897 ps->SetTextAlign(11); // left bottom
2898 PSToolsTextNDC(*ps, 0.01, top+off, c->GetName());
2899
2900 ps->SetTextAlign(21); // cent bottom
2901 PSToolsTextNDC(*ps, 0.50, top+off, TString("MARS V"MARSVER" - Modular Analysis and Reconstruction Software - ")+d.AsString());
2902
2903 ps->SetTextAlign(31); // right bottom
2904 PSToolsTextNDC(*ps, 0.99, top+off, MString::Format("Page No.%i (%i)", page++, i));
2905
2906 // Text on bottom
2907 ps->SetTextAlign(13); // left top
2908 PSToolsTextNDC(*ps, 0.01, bot-off, c->GetTitle());
2909
2910 ps->SetTextAlign(23); // cent top
2911 PSToolsTextNDC(*ps, 0.50, bot-off, txt);
2912
2913 ps->SetTextAlign(33); // right top
2914 PSToolsTextNDC(*ps, 0.99, bot-off, MString::Format("(c) 2000-%d, Thomas Bretz", TDatime().GetYear()));
2915
2916 static_cast<MyCanvas*>(c)->Scale(0);
2917
2918 //
2919 // Finish drawing page
2920 //
2921 *fLog << "done." << endl;
2922 }
2923
2924 gPad = NULL; // Important!
2925
2926 ps->Close();
2927 delete ps;
2928
2929#if ROOT_VERSION_CODE < ROOT_VERSION(5,12,00)
2930 if (type==1)
2931 {
2932 SetStatusLine2("Updating header of PS file...");
2933
2934 if (num<0)
2935 *fLog << inf3 << " - Updating header of PS file... " << flush;
2936 UpdatePSHeader(name);
2937 if (num<0)
2938 *fLog << inf3 << "done." << endl;
2939 }
2940#endif
2941
2942 gVirtualPS = psave;
2943 if (padsav)
2944 padsav->cd();
2945
2946 if (num<0)
2947 *fLog << inf << "done." << endl;
2948
2949 SetStatusLine2(MString::Format("Done (%dpages)", page-1));
2950
2951 return page-1;
2952}
2953
2954// --------------------------------------------------------------------------
2955//
2956Bool_t MStatusDisplay::SaveAsImage(Int_t num, TString name, TImage::EImageFileTypes type)
2957{
2958#if ROOT_VERSION_CODE < ROOT_VERSION(5,12,00)
2959 if (gROOT->IsBatch())
2960 {
2961 *fLog << warn << "Sorry, writing image-files is not available in batch mode." << endl;
2962 return 0;
2963 }
2964#endif
2965
2966 TString ext;
2967 switch (type)
2968 {
2969 case TImage::kXpm:
2970 case TImage::kZCompressedXpm: ext = "xpm"; break;
2971 case TImage::kPng: ext = "png"; break;
2972 case TImage::kJpeg: ext = "jpg"; break;
2973 case TImage::kGif: ext = "gif"; break;
2974 case TImage::kTiff: ext = "tiff"; break;
2975 case TImage::kBmp: ext = "bmp"; break;
2976 case TImage::kXml: ext = "xml"; break;
2977 //case TImage::kGZCompressedXpm: ext = "xpm.gz"; break;
2978 //case TImage::kPpm: ext = "ppm"; break;
2979 //case TImage::kPnm: ext = "pnm"; break;
2980 //case TImage::kIco: ext = "ico"; break;
2981 //case TImage::kCur: ext = "cur"; break;
2982 //case TImage::kXcf: ext = "xcf"; break;
2983 //case TImage::kXbm: ext = "xbm"; break;
2984 //case TImage::kFits: ext = "fits"; break;
2985 //case TImage::kTga: ext = "tga"; break;
2986 default:
2987 *fLog << warn << "Sorry, unknown or unsupported file type..." << endl;
2988 return 0;
2989 }
2990
2991 num = InitWriteDisplay(num, name, ext);
2992 if (num==0)
2993 return 0;
2994
2995 TPad *padsav = (TPad*)gPad;
2996
2997 Int_t counter = 0;
2998
2999 //
3000 // Maintain tab numbers
3001 //
3002 Int_t from, to;
3003 GetCanvasRange(from, to, num);
3004
3005 for (int i=from; i<to; i++)
3006 {
3007 TString writename(name);
3008
3009 TCanvas *c = InitWriteTab(num<0 ? -i : i, writename);
3010 if (!c)
3011 continue;
3012
3013 //
3014 // Paint canvas into root file
3015 //
3016
3017 // TImage *img = TImage::Create();
3018 // img->FromPad(c);
3019 // img->WriteImage(writename, type);
3020 // delete img;
3021
3022 // FIXME: Not all file types are supported by Print()
3023 c->Print(writename);
3024
3025 if (num<0)
3026 *fLog << "done." << endl;
3027
3028 counter++;
3029 }
3030
3031 if (padsav)
3032 padsav->cd();
3033
3034 *fLog << inf << "done." << endl;
3035
3036 SetStatusLine2("Done.");
3037
3038 return counter>0;
3039}
3040
3041// --------------------------------------------------------------------------
3042//
3043Bool_t MStatusDisplay::SaveAsC(Int_t num, TString name)
3044{
3045 num = InitWriteDisplay(num, name, "C");
3046 if (num==0)
3047 return kFALSE;
3048
3049 TPad *padsav = (TPad*)gPad;
3050
3051 Int_t counter = 0;
3052
3053 //
3054 // Maintain tab numbers
3055 //
3056 Int_t from, to;
3057 GetCanvasRange(from, to, num);
3058
3059 for (int i=from; i<to; i++)
3060 {
3061 TString writename(name);
3062
3063 TCanvas *c = InitWriteTab(num<0 ? -i : i, writename);
3064 if (!c)
3065 continue;
3066
3067 //
3068 // Clone canvas and change background color and schedule for
3069 // deletion
3070 //
3071 c->SaveSource(writename, "");
3072
3073 if (num<0)
3074 *fLog << "done." << endl;
3075
3076 counter++;
3077 }
3078
3079 if (padsav)
3080 padsav->cd();
3081
3082 *fLog << inf << "done." << endl;
3083
3084 SetStatusLine2("Done.");
3085
3086 return counter>0;
3087}
3088
3089// --------------------------------------------------------------------------
3090//
3091// In case of num<0 all tabs are written into a root file. As plain
3092// TCanvas objects if plain==kTRUE otherwise in a MStatusArray. If num>0
3093// the canvas in the corresponding tab is written to the file.
3094// Name is the name of the file (with or without extension).
3095//
3096// Returns the number of keys written.
3097//
3098// To write all tabs you can also use SaveAsRoot(name)
3099//
3100Int_t MStatusDisplay::SaveAsRoot(Int_t num, TString name, Bool_t plain)
3101{
3102 num = InitWriteDisplay(num, name, "root");
3103 if (num==0)
3104 return -1;
3105
3106 TFile *fsave = gFile;
3107 TFile file(name, "RECREATE", GetTitle(), 9);
3108 const Int_t keys = Write(num, "MStatusDisplay", plain ? "plain" : "");
3109 gFile = fsave;
3110
3111 SetStatusLine2("Done.");
3112
3113 return keys;
3114}
3115
3116// --------------------------------------------------------------------------
3117//
3118Bool_t MStatusDisplay::SaveAsCSV(Int_t num, TString name, Char_t delim)
3119{
3120 num = InitWriteDisplay(num, name, "csv");
3121 if (num==0)
3122 return kFALSE;
3123
3124 gSystem->ExpandPathName(name);
3125
3126 ofstream fout(name);
3127 if (!fout)
3128 {
3129 *fLog << err << "Cannot open file " << name << ": " << strerror(errno) << endl;
3130 return kFALSE;
3131 }
3132
3133 fout << 0 << delim << GetName() << delim << GetTitle() << endl;
3134
3135 Int_t from, to;
3136 GetCanvasRange(from, to, num);
3137
3138 for (int i=from; i<to; i++)
3139 {
3140 TCanvas *c;
3141 if (!(c = GetCanvas(i)))
3142 {
3143 if (num<0)
3144 *fLog << inf << " - ";
3145 *fLog << "Tab #" << i << " doesn't contain an embedded Canvas... skipped." << endl;
3146 continue;
3147 }
3148
3149 fout << i << delim << c->GetName() << delim << c->GetTitle() << endl;
3150 }
3151
3152 SetStatusLine2("Done.");
3153
3154 return kTRUE;
3155}
3156
3157/*
3158Bool_t MStatusDisplay::SaveAsCSV(Int_t num, TString name)
3159{
3160 num = InitWriteDisplay(num, name, "csv");
3161 if (num==0)
3162 return kFALSE;
3163
3164 gSystem->ExpandPathName(name);
3165
3166 ofstream fout(name);
3167 if (!fout)
3168 {
3169 *fLog << err << "Cannot open file " << name << ": " << strerror(errno) << endl;
3170 return kFALSE;
3171 }
3172
3173 fout << "<?xml version=\"1.0\"?>" << endl;
3174 fout << "<display name='" << GetName() << "'>" << endl;
3175 fout << " <file>" << name << "</file>" << endl;
3176 fout << " <status>" << endl;
3177 fout << " <name>" << GetName() << "</name>" << endl;
3178 fout << " <title>" << GetTitle() << "</title>" << endl;
3179 fout << " </status>" << endl;
3180 fout << " <tabs>" << endl;
3181
3182 fout << 0 << delim << GetName() << delim << GetTitle() << endl;
3183
3184 Int_t from, to;
3185 GetCanvasRange(from, to, num);
3186
3187 for (int i=from; i<to; i++)
3188 {
3189 TCanvas *c;
3190 if (!(c = GetCanvas(i)))
3191 {
3192 if (num<0)
3193 *fLog << inf << " - ";
3194 *fLog << "Tab #" << i << " doesn't contain an embedded Canvas... skipped." << endl;
3195 continue;
3196 }
3197
3198 fout << " <tab index='" << i << "'>" << endl;
3199 fout << " <index>" << i << "</index>" << endl;
3200 fout << " <name>" << c->GetName() << "</name>" << endl;
3201 fout << " <title>" << c->GetName() << "</title>" << endl;
3202 fout << " </tab>" << endl;
3203 }
3204
3205 fout << " </tabs>" << endl;
3206 fout << "</display>" << endl;
3207
3208 SetStatusLine2("Done.");
3209
3210 return kTRUE;
3211}
3212*/
3213
3214// --------------------------------------------------------------------------
3215//
3216void MStatusDisplay::SaveAs(const char *c, const Option_t *o) const
3217{
3218#if ROOT_VERSION_CODE >= ROOT_VERSION(5,18,00)
3219 TGObject::SaveAs(c, o);
3220#endif
3221}
3222
3223// --------------------------------------------------------------------------
3224//
3225// Determin File type to save file as by extension. Allowed extensions are:
3226// root, ps, pdf, svg, gif, png, jpg, xpm, C
3227//
3228// returns -1 if file type is unknown. Otherwise return value of SaveAs*
3229//
3230Int_t MStatusDisplay::SaveAs(Int_t num, TString name)
3231{
3232 if (name.EndsWith(".root")) return SaveAsRoot(num, name); // kFileSaveAsRoot
3233 if (name.EndsWith(".ps")) return SaveAsPS(num, name); // kFileSaveAsPS
3234 if (name.EndsWith(".pdf")) return SaveAsPDF(num, name); // kFileSaveAsPDF
3235 if (name.EndsWith(".svg")) return SaveAsSVG(num, name); // kFileSaveAsSVG
3236 if (name.EndsWith(".gif")) return SaveAsGIF(num, name); // kFileSaveAsGIF
3237 if (name.EndsWith(".png")) return SaveAsPNG(num, name); // kFileSaveAsPNG
3238 if (name.EndsWith(".bmp")) return SaveAsBMP(num, name); // kFileSaveAsBMP
3239 if (name.EndsWith(".xml")) return SaveAsXML(num, name); // kFileSaveAsXML
3240 if (name.EndsWith(".jpg")) return SaveAsJPG(num, name); // kFileSaveAsJPG
3241 if (name.EndsWith(".xpm")) return SaveAsXPM(num, name); // kFileSaveAsXPM
3242 if (name.EndsWith(".csv")) return SaveAsCSV(num, name); // kFileSaveAsCSV
3243 if (name.EndsWith(".tiff")) return SaveAsTIFF(num, name); // kFileSaveAsTIFF
3244 if (name.EndsWith(".C")) return SaveAsC(num, name); // kFileSaveAsC
3245 return -1;
3246}
3247
3248// --------------------------------------------------------------------------
3249//
3250// Opens a save as dialog
3251//
3252Int_t MStatusDisplay::SaveAs(Int_t num)
3253{
3254 static const char *gSaveAsTypes[] =
3255 {
3256 "PostScript", "*.ps",
3257 "Acrobat pdf", "*.pdf",
3258 "SVG vector", "*.svg",
3259 "Gif files", "*.gif",
3260 "Png files", "*.png",
3261 "Gif files", "*.gif",
3262 "Jpeg files", "*.jpeg",
3263 "Xpm files", "*.xpm",
3264 "Bmp files", "*.bmp",
3265 "Xml files", "*.xml",
3266 "Tiff files", "*.tiff",
3267 "Csv files", "*.csv",
3268 "Macro files", "*.C",
3269 "ROOT files", "*.root",
3270 "All files", "*",
3271 NULL, NULL
3272 };
3273
3274 static TString dir(".");
3275
3276 TGFileInfo fi; // fFileName and fIniDir deleted in ~TGFileInfo
3277
3278 fi.fFileTypes = (const char**)gSaveAsTypes;
3279 fi.fIniDir = StrDup(dir);
3280
3281 new TGFileDialog(fClient->GetRoot(), this, kFDSave, &fi);
3282
3283 if (!fi.fFilename)
3284 return 0;
3285
3286 dir = fi.fIniDir;
3287
3288 const Int_t rc = SaveAs(num, fi.fFilename);
3289 if (rc>=0)
3290 return rc;
3291
3292 Warning("MStatusDisplay::SaveAs", "Unknown Extension: %s", fi.fFilename);
3293 return 0;
3294}
3295
3296// --------------------------------------------------------------------------
3297//
3298// Open contents of a MStatusDisplay with key name from file fname.
3299//
3300Int_t MStatusDisplay::Open(TString fname, const char *name)
3301{
3302 TFile file(fname, "READ");
3303 if (file.IsZombie())
3304 {
3305 gLog << warn << "WARNING - Cannot open file " << fname << endl;
3306 return 0;
3307 }
3308
3309 return Read(name);
3310}
3311
3312// --------------------------------------------------------------------------
3313//
3314// Opens an open dialog
3315//
3316Int_t MStatusDisplay::Open()
3317{
3318 static const char *gOpenTypes[] =
3319 {
3320 "ROOT files", "*.root",
3321 "All files", "*",
3322 NULL, NULL
3323 };
3324
3325 static TString dir(".");
3326
3327 TGFileInfo fi; // fFileName and fIniDir deleted in ~TGFileInfo
3328
3329 fi.fFileTypes = (const char**)gOpenTypes;
3330 fi.fIniDir = StrDup(dir);
3331
3332 new TGFileDialog(fClient->GetRoot(), this, kFDOpen, &fi);
3333
3334 if (!fi.fFilename)
3335 return 0;
3336
3337 dir = fi.fIniDir;
3338
3339 return Open(fi.fFilename);
3340}
3341
3342// --------------------------------------------------------------------------
3343//
3344// Change width of display. The height is calculated accordingly.
3345//
3346void MStatusDisplay::SetDisplayWidth(UInt_t dw)
3347{
3348 if (gROOT->IsBatch())
3349 {
3350 SetCanvasWidth(dw);
3351 return;
3352 }
3353
3354 // 4 == 2*default border with of canvas
3355 dw -= 4;
3356
3357 // Difference between canvas size and display size
3358 const UInt_t cw = GetWidth() -fTab->GetWidth();
3359 const UInt_t ch = GetHeight()-fTab->GetHeight()+fTab->GetTabHeight();
3360
3361 const UInt_t dh = TMath::Nint((dw - cw)/1.5 + ch);
3362
3363 Resize(dw, dh); // Set display size
3364}
3365
3366// --------------------------------------------------------------------------
3367//
3368// Change height of display. The width is calculated accordingly.
3369//
3370void MStatusDisplay::SetDisplayHeight(UInt_t dh)
3371{
3372 if (gROOT->IsBatch())
3373 {
3374 SetCanvasHeight(dh);
3375 return;
3376 }
3377
3378 // 4 == 2*default border with of canvas
3379 dh -= 4;
3380
3381 // Difference between canvas size and display size
3382 const UInt_t cw = GetWidth() -fTab->GetWidth();
3383 const UInt_t ch = GetHeight()-fTab->GetHeight()+fTab->GetTabHeight();
3384
3385 const UInt_t dw = TMath::Nint((dh - ch)*1.5 + cw);
3386
3387 Resize(dw, dh); // Set display size
3388}
3389
3390// --------------------------------------------------------------------------
3391//
3392// Change width of canvas. The height is calculated accordingly.
3393//
3394void MStatusDisplay::SetCanvasWidth(UInt_t w)
3395{
3396 // 4 == 2*default border with of canvas
3397 w += 4;
3398
3399 if (gROOT->IsBatch())
3400 {
3401 Resize(w, 3*w/2);
3402 return;
3403 }
3404
3405 // Difference between canvas size and display size
3406 const UInt_t cw = GetWidth() -fTab->GetWidth();
3407 const UInt_t ch = GetHeight()-fTab->GetHeight()+fTab->GetTabHeight();
3408
3409 const UInt_t h = TMath::Nint(w/1.5 + ch);
3410
3411 Resize(w + cw, h); // Set display size
3412}
3413
3414// --------------------------------------------------------------------------
3415//
3416// Change height of canvas. The width is calculated accordingly.
3417//
3418void MStatusDisplay::SetCanvasHeight(UInt_t h)
3419{
3420 // 4 == 2*default border with of canvas
3421 h += 4;
3422
3423 if (gROOT->IsBatch())
3424 {
3425 Resize(2*h/3, h);
3426 return;
3427 }
3428
3429 // Difference between canvas size and display size
3430 const UInt_t cw = GetWidth() -fTab->GetWidth();
3431 const UInt_t ch = GetHeight()-fTab->GetHeight()+fTab->GetTabHeight();
3432
3433 // 4 == 2*default border with of canvas
3434 const UInt_t dw = TMath::Nint((h+4)*1.5 + cw);
3435
3436 Resize(dw, h + ch); // Set display size
3437}
3438
3439// --------------------------------------------------------------------------
3440//
3441// Calculate width and height of the display such that it fits into the
3442// defined box.
3443//
3444void MStatusDisplay::SetDisplaySize(UInt_t w, UInt_t h)
3445{
3446 if (gROOT->IsBatch())
3447 return;
3448
3449 SetDisplayHeight(h);
3450
3451 if (GetWidth()>w)
3452 SetDisplayWidth(w);
3453}
3454
3455// --------------------------------------------------------------------------
3456//
3457// Calculate an optimum size for the display from the desktop size
3458//
3459void MStatusDisplay::SetOptimumSize()
3460{
3461 if (gROOT->IsBatch())
3462 return;
3463
3464 const UInt_t w = TMath::Nint(0.95*gClient->GetDisplayWidth());
3465 const UInt_t h = TMath::Nint(0.95*gClient->GetDisplayHeight());
3466
3467 SetDisplaySize(w, h);
3468}
3469
3470
3471Bool_t MStatusDisplay::HandleConfigureNotify(Event_t *evt)
3472{
3473 //
3474 // The initialization of the GUI is not yet enough finished...
3475 //
3476 if (!fTab)
3477 return kTRUE;
3478
3479 UInt_t w = evt->fWidth;
3480 UInt_t h = evt->fHeight;
3481
3482 const Bool_t wchanged = w!=GetWidth()-fTab->GetWidth();
3483 const Bool_t hchanged = h!=GetHeight()-fTab->GetHeight();
3484
3485 if (!wchanged && !hchanged)
3486 {
3487 Layout();
3488 // FIXME: Make sure that this doesn't result in endless loops.
3489 return kTRUE;
3490 }
3491
3492 if (GetWidth()==1 && GetHeight()==1)
3493 return kTRUE;
3494
3495 // calculate the constant part of the window
3496 const UInt_t cw = GetWidth() -fTab->GetWidth();
3497 const UInt_t ch = GetHeight()-fTab->GetHeight()+fTab->GetTabHeight();
3498
3499 // calculate new size of frame (canvas @ 2:3)
3500 if (hchanged)
3501 w = TMath::Nint((h-ch)*1.5+cw);
3502 else
3503 h = TMath::Nint((w-cw)/1.5+ch);
3504
3505 // resize frame
3506 Resize(w, h);
3507
3508 return kTRUE;
3509}
3510
3511Bool_t MStatusDisplay::HandleEvent(Event_t *event)
3512{
3513 // Instead of doing this in CloseWindow (called from HandleEvent)
3514 // we do it here. This makes sure, that handle event doesn't
3515 // execute code after deleting this.
3516 if (event->fType==kDestroyNotify)
3517 {
3518 if (Close())
3519 delete this;
3520// Close();
3521 return kTRUE;
3522 }
3523
3524 const Bool_t rc = TGMainFrame::HandleEvent(event);
3525
3526 //
3527 // This fixes a bug in older root versions which makes
3528 // TCanvas crash if gPad==NULL. So we make sure, that
3529 // gPad!=NULL -- be carfull, this may have other side
3530 // effects.
3531 //
3532#if ROOT_VERSION_CODE < ROOT_VERSION(3,10,01)
3533 if (!gPad && fTab)
3534 for (int i=0; i<fTab->GetNumberOfTabs(); i++)
3535 {
3536 TCanvas *c = GetCanvas(i);
3537 if (c)
3538 {
3539 c->cd();
3540 gLog << dbg << "MStatusDisplay::HandleEvent - Workaround: gPad=" << gPad << "." << endl;
3541 break;
3542 }
3543 }
3544#endif
3545
3546 return rc;
3547}
Note: See TracBrowser for help on using the repository browser.