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, MString::Format("(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 | *fLog << inf3 << "Adding Canvas '" << name << "' (" << c->GetWw() << "x";
|
---|
1108 | *fLog << c->GetWh() << ", TCanvas=" << c << ")" << endl;
|
---|
1109 |
|
---|
1110 | // Remove the canvas from the global list to make sure it is
|
---|
1111 | // not found by gROOT->FindObject
|
---|
1112 | //gROOT->GetListOfCanvases()->Remove(c);
|
---|
1113 | //gROOT->GetListOfCleanups()->Add(c);
|
---|
1114 |
|
---|
1115 | return *c;
|
---|
1116 | }
|
---|
1117 |
|
---|
1118 | // Add new tab
|
---|
1119 | TGCompositeFrame *f = fTab->AddTab(name);
|
---|
1120 |
|
---|
1121 | // create root embedded canvas and add it to the tab
|
---|
1122 | TRootEmbeddedCanvas *ec = new TRootEmbeddedCanvas(name, f, f->GetWidth(), f->GetHeight(), kSunkenFrame);
|
---|
1123 | f->AddFrame(ec, fLayCanvas);
|
---|
1124 | fList->Add(ec);
|
---|
1125 |
|
---|
1126 | // set background and border mode of the canvas
|
---|
1127 | TCanvas &c = *ec->GetCanvas();
|
---|
1128 |
|
---|
1129 | if (title)
|
---|
1130 | c.SetTitle(title);
|
---|
1131 |
|
---|
1132 | c.SetFillColor(10); // White
|
---|
1133 | c.SetFrameBorderMode(0);
|
---|
1134 | c.SetBorderMode(0);
|
---|
1135 |
|
---|
1136 | // If kNoContextMenu set set kNoContextMenu of the canvas
|
---|
1137 | if (TestBit(kNoContextMenu))
|
---|
1138 | c.SetBit(kNoContextMenu);
|
---|
1139 |
|
---|
1140 | // Connect all TCanvas::ProcessedEvent to this->EventInfo
|
---|
1141 | // This means, that after TCanvas has processed an event
|
---|
1142 | // EventInfo of this class is called, see TCanvas::HandleInput
|
---|
1143 | c.Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)",
|
---|
1144 | "MStatusDisplay", this, "EventInfo(Int_t,Int_t,Int_t,TObject*)");
|
---|
1145 |
|
---|
1146 | // Make sure that root itself doesn't try to call GetObjectInfo
|
---|
1147 | // This is now handled from EventsInfo. This is necessary
|
---|
1148 | // due to the buffer overflow bug in GetObjectInfo of
|
---|
1149 | // TProfile and TH1
|
---|
1150 | c.ResetBit(TCanvas::kShowEventStatus);
|
---|
1151 |
|
---|
1152 | // Remove the canvas from the global list to make sure it is
|
---|
1153 | // not found by gROOT->FindObject
|
---|
1154 | //gROOT->GetListOfCanvases()->Remove(&c);
|
---|
1155 | //gROOT->GetListOfCleanups()->Add(&c);
|
---|
1156 |
|
---|
1157 | TGComboBox *box = (TGComboBox*)fList->FindWidget(kTabs);
|
---|
1158 | box->AddEntry(name, box->GetListBox()->GetNumberOfEntries());
|
---|
1159 |
|
---|
1160 | // layout and map new tab
|
---|
1161 | Layout(); // seems to layout the TGCompositeFrame
|
---|
1162 | MapSubwindows(); // maps the TGCompositeFrame
|
---|
1163 | Layout(); // layout the embedded canvas in the frame
|
---|
1164 |
|
---|
1165 | // display new tab in the main frame
|
---|
1166 | // FIXME: This is a workaround, because TApplication::Run is not
|
---|
1167 | // thread safe against ProcessEvents. We assume, that if
|
---|
1168 | // we are not in the Main-Thread ProcessEvents() is
|
---|
1169 | // called by the TApplication Event Loop...
|
---|
1170 | if (!TThread::Self()/*gApplication->InheritsFrom(TRint::Class())*/)
|
---|
1171 | gClient->ProcessEventsFor(fTab);
|
---|
1172 |
|
---|
1173 | *fLog << inf3 << "Adding Tab '" << name << "' (" << f->GetWidth() << "x";
|
---|
1174 | *fLog << f->GetHeight() << ", TCanvas=" << &c << ")" << endl;
|
---|
1175 |
|
---|
1176 | // return pointer to new canvas
|
---|
1177 | return c;
|
---|
1178 | }
|
---|
1179 |
|
---|
1180 | // --------------------------------------------------------------------------
|
---|
1181 | //
|
---|
1182 | // Update a canvas in a tab, takes the corresponding TGCompositeFrame
|
---|
1183 | // as an argument. This is necessary, because not all functions
|
---|
1184 | // changing the contents of a canvas or pad can call SetModified()
|
---|
1185 | // for the corresponding tab. If this is not called correctly the
|
---|
1186 | // tab won't be updated calling TCanvas::Update(). So we simply
|
---|
1187 | // redraw it by our own (instead we could recursively call
|
---|
1188 | // TPad::Modified() for everything contained by the TCanvas and
|
---|
1189 | // call TCanvas::Update() afterwards)
|
---|
1190 | //
|
---|
1191 | void MStatusDisplay::UpdateTab(TGCompositeFrame *f)
|
---|
1192 | {
|
---|
1193 | if (!f)
|
---|
1194 | return;
|
---|
1195 |
|
---|
1196 | TCanvas *c=GetCanvas(*f);
|
---|
1197 | if (!c)
|
---|
1198 | return;
|
---|
1199 |
|
---|
1200 | //
|
---|
1201 | // If we are in a multithreaded environment (gThreadXAR) we
|
---|
1202 | // have to make sure, that thus function is called from
|
---|
1203 | // the main thread.
|
---|
1204 | //
|
---|
1205 | if (gThreadXAR)
|
---|
1206 | {
|
---|
1207 | // Tell the X-Requester how to call this method
|
---|
1208 | TString str = MString::Format("%d", (ULong_t)f);
|
---|
1209 |
|
---|
1210 | TMethodCall call(IsA(), "UpdateTab", "NULL");
|
---|
1211 | void *arr[4] = { NULL, &call, this, (void*)(const char*)str };
|
---|
1212 |
|
---|
1213 | // If this is not the main thread return
|
---|
1214 | if (((*gThreadXAR)("METH", 4, arr, NULL)))
|
---|
1215 | return;
|
---|
1216 | }
|
---|
1217 |
|
---|
1218 | //
|
---|
1219 | // Secure calls to update the tabs against itself, at least
|
---|
1220 | // c->Paint() or c->Flush() may crash X (bad drawable).
|
---|
1221 | // This makes sure, that a X call is not interuppted by
|
---|
1222 | // another X-call which was started from an gui interrrupt
|
---|
1223 | // in the same thread
|
---|
1224 | //
|
---|
1225 | if (fMutex->TryLock())
|
---|
1226 | return;
|
---|
1227 |
|
---|
1228 | #if ROOT_VERSION_CODE < ROOT_VERSION(3,10,02)
|
---|
1229 | TPad *padsav = (TPad*)gPad;
|
---|
1230 | if (!gPad)
|
---|
1231 | c->cd();
|
---|
1232 | #endif
|
---|
1233 |
|
---|
1234 | if (!c->IsBatch())
|
---|
1235 | c->FeedbackMode(kFALSE); // Goto double buffer mode
|
---|
1236 |
|
---|
1237 | //
|
---|
1238 | // Doing this ourself gives us the possibility to repaint
|
---|
1239 | // the canvas in any case (Paint() instead of PaintModified())
|
---|
1240 | //
|
---|
1241 | c->Paint(); // Repaint all pads
|
---|
1242 | c->Flush(); // Copy all pad pixmaps to the screen
|
---|
1243 |
|
---|
1244 | #if ROOT_VERSION_CODE < ROOT_VERSION(3,10,02)
|
---|
1245 | if (padsav)
|
---|
1246 | padsav->cd();
|
---|
1247 | else
|
---|
1248 | gPad=NULL;
|
---|
1249 | #endif
|
---|
1250 |
|
---|
1251 | //c->SetCursor(kCross);
|
---|
1252 |
|
---|
1253 | // Old version
|
---|
1254 | //c->Modified();
|
---|
1255 | //c->Update();
|
---|
1256 | //c->Paint();
|
---|
1257 |
|
---|
1258 | fMutex->UnLock();
|
---|
1259 | }
|
---|
1260 |
|
---|
1261 | TString MStatusDisplay::PrintDialog(TString &p, TString &c, TString &t, const char *ext)
|
---|
1262 | {
|
---|
1263 | // If not in batch mode open a user dialog
|
---|
1264 | if (!gROOT->IsBatch())
|
---|
1265 | {
|
---|
1266 | char *cprinter = StrDup(p);
|
---|
1267 | char *ccmd = StrDup(c);
|
---|
1268 |
|
---|
1269 | Int_t rc=0;
|
---|
1270 | new TGPrintDialog(fClient->GetRoot(), this, 400, 150, &cprinter, &ccmd, &rc);
|
---|
1271 | if (rc)
|
---|
1272 | {
|
---|
1273 | p = cprinter; // default has been changed
|
---|
1274 | c = ccmd;
|
---|
1275 | }
|
---|
1276 |
|
---|
1277 | delete [] cprinter;
|
---|
1278 | delete [] ccmd;
|
---|
1279 |
|
---|
1280 | if (!rc)
|
---|
1281 | return "";
|
---|
1282 | }
|
---|
1283 |
|
---|
1284 | if (c.Contains("%f") && ext)
|
---|
1285 | {
|
---|
1286 | // Get temporary file name
|
---|
1287 | TString name = "mars";
|
---|
1288 |
|
---|
1289 | FILE *f = gSystem->TempFileName(name, t);
|
---|
1290 | if (!f)
|
---|
1291 | {
|
---|
1292 | *fLog << warn << "MStatusDisplay::PrintDialog: Couldn't create temporary file in " << t << endl;
|
---|
1293 | SetStatusLine2("failed!");
|
---|
1294 | return "";
|
---|
1295 | }
|
---|
1296 | fclose(f);
|
---|
1297 |
|
---|
1298 | // remove temp file
|
---|
1299 | gSystem->Unlink(name);
|
---|
1300 | name += ".";
|
---|
1301 | name += ext;
|
---|
1302 |
|
---|
1303 | t = name;
|
---|
1304 | }
|
---|
1305 |
|
---|
1306 | // compile command
|
---|
1307 | TString cmd(c);
|
---|
1308 |
|
---|
1309 | // if sprinter.IsNull we assume that everything around %p can
|
---|
1310 | // be omitted and the program uses some kind of default
|
---|
1311 | if (p.IsNull())
|
---|
1312 | {
|
---|
1313 | TString sub;
|
---|
1314 | while (1)
|
---|
1315 | {
|
---|
1316 | sub = TString(cmd(TRegexp(" .*%p.* "))).Strip(TString::kBoth);
|
---|
1317 | if (sub.IsNull())
|
---|
1318 | break;
|
---|
1319 |
|
---|
1320 | cmd.ReplaceAll(sub, "");
|
---|
1321 | }
|
---|
1322 | }
|
---|
1323 |
|
---|
1324 | cmd.ReplaceAll("%p", p);
|
---|
1325 | cmd.ReplaceAll("%f", t);
|
---|
1326 |
|
---|
1327 | return cmd;
|
---|
1328 | }
|
---|
1329 |
|
---|
1330 | // --------------------------------------------------------------------------
|
---|
1331 | //
|
---|
1332 | // Saves the given canvas (pad) or all pads (num<0) as a temporary
|
---|
1333 | // postscript file and prints it.
|
---|
1334 | //
|
---|
1335 | // The default command line c is: lpr -P%p %f
|
---|
1336 | // %p: printer name
|
---|
1337 | // %f: temporary file name
|
---|
1338 | //
|
---|
1339 | // The default printer name p is: <empty>
|
---|
1340 | //
|
---|
1341 | // Both can be changed in .rootrc by:
|
---|
1342 | // PrintPS.Printer
|
---|
1343 | // PrintPS.Command
|
---|
1344 | //
|
---|
1345 | // Ant the location of the temporary file t can by changed by
|
---|
1346 | // Print.Directory
|
---|
1347 | // the default is the system default directory (normally /tmp)
|
---|
1348 | //
|
---|
1349 | Int_t MStatusDisplay::PrintPS(Int_t num, const char *p, const char *c, const char *t)
|
---|
1350 | {
|
---|
1351 | static TString sprinter = gEnv->GetValue("PrintPS.Printer", p&&*p?p:"");
|
---|
1352 | static TString scmd = gEnv->GetValue("PrintPS.Command", c&&*c?c:"lpr -P%p %f");
|
---|
1353 |
|
---|
1354 | TString tmp = gEnv->GetValue("Print.Directory", t&&*t?t:gSystem->TempDirectory());
|
---|
1355 |
|
---|
1356 | TString cmd = PrintDialog(sprinter, scmd, tmp, "ps");
|
---|
1357 | if (cmd.IsNull())
|
---|
1358 | return 0;
|
---|
1359 |
|
---|
1360 | // set status lines
|
---|
1361 | SetStatusLine1("Printing...");
|
---|
1362 | SetStatusLine2("");
|
---|
1363 |
|
---|
1364 | // print to temporary file
|
---|
1365 | const Int_t pages = SaveAsPS(num, tmp);
|
---|
1366 |
|
---|
1367 | // check
|
---|
1368 | if (!pages)
|
---|
1369 | {
|
---|
1370 | *fLog << warn << "MStatusDisplay::Print: Sorry, couldn't save file as temporary postscript!" << endl;
|
---|
1371 | SetStatusLine2("Failed!");
|
---|
1372 | return 0;
|
---|
1373 | }
|
---|
1374 |
|
---|
1375 | // execute command
|
---|
1376 | *fLog << dbg << "Executing: " << cmd << endl;
|
---|
1377 | gSystem->Exec(cmd);
|
---|
1378 |
|
---|
1379 | // remove temporary file
|
---|
1380 | gSystem->Unlink(tmp);
|
---|
1381 |
|
---|
1382 | SetStatusLine2(MString::Format("Done (%dpage(s))", pages));
|
---|
1383 |
|
---|
1384 | return pages;
|
---|
1385 | }
|
---|
1386 |
|
---|
1387 | // --------------------------------------------------------------------------
|
---|
1388 | //
|
---|
1389 | // Remove tab no i if this tab contains a TRootEmbeddedCanvas
|
---|
1390 | //
|
---|
1391 | void MStatusDisplay::RemoveTab(int i)
|
---|
1392 | {
|
---|
1393 | TGCompositeFrame *f = fTab->GetTabContainer(i);
|
---|
1394 | if (!f)
|
---|
1395 | return;
|
---|
1396 |
|
---|
1397 | TRootEmbeddedCanvas *ec = GetEmbeddedCanvas(*f);
|
---|
1398 | if (!ec)
|
---|
1399 | return;
|
---|
1400 |
|
---|
1401 | TCanvas *c = ec->GetCanvas();
|
---|
1402 | if (!c)
|
---|
1403 | return;
|
---|
1404 |
|
---|
1405 | // Repair the "Workaround" being in the RecursiveRemove list
|
---|
1406 | // but not in a list checked by gROOT->FindObject
|
---|
1407 | //gROOT->GetListOfCleanups()->Remove(c);
|
---|
1408 | //gROOT->GetListOfCanvases()->Add(c);
|
---|
1409 |
|
---|
1410 | // FIXME: Due to our workaround this is necessary for a successfull deletion
|
---|
1411 | //c->cd();
|
---|
1412 |
|
---|
1413 | const TString name(c->GetName());
|
---|
1414 |
|
---|
1415 | f->RemoveFrame(ec);
|
---|
1416 | delete fList->Remove(ec);
|
---|
1417 |
|
---|
1418 | fTab->RemoveTab(i);
|
---|
1419 | fTab->SetTab(0);
|
---|
1420 |
|
---|
1421 | TGComboBox *box = (TGComboBox*)fList->FindWidget(kTabs);
|
---|
1422 | box->RemoveEntry(i);
|
---|
1423 | for (int j=i; j<box->GetListBox()->GetNumberOfEntries(); j++)
|
---|
1424 | {
|
---|
1425 | TGTextLBEntry *entry = (TGTextLBEntry *)box->GetListBox()->Select(j+1, kFALSE);
|
---|
1426 | box->AddEntry(entry->GetText()->GetString(), j);
|
---|
1427 | box->RemoveEntry(j+1);
|
---|
1428 | }
|
---|
1429 | box->GetListBox()->Select(0);
|
---|
1430 |
|
---|
1431 | // Looks strange...
|
---|
1432 | // const Int_t n = fTab->GetNumberOfTabs();
|
---|
1433 | // fTab->SetTab(i<=n-1 ? i : i-1);
|
---|
1434 |
|
---|
1435 | // layout and map new tab
|
---|
1436 | Layout(); // seems to layout the TGCompositeFrame
|
---|
1437 | MapSubwindows(); // maps the TGCompositeFrame
|
---|
1438 | Layout(); // layout the embedded canvas in the frame
|
---|
1439 |
|
---|
1440 | // display new tab in the main frame
|
---|
1441 | // FIXME: This is a workaround, because TApplication::Run is not
|
---|
1442 | // thread safe against ProcessEvents. We assume, that if
|
---|
1443 | // we are not in the Main-Thread ProcessEvents() is
|
---|
1444 | // called by the TApplication Event Loop...
|
---|
1445 | if (!TThread::Self()/*gApplication->InheritsFrom(TRint::Class())*/)
|
---|
1446 | gClient->ProcessEventsFor(fTab);
|
---|
1447 |
|
---|
1448 | *fLog << inf << "Removed Tab #" << i << " '" << name << "'" << endl;
|
---|
1449 | }
|
---|
1450 |
|
---|
1451 | // --------------------------------------------------------------------------
|
---|
1452 | //
|
---|
1453 | // Use this to check whether the MStatusDisplay still contains the
|
---|
1454 | // TCanvas c. It could be removed meanwhile by menu usage.
|
---|
1455 | //
|
---|
1456 | Bool_t MStatusDisplay::HasCanvas(const TCanvas *c) const
|
---|
1457 | {
|
---|
1458 | if (!c)
|
---|
1459 | return kFALSE;
|
---|
1460 |
|
---|
1461 | // If you encounter unexpected crashes here, check if
|
---|
1462 | // a canvas is existing twice in the list or has been
|
---|
1463 | // deleted by accident. (Check AddTab)
|
---|
1464 |
|
---|
1465 | if (gROOT->IsBatch())
|
---|
1466 | return (Bool_t)fBatch->FindObject(c);
|
---|
1467 |
|
---|
1468 | for (int i=1; i<fTab->GetNumberOfTabs(); i++)
|
---|
1469 | if (c==GetCanvas(i))
|
---|
1470 | return kTRUE;
|
---|
1471 | return kFALSE;
|
---|
1472 | }
|
---|
1473 |
|
---|
1474 | /*
|
---|
1475 | if (...)
|
---|
1476 | fMenu->AddPopup("&CaOs", fCaOs, NULL);
|
---|
1477 | else
|
---|
1478 | fMenu->RemovePopup("CaOs");
|
---|
1479 | fMenu->Resize(fMenu->GetDefaultSize());
|
---|
1480 | MapSubwindows();
|
---|
1481 | MapWindow();
|
---|
1482 | */
|
---|
1483 |
|
---|
1484 | void MStatusDisplay::Reset()
|
---|
1485 | {
|
---|
1486 | if (gROOT->IsBatch())
|
---|
1487 | {
|
---|
1488 | fBatch->Delete();
|
---|
1489 | return;
|
---|
1490 | }
|
---|
1491 |
|
---|
1492 | for (int i=fTab->GetNumberOfTabs()-1; i>0; i--)
|
---|
1493 | RemoveTab(i);
|
---|
1494 | }
|
---|
1495 |
|
---|
1496 | Bool_t MStatusDisplay::SaveLogAsPS(const char *n) const
|
---|
1497 | {
|
---|
1498 | TString name(n);
|
---|
1499 | AddExtension(name, "ps");
|
---|
1500 |
|
---|
1501 | // Code taken from TGTextEdit::Print
|
---|
1502 | const TString pipe = MString::Format("a2ps -o%s", name.Data());
|
---|
1503 | FILE *p = gSystem->OpenPipe(pipe, "w");
|
---|
1504 | if (!p)
|
---|
1505 | {
|
---|
1506 | *fLog << err << "ERROR - Couldn't open pipe " << pipe << ": " << strerror(errno) << endl;
|
---|
1507 | return kFALSE;
|
---|
1508 | }
|
---|
1509 |
|
---|
1510 | TGText *text = fLogBox->GetText();
|
---|
1511 |
|
---|
1512 | char *buf1, *buf2;
|
---|
1513 | Long_t len;
|
---|
1514 | ULong_t i = 0;
|
---|
1515 | TGLongPosition pos;
|
---|
1516 |
|
---|
1517 | Bool_t rc = kTRUE;
|
---|
1518 |
|
---|
1519 | pos.fX = pos.fY = 0;
|
---|
1520 | while (pos.fY < text->RowCount())
|
---|
1521 | {
|
---|
1522 | len = text->GetLineLength(pos.fY);
|
---|
1523 | buf1 = text->GetLine(pos, len);
|
---|
1524 | buf2 = new char[len + 2];
|
---|
1525 | strncpy(buf2, buf1, (UInt_t)len);
|
---|
1526 | buf2[len] = '\n';
|
---|
1527 | buf2[len+1] = '\0';
|
---|
1528 | while (buf2[i] != '\0') {
|
---|
1529 | if (buf2[i] == '\t') {
|
---|
1530 | ULong_t j = i+1;
|
---|
1531 | while (buf2[j] == 16 && buf2[j] != '\0')
|
---|
1532 | j++;
|
---|
1533 | strcpy(buf2+i+1, buf2+j);
|
---|
1534 | }
|
---|
1535 | i++;
|
---|
1536 | }
|
---|
1537 |
|
---|
1538 | const UInt_t len = sizeof(char)*(strlen(buf2)+1);
|
---|
1539 |
|
---|
1540 | const size_t ret = fwrite(buf2, len, 1, p);
|
---|
1541 | delete [] buf1;
|
---|
1542 | delete [] buf2;
|
---|
1543 |
|
---|
1544 | if (ret!=1)
|
---|
1545 | {
|
---|
1546 | *fLog << err << "ERROR - fwrite to pipe " << pipe << " failed: " << strerror(errno) << endl;
|
---|
1547 | rc = kFALSE;
|
---|
1548 | break;
|
---|
1549 | }
|
---|
1550 |
|
---|
1551 | pos.fY++;
|
---|
1552 | }
|
---|
1553 | gSystem->ClosePipe(p);
|
---|
1554 | return kTRUE;
|
---|
1555 | }
|
---|
1556 |
|
---|
1557 | // --------------------------------------------------------------------------
|
---|
1558 | //
|
---|
1559 | // Print the log text.
|
---|
1560 | //
|
---|
1561 | // The default command line c is: a2ps -P%p
|
---|
1562 | // %p: printer name
|
---|
1563 | //
|
---|
1564 | // The default printer name p is: <empty>
|
---|
1565 | //
|
---|
1566 | // Both can be changed in .rootrc by:
|
---|
1567 | // PrintText.Printer
|
---|
1568 | // PrintText.Command
|
---|
1569 | //
|
---|
1570 | Bool_t MStatusDisplay::PrintLog(const char *p, const char *c)
|
---|
1571 | {
|
---|
1572 | static TString sprinter = gEnv->GetValue("PrintText.Printer", p&&*p?p:"");
|
---|
1573 | static TString scmd = gEnv->GetValue("PrintText.Command", c&&*c?c:"a2ps -P%p");
|
---|
1574 |
|
---|
1575 | TString tmp;
|
---|
1576 | TString cmd = PrintDialog(sprinter, scmd, tmp);
|
---|
1577 | if (cmd.IsNull())
|
---|
1578 | return kFALSE;
|
---|
1579 |
|
---|
1580 | // set status lines
|
---|
1581 | SetStatusLine1("Printing...");
|
---|
1582 | SetStatusLine2("");
|
---|
1583 |
|
---|
1584 | // print to temporary file
|
---|
1585 | if (!SaveLogAsPS(cmd))
|
---|
1586 | {
|
---|
1587 | *fLog << warn << "MStatusDisplay::PrintLog: Sorry, couldn't create postscript!" << endl;
|
---|
1588 | SetStatusLine2("Failed!");
|
---|
1589 | return kFALSE;
|
---|
1590 | }
|
---|
1591 |
|
---|
1592 | // execute command
|
---|
1593 | *fLog << dbg << "Executing: " << cmd << endl;
|
---|
1594 | gSystem->Exec(cmd);
|
---|
1595 |
|
---|
1596 | SetStatusLine2("Done.");
|
---|
1597 |
|
---|
1598 | return kTRUE;
|
---|
1599 | }
|
---|
1600 |
|
---|
1601 | // --------------------------------------------------------------------------
|
---|
1602 | //
|
---|
1603 | // Process the kC_COMMAND, kCM_MENU messages
|
---|
1604 | //
|
---|
1605 | Bool_t MStatusDisplay::ProcessMessageCommandMenu(Long_t id)
|
---|
1606 | {
|
---|
1607 | switch (id)
|
---|
1608 | {
|
---|
1609 | case kLoopPause:
|
---|
1610 | {
|
---|
1611 | TGPopupMenu *m = GetPopup("Loop");
|
---|
1612 | if (!m)
|
---|
1613 | return kTRUE;
|
---|
1614 |
|
---|
1615 | if (fStatus==kLoopNone)
|
---|
1616 | {
|
---|
1617 | fStatus = (Status_t)kLoopPause;
|
---|
1618 | m->CheckEntry(kLoopPause);
|
---|
1619 | m->EnableEntry(kLoopStep);
|
---|
1620 | return kTRUE;
|
---|
1621 | }
|
---|
1622 | if (fStatus==kLoopPause)
|
---|
1623 | {
|
---|
1624 | fStatus = (Status_t)kLoopNone;
|
---|
1625 | m->UnCheckEntry(kLoopPause);
|
---|
1626 | m->DisableEntry(kLoopStep);
|
---|
1627 | return kTRUE;
|
---|
1628 | }
|
---|
1629 | }
|
---|
1630 | return kTRUE;
|
---|
1631 |
|
---|
1632 | case kLoopStep:
|
---|
1633 | fStatus = (Status_t)kLoopStep;
|
---|
1634 | return kTRUE;
|
---|
1635 |
|
---|
1636 | case kLoopStop:
|
---|
1637 | case kFileClose:
|
---|
1638 | case kFileExit:
|
---|
1639 | if (id==kFileExit || id==kFileClose)
|
---|
1640 | if (Close())
|
---|
1641 | delete this;
|
---|
1642 | fStatus = (Status_t)id;
|
---|
1643 | return kTRUE;
|
---|
1644 |
|
---|
1645 | case kFileCanvas:
|
---|
1646 | new TCanvas;
|
---|
1647 | return kTRUE;
|
---|
1648 |
|
---|
1649 | case kFileBrowser:
|
---|
1650 | new TBrowser;
|
---|
1651 | return kTRUE;
|
---|
1652 |
|
---|
1653 | case kFileTab:
|
---|
1654 | AddTab(MString::Format("%d", fTab->GetNumberOfTabs()));
|
---|
1655 | return kTRUE;
|
---|
1656 |
|
---|
1657 | case kFileReset:
|
---|
1658 | Reset();
|
---|
1659 | return kTRUE;
|
---|
1660 |
|
---|
1661 | case kFileOpen:
|
---|
1662 | Open();
|
---|
1663 | return kTRUE;
|
---|
1664 |
|
---|
1665 | case kFileSaveAs:
|
---|
1666 | SaveAs();
|
---|
1667 | return kTRUE;
|
---|
1668 |
|
---|
1669 | case kFileSaveAsPS:
|
---|
1670 | SaveAsPS();
|
---|
1671 | return kTRUE;
|
---|
1672 |
|
---|
1673 | case kFileSaveAsPDF:
|
---|
1674 | SaveAsPDF();
|
---|
1675 | return kTRUE;
|
---|
1676 |
|
---|
1677 | case kFileSaveAsSVG:
|
---|
1678 | SaveAsSVG();
|
---|
1679 | return kTRUE;
|
---|
1680 |
|
---|
1681 | case kFileSaveAsPNG:
|
---|
1682 | SaveAsPNG();
|
---|
1683 | return kTRUE;
|
---|
1684 |
|
---|
1685 | case kFileSaveAsGIF:
|
---|
1686 | SaveAsGIF();
|
---|
1687 | return kTRUE;
|
---|
1688 |
|
---|
1689 | case kFileSaveAsXPM:
|
---|
1690 | SaveAsXPM();
|
---|
1691 | return kTRUE;
|
---|
1692 |
|
---|
1693 | case kFileSaveAsJPG:
|
---|
1694 | SaveAsJPG();
|
---|
1695 | return kTRUE;
|
---|
1696 |
|
---|
1697 | case kFileSaveAsTIFF:
|
---|
1698 | SaveAsTIFF();
|
---|
1699 | return kTRUE;
|
---|
1700 |
|
---|
1701 | case kFileSaveAsBMP:
|
---|
1702 | SaveAsBMP();
|
---|
1703 | return kTRUE;
|
---|
1704 |
|
---|
1705 | case kFileSaveAsXML:
|
---|
1706 | SaveAsXML();
|
---|
1707 | return kTRUE;
|
---|
1708 |
|
---|
1709 | case kFileSaveAsCSV:
|
---|
1710 | SaveAsCSV();
|
---|
1711 | return kTRUE;
|
---|
1712 |
|
---|
1713 | case kFileSaveAsC:
|
---|
1714 | SaveAsC();
|
---|
1715 | return kTRUE;
|
---|
1716 |
|
---|
1717 | case kFileSaveAsRoot:
|
---|
1718 | SaveAsRoot();
|
---|
1719 | return kTRUE;
|
---|
1720 |
|
---|
1721 | case kFilePrint:
|
---|
1722 | PrintPS();
|
---|
1723 | return kTRUE;
|
---|
1724 |
|
---|
1725 | case kTabSaveAs:
|
---|
1726 | SaveAs(fTab->GetCurrent());
|
---|
1727 | return kTRUE;
|
---|
1728 |
|
---|
1729 | case kTabSaveAsPS:
|
---|
1730 | SaveAsPS(fTab->GetCurrent());
|
---|
1731 | return kTRUE;
|
---|
1732 |
|
---|
1733 | case kTabSaveAsPDF:
|
---|
1734 | SaveAsPDF(fTab->GetCurrent());
|
---|
1735 | return kTRUE;
|
---|
1736 |
|
---|
1737 | case kTabSaveAsSVG:
|
---|
1738 | SaveAsSVG(fTab->GetCurrent());
|
---|
1739 | return kTRUE;
|
---|
1740 |
|
---|
1741 | case kTabSaveAsPNG:
|
---|
1742 | SaveAsPNG(fTab->GetCurrent());
|
---|
1743 | return kTRUE;
|
---|
1744 |
|
---|
1745 | case kTabSaveAsGIF:
|
---|
1746 | SaveAsGIF(fTab->GetCurrent());
|
---|
1747 | return kTRUE;
|
---|
1748 |
|
---|
1749 | case kTabSaveAsXPM:
|
---|
1750 | SaveAsXPM(fTab->GetCurrent());
|
---|
1751 | return kTRUE;
|
---|
1752 |
|
---|
1753 | case kTabSaveAsJPG:
|
---|
1754 | SaveAsJPG(fTab->GetCurrent());
|
---|
1755 | return kTRUE;
|
---|
1756 |
|
---|
1757 | case kTabSaveAsTIFF:
|
---|
1758 | SaveAsTIFF(fTab->GetCurrent());
|
---|
1759 | return kTRUE;
|
---|
1760 |
|
---|
1761 | case kTabSaveAsBMP:
|
---|
1762 | SaveAsBMP(fTab->GetCurrent());
|
---|
1763 | return kTRUE;
|
---|
1764 |
|
---|
1765 | case kTabSaveAsXML:
|
---|
1766 | SaveAsXML(fTab->GetCurrent());
|
---|
1767 | return kTRUE;
|
---|
1768 |
|
---|
1769 | case kTabSaveAsCSV:
|
---|
1770 | SaveAsCSV(fTab->GetCurrent());
|
---|
1771 | return kTRUE;
|
---|
1772 |
|
---|
1773 | case kTabSaveAsC:
|
---|
1774 | SaveAsC(fTab->GetCurrent());
|
---|
1775 | return kTRUE;
|
---|
1776 |
|
---|
1777 | case kTabSaveAsRoot:
|
---|
1778 | SaveAsRoot(fTab->GetCurrent());
|
---|
1779 | return kTRUE;
|
---|
1780 |
|
---|
1781 | case kTabPrint:
|
---|
1782 | PrintPS(fTab->GetCurrent());
|
---|
1783 | return kTRUE;
|
---|
1784 |
|
---|
1785 | case kTabNext:
|
---|
1786 | fTab->SetTab(fTab->GetCurrent()+1);
|
---|
1787 | return kTRUE;
|
---|
1788 |
|
---|
1789 | case kTabPrevious:
|
---|
1790 | fTab->SetTab(fTab->GetCurrent()-1);
|
---|
1791 | return kTRUE;
|
---|
1792 |
|
---|
1793 | case kTabRemove:
|
---|
1794 | RemoveTab(fTab->GetCurrent());
|
---|
1795 | return kTRUE;
|
---|
1796 |
|
---|
1797 | case kSize640:
|
---|
1798 | SetDisplaySize(640, 480);
|
---|
1799 | return kTRUE;
|
---|
1800 | case kSize768:
|
---|
1801 | SetDisplaySize(768, 576);
|
---|
1802 | return kTRUE;
|
---|
1803 | case kSize800:
|
---|
1804 | SetDisplaySize(800, 600);
|
---|
1805 | return kTRUE;
|
---|
1806 | case kSize960:
|
---|
1807 | SetDisplaySize(960, 720);
|
---|
1808 | return kTRUE;
|
---|
1809 | case kSize1024:
|
---|
1810 | SetDisplaySize(1024, 768);
|
---|
1811 | return kTRUE;
|
---|
1812 | case kSize1152:
|
---|
1813 | SetDisplaySize(1152, 864);
|
---|
1814 | return kTRUE;
|
---|
1815 | case kSize1280:
|
---|
1816 | SetDisplaySize(1280, 1024);
|
---|
1817 | return kTRUE;
|
---|
1818 | case kSize1400:
|
---|
1819 | SetDisplaySize(1400, 1050);
|
---|
1820 | return kTRUE;
|
---|
1821 | case kSize1600:
|
---|
1822 | SetDisplaySize(1600, 1200);
|
---|
1823 | return kTRUE;
|
---|
1824 | case kSizeOptimum:
|
---|
1825 | SetOptimumSize();
|
---|
1826 | return kTRUE;
|
---|
1827 |
|
---|
1828 | case kLogClear:
|
---|
1829 | fLogBox->Clear();
|
---|
1830 | return kTRUE;
|
---|
1831 | case kLogCopy:
|
---|
1832 | fLogBox->Copy();
|
---|
1833 | return kTRUE;
|
---|
1834 | case kLogSelect:
|
---|
1835 | fLogBox->SelectAll();
|
---|
1836 | return kTRUE;
|
---|
1837 | case kLogFind:
|
---|
1838 | new MSearch(this);
|
---|
1839 | return kTRUE;
|
---|
1840 | case kLogSave:
|
---|
1841 | SetStatusLine1("Saving log...");
|
---|
1842 | SetStatusLine2("");
|
---|
1843 | *fLog << inf << "Saving log... " << flush;
|
---|
1844 | if (fLogBox->GetText()->Save(MString::Format("%s.log", gROOT->GetName())))
|
---|
1845 | {
|
---|
1846 | *fLog << "done." << endl;
|
---|
1847 | SetStatusLine2("done.");
|
---|
1848 | }
|
---|
1849 | else
|
---|
1850 | {
|
---|
1851 | *fLog << "failed!" << endl;
|
---|
1852 | SetStatusLine2("Failed!");
|
---|
1853 | }
|
---|
1854 | return kTRUE;
|
---|
1855 |
|
---|
1856 | case kLogAppend:
|
---|
1857 | SetStatusLine1("Appending log...");
|
---|
1858 | SetStatusLine2("");
|
---|
1859 | *fLog << inf << "Appending log... " << flush;
|
---|
1860 | if (fLogBox->GetText()->Append(MString::Format("%s.log", gROOT->GetName())))
|
---|
1861 | {
|
---|
1862 | *fLog << "done." << endl;
|
---|
1863 | SetStatusLine2("done.");
|
---|
1864 | }
|
---|
1865 | else
|
---|
1866 | {
|
---|
1867 | *fLog << "failed!" << endl;
|
---|
1868 | SetStatusLine2("Failed!");
|
---|
1869 | }
|
---|
1870 | return kTRUE;
|
---|
1871 |
|
---|
1872 | case kLogPrint:
|
---|
1873 | PrintLog();
|
---|
1874 | return kTRUE;
|
---|
1875 | #ifdef DEBUG
|
---|
1876 | default:
|
---|
1877 | cout << "Command-Menu #" << id << endl;
|
---|
1878 | #endif
|
---|
1879 | }
|
---|
1880 | return kTRUE;
|
---|
1881 |
|
---|
1882 | }
|
---|
1883 |
|
---|
1884 | // --------------------------------------------------------------------------
|
---|
1885 | //
|
---|
1886 | // Process the kC_COMMAND messages
|
---|
1887 | //
|
---|
1888 | Bool_t MStatusDisplay::ProcessMessageCommand(Long_t submsg, Long_t mp1, Long_t mp2)
|
---|
1889 | {
|
---|
1890 | switch (submsg)
|
---|
1891 | {
|
---|
1892 | case kCM_MENU: // 1
|
---|
1893 | return ProcessMessageCommandMenu(mp1); // mp2=userdata
|
---|
1894 | case kCM_TAB: // 8
|
---|
1895 | /*
|
---|
1896 | for (int i=0; i<fTab->GetNumberOfTabs(); i++)
|
---|
1897 | fTab->GetTabContainer(i)->UnmapWindow();
|
---|
1898 | */
|
---|
1899 | UpdateTab(fTab->GetTabContainer(mp1));
|
---|
1900 | //fTab->GetTabContainer(mp1)->MapWindow();
|
---|
1901 |
|
---|
1902 | /*
|
---|
1903 | if (mp1>0)
|
---|
1904 | fMenu->AddPopup("&CaOs", fCaOs, NULL);
|
---|
1905 | else
|
---|
1906 | fMenu->RemovePopup("CaOs");
|
---|
1907 | fMenu->Resize(fMenu->GetDefaultSize());
|
---|
1908 | MapSubwindows();
|
---|
1909 | MapWindow();
|
---|
1910 | */
|
---|
1911 | return kTRUE;
|
---|
1912 | case kCM_COMBOBOX: // 7
|
---|
1913 | if (mp1==kTabs)
|
---|
1914 | fTab->SetTab(mp2);
|
---|
1915 | return kTRUE;
|
---|
1916 | #ifdef DEBUG
|
---|
1917 | case kCM_MENUSELECT: // 2
|
---|
1918 | cout << "Command-Menuselect #" << mp1 << " (UserData=" << (void*)mp2 << ")" << endl;
|
---|
1919 | return kTRUE;
|
---|
1920 |
|
---|
1921 | case kCM_BUTTON: // 3
|
---|
1922 | cout << "Command-Button." << endl;
|
---|
1923 | return kTRUE;
|
---|
1924 |
|
---|
1925 | case kCM_CHECKBUTTON: // 4
|
---|
1926 | cout << "Command-CheckButton." << endl;
|
---|
1927 | return kTRUE;
|
---|
1928 |
|
---|
1929 | case kCM_RADIOBUTTON: // 5
|
---|
1930 | cout << "Command-RadioButton." << endl;
|
---|
1931 | return kTRUE;
|
---|
1932 |
|
---|
1933 | case kCM_LISTBOX: // 6
|
---|
1934 | cout << "Command-Listbox #" << mp1 << " (LineId #" << mp2 << ")" << endl;
|
---|
1935 | return kTRUE;
|
---|
1936 | default:
|
---|
1937 | cout << "Command: " << "Submsg:" << submsg << " Mp1=" << mp1 << " Mp2=" << mp2 << endl;
|
---|
1938 | #endif
|
---|
1939 | }
|
---|
1940 | return kTRUE;
|
---|
1941 | }
|
---|
1942 |
|
---|
1943 | // --------------------------------------------------------------------------
|
---|
1944 | //
|
---|
1945 | // Process the kC_TEXTVIEW messages
|
---|
1946 | //
|
---|
1947 | Bool_t MStatusDisplay::ProcessMessageTextview(Long_t /*submsg*/, Long_t /*mp1*/, Long_t /*mp2*/)
|
---|
1948 | {
|
---|
1949 | // kC_TEXTVIEW, kTXT_ISMARKED, widget id, [true|false] //
|
---|
1950 | // kC_TEXTVIEW, kTXT_DATACHANGE, widget id, 0 //
|
---|
1951 | // kC_TEXTVIEW, kTXT_CLICK2, widget id, position (y << 16) | x) //
|
---|
1952 | // kC_TEXTVIEW, kTXT_CLICK3, widget id, position (y << 16) | x) //
|
---|
1953 | // kC_TEXTVIEW, kTXT_F3, widget id, true //
|
---|
1954 | // kC_TEXTVIEW, kTXT_OPEN, widget id, 0 //
|
---|
1955 | // kC_TEXTVIEW, kTXT_CLOSE, widget id, 0 //
|
---|
1956 | // kC_TEXTVIEW, kTXT_SAVE, widget id, 0 //
|
---|
1957 | #ifdef DEBUG
|
---|
1958 | switch (submsg)
|
---|
1959 | {
|
---|
1960 | case kTXT_ISMARKED:
|
---|
1961 | cout << "Textview-IsMarked #" << mp1 << " " << (mp2?"yes":"no") << endl;
|
---|
1962 | return kTRUE;
|
---|
1963 |
|
---|
1964 | case kTXT_DATACHANGE:
|
---|
1965 | cout << "Textview-DataChange #" << mp1 << endl;
|
---|
1966 | return kTRUE;
|
---|
1967 |
|
---|
1968 | case kTXT_CLICK2:
|
---|
1969 | cout << "Textview-Click2 #" << mp1 << " x=" << (mp2&0xffff) << " y= " << (mp2>>16) << endl;
|
---|
1970 | return kTRUE;
|
---|
1971 |
|
---|
1972 | case kTXT_CLICK3:
|
---|
1973 | cout << "Textview-Click3 #" << mp1 << " x=" << (mp2&0xffff) << " y= " << (mp2>>16) << endl;
|
---|
1974 | return kTRUE;
|
---|
1975 |
|
---|
1976 | case kTXT_F3:
|
---|
1977 | cout << "Textview-F3 #" << mp1 << endl;
|
---|
1978 | return kTRUE;
|
---|
1979 |
|
---|
1980 | case kTXT_OPEN:
|
---|
1981 | cout << "Textview-Open #" << mp1 << endl;
|
---|
1982 | return kTRUE;
|
---|
1983 |
|
---|
1984 | case kTXT_CLOSE:
|
---|
1985 | cout << "Textview-Close #" << mp1 << endl;
|
---|
1986 | return kTRUE;
|
---|
1987 |
|
---|
1988 | case kTXT_SAVE:
|
---|
1989 | cout << "Textview-Save #" << mp1 << endl;
|
---|
1990 | return kTRUE;
|
---|
1991 |
|
---|
1992 | default:
|
---|
1993 | cout << "Textview: " << "Submsg:" << submsg << " Mp1=" << mp1 << " Mp2=" << mp2 << endl;
|
---|
1994 | }
|
---|
1995 | #endif
|
---|
1996 | return kTRUE;
|
---|
1997 | }
|
---|
1998 |
|
---|
1999 | // --------------------------------------------------------------------------
|
---|
2000 | //
|
---|
2001 | // Process the kC_USER messages
|
---|
2002 | //
|
---|
2003 | Bool_t MStatusDisplay::ProcessMessageUser(Long_t submsg, Long_t mp1, Long_t mp2)
|
---|
2004 | {
|
---|
2005 | // kS_START, case sensitive | backward<<1, char *txt
|
---|
2006 | switch (submsg)
|
---|
2007 | {
|
---|
2008 | case kS_START:
|
---|
2009 | fLogBox->Search((char*)mp2, !(mp1&2>>1), mp1&1);
|
---|
2010 | return kTRUE;
|
---|
2011 | #ifdef DEBUG
|
---|
2012 | default:
|
---|
2013 | cout << "User: " << "Submsg:" << submsg << " Mp1=" << mp1 << " Mp2=" << mp2 << endl;
|
---|
2014 | #endif
|
---|
2015 | }
|
---|
2016 | return kTRUE;
|
---|
2017 | }
|
---|
2018 |
|
---|
2019 | // --------------------------------------------------------------------------
|
---|
2020 | //
|
---|
2021 | // Process the messages from the GUI
|
---|
2022 | //
|
---|
2023 | Bool_t MStatusDisplay::ProcessMessage(Long_t msg, Long_t mp1, Long_t mp2)
|
---|
2024 | {
|
---|
2025 | // Can be found in WidgetMessageTypes.h
|
---|
2026 | #ifdef DEBUG
|
---|
2027 | cout << "Msg: " << GET_MSG(msg) << " Submsg:" << GET_SUBMSG(msg);
|
---|
2028 | cout << " Mp1=" << mp1 << " Mp2=" << mp2 << endl;
|
---|
2029 | #endif
|
---|
2030 | switch (GET_MSG(msg))
|
---|
2031 | {
|
---|
2032 | case kC_COMMAND: // 1
|
---|
2033 | return ProcessMessageCommand(GET_SUBMSG(msg), mp1, mp2);
|
---|
2034 |
|
---|
2035 | case kC_TEXTVIEW: // 9
|
---|
2036 | return ProcessMessageTextview(GET_SUBMSG(msg), mp1, mp2);
|
---|
2037 |
|
---|
2038 | case kC_USER: // 1001
|
---|
2039 | return ProcessMessageUser(GET_SUBMSG(msg), mp1, mp2);
|
---|
2040 | }
|
---|
2041 | #ifdef DEBUG
|
---|
2042 | cout << "Msg: " << GET_MSG(msg) << " Submsg:" << GET_SUBMSG(msg);
|
---|
2043 | cout << " Mp1=" << mp1 << " Mp2=" << mp2 << endl;
|
---|
2044 | #endif
|
---|
2045 | return kTRUE;
|
---|
2046 | }
|
---|
2047 |
|
---|
2048 | Bool_t MStatusDisplay::Close()
|
---|
2049 | {
|
---|
2050 | // Got close message for this MainFrame. Calls parent CloseWindow()
|
---|
2051 | // (which destroys the window) and terminate the application.
|
---|
2052 | // The close message is generated by the window manager when its close
|
---|
2053 | // window menu item is selected.
|
---|
2054 |
|
---|
2055 | // CloseWindow must be overwritten because otherwise CloseWindow
|
---|
2056 | // and the destructor are calling DestroyWindow which seems to be
|
---|
2057 | // in conflict with the TRootEmbeddedCanvas.
|
---|
2058 |
|
---|
2059 | // FIXME: Make sure that the Status Display is deleted from every
|
---|
2060 | // where (eg Eventloop) first!
|
---|
2061 |
|
---|
2062 | //gLog << dbg << fName << " is on heap: " << (int)IsOnHeap() << endl;
|
---|
2063 |
|
---|
2064 | if (TestBit(kExitLoopOnExit) || TestBit(kExitLoopOnClose))
|
---|
2065 | {
|
---|
2066 | //gLog << dbg << "CloseWindow() calling ExitLoop." << endl;
|
---|
2067 | gSystem->ExitLoop();
|
---|
2068 | }
|
---|
2069 |
|
---|
2070 | if (fIsLocked<=0 && IsOnHeap())
|
---|
2071 | return kTRUE;
|
---|
2072 |
|
---|
2073 | fStatus = kFileExit;
|
---|
2074 | return kFALSE;
|
---|
2075 | }
|
---|
2076 |
|
---|
2077 | void MStatusDisplay::CloseWindow()
|
---|
2078 | {
|
---|
2079 | if (Close())
|
---|
2080 | delete this;
|
---|
2081 | }
|
---|
2082 |
|
---|
2083 | // --------------------------------------------------------------------------
|
---|
2084 | //
|
---|
2085 | // Calls SetBit(kNoContextMenu) for all TCanvas objects found in the
|
---|
2086 | // Tabs.
|
---|
2087 | //
|
---|
2088 | void MStatusDisplay::SetNoContextMenu(Bool_t flag)
|
---|
2089 | {
|
---|
2090 | if (fIsLocked>1 || gROOT->IsBatch())
|
---|
2091 | return;
|
---|
2092 |
|
---|
2093 | flag ? SetBit(kNoContextMenu) : ResetBit(kNoContextMenu);
|
---|
2094 |
|
---|
2095 | for (int i=1; i<fTab->GetNumberOfTabs(); i++)
|
---|
2096 | {
|
---|
2097 | TCanvas *c = GetCanvas(i);
|
---|
2098 | if (c)
|
---|
2099 | flag ? c->SetBit(kNoContextMenu) : c->ResetBit(kNoContextMenu);
|
---|
2100 | }
|
---|
2101 | }
|
---|
2102 |
|
---|
2103 | // --------------------------------------------------------------------------
|
---|
2104 | //
|
---|
2105 | // Update the memory display in the status bar
|
---|
2106 | //
|
---|
2107 | void MStatusDisplay::UpdateMemory() const
|
---|
2108 | {
|
---|
2109 | const TString path = MString::Format("/proc/%d/status", gSystem->GetPid());
|
---|
2110 | if (gSystem->AccessPathName(path, kFileExists))
|
---|
2111 | return;
|
---|
2112 |
|
---|
2113 | TEnv env(path);
|
---|
2114 | const UInt_t kb = env.GetValue("VmSize", 0);
|
---|
2115 | if (kb==0)
|
---|
2116 | return;
|
---|
2117 |
|
---|
2118 | char type = 'k';
|
---|
2119 | Float_t val = kb;
|
---|
2120 |
|
---|
2121 | if (val>999)
|
---|
2122 | {
|
---|
2123 | type = 'M';
|
---|
2124 | val /= 1000;
|
---|
2125 | }
|
---|
2126 | if (val>999)
|
---|
2127 | {
|
---|
2128 | type = 'G';
|
---|
2129 | val /= 1000;
|
---|
2130 | }
|
---|
2131 | const TString txt = MString::Format("%.1f%c", val, type);
|
---|
2132 | fStatusBar->SetText(txt, 2);
|
---|
2133 | }
|
---|
2134 |
|
---|
2135 | // --------------------------------------------------------------------------
|
---|
2136 | //
|
---|
2137 | // Updates the canvas (if existing) in the currenly displayed Tab.
|
---|
2138 | // The update intervall is controlled by StartUpdate and StopUpdate
|
---|
2139 | //
|
---|
2140 | Bool_t MStatusDisplay::HandleTimer(TTimer *timer)
|
---|
2141 | {
|
---|
2142 | if (gROOT->IsBatch())
|
---|
2143 | return kTRUE;
|
---|
2144 |
|
---|
2145 | UpdateMemory();
|
---|
2146 |
|
---|
2147 | const Int_t c = fTab->GetCurrent();
|
---|
2148 |
|
---|
2149 | // Skip Legend Tab
|
---|
2150 | if (c==0)
|
---|
2151 | return kTRUE;
|
---|
2152 |
|
---|
2153 | // Update a canvas tab (if visible)
|
---|
2154 | if (timer==&fTimer && c!=fLogIdx)
|
---|
2155 | {
|
---|
2156 | UpdateTab(fTab->GetCurrentContainer());
|
---|
2157 | return kTRUE;
|
---|
2158 | }
|
---|
2159 |
|
---|
2160 | // update the logbook tab (if visible)
|
---|
2161 | if (timer==&fLogTimer && c==fLogIdx)
|
---|
2162 | {
|
---|
2163 | fLog->UpdateGui();
|
---|
2164 |
|
---|
2165 | /*
|
---|
2166 | if (!fLogBox->TestBit(kHasChanged))
|
---|
2167 | return kTRUE;
|
---|
2168 |
|
---|
2169 | fLogBox->ResetBit(kHasChanged);
|
---|
2170 | */
|
---|
2171 | return kTRUE;
|
---|
2172 | }
|
---|
2173 |
|
---|
2174 | return kTRUE;
|
---|
2175 | }
|
---|
2176 |
|
---|
2177 | // --------------------------------------------------------------------------
|
---|
2178 | //
|
---|
2179 | // Find an object in a canvas (uses MStatusArray as helper)
|
---|
2180 | //
|
---|
2181 | void MStatusDisplay::PrintContent(Option_t *o) const
|
---|
2182 | {
|
---|
2183 | MStatusArray(*this).Print(o);
|
---|
2184 | }
|
---|
2185 |
|
---|
2186 | // --------------------------------------------------------------------------
|
---|
2187 | //
|
---|
2188 | // Find an object in a canvas (uses MStatusArray as helper)
|
---|
2189 | //
|
---|
2190 | TObject *MStatusDisplay::FindObjectInCanvas(const char *obj, const char *base, const char *canv) const
|
---|
2191 | {
|
---|
2192 | return MStatusArray(*this).FindObjectInCanvas(obj, base, canv);
|
---|
2193 | }
|
---|
2194 |
|
---|
2195 | // --------------------------------------------------------------------------
|
---|
2196 | //
|
---|
2197 | // Draws a clone of a canvas into a new canvas. Taken from TCanvas.
|
---|
2198 | //
|
---|
2199 | void MStatusDisplay::DrawClonePad(TCanvas &newc, TCanvas &oldc) const
|
---|
2200 | {
|
---|
2201 | //copy pad attributes
|
---|
2202 | newc.Range(oldc.GetX1(),oldc.GetY1(),oldc.GetX2(),oldc.GetY2());
|
---|
2203 | newc.SetTickx(oldc.GetTickx());
|
---|
2204 | newc.SetTicky(oldc.GetTicky());
|
---|
2205 | newc.SetGridx(oldc.GetGridx());
|
---|
2206 | newc.SetGridy(oldc.GetGridy());
|
---|
2207 | newc.SetLogx(oldc.GetLogx());
|
---|
2208 | newc.SetLogy(oldc.GetLogy());
|
---|
2209 | newc.SetLogz(oldc.GetLogz());
|
---|
2210 | newc.SetBorderSize(oldc.GetBorderSize());
|
---|
2211 | newc.SetBorderMode(oldc.GetBorderMode());
|
---|
2212 | ((TAttLine&)oldc).Copy((TAttLine&)newc);
|
---|
2213 | ((TAttFill&)oldc).Copy((TAttFill&)newc);
|
---|
2214 | ((TAttPad&)oldc).Copy((TAttPad&)newc);
|
---|
2215 |
|
---|
2216 | // This must be there: Otherwise GetDrawOption() won't work
|
---|
2217 | TVirtualPad *padsav = gPad;
|
---|
2218 | oldc.cd();
|
---|
2219 |
|
---|
2220 | const Bool_t store = TH1::AddDirectoryStatus();
|
---|
2221 | TH1::AddDirectory(kFALSE);
|
---|
2222 |
|
---|
2223 | //copy primitives
|
---|
2224 | TObject *obj;
|
---|
2225 | TIter next(oldc.GetListOfPrimitives());
|
---|
2226 | while ((obj=next()))
|
---|
2227 | {
|
---|
2228 | // Old line - I think it is not necessary anymore because of the cd()
|
---|
2229 | //gROOT->SetSelectedPad(&newc);
|
---|
2230 |
|
---|
2231 | // Now make a clone of the object
|
---|
2232 | TObject *clone = obj->Clone();
|
---|
2233 |
|
---|
2234 | // Clone also important bits (FIXME: Is this correct)
|
---|
2235 | clone->SetBit(obj->TestBits(kCannotPick|kNoContextMenu));
|
---|
2236 |
|
---|
2237 | // Now make sure that the clones are deleted at a later time
|
---|
2238 | clone->SetBit(kCanDelete|kMustCleanup);
|
---|
2239 |
|
---|
2240 | // FIXME: This is a workaround for the problem with the MAstroCatalog in
|
---|
2241 | // MHFalseSource. It doesn't harm. We'll still try to find the reason
|
---|
2242 | if (clone->IsA()==TPad::Class())
|
---|
2243 | gROOT->GetListOfCleanups()->Add(clone);
|
---|
2244 |
|
---|
2245 | // Add the clone and its draw-option to the current pad
|
---|
2246 | TVirtualPad *save2 = gPad;
|
---|
2247 | gPad = &oldc; // Don't do this before Clone()!
|
---|
2248 | newc.GetListOfPrimitives()->Add(clone, obj->GetDrawOption());
|
---|
2249 | gPad = save2;
|
---|
2250 | }
|
---|
2251 | newc.Modified();
|
---|
2252 | newc.Update();
|
---|
2253 |
|
---|
2254 | TH1::AddDirectory(store);
|
---|
2255 |
|
---|
2256 | padsav->cd();
|
---|
2257 | }
|
---|
2258 |
|
---|
2259 | // --------------------------------------------------------------------------
|
---|
2260 | //
|
---|
2261 | // Display the contexts of a TObjArray in the display (all canvases)
|
---|
2262 | //
|
---|
2263 | Bool_t MStatusDisplay::Display(const TObjArray &list, const char *tab)
|
---|
2264 | {
|
---|
2265 | TIter Next(&list);
|
---|
2266 |
|
---|
2267 | TObject *o=Next();
|
---|
2268 | if (!o)
|
---|
2269 | {
|
---|
2270 | *fLog << err << "MStatusDisplay::Display: No entry in TObjArray." << endl;
|
---|
2271 | return kFALSE;
|
---|
2272 | }
|
---|
2273 |
|
---|
2274 | fTitle = o->GetTitle();
|
---|
2275 |
|
---|
2276 | TCanvas *c;
|
---|
2277 | while ((c=(TCanvas*)Next()))
|
---|
2278 | //if (!GetCanvas(c->GetName()))
|
---|
2279 | if (c->InheritsFrom(TCanvas::Class()))
|
---|
2280 | if (!tab || c->GetName()==(TString)tab)
|
---|
2281 | DrawClonePad(AddTab(c->GetName(), c->GetTitle()), *c);
|
---|
2282 |
|
---|
2283 | return kTRUE;
|
---|
2284 | }
|
---|
2285 |
|
---|
2286 | // --------------------------------------------------------------------------
|
---|
2287 | //
|
---|
2288 | // Reads the contents of a saved MStatusDisplay from a file.
|
---|
2289 | //
|
---|
2290 | Int_t MStatusDisplay::Read(const char *name, const char *tab)
|
---|
2291 | {
|
---|
2292 | if (!gFile)
|
---|
2293 | {
|
---|
2294 | *fLog << warn << "MStatusDisplay::Read: No file found. Please create a TFile first." << endl;
|
---|
2295 | return 0;
|
---|
2296 | }
|
---|
2297 |
|
---|
2298 | if (!gFile->IsOpen())
|
---|
2299 | {
|
---|
2300 | *fLog << warn << "MStatusDisplay::Read: File not open. Please open the TFile first." << endl;
|
---|
2301 | return 0;
|
---|
2302 | }
|
---|
2303 |
|
---|
2304 | MStatusArray list;
|
---|
2305 |
|
---|
2306 | const Int_t n = list.Read(name);
|
---|
2307 |
|
---|
2308 | //
|
---|
2309 | // If no status display was found with this name try to find canvases
|
---|
2310 | // in the file and s´display them instead.
|
---|
2311 | //
|
---|
2312 | if (n==0)
|
---|
2313 | {
|
---|
2314 | const Bool_t store = TH1::AddDirectoryStatus();
|
---|
2315 | TH1::AddDirectory(kFALSE);
|
---|
2316 |
|
---|
2317 | TIter Next(gFile->GetListOfKeys());
|
---|
2318 | TObject *key = 0;
|
---|
2319 | while ((key=Next()))
|
---|
2320 | {
|
---|
2321 | TCanvas *c=0;
|
---|
2322 | gFile->GetObject(key->GetName(), c);
|
---|
2323 | if (!c)
|
---|
2324 | break;
|
---|
2325 |
|
---|
2326 | if (list.GetEntries()==0)
|
---|
2327 | list.Add(new TNamed(GetName(), GetTitle()));
|
---|
2328 |
|
---|
2329 | c->SetTitle(gFile->GetName());
|
---|
2330 | list.Add(c);
|
---|
2331 | }
|
---|
2332 |
|
---|
2333 | TH1::AddDirectory(store);
|
---|
2334 |
|
---|
2335 | if (list.GetEntries()==0)
|
---|
2336 | {
|
---|
2337 | *fLog << warn << "MStatusDisplay::Read: No objects read from " << gFile->GetName() << endl;
|
---|
2338 | return 0;
|
---|
2339 | }
|
---|
2340 |
|
---|
2341 | *fLog << inf << "MStatusDisplay: " << list.GetEntries() << " canvases directly read from file." << endl;
|
---|
2342 | }
|
---|
2343 |
|
---|
2344 |
|
---|
2345 | if (!Display(list, tab))
|
---|
2346 | {
|
---|
2347 | *fLog << err << "MStatusDisplay::Display: No entries found." << endl;
|
---|
2348 | return 0;
|
---|
2349 | }
|
---|
2350 |
|
---|
2351 |
|
---|
2352 | if (n==0)
|
---|
2353 | return list.GetEntries();
|
---|
2354 |
|
---|
2355 | *fLog << inf << "MStatusDisplay: Key " << name << " with " << n << " keys read from file." << endl;
|
---|
2356 | return n;
|
---|
2357 | }
|
---|
2358 |
|
---|
2359 | // --------------------------------------------------------------------------
|
---|
2360 | //
|
---|
2361 | // Add all canvases to the MStatusArray
|
---|
2362 | //
|
---|
2363 | void MStatusDisplay::FillArray(MStatusArray &list, Int_t num) const
|
---|
2364 | {
|
---|
2365 | Int_t from, to;
|
---|
2366 | GetCanvasRange(from, to, num);
|
---|
2367 |
|
---|
2368 | TCanvas *c;
|
---|
2369 | for (int i=from; i<to; i++)
|
---|
2370 | if ((c = GetCanvas(i)))
|
---|
2371 | list.Add(c);
|
---|
2372 | }
|
---|
2373 |
|
---|
2374 | // --------------------------------------------------------------------------
|
---|
2375 | //
|
---|
2376 | // Writes the contents of a MStatusDisplay to a file.
|
---|
2377 | //
|
---|
2378 | Int_t MStatusDisplay::Write(Int_t num, const char *name, Int_t /*option*/, Int_t /*bufsize*/) const
|
---|
2379 | {
|
---|
2380 | if (!gFile)
|
---|
2381 | {
|
---|
2382 | *fLog << warn << "MStatusDisplay::Write: No file found. Please create a TFile first." << endl;
|
---|
2383 | return 0;
|
---|
2384 | }
|
---|
2385 |
|
---|
2386 | if (!gFile->IsOpen())
|
---|
2387 | {
|
---|
2388 | *fLog << warn << "MStatusDisplay::Write: File not open. Please open the TFile first." << endl;
|
---|
2389 | return 0;
|
---|
2390 | }
|
---|
2391 |
|
---|
2392 | if (!gFile->IsWritable())
|
---|
2393 | {
|
---|
2394 | *fLog << warn << "MStatusDisplay::Write: File not writable." << endl;
|
---|
2395 | return 0;
|
---|
2396 | }
|
---|
2397 |
|
---|
2398 | if (num==0)
|
---|
2399 | {
|
---|
2400 | *fLog << warn << "MStatusDisplay::Write: Tab doesn't contain an embedded Canvas... skipped." << endl;
|
---|
2401 | return 0;
|
---|
2402 | }
|
---|
2403 |
|
---|
2404 | if (!gROOT->IsBatch() && num>=fTab->GetNumberOfTabs())
|
---|
2405 | {
|
---|
2406 | *fLog << warn << "MStatusDisplay::Write: Tab doesn't exist... skipped." << endl;
|
---|
2407 | return 0;
|
---|
2408 | }
|
---|
2409 | if (gROOT->IsBatch() && num>fBatch->GetSize())
|
---|
2410 | {
|
---|
2411 | *fLog << warn << "MStatusDisplay::Write: Tab doesn't exist... skipped." << endl;
|
---|
2412 | return 0;
|
---|
2413 | }
|
---|
2414 |
|
---|
2415 | MStatusArray list;
|
---|
2416 |
|
---|
2417 | // Be careful: So far Display() assumes that it is the first entry in the list
|
---|
2418 | TNamed named;
|
---|
2419 | named.SetTitle(fTitle);
|
---|
2420 | list.Add(&named);
|
---|
2421 |
|
---|
2422 | FillArray(list, num);
|
---|
2423 |
|
---|
2424 | const Int_t n = list.Write(name, kSingleKey);
|
---|
2425 |
|
---|
2426 | //*fLog << inf << "MStatusDisplay: " << n << " keys written to file as key " << name << "." << endl;
|
---|
2427 |
|
---|
2428 | return n;
|
---|
2429 | }
|
---|
2430 |
|
---|
2431 | // --------------------------------------------------------------------------
|
---|
2432 | //
|
---|
2433 | // Use this to start the synchronous (GUI eventloop driven) tab update.
|
---|
2434 | // Can also be used to change the update intervall. If millisec<0
|
---|
2435 | // the intervall given in SetUpdateTime is used. If the intervall in
|
---|
2436 | // SetUpdateTime is <0 nothing is done. (Call SetUpdateTime(-1) to
|
---|
2437 | // disable the automatic update in a MEventloop.
|
---|
2438 | //
|
---|
2439 | void MStatusDisplay::StartUpdate(Int_t millisec)
|
---|
2440 | {
|
---|
2441 | if (fIsLocked>1)
|
---|
2442 | return;
|
---|
2443 |
|
---|
2444 | if (fTimer.GetTime()<TTime(0))
|
---|
2445 | return;
|
---|
2446 | fTimer.Start(millisec);
|
---|
2447 | }
|
---|
2448 |
|
---|
2449 | // --------------------------------------------------------------------------
|
---|
2450 | //
|
---|
2451 | // Stops the automatic GUI update
|
---|
2452 | //
|
---|
2453 | void MStatusDisplay::StopUpdate()
|
---|
2454 | {
|
---|
2455 | if (fIsLocked>1)
|
---|
2456 | return;
|
---|
2457 |
|
---|
2458 | fTimer.Stop();
|
---|
2459 | }
|
---|
2460 |
|
---|
2461 | // --------------------------------------------------------------------------
|
---|
2462 | //
|
---|
2463 | // Set the update interval for the GUI update, see StartUpdate.
|
---|
2464 | //
|
---|
2465 | void MStatusDisplay::SetUpdateTime(Long_t t)
|
---|
2466 | {
|
---|
2467 | fTimer.SetTime(t);
|
---|
2468 | }
|
---|
2469 |
|
---|
2470 | // --------------------------------------------------------------------------
|
---|
2471 | //
|
---|
2472 | // If the filename name doesn't end with ext, ext is added to the end.
|
---|
2473 | // If name.IsNull() "status" is assumed and the a number (>0) is added
|
---|
2474 | // as "status-6".
|
---|
2475 | // The extension is returned.
|
---|
2476 | //
|
---|
2477 | const TString &MStatusDisplay::AddExtension(TString &name, const TString &ext, Int_t num) const
|
---|
2478 | {
|
---|
2479 | if (name.IsNull())
|
---|
2480 | {
|
---|
2481 | name = gROOT->GetName();
|
---|
2482 | if (num>0)
|
---|
2483 | {
|
---|
2484 | name += "-";
|
---|
2485 | name += num;
|
---|
2486 | }
|
---|
2487 | }
|
---|
2488 |
|
---|
2489 | if (name.EndsWith("."+ext))
|
---|
2490 | return ext;
|
---|
2491 |
|
---|
2492 | name += ".";
|
---|
2493 | name += ext;
|
---|
2494 |
|
---|
2495 | return ext;
|
---|
2496 | }
|
---|
2497 |
|
---|
2498 | Bool_t MStatusDisplay::CheckTabForCanvas(int num) const
|
---|
2499 | {
|
---|
2500 | if (gROOT->IsBatch())
|
---|
2501 | return (num>0 && num<=fBatch->GetSize()) || num<0;
|
---|
2502 |
|
---|
2503 | if (num>=fTab->GetNumberOfTabs())
|
---|
2504 | {
|
---|
2505 | *fLog << warn << "Tab #" << num << " doesn't exist..." << endl;
|
---|
2506 | return kFALSE;
|
---|
2507 | }
|
---|
2508 | if (num==0)
|
---|
2509 | {
|
---|
2510 | *fLog << warn << "Tab #" << num << " doesn't contain an embedded canvas..." << endl;
|
---|
2511 | return kFALSE;
|
---|
2512 | }
|
---|
2513 | if (fTab->GetNumberOfTabs()<2 || !gPad)
|
---|
2514 | {
|
---|
2515 | *fLog << warn << "Sorry, you must have at least one existing canvas (gPad!=NULL)" << endl;
|
---|
2516 | return kFALSE;
|
---|
2517 | }
|
---|
2518 | return kTRUE;
|
---|
2519 | }
|
---|
2520 |
|
---|
2521 | // --------------------------------------------------------------------------
|
---|
2522 | //
|
---|
2523 | // Insert the following two lines into the postscript header:
|
---|
2524 | //
|
---|
2525 | // %%DocumentPaperSizes: a4
|
---|
2526 | // %%Orientation: Landscape
|
---|
2527 | //
|
---|
2528 | void MStatusDisplay::UpdatePSHeader(const TString &name) const
|
---|
2529 | {
|
---|
2530 | const TString newstr("%%DocumentPaperSizes: a4\n%%Orientation: Landscape\n");
|
---|
2531 |
|
---|
2532 | TString tmp(name+"XXXXXX");
|
---|
2533 |
|
---|
2534 | // FIXME: Use mkstemp instead
|
---|
2535 | if (!mktemp(const_cast<char*>(tmp.Data())))
|
---|
2536 | {
|
---|
2537 | *fLog << err << "ERROR - MStatusDisplay::UpdatePSHeader: mktemp failed." << endl;
|
---|
2538 | return;
|
---|
2539 | }
|
---|
2540 |
|
---|
2541 | ifstream fin(name);
|
---|
2542 | ofstream fout(tmp);
|
---|
2543 | if (!fout)
|
---|
2544 | {
|
---|
2545 | *fLog << err << "Cannot open file " << name << ": " << strerror(errno) << endl;
|
---|
2546 | return;
|
---|
2547 | }
|
---|
2548 |
|
---|
2549 | char c;
|
---|
2550 |
|
---|
2551 | TString str;
|
---|
2552 | fin >> str >> c; // Read "%!PS-Adobe-2.0\n"
|
---|
2553 | fout << str << endl << newstr;
|
---|
2554 |
|
---|
2555 | // Doing it in blocks seems not to gain much for small (MB) files
|
---|
2556 | while (fin)
|
---|
2557 | {
|
---|
2558 | fin.read(&c, 1);
|
---|
2559 | fout.write(&c, 1);
|
---|
2560 | }
|
---|
2561 |
|
---|
2562 | gSystem->Unlink(name);
|
---|
2563 | gSystem->Rename(tmp, name);
|
---|
2564 | }
|
---|
2565 |
|
---|
2566 | // --------------------------------------------------------------------------
|
---|
2567 | //
|
---|
2568 | void MStatusDisplay::PSToolsRange(TVirtualPS &vps, Float_t psw, Float_t psh) const
|
---|
2569 | {
|
---|
2570 | if (vps.InheritsFrom(TPostScript::Class()))
|
---|
2571 | static_cast<TPostScript&>(vps).Range(psw, psh);
|
---|
2572 | // if (vps.InheritsFrom(TPDF::Class()))
|
---|
2573 | // static_cast<TPDF&>(vps).Range(psw*0.69, psh*0.69);
|
---|
2574 | // if (vps.InheritsFrom(TSVG::Class()))
|
---|
2575 | // static_cast<TSVG&>(vps).Range(psw, psh);
|
---|
2576 | }
|
---|
2577 |
|
---|
2578 | // --------------------------------------------------------------------------
|
---|
2579 | //
|
---|
2580 | void MStatusDisplay::PSToolsTextNDC(TVirtualPS &vps, Double_t u, Double_t v, const char *string) const
|
---|
2581 | {
|
---|
2582 | if (vps.InheritsFrom(TPostScript::Class()))
|
---|
2583 | static_cast<TPostScript&>(vps).TextNDC(u, v, string);
|
---|
2584 | if (vps.InheritsFrom(TPDF::Class()))
|
---|
2585 | static_cast<TPDF&>(vps).TextNDC(u, v, string);
|
---|
2586 | // if (vps.InheritsFrom(TSVG::Class()))
|
---|
2587 | // static_cast<TSVG&>(vps).TextNDC(u, v, string);
|
---|
2588 | }
|
---|
2589 |
|
---|
2590 | // --------------------------------------------------------------------------
|
---|
2591 | //
|
---|
2592 | Int_t MStatusDisplay::InitWriteDisplay(Int_t num, TString &name, const TString &ext)
|
---|
2593 | {
|
---|
2594 | SetStatusLine1(MString::Format("Writing %s file...",ext.Data()));
|
---|
2595 | SetStatusLine2("Please be patient!");
|
---|
2596 |
|
---|
2597 | if (!CheckTabForCanvas(num))
|
---|
2598 | {
|
---|
2599 | SetStatusLine2("Failed!");
|
---|
2600 | return 0;
|
---|
2601 | }
|
---|
2602 |
|
---|
2603 | AddExtension(name, ext, num);
|
---|
2604 |
|
---|
2605 | if (num<0)
|
---|
2606 | *fLog << inf << "Open " << ext << "-File: " << name << endl;
|
---|
2607 |
|
---|
2608 | return num;
|
---|
2609 | }
|
---|
2610 |
|
---|
2611 | // --------------------------------------------------------------------------
|
---|
2612 | //
|
---|
2613 | TCanvas *MStatusDisplay::InitWriteTab(Int_t num, TString &name)
|
---|
2614 | {
|
---|
2615 | const Int_t i = TMath::Abs(num);
|
---|
2616 |
|
---|
2617 | TCanvas *c = GetCanvas(i);
|
---|
2618 | if (!c)
|
---|
2619 | {
|
---|
2620 | if (num<0)
|
---|
2621 | *fLog << inf << " - ";
|
---|
2622 | *fLog << "Tab #" << i << " doesn't contain an embedded Canvas... skipped." << endl;
|
---|
2623 | return 0;
|
---|
2624 | }
|
---|
2625 |
|
---|
2626 | SetStatusLine2(MString::Format("Tab #%d", i));
|
---|
2627 |
|
---|
2628 | //
|
---|
2629 | // Paint canvas into root file
|
---|
2630 | //
|
---|
2631 | if (num<0 && !name.IsNull())
|
---|
2632 | {
|
---|
2633 | Bool_t found = kFALSE;
|
---|
2634 | if (name.Index("%%%%name%%%%"))
|
---|
2635 | {
|
---|
2636 | name.ReplaceAll("%%name%%", c->GetName());
|
---|
2637 | found = kTRUE;
|
---|
2638 | }
|
---|
2639 |
|
---|
2640 | if (name.Index("%%%%title%%%%"))
|
---|
2641 | {
|
---|
2642 | name.ReplaceAll("%%title%%", c->GetTitle());
|
---|
2643 | found = kTRUE;
|
---|
2644 | }
|
---|
2645 |
|
---|
2646 | if (name.Index("%%%%tab%%%%"))
|
---|
2647 | {
|
---|
2648 | name.ReplaceAll("%%tab%%", MString::Format("%d", i));
|
---|
2649 | found = kTRUE;
|
---|
2650 | }
|
---|
2651 |
|
---|
2652 | if (!found)
|
---|
2653 | name.Insert(name.Last('.'), MString::Format("-%d", i));
|
---|
2654 | }
|
---|
2655 |
|
---|
2656 | if (num<0)
|
---|
2657 | *fLog << inf << " - ";
|
---|
2658 | *fLog << inf << "Writing Tab #" << i;
|
---|
2659 |
|
---|
2660 | if (!name.IsNull())
|
---|
2661 | *fLog << " to " << name;
|
---|
2662 |
|
---|
2663 | *fLog << ": " << c->GetName() << "... " << flush;
|
---|
2664 |
|
---|
2665 | return c;
|
---|
2666 | }
|
---|
2667 |
|
---|
2668 | // This is a stupid workaround to get rid of the damned clipping
|
---|
2669 | // of the text. Who the hell needs clipping?
|
---|
2670 | class MyCanvas : public TCanvas
|
---|
2671 | {
|
---|
2672 | public:
|
---|
2673 | void Scale(Double_t val)
|
---|
2674 | {
|
---|
2675 | fAbsXlowNDC = -val;
|
---|
2676 | fAbsYlowNDC = -val;
|
---|
2677 | fAbsWNDC = 1+2*val;
|
---|
2678 | fAbsHNDC = 1+2*val;
|
---|
2679 | }
|
---|
2680 | };
|
---|
2681 |
|
---|
2682 | // --------------------------------------------------------------------------
|
---|
2683 | //
|
---|
2684 | // Write some VGF (vector graphics format). Currently PS, PDF and SVG
|
---|
2685 | // is available. Specified by ext.
|
---|
2686 | //
|
---|
2687 | // In case of num<0 all tabs are written into the VGF file. If num>0
|
---|
2688 | // the canvas in the corresponding tab is written to the file.
|
---|
2689 | // Name is the name of the file (with or without extension).
|
---|
2690 | //
|
---|
2691 | // Returns the number of pages written.
|
---|
2692 | //
|
---|
2693 | // To write all tabs you can also use SaveAsVGF(name, ext)
|
---|
2694 | //
|
---|
2695 | // If the third argument is given a bottom line is drawn with the text
|
---|
2696 | // under it. If no argument is given a bottom line is drawn if
|
---|
2697 | // fTitle (SetTitle) is not empty.
|
---|
2698 | //
|
---|
2699 | Int_t MStatusDisplay::SaveAsVGF(Int_t num, TString name, const TString addon, const TString ext)
|
---|
2700 | {
|
---|
2701 | num = InitWriteDisplay(num, name, ext);
|
---|
2702 | if (num==0)
|
---|
2703 | return 0;
|
---|
2704 |
|
---|
2705 | TPad *padsav = (TPad*)gPad;
|
---|
2706 | TVirtualPS *psave = gVirtualPS;
|
---|
2707 |
|
---|
2708 | TDatime d;
|
---|
2709 |
|
---|
2710 | Int_t type = -1;
|
---|
2711 |
|
---|
2712 | TVirtualPS *ps =0;
|
---|
2713 | if (!ext.CompareTo("ps", TString::kIgnoreCase))
|
---|
2714 | {
|
---|
2715 | gStyle->SetColorModelPS(1);
|
---|
2716 | ps = new TPostScript(name, 112);
|
---|
2717 | type = 1;
|
---|
2718 | }
|
---|
2719 | if (!ext.CompareTo("pdf", TString::kIgnoreCase))
|
---|
2720 | {
|
---|
2721 | ps = new TPDF(name, 112);
|
---|
2722 | type = 2;
|
---|
2723 | }
|
---|
2724 | if (!ext.CompareTo("svg", TString::kIgnoreCase))
|
---|
2725 | {
|
---|
2726 | ps = new TSVG(name, 112);
|
---|
2727 | type = 3;
|
---|
2728 | }
|
---|
2729 |
|
---|
2730 | if (!ps)
|
---|
2731 | {
|
---|
2732 | *fLog << err << "Extension " << ext << " unknown..." << endl;
|
---|
2733 | SetStatusLine2("Failed!");
|
---|
2734 | return 0;
|
---|
2735 | }
|
---|
2736 |
|
---|
2737 | ps->SetBit(TPad::kPrintingPS);
|
---|
2738 | if (type==1)
|
---|
2739 | ps->PrintFast(13, "/nan {1} def ");
|
---|
2740 |
|
---|
2741 | gVirtualPS = ps;
|
---|
2742 |
|
---|
2743 | //
|
---|
2744 | // Create some GUI elements for a page legend
|
---|
2745 | //
|
---|
2746 | TLine line;
|
---|
2747 |
|
---|
2748 | int page = 1;
|
---|
2749 |
|
---|
2750 | //
|
---|
2751 | // Maintain tab numbers
|
---|
2752 | //
|
---|
2753 | Int_t from, to;
|
---|
2754 | GetCanvasRange(from, to, num);
|
---|
2755 |
|
---|
2756 | for (int i=from; i<to; i++)
|
---|
2757 | {
|
---|
2758 | TCanvas *c = InitWriteTab(num<0?-i:i);
|
---|
2759 | if (c==0)
|
---|
2760 | continue;
|
---|
2761 |
|
---|
2762 | //
|
---|
2763 | // Init page and page size, make sure, that the canvas in the file
|
---|
2764 | // has the same Aspect Ratio than on the screen.
|
---|
2765 | //
|
---|
2766 | if (type==1 || i>from)
|
---|
2767 | ps->NewPage();
|
---|
2768 |
|
---|
2769 | //
|
---|
2770 | // 28 is used here to scale the canvas into a height of 28,
|
---|
2771 | // such that the page title can be set above the canvas...
|
---|
2772 | //
|
---|
2773 | Float_t psw = 28.0; // A4 - width (29.7)
|
---|
2774 | Float_t psh = 21.0; // A4 - height (21.0)
|
---|
2775 |
|
---|
2776 | const Float_t cw = c->GetWw();
|
---|
2777 | const Float_t ch = c->GetWh();
|
---|
2778 |
|
---|
2779 | if (psw/psh>cw/ch)
|
---|
2780 | psw = cw/ch*psh;
|
---|
2781 | else
|
---|
2782 | psh = ch/cw*psw;
|
---|
2783 |
|
---|
2784 | PSToolsRange(*ps, psw, psh);
|
---|
2785 |
|
---|
2786 | //
|
---|
2787 | // Clone canvas and change background color and schedule for
|
---|
2788 | // deletion
|
---|
2789 | //
|
---|
2790 |
|
---|
2791 | //const Bool_t store = c->IsBatch();
|
---|
2792 | //c->SetBatch(kTRUE);
|
---|
2793 | c->Paint();
|
---|
2794 | //c->SetBatch(store);
|
---|
2795 |
|
---|
2796 | //
|
---|
2797 | // Change/fix the canvas coordinate system for the overlaying text.
|
---|
2798 | // This is necessary because root clip everything away which is
|
---|
2799 | // outside a predefined area, which is (0,0)/(1,1)
|
---|
2800 | //
|
---|
2801 | const Double_t height = 0.015; // Text height
|
---|
2802 | const Double_t off = 0.005; // Line offset from text
|
---|
2803 |
|
---|
2804 | const Double_t bot = height+off;
|
---|
2805 | const Double_t top = 1-bot;
|
---|
2806 |
|
---|
2807 | static_cast<MyCanvas*>(c)->Scale(bot);
|
---|
2808 |
|
---|
2809 | // If gPad is not set to c all follwing commands will
|
---|
2810 | // get the wrong numbers for alignment
|
---|
2811 | gPad = c;
|
---|
2812 |
|
---|
2813 | // Separator Lines
|
---|
2814 | line.PaintLineNDC(0.01, top, 0.99, top);
|
---|
2815 | line.PaintLineNDC(0.01, bot, 0.99, bot);
|
---|
2816 |
|
---|
2817 | //
|
---|
2818 | // Print overlaying text (NDC = %)
|
---|
2819 | //
|
---|
2820 | // align phi col font size (11=left top)
|
---|
2821 | const TString txt(addon.IsNull() ? fTitle : addon);
|
---|
2822 |
|
---|
2823 | // Text Attributes
|
---|
2824 | TAttText(11, 0, kBlack, 22, height).Copy(*ps);
|
---|
2825 |
|
---|
2826 | // Text on top
|
---|
2827 | ps->SetTextAlign(11); // left bottom
|
---|
2828 | PSToolsTextNDC(*ps, 0.01, top+off, c->GetName());
|
---|
2829 |
|
---|
2830 | ps->SetTextAlign(21); // cent bottom
|
---|
2831 | PSToolsTextNDC(*ps, 0.50, top+off, TString("MARS V"MARSVER" - Modular Analysis and Reconstruction Software - ")+d.AsString());
|
---|
2832 |
|
---|
2833 | ps->SetTextAlign(31); // right bottom
|
---|
2834 | PSToolsTextNDC(*ps, 0.99, top+off, MString::Format("Page No.%i (%i)", page++, i));
|
---|
2835 |
|
---|
2836 | // Text on bottom
|
---|
2837 | ps->SetTextAlign(13); // left top
|
---|
2838 | PSToolsTextNDC(*ps, 0.01, bot-off, c->GetTitle());
|
---|
2839 |
|
---|
2840 | ps->SetTextAlign(23); // cent top
|
---|
2841 | PSToolsTextNDC(*ps, 0.50, bot-off, txt);
|
---|
2842 |
|
---|
2843 | ps->SetTextAlign(33); // right top
|
---|
2844 | PSToolsTextNDC(*ps, 0.99, bot-off, MString::Format("(c) 2000-%d, Thomas Bretz", TDatime().GetYear()));
|
---|
2845 |
|
---|
2846 | static_cast<MyCanvas*>(c)->Scale(0);
|
---|
2847 |
|
---|
2848 | //
|
---|
2849 | // Finish drawing page
|
---|
2850 | //
|
---|
2851 | *fLog << "done." << endl;
|
---|
2852 | }
|
---|
2853 |
|
---|
2854 | gPad = NULL; // Important!
|
---|
2855 |
|
---|
2856 | ps->Close();
|
---|
2857 | delete ps;
|
---|
2858 |
|
---|
2859 | #if ROOT_VERSION_CODE < ROOT_VERSION(5,12,00)
|
---|
2860 | if (type==1)
|
---|
2861 | {
|
---|
2862 | SetStatusLine2("Updating header of PS file...");
|
---|
2863 |
|
---|
2864 | if (num<0)
|
---|
2865 | *fLog << inf3 << " - Updating header of PS file... " << flush;
|
---|
2866 | UpdatePSHeader(name);
|
---|
2867 | if (num<0)
|
---|
2868 | *fLog << inf3 << "done." << endl;
|
---|
2869 | }
|
---|
2870 | #endif
|
---|
2871 |
|
---|
2872 | gVirtualPS = psave;
|
---|
2873 | if (padsav)
|
---|
2874 | padsav->cd();
|
---|
2875 |
|
---|
2876 | if (num<0)
|
---|
2877 | *fLog << inf << "done." << endl;
|
---|
2878 |
|
---|
2879 | SetStatusLine2(MString::Format("Done (%dpages)", page-1));
|
---|
2880 |
|
---|
2881 | return page-1;
|
---|
2882 | }
|
---|
2883 |
|
---|
2884 | // --------------------------------------------------------------------------
|
---|
2885 | //
|
---|
2886 | Bool_t MStatusDisplay::SaveAsImage(Int_t num, TString name, TImage::EImageFileTypes type)
|
---|
2887 | {
|
---|
2888 | #if ROOT_VERSION_CODE < ROOT_VERSION(5,12,00)
|
---|
2889 | if (gROOT->IsBatch())
|
---|
2890 | {
|
---|
2891 | *fLog << warn << "Sorry, writing image-files is not available in batch mode." << endl;
|
---|
2892 | return 0;
|
---|
2893 | }
|
---|
2894 | #endif
|
---|
2895 |
|
---|
2896 | TString ext;
|
---|
2897 | switch (type)
|
---|
2898 | {
|
---|
2899 | case TImage::kXpm:
|
---|
2900 | case TImage::kZCompressedXpm: ext = "xpm"; break;
|
---|
2901 | case TImage::kPng: ext = "png"; break;
|
---|
2902 | case TImage::kJpeg: ext = "jpg"; break;
|
---|
2903 | case TImage::kGif: ext = "gif"; break;
|
---|
2904 | case TImage::kTiff: ext = "tiff"; break;
|
---|
2905 | case TImage::kBmp: ext = "bmp"; break;
|
---|
2906 | case TImage::kXml: ext = "xml"; break;
|
---|
2907 | //case TImage::kGZCompressedXpm: ext = "xpm.gz"; break;
|
---|
2908 | //case TImage::kPpm: ext = "ppm"; break;
|
---|
2909 | //case TImage::kPnm: ext = "pnm"; break;
|
---|
2910 | //case TImage::kIco: ext = "ico"; break;
|
---|
2911 | //case TImage::kCur: ext = "cur"; break;
|
---|
2912 | //case TImage::kXcf: ext = "xcf"; break;
|
---|
2913 | //case TImage::kXbm: ext = "xbm"; break;
|
---|
2914 | //case TImage::kFits: ext = "fits"; break;
|
---|
2915 | //case TImage::kTga: ext = "tga"; break;
|
---|
2916 | default:
|
---|
2917 | *fLog << warn << "Sorry, unknown or unsupported file type..." << endl;
|
---|
2918 | return 0;
|
---|
2919 | }
|
---|
2920 |
|
---|
2921 | num = InitWriteDisplay(num, name, ext);
|
---|
2922 | if (num==0)
|
---|
2923 | return 0;
|
---|
2924 |
|
---|
2925 | TPad *padsav = (TPad*)gPad;
|
---|
2926 |
|
---|
2927 | Int_t counter = 0;
|
---|
2928 |
|
---|
2929 | //
|
---|
2930 | // Maintain tab numbers
|
---|
2931 | //
|
---|
2932 | Int_t from, to;
|
---|
2933 | GetCanvasRange(from, to, num);
|
---|
2934 |
|
---|
2935 | for (int i=from; i<to; i++)
|
---|
2936 | {
|
---|
2937 | TString writename(name);
|
---|
2938 |
|
---|
2939 | TCanvas *c = InitWriteTab(num<0 ? -i : i, writename);
|
---|
2940 | if (!c)
|
---|
2941 | continue;
|
---|
2942 |
|
---|
2943 | //
|
---|
2944 | // Paint canvas into root file
|
---|
2945 | //
|
---|
2946 |
|
---|
2947 | // TImage *img = TImage::Create();
|
---|
2948 | // img->FromPad(c);
|
---|
2949 | // img->WriteImage(writename, type);
|
---|
2950 | // delete img;
|
---|
2951 |
|
---|
2952 | // FIXME: Not all file types are supported by Print()
|
---|
2953 | c->Print(writename);
|
---|
2954 |
|
---|
2955 | if (num<0)
|
---|
2956 | *fLog << "done." << endl;
|
---|
2957 |
|
---|
2958 | counter++;
|
---|
2959 | }
|
---|
2960 |
|
---|
2961 | if (padsav)
|
---|
2962 | padsav->cd();
|
---|
2963 |
|
---|
2964 | *fLog << inf << "done." << endl;
|
---|
2965 |
|
---|
2966 | SetStatusLine2("Done.");
|
---|
2967 |
|
---|
2968 | return counter>0;
|
---|
2969 | }
|
---|
2970 |
|
---|
2971 | // --------------------------------------------------------------------------
|
---|
2972 | //
|
---|
2973 | Bool_t MStatusDisplay::SaveAsC(Int_t num, TString name)
|
---|
2974 | {
|
---|
2975 | num = InitWriteDisplay(num, name, "C");
|
---|
2976 | if (num==0)
|
---|
2977 | return kFALSE;
|
---|
2978 |
|
---|
2979 | TPad *padsav = (TPad*)gPad;
|
---|
2980 |
|
---|
2981 | Int_t counter = 0;
|
---|
2982 |
|
---|
2983 | //
|
---|
2984 | // Maintain tab numbers
|
---|
2985 | //
|
---|
2986 | Int_t from, to;
|
---|
2987 | GetCanvasRange(from, to, num);
|
---|
2988 |
|
---|
2989 | for (int i=from; i<to; i++)
|
---|
2990 | {
|
---|
2991 | TString writename(name);
|
---|
2992 |
|
---|
2993 | TCanvas *c = InitWriteTab(num<0 ? -i : i, writename);
|
---|
2994 | if (!c)
|
---|
2995 | continue;
|
---|
2996 |
|
---|
2997 | //
|
---|
2998 | // Clone canvas and change background color and schedule for
|
---|
2999 | // deletion
|
---|
3000 | //
|
---|
3001 | c->SaveSource(writename, "");
|
---|
3002 |
|
---|
3003 | if (num<0)
|
---|
3004 | *fLog << "done." << endl;
|
---|
3005 |
|
---|
3006 | counter++;
|
---|
3007 | }
|
---|
3008 |
|
---|
3009 | if (padsav)
|
---|
3010 | padsav->cd();
|
---|
3011 |
|
---|
3012 | *fLog << inf << "done." << endl;
|
---|
3013 |
|
---|
3014 | SetStatusLine2("Done.");
|
---|
3015 |
|
---|
3016 | return counter>0;
|
---|
3017 | }
|
---|
3018 |
|
---|
3019 | // --------------------------------------------------------------------------
|
---|
3020 | //
|
---|
3021 | // In case of num<0 all tabs are written into the PS file. If num>0
|
---|
3022 | // the canvas in the corresponding tab is written to the file.
|
---|
3023 | // Name is the name of the file (with or without extension).
|
---|
3024 | //
|
---|
3025 | // Returns the number of keys written.
|
---|
3026 | //
|
---|
3027 | // To write all tabs you can also use SaveAsPS(name)
|
---|
3028 | //
|
---|
3029 | Int_t MStatusDisplay::SaveAsRoot(Int_t num, TString name)
|
---|
3030 | {
|
---|
3031 | num = InitWriteDisplay(num, name, "root");
|
---|
3032 | if (num==0)
|
---|
3033 | return -1;
|
---|
3034 |
|
---|
3035 | TFile *fsave = gFile;
|
---|
3036 | TFile file(name, "RECREATE", GetTitle(), 9);
|
---|
3037 | const Int_t keys = Write(num);
|
---|
3038 | gFile = fsave;
|
---|
3039 |
|
---|
3040 | SetStatusLine2("Done.");
|
---|
3041 |
|
---|
3042 | return keys;
|
---|
3043 | }
|
---|
3044 |
|
---|
3045 | // --------------------------------------------------------------------------
|
---|
3046 | //
|
---|
3047 | Bool_t MStatusDisplay::SaveAsCSV(Int_t num, TString name, Char_t delim)
|
---|
3048 | {
|
---|
3049 | num = InitWriteDisplay(num, name, "csv");
|
---|
3050 | if (num==0)
|
---|
3051 | return kFALSE;
|
---|
3052 |
|
---|
3053 | gSystem->ExpandPathName(name);
|
---|
3054 |
|
---|
3055 | ofstream fout(name);
|
---|
3056 | if (!fout)
|
---|
3057 | {
|
---|
3058 | *fLog << err << "Cannot open file " << name << ": " << strerror(errno) << endl;
|
---|
3059 | return kFALSE;
|
---|
3060 | }
|
---|
3061 |
|
---|
3062 | fout << 0 << delim << GetName() << delim << GetTitle() << endl;
|
---|
3063 |
|
---|
3064 | Int_t from, to;
|
---|
3065 | GetCanvasRange(from, to, num);
|
---|
3066 |
|
---|
3067 | for (int i=from; i<to; i++)
|
---|
3068 | {
|
---|
3069 | TCanvas *c;
|
---|
3070 | if (!(c = GetCanvas(i)))
|
---|
3071 | {
|
---|
3072 | if (num<0)
|
---|
3073 | *fLog << inf << " - ";
|
---|
3074 | *fLog << "Tab #" << i << " doesn't contain an embedded Canvas... skipped." << endl;
|
---|
3075 | continue;
|
---|
3076 | }
|
---|
3077 |
|
---|
3078 | fout << i << delim << c->GetName() << delim << c->GetTitle() << endl;
|
---|
3079 | }
|
---|
3080 |
|
---|
3081 | SetStatusLine2("Done.");
|
---|
3082 |
|
---|
3083 | return kTRUE;
|
---|
3084 | }
|
---|
3085 |
|
---|
3086 | /*
|
---|
3087 | Bool_t MStatusDisplay::SaveAsCSV(Int_t num, TString name)
|
---|
3088 | {
|
---|
3089 | num = InitWriteDisplay(num, name, "csv");
|
---|
3090 | if (num==0)
|
---|
3091 | return kFALSE;
|
---|
3092 |
|
---|
3093 | gSystem->ExpandPathName(name);
|
---|
3094 |
|
---|
3095 | ofstream fout(name);
|
---|
3096 | if (!fout)
|
---|
3097 | {
|
---|
3098 | *fLog << err << "Cannot open file " << name << ": " << strerror(errno) << endl;
|
---|
3099 | return kFALSE;
|
---|
3100 | }
|
---|
3101 |
|
---|
3102 | fout << "<?xml version=\"1.0\"?>" << endl;
|
---|
3103 | fout << "<display name='" << GetName() << "'>" << endl;
|
---|
3104 | fout << " <file>" << name << "</file>" << endl;
|
---|
3105 | fout << " <status>" << endl;
|
---|
3106 | fout << " <name>" << GetName() << "</name>" << endl;
|
---|
3107 | fout << " <title>" << GetTitle() << "</title>" << endl;
|
---|
3108 | fout << " </status>" << endl;
|
---|
3109 | fout << " <tabs>" << endl;
|
---|
3110 |
|
---|
3111 | fout << 0 << delim << GetName() << delim << GetTitle() << endl;
|
---|
3112 |
|
---|
3113 | Int_t from, to;
|
---|
3114 | GetCanvasRange(from, to, num);
|
---|
3115 |
|
---|
3116 | for (int i=from; i<to; i++)
|
---|
3117 | {
|
---|
3118 | TCanvas *c;
|
---|
3119 | if (!(c = GetCanvas(i)))
|
---|
3120 | {
|
---|
3121 | if (num<0)
|
---|
3122 | *fLog << inf << " - ";
|
---|
3123 | *fLog << "Tab #" << i << " doesn't contain an embedded Canvas... skipped." << endl;
|
---|
3124 | continue;
|
---|
3125 | }
|
---|
3126 |
|
---|
3127 | fout << " <tab index='" << i << "'>" << endl;
|
---|
3128 | fout << " <index>" << i << "</index>" << endl;
|
---|
3129 | fout << " <name>" << c->GetName() << "</name>" << endl;
|
---|
3130 | fout << " <title>" << c->GetName() << "</title>" << endl;
|
---|
3131 | fout << " </tab>" << endl;
|
---|
3132 | }
|
---|
3133 |
|
---|
3134 | fout << " </tabs>" << endl;
|
---|
3135 | fout << "</display>" << endl;
|
---|
3136 |
|
---|
3137 | SetStatusLine2("Done.");
|
---|
3138 |
|
---|
3139 | return kTRUE;
|
---|
3140 | }
|
---|
3141 | */
|
---|
3142 |
|
---|
3143 | // --------------------------------------------------------------------------
|
---|
3144 | //
|
---|
3145 | void MStatusDisplay::SaveAs(const char *c, const Option_t *o) const
|
---|
3146 | {
|
---|
3147 | #if ROOT_VERSION_CODE >= ROOT_VERSION(5,18,00)
|
---|
3148 | TGObject::SaveAs(c, o);
|
---|
3149 | #endif
|
---|
3150 | }
|
---|
3151 |
|
---|
3152 | // --------------------------------------------------------------------------
|
---|
3153 | //
|
---|
3154 | // Determin File type to save file as by extension. Allowed extensions are:
|
---|
3155 | // root, ps, pdf, svg, gif, png, jpg, xpm, C
|
---|
3156 | //
|
---|
3157 | // returns -1 if file type is unknown. Otherwise return value of SaveAs*
|
---|
3158 | //
|
---|
3159 | Int_t MStatusDisplay::SaveAs(Int_t num, TString name)
|
---|
3160 | {
|
---|
3161 | if (name.EndsWith(".root")) return SaveAsRoot(num, name); // kFileSaveAsRoot
|
---|
3162 | if (name.EndsWith(".ps")) return SaveAsPS(num, name); // kFileSaveAsPS
|
---|
3163 | if (name.EndsWith(".pdf")) return SaveAsPDF(num, name); // kFileSaveAsPDF
|
---|
3164 | if (name.EndsWith(".svg")) return SaveAsSVG(num, name); // kFileSaveAsSVG
|
---|
3165 | if (name.EndsWith(".gif")) return SaveAsGIF(num, name); // kFileSaveAsGIF
|
---|
3166 | if (name.EndsWith(".png")) return SaveAsPNG(num, name); // kFileSaveAsPNG
|
---|
3167 | if (name.EndsWith(".bmp")) return SaveAsBMP(num, name); // kFileSaveAsBMP
|
---|
3168 | if (name.EndsWith(".xml")) return SaveAsXML(num, name); // kFileSaveAsXML
|
---|
3169 | if (name.EndsWith(".jpg")) return SaveAsJPG(num, name); // kFileSaveAsJPG
|
---|
3170 | if (name.EndsWith(".xpm")) return SaveAsXPM(num, name); // kFileSaveAsXPM
|
---|
3171 | if (name.EndsWith(".csv")) return SaveAsCSV(num, name); // kFileSaveAsCSV
|
---|
3172 | if (name.EndsWith(".tiff")) return SaveAsTIFF(num, name); // kFileSaveAsTIFF
|
---|
3173 | if (name.EndsWith(".C")) return SaveAsC(num, name); // kFileSaveAsC
|
---|
3174 | return -1;
|
---|
3175 | }
|
---|
3176 |
|
---|
3177 | // --------------------------------------------------------------------------
|
---|
3178 | //
|
---|
3179 | // Opens a save as dialog
|
---|
3180 | //
|
---|
3181 | Int_t MStatusDisplay::SaveAs(Int_t num)
|
---|
3182 | {
|
---|
3183 | static const char *gSaveAsTypes[] =
|
---|
3184 | {
|
---|
3185 | "PostScript", "*.ps",
|
---|
3186 | "Acrobat pdf", "*.pdf",
|
---|
3187 | "SVG vector", "*.svg",
|
---|
3188 | "Gif files", "*.gif",
|
---|
3189 | "Png files", "*.png",
|
---|
3190 | "Gif files", "*.gif",
|
---|
3191 | "Jpeg files", "*.jpeg",
|
---|
3192 | "Xpm files", "*.xpm",
|
---|
3193 | "Bmp files", "*.bmp",
|
---|
3194 | "Xml files", "*.xml",
|
---|
3195 | "Tiff files", "*.tiff",
|
---|
3196 | "Csv files", "*.csv",
|
---|
3197 | "Macro files", "*.C",
|
---|
3198 | "ROOT files", "*.root",
|
---|
3199 | "All files", "*",
|
---|
3200 | NULL, NULL
|
---|
3201 | };
|
---|
3202 |
|
---|
3203 | static TString dir(".");
|
---|
3204 |
|
---|
3205 | TGFileInfo fi; // fFileName and fIniDir deleted in ~TGFileInfo
|
---|
3206 |
|
---|
3207 | fi.fFileTypes = (const char**)gSaveAsTypes;
|
---|
3208 | fi.fIniDir = StrDup(dir);
|
---|
3209 |
|
---|
3210 | new TGFileDialog(fClient->GetRoot(), this, kFDSave, &fi);
|
---|
3211 |
|
---|
3212 | if (!fi.fFilename)
|
---|
3213 | return 0;
|
---|
3214 |
|
---|
3215 | dir = fi.fIniDir;
|
---|
3216 |
|
---|
3217 | const Int_t rc = SaveAs(num, fi.fFilename);
|
---|
3218 | if (rc>=0)
|
---|
3219 | return rc;
|
---|
3220 |
|
---|
3221 | Warning("MStatusDisplay::SaveAs", "Unknown Extension: %s", fi.fFilename);
|
---|
3222 | return 0;
|
---|
3223 | }
|
---|
3224 |
|
---|
3225 | // --------------------------------------------------------------------------
|
---|
3226 | //
|
---|
3227 | // Open contents of a MStatusDisplay with key name from file fname.
|
---|
3228 | //
|
---|
3229 | Int_t MStatusDisplay::Open(TString fname, const char *name)
|
---|
3230 | {
|
---|
3231 | TFile file(fname, "READ");
|
---|
3232 | if (file.IsZombie())
|
---|
3233 | {
|
---|
3234 | gLog << warn << "WARNING - Cannot open file " << fname << endl;
|
---|
3235 | return 0;
|
---|
3236 | }
|
---|
3237 |
|
---|
3238 | return Read(name);
|
---|
3239 | }
|
---|
3240 |
|
---|
3241 | // --------------------------------------------------------------------------
|
---|
3242 | //
|
---|
3243 | // Opens an open dialog
|
---|
3244 | //
|
---|
3245 | Int_t MStatusDisplay::Open()
|
---|
3246 | {
|
---|
3247 | static const char *gOpenTypes[] =
|
---|
3248 | {
|
---|
3249 | "ROOT files", "*.root",
|
---|
3250 | "All files", "*",
|
---|
3251 | NULL, NULL
|
---|
3252 | };
|
---|
3253 |
|
---|
3254 | static TString dir(".");
|
---|
3255 |
|
---|
3256 | TGFileInfo fi; // fFileName and fIniDir deleted in ~TGFileInfo
|
---|
3257 |
|
---|
3258 | fi.fFileTypes = (const char**)gOpenTypes;
|
---|
3259 | fi.fIniDir = StrDup(dir);
|
---|
3260 |
|
---|
3261 | new TGFileDialog(fClient->GetRoot(), this, kFDOpen, &fi);
|
---|
3262 |
|
---|
3263 | if (!fi.fFilename)
|
---|
3264 | return 0;
|
---|
3265 |
|
---|
3266 | dir = fi.fIniDir;
|
---|
3267 |
|
---|
3268 | return Open(fi.fFilename);
|
---|
3269 | }
|
---|
3270 |
|
---|
3271 | // --------------------------------------------------------------------------
|
---|
3272 | //
|
---|
3273 | // Change width of display. The height is calculated accordingly.
|
---|
3274 | //
|
---|
3275 | void MStatusDisplay::SetDisplayWidth(UInt_t dw)
|
---|
3276 | {
|
---|
3277 | if (gROOT->IsBatch())
|
---|
3278 | {
|
---|
3279 | SetCanvasWidth(dw);
|
---|
3280 | return;
|
---|
3281 | }
|
---|
3282 |
|
---|
3283 | // 4 == 2*default border with of canvas
|
---|
3284 | dw -= 4;
|
---|
3285 |
|
---|
3286 | // Difference between canvas size and display size
|
---|
3287 | const UInt_t cw = GetWidth() -fTab->GetWidth();
|
---|
3288 | const UInt_t ch = GetHeight()-fTab->GetHeight()+fTab->GetTabHeight();
|
---|
3289 |
|
---|
3290 | const UInt_t dh = TMath::Nint((dw - cw)/1.5 + ch);
|
---|
3291 |
|
---|
3292 | Resize(dw, dh); // Set display size
|
---|
3293 | }
|
---|
3294 |
|
---|
3295 | // --------------------------------------------------------------------------
|
---|
3296 | //
|
---|
3297 | // Change height of display. The width is calculated accordingly.
|
---|
3298 | //
|
---|
3299 | void MStatusDisplay::SetDisplayHeight(UInt_t dh)
|
---|
3300 | {
|
---|
3301 | if (gROOT->IsBatch())
|
---|
3302 | {
|
---|
3303 | SetCanvasHeight(dh);
|
---|
3304 | return;
|
---|
3305 | }
|
---|
3306 |
|
---|
3307 | // 4 == 2*default border with of canvas
|
---|
3308 | dh -= 4;
|
---|
3309 |
|
---|
3310 | // Difference between canvas size and display size
|
---|
3311 | const UInt_t cw = GetWidth() -fTab->GetWidth();
|
---|
3312 | const UInt_t ch = GetHeight()-fTab->GetHeight()+fTab->GetTabHeight();
|
---|
3313 |
|
---|
3314 | const UInt_t dw = TMath::Nint((dh - ch)*1.5 + cw);
|
---|
3315 |
|
---|
3316 | Resize(dw, dh); // Set display size
|
---|
3317 | }
|
---|
3318 |
|
---|
3319 | // --------------------------------------------------------------------------
|
---|
3320 | //
|
---|
3321 | // Change width of canvas. The height is calculated accordingly.
|
---|
3322 | //
|
---|
3323 | void MStatusDisplay::SetCanvasWidth(UInt_t w)
|
---|
3324 | {
|
---|
3325 | // 4 == 2*default border with of canvas
|
---|
3326 | w += 4;
|
---|
3327 |
|
---|
3328 | if (gROOT->IsBatch())
|
---|
3329 | {
|
---|
3330 | Resize(w, 3*w/2);
|
---|
3331 | return;
|
---|
3332 | }
|
---|
3333 |
|
---|
3334 | // Difference between canvas size and display size
|
---|
3335 | const UInt_t cw = GetWidth() -fTab->GetWidth();
|
---|
3336 | const UInt_t ch = GetHeight()-fTab->GetHeight()+fTab->GetTabHeight();
|
---|
3337 |
|
---|
3338 | const UInt_t h = TMath::Nint(w/1.5 + ch);
|
---|
3339 |
|
---|
3340 | Resize(w + cw, h); // Set display size
|
---|
3341 | }
|
---|
3342 |
|
---|
3343 | // --------------------------------------------------------------------------
|
---|
3344 | //
|
---|
3345 | // Change height of canvas. The width is calculated accordingly.
|
---|
3346 | //
|
---|
3347 | void MStatusDisplay::SetCanvasHeight(UInt_t h)
|
---|
3348 | {
|
---|
3349 | // 4 == 2*default border with of canvas
|
---|
3350 | h += 4;
|
---|
3351 |
|
---|
3352 | if (gROOT->IsBatch())
|
---|
3353 | {
|
---|
3354 | Resize(2*h/3, h);
|
---|
3355 | return;
|
---|
3356 | }
|
---|
3357 |
|
---|
3358 | // Difference between canvas size and display size
|
---|
3359 | const UInt_t cw = GetWidth() -fTab->GetWidth();
|
---|
3360 | const UInt_t ch = GetHeight()-fTab->GetHeight()+fTab->GetTabHeight();
|
---|
3361 |
|
---|
3362 | // 4 == 2*default border with of canvas
|
---|
3363 | const UInt_t dw = TMath::Nint((h+4)*1.5 + cw);
|
---|
3364 |
|
---|
3365 | Resize(dw, h + ch); // Set display size
|
---|
3366 | }
|
---|
3367 |
|
---|
3368 | // --------------------------------------------------------------------------
|
---|
3369 | //
|
---|
3370 | // Calculate width and height of the display such that it fits into the
|
---|
3371 | // defined box.
|
---|
3372 | //
|
---|
3373 | void MStatusDisplay::SetDisplaySize(UInt_t w, UInt_t h)
|
---|
3374 | {
|
---|
3375 | if (gROOT->IsBatch())
|
---|
3376 | return;
|
---|
3377 |
|
---|
3378 | SetDisplayHeight(h);
|
---|
3379 |
|
---|
3380 | if (GetWidth()>w)
|
---|
3381 | SetDisplayWidth(w);
|
---|
3382 | }
|
---|
3383 |
|
---|
3384 | // --------------------------------------------------------------------------
|
---|
3385 | //
|
---|
3386 | // Calculate an optimum size for the display from the desktop size
|
---|
3387 | //
|
---|
3388 | void MStatusDisplay::SetOptimumSize()
|
---|
3389 | {
|
---|
3390 | if (gROOT->IsBatch())
|
---|
3391 | return;
|
---|
3392 |
|
---|
3393 | const UInt_t w = TMath::Nint(0.95*gClient->GetDisplayWidth());
|
---|
3394 | const UInt_t h = TMath::Nint(0.95*gClient->GetDisplayHeight());
|
---|
3395 |
|
---|
3396 | SetDisplaySize(w, h);
|
---|
3397 | }
|
---|
3398 |
|
---|
3399 |
|
---|
3400 | Bool_t MStatusDisplay::HandleConfigureNotify(Event_t *evt)
|
---|
3401 | {
|
---|
3402 | //
|
---|
3403 | // The initialization of the GUI is not yet enough finished...
|
---|
3404 | //
|
---|
3405 | if (!fTab)
|
---|
3406 | return kTRUE;
|
---|
3407 |
|
---|
3408 | UInt_t w = evt->fWidth;
|
---|
3409 | UInt_t h = evt->fHeight;
|
---|
3410 |
|
---|
3411 | const Bool_t wchanged = w!=GetWidth()-fTab->GetWidth();
|
---|
3412 | const Bool_t hchanged = h!=GetHeight()-fTab->GetHeight();
|
---|
3413 |
|
---|
3414 | if (!wchanged && !hchanged)
|
---|
3415 | {
|
---|
3416 | Layout();
|
---|
3417 | // FIXME: Make sure that this doesn't result in endless loops.
|
---|
3418 | return kTRUE;
|
---|
3419 | }
|
---|
3420 |
|
---|
3421 | if (GetWidth()==1 && GetHeight()==1)
|
---|
3422 | return kTRUE;
|
---|
3423 |
|
---|
3424 | // calculate the constant part of the window
|
---|
3425 | const UInt_t cw = GetWidth() -fTab->GetWidth();
|
---|
3426 | const UInt_t ch = GetHeight()-fTab->GetHeight()+fTab->GetTabHeight();
|
---|
3427 |
|
---|
3428 | // calculate new size of frame (canvas @ 2:3)
|
---|
3429 | if (hchanged)
|
---|
3430 | w = TMath::Nint((h-ch)*1.5+cw);
|
---|
3431 | else
|
---|
3432 | h = TMath::Nint((w-cw)/1.5+ch);
|
---|
3433 |
|
---|
3434 | // resize frame
|
---|
3435 | Resize(w, h);
|
---|
3436 |
|
---|
3437 | return kTRUE;
|
---|
3438 | }
|
---|
3439 |
|
---|
3440 | Bool_t MStatusDisplay::HandleEvent(Event_t *event)
|
---|
3441 | {
|
---|
3442 | // Instead of doing this in CloseWindow (called from HandleEvent)
|
---|
3443 | // we do it here. This makes sure, that handle event doesn't
|
---|
3444 | // execute code after deleting this.
|
---|
3445 | if (event->fType==kDestroyNotify)
|
---|
3446 | {
|
---|
3447 | if (Close())
|
---|
3448 | delete this;
|
---|
3449 | // Close();
|
---|
3450 | return kTRUE;
|
---|
3451 | }
|
---|
3452 |
|
---|
3453 | const Bool_t rc = TGMainFrame::HandleEvent(event);
|
---|
3454 |
|
---|
3455 | //
|
---|
3456 | // This fixes a bug in older root versions which makes
|
---|
3457 | // TCanvas crash if gPad==NULL. So we make sure, that
|
---|
3458 | // gPad!=NULL -- be carfull, this may have other side
|
---|
3459 | // effects.
|
---|
3460 | //
|
---|
3461 | #if ROOT_VERSION_CODE < ROOT_VERSION(3,10,01)
|
---|
3462 | if (!gPad && fTab)
|
---|
3463 | for (int i=0; i<fTab->GetNumberOfTabs(); i++)
|
---|
3464 | {
|
---|
3465 | TCanvas *c = GetCanvas(i);
|
---|
3466 | if (c)
|
---|
3467 | {
|
---|
3468 | c->cd();
|
---|
3469 | gLog << dbg << "MStatusDisplay::HandleEvent - Workaround: gPad=" << gPad << "." << endl;
|
---|
3470 | break;
|
---|
3471 | }
|
---|
3472 | }
|
---|
3473 | #endif
|
---|
3474 |
|
---|
3475 | return rc;
|
---|
3476 | }
|
---|