34#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
56#include <Xm/DrawingA.h>
60void G4OpenGLXmViewer::ShowView () {
62 G4Xt::getInstance () -> SecondaryLoop ();
66void G4OpenGLXmViewer::ResetView () {
68 G4OpenGLViewer::ResetView();
71 zoom_high = fVP.GetZoomFactor() * 10.0;
72 zoom_low = fVP.GetZoomFactor() / 10.0;
78 bool firstInit =
true;
79 if (GetSceneHandler() != NULL) {
80 if (GetSceneHandler()->GetScene() != NULL) {
85 pan_sens_limit = 100.;
86 fPan_sens = pan_sens_limit / 10.0;
87 dolly_low = fVP.GetDolly() - 1000.0;
88 dolly_high = fVP.GetDolly() + 1000.0;
90 fPan_sens = GetSceneHandler()->GetScene()->GetExtent().GetExtentRadius() / 10.0;
91 pan_sens_limit = GetSceneHandler()->GetScene()->GetExtent().GetExtentRadius();
93 dolly_high = GetSceneHandler()->GetScene()->GetExtent().GetExtentRadius();
94 dolly_low = -(GetSceneHandler()->GetScene()->GetExtent().GetExtentRadius());
97 UpdateControlPanel ();
106void G4OpenGLXmViewer::GetXmConnection () {
108 G4Xt* interactorManager = G4Xt::getInstance ();
109 toplevel = (Widget)interactorManager->GetMainInteractor();
110 app = XtWidgetToApplicationContext(toplevel);
114 G4cerr <<
"G4OpenGLXmViewer::GetXmConnection unable to Initialize"
115 " application context." <<
G4endl;
120 std::ostringstream oss;
122 "*glxarea*width: " << fVP.GetWindowSizeHintX() <<
"\n"
123 "*glxarea*height: " << fVP.GetWindowSizeHintY() <<
"\n"
131 "*frame*topOffset: 10\n"
132 "*frame*bottomOffset: 10\n"
133 "*frame*rightOffset: 10\n"
134 "*frame*leftOffset: 10\n"
135 "*frame*shadowType: SHADOW_IN\n"
136 "*frame*useColorObj: False\n"
137 "*frame*primaryColorSetId: 3\n"
138 "*frame*secondaryColorSetId: 3\n"
139 "*menubar*useColorObj: False\n"
140 "*menubar*primaryColorSetId: 3\n"
141 "*menubar*secondaryColorSetId: 3\n"
142 "*toplevel*useColorObj: False\n"
143 "*toplevel*primaryColorSetId: 3\n"
144 "*toplevel*secondaryColorSetId: 3\n";
145 interactorManager->PutStringInResourceDatabase ((
char*)oss.str().c_str());
149 shell = XtAppCreateShell ((String)fName.
data(),(String)fName.
data(),topLevelShellWidgetClass,XtDisplay(toplevel),NULL,0);
150 interactorManager->AddShell (shell);
152 dpy = XtDisplay (shell);
156 G4cerr <<
"G4OpenGLXmViewer::GetXmConnection unable to connect to display."
161 if (!glXQueryExtension (dpy, &errorBase, &eventBase)) {
163 G4cerr <<
"G4OpenGLXmViewer::GetXmConnection. X Server has no GLX extension."
169void G4OpenGLXmViewer::CreateMainWindow () {
171 bgnd = XWhitePixelOfScreen (XtScreen(shell));
172 borcol = XBlackPixelOfScreen (XtScreen(shell));
174 ResizeWindow(fVP.GetWindowSizeHintX(),fVP.GetWindowSizeHintY());
176 G4int x_origin = fVP.GetWindowAbsoluteLocationHintX(DisplayWidth(dpy, vi -> screen));
180 G4int y_origin = fVP.GetWindowAbsoluteLocationHintY(DisplayHeight(dpy, vi -> screen));
182 if (fVP.IsWindowSizeHintX () && fVP.IsWindowLocationHintX () && fVP.IsWindowLocationHintY ()) {
183 XtVaSetValues (shell,
184 XtNvisual, vi -> visual,
185 XtNdepth, vi -> depth,
187 XtNwidth, getWinWidth(),
188 XtNheight, getWinHeight(),
191 XtNborderColor, &borcol,
192 XtNbackground, &bgnd,
193 XmNtitle, fName.
data(),
195 }
else if (fVP.IsWindowSizeHintX () && !(fVP.IsWindowLocationHintX () || fVP.IsWindowLocationHintY ())) {
196 XtVaSetValues (shell,
197 XtNvisual, vi -> visual,
198 XtNdepth, vi -> depth,
200 XtNwidth, getWinWidth(),
201 XtNheight, getWinHeight(),
202 XtNborderColor, &borcol,
203 XtNbackground, &bgnd,
204 XmNtitle, fName.
data(),
206 }
else if ((!fVP.IsWindowSizeHintX ()) && fVP.IsWindowLocationHintX () && fVP.IsWindowLocationHintY ()) {
207 XtVaSetValues (shell,
208 XtNvisual, vi -> visual,
209 XtNdepth, vi -> depth,
213 XtNborderColor, &borcol,
214 XtNbackground, &bgnd,
215 XmNtitle, fName.
data(),
218 XtVaSetValues (shell,
219 XtNvisual, vi -> visual,
220 XtNdepth, vi -> depth,
222 XtNborderColor, &borcol,
223 XtNbackground, &bgnd,
224 XmNtitle, fName.
data(),
229 main_win = XtVaCreateManagedWidget (
"main_win",
230 xmMainWindowWidgetClass,
232 XtNvisual, vi -> visual,
233 XtNdepth, vi -> depth,
235 XtNborderColor, borcol,
240 style_str = XmStringCreateLocalized ((
char*)
"Style");
241 actions_str = XmStringCreateLocalized ((
char*)
"Actions");
242 misc_str = XmStringCreateLocalized ((
char*)
"Miscellany");
243 spec_str = XmStringCreateLocalized ((
char*)
"Special");
245 menubar = XmVaCreateSimpleMenuBar (main_win,
247 XmVaCASCADEBUTTON, style_str,
'S',
248 XmVaCASCADEBUTTON, actions_str,
'A',
249 XmVaCASCADEBUTTON, misc_str,
'M',
250 XmVaCASCADEBUTTON, spec_str,
'p',
251 XtNvisual, vi -> visual,
252 XtNdepth, vi -> depth,
254 XtNborderColor, borcol,
258 XmStringFree (style_str);
259 XmStringFree (actions_str);
260 XmStringFree (misc_str);
261 XmStringFree (spec_str);
267 rep_str = XmStringCreateLocalized ((
char*)
"Representation");
268 draw_str = XmStringCreateLocalized ((
char*)
"Drawing");
269 bgnd_str = XmStringCreateLocalized ((
char*)
"Background color");
271 style_cascade = XmVaCreateSimplePulldownMenu
276 XmVaCASCADEBUTTON, rep_str,
'R',
277 XmVaCASCADEBUTTON, draw_str,
'D',
278 XmVaCASCADEBUTTON, bgnd_str,
'B',
279 XtNvisual, vi -> visual,
280 XtNdepth, vi -> depth,
282 XtNborderColor, borcol,
286 XmStringFree (rep_str);
287 XmStringFree (draw_str);
288 XmStringFree (bgnd_str);
293 polyhedron_str = XmStringCreateLocalized ((
char*)
"Polyhedron");
294 nurbs_str = XmStringCreateLocalized ((
char*)
"NURBS");
296 rep_style_pullright = XmVaCreateSimplePulldownMenu
301 XmVaRADIOBUTTON, polyhedron_str,
'P', NULL, NULL,
302 XmVaRADIOBUTTON, nurbs_str,
'N', NULL, NULL,
303 XmNradioBehavior, True,
304 XmNradioAlwaysOne, True,
306 XtNvisual, vi -> visual,
307 XtNdepth, vi -> depth,
309 XtNborderColor, borcol,
313 Widget special_widget;
316 style = fVP.GetRepStyle();
319 special_widget = XtNameToWidget(rep_style_pullright,
"button_0");
321 XtVaSetValues (special_widget, XmNset, True, NULL);
324 special_widget = XtNameToWidget(rep_style_pullright,
"button_1");
326 XtVaSetValues (special_widget, XmNset, True, NULL);
330 (
"G4OpenGLXmViewer::CreateMainWindow",
332 "Invalid Representation style");
334 XmStringFree (polyhedron_str);
335 XmStringFree (nurbs_str);
340 wireframe_str = XmStringCreateLocalized ((
char*)
"Wireframe");
341 hlr_str = XmStringCreateLocalized ((
char*)
"Hidden line removal");
342 hsr_str = XmStringCreateLocalized ((
char*)
"Hidden surface removal");
343 hlhsr_str = XmStringCreateLocalized ((
char*)
"Hidden line and surface removal");
345 drawing_style_pullright = XmVaCreateSimplePulldownMenu
347 (
char*)
"drawing_style",
349 drawing_style_callback,
350 XmVaRADIOBUTTON, wireframe_str,
'W', NULL, NULL,
351 XmVaRADIOBUTTON, hlr_str,
'L', NULL, NULL,
352 XmVaRADIOBUTTON, hsr_str,
'S', NULL, NULL,
353 XmVaRADIOBUTTON, hlhsr_str,
'H', NULL, NULL,
354 XmNradioBehavior, True,
355 XmNradioAlwaysOne, True,
357 XtNvisual, vi -> visual,
358 XtNdepth, vi -> depth,
360 XtNborderColor, borcol,
365 d_style = fVP.GetDrawingStyle();
368 special_widget = XtNameToWidget(drawing_style_pullright,
"button_0");
370 XtVaSetValues (special_widget, XmNset, True, NULL);
373 special_widget = XtNameToWidget(drawing_style_pullright,
"button_1");
375 XtVaSetValues (special_widget, XmNset, True, NULL);
378 special_widget = XtNameToWidget(drawing_style_pullright,
"button_2");
380 XtVaSetValues (special_widget, XmNset, True, NULL);
383 special_widget = XtNameToWidget(drawing_style_pullright,
"button_3");
385 XtVaSetValues (special_widget, XmNset, True, NULL);
389 (
"G4OpenGLXmViewer::CreateMainWindow",
391 "Invalid Drawing style in G4OpenGLXmViewer::CreateContext");
394 XmStringFree (wireframe_str);
395 XmStringFree (hlr_str);
396 XmStringFree (hsr_str);
397 XmStringFree (hlhsr_str);
402 white_str = XmStringCreateLocalized ((
char*)
"White");
403 black_str = XmStringCreateLocalized ((
char*)
"Black");
405 background_color_pullright = XmVaCreateSimplePulldownMenu
407 (
char*)
"background_color",
409 background_color_callback,
410 XmVaRADIOBUTTON, white_str,
'W', NULL, NULL,
411 XmVaRADIOBUTTON, black_str,
'B', NULL, NULL,
412 XmNradioBehavior, True,
413 XmNradioAlwaysOne, True,
415 XtNvisual, vi -> visual,
416 XtNdepth, vi -> depth,
418 XtNborderColor, borcol,
422 if (background.GetRed() == 1. &&
423 background.GetGreen() == 1. &&
424 background.GetBlue() == 1.) {
425 special_widget = XtNameToWidget(background_color_pullright,
"button_0");
427 XtVaSetValues (special_widget, XmNset, True, NULL);
430 special_widget = XtNameToWidget(background_color_pullright,
"button_1");
432 XtVaSetValues (special_widget, XmNset, True, NULL);
436 XmStringFree (white_str);
437 XmStringFree (black_str);
442 rot_str = XmStringCreateLocalized ((
char*)
"Rotation control panel");
443 pan_str = XmStringCreateLocalized ((
char*)
"Panning control panel");
444 set_str = XmStringCreateLocalized ((
char*)
"Set control panel limits");
446 actions_cascade = XmVaCreateSimplePulldownMenu
451 XmVaPUSHBUTTON, rot_str,
'R', NULL, NULL,
452 XmVaPUSHBUTTON, pan_str,
'P', NULL, NULL,
453 XmVaPUSHBUTTON, set_str,
'S', NULL, NULL,
455 XtNvisual, vi -> visual,
456 XtNdepth, vi -> depth,
458 XtNborderColor, borcol,
462 XmStringFree (rot_str);
463 XmStringFree (pan_str);
464 XmStringFree (set_str);
467 misc_str = XmStringCreateLocalized ((
char*)
"Miscellany control panel");
468 exit_str = XmStringCreateLocalized ((
char*)
"Exit to G4Vis>");
469 print_str = XmStringCreateLocalized ((
char*)
"Create .eps file");
472 misc_cascade = XmVaCreateSimplePulldownMenu
477 XmVaPUSHBUTTON, misc_str,
'M', NULL, NULL,
478 XmVaPUSHBUTTON, exit_str,
'E', NULL, NULL,
479 XmVaPUSHBUTTON, print_str,
'P', NULL, NULL,
481 XtNvisual, vi -> visual,
482 XtNdepth, vi -> depth,
484 XtNborderColor, borcol,
488 XmStringFree (misc_str);
489 XmStringFree (exit_str);
490 XmStringFree (print_str);
493 trans_str = XmStringCreateLocalized ((
char*)
"Transparency");
494 anti_str = XmStringCreateLocalized ((
char*)
"Antialiasing");
495 halo_str = XmStringCreateLocalized ((
char*)
"Haloing");
496 aux_edge_str = XmStringCreateLocalized ((
char*)
"Auxiliary edges");
499 spec_cascade = XmVaCreateSimplePulldownMenu
504 XmVaCASCADEBUTTON, trans_str,
'T',
505 XmVaCASCADEBUTTON, anti_str,
'A',
506 XmVaCASCADEBUTTON, halo_str,
'H',
507 XmVaCASCADEBUTTON, aux_edge_str,
'E',
508 XtNvisual, vi -> visual,
509 XtNdepth, vi -> depth,
511 XtNborderColor, borcol,
515 XmStringFree (trans_str);
516 XmStringFree (anti_str);
517 XmStringFree (halo_str);
518 XmStringFree (aux_edge_str);
523 off_str = XmStringCreateLocalized ((
char*)
"Off");
524 on_str = XmStringCreateLocalized ((
char*)
"On");
526 transparency_pullright = XmVaCreateSimplePulldownMenu
528 (
char*)
"transparency",
530 transparency_callback,
531 XmVaRADIOBUTTON, off_str,
'f', NULL, NULL,
532 XmVaRADIOBUTTON, on_str,
'n', NULL, NULL,
533 XmNradioBehavior, True,
534 XmNradioAlwaysOne, True,
536 XtNvisual, vi -> visual,
537 XtNdepth, vi -> depth,
539 XtNborderColor, borcol,
543 if (transparency_enabled ==
false) {
544 special_widget = XtNameToWidget(transparency_pullright,
"button_0");
546 XtVaSetValues (special_widget, XmNset, True, NULL);
548 }
else if (transparency_enabled ==
true) {
549 special_widget = XtNameToWidget(transparency_pullright,
"button_1");
551 XtVaSetValues (special_widget, XmNset, True, NULL);
555 (
"G4OpenGLXmViewer::CreateMainWindow",
557 "transparency_enabled in G4OpenGLXmViewer is neither true nor false!!");
561 antialias_pullright = XmVaCreateSimplePulldownMenu
566 XmVaRADIOBUTTON, off_str,
'f', NULL, NULL,
567 XmVaRADIOBUTTON, on_str,
'n', NULL, NULL,
568 XmNradioBehavior, True,
569 XmNradioAlwaysOne, True,
571 XtNvisual, vi -> visual,
572 XtNdepth, vi -> depth,
574 XtNborderColor, borcol,
578 if (antialiasing_enabled ==
false) {
579 special_widget = XtNameToWidget(antialias_pullright,
"button_0");
581 XtVaSetValues (special_widget, XmNset, True, NULL);
583 }
else if (antialiasing_enabled ==
true) {
584 special_widget = XtNameToWidget(antialias_pullright,
"button_1");
586 XtVaSetValues (special_widget, XmNset, True, NULL);
590 (
"G4OpenGLXmViewer::CreateMainWindow",
592 "antialiasing_enabled in G4OpenGLXmViewer is neither true nor false!!");
596 haloing_pullright = XmVaCreateSimplePulldownMenu
601 XmVaRADIOBUTTON, off_str,
'f', NULL, NULL,
602 XmVaRADIOBUTTON, on_str,
'n', NULL, NULL,
603 XmNradioBehavior, True,
604 XmNradioAlwaysOne, True,
606 XtNvisual, vi -> visual,
607 XtNdepth, vi -> depth,
609 XtNborderColor, borcol,
613 if (haloing_enabled ==
false) {
614 special_widget = XtNameToWidget(haloing_pullright,
"button_0");
616 XtVaSetValues (special_widget, XmNset, True, NULL);
618 }
else if (haloing_enabled ==
true) {
619 special_widget = XtNameToWidget(haloing_pullright,
"button_1");
621 XtVaSetValues (special_widget, XmNset, True, NULL);
625 (
"G4OpenGLXmViewer::CreateMainWindow",
627 "haloing_enabled in G4OpenGLXmViewer is neither true nor false!!");
631 aux_edge_pullright = XmVaCreateSimplePulldownMenu
636 XmVaRADIOBUTTON, off_str,
'f', NULL, NULL,
637 XmVaRADIOBUTTON, on_str,
'n', NULL, NULL,
638 XmNradioBehavior, True,
639 XmNradioAlwaysOne, True,
641 XtNvisual, vi -> visual,
642 XtNdepth, vi -> depth,
644 XtNborderColor, borcol,
648 if (!fVP.IsAuxEdgeVisible()) {
649 special_widget = XtNameToWidget(aux_edge_pullright,
"button_0");
651 XtVaSetValues (special_widget, XmNset, True, NULL);
654 special_widget = XtNameToWidget(aux_edge_pullright,
"button_1");
656 XtVaSetValues (special_widget, XmNset, True, NULL);
660 XtManageChild (menubar);
661 frame = XtVaCreateManagedWidget ((
char*)
"frame",
662 xmFrameWidgetClass, main_win,
663 XtNvisual, vi -> visual,
664 XtNdepth, vi -> depth,
666 XtNborderColor, borcol,
670 glxarea = XtVaCreateManagedWidget ((
char*)
"glxarea",
671 xmDrawingAreaWidgetClass,
673 XtNvisual, vi -> visual,
674 XtNdepth, vi -> depth,
676 XtNborderColor, borcol,
681 XmMainWindowSetAreas (main_win,
689 XtRealizeWidget(shell);
694 win = XtWindow (glxarea);
696 glXMakeCurrent (dpy, win, cx);
699 XtAddCallback (glxarea,
704 XtAddCallback (glxarea,
711G4OpenGLXmViewer::G4OpenGLXmViewer (G4OpenGLSceneHandler& scene):
713G4OpenGLViewer (scene),
714G4OpenGLXViewer (scene),
716original_vp(fVP.GetViewpointDirection()),
719fprotation_slider (0),
737 if (fViewId < 0)
return;
741void G4OpenGLXmViewer::UpdateControlPanel () {
745 if (fprotation_slider) {
746 fprotation_slider->SetInitialValue(fRot_sens);
747 fprotation_slider->SetMaxValue(rot_sens_limit);
748 fprotation_slider->SetMinValue(0);
750 if (fppanning_slider) {
751 fppanning_slider->SetInitialValue(fPan_sens);
752 fppanning_slider->SetMaxValue(pan_sens_limit);
753 fppanning_slider->SetMinValue(0);
756 fpzoom_slider->SetInitialValue(fVP.GetZoomFactor());
757 fpzoom_slider->SetMinValue(zoom_low);
758 fpzoom_slider->SetMaxValue(zoom_high);
760 if (fpdolly_slider) {
761 fpdolly_slider->SetInitialValue(fVP.GetDolly());
762 fpdolly_slider->SetMinValue(dolly_low);
763 fpdolly_slider->SetMaxValue(dolly_high);
766 if (fpwobble_slider) {
767 fpwobble_slider->SetInitialValue(fVP.GetDolly());
771 fppan_set->SetValue(pan_sens_limit);
775 fprot_set->SetValue(rot_sens_limit);
779 fpzoom_upper->SetValue(zoom_high);
783 fpzoom_lower->SetValue(zoom_low);
786 fpdolly_upper->SetValue(dolly_high);
790 fpdolly_lower->SetValue(dolly_low);
797G4OpenGLXmViewer::~G4OpenGLXmViewer ()
799 XtDestroyWidget (shell);
802 G4Xt::getInstance () ->RemoveShell (shell);
G4DLLIMPORT std::ostream G4cerr
G4DLLIMPORT std::ostream G4cout
const char * data() const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)