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