MagicControlPanel.cxx
1 #include <fstream>
9 #include <iostream>
10 #include "MagicDisplayConventions.h"
11 #include "MagicControlPanel.h"
12 #include "MagicDisplay.h"
13 
14 #include "TString.h"
15 #include "TObjArray.h"
16 #include "TObjString.h"
17 #include "TVector3.h"
18 #include "TROOT.h"
19 #include "TPaveText.h"
20 #include "TPad.h"
21 #include "TText.h"
22 #include "TLatex.h"
23 #include "TGraph.h"
24 #include "WaveformGraph.h"
25 #include "TStyle.h"
26 #include "TCanvas.h"
27 #include "TAxis.h"
28 #include "TH1.h"
29 #include "THStack.h"
30 #include "TList.h"
31 #include "TObject.h"
32 #include "TTimeStamp.h"
33 #include "TApplication.h"
34 #include "KeySymbols.h"
35 
36 ClassImp(MagicControlPanel) ;
37 
39 
40 
41 enum ETestCommandIdentifiers {
42  M_EVENT_BUT =1,
43  M_SURF_BUT,
44  M_TURF_BUT,
45  M_AVG_SURF_BUT,
46  M_SUM_TURF_BUT,
47  M_GOTO_EVENT
48 };
49 
50 MagicControlPanel::MagicControlPanel() : TGMainFrame(gClient->GetRoot(),200,300,kVerticalFrame)
51 {
52 
53  //Default constructor
54  fgInstance=this;
55  MagicDisplay *magicDisPtr = MagicDisplay::Instance();
56 
57  fEntryPanel = new TGVerticalFrame(this,200,300);
58  fLeftLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft,2,2,2,2);
59  fRightLayout = new TGLayoutHints(kLHintsCenterY | kLHintsRight,2,2,2,2);
60  fCenterLayout = new TGLayoutHints(kLHintsCenterY | kLHintsCenterX,2,2,2,2);
61  this->AddFrame(fEntryPanel,fLeftLayout);
62 
63 
64  fRunPanel = new TGHorizontalFrame(fEntryPanel,200,30);
66  fRunEntry =new TGNumberEntry(fRunPanel,magicDisPtr->getCurrentRun(),12,20,(TGNumberEntry::EStyle)0);
67  fRunEntryField = fRunEntry->GetNumberEntry();
68  fRunEntryField->Connect("ReturnPressed()", "MagicControlPanel", this, "goToEvent()");
69  fRunEntryField->Connect("TabPressed()", "MagicControlPanel", this, "cycleThroughInputs()");
70 
71  fRunPanel->AddFrame(fRunEntry,fRightLayout);
72  fRunLabel = new TGLabel(fRunPanel,"Run: ");
73  fRunPanel->AddFrame(fRunLabel,fRightLayout);
74 
75  fEventPanel = new TGHorizontalFrame(fEntryPanel,200,30);
77  fEventEntry =new TGNumberEntry(fEventPanel,magicDisPtr->getCurrentEvent(),12,20,(TGNumberEntry::EStyle)0);
78  fEventEntryField = fEventEntry->GetNumberEntry();
79  fEventEntryField->Connect("ReturnPressed()", "MagicControlPanel", this, "goToEvent()");
80  fEventEntryField->Connect("TabPressed()", "MagicControlPanel", this, "cycleThroughInputs()");
81 
83  fEventLabel = new TGLabel(fEventPanel,"Event: ");
85 
86  fGotoBut = new TGTextButton(fEntryPanel, "&Go to Event", M_GOTO_EVENT);
87  // fGotoBut->SetBackgroundColor(TColor::Number2Pixel(5));
88  // fGotoBut->Associate(this);
89  fGotoBut->Connect("Pressed()","MagicControlPanel",this,"goToEvent()");
90 
91 
93 
94 
95  // start with the cursor in run
96  cycleThroughInputs();
97 
98 
99 // // this->SetBackgroundColor(TColor::Number2Pixel(kRed));
100 // fButtonPanel = new TGVerticalFrame(this,200,500);
101 // fUpdateLabel = new TGLabel(fButtonPanel,"Update Canvas?");
102 // fButtonPanel->AddFrame(fUpdateLabel,fLeftLayout);
103 // fButtonLayout = new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2);
104 // this->AddFrame(fButtonPanel,fButtonLayout);
105 // fEventBut = new TGCheckButton(fButtonPanel, "Event Canvas", M_EVENT_BUT);
106 // fEventBut->Associate(this);
107 // fEventBut->SetBackgroundColor(TColor::Number2Pixel(5));
108 // fButtonPanel->AddFrame(fEventBut, fLayout);
109 // fSurfBut = new TGCheckButton(fButtonPanel, "SURF Canvas", M_SURF_BUT);
110 // fSurfBut->Associate(this);
111 // fSurfBut->SetBackgroundColor(TColor::Number2Pixel(5));
112 // fButtonPanel->AddFrame(fSurfBut, fLayout);
113 // fTurfBut = new TGCheckButton(fButtonPanel, "TURF Canvas", M_TURF_BUT);
114 // fTurfBut->Associate(this);
115 // fTurfBut->SetBackgroundColor(TColor::Number2Pixel(5));
116 // fButtonPanel->AddFrame(fTurfBut, fLayout);
117 // fAvgSurfBut = new TGCheckButton(fButtonPanel, "Avg. SURF Canvas", M_AVG_SURF_BUT);
118 // fAvgSurfBut->Associate(this);
119 // fAvgSurfBut->SetBackgroundColor(TColor::Number2Pixel(5));
120 // fButtonPanel->AddFrame(fAvgSurfBut, fLayout);
121 // fSumTurfBut = new TGCheckButton(fButtonPanel, "Sum. TURF Canvas", M_SUM_TURF_BUT);
122 // fSumTurfBut->Associate(this);
123 // fSumTurfBut->SetBackgroundColor(TColor::Number2Pixel(5));
124 // fButtonPanel->AddFrame(fSumTurfBut, fLayout);
125 
126 
127 
128 
129  this->SetWindowName("MagicControlPanel");
130  this->MapSubwindows();
131 
132  // this->DontCallClose();
133  // this->Connect("CloseWindow()", "MagicControlPanel", this, "closeControlPanel()");
134 
135  this->Connect("CloseWindow()", "MagicControlPanel", this, "DontCallClose()");
136 
137  // we need to use GetDefault...() to initialize the layout algorithm...
138  this->Resize(); // resize to default size
139  this->MapRaised();
140  // this->Print();
141 
142 }
143 
144 
145 //______________________________________________________________________________
147 {
148  //static function
149  if(fgInstance){
150  fgInstance->CloseWindow();
151  }
152  return new MagicControlPanel();
153  // return (fgInstance) ? (MagicControlPanel*) fgInstance : new MagicControlPanel();
154  // return (fgInstance) ? (MagicControlPanel*) fgInstance : new MagicControlPanel();
155 
156 }
157 
158 void MagicControlPanel::CloseWindow(){
159  this->RequestFocus(); // the magic line that stops the stupid blink cursor timer causing seg faults...
160  TGMainFrame::CloseWindow();
161 }
162 
163 
164 void MagicControlPanel::cycleThroughInputs(){
165 
166  if (gTQSender == fRunEntryField){
167  fEventEntryField->SetFocus();
168  }
169  else{
170  fRunEntryField->SetFocus();
171  }
172  // std::cout << "Do something here" << std::endl;
173 }
174 
175 
176 Bool_t MagicControlPanel::HandleKey(Event_t* ev){
177 
178  // want a special case for the G/g keys to close the window...
179  // and tab to cycle through the boxes
180  // and enter to go to the event
181  if(ev->fType == kGKeyPress){
182 
183  UInt_t keysym;
184  char tmp[2];
185  gVirtualX->LookupString(ev,tmp,sizeof(tmp),keysym);
186  switch(keysym){
187  case kKey_G:
188  case kKey_g:
189  case kKey_Q:
190  case kKey_q:
191  CloseWindow();
192  return false;
193 
194  case kKey_Tab:
195  cycleThroughInputs();
196  return false;
197 
198  case kKey_Return:
199  case kKey_Enter:
200  goToEvent();
201  return false;
202 
203  default:
204  ;
205  // do nothing
206 
207  }
208  }
209  return MagicDisplay::Instance()->HandleKey(ev);
210 }
211 
212 
214 {
215  fgInstance=0;
216  MagicDisplay::Instance()->fControlPanel = 0;
217 }
218 
219 void MagicControlPanel::goToEvent()
220 {
221  MagicDisplay::Instance()->displayThisEvent((UInt_t)this->fEventEntry->GetNumber(),(UInt_t)this->fRunEntry->GetNumber());
222  CloseWindow();
223 
224 }
225 
226 void MagicControlPanel::closeControlPanel()
227 {
228  delete this;
229 }
230 
231 
232 //void MagicControlPanel::CloseWindow()
233 //{
234  // Got close message for this MainFrame. Terminate the application
235  // or returns from the TApplication event loop (depending on the
236  // argument specified in TApplication::Run()).
237 //}
238 
239 // Bool_t MagicControlPanel::ProcessMessage(Long_t msg, Long_t parm1, Long_t)
240 // {
241 // // Handle messages send to the MagicControlPanel object. E.g. all menu button
242 // switch (GET_MSG(msg)) {
243 // case kC_COMMAND:
244 // {
245 // switch (GET_SUBMSG(msg)) {
246 // case kCM_BUTTON:
247 // {
248 // switch (parm1) {
249 // // exit button
250 // case M_EVENT_BUT:
251 // {
252 // // CloseWindow();
253 // std::cout << "Event But" << std::endl;
254 // break;
255 // }
256 // case M_SURF_BUT:
257 // {
258 // // CloseWindow();
259 // std::cout << "SURF But" << std::endl;
260 // break;
261 // }
262 // // set button
263 // case M_GOTO_EVENT:
264 // {
265 // std::cout << "Goto Event: " << this->fRunEntry->GetNumber()
266 // << "\t" << this->fEventEntry->GetNumber()
267 // << std::endl;
268 // std::cout << "Event State: " << this->fEventBut->GetState() << std::endl;
269 
270 // if(this->fEventBut->GetState()) {
271 // MagicDisplay::Instance()->displayThisEvent((UInt_t)this->fEventEntry->GetNumber(),(UInt_t)this->fRunEntry->GetNumber());
272 // }
273 
274 // break;
275 // }
276 // }
277 // break;
278 // }
279 // }
280 // break;
281 // }
282 // }
283 // return kTRUE;
284 
285 
286 // }
static MagicControlPanel * fgInstance
Protect against multiple instances.
TGNumberEntry * fRunEntry
Number entry form.
TGNumberEntryField * fEventEntryField
Number entry form field.
TGLayoutHints * fRightLayout
Layout nonsense.
TGTextButton * fGotoBut
Text button.
TGLayoutHints * fCenterLayout
Layout nonsense.
TGNumberEntry * fEventEntry
Number entry form.
Int_t getCurrentRun()
Returns the current run number.
Definition: MagicDisplay.h:107
MagicControlPanel()
The default constructor.
virtual ~MagicControlPanel()
The destructor.
TGLayoutHints * fLeftLayout
Layout nonsense.
TGNumberEntryField * fRunEntryField
Number entry form field.
UInt_t getCurrentEvent()
Returns the current event number.
TGHorizontalFrame * fRunPanel
A horizontal frame.
static MagicControlPanel * Instance()
The instance generator (there should only be one instance of the MagicControlPanel at a time...
static MagicDisplay * Instance()
Returns a pointer to the active MagicDisplay. This is very useful if you want to access the TTree&#39;s d...
The Magic Display control panel.
int displayThisEvent(UInt_t eventNumber, Int_t run=-1)
Displays a specified event number (from the specified run number). This is an increddibly useful and ...
TGVerticalFrame * fEntryPanel
A vertical frame.
The Marvellous ANITA Graphical Interface and Class Display (Magic Display)
Definition: MagicDisplay.h:75
TGHorizontalFrame * fEventPanel
A horizontal frame.
TGLabel * fEventLabel
It&#39;s a label.
TGLabel * fRunLabel
It&#39;s a label.