1 | // |
---|
2 | // ******************************************************************** |
---|
3 | // * License and Disclaimer * |
---|
4 | // * * |
---|
5 | // * The Geant4 software is copyright of the Copyright Holders of * |
---|
6 | // * the Geant4 Collaboration. It is provided under the terms and * |
---|
7 | // * conditions of the Geant4 Software License, included in the file * |
---|
8 | // * LICENSE and available at http://cern.ch/geant4/license . These * |
---|
9 | // * include a list of copyright holders. * |
---|
10 | // * * |
---|
11 | // * Neither the authors of this software system, nor their employing * |
---|
12 | // * institutes,nor the agencies providing financial support for this * |
---|
13 | // * work make any representation or warranty, express or implied, * |
---|
14 | // * regarding this software system or assume any liability for its * |
---|
15 | // * use. Please see the license in the file LICENSE and URL above * |
---|
16 | // * for the full disclaimer and the limitation of liability. * |
---|
17 | // * * |
---|
18 | // * This code implementation is the result of the scientific and * |
---|
19 | // * technical work of the GEANT4 collaboration. * |
---|
20 | // * By using, copying, modifying or distributing the software (or * |
---|
21 | // * any work based on the software) you agree to acknowledge its * |
---|
22 | // * use in resulting scientific publications, and indicate your * |
---|
23 | // * acceptance of all terms of the Geant4 Software license. * |
---|
24 | // ******************************************************************** |
---|
25 | // |
---|
26 | // |
---|
27 | // $Id: G4OpenGLXmViewer.cc,v 1.29 2009/01/22 15:39:55 lgarnier Exp $ |
---|
28 | // GEANT4 tag $Name: $ |
---|
29 | // |
---|
30 | // |
---|
31 | // Andrew Walkden 10th February 1997 |
---|
32 | // G4OpenGLXmViewer : Class derived from G4OpenGLXViewer, to provide |
---|
33 | // (Motif) widget OpenGL functionality for GEANT4. |
---|
34 | |
---|
35 | #ifdef G4VIS_BUILD_OPENGLXM_DRIVER |
---|
36 | |
---|
37 | #include "globals.hh" |
---|
38 | |
---|
39 | #include "G4OpenGLXmViewer.hh" |
---|
40 | #include "G4OpenGLSceneHandler.hh" |
---|
41 | |
---|
42 | #include "G4VisExtent.hh" |
---|
43 | #include "G4LogicalVolume.hh" |
---|
44 | #include "G4VSolid.hh" |
---|
45 | #include "G4Point3D.hh" |
---|
46 | #include "G4Normal3D.hh" |
---|
47 | |
---|
48 | #include "G4OpenGLXmSliderBar.hh" |
---|
49 | |
---|
50 | #include "G4Xt.hh" |
---|
51 | #include <X11/Shell.h> |
---|
52 | |
---|
53 | #include <sstream> |
---|
54 | |
---|
55 | void G4OpenGLXmViewer::ShowView () { |
---|
56 | |
---|
57 | G4Xt::getInstance () -> SecondaryLoop (); |
---|
58 | |
---|
59 | } |
---|
60 | |
---|
61 | void G4OpenGLXmViewer::GetXmConnection () { |
---|
62 | |
---|
63 | G4Xt* interactorManager = G4Xt::getInstance (); |
---|
64 | toplevel = (Widget)interactorManager->GetMainInteractor(); |
---|
65 | app = XtWidgetToApplicationContext(toplevel); |
---|
66 | |
---|
67 | if (!toplevel) { |
---|
68 | fViewId = -1; // This flags an error. |
---|
69 | G4cerr << "G4OpenGLXmViewer::GetXmConnection unable to Initialize" |
---|
70 | " application context." << G4endl; |
---|
71 | return; |
---|
72 | } |
---|
73 | |
---|
74 | // Better to put this in an X11 resource file !!! |
---|
75 | std::ostringstream oss; |
---|
76 | oss << |
---|
77 | "*glxarea*width: " << fVP.GetWindowSizeHintX() << "\n" |
---|
78 | "*glxarea*height: " << fVP.GetWindowSizeHintY() << "\n" |
---|
79 | /* |
---|
80 | // Tried this as a replacement for the above two lines, but |
---|
81 | // sub-windows (rotation, etc.) came same size!! |
---|
82 | "*geometry: " << fVP.GetXGeometryString() << "\n" |
---|
83 | */ |
---|
84 | "*frame*x: 10\n" |
---|
85 | "*frame*y: 10\n" |
---|
86 | "*frame*topOffset: 10\n" |
---|
87 | "*frame*bottomOffset: 10\n" |
---|
88 | "*frame*rightOffset: 10\n" |
---|
89 | "*frame*leftOffset: 10\n" |
---|
90 | "*frame*shadowType: SHADOW_IN\n" |
---|
91 | "*frame*useColorObj: False\n" |
---|
92 | "*frame*primaryColorSetId: 3\n" |
---|
93 | "*frame*secondaryColorSetId: 3\n" |
---|
94 | "*menubar*useColorObj: False\n" |
---|
95 | "*menubar*primaryColorSetId: 3\n" |
---|
96 | "*menubar*secondaryColorSetId: 3\n" |
---|
97 | "*toplevel*useColorObj: False\n" |
---|
98 | "*toplevel*primaryColorSetId: 3\n" |
---|
99 | "*toplevel*secondaryColorSetId: 3\n"; |
---|
100 | interactorManager->PutStringInResourceDatabase ((char*)oss.str().c_str()); |
---|
101 | |
---|
102 | // interactorManager->AddSecondaryLoopPostAction ((G4SecondaryLoopAction)G4OpenGLXmViewerSecondaryLoopPostAction); |
---|
103 | |
---|
104 | shell = XtAppCreateShell ((String)fName.data(),(String)fName.data(),topLevelShellWidgetClass,XtDisplay(toplevel),NULL,0); |
---|
105 | interactorManager->AddShell (shell); |
---|
106 | |
---|
107 | dpy = XtDisplay (shell); |
---|
108 | |
---|
109 | if (!dpy) { |
---|
110 | fViewId = -1; // This flags an error. |
---|
111 | G4cerr << "G4OpenGLXmViewer::GetXmConnection unable to connect to display." |
---|
112 | << G4endl; |
---|
113 | return; |
---|
114 | } |
---|
115 | |
---|
116 | if (!glXQueryExtension (dpy, &errorBase, &eventBase)) { |
---|
117 | fViewId = -1; // This flags an error. |
---|
118 | G4cerr << "G4OpenGLXmViewer::GetXmConnection. X Server has no GLX extension." |
---|
119 | << G4endl;; |
---|
120 | return; |
---|
121 | } |
---|
122 | } |
---|
123 | |
---|
124 | void G4OpenGLXmViewer::CreateMainWindow () { |
---|
125 | |
---|
126 | bgnd = XWhitePixelOfScreen (XtScreen(shell)); |
---|
127 | borcol = XBlackPixelOfScreen (XtScreen(shell)); |
---|
128 | |
---|
129 | fWinSize_x = fVP.GetWindowSizeHintX(); |
---|
130 | fWinSize_y = fVP.GetWindowSizeHintY(); |
---|
131 | G4int x_origin = fVP.GetWindowAbsoluteLocationHintX(DisplayWidth(dpy, vi -> screen)); |
---|
132 | |
---|
133 | // FIXME, screen size != window size on MAC, but I don't know have to get the menuBar |
---|
134 | // size on MAC. L.Garnier 01/2009 |
---|
135 | G4int y_origin = fVP.GetWindowAbsoluteLocationHintY(DisplayHeight(dpy, vi -> screen)); |
---|
136 | |
---|
137 | if (fVP.IsWindowSizeHintX () && fVP.IsWindowLocationHintX () && fVP.IsWindowLocationHintY ()) { |
---|
138 | XtVaSetValues (shell, |
---|
139 | XtNvisual, vi -> visual, |
---|
140 | XtNdepth, vi -> depth, |
---|
141 | XtNcolormap, cmap, |
---|
142 | XtNwidth, fWinSize_x, |
---|
143 | XtNheight, fWinSize_y, |
---|
144 | XtNx, x_origin, |
---|
145 | XtNy, y_origin, |
---|
146 | XtNborderColor, &borcol, |
---|
147 | XtNbackground, &bgnd, |
---|
148 | XmNtitle, fName.data(), |
---|
149 | NULL); |
---|
150 | } else if (fVP.IsWindowSizeHintX () && !(fVP.IsWindowLocationHintX () || fVP.IsWindowLocationHintY ())) { |
---|
151 | XtVaSetValues (shell, |
---|
152 | XtNvisual, vi -> visual, |
---|
153 | XtNdepth, vi -> depth, |
---|
154 | XtNcolormap, cmap, |
---|
155 | XtNwidth, fWinSize_x, |
---|
156 | XtNheight, fWinSize_y, |
---|
157 | XtNborderColor, &borcol, |
---|
158 | XtNbackground, &bgnd, |
---|
159 | XmNtitle, fName.data(), |
---|
160 | NULL); |
---|
161 | } else if ((!fVP.IsWindowSizeHintX ()) && fVP.IsWindowLocationHintX () && fVP.IsWindowLocationHintY ()) { |
---|
162 | XtVaSetValues (shell, |
---|
163 | XtNvisual, vi -> visual, |
---|
164 | XtNdepth, vi -> depth, |
---|
165 | XtNcolormap, cmap, |
---|
166 | XtNx, x_origin, |
---|
167 | XtNy, y_origin, |
---|
168 | XtNborderColor, &borcol, |
---|
169 | XtNbackground, &bgnd, |
---|
170 | XmNtitle, fName.data(), |
---|
171 | NULL); |
---|
172 | } else { |
---|
173 | XtVaSetValues (shell, |
---|
174 | XtNvisual, vi -> visual, |
---|
175 | XtNdepth, vi -> depth, |
---|
176 | XtNcolormap, cmap, |
---|
177 | XtNborderColor, &borcol, |
---|
178 | XtNbackground, &bgnd, |
---|
179 | XmNtitle, fName.data(), |
---|
180 | NULL); |
---|
181 | } |
---|
182 | |
---|
183 | |
---|
184 | main_win = XtVaCreateManagedWidget ("main_win", |
---|
185 | xmMainWindowWidgetClass, |
---|
186 | shell, |
---|
187 | XtNvisual, vi -> visual, |
---|
188 | XtNdepth, vi -> depth, |
---|
189 | XtNcolormap, cmap, |
---|
190 | XtNborderColor, borcol, |
---|
191 | XtNbackground, bgnd, |
---|
192 | NULL); |
---|
193 | |
---|
194 | //*********Create a menu bar for the window******** |
---|
195 | style_str = XmStringCreateLocalized ((char*)"Style"); |
---|
196 | actions_str = XmStringCreateLocalized ((char*)"Actions"); |
---|
197 | misc_str = XmStringCreateLocalized ((char*)"Miscellany"); |
---|
198 | spec_str = XmStringCreateLocalized ((char*)"Special"); |
---|
199 | |
---|
200 | menubar = XmVaCreateSimpleMenuBar (main_win, |
---|
201 | (char*)"menubar", |
---|
202 | XmVaCASCADEBUTTON, style_str, 'S', |
---|
203 | XmVaCASCADEBUTTON, actions_str, 'A', |
---|
204 | XmVaCASCADEBUTTON, misc_str, 'M', |
---|
205 | XmVaCASCADEBUTTON, spec_str, 'p', |
---|
206 | XtNvisual, vi -> visual, |
---|
207 | XtNdepth, vi -> depth, |
---|
208 | XtNcolormap, cmap, |
---|
209 | XtNborderColor, borcol, |
---|
210 | XtNbackground, bgnd, |
---|
211 | NULL); |
---|
212 | |
---|
213 | XmStringFree (style_str); |
---|
214 | XmStringFree (actions_str); |
---|
215 | XmStringFree (misc_str); |
---|
216 | XmStringFree (spec_str); |
---|
217 | |
---|
218 | G4cout << "Created menubar" << G4endl; |
---|
219 | |
---|
220 | |
---|
221 | //*********Create style pulldown menu on menubar********* |
---|
222 | rep_str = XmStringCreateLocalized ((char*)"Representation"); |
---|
223 | draw_str = XmStringCreateLocalized ((char*)"Drawing"); |
---|
224 | bgnd_str = XmStringCreateLocalized ((char*)"Background color"); |
---|
225 | |
---|
226 | style_cascade = XmVaCreateSimplePulldownMenu |
---|
227 | (menubar, |
---|
228 | (char*)"style", |
---|
229 | 0, |
---|
230 | NULL, |
---|
231 | XmVaCASCADEBUTTON, rep_str, 'R', |
---|
232 | XmVaCASCADEBUTTON, draw_str, 'D', |
---|
233 | XmVaCASCADEBUTTON, bgnd_str, 'B', |
---|
234 | XtNvisual, vi -> visual, |
---|
235 | XtNdepth, vi -> depth, |
---|
236 | XtNcolormap, cmap, |
---|
237 | XtNborderColor, borcol, |
---|
238 | XtNbackground, bgnd, |
---|
239 | NULL); |
---|
240 | |
---|
241 | XmStringFree (rep_str); |
---|
242 | XmStringFree (draw_str); |
---|
243 | XmStringFree (bgnd_str); |
---|
244 | |
---|
245 | // G4cout << "Created Style pulldown menu" << G4endl; |
---|
246 | |
---|
247 | //Add Representation pullright menu to style cascade... |
---|
248 | polyhedron_str = XmStringCreateLocalized ((char*)"Polyhedron"); |
---|
249 | nurbs_str = XmStringCreateLocalized ((char*)"NURBS"); |
---|
250 | |
---|
251 | rep_style_pullright = XmVaCreateSimplePulldownMenu |
---|
252 | (style_cascade, |
---|
253 | (char*)"rep_style", |
---|
254 | 0, |
---|
255 | rep_style_callback, |
---|
256 | XmVaRADIOBUTTON, polyhedron_str, 'P', NULL, NULL, |
---|
257 | XmVaRADIOBUTTON, nurbs_str, 'N', NULL, NULL, |
---|
258 | XmNradioBehavior, True, |
---|
259 | XmNradioAlwaysOne, True, |
---|
260 | XmNuserData, this, |
---|
261 | XtNvisual, vi -> visual, |
---|
262 | XtNdepth, vi -> depth, |
---|
263 | XtNcolormap, cmap, |
---|
264 | XtNborderColor, borcol, |
---|
265 | XtNbackground, bgnd, |
---|
266 | NULL); |
---|
267 | |
---|
268 | Widget special_widget; |
---|
269 | |
---|
270 | G4ViewParameters::RepStyle style; |
---|
271 | style = fVP.GetRepStyle(); |
---|
272 | |
---|
273 | if (style == G4ViewParameters::polyhedron) { |
---|
274 | special_widget = XtNameToWidget(rep_style_pullright, "button_0"); |
---|
275 | if(special_widget) { |
---|
276 | XtVaSetValues (special_widget, XmNset, True, NULL); |
---|
277 | } |
---|
278 | } else if (style == G4ViewParameters::nurbs) { |
---|
279 | special_widget = XtNameToWidget(rep_style_pullright, "button_1"); |
---|
280 | if(special_widget) { |
---|
281 | XtVaSetValues (special_widget, XmNset, True, NULL); |
---|
282 | } |
---|
283 | } else { |
---|
284 | G4Exception("Invalid Representation style in G4OpenGLXmViewer::CreateContext"); |
---|
285 | } |
---|
286 | XmStringFree (polyhedron_str); |
---|
287 | XmStringFree (nurbs_str); |
---|
288 | |
---|
289 | // G4cout << "Created Representation pulldown menu" << G4endl; |
---|
290 | |
---|
291 | //Add Drawing pullright menu to style cascade... |
---|
292 | wireframe_str = XmStringCreateLocalized ((char*)"Wireframe"); |
---|
293 | hlr_str = XmStringCreateLocalized ((char*)"Hidden line removal"); |
---|
294 | hsr_str = XmStringCreateLocalized ((char*)"Hidden surface removal"); |
---|
295 | hlhsr_str = XmStringCreateLocalized ((char*)"Hidden line and surface removal"); |
---|
296 | |
---|
297 | drawing_style_pullright = XmVaCreateSimplePulldownMenu |
---|
298 | (style_cascade, |
---|
299 | (char*)"drawing_style", |
---|
300 | 1, |
---|
301 | drawing_style_callback, |
---|
302 | XmVaRADIOBUTTON, wireframe_str, 'W', NULL, NULL, |
---|
303 | XmVaRADIOBUTTON, hlr_str, 'L', NULL, NULL, |
---|
304 | XmVaRADIOBUTTON, hsr_str, 'S', NULL, NULL, |
---|
305 | XmVaRADIOBUTTON, hlhsr_str, 'H', NULL, NULL, |
---|
306 | XmNradioBehavior, True, |
---|
307 | XmNradioAlwaysOne, True, |
---|
308 | XmNuserData, this, |
---|
309 | XtNvisual, vi -> visual, |
---|
310 | XtNdepth, vi -> depth, |
---|
311 | XtNcolormap, cmap, |
---|
312 | XtNborderColor, borcol, |
---|
313 | XtNbackground, bgnd, |
---|
314 | NULL); |
---|
315 | |
---|
316 | G4ViewParameters::DrawingStyle d_style; |
---|
317 | d_style = fVP.GetDrawingStyle(); |
---|
318 | |
---|
319 | if (d_style == G4ViewParameters::wireframe) { |
---|
320 | special_widget = XtNameToWidget(drawing_style_pullright, "button_0"); |
---|
321 | if(special_widget) { |
---|
322 | XtVaSetValues (special_widget, XmNset, True, NULL); |
---|
323 | } |
---|
324 | } else if (d_style == G4ViewParameters::hlr) { |
---|
325 | special_widget = XtNameToWidget(drawing_style_pullright, "button_1"); |
---|
326 | if(special_widget) { |
---|
327 | XtVaSetValues (special_widget, XmNset, True, NULL); |
---|
328 | } |
---|
329 | } else if (d_style == G4ViewParameters::hsr) { |
---|
330 | special_widget = XtNameToWidget(drawing_style_pullright, "button_2"); |
---|
331 | if(special_widget) { |
---|
332 | XtVaSetValues (special_widget, XmNset, True, NULL); |
---|
333 | } |
---|
334 | } else if (d_style == G4ViewParameters::hlhsr) { |
---|
335 | special_widget = XtNameToWidget(drawing_style_pullright, "button_3"); |
---|
336 | if(special_widget) { |
---|
337 | XtVaSetValues (special_widget, XmNset, True, NULL); |
---|
338 | } |
---|
339 | } else { |
---|
340 | G4Exception("Invalid Drawing style in G4OpenGLXmViewer::CreateContext"); |
---|
341 | } |
---|
342 | |
---|
343 | XmStringFree (wireframe_str); |
---|
344 | XmStringFree (hlr_str); |
---|
345 | XmStringFree (hsr_str); |
---|
346 | XmStringFree (hlhsr_str); |
---|
347 | |
---|
348 | // G4cout << "Created Drawing pullright menu" << G4endl; |
---|
349 | |
---|
350 | //Add Drawing pullright menu to style cascade... |
---|
351 | white_str = XmStringCreateLocalized ((char*)"White"); |
---|
352 | black_str = XmStringCreateLocalized ((char*)"Black"); |
---|
353 | |
---|
354 | background_color_pullright = XmVaCreateSimplePulldownMenu |
---|
355 | (style_cascade, |
---|
356 | (char*)"background_color", |
---|
357 | 2, |
---|
358 | background_color_callback, |
---|
359 | XmVaRADIOBUTTON, white_str, 'W', NULL, NULL, |
---|
360 | XmVaRADIOBUTTON, black_str, 'B', NULL, NULL, |
---|
361 | XmNradioBehavior, True, |
---|
362 | XmNradioAlwaysOne, True, |
---|
363 | XmNuserData, this, |
---|
364 | XtNvisual, vi -> visual, |
---|
365 | XtNdepth, vi -> depth, |
---|
366 | XtNcolormap, cmap, |
---|
367 | XtNborderColor, borcol, |
---|
368 | XtNbackground, bgnd, |
---|
369 | NULL); |
---|
370 | |
---|
371 | if (background.GetRed() == 1. && |
---|
372 | background.GetGreen() == 1. && |
---|
373 | background.GetBlue() == 1.) { |
---|
374 | special_widget = XtNameToWidget(background_color_pullright, "button_0"); |
---|
375 | if(special_widget) { |
---|
376 | XtVaSetValues (special_widget, XmNset, True, NULL); |
---|
377 | } |
---|
378 | } else { |
---|
379 | special_widget = XtNameToWidget(background_color_pullright, "button_1"); |
---|
380 | if(special_widget) { |
---|
381 | XtVaSetValues (special_widget, XmNset, True, NULL); |
---|
382 | } |
---|
383 | } |
---|
384 | |
---|
385 | XmStringFree (white_str); |
---|
386 | XmStringFree (black_str); |
---|
387 | |
---|
388 | // G4cout << "Created Background color pullright menu" << G4endl; |
---|
389 | |
---|
390 | //*********Create actions pulldown menu on menubar********* |
---|
391 | rot_str = XmStringCreateLocalized ((char*)"Rotation control panel"); |
---|
392 | pan_str = XmStringCreateLocalized ((char*)"Panning control panel"); |
---|
393 | set_str = XmStringCreateLocalized ((char*)"Set control panel limits"); |
---|
394 | |
---|
395 | actions_cascade = XmVaCreateSimplePulldownMenu |
---|
396 | (menubar, |
---|
397 | (char*)"actions", |
---|
398 | 1, |
---|
399 | actions_callback, |
---|
400 | XmVaPUSHBUTTON, rot_str, 'R', NULL, NULL, |
---|
401 | XmVaPUSHBUTTON, pan_str, 'P', NULL, NULL, |
---|
402 | XmVaPUSHBUTTON, set_str, 'S', NULL, NULL, |
---|
403 | XmNuserData, this, |
---|
404 | XtNvisual, vi -> visual, |
---|
405 | XtNdepth, vi -> depth, |
---|
406 | XtNcolormap, cmap, |
---|
407 | XtNborderColor, borcol, |
---|
408 | XtNbackground, bgnd, |
---|
409 | NULL); |
---|
410 | |
---|
411 | XmStringFree (rot_str); |
---|
412 | XmStringFree (pan_str); |
---|
413 | XmStringFree (set_str); |
---|
414 | G4cout << "Created Actions pulldown menu" << G4endl; |
---|
415 | |
---|
416 | misc_str = XmStringCreateLocalized ((char*)"Miscellany control panel"); |
---|
417 | exit_str = XmStringCreateLocalized ((char*)"Exit to G4Vis>"); |
---|
418 | print_str = XmStringCreateLocalized ((char*)"Create .eps file"); |
---|
419 | |
---|
420 | //*********Create miscellany pulldown menu on menubar********* |
---|
421 | misc_cascade = XmVaCreateSimplePulldownMenu |
---|
422 | (menubar, |
---|
423 | (char*)"miscellany", |
---|
424 | 2, |
---|
425 | misc_callback, |
---|
426 | XmVaPUSHBUTTON, misc_str, 'M', NULL, NULL, |
---|
427 | XmVaPUSHBUTTON, exit_str, 'E', NULL, NULL, |
---|
428 | XmVaPUSHBUTTON, print_str, 'P', NULL, NULL, |
---|
429 | XmNuserData, this, |
---|
430 | XtNvisual, vi -> visual, |
---|
431 | XtNdepth, vi -> depth, |
---|
432 | XtNcolormap, cmap, |
---|
433 | XtNborderColor, borcol, |
---|
434 | XtNbackground, bgnd, |
---|
435 | NULL); |
---|
436 | |
---|
437 | XmStringFree (misc_str); |
---|
438 | XmStringFree (exit_str); |
---|
439 | XmStringFree (print_str); |
---|
440 | G4cout << "Created Miscellany pulldown menu" << G4endl; |
---|
441 | |
---|
442 | trans_str = XmStringCreateLocalized ((char*)"Transparency"); |
---|
443 | anti_str = XmStringCreateLocalized ((char*)"Antialiasing"); |
---|
444 | halo_str = XmStringCreateLocalized ((char*)"Haloing"); |
---|
445 | aux_edge_str = XmStringCreateLocalized ((char*)"Auxiliary edges"); |
---|
446 | |
---|
447 | //*********Create special pulldown menu on menubar********* |
---|
448 | spec_cascade = XmVaCreateSimplePulldownMenu |
---|
449 | (menubar, |
---|
450 | (char*)"special", |
---|
451 | 3, |
---|
452 | NULL, |
---|
453 | XmVaCASCADEBUTTON, trans_str, 'T', |
---|
454 | XmVaCASCADEBUTTON, anti_str, 'A', |
---|
455 | XmVaCASCADEBUTTON, halo_str, 'H', |
---|
456 | XmVaCASCADEBUTTON, aux_edge_str, 'E', |
---|
457 | XtNvisual, vi -> visual, |
---|
458 | XtNdepth, vi -> depth, |
---|
459 | XtNcolormap, cmap, |
---|
460 | XtNborderColor, borcol, |
---|
461 | XtNbackground, bgnd, |
---|
462 | NULL); |
---|
463 | |
---|
464 | XmStringFree (trans_str); |
---|
465 | XmStringFree (anti_str); |
---|
466 | XmStringFree (halo_str); |
---|
467 | XmStringFree (aux_edge_str); |
---|
468 | |
---|
469 | // G4cout << "Created Special pulldown menu" << G4endl; |
---|
470 | |
---|
471 | //Add Transparency pullright menu to special cascade... |
---|
472 | off_str = XmStringCreateLocalized ((char*)"Off"); |
---|
473 | on_str = XmStringCreateLocalized ((char*)"On"); |
---|
474 | |
---|
475 | transparency_pullright = XmVaCreateSimplePulldownMenu |
---|
476 | (spec_cascade, |
---|
477 | (char*)"transparency", |
---|
478 | 0, |
---|
479 | transparency_callback, |
---|
480 | XmVaRADIOBUTTON, off_str, 'f', NULL, NULL, |
---|
481 | XmVaRADIOBUTTON, on_str, 'n', NULL, NULL, |
---|
482 | XmNradioBehavior, True, |
---|
483 | XmNradioAlwaysOne, True, |
---|
484 | XmNuserData, this, |
---|
485 | XtNvisual, vi -> visual, |
---|
486 | XtNdepth, vi -> depth, |
---|
487 | XtNcolormap, cmap, |
---|
488 | XtNborderColor, borcol, |
---|
489 | XtNbackground, bgnd, |
---|
490 | NULL); |
---|
491 | |
---|
492 | if (transparency_enabled == false) { |
---|
493 | special_widget = XtNameToWidget(transparency_pullright, "button_0"); |
---|
494 | if(special_widget) { |
---|
495 | XtVaSetValues (special_widget, XmNset, True, NULL); |
---|
496 | } |
---|
497 | } else if (transparency_enabled == true) { |
---|
498 | special_widget = XtNameToWidget(transparency_pullright, "button_1"); |
---|
499 | if(special_widget) { |
---|
500 | XtVaSetValues (special_widget, XmNset, True, NULL); |
---|
501 | } |
---|
502 | } else { |
---|
503 | G4Exception("transparency_enabled in G4OpenGLXmViewer is neither true nor false!!"); |
---|
504 | } |
---|
505 | |
---|
506 | //Add antialias pullright menu to special cascade... |
---|
507 | antialias_pullright = XmVaCreateSimplePulldownMenu |
---|
508 | (spec_cascade, |
---|
509 | (char*)"antialias", |
---|
510 | 1, |
---|
511 | antialias_callback, |
---|
512 | XmVaRADIOBUTTON, off_str, 'f', NULL, NULL, |
---|
513 | XmVaRADIOBUTTON, on_str, 'n', NULL, NULL, |
---|
514 | XmNradioBehavior, True, |
---|
515 | XmNradioAlwaysOne, True, |
---|
516 | XmNuserData, this, |
---|
517 | XtNvisual, vi -> visual, |
---|
518 | XtNdepth, vi -> depth, |
---|
519 | XtNcolormap, cmap, |
---|
520 | XtNborderColor, borcol, |
---|
521 | XtNbackground, bgnd, |
---|
522 | NULL); |
---|
523 | |
---|
524 | if (antialiasing_enabled == false) { |
---|
525 | special_widget = XtNameToWidget(antialias_pullright, "button_0"); |
---|
526 | if(special_widget) { |
---|
527 | XtVaSetValues (special_widget, XmNset, True, NULL); |
---|
528 | } |
---|
529 | } else if (antialiasing_enabled == true) { |
---|
530 | special_widget = XtNameToWidget(antialias_pullright, "button_1"); |
---|
531 | if(special_widget) { |
---|
532 | XtVaSetValues (special_widget, XmNset, True, NULL); |
---|
533 | } |
---|
534 | } else { |
---|
535 | G4Exception("antialiasing_enabled in G4OpenGLXmViewer is neither true nor false!!"); |
---|
536 | } |
---|
537 | |
---|
538 | //Add Haloing pullright menu to special cascade... |
---|
539 | haloing_pullright = XmVaCreateSimplePulldownMenu |
---|
540 | (spec_cascade, |
---|
541 | (char*)"haloing", |
---|
542 | 2, |
---|
543 | haloing_callback, |
---|
544 | XmVaRADIOBUTTON, off_str, 'f', NULL, NULL, |
---|
545 | XmVaRADIOBUTTON, on_str, 'n', NULL, NULL, |
---|
546 | XmNradioBehavior, True, |
---|
547 | XmNradioAlwaysOne, True, |
---|
548 | XmNuserData, this, |
---|
549 | XtNvisual, vi -> visual, |
---|
550 | XtNdepth, vi -> depth, |
---|
551 | XtNcolormap, cmap, |
---|
552 | XtNborderColor, borcol, |
---|
553 | XtNbackground, bgnd, |
---|
554 | NULL); |
---|
555 | |
---|
556 | if (haloing_enabled == false) { |
---|
557 | special_widget = XtNameToWidget(haloing_pullright, "button_0"); |
---|
558 | if(special_widget) { |
---|
559 | XtVaSetValues (special_widget, XmNset, True, NULL); |
---|
560 | } |
---|
561 | } else if (haloing_enabled == true) { |
---|
562 | special_widget = XtNameToWidget(haloing_pullright, "button_1"); |
---|
563 | if(special_widget) { |
---|
564 | XtVaSetValues (special_widget, XmNset, True, NULL); |
---|
565 | } |
---|
566 | } else { |
---|
567 | G4Exception("haloing_enabled in G4OpenGLXmViewer is neither true nor false!!"); |
---|
568 | } |
---|
569 | |
---|
570 | //Add Aux_Edge pullright menu to special cascade... |
---|
571 | aux_edge_pullright = XmVaCreateSimplePulldownMenu |
---|
572 | (spec_cascade, |
---|
573 | (char*)"aux_edge", |
---|
574 | 3, |
---|
575 | aux_edge_callback, |
---|
576 | XmVaRADIOBUTTON, off_str, 'f', NULL, NULL, |
---|
577 | XmVaRADIOBUTTON, on_str, 'n', NULL, NULL, |
---|
578 | XmNradioBehavior, True, |
---|
579 | XmNradioAlwaysOne, True, |
---|
580 | XmNuserData, this, |
---|
581 | XtNvisual, vi -> visual, |
---|
582 | XtNdepth, vi -> depth, |
---|
583 | XtNcolormap, cmap, |
---|
584 | XtNborderColor, borcol, |
---|
585 | XtNbackground, bgnd, |
---|
586 | NULL); |
---|
587 | |
---|
588 | if (!fVP.IsAuxEdgeVisible()) { |
---|
589 | special_widget = XtNameToWidget(aux_edge_pullright, "button_0"); |
---|
590 | if(special_widget) { |
---|
591 | XtVaSetValues (special_widget, XmNset, True, NULL); |
---|
592 | } |
---|
593 | } else { |
---|
594 | special_widget = XtNameToWidget(aux_edge_pullright, "button_1"); |
---|
595 | if(special_widget) { |
---|
596 | XtVaSetValues (special_widget, XmNset, True, NULL); |
---|
597 | } |
---|
598 | } |
---|
599 | |
---|
600 | XtManageChild (menubar); |
---|
601 | frame = XtVaCreateManagedWidget ((char*)"frame", |
---|
602 | xmFrameWidgetClass, main_win, |
---|
603 | XtNvisual, vi -> visual, |
---|
604 | XtNdepth, vi -> depth, |
---|
605 | XtNcolormap, cmap, |
---|
606 | XtNborderColor, borcol, |
---|
607 | XtNbackground, bgnd, |
---|
608 | NULL); |
---|
609 | |
---|
610 | glxarea = XtVaCreateManagedWidget ((char*)"glxarea", |
---|
611 | xmDrawingAreaWidgetClass, |
---|
612 | frame, |
---|
613 | XtNvisual, vi -> visual, |
---|
614 | XtNdepth, vi -> depth, |
---|
615 | XtNcolormap, cmap, |
---|
616 | XtNborderColor, borcol, |
---|
617 | XtNbackground, bgnd, |
---|
618 | NULL); |
---|
619 | |
---|
620 | |
---|
621 | XmMainWindowSetAreas (main_win, // main widget, children are specified |
---|
622 | menubar, // widget to use as menu bar |
---|
623 | NULL, // widget to use as command window |
---|
624 | NULL, // widget for horizontal scroll bar |
---|
625 | NULL, // widget for vertical scroll bar |
---|
626 | frame // widget to be used for work window |
---|
627 | ); |
---|
628 | |
---|
629 | XtRealizeWidget(shell); |
---|
630 | |
---|
631 | // Once widget is realized (ie, associated with a created X window), we |
---|
632 | // can bind the OpenGL rendering context to the window. |
---|
633 | |
---|
634 | win = XtWindow (glxarea); |
---|
635 | |
---|
636 | glXMakeCurrent (dpy, win, cx); |
---|
637 | |
---|
638 | // This should be add AFTER glXMakeCurrent done because it will fire a resizeCallback |
---|
639 | XtAddCallback (glxarea, |
---|
640 | XmNresizeCallback, |
---|
641 | resize_callback, |
---|
642 | this); |
---|
643 | |
---|
644 | XtAddCallback (glxarea, |
---|
645 | XmNexposeCallback, |
---|
646 | expose_callback, |
---|
647 | this); |
---|
648 | |
---|
649 | } |
---|
650 | |
---|
651 | G4OpenGLXmViewer::G4OpenGLXmViewer (G4OpenGLSceneHandler& scene): |
---|
652 | G4VViewer (scene, -1), |
---|
653 | G4OpenGLViewer (scene), |
---|
654 | G4OpenGLXViewer (scene), |
---|
655 | zoom_high (fVP.GetZoomFactor() * 10.0), |
---|
656 | zoom_low (fVP.GetZoomFactor() / 10.0), |
---|
657 | dolly_low (fVP.GetDolly() - 1000.0), |
---|
658 | dolly_high (fVP.GetDolly() + 1000.0), |
---|
659 | fov (0.0), |
---|
660 | rot_sens_limit (90.), |
---|
661 | pan_sens_limit (100.), |
---|
662 | rot_sens (1.), |
---|
663 | wob_sens (20.), |
---|
664 | original_vp(fVP.GetViewpointDirection()), |
---|
665 | frameNo (0), |
---|
666 | fprotation_top (0), |
---|
667 | fprotation_slider (0), |
---|
668 | fppanning_top (0), |
---|
669 | fppanning_slider (0), |
---|
670 | fpzoom_slider (0), |
---|
671 | fpdolly_slider (0), |
---|
672 | fpsetting_top (0), |
---|
673 | fpmiscellany_top (0), |
---|
674 | fpprint_top (0) |
---|
675 | { |
---|
676 | GetXmConnection (); |
---|
677 | if (fViewId < 0) return; |
---|
678 | } |
---|
679 | |
---|
680 | G4OpenGLXmViewer::~G4OpenGLXmViewer () |
---|
681 | { |
---|
682 | XtDestroyWidget (shell); |
---|
683 | win = 0; // ...to avoid XDestroyWindow in G4OpenGLXViewer base class |
---|
684 | // because XtDestroyWidget has already destroyed it. |
---|
685 | G4Xt::getInstance () ->RemoveShell (shell); |
---|
686 | |
---|
687 | /****************************** |
---|
688 | if (fprotation_top) { |
---|
689 | delete fprotation_top; |
---|
690 | } |
---|
691 | |
---|
692 | if (fppanning_top) { |
---|
693 | delete fppanning_top; |
---|
694 | } |
---|
695 | |
---|
696 | if (fpsetting_top) { |
---|
697 | delete fpsetting_top; |
---|
698 | } |
---|
699 | |
---|
700 | if (fpmiscellany_top) { |
---|
701 | delete fpmiscellany_top; |
---|
702 | } |
---|
703 | ******************************/ |
---|
704 | |
---|
705 | } |
---|
706 | |
---|
707 | #endif |
---|