PadZoomer.cc

00001 #include "PadZoomer.hh"
00002 #include "TCanvas.h"
00003 #include "TH1.h"
00004 #include "TGraph.h"
00005 #include "TMultiGraph.h"
00006 #include "TF1.h"
00007 #include "TExec.h"
00008 #include "TList.h"
00009 
00010 #include <string>
00011 
00012 void PadZoomer::Attach(TVirtualPad* pad) 
00013 {
00014   if(!pad) return;
00015   owner = pad;
00016   TList* execs = pad->GetListOfExecs();
00017   if(!execs){
00018     //this seems to be the only way to create the list...
00019     pad->AddExec("dummy","");
00020     execs = pad->GetListOfExecs();
00021     execs->SetOwner(true);
00022     execs->Clear();
00023   }
00024   TObject* oldcopy = execs->FindObject(GetName());
00025   if(oldcopy){
00026     execs->Remove(oldcopy);
00027     delete oldcopy;
00028   }
00029   SetBit(kCanDelete,true);
00030   execs->Add(this);
00031   //also add capability to sub-pads
00032   TList* owned = pad->GetListOfPrimitives();
00033   if(owned){
00034     for(int i=0; i<owned->GetSize(); ++i){
00035       if(owned->At(i)->InheritsFrom(TVirtualPad::Class()))
00036         new PadZoomer((TVirtualPad*)(owned->At(i)));
00037     }
00038   }
00039 }
00040 
00041 void PadZoomer::Exec(const char*)
00042 {
00043   if(!owner || owner->GetEvent() != 61)
00044     return;
00045   
00046   const TObject* selected = owner->GetSelected();
00047   if(!selected) 
00048     return;
00049   std::string drawopt = selected->GetDrawOption();
00050   if(selected->InheritsFrom(TH1::Class()) || 
00051      selected->InheritsFrom(TGraph::Class()) ||
00052      selected->InheritsFrom(TF1::Class()) ){
00053     if(selected->InheritsFrom(TGraph::Class())) {
00054       //TGraphs may belong to a TMultiGraph, so look to it for draw option
00055       TList* primitives = owner->GetListOfPrimitives();
00056       for(int i=0; i < primitives->GetSize(); ++i){
00057         TObject* prim = primitives->At(i);
00058         if(prim->InheritsFrom(TMultiGraph::Class()) &&
00059            ((TMultiGraph*)prim)->GetListOfGraphs()->FindObject(selected)){
00060           //prim owns selected
00061           drawopt = ((TMultiGraph*)prim)->
00062             GetGraphDrawOption((const TGraph*)selected);
00063           if(drawopt=="")
00064             drawopt = prim->GetDrawOption();
00065         }
00066       }
00067       //graph might still need to have the 'a' for 'axes' appended
00068       if(drawopt.find('a')==std::string::npos)
00069         drawopt.append("a");
00070     }
00071     size_t pos = drawopt.find("same");
00072     if(pos != std::string::npos){
00073       drawopt.erase(pos,4);
00074     }
00075   }
00076   else{
00077     //if we get here, we want to copy the whole sub-pad
00078     //but don't copy full-size pads!
00079     if(owner->InheritsFrom(TCanvas::Class()) || 
00080        owner->GetCanvas()->GetListOfPrimitives()->GetSize()==1)
00081       return;
00082     selected = owner;
00083   }
00084   TCanvas* c = new TCanvas;
00085   c->cd(0);
00086   c->Update(); //<why do I have to do this?
00087   TObject* newobj = selected->DrawClone(drawopt.c_str());
00088   newobj->SetBit(kCanDelete,true);
00089   if(selected == owner){
00090     TVirtualPad* newpad = (TVirtualPad*)newobj;
00091     newpad->SetPad(0,0,1,1);
00092     new PadZoomer(newpad);
00093   }
00094     
00095   return;
00096 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines

Generated on 20 Jun 2014 for daqman by  doxygen 1.6.1