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

Generated on Mon Nov 23 04:45:24 2009 for NOvA Offline by  doxygen 1.3.9.1