2 // Category: interfaces
6 //========================================================
8 //------------TG4MainFrame.cxx--------------------------------//
9 //---------Main Window for the AG4 Geometry Browser---//
11 //=========================================================
13 #include "TG4MainFrame.h"
14 #include "TG4Editor.h"
15 #include "TG4VolumesFrames.h"
16 #include "TG4MaterialsFrames.h"
17 #include "TG4GuiVolume.h"
18 #include "TG4Globals.h"
20 #include <TGListTree.h>
24 #include <TApplication.h>
26 #include <TGTextBuffer.h>
28 #include <G4LogicalVolume.hh>
31 ClassImp(TG4MainFrame)
33 TG4MainFrame::TG4MainFrame(const TGWindow* p, UInt_t w, UInt_t h)
34 : TGMainFrame(p, w, h)
36 //---> Creates the main frame
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);
42 fPopupMenu= new TGPopupMenu(gClient->GetRoot());
43 fPopupMenu->AddEntry("&Close Window", 1);
44 fPopupMenu->AddEntry("&Exit Root", 2);
46 fPopupMenuTest = new TGPopupMenu(this);
47 fPopupMenuTest->AddEntry("&Message", 3);
49 fPopupMenuHelp = new TGPopupMenu(gClient->GetRoot());
50 fPopupMenuHelp->AddEntry("&About", 4);
52 fPopupMenu->Associate(this);
53 fPopupMenuTest->Associate(this);
54 fPopupMenuHelp->Associate(this);
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);
61 AddFrame(fMenuBar, fMenuBarLayout);
65 fTab = new TGTab(this, 400, 400);
66 TGCompositeFrame* tf = fTab->AddTab("Volumes");
68 TGLayoutHints* lTabLayout = new TGLayoutHints(kLHintsBottom | kLHintsExpandX |
69 kLHintsExpandY, 2, 2, 5, 1);
70 AddFrame(fTab, lTabLayout);
72 //------>TGCanvas and a canvas container
73 fCanvasWindow = new TGCanvas(tf, 400, 240);
75 //----->List fVolumesListTree
76 fVolumesListTree= new TGListTree(fCanvasWindow->GetViewPort(), 10, 10, kHorizontalFrame,
78 fVolumesListTree->Associate(this);
79 fCanvasWindow->SetContainer(fVolumesListTree);
82 TGLayoutHints *lCanvasLayout = new TGLayoutHints(kLHintsExpandX | kLHintsExpandY);
83 tf->AddFrame(fCanvasWindow, lCanvasLayout);
85 //-----------------------------------------------------------------------------
87 //----->Volumes Properties
88 tf = fTab->AddTab("Volumes Properties");
89 fvolumesFrames = new TG4VolumesFrames( tf, this);
92 //----->Materials Properties
93 tf = fTab->AddTab("Materials Properties");
94 fmaterialsFrames = new TG4MaterialsFrames( tf, this);
96 //----->Window name and final mapping
97 SetWindowName("ALICE Geant4 Browser");
99 Resize(GetDefaultSize());
105 TG4MainFrame::TG4MainFrame(const TG4MainFrame& mf)
106 : TGMainFrame( (const TGMainFrame&) mf)
108 // Dummy copy constructor
109 TG4Globals::Exception(
110 "Attempt to use TG4MainFrame copy constructor.");
113 TG4MainFrame& TG4MainFrame::operator=(const TG4MainFrame& mf)
115 // check assignement to self
116 if (this == &mf) return *this;
118 TG4Globals::Exception(
119 "Attempt to assign TG4MainFrame singleton.");
124 TG4MainFrame::~TG4MainFrame()
126 //----> Delete created widgets.
127 G4cout << "\n Now in the TG4MainFrame destructor\n" << G4endl;
128 delete fMenuBarLayout;
129 delete fMenuBarItemLayout;
130 delete fMenuBarHelpLayout;
133 delete fPopupMenuTest;
134 delete fPopupMenuHelp;
139 delete fCanvasWindow;
140 delete fVolumesListTree;
141 delete fvolumesFrames;
142 delete fmaterialsFrames;
145 TG4VolumesFrames* TG4MainFrame::GetVolumesFrames() const
147 //---> For use in TG4GeometryGUI
148 return fvolumesFrames;
151 TG4MaterialsFrames* TG4MainFrame::GetMaterialsFrames() const
153 //---> For use in TG4GeometryGUI
154 return fmaterialsFrames;
157 TGListTreeItem* TG4MainFrame::
158 AddItem(TObject* obj, TGListTreeItem* parent, const char* name,
159 const TGPicture* open, const TGPicture* closed)
161 //----->Add item to the list tree
162 return fVolumesListTree->AddItem(parent, name, obj, open, closed);
165 void TG4MainFrame::CloseWindow()
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.
172 TGMainFrame::CloseWindow();
173 gApplication->Terminate(0);
176 Bool_t TG4MainFrame::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
178 //---> Processes events generated by the widgets in the frame
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!");
190 //=================================================================
194 EMsgBoxIcon icontype = kMBIconExclamation;
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" ;
203 //=================================================================
204 //----->Process messages to widgets
205 switch (GET_MSG(msg)) {
208 switch (GET_SUBMSG(msg)) {
209 case kTE_TEXTCHANGED:
212 G4cout <<" Acting in TextEntry !!! " << G4endl;
225 //---->case Handle Popup menus
227 switch (GET_SUBMSG(msg)) {
234 // for (Int_t i=1; i<3; 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();
246 G4cout << "\n\n!!!!EXITING. BYE!!!\n\n" << G4endl;
247 CloseWindow(); //-->and exit root
252 buttons = kMBDismiss;
253 new TGMsgBox(fClient->GetRoot(), this,
254 lMsgBTtleBf->GetString(), lMsgBAnnBf1->GetString(),
255 icontype, buttons, &retval);
261 TG4Editor* ed = new TG4Editor(this, 400, 150);
262 ed->LoadBuffer(editortxt);
275 fvolumesFrames->DisplayVolumeCharacteristics();
279 fmaterialsFrames->DisplayMaterialCharacteristics();
291 //----->case Handle volumes ListTree
293 switch (GET_SUBMSG(msg)) {
295 //----->Cases to Handle mouse click
298 // Button 1: Select volume
299 if (parm1 == kButton1){
300 TGListTreeItem* item = fVolumesListTree->GetSelected();
303 TG4GuiVolume* volume=((TG4GuiVolume*) item->GetUserData());
304 G4LogicalVolume* lvolume = volume->GetLogicalVolume();
307 G4cout << "The selected logical volume name is "
308 << lvolume->GetName() << G4endl;
313 // Button 3: Draw Volume
314 if (parm1 == kButton3){
315 TGListTreeItem* item = fVolumesListTree->GetSelected();
318 TG4GuiVolume* volume=((TG4GuiVolume*) item->GetUserData());
319 G4LogicalVolume* lvolume = volume->GetLogicalVolume();
322 G4cout << "The selected logical volume name is "
323 << lvolume->GetName() << G4endl;
330 case kCT_ITEMDBLCLICK:
331 if (parm1 == kButton1) {
332 if (fVolumesListTree->GetSelected() != 0) {
333 gClient->NeedRedraw(fVolumesListTree);
337 //-->default for GET_SUBMSG
342 //---->default for GET_MSG