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

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