source: trunk/MagicSoft/Mars/mdatacheck/MGDisplayAdc.cc@ 1164

Last change on this file since 1164 was 1081, checked in by tbretz, 23 years ago
*** empty log message ***
File size: 11.1 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of MARS, the MAGIC Analysis and Reconstruction
5! * Software. It is distributed to you in the hope that it can be a useful
6! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
7! * It is distributed WITHOUT ANY WARRANTY.
8! *
9! * Permission to use, copy, modify and distribute this software and its
10! * documentation for any purpose is hereby granted without fee,
11! * provided that the above copyright notice appear in all copies and
12! * that both that copyright notice and this permission notice appear
13! * in supporting documentation. It is provided "as is" without express
14! * or implied warranty.
15! *
16!
17!
18! Author(s): Thomas Bretz 12/2000 <mailto:tbretz@uni-sw.gwdg.de>
19! Author(s): Harald Kornmayer 1/2001
20!
21! Copyright: MAGIC Software Development, 2000-2001
22!
23!
24\* ======================================================================== */
25
26#include "MGDisplayAdc.h"
27
28#include <iostream.h> // cout for debugging
29
30#include <TGButton.h> // TGTextButton
31#include <TCanvas.h> // TCanvas.h
32#include <TGMsgBox.h> // TGMsgBox
33#include <TGListBox.h> // TGListBox
34#include <TGSlider.h> // TGVSlider
35#include <TGButtonGroup.h> // TGVButtonGroup
36#include <TRootEmbeddedCanvas.h> // TRootEmbeddedCanvas
37
38#include "MHFadcCam.h"
39
40enum ComIdentDisplayAdc
41{
42 M_BUTTON_SAVE,
43 M_BUTTON_PRINT,
44 M_BUTTON_PRINTALL,
45 M_BUTTON_CLOSE,
46
47 M_BUTTON_PREV,
48 M_BUTTON_NEXT,
49
50 M_LIST_HISTO,
51 M_RADIO_HI,
52 M_RADIO_LO,
53 M_RADIO_LH,
54 M_BUTTON_RESET,
55 M_VSId1
56};
57
58void MGDisplayAdc::AddFrameTop(TGHorizontalFrame *frame)
59{
60 //
61 // left part of top frame
62 //
63 TGVerticalFrame *left = new TGVerticalFrame(frame, 80, 300, kFitWidth);
64 fList->Add(left);
65
66 fHistoList = new TGListBox (left, M_LIST_HISTO);
67 fHistoList->Associate(this);
68 fHistoList->Resize(100, 405);
69
70 fList->Add(fHistoList);
71
72 TGLayoutHints *laylist = new TGLayoutHints(kLHintsNormal, 10, 10, 10, 10);
73 fList->Add(laylist);
74
75 left->AddFrame(fHistoList, laylist);
76
77 //
78 // middle part of top frame
79 //
80 TGVerticalFrame *mid = new TGVerticalFrame(frame, 80, 20, kFitWidth);
81 fList->Add(mid);
82
83 // ---
84
85 TGTextButton *prev = new TGTextButton(mid, "Prev Histo", M_BUTTON_PREV);
86 TGTextButton *next = new TGTextButton(mid, "Next Histo", M_BUTTON_NEXT);
87 prev->Associate(this);
88 next->Associate(this);
89
90 fList->Add(prev);
91 fList->Add(next);
92
93 // ---
94
95 fSlider = new TGVSlider(mid, 250, kSlider1|kScaleBoth, M_VSId1);
96 fSlider->Associate(this);
97 fSlider->SetRange(1, 577);
98
99 fList->Add(fSlider);
100
101 // ---
102
103 TGVButtonGroup *group = new TGVButtonGroup(mid);
104 fList->Add(group);
105
106 TGRadioButton *radio1 = new TGRadioButton(group, "&High Gain", M_RADIO_HI);
107 TGRadioButton *radio2 = new TGRadioButton(group, "&Low Gain", M_RADIO_LO);
108 TGRadioButton *radio3 = new TGRadioButton(group, "H&igh/Low Gain", M_RADIO_LH);
109
110 /* FIXME:
111
112 ~TGRadioButton calls TGRadioButton::TGFrame::GetMainFrame
113 which calles fParent->GetFrame()
114
115 fList->Add(radio1);
116 fList->Add(radio2);
117 fList->Add(radio3);
118 */
119
120 radio3->SetState(kButtonDown);
121
122 radio1->Associate(this);
123 radio2->Associate(this);
124 radio3->Associate(this);
125
126 // ---
127
128 TGLayoutHints *laybut1 = new TGLayoutHints(kLHintsCenterX|kLHintsTop, 10, 10, 0, 10);
129 TGLayoutHints *laybut2 = new TGLayoutHints(kLHintsCenterX|kLHintsTop, 10, 10, 10, 5);
130 TGLayoutHints *layslid = new TGLayoutHints(kLHintsCenterX|kLHintsTop);
131
132 fList->Add(laybut1);
133 fList->Add(laybut2);
134 fList->Add(layslid);
135
136 mid->AddFrame(prev, laybut1);
137 mid->AddFrame(fSlider, layslid);
138 mid->AddFrame(next, laybut2);
139 mid->AddFrame(group, laybut2);
140
141 //
142 // right part of top frame
143 //
144 TGVerticalFrame *right = new TGVerticalFrame(frame, 100, 100, kFitWidth);
145 fList->Add(right);
146
147 TRootEmbeddedCanvas *canvas = new TRootEmbeddedCanvas("fECanv", right, 100, 100);
148 fList->Add(canvas);
149
150 TGLayoutHints *laycanv = new TGLayoutHints(kLHintsCenterX|kLHintsCenterY|kLHintsExpandX|kLHintsExpandY, 10, 10, 10, 10);
151 fList->Add(laycanv);
152
153 right->AddFrame(canvas, laycanv);
154
155
156 TGTextButton *reset = new TGTextButton(right, "Reset histo", M_BUTTON_RESET);
157 reset->Associate(this);
158 fList->Add(reset);
159
160 TGLayoutHints *layreset = new TGLayoutHints(kLHintsCenterX|kLHintsTop, 10, 10, 0, 10);
161 fList->Add(layreset);
162
163 right->AddFrame(reset, layreset);
164
165 // ---
166
167 fCanvas = canvas->GetCanvas();
168
169 //
170 // layout the three subframes
171 //
172 TGLayoutHints *layframe1 = new TGLayoutHints(kLHintsTop, 10, 10, 10, 10);
173 TGLayoutHints *layframe2 = new TGLayoutHints(kLHintsCenterX|kLHintsCenterY|kLHintsExpandX|kLHintsExpandY, 10, 10, 10, 10);
174 fList->Add(layframe1);
175 fList->Add(layframe2);
176
177 frame->AddFrame(left, layframe1);
178 frame->AddFrame(mid, layframe1);
179 frame->AddFrame(right, layframe2);
180}
181
182void MGDisplayAdc::AddFrameLow(TGHorizontalFrame *frame)
183{
184 //
185 // the low frame for the control buttons
186 //
187 TGTextButton *but1 = new TGTextButton(frame, "Save", M_BUTTON_SAVE);
188 TGTextButton *but2 = new TGTextButton(frame, "Print", M_BUTTON_PRINT);
189 TGTextButton *but3 = new TGTextButton(frame, "PrintAll", M_BUTTON_PRINTALL);
190 TGTextButton *but4 = new TGTextButton(frame, "Close", M_BUTTON_CLOSE);
191
192 but1->Associate(this);
193 but2->Associate(this);
194 but3->Associate(this);
195 but4->Associate(this);
196
197 fList->Add(but1);
198 fList->Add(but2);
199 fList->Add(but3);
200 fList->Add(but4);
201
202 TGLayoutHints *laybut = new TGLayoutHints(kLHintsNormal, 10, 10, 5, 5);
203 fList->Add(laybut);
204
205 frame->AddFrame(but1, laybut);
206 frame->AddFrame(but2, laybut);
207 frame->AddFrame(but3, laybut);
208 frame->AddFrame(but4, laybut);
209}
210
211MGDisplayAdc::MGDisplayAdc(MHFadcCam *histos,
212 const TGWindow *p, const TGWindow *main,
213 UInt_t w, UInt_t h,
214 UInt_t options)
215: TGTransientFrame(p?p:gClient->GetRoot(), main?main:gClient->GetRoot(), w, h, options),
216 fHistoType(M_RADIO_LH)
217{
218 fHists = (MHFadcCam*)histos->Clone();
219
220 fList = new TList;
221 fList->SetOwner();
222
223 //
224 // Create the to frames
225 //
226 TGHorizontalFrame *frametop = new TGHorizontalFrame(this, 60, 20, kFitWidth);
227 TGHorizontalFrame *framelow = new TGHorizontalFrame(this, 60, 20, kFixedWidth);
228
229 //
230 // Add frames to 'autodel'
231 //
232 fList->Add(frametop);
233 fList->Add(framelow);
234
235 //
236 // Add the gui elements to the two frames
237 //
238 AddFrameTop(frametop);
239 AddFrameLow(framelow);
240
241 //
242 // layout the two frames in this frame
243 //
244 TGLayoutHints *laytop = new TGLayoutHints(kLHintsTop|kLHintsExpandX, 10, 10, 10, 10);
245 TGLayoutHints *laylow = new TGLayoutHints(kLHintsBottom|kLHintsExpandX, 10, 10, 10, 10);
246
247 AddFrame(frametop, laytop);
248 AddFrame(framelow, laylow);
249
250 //
251 // Setup interieur
252 //
253 BuildHistoList();
254
255 //
256 // Here the initial display is set to hitogram 0
257 //
258 fHistoList->Select(1);
259 UpdateHist();
260
261 //
262 // Setup frame
263 //
264 MapSubwindows();
265
266 Layout();
267
268 SetWindowName("ADC Spectra");
269 SetIconName("ADC Spectra");
270
271 MapWindow();
272 SetWMSizeHints(950, 500, 1000, 1000, 1, 1);
273}
274
275MGDisplayAdc::~MGDisplayAdc()
276{
277 delete fList;
278 delete fHists;
279}
280
281void MGDisplayAdc::CloseWindow()
282{
283 //
284 // The close message is generated by the window manager when its close
285 // window menu item is selected.
286 //
287 delete this;
288}
289
290Bool_t MGDisplayAdc::BuildHistoList()
291{
292 //
293 // looks in the container of the AdcSpectra and reads in the
294 // Histogramms in there.
295 //
296 // In the class MHFadcCam are in fact two lists. One for the high and
297 // one for the low gain. Here we will use only the high gain list!!!
298 // With some special options (settings in the gui) we will also be able
299 // to plot the low gain
300 //
301 const Int_t nhi = fHists->GetEntries();
302
303 for (Int_t i=0; i<nhi; i++)
304 fHistoList->AddEntry(fHists->GetHistHi(i)->GetName(), i+1);
305
306 fHistoList->MapSubwindows();
307 fHistoList->Layout();
308
309 return kTRUE;
310}
311
312void MGDisplayAdc::UpdateHist()
313{
314 const Int_t selected = fHistoList->GetSelected();
315
316 if (selected<0)
317 {
318 cout << "MGDisplayAdc: No histograms found in list. " << endl;
319 return;
320 }
321
322 fHistoList->Select(selected); // ???
323
324 fCanvas->Clear();
325
326 switch (fHistoType)
327 {
328 case M_RADIO_HI:
329 case M_RADIO_LO:
330 fCanvas->Divide(1, 1);
331
332 fCanvas->cd();
333 if (fHistoType==M_RADIO_HI)
334 fHists->DrawHi(selected-1);
335 else
336 fHists->DrawLo(selected-1);
337 break;
338
339 case M_RADIO_LH:
340 fCanvas->Divide(1, 2);
341
342 fCanvas->cd(1);
343 fHists->DrawHi(selected-1);
344
345 fCanvas->cd(2);
346 fHists->DrawLo(selected-1);
347 break;
348 }
349
350 fHistoList->SetTopEntry(selected);
351
352 fCanvas->Modified();
353 fCanvas->Update();
354
355 fSlider->SetPosition(selected);
356}
357
358Bool_t MGDisplayAdc::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
359{
360 //
361 // Process events generated by the buttons in the frame.
362 //
363 switch (GET_MSG(msg))
364 {
365 case kC_COMMAND:
366 switch (GET_SUBMSG(msg))
367 {
368 case kCM_BUTTON:
369 switch (parm1)
370 {
371 case M_BUTTON_SAVE:
372 cout << "Sorry, not yet implemented!" << endl;
373 return kTRUE;
374
375 case M_BUTTON_PRINT:
376 cout << "Sorry, not yet implemented!" << endl;
377 return kTRUE;
378
379 case M_BUTTON_RESET:
380 cout << "Sorry, not yet implemented!" << endl;
381 return kTRUE;
382
383 case M_BUTTON_CLOSE:
384 CloseWindow();
385 return kTRUE;
386
387 case M_BUTTON_PREV:
388 case M_BUTTON_NEXT:
389 {
390 const Int_t selected = fHistoList->GetSelected();
391
392 if ((parm1==M_BUTTON_PREV && selected==1) ||
393 (parm1==M_BUTTON_NEXT && selected==577))
394 return kTRUE;
395
396 fHistoList->Select(parm1==M_BUTTON_PREV ? selected-1 : selected+1);
397 UpdateHist();
398 }
399 return kTRUE;
400 }
401 return kTRUE;
402
403 case kCM_RADIOBUTTON:
404 switch(parm1)
405 {
406 case M_RADIO_HI:
407 case M_RADIO_LO:
408 case M_RADIO_LH:
409 fHistoType = parm1;
410 UpdateHist();
411 return kTRUE;
412 }
413 return kTRUE;
414 }
415
416 case kCM_LISTBOX:
417 if (GET_SUBMSG(msg) == M_LIST_HISTO)
418 UpdateHist();
419
420 return kTRUE;
421
422 case kC_VSLIDER:
423 if (GET_SUBMSG(msg)!=kSL_POS || parm1!=M_VSId1)
424 return kTRUE;
425
426 // Check for the slider movement and sicronise with TGListBox
427 if (parm2<1 || parm2>577)
428 return kTRUE;
429
430 fHistoList->Select(parm2);
431 UpdateHist();
432 return kTRUE;
433 }
434
435 return kTRUE;
436}
Note: See TracBrowser for help on using the repository browser.