]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TGeant4/TG4MainFrame.cxx
changed printout
[u/mrichter/AliRoot.git] / TGeant4 / TG4MainFrame.cxx
1 // $Id$
2 // Category: interfaces
3 //
4 // Author: D. Adamova
5 //
6 //========================================================
7 //
8 //------------TG4MainFrame.cxx--------------------------------//
9 //---------Main Window for the AG4 Geometry Browser---//
10 //
11 //========================================================= 
12
13 #include "TG4MainFrame.h"
14 #include "TG4Editor.h"
15 #include "TG4ListTreeFrame.h"
16 #include "TG4VolumesFrames.h"
17 #include "TG4MaterialsFrames.h"
18 #include "TG4GuiVolume.h"
19 #include "TG4Globals.h"
20
21 #include <TGTab.h>
22 #include <TGMenu.h>
23 #include <TApplication.h>
24 #include <TGMsgBox.h>
25 #include <TGTextBuffer.h>
26
27 #include <G4LogicalVolume.hh>
28
29 ClassImp(TG4MainFrame)
30
31 TG4MainFrame::TG4MainFrame(const TGWindow* p, UInt_t w, UInt_t h)
32     : TGMainFrame(p, w, h)
33 {
34 //---> Creates the main frame 
35
36   fMenuBarLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 0, 0, 1, 1);
37   fMenuBarItemLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0);
38   fMenuBarHelpLayout = new TGLayoutHints(kLHintsTop | kLHintsRight);
39
40   fPopupMenu= new TGPopupMenu(gClient->GetRoot());
41   fPopupMenu->AddEntry("&Close Window", 1);
42   fPopupMenu->AddEntry("&Exit Root", 2);
43   
44   fPopupMenuTest = new TGPopupMenu(this);
45   fPopupMenuTest->AddEntry("&Message", 3);
46     
47   fPopupMenuHelp = new TGPopupMenu(gClient->GetRoot());
48   fPopupMenuHelp->AddEntry("&About", 4);
49
50    fPopupMenu->Associate(this);
51    fPopupMenuTest->Associate(this);
52    fPopupMenuHelp->Associate(this);
53  
54    fMenuBar = new TGMenuBar(this, 1, 1, kHorizontalFrame);
55    fMenuBar->AddPopup("&CloseWindow/ExitRoot",fPopupMenu, fMenuBarItemLayout);
56    fMenuBar->AddPopup("&Draw Control", fPopupMenuTest, fMenuBarItemLayout);
57    fMenuBar->AddPopup("&Report", fPopupMenuHelp, fMenuBarHelpLayout);
58
59    AddFrame(fMenuBar, fMenuBarLayout);
60  
61 //------>Adding a tab
62    fTab = new TGTab(this, 400, 400);
63    TGLayoutHints* lTabLayout = new TGLayoutHints(kLHintsBottom | kLHintsExpandX |
64                                           kLHintsExpandY, 2, 2, 5, 1);
65    AddFrame(fTab, lTabLayout);
66
67 //------->Frame for ListTree of logical volumes
68    flistTreeFrame = new TG4ListTreeFrame( fTab, this);
69
70 //----->Frame for volumes properties
71    fvolumesFrames = new TG4VolumesFrames( fTab, this);
72
73
74 //----->Frame for materials properties
75    fmaterialsFrames = new TG4MaterialsFrames( fTab, this);
76
77 //----->Window name and final mapping
78    SetWindowName("ALICE Geant4 Browser");
79    MapSubwindows();
80    Resize(GetDefaultSize());
81  
82    MapWindow();
83    
84 }
85
86 TG4MainFrame::TG4MainFrame(const TG4MainFrame& mf)
87    : TGMainFrame( (const TGMainFrame&) mf)
88 {
89 // Dummy copy constructor 
90   TG4Globals::Exception(
91     "Attempt to use TG4MainFrame copy constructor.");
92 }
93
94 TG4MainFrame& TG4MainFrame::operator=(const TG4MainFrame& mf)
95 {
96   // check assignement to self
97   if (this == &mf) return *this;
98
99   TG4Globals::Exception(
100     "Attempt to assign TG4MainFrame singleton.");
101     
102   return *this;  
103 }
104
105 TG4MainFrame::~TG4MainFrame()
106 {
107 //----> Delete created widgets.
108    G4cout << "\n Now in the TG4MainFrame destructor\n" << G4endl;  
109    delete fMenuBarLayout;
110    delete fMenuBarItemLayout;
111    delete fMenuBarHelpLayout;
112
113    delete fPopupMenu;
114    delete fPopupMenuTest;
115    delete fPopupMenuHelp;
116  
117    delete fMenuBar;
118    delete fTab;
119
120    delete flistTreeFrame;
121    delete fvolumesFrames;   
122    delete fmaterialsFrames;
123 }
124
125 TG4VolumesFrames* TG4MainFrame::GetVolumesFrames() const
126 {
127 //---> For use in TG4GeometryGUI
128    return fvolumesFrames;
129 }
130
131 TG4MaterialsFrames* TG4MainFrame::GetMaterialsFrames() const
132 {
133 //---> For use in TG4GeometryGUI
134    return fmaterialsFrames;
135 }
136
137 TG4ListTreeFrame* TG4MainFrame::GetListTreeFrame() const
138 {
139 //---> For use in TG4GeometryGUI
140    return flistTreeFrame;
141 }
142
143 void TG4MainFrame::CloseWindow()
144 {
145    // Got close message for this MainFrame. Calls parent CloseWindow()
146    // (which destroys the window) ((//and terminate the application)).
147    // The close message is generated by the window manager when its close
148    // window menu item is selected.
149
150    TGMainFrame::CloseWindow();
151    gApplication->Terminate(0);
152 }
153
154 Bool_t TG4MainFrame::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
155 {
156 //---> Processes events generated by the widgets in the frame
157
158 //=============================================================
159 //-----> text buffers for Message Boxes
160    TGTextBuffer* lMsgBTtleBf = new TGTextBuffer(100);
161    TGTextBuffer* lMsgBAnnBf1 = new TGTextBuffer(100);
162    TGTextBuffer* lMsgBAnnBf2 = new TGTextBuffer(100);
163    lMsgBTtleBf->AddText(0, "MsgBox");
164    lMsgBAnnBf1->AddText(0, "Volumes drawing almost completed !");
165    lMsgBAnnBf2->AddText(0, "YOU'RE CLOSING THE MAIN WINDOW!");
166
167
168 //=================================================================
169 //----->Message Box
170
171    int  retval;
172    EMsgBoxIcon icontype = kMBIconExclamation;
173    Int_t buttons;
174 //===================================================================
175 //----->Editor window text
176 const char *editortxt =
177 "This is a to-be AG4 Geometry Browser. \n"
178 "The volumes drawing coming soon.\n" ;
179
180
181 //=================================================================
182 //----->Process messages from widgets
183     switch (GET_MSG(msg)) {
184     
185     case kC_TEXTENTRY:
186         switch (GET_SUBMSG(msg)) {
187         case kTE_TEXTCHANGED:
188             switch (parm1) {
189             case 300:
190                 G4cout <<" Acting in TextEntry !!! " << G4endl;
191                 
192                 break;
193                 
194              default:
195                  break;
196             };
197             
198          default:
199             break;
200          }
201         break;
202
203 //---->case Handle Popup menus    
204     case kC_COMMAND:
205         switch (GET_SUBMSG(msg)) {
206             case kCM_MENU:
207                switch (parm1) {
208
209                    case 1:
210                    
211                      buttons = kMBOk;
212                     // for (Int_t i=1; i<3; i++)
213                     //      buttons |= i;
214                      new TGMsgBox(fClient->GetRoot(), this,
215                                   lMsgBTtleBf->GetString(), lMsgBAnnBf2->GetString(),
216                                   icontype, buttons, &retval);
217                            // if not here, produces
218                            // Error in <RootX11ErrorHandler>: BadWindow 
219                            // (invalid Window parameter) (XID: 100663461)                     
220                      TGMainFrame::CloseWindow();
221                              break;  
222
223                   case 2:
224                      G4cout << "\n\n!!!!EXITING. BYE!!!\n\n" << G4endl; 
225                      CloseWindow();   //-->and exit root
226                      break;
227                      
228                    case 3:
229                       //-->popup Message 
230                       buttons = kMBDismiss;
231                       new TGMsgBox(fClient->GetRoot(), this,
232                                   lMsgBTtleBf->GetString(), lMsgBAnnBf1->GetString(),
233                                   icontype, buttons, &retval);
234                       break;
235                       
236                   case 4:
237                      //-->editor window
238                      {
239                       TG4Editor* ed = new TG4Editor(this, 400, 150);
240                       ed->LoadBuffer(editortxt);
241                       ed->Popup();
242                       };
243                       break;
244                   
245                   default:    
246                      break;
247                 };
248                 
249             case kCM_COMBOBOX: 
250                 switch(parm1) {
251                 
252                     case 100:
253                       fvolumesFrames->DisplayVolumeCharacteristics();
254                       break;
255                       
256                     case 200:
257                       fmaterialsFrames->DisplayMaterialCharacteristics();
258                       break;
259                      
260                     default:
261                       break;
262                };
263                
264             default:
265                break;
266          }
267          break;    
268
269 //----->case Handle volumes ListTree
270     case kC_LISTTREE:
271         flistTreeFrame->ProcessSubMessage( msg, parm1);    
272         break;
273
274 //---->default for GET_MSG      
275     default:
276         break;
277     }
278
279     delete lMsgBTtleBf;
280     delete lMsgBAnnBf1;
281     delete lMsgBAnnBf2; 
282    
283     return kTRUE;
284 }
285