TPaveText.cxx

Go to the documentation of this file.
00001 // @(#)root/graf:$Id: TPaveText.cxx 36735 2010-11-18 09:33:53Z couet $
00002 // Author: Rene Brun   20/10/95
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #include <string.h>
00013 #include <stdlib.h>
00014 #include <stdio.h>
00015 
00016 #include "Riostream.h"
00017 #include "TBufferFile.h"
00018 #include "TROOT.h"
00019 #include "TStyle.h"
00020 #include "TPaveText.h"
00021 #include "TPaveLabel.h"
00022 #include "TVirtualPad.h"
00023 #include "TMath.h"
00024 #include "TLatex.h"
00025 #include "TError.h"
00026 #include "TColor.h"
00027 #include "TClass.h"
00028 
00029 ClassImp(TPaveText)
00030 
00031 
00032 //______________________________________________________________________________
00033 //  A PaveText is a Pave (see TPave) with text,lines or/and boxes.
00034 //Begin_Html
00035 /*
00036 <img src="gif/pavetext.gif">
00037 */
00038 //End_Html
00039 //
00040 
00041 
00042 //______________________________________________________________________________
00043 TPaveText::TPaveText(): TPave(), TAttText()
00044 {
00045    // pavetext default constructor.
00046 
00047    fLines   = 0;
00048    fMargin  = 0.05;
00049    fLongest = 0;
00050 }
00051 
00052 
00053 //______________________________________________________________________________
00054 TPaveText::TPaveText(Double_t x1, Double_t y1,Double_t x2, Double_t  y2, Option_t *option)
00055            :TPave(x1,y1,x2,y2,4,option), TAttText(22,0,gStyle->GetTextColor(),gStyle->GetTextFont(),0)
00056 {
00057    // pavetext normal constructor.
00058    //
00059    // a PaveText is a Pave with several lines of text
00060    // The Pave is by default defined bith bordersize=5 and option ="br".
00061    //  option = "T" Top frame
00062    //  option = "B" Bottom frame
00063    //  option = "R" Right frame
00064    //  option = "L" Left frame
00065    //  option = "NDC" x1,y1,x2,y2 are given in NDC
00066    //  option = "ARC" corners are rounded
00067    //
00068    // The individual text items are entered via AddText
00069    // By default, text items inherits from the default pavetext AttText.
00070    // A title can be added later to this pavetext via TPaveText::SetLabel.
00071    //
00072    //  IMPORTANT NOTE:
00073    //  Because TPave objects (and objects deriving from TPave) have their
00074    //  master coordinate system in NDC, one cannot use the TBox functions
00075    //  SetX1,SetY1,SetX2,SetY2 to change the corner coordinates. One should use
00076    //  instead SetX1NDC, SetY1NDC, SetX2NDC, SetY2NDC.
00077 
00078    fLines   = new TList;
00079    fMargin  = 0.05;
00080    fLongest = 0;
00081 }
00082 
00083 
00084 //______________________________________________________________________________
00085 TPaveText::~TPaveText()
00086 {
00087    // pavetext default destructor.
00088 
00089    if (!TestBit(kNotDeleted)) return;
00090    if (fLines) fLines->Delete();
00091    delete fLines;
00092    fLines = 0;
00093 }
00094 
00095 
00096 //______________________________________________________________________________
00097 TPaveText::TPaveText(const TPaveText &pavetext) : TPave(), TAttText()
00098 {
00099    // pavetext copy constructor.
00100 
00101    TBufferFile b(TBuffer::kWrite);
00102    TPaveText *p = (TPaveText*)(&pavetext);
00103    p->Streamer(b);
00104    b.SetReadMode();
00105    b.SetBufferOffset(0);
00106    fLines = 0;
00107    Streamer(b);
00108 }
00109 
00110 //______________________________________________________________________________
00111 TPaveText& TPaveText::operator=(const TPaveText& pt)
00112 {
00113    //assignment operator
00114    if(this!=&pt) {
00115       TPave::operator=(pt);
00116       TAttText::operator=(pt);
00117       fLabel=pt.fLabel;
00118       fLongest=pt.fLongest;
00119       fMargin=pt.fMargin;
00120       fLines=pt.fLines;
00121    }
00122    return *this;
00123 }
00124 
00125 //______________________________________________________________________________
00126 TBox *TPaveText::AddBox(Double_t x1, Double_t y1, Double_t x2, Double_t y2)
00127 {
00128    // Add a new graphics box to this pavetext.
00129 
00130    if (!gPad->IsEditable()) return 0;
00131    TBox *newbox = new TBox(x1,y1,x2,y2);
00132 
00133    if (!fLines) fLines = new TList;
00134    fLines->Add(newbox);
00135    return newbox;
00136 }
00137 
00138 
00139 //______________________________________________________________________________
00140 TLine *TPaveText::AddLine(Double_t x1, Double_t y1, Double_t x2, Double_t y2)
00141 {
00142    // Add a new graphics line to this pavetext.
00143 
00144    if (!gPad->IsEditable()) return 0;
00145    TLine *newline = new TLine(x1,y1,x2,y2);
00146 
00147    if (!fLines) fLines = new TList;
00148    fLines->Add(newline);
00149    return newline;
00150 }
00151 
00152 
00153 //______________________________________________________________________________
00154 TText *TPaveText::AddText(Double_t x1, Double_t y1, const char *text)
00155 {
00156    // Add a new Text line to this pavetext at given coordinates.
00157 
00158    TLatex *newtext = new TLatex(x1,y1,text);
00159    newtext->SetTextAlign(0);
00160    newtext->SetTextColor(0);
00161    newtext->SetTextFont(0);
00162    newtext->SetTextSize(0);
00163    Int_t nch = strlen(text);
00164    if (nch > fLongest) fLongest = nch;
00165 
00166    if (!fLines) fLines = new TList;
00167    fLines->Add(newtext);
00168    return newtext;
00169 }
00170 
00171 
00172 //______________________________________________________________________________
00173 TText *TPaveText::AddText(const char *text)
00174 {
00175    // Add a new Text line to this pavetext.
00176 
00177    return AddText(0,0,text);
00178 }
00179 
00180 
00181 //______________________________________________________________________________
00182 void TPaveText::Clear(Option_t *)
00183 {
00184    // Clear all lines in this pavetext.
00185 
00186    if (!fLines) return;
00187    fLines->Delete();
00188    fLongest = 0;
00189 }
00190 
00191 
00192 //______________________________________________________________________________
00193 void TPaveText::DeleteText()
00194 {
00195    // Delete text at the mouse position.
00196 
00197    if (!gPad->IsEditable()) return;
00198    if (!fLines) return;
00199    Double_t ymouse, yobj;
00200    TObject *obj = GetObject(ymouse, yobj);             //get object pointed by the mouse
00201    if (!obj) return;
00202    if (!obj->InheritsFrom(TText::Class())) return;
00203    fLines->Remove(obj);
00204    delete obj;
00205 }
00206 
00207 
00208 //______________________________________________________________________________
00209 void TPaveText::Draw(Option_t *option)
00210 {
00211    // Draw this pavetext with its current attributes.
00212 
00213    AppendPad(option);
00214 }
00215 
00216 
00217 //______________________________________________________________________________
00218 void TPaveText::DrawFile(const char *filename, Option_t *option)
00219 {
00220    // Draw lines in filename in this pavetext.
00221 
00222    ReadFile(filename);
00223 
00224    AppendPad(option);
00225 }
00226 
00227 
00228 //______________________________________________________________________________
00229 void TPaveText::EditText()
00230 {
00231    // Edit text at the mouse position.
00232 
00233    if (!gPad->IsEditable()) return;
00234    Double_t ymouse, yobj;
00235    TObject *obj = GetObject(ymouse, yobj);             //get object pointed by the mouse
00236    if (!obj) return;
00237    if (!obj->InheritsFrom(TText::Class())) return;
00238    TText *text = (TText*)obj;
00239    gROOT->SetSelectedPrimitive(text);
00240    gROOT->ProcessLine(Form("((TCanvas*)0x%lx)->SetSelected((TObject*)0x%lx)",
00241                            (ULong_t)gPad->GetCanvas(), (ULong_t)text));
00242    gROOT->ProcessLine(Form("((TCanvas*)0x%lx)->Selected((TVirtualPad*)0x%lx,(TObject*)0x%lx,1)",
00243                            (ULong_t)gPad->GetCanvas(), (ULong_t)gPad, (ULong_t)text));
00244    text->SetTextAttributes();
00245 }
00246 
00247 
00248 //______________________________________________________________________________
00249 TText *TPaveText::GetLine(Int_t number) const
00250 {
00251    // Get Pointer to line number in this pavetext.
00252 
00253    TText *line;
00254    TIter next(fLines);
00255    Int_t nlines = 0;
00256    while ((line = (TText*) next())) {
00257       if (nlines == number) return line;
00258       nlines++;
00259    }
00260    return 0;
00261 }
00262 
00263 
00264 //______________________________________________________________________________
00265 TText *TPaveText::GetLineWith(const char *text) const
00266 {
00267    // Get Pointer to first containing string text in this pavetext.
00268 
00269    TText *line;
00270    TIter next(fLines);
00271    while ((line = (TText*) next())) {
00272       if (strstr(line->GetTitle(),text)) return line;
00273    }
00274    return 0;
00275 }
00276 
00277 
00278 //______________________________________________________________________________
00279 TObject *TPaveText::GetObject(Double_t &ymouse, Double_t &yobj) const
00280 {
00281    // Get object pointed by the mouse in this pavetext.
00282 
00283    if (!fLines) return 0;
00284    Int_t nlines = GetSize();
00285    if (nlines == 0) return 0;
00286 
00287    // Evaluate text size as a function of the number of lines
00288 
00289    ymouse   = gPad->AbsPixeltoY(gPad->GetEventY());
00290    Double_t yspace   = (fY2 - fY1)/Double_t(nlines);
00291    Double_t textsize = GetTextSize();
00292    Double_t y1,y,dy;
00293    if (textsize == 0)  {
00294       y1       = gPad->GetY1();
00295    }
00296    Double_t ytext = fY2 + 0.5*yspace;
00297    Int_t valign;
00298 
00299    // Iterate over all lines
00300    // Copy pavetext attributes to line attributes if line attributes not set
00301    dy = fY2 - fY1;
00302    TObject *line;
00303    TText *linet;
00304    TLine *linel;
00305    TBox  *lineb;
00306    TIter next(fLines);
00307    while ((line = (TObject*) next())) {
00308    // Next primitive is a line
00309       if (line->IsA() == TLine::Class()) {
00310          linel = (TLine*)line;
00311          y1 = linel->GetY1();   if (y1 == 0) y1 = ytext; else y1 = fY1 + y1*dy;
00312          if (TMath::Abs(y1-ymouse) < 0.2*yspace) {yobj = y1; return line;}
00313          continue;
00314       }
00315    // Next primitive is a box
00316       if (line->IsA() == TBox::Class()) {
00317          lineb = (TBox*)line;
00318          y1 = lineb->GetY1();   if (y1 == 0) y1 = ytext; else y1 = fY1 + y1*dy;
00319          if (TMath::Abs(y1-ymouse) < 0.4*yspace) {yobj = y1; return line;}
00320          continue;
00321       }
00322    // Next primitive is a text
00323       if (line->InheritsFrom(TText::Class())) {
00324          linet = (TText*)line;
00325          ytext -= yspace;
00326          Double_t yl     = linet->GetY();
00327          Short_t talign = linet->GetTextAlign();
00328          if (talign == 0) talign = GetTextAlign();
00329          if (yl > 0 && yl <1) {
00330             ytext = fY1 + yl*dy;
00331          }
00332          valign = linet->GetTextAlign()%10;
00333          y = ytext;
00334          if (valign == 1) y = ytext -0.5*yspace;
00335          if (valign == 3) y = ytext +0.5*yspace;
00336 
00337          if (TMath::Abs(y-ymouse) < 0.5*yspace) {yobj = y; return line;}
00338       }
00339    }
00340    return 0;
00341 }
00342 
00343 
00344 //______________________________________________________________________________
00345 Int_t TPaveText::GetSize() const
00346 {
00347    //  return number of text lines (ignoring Tlines, etc)
00348 
00349    Int_t nlines = 0;
00350    TIter next(fLines);
00351    TObject *line;
00352    while ((line = (TObject*) next())) {
00353       if (line->InheritsFrom(TText::Class())) nlines++;
00354    }
00355    return nlines;
00356 }
00357 
00358 
00359 //______________________________________________________________________________
00360 void TPaveText::InsertLine()
00361 {
00362    // Add a new lineine at the mouse position.
00363 
00364    if (!gPad->IsEditable()) return;
00365    Double_t ymouse, yobj;
00366    TObject *obj = GetObject(ymouse, yobj); //get object pointed by the mouse
00367    Double_t yline = (ymouse-fY1)/(fY2-fY1);
00368    TLine *newline = AddLine(0,yline,0,yline);
00369    if (obj) {
00370       fLines->Remove(newline);        //remove line from last position
00371       if (yobj < ymouse) fLines->AddBefore(obj,newline);
00372       else               fLines->AddAfter(obj,newline);
00373    }
00374 }
00375 
00376 
00377 //______________________________________________________________________________
00378 void TPaveText::InsertText(const char *text)
00379 {
00380    // Add a new Text line at the mouse position.
00381 
00382    if (!gPad->IsEditable()) return;
00383    Double_t ymouse, yobj;
00384    TObject *obj = GetObject(ymouse, yobj); //get object pointed by the mouse
00385    TText *newtext = AddText(0,0,text);     //create new text object
00386    if (obj) {
00387       fLines->Remove(newtext);        //remove text from last position
00388       if (yobj < ymouse) fLines->AddBefore(obj,newtext); //insert new text at right position
00389       else               fLines->AddAfter(obj,newtext);  //insert new text at right position
00390    }
00391 }
00392 
00393 
00394 //______________________________________________________________________________
00395 void TPaveText::Paint(Option_t *option)
00396 {
00397    // Paint this pavetext with its current attributes.
00398 
00399    // Draw the pave
00400    TPave::ConvertNDCtoPad();
00401    TPave::PaintPave(fX1,fY1,fX2,fY2,GetBorderSize(),option);
00402    PaintPrimitives(kPaveText);
00403 }
00404 
00405 
00406 //______________________________________________________________________________
00407 void TPaveText::PaintPrimitives(Int_t mode)
00408 {
00409    // Paint list of primitives in this pavetext.
00410 
00411    if (!fLines) return;
00412    Double_t dx = fX2 - fX1;
00413    Double_t dy = fY2 - fY1;
00414    Double_t textsize = GetTextSize();
00415    Int_t nlines = GetSize();
00416    if (nlines == 0) nlines = 5;
00417 
00418    // Evaluate text size as a function of the number of lines
00419 
00420    Double_t x1,y1,x2,y2;
00421    y1       = gPad->GetY1();
00422    y2       = gPad->GetY2();
00423    Float_t margin  = fMargin*dx;
00424    Double_t yspace = dy/Double_t(nlines);
00425    Double_t textsave = textsize;
00426    TObject *line;
00427    TText *linet;
00428    TLatex *latex;
00429    TIter next(fLines);
00430    Double_t longest = 0;
00431    Double_t w;
00432    if (textsize == 0)  {
00433       textsize = 0.85*yspace/(y2 - y1);
00434       while ((line = (TObject*) next())) {
00435          if (line->IsA() == TLatex::Class()) {
00436             latex = (TLatex*)line;
00437             Float_t tangle = latex->GetTextAngle();
00438             if (latex->GetTextSize() != 0) continue;
00439             Style_t tfont = latex->GetTextFont();
00440             if (tfont == 0) latex->SetTextFont(GetTextFont());
00441             latex->SetTextSize(textsize);
00442             w = latex->GetXsize();
00443             latex->SetTextSize(0);
00444             latex->SetTextAngle(tangle); //text angle was redefined in GetXsize !
00445             if (w > longest) longest = w;
00446             latex->SetTextFont(tfont);
00447          }
00448       }
00449       if (longest > 0.92*dx) textsize *= 0.92*dx/longest;
00450       if (mode == kDiamond) textsize *= 0.66;
00451       SetTextSize(textsize);
00452    }
00453    Double_t yfont;
00454    if (GetTextFont()%10 > 2)
00455       yfont = (gPad->PixeltoY(Int_t(-textsize))-gPad->PixeltoY(0))/(y2-y1)*dy;
00456    else
00457       yfont = textsize*dy;
00458    Double_t ytext = fY2 + 0.5*yspace;
00459    Double_t xtext = 0;
00460    Int_t halign;
00461 
00462    // Iterate over all lines
00463    // Copy pavetext attributes to line attributes if line attributes not set
00464    TLine *linel;
00465    TBox  *lineb;
00466    next.Reset();
00467    while ((line = (TObject*) next())) {
00468    // Next primitive is a line
00469       if (line->IsA() == TLine::Class()) {
00470          linel = (TLine*)line;
00471          x1 = linel->GetX1();   if (x1 == 0) x1 = fX1; else x1 = fX1 + x1*dx;
00472          x2 = linel->GetX2();   if (x2 == 0) x2 = fX2; else x2 = fX1 + x2*dx;
00473          y1 = linel->GetY1();   if (y1 == 0) y1 = ytext; else y1 = fY1 + y1*dy;
00474          y2 = linel->GetY2();   if (y2 == 0) y2 = ytext; else y2 = fY1 + y2*dy;
00475          linel->PaintLine(x1,y1,x2,y2);
00476          continue;
00477       }
00478    // Next primitive is a box
00479       if (line->IsA() == TBox::Class()) {
00480          lineb = (TBox*)line;
00481          x1 = lineb->GetX1();
00482          if (x1) x1 = fX1 + x1*dx;
00483          else    x1 = fX1 + gPad->PixeltoX(1) - gPad->PixeltoX(0);
00484          x2 = lineb->GetX2();
00485          if (x2) x2 = fX1 + x2*dx;
00486          else    x2 = fX2;
00487          y1 = lineb->GetY1();   if (y1 == 0) y1 = ytext; else y1 = fY1 + y1*dy;
00488          y2 = lineb->GetY2();   if (y2 == 0) y2 = ytext; else y2 = fY1 + y2*dy;
00489          lineb->PaintBox(x1,y1,x2,y2);
00490          continue;
00491       }
00492    // Next primitive is a text
00493       if (line->IsA() == TText::Class()) {
00494          linet = (TText*)line;
00495          ytext -= yspace;
00496          Double_t xl    = linet->GetX();
00497          Double_t yl    = linet->GetY();
00498          Short_t talign = linet->GetTextAlign();
00499          Color_t tcolor = linet->GetTextColor();
00500          Style_t tfont  = linet->GetTextFont();
00501          Size_t  tsize  = linet->GetTextSize();
00502          if (talign == 0) linet->SetTextAlign(GetTextAlign());
00503          if (tcolor == 0) linet->SetTextColor(GetTextColor());
00504          if (tfont  == 0) linet->SetTextFont(GetTextFont());
00505          if (tsize  == 0) linet->SetTextSize(GetTextSize());
00506          if (xl > 0 && xl <1) {
00507             xtext = fX1 + xl*dx;
00508          } else {
00509             halign = linet->GetTextAlign()/10;
00510             if (halign == 1) xtext = fX1 + margin;
00511             if (halign == 2) xtext = 0.5*(fX1+fX2);
00512             if (halign == 3) xtext = fX2 - margin;
00513          }
00514          if (yl > 0 && yl <1) ytext = fY1 + yl*dy;
00515          linet->PaintText(xtext,ytext,linet->GetTitle());
00516          linet->SetTextAlign(talign);
00517          linet->SetTextColor(tcolor);
00518          linet->SetTextFont(tfont);
00519          linet->SetTextSize(tsize);
00520       }
00521    // Next primitive is a Latex text
00522       if (line->IsA() == TLatex::Class()) {
00523          latex = (TLatex*)line;
00524          ytext -= yspace;
00525          Double_t xl    = latex->GetX();
00526          Double_t yl    = latex->GetY();
00527          Short_t talign = latex->GetTextAlign();
00528          Color_t tcolor = latex->GetTextColor();
00529          Style_t tfont  = latex->GetTextFont();
00530          Size_t  tsize  = latex->GetTextSize();
00531          if (talign == 0) latex->SetTextAlign(GetTextAlign());
00532          if (tcolor == 0) latex->SetTextColor(GetTextColor());
00533          if (tfont  == 0) latex->SetTextFont(GetTextFont());
00534          if (tsize  == 0) latex->SetTextSize(GetTextSize());
00535          if (xl > 0 && xl <1) {
00536             xtext = fX1 + xl*dx;
00537          } else {
00538             halign = latex->GetTextAlign()/10;
00539             if (halign == 1) xtext = fX1 + margin;
00540             if (halign == 2) xtext = 0.5*(fX1+fX2);
00541             if (halign == 3) xtext = fX2 - margin;
00542          }
00543          if (yl > 0 && yl <1) ytext = fY1 + yl*dy;
00544          latex->PaintLatex(xtext,ytext,latex->GetTextAngle(),
00545                            latex->GetTextSize(),
00546                            latex->GetTitle());
00547          latex->SetTextAlign(talign);
00548          latex->SetTextColor(tcolor);
00549          latex->SetTextFont(tfont);
00550          latex->SetTextSize(tsize);
00551          latex->SetX(xl);  // PaintLatex modifies fX and fY
00552          latex->SetY(yl);
00553       }
00554    }
00555 
00556    SetTextSize(textsave);
00557 
00558    // if a label create & paint a pavetext title
00559    if (fLabel.Length() > 0) {
00560       dy = gPad->GetY2() - gPad->GetY1();
00561       x1 = fX1 + 0.25*dx;
00562       x2 = fX2 - 0.25*dx;
00563       y1 = fY2 - 0.02*dy;
00564       y2 = fY2 + 0.02*dy;
00565       TPaveLabel *title = new TPaveLabel(x1,y1,x2,y2,fLabel.Data(),GetDrawOption());
00566       title->SetFillColor(GetFillColor());
00567       title->SetTextColor(GetTextColor());
00568       title->SetTextFont(GetTextFont());
00569       title->Paint();
00570       delete title;
00571    }
00572 }
00573 
00574 
00575 //______________________________________________________________________________
00576 void TPaveText::Print(Option_t *option) const
00577 {
00578    // Dump this pavetext with its attributes.
00579 
00580    TPave::Print(option);
00581    if (fLines) fLines->Print();
00582 }
00583 
00584 
00585 //______________________________________________________________________________
00586 void TPaveText::ReadFile(const char *filename, Option_t *option, Int_t nlines, Int_t fromline)
00587 {
00588    // Read lines of filename in this pavetext.
00589    //
00590    //  Read from line number fromline a total of nlines
00591    //
00592    //  Note that this function changes the default text alignment to left/center
00593 
00594    Int_t ival;
00595    Float_t val;
00596    TText *lastline = 0;
00597    TString opt = option;
00598    if (!opt.Contains("+")) {
00599       Clear();
00600       fLongest = 0;
00601    }
00602    SetTextAlign(12);
00603    // Get file name
00604    Int_t nch = strlen(filename);
00605    if (nch == 0) return;
00606 
00607    char *fname = StrDup(filename);
00608    if (fname[nch-1] == ';') { nch--; fname[nch]=0;}
00609 
00610    ifstream file(fname,ios::in);
00611    if (!file.good()) {
00612       Error("ReadFile", "illegal file name");
00613       delete [] fname;
00614       return;
00615    }
00616 
00617    const int linesize = 255;
00618    char currentline[linesize];
00619    char *ss, *sclose, *s= 0;
00620 
00621    Int_t kline = 0;
00622    while (1) {
00623       file.getline(currentline,linesize);
00624       if (file.eof())break;
00625       if (kline >= fromline && kline < fromline+nlines) {
00626          s = currentline;
00627          if (strstr(s,"+SetText")) {
00628             ss = s+8;
00629             sclose = strstr(ss,")");
00630             if (!sclose) continue;
00631             *sclose = 0;
00632             lastline = (TText*)fLines->Last();
00633             if (!lastline) continue;
00634             if (strstr(ss,"Color(")) {
00635                sscanf(ss+6,"%d",&ival);
00636                lastline->SetTextColor(ival);
00637                continue;
00638             }
00639             if (strstr(ss,"Align(")) {
00640                sscanf(ss+6,"%d",&ival);
00641                lastline->SetTextAlign(ival);
00642                continue;
00643             }
00644             if (strstr(ss,"Font(")) {
00645                sscanf(ss+5,"%d",&ival);
00646                lastline->SetTextFont(ival);
00647                continue;
00648             }
00649             if (strstr(ss,"Size(")) {
00650                sscanf(ss+5,"%f",&val);
00651                lastline->SetTextSize(val);
00652                continue;
00653             }
00654             if (strstr(ss,"Angle(")) {
00655                sscanf(ss+6,"%f",&val);
00656                lastline->SetTextAngle(val);
00657                continue;
00658             }
00659          }
00660          AddText(s);
00661       }
00662       kline++;
00663    }
00664    file.close();
00665    delete [] fname;
00666 }
00667 
00668 
00669 //______________________________________________________________________________
00670 void TPaveText::SaveLines(ostream &out, const char *name)
00671 {
00672    // Save lines of this pavetext as C++ statements on output stream out
00673 
00674    if (!fLines) return;
00675    Int_t nlines = GetSize();
00676    if (nlines == 0) return;
00677 
00678    // Iterate over all lines
00679    char quote = '"';
00680    TObject *line;
00681    TText *linet;
00682    TLatex *latex;
00683    TLine *linel;
00684    TBox  *lineb;
00685    TIter next(fLines);
00686    while ((line = (TObject*) next())) {
00687    // Next primitive is a line
00688       if (line->IsA() == TLine::Class()) {
00689          linel = (TLine*)line;
00690          if (gROOT->ClassSaved(TLine::Class())) {
00691             out<<"   ";
00692          } else {
00693             out<<"   TLine *";
00694          }
00695          out<<"line = "<<name<<"->AddLine("
00696             <<linel->GetX1()<<","<<linel->GetY1()<<","<<linel->GetX2()<<","<<linel->GetY2()<<");"<<endl;
00697          if (linel->GetLineColor() != 1) {
00698             if (linel->GetLineColor() > 228) {
00699                TColor::SaveColor(out, linel->GetLineColor());
00700                out<<"   line->SetLineColor(ci);" << endl;
00701             } else
00702                out<<"   line->SetLineColor("<<linel->GetLineColor()<<");"<<endl;
00703          }
00704          if (linel->GetLineStyle() != 1) {
00705             out<<"   line->SetLineStyle("<<linel->GetLineStyle()<<");"<<endl;
00706          }
00707          if (linel->GetLineWidth() != 1) {
00708             out<<"   line->SetLineWidth("<<linel->GetLineWidth()<<");"<<endl;
00709          }
00710          continue;
00711       }
00712    // Next primitive is a box
00713       if (line->IsA() == TBox::Class()) {
00714          lineb = (TBox*)line;
00715          if (gROOT->ClassSaved(TBox::Class())) {
00716             out<<"   ";
00717          } else {
00718             out<<"   TBox *";
00719          }
00720          out<<"box = "<<name<<"->AddBox("
00721             <<lineb->GetX1()<<","<<lineb->GetY1()<<","<<lineb->GetX2()<<","<<lineb->GetY2()<<");"<<endl;
00722          if (lineb->GetFillColor() != 18) {
00723             if (lineb->GetFillColor() > 228) {
00724                TColor::SaveColor(out, lineb->GetFillColor());
00725                out<<"   box->SetFillColor(ci);" << endl;
00726             } else
00727                out<<"   box->SetFillColor("<<lineb->GetFillColor()<<");"<<endl;
00728          }
00729          if (lineb->GetFillStyle() != 1001) {
00730             out<<"   box->SetFillStyle("<<lineb->GetFillStyle()<<");"<<endl;
00731          }
00732          if (lineb->GetLineColor() != 1) {
00733             if (lineb->GetLineColor() > 228) {
00734                TColor::SaveColor(out, lineb->GetLineColor());
00735                out<<"   box->SetLineColor(ci);" << endl;
00736             } else
00737                out<<"   box->SetLineColor("<<lineb->GetLineColor()<<");"<<endl;
00738          }
00739          if (lineb->GetLineStyle() != 1) {
00740             out<<"   box->SetLineStyle("<<lineb->GetLineStyle()<<");"<<endl;
00741          }
00742          if (lineb->GetLineWidth() != 1) {
00743             out<<"   box->SetLineWidth("<<lineb->GetLineWidth()<<");"<<endl;
00744          }
00745          continue;
00746       }
00747    // Next primitive is a text
00748       if (line->IsA() == TText::Class()) {
00749          linet = (TText*)line;
00750          if (gROOT->ClassSaved(TText::Class())) {
00751             out<<"   ";
00752          } else {
00753             out<<"   TText *";
00754          }
00755          if (!linet->GetX() && !linet->GetY()) {
00756             TString s = linet->GetTitle();
00757             s.ReplaceAll("\"","\\\"");
00758             out<<"text = "<<name<<"->AddText("
00759                <<quote<<s.Data()<<quote<<");"<<endl;
00760          } else {
00761             out<<"text = "<<name<<"->AddText("
00762                <<linet->GetX()<<","<<linet->GetY()<<","<<quote<<linet->GetTitle()<<quote<<");"<<endl;
00763          }
00764          if (linet->GetTextColor()) {
00765             if (linet->GetTextColor() > 228) {
00766                TColor::SaveColor(out, linet->GetTextColor());
00767                out<<"   text->SetTextColor(ci);" << endl;
00768             } else
00769                out<<"   text->SetTextColor("<<linet->GetTextColor()<<");"<<endl;
00770          }
00771          if (linet->GetTextFont()) {
00772             out<<"   text->SetTextFont("<<linet->GetTextFont()<<");"<<endl;
00773          }
00774          if (linet->GetTextSize()) {
00775             out<<"   text->SetTextSize("<<linet->GetTextSize()<<");"<<endl;
00776          }
00777          if (linet->GetTextAngle() != GetTextAngle()) {
00778             out<<"   text->SetTextAngle("<<linet->GetTextAngle()<<");"<<endl;
00779          }
00780          if (linet->GetTextAlign()) {
00781             out<<"   text->SetTextAlign("<<linet->GetTextAlign()<<");"<<endl;
00782          }
00783       }
00784    // Next primitive is a Latex text
00785       if (line->IsA() == TLatex::Class()) {
00786          latex = (TLatex*)line;
00787          if (gROOT->ClassSaved(TLatex::Class())) {
00788             out<<"   ";
00789          } else {
00790             out<<"   TText *";
00791          }
00792          if (!latex->GetX() && !latex->GetY()) {
00793             TString sl = latex->GetTitle();
00794             sl.ReplaceAll("\"","\\\"");
00795             out<<"text = "<<name<<"->AddText("
00796                <<quote<<sl.Data()<<quote<<");"<<endl;
00797          } else {
00798             out<<"text = "<<name<<"->AddText("
00799                <<latex->GetX()<<","<<latex->GetY()<<","<<quote<<latex->GetTitle()<<quote<<");"<<endl;
00800          }
00801          if (latex->GetTextColor()) {
00802             if (latex->GetTextColor() > 228) {
00803                TColor::SaveColor(out, latex->GetTextColor());
00804                out<<"   text->SetTextColor(ci);" << endl;
00805             } else
00806                out<<"   text->SetTextColor("<<latex->GetTextColor()<<");"<<endl;
00807          }
00808          if (latex->GetTextFont()) {
00809             out<<"   text->SetTextFont("<<latex->GetTextFont()<<");"<<endl;
00810          }
00811          if (latex->GetTextSize()) {
00812             out<<"   text->SetTextSize("<<latex->GetTextSize()<<");"<<endl;
00813          }
00814          if (latex->GetTextAngle() != GetTextAngle()) {
00815             out<<"   text->SetTextAngle("<<latex->GetTextAngle()<<");"<<endl;
00816          }
00817          if (latex->GetTextAlign()) {
00818             out<<"   text->SetTextAlign("<<latex->GetTextAlign()<<");"<<endl;
00819          }
00820       }
00821    }
00822 }
00823 
00824 
00825 //______________________________________________________________________________
00826 void TPaveText::SavePrimitive(ostream &out, Option_t * /*= ""*/)
00827 {
00828    // Save primitive as a C++ statement(s) on output stream out
00829 
00830    char quote = '"';
00831    out<<"   "<<endl;
00832    if (gROOT->ClassSaved(TPaveText::Class())) {
00833       out<<"   ";
00834    } else {
00835       out<<"   "<<ClassName()<<" *";
00836    }
00837    if (fOption.Contains("NDC")) {
00838       out<<"pt = new "<<ClassName()<<"("<<fX1NDC<<","<<fY1NDC<<","<<fX2NDC<<","<<fY2NDC
00839       <<","<<quote<<fOption<<quote<<");"<<endl;
00840    } else {
00841       out<<"pt = new "<<ClassName()<<"("<<gPad->PadtoX(fX1)<<","<<gPad->PadtoY(fY1)<<","<<gPad->PadtoX(fX2)<<","<<gPad->PadtoY(fY2)
00842       <<","<<quote<<fOption<<quote<<");"<<endl;
00843    }
00844    if (strcmp(GetName(),"TPave")) {
00845       out<<"   pt->SetName("<<quote<<GetName()<<quote<<");"<<endl;
00846    }
00847    if (fLabel.Length() > 0) {
00848       out<<"   pt->SetLabel("<<quote<<fLabel<<quote<<");"<<endl;
00849    }
00850    if (fBorderSize != 4) {
00851       out<<"   pt->SetBorderSize("<<fBorderSize<<");"<<endl;
00852    }
00853    SaveFillAttributes(out,"pt",19,1001);
00854    SaveLineAttributes(out,"pt",1,1,1);
00855    SaveTextAttributes(out,"pt",22,0,1,62,0);
00856    SaveLines(out,"pt");
00857    out<<"   pt->Draw();"<<endl;
00858 }
00859 
00860 
00861 //______________________________________________________________________________
00862 void TPaveText::SetAllWith(const char *text, Option_t *option, Double_t value)
00863 {
00864    // Set attribute option for all lines containing string text.
00865    //
00866    // Possible options are all the AttText attributes
00867    //       Align, Color, Font, Size and Angle
00868 
00869    TString opt=option;
00870    opt.ToLower();
00871    TText *line;
00872    TIter next(fLines);
00873    while ((line = (TText*) next())) {
00874       if (strstr(line->GetTitle(),text)) {
00875          if (opt == "align") line->SetTextAlign(Int_t(value));
00876          if (opt == "color") line->SetTextColor(Int_t(value));
00877          if (opt == "font")  line->SetTextFont(Int_t(value));
00878          if (opt == "size")  line->SetTextSize(value);
00879          if (opt == "angle") line->SetTextAngle(value);
00880       }
00881    }
00882 }
00883 
00884 
00885 //______________________________________________________________________________
00886 void TPaveText::Streamer(TBuffer &R__b)
00887 {
00888    // Stream an object of class TPaveText.
00889 
00890    if (R__b.IsReading()) {
00891       UInt_t R__s, R__c;
00892       Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
00893       if (R__v > 1) {
00894          R__b.ReadClassBuffer(TPaveText::Class(), this, R__v, R__s, R__c);
00895          return;
00896       }
00897       //====process old versions before automatic schema evolution
00898       TPave::Streamer(R__b);
00899       TAttText::Streamer(R__b);
00900       if (R__v > 1) fLabel.Streamer(R__b);
00901       R__b >> fLongest;
00902       R__b >> fMargin;
00903       R__b >> fLines;
00904       R__b.CheckByteCount(R__s, R__c, TPaveText::IsA());
00905       //====end of old versions
00906 
00907    } else {
00908       R__b.WriteClassBuffer(TPaveText::Class(),this);
00909    }
00910 }
00911 
00912 //______________________________________________________________________________
00913 void TPaveText::UseCurrentStyle()
00914 {
00915    // Replace current attributes by current style.
00916 
00917    if (gStyle->IsReading()) {
00918       SetTextFont(gStyle->GetTextFont());
00919       SetTextSize(gStyle->GetTextSize());
00920       SetTextColor(gStyle->GetTextColor());
00921    } else {
00922       gStyle->SetTextColor(GetTextColor());
00923       gStyle->SetTextFont(GetTextFont());
00924       gStyle->SetTextSize(GetTextSize());
00925    }
00926 }

Generated on Tue Jul 5 14:14:28 2011 for ROOT_528-00b_version by  doxygen 1.5.1