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