/home/cern/BDSIM_new/utils/display/BDSCanvas.C

00001 /* Display for BDSIM code     
00002 Author: Olivier Dadoun, Laboratoire de l'Accelerateur Lineaire (LAL-IN2P3), Orsay (France)
00003 <mailto:> dadoun@lal.in2p3.fr, 2005
00004 Last modified 23.11.2005
00005 */
00006 #include <iostream>
00007 
00008 #ifndef ROOT_TGaxis
00009 #include "TGaxis.h"
00010 #endif
00011 
00012 #ifndef ROOT_TClassMenuItem
00013 #include "TClassMenuItem.h"
00014 #endif
00015 
00016 #include "BDSConstant.h"
00017 #include "BDSCanvas.h"
00018 #include "BDSPad.h"
00019 #include "BDSParser.h"
00020 ClassImp(BDSCanvas) 
00021 
00022 Int_t px1old,py1old,px2old,py2old;      
00023 BDSCanvas::BDSCanvas(char* opticfile):TCanvas("BDSIMBrowser","BDSIM ROOT Framework",10,10,800,600)
00024 {               
00025         this->cd();     
00026         TPad *info = new TPad("info", "this info pad", 0., 0.,1.,1,0);
00027         info->Draw();
00028         info->cd();
00029         UserInfo(opticfile);
00030         
00031         this->cd();
00032         line = new BDSPad(this,"line","this a line", 0.,0.75,1.,1,0);
00033    this->cd();  
00034         plot = new TPad("plot", "this a plot", 0., 0.05,1.,0.75,0);
00035         plot->SetLeftMargin(xmin_axis_position);
00036         plot->SetRightMargin(1.-xmax_axis_position);
00037         plot->Draw();
00038 
00039         BDSParser parser;
00040         parser.LoadFile(line,opticfile);
00041         plot->cd();
00042         plot->AddExec("ex","BDSCanvas::AxisClickedCB()");
00043 }
00044 BDSCanvas::~BDSCanvas()
00045 {
00046         if(line != NULL) delete line;   
00047         if(plot != NULL) delete plot;   
00048         if(h2 != NULL) delete h2;
00049 }
00050 
00051 void BDSCanvas::AxisClickedCB()
00052 {
00053         ((BDSCanvas*)gPad->GetCanvas())->AxisClicked();
00054 }
00055 
00056 void BDSCanvas::AxisClicked()
00057 {
00058         int event = plot->GetEvent();
00059         //else Box don't disappear
00060         TGaxis *plot_axis;
00061         plot_axis = (TGaxis*)line->GetAxis();
00062         TObject *select = plot->GetSelected();
00063         
00064         if (!select || !select->InheritsFrom("TAxis")) return;
00065         
00066         if (event == kButton1Down)
00067         {
00068         //Draw the virtual box (always this in ROOT when you ZOOM )
00069                 px1old = GetEventX();
00070                 py1old = 116;
00071                 px2old = px1old;
00072                 py2old = 16;
00073                 gVirtualX->DrawBox(px1old,py1old,px2old,py2old,TVirtualX::kHollow);
00074                 gVirtualX->SetLineColor(-1);
00075         }
00076         
00077         if(event == kButton1Motion)
00078         {
00079         gVirtualX->DrawBox(px1old,py1old,px2old,py2old,TVirtualX::kHollow);
00080         px2old = GetEventX();
00081         gVirtualX->DrawBox(px1old,py1old,px2old,py2old,TVirtualX::kHollow);
00082         }
00083                                                                                 
00084         //Need this: update plot before line 
00085         if(event == kButton1Up)gPad->Update();
00086         xmin=gPad->GetUxmin();
00087         xmax=gPad->GetUxmax();
00088 
00089         plot_axis->SetWmax(xmax);
00090         plot_axis->SetWmin(xmin);
00091         line->UpdateLine(xmin,xmax);                            
00092         line->Modified(kTRUE);
00093         
00094         //Double Click = Unzoom
00095         if(event == 61 || event == 62 || event == 63 )
00096         {
00097                 TH1F *ax = ((BDSCanvas*)gPad->GetCanvas())->GetHisto();
00098                 if(ax)
00099                 {
00100                         ax->SetAxisRange(BDSPad::get_xmin_axis(),BDSPad::get_xmax_axis());
00101                         gPad->Modified(kTRUE);
00102                 }
00103                 
00104                 TH2F   *ax2 = (TH2F*)((BDSPad*)gPad->GetPrimitive("temp"));
00105                 if(ax2)
00106                 {
00107                         ax2->SetAxisRange(BDSPad::get_xmin_axis(),BDSPad::get_xmax_axis());
00108                         gPad->Modified(kTRUE);
00109                 }
00110                 
00111                 BDSCanvas *bro =(BDSCanvas*)gPad->GetCanvas();
00112                 bro->GetLine()->UpdateLine(BDSPad::get_xmin_axis(),BDSPad::get_xmax_axis());
00113                 bro->GetLine()->Modified(kTRUE);
00114         }
00115 }
00116 
00117 
00118 void BDSCanvas::UserInfo(char* _path){
00119         TString date;
00120         TString user;
00121         TString temp;
00122         FILE *fp = gSystem->OpenPipe("date", "r");
00123         date.Gets(fp);
00124         gSystem->ClosePipe(fp);
00125         fp = gSystem->OpenPipe("echo $USER","r");
00126         user.Gets(fp);
00127         temp = user + ", " + date;
00128     TText *infodate = new TText(0.015,0.011,temp);
00129     infodate->SetTextSize(0.02);
00130     infodate->Draw();
00131 
00132         temp = "BDSIM input file : " ;
00133         temp= temp + Form(_path);
00134         TText *infooptics=new TText(0.7,0.011,temp);
00135         infooptics->SetTextSize(0.02);
00136         infooptics->Draw();
00137 }

Generated on Wed Mar 5 17:25:25 2008 for BDSIM by  doxygen 1.5.3