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

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