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