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