source: trunk/MagicSoft/Mars/mgui/MGMonteCarloMain.cc@ 602

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