Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "TGo4MarkerPainter.h"
00015
00016 #include "TROOT.h"
00017 #include "TList.h"
00018 #include "TVirtualPad.h"
00019 #include "snprintf.h"
00020
00021 #include "TGo4Marker.h"
00022 #include "TH1.h"
00023
00024 TGo4MarkerPainter::TGo4MarkerPainter() :
00025 TGo4LabelPainter(),
00026 fxMarker(0),
00027 fxConnector(0),
00028 fbIsConStreamed(kTRUE)
00029 {
00030 }
00031
00032 TGo4MarkerPainter::TGo4MarkerPainter(const char* name, const char* title) :
00033 TGo4LabelPainter(name, title),
00034 fxMarker(0),
00035 fxConnector(0),
00036 fbIsConStreamed(kFALSE)
00037 {
00038 }
00039
00040 TGo4MarkerPainter::~TGo4MarkerPainter()
00041 {
00042 if (fxConnector!=0) {
00043 delete fxConnector;
00044 fxConnector = 0;
00045 }
00046 }
00047
00048
00049
00050 void TGo4MarkerPainter::PaintLabel(Option_t* opt)
00051 {
00052 if(gPad==0) return;
00053 if(fxMarker && fxMarker->HasLabel())
00054 {
00055
00056 Double_t xoff=0.015*(gPad->GetUxmax()-gPad->GetUxmin());
00057 Double_t yoff=0.015*(gPad->GetUymax()-gPad->GetUymin());
00058 Double_t xpmin=gPad->PadtoX(gPad->XtoPad(fxMarker->GetLabelX())+xoff);
00059 Double_t ypmin=gPad->PadtoY(gPad->YtoPad(fxMarker->GetLabelY())+yoff);
00060 Bool_t drx=fxMarker->IsXDraw();
00061 Bool_t dry=fxMarker->IsYDraw();
00062 Bool_t drxbin=fxMarker->IsXbinDraw();
00063 Bool_t drybin=fxMarker->IsYbinDraw();
00064 Bool_t drcont=fxMarker->IsContDraw();
00065 TString fmt=fxMarker->GetNumFormat();
00066 SetX0(xpmin);
00067 SetY0(ypmin);
00068 SetLineColor(fxMarker->GetMarkerColor());
00069
00070 TString cap=fxMarker->GetName();
00071 TH1* his=fxMarker->GetHistogram();
00072 if(his)
00073 {
00074 cap+=":";
00075 cap+=his->GetName();
00076 }
00077 SetCaption(cap.Data());
00078 TGo4LabelPainter::PaintLabel();
00079 if(drx)
00080 AddToLabel(Form(Form("X = %s",fmt.Data()),fxMarker->GetX()));
00081 if(dry)
00082 AddToLabel(Form(Form("Y = %s",fmt.Data()),fxMarker->GetY()));
00083 if(drxbin)
00084 AddToLabel(Form("Xbin = %d",fxMarker->GetXbin()));
00085 if(drybin)
00086 AddToLabel(Form("Ybin = %d",fxMarker->GetYbin()));
00087 if(drcont)
00088 AddToLabel(Form("C = %d",fxMarker->GetCont()));
00089 RePaintLabel();
00090 PaintConnector();
00091 }
00092 else
00093 {
00094 UnPaintLabel();
00095 }
00096 }
00097
00098 void TGo4MarkerPainter::UnPaintLabel(Option_t* opt)
00099 {
00100 if(gPad==0) return;
00101 TGo4LabelPainter::UnPaintLabel(opt);
00102 UnPaintConnector(opt);
00103 }
00104
00105
00106 Bool_t TGo4MarkerPainter::CheckConnector()
00107 {
00108 if(fbIsConStreamed && fxConnector!=0) {
00109
00110 fxConnector->SetOwner(this);
00111 fbIsConStreamed=kFALSE;
00112 return kTRUE;
00113 }
00114 if(TGo4LabelConnector::fxLastDeleted==(char*) fxConnector)
00115 {
00116
00117 TGo4LabelConnector::fxLastDeleted=0;
00118 fxConnector=0;
00119 return kFALSE;
00120 }
00121
00122
00123 return fxConnector!=0;
00124 }
00125
00126 void TGo4MarkerPainter::PaintConnector(Option_t* opt)
00127 {
00128 if(gPad==0) return;
00129 if(fxMarker && fxMarker->HasConnector()) {
00130 Double_t xmark=0;
00131 Double_t ymark=0;
00132 Double_t xmark0=fxMarker->GetX();
00133 Double_t ymark0=fxMarker->GetY();
00134 Double_t xlab,ylab;
00135 Double_t xlablo=GetLabelXlo();
00136 Double_t ylablo=GetLabelYlo();
00137 Double_t xlabup=GetLabelXup();
00138 Double_t ylabup=GetLabelYup();
00139 Double_t xlabmid=0.5*(xlabup+xlablo);
00140 Double_t ylabmid=0.5*(ylabup+ylablo);
00141 xlablo=gPad->PadtoX(xlablo);
00142 ylablo=gPad->PadtoY(ylablo);
00143 xlabup=gPad->PadtoX(xlabup);
00144 ylabup=gPad->PadtoY(ylabup);
00145 xlabmid=gPad->PadtoX(xlabmid);
00146 ylabmid=gPad->PadtoY(ylabmid);
00147
00148 if(TMath::Abs(xlablo-xmark0) < TMath::Abs(xlabup-xmark0))
00149 {
00150 if(TMath::Abs(xlablo-xmark0) < TMath::Abs(xlabmid-xmark0))
00151 xlab=xlablo;
00152 else
00153 xlab=xlabmid;
00154 }
00155 else
00156 {
00157 if(TMath::Abs(xlabup-xmark0) < TMath::Abs(xlabmid-xmark0))
00158 xlab=xlabup;
00159 else
00160 xlab=xlabmid;
00161 }
00162
00163 if(TMath::Abs(ylablo-ymark0) < TMath::Abs(ylabup-ymark0))
00164 {
00165 if(TMath::Abs(ylablo-ymark0) < TMath::Abs(ylabmid-ymark0))
00166 ylab=ylablo;
00167 else
00168 ylab=ylabmid;
00169 }
00170 else
00171 {
00172 if(TMath::Abs(ylabup-ymark0) < TMath::Abs(ylabmid-ymark0))
00173 ylab=ylabup;
00174 else
00175 ylab=ylabmid;
00176 }
00177
00178 Double_t f=0.92;
00179
00180 Double_t xmark_pad=0;
00181 Double_t ymark_pad=0;
00182 Double_t xlab_pad=gPad->XtoPad(xlab);
00183 Double_t ylab_pad=gPad->YtoPad(ylab);
00184 Double_t xmark0_pad=gPad->XtoPad(xmark0);
00185 Double_t ymark0_pad=gPad->YtoPad(ymark0);
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203 if(xlab_pad>xmark0_pad)
00204 xmark_pad=xlab_pad-f*(xlab_pad-xmark0_pad);
00205 else
00206 xmark_pad=xlab_pad+f*(xmark0_pad-xlab_pad);
00207 if(ylab_pad>ymark0_pad)
00208 ymark_pad=ylab_pad-f*(ylab_pad-ymark0_pad);
00209 else
00210 ymark_pad=ylab_pad+f*(ymark0_pad-ylab_pad);
00211
00212 xmark=gPad->PadtoX(xmark_pad);
00213 ymark=gPad->PadtoY(ymark_pad);
00214 if(!CheckConnector()) {
00215
00216 fxConnector=new TGo4LabelConnector(xmark,ymark,xlab,ylab);
00217 fxConnector->SetOwner(this);
00218 fxConnector->SetLineStyle(4);
00219 fxConnector->AppendPad();
00220 } else {
00221
00222 if (gPad->GetListOfPrimitives()->FindObject(fxConnector)==0)
00223 fxConnector->AppendPad();
00224 fxConnector->SetX1(xmark);
00225 fxConnector->SetY1(ymark);
00226 fxConnector->SetX2(xlab);
00227 fxConnector->SetY2(ylab);
00228 }
00229 fxConnector->SetLineColor(fxMarker->GetMarkerColor());
00230
00231 }
00232 else
00233 {
00234 UnPaintConnector(opt);
00235 }
00236 }
00237
00238 void TGo4MarkerPainter::UnPaintConnector(Option_t* opt)
00239 {
00240 TString option=opt;
00241 if(option.Contains("reset")) {
00242
00243 if(CheckConnector()) {
00244 delete fxConnector;
00245 fxConnector=0;
00246 }
00247 }
00248 }
00249
00250 void TGo4MarkerPainter::DisplayToFront(Option_t* opt)
00251 {
00252 UnPaintConnector();
00253 PaintConnector();
00254 if(fxMarker) fxMarker->TObject::Pop();
00255 TGo4LabelPainter::DisplayToFront(opt);
00256 }
00257
00258