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

Last change on this file since 961 was 961, checked in by tbretz, 23 years ago
*** empty log message ***
File size: 11.4 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): Harald Kornmayer 1/2001 (harald@mppmu.mpg.de)
19! Author(s): Thomas Bretz 12/2000 (tbretz@uni-sw.gwdg.de)
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
281// ======================================================================
282
283void MGDisplayAdc::CloseWindow()
284{
285 //
286 // The close message is generated by the window manager when its close
287 // window menu item is selected.
288 //
289 delete this;
290}
291
292
293
294// ======================================================================
295// ======================================================================
296
297Bool_t MGDisplayAdc::BuildHistoList()
298{
299 //
300 // looks in the container of the AdcSpectra and reads in the
301 // Histogramms in there.
302 //
303 // In the class MHFadcCam are in fact two lists. One for the high and
304 // one for the low gain. Here we will use only the high gain list!!!
305 // With some special options (settings in the gui) we will also be able
306 // to plot the low gain
307 //
308 const Int_t nhi = fHists->GetEntries();
309 for (Int_t i=0 ; i<nhi; i++)
310 fHistoList->AddEntry(fHists->GetHistHi(i)->GetName(), i+1);
311
312 fHistoList->MapSubwindows();
313 fHistoList->Layout();
314
315 return kTRUE;
316}
317
318// ======================================================================
319// ======================================================================
320void MGDisplayAdc::UpdateHist()
321{
322 const Int_t selected = fHistoList->GetSelected();
323
324 fHistoList->Select(selected); // ???
325
326 fCanvas->Clear();
327
328 switch (fHistoType)
329 {
330 case M_RADIO_HI:
331 case M_RADIO_LO:
332 fCanvas->Divide(1, 1);
333
334 fCanvas->cd();
335 if (fHistoType==M_RADIO_HI)
336 fHists->DrawHi(selected-1);
337 else
338 fHists->DrawLo(selected-1);
339 break;
340
341 case M_RADIO_LH:
342 fCanvas->Divide(1, 2);
343
344 fCanvas->cd(1);
345 fHists->DrawHi(selected-1);
346
347 fCanvas->cd(2);
348 fHists->DrawLo(selected-1);
349 break;
350 }
351
352 fHistoList->SetTopEntry(selected);
353
354 fCanvas->Modified();
355 fCanvas->Update();
356
357 fSlider->SetPosition(selected);
358}
359
360Bool_t MGDisplayAdc::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
361{
362 //
363 // Process events generated by the buttons in the frame.
364 //
365 switch (GET_MSG(msg))
366 {
367 case kC_COMMAND:
368 switch (GET_SUBMSG(msg))
369 {
370 case kCM_BUTTON:
371 switch (parm1)
372 {
373 case M_BUTTON_SAVE:
374 cout << "Sorry, not yet implemented!" << endl;
375 return kTRUE;
376
377 case M_BUTTON_PRINT:
378 cout << "Sorry, not yet implemented!" << endl;
379 return kTRUE;
380
381 case M_BUTTON_RESET:
382 cout << "Sorry, not yet implemented!" << endl;
383 return kTRUE;
384
385 case M_BUTTON_CLOSE:
386 CloseWindow();
387 return kTRUE;
388
389 case M_BUTTON_PREV:
390 case M_BUTTON_NEXT:
391 {
392 const Int_t selected = fHistoList->GetSelected();
393
394 if ((parm1==M_BUTTON_PREV && selected==1) ||
395 (parm1==M_BUTTON_NEXT && selected==577))
396 return kTRUE;
397
398 fHistoList->Select(parm1==M_BUTTON_PREV ? selected-1 : selected+1);
399 UpdateHist();
400 }
401 return kTRUE;
402 }
403 return kTRUE;
404
405 case kCM_RADIOBUTTON:
406 switch(parm1)
407 {
408 case M_RADIO_HI:
409 case M_RADIO_LO:
410 case M_RADIO_LH:
411 fHistoType = parm1;
412 UpdateHist();
413 return kTRUE;
414 }
415 return kTRUE;
416 }
417
418 case kCM_LISTBOX:
419 if (GET_SUBMSG(msg) == M_LIST_HISTO)
420 UpdateHist();
421
422 return kTRUE;
423
424 case kC_VSLIDER:
425 if (GET_SUBMSG(msg)!=kSL_POS || parm1!=M_VSId1)
426 return kTRUE;
427
428 // Check for the slider movement and sicronise with TGListBox
429 if (parm2<1 || parm2>577)
430 return kTRUE;
431
432 fHistoList->Select(parm2);
433 UpdateHist();
434 return kTRUE;
435 }
436
437 return kTRUE;
438}
Note: See TracBrowser for help on using the repository browser.