Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

TridPageDisplay.cxx

Go to the documentation of this file.
00001 
00002 #include "TridPageDisplay.h"
00003 #include "Midad/Base/PageProxy.h"
00004 #include "Midad/Base/PageABC.h"
00005 #include "Midad/Base/RunSnarlEntry.h"
00006 #include "Midad/Base/TimeHist.h"
00007 #include "Midad/Base/DigitText.h"
00008 #include "Midad/Base/MCText.h"
00009 #include "Midad/Base/MCTree.h"
00010 #include "Midad/Base/PmtPixels.h"
00011 #include "Midad/Base/Mint.h"
00012 
00013 
00014 #include <Midad/Gui/GuiMenu.h>
00015 #include <Midad/Gui/GuiBox.h>
00016 #include <Midad/Gui/GuiStatusBar.h>
00017 #include <Midad/Gui/GuiTab.h>
00018 #include <Midad/Gui/GuiFrame.h>
00019 #include <Midad/Gui/GuiButton.h>
00020 #include <Midad/Gui/GuiMainWindow.h>
00021 #include <Midad/Gui/GuiTextView.h>
00022 #include <Midad/Gui/GuiTree.h>
00023 #include <Midad/Gui/GuiSlider.h>
00024 #include <Midad/Gui/GuiCanvas.h>
00025 #include <Midad/Gui/GuiScrolled.h>
00026 #include <Midad/Gui/GuiLabel.h>
00027 #include <Midad/Gui/GuiTextEntry.h>
00028 
00029 #include <JobControl/JobC.h>
00030 
00031 #include <MessageService/MsgService.h>
00032 
00033 #include <TCanvas.h>
00034 #include <TGFileDialog.h>
00035 #include <TROOT.h>
00036 #include <TSystem.h>
00037 #include <TEnv.h>
00038 #include <TTimer.h>
00039 
00040 #include <sigc++/sigc++.h>
00041 #include <sigc++/class_slot.h>
00042 #include <sigc++/retype_return.h>
00043 using namespace SigC;
00044 
00045 #include <iostream>
00046 #include <vector>
00047 using namespace std;
00048 
00049 CVSID("$Id: TridPageDisplay.cxx,v 1.10 2005/09/28 10:17:40 tagg Exp $");
00050 
00051 ClassImp(TridPageDisplay)
00052 
00053 class AutoEventTimer : public TTimer
00054 {
00055 public:
00056   AutoEventTimer(Float_t delay) :
00057     fAutoNextDelay(delay) {};
00058   Bool_t Notify() {
00059     //cout << "Auto-advancing..." << endl;
00060     gMint->Next();
00061     Start((Long_t)(fAutoNextDelay*1000.),true);
00062     return true;
00063   };
00064   
00065   Float_t fAutoNextDelay;
00066 };
00067 
00068 AutoEventTimer gAutoTimer(20.0);
00069 
00070 
00071 static void toggle_free_run(TridPageDisplay* tpd, GuiTextButton* but)
00072 {
00073     TString label = but->GetString();
00074     if (label == "Start Auto") 
00075       tpd->SetAutoRun(true);
00076     else
00077       tpd->SetAutoRun(false);
00078 }
00079 
00080 
00081 TridPageDisplay::TridPageDisplay( TGWindow& parent, Mint* mint ) :
00082   PageDisplay(parent,mint),
00083   fAutoAdvanceTime(20)
00084 {
00085   MSG("TriD",Msg::kDebug) << "Running TridPageDisplay::Constructor()\n";
00086 } 
00087 
00088 TridPageDisplay::~TridPageDisplay( void )
00089 {
00090 }
00091 
00092 void TridPageDisplay::BuildGUI(const PageDisplayConfig& /*cfg*/)
00093 {
00094     MSG("TriD",Msg::kDebug) << "Running TridPageDisplay::BuildGUI()\n";
00095     // MENU
00096     this->SetupMenus();
00097 
00098     // Boxes:
00099     GuiBox* vbox = manage(new GuiBox(*this,kVerticalFrame));
00100     this->Add(*vbox);
00101 
00102     // RSE
00103     GuiHBox* hbox = manage(new GuiHBox(*vbox));
00104     vbox->Add(*hbox);
00105     GuiLabel* lab;
00106 
00107     lab = manage(new GuiLabel(*hbox,"Advance Time:"));
00108     hbox->Add(*lab);
00109     fAutoTimeEntry = manage(new GuiTextEntry(*hbox,Form("%f.0",fAutoAdvanceTime)));
00110     hbox->Add(*fAutoTimeEntry);
00111     fAutoTimeEntry->activated.connect
00112       (slot(*this,&TridPageDisplay::AutoTimeEntryHandler));
00113 
00114     lab = manage(new GuiLabel(*hbox,"Jump snarls:"));
00115     hbox->Add(*lab);
00116     fJumpEntry = manage(new GuiTextEntry(*hbox,""));
00117     hbox->Add(*fJumpEntry);
00118     fJumpEntry->activated.connect
00119       (slot(*this,&TridPageDisplay::JumpEntryHandler));
00120 
00121     lab = manage(new GuiLabel(*hbox,"Run:"));
00122     hbox->Add(*lab);
00123     fRunEntry = manage(new GuiTextEntry(*hbox,""));
00124     hbox->Add(*fRunEntry);
00125     fRunEntry->activated.connect
00126       (slot(*this,&TridPageDisplay::RunSnarlEntryHandler));
00127 
00128     lab = manage(new GuiLabel(*hbox,"Snarl:"));
00129     hbox->Add(*lab);
00130     fSnarlEntry = manage(new GuiTextEntry(*hbox,""));
00131     hbox->Add(*fSnarlEntry);
00132     fSnarlEntry->activated.connect
00133       (slot(*this,&TridPageDisplay::RunSnarlEntryHandler));
00134     
00135    
00136 
00137     // Button box
00138     fBBox = manage(new GuiBox(*vbox,kHorizontalFrame));
00139     fBBox->SetLayoutHints(kLHintsExpandX);
00140     vbox->Add(*fBBox);
00141     this->SetupButtons();
00142 
00143     // Tabs
00144     fTabs = manage(new GuiTab(*vbox));
00145     vbox->Add(*fTabs);
00146     fTabs->selected.connect(slot(*this,&PageDisplay::UpdateTab));
00147 
00148     // Sliders
00149     //this->SetupSliders();
00150 
00151     // status bar
00152     fStatusBar = manage(new GuiStatusBar(*this));
00153     this->Add(*fStatusBar);
00154 
00155 }
00156 
00157 static void my_add_to_window_menu(const char* name, GuiMenu* menu, TridPageDisplay* pd)
00158 {
00159     // This kludge is used to keep UserDisplay out of the menus.
00160     // UserDisplay is not a complete display and is intended to be
00161     // created and filled from a macro.
00162     if (string("UserCanvas") == name) return;
00163 
00164     menu->Add(name,retype_return<void>(bind(bind(slot(*pd,&TridPageDisplay::MySpawnSinglePage),500,400),name)));
00165 }
00166 
00167 static void die_die_die( void ) {
00168   gROOT->ProcessLine(".q");   // whatever
00169 }
00170 
00171 void TridPageDisplay::SetupMenus()
00172 {
00173     MSG("TriD",Msg::kDebug) << "Running TridPageDisplay::SetupMenus()\n";
00174     fMenuBar = manage(new GuiMenuBar(*this));
00175     this->Add(*fMenuBar);
00176 
00177     GuiMenu* file_menu = manage(new GuiMenu);
00178     fMenuBar->AddMenu(*file_menu,"File");
00179     file_menu->Add("Open...",slot(*this,&PageDisplay::OpenFile));
00180     file_menu->Add("Load Lib...",slot(*this,&PageDisplay::LoadLib));
00181     file_menu->Add("Print...",bind(slot(*this,&PageDisplay::Print),""));
00182     file_menu->Add("Close",close_window.slot());
00183     file_menu->Add("Quit",slot(die_die_die));
00184 
00185     GuiMenu* pages_menu = manage(new GuiMenu);
00186     fMenuBar->AddMenu(*pages_menu,"Windows");
00187     
00188     vector<const char*> page_names = PageProxyBase::GetRegisteredNames();
00189     for (unsigned int ind = 0; ind < page_names.size(); ++ind) {
00190         my_add_to_window_menu(page_names[ind],pages_menu,this);
00191     }
00192     PageProxyBase::page_added.connect(bind(bind(slot(my_add_to_window_menu),this),pages_menu));
00193     pages_menu->Add(0);
00194 
00195     GuiMenu* view_menu = manage(new GuiMenu);
00196     fMenuBar->AddMenu(*view_menu,"Views");
00197     view_menu->Add("3D Geometry",slot(*this,&PageDisplay::DrawGeometry));    
00198     view_menu->Add("Digit text",slot(*this,&PageDisplay::MakeDigitText));
00199     view_menu->Add("Time hist",slot(*this,&PageDisplay::MakeTimeHist));
00200     view_menu->Add("Pmt Pixels",slot(*this,&PageDisplay::MakePmtPixels));
00201     view_menu->Add("MC text",slot(*this,&PageDisplay::MakeMCText));
00202     view_menu->Add("MC tree",slot(*this,&PageDisplay::MakeMCTree));
00203 
00204     GuiMenu* zoom_menu = manage(new GuiMenu);
00205     fMenuBar->AddMenu(*zoom_menu,"Zoom");
00206     zoom_menu->Add("Undo",slot(*this,&PageDisplay::Unzoom));
00207     zoom_menu->Add("Redo",slot(*this,&PageDisplay::Rezoom));
00208     zoom_menu->Add("Auto",slot(*this,&PageDisplay::AutoZoom));
00209     zoom_menu->Add("Full",slot(*this,&PageDisplay::FullZoom));
00210 }
00211 
00212 void TridPageDisplay::SetupButtons()
00213 {
00214     GuiTextButton* but;
00215 
00216     but = this->AddButton("Start Auto");
00217     but->clicked.connect(bind(slot(toggle_free_run),this,but));
00218     fAutoButton = but;
00219 
00220    // but = this->AddButton("Next Pass ->");
00221     //but->clicked.connect(fNextPassSignal);
00222 
00223     but = this->AddButton("Next -->");
00224     but->clicked.connect(fNextSignal);
00225 
00226     but = this->AddButton("<-- Prev");
00227     but->clicked.connect(fPrevSignal);
00228 
00229     but = this->AddButton("Zoom Auto");
00230     but->clicked.connect(slot(*this,&PageDisplay::AutoZoom));
00231     
00232     but = this->AddButton("Zoom Full");
00233     but->clicked.connect(slot(*this,&PageDisplay::FullZoom));
00234 
00235     //but = this->AddButton("Zoom Undo");
00236     //but->clicked.connect(slot(*this,&PageDisplay::Unzoom));
00237 
00238     //but = this->AddButton("Zoom Redo");
00239     //but->clicked.connect(slot(*this,&PageDisplay::Rezoom));
00240 
00241 }
00242 
00243 void TridPageDisplay::SetAutoRun(Bool_t on)
00244 {
00245   if(on) {
00246     
00247     fAutoButton->SetText("Stop Auto");
00248     gAutoTimer.fAutoNextDelay = fAutoAdvanceTime;
00249     gAutoTimer.Start((Long_t)(gAutoTimer.fAutoNextDelay*1000.),true);
00250     gAutoTimer.TurnOn();
00251   } else {
00252     fAutoButton->SetText("Start Auto");
00253     gAutoTimer.TurnOff();
00254   }
00255 }
00256 
00257 
00258 void TridPageDisplay::SetAutoTime(Float_t t) 
00259 {
00260   fAutoAdvanceTime = t;
00261   fAutoTimeEntry->SetText(Form("%.1f",t));
00262   gAutoTimer.fAutoNextDelay = t;
00263 }
00264 
00265 
00266 void TridPageDisplay::AutoTimeEntryHandler()
00267 {
00268   const char* txt = fAutoTimeEntry->GetText();
00269   if(txt!="") {
00270     SetAutoTime(atof(txt));
00271   }
00272 }
00273 
00274 void TridPageDisplay::JumpEntryHandler()
00275 {
00276   const char* txt = fJumpEntry->GetText();
00277   if(txt!="") {
00278     int jumpi = atoi(fJumpEntry->GetText());
00279     if(jumpi >0)     fMint->GetJint().Next(jumpi);
00280     else if(jumpi<0) fMint->GetJint().Prev(-jumpi);
00281   }
00282 }
00283 
00284 void TridPageDisplay::RunSnarlEntryHandler()
00285 {
00286   if (!fMint) return;
00287 
00288   string run = fRunEntry->GetText();
00289   string snarl = fSnarlEntry->GetText();
00290   
00291   if (run == "" || snarl == "" || run == " " || snarl == " ") {
00292     cerr << "Both run and snarl must be set to jump to record\n";
00293     return;
00294   }
00295 
00296   int runi = atoi(run.c_str());
00297   int snarli = atoi(snarl.c_str());
00298   
00299   fMint->GetJint().GoTo(runi,snarli);
00300 }
00301 
00302 
00303 
00304 TObject* TridPageDisplay::MySpawnSinglePage(const char* name, int width, int height)
00305 {
00306     MSG("TriD",Msg::kDebug) << "TridPageDisplay::SpawnSinglePage\n";
00307     PageProxyBase* ppb = dynamic_cast<PageProxyBase*>
00308         (NamedFactory::Instance("Page").GetProxy(name));
00309     if (!ppb) {
00310         MSG("TriD",Msg::kWarning) << "Can't get page named: \"" << name << "\"\n";
00311         return 0;
00312     }
00313     PageABC* page = ppb->Create();
00314     fSinglePageList.push_back(page);
00315 
00316     MSG("TriD",Msg::kDebug) << "Adding page @ " << page << endl;
00317     // Load the geometry info, if any.
00318     Int_t x,y;
00319     UInt_t w = width;
00320     UInt_t h = height;
00321     TEnv env(".tridrc");  
00322     TString newname(name);
00323     newname.ReplaceAll(" ","_");
00324     const char* value = env.GetValue(Form("Trid.WindowGeom.%s",newname.Data()),
00325                                      "");
00326     MSG("TriD",Msg::kDebug) << "Looking for " << newname << "  got " << value << endl;
00327     if(strlen(value)>0) {
00328       sscanf(value,"%ux%u+%d+%d",&w,&h,&x,&y);      
00329     }
00330 
00331     MSG("TriD",Msg::kDebug) << "Making gui window with dimensions " << w << "  " << h << endl;
00332     GuiMainWindow* gmw = new GuiMainWindow(w,h);
00333     gmw->SetWindowName(name);
00334     GuiBox* box = manage(new GuiBox(*gmw, kVerticalFrame));
00335     gmw->Add(*box);
00336     
00337 
00338     gmw->ShowAll();
00339 
00340     // Locate the outermost part of the window.
00341     Window_t wind = (Window_t)((gmw->GetId()));
00342     Window_t root = (Window_t)gClient->GetRoot()->GetId();
00343     Window_t frame = wind;
00344     Window_t parent = wind;
00345     while( (parent != root) && (parent) ) {
00346       frame = parent;
00347       parent = gVirtualX->GetParent(parent);
00348     }
00349     WindowAttributes_t attr;
00350     gVirtualX->GetWindowAttributes(frame,attr);
00351     x = attr.fX;
00352     y = attr.fY;
00353     w = attr.fWidth;
00354     h = attr.fHeight;
00355     
00356     if(strlen(value)>0) {
00357       sscanf(value,"%ux%u+%d+%d",&w,&h,&x,&y);      
00358       MSG("TriD",Msg::kDebug) << "----> Got Value " << value << endl;
00359       gVirtualX->MoveResizeWindow(frame,x,y,w,h);
00360     }
00361 
00362     MSG("TriD",Msg::kDebug) << "Restoring geometry " << Form("Trid.WindowGeom.%s",newname.Data())
00363                             << endl;
00364 
00365     TObject* obj = page->Init(fMint,this,*box);
00366     //gmw->ShowAll();
00367 
00368     gmw->close_window.connect(bind(slot_class(*this,&TridPageDisplay::RemovePage),page));
00369     gmw->ConnectClose(true);
00370 
00371     page->Update();
00372 
00373     return obj;
00374 }
00375 
00376 void TridPageDisplay::RemovePage(PageABC* page) 
00377 {
00378   MSG("TriD",Msg::kDebug) << "TridPageDisplay::RemovePage() called " << page << "\n";
00379   if(!page) return;
00380 
00381   for( PageList_t::iterator it = fPageList.begin(); it != fPageList.end(); it++) {
00382     if(*it == page) {
00383       MSG("TriD",Msg::kDebug) << "Deleteing page.\n";
00384       fPageList.erase(it,it+1);
00385       delete page;      
00386       return;
00387     }
00388   }
00389   for( PageList_t::iterator it = fSinglePageList.begin(); it != fSinglePageList.end(); it++) {
00390     if(*it == page) {
00391       MSG("TriD",Msg::kDebug) << "Deleteing page.\n";
00392       fSinglePageList.erase(it,it+1);
00393       delete page;      
00394       return;
00395     }
00396   }
00397  
00398 }

Generated on Mon Feb 15 11:07:46 2010 for loon by  doxygen 1.3.9.1