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