source: trunk/MagicSoft/Mars/mbase/MStatusDisplay.cc@ 6942

Last change on this file since 6942 was 6938, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 72.4 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-2004
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// PrintToLpr().
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 <fstream> // fstream
64
65#include <TH1.h> // TH1::AddDirectory
66#include <TEnv.h> // TEnv
67#include <TLine.h> // TLine
68#include <TText.h> // TText
69#include <TFile.h> // gFile
70#include <TFrame.h> // TFrame
71#include <TStyle.h> // gStyle
72#include <TCanvas.h> // TCanvas
73#include <TSystem.h> // gSystem
74#include <TDatime.h> // TDatime
75#include <TRandom.h> // TRandom
76#include <TThread.h> // TThread::Self()
77#include <TBrowser.h> // TBrowser
78#include <TObjArray.h> // TObjArray
79#include <TPostScript.h> // TPostScript
80#include <TMethodCall.h> // TMethodCall
81
82//#include <TRint.h> // gApplication, TRint::Class()
83#include <TInterpreter.h> // gInterpreter
84
85#include <TGTab.h> // TGTab
86#include <TGLabel.h> // TGLabel
87#include <TG3DLine.h> // TGHorizontal3DLine
88#include <TGButton.h> // TGPictureButton
89#include <TGTextView.h> // TGTextView
90#include <TGComboBox.h> // TGComboBox
91#include <TGStatusBar.h> // TGStatusBar
92#include <TGFileDialog.h> // TGFileDialog
93#include <TGProgressBar.h> // TGHProgressBar
94#include <TRootEmbeddedCanvas.h> // TRootEmbeddedCanvas
95
96#include "MString.h"
97
98#include "MLog.h" // MLog
99#include "MLogManip.h" // inf, warn, err
100
101#include "MGList.h" // MGList
102#include "MGMenu.h" // MGMenu, TGMenu
103#include "MSearch.h" // MSearch
104#include "MParContainer.h" // MParContainer::GetDescriptor
105#include "MStatusArray.h" // MStatusArray
106
107#undef DEBUG
108//#define DEBUG
109
110ClassImp(MStatusDisplay);
111
112using namespace std;
113
114// ------------ Workaround for a non working TGTextView::Search -------------
115#if ROOT_VERSION_CODE < ROOT_VERSION(3,02,05)
116class MGTextView : public TGTextView
117{
118public:
119 MGTextView(const TGWindow *parent, UInt_t w, UInt_t h, Int_t id = -1,
120 UInt_t sboptions = 0, ULong_t back = GetWhitePixel()) :
121 TGTextView(parent, w, h, id, sboptions, back) {}
122 MGTextView(const TGWindow *parent, UInt_t w, UInt_t h, TGText *text,
123 Int_t id = -1, UInt_t sboptions = 0, ULong_t back = GetWhitePixel()) :
124 TGTextView(parent, w, h, text, id, sboptions, back) {}
125 MGTextView(const TGWindow *parent, UInt_t w, UInt_t h, const char *string,
126 Int_t id = -1, UInt_t sboptions = 0, ULong_t back = GetWhitePixel()) :
127 TGTextView(parent, w, h, string, id, sboptions, back) {}
128
129 void Mark(Long_t xPos, Long_t yPos) { TGTextView::Mark(xPos, yPos); }
130 void UnMark() { TGTextView::UnMark(); }
131
132 Bool_t Search(const char *string, Bool_t direction, Bool_t caseSensitive)
133 {
134 // Taken from TGTextView::Search and modified.
135
136 TGLongPosition pos, pos2;
137 pos2.fX = pos2.fY = 0;
138 if (fIsMarked) {
139 if (!direction)
140 {
141 pos2.fX = fMarkedStart.fX;
142 pos2.fY = fMarkedStart.fY;
143 }
144 else
145 {
146 pos2.fX = fMarkedEnd.fX + 1;
147 pos2.fY = fMarkedEnd.fY;
148 }
149 }
150 if (!fText->Search(&pos, pos2, string, direction, caseSensitive))
151 return kFALSE;
152 UnMark();
153 fIsMarked = kTRUE;
154 fMarkedStart.fY = fMarkedEnd.fY = pos.fY;
155 fMarkedStart.fX = pos.fX;
156 fMarkedEnd.fX = fMarkedStart.fX + strlen(string);
157 pos.fY = ToObjYCoord(fVisible.fY);
158 if ((fMarkedStart.fY < pos.fY) ||
159 (ToScrYCoord(fMarkedStart.fY) >= (Int_t)fCanvas->GetHeight()))
160 pos.fY = fMarkedStart.fY;
161 pos.fX = ToObjXCoord(fVisible.fX, pos.fY);
162 if ((fMarkedStart.fX < pos.fX) ||
163 (ToScrXCoord(fMarkedStart.fX, pos.fY) >= (Int_t)fCanvas->GetWidth()))
164 pos.fX = fMarkedStart.fX;
165
166 SetVsbPosition((ToScrYCoord(pos.fY) + fVisible.fY)/fScrollVal.fY);
167 SetHsbPosition((ToScrXCoord(pos.fX, pos.fY) + fVisible.fX)/fScrollVal.fX);
168 DrawRegion(0, (Int_t)ToScrYCoord(fMarkedStart.fY), fCanvas->GetWidth(),
169 UInt_t(ToScrYCoord(fMarkedEnd.fY+1) - ToScrYCoord(fMarkedEnd.fY)));
170
171 return kTRUE;
172 }
173};
174#else
175#define MGTextView TGTextView
176#endif
177
178// --------------------------------------------------------------------------
179
180// --------------------------------------------------------------------------
181//
182// Add menu bar to the GUI
183//
184void MStatusDisplay::AddMenuBar()
185{
186 //
187 // File Menu
188 //
189 MGPopupMenu *filemenu = new MGPopupMenu(gClient->GetRoot());
190 // filemenu->AddEntry("Save &As...", kFileSaveAs);
191 filemenu->AddEntry("New Can&vas", kFileCanvas);
192 filemenu->AddEntry("New &Browser", kFileBrowser);
193 filemenu->AddSeparator();
194 filemenu->AddEntry("Save status.&ps", kFileSaveAsPS);
195 filemenu->AddEntry("Save status.&png", kFileSaveAsPNG);
196 filemenu->AddEntry("Save status.&gif", kFileSaveAsGIF);
197 filemenu->AddEntry("Save status.&jpg", kFileSaveAsJPG);
198 filemenu->AddEntry("Save status.&xpm", kFileSaveAsXPM);
199 filemenu->AddEntry("Save status.&C", kFileSaveAsC);
200 filemenu->AddEntry("Save status.&root", kFileSaveAsRoot);
201 filemenu->AddSeparator();
202 filemenu->AddEntry("&Open...", kFileOpen);
203 filemenu->AddEntry("Save &As...", kFileSaveAs);
204 filemenu->AddSeparator();
205 filemenu->AddEntry("Re&set", kFileReset);
206 filemenu->AddSeparator();
207 filemenu->AddEntry("Print with &lpr", kFilePrint);
208 //filemenu->AddEntry("Set printer &name", kFilePrinterName);
209 filemenu->AddSeparator();
210 filemenu->AddEntry("C&lose", kFileClose);
211 filemenu->AddEntry("E&xit", kFileExit);
212 filemenu->Associate(this);
213
214 //
215 // Tab Menu
216 //
217 MGPopupMenu *tabmenu = new MGPopupMenu(gClient->GetRoot());
218 tabmenu->AddEntry("Next [&+]", kTabNext);
219 tabmenu->AddEntry("Previous [&-]", kTabPrevious);
220 tabmenu->AddSeparator();
221 tabmenu->AddEntry("Save tab-i.&ps", kTabSaveAsPS);
222 tabmenu->AddEntry("Save tab-i.&png", kTabSaveAsPNG);
223 tabmenu->AddEntry("Save tab-i.&gif", kTabSaveAsGIF);
224 tabmenu->AddEntry("Save tab-i.&jpg", kTabSaveAsJPG);
225 tabmenu->AddEntry("Save tab-i.&xpm", kTabSaveAsXPM);
226 tabmenu->AddEntry("Save tab-i.&C", kTabSaveAsC);
227 tabmenu->AddEntry("Save tab-i.&root", kTabSaveAsRoot);
228 tabmenu->AddSeparator();
229 tabmenu->AddEntry("Save tab &As...", kTabSaveAs);
230 tabmenu->AddSeparator();
231 tabmenu->AddEntry("Re&move", kTabRemove);
232 tabmenu->AddSeparator();
233 tabmenu->AddEntry("Print with &lpr", kTabPrint);
234 tabmenu->Associate(this);
235
236 //
237 // Loop Menu
238 //
239 MGPopupMenu *loopmenu = new MGPopupMenu(gClient->GetRoot());
240 loopmenu->AddEntry("&Stop", kLoopStop);
241 loopmenu->Associate(this);
242
243 //
244 // Loop Menu
245 //
246 MGPopupMenu *sizemenu = new MGPopupMenu(gClient->GetRoot());
247 sizemenu->AddEntry("Fit to 640x&480", kSize640);
248 sizemenu->AddEntry("Fit to 768x&576", kSize768);
249 sizemenu->AddEntry("Fit to 800x&600", kSize800);
250 sizemenu->AddEntry("Fit to 960x7&20", kSize960);
251 sizemenu->AddEntry("Fit to 1024x&768", kSize1024);
252 sizemenu->AddEntry("Fit to 1152x&864", kSize1152);
253 sizemenu->AddEntry("Fit to 1280x&1024", kSize1280);
254 sizemenu->AddEntry("Fit to 1400x1050", kSize1400);
255 sizemenu->AddEntry("Fit to 1600x1200", kSize1600);
256 sizemenu->Associate(this);
257
258 //
259 // Log Menu
260 //
261 MGPopupMenu *logmenu = new MGPopupMenu(gClient->GetRoot());
262 logmenu->AddEntry("&Copy Selected", kLogCopy);
263 logmenu->AddEntry("Cl&ear all", kLogClear);
264 logmenu->AddSeparator();
265 logmenu->AddEntry("Select &All", kLogSelect);
266 logmenu->AddSeparator();
267 logmenu->AddEntry("&Find...", kLogFind);
268 logmenu->AddSeparator();
269 logmenu->AddEntry("&Save", kLogSave);
270 logmenu->AddEntry("Save &append", kLogAppend);
271 logmenu->Associate(this);
272
273 //
274 // Menu Bar
275 //
276 TGLayoutHints *layitem = new TGLayoutHints(kLHintsNormal, 0, 4, 0, 0);
277 fList->Add(layitem);
278
279 MGMenuBar *menubar = new MGMenuBar(this, 1, 1, kHorizontalFrame);
280 menubar->AddPopup("&File", filemenu, layitem);
281 menubar->AddPopup("Lo&g", logmenu, layitem);
282 menubar->AddPopup("&Size", sizemenu, layitem);
283 menubar->AddPopup("&Tab", tabmenu, layitem);
284 menubar->AddPopup("&Loop", loopmenu, layitem);
285 menubar->BindKeys(this);
286 AddFrame(menubar);
287
288 //
289 // Line below menu bar
290 //
291 TGLayoutHints *laylinesep = new TGLayoutHints(kLHintsTop|kLHintsExpandX);
292 fList->Add(laylinesep);
293
294 TGHorizontal3DLine *linesep = new TGHorizontal3DLine(this);
295 AddFrame(linesep, laylinesep);
296
297 //
298 // Add everything to autodel list
299 //
300 fList->Add(filemenu);
301 fList->Add(loopmenu);
302 fList->Add(sizemenu);
303 fList->Add(menubar);
304 fList->Add(tabmenu);
305 fList->Add(logmenu);
306 fList->Add(linesep);
307}
308
309// --------------------------------------------------------------------------
310//
311// Adds an empty TGCompositeFrame which might be filled by the user
312//
313void MStatusDisplay::AddUserFrame()
314{
315 TGLayoutHints *lay=new TGLayoutHints(kLHintsExpandX);
316 fList->Add(lay);
317
318 fUserFrame = new TGCompositeFrame(this, 1, 1);
319 AddFrame(fUserFrame, lay);
320 fList->Add(fUserFrame);
321}
322
323char *rot128(char *c)
324{
325 char *rc=c;
326 while (*c) *c++ += 128;
327 return rc;
328}
329
330// --------------------------------------------------------------------------
331//
332// Add the title tab
333//
334void MStatusDisplay::AddMarsTab()
335{
336 // Create Tab1
337 TGCompositeFrame *f = fTab->AddTab("-=MARS=-");
338
339 // Add list of tabs
340
341 TGComboBox *filter = new TGComboBox(f, kTabs);
342 fList->Add(filter);
343 filter->Associate(this);
344 filter->AddEntry("-=MARS=-", 0);
345 filter->Select(0);
346
347 TGLayoutHints *lay3 = new TGLayoutHints(kLHintsCenterX|kLHintsTop, 10, 10, 10, 5);
348 fList->Add(lay3);
349 f->AddFrame(filter, lay3);
350
351 // Add MARS version
352 TGLabel *l = new TGLabel(f, MString::Form("Official Release: V%s", MARSVER));
353 fList->Add(l);
354
355 filter->SetWidth(l->GetWidth());
356 filter->SetHeight(4*l->GetHeight()/3);
357
358 TGLayoutHints *layb = new TGLayoutHints(kLHintsCenterX|kLHintsTop, 10, 10, 5, 5);
359 fList->Add(layb);
360 f->AddFrame(l, layb);
361
362 // Add root version
363 l = new TGLabel(f, MString::Form("Using ROOT v%s", ROOTVER));
364 fList->Add(l);
365
366 TGLayoutHints *lay = new TGLayoutHints(kLHintsCenterX|kLHintsTop);
367 fList->Add(lay);
368 f->AddFrame(l, lay);
369
370 // Add Mars logo picture
371 const TGPicture *pic2 = fList->GetPicture("marslogo.xpm");
372 if (pic2)
373 {
374 TGPictureButton *mars = new TGPictureButton(f, pic2, kPicMars);
375 fList->Add(mars);
376 mars->Associate(this);
377
378 TGLayoutHints *lay2 = new TGLayoutHints(kLHintsCenterX|kLHintsCenterY, 10, 10, 5, 5);
379 fList->Add(lay2);
380 f->AddFrame(mars, lay2);
381 }
382
383 // Add date and time
384 TDatime d;
385 l = new TGLabel(f, d.AsString());
386 fList->Add(l);
387 f->AddFrame(l, lay);
388
389 // Add copyright notice
390 l = new TGLabel(f, "(c) MAGIC Software Development, 2000-2004");
391 fList->Add(l);
392 f->AddFrame(l, layb);
393
394 TGLayoutHints *layc = new TGLayoutHints(kLHintsCenterX|kLHintsTop, 10, 10, 0, 5);
395 fList->Add(layc);
396
397 char *txt = "<< Thomas Bretz >>";
398 l = new TGLabel(f, txt);
399 fList->Add(l);
400 f->AddFrame(l, layc);
401}
402
403// --------------------------------------------------------------------------
404//
405// Adds the logbook tab to the GUI if it was not added previously.
406//
407// The logbook is updated four times a second only if the tab is visible.
408//
409// You can redirect an output to a MLog-logstream by calling SetLogStream().
410// To disable redirction call SetLogStream(NULL)
411//
412// if enable==kFALSE the stdout is disabled/enabled. Otherwise stdout
413// is ignored.
414//
415void MStatusDisplay::SetLogStream(MLog *log, Bool_t enable)
416{
417 if (gROOT->IsBatch())
418 return;
419
420 if (log && fLogBox==NULL)
421 {
422 fLogIdx = fTab->GetNumberOfTabs();
423
424 // Create Tab1
425 TGCompositeFrame *f = AddRawTab("-Logbook-");//fTab->AddTab("-Logbook-");
426
427 // Create Text View
428 fLogBox = new MGTextView(f, 1, 1); // , -1, 0, TGFrame::GetDefaultFrameBackground());
429 if (fFont)
430 fLogBox->SetFont(fFont);
431 //fLogBox->Associate(this);
432
433 // Add List box to the tab
434 TGLayoutHints *lay = new TGLayoutHints(kLHintsNormal|kLHintsExpandX|kLHintsExpandY,2,2,2,2);
435 f->AddFrame(fLogBox, lay);
436
437 // layout and map tab
438 Layout();
439 MapSubwindows();
440
441 // make it visible
442 // FIXME: This is a workaround, because TApplication::Run is not
443 // thread safe against ProcessEvents. We assume, that if
444 // we are not in the Main-Thread ProcessEvents() is
445 // called by the TApplication Event Loop...
446 if (!TThread::Self()/*gApplication->InheritsFrom(TRint::Class())*/)
447 gClient->ProcessEventsFor(fTab);
448 }
449
450 if (log)
451 {
452 fLog = log;
453
454 log->SetOutputGui(fLogBox, kTRUE);
455 log->EnableOutputDevice(MLog::eGui);
456 if (!enable)
457 log->DisableOutputDevice(MLog::eStdout);
458
459 fLogTimer.Start();
460 }
461 else
462 {
463 fLogTimer.Stop();
464
465 fLog->DisableOutputDevice(MLog::eGui);
466 fLog->SetOutputGui(NULL);
467 if (!enable)
468 fLog->EnableOutputDevice(MLog::eStdout);
469
470 fLog = &gLog;
471 }
472}
473
474// --------------------------------------------------------------------------
475//
476// Add the Tabs and the predifined Tabs to the GUI
477//
478void MStatusDisplay::AddTabs()
479{
480 fTab = new TGTab(this, 300, 300);
481
482 AddMarsTab();
483
484 // Add fTab to Frame
485 TGLayoutHints *laytabs = new TGLayoutHints(kLHintsNormal|kLHintsExpandX|kLHintsExpandY, 5, 5, 5);
486 AddFrame(fTab, laytabs);
487
488 fList->Add(fTab);
489 fList->Add(laytabs);
490}
491
492// --------------------------------------------------------------------------
493//
494// Add the progress bar to the GUI. The Progress Bar range is set to
495// (0,1) as default.
496//
497void MStatusDisplay::AddProgressBar()
498{
499 TGLayoutHints *laybar=new TGLayoutHints(kLHintsExpandX, 5, 5, 5, 5);
500 fList->Add(laybar);
501
502 fBar=new TGHProgressBar(this);
503 fBar->SetRange(0, 1);
504 fBar->ShowPosition();
505 AddFrame(fBar, laybar);
506 fList->Add(fBar);
507}
508
509// --------------------------------------------------------------------------
510//
511// Set the progress bar position between 0 and 1. The Progress bar range
512// is assumed to be (0,1)
513//
514void MStatusDisplay::SetProgressBarPosition(Float_t p)
515{
516 fBar->SetPosition(p);
517}
518
519// --------------------------------------------------------------------------
520//
521// Adds the status bar to the GUI
522//
523void MStatusDisplay::AddStatusBar()
524{
525 fStatusBar = new TGStatusBar(this, 1, 1);
526
527 //
528 // Divide it like the 'Golden Cut' (goldener Schnitt)
529 //
530 // 1-a a
531 // 1: ------|----
532 //
533 // a/(1-a) = (1-a)/1
534 // a^2+a-1 = 0
535 // a = (-1+-sqrt(1+4))/2 = sqrt(5)/2-1/2 = 0.618
536 //
537 Int_t p[] = {38-2, 62-8, 10};
538
539 fStatusBar->SetParts(p, 3);
540
541 TGLayoutHints *layb = new TGLayoutHints(kLHintsNormal|kLHintsExpandX, 5, 4, 0, 3);
542 AddFrame(fStatusBar, layb);
543
544 fList->Add(fStatusBar);
545 fList->Add(layb);
546}
547
548// --------------------------------------------------------------------------
549//
550// Change the text in the status line 1
551//
552void MStatusDisplay::SetStatusLine(const char *txt, Int_t i)
553{
554 if (gROOT->IsBatch())
555 return;
556 fStatusBar->SetText(txt, i);
557
558 // FIXME: This is a workaround, because TApplication::Run is not
559 // thread safe against ProcessEvents. We assume, that if
560 // we are not in the Main-Thread ProcessEvents() is
561 // called by the TApplication Event Loop...
562 if (!TThread::Self()/*gApplication->InheritsFrom(TRint::Class())*/)
563 gClient->ProcessEventsFor(fStatusBar);
564}
565
566// --------------------------------------------------------------------------
567//
568// Display information about the name of a container
569//
570void MStatusDisplay::SetStatusLine2(const MParContainer &cont)
571{
572 SetStatusLine2(MString::Form("%s: %s", cont.GetDescriptor().Data(), cont.GetTitle()));
573}
574
575// --------------------------------------------------------------------------
576//
577// Default constructor. Opens a window with a progress bar. Get a pointer
578// to the bar by calling GetBar. This pointer can be used for the
579// eventloop.
580//
581// Be carefull: killing or closing the window while the progress meter
582// is still in use may cause segmentation faults. Please kill the window
583// always by deleting the corresponding object.
584//
585// Update time default: 10s
586//
587MStatusDisplay::MStatusDisplay(Long_t t)
588: TGMainFrame(NULL, 1, 1), fName("MStatusDisplay"), fLog(&gLog), fTab(NULL), fTimer(this, t, kTRUE), fStatus(kLoopNone), fLogIdx(-1), fLogTimer(this, 250, kTRUE), fLogBox(NULL), fIsLocked(0)
589{
590 // p==NULL means: Take gClient->GetRoot() if not in batch mode
591 // see TGWindow::TGWindow()
592
593 //
594 // This is a possibility for the user to check whether this
595 // object has already been deleted. It will be removed
596 // from the list in the destructor.
597 //
598// gROOT->GetListOfSpecials()->Add(this);
599
600 fFont = gVirtualX->LoadQueryFont("7x13bold");
601 fMutex = new TMutex;
602
603 //
604 // In case we are in batch mode use a list of canvases
605 // instead of the Root Embedded Canvases in the TGTab
606 //
607 fBatch = new TList;
608 fBatch->SetOwner();
609
610 //
611 // Create a list handling GUI widgets
612 //
613 fList = new MGList;
614 fList->SetOwner();
615
616 //
617 // Create the layout hint for the root embedded canavses
618 //
619 fLayCanvas = new TGLayoutHints(kLHintsExpandX|kLHintsExpandY);
620 fList->Add(fLayCanvas);
621
622 //
623 // Add Widgets (from top to bottom)
624 //
625 if (gClient) // BATCH MODE
626 {
627 AddMenuBar();
628 AddUserFrame();
629 AddTabs();
630 AddProgressBar();
631 AddStatusBar();
632 }
633
634 //
635 // set the smallest and biggest size of the Main frame
636 // and move it to its appearance position
637 SetWMSizeHints(570, 480, 2048, 1536, 1, 1);
638 MoveResize(rand()%100+570, rand()%100+480, 570, 480);
639
640 //
641 // Now do an automatic layout of the widgets and display the window
642 //
643 Layout();
644 MapSubwindows();
645
646 SetWindowName("Status Display");
647 SetIconName("Status Display");
648
649 MapWindow();
650
651 // FIXME: This is a workaround, because TApplication::Run is not
652 // thread safe against ProcessEvents. We assume, that if
653 // we are not in the Main-Thread ProcessEvents() is
654 // called by the TApplication Event Loop...
655 if (!TThread::Self()/*gApplication->InheritsFrom(TRint::Class())*/)
656 gSystem->ProcessEvents();
657}
658
659// --------------------------------------------------------------------------
660//
661// Destruct the window with all its tiles. Also the Progress Bar object
662// is deleted.
663//
664MStatusDisplay::~MStatusDisplay()
665{
666#if ROOT_VERSION_CODE < ROOT_VERSION(3,10,01)
667 fTab = NULL; // See HandleEvent
668#endif
669
670 //
671 // Delete object from global object table so it cannot
672 // be deleted by chance a second time
673 //
674 gInterpreter->DeleteGlobal(this);
675
676 //
677 // This is a possibility for the user to check whether this
678 // object has already been deleted. It has been added
679 // to the list in the constructor.
680 //
681 gROOT->GetListOfSpecials()->Remove(this);
682
683 SetLogStream(NULL);
684
685 //
686 // Delete the list of objects corresponding to this object
687 //
688 delete fList;
689
690 //
691 // Delete the list of canvases used in batch mode
692 // instead of the Root Embedded Canvases in the TGTab
693 //
694 delete fBatch;
695
696 //
697 // Delete the font used for the logging window
698 //
699 if (fFont)
700 gVirtualX->DeleteFont(fFont);
701
702 //
703 // Delete mutex
704 //
705 delete fMutex;
706}
707
708// --------------------------------------------------------------------------
709//
710// Takes a TGCompositeFrame as argument. Searches for the first
711// TRootEmbeddedCanvas which is contained by it and returns a pointer
712// to the corresponding TCanvas. If it isn't found NULL is returned.
713//
714TRootEmbeddedCanvas *MStatusDisplay::GetEmbeddedCanvas(TGCompositeFrame *cf) const
715{
716 TIter Next(cf->GetList());
717
718 TGFrameElement *f;
719 while ((f=(TGFrameElement*)Next()))
720 if (f->fFrame->InheritsFrom(TRootEmbeddedCanvas::Class()))
721 return (TRootEmbeddedCanvas*)f->fFrame;
722
723 return NULL;
724}
725
726// --------------------------------------------------------------------------
727//
728// Takes a TGCompositeFrame as argument. Searches for the first
729// TRootEmbeddedCanvas which is contained by it and returns a pointer
730// to the corresponding TCanvas. If it isn't found NULL is returned.
731//
732TCanvas *MStatusDisplay::GetCanvas(TGCompositeFrame *cf) const
733{
734 TRootEmbeddedCanvas *ec = GetEmbeddedCanvas(cf);
735 return ec ? ec->GetCanvas() : NULL;
736}
737
738// --------------------------------------------------------------------------
739//
740// Returns GetCanvas of the i-th Tab.
741//
742TCanvas *MStatusDisplay::GetCanvas(int i) const
743{
744 if (gROOT->IsBatch())
745 return (TCanvas*)fBatch->At(i-1);
746
747 if (i<0 || i>=fTab->GetNumberOfTabs())
748 {
749 *fLog << warn << "MStatusDisplay::GetCanvas: Out of range." << endl;
750 return NULL;
751 }
752
753 return GetCanvas(fTab->GetTabContainer(i));
754}
755
756// --------------------------------------------------------------------------
757//
758// Returns j-th pad of the i-th Tab.
759// Sets the pad to fill an entire window.
760//
761// This function can be used if single pad's out of an MStatusDisplay
762// have to be stored to file.
763//
764// ATTENTION: This function modifies the requested tab in MStatusDisplay itself!
765//
766TVirtualPad *MStatusDisplay::GetFullPad(const Int_t i, const Int_t j)
767{
768
769 TVirtualPad *vpad = GetCanvas(i)->GetPad(j);
770 if (vpad)
771 vpad->SetPad(0.,0.,1.,1.);
772 else
773 *fLog << warn << "MStatusDisplay::GetFullPad: Pad is out of range." << endl;
774
775 return vpad;
776}
777
778
779
780// --------------------------------------------------------------------------
781//
782// Searches for a TRootEmbeddedCanvas in the TGCompositeFramme of the
783// Tab with the name 'name'. Returns the corresponding TCanvas or
784// NULL if something isn't found.
785//
786TCanvas *MStatusDisplay::GetCanvas(const TString &name) const
787{
788 if (gROOT->IsBatch())
789 return (TCanvas*)fBatch->FindObject(name);
790
791 TGFrameElement *f;
792 TIter Next(fTab->GetList());
793 while ((f=(TGFrameElement*)Next()))
794 {
795 TObject *frame = f->fFrame;
796 if (!frame->InheritsFrom(TGTabElement::Class()))
797 continue;
798
799 TGTabElement *tab = (TGTabElement*)frame;
800 if (tab->GetString()==name)
801 break;
802 }
803
804 // Search for the next TGCompositeFrame in the list
805 while ((f=(TGFrameElement*)Next()))
806 {
807 TObject *frame = f->fFrame;
808 if (frame->InheritsFrom(TGCompositeFrame::Class()))
809 return GetCanvas((TGCompositeFrame*)frame);
810 }
811
812 return NULL;
813}
814
815// --------------------------------------------------------------------------
816//
817// Calls TCanvas::cd(), for the canvas returned by GetCanvas.
818//
819Bool_t MStatusDisplay::CdCanvas(const TString &name)
820{
821 TCanvas *c = GetCanvas(name);
822 if (!c)
823 return kFALSE;
824
825 c->cd();
826 return kTRUE;
827}
828
829TGCompositeFrame *MStatusDisplay::AddRawTab(const char *name)
830{
831 // Add new tab
832 TGCompositeFrame *f = fTab->AddTab(name);
833
834 TGComboBox *box = (TGComboBox*)fList->FindWidget(kTabs);
835 box->AddEntry(name, box->GetListBox()->GetNumberOfEntries());
836
837 // layout and map new tab
838 Layout();
839 MapSubwindows();
840 Layout();
841
842 // display new tab in the main frame
843 // FIXME: This is a workaround, because TApplication::Run is not
844 // thread safe against ProcessEvents. We assume, that if
845 // we are not in the Main-Thread ProcessEvents() is
846 // called by the TApplication Event Loop...
847 if (!TThread::Self()/*gApplication->InheritsFrom(TRint::Class())*/)
848 gClient->ProcessEventsFor(fTab);
849
850 *fLog << inf << "Adding Raw Tab '" << name << "' (" << f->GetWidth() << "x";
851 *fLog << f->GetHeight() << ")" << endl;
852
853 // return pointer to new canvas
854 return f;
855}
856
857// --------------------------------------------------------------------------
858//
859// This function was connected to all created canvases. It is used
860// to redirect GetObjectInfo into our own status bar.
861//
862// The 'connection' is done in AddTab
863//
864void MStatusDisplay::EventInfo(Int_t event, Int_t px, Int_t py, TObject *selected)
865{
866 // Writes the event status in the status bar parts
867 if (!selected)
868 return;
869
870 TCanvas *c = (TCanvas*)gTQSender;
871
872 TVirtualPad* save=gPad;
873
874 gPad = c ? c->GetSelectedPad() : NULL;
875
876 if (gPad)
877 SetStatusLine2(selected->GetObjectInfo(px,py));
878
879 gPad=save;
880}
881
882// --------------------------------------------------------------------------
883//
884// Adds a new tab with the name 'name'. Adds a TRootEmbeddedCanvas to the
885// tab and returns a reference to the corresponding TCanvas.
886//
887TCanvas &MStatusDisplay::AddTab(const char *name)
888{
889 if (gROOT->IsBatch())
890 {
891 TCanvas *c = new TCanvas(name, name);
892 fBatch->Add(c);
893 return *c;
894 }
895
896 // Add new tab
897 TGCompositeFrame *f = fTab->AddTab(name);
898
899 // create root embedded canvas and add it to the tab
900 TRootEmbeddedCanvas *ec = new TRootEmbeddedCanvas(name, f, f->GetWidth(), f->GetHeight(), 0);
901 f->AddFrame(ec, fLayCanvas);
902 fList->Add(ec);
903
904 // set background and border mode of the canvas
905 TCanvas &c = *ec->GetCanvas();
906
907 c.SetFillColor(16/*165*//*17*//*203*/);
908 c.SetBorderMode(0);
909
910 // If kNoContextMenu set set kNoContextMenu of the canvas
911 if (TestBit(kNoContextMenu))
912 c.SetBit(kNoContextMenu);
913
914 // Connect all TCanvas::ProcessedEvent to this->EventInfo
915 // This means, that after TCanvas has processed an event
916 // EventInfo of this class is called, see TCanvas::HandleInput
917 c.Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)",
918 "MStatusDisplay", this, "EventInfo(Int_t,Int_t,Int_t,TObject*)");
919
920 TGComboBox *box = (TGComboBox*)fList->FindWidget(kTabs);
921 box->AddEntry(name, box->GetListBox()->GetNumberOfEntries());
922
923 // layout and map new tab
924 Layout(); // seems to layout the TGCompositeFrame
925 MapSubwindows(); // maps the TGCompositeFrame
926 Layout(); // layout the embedded canvas in the frame
927
928 // display new tab in the main frame
929 // FIXME: This is a workaround, because TApplication::Run is not
930 // thread safe against ProcessEvents. We assume, that if
931 // we are not in the Main-Thread ProcessEvents() is
932 // called by the TApplication Event Loop...
933 if (!TThread::Self()/*gApplication->InheritsFrom(TRint::Class())*/)
934 gClient->ProcessEventsFor(fTab);
935
936 *fLog << inf << "Adding Tab '" << name << "' (" << f->GetWidth() << "x";
937 *fLog << f->GetHeight() << ", TCanvas=" << &c << ")" << endl;
938
939 // return pointer to new canvas
940 return c;
941}
942
943// --------------------------------------------------------------------------
944//
945// Update a canvas in a tab, takes the corresponding TGCompositeFrame
946// as an argument. This is necessary, because not all functions
947// changing the contents of a canvas or pad can call SetModified()
948// for the corresponding tab. If this is not called correctly the
949// tab won't be updated calling TCanvas::Update(). So we simply
950// redraw it by our own (instead we could recursively call
951// TPad::Modified() for everything contained by the TCanvas and
952// call TCanvas::Update() afterwards)
953//
954void MStatusDisplay::UpdateTab(TGCompositeFrame *f)
955{
956 if (!f)
957 return;
958
959 TCanvas *c=GetCanvas(f);
960 if (!c)
961 return;
962
963 //
964 // If we are in a multithreaded environment (gThreadXAR) we
965 // have to make sure, that thus function is called from
966 // the main thread.
967 //
968 if (gThreadXAR)
969 {
970 // Tell the X-Requester how to call this method
971 TString str = MString::Form("%d", (ULong_t)f);
972
973 TMethodCall call(IsA(), "UpdateTab", "NULL");
974 void *arr[4] = { NULL, &call, this, (void*)(const char*)str };
975
976 // If this is not the main thread return
977 if (((*gThreadXAR)("METH", 4, arr, NULL)))
978 return;
979 }
980
981 //
982 // Secure calls to update the tabs against itself, at least
983 // c->Paint() or c->Flush() may crash X (bad drawable).
984 // This makes sure, that a X call is not interuppted by
985 // another X-call which was started from an gui interrrupt
986 // in the same thread
987 //
988 if (fMutex->TryLock())
989 return;
990
991#if ROOT_VERSION_CODE < ROOT_VERSION(3,10,02)
992 TPad *padsav = (TPad*)gPad;
993 if (!gPad)
994 c->cd();
995#endif
996
997 if (!c->IsBatch())
998 c->FeedbackMode(kFALSE); // Goto double buffer mode
999
1000 //
1001 // Doing this ourself gives us the possibility to repaint
1002 // the canvas in any case (Paint() instead of PaintModified())
1003 //
1004 c->Paint(); // Repaint all pads
1005 c->Flush(); // Copy all pad pixmaps to the screen
1006
1007#if ROOT_VERSION_CODE < ROOT_VERSION(3,10,02)
1008 if (padsav)
1009 padsav->cd();
1010 else
1011 gPad=NULL;
1012#endif
1013
1014 //c->SetCursor(kCross);
1015
1016 // Old version
1017 //c->Modified();
1018 //c->Update();
1019 //c->Paint();
1020
1021 fMutex->UnLock();
1022}
1023
1024// --------------------------------------------------------------------------
1025//
1026// Saves the given canvas (pad) or all pads (num<0) as a temporary
1027// postscript file and prints it using 'lpr'. If a printer name is set
1028// via SetPrinter 'lpr -Pname' is used.
1029//
1030Int_t MStatusDisplay::PrintToLpr(Int_t num)
1031{
1032 TString name = "mars";
1033
1034 for (int i=0; i<6; i++)
1035 name += (char)(gRandom->Uniform(25)+65);
1036
1037 name += ".ps";
1038
1039 const Int_t pages = SaveAsPS(num, name);
1040
1041 SetStatusLine1("Printing...");
1042 SetStatusLine2("");
1043
1044 if (!pages)
1045 {
1046 *fLog << warn << "MStatusDisplay::PrintToLpr: Sorry, couldn't save file as temporary postscript!" << endl;
1047 SetStatusLine2("Failed!");
1048 return 0;
1049 }
1050
1051 TString cmd="lpr ";
1052 if (!fPrinter.IsNull())
1053 {
1054 cmd += "-P";
1055 cmd += fPrinter;
1056 cmd += " ";
1057 }
1058 cmd += name;
1059
1060 gSystem->Exec(cmd);
1061 gSystem->Unlink(name);
1062
1063 SetStatusLine2(MString::Form("Done (%dpage(s))", pages));
1064
1065 return pages;
1066}
1067
1068// --------------------------------------------------------------------------
1069//
1070// Remove tab no i if this tab contains a TRootEmbeddedCanvas
1071//
1072void MStatusDisplay::RemoveTab(int i)
1073{
1074 TGCompositeFrame *f = fTab->GetTabContainer(i);
1075 if (!f)
1076 return;
1077
1078 TRootEmbeddedCanvas *ec = GetEmbeddedCanvas(f);
1079 if (!ec)
1080 return;
1081
1082 TCanvas *c = ec->GetCanvas();
1083 if (!c)
1084 return;
1085
1086 const TString name(c->GetName());
1087
1088 f->RemoveFrame(ec);
1089 delete fList->Remove(ec);
1090
1091 fTab->RemoveTab(i);
1092 fTab->SetTab(0);
1093
1094 TGComboBox *box = (TGComboBox*)fList->FindWidget(kTabs);
1095 box->RemoveEntry(i);
1096 for (int j=i; j<box->GetListBox()->GetNumberOfEntries(); j++)
1097 {
1098 TGTextLBEntry *entry = (TGTextLBEntry *)box->GetListBox()->Select(j+1, kFALSE);
1099 box->AddEntry(entry->GetText()->GetString(), j);
1100 box->RemoveEntry(j+1);
1101 }
1102 box->GetListBox()->Select(0);
1103
1104 // Looks strange...
1105 // const Int_t n = fTab->GetNumberOfTabs();
1106 // fTab->SetTab(i<=n-1 ? i : i-1);
1107
1108 // layout and map new tab
1109 Layout(); // seems to layout the TGCompositeFrame
1110 MapSubwindows(); // maps the TGCompositeFrame
1111 Layout(); // layout the embedded canvas in the frame
1112
1113 // display new tab in the main frame
1114 // FIXME: This is a workaround, because TApplication::Run is not
1115 // thread safe against ProcessEvents. We assume, that if
1116 // we are not in the Main-Thread ProcessEvents() is
1117 // called by the TApplication Event Loop...
1118 if (!TThread::Self()/*gApplication->InheritsFrom(TRint::Class())*/)
1119 gClient->ProcessEventsFor(fTab);
1120
1121 *fLog << inf << "Removed Tab #" << i << " '" << name << "'" << endl;
1122}
1123
1124// --------------------------------------------------------------------------
1125//
1126// Use this to check whether the MStatusDisplay still contains the
1127// TCanvas c. It could be removed meanwhile by menu usage.
1128//
1129Bool_t MStatusDisplay::HasCanvas(const TCanvas *c) const
1130{
1131 if (!c)
1132 return kFALSE;
1133
1134 if (gROOT->IsBatch())
1135 return (Bool_t)fBatch->FindObject(c);
1136
1137 for (int i=1; i<fTab->GetNumberOfTabs(); i++)
1138 if (c==GetCanvas(i))
1139 return kTRUE;
1140 return kFALSE;
1141}
1142
1143/*
1144 if (...)
1145 fMenu->AddPopup("&CaOs", fCaOs, NULL);
1146 else
1147 fMenu->RemovePopup("CaOs");
1148 fMenu->Resize(fMenu->GetDefaultSize());
1149 MapSubwindows();
1150 MapWindow();
1151 */
1152
1153void MStatusDisplay::Reset()
1154{
1155 if (gROOT->IsBatch())
1156 {
1157 fBatch->Delete();
1158 return;
1159 }
1160
1161 for (int i=fTab->GetNumberOfTabs()-1; i>0; i--)
1162 RemoveTab(i);
1163}
1164
1165// --------------------------------------------------------------------------
1166//
1167// Process the kC_COMMAND, kCM_MENU messages
1168//
1169Bool_t MStatusDisplay::ProcessMessageCommandMenu(Long_t id)
1170{
1171 switch (id)
1172 {
1173 case kLoopStop:
1174 case kFileClose:
1175 case kFileExit:
1176 if (id==kFileExit || id==kFileClose)
1177 if (Close())
1178 delete this;
1179 fStatus = (Status_t)id;
1180 return kTRUE;
1181
1182 case kFileCanvas:
1183 new TCanvas;
1184 return kTRUE;
1185
1186 case kFileBrowser:
1187 new TBrowser;
1188 return kTRUE;
1189
1190 case kFileReset:
1191 Reset();
1192 return kTRUE;
1193
1194 case kFileOpen:
1195 Open();
1196 return kTRUE;
1197
1198 case kFileSaveAs:
1199 SaveAs();
1200 return kTRUE;
1201
1202 case kFileSaveAsPS:
1203 SaveAsPS();
1204 return kTRUE;
1205
1206 case kFileSaveAsPNG:
1207 SaveAsPNG();
1208 return kTRUE;
1209
1210 case kFileSaveAsGIF:
1211 SaveAsGIF();
1212 return kTRUE;
1213
1214 case kFileSaveAsXPM:
1215 SaveAsXPM();
1216 return kTRUE;
1217
1218 case kFileSaveAsJPG:
1219 SaveAsJPG();
1220 return kTRUE;
1221
1222 case kFileSaveAsC:
1223 SaveAsC();
1224 return kTRUE;
1225
1226 case kFileSaveAsRoot:
1227 SaveAsRoot();
1228 return kTRUE;
1229
1230 case kFilePrint:
1231 PrintToLpr();
1232 return kTRUE;
1233
1234 case kTabSaveAs:
1235 SaveAs(fTab->GetCurrent());
1236 return kTRUE;
1237
1238 case kTabSaveAsPS:
1239 SaveAsPS(fTab->GetCurrent());
1240 return kTRUE;
1241
1242 case kTabSaveAsPNG:
1243 SaveAsPNG(fTab->GetCurrent());
1244 return kTRUE;
1245
1246 case kTabSaveAsGIF:
1247 SaveAsGIF(fTab->GetCurrent());
1248 return kTRUE;
1249
1250 case kTabSaveAsXPM:
1251 SaveAsXPM(fTab->GetCurrent());
1252 return kTRUE;
1253
1254 case kTabSaveAsJPG:
1255 SaveAsJPG(fTab->GetCurrent());
1256 return kTRUE;
1257
1258 case kTabSaveAsC:
1259 SaveAsC(fTab->GetCurrent());
1260 return kTRUE;
1261
1262 case kTabSaveAsRoot:
1263 SaveAsRoot(fTab->GetCurrent());
1264 return kTRUE;
1265
1266 case kTabPrint:
1267 PrintToLpr(fTab->GetCurrent());
1268 return kTRUE;
1269
1270 case kTabNext:
1271 fTab->SetTab(fTab->GetCurrent()+1);
1272 return kTRUE;
1273
1274 case kTabPrevious:
1275 fTab->SetTab(fTab->GetCurrent()-1);
1276 return kTRUE;
1277
1278 case kTabRemove:
1279 RemoveTab(fTab->GetCurrent());
1280 return kTRUE;
1281
1282 case kSize640:
1283 Resize(570, 480);
1284 return kTRUE;
1285 case kSize768:
1286 Resize(700, 576);
1287 return kTRUE;
1288 case kSize800:
1289 Resize(740, 600);
1290 return kTRUE;
1291 case kSize960:
1292 Resize(880, 700);
1293 return kTRUE;
1294 case kSize1024:
1295 Resize(980, 768);
1296 return kTRUE;
1297 case kSize1152:
1298 Resize(1080, 864);
1299 case kSize1280:
1300 Resize(1280, 980);
1301 return kTRUE;
1302 case kSize1400:
1303 Resize(1350, 1050);
1304 return kTRUE;
1305 case kSize1600:
1306 Resize(1550, 1400);
1307 return kTRUE;
1308
1309 case kLogClear:
1310 fLogBox->Clear();
1311 return kTRUE;
1312 case kLogCopy:
1313 fLogBox->Copy();
1314 return kTRUE;
1315 case kLogSelect:
1316 fLogBox->SelectAll();
1317 return kTRUE;
1318 case kLogFind:
1319 new MSearch(this);
1320 return kTRUE;
1321 case kLogSave:
1322 SetStatusLine1("Saving log...");
1323 SetStatusLine2("");
1324 *fLog << inf << "Saving log... " << flush;
1325 if (fLogBox->GetText()->Save("statusdisplay.log"))
1326 {
1327 *fLog << "done." << endl;
1328 SetStatusLine2("done.");
1329 }
1330 else
1331 {
1332 *fLog << "failed!" << endl;
1333 SetStatusLine2("Failed!");
1334 }
1335 return kTRUE;
1336
1337 case kLogAppend:
1338 SetStatusLine1("Appending logg...");
1339 SetStatusLine2("");
1340 *fLog << inf << "Appending log... " << flush;
1341 if (fLogBox->GetText()->Append("statusdisplay.log"))
1342 {
1343 *fLog << "done." << endl;
1344 SetStatusLine2("done.");
1345 }
1346 else
1347 {
1348 *fLog << "failed!" << endl;
1349 SetStatusLine2("Failed!");
1350 }
1351 return kTRUE;
1352#ifdef DEBUG
1353 default:
1354 cout << "Command-Menu #" << id << endl;
1355#endif
1356 }
1357 return kTRUE;
1358
1359}
1360
1361// --------------------------------------------------------------------------
1362//
1363// Process the kC_COMMAND messages
1364//
1365Bool_t MStatusDisplay::ProcessMessageCommand(Long_t submsg, Long_t mp1, Long_t mp2)
1366{
1367 switch (submsg)
1368 {
1369 case kCM_MENU: // 1
1370 return ProcessMessageCommandMenu(mp1); // mp2=userdata
1371 case kCM_TAB: // 8
1372 /*
1373 for (int i=0; i<fTab->GetNumberOfTabs(); i++)
1374 fTab->GetTabContainer(i)->UnmapWindow();
1375 */
1376 UpdateTab(fTab->GetTabContainer(mp1));
1377 //fTab->GetTabContainer(mp1)->MapWindow();
1378
1379 /*
1380 if (mp1>0)
1381 fMenu->AddPopup("&CaOs", fCaOs, NULL);
1382 else
1383 fMenu->RemovePopup("CaOs");
1384 fMenu->Resize(fMenu->GetDefaultSize());
1385 MapSubwindows();
1386 MapWindow();
1387 */
1388 return kTRUE;
1389 case kCM_COMBOBOX: // 7
1390 if (mp1==kTabs)
1391 fTab->SetTab(mp2);
1392 return kTRUE;
1393#ifdef DEBUG
1394 case kCM_MENUSELECT: // 2
1395 cout << "Command-Menuselect #" << mp1 << " (UserData=" << (void*)mp2 << ")" << endl;
1396 return kTRUE;
1397
1398 case kCM_BUTTON: // 3
1399 cout << "Command-Button." << endl;
1400 return kTRUE;
1401
1402 case kCM_CHECKBUTTON: // 4
1403 cout << "Command-CheckButton." << endl;
1404 return kTRUE;
1405
1406 case kCM_RADIOBUTTON: // 5
1407 cout << "Command-RadioButton." << endl;
1408 return kTRUE;
1409
1410 case kCM_LISTBOX: // 6
1411 cout << "Command-Listbox #" << mp1 << " (LineId #" << mp2 << ")" << endl;
1412 return kTRUE;
1413 default:
1414 cout << "Command: " << "Submsg:" << submsg << " Mp1=" << mp1 << " Mp2=" << mp2 << endl;
1415#endif
1416 }
1417 return kTRUE;
1418}
1419
1420// --------------------------------------------------------------------------
1421//
1422// Process the kC_TEXTVIEW messages
1423//
1424Bool_t MStatusDisplay::ProcessMessageTextview(Long_t submsg, Long_t mp1, Long_t mp2)
1425{
1426 // kC_TEXTVIEW, kTXT_ISMARKED, widget id, [true|false] //
1427 // kC_TEXTVIEW, kTXT_DATACHANGE, widget id, 0 //
1428 // kC_TEXTVIEW, kTXT_CLICK2, widget id, position (y << 16) | x) //
1429 // kC_TEXTVIEW, kTXT_CLICK3, widget id, position (y << 16) | x) //
1430 // kC_TEXTVIEW, kTXT_F3, widget id, true //
1431 // kC_TEXTVIEW, kTXT_OPEN, widget id, 0 //
1432 // kC_TEXTVIEW, kTXT_CLOSE, widget id, 0 //
1433 // kC_TEXTVIEW, kTXT_SAVE, widget id, 0 //
1434#ifdef DEBUG
1435 switch (submsg)
1436 {
1437 case kTXT_ISMARKED:
1438 cout << "Textview-IsMarked #" << mp1 << " " << (mp2?"yes":"no") << endl;
1439 return kTRUE;
1440
1441 case kTXT_DATACHANGE:
1442 cout << "Textview-DataChange #" << mp1 << endl;
1443 return kTRUE;
1444
1445 case kTXT_CLICK2:
1446 cout << "Textview-Click2 #" << mp1 << " x=" << (mp2&0xffff) << " y= " << (mp2>>16) << endl;
1447 return kTRUE;
1448
1449 case kTXT_CLICK3:
1450 cout << "Textview-Click3 #" << mp1 << " x=" << (mp2&0xffff) << " y= " << (mp2>>16) << endl;
1451 return kTRUE;
1452
1453 case kTXT_F3:
1454 cout << "Textview-F3 #" << mp1 << endl;
1455 return kTRUE;
1456
1457 case kTXT_OPEN:
1458 cout << "Textview-Open #" << mp1 << endl;
1459 return kTRUE;
1460
1461 case kTXT_CLOSE:
1462 cout << "Textview-Close #" << mp1 << endl;
1463 return kTRUE;
1464
1465 case kTXT_SAVE:
1466 cout << "Textview-Save #" << mp1 << endl;
1467 return kTRUE;
1468
1469 default:
1470 cout << "Textview: " << "Submsg:" << submsg << " Mp1=" << mp1 << " Mp2=" << mp2 << endl;
1471 }
1472#endif
1473 return kTRUE;
1474}
1475
1476// --------------------------------------------------------------------------
1477//
1478// Process the kC_USER messages
1479//
1480Bool_t MStatusDisplay::ProcessMessageUser(Long_t submsg, Long_t mp1, Long_t mp2)
1481{
1482 // kS_START, case sensitive | backward<<1, char *txt
1483 switch (submsg)
1484 {
1485 case kS_START:
1486 fLogBox->Search((char*)mp2, !(mp1&2>>1), mp1&1);
1487 return kTRUE;
1488#ifdef DEBUG
1489 default:
1490 cout << "User: " << "Submsg:" << submsg << " Mp1=" << mp1 << " Mp2=" << mp2 << endl;
1491#endif
1492 }
1493 return kTRUE;
1494}
1495
1496// --------------------------------------------------------------------------
1497//
1498// Process the messages from the GUI
1499//
1500Bool_t MStatusDisplay::ProcessMessage(Long_t msg, Long_t mp1, Long_t mp2)
1501{
1502 // Can be found in WidgetMessageTypes.h
1503#ifdef DEBUG
1504 cout << "Msg: " << GET_MSG(msg) << " Submsg:" << GET_SUBMSG(msg);
1505 cout << " Mp1=" << mp1 << " Mp2=" << mp2 << endl;
1506#endif
1507 switch (GET_MSG(msg))
1508 {
1509 case kC_COMMAND: // 1
1510 return ProcessMessageCommand(GET_SUBMSG(msg), mp1, mp2);
1511
1512 case kC_TEXTVIEW: // 9
1513 return ProcessMessageTextview(GET_SUBMSG(msg), mp1, mp2);
1514
1515 case kC_USER: // 1001
1516 return ProcessMessageUser(GET_SUBMSG(msg), mp1, mp2);
1517 }
1518#ifdef DEBUG
1519 cout << "Msg: " << GET_MSG(msg) << " Submsg:" << GET_SUBMSG(msg);
1520 cout << " Mp1=" << mp1 << " Mp2=" << mp2 << endl;
1521#endif
1522 return kTRUE;
1523}
1524
1525Bool_t MStatusDisplay::Close()
1526{
1527 // Got close message for this MainFrame. Calls parent CloseWindow()
1528 // (which destroys the window) and terminate the application.
1529 // The close message is generated by the window manager when its close
1530 // window menu item is selected.
1531
1532 // CloseWindow must be overwritten because otherwise CloseWindow
1533 // and the destructor are calling DestroyWindow which seems to be
1534 // in conflict with the TRootEmbeddedCanvas.
1535
1536 // FIXME: Make sure that the Status Display is deleted from every
1537 // where (eg Eventloop) first!
1538
1539 //gLog << dbg << fName << " is on heap: " << (int)IsOnHeap() << endl;
1540
1541 if (TestBit(kExitLoopOnExit) || TestBit(kExitLoopOnClose))
1542 {
1543 //gLog << dbg << "CloseWindow() calling ExitLoop." << endl;
1544 gSystem->ExitLoop();
1545 }
1546
1547 if (fIsLocked<=0 && IsOnHeap())
1548 return kTRUE;
1549
1550 fStatus = kFileExit;
1551 return kFALSE;
1552}
1553
1554void MStatusDisplay::CloseWindow()
1555{
1556 if (Close())
1557 delete this;
1558}
1559
1560// --------------------------------------------------------------------------
1561//
1562// Calls SetBit(kNoContextMenu) for all TCanvas objects found in the
1563// Tabs.
1564//
1565void MStatusDisplay::SetNoContextMenu(Bool_t flag)
1566{
1567 if (fIsLocked>1 || gROOT->IsBatch())
1568 return;
1569
1570 flag ? SetBit(kNoContextMenu) : ResetBit(kNoContextMenu);
1571
1572 for (int i=1; i<fTab->GetNumberOfTabs(); i++)
1573 {
1574 TCanvas *c = GetCanvas(i);
1575 if (c)
1576 flag ? c->SetBit(kNoContextMenu) : c->ResetBit(kNoContextMenu);
1577 }
1578}
1579
1580// --------------------------------------------------------------------------
1581//
1582// Update the memory display in the status bar
1583//
1584void MStatusDisplay::UpdateMemory() const
1585{
1586 const TString path = MString::Form("/proc/%d/status", gSystem->GetPid());
1587 if (gSystem->AccessPathName(path, kFileExists))
1588 return;
1589
1590 TEnv env(path);
1591 const UInt_t kb = env.GetValue("VmSize", 0);
1592 if (kb==0)
1593 return;
1594
1595 char type = 'k';
1596 Float_t val = kb;
1597
1598 if (val>999)
1599 {
1600 type = 'M';
1601 val /= 1024;
1602 }
1603 if (val>999)
1604 {
1605 type = 'G';
1606 val /= 1024;
1607 }
1608 const TString txt = MString::Form("%.1f%c", val, type);
1609 fStatusBar->SetText(txt, 2);
1610}
1611
1612// --------------------------------------------------------------------------
1613//
1614// Updates the canvas (if existing) in the currenly displayed Tab.
1615// The update intervall is controlled by StartUpdate and StopUpdate
1616//
1617Bool_t MStatusDisplay::HandleTimer(TTimer *timer)
1618{
1619 if (gROOT->IsBatch())
1620 return kTRUE;
1621
1622 UpdateMemory();
1623
1624 const Int_t c = fTab->GetCurrent();
1625
1626 // Skip Legend Tab
1627 if (c==0)
1628 return kTRUE;
1629
1630 // Update a canvas tab (if visible)
1631 if (timer==&fTimer && c!=fLogIdx)
1632 {
1633 UpdateTab(fTab->GetCurrentContainer());
1634 return kTRUE;
1635 }
1636
1637 // update the logbook tab (if visible)
1638 if (timer==&fLogTimer && c==fLogIdx)
1639 {
1640 fLog->UpdateGui();
1641
1642 /*
1643 if (!fLogBox->TestBit(kHasChanged))
1644 return kTRUE;
1645
1646 fLogBox->ResetBit(kHasChanged);
1647 */
1648 return kTRUE;
1649 }
1650
1651 return kTRUE;
1652}
1653
1654// --------------------------------------------------------------------------
1655//
1656// Draws a clone of a canvas into a new canvas. Taken from TCanvas.
1657//
1658void MStatusDisplay::DrawClonePad(TCanvas &newc, TCanvas &oldc) const
1659{
1660 //copy pad attributes
1661 newc.Range(oldc.GetX1(),oldc.GetY1(),oldc.GetX2(),oldc.GetY2());
1662 newc.SetTickx(oldc.GetTickx());
1663 newc.SetTicky(oldc.GetTicky());
1664 newc.SetGridx(oldc.GetGridx());
1665 newc.SetGridy(oldc.GetGridy());
1666 newc.SetLogx(oldc.GetLogx());
1667 newc.SetLogy(oldc.GetLogy());
1668 newc.SetLogz(oldc.GetLogz());
1669 newc.SetBorderSize(oldc.GetBorderSize());
1670 newc.SetBorderMode(oldc.GetBorderMode());
1671 ((TAttLine&)oldc).Copy((TAttLine&)newc);
1672 ((TAttFill&)oldc).Copy((TAttFill&)newc);
1673 ((TAttPad&)oldc).Copy((TAttPad&)newc);
1674
1675 // This must be there: Otherwise GetDrawOption() won't work
1676 TVirtualPad *padsav = gPad;
1677 oldc.cd();
1678
1679 const Bool_t store = TH1::AddDirectoryStatus();
1680 TH1::AddDirectory(kFALSE);
1681
1682 //copy primitives
1683 TObject *obj;
1684 TIter next(oldc.GetListOfPrimitives());
1685 while ((obj=next()))
1686 {
1687 // Old line - I think it is not necessary anymore because of the cd()
1688 //gROOT->SetSelectedPad(&newc);
1689
1690 // Now make a clone of the object
1691 TObject *clone = obj->Clone();
1692
1693 // Clone also important bits (FIXME: Is this correct)
1694 clone->SetBit(obj->TestBits(kCannotPick|kNoContextMenu));
1695
1696 // Now make sure that the clones are deleted at a later time
1697 clone->SetBit(kCanDelete|kMustCleanup);
1698
1699 // FIXME: This is a workaround for the problem with the MAstroCatalog in
1700 // MHFalseSource. It doesn't harm. We'll still try to find the reason
1701 if (clone->IsA()==TPad::Class())
1702 gROOT->GetListOfCleanups()->Add(clone);
1703
1704 // Add the clone and its draw-option to the current pad
1705 TVirtualPad *save2 = gPad;
1706 gPad = &oldc; // Don't do this before Clone()!
1707 newc.GetListOfPrimitives()->Add(clone, obj->GetDrawOption());
1708 gPad = save2;
1709 }
1710 newc.Modified();
1711 newc.Update();
1712
1713 TH1::AddDirectory(store);
1714
1715 padsav->cd();
1716}
1717
1718Bool_t MStatusDisplay::Display(const TObjArray &list, const char *tab)
1719{
1720 TIter Next(&list);
1721
1722 TObject *o=Next();
1723 if (!o)
1724 {
1725 *fLog << err << "MStatusDisplay::Display: No entry in TObjArray." << endl;
1726 return kFALSE;
1727 }
1728
1729 fTitle = o->GetTitle();
1730
1731 TCanvas *c;
1732 while ((c=(TCanvas*)Next()))
1733 //if (!GetCanvas(c->GetName()))
1734 if (!tab || c->GetName()==(TString)tab)
1735 DrawClonePad(AddTab(c->GetName()), *c);
1736
1737 return kTRUE;
1738}
1739
1740// --------------------------------------------------------------------------
1741//
1742// Reads the contents of a saved MStatusDisplay from a file.
1743//
1744Int_t MStatusDisplay::Read(const char *name, const char *tab)
1745{
1746 if (!gFile)
1747 {
1748 *fLog << warn << "MStatusDisplay::Read: No file found. Please create a TFile first." << endl;
1749 return 0;
1750 }
1751
1752 if (!gFile->IsOpen())
1753 {
1754 *fLog << warn << "MStatusDisplay::Read: File not open. Please open the TFile first." << endl;
1755 return 0;
1756 }
1757
1758 MStatusArray list;
1759
1760 const Int_t n = list.Read(name);
1761 if (n==0)
1762 {
1763 *fLog << warn << "MStatusDisplay::Read: No objects read." << endl;
1764 return 0;
1765 }
1766
1767 if (!Display(list, tab))
1768 {
1769 *fLog << err << "MStatusDisplay::Display: No entry in " << name << "." << endl;
1770 return 0;
1771 }
1772
1773 *fLog << inf << "MStatusDisplay: Key " << name << " with " << n << " keys read from file." << endl;
1774
1775 return n;
1776}
1777
1778// --------------------------------------------------------------------------
1779//
1780// Writes the contents of a MStatusDisplay to a file.
1781//
1782Int_t MStatusDisplay::Write(Int_t num, const char *name, Int_t option, Int_t bufsize) const
1783{
1784 if (!gFile)
1785 {
1786 *fLog << warn << "MStatusDisplay::Write: No file found. Please create a TFile first." << endl;
1787 return 0;
1788 }
1789
1790 if (!gFile->IsOpen())
1791 {
1792 *fLog << warn << "MStatusDisplay::Write: File not open. Please open the TFile first." << endl;
1793 return 0;
1794 }
1795
1796 if (!gFile->IsWritable())
1797 {
1798 *fLog << warn << "MStatusDisplay::Write: File not writable." << endl;
1799 return 0;
1800 }
1801
1802 if (num==0)
1803 {
1804 *fLog << warn << "MStatusDisplay::Write: Tab doesn't contain an embedded Canvas... skipped." << endl;
1805 return 0;
1806 }
1807
1808 if (!gROOT->IsBatch() && num>=fTab->GetNumberOfTabs())
1809 {
1810 *fLog << warn << "MStatusDisplay::Write: Tab doesn't exist... skipped." << endl;
1811 return 0;
1812 }
1813 if (gROOT->IsBatch() && num>fBatch->GetSize())
1814 {
1815 *fLog << warn << "MStatusDisplay::Write: Tab doesn't exist... skipped." << endl;
1816 return 0;
1817 }
1818
1819 MStatusArray list;
1820
1821 TNamed named;
1822 named.SetTitle(fTitle);
1823 list.Add(&named);
1824
1825 const Int_t max = gROOT->IsBatch() ? fBatch->GetSize()+1 : fTab->GetNumberOfTabs();
1826 const Int_t from = num<0 ? 1 : num;
1827 const Int_t to = num<0 ? max : num+1;
1828
1829 TCanvas *c;
1830 for (int i=from; i<to; i++)
1831 if ((c = GetCanvas(i)))
1832 list.Add(c);
1833
1834 const Int_t n = list.Write(name, kSingleKey);
1835
1836 //*fLog << inf << "MStatusDisplay: " << n << " keys written to file as key " << name << "." << endl;
1837
1838 return n;
1839}
1840
1841// --------------------------------------------------------------------------
1842//
1843// Use this to start the synchronous (GUI eventloop driven) tab update.
1844// Can also be used to change the update intervall. If millisec<0
1845// the intervall given in SetUpdateTime is used. If the intervall in
1846// SetUpdateTime is <0 nothing is done. (Call SetUpdateTime(-1) to
1847// disable the automatic update in a MEventloop.
1848//
1849void MStatusDisplay::StartUpdate(Int_t millisec)
1850{
1851 if (fIsLocked>1)
1852 return;
1853
1854 if (fTimer.GetTime()<TTime(0))
1855 return;
1856 fTimer.Start(millisec);
1857}
1858
1859// --------------------------------------------------------------------------
1860//
1861// Stops the automatic GUI update
1862//
1863void MStatusDisplay::StopUpdate()
1864{
1865 if (fIsLocked>1)
1866 return;
1867
1868 fTimer.Stop();
1869}
1870
1871// --------------------------------------------------------------------------
1872//
1873// Set the update interval for the GUI update, see StartUpdate.
1874//
1875void MStatusDisplay::SetUpdateTime(Long_t t)
1876{
1877 fTimer.SetTime(t);
1878}
1879
1880// --------------------------------------------------------------------------
1881//
1882// Set the background color in a canvas
1883//
1884void MStatusDisplay::CanvasSetFillColor(TPad &p, Int_t col) const
1885{
1886 TObject *obj;
1887
1888 // See also TPad::UseCurrentStyle
1889 TIter Next(p.GetListOfPrimitives());
1890 while ((obj=Next()))
1891 {
1892 if (obj->InheritsFrom(TPad::Class()))
1893 CanvasSetFillColor(*(TPad*)obj, col);
1894 if (obj->InheritsFrom(TFrame::Class()))
1895 ((TFrame*)obj)->SetFillColor(col);
1896 }
1897
1898 p.SetFillColor(col);
1899}
1900
1901// --------------------------------------------------------------------------
1902//
1903// If the filename name doesn't end with ext, ext is added to the end.
1904// If name.IsNull() "status" is assumed and the a number (>0) is added
1905// as "status-6".
1906// The extension is returned.
1907//
1908const TString &MStatusDisplay::AddExtension(TString &name, const TString &ext, Int_t num) const
1909{
1910 if (name.IsNull())
1911 {
1912 name = "status";
1913 if (num>0)
1914 {
1915 name += "-";
1916 name += num;
1917 }
1918 }
1919
1920 if (name.EndsWith("."+ext))
1921 return ext;
1922
1923 name += ".";
1924 name += ext;
1925
1926 return ext;
1927}
1928
1929Bool_t MStatusDisplay::CheckTabForCanvas(int num) const
1930{
1931 if (gROOT->IsBatch())
1932 return num>0 && num<=fBatch->GetSize() || num<0;
1933
1934 if (num>=fTab->GetNumberOfTabs())
1935 {
1936 *fLog << warn << "Tab #" << num << " doesn't exist..." << endl;
1937 return kFALSE;
1938 }
1939 if (num==0)
1940 {
1941 *fLog << warn << "Tab #" << num << " doesn't contain an embedded canvas..." << endl;
1942 return kFALSE;
1943 }
1944 if (fTab->GetNumberOfTabs()<2 || !gPad)
1945 {
1946 *fLog << warn << "Sorry, you must have at least one existing canvas (gPad!=NULL)" << endl;
1947 return kFALSE;
1948 }
1949 return kTRUE;
1950}
1951
1952// --------------------------------------------------------------------------
1953//
1954// Insert the following two lines into the postscript header:
1955//
1956// %%DocumentPaperSizes: a4
1957// %%Orientation: Landscape
1958//
1959void MStatusDisplay::UpdatePSHeader(const TString &name) const
1960{
1961 const TString newstr("%%DocumentPaperSizes: a4\n%%Orientation: Landscape\n");
1962
1963 ifstream fin(name);
1964 ofstream fout(name+".$$$");
1965
1966 char c;
1967
1968 TString str;
1969 fin >> str >> c; // Read "%!PS-Adobe-2.0\n"
1970 fout << str << endl << newstr;
1971
1972 // Doing it in blocks seems not to gain much for small (MB) files
1973 while (fin)
1974 {
1975 fin.read(&c, 1);
1976 fout.write(&c, 1);
1977 }
1978
1979 gSystem->Unlink(name);
1980 gSystem->Rename(name+".$$$", name);
1981/*
1982 //
1983 // Old style algorithm. Shifts blocks inside a single file --- SLOW!
1984 //
1985 const Int_t l = newstr.Length();
1986
1987 Long_t t[4]; // { id, size, flags, modtime }
1988 gSystem->GetPathInfo(name, t, t+1, t+2, t+3);
1989
1990 char *c[2] = { new char[l], new char[l] };
1991
1992 fstream f(name, ios::in|ios::out);
1993
1994 TString str;
1995 f >> str >> c[0][0]; // Read "%!PS-Adobe-2.0\n" (Mini Header)
1996 f.read(c[0], l);
1997 f.seekp(-l, ios::cur);
1998 f.write(newstr, l);
1999
2000 int i=0;
2001 while (1)
2002 {
2003 f.read(c[(i+1)%2], l);
2004 f.seekp(-l, ios::cur);
2005
2006 if (f)
2007 {
2008 f.write(c[i%2],l);
2009 i++;
2010 i%=2;
2011 continue;
2012 }
2013
2014 const Int_t ssz = str.Length()+1; // Length of Mini-Header
2015 const Int_t block = t[1]-ssz; // Length of block to be shifted
2016 const Int_t size = block%l; // Reminder
2017 const Int_t pos = (block/l)*l + ssz + 1; // Position to start writing
2018
2019 f.clear();
2020 f.seekp(pos);
2021 f.write(c[i%2], l);
2022 f.write(c[(i+1)%2], size);
2023 break;
2024 }
2025
2026 delete c[1];
2027 delete c[0];
2028*/
2029}
2030
2031// --------------------------------------------------------------------------
2032//
2033// In case of num<0 all tabs are written into the PS file. If num>0
2034// the canvas in the corresponding tab is written to the file.
2035// Name is the name of the file (with or without extension).
2036//
2037// Returns the number of pages written.
2038//
2039// To write all tabs you can also use SaveAsPS(name)
2040//
2041// If the third argument is given a bottom line is drawn with the text
2042// under it. If no argument is given a bottom line is drawn if
2043// fTitle (SetTitle) is not empty.
2044//
2045Int_t MStatusDisplay::SaveAsPS(Int_t num, TString name, const TString addon)
2046{
2047 SetStatusLine1("Writing Postscript file...");
2048 SetStatusLine2("");
2049
2050 if (!CheckTabForCanvas(num))
2051 {
2052 SetStatusLine2("Failed!");
2053 return 0;
2054 }
2055
2056 AddExtension(name, "ps", num);
2057
2058 if (num<0)
2059 *fLog << inf << "Open ps-File: " << name << endl;
2060
2061 TPad *padsav = (TPad*)gPad;
2062 TVirtualPS *psave = gVirtualPS;
2063
2064 TDatime d;
2065
2066 TPostScript ps(name, 112);
2067 ps.SetBit(TPad::kPrintingPS);
2068 ps.PrintFast(13, "/nan {1} def ");
2069
2070 gVirtualPS = &ps;
2071
2072 //
2073 // Create a list to delete the canvas clones
2074 //
2075 TList l;
2076 l.SetOwner();
2077
2078 //
2079 // Create some GUI elements for a page legend
2080 //
2081 TLine line;
2082
2083 int page = 1;
2084
2085 //
2086 // Maintain tab numbers
2087 //
2088 const Int_t max = gROOT->IsBatch() ? fBatch->GetSize()+1 : fTab->GetNumberOfTabs();
2089 const Int_t from = num<0 ? 1 : num;
2090 const Int_t to = num<0 ? max : num+1;
2091
2092 for (int i=from; i<to; i++)
2093 {
2094 TCanvas *c;
2095 if (!(c = GetCanvas(i)))
2096 {
2097 if (num<0)
2098 *fLog << inf << " - ";
2099 *fLog << "Tab #" << i << " doesn't contain an embedded Canvas... skipped." << endl;
2100 continue;
2101 }
2102
2103 SetStatusLine2(MString::Form("Tab #%d", i));
2104
2105 //
2106 // Init page and page size, make sure, that the canvas in the file
2107 // has the same Aspect Ratio than on the screen.
2108 //
2109 ps.NewPage();
2110
2111 //
2112 // 28 is used here to scale the canvas into a height of 28,
2113 // such that the page title can be set above the canvas...
2114 //
2115 Float_t psw = 28.0; // A4 - width (29.7)
2116 Float_t psh = 21.0; // A4 - height (21.0)
2117
2118 const Float_t cw = c->GetWw();
2119 const Float_t ch = c->GetWh();
2120
2121 if (psw/psh>cw/ch)
2122 psw = cw/ch*psh;
2123 else
2124 psh = ch/cw*psw;
2125
2126 ps.Range(psw, psh); // A4
2127
2128 //
2129 // Clone canvas and change background color and schedule for
2130 // deletion
2131 //
2132 TCanvas *n = (TCanvas*)c->Clone();
2133 CanvasSetFillColor(*n, kWhite);
2134 l.Add(n);
2135
2136 //
2137 // Paint canvas into root file
2138 //
2139 if (num<0)
2140 *fLog << inf << " - ";
2141 *fLog << inf << "Writing Tab #" << i << ": " << c->GetName() << " (" << c << ") ";
2142 if (num>0)
2143 *fLog << "to " << name;
2144 *fLog << "... " << flush;
2145
2146 n->SetBatch(kTRUE);
2147 n->Paint();
2148
2149 //
2150 // Use the canvas as coordinate system for the overlaying text
2151 //
2152 gPad = n;
2153 //n->cd();
2154
2155 //
2156 // Print overlaying text (NDC = %)
2157 //
2158 ps.SetTextColor(kBlack);
2159 ps.SetTextSize(0.015);
2160 ps.SetTextFont(22);
2161 ps.SetTextAlign(11); // left top
2162 ps.TextNDC(0, 1.015, TString(" ")+n->GetName());
2163 ps.SetTextAlign(21); // cent top
2164 ps.TextNDC(0.5, 1.015, TString("MARS - Magic Analysis and Reconstruction Software - ")+d.AsString());
2165 ps.SetTextAlign(31); // right top
2166 ps.TextNDC(1, 1.015, MString::Form("Page No.%i (%i) ", page++, i));
2167 line.PaintLineNDC(0, 1.01, 1, 1.01);
2168
2169 TString txt(addon.IsNull() ? fTitle : addon);
2170 if (!txt.IsNull())
2171 {
2172 line.PaintLineNDC(0, -0.00, 1, -0.00);
2173 ps.SetTextAlign(11); // left top
2174 ps.TextNDC(0, -0.015, TString(" ")+txt);
2175 ps.SetTextAlign(31); // right top
2176 ps.TextNDC(1, -0.015, "(c) 2000-2004, Thomas Bretz ");
2177 }
2178
2179 //
2180 // Finish drawing page
2181 //
2182 n->SetBatch(kFALSE);
2183 *fLog << "done." << endl;
2184 }
2185
2186 gPad = NULL; // Important!
2187 l.Delete();
2188
2189 ps.Close();
2190
2191 SetStatusLine2("Updating header of PS file...");
2192
2193 if (num<0)
2194 *fLog << " - Updating header of PS file... " << flush;
2195 UpdatePSHeader(name);
2196 if (num<0)
2197 *fLog << inf << "done." << endl;
2198
2199 gVirtualPS = psave;
2200 if (padsav)
2201 padsav->cd();
2202
2203 if (num<0)
2204 *fLog << inf << "done." << endl;
2205
2206 SetStatusLine2(MString::Form("Done (%dpages)", page-1));
2207
2208 return page-1;
2209}
2210
2211Bool_t MStatusDisplay::SaveAsImage(Int_t num, TString name, TImage::EImageFileTypes type)
2212{
2213 if (gROOT->IsBatch())
2214 {
2215 *fLog << warn << "Sorry, writing image-files is not available in batch mode." << endl;
2216 //*fLog << warn << "Sorry, writing gif-files is not available in batch mode." << endl;
2217 return 0;
2218 }
2219 //SetStatusLine1("Writing GIF file...");
2220 SetStatusLine1("Writing image file... <please be patient>");
2221 SetStatusLine2("");
2222
2223 if (!CheckTabForCanvas(num))
2224 {
2225 SetStatusLine2("Failed!");
2226 return 0;
2227 }
2228
2229 TString ext;
2230 switch (type)
2231 {
2232 case TImage::kXpm:
2233 case TImage::kZCompressedXpm:
2234 ext = AddExtension(name, "xpm", num);
2235 break;
2236// case TImage::kGZCompressedXpm:
2237// ext = AddExtension(name, "xpm.gz", num);
2238// break;
2239 case TImage::kPng:
2240 ext = AddExtension(name, "png", num);
2241 break;
2242 case TImage::kJpeg:
2243 ext = AddExtension(name, "jpg", num);
2244 break;
2245// case TImage::kXcf:
2246// ext = AddExtension(name, "xcf", num);
2247// break;
2248// case TImage::kPpm:
2249// ext = AddExtension(name, "ppm", num);
2250// break;
2251// case TImage::kPnm:
2252// ext = AddExtension(name, "pnm", num);
2253// break;
2254// case TImage::kBmp:
2255// ext = AddExtension(name, "bmp", num);
2256// break;
2257// case TImage::kIco:
2258// ext = AddExtension(name, "ico", num);
2259// break;
2260// case TImage::kCur:
2261// ext = AddExtension(name, "cur", num);
2262// break;
2263 case TImage::kGif:
2264 ext = AddExtension(name, "gif", num);
2265 break;
2266// case TImage::kTiff:
2267// ext = AddExtension(name, "tif", num);
2268// break;
2269// case TImage::kXbm:
2270// ext = AddExtension(name, "xbm", num);
2271// break;
2272// case TImage::kFits:
2273// ext = AddExtension(name, "fits", num);
2274// break;
2275// case TImage::kTga:
2276// ext = AddExtension(name, "tga", num);
2277// break;
2278// case TImage::kXml:
2279// ext = AddExtension(name, "xml", num);
2280// break;
2281 default:
2282 *fLog << warn << "Sorry, unknown or unsupported file type..." << endl;
2283 return 0;
2284 }
2285
2286 if (num<0)
2287 *fLog << inf << "Writing " << ext << "-Files..." << endl;
2288
2289 TPad *padsav = (TPad*)gPad;
2290
2291 int page = 1;
2292
2293 //
2294 // Maintain tab numbers
2295 //
2296 const Int_t from = num<0 ? 1 : num;
2297 const Int_t to = num<0 ? fTab->GetNumberOfTabs() : num+1;
2298
2299 for (int i=from; i<to; i++)
2300 {
2301 TCanvas *c;
2302 if (!(c = GetCanvas(i)))
2303 {
2304 if (num<0)
2305 *fLog << inf << " - ";
2306 *fLog << "Tab #" << i << " doesn't contain an embedded Canvas... skipped." << endl;
2307 continue;
2308 }
2309
2310 SetStatusLine2(MString::Form("Tab #%d", i));
2311
2312 //
2313 // Clone canvas and change background color and schedule for
2314 // deletion
2315 //
2316 //TCanvas *n = (TCanvas*)c->Clone();
2317 //CanvasSetFillColor(*n, kWhite);
2318
2319 //
2320 // Paint canvas into root file
2321 //
2322 TString writename = name;
2323 if (num<0)
2324 {
2325 TString numname = "-";
2326 numname += i;
2327 writename.Insert(name.Last('.'), numname);
2328 }
2329 if (num<0)
2330 *fLog << inf << " - ";
2331 *fLog << inf << "Writing Tab #" << i << " to " << writename << ": " << c->GetName() << " (" << c << ") ";
2332 if (num>0)
2333 *fLog << "to " << name;
2334 *fLog << "..." << flush;
2335
2336 c->Draw();
2337 if (type==TImage::kGif)
2338 c->SaveAs(writename); // FIXME: Seems not to work well in TImage! (root 3.10/02)
2339 else
2340 {
2341 TImage *img = TImage::Create();
2342 img->FromPad(c);
2343 img->WriteImage(writename, type);
2344 delete img;
2345 }
2346
2347 if (num<0)
2348 *fLog << "done." << endl;
2349 }
2350
2351 padsav->cd();
2352
2353 *fLog << inf << "done." << endl;
2354
2355 SetStatusLine2("Done.");
2356
2357 return page-1;
2358}
2359
2360Bool_t MStatusDisplay::SaveAsC(Int_t num, TString name)
2361{
2362 SetStatusLine1("Writing C++ file...");
2363 SetStatusLine2("");
2364
2365 if (!CheckTabForCanvas(num))
2366 {
2367 SetStatusLine2("Failed!");
2368 return 0;
2369 }
2370
2371 AddExtension(name, "C", num);
2372
2373 if (num<0)
2374 *fLog << inf << "Writing C-Files..." << endl;
2375
2376 TPad *padsav = (TPad*)gPad;
2377
2378 int page = 1;
2379
2380 //
2381 // Maintain tab numbers
2382 //
2383 const Int_t from = num<0 ? 1 : num;
2384 const Int_t to = num<0 ? fTab->GetNumberOfTabs() : num+1;
2385
2386 for (int i=from; i<to; i++)
2387 {
2388 TCanvas *c;
2389 if (!(c = GetCanvas(i)))
2390 {
2391 if (num<0)
2392 *fLog << inf << " - ";
2393 *fLog << "Tab #" << i << " doesn't contain an embedded Canvas... skipped." << endl;
2394 continue;
2395 }
2396
2397 SetStatusLine2(MString::Form("Tab #%d", i));
2398
2399 //
2400 // Clone canvas and change background color and schedule for
2401 // deletion
2402 //
2403 TCanvas *n = (TCanvas*)c->Clone();
2404 CanvasSetFillColor(*n, kWhite);
2405
2406 //
2407 // Paint canvas into root file
2408 //
2409 TString writename = name;
2410 if (num<0)
2411 {
2412 TString numname = "-";
2413 numname += i;
2414 writename.Insert(name.Last('.'), numname);
2415 }
2416 if (num<0)
2417 *fLog << inf << " - ";
2418 *fLog << inf << "Writing Tab #" << i << " to " << writename << ": " << c->GetName() << " (" << n << ") ";
2419 if (num>0)
2420 *fLog << "to " << name;
2421 *fLog << "..." << flush;
2422
2423 n->SaveSource(writename, "");
2424 delete n;
2425
2426 if (num<0)
2427 *fLog << "done." << endl;
2428 }
2429
2430 padsav->cd();
2431
2432 *fLog << inf << "done." << endl;
2433
2434 SetStatusLine2("Done.");
2435
2436 return page-1;
2437}
2438
2439// --------------------------------------------------------------------------
2440//
2441// In case of num<0 all tabs are written into the PS file. If num>0
2442// the canvas in the corresponding tab is written to the file.
2443// Name is the name of the file (with or without extension).
2444//
2445// Returns the number of keys written.
2446//
2447// To write all tabs you can also use SaveAsPS(name)
2448//
2449Int_t MStatusDisplay::SaveAsRoot(Int_t num, TString name)
2450{
2451 SetStatusLine1("Writing root file...");
2452 SetStatusLine2("");
2453
2454 if (!CheckTabForCanvas(num))
2455 {
2456 SetStatusLine2("Failed!");
2457 return 0;
2458 }
2459
2460 AddExtension(name, "root", num);
2461
2462 TFile *fsave = gFile;
2463 TFile file(name, "RECREATE", "MARS - Status Window Contents", 9);
2464 const Int_t keys = Write(num);
2465 gFile = fsave;
2466
2467 SetStatusLine2("Done.");
2468
2469 return keys;
2470}
2471
2472// --------------------------------------------------------------------------
2473//
2474// Opens a save as dialog
2475//
2476Int_t MStatusDisplay::SaveAs(Int_t num)
2477{
2478 static const char *gSaveAsTypes[] =
2479 {
2480 "PostScript", "*.ps",
2481 "Gif files", "*.gif",
2482 "Macro files", "*.C",
2483 "ROOT files", "*.root",
2484 "All files", "*",
2485 NULL, NULL
2486 };
2487
2488 static TString dir(".");
2489
2490 TGFileInfo fi; // fFileName and fIniDir deleted in ~TGFileInfo
2491
2492 fi.fFileTypes = (const char**)gSaveAsTypes;
2493 fi.fIniDir = StrDup(dir);
2494
2495 new TGFileDialog(fClient->GetRoot(), this, kFDSave, &fi);
2496
2497 if (!fi.fFilename)
2498 return 0;
2499
2500 dir = fi.fIniDir;
2501
2502 const TString name(fi.fFilename);
2503
2504 if (name.EndsWith(".root")) return SaveAsRoot(num, name);
2505 if (name.EndsWith(".ps")) return SaveAsPS(num, name);
2506 if (name.EndsWith(".gif")) return SaveAsGIF(num, name);
2507 if (name.EndsWith(".C")) return SaveAsC(num, name);
2508
2509 Warning("MStatusDisplay::SaveAs", "Unknown Extension: %s", fi.fFilename);
2510 return 0;
2511}
2512
2513// --------------------------------------------------------------------------
2514//
2515// Open contents of a MStatusDisplay with key name from file fname.
2516//
2517Int_t MStatusDisplay::Open(TString fname, const char *name)
2518{
2519 TFile file(fname, "READ");
2520 if (file.IsZombie())
2521 {
2522 gLog << warn << "WARNING - Cannot open file " << fname << endl;
2523 return 0;
2524 }
2525
2526 return Read(name);
2527}
2528
2529// --------------------------------------------------------------------------
2530//
2531// Opens an open dialog
2532//
2533Int_t MStatusDisplay::Open()
2534{
2535 static const char *gOpenTypes[] =
2536 {
2537 "ROOT files", "*.root",
2538 "All files", "*",
2539 NULL, NULL
2540 };
2541
2542 static TString dir(".");
2543
2544 TGFileInfo fi; // fFileName and fIniDir deleted in ~TGFileInfo
2545
2546 fi.fFileTypes = (const char**)gOpenTypes;
2547 fi.fIniDir = StrDup(dir);
2548
2549 new TGFileDialog(fClient->GetRoot(), this, kFDSave, &fi);
2550
2551 if (!fi.fFilename)
2552 return 0;
2553
2554 dir = fi.fIniDir;
2555
2556 return Open(fi.fFilename);
2557}
2558
2559Bool_t MStatusDisplay::HandleConfigureNotify(Event_t *evt)
2560{
2561 //
2562 // The initialization of the GUI is not yet enough finished...
2563 //
2564 if (!fTab)
2565 return kTRUE;
2566
2567 UInt_t w = evt->fWidth;
2568 UInt_t h = evt->fHeight;
2569
2570 /*
2571 cout << "Old: " << GetWidth() << " " << GetHeight() << " " << GetBorderWidth() << endl;
2572 cout << "New: " << w << " " << h << " ";
2573 cout << "New: " << GetDefaultWidth() << " " << GetDefaultHeight() << " " << endl;
2574 */
2575
2576 Bool_t wchanged = w!=GetWidth();
2577 Bool_t hchanged = h!=GetHeight();
2578
2579 if (!wchanged && !hchanged)
2580 {
2581 Layout();
2582 // FIXME: Make sure that this doesn't result in endless loops.
2583 return kTRUE;
2584 }
2585
2586
2587 if (GetWidth()==1 && GetHeight()==1)
2588 return kTRUE;
2589
2590 // calculate the constant part of the window
2591 const UInt_t cw = GetWidth() -fTab->GetWidth();
2592 const UInt_t ch = GetHeight()-fTab->GetHeight();
2593
2594 // calculate new size of frame (canvas @ 1:sqrt(2))
2595 if (hchanged)
2596 w = (UInt_t)((h-ch)*sqrt(2.)+.5)+cw;
2597 else
2598 h = (UInt_t)((w-cw)/sqrt(2.)+.5)+ch;
2599
2600 // resize frame
2601 Resize(w, h);
2602
2603 return kTRUE;
2604}
2605
2606Bool_t MStatusDisplay::HandleEvent(Event_t *event)
2607{
2608 // Instead of doing this in CloseWindow (called from HandleEvent)
2609 // we do it here. This makes sure, that handle event doesn't
2610 // execute code after deleting this.
2611 if (event->fType==kDestroyNotify)
2612 {
2613 if (Close())
2614 delete this;
2615// Close();
2616 return kTRUE;
2617 }
2618
2619 const Bool_t rc = TGMainFrame::HandleEvent(event);
2620
2621 //
2622 // This fixes a bug in older root versions which makes
2623 // TCanvas crash if gPad==NULL. So we make sure, that
2624 // gPad!=NULL -- be carfull, this may have other side
2625 // effects.
2626 //
2627#if ROOT_VERSION_CODE < ROOT_VERSION(3,10,01)
2628 if (!gPad && fTab)
2629 for (int i=0; i<fTab->GetNumberOfTabs(); i++)
2630 {
2631 TCanvas *c = GetCanvas(i);
2632 if (c)
2633 {
2634 c->cd();
2635 gLog << dbg << "MStatusDisplay::HandleEvent - Workaround: gPad=" << gPad << "." << endl;
2636 break;
2637 }
2638 }
2639#endif
2640
2641 return rc;
2642}
Note: See TracBrowser for help on using the repository browser.