]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TGeant4/TG4MainFrame.cxx
Update to track display by Chuncheng
[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 "TG4Globals.h"
19
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("&Main Window",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 G4String editortxt =
177 "\n**********************************************"
178 "\n**********************************************"
179 "\nWelcome to ALICE Geant4 Geometry Browser. \n"
180 "Clicking with the right button on a volume icon\n" 
181 "will produce the volume's image. "
182 "\n\n**********************************************"
183 "\n**********************************************";
184 //=================================================================
185 //----->Process messages from widgets
186     switch (GET_MSG(msg)) {
187     
188     case kC_TEXTENTRY:
189         switch (GET_SUBMSG(msg)) {
190         case kTE_TEXTCHANGED:
191             switch (parm1) {
192             case 300:
193                 G4cout <<" Acting in TextEntry !!! " << G4endl;
194                 
195                 break;
196                 
197              default:
198                  break;
199             };
200             
201          default:
202             break;
203          }
204         break;
205
206 //---->case Handle Popup menus    
207     case kC_COMMAND:
208         switch (GET_SUBMSG(msg)) {
209                 
210             case kCM_TAB:
211                G4cout << "!!!!CLICKING IN A TAB no.  " 
212                       << fTab->GetCurrent() << "   !!!" << G4endl;
213                break;
214         
215             case kCM_MENU:
216                switch (parm1) {
217
218                    case 1:
219                      fTab->SetTab(0);
220                      flistTreeFrame->SendCloseMessage();
221                      buttons = kMBOk;
222                     // for (Int_t i=1; i<3; i++)
223                     //      buttons |= i;
224                     new TGMsgBox(fClient->GetRoot(), this,
225                                  lMsgBTtleBf->GetString(), lMsgBAnnBf2->GetString(),
226                                  icontype, buttons, &retval);
227                            // if not here, produces
228                            // Error in <RootX11ErrorHandler>: BadWindow 
229                            // (invalid Window parameter) (XID: 100663461)                                             
230                      TGMainFrame::CloseWindow();
231                              break;  
232
233                   case 2:
234                      G4cout << "\n\n!!!!EXITING. BYE!!!\n\n" << G4endl; 
235                      CloseWindow();   //-->and exit root
236                      break;
237                      
238                    case 3:
239                       //-->popup Message 
240                       buttons = kMBDismiss;
241                       new TGMsgBox(fClient->GetRoot(), this,
242                                   lMsgBTtleBf->GetString(), lMsgBAnnBf1->GetString(),
243                                   icontype, buttons, &retval);
244                       break;
245                       
246                   case 4:
247                      //-->editor window
248                      {
249                       TG4Editor* ed = new TG4Editor(this, 400, 150);
250                       ed->LoadBuffer(editortxt);
251                       ed->Popup();
252                       };
253                       break;
254                   
255                   default:    
256                      break;
257                 };
258                 
259             case kCM_COMBOBOX: 
260                 switch(parm1) {
261                 
262                     case 100:
263                       fvolumesFrames->DisplayVolumeCharacteristics();
264                       break;
265                       
266                     case 200:
267                       fmaterialsFrames->DisplayMaterialCharacteristics( 0 );
268                       break;
269                      
270                     default:
271                       break;
272                };
273                
274            case kCM_BUTTON:
275                switch(parm1) {
276                
277                    case 301:   
278                      fvolumesFrames->DisplayUserLimits();
279                      break;
280                      
281                    case 302:
282                       fvolumesFrames->DisplayCuts();
283                       break;
284                       
285                    case 303:
286                       fvolumesFrames->DisplayControls();
287                       break;
288                       
289                    default:
290                       break;
291                };
292                
293             default:
294                break;
295          }
296          break;    
297
298 //----->case Handle volumes ListTree
299     case kC_LISTTREE:
300         flistTreeFrame->ProcessSubMessage( msg, parm1);    
301         break;
302
303 //---->default for GET_MSG      
304     default:
305         break;
306     }
307
308     delete lMsgBTtleBf;
309     delete lMsgBAnnBf1;
310     delete lMsgBAnnBf2; 
311    
312     return kTRUE;
313 }
314