]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TGeant4/TG4MainFrame.cxx
README updated (R.Barbera)
[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 "TG4VolumesFrames.h"
16 #include "TG4MaterialsFrames.h"
17 #include "TG4GuiVolume.h"
18 #include "TG4Globals.h"
19
20 #include <TGListTree.h>
21 #include <TGCanvas.h>
22 #include <TGTab.h>
23 #include <TGMenu.h>
24 #include <TApplication.h>
25 #include <TGMsgBox.h>
26 #include <TGTextBuffer.h>
27
28 #include <G4LogicalVolume.hh>
29
30
31 ClassImp(TG4MainFrame)
32
33 TG4MainFrame::TG4MainFrame(const TGWindow* p, UInt_t w, UInt_t h)
34     : TGMainFrame(p, w, h)
35 {
36 //---> Creates the main frame 
37
38   fMenuBarLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 0, 0, 1, 1);
39   fMenuBarItemLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0);
40   fMenuBarHelpLayout = new TGLayoutHints(kLHintsTop | kLHintsRight);
41
42   fPopupMenu= new TGPopupMenu(gClient->GetRoot());
43   fPopupMenu->AddEntry("&Close Window", 1);
44   fPopupMenu->AddEntry("&Exit Root", 2);
45   
46   fPopupMenuTest = new TGPopupMenu(this);
47   fPopupMenuTest->AddEntry("&Message", 3);
48     
49   fPopupMenuHelp = new TGPopupMenu(gClient->GetRoot());
50   fPopupMenuHelp->AddEntry("&About", 4);
51
52    fPopupMenu->Associate(this);
53    fPopupMenuTest->Associate(this);
54    fPopupMenuHelp->Associate(this);
55  
56    fMenuBar = new TGMenuBar(this, 1, 1, kHorizontalFrame);
57    fMenuBar->AddPopup("&CloseWindow/ExitRoot",fPopupMenu, fMenuBarItemLayout);
58    fMenuBar->AddPopup("&Draw Control", fPopupMenuTest, fMenuBarItemLayout);
59    fMenuBar->AddPopup("&Report", fPopupMenuHelp, fMenuBarHelpLayout);
60
61    AddFrame(fMenuBar, fMenuBarLayout);
62  
63 //------>Volumes tab
64
65    fTab = new TGTab(this, 400, 400);
66    TGCompositeFrame* tf = fTab->AddTab("Volumes");
67
68    TGLayoutHints* lTabLayout = new TGLayoutHints(kLHintsBottom | kLHintsExpandX |
69                                           kLHintsExpandY, 2, 2, 5, 1);
70    AddFrame(fTab, lTabLayout);
71
72 //------>TGCanvas and a canvas container  
73    fCanvasWindow = new TGCanvas(tf, 400, 240);
74  
75 //----->List    fVolumesListTree
76    fVolumesListTree= new TGListTree(fCanvasWindow->GetViewPort(), 10, 10, kHorizontalFrame,
77                         fgWhitePixel);
78    fVolumesListTree->Associate(this);
79    fCanvasWindow->SetContainer(fVolumesListTree);
80
81  
82    TGLayoutHints *lCanvasLayout = new TGLayoutHints(kLHintsExpandX | kLHintsExpandY);
83    tf->AddFrame(fCanvasWindow, lCanvasLayout);
84  
85 //----------------------------------------------------------------------------- 
86
87 //----->Volumes Properties
88    tf = fTab->AddTab("Volumes Properties");
89    fvolumesFrames = new TG4VolumesFrames( tf, this);
90
91
92 //----->Materials Properties
93    tf = fTab->AddTab("Materials Properties");
94    fmaterialsFrames = new TG4MaterialsFrames( tf, this);
95
96 //----->Window name and final mapping
97    SetWindowName("ALICE Geant4 Browser");
98    MapSubwindows();
99    Resize(GetDefaultSize());
100  
101    MapWindow();
102    
103 }
104
105 TG4MainFrame::TG4MainFrame(const TG4MainFrame& mf)
106    : TGMainFrame( (const TGMainFrame&) mf)
107 {
108 // Dummy copy constructor 
109   TG4Globals::Exception(
110     "Attempt to use TG4MainFrame copy constructor.");
111 }
112
113 TG4MainFrame& TG4MainFrame::operator=(const TG4MainFrame& mf)
114 {
115   // check assignement to self
116   if (this == &mf) return *this;
117
118   TG4Globals::Exception(
119     "Attempt to assign TG4MainFrame singleton.");
120     
121   return *this;  
122 }
123
124 TG4MainFrame::~TG4MainFrame()
125 {
126 //----> Delete created widgets.
127    G4cout << "\n Now in the TG4MainFrame destructor\n" << G4endl;  
128    delete fMenuBarLayout;
129    delete fMenuBarItemLayout;
130    delete fMenuBarHelpLayout;
131
132    delete fPopupMenu;
133    delete fPopupMenuTest;
134    delete fPopupMenuHelp;
135  
136    delete fMenuBar;
137    delete fTab;
138
139    delete fCanvasWindow;
140    delete fVolumesListTree;
141    delete fvolumesFrames;   
142    delete fmaterialsFrames;
143 }
144
145 TG4VolumesFrames* TG4MainFrame::GetVolumesFrames() const
146 {
147 //---> For use in TG4GeometryGUI
148    return fvolumesFrames;
149 }
150
151 TG4MaterialsFrames* TG4MainFrame::GetMaterialsFrames() const
152 {
153 //---> For use in TG4GeometryGUI
154    return fmaterialsFrames;
155 }
156
157 TGListTreeItem*  TG4MainFrame::
158 AddItem(TObject* obj, TGListTreeItem* parent, const char* name, 
159                        const TGPicture* open, const TGPicture* closed)
160 {
161 //----->Add item to the list tree
162     return fVolumesListTree->AddItem(parent, name, obj, open, closed);
163 }
164
165 void TG4MainFrame::CloseWindow()
166 {
167    // Got close message for this MainFrame. Calls parent CloseWindow()
168    // (which destroys the window) ((//and terminate the application)).
169    // The close message is generated by the window manager when its close
170    // window menu item is selected.
171
172    TGMainFrame::CloseWindow();
173    gApplication->Terminate(0);
174 }
175
176 Bool_t TG4MainFrame::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
177 {
178 //---> Processes events generated by the widgets in the frame
179
180 //=============================================================
181 //-----> text buffers for Message Boxes
182    TGTextBuffer* lMsgBTtleBf = new TGTextBuffer(100);
183    TGTextBuffer* lMsgBAnnBf1 = new TGTextBuffer(100);
184    TGTextBuffer* lMsgBAnnBf2 = new TGTextBuffer(100);
185    lMsgBTtleBf->AddText(0, "MsgBox");
186    lMsgBAnnBf1->AddText(0, "Volumes drawing coming soon!");
187    lMsgBAnnBf2->AddText(0, "YOU'RE CLOSING THE MAIN WINDOW!");
188
189
190 //=================================================================
191 //----->Message Box
192
193    int  retval;
194    EMsgBoxIcon icontype = kMBIconExclamation;
195    Int_t buttons;
196 //===================================================================
197 //----->Editor window text
198 const char *editortxt =
199 "This is a to-be AG4 Geometry Browser. \n"
200 "The volumes drawing coming soon.\n" ;
201
202
203 //=================================================================
204 //----->Process messages to widgets
205     switch (GET_MSG(msg)) {
206     
207     case kC_TEXTENTRY:
208         switch (GET_SUBMSG(msg)) {
209         case kTE_TEXTCHANGED:
210             switch (parm1) {
211             case 300:
212                 G4cout <<" Acting in TextEntry !!! " << G4endl;
213                 
214                 break;
215                 
216              default:
217                  break;
218             };
219             
220          default:
221             break;
222          }
223         break;
224
225 //---->case Handle Popup menus    
226     case kC_COMMAND:
227         switch (GET_SUBMSG(msg)) {
228             case kCM_MENU:
229                switch (parm1) {
230
231                    case 1:
232                    
233                      buttons = kMBOk;
234                     // for (Int_t i=1; i<3; i++)
235                     //      buttons |= i;
236                      new TGMsgBox(fClient->GetRoot(), this,
237                                   lMsgBTtleBf->GetString(), lMsgBAnnBf2->GetString(),
238                                   icontype, buttons, &retval);
239                            // if not here, produces
240                            // Error in <RootX11ErrorHandler>: BadWindow 
241                            // (invalid Window parameter) (XID: 100663461)                     
242                      TGMainFrame::CloseWindow();
243                              break;  
244
245                   case 2:
246                      G4cout << "\n\n!!!!EXITING. BYE!!!\n\n" << G4endl; 
247                      CloseWindow();   //-->and exit root
248                      break;
249                      
250                    case 3:
251                       //-->popup Message 
252                       buttons = kMBDismiss;
253                       new TGMsgBox(fClient->GetRoot(), this,
254                                   lMsgBTtleBf->GetString(), lMsgBAnnBf1->GetString(),
255                                   icontype, buttons, &retval);
256                       break;
257                       
258                   case 4:
259                      //-->editor window
260                      {
261                       TG4Editor* ed = new TG4Editor(this, 400, 150);
262                       ed->LoadBuffer(editortxt);
263                       ed->Popup();
264                       };
265                       break;
266                   
267                   default:    
268                      break;
269                 };
270                 
271             case kCM_COMBOBOX: 
272                 switch(parm1) {
273                 
274                     case 100:
275                       fvolumesFrames->DisplayVolumeCharacteristics();
276                       break;
277                       
278                     case 200:
279                       fmaterialsFrames->DisplayMaterialCharacteristics();
280                       break;
281                      
282                     default:
283                       break;
284                };
285                
286             default:
287                break;
288          }
289          break;    
290
291 //----->case Handle volumes ListTree
292     case kC_LISTTREE:
293         switch (GET_SUBMSG(msg)) {
294
295 //----->Cases to Handle mouse click
296    //-->case 1 
297         case kCT_ITEMCLICK: 
298      // Button 1: Select volume
299             if (parm1 == kButton1){
300             TGListTreeItem* item = fVolumesListTree->GetSelected();
301              if (item) {
302              
303              TG4GuiVolume* volume=((TG4GuiVolume*) item->GetUserData());   
304              G4LogicalVolume* lvolume = volume->GetLogicalVolume();
305
306               if  ( lvolume ) {
307                G4cout << "The selected logical volume name is   " 
308                     << lvolume->GetName() << G4endl;
309                   };
310               };
311             }; 
312               
313      // Button 3: Draw Volume
314             if (parm1 == kButton3){
315              TGListTreeItem* item = fVolumesListTree->GetSelected();
316               if (item) {
317              
318              TG4GuiVolume* volume=((TG4GuiVolume*) item->GetUserData());   
319              G4LogicalVolume* lvolume = volume->GetLogicalVolume();
320
321               if  ( lvolume ) {
322                G4cout << "The selected logical volume name is   " 
323                     << lvolume->GetName() << G4endl;
324                   };
325                };
326             }; 
327                   
328             break;
329    //-->case 2      
330         case kCT_ITEMDBLCLICK:
331             if (parm1 == kButton1) {
332                 if (fVolumesListTree->GetSelected() != 0) {
333                     gClient->NeedRedraw(fVolumesListTree);
334                 };
335             };
336             break;
337    //-->default for GET_SUBMSG      
338         default:
339             break;
340         }
341         break;
342 //---->default for GET_MSG      
343     default:
344         break;
345     }
346
347     delete lMsgBTtleBf;
348     delete lMsgBAnnBf1;
349     delete lMsgBAnnBf2; 
350    
351     return kTRUE;
352 }
353