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