source: trunk/MagicSoft/Mars/mgui/MGDataCheckMain.cc@ 597

Last change on this file since 597 was 571, checked in by harald, 24 years ago
Added the Main gui for MonteCarlo. Now there is also a gui called MGPrototyp. This can be used as the start point for the next guis.
  • Property svn:executable set to *
File size: 12.5 KB
Line 
1#include "MGDataCheckMain.h"
2
3#include <TSystem.h> // gSystem
4
5#include <TGTab.h> // TGTab
6#include <TGMenu.h> // TGPopupMenu
7#include <TGButton.h> // TGTextButton
8#include <TGMsgBox.h> // TGMsgBox
9#include <TGListBox.h> // TGListBox
10#include <TGFSContainer.h> // TGFileContainer
11
12// FIXME: Move to MAGIC.h
13#define S_ISDIR(m) (((m)&(0170000)) == (0040000))
14
15ClassImp(MGDataCheckMain)
16
17enum CommandDataChecker {
18 M_FILE_CLOSE ,
19 M_BUTTON_PEDADC,
20 M_BUTTON_CRADC,
21 M_BUTTON_PEDTDC,
22 M_BUTTON_CRTDC,
23
24 M_PBUTTON_CDIR_UP,
25 M_PBUTTON_LIST_MODE,
26 M_PBUTTON_DETAIL_MODE
27} ;
28
29
30MGDataCheckMain::MGDataCheckMain(const TGWindow *p, const TGWindow *main,
31 UInt_t w, UInt_t h )
32 : TGTransientFrame(p, main, w, h )
33{
34 //
35 // Main window to controll the october test
36 //
37
38 // set non-gui members to starting values
39
40 sprintf ( fInputFile, "\n" ) ;
41
42 //
43 // First create the MenuBar.
44 //
45
46 // Layout objects for menue.
47
48 fLayMenuBar = new TGLayoutHints ( kLHintsTop | kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2 ) ;
49 fLayMenuItem = new TGLayoutHints ( kLHintsTop | kLHintsLeft , 0, 4, 0, 0 ) ;
50
51 // crate the menu bar
52
53 fFileMenu = new TGPopupMenu ( fClient->GetRoot() ) ;
54 fFileMenu->AddEntry ("Close", M_FILE_CLOSE ) ;
55 fFileMenu->Associate(this) ;
56
57 // the button messages are handled by main frame (this)
58
59 fMenuBar = new TGMenuBar ( this, 1, 1, kHorizontalFrame ) ;
60 fMenuBar->AddPopup("File", fFileMenu, fLayMenuItem ) ;
61 AddFrame(fMenuBar, fLayMenuBar ) ;
62
63 //
64 // Create the top window with a lot of buttons
65 //
66
67 fFrameTop = new TGCompositeFrame (this, 300,100, kVerticalFrame ) ;
68
69 fTop1 = new TGHorizontalFrame (fFrameTop, 300, 100 ) ;
70
71 fFrameTop->AddFrame (fTop1, new TGLayoutHints(kLHintsCenterX, 10, 10, 5, 5) );
72
73 fTop2 = new TGHorizontalFrame (fFrameTop, 300, 100 ) ;
74
75 fButPedADC = new TGTextButton(fTop2, "ADC Spectra of Pedestals", M_BUTTON_PEDADC );
76 fButPedADC->Associate(this) ;
77 fTop2->AddFrame (fButPedADC, new TGLayoutHints(kLHintsTop | kLHintsLeft, 10, 10, 5, 5) );
78
79 fButCrADC = new TGTextButton(fTop2, "ADC Specta of Cosmics", M_BUTTON_CRADC );
80 fButCrADC->Associate(this) ;
81 fTop2->AddFrame (fButCrADC, new TGLayoutHints(kLHintsTop | kLHintsLeft, 10, 10, 5, 5) );
82
83 fFrameTop->AddFrame (fTop2, new TGLayoutHints(kLHintsCenterX, 10, 10, 5, 5) );
84
85 fTop3 = new TGHorizontalFrame (fFrameTop, 300, 100 ) ;
86
87 fButPedTDC = new TGTextButton(fTop3, "TDC Spectra of Pedestals", M_BUTTON_PEDTDC );
88 fButPedTDC->Associate(this) ;
89 fTop3->AddFrame (fButPedTDC, new TGLayoutHints(kLHintsTop | kLHintsLeft, 10, 10, 5, 5) );
90
91 fButCrTDC = new TGTextButton(fTop3, "TDC Specta of Cosmics", M_BUTTON_CRTDC );
92 fButCrTDC->Associate(this) ;
93 fTop3->AddFrame (fButCrTDC, new TGLayoutHints(kLHintsTop | kLHintsLeft, 10, 10, 5, 5) );
94
95 fFrameTop->AddFrame (fTop3, new TGLayoutHints(kLHintsCenterX, 10, 10, 5, 5) );
96
97 AddFrame(fFrameTop, new TGLayoutHints (kLHintsTop ) ) ;
98
99
100 //
101 // Create the low window with a tabs in it
102 //
103
104 fFrameLow = new TGCompositeFrame (this, 300,100, kHorizontalFrame ) ;
105
106 fLayTab = new TGLayoutHints ( kLHintsExpandX , 5, 5, 5, 5 ) ;
107
108 // create the first tab
109
110 fTab = new TGTab ( fFrameLow, 400, 400 ) ;
111
112 TGCompositeFrame *tf = fTab->AddTab("Input File") ;
113
114 fTabF1 = new TGCompositeFrame (tf, 100, 100, kHorizontalFrame) ;
115 // tf->AddFrame(fTabF1, fLayTab ) ;
116
117
118 fTabF1a = new TGCompositeFrame (tf, 100, 100, kHorizontalFrame) ;
119 tf->AddFrame(fTabF1a, new TGLayoutHints ( kLHintsTop | kLHintsLeft | kLHintsExpandX, 5, 5, 5, 5 ) ) ;
120
121 fTabF1b = new TGCompositeFrame (tf, 100, 100, kVerticalFrame) ;
122 // tf->AddFrame(fTabF1b, new TGLayoutHints ( kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY , 5, 5, 5, 5 ) ) ;
123 tf->AddFrame(fTabF1b, new TGLayoutHints ( kLHintsExpandX | kLHintsExpandY , 5, 5, 5, 5 ) ) ;
124
125
126 fDir = new TGListBox(fTabF1a, -1) ;
127 fDir->Resize(350,20) ;
128 char temp[100] ;
129 // sprintf ( temp, "%s", START_DIRECTORY ) ;
130 sprintf ( temp, "%s", gSystem->WorkingDirectory() ) ;
131 fDir->AddEntry(temp, 1) ;
132 fTabF1a->AddFrame( fDir, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 5, 5, 5, 5 ) ) ;
133
134
135 fPicCdup = fClient->GetPicture("tb_uplevel.xpm") ;
136 fCdup = new TGPictureButton(fTabF1a, fPicCdup, M_PBUTTON_CDIR_UP ) ;
137 fCdup->SetToolTipText("One Level up!") ;
138 fCdup->Associate(this) ;
139 fTabF1a->AddFrame (fCdup, new TGLayoutHints(kLHintsLeft | kLHintsTop, 5, 5, 5, 5) ) ;
140
141 fPicList = fClient->GetPicture("tb_list.xpm") ;
142 fListMode = new TGPictureButton(fTabF1a, fPicList, M_PBUTTON_LIST_MODE ) ;
143 fListMode->SetToolTipText("List Mode") ;
144 fListMode->Associate(this) ;
145 fListMode->SetState(kButtonUp) ;
146 fListMode->AllowStayDown(kTRUE) ;
147 fListMode->AllowStayDown(kTRUE) ; fTabF1a->AddFrame (fListMode, new TGLayoutHints(kLHintsLeft | kLHintsTop, 5, 5, 5, 5) ) ;
148
149 fPicDetail = fClient->GetPicture("tb_details.xpm") ;
150 fDetail = new TGPictureButton(fTabF1a, fPicDetail, M_PBUTTON_DETAIL_MODE ) ;
151 fDetail->SetToolTipText("Details Mode") ;
152 fDetail->Associate(this) ;
153 fDetail->SetState(kButtonEngaged) ;
154 fDetail->AllowStayDown(kTRUE) ;
155 fTabF1a->AddFrame (fDetail, new TGLayoutHints(kLHintsLeft | kLHintsTop, 5, 5, 5, 5) ) ;
156
157
158 fFileView = new TGListView(fTabF1b, 540, 380 ) ;
159 fFileCont = new TGFileContainer(fFileView->GetViewPort(), 100, 100,
160 kVerticalFrame, fgWhitePixel) ;
161
162 fFileCont->Associate(this) ;
163 fFileView->GetViewPort()->SetBackgroundColor(fgWhitePixel) ;
164 fFileView->SetContainer(fFileCont) ;
165 fFileCont->SetFilter("*") ;
166 // fFileCont->ChangeDirectory(START_DIRECTORY) ;
167 fFileCont->ChangeDirectory(gSystem->WorkingDirectory()) ;
168 fFileView->SetViewMode(kLVDetails);
169 fFileCont->Sort(kSortByName) ;
170
171 fTabF1b->AddFrame(fFileView, new TGLayoutHints(kLHintsTop | kLHintsExpandX | kLHintsExpandY, 5, 5, 5, 5) ) ;
172
173 tf->AddFrame(fTabF1, fLayTab) ;
174
175 fFrameLow->AddFrame ( fTab, new TGLayoutHints(kLHintsBottom | kLHintsExpandX | kLHintsExpandY, 5, 5, 5, 5) );
176
177 AddFrame(fFrameLow, new TGLayoutHints (kLHintsExpandX|kLHintsExpandY) ) ;
178
179 //
180 // Map the window, set up the layout, etc.
181 //
182
183 SetWMSizeHints(400, 350, 1000, 1000, 10, 10 ) ; // set the smallest and biggest size of the Main frame
184
185 MapSubwindows();
186
187 Layout();
188
189 SetWindowName("DataCheck Window");
190 SetIconName("DataCheck");
191
192 MapWindow();
193
194}
195
196
197// ======================================================================
198// ======================================================================
199
200MGDataCheckMain::~MGDataCheckMain()
201{
202 //delete fPicCdup, fPicList, fPicDetail;
203 delete fLayTab;
204 delete fLayMenuBar;
205 delete fLayMenuItem;
206 delete fFileView;
207 delete fFileCont;
208 delete fCdup;
209 delete fListMode;
210 delete fDetail;
211 delete fDir ;
212 delete fTabF1b;
213 delete fTabF1a;
214 delete fTabF1;
215 delete fButPedADC;
216 delete fButCrADC;
217 delete fButPedTDC;
218 delete fButCrTDC;
219 delete fTop3;
220 delete fTop2;
221 delete fTop1;
222 delete fTab;
223 delete fFrameTop;
224 delete fFrameLow;
225 delete fFileMenu;
226 delete fMenuBar;
227
228}
229
230
231// ======================================================================
232// ======================================================================
233
234void MGDataCheckMain::CloseWindow()
235{
236 // Got close message for this MainFrame. Calls parent CloseWindow()
237 // (which destroys the window) and terminate the application.
238 // The close message is generated by the window manager when its close
239 // window menu item is selected.
240
241 delete this ;
242}
243
244
245// ======================================================================
246// ======================================================================
247
248Bool_t MGDataCheckMain::InputFileSelected()
249{
250 // Checks if there is a selected input root file
251
252 if ( strcmp ( fInputFile, "\n") == 0 )
253 {
254 return ( kFALSE ) ;
255 }
256
257 return (kTRUE) ;
258}
259
260
261// ======================================================================
262// ======================================================================
263
264Bool_t MGDataCheckMain::ProcessMessage(Long_t msg, Long_t parm1, Long_t)
265{
266 // Process events generated by the buttons in the frame.
267
268 Int_t buttons = 4, retval = 0 ;
269 Char_t wort[100] ;
270 Char_t extens[5] ;
271 Char_t command[110] ;
272
273 TGFileItem *item ; // to process items in the file view container
274 void *np = NULL ; // null pointer
275
276 switch (GET_MSG(msg))
277 {
278 case kC_COMMAND:
279 switch (GET_SUBMSG(msg))
280 {
281 case kCM_BUTTON:
282
283 switch (parm1)
284 {
285
286 case M_BUTTON_PEDADC:
287
288 if ( InputFileSelected() == kFALSE ) { // it is not selected
289
290 new TGMsgBox(fClient->GetRoot(), this, "ERROR!",
291 "No Input (root) File selected!", kMBIconExclamation, buttons, &retval);
292 break ;
293 }
294
295 fViewAdc.AdcSpectra(fInputFile, "PedEvents" ) ;
296
297 break ;
298
299
300 case M_BUTTON_CRADC:
301
302 if ( InputFileSelected() == kFALSE ) { // it is not selected
303
304 new TGMsgBox(fClient->GetRoot(), this, "ERROR!",
305 "No Input (root) File selected!", kMBIconExclamation, buttons, &retval);
306 break ;
307 }
308
309 fViewAdc.AdcSpectra(fInputFile, "Events" ) ;
310
311 break ;
312
313 case M_BUTTON_PEDTDC:
314
315 if ( InputFileSelected() == kFALSE ) { // it is not selected
316
317 new TGMsgBox(fClient->GetRoot(), this, "ERROR!",
318 "No Input (root) File selected!", kMBIconExclamation, buttons, &retval);
319 break ;
320 }
321
322 // fOctober.PedTdcSpectra(fInputFile) ;
323
324 break ;
325
326 case M_BUTTON_CRTDC:
327
328 if ( InputFileSelected() == kFALSE ) { // it is not selected
329
330 new TGMsgBox(fClient->GetRoot(), this, "ERROR!",
331 "No Input (root) File selected!", kMBIconExclamation, buttons, &retval);
332 break ;
333 }
334
335
336
337 break ;
338
339 case M_PBUTTON_CDIR_UP :
340
341 // goto the parent directory
342
343 gSystem->ChangeDirectory("..") ;
344 fDir->RemoveEntry(1) ;
345 sprintf (wort, "%s", gSystem->WorkingDirectory() ) ;
346 fDir->AddEntry(wort,1) ;
347 fDir->MapSubwindows() ;
348 fDir->Layout() ;
349 fFileCont->ChangeDirectory( wort ) ;
350 fFileCont->DisplayDirectory() ;
351
352 break ;
353
354 case M_PBUTTON_LIST_MODE:
355 fFileView->SetViewMode(kLVList) ;
356 fDetail->SetState(kButtonUp) ;
357
358 break ;
359
360 case M_PBUTTON_DETAIL_MODE:
361 fFileView->SetViewMode(kLVDetails) ;
362 fListMode->SetState(kButtonUp) ;
363
364 break ;
365
366 default:
367 break ;
368 }
369
370 case kCM_MENU:
371
372 switch (parm1) {
373 case M_FILE_CLOSE:
374 CloseWindow() ;
375
376 break;
377 }
378 break ;
379
380 default:
381 break ;
382
383 }
384
385 case kC_CONTAINER:
386 switch (GET_SUBMSG(msg)) {
387
388 // case kCT_ITEMCLICK:
389 // printf ("itemclick\n");
390 // break;
391
392
393 case kCT_ITEMDBLCLICK:
394 //
395 // process the double click in the file view container
396 //
397
398 if ( parm1 == kButton1) {
399 if ( fFileCont->NumSelected() == 1 ) {
400 //
401 // one file selected
402 //
403 item = (TGFileItem *) fFileCont->GetNextSelected(&np) ;
404
405 if ( S_ISDIR(item->GetType()) ) // file is directory
406 {
407 // goto directory
408
409 sprintf (wort, "%s", item->GetItemName()->GetString()) ;
410 fFileCont->ChangeDirectory ( wort ) ;
411 gSystem->ChangeDirectory( wort ) ;
412
413 sprintf (wort, "%s", gSystem->WorkingDirectory() ) ;
414 fDir->RemoveEntry(1) ;
415 fDir->AddEntry( wort, 1 ) ;
416 fDir->MapSubwindows() ;
417 fDir->Layout() ;
418 }
419 else // file is no directory, is a file
420 {
421 sprintf (wort, "%s", item->GetItemName()->GetString() ) ;
422
423 // determine the file type by extensions
424
425 for (Int_t i = 0 ; i<5; i++)
426 extens[i] = '\0' ;
427
428 for ( Int_t i=0; wort[i] != '\0'; i++) {
429 if ( wort[i] == '.') {
430 strncpy (extens, &wort[i+1], 4 ) ;
431 break ;
432 }
433 }
434
435 if ( ! strcmp(extens, "ps") ) { // postscript file
436 sprintf ( command, "gv %s/%s &",
437 gSystem->WorkingDirectory(),
438 wort ) ;
439 gSystem->Exec(command) ;
440 break ;
441 }
442 else if ( ! strcmp(extens, "root") ) { // root file
443 sprintf ( fInputFile, "%s/%s" , gSystem->WorkingDirectory(), wort ) ;
444
445 printf (" %s \n", fInputFile ) ;
446 break ;
447 }
448
449 }
450 }
451 }
452 break;
453
454 default:
455 break ;
456 }
457
458
459
460 default:
461 break;
462 }
463 return kTRUE;
464}
Note: See TracBrowser for help on using the repository browser.