Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

TGo4MarkerPainter.cxx

Go to the documentation of this file.
00001 //-------------------------------------------------------------
00002 //        Go4 Release Package v3.04-01 (build 30401)
00003 //                      28-November-2008
00004 //---------------------------------------------------------------
00005 //   The GSI Online Offline Object Oriented (Go4) Project
00006 //   Experiment Data Processing at EE 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 "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       //------ find out initial coordinates for labels near marker boundaries:
00062       Double_t xoff=0.015*(gPad->GetUxmax()-gPad->GetUxmin());
00063       Double_t yoff=0.015*(gPad->GetUymax()-gPad->GetUymin()); // offset is in pad coordinates
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); // initial coordinates are real axis coordinates
00074       SetLineColor(fxMarker->GetMarkerColor());
00075       //SetTextColor(fxMarker->GetMarkerColor());
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();// this creates new label
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    }//if(fxMarker && fxMarker->HasLabel())
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        // case of Connector was streamed from file: not yet in cleanup list!
00131        fxConnector->SetOwner(this);
00132        fbIsConStreamed=kFALSE;
00133        return kTRUE;
00134    }
00135     if(TGo4LabelConnector::fxLastDeleted==(char*) fxConnector) 
00136       {
00137          // our label was deleted by user mouse menu just before
00138          TGo4LabelConnector::fxLastDeleted=0;
00139          fxConnector=0; // reset reference, will re-create label on next paint
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       // evaluate connection to nearest label edge or side centre:
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       // offset from marker center:
00199       Double_t f=0.92; // fraction of direct distance between marker and label
00200       // we calculate connector geometry in pad coordinates for log scale!
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 //      if(gPad->GetLogx() || gPad->GetLogy())
00208 //         {
00209 //            //cout <<"using percentage for f" << endl;
00210 //            f=0.95;
00211 //         }
00212 //      else
00213 //         {
00214 //            // note: this method only works if we have equal axis scaling in x and y!
00215 //            //cout <<"using roff for f" << endl;
00216 //            Double_t dr=TMath::Sqrt(TMath::Power(xlab-xmark0,2) + TMath::Power(ylab-ymark0,2));
00217 //            Size_t msize=fxMarker->GetMarkerSize();
00218 //            Double_t xoff=0.008*msize*(gPad->GetUxmax()-gPad->GetUxmin());
00219 //            Double_t yoff=0.008*msize*(gPad->GetUymax()-gPad->GetUymin());
00220 //            Double_t roff= TMath::Sqrt(TMath::Power(xoff,2) + TMath::Power(yoff,2));
00221 //            if(dr) f=1- roff/dr;// we do it relative to marker size
00222 //         }
00223 //      cout <<"f="<<f << endl;
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); // back to real axis coordinates
00234       ymark=gPad->PadtoY(ymark_pad);
00235       if(!CheckConnector()) {
00236          // connection line not existing or deleted by root:
00237          fxConnector=new TGo4LabelConnector(xmark,ymark,xlab,ylab);
00238          fxConnector->SetOwner(this);
00239          fxConnector->SetLineStyle(4);
00240          fxConnector->AppendPad();
00241       } else {
00242          // connection line is still exisiting:
00243          if (gPad->GetListOfPrimitives()->FindObject(fxConnector)==0)
00244             fxConnector->AppendPad();// connection line was removed from pad, we redraw it:
00245          fxConnector->SetX1(xmark);
00246          fxConnector->SetY1(ymark);
00247          fxConnector->SetX2(xlab);
00248          fxConnector->SetY2(ylab);
00249       }
00250       fxConnector->SetLineColor(fxMarker->GetMarkerColor());
00251       //fxConnector->Paint(); // for direct update of view
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       // case of reset option: discard old connector line style
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(); // pop line to front if enabled
00275 if(fxMarker) fxMarker->TObject::Pop(); // then pop marker
00276 TGo4LabelPainter::DisplayToFront(opt); // label itself will be frontmost
00277 }
00278 
00279 
00280 
00281 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Fri Nov 28 12:59:06 2008 for Go4-v3.04-1 by  doxygen 1.4.2