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