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