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

ButtonBar.cxx

Go to the documentation of this file.
00001 
00002 // $Id: ButtonBar.cxx,v 1.2 2008/08/25 19:20:54 fmwk Exp $
00003 //
00004 // The button bar across the top of the display
00005 //
00006 // messier@indiana.edu
00008 #include "EventDisplayBase/ButtonBar.h"
00009 #include <iostream>
00010 #include <string>
00011 // ROOT includes
00012 #include "TGFrame.h"
00013 #include "TGButton.h"
00014 #include "TGLayout.h"
00015 #include "TGLabel.h"
00016 #include "TGTextEntry.h"
00017 #include "TGPicture.h"
00018 #include "TGMsgBox.h"
00019 // MIPP includes
00020 #include "EventDataModel/EventHandle.h"
00021 #include "EventDataModel/EventHeader.h"
00022 #include "EventDisplayBase/evdb.h"
00023 #include "EventDisplayBase/IoModule.h"
00024 #include "EventDisplayBase/PrintDialog.h"
00025 #include "EventDisplayBase/GoToDialog.h"
00026 using namespace evdb;
00027 
00028 //......................................................................
00029 
00030 static void gsGetEventNumbers(int& run, int& event)
00031 {
00032   // Grad the header out of the event
00033   edm::EventHandle& evt  = IoModule::Instance()->GetEvent();
00034   edm::EventHeader& head = evt.Header();
00035 
00036   run   = head.Run();
00037   event = head.Event();
00038 }
00039 
00040 //......................................................................
00041 
00042 ButtonBar::ButtonBar(TGMainFrame* frame) 
00043 {
00044   fButtonBar = new TGCompositeFrame(frame, 60, 20, 
00045                                     kSunkenFrame|kHorizontalFrame);
00046   fLayout    = new TGLayoutHints(kLHintsTop | kLHintsExpandX, 0, 0, 1, 0);
00047 
00048   // Previous event button
00049   fPrevEvt = new TGTextButton(fButtonBar, "<-Previous", 150);
00050   fPrevEvt->SetToolTipText("Go to previous event");
00051   fPrevEvt->Connect("Clicked()", "evdb::ButtonBar", this, "PrevEvt()");
00052   fButtonBar->AddFrame(fPrevEvt, new TGLayoutHints(kLHintsTop |
00053                                                    kLHintsLeft, 2, 0, 2, 2));
00054 
00055   // Next event button
00056   fNextEvt = new TGTextButton(fButtonBar, "Next->", 150);
00057   fNextEvt->SetToolTipText("Go to next event");
00058   fNextEvt->Connect("Clicked()", "evdb::ButtonBar", this, "NextEvt()");
00059   fButtonBar->AddFrame(fNextEvt, new TGLayoutHints(kLHintsTop |
00060                                                    kLHintsLeft, 2, 0, 2, 2));
00061   
00062   // Reload button
00063   fReload = new TGTextButton(fButtonBar, "Reload", 150);
00064   fReload->SetToolTipText("Reload current event");
00065   fReload->Connect("Clicked()", "evdb::ButtonBar", this, "ReloadEvt()");
00066   fButtonBar->AddFrame(fReload, new TGLayoutHints(kLHintsTop |
00067                                                   kLHintsLeft, 2, 0, 2, 2));
00068     
00069   fCurrentFile = new TGTextEntry(fButtonBar, new TGTextBuffer(256));
00070   fCurrentFile->SetToolTipText("Name of current file");
00071   fCurrentFile->Resize(400, fCurrentFile->GetDefaultHeight());
00072   fButtonBar->AddFrame(fCurrentFile, 
00073                        new TGLayoutHints(kLHintsTop | kLHintsLeft,
00074                                          8, 2, 2, 2));
00075 
00076   // Button to list attached files
00077   const TGPicture* p = ::PicturePool()->GetPicture("arrow_down.xpm");
00078   GContext_t norm = TGPictureButton::GetDefaultGC()();
00079   fFileList = new TGPictureButton(fButtonBar, p, -1, norm, kRaisedFrame);
00080   fFileList->SetToolTipText("List files");
00081   fFileList->Connect("Clicked()", "evdb::ButtonBar", this, "FileList()");
00082   fButtonBar->AddFrame(fFileList, new TGLayoutHints(kLHintsCenterY,
00083                                                     2, 0, 2, 2));
00084 
00085   // Print button
00086   fPrint = new TGTextButton(fButtonBar, "Print", 150);
00087   fPrint->SetToolTipText("Print Display");
00088   fPrint->Connect("Clicked()", "evdb::ButtonBar", this, "Print()");
00089   fButtonBar->AddFrame(fPrint, new TGLayoutHints(kLHintsTop|kLHintsRight, 
00090                                                  2, 0, 2, 2));
00091   
00092   // Go To button
00093   fGoTo = new TGTextButton(fButtonBar, "Go");
00094   fGoTo->SetToolTipText("Go to event");
00095   fGoTo->Connect("Clicked()", "evdb::ButtonBar", this, "GoTo()");
00096   fButtonBar->AddFrame(fGoTo, new TGLayoutHints(kLHintsTop|kLHintsRight, 
00097                                                 2, 0, 2, 2));
00098 
00099   // Go to event text entry
00100   fEventTextEntry = new TGTextEntry(fButtonBar, new TGTextBuffer(128));
00101   fEventTextEntry->Connect("ReturnPressed()","evdb::ButtonBar",this,"GoTo()");
00102   fEventTextEntry->Resize(75,20);
00103   fButtonBar->AddFrame(fEventTextEntry, 
00104                        new TGLayoutHints(kLHintsTop|kLHintsRight,2,0,2,2));
00105 
00106   fRunTextEntry = new TGTextEntry(fButtonBar, new TGTextBuffer(128));
00107   fRunTextEntry->Connect("ReturnPressed()","evdb::ButtonBar",this,"GoTo()");
00108   fRunTextEntry->Resize(50,20);
00109   fButtonBar->AddFrame(fRunTextEntry, 
00110                        new TGLayoutHints(kLHintsCenterY|kLHintsRight,2,0,2,2));
00111 
00112   fRunEvtLabel = new TGLabel(fButtonBar, new TGHotString("[Run/Event]="));
00113   fButtonBar->AddFrame(fRunEvtLabel, 
00114                        new TGLayoutHints(kLHintsCenterY|kLHintsRight,2,0,2,2));
00115 
00116   // Add button bar to frame
00117   frame->AddFrame(fButtonBar, fLayout);
00118 
00119   // Connect the new event signal from the iomodule to the new event slot
00120   IoModule::Instance()->Connect("NewEvent()",
00121                                 "evdb::ButtonBar",this,"NewEvent()");
00122   
00123   this->NewEvent();
00124 }
00125 
00126 //......................................................................
00127 
00128 ButtonBar::~ButtonBar() 
00129 {
00130   IoModule::Instance()->Disconnect(0,this,0);
00131 
00132   delete fEventTextEntry; fEventTextEntry=0;
00133   delete fRunTextEntry;   fRunTextEntry  =0;
00134   delete fRunEvtLabel;    fRunEvtLabel   =0;
00135   delete fPrint;          fPrint         =0;
00136   delete fGoTo;           fGoTo          =0;
00137   delete fFileList;       fFileList      =0;
00138   delete fCurrentFile;    fCurrentFile   =0;
00139   delete fReload;         fReload        =0;
00140   delete fNextEvt;        fNextEvt       =0;
00141   delete fPrevEvt;        fPrevEvt       =0;
00142   delete fLayout;         fLayout        =0;
00143   delete fButtonBar;      fButtonBar     =0;
00144 }
00145 
00146 //......................................................................
00147 
00148 void ButtonBar::PrevEvt() { IoModule::Instance()->Rewind(); }
00149 
00150 //......................................................................
00151 
00152 void ButtonBar::NextEvt() { IoModule::Instance()->Advance(); }
00153 
00154 //......................................................................
00155 
00156 void ButtonBar::ReloadEvt() { IoModule::Instance()->Reload(); }
00157 
00158 //......................................................................
00159 
00160 void ButtonBar::FileList() 
00161 {
00162   int i;
00163   const char* f;
00164   for (i=0; (f=IoModule::Instance()->FileName(i)); ++i) {
00165     std::cerr << f << std::endl;
00166   }
00167 }
00168 
00169 //......................................................................
00170 
00171 void ButtonBar::Print() { new PrintDialog(); }
00172 
00173 //......................................................................
00174 
00175 void ButtonBar::GoTo() 
00176 {
00177   int run = atoi(fRunTextEntry  ->GetText());
00178   int evt = atoi(fEventTextEntry->GetText());
00179   IoModule::Instance()->GoTo(run,evt);
00180 }
00181 
00182 //......................................................................
00183 
00184 void ButtonBar::NewEvent() 
00185 {
00186   int run;
00187   int evt;
00188   char runtxt[128];
00189   char evttxt[128];
00190 
00191   gsGetEventNumbers(run,evt);
00192   sprintf(runtxt,"%d",run);
00193   sprintf(evttxt,"%d",evt);
00194   fRunTextEntry  ->SetText(runtxt);
00195   fEventTextEntry->SetText(evttxt);
00196 
00197   fCurrentFile->SetText(IoModule::Instance()->CurrentFile());
00198 }
00199 
00200 //......................................................................
00201 
00202 int ButtonBar::NoImpl(const char* method)
00203 {
00204   std::string s;
00205   s = "Sorry action '"; s += method; s+= "' is not implemented.\n";
00206   new TGMsgBox(evdb::TopWindow(), fButtonBar,
00207                "No implementation",s.c_str(),kMBIconExclamation);
00208   return 0;
00209 }
00210 
00211 

Generated on Wed Oct 15 02:35:25 2008 for NOvA Offline by  doxygen 1.3.9.1