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

TGo4WinCondPainter.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 "TGo4WinCondPainter.h"
00017 
00018 #include "Riostream.h"
00019 
00020 #include "TVirtualPad.h"
00021 #include "RVersion.h"
00022 #include "TList.h"
00023 #include "TROOT.h"
00024 
00025 #include "TGo4WinCond.h"
00026 #include "TGo4WinCondView.h"
00027 
00028 TGo4WinCondPainter::TGo4WinCondPainter() :
00029    TGo4ConditionPainter(),
00030    fxBox(0)
00031 {
00032 }
00033 
00034 TGo4WinCondPainter::TGo4WinCondPainter(const char* name, const char* title) :
00035    TGo4ConditionPainter(name,title),
00036    fxBox(0)
00037 {
00038 }
00039 
00040 TGo4WinCondPainter::~TGo4WinCondPainter()
00041 {
00042    UnPaintCondition();
00043    if (fxBox!=0) {
00044       delete fxBox;
00045       fxBox = 0;
00046    }
00047 }
00048 
00049 
00050 void TGo4WinCondPainter::PaintCondition(Option_t* opt)
00051 {
00052 if(gPad==0) return;
00053 //cout <<"WinCondPainter PaintCondition on gPad "<<gPad << endl;
00054 double xpmin=0;
00055 double xpmax=0;
00056 double ypmin=0;
00057 double ypmax=0;
00058 int dim=0;
00059 TGo4WinCond* wconny=dynamic_cast<TGo4WinCond*>(fxCondition);
00060 if(wconny && wconny->IsVisible())
00061    {
00062       wconny->GetValues(dim, xpmin, xpmax, ypmin, ypmax);
00063 
00064       // for loaded window conditions, we have to correct limits
00065       // otherwise, this would yield wrong statistics from work histogram
00066       // root would correct box limits only on first edge resize!
00067       if(xpmin>xpmax)
00068             {
00069                if(wconny->GetDimension()>1) // keep dimension!
00070                   wconny->SetValues(xpmax, xpmin, ypmin, ypmax );
00071                else
00072                   wconny->SetValues(xpmax, xpmin);
00073             }
00074       if(ypmin>ypmax)
00075             {
00076                if(wconny->GetDimension()>1) // keep dimension!
00077                   wconny->SetValues(xpmin, xpmax, ypmax, ypmin );
00078             }
00079 
00080 //      cout <<"\nBefore toPad:"<< endl;
00081 //      cout <<" xpmin="<<xpmin << endl;
00082 //      cout <<" xpmax="<<xpmax << endl;
00083 //      cout <<" ypmin="<<ypmin << endl;
00084 //      cout <<" ypmax="<<ypmax << endl;
00085 
00086 // note: newer root versions treat log scale correctly in TBox
00087 #if ROOT_VERSION_CODE < ROOT_VERSION(4,3,2)
00088 
00089 // #if __GO4ROOTVERSION__ < 40302
00090 
00091       xpmin=gPad->XtoPad(xpmin); // for case of log scale
00092       xpmax=gPad->XtoPad(xpmax);
00093       if(dim==1)
00094          {
00095             ypmin =gPad->GetUymin();
00096             ypmax =gPad->GetUymax();
00097          }
00098       else
00099          {
00100             ypmin=gPad->YtoPad(ypmin);
00101             ypmax=gPad->YtoPad(ypmax);
00102          }
00103 
00104 #else
00105       if(dim==1)
00106          {
00107             ypmin=gPad->PadtoY(gPad->GetUymin());
00108             ypmax=gPad->PadtoY(gPad->GetUymax());
00109          }
00110 #endif //__GO4ROOTVERSION__ < 40302
00111 
00112       if(fxBox==0 || gPad->GetListOfPrimitives()->FindObject(fxBox)==0)
00113       // user might have deleted box from pad by mouse even if fxBox!=0
00114          {
00115             fxBox= new TGo4WinCondView(xpmin,ypmin,xpmax, ypmax);
00116          }
00117       else
00118          {
00119              fxBox->SetX1(xpmin);
00120              fxBox->SetY1(ypmin);
00121              fxBox->SetX2(xpmax);
00122              fxBox->SetY2(ypmax);
00123          }
00124       fxBox->SetCondition(wconny);
00125       if(!strcmp(opt,"fixstyle"))
00126          {
00127             // reproduce condition colors always
00128             // this mode will prevent the user from changing box color interactively
00129             fxBox->SetLineWidth(wconny->GetLineWidth());
00130             fxBox->SetLineColor(wconny->GetLineColor());
00131             fxBox->SetLineStyle(wconny->GetLineStyle());
00132             fxBox->SetFillColor(wconny->GetFillColor());
00133             fxBox->SetFillStyle(wconny->GetFillStyle());
00134          }
00135       if(gPad->GetListOfPrimitives()->FindObject(fxBox)==0)
00136          {
00137             fxBox->SetLineWidth(wconny->GetLineWidth());
00138             fxBox->SetLineColor(wconny->GetLineColor());
00139             fxBox->SetLineStyle(wconny->GetLineStyle());
00140             fxBox->SetFillColor(wconny->GetFillColor());
00141             fxBox->SetFillStyle(wconny->GetFillStyle());
00142             fxBox->AppendPad(); // only append to pad if not already there
00143                                 // this is necessary for the Pop() in array painter
00144             //cout <<"TGo4WinCondPainter::PaintCondition appended box for condition "<<wconny->GetName() << endl;
00145          }
00146         fxBox->Paint(); // for condarrays
00147         //cout <<"------WinCondPainter "<< GetName() <<"PaintCondition has painted box." << endl;
00148 
00149    }// if(wconny && wconny->IsVisible())
00150 else
00151    {
00152       UnPaintCondition();
00153    }
00154 }
00155 
00156 void TGo4WinCondPainter::UnPaintCondition(Option_t* opt)
00157 {
00158    gROOT->GetListOfCanvases()->RecursiveRemove(fxBox);
00159    // we do not delete view, but restore graphics properties though invisible
00160    TString option(opt);
00161    if(option.Contains("reset")) {
00162       // case of reset option: discard old label geometry
00163       delete fxBox;
00164       fxBox=0;
00165    }
00166 }
00167 
00168 void TGo4WinCondPainter::DisplayToFront(Option_t* opt)
00169 {
00170    if(fxBox) fxBox->Pop(); // box to front
00171    TGo4LabelPainter::DisplayToFront(opt); // label itself will be frontmost
00172 }
00173 
00174 //----------------------------END OF GO4 SOURCE FILE ---------------------

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