source: trunk/MagicSoft/Mars/mmain/MGPrototyp.cc@ 859

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