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

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