Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

/Go4ConditionsBase/TGo4MarkerPainter.cxx

Go to the documentation of this file.
00001 //---------------------------------------------------------------
00002 //        Go4 Release Package v2.10-5 (build 21005) 
00003 //                      03-Nov-2005
00004 //---------------------------------------------------------------
00005 //       The GSI Online Offline Object Oriented (Go4) Project
00006 //       Experiment Data Processing at DVEE department, GSI
00007 //---------------------------------------------------------------
00008 //
00009 //Copyright (C) 2000- Gesellschaft f. Schwerionenforschung, GSI
00010 //                    Planckstr. 1, 64291 Darmstadt, Germany
00011 //Contact:            http://go4.gsi.de
00012 //----------------------------------------------------------------
00013 //This software can be used under the license agreements as stated
00014 //in Go4License.txt file which is part of the distribution.
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       //------ find out initial coordinates for labels near marker boundaries:
00056       Double_t xoff=0.015*(gPad->GetUxmax()-gPad->GetUxmin());
00057       Double_t yoff=0.015*(gPad->GetUymax()-gPad->GetUymin()); // offset is in pad coordinates
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); // initial coordinates are real axis coordinates
00068       SetLineColor(fxMarker->GetMarkerColor());
00069       //SetTextColor(fxMarker->GetMarkerColor());
00070       SetCaption(fxMarker->GetName());
00071       TGo4LabelPainter::PaintLabel();// this creates new label
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    }//if(fxMarker && fxMarker->HasLabel())
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     // case of Connector was streamed from file: not yet in cleanup list!
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       // evaluate connection to nearest label edge or side centre:
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       // offset from marker center:
00187       Double_t f=0.92; // fraction of direct distance between marker and label
00188       // we calculate connector geometry in pad coordinates for log scale!
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 //      if(gPad->GetLogx() || gPad->GetLogy())
00196 //         {
00197 //            //cout <<"using percentage for f" << endl;
00198 //            f=0.95;
00199 //         }
00200 //      else
00201 //         {
00202 //            // note: this method only works if we have equal axis scaling in x and y!
00203 //            //cout <<"using roff for f" << endl;
00204 //            Double_t dr=TMath::Sqrt(TMath::Power(xlab-xmark0,2) + TMath::Power(ylab-ymark0,2));
00205 //            Size_t msize=fxMarker->GetMarkerSize();
00206 //            Double_t xoff=0.008*msize*(gPad->GetUxmax()-gPad->GetUxmin());
00207 //            Double_t yoff=0.008*msize*(gPad->GetUymax()-gPad->GetUymin());
00208 //            Double_t roff= TMath::Sqrt(TMath::Power(xoff,2) + TMath::Power(yoff,2));
00209 //            if(dr) f=1- roff/dr;// we do it relative to marker size
00210 //         }
00211 //      cout <<"f="<<f << endl;
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); // back to real axis coordinates
00222       ymark=gPad->PadtoY(ymark_pad);
00223       if(!CheckConnector())
00224          {
00225 
00226             // connection line not existing or deleted by root:
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             // connection line is still exisiting:
00236             if(gPad->GetListOfPrimitives()->FindObject(fxConnector)==0)
00237                fxConnector->AppendPad();// connection line was removed from pad, we redraw it:
00238             fxConnector->SetX1(xmark);
00239             fxConnector->SetY1(ymark);
00240             fxConnector->SetX2(xlab);
00241             fxConnector->SetY2(ylab);
00242          }
00243       fxConnector->SetLineColor(fxMarker->GetMarkerColor());
00244       //fxConnector->Paint(); // for direct update of view
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       // case of reset option: discard old connector line style
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 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Tue Nov 8 10:55:52 2005 for Go4-v2.10-5 by doxygen1.2.15