Logo ROOT   6.08/07
Reference Guide
TPaveText.cxx
Go to the documentation of this file.
1 // @(#)root/graf:$Id$
2 // Author: Rene Brun 20/10/95
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #include <string.h>
13 #include <stdlib.h>
14 #include <stdio.h>
15 
16 #include "Riostream.h"
17 #include "TBufferFile.h"
18 #include "TROOT.h"
19 #include "TStyle.h"
20 #include "TPaveText.h"
21 #include "TPaveLabel.h"
22 #include "TVirtualPad.h"
23 #include "TMath.h"
24 #include "TLatex.h"
25 #include "TError.h"
26 #include "TColor.h"
27 #include "TClass.h"
28 
30 
31 
32 /** \class TPaveText
33 \ingroup BasicGraphics
34 
35 A Pave (see TPave) with text, lines or/and boxes inside.
36 
37 Line (and boxes) are positioned in the pave using coordinates relative to
38 the pave (%).
39 
40 Example:
41 Begin_Macro(source)
42 ../../../tutorials/graphics/pavetext.C
43 End_Macro
44 */
45 
46 ////////////////////////////////////////////////////////////////////////////////
47 /// pavetext default constructor.
48 
50 {
51  fLines = 0;
52  fMargin = 0.05;
53  fLongest = 0;
54 }
55 
56 ////////////////////////////////////////////////////////////////////////////////
57 /// PaveText normal constructor.
58 ///
59 /// A PaveText is a Pave with several lines of text
60 ///
61 /// - option = "TR" Top and Right shadows are drawn.
62 /// - option = "TL" Top and Left shadows are drawn.
63 /// - option = "BR" Bottom and Right shadows are drawn.
64 /// - option = "BL" Bottom and Left shadows are drawn.
65 ///
66 /// If none of these four above options is specified the default the
67 /// option "BR" will be used to draw the border. To produces a pave
68 /// without any border it is enough to specify the option "NB" (no border).
69 ///
70 /// - option = "NDC" x1,y1,x2,y2 are given in NDC
71 /// - option = "ARC" corners are rounded
72 ///
73 /// In case of option "ARC", the corner radius is specified
74 /// via TPave::SetCornerRadius(rad) where rad is given in percent
75 /// of the pave height (default value is 0.2).
76 ///
77 /// The individual text items are entered via AddText
78 /// By default, text items inherits from the default pavetext AttText.
79 /// A title can be added later to this pavetext via TPaveText::SetLabel.
80 
82  :TPave(x1,y1,x2,y2,4,option), TAttText(22,0,gStyle->GetTextColor(),gStyle->GetTextFont(),0)
83 {
84  fLines = new TList;
85  fMargin = 0.05;
86  fLongest = 0;
87 }
88 
89 ////////////////////////////////////////////////////////////////////////////////
90 /// pavetext default destructor.
91 
93 {
94  if (!TestBit(kNotDeleted)) return;
95  if (fLines) fLines->Delete();
96  delete fLines;
97  fLines = 0;
98 }
99 
100 ////////////////////////////////////////////////////////////////////////////////
101 /// pavetext copy constructor.
102 
103 TPaveText::TPaveText(const TPaveText &pavetext) : TPave(), TAttText()
104 {
106  TPaveText *p = (TPaveText*)(&pavetext);
107  p->Streamer(b);
108  b.SetReadMode();
109  b.SetBufferOffset(0);
110  fLines = 0;
111  Streamer(b);
112 }
113 
114 ////////////////////////////////////////////////////////////////////////////////
115 ///assignment operator
116 
118 {
119  if(this!=&pt) {
120  TPave::operator=(pt);
121  TAttText::operator=(pt);
122  fLabel=pt.fLabel;
123  fLongest=pt.fLongest;
124  fMargin=pt.fMargin;
125  fLines=pt.fLines;
126  }
127  return *this;
128 }
129 
130 ////////////////////////////////////////////////////////////////////////////////
131 /// Add a new graphics box to this pavetext.
132 
134 {
135  if (!gPad->IsEditable()) return 0;
136  TBox *newbox = new TBox(x1,y1,x2,y2);
137 
138  if (!fLines) fLines = new TList;
139  fLines->Add(newbox);
140  return newbox;
141 }
142 
143 ////////////////////////////////////////////////////////////////////////////////
144 /// Add a new graphics line to this pavetext.
145 
147 {
148  if (!gPad->IsEditable()) return 0;
149  TLine *newline = new TLine(x1,y1,x2,y2);
150 
151  if (!fLines) fLines = new TList;
152  fLines->Add(newline);
153  return newline;
154 }
155 
156 ////////////////////////////////////////////////////////////////////////////////
157 /// Add a new Text line to this pavetext at given coordinates.
158 
159 TText *TPaveText::AddText(Double_t x1, Double_t y1, const char *text)
160 {
161  TLatex *newtext = new TLatex(x1,y1,text);
162  newtext->SetTextAlign(0);
163  newtext->SetTextColor(0);
164  newtext->SetTextFont(0);
165  newtext->SetTextSize(0);
166  Int_t nch = strlen(text);
167  if (nch > fLongest) fLongest = nch;
168 
169  if (!fLines) fLines = new TList;
170  fLines->Add(newtext);
171  return newtext;
172 }
173 
174 ////////////////////////////////////////////////////////////////////////////////
175 /// Add a new Text line to this pavetext.
176 
177 TText *TPaveText::AddText(const char *text)
178 {
179  return AddText(0,0,text);
180 }
181 
182 ////////////////////////////////////////////////////////////////////////////////
183 /// Clear all lines in this pavetext.
184 
186 {
187  if (!fLines) return;
188  fLines->Delete();
189  fLongest = 0;
190 }
191 
192 ////////////////////////////////////////////////////////////////////////////////
193 /// Delete text at the mouse position.
194 
196 {
197  if (!gPad->IsEditable()) return;
198  if (!fLines) return;
199  Double_t ymouse, yobj;
200  TObject *obj = GetObject(ymouse, yobj); //get object pointed by the mouse
201  if (!obj) return;
202  if (!obj->InheritsFrom(TText::Class())) return;
203  fLines->Remove(obj);
204  delete obj;
205 }
206 
207 ////////////////////////////////////////////////////////////////////////////////
208 /// Draw this pavetext with its current attributes.
209 
210 void TPaveText::Draw(Option_t *option)
211 {
212  Option_t *opt;
213  if (option && strlen(option)) opt = option;
214  else opt = GetOption();
215 
216  AppendPad(opt);
217 }
218 
219 ////////////////////////////////////////////////////////////////////////////////
220 /// Draw lines in filename in this pavetext.
221 
222 void TPaveText::DrawFile(const char *filename, Option_t *option)
223 {
224  ReadFile(filename);
225 
226  AppendPad(option);
227 }
228 
229 ////////////////////////////////////////////////////////////////////////////////
230 /// Edit text at the mouse position.
231 
232 void TPaveText::EditText()
233 {
234  if (!gPad->IsEditable()) return;
235  Double_t ymouse, yobj;
236  TObject *obj = GetObject(ymouse, yobj); //get object pointed by the mouse
237  if (!obj) return;
238  if (!obj->InheritsFrom(TText::Class())) return;
239  TText *text = (TText*)obj;
240  gROOT->SetSelectedPrimitive(text);
241  gROOT->ProcessLine(Form("((TCanvas*)0x%lx)->SetSelected((TObject*)0x%lx)",
242  (ULong_t)gPad->GetCanvas(), (ULong_t)text));
243  gROOT->ProcessLine(Form("((TCanvas*)0x%lx)->Selected((TVirtualPad*)0x%lx,(TObject*)0x%lx,1)",
244  (ULong_t)gPad->GetCanvas(), (ULong_t)gPad, (ULong_t)text));
245  text->SetTextAttributes();
246 }
247 
248 ////////////////////////////////////////////////////////////////////////////////
249 /// Get Pointer to line number in this pavetext.
250 
251 TText *TPaveText::GetLine(Int_t number) const
252 {
253  TText *line;
254  TIter next(fLines);
255  Int_t nlines = 0;
256  while ((line = (TText*) next())) {
257  if (nlines == number) return line;
258  nlines++;
259  }
260  return 0;
261 }
262 
263 ////////////////////////////////////////////////////////////////////////////////
264 /// Get Pointer to first containing string text in this pavetext.
265 
266 TText *TPaveText::GetLineWith(const char *text) const
267 {
268  TText *line;
269  TIter next(fLines);
270  while ((line = (TText*) next())) {
271  if (strstr(line->GetTitle(),text)) return line;
272  }
273  return 0;
274 }
275 
276 ////////////////////////////////////////////////////////////////////////////////
277 /// Get object pointed by the mouse in this pavetext.
278 
279 TObject *TPaveText::GetObject(Double_t &ymouse, Double_t &yobj) const
280 {
281  if (!fLines) return 0;
282  Int_t nlines = GetSize();
283  if (nlines == 0) return 0;
284 
285  // Evaluate text size as a function of the number of lines
286 
287  ymouse = gPad->AbsPixeltoY(gPad->GetEventY());
288  Double_t yspace = (fY2 - fY1)/Double_t(nlines);
289  Double_t textsize = GetTextSize();
290  Double_t y1,y,dy;
291  if (textsize == 0) {
292  y1 = gPad->GetY1();
293  }
294  Double_t ytext = fY2 + 0.5*yspace;
295  Int_t valign;
296 
297  // Iterate over all lines
298  // Copy pavetext attributes to line attributes if line attributes not set
299  dy = fY2 - fY1;
300  TObject *line;
301  TText *linet;
302  TLine *linel;
303  TBox *lineb;
304  TIter next(fLines);
305  while ((line = (TObject*) next())) {
306  // Next primitive is a line
307  if (line->IsA() == TLine::Class()) {
308  linel = (TLine*)line;
309  y1 = linel->GetY1(); if (y1 == 0) y1 = ytext; else y1 = fY1 + y1*dy;
310  if (TMath::Abs(y1-ymouse) < 0.2*yspace) {yobj = y1; return line;}
311  continue;
312  }
313  // Next primitive is a box
314  if (line->IsA() == TBox::Class()) {
315  lineb = (TBox*)line;
316  y1 = lineb->GetY1(); if (y1 == 0) y1 = ytext; else y1 = fY1 + y1*dy;
317  if (TMath::Abs(y1-ymouse) < 0.4*yspace) {yobj = y1; return line;}
318  continue;
319  }
320  // Next primitive is a text
321  if (line->InheritsFrom(TText::Class())) {
322  linet = (TText*)line;
323  ytext -= yspace;
324  Double_t yl = linet->GetY();
325  Short_t talign = linet->GetTextAlign();
326  if (talign == 0) talign = GetTextAlign();
327  if (yl > 0 && yl <1) {
328  ytext = fY1 + yl*dy;
329  }
330  valign = linet->GetTextAlign()%10;
331  y = ytext;
332  if (valign == 1) y = ytext -0.5*yspace;
333  if (valign == 3) y = ytext +0.5*yspace;
334 
335  if (TMath::Abs(y-ymouse) < 0.5*yspace) {yobj = y; return line;}
336  }
337  }
338  return 0;
339 }
340 
341 ////////////////////////////////////////////////////////////////////////////////
342 /// return number of text lines (ignoring TLine, etc)
343 
345 {
346  Int_t nlines = 0;
347  TIter next(fLines);
348  TObject *line;
349  while ((line = (TObject*) next())) {
350  if (line->InheritsFrom(TText::Class())) nlines++;
351  }
352  return nlines;
353 }
354 
355 ////////////////////////////////////////////////////////////////////////////////
356 /// Add a new line at the mouse position.
357 
359 {
360  if (!gPad->IsEditable()) return;
361  Double_t ymouse=0, yobj;
362  TObject *obj = GetObject(ymouse, yobj); //get object pointed by the mouse
363  Double_t yline = (ymouse-fY1)/(fY2-fY1);
364  TLine *newline = AddLine(0,yline,0,yline);
365  if (obj) {
366  fLines->Remove(newline); //remove line from last position
367  if (yobj < ymouse) fLines->AddBefore(obj,newline);
368  else fLines->AddAfter(obj,newline);
369  }
370 }
371 
372 ////////////////////////////////////////////////////////////////////////////////
373 /// Add a new Text line at the mouse position.
374 
375 void TPaveText::InsertText(const char *text)
376 {
377  if (!gPad->IsEditable()) return;
378  Double_t ymouse, yobj;
379  TObject *obj = GetObject(ymouse, yobj); //get object pointed by the mouse
380  TText *newtext = AddText(0,0,text); //create new text object
381  if (obj) {
382  fLines->Remove(newtext); //remove text from last position
383  if (yobj < ymouse) fLines->AddBefore(obj,newtext); //insert new text at right position
384  else fLines->AddAfter(obj,newtext); //insert new text at right position
385  }
386 }
387 
388 ////////////////////////////////////////////////////////////////////////////////
389 /// Paint this pavetext with its current attributes.
390 
391 void TPaveText::Paint(Option_t *option)
392 {
393  // Draw the pave
397 }
398 
399 ////////////////////////////////////////////////////////////////////////////////
400 /// Paint list of primitives in this pavetext.
401 
403 {
404  if (!fLines) return;
405  Double_t dx = fX2 - fX1;
406  Double_t dy = fY2 - fY1;
407  Double_t textsize = GetTextSize();
408  Int_t nlines = GetSize();
409  if (nlines == 0) nlines = 5;
410 
411  // Evaluate text size as a function of the number of lines
412 
413  Double_t x1,y1,x2,y2;
414  y1 = gPad->GetY1();
415  y2 = gPad->GetY2();
416  Float_t margin = fMargin*dx;
417  Double_t yspace = dy/Double_t(nlines);
418  Double_t textsave = textsize;
419  TObject *line;
420  TText *linet;
421  TLatex *latex;
422  TIter next(fLines);
423  Double_t longest = 0;
424  Double_t w;
425  if (textsize == 0) {
426  textsize = 0.85*yspace/(y2 - y1);
427  while ((line = (TObject*) next())) {
428  if (line->IsA() == TLatex::Class()) {
429  latex = (TLatex*)line;
430  Float_t tangle = latex->GetTextAngle();
431  if (latex->GetTextSize() != 0) continue;
432  Style_t tfont = latex->GetTextFont();
433  if (tfont == 0) latex->SetTextFont(GetTextFont());
434  latex->SetTextSize(textsize);
435  w = latex->GetXsize();
436  latex->SetTextSize(0);
437  latex->SetTextAngle(tangle); //text angle was redefined in GetXsize !
438  if (w > longest) longest = w;
439  latex->SetTextFont(tfont);
440  }
441  }
442  if (longest > 0.92*dx) textsize *= 0.92*dx/longest;
443  if (mode == kDiamond) textsize *= 0.66;
444  SetTextSize(textsize);
445  }
446  Double_t ytext = fY2 + 0.5*yspace;
447  Double_t xtext = 0;
448  Int_t halign;
449 
450  // Iterate over all lines
451  // Copy pavetext attributes to line attributes if line attributes not set
452  TLine *linel;
453  TBox *lineb;
454  next.Reset();
455  while ((line = (TObject*) next())) {
456  // Next primitive is a line
457  if (line->IsA() == TLine::Class()) {
458  linel = (TLine*)line;
459  x1 = linel->GetX1(); if (x1 == 0) x1 = fX1; else x1 = fX1 + x1*dx;
460  x2 = linel->GetX2(); if (x2 == 0) x2 = fX2; else x2 = fX1 + x2*dx;
461  y1 = linel->GetY1(); if (y1 == 0) y1 = ytext; else y1 = fY1 + y1*dy;
462  y2 = linel->GetY2(); if (y2 == 0) y2 = ytext; else y2 = fY1 + y2*dy;
463  linel->PaintLine(x1,y1,x2,y2);
464  continue;
465  }
466  // Next primitive is a box
467  if (line->IsA() == TBox::Class()) {
468  lineb = (TBox*)line;
469  x1 = lineb->GetX1();
470  if (x1) x1 = fX1 + x1*dx;
471  else x1 = fX1 + gPad->PixeltoX(1) - gPad->PixeltoX(0);
472  x2 = lineb->GetX2();
473  if (x2) x2 = fX1 + x2*dx;
474  else x2 = fX2;
475  y1 = lineb->GetY1(); if (y1 == 0) y1 = ytext; else y1 = fY1 + y1*dy;
476  y2 = lineb->GetY2(); if (y2 == 0) y2 = ytext; else y2 = fY1 + y2*dy;
477  lineb->PaintBox(x1,y1,x2,y2);
478  continue;
479  }
480  // Next primitive is a text
481  if (line->IsA() == TText::Class()) {
482  linet = (TText*)line;
483  ytext -= yspace;
484  Double_t xl = linet->GetX();
485  Double_t yl = linet->GetY();
486  Short_t talign = linet->GetTextAlign();
487  Color_t tcolor = linet->GetTextColor();
488  Style_t tfont = linet->GetTextFont();
489  Size_t tsize = linet->GetTextSize();
490  if (talign == 0) linet->SetTextAlign(GetTextAlign());
491  if (tcolor == 0) linet->SetTextColor(GetTextColor());
492  if (tfont == 0) linet->SetTextFont(GetTextFont());
493  if (tsize == 0) linet->SetTextSize(GetTextSize());
494  if (xl > 0 && xl <1) {
495  xtext = fX1 + xl*dx;
496  } else {
497  halign = linet->GetTextAlign()/10;
498  if (halign == 1) xtext = fX1 + margin;
499  if (halign == 2) xtext = 0.5*(fX1+fX2);
500  if (halign == 3) xtext = fX2 - margin;
501  }
502  if (yl > 0 && yl <1) ytext = fY1 + yl*dy;
503  linet->PaintText(xtext,ytext,linet->GetTitle());
504  linet->SetTextAlign(talign);
505  linet->SetTextColor(tcolor);
506  linet->SetTextFont(tfont);
507  linet->SetTextSize(tsize);
508  }
509  // Next primitive is a Latex text
510  if (line->IsA() == TLatex::Class()) {
511  latex = (TLatex*)line;
512  ytext -= yspace;
513  Double_t xl = latex->GetX();
514  Double_t yl = latex->GetY();
515  Short_t talign = latex->GetTextAlign();
516  Color_t tcolor = latex->GetTextColor();
517  Style_t tfont = latex->GetTextFont();
518  Size_t tsize = latex->GetTextSize();
519  if (talign == 0) latex->SetTextAlign(GetTextAlign());
520  if (tcolor == 0) latex->SetTextColor(GetTextColor());
521  if (tfont == 0) latex->SetTextFont(GetTextFont());
522  if (tsize == 0) latex->SetTextSize(GetTextSize());
523  if (xl > 0 && xl <1) {
524  xtext = fX1 + xl*dx;
525  } else {
526  halign = latex->GetTextAlign()/10;
527  if (halign == 1) xtext = fX1 + margin;
528  if (halign == 2) xtext = 0.5*(fX1+fX2);
529  if (halign == 3) xtext = fX2 - margin;
530  }
531  if (yl > 0 && yl <1) ytext = fY1 + yl*dy;
532  latex->PaintLatex(xtext,ytext,latex->GetTextAngle(),
533  latex->GetTextSize(),
534  latex->GetTitle());
535  latex->SetTextAlign(talign);
536  latex->SetTextColor(tcolor);
537  latex->SetTextFont(tfont);
538  latex->SetTextSize(tsize);
539  latex->SetX(xl); // PaintLatex modifies fX and fY
540  latex->SetY(yl);
541  }
542  }
543 
544  SetTextSize(textsave);
545 
546  // if a label create & paint a pavetext title
547  if (fLabel.Length() > 0) {
548  dy = gPad->GetY2() - gPad->GetY1();
549  x1 = fX1 + 0.25*dx;
550  x2 = fX2 - 0.25*dx;
551  y1 = fY2 - 0.02*dy;
552  y2 = fY2 + 0.02*dy;
553  TPaveLabel *title = new TPaveLabel(x1,y1,x2,y2,fLabel.Data(),GetDrawOption());
554  title->SetFillColor(GetFillColor());
555  title->SetTextColor(GetTextColor());
556  title->SetTextFont(GetTextFont());
557  title->Paint();
558  delete title;
559  }
560 }
561 
562 ////////////////////////////////////////////////////////////////////////////////
563 /// Dump this pavetext with its attributes.
564 
565 void TPaveText::Print(Option_t *option) const
566 {
567  TPave::Print(option);
568  if (fLines) fLines->Print();
569 }
570 
571 ////////////////////////////////////////////////////////////////////////////////
572 /// Read lines of filename in this pavetext.
573 ///
574 /// Read from line number fromline a total of nlines
575 ///
576 /// Note that this function changes the default text alignment to left/center
577 
578 void TPaveText::ReadFile(const char *filename, Option_t *option, Int_t nlines, Int_t fromline)
579 {
580  Int_t ival;
581  Float_t val;
582  TText *lastline = 0;
583  TString opt = option;
584  if (!opt.Contains("+")) {
585  Clear();
586  fLongest = 0;
587  }
588  SetTextAlign(12);
589  // Get file name
590  Int_t nch = strlen(filename);
591  if (nch == 0) return;
592 
593  char *fname = StrDup(filename);
594  if (fname[nch-1] == ';') { nch--; fname[nch]=0;}
595 
596  std::ifstream file(fname,std::ios::in);
597  if (!file.good()) {
598  Error("ReadFile", "illegal file name");
599  delete [] fname;
600  return;
601  }
602 
603  const int linesize = 255;
604  char currentline[linesize];
605  char *ss, *sclose, *s= 0;
606 
607  Int_t kline = 0;
608  while (1) {
609  file.getline(currentline,linesize);
610  if (file.eof())break;
611  if (kline >= fromline && kline < fromline+nlines) {
612  s = currentline;
613  if (strstr(s,"+SetText")) {
614  ss = s+8;
615  sclose = strstr(ss,")");
616  if (!sclose) continue;
617  *sclose = 0;
618  lastline = (TText*)fLines->Last();
619  if (!lastline) continue;
620  if (strstr(ss,"Color(")) {
621  sscanf(ss+6,"%d",&ival);
622  lastline->SetTextColor(ival);
623  continue;
624  }
625  if (strstr(ss,"Align(")) {
626  sscanf(ss+6,"%d",&ival);
627  lastline->SetTextAlign(ival);
628  continue;
629  }
630  if (strstr(ss,"Font(")) {
631  sscanf(ss+5,"%d",&ival);
632  lastline->SetTextFont(ival);
633  continue;
634  }
635  if (strstr(ss,"Size(")) {
636  sscanf(ss+5,"%f",&val);
637  lastline->SetTextSize(val);
638  continue;
639  }
640  if (strstr(ss,"Angle(")) {
641  sscanf(ss+6,"%f",&val);
642  lastline->SetTextAngle(val);
643  continue;
644  }
645  }
646  AddText(s);
647  }
648  kline++;
649  }
650  file.close();
651  delete [] fname;
652 }
653 
654 ////////////////////////////////////////////////////////////////////////////////
655 /// Save lines of this pavetext as C++ statements on output stream out
656 
657 void TPaveText::SaveLines(std::ostream &out, const char *name)
658 {
659  if (!fLines) return;
660  Int_t nlines = GetSize();
661  if (nlines == 0) return;
662 
663  // Iterate over all lines
664  char quote = '"';
665  TObject *line;
666  TText *linet;
667  TLatex *latex;
668  TLine *linel;
669  TBox *lineb;
670  TIter next(fLines);
671  while ((line = (TObject*) next())) {
672  // Next primitive is a line
673  if (line->IsA() == TLine::Class()) {
674  linel = (TLine*)line;
675  if (gROOT->ClassSaved(TLine::Class())) {
676  out<<" ";
677  } else {
678  out<<" TLine *";
679  }
680  out<<"line = "<<name<<"->AddLine("
681  <<linel->GetX1()<<","<<linel->GetY1()<<","<<linel->GetX2()<<","<<linel->GetY2()<<");"<<std::endl;
682  if (linel->GetLineColor() != 1) {
683  if (linel->GetLineColor() > 228) {
684  TColor::SaveColor(out, linel->GetLineColor());
685  out<<" line->SetLineColor(ci);" << std::endl;
686  } else
687  out<<" line->SetLineColor("<<linel->GetLineColor()<<");"<<std::endl;
688  }
689  if (linel->GetLineStyle() != 1) {
690  out<<" line->SetLineStyle("<<linel->GetLineStyle()<<");"<<std::endl;
691  }
692  if (linel->GetLineWidth() != 1) {
693  out<<" line->SetLineWidth("<<linel->GetLineWidth()<<");"<<std::endl;
694  }
695  continue;
696  }
697  // Next primitive is a box
698  if (line->IsA() == TBox::Class()) {
699  lineb = (TBox*)line;
700  if (gROOT->ClassSaved(TBox::Class())) {
701  out<<" ";
702  } else {
703  out<<" TBox *";
704  }
705  out<<"box = "<<name<<"->AddBox("
706  <<lineb->GetX1()<<","<<lineb->GetY1()<<","<<lineb->GetX2()<<","<<lineb->GetY2()<<");"<<std::endl;
707  if (lineb->GetFillColor() != 18) {
708  if (lineb->GetFillColor() > 228) {
709  TColor::SaveColor(out, lineb->GetFillColor());
710  out<<" box->SetFillColor(ci);" << std::endl;
711  } else
712  out<<" box->SetFillColor("<<lineb->GetFillColor()<<");"<<std::endl;
713  }
714  if (lineb->GetFillStyle() != 1001) {
715  out<<" box->SetFillStyle("<<lineb->GetFillStyle()<<");"<<std::endl;
716  }
717  if (lineb->GetLineColor() != 1) {
718  if (lineb->GetLineColor() > 228) {
719  TColor::SaveColor(out, lineb->GetLineColor());
720  out<<" box->SetLineColor(ci);" << std::endl;
721  } else
722  out<<" box->SetLineColor("<<lineb->GetLineColor()<<");"<<std::endl;
723  }
724  if (lineb->GetLineStyle() != 1) {
725  out<<" box->SetLineStyle("<<lineb->GetLineStyle()<<");"<<std::endl;
726  }
727  if (lineb->GetLineWidth() != 1) {
728  out<<" box->SetLineWidth("<<lineb->GetLineWidth()<<");"<<std::endl;
729  }
730  continue;
731  }
732  // Next primitive is a text
733  if (line->IsA() == TText::Class()) {
734  linet = (TText*)line;
735  if (gROOT->ClassSaved(TText::Class())) {
736  out<<" ";
737  } else {
738  out<<" TText *";
739  }
740  if (!linet->GetX() && !linet->GetY()) {
741  TString s = linet->GetTitle();
742  s.ReplaceAll("\"","\\\"");
743  out<<"AText = "<<name<<"->AddText("
744  <<quote<<s.Data()<<quote<<");"<<std::endl;
745  } else {
746  out<<"AText = "<<name<<"->AddText("
747  <<linet->GetX()<<","<<linet->GetY()<<","<<quote<<linet->GetTitle()<<quote<<");"<<std::endl;
748  }
749  if (linet->GetTextColor()) {
750  if (linet->GetTextColor() > 228) {
751  TColor::SaveColor(out, linet->GetTextColor());
752  out<<" AText->SetTextColor(ci);" << std::endl;
753  } else
754  out<<" AText->SetTextColor("<<linet->GetTextColor()<<");"<<std::endl;
755  }
756  if (linet->GetTextFont()) {
757  out<<" AText->SetTextFont("<<linet->GetTextFont()<<");"<<std::endl;
758  }
759  if (linet->GetTextSize()) {
760  out<<" AText->SetTextSize("<<linet->GetTextSize()<<");"<<std::endl;
761  }
762  if (linet->GetTextAngle() != GetTextAngle()) {
763  out<<" AText->SetTextAngle("<<linet->GetTextAngle()<<");"<<std::endl;
764  }
765  if (linet->GetTextAlign()) {
766  out<<" AText->SetTextAlign("<<linet->GetTextAlign()<<");"<<std::endl;
767  }
768  }
769  // Next primitive is a Latex text
770  if (line->IsA() == TLatex::Class()) {
771  latex = (TLatex*)line;
772  if (gROOT->ClassSaved(TLatex::Class())) {
773  out<<" ";
774  } else {
775  out<<" TText *";
776  }
777  if (!latex->GetX() && !latex->GetY()) {
778  TString sl = latex->GetTitle();
779  sl.ReplaceAll("\"","\\\"");
780  out<<"AText = "<<name<<"->AddText("
781  <<quote<<sl.Data()<<quote<<");"<<std::endl;
782  } else {
783  out<<"AText = "<<name<<"->AddText("
784  <<latex->GetX()<<","<<latex->GetY()<<","<<quote<<latex->GetTitle()<<quote<<");"<<std::endl;
785  }
786  if (latex->GetTextColor()) {
787  if (latex->GetTextColor() > 228) {
788  TColor::SaveColor(out, latex->GetTextColor());
789  out<<" AText->SetTextColor(ci);" << std::endl;
790  } else
791  out<<" AText->SetTextColor("<<latex->GetTextColor()<<");"<<std::endl;
792  }
793  if (latex->GetTextFont()) {
794  out<<" AText->SetTextFont("<<latex->GetTextFont()<<");"<<std::endl;
795  }
796  if (latex->GetTextSize()) {
797  out<<" AText->SetTextSize("<<latex->GetTextSize()<<");"<<std::endl;
798  }
799  if (latex->GetTextAngle() != GetTextAngle()) {
800  out<<" AText->SetTextAngle("<<latex->GetTextAngle()<<");"<<std::endl;
801  }
802  if (latex->GetTextAlign()) {
803  out<<" AText->SetTextAlign("<<latex->GetTextAlign()<<");"<<std::endl;
804  }
805  }
806  }
807 }
808 
809 ////////////////////////////////////////////////////////////////////////////////
810 /// Save primitive as a C++ statement(s) on output stream out
811 
812 void TPaveText::SavePrimitive(std::ostream &out, Option_t * /*= ""*/)
813 {
814  char quote = '"';
815  out<<" "<<std::endl;
816  if (gROOT->ClassSaved(TPaveText::Class())) {
817  out<<" ";
818  } else {
819  out<<" "<<ClassName()<<" *";
820  }
821  if (fOption.Contains("NDC")) {
822  out<<"pt = new "<<ClassName()<<"("<<fX1NDC<<","<<fY1NDC<<","<<fX2NDC<<","<<fY2NDC
823  <<","<<quote<<fOption<<quote<<");"<<std::endl;
824  } else {
825  out<<"pt = new "<<ClassName()<<"("<<gPad->PadtoX(fX1)<<","<<gPad->PadtoY(fY1)<<","<<gPad->PadtoX(fX2)<<","<<gPad->PadtoY(fY2)
826  <<","<<quote<<fOption<<quote<<");"<<std::endl;
827  }
828  if (strcmp(GetName(),"TPave")) {
829  out<<" pt->SetName("<<quote<<GetName()<<quote<<");"<<std::endl;
830  }
831  if (fLabel.Length() > 0) {
832  out<<" pt->SetLabel("<<quote<<fLabel<<quote<<");"<<std::endl;
833  }
834  if (fBorderSize != 4) {
835  out<<" pt->SetBorderSize("<<fBorderSize<<");"<<std::endl;
836  }
837  SaveFillAttributes(out,"pt",19,1001);
838  SaveLineAttributes(out,"pt",1,1,1);
839  SaveTextAttributes(out,"pt",22,0,1,62,0);
840  SaveLines(out,"pt");
841  out<<" pt->Draw();"<<std::endl;
842 }
843 
844 ////////////////////////////////////////////////////////////////////////////////
845 /// Set attribute option for all lines containing string text.
846 ///
847 /// Possible options are all the AttText attributes
848 /// Align, Color, Font, Size and Angle
849 
850 void TPaveText::SetAllWith(const char *text, Option_t *option, Double_t value)
851 {
852  TString opt=option;
853  opt.ToLower();
854  TText *line;
855  TIter next(fLines);
856  while ((line = (TText*) next())) {
857  if (strstr(line->GetTitle(),text)) {
858  if (opt == "align") line->SetTextAlign(Int_t(value));
859  if (opt == "color") line->SetTextColor(Int_t(value));
860  if (opt == "font") line->SetTextFont(Int_t(value));
861  if (opt == "size") line->SetTextSize(value);
862  if (opt == "angle") line->SetTextAngle(value);
863  }
864  }
865 }
866 
867 ////////////////////////////////////////////////////////////////////////////////
868 /// Stream an object of class TPaveText.
869 
870 void TPaveText::Streamer(TBuffer &R__b)
871 {
872  if (R__b.IsReading()) {
873  UInt_t R__s, R__c;
874  Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
875  if (R__v > 1) {
876  R__b.ReadClassBuffer(TPaveText::Class(), this, R__v, R__s, R__c);
877  return;
878  }
879  //====process old versions before automatic schema evolution
880  TPave::Streamer(R__b);
881  TAttText::Streamer(R__b);
882  if (R__v > 1) fLabel.Streamer(R__b);
883  R__b >> fLongest;
884  R__b >> fMargin;
885  R__b >> fLines;
886  R__b.CheckByteCount(R__s, R__c, TPaveText::IsA());
887  //====end of old versions
888 
889  } else {
890  R__b.WriteClassBuffer(TPaveText::Class(),this);
891  }
892 }
893 
894 ////////////////////////////////////////////////////////////////////////////////
895 /// Replace current attributes by current style.
896 
898 {
899  if (gStyle->IsReading()) {
903  } else {
907  }
908 }
Double_t GetX1() const
Definition: TLine.h:59
void SetBufferOffset(Int_t offset=0)
Definition: TBuffer.h:90
Bool_t IsReading() const
Definition: TBuffer.h:83
object has not been deleted
Definition: TObject.h:69
TBox & operator=(const TBox &)
Assignment operator.
Definition: TBox.cxx:92
Option_t * GetOption() const
Definition: TPave.h:58
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition: TList.cxx:405
virtual void Print(Option_t *option="") const
Dump this pave with its attributes.
Definition: TPave.cxx:593
virtual void Draw(Option_t *option="")
Draw this pavetext with its current attributes.
Definition: TPaveText.cxx:211
The concrete implementation of TBuffer for writing/reading to/from a ROOT file or socket...
Definition: TBufferFile.h:51
TBox()
Box default constructor.
Definition: TBox.cxx:41
short Style_t
Definition: RtypesCore.h:76
Double_t GetY1() const
Definition: TLine.h:61
virtual TBox * AddBox(Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Add a new graphics box to this pavetext.
Definition: TPaveText.cxx:134
Double_t GetX2() const
Definition: TBox.h:65
short Version_t
Definition: RtypesCore.h:61
virtual Color_t GetTextColor() const
Return the text color.
Definition: TAttText.h:40
TLine * line
float Float_t
Definition: RtypesCore.h:53
float Size_t
Definition: RtypesCore.h:83
virtual Short_t GetTextAlign() const
Return the text alignment.
Definition: TAttText.h:38
Float_t fMargin
Text margin.
Definition: TPaveText.h:32
const char Option_t
Definition: RtypesCore.h:62
virtual TLine * AddLine(Double_t x1=0, Double_t y1=0, Double_t x2=0, Double_t y2=0)
Add a new graphics line to this pavetext.
Definition: TPaveText.cxx:147
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save primitive as a C++ statement(s) on output stream out.
Definition: TPaveText.cxx:813
Create a Box.
Definition: TBox.h:36
virtual void SetX(Double_t x)
Definition: TText.h:84
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:635
R__EXTERN TStyle * gStyle
Definition: TStyle.h:418
Bool_t TestBit(UInt_t f) const
Definition: TObject.h:157
virtual void DeleteText()
Delete text at the mouse position.
Definition: TPaveText.cxx:196
static void SaveColor(std::ostream &out, Int_t ci)
Save a color with index > 228 as a C++ statement(s) on output stream out.
Definition: TColor.cxx:2021
virtual void UseCurrentStyle()
Replace current attributes by current style.
Definition: TPaveText.cxx:898
virtual Float_t GetTextAngle() const
Return the text angle.
Definition: TAttText.h:39
Double_t fY2
Y of 2nd point.
Definition: TBox.h:45
virtual TObject * Last() const
Return the last object in the list. Returns 0 when list is empty.
Definition: TList.cxx:581
virtual TText * AddText(Double_t x1, Double_t y1, const char *label)
Add a new Text line to this pavetext at given coordinates.
Definition: TPaveText.cxx:160
Buffer base class used for serializing objects.
Definition: TBuffer.h:42
virtual void SetTextAttributes()
Invoke the DialogCanvas Text attributes.
Definition: TAttText.cxx:375
virtual Int_t CheckByteCount(UInt_t startpos, UInt_t bcnt, const TClass *clss)=0
#define gROOT
Definition: TROOT.h:364
Basic string class.
Definition: TString.h:137
void ToLower()
Change string to lower-case.
Definition: TString.cxx:1089
int Int_t
Definition: RtypesCore.h:41
Double_t GetY2() const
Definition: TBox.h:67
virtual void InsertText(const char *label)
Add a new Text line at the mouse position.
Definition: TPaveText.cxx:376
const char * Class
Definition: TXMLSetup.cxx:64
Short_t Abs(Short_t d)
Definition: TMathBase.h:110
virtual Width_t GetLineWidth() const
Return the line width.
Definition: TAttLine.h:41
void Reset()
Definition: TCollection.h:161
virtual void AppendPad(Option_t *option="")
Append graphics object to current pad.
Definition: TObject.cxx:165
A TBox with a bordersize and a shadow option.
Definition: TPave.h:23
virtual void ConvertNDCtoPad()
Convert pave coordinates from NDC to Pad coordinates.
Definition: TPave.cxx:121
Double_t fY1
Y of 1st point.
Definition: TBox.h:43
virtual void SetTextFont(Font_t tfont=62)
Set the text font.
Definition: TAttText.h:51
virtual Style_t GetLineStyle() const
Return the line style.
Definition: TAttLine.h:40
static const double x2[5]
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:188
virtual void DrawFile(const char *filename, Option_t *option="")
Draw lines in filename in this pavetext.
Definition: TPaveText.cxx:223
Double_t fX1NDC
X1 point in NDC coordinates.
Definition: TPave.h:26
virtual void Paint(Option_t *option="")
Paint this pavetext with its current attributes.
Definition: TPaveText.cxx:392
virtual void SaveLineAttributes(std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1, Int_t widdef=1)
Save line attributes as C++ statement(s) on output stream out.
Definition: TAttLine.cxx:260
virtual Float_t GetTextSize() const
Return the text size.
Definition: TAttText.h:42
virtual Int_t GetSize() const
return number of text lines (ignoring TLine, etc)
Definition: TPaveText.cxx:345
To draw Mathematical Formula.
Definition: TLatex.h:25
TList * fLines
List of labels.
Definition: TPaveText.h:33
TString fLabel
Label written at the top of the pavetext.
Definition: TPaveText.h:30
virtual TText * GetLine(Int_t number) const
Get Pointer to line number in this pavetext.
Definition: TPaveText.cxx:252
virtual void Clear(Option_t *option="")
Clear all lines in this pavetext.
Definition: TPaveText.cxx:186
Base class for several text objects.
Definition: TText.h:33
virtual ~TPaveText()
pavetext default destructor.
Definition: TPaveText.cxx:93
virtual void PaintLatex(Double_t x, Double_t y, Double_t angle, Double_t size, const char *text)
Main drawing function.
Definition: TLatex.cxx:2038
virtual void ReadFile(const char *filename, Option_t *option="", Int_t nlines=50, Int_t fromline=0)
Read lines of filename in this pavetext.
Definition: TPaveText.cxx:579
Int_t fLongest
Length of the longest line.
Definition: TPaveText.h:31
short Color_t
Definition: RtypesCore.h:79
virtual void SetTextAlign(Short_t align=11)
Set the text alignment.
Definition: TAttText.h:47
virtual Option_t * GetDrawOption() const
Get option used by the graphics system to draw this object.
Definition: TObject.cxx:400
A doubly linked list.
Definition: TList.h:47
virtual void PaintLine(Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Draw this line with new coordinates.
Definition: TLine.cxx:380
A Pave (see TPave) with a text centered in the Pave.
Definition: TPaveLabel.h:24
TAttText()
AttText default constructor.
Definition: TAttText.cxx:257
virtual void InsertLine()
Add a new line at the mouse position.
Definition: TPaveText.cxx:359
Double_t GetX() const
Definition: TText.h:61
virtual void EditText()
Edit text at the mouse position.
Definition: TPaveText.cxx:233
virtual TText * GetLineWith(const char *text) const
Get Pointer to first containing string text in this pavetext.
Definition: TPaveText.cxx:267
TPaveText * pt
Double_t GetXsize()
Return size of the formula along X in pad coordinates.
Definition: TLatex.cxx:2507
virtual void SaveTextAttributes(std::ostream &out, const char *name, Int_t alidef=12, Float_t angdef=0, Int_t coldef=1, Int_t fondef=61, Float_t sizdef=1)
Save text attributes as C++ statement(s) on output stream out.
Definition: TAttText.cxx:347
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition: TAttFill.h:42
Double_t GetY() const
Definition: TText.h:69
virtual Font_t GetTextFont() const
Return the text font.
Definition: TAttText.h:41
virtual TObject * Remove(TObject *obj)
Remove object from the list.
Definition: TList.cxx:675
Double_t fX2
X of 2nd point.
Definition: TBox.h:44
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:488
virtual void SetTextAngle(Float_t tangle=0)
Set the text angle.
Definition: TAttText.h:48
Text Attributes class.
Definition: TAttText.h:24
virtual TObject * GetObject(Double_t &ymouse, Double_t &yobj) const
Get object pointed by the mouse in this pavetext.
Definition: TPaveText.cxx:280
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual void SaveFillAttributes(std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1001)
Save fill attributes as C++ statement(s) on output stream out.
Definition: TAttFill.cxx:232
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:925
char * Form(const char *fmt,...)
Ssiz_t Length() const
Definition: TString.h:390
A simple line.
Definition: TLine.h:33
Double_t fX1
X of 1st point.
Definition: TBox.h:42
void SetReadMode()
Set buffer in read mode.
Definition: TBuffer.cxx:271
short Short_t
Definition: RtypesCore.h:35
Option_t * GetName() const
Returns name of object.
Definition: TPave.h:57
virtual void AddBefore(const TObject *before, TObject *obj)
Insert object before object before in the list.
Definition: TList.cxx:173
Int_t fBorderSize
window box bordersize in pixels
Definition: TPave.h:30
virtual void PaintBox(Double_t x1, Double_t y1, Double_t x2, Double_t y2, Option_t *option="")
Draw this box with new coordinates.
Definition: TBox.cxx:627
char * StrDup(const char *str)
Duplicate the string str.
Definition: TString.cxx:2514
virtual Color_t GetLineColor() const
Return the line color.
Definition: TAttLine.h:39
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=0)=0
Double_t fY2NDC
Y2 point in NDC coordinates.
Definition: TPave.h:29
static const double x1[5]
A Pave (see TPave) with text, lines or/and boxes inside.
Definition: TPaveText.h:27
#define ClassImp(name)
Definition: Rtypes.h:279
Double_t GetX1() const
Definition: TBox.h:64
double Double_t
Definition: RtypesCore.h:55
TText * text
virtual void Print(Option_t *option="") const
Dump this pavetext with its attributes.
Definition: TPaveText.cxx:566
unsigned long ULong_t
Definition: RtypesCore.h:51
Double_t y[n]
Definition: legend1.C:17
virtual Color_t GetFillColor() const
Return the fill area color.
Definition: TAttFill.h:35
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:567
Double_t fX2NDC
X2 point in NDC coordinates.
Definition: TPave.h:28
virtual void AddAfter(const TObject *after, TObject *obj)
Insert object after object after in the list.
Definition: TList.cxx:221
Mother of all ROOT objects.
Definition: TObject.h:37
Bool_t IsReading() const
Definition: TStyle.h:290
TPave()
Pave default constructor.
Definition: TPave.cxx:35
virtual void Add(TObject *obj)
Definition: TList.h:81
Double_t GetX2() const
Definition: TLine.h:60
Definition: file.py:1
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
virtual void PaintPrimitives(Int_t mode)
Paint list of primitives in this pavetext.
Definition: TPaveText.cxx:403
#define gPad
Definition: TVirtualPad.h:289
virtual void SetTextColor(Color_t tcolor=1)
Set the text color.
Definition: TAttText.h:49
Double_t GetY2() const
Definition: TLine.h:62
Double_t GetY1() const
Definition: TBox.h:66
virtual void SetY(Double_t y)
Definition: TText.h:85
Double_t fY1NDC
Y1 point in NDC coordinates.
Definition: TPave.h:27
virtual void PaintPave(Double_t x1, Double_t y1, Double_t x2, Double_t y2, Int_t bordersize=4, Option_t *option="br")
Draw this pave with new coordinates.
Definition: TPave.cxx:294
virtual Style_t GetFillStyle() const
Return the fill area style.
Definition: TAttFill.h:36
virtual void SetTextSize(Float_t tsize=1)
Set the text size.
Definition: TAttText.h:52
virtual void Print(Option_t *option="") const
Default print for collections, calls Print(option, 1).
TString fOption
Pave style.
Definition: TPave.h:34
TPaveText & operator=(const TPaveText &)
assignment operator
Definition: TPaveText.cxx:118
virtual void PaintText(Double_t x, Double_t y, const char *text)
Draw this text with new coordinates.
Definition: TText.cxx:744
virtual void Paint(Option_t *option="")
Paint this pavelabel with its current attributes.
Definition: TPaveLabel.cxx:99
TPaveText()
pavetext default constructor.
Definition: TPaveText.cxx:50
char name[80]
Definition: TGX11.cxx:109
virtual void SetAllWith(const char *text, Option_t *option, Double_t value)
Set attribute option for all lines containing string text.
Definition: TPaveText.cxx:851
virtual Version_t ReadVersion(UInt_t *start=0, UInt_t *bcnt=0, const TClass *cl=0)=0
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:52
virtual void SaveLines(std::ostream &out, const char *name)
Save lines of this pavetext as C++ statements on output stream out.
Definition: TPaveText.cxx:658
Int_t GetBorderSize() const
Definition: TPave.h:55
const char * Data() const
Definition: TString.h:349