Logo ROOT  
Reference Guide
TLegendEntry.cxx
Go to the documentation of this file.
1 // @(#)root/graf:$Id$
2 // Author: Matthew.Adam.Dobbs 06/09/99
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 <stdio.h>
13 
14 #include "TLegendEntry.h"
15 #include "TVirtualPad.h"
16 #include "TROOT.h"
17 #include <iostream>
18 
20 
21 /** \class TLegendEntry
22 \ingroup BasicGraphics
23 
24 Storage class for one entry of a TLegend.
25 */
26 
27 ////////////////////////////////////////////////////////////////////////////////
28 /// TLegendEntry do-nothing default constructor
29 
31 {
32  fObject = 0;
33 }
34 
35 ////////////////////////////////////////////////////////////////////////////////
36 /// TLegendEntry normal constructor for one entry in a TLegend.
37 ///
38 /// obj is the object this entry will represent. If obj has
39 /// line/fill/marker attributes, then the TLegendEntry will display
40 /// these attributes.
41 ///
42 /// label is the text that will describe the entry, it is displayed using
43 /// TLatex, so may have a complex format.
44 ///
45 /// option may have values
46 /// - L draw line associated w/ TAttLine if obj inherits from TAttLine
47 /// - P draw polymarker assoc. w/ TAttMarker if obj inherits from TAttMarker
48 /// - F draw a box with fill associated w/ TAttFill if obj inherits TAttFill
49 /// default is object = "LPF"
50 
51 TLegendEntry::TLegendEntry(const TObject* obj, const char* label, Option_t* option )
52  :TAttText(0,0,0,0,0), TAttLine(1,1,1), TAttFill(0,0), TAttMarker(1,21,1)
53 {
54  fObject = 0;
55  if ( !label && obj ) fLabel = obj->GetTitle();
56  else fLabel = label;
57  fOption = option;
58  if (obj) SetObject((TObject*)obj);
59 }
60 
61 ////////////////////////////////////////////////////////////////////////////////
62 /// TLegendEntry copy constructor
63 
64 TLegendEntry::TLegendEntry( const TLegendEntry &entry ) : TObject(entry), TAttText(entry), TAttLine(entry), TAttFill(entry), TAttMarker(entry)
65 {
66  ((TLegendEntry&)entry).Copy(*this);
67 }
68 
69 ////////////////////////////////////////////////////////////////////////////////
70 /// TLegendEntry default destructor
71 
73 {
74  fObject = 0;
75 }
76 
77 ////////////////////////////////////////////////////////////////////////////////
78 /// copy this TLegendEntry into obj
79 
80 void TLegendEntry::Copy( TObject &obj ) const
81 {
82  TObject::Copy(obj);
87  ((TLegendEntry&)obj).fObject = fObject;
88  ((TLegendEntry&)obj).fLabel = fLabel;
89  ((TLegendEntry&)obj).fOption = fOption;
90 }
91 
92 ////////////////////////////////////////////////////////////////////////////////
93 /// dump this TLegendEntry to std::cout
94 
96 {
98  std::cout << "TLegendEntry: Object ";
99  if ( fObject ) output = fObject->GetName();
100  else output = "NULL";
101  std::cout << output << " Label ";
102  if ( fLabel ) output = fLabel.Data();
103  else output = "NULL";
104  std::cout << output << " Option ";
105  if (fOption ) output = fOption.Data();
106  else output = "NULL";
107  std::cout << output << std::endl;
108 }
109 
110 ////////////////////////////////////////////////////////////////////////////////
111 /// Save this TLegendEntry as C++ statements on output stream out
112 /// to be used with the SaveAs .C option
113 
114 void TLegendEntry::SaveEntry(std::ostream &out, const char* name )
115 {
116  char quote = '"';
117  if ( gROOT->ClassSaved( TLegendEntry::Class() ) ) {
118  out << " entry=";
119  } else {
120  out << " TLegendEntry *entry=";
121  }
122  TString objname = "NULL";
123  if ( fObject ) objname = fObject->GetName();
124  TString tL(fLabel);
125  tL.ReplaceAll("\\","\\\\");
126  tL.ReplaceAll("\"","\\\"");
127  out << name << "->AddEntry("<<quote<<objname<<quote<<","<<quote<<
128  tL.Data()<<quote<<","<<quote<<fOption.Data()<<quote<<");"<<std::endl;
129  SaveFillAttributes(out,"entry",0,0);
130  SaveLineAttributes(out,"entry",0,0,0);
131  SaveMarkerAttributes(out,"entry",0,0,0);
132  SaveTextAttributes(out,"entry",0,0,0,0,0);
133 }
134 
135 ////////////////////////////////////////////////////////////////////////////////
136 /// (re)set the obj pointed to by this entry
137 
139 {
140  if ( ( fObject && fLabel == fObject->GetTitle() ) || !fLabel ) {
141  if (obj) fLabel = obj->GetTitle();
142  }
143  fObject = obj;
144 }
145 
146 ////////////////////////////////////////////////////////////////////////////////
147 /// (re)set the obj pointed to by this entry
148 
149 void TLegendEntry::SetObject( const char* objectName)
150 {
151  TObject* obj = 0;
152  TList* padprimitives = gPad->GetListOfPrimitives();
153  if (padprimitives) obj = padprimitives->FindObject( objectName );
154  if (obj) SetObject( obj );
155 }
TAttText
Text Attributes class.
Definition: TAttText.h:18
TLegendEntry::TLegendEntry
TLegendEntry()
TLegendEntry do-nothing default constructor.
Definition: TLegendEntry.cxx:30
Option_t
const char Option_t
Definition: RtypesCore.h:66
TLegendEntry::SaveEntry
virtual void SaveEntry(std::ostream &out, const char *name)
Save this TLegendEntry as C++ statements on output stream out to be used with the SaveAs ....
Definition: TLegendEntry.cxx:114
TLegendEntry::fOption
TString fOption
Options associated with this entry.
Definition: TLegendEntry.h:45
TList::FindObject
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
Definition: TList.cxx:578
TString::Data
const char * Data() const
Definition: TString.h:369
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
TLegendEntry::Print
virtual void Print(Option_t *option="") const
dump this TLegendEntry to std::cout
Definition: TLegendEntry.cxx:95
output
static void output(int code)
Definition: gifencode.c:226
TAttMarker::Copy
void Copy(TAttMarker &attmarker) const
Copy this marker attributes to a new TAttMarker.
Definition: TAttMarker.cxx:235
TAttText::SaveTextAttributes
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:344
TAttText::Copy
void Copy(TAttText &atttext) const
Copy this text attributes to a new TAttText.
Definition: TAttText.cxx:291
TAttLine::SaveLineAttributes
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:270
TLegendEntry::SetObject
virtual void SetObject(TObject *obj)
(re)set the obj pointed to by this entry
Definition: TLegendEntry.cxx:138
TObject::GetTitle
virtual const char * GetTitle() const
Returns title of object.
Definition: TObject.cxx:403
TString
Basic string class.
Definition: TString.h:136
TAttFill::SaveFillAttributes
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:234
TString::ReplaceAll
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:692
TROOT.h
TObject::GetName
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:359
TAttLine::Copy
void Copy(TAttLine &attline) const
Copy this line attributes to a new TAttLine.
Definition: TAttLine.cxx:172
TAttMarker::SaveMarkerAttributes
virtual void SaveMarkerAttributes(std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1, Int_t sizdef=1)
Save line attributes as C++ statement(s) on output stream out.
Definition: TAttMarker.cxx:339
TLegendEntry.h
TAttFill::Copy
void Copy(TAttFill &attfill) const
Copy this fill attributes to a new TAttFill.
Definition: TAttFill.cxx:202
TAttLine
Line Attributes class.
Definition: TAttLine.h:18
TLegendEntry::fObject
TObject * fObject
pointer to object being represented by this entry
Definition: TLegendEntry.h:43
TLegendEntry
Storage class for one entry of a TLegend.
Definition: TLegendEntry.h:25
TAttMarker
Marker Attributes class.
Definition: TAttMarker.h:19
TVirtualPad.h
TLegendEntry::fLabel
TString fLabel
Text associated with the entry, will become latex.
Definition: TLegendEntry.h:44
TObject
Mother of all ROOT objects.
Definition: TObject.h:37
TLegendEntry::~TLegendEntry
virtual ~TLegendEntry()
TLegendEntry default destructor.
Definition: TLegendEntry.cxx:72
name
char name[80]
Definition: TGX11.cxx:110
gPad
#define gPad
Definition: TVirtualPad.h:287
TObject::Copy
virtual void Copy(TObject &object) const
Copy this to obj.
Definition: TObject.cxx:63
TAttFill
Fill Area Attributes class.
Definition: TAttFill.h:19
Class
void Class()
Definition: Class.C:29
TLegendEntry::Copy
virtual void Copy(TObject &obj) const
copy this TLegendEntry into obj
Definition: TLegendEntry.cxx:80
TList
A doubly linked list.
Definition: TList.h:44
gROOT
#define gROOT
Definition: TROOT.h:406