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

Last change on this file since 711 was 706, checked in by tbretz, 24 years ago
*** empty log message ***
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 return strcmp ( fInputFile, "\n") == 0 ? kFALSE : kTRUE;
225}
226
227
228// ======================================================================
229// ======================================================================
230
231Bool_t MGMonteCarloMain::ProcessMessage(Long_t msg, Long_t parm1, Long_t)
232{
233 // Process events generated by the buttons in the frame.
234
235 Int_t buttons = 4, retval = 0 ;
236 Char_t wort[100] ;
237 Char_t extens[5] ;
238 Char_t command[110] ;
239
240 TGFileItem *item ; // to process items in the file view container
241 void *np = NULL ; // null pointer
242
243 switch (GET_MSG(msg))
244 {
245 case kC_COMMAND:
246 switch (GET_SUBMSG(msg))
247 {
248 case kCM_BUTTON:
249
250 switch (parm1)
251 {
252
253 case M_BUTTON_ACTION:
254
255 if ( InputFileSelected() == kFALSE ) { // it is not selected
256
257 new TGMsgBox(fClient->GetRoot(), this, "ERROR!",
258 "No Input (root) File selected!", kMBIconExclamation, buttons, &retval);
259 break ;
260 }
261
262 new TGMsgBox(fClient->GetRoot(), this, "INFORMATION!",
263 "Put Intelligence here!!!", kMBIconExclamation, buttons, &retval);
264
265 break ;
266
267 case M_PBUTTON_CDIR_UP :
268
269 // goto the parent directory
270
271 gSystem->ChangeDirectory("..") ;
272 fDir->RemoveEntry(1) ;
273 sprintf (wort, "%s", gSystem->WorkingDirectory() ) ;
274 fDir->AddEntry(wort,1) ;
275 fDir->MapSubwindows() ;
276 fDir->Layout() ;
277 fFileCont->ChangeDirectory( wort ) ;
278 fFileCont->DisplayDirectory() ;
279
280 break ;
281
282 case M_PBUTTON_LIST_MODE:
283 fFileView->SetViewMode(kLVList) ;
284 fDetail->SetState(kButtonUp) ;
285
286 break ;
287
288 case M_PBUTTON_DETAIL_MODE:
289 fFileView->SetViewMode(kLVDetails) ;
290 fListMode->SetState(kButtonUp) ;
291
292 break ;
293
294 default:
295 break ;
296 }
297
298 case kCM_MENU:
299
300 switch (parm1) {
301 case M_FILE_CLOSE:
302 CloseWindow() ;
303
304 break;
305 }
306 break ;
307
308 default:
309 break ;
310
311 }
312
313 case kC_CONTAINER:
314 switch (GET_SUBMSG(msg)) {
315
316 // case kCT_ITEMCLICK:
317 // printf ("itemclick\n");
318 // break;
319
320
321 case kCT_ITEMDBLCLICK:
322 //
323 // process the double click in the file view container
324 //
325
326 if ( parm1 == kButton1) {
327 if ( fFileCont->NumSelected() == 1 ) {
328 //
329 // one file selected
330 //
331 item = (TGFileItem *) fFileCont->GetNextSelected(&np) ;
332
333 if ( S_ISDIR(item->GetType()) ) // file is directory
334 {
335 // goto directory
336
337 sprintf (wort, "%s", item->GetItemName()->GetString()) ;
338 fFileCont->ChangeDirectory ( wort ) ;
339 gSystem->ChangeDirectory( wort ) ;
340
341 sprintf (wort, "%s", gSystem->WorkingDirectory() ) ;
342 fDir->RemoveEntry(1) ;
343 fDir->AddEntry( wort, 1 ) ;
344 fDir->MapSubwindows() ;
345 fDir->Layout() ;
346 }
347 else // file is no directory, is a file
348 {
349 sprintf (wort, "%s", item->GetItemName()->GetString() ) ;
350
351 // determine the file type by extensions
352
353 for (Int_t i = 0 ; i<5; i++)
354 extens[i] = '\0' ;
355
356 for ( Int_t i=0; wort[i] != '\0'; i++) {
357 if ( wort[i] == '.') {
358 strncpy (extens, &wort[i+1], 4 ) ;
359 break ;
360 }
361 }
362
363 if ( ! strcmp(extens, "ps") ) { // postscript file
364 sprintf ( command, "gv %s/%s &",
365 gSystem->WorkingDirectory(),
366 wort ) ;
367 gSystem->Exec(command) ;
368 break ;
369 }
370 else if ( ! strcmp(extens, "root") ) { // root file
371 sprintf ( fInputFile, "%s/%s" , gSystem->WorkingDirectory(), wort ) ;
372
373 printf (" %s \n", fInputFile ) ;
374 break ;
375 }
376
377 }
378 }
379 }
380 break;
381
382 default:
383 break ;
384 }
385
386
387
388 default:
389 break;
390 }
391 return kTRUE;
392}
Note: See TracBrowser for help on using the repository browser.