33 #ifdef G4VIS_BUILD_OPENGLXM_DRIVER
52 #include <X11/Shell.h>
55 #include <Xm/DrawingA.h>
59 void G4OpenGLXmViewer::ShowView () {
65 G4Xt::getInstance () -> SecondaryLoop ();
69 void G4OpenGLXmViewer::ResetView () {
71 G4OpenGLViewer::ResetView();
74 zoom_high = fVP.GetZoomFactor() * 10.0;
75 zoom_low = fVP.GetZoomFactor() / 10.0;
81 bool firstInit =
true;
82 if (GetSceneHandler() != NULL) {
83 if (GetSceneHandler()->GetScene() != NULL) {
88 pan_sens_limit = 100.;
89 fPan_sens = pan_sens_limit / 10.0;
90 dolly_low = fVP.GetDolly() - 1000.0;
91 dolly_high = fVP.GetDolly() + 1000.0;
93 fPan_sens = GetSceneHandler()->GetScene()->GetExtent().GetExtentRadius() / 10.0;
94 pan_sens_limit = GetSceneHandler()->GetScene()->GetExtent().GetExtentRadius();
96 dolly_high = GetSceneHandler()->GetScene()->GetExtent().GetExtentRadius();
97 dolly_low = -(GetSceneHandler()->GetScene()->GetExtent().GetExtentRadius());
100 UpdateControlPanel ();
109 void G4OpenGLXmViewer::GetXmConnection () {
111 G4Xt* interactorManager = G4Xt::getInstance ();
112 toplevel = (Widget)interactorManager->GetMainInteractor();
113 app = XtWidgetToApplicationContext(toplevel);
117 G4cerr <<
"G4OpenGLXmViewer::GetXmConnection unable to Initialize"
118 " application context." <<
G4endl;
123 std::ostringstream oss;
125 "*glxarea*width: " << fVP.GetWindowSizeHintX() <<
"\n"
126 "*glxarea*height: " << fVP.GetWindowSizeHintY() <<
"\n"
134 "*frame*topOffset: 10\n"
135 "*frame*bottomOffset: 10\n"
136 "*frame*rightOffset: 10\n"
137 "*frame*leftOffset: 10\n"
138 "*frame*shadowType: SHADOW_IN\n"
139 "*frame*useColorObj: False\n"
140 "*frame*primaryColorSetId: 3\n"
141 "*frame*secondaryColorSetId: 3\n"
142 "*menubar*useColorObj: False\n"
143 "*menubar*primaryColorSetId: 3\n"
144 "*menubar*secondaryColorSetId: 3\n"
145 "*toplevel*useColorObj: False\n"
146 "*toplevel*primaryColorSetId: 3\n"
147 "*toplevel*secondaryColorSetId: 3\n";
148 interactorManager->PutStringInResourceDatabase ((
char*)oss.str().c_str());
152 shell = XtAppCreateShell ((String)
fName.
data(),(String)
fName.
data(),topLevelShellWidgetClass,XtDisplay(toplevel),NULL,0);
153 interactorManager->AddShell (shell);
155 dpy = XtDisplay (shell);
159 G4cerr <<
"G4OpenGLXmViewer::GetXmConnection unable to connect to display."
164 if (!glXQueryExtension (dpy, &errorBase, &eventBase)) {
166 G4cerr <<
"G4OpenGLXmViewer::GetXmConnection. X Server has no GLX extension."
172 void G4OpenGLXmViewer::CreateMainWindow () {
174 bgnd = XWhitePixelOfScreen (XtScreen(shell));
175 borcol = XBlackPixelOfScreen (XtScreen(shell));
177 ResizeWindow(fVP.GetWindowSizeHintX(),fVP.GetWindowSizeHintY());
179 G4int x_origin = fVP.GetWindowAbsoluteLocationHintX(DisplayWidth(dpy, vi -> screen));
183 G4int y_origin = fVP.GetWindowAbsoluteLocationHintY(DisplayHeight(dpy, vi -> screen));
185 if (fVP.IsWindowSizeHintX () && fVP.IsWindowLocationHintX () && fVP.IsWindowLocationHintY ()) {
186 XtVaSetValues (shell,
187 XtNvisual, vi -> visual,
188 XtNdepth, vi -> depth,
190 XtNwidth, getWinWidth(),
191 XtNheight, getWinHeight(),
194 XtNborderColor, &borcol,
195 XtNbackground, &bgnd,
198 }
else if (fVP.IsWindowSizeHintX () && !(fVP.IsWindowLocationHintX () || fVP.IsWindowLocationHintY ())) {
199 XtVaSetValues (shell,
200 XtNvisual, vi -> visual,
201 XtNdepth, vi -> depth,
203 XtNwidth, getWinWidth(),
204 XtNheight, getWinHeight(),
205 XtNborderColor, &borcol,
206 XtNbackground, &bgnd,
209 }
else if ((!fVP.IsWindowSizeHintX ()) && fVP.IsWindowLocationHintX () && fVP.IsWindowLocationHintY ()) {
210 XtVaSetValues (shell,
211 XtNvisual, vi -> visual,
212 XtNdepth, vi -> depth,
216 XtNborderColor, &borcol,
217 XtNbackground, &bgnd,
221 XtVaSetValues (shell,
222 XtNvisual, vi -> visual,
223 XtNdepth, vi -> depth,
225 XtNborderColor, &borcol,
226 XtNbackground, &bgnd,
232 main_win = XtVaCreateManagedWidget (
"main_win",
233 xmMainWindowWidgetClass,
235 XtNvisual, vi -> visual,
236 XtNdepth, vi -> depth,
238 XtNborderColor, borcol,
243 style_str = XmStringCreateLocalized ((
char*)
"Style");
244 actions_str = XmStringCreateLocalized ((
char*)
"Actions");
245 misc_str = XmStringCreateLocalized ((
char*)
"Miscellany");
246 spec_str = XmStringCreateLocalized ((
char*)
"Special");
248 menubar = XmVaCreateSimpleMenuBar (main_win,
250 XmVaCASCADEBUTTON, style_str, (KeySym)XK_S,
251 XmVaCASCADEBUTTON, actions_str, (KeySym)XK_A,
252 XmVaCASCADEBUTTON, misc_str, (KeySym)XK_M,
253 XmVaCASCADEBUTTON, spec_str, (KeySym)XK_p,
254 XtNvisual, vi -> visual,
255 XtNdepth, vi -> depth,
257 XtNborderColor, borcol,
261 XmStringFree (style_str);
262 XmStringFree (actions_str);
263 XmStringFree (misc_str);
264 XmStringFree (spec_str);
270 draw_str = XmStringCreateLocalized ((
char*)
"Drawing");
271 bgnd_str = XmStringCreateLocalized ((
char*)
"Background color");
273 style_cascade = XmVaCreateSimplePulldownMenu
278 XmVaCASCADEBUTTON, draw_str, (KeySym)XK_D,
279 XmVaCASCADEBUTTON, bgnd_str, (KeySym)XK_B,
280 XtNvisual, vi -> visual,
281 XtNdepth, vi -> depth,
283 XtNborderColor, borcol,
287 XmStringFree (draw_str);
288 XmStringFree (bgnd_str);
293 wireframe_str = XmStringCreateLocalized ((
char*)
"Wireframe");
294 hlr_str = XmStringCreateLocalized ((
char*)
"Hidden line removal");
295 hsr_str = XmStringCreateLocalized ((
char*)
"Hidden surface removal");
296 hlhsr_str = XmStringCreateLocalized ((
char*)
"Hidden line and surface removal");
298 drawing_style_pullright = XmVaCreateSimplePulldownMenu
300 (
char*)
"drawing_style",
302 drawing_style_callback,
303 XmVaRADIOBUTTON, wireframe_str, (KeySym)XK_W, NULL, NULL,
304 XmVaRADIOBUTTON, hlr_str, (KeySym)XK_L, NULL, NULL,
305 XmVaRADIOBUTTON, hsr_str, (KeySym)XK_S, NULL, NULL,
306 XmVaRADIOBUTTON, hlhsr_str, (KeySym)XK_H, NULL, NULL,
307 XmNradioBehavior, True,
308 XmNradioAlwaysOne, True,
310 XtNvisual, vi -> visual,
311 XtNdepth, vi -> depth,
313 XtNborderColor, borcol,
317 Widget special_widget;
320 d_style = fVP.GetDrawingStyle();
323 special_widget = XtNameToWidget(drawing_style_pullright,
"button_0");
325 XtVaSetValues (special_widget, XmNset, True, NULL);
328 special_widget = XtNameToWidget(drawing_style_pullright,
"button_1");
330 XtVaSetValues (special_widget, XmNset, True, NULL);
333 special_widget = XtNameToWidget(drawing_style_pullright,
"button_2");
335 XtVaSetValues (special_widget, XmNset, True, NULL);
338 special_widget = XtNameToWidget(drawing_style_pullright,
"button_3");
340 XtVaSetValues (special_widget, XmNset, True, NULL);
344 (
"G4OpenGLXmViewer::CreateMainWindow",
346 "Invalid Drawing style in G4OpenGLXmViewer::CreateContext");
349 XmStringFree (wireframe_str);
350 XmStringFree (hlr_str);
351 XmStringFree (hsr_str);
352 XmStringFree (hlhsr_str);
357 white_str = XmStringCreateLocalized ((
char*)
"White");
358 black_str = XmStringCreateLocalized ((
char*)
"Black");
360 background_color_pullright = XmVaCreateSimplePulldownMenu
362 (
char*)
"background_color",
364 background_color_callback,
365 XmVaRADIOBUTTON, white_str, (KeySym)XK_W, NULL, NULL,
366 XmVaRADIOBUTTON, black_str, (KeySym)XK_B, NULL, NULL,
367 XmNradioBehavior, True,
368 XmNradioAlwaysOne, True,
370 XtNvisual, vi -> visual,
371 XtNdepth, vi -> depth,
373 XtNborderColor, borcol,
377 if (background.GetRed() == 1. &&
378 background.GetGreen() == 1. &&
379 background.GetBlue() == 1.) {
380 special_widget = XtNameToWidget(background_color_pullright,
"button_0");
382 XtVaSetValues (special_widget, XmNset, True, NULL);
385 special_widget = XtNameToWidget(background_color_pullright,
"button_1");
387 XtVaSetValues (special_widget, XmNset, True, NULL);
391 XmStringFree (white_str);
392 XmStringFree (black_str);
397 rot_str = XmStringCreateLocalized ((
char*)
"Rotation control panel");
398 pan_str = XmStringCreateLocalized ((
char*)
"Panning control panel");
399 set_str = XmStringCreateLocalized ((
char*)
"Set control panel limits");
401 actions_cascade = XmVaCreateSimplePulldownMenu
406 XmVaPUSHBUTTON, rot_str, (KeySym)XK_R, NULL, NULL,
407 XmVaPUSHBUTTON, pan_str, (KeySym)XK_P, NULL, NULL,
408 XmVaPUSHBUTTON, set_str, (KeySym)XK_S, NULL, NULL,
410 XtNvisual, vi -> visual,
411 XtNdepth, vi -> depth,
413 XtNborderColor, borcol,
417 XmStringFree (rot_str);
418 XmStringFree (pan_str);
419 XmStringFree (set_str);
422 misc_str = XmStringCreateLocalized ((
char*)
"Miscellany control panel");
423 exit_str = XmStringCreateLocalized ((
char*)
"Exit to G4Vis>");
424 print_str = XmStringCreateLocalized ((
char*)
"Create .eps file");
427 misc_cascade = XmVaCreateSimplePulldownMenu
432 XmVaPUSHBUTTON, misc_str, (KeySym)XK_M, NULL, NULL,
433 XmVaPUSHBUTTON, exit_str, (KeySym)XK_E, NULL, NULL,
434 XmVaPUSHBUTTON, print_str, (KeySym)XK_P, NULL, NULL,
436 XtNvisual, vi -> visual,
437 XtNdepth, vi -> depth,
439 XtNborderColor, borcol,
443 XmStringFree (misc_str);
444 XmStringFree (exit_str);
445 XmStringFree (print_str);
448 trans_str = XmStringCreateLocalized ((
char*)
"Transparency");
449 anti_str = XmStringCreateLocalized ((
char*)
"Antialiasing");
450 halo_str = XmStringCreateLocalized ((
char*)
"Haloing");
451 aux_edge_str = XmStringCreateLocalized ((
char*)
"Auxiliary edges");
454 spec_cascade = XmVaCreateSimplePulldownMenu
459 XmVaCASCADEBUTTON, trans_str, (KeySym)XK_T,
460 XmVaCASCADEBUTTON, anti_str, (KeySym)XK_A,
461 XmVaCASCADEBUTTON, halo_str, (KeySym)XK_H,
462 XmVaCASCADEBUTTON, aux_edge_str, (KeySym)XK_E,
463 XtNvisual, vi -> visual,
464 XtNdepth, vi -> depth,
466 XtNborderColor, borcol,
470 XmStringFree (trans_str);
471 XmStringFree (anti_str);
472 XmStringFree (halo_str);
473 XmStringFree (aux_edge_str);
478 off_str = XmStringCreateLocalized ((
char*)
"Off");
479 on_str = XmStringCreateLocalized ((
char*)
"On");
481 transparency_pullright = XmVaCreateSimplePulldownMenu
483 (
char*)
"transparency",
485 transparency_callback,
486 XmVaRADIOBUTTON, off_str, (KeySym)XK_f, NULL, NULL,
487 XmVaRADIOBUTTON, on_str, (KeySym)XK_n, NULL, NULL,
488 XmNradioBehavior, True,
489 XmNradioAlwaysOne, True,
491 XtNvisual, vi -> visual,
492 XtNdepth, vi -> depth,
494 XtNborderColor, borcol,
498 if (transparency_enabled ==
false) {
499 special_widget = XtNameToWidget(transparency_pullright,
"button_0");
501 XtVaSetValues (special_widget, XmNset, True, NULL);
503 }
else if (transparency_enabled ==
true) {
504 special_widget = XtNameToWidget(transparency_pullright,
"button_1");
506 XtVaSetValues (special_widget, XmNset, True, NULL);
510 (
"G4OpenGLXmViewer::CreateMainWindow",
512 "transparency_enabled in G4OpenGLXmViewer is neither true nor false!!");
516 antialias_pullright = XmVaCreateSimplePulldownMenu
521 XmVaRADIOBUTTON, off_str, (KeySym)XK_f, NULL, NULL,
522 XmVaRADIOBUTTON, on_str, (KeySym)XK_n, NULL, NULL,
523 XmNradioBehavior, True,
524 XmNradioAlwaysOne, True,
526 XtNvisual, vi -> visual,
527 XtNdepth, vi -> depth,
529 XtNborderColor, borcol,
533 if (antialiasing_enabled ==
false) {
534 special_widget = XtNameToWidget(antialias_pullright,
"button_0");
536 XtVaSetValues (special_widget, XmNset, True, NULL);
538 }
else if (antialiasing_enabled ==
true) {
539 special_widget = XtNameToWidget(antialias_pullright,
"button_1");
541 XtVaSetValues (special_widget, XmNset, True, NULL);
545 (
"G4OpenGLXmViewer::CreateMainWindow",
547 "antialiasing_enabled in G4OpenGLXmViewer is neither true nor false!!");
551 haloing_pullright = XmVaCreateSimplePulldownMenu
556 XmVaRADIOBUTTON, off_str, (KeySym)XK_f, NULL, NULL,
557 XmVaRADIOBUTTON, on_str, (KeySym)XK_n, NULL, NULL,
558 XmNradioBehavior, True,
559 XmNradioAlwaysOne, True,
561 XtNvisual, vi -> visual,
562 XtNdepth, vi -> depth,
564 XtNborderColor, borcol,
568 if (haloing_enabled ==
false) {
569 special_widget = XtNameToWidget(haloing_pullright,
"button_0");
571 XtVaSetValues (special_widget, XmNset, True, NULL);
573 }
else if (haloing_enabled ==
true) {
574 special_widget = XtNameToWidget(haloing_pullright,
"button_1");
576 XtVaSetValues (special_widget, XmNset, True, NULL);
580 (
"G4OpenGLXmViewer::CreateMainWindow",
582 "haloing_enabled in G4OpenGLXmViewer is neither true nor false!!");
586 aux_edge_pullright = XmVaCreateSimplePulldownMenu
591 XmVaRADIOBUTTON, off_str, (KeySym)XK_f, NULL, NULL,
592 XmVaRADIOBUTTON, on_str, (KeySym)XK_n, NULL, NULL,
593 XmNradioBehavior, True,
594 XmNradioAlwaysOne, True,
596 XtNvisual, vi -> visual,
597 XtNdepth, vi -> depth,
599 XtNborderColor, borcol,
603 if (!fVP.IsAuxEdgeVisible()) {
604 special_widget = XtNameToWidget(aux_edge_pullright,
"button_0");
606 XtVaSetValues (special_widget, XmNset, True, NULL);
609 special_widget = XtNameToWidget(aux_edge_pullright,
"button_1");
611 XtVaSetValues (special_widget, XmNset, True, NULL);
615 XtManageChild (menubar);
616 frame = XtVaCreateManagedWidget ((
char*)
"frame",
617 xmFrameWidgetClass, main_win,
618 XtNvisual, vi -> visual,
619 XtNdepth, vi -> depth,
621 XtNborderColor, borcol,
625 glxarea = XtVaCreateManagedWidget ((
char*)
"glxarea",
626 xmDrawingAreaWidgetClass,
628 XtNvisual, vi -> visual,
629 XtNdepth, vi -> depth,
631 XtNborderColor, borcol,
636 XmMainWindowSetAreas (main_win,
644 XtRealizeWidget(shell);
649 win = XtWindow (glxarea);
651 glXMakeCurrent (dpy, win, cxMaster);
654 XtAddCallback (glxarea,
659 XtAddCallback (glxarea,
666 G4OpenGLXmViewer::G4OpenGLXmViewer (G4OpenGLSceneHandler& scene):
668 G4OpenGLViewer (scene),
669 G4OpenGLXViewer (scene),
678 drawing_style_pullright (0),
679 background_color_pullright (0),
680 transparency_pullright (0),
681 antialias_pullright (0),
682 haloing_pullright (0),
683 aux_edge_pullright (0),
718 rot_sens_limit (0.0),
719 pan_sens_limit (0.0),
724 rotate_right (
false),
727 original_vp(fVP.GetViewpointDirection()),
730 fprotation_button_box (0),
731 fprotation_button1 (0),
732 fprotation_button2 (0),
733 fprotation_slider_box (0),
734 fprotation_slider (0),
735 fprotation_arrow_box (0),
736 fprotation_arrow (0),
739 fppanning_arrows (0),
740 fppanning_slider (0),
754 fpmiscellany_top (0),
760 fpproj_style_box (0),
761 fporthogonal_button (0),
762 fpperspective_button (0),
767 fpprint_style_box (0),
771 fpprint_col_radio1 (0),
772 fpprint_col_radio2 (0),
773 fpprint_style_radio1 (0),
774 fpprint_style_radio2 (0)
778 if (fViewId < 0)
return;
782 void G4OpenGLXmViewer::UpdateControlPanel () {
786 if (fprotation_slider) {
787 fprotation_slider->SetInitialValue(fRot_sens);
788 fprotation_slider->SetMaxValue(rot_sens_limit);
789 fprotation_slider->SetMinValue(0);
791 if (fppanning_slider) {
792 fppanning_slider->SetInitialValue(fPan_sens);
793 fppanning_slider->SetMaxValue(pan_sens_limit);
794 fppanning_slider->SetMinValue(0);
797 fpzoom_slider->SetInitialValue(fVP.GetZoomFactor());
798 fpzoom_slider->SetMinValue(zoom_low);
799 fpzoom_slider->SetMaxValue(zoom_high);
801 if (fpdolly_slider) {
802 fpdolly_slider->SetInitialValue(fVP.GetDolly());
803 fpdolly_slider->SetMinValue(dolly_low);
804 fpdolly_slider->SetMaxValue(dolly_high);
807 if (fpwobble_slider) {
808 fpwobble_slider->SetInitialValue(fVP.GetDolly());
812 fppan_set->SetValue(pan_sens_limit);
816 fprot_set->SetValue(rot_sens_limit);
820 fpzoom_upper->SetValue(zoom_high);
824 fpzoom_lower->SetValue(zoom_low);
827 fpdolly_upper->SetValue(dolly_high);
831 fpdolly_lower->SetValue(dolly_low);
838 G4OpenGLXmViewer::~G4OpenGLXmViewer ()
840 XtDestroyWidget (shell);
843 G4Xt::getInstance () ->RemoveShell (shell);