ListWindow.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file ListWindow.h
3 /// \brief A window containing a list of objects
4 ///
5 /// \version $Id: ListWindow.cxx,v 1.1.1.1 2010-12-22 16:18:52 p-nusoftart Exp $
6 /// \author jpaley@anl.gov
7 ////////////////////////////////////////////////////////////////////////
8 #include <cassert>
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 #include "nutools/EventDisplayBase/evdb.h"
19 #include "nutools/EventDisplayBase/ListWindow.h"
20 #include "nutools/EventDisplayBase/MenuBar.h"
21 #include "nutools/EventDisplayBase/ButtonBar.h"
22 #include "nutools/EventDisplayBase/Canvas.h"
23 #include "nutools/EventDisplayBase/StatusBar.h"
24 #include "nutools/EventDisplayBase/ObjListCanvas.h"
25 
26 namespace evdb{
27 
28  ///
29  /// The collection of open windows
30  ///
31  static std::vector<ListWindow*> gsWindows(64);
32 
33  //......................................................................
34 
35  ///
36  /// Tables of information for display windows
37  ///
38  static std::vector<std::string> gsName;
39  static std::vector<std::string> gsDescription;
40  static std::vector<unsigned int> gsHeight;
41  static std::vector<unsigned int> gsWidth;
42  static std::vector<ObjListCanvasCreator_t> gsObjListCanvasCreator;
43 
44  //......................................................................
45 
46  const std::vector<std::string>& ListWindow::Names() { return gsName; }
47 
48  //......................................................................
49 
50  ///
51  /// Register a display canvas for use in creating windows
52  ///
53  void ListWindow::Register(const char* name,
54  const char* description,
55  unsigned int h,
56  unsigned int w,
57  ObjListCanvasCreator_t creator)
58  {
59  gsName.push_back(std::string(name));
60  gsDescription.push_back(std::string(description));
61  gsHeight.push_back(h);
62  gsWidth.push_back(w);
63  gsObjListCanvasCreator.push_back(creator);
64 
65  if (gsName.size()>gsWindows.size()) gsWindows.resize(gsName.size());
66  }
67 
68  //......................................................................
69 
70  ///
71  /// Create a window given a system-assigned ID number
72  ///
74  {
75  unsigned id = 0;
76  if (type>0) id = type;
77  if (id>=gsName.size()) return 0;
78 
79  ListWindow* w = gsWindows[id];
80  if (w==0) {
81  w = gsWindows[id] = new ListWindow(id);
82  }
83  if (w==0) return 0;
84  w->Raise();
85  w->Draw();
86 
87  return 1;
88  }
89 
90  //......................................................................
91 
93  {
94  if (gROOT->IsBatch()) assert(0);
95  assert(gClient);
96  const TGWindow* tgw = gClient->GetRoot();
97  assert(tgw);
98 
99  // Create the main application window. I need a resize to get the
100  // window to draw the first time, so create the window slightly
101  // smaller than the intended size. Bogus, but so it goes...
102  unsigned int w = gsWidth[id];
103  unsigned int h = gsHeight[id];
104  fMain = new TGMainFrame(tgw, w-1, h-1);
105 
106  // Add items to the main window
107  fMenuBar = new MenuBar(fMain);
108  fButtonBar = new ButtonBar(fMain);
109 
110  fDisplay = (*gsObjListCanvasCreator[id])(fMain);
111  fStatusBar = new StatusBar(fMain);
112 
113  fMain->SetWindowName(gsName[id].c_str());
114 
115  // Now that all the subwindows are attached, do the final layout
116  fMain->MapSubwindows();
117  fMain->MapWindow();
118 
119  // Don't understand this, but I need a resize to get things to draw
120  // the first time...
121  fMain->Resize(w,h);
122 
123  // Plug the display into its signal/slots
124  fDisplay->Connect();
125 
126  // fMain->Connect("CloseWindow()","evdb::ListWindow",this,"CloseWindow()");
127 
128  // Add to list of windows open
129  gsWindows[id] = this;
130 
131  }
132 
133  //......................................................................
134 
135  void ListWindow::Draw(const char* opt) { fDisplay->Draw(opt); }
136 
137  //......................................................................
138 
139  void ListWindow::CloseWindow() { delete this; }
140 
141  //......................................................................
142 
144  {
145  if (fDisplay) { delete fDisplay; fDisplay = 0; }
146  if (fStatusBar) { delete fStatusBar; fStatusBar = 0; }
147  if (fButtonBar) { delete fButtonBar; fButtonBar = 0; }
148  if (fMenuBar) { delete fMenuBar; fMenuBar = 0; }
149  if (fMain) { delete fMain; fMain = 0; }
150  for (unsigned int i=0; i<gsWindows.size(); ++i) {
151  if (gsWindows[i] == this) gsWindows[i] = 0;
152  }
153  }
154 
155  //......................................................................
156 
157  void ListWindow::Raise() { fMain->RaiseWindow(); }
158 
159 }//namespace
160 ////////////////////////////////////////////////////////////////////////
static QCString name
Definition: declinfo.cpp:673
MenuBar * fMenuBar
Top menu bar.
Definition: ListWindow.h:49
virtual void Draw(const char *opt=0)=0
ButtonBar * fButtonBar
Top button bar.
Definition: ListWindow.h:50
static std::vector< DisplayWindow * > gsWindows(64)
A status bar on the bottom of the display.
Definition: StatusBar.h:15
std::string string
Definition: nybbler.cc:12
ObjListCanvas *(* ObjListCanvasCreator_t)(TGMainFrame *mf)
Definition: ListWindow.h:21
virtual void CloseWindow()
Definition: ListWindow.cxx:139
opt
Definition: train.py:196
static std::vector< unsigned int > gsWidth
void Connect()
Make signal/slot connections.
Manage all things related to colors for the event display.
virtual void Draw(const char *opt="")
Definition: ListWindow.cxx:135
static const std::vector< std::string > & Names()
Definition: ListWindow.cxx:46
static void Register(const char *name, const char *description, unsigned int h, unsigned int w, ObjListCanvasCreator_t creator)
Definition: ListWindow.cxx:53
ListWindow(int window=0)
Definition: ListWindow.cxx:92
static std::vector< std::string > gsName
static std::vector< ObjListCanvasCreator_t > gsObjListCanvasCreator
Definition: ListWindow.cxx:42
TGMainFrame * fMain
Main window.
Definition: ListWindow.h:48
An event display window.
Definition: ListWindow.h:28
virtual ~ListWindow()
Definition: ListWindow.cxx:143
static QCString type
Definition: declinfo.cpp:672
static std::vector< std::string > gsDescription
static int OpenWindow(int type=0)
Definition: ListWindow.cxx:73
The pull down menu bar.
Definition: MenuBar.h:25
StatusBar * fStatusBar
Status bar running along the bottom.
Definition: ListWindow.h:51
static std::vector< unsigned int > gsHeight
h
training ###############################
Definition: train_cnn.py:186
ObjListCanvas * fDisplay
Display of detector event information.
Definition: ListWindow.h:52