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