DisplayWindow.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file DisplayWindow.h
3 /// \brief A window containing a display of the detector or one of its
4 /// components
5 ///
6 /// \version $Id: DisplayWindow.cxx,v 1.7 2012-01-17 20:53:56 brebel Exp $
7 /// \author messier@indiana.edu
8 ////////////////////////////////////////////////////////////////////////
9 #include <iostream>
10 #include <vector>
11 #include "TROOT.h"
12 #include "TGClient.h"
13 #include "TGWindow.h"
14 #include "TGFrame.h"
15 #include "TRootEmbeddedCanvas.h"
16 #include "TCanvas.h"
17 #include "TH1.h"
18 
27 
28 #include "cetlib_except/exception.h"
29 
30 namespace evdb{
31 
32  ///
33  /// The collection of open windows
34  ///
35  static std::vector<DisplayWindow*> gsWindows(64);
36 
37  //......................................................................
38 
39  ///
40  /// Tables of information for display windows
41  ///
42  static std::vector<std::string> gsName;
43  static std::vector<std::string> gsDescription;
44  static std::vector<unsigned int> gsHeight;
45  static std::vector<unsigned int> gsWidth;
46  static std::vector<CanvasCreator_t> gsCanvasCreator;
47 
48  void DisplayWindow::SetRunEventAll(int run, int event)
49  {
50  for (size_t i=0; i<gsWindows.size(); ++i) {
51  if (gsWindows[i]!=0) gsWindows[i]->SetRunEvent(run, event);
52  }
53  }
54 
55  //......................................................................
56 
57  void DisplayWindow::DrawAll(const char* opt)
58  {
59  for (size_t i=0; i<gsWindows.size(); ++i) {
60  if (gsWindows[i]!=0) gsWindows[i]->Draw(opt);
61  }
62  }
63 
64  //......................................................................
65 
66  void DisplayWindow::SetRunEvent(int run, int event)
67  {
68  fButtonBar->SetRunEvent(run, event);
69  }
70 
71  //......................................................................
72 
74  {
75  for (size_t i=0; i<gsWindows.size(); ++i) {
76  if (gsWindows[i]!=0) gsWindows[i]->SetServices();
77  }
78  }
79 
80  //......................................................................
81 
83  {
85  }
86 
87  //......................................................................
88 
89  const std::vector<std::string>& DisplayWindow::Names() { return gsName; }
90 
91  //......................................................................
92 
93  ///
94  /// Register a display canvas for use in creating windows
95  ///
96  void DisplayWindow::Register(const char* name,
97  const char* description,
98  unsigned int h,
99  unsigned int w,
100  CanvasCreator_t creator)
101  {
102  gsName.push_back(std::string(name));
103  gsDescription.push_back(std::string(description));
104  gsHeight.push_back(h);
105  gsWidth.push_back(w);
106  gsCanvasCreator.push_back(creator);
107 
108  if (gsName.size()>gsWindows.size()) gsWindows.resize(gsName.size());
109  }
110 
111  //......................................................................
112 
113  ///
114  /// Create a window given a system-assigned ID number
115  ///
117  {
118  unsigned id = 0;
119  if (type>0) id = type;
120  if (id>=gsName.size()) return 0;
121 
123  if (w==0) {
124  w = gsWindows[id] = new DisplayWindow(id);
125  }
126  if (w==0) return 0;
127 
128  // Update run and event number in newly opened window.
130  if(evt)
131  w->SetRunEvent(evt->id().run(), evt->id().event());
132 
133  w->Raise();
134  w->Draw();
135 
136  return 1;
137  }
138 
139 
140  //......................................................................
141 
143  {
144  if(gROOT->IsBatch())
145  throw cet::exception("DisplayWindow") << "ROOT is in batch mode"
146  << " cannot open DisplayWindow";
147  if(!gClient)
148  throw cet::exception("DisplayWindow") << "No ROOT global TClient";
149 
150  const TGWindow* tgw = gClient->GetRoot();
151  if(!tgw)
152  throw cet::exception("DisplayWindow") << "No TGWindow pointer";
153 
154  // Create the main application window. I need a resize to get the
155  // window to draw the first time, so create the window slightly
156  // smaller than the intended size. Bogus, but so it goes...
157  unsigned int w = gsWidth[id];
158  unsigned int h = gsHeight[id];
159  fMain = new TGMainFrame(tgw, w-1, h-1);
160 
161  // Add items to the main window
162  fMenuBar = new MenuBar(fMain);
163  fButtonBar = new ButtonBar(fMain);
164  fDisplay = (*gsCanvasCreator[id])(fMain);
165  fStatusBar = new StatusBar(fMain);
166 
167  fMain->SetWindowName(gsName[id].c_str());
168 
169  // Now that all the subwindows are attached, do the final layout
170  fMain->MapSubwindows();
171  fMain->MapWindow();
172 
173  // Don't understand this, but I need a resize to get things to draw
174  // the first time...
175  fMain->Resize(w,h);
176 
177  // Plug the display into its signal/slots
178  fDisplay->Connect();
179 
180  fMain->Connect("CloseWindow()","evdb::DisplayWindow",this,"CloseWindow()");
181 
182  // Add to list of windows open
183  gsWindows[id] = this;
184  }
185 
186  //......................................................................
187 
188  void DisplayWindow::Draw(const char* opt) { fDisplay->Draw(opt); }
189 
190  //......................................................................
191 
192  void DisplayWindow::CloseWindow() { delete this; }
193 
194  //......................................................................
195 
197  {
198  if (fDisplay) { delete fDisplay; fDisplay = 0; }
199  if (fStatusBar) { delete fStatusBar; fStatusBar = 0; }
200  if (fButtonBar) { delete fButtonBar; fButtonBar = 0; }
201  if (fMenuBar) { delete fMenuBar; fMenuBar = 0; }
202  if (fMain) { delete fMain; fMain = 0; }
203  for (unsigned int i=0; i<gsWindows.size(); ++i) {
204  if (gsWindows[i] == this) gsWindows[i] = 0;
205  }
206  }
207 
208  //......................................................................
209 
210  void DisplayWindow::Raise() { fMain->RaiseWindow(); }
211 
212 }// namespace
213 ////////////////////////////////////////////////////////////////////////
::xsd::cxx::tree::id< char, ncname > id
Definition: Database.h:165
const XML_Char * name
Definition: expat.h:151
MenuBar * fMenuBar
Top menu bar.
Definition: DisplayWindow.h:60
void Connect()
Make signal/slot connections.
Definition: Canvas.cxx:68
const art::Event * GetEvent() const
Definition: EventHolder.cxx:45
virtual void CloseWindow()
The edit pull down menu.
An event display window.
Definition: DisplayWindow.h:33
static std::vector< DisplayWindow * > gsWindows(64)
virtual void Draw(const char *opt="")
A status bar on the bottom of the display.
Definition: StatusBar.h:15
ButtonBar * fButtonBar
Top button bar.
Definition: DisplayWindow.h:61
static std::vector< unsigned int > gsWidth
static void SetServicesAll()
::xsd::cxx::tree::exception< char > exception
Definition: Database.h:225
Canvas *(* CanvasCreator_t)(TGMainFrame *mf)
Definition: DisplayWindow.h:26
RunNumber_t run() const
Definition: EventID.h:98
Manage all things related to colors for the event display.
Definition: Display3DPad.h:11
static std::vector< CanvasCreator_t > gsCanvasCreator
Singleton to hold the current art::Event for the event display.
static int OpenWindow(int type=0)
Base class for define a detector display.
StatusBar * fStatusBar
Status bar running along the bottom.
Definition: DisplayWindow.h:62
void SetServices()
Definition: EditMenu.cxx:51
static void SetRunEventAll(int run, int event)
static EventHolder * Instance()
Definition: EventHolder.cxx:15
int evt
static void Register(const char *name, const char *description, unsigned int h, unsigned int w, CanvasCreator_t creator)
Canvas * fDisplay
Display of detector event information.
Definition: DisplayWindow.h:63
Definition: run.py:1
static std::vector< std::string > gsName
void SetRunEvent(int run, int event)
static void DrawAll(const char *opt=0)
EventNumber_t event() const
Definition: EventID.h:116
static const std::vector< std::string > & Names()
A status bar on the bottom of the display.
The file pull down menu.
A bar containing the next event and related buttons.
void SetRunEvent(int run, int event)
Definition: ButtonBar.cxx:229
static std::vector< std::string > gsDescription
A window containing a display of the detector or one of its components.
The pull down menu bar.
Definition: MenuBar.h:25
DisplayWindow(int window=0)
TGMainFrame * fMain
Main window.
Definition: DisplayWindow.h:59
Float_t w
Definition: plot.C:20
EditMenu * fEditMenu
Edit menu.
Definition: MenuBar.h:36
EventID id() const
virtual void Draw(const char *opt=0)=0
static std::vector< unsigned int > gsHeight
enum BeamMode string