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

Last change on this file since 2041 was 2010, checked in by tbretz, 22 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->HasHi(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 const Int_t idx = selected-1;
330
331 if (!fHists->HasHi(idx))
332 return;
333
334 const Int_t type = fHists->HasLo(idx) ? fHistoType : M_RADIO_HI;
335
336 switch (type)
337 {
338 case M_RADIO_HI:
339 case M_RADIO_LO:
340 fCanvas->Divide(1, 1);
341
342 fCanvas->cd();
343 if (type==M_RADIO_HI)
344 fHists->DrawHi(idx);
345 else
346 fHists->DrawLo(idx);
347 break;
348
349 case M_RADIO_LH:
350 fCanvas->Divide(1, 2);
351
352 fCanvas->cd(1);
353 fHists->DrawHi(idx);
354
355 fCanvas->cd(2);
356 fHists->DrawLo(idx);
357 break;
358 }
359
360 fHistoList->SetTopEntry(selected);
361
362 fCanvas->Modified();
363 fCanvas->Update();
364
365 fSlider->SetPosition(selected);
366}
367
368Bool_t MGDisplayAdc::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
369{
370 //
371 // Process events generated by the buttons in the frame.
372 //
373 switch (GET_MSG(msg))
374 {
375 case kC_COMMAND:
376 switch (GET_SUBMSG(msg))
377 {
378 case kCM_BUTTON:
379 switch (parm1)
380 {
381 case M_BUTTON_SAVE:
382 fCanvas->SaveAs();
383 cout << "Sorry, no well implemented!" << endl;
384 return kTRUE;
385
386 case M_BUTTON_PRINT:
387 {
388 char *txt = (char*)"canvasXXXXXX";
389 mkstemp(txt);
390 TString name = txt;
391 name += ".ps";
392 fCanvas->SaveAs(name);
393 cout << "Calling 'lpr " << name << ".ps'" << endl;
394 gSystem->Exec(TString("lpr ")+name+".ps");
395 gSystem->Exec(TString("rm ")+name+".ps");
396 }
397 cout << "Sorry, not well implemented!" << endl;
398 return kTRUE;
399
400 case M_BUTTON_RESET:
401 cout << "Sorry, not yet implemented!" << endl;
402 return kTRUE;
403
404 case M_BUTTON_CLOSE:
405 CloseWindow();
406 return kTRUE;
407
408 case M_BUTTON_PREV:
409 case M_BUTTON_NEXT:
410 {
411 const Int_t selected = fHistoList->GetSelected();
412
413 if ((parm1==M_BUTTON_PREV && selected==1) ||
414 (parm1==M_BUTTON_NEXT && selected==577))
415 return kTRUE;
416
417 fHistoList->Select(parm1==M_BUTTON_PREV ? selected-1 : selected+1);
418 UpdateHist();
419 }
420 return kTRUE;
421 }
422 return kTRUE;
423
424 case kCM_RADIOBUTTON:
425 switch(parm1)
426 {
427 case M_RADIO_HI:
428 case M_RADIO_LO:
429 case M_RADIO_LH:
430 fHistoType = parm1;
431 UpdateHist();
432 return kTRUE;
433 }
434 return kTRUE;
435 }
436
437 case kCM_LISTBOX:
438 if (GET_SUBMSG(msg) == M_LIST_HISTO)
439 UpdateHist();
440
441 return kTRUE;
442
443 case kC_VSLIDER:
444 if (GET_SUBMSG(msg)!=kSL_POS || parm1!=M_VSId1)
445 return kTRUE;
446
447 // Check for the slider movement and synchronise with TGListBox
448 if (parm2<1 || parm2>577)
449 return kTRUE;
450
451 fHistoList->Select(parm2);
452 UpdateHist();
453 return kTRUE;
454 }
455
456 return kTRUE;
457}
Note: See TracBrowser for help on using the repository browser.