source: branches/start/MagicSoft/MarsOctober/mocttest/MGOctMain.cc@ 9492

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