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

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