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 
19 #include "nutools/EventDisplayBase/DisplayWindow.h"
20 #include "nutools/EventDisplayBase/FileMenu.h"
21 #include "nutools/EventDisplayBase/EditMenu.h"
22 #include "nutools/EventDisplayBase/MenuBar.h"
23 #include "nutools/EventDisplayBase/ButtonBar.h"
24 #include "nutools/EventDisplayBase/Canvas.h"
25 #include "nutools/EventDisplayBase/StatusBar.h"
26 #include "nutools/EventDisplayBase/EventHolder.h"
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 
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 
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 
122  DisplayWindow* w = gsWindows[id];
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 ////////////////////////////////////////////////////////////////////////
static QCString name
Definition: declinfo.cpp:673
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()
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
std::string string
Definition: nybbler.cc:12
opt
Definition: train.py:196
ButtonBar * fButtonBar
Top button bar.
Definition: DisplayWindow.h:61
static std::vector< unsigned int > gsWidth
static void SetServicesAll()
Canvas *(* CanvasCreator_t)(TGMainFrame *mf)
Definition: DisplayWindow.h:26
Manage all things related to colors for the event display.
static std::vector< CanvasCreator_t > gsCanvasCreator
RunNumber_t run() const
Definition: EventID.h:98
static int OpenWindow(int type=0)
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
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
static std::vector< std::string > gsName
void SetRunEvent(int run, int event)
static void DrawAll(const char *opt=0)
static const std::vector< std::string > & Names()
void SetRunEvent(int run, int event)
Definition: ButtonBar.cxx:229
static QCString type
Definition: declinfo.cpp:672
static std::vector< std::string > gsDescription
EventNumber_t event() const
Definition: EventID.h:116
The pull down menu bar.
Definition: MenuBar.h:25
DisplayWindow(int window=0)
TCEvent evt
Definition: DataStructs.cxx:7
TGMainFrame * fMain
Main window.
Definition: DisplayWindow.h:59
EditMenu * fEditMenu
Edit menu.
Definition: MenuBar.h:36
EventID id() const
Definition: Event.cc:37
virtual void Draw(const char *opt=0)=0
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
Event finding and building.
static std::vector< unsigned int > gsHeight
h
training ###############################
Definition: train_cnn.py:186
unsigned int run