Changeset 8962 for trunk/MagicSoft/Mars


Ignore:
Timestamp:
06/15/08 21:53:41 (16 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/Changelog

    r8961 r8962  
    4949   * mraw/Makefile, mraw/RawLinkDef.h:
    5050     - removed MRawFileWrite
     51
     52   * mbase/MStatusDisplay.[h,cc]:
     53     - added the tif file format
     54     - added the csv file format
     55     - fixed the bmp and xml menu entries
     56     - added again to list of specials to allow for access from the
     57       interpreter
     58     - added title to AddTab. The title is stored as canvas title
     59     - added some warpper to access FindobjectInCanvas and Print
     60       from the MStatusDisplay to gain access from the interpreter
     61     - Removed obsolete DrawClonePad wrapper in Display and
     62       added title
     63     - added FillArray to add all canvases to a temporary MStatusArray
     64     - removed obsolete CanvasSetFillColor
     65     - use mktemp in UpdatePSHeader
     66     - some code cleanup. Moved some common code from the SaveAs function
     67       to the new InitWrite* functions
     68     - implemented %%tab%% and %%name%%
     69     - added a workround (MyCanvas) to get the title and footer in the
     70       ps-files also in root 5.18
     71     - removed cloning of the canvases whereever possible.Gave problems
     72       in root 5.18 (not yet understood)
     73     - changed color mode of postscrip files from rgb to cmyk
     74     - UpdatePSHeader not long needed in root >=5.12
     75     - reorganized header file
    5176
    5277
  • trunk/MagicSoft/Mars/NEWS

    r8961 r8962  
    7575
    7676   * Tabs now can have a title which is displayed in the postscript file
     77
     78   * When multiple file are written at once (e.g. pngs from a display)
     79     it is now possible to use the tab name and or tab number in the
     80     file name. For details see showplos's help.
    7781
    7882 ;merpp
  • trunk/MagicSoft/Mars/mbase/MStatusDisplay.cc

    r8955 r8962  
    6060/////////////////////////////////////////////////////////////////////////////
    6161#include "MStatusDisplay.h"
     62
     63#include <errno.h>
    6264
    6365#include <fstream>                // fstream
     
    264266    savemenu->AddEntry(MString::Format("%s&jpg", fname.Data()),  kFileSaveAsJPG);
    265267    savemenu->AddEntry(MString::Format("%s&xpm", fname.Data()),  kFileSaveAsXPM);
    266     //savemenu->AddEntry("Save status.x&cf",  kFileSaveAsXCF);
    267     //savemenu->AddEntry("Save status.&tiff", kFileSaveAsTIFF);
    268     savemenu->AddEntry("Save status.&bmp",  kFileSaveAsBMP);
    269     savemenu->AddEntry("Save status.&xml",  kFileSaveAsXML);
     268    savemenu->AddEntry(MString::Format("%s&tiff",fname.Data()),  kFileSaveAsTIFF);
     269    savemenu->AddEntry(MString::Format("%s&bmp", fname.Data()),  kFileSaveAsBMP);
     270    savemenu->AddEntry(MString::Format("%sx&ml", fname.Data()),  kFileSaveAsXML);
     271    savemenu->AddEntry(MString::Format("%scs&v", fname.Data()),  kFileSaveAsCSV);
    270272    savemenu->AddSeparator();
    271273    savemenu->AddEntry(MString::Format("%s&C",    fname.Data()), kFileSaveAsC);
     
    303305    savemenu2->AddEntry(MString::Format("%s&jpg", fname2.Data()),  kTabSaveAsJPG);
    304306    savemenu2->AddEntry(MString::Format("%s&xpm", fname2.Data()),  kTabSaveAsXPM);
    305     //savemenu->AddEntry("Save status.x&cf",  kFileSaveAsXCF);
    306     //savemenu->AddEntry("Save status.&tiff", kFileSaveAsTIFF);
    307     savemenu->AddEntry("Save status.&bmp",  kFileSaveAsBMP);
    308     savemenu->AddEntry("Save status.&xml",  kFileSaveAsXML);
     307    savemenu2->AddEntry(MString::Format("%s&tiff",fname2.Data()),  kTabSaveAsTIFF);
     308    savemenu2->AddEntry(MString::Format("%s&bmp", fname2.Data()),  kTabSaveAsBMP);
     309    savemenu2->AddEntry(MString::Format("%sx&ml", fname2.Data()),  kTabSaveAsXML);
     310    savemenu2->AddEntry(MString::Format("%scs&v", fname2.Data()),  kTabSaveAsCSV);
    309311    savemenu2->AddSeparator();
    310312    savemenu2->AddEntry(MString::Format("%s&C",    fname2.Data()), kTabSaveAsC);
     
    700702    // from the list in the destructor.
    701703    //
    702 //    gROOT->GetListOfSpecials()->Add(this);
     704    gROOT->GetListOfSpecials()->Add(this);
    703705
    704706    fFont = gVirtualX->LoadQueryFont("7x13bold");
     
    10171019// tab and returns a reference to the corresponding TCanvas.
    10181020//
    1019 TCanvas &MStatusDisplay::AddTab(const char *name)
     1021TCanvas &MStatusDisplay::AddTab(const char *name, const char *title)
    10201022{
    10211023    /*
     
    10331035        const UInt_t ch = 2*cw/3 + 25; // 25: Menu, etc
    10341036
    1035         // The constructor of TCanvas adds the canvas to th eglobal list
     1037        // The constructor of TCanvas adds the canvas to the global list
    10361038        // of canvases gROOT->GetListOfCanvases(). If a canvas with an
    10371039        // identical name exists already in this list, the canvas is
     
    10441046        // part of the list of cleanups, thus fBatch need not to be added
    10451047        // to the list of cleanups.
    1046         TCanvas *c = new TCanvas("", name, -cw, ch);
     1048        TCanvas *c = new TCanvas("", title?title:"", -cw, ch);
    10471049        c->SetName(name);
    10481050        fBatch->Add(c);
     
    10661068    // set background and border mode of the canvas
    10671069    TCanvas &c = *ec->GetCanvas();
     1070
     1071    if (title)
     1072        c.SetTitle(title);
    10681073
    10691074    c.SetFillColor(16/*165*//*17*//*203*/);
     
    12121217            return "";
    12131218    }
    1214 
    12151219
    12161220    if (c.Contains("%f") && ext)
     
    15881592        return kTRUE;
    15891593
    1590     //case kFileSaveAsXCF:
    1591     //    SaveAsXCF();
    1592     //    return kTRUE;
    1593 
    1594     //case kFileSaveAsTIFF:
    1595     //    SaveAsTIFF();
    1596     //    return kTRUE;
     1594    case kFileSaveAsTIFF:
     1595        SaveAsTIFF();
     1596        return kTRUE;
    15971597
    15981598    case kFileSaveAsBMP:
     
    16041604        return kTRUE;
    16051605
     1606    case kFileSaveAsCSV:
     1607        SaveAsCSV();
     1608        return kTRUE;
     1609
    16061610    case kFileSaveAsC:
    16071611        SaveAsC();
     
    16481652        return kTRUE;
    16491653
    1650     //case kTabSaveAsXCF:
    1651     //    SaveAsXCF(fTab->GetCurrent());
    1652     //    return kTRUE;
    1653 
    1654     //case kTabSaveAsTIFF:
    1655     //    SaveAsTIFF(fTab->GetCurrent());
    1656     //    return kTRUE;
     1654    case kTabSaveAsTIFF:
     1655        SaveAsTIFF(fTab->GetCurrent());
     1656        return kTRUE;
    16571657
    16581658    case kTabSaveAsBMP:
     
    16621662    case kTabSaveAsXML:
    16631663        SaveAsXML(fTab->GetCurrent());
     1664        return kTRUE;
     1665
     1666    case kTabSaveAsCSV:
     1667        SaveAsCSV(fTab->GetCurrent());
    16641668        return kTRUE;
    16651669
     
    20702074// --------------------------------------------------------------------------
    20712075//
     2076// Find an object in a canvas (uses MStatusArray as helper)
     2077//
     2078void MStatusDisplay::PrintContent(Option_t *o) const
     2079{
     2080    MStatusArray(*this).Print(o);
     2081}
     2082
     2083// --------------------------------------------------------------------------
     2084//
     2085// Find an object in a canvas (uses MStatusArray as helper)
     2086//
     2087TObject *MStatusDisplay::FindObjectInCanvas(const char *obj, const char *base, const char *canv) const
     2088{
     2089    return MStatusArray(*this).FindObjectInCanvas(obj, base, canv);
     2090}
     2091
     2092// --------------------------------------------------------------------------
     2093//
    20722094// Draws a clone of a canvas into a new canvas. Taken from TCanvas.
    20732095//
     
    21322154}
    21332155
     2156// --------------------------------------------------------------------------
     2157//
     2158// Display the contexts of a TObjArray in the display (all canvases)
     2159//
    21342160Bool_t MStatusDisplay::Display(const TObjArray &list, const char *tab)
    21352161{
     
    21482174    while ((c=(TCanvas*)Next()))
    21492175        //if (!GetCanvas(c->GetName()))
    2150         if (!tab || c->GetName()==(TString)tab)
    2151             DrawClonePad(c->GetName(), *c);
     2176        if (c->InheritsFrom(TCanvas::Class()))
     2177            if (!tab || c->GetName()==(TString)tab)
     2178                DrawClonePad(AddTab(c->GetName(), c->GetTitle()), *c);
    21522179
    21532180    return kTRUE;
     
    21752202
    21762203    const Int_t n = list.Read(name);
     2204
     2205    //
     2206    // If no status display was found with this name try to find canvases
     2207    // in the file and s´display them instead.
     2208    //
    21772209    if (n==0)
    21782210    {
     
    22252257// --------------------------------------------------------------------------
    22262258//
    2227 // Writes the contents of a MStatusDisplay to a file.
    2228 //
    2229 Int_t MStatusDisplay::Write(Int_t num, const char *name, Int_t /*option*/, Int_t /*bufsize*/) const
    2230 {
    2231     if (!gFile)
    2232     {
    2233         *fLog << warn << "MStatusDisplay::Write: No file found. Please create a TFile first." << endl;
    2234         return 0;
    2235     }
    2236 
    2237     if (!gFile->IsOpen())
    2238     {
    2239         *fLog << warn << "MStatusDisplay::Write: File not open. Please open the TFile first." << endl;
    2240         return 0;
    2241     }
    2242 
    2243     if (!gFile->IsWritable())
    2244     {
    2245         *fLog << warn << "MStatusDisplay::Write: File not writable." << endl;
    2246         return 0;
    2247     }
    2248 
    2249     if (num==0)
    2250     {
    2251         *fLog << warn << "MStatusDisplay::Write: Tab doesn't contain an embedded Canvas... skipped." << endl;
    2252         return 0;
    2253     }
    2254 
    2255     if (!gROOT->IsBatch() && num>=fTab->GetNumberOfTabs())
    2256     {
    2257         *fLog << warn << "MStatusDisplay::Write: Tab doesn't exist... skipped." << endl;
    2258         return 0;
    2259     }
    2260     if (gROOT->IsBatch() && num>fBatch->GetSize())
    2261     {
    2262         *fLog << warn << "MStatusDisplay::Write: Tab doesn't exist... skipped." << endl;
    2263         return 0;
    2264     }
    2265 
    2266     MStatusArray list;
    2267 
    2268     TNamed named;
    2269     named.SetTitle(fTitle);
    2270     list.Add(&named);
    2271 
     2259// Add all canvases to the MStatusArray
     2260//
     2261void MStatusDisplay::FillArray(MStatusArray &list, Int_t num) const
     2262{
    22722263    Int_t from, to;
    22732264    GetCanvasRange(from, to, num);
     
    22772268        if ((c = GetCanvas(i)))
    22782269            list.Add(c);
     2270}
     2271
     2272// --------------------------------------------------------------------------
     2273//
     2274// Writes the contents of a MStatusDisplay to a file.
     2275//
     2276Int_t MStatusDisplay::Write(Int_t num, const char *name, Int_t /*option*/, Int_t /*bufsize*/) const
     2277{
     2278    if (!gFile)
     2279    {
     2280        *fLog << warn << "MStatusDisplay::Write: No file found. Please create a TFile first." << endl;
     2281        return 0;
     2282    }
     2283
     2284    if (!gFile->IsOpen())
     2285    {
     2286        *fLog << warn << "MStatusDisplay::Write: File not open. Please open the TFile first." << endl;
     2287        return 0;
     2288    }
     2289
     2290    if (!gFile->IsWritable())
     2291    {
     2292        *fLog << warn << "MStatusDisplay::Write: File not writable." << endl;
     2293        return 0;
     2294    }
     2295
     2296    if (num==0)
     2297    {
     2298        *fLog << warn << "MStatusDisplay::Write: Tab doesn't contain an embedded Canvas... skipped." << endl;
     2299        return 0;
     2300    }
     2301
     2302    if (!gROOT->IsBatch() && num>=fTab->GetNumberOfTabs())
     2303    {
     2304        *fLog << warn << "MStatusDisplay::Write: Tab doesn't exist... skipped." << endl;
     2305        return 0;
     2306    }
     2307    if (gROOT->IsBatch() && num>fBatch->GetSize())
     2308    {
     2309        *fLog << warn << "MStatusDisplay::Write: Tab doesn't exist... skipped." << endl;
     2310        return 0;
     2311    }
     2312
     2313    MStatusArray list;
     2314
     2315    // Be careful: So far Display() assumes that it is the first entry in the list
     2316    TNamed named;
     2317    named.SetTitle(fTitle);
     2318    list.Add(&named);
     2319
     2320    FillArray(list, num);
    22792321
    22802322    const Int_t n = list.Write(name, kSingleKey);
     
    23222364{
    23232365    fTimer.SetTime(t);
    2324 }
    2325 
    2326 // --------------------------------------------------------------------------
    2327 //
    2328 // Set the background color in a canvas
    2329 //
    2330 void MStatusDisplay::CanvasSetFillColor(TPad &p, Int_t col) const
    2331 {
    2332     TObject *obj;
    2333 
    2334     // See also TPad::UseCurrentStyle
    2335     TIter Next(p.GetListOfPrimitives());
    2336     while ((obj=Next()))
    2337     {
    2338         if (obj->InheritsFrom(TPad::Class()))
    2339             CanvasSetFillColor(*(TPad*)obj, col);
    2340         if (obj->InheritsFrom(TFrame::Class()))
    2341             ((TFrame*)obj)->SetFillColor(col);
    2342     }
    2343 
    2344     p.SetFillColor(col);
    23452366}
    23462367
     
    24072428    const TString newstr("%%DocumentPaperSizes: a4\n%%Orientation: Landscape\n");
    24082429
     2430    TString tmp(name+"XXXXXX");
     2431
     2432    // FIXME: Use mkstemp instead
     2433    if (!mktemp(const_cast<char*>(tmp.Data())))
     2434    {
     2435        *fLog << err << "ERROR - MStatusDisplay::UpdatePSHeader: mktemp failed." << endl;
     2436        return;
     2437    }
     2438
    24092439    ifstream fin(name);
    2410     ofstream fout(name+".$$$");
     2440    ofstream fout(tmp);
     2441    if (!fout)
     2442    {
     2443        *fLog << err << "Cannot open file " << name << ": " << strerror(errno) << endl;
     2444        return;
     2445    }
    24112446
    24122447    char c;
     
    24242459
    24252460    gSystem->Unlink(name);
    2426     gSystem->Rename(name+".$$$", name);
    2427 }
    2428 
     2461    gSystem->Rename(tmp, name);
     2462}
     2463
     2464// --------------------------------------------------------------------------
     2465//
    24292466void MStatusDisplay::PSToolsRange(TVirtualPS &vps, Float_t psw, Float_t psh) const
    24302467{
     
    24372474}
    24382475
     2476// --------------------------------------------------------------------------
     2477//
    24392478void MStatusDisplay::PSToolsTextNDC(TVirtualPS &vps, Double_t u, Double_t v, const char *string) const
    24402479{
     
    24492488// --------------------------------------------------------------------------
    24502489//
     2490Int_t MStatusDisplay::InitWriteDisplay(Int_t num, TString &name, const TString &ext)
     2491{
     2492    SetStatusLine1(Form("Writing %s file...",ext.Data()));
     2493    SetStatusLine2("Please be patient!");
     2494
     2495    if (!CheckTabForCanvas(num))
     2496    {
     2497        SetStatusLine2("Failed!");
     2498        return 0;
     2499    }
     2500
     2501    AddExtension(name, ext, num);
     2502
     2503    if (num<0)
     2504        *fLog << inf << "Open " << ext << "-File: " << name << endl;
     2505
     2506    return num;
     2507}
     2508
     2509// --------------------------------------------------------------------------
     2510//
     2511TCanvas *MStatusDisplay::InitWriteTab(Int_t num, TString &name)
     2512{
     2513    const Int_t i = TMath::Abs(num);
     2514
     2515    TCanvas *c = GetCanvas(i);
     2516    if (!c)
     2517    {
     2518        if (num<0)
     2519            *fLog << inf << " - ";
     2520        *fLog << "Tab #" << i << " doesn't contain an embedded Canvas... skipped." << endl;
     2521        return 0;
     2522    }
     2523
     2524    SetStatusLine2(MString::Format("Tab #%d", i));
     2525
     2526    //
     2527    // Paint canvas into root file
     2528    //
     2529    if (num<0 && !name.IsNull())
     2530    {
     2531        Bool_t found = kFALSE;
     2532        if (name.Index("%%%%name%%%%"))
     2533        {
     2534            name.ReplaceAll("%%name%%", c->GetName());
     2535            found = kTRUE;
     2536        }
     2537
     2538        if (name.Index("%%%%tab%%%%"))
     2539        {
     2540            name.ReplaceAll("%%tab%%", MString::Format("%d", i));
     2541            found = kTRUE;
     2542        }
     2543
     2544        if (!found)
     2545            name.Insert(name.Last('.'), MString::Format("-%d", i));
     2546    }
     2547
     2548    if (num<0)
     2549        *fLog << inf << " - ";
     2550    *fLog << inf << "Writing Tab #" << i;
     2551
     2552    if (!name.IsNull())
     2553        *fLog << " to " << name;
     2554
     2555    *fLog << ": " << c->GetName() << "... " << flush;
     2556
     2557    return c;
     2558}
     2559
     2560// This is a stupid workaround to get rid of the damned clipping
     2561// of the text. Who the hell needs clipping?
     2562class MyCanvas : public TCanvas
     2563{
     2564public:
     2565    void Scale(Double_t val)
     2566    {
     2567        fAbsXlowNDC = -val;
     2568        fAbsYlowNDC = -val;
     2569        fAbsWNDC    = 1+2*val;
     2570        fAbsHNDC    = 1+2*val;
     2571    }
     2572};
     2573
     2574// --------------------------------------------------------------------------
     2575//
    24512576// Write some VGF (vector graphics format). Currently PS, PDF and SVG
    24522577// is available. Specified by ext.
     
    24662591Int_t MStatusDisplay::SaveAsVGF(Int_t num, TString name, const TString addon, const TString ext)
    24672592{
    2468     SetStatusLine1(Form("Writing %s file...",ext.Data()));
    2469     SetStatusLine2("");
    2470 
    2471     if (!CheckTabForCanvas(num))
    2472     {
    2473         SetStatusLine2("Failed!");
     2593    num = InitWriteDisplay(num, name, ext);
     2594    if (num==0)
    24742595        return 0;
    2475     }
    2476 
    2477     AddExtension(name, ext, num);
    2478 
    2479     if (num<0)
    2480         *fLog << inf << "Open " << ext << "-File: " << name << endl;
    24812596
    24822597    TPad       *padsav = (TPad*)gPad;
     
    24902605    if (!ext.CompareTo("ps", TString::kIgnoreCase))
    24912606    {
     2607        gStyle->SetColorModelPS(1);
    24922608        ps = new TPostScript(name, 112);
    24932609        type = 1;
     
    25182634
    25192635    //
    2520     // Create a list to delete the canvas clones
    2521     //
    2522     TList l;
    2523     l.SetOwner();
    2524 
    2525     //
    25262636    // Create some GUI elements for a page legend
    25272637    //
     
    25332643    // Maintain tab numbers
    25342644    //
     2645    Int_t from, to;
     2646    GetCanvasRange(from, to, num);
     2647
     2648    for (int i=from; i<to; i++)
     2649    {
     2650        TCanvas *c = InitWriteTab(num<0?-i:i);
     2651        if (c==0)
     2652            continue;
     2653
     2654        //
     2655        // Init page and page size, make sure, that the canvas in the file
     2656        // has the same Aspect Ratio than on the screen.
     2657        //
     2658        if (type==1 || i>from)
     2659            ps->NewPage();
     2660
     2661        //
     2662        // 28 is used here to scale the canvas into a height of 28,
     2663        // such that the page title can be set above the canvas...
     2664        //
     2665        Float_t psw = 28.0; // A4 - width  (29.7)
     2666        Float_t psh = 21.0; // A4 - height (21.0)
     2667
     2668        const Float_t cw = c->GetWw();
     2669        const Float_t ch = c->GetWh();
     2670
     2671        if (psw/psh>cw/ch)
     2672            psw = cw/ch*psh;
     2673        else
     2674            psh = ch/cw*psw;
     2675
     2676        PSToolsRange(*ps, psw, psh);
     2677
     2678        //
     2679        // Clone canvas and change background color and schedule for
     2680        // deletion
     2681        //
     2682        const Bool_t store = c->IsBatch();
     2683
     2684        c->SetBatch(kTRUE);
     2685        c->Paint();
     2686        c->SetBatch(store);
     2687
     2688        //
     2689        // Use the canvas as coordinate system for the overlaying text
     2690        //
     2691        gPad = c;
     2692        //n->cd();
     2693
     2694        const Double_t height = 0.015;
     2695
     2696        const Double_t off = 0.005;
     2697        const Double_t bot = height+off;
     2698        const Double_t top = 1-bot;
     2699
     2700        static_cast<MyCanvas*>(c)->Scale(bot);
     2701
     2702        // Separator Lines
     2703        line.PaintLineNDC(0.01, top, 0.99, top);
     2704        line.PaintLineNDC(0.01, bot, 0.99, bot);
     2705
     2706        //
     2707        // Print overlaying text (NDC = %)
     2708        //
     2709        // align phi col font size (11=left top)
     2710        const TString txt(addon.IsNull() ? fTitle : addon);
     2711
     2712        // Text Attributes
     2713        TAttText(11, 0, kBlack, 22, height).Copy(*ps);
     2714
     2715        // Text on top
     2716        ps->SetTextAlign(11); // left bottom
     2717        PSToolsTextNDC(*ps, 0.01, top+off, c->GetName());
     2718
     2719        ps->SetTextAlign(21); // cent bottom
     2720        PSToolsTextNDC(*ps, 0.50, top+off, TString("MARS V"MARSVER" - Modular Analysis and Reconstruction Software - ")+d.AsString());
     2721
     2722        ps->SetTextAlign(31); // right bottom
     2723        PSToolsTextNDC(*ps, 0.99, top+off, MString::Format("Page No.%i (%i)", page++, i));
     2724
     2725        // Text on bottom
     2726        ps->SetTextAlign(13); // left top
     2727        PSToolsTextNDC(*ps, 0.01, bot-off, c->GetTitle());
     2728
     2729        ps->SetTextAlign(23); // cent top
     2730        PSToolsTextNDC(*ps, 0.50, bot-off, txt);
     2731
     2732        ps->SetTextAlign(33); // right top
     2733        PSToolsTextNDC(*ps, 0.99, bot-off, MString::Format("(c) 2000-%d, Thomas Bretz", TDatime().GetYear()));
     2734
     2735        static_cast<MyCanvas*>(c)->Scale(0);
     2736
     2737        //
     2738        // Finish drawing page
     2739        //
     2740        *fLog << "done." << endl;
     2741    }
     2742
     2743    gPad = NULL; // Important!
     2744
     2745    ps->Close();
     2746    delete ps;
     2747
     2748#if ROOT_VERSION_CODE < ROOT_VERSION(5,12,00)
     2749    if (type==1)
     2750    {
     2751        SetStatusLine2("Updating header of PS file...");
     2752
     2753        if (num<0)
     2754            *fLog << inf3 << " - Updating header of PS file... " << flush;
     2755        UpdatePSHeader(name);
     2756        if (num<0)
     2757            *fLog << inf3 << "done." << endl;
     2758    }
     2759#endif
     2760
     2761    gVirtualPS = psave;
     2762    if (padsav)
     2763        padsav->cd();
     2764
     2765    if (num<0)
     2766        *fLog << inf << "done." << endl;
     2767
     2768    SetStatusLine2(MString::Format("Done (%dpages)", page-1));
     2769
     2770    return page-1;
     2771}
     2772
     2773// --------------------------------------------------------------------------
     2774//
     2775Bool_t MStatusDisplay::SaveAsImage(Int_t num, TString name, TImage::EImageFileTypes type)
     2776{
     2777#if ROOT_VERSION_CODE < ROOT_VERSION(5,12,00)
     2778    if (gROOT->IsBatch())
     2779    {
     2780        *fLog << warn << "Sorry, writing image-files is not available in batch mode." << endl;
     2781        return 0;
     2782    }
     2783#endif
     2784
     2785    TString ext;
     2786    switch (type)
     2787    {
     2788    case TImage::kXpm:
     2789    case TImage::kZCompressedXpm:  ext = "xpm";     break;
     2790    case TImage::kPng:             ext = "png";     break;
     2791    case TImage::kJpeg:            ext = "jpg";     break;
     2792    case TImage::kGif:             ext = "gif";     break;
     2793    case TImage::kTiff:            ext = "tiff";    break;
     2794    case TImage::kBmp:             ext = "bmp";     break;
     2795    case TImage::kXml:             ext = "xml";     break;
     2796    //case TImage::kGZCompressedXpm: ext = "xpm.gz";  break;
     2797    //case TImage::kPpm:             ext = "ppm";     break;
     2798    //case TImage::kPnm:             ext = "pnm";     break;
     2799    //case TImage::kIco:             ext = "ico";     break;
     2800    //case TImage::kCur:             ext = "cur";     break;
     2801    //case TImage::kXcf:             ext = "xcf";     break;
     2802    //case TImage::kXbm:             ext = "xbm";     break;
     2803    //case TImage::kFits:            ext = "fits";    break;
     2804    //case TImage::kTga:             ext = "tga";     break;
     2805    default:
     2806        *fLog << warn << "Sorry, unknown or unsupported file type..." << endl;
     2807        return 0;
     2808    }
     2809
     2810    num = InitWriteDisplay(num, name, ext);
     2811    if (num==0)
     2812        return 0;
     2813
     2814    TPad *padsav = (TPad*)gPad;
     2815
     2816    Int_t counter = 0;
     2817
     2818    //
     2819    // Maintain tab numbers
     2820    //
     2821    Int_t from, to;
     2822    GetCanvasRange(from, to, num);
     2823
     2824    for (int i=from; i<to; i++)
     2825    {
     2826        TString writename(name);
     2827
     2828        TCanvas *c = InitWriteTab(num<0 ? -i : i, writename);
     2829        if (!c)
     2830            continue;
     2831
     2832        //
     2833        // Paint canvas into root file
     2834        //
     2835
     2836        // TImage *img = TImage::Create();
     2837        // img->FromPad(c);
     2838        // img->WriteImage(writename, type);
     2839        // delete img;
     2840
     2841        // FIXME: Not all file types are supported by Print()
     2842        c->Print(writename);
     2843
     2844        if (num<0)
     2845            *fLog << "done." << endl;
     2846
     2847        counter++;
     2848    }
     2849
     2850    if (padsav)
     2851        padsav->cd();
     2852
     2853    *fLog << inf << "done." << endl;
     2854
     2855    SetStatusLine2("Done.");
     2856
     2857    return counter>0;
     2858}
     2859
     2860// --------------------------------------------------------------------------
     2861//
     2862Bool_t MStatusDisplay::SaveAsC(Int_t num, TString name)
     2863{
     2864    num = InitWriteDisplay(num, name, "C");
     2865    if (num==0)
     2866        return kFALSE;
     2867
     2868    TPad *padsav = (TPad*)gPad;
     2869
     2870    Int_t counter = 0;
     2871
     2872    //
     2873    // Maintain tab numbers
     2874    //
     2875    Int_t from, to;
     2876    GetCanvasRange(from, to, num);
     2877
     2878    for (int i=from; i<to; i++)
     2879    {
     2880        TString writename(name);
     2881
     2882        TCanvas *c = InitWriteTab(num<0 ? -i : i, writename);
     2883        if (!c)
     2884            continue;
     2885
     2886        //
     2887        // Clone canvas and change background color and schedule for
     2888        // deletion
     2889        //
     2890        c->SaveSource(writename, "");
     2891
     2892        if (num<0)
     2893            *fLog << "done." << endl;
     2894
     2895        counter++;
     2896    }
     2897
     2898    if (padsav)
     2899        padsav->cd();
     2900
     2901    *fLog << inf << "done." << endl;
     2902
     2903    SetStatusLine2("Done.");
     2904
     2905    return counter>0;
     2906}
     2907
     2908// --------------------------------------------------------------------------
     2909//
     2910// In case of num<0 all tabs are written into the PS file. If num>0
     2911// the canvas in the corresponding tab is written to the file.
     2912// Name is the name of the file (with or without extension).
     2913//
     2914// Returns the number of keys written.
     2915//
     2916// To write all tabs you can also use SaveAsPS(name)
     2917//
     2918Int_t MStatusDisplay::SaveAsRoot(Int_t num, TString name)
     2919{
     2920    num = InitWriteDisplay(num, name, "root");
     2921    if (num==0)
     2922        return -1;
     2923
     2924    TFile *fsave = gFile;
     2925    TFile file(name, "RECREATE", GetTitle(), 9);
     2926    const Int_t keys = Write(num);
     2927    gFile = fsave;
     2928
     2929    SetStatusLine2("Done.");
     2930
     2931    return keys;
     2932}
     2933
     2934// --------------------------------------------------------------------------
     2935//
     2936Bool_t MStatusDisplay::SaveAsCSV(Int_t num, TString name, Char_t delim)
     2937{
     2938    num = InitWriteDisplay(num, name, "csv");
     2939    if (num==0)
     2940        return kFALSE;
     2941
     2942    ofstream fout(name);
     2943    if (!fout)
     2944    {
     2945        *fLog << err << "Cannot open file " << name << ": " << strerror(errno) << endl;
     2946        return kFALSE;
     2947    }
     2948
     2949    fout << 0 << delim << GetName() << delim << GetTitle() << endl;
     2950
    25352951    Int_t from, to;
    25362952    GetCanvasRange(from, to, num);
     
    25472963        }
    25482964
    2549         SetStatusLine2(MString::Format("Tab #%d", i));
    2550 
    2551         //
    2552         // Init page and page size, make sure, that the canvas in the file
    2553         // has the same Aspect Ratio than on the screen.
    2554         //
    2555         if (type==1 || i>from)
    2556             ps->NewPage();
    2557 
    2558         //
    2559         // 28 is used here to scale the canvas into a height of 28,
    2560         // such that the page title can be set above the canvas...
    2561         //
    2562         Float_t psw = 28.0; // A4 - width  (29.7)
    2563         Float_t psh = 21.0; // A4 - height (21.0)
    2564 
    2565         const Float_t cw = c->GetWw();
    2566         const Float_t ch = c->GetWh();
    2567 
    2568         if (psw/psh>cw/ch)
    2569             psw = cw/ch*psh;
    2570         else
    2571             psh = ch/cw*psw;
    2572 
    2573         PSToolsRange(*ps, psw, psh);
    2574 
    2575         //
    2576         // Clone canvas and change background color and schedule for
    2577         // deletion
    2578         //
    2579         TCanvas *n = (TCanvas*)c->Clone();
    2580         CanvasSetFillColor(*n, kWhite);
    2581         l.Add(n);
    2582 
    2583         //
    2584         // Paint canvas into root file
    2585         //
    2586         if (num<0)
    2587             *fLog << inf << " - ";
    2588         *fLog << inf << "Writing Tab #" << i << ": " << c->GetName() << " (" << c << ") ";
    2589         if (num>0)
    2590             *fLog << "to " << name;
    2591         *fLog << "... " << flush;
    2592 
    2593         n->SetBatch(kTRUE);
    2594         n->Paint();
    2595 
    2596         //
    2597         // Use the canvas as coordinate system for the overlaying text
    2598         //
    2599         gPad = n;
    2600         //n->cd();
    2601 
    2602         //
    2603         // Print overlaying text (NDC = %)
    2604         //
    2605         // align phi col font size (11=left top)
    2606         TAttText(11, 0, kBlack, 22, 0.015).Copy(*ps);
    2607         PSToolsTextNDC(*ps, 0, 1.015, TString("  ")+n->GetName());
    2608         ps->SetTextAlign(21); // cent top
    2609         PSToolsTextNDC(*ps, 0.5, 1.015, TString("MARS V"MARSVER" - Modular Analysis and Reconstruction Software - ")+d.AsString());
    2610         ps->SetTextAlign(31); // right top
    2611         PSToolsTextNDC(*ps, 1, 1.015, MString::Format("Page No.%i (%i)  ", page++, i));
    2612         line.PaintLineNDC(0, 1.01, 1, 1.01);
    2613 
    2614         TString txt(addon.IsNull() ? fTitle : addon);
    2615         if (!txt.IsNull())
    2616         {
    2617             line.PaintLineNDC(0, -0.00, 1, -0.00);
    2618             ps->SetTextAlign(11); // left top
    2619             PSToolsTextNDC(*ps, 0, -0.015, TString("  ")+txt);
    2620             ps->SetTextAlign(31); // right top
    2621             PSToolsTextNDC(*ps, 1, -0.015, Form("(c) 2000-%d, Thomas Bretz  ", TDatime().GetYear()));
    2622         }
    2623 
    2624         //
    2625         // Finish drawing page
    2626         //
    2627         n->SetBatch(kFALSE);
    2628         *fLog << "done." << endl;
    2629     }
    2630 
    2631     gPad = NULL; // Important!
    2632     l.Delete();
    2633 
    2634     ps->Close();
    2635     delete ps;
    2636 
    2637     if (type==1)
    2638     {
    2639         SetStatusLine2("Updating header of PS file...");
    2640 
    2641         if (num<0)
    2642             *fLog << inf3 << " - Updating header of PS file... " << flush;
    2643         UpdatePSHeader(name);
    2644         if (num<0)
    2645             *fLog << inf3 << "done." << endl;
    2646     }
    2647 
    2648     gVirtualPS = psave;
    2649     if (padsav)
    2650         padsav->cd();
    2651 
    2652     if (num<0)
    2653         *fLog << inf << "done." << endl;
    2654 
    2655     SetStatusLine2(MString::Format("Done (%dpages)", page-1));
    2656 
    2657     return page-1;
    2658 }
    2659 
    2660 Bool_t MStatusDisplay::SaveAsImage(Int_t num, TString name, TImage::EImageFileTypes type)
    2661 {
    2662 #if ROOT_VERSION_CODE < ROOT_VERSION(5,12,00)
    2663     if (gROOT->IsBatch())
    2664     {
    2665         *fLog << warn << "Sorry, writing image-files is not available in batch mode." << endl;
    2666         return 0;
    2667     }
    2668 #endif
    2669 
    2670     SetStatusLine1("Writing image file...");
    2671     SetStatusLine2("please be patient!");
    2672 
    2673     if (!CheckTabForCanvas(num))
    2674     {
    2675         SetStatusLine2("Failed!");
    2676         return 0;
    2677     }
    2678 
    2679     TString ext;
    2680     switch (type)
    2681     {
    2682     case TImage::kXpm:
    2683     case TImage::kZCompressedXpm:
    2684         ext = AddExtension(name, "xpm", num);
    2685         break;
    2686 //    case TImage::kGZCompressedXpm:
    2687 //        ext = AddExtension(name, "xpm.gz", num);
    2688 //        break;
    2689     case TImage::kPng:
    2690         ext = AddExtension(name, "png", num);
    2691         break;
    2692     case TImage::kJpeg:
    2693         ext = AddExtension(name, "jpg", num);
    2694         break;
    2695     case TImage::kGif:
    2696         ext = AddExtension(name, "gif", num);
    2697         break;
    2698 //    case TImage::kTiff:
    2699 //        ext = AddExtension(name, "tiff", num);
    2700 //        break;
    2701 //    case TImage::kPpm:
    2702 //        ext = AddExtension(name, "ppm", num);
    2703 //        break;
    2704 //    case TImage::kPnm:
    2705 //        ext = AddExtension(name, "pnm", num);
    2706 //        break;
    2707 //    case TImage::kIco:
    2708 //        ext = AddExtension(name, "ico", num);
    2709 //        break;
    2710 //    case TImage::kCur:
    2711 //        ext = AddExtension(name, "cur", num);
    2712 //        break;
    2713     case TImage::kBmp:
    2714         ext = AddExtension(name, "bmp", num);
    2715         break;
    2716 //    case TImage::kXcf:
    2717 //        ext = AddExtension(name, "xcf", num);
    2718 //        break;
    2719 //    case TImage::kXbm:
    2720 //        ext = AddExtension(name, "xbm", num);
    2721 //        break;
    2722 //    case TImage::kFits:
    2723 //        ext = AddExtension(name, "fits", num);
    2724 //        break;
    2725 //    case TImage::kTga:
    2726 //        ext = AddExtension(name, "tga", num);
    2727 //        break;
    2728     case TImage::kXml:
    2729         ext = AddExtension(name, "xml", num);
    2730         break;
    2731     default:
    2732         *fLog << warn << "Sorry, unknown or unsupported file type..." << endl;
    2733         return 0;
    2734     }
    2735 
    2736     if (num<0)
    2737         *fLog << inf << "Writing " << ext << "-Files..." << endl;
    2738 
    2739     TPad *padsav = (TPad*)gPad;
    2740 
    2741     int page = 1;
    2742 
    2743     //
    2744     // Maintain tab numbers
    2745     //
    2746     Int_t from, to;
    2747     GetCanvasRange(from, to, num);
    2748 
    2749     for (int i=from; i<to; i++)
    2750     {
    2751         TCanvas *c;
    2752         if (!(c = GetCanvas(i)))
    2753         {
    2754             if (num<0)
    2755                 *fLog << inf << " - ";
    2756             *fLog << "Tab #" << i << " doesn't contain an embedded Canvas... skipped." << endl;
    2757             continue;
    2758         }
    2759 
    2760         SetStatusLine2(MString::Format("Tab #%d", i));
    2761 
    2762         //
    2763         // Clone canvas and change background color and schedule for
    2764         // deletion
    2765         //
    2766         TCanvas *n = c;
    2767         //TCanvas *n = (TCanvas*)c->Clone();
    2768         //CanvasSetFillColor(*n, kWhite);
    2769 
    2770         //
    2771         // Paint canvas into root file
    2772         //
    2773         TString writename = name;
    2774         if (num<0)
    2775         {
    2776             TString numname = "-";
    2777             numname += i;
    2778             writename.Insert(name.Last('.'), numname);
    2779         }
    2780         if (num<0)
    2781             *fLog << inf << " - ";
    2782         *fLog << inf << "Writing Tab #" << i << " to " << writename << ": " << c->GetName() << " (" << c << ") ";
    2783         if (num>0)
    2784             *fLog << "to " << name;
    2785         *fLog << "..." << flush;
    2786 
    2787 #if ROOT_VERSION_CODE < ROOT_VERSION(4,04,00)
    2788         n->Draw();
    2789 
    2790         if (type==TImage::kGif)
    2791             n->SaveAs(writename); // FIXME: Seems not to work well in TImage! (root 3.10/02)
    2792         else
    2793         {
    2794             TImage *img = TImage::Create();
    2795             img->FromPad(n);
    2796             img->WriteImage(writename, type);
    2797             delete img;
    2798         }
    2799 #else
    2800         //gROOT->SetBatch();
    2801         n->Print(writename);
    2802         //gROOT->SetBatch(kFALSE);
    2803 #endif
    2804         // delete n;
    2805         if (num<0)
    2806             *fLog << "done." << endl;
    2807     }
    2808 
    2809     if (padsav)
    2810         padsav->cd();
    2811 
    2812     *fLog << inf << "done." << endl;
     2965        fout << i << delim << c->GetName() << delim << c->GetTitle() << endl;
     2966    }
    28132967
    28142968    SetStatusLine2("Done.");
    28152969
    2816     return page-1;
    2817 }
    2818 
    2819 Bool_t MStatusDisplay::SaveAsC(Int_t num, TString name)
    2820 {
    2821     SetStatusLine1("Writing C++ file...");
    2822     SetStatusLine2("");
    2823 
    2824     if (!CheckTabForCanvas(num))
    2825     {
    2826         SetStatusLine2("Failed!");
    2827         return 0;
    2828     }
    2829 
    2830     AddExtension(name, "C", num);
    2831 
    2832     if (num<0)
    2833         *fLog << inf << "Writing C-Files..." << endl;
    2834 
    2835     TPad *padsav = (TPad*)gPad;
    2836 
    2837     int page = 1;
    2838 
    2839     //
    2840     // Maintain tab numbers
    2841     //
    2842     Int_t from, to;
    2843     GetCanvasRange(from, to, num);
    2844 
    2845     for (int i=from; i<to; i++)
    2846     {
    2847         TCanvas *c;
    2848         if (!(c = GetCanvas(i)))
    2849         {
    2850             if (num<0)
    2851                 *fLog << inf << " - ";
    2852             *fLog << "Tab #" << i << " doesn't contain an embedded Canvas... skipped." << endl;
    2853             continue;
    2854         }
    2855 
    2856         SetStatusLine2(MString::Format("Tab #%d", i));
    2857 
    2858         //
    2859         // Clone canvas and change background color and schedule for
    2860         // deletion
    2861         //
    2862         TCanvas *n = (TCanvas*)c->Clone();
    2863         CanvasSetFillColor(*n, kWhite);
    2864 
    2865         //
    2866         // Paint canvas into root file
    2867         //
    2868         TString writename = name;
    2869         if (num<0)
    2870         {
    2871             TString numname = "-";
    2872             numname += i;
    2873             writename.Insert(name.Last('.'), numname);
    2874         }
    2875         if (num<0)
    2876             *fLog << inf << " - ";
    2877         *fLog << inf << "Writing Tab #" << i << " to " << writename << ": " << c->GetName() << " (" << n << ") ";
    2878         if (num>0)
    2879             *fLog << "to " << name;
    2880         *fLog << "..." << flush;
    2881 
    2882         n->SaveSource(writename, "");
    2883         delete n;
    2884 
    2885         if (num<0)
    2886             *fLog << "done." << endl;
    2887     }
    2888 
    2889     if (padsav)
    2890         padsav->cd();
    2891 
    2892     *fLog << inf << "done." << endl;
    2893 
    2894     SetStatusLine2("Done.");
    2895 
    2896     return page-1;
    2897 }
    2898 
    2899 // --------------------------------------------------------------------------
    2900 //
    2901 // In case of num<0 all tabs are written into the PS file. If num>0
    2902 // the canvas in the corresponding tab is written to the file.
    2903 // Name is the name of the file (with or without extension).
    2904 //
    2905 // Returns the number of keys written.
    2906 //
    2907 // To write all tabs you can also use SaveAsPS(name)
    2908 //
    2909 Int_t MStatusDisplay::SaveAsRoot(Int_t num, TString name)
    2910 {
    2911     SetStatusLine1("Writing root file...");
    2912     SetStatusLine2("");
    2913 
    2914     if (!CheckTabForCanvas(num))
    2915     {
    2916         SetStatusLine2("Failed!");
    2917         return 0;
    2918     }
    2919 
    2920     AddExtension(name, "root", num);
    2921 
    2922     TFile *fsave = gFile;
    2923     TFile file(name, "RECREATE", "MARS - Status Window Contents", 9);
    2924     const Int_t keys = Write(num);
    2925     gFile = fsave;
    2926 
    2927     SetStatusLine2("Done.");
    2928 
    2929     return keys;
    2930 }
    2931 
     2970    return kTRUE;
     2971}
     2972
     2973// --------------------------------------------------------------------------
     2974//
    29322975void MStatusDisplay::SaveAs(const char *c, const Option_t *o) const
    29332976{
     
    29462989Int_t MStatusDisplay::SaveAs(Int_t num, TString name)
    29472990{
    2948     if (name.EndsWith(".root")) return SaveAsRoot(num, name);
    2949     if (name.EndsWith(".ps"))   return SaveAsPS(num, name);
    2950     if (name.EndsWith(".pdf"))  return SaveAsPDF(num, name);
    2951     if (name.EndsWith(".svg"))  return SaveAsSVG(num, name);
    2952     if (name.EndsWith(".gif"))  return SaveAsGIF(num, name);
    2953     if (name.EndsWith(".png"))  return SaveAsPNG(num, name);
    2954     if (name.EndsWith(".bmp"))  return SaveAsBMP(num, name);
    2955     if (name.EndsWith(".xml"))  return SaveAsXML(num, name);
    2956     if (name.EndsWith(".jpg"))  return SaveAsJPG(num, name);
    2957     if (name.EndsWith(".xpm"))  return SaveAsXPM(num, name);
    2958     if (name.EndsWith(".C"))    return SaveAsC(num, name);
     2991    if (name.EndsWith(".root")) return SaveAsRoot(num, name); // kFileSaveAsRoot
     2992    if (name.EndsWith(".ps"))   return SaveAsPS(num, name);   // kFileSaveAsPS
     2993    if (name.EndsWith(".pdf"))  return SaveAsPDF(num, name);  // kFileSaveAsPDF
     2994    if (name.EndsWith(".svg"))  return SaveAsSVG(num, name);  // kFileSaveAsSVG
     2995    if (name.EndsWith(".gif"))  return SaveAsGIF(num, name);  // kFileSaveAsGIF
     2996    if (name.EndsWith(".png"))  return SaveAsPNG(num, name);  // kFileSaveAsPNG
     2997    if (name.EndsWith(".bmp"))  return SaveAsBMP(num, name);  // kFileSaveAsBMP
     2998    if (name.EndsWith(".xml"))  return SaveAsXML(num, name);  // kFileSaveAsXML
     2999    if (name.EndsWith(".jpg"))  return SaveAsJPG(num, name);  // kFileSaveAsJPG
     3000    if (name.EndsWith(".xpm"))  return SaveAsXPM(num, name);  // kFileSaveAsXPM
     3001    if (name.EndsWith(".csv"))  return SaveAsCSV(num, name);  // kFileSaveAsCSV
     3002    if (name.EndsWith(".tiff")) return SaveAsTIFF(num, name); // kFileSaveAsTIFF
     3003    if (name.EndsWith(".C"))    return SaveAsC(num, name);    // kFileSaveAsC
    29593004    return -1;
    29603005}
     
    29783023        "Bmp files",    "*.bmp",
    29793024        "Xml files",    "*.xml",
     3025        "Tiff files",   "*.tiff",
     3026        "Csv files",    "*.csv",
    29803027        "Macro files",  "*.C",
    29813028        "ROOT files",   "*.root",
  • trunk/MagicSoft/Mars/mbase/MStatusDisplay.h

    r8926 r8962  
    2020class MLog;
    2121class MGList;
     22class MStatusArray;
    2223class MParContainer;
    2324
     
    4647        kFileSaveAsPS, kFileSaveAsPDF, kFileSaveAsSVG, kFileSaveAsRoot,
    4748        kFileSaveAsPNG, kFileSaveAsGIF, kFileSaveAsJPG, kFileSaveAsXPM,
    48         kFileSaveAsBMP, /*kFileSaveAsXCF, kFileSaveAsTIFF,*/
     49        kFileSaveAsBMP, kFileSaveAsCSV, kFileSaveAsTIFF,
    4950        kFileSaveAsXML, kFileSaveAsC, kFilePrint, kFilePrinterName,
    5051        kFileClose, kFileExit, kFileReset,
     
    5455        kTabSave, kTabSaveAs, kTabSaveAsPS, kTabSaveAsPDF, kTabSaveAsSVG,
    5556        kTabSaveAsRoot, kTabSaveAsPNG, kTabSaveAsGIF, kTabSaveAsJPG,
    56         kTabSaveAsXPM, kTabSaveAsBMP, /*kTabSaveAsXCF, kTabSaveAsTIFF,*/
     57        kTabSaveAsXPM, kTabSaveAsBMP, kTabSaveAsCSV, kTabSaveAsTIFF,
    5758        kTabSaveAsXML, kTabSaveAsC,
    5859        kTabPrint, kTabNext, kTabPrevious, kTabRemove,
     
    110111    TList *fBatch;          //!
    111112
     113    // GUI setup
    112114    void AddMenuBar();
    113115    void AddUserFrame();
     
    118120    void AddLogTab();
    119121
     122    // GUI event handling
    120123    Bool_t ProcessMessageCommandMenu(Long_t mp1);
    121124    Bool_t ProcessMessageCommand(Long_t submsg, Long_t mp1, Long_t mp2);
     
    125128    void   CloseWindow();
    126129    Bool_t HandleConfigureNotify(Event_t *);
    127     Bool_t HandleEvent(Event_t *event);
    128 
     130
     131    // Access to the tabs
    129132    TGCompositeFrame *GetTabContainer(const char *name) const;
    130133    TGTabElement     *GetTabTab(const char *name) const;
    131134
     135    // Display update
    132136    Bool_t HandleTimer(TTimer *timer=NULL);
    133137    void UpdateTab(TGCompositeFrame *f);
    134138    void UpdateMemory() const;
    135139
    136     void DrawClonePad(TCanvas &newc, TCanvas &oldc) const;
    137     void CanvasSetFillColor(TPad &c, Int_t col) const;
    138     Bool_t Display(const TObjArray &list, const char *tab=0);
    139 
    140     const TString &AddExtension(TString &name, const TString &ext, Int_t num=-1) const;
    141 
    142     void UpdatePSHeader(const TString &name) const;
    143 
     140    // Display helper functions
    144141    void RemoveTab(int i);
    145142    void SetStatusLine(const char *txt, Int_t idx);
     143
     144    // Drawing helper
     145    void DrawClonePad(TCanvas &newc, TCanvas &oldc) const;
     146    void GetCanvasRange(Int_t &from, Int_t &to, Int_t num=-1) const;
     147
     148    // MStatusArray interface
     149    Bool_t Display(const TObjArray &list, const char *tab=0);
     150    void FillArray(MStatusArray &list, Int_t num=-1) const;
     151
     152    // I/O helper function
     153    const TString &AddExtension(TString &name, const TString &ext, Int_t num=-1) const;
     154
     155    TCanvas *InitWriteTab(Int_t num, TString &name);
     156    TCanvas *InitWriteTab(Int_t num) { TString s; return InitWriteTab(num, s); }
     157    Int_t    InitWriteDisplay(Int_t num, TString &name, const TString &ext);
     158
     159    void UpdatePSHeader(const TString &name) const;
    146160
    147161    Bool_t SaveAsImage(Int_t num, TString name, TImage::EImageFileTypes type);
     
    152166    TString PrintDialog(TString &p, TString &c, TString &t, const char *ext=0);
    153167
    154     void GetCanvasRange(Int_t &from, Int_t &to, Int_t num=-1) const;
    155 
    156168public:
    157169     MStatusDisplay(Int_t w=-1, Int_t h=-1, Long_t t=1000);
    158170     virtual ~MStatusDisplay();
    159171
    160      void SetLogStream(MLog *log, Bool_t enable=kFALSE);
    161 
    162      void StartUpdate(Int_t millisec=-1);
    163      void StopUpdate();
    164      void SetUpdateTime(Long_t t);
    165 
    166      void SetProgressBarPosition(Float_t p, Bool_t upd=kFALSE);
    167      TGProgressBar *GetBar() const { return (TGProgressBar*)fBar; }
    168 
    169      void SetStatusLine1(const char *txt) { SetStatusLine(txt, 0); }
    170      void SetStatusLine2(const char *txt) { SetStatusLine(txt, 1); }
    171      void SetStatusLine2(const MParContainer &cont);
    172 
     172     // Name and title handling
    173173     virtual void SetName(const char *name) { fName = name; }
    174174     virtual void SetTitle(const char *title="") { fTitle = title; }
     
    176176     virtual const char *GetTitle() const { return fTitle.Data(); }
    177177
    178      TCanvas &AddTab(const char *name);
    179      TGCompositeFrame *AddRawTab(const char *name);
    180 
     178     // Getter / display access
    181179     Bool_t   HasCanvas(const TCanvas *c) const;
    182180     TCanvas *GetCanvas(int i) const;
     
    184182     TVirtualPad *GetFullPad(const Int_t canvas, const Int_t pad);
    185183
    186      Int_t Write(Int_t num, const char *name="MStatusDisplay", Int_t option=0, Int_t bufsize=0) const;
    187 
    188      Int_t Read(const char *name, const char *tab);
    189      Int_t Read(const char *name="MStatusDisplay")
    190      {
    191          return Read(name, 0);
    192      }
    193      Int_t Write(const char *name="MStatusDisplay", Int_t option=0, Int_t bufsize=0)
    194      {
    195          return Write(-1, name, option, bufsize);
    196      }
    197      Int_t Write(const char *name="MStatusDisplay", Int_t option=0, Int_t bufsize=0) const
    198      {
    199          return Write(-1, name, option, bufsize);
    200      }
    201 
    202184     Bool_t CdCanvas(const TString &name);
    203      void   Update() { HandleTimer(&fTimer); HandleTimer(&fLogTimer); }
    204 
    205      void DrawClonePad(const char *tab, TCanvas &oldc)
    206      {
    207          DrawClonePad(AddTab(tab), oldc);
    208      }
    209 
     185     Bool_t CheckTabForCanvas(int num) const;
     186
     187     TObject *FindObjectInCanvas(const char *obj, const char *base, const char *canv) const;
     188     TObject *FindObjectInCanvas(const char *obj, const char *canv) const { return FindObjectInCanvas(obj, obj, canv); }
     189     TObject *FindObject(const char *obj, const char *base) const { return FindObjectInCanvas(obj, base, 0); }
     190     TObject *FindObject(const char *obj) const { return FindObjectInCanvas(obj, obj, 0); }
     191     TObject *FindObject(const TObject *o) const { return 0;  }
     192
     193     void PrintContent(Option_t *o="") const;
     194
     195     // Display Manipulation
     196     TCanvas &AddTab(const char *name, const char *title=0);
     197     TGCompositeFrame *AddRawTab(const char *name);
     198
     199     void SetProgressBarPosition(Float_t p, Bool_t upd=kFALSE);
     200     TGProgressBar *GetBar() const { return (TGProgressBar*)fBar; }
     201
     202     void SetStatusLine1(const char *txt) { SetStatusLine(txt, 0); }
     203     void SetStatusLine2(const char *txt) { SetStatusLine(txt, 1); }
     204     void SetStatusLine2(const MParContainer &cont);
     205
     206     void Reset();
    210207     void SetNoContextMenu(Bool_t flag=kTRUE);
    211208
     209     // Update handling
     210     void StartUpdate(Int_t millisec=-1);
     211     void StopUpdate();
     212     void SetUpdateTime(Long_t t);
     213
     214     void Update() { HandleTimer(&fTimer); HandleTimer(&fLogTimer); }
     215
     216     // Log stream interface
     217     void SetLogStream(MLog *log, Bool_t enable=kFALSE);
     218
     219     // Size options
     220     void SetCanvasWidth(UInt_t w);
     221     void SetCanvasHeight(UInt_t h);
     222
     223     void SetDisplayWidth(UInt_t w);
     224     void SetDisplayHeight(UInt_t h);
     225
     226     void SetOptimumSize();
     227     void SetDisplaySize(UInt_t w, UInt_t h);
     228
     229     // Graphics output
    212230     Int_t  SaveAsPS(TString name="",  const TString addon="") { return SaveAsVGF(-1, name, addon, "ps"); }
    213231     Int_t  SaveAsPDF(TString name="", const TString addon="") { return SaveAsVGF(-1, name, addon, "pdf"); }
     
    217235     Bool_t SaveAsXPM(TString name="")  { return SaveAsXPM(-1, name); }
    218236     Bool_t SaveAsJPG(TString name="")  { return SaveAsJPG(-1, name); }
    219      //Bool_t SaveAsTIFF(TString name="") { return SaveAsTIFF(-1, name); }
    220      //Bool_t SaveAsXCF(TString name="")  { return SaveAsXCF(-1, name); }
     237     Bool_t SaveAsTIFF(TString name="") { return SaveAsTIFF(-1, name); }
    221238     Bool_t SaveAsBMP(TString name="")  { return SaveAsBMP(-1, name); }
    222239     Bool_t SaveAsXML(TString name="")  { return SaveAsXML(-1, name); }
     
    224241     Int_t  SaveAsRoot(TString name="") { return SaveAsRoot(-1, name); }
    225242     Int_t  SaveAs(TString name)        { return SaveAs(-1, name); }
     243
     244     Bool_t SaveAsCSV(TString name="", Char_t delim='\t') { return SaveAsCSV(-1, name, delim); }
    226245     Int_t  PrintPS() { return PrintPS(-1); }
    227246
     
    235254     Bool_t SaveAsXPM(Int_t num, TString name="")  { return SaveAsImage(num, name, TImage::kXpm); }
    236255     Bool_t SaveAsJPG(Int_t num, TString name="")  { return SaveAsImage(num, name, TImage::kJpeg); }
    237      //Bool_t SaveAsTIFF(Int_t num, TString name="") { return SaveAsImage(num, name, TImage::kTiff); }
    238      //Bool_t SaveAsXCF(Int_t num, TString name="")  { return SaveAsImage(num, name, TImage::kXcf); }
     256     Bool_t SaveAsTIFF(Int_t num, TString name="") { return SaveAsImage(num, name, TImage::kTiff); }
    239257     Bool_t SaveAsBMP(Int_t num, TString name="")  { return SaveAsImage(num, name, TImage::kBmp); }
    240258     Bool_t SaveAsXML(Int_t num, TString name="")  { return SaveAsImage(num, name, TImage::kXml); }
     
    242260     Int_t  SaveAsRoot(Int_t num, TString name="");
    243261     Int_t  SaveAs(Int_t num, TString name);
     262
     263     Bool_t SaveAsCSV(Int_t num, TString name="", Char_t delim='\t');
    244264     Int_t  PrintPS(Int_t num, const char *p=0, const char *cmd=0, const char *tmp=0);
    245265     Bool_t PrintLog(const char *p=0, const char *c=0);
     266
    246267     Bool_t SaveLogAsPS(const char *name) const;
    247268
    248      // Size options
    249      void SetCanvasWidth(UInt_t w);
    250      void SetCanvasHeight(UInt_t h);
    251 
    252      void SetDisplayWidth(UInt_t w);
    253      void SetDisplayHeight(UInt_t h);
    254 
    255      void SetOptimumSize();
    256      void SetDisplaySize(UInt_t w, UInt_t h);
    257 
     269     // I/O
    258270     Int_t  SaveAs(Int_t num=-1);
    259271     Int_t  Open(TString fname, const char *name="MStatusDisplay");
    260272     Int_t  Open();
    261273
     274     // Root I/O
     275     Int_t Write(Int_t num, const char *name="MStatusDisplay", Int_t option=0, Int_t bufsize=0) const;
     276
     277     Int_t Read(const char *name, const char *tab);
     278     Int_t Read(const char *name="MStatusDisplay") { return Read(name, 0); }
     279     Int_t Write(const char *name="MStatusDisplay", Int_t option=0, Int_t bufsize=0) { return Write(-1, name, option, bufsize); }
     280     Int_t Write(const char *name="MStatusDisplay", Int_t option=0, Int_t bufsize=0) const { return Write(-1, name, option, bufsize); }
     281
     282     // Eventloop interface
    262283     Status_t CheckStatus() const { return fStatus; }
    263284     void ClearStatus() { fStatus = kLoopNone; }
     
    266287     void UnLock() { if (fIsLocked>0) fIsLocked--; }
    267288
    268      void Reset();
    269 
    270      Bool_t CheckTabForCanvas(int num) const;
    271 
     289     // GUI event handling
    272290     void EventInfo(Int_t event, Int_t px, Int_t py, TObject *selected);
     291     Bool_t HandleEvent(Event_t *event);
    273292
    274293     // Public helper functions
  • trunk/MagicSoft/Mars/showplot.cc

    r8961 r8962  
    7575    gLog << " Only the last size option given is taken into account." << endl;
    7676    gLog << " Width or height is set according to height or width." << endl << endl;
    77     gLog << " In batch mode display width and height and auto-size is ignored." << endl;
     77    gLog << " In batch mode display width and height and auto-size is ignored." << endl << endl;
     78    gLog << " If multiple files are written (e.g. a while display is written as png-files)" << endl;
     79    gLog << " you can use %%name%% and %%tab%% in the name, which is then replaced by" << endl;
     80    gLog << " the tab-name or tab.number respectively. If none of them are given a" << endl;
     81    gLog << " minus and the tab.number is added in front of the extension." << endl << endl;
    7882    gLog << "Printing:" << endl;
    7983    gLog << " For more details see MStatusDisplay::PrintPS" << endl << endl;
Note: See TracChangeset for help on using the changeset viewer.