34 #ifdef G4VIS_BUILD_OPENGLXM_DRIVER
53 #include <X11/Shell.h>
56 #include <Xm/DrawingA.h>
60 void G4OpenGLXmViewer::ShowView () {
66 G4Xt::getInstance () -> SecondaryLoop ();
70 void G4OpenGLXmViewer::ResetView () {
72 G4OpenGLViewer::ResetView();
75 zoom_high = fVP.GetZoomFactor() * 10.0;
76 zoom_low = fVP.GetZoomFactor() / 10.0;
82 bool firstInit =
true;
83 if (GetSceneHandler() != NULL) {
84 if (GetSceneHandler()->GetScene() != NULL) {
89 pan_sens_limit = 100.;
90 fPan_sens = pan_sens_limit / 10.0;
91 dolly_low = fVP.GetDolly() - 1000.0;
92 dolly_high = fVP.GetDolly() + 1000.0;
94 fPan_sens = GetSceneHandler()->GetScene()->GetExtent().GetExtentRadius() / 10.0;
95 pan_sens_limit = GetSceneHandler()->GetScene()->GetExtent().GetExtentRadius();
97 dolly_high = GetSceneHandler()->GetScene()->GetExtent().GetExtentRadius();
98 dolly_low = -(GetSceneHandler()->GetScene()->GetExtent().GetExtentRadius());
101 UpdateControlPanel ();
110 void G4OpenGLXmViewer::GetXmConnection () {
112 G4Xt* interactorManager = G4Xt::getInstance ();
113 toplevel = (Widget)interactorManager->GetMainInteractor();
114 app = XtWidgetToApplicationContext(toplevel);
118 G4cerr <<
"G4OpenGLXmViewer::GetXmConnection unable to Initialize"
119 " application context." <<
G4endl;
124 std::ostringstream oss;
126 "*glxarea*width: " << fVP.GetWindowSizeHintX() <<
"\n"
127 "*glxarea*height: " << fVP.GetWindowSizeHintY() <<
"\n"
135 "*frame*topOffset: 10\n"
136 "*frame*bottomOffset: 10\n"
137 "*frame*rightOffset: 10\n"
138 "*frame*leftOffset: 10\n"
139 "*frame*shadowType: SHADOW_IN\n"
140 "*frame*useColorObj: False\n"
141 "*frame*primaryColorSetId: 3\n"
142 "*frame*secondaryColorSetId: 3\n"
143 "*menubar*useColorObj: False\n"
144 "*menubar*primaryColorSetId: 3\n"
145 "*menubar*secondaryColorSetId: 3\n"
146 "*toplevel*useColorObj: False\n"
147 "*toplevel*primaryColorSetId: 3\n"
148 "*toplevel*secondaryColorSetId: 3\n";
149 interactorManager->PutStringInResourceDatabase ((
char*)oss.str().c_str());
153 shell = XtAppCreateShell ((String)
fName.
data(),(String)
fName.
data(),topLevelShellWidgetClass,XtDisplay(toplevel),NULL,0);
154 interactorManager->AddShell (shell);
156 dpy = XtDisplay (shell);
160 G4cerr <<
"G4OpenGLXmViewer::GetXmConnection unable to connect to display."
165 if (!glXQueryExtension (dpy, &errorBase, &eventBase)) {
167 G4cerr <<
"G4OpenGLXmViewer::GetXmConnection. X Server has no GLX extension."
173 void G4OpenGLXmViewer::CreateMainWindow () {
175 bgnd = XWhitePixelOfScreen (XtScreen(shell));
176 borcol = XBlackPixelOfScreen (XtScreen(shell));
178 ResizeWindow(fVP.GetWindowSizeHintX(),fVP.GetWindowSizeHintY());
180 G4int x_origin = fVP.GetWindowAbsoluteLocationHintX(DisplayWidth(dpy, vi -> screen));
184 G4int y_origin = fVP.GetWindowAbsoluteLocationHintY(DisplayHeight(dpy, vi -> screen));
186 if (fVP.IsWindowSizeHintX () && fVP.IsWindowLocationHintX () && fVP.IsWindowLocationHintY ()) {
187 XtVaSetValues (shell,
188 XtNvisual, vi -> visual,
189 XtNdepth, vi -> depth,
191 XtNwidth, getWinWidth(),
192 XtNheight, getWinHeight(),
195 XtNborderColor, &borcol,
196 XtNbackground, &bgnd,
199 }
else if (fVP.IsWindowSizeHintX () && !(fVP.IsWindowLocationHintX () || fVP.IsWindowLocationHintY ())) {
200 XtVaSetValues (shell,
201 XtNvisual, vi -> visual,
202 XtNdepth, vi -> depth,
204 XtNwidth, getWinWidth(),
205 XtNheight, getWinHeight(),
206 XtNborderColor, &borcol,
207 XtNbackground, &bgnd,
210 }
else if ((!fVP.IsWindowSizeHintX ()) && fVP.IsWindowLocationHintX () && fVP.IsWindowLocationHintY ()) {
211 XtVaSetValues (shell,
212 XtNvisual, vi -> visual,
213 XtNdepth, vi -> depth,
217 XtNborderColor, &borcol,
218 XtNbackground, &bgnd,
222 XtVaSetValues (shell,
223 XtNvisual, vi -> visual,
224 XtNdepth, vi -> depth,
226 XtNborderColor, &borcol,
227 XtNbackground, &bgnd,
233 main_win = XtVaCreateManagedWidget (
"main_win",
234 xmMainWindowWidgetClass,
236 XtNvisual, vi -> visual,
237 XtNdepth, vi -> depth,
239 XtNborderColor, borcol,
244 style_str = XmStringCreateLocalized ((
char*)
"Style");
245 actions_str = XmStringCreateLocalized ((
char*)
"Actions");
246 misc_str = XmStringCreateLocalized ((
char*)
"Miscellany");
247 spec_str = XmStringCreateLocalized ((
char*)
"Special");
249 menubar = XmVaCreateSimpleMenuBar (main_win,
251 XmVaCASCADEBUTTON, style_str,
'S',
252 XmVaCASCADEBUTTON, actions_str,
'A',
253 XmVaCASCADEBUTTON, misc_str,
'M',
254 XmVaCASCADEBUTTON, spec_str,
'p',
255 XtNvisual, vi -> visual,
256 XtNdepth, vi -> depth,
258 XtNborderColor, borcol,
262 XmStringFree (style_str);
263 XmStringFree (actions_str);
264 XmStringFree (misc_str);
265 XmStringFree (spec_str);
271 draw_str = XmStringCreateLocalized ((
char*)
"Drawing");
272 bgnd_str = XmStringCreateLocalized ((
char*)
"Background color");
274 style_cascade = XmVaCreateSimplePulldownMenu
279 XmVaCASCADEBUTTON, draw_str,
'D',
280 XmVaCASCADEBUTTON, bgnd_str,
'B',
281 XtNvisual, vi -> visual,
282 XtNdepth, vi -> depth,
284 XtNborderColor, borcol,
288 XmStringFree (draw_str);
289 XmStringFree (bgnd_str);
294 wireframe_str = XmStringCreateLocalized ((
char*)
"Wireframe");
295 hlr_str = XmStringCreateLocalized ((
char*)
"Hidden line removal");
296 hsr_str = XmStringCreateLocalized ((
char*)
"Hidden surface removal");
297 hlhsr_str = XmStringCreateLocalized ((
char*)
"Hidden line and surface removal");
299 drawing_style_pullright = XmVaCreateSimplePulldownMenu
301 (
char*)
"drawing_style",
303 drawing_style_callback,
304 XmVaRADIOBUTTON, wireframe_str,
'W', NULL, NULL,
305 XmVaRADIOBUTTON, hlr_str,
'L', NULL, NULL,
306 XmVaRADIOBUTTON, hsr_str,
'S', NULL, NULL,
307 XmVaRADIOBUTTON, hlhsr_str,
'H', NULL, NULL,
308 XmNradioBehavior, True,
309 XmNradioAlwaysOne, True,
311 XtNvisual, vi -> visual,
312 XtNdepth, vi -> depth,
314 XtNborderColor, borcol,
318 Widget special_widget;
321 d_style = fVP.GetDrawingStyle();
324 special_widget = XtNameToWidget(drawing_style_pullright,
"button_0");
326 XtVaSetValues (special_widget, XmNset, True, NULL);
329 special_widget = XtNameToWidget(drawing_style_pullright,
"button_1");
331 XtVaSetValues (special_widget, XmNset, True, NULL);
334 special_widget = XtNameToWidget(drawing_style_pullright,
"button_2");
336 XtVaSetValues (special_widget, XmNset, True, NULL);
339 special_widget = XtNameToWidget(drawing_style_pullright,
"button_3");
341 XtVaSetValues (special_widget, XmNset, True, NULL);
345 (
"G4OpenGLXmViewer::CreateMainWindow",
347 "Invalid Drawing style in G4OpenGLXmViewer::CreateContext");
350 XmStringFree (wireframe_str);
351 XmStringFree (hlr_str);
352 XmStringFree (hsr_str);
353 XmStringFree (hlhsr_str);
358 white_str = XmStringCreateLocalized ((
char*)
"White");
359 black_str = XmStringCreateLocalized ((
char*)
"Black");
361 background_color_pullright = XmVaCreateSimplePulldownMenu
363 (
char*)
"background_color",
365 background_color_callback,
366 XmVaRADIOBUTTON, white_str,
'W', NULL, NULL,
367 XmVaRADIOBUTTON, black_str,
'B', NULL, NULL,
368 XmNradioBehavior, True,
369 XmNradioAlwaysOne, True,
371 XtNvisual, vi -> visual,
372 XtNdepth, vi -> depth,
374 XtNborderColor, borcol,
378 if (background.GetRed() == 1. &&
379 background.GetGreen() == 1. &&
380 background.GetBlue() == 1.) {
381 special_widget = XtNameToWidget(background_color_pullright,
"button_0");
383 XtVaSetValues (special_widget, XmNset, True, NULL);
386 special_widget = XtNameToWidget(background_color_pullright,
"button_1");
388 XtVaSetValues (special_widget, XmNset, True, NULL);
392 XmStringFree (white_str);
393 XmStringFree (black_str);
398 rot_str = XmStringCreateLocalized ((
char*)
"Rotation control panel");
399 pan_str = XmStringCreateLocalized ((
char*)
"Panning control panel");
400 set_str = XmStringCreateLocalized ((
char*)
"Set control panel limits");
402 actions_cascade = XmVaCreateSimplePulldownMenu
407 XmVaPUSHBUTTON, rot_str,
'R', NULL, NULL,
408 XmVaPUSHBUTTON, pan_str,
'P', NULL, NULL,
409 XmVaPUSHBUTTON, set_str,
'S', NULL, NULL,
411 XtNvisual, vi -> visual,
412 XtNdepth, vi -> depth,
414 XtNborderColor, borcol,
418 XmStringFree (rot_str);
419 XmStringFree (pan_str);
420 XmStringFree (set_str);
423 misc_str = XmStringCreateLocalized ((
char*)
"Miscellany control panel");
424 exit_str = XmStringCreateLocalized ((
char*)
"Exit to G4Vis>");
425 print_str = XmStringCreateLocalized ((
char*)
"Create .eps file");
428 misc_cascade = XmVaCreateSimplePulldownMenu
433 XmVaPUSHBUTTON, misc_str,
'M', NULL, NULL,
434 XmVaPUSHBUTTON, exit_str,
'E', NULL, NULL,
435 XmVaPUSHBUTTON, print_str,
'P', NULL, NULL,
437 XtNvisual, vi -> visual,
438 XtNdepth, vi -> depth,
440 XtNborderColor, borcol,
444 XmStringFree (misc_str);
445 XmStringFree (exit_str);
446 XmStringFree (print_str);
449 trans_str = XmStringCreateLocalized ((
char*)
"Transparency");
450 anti_str = XmStringCreateLocalized ((
char*)
"Antialiasing");
451 halo_str = XmStringCreateLocalized ((
char*)
"Haloing");
452 aux_edge_str = XmStringCreateLocalized ((
char*)
"Auxiliary edges");
455 spec_cascade = XmVaCreateSimplePulldownMenu
460 XmVaCASCADEBUTTON, trans_str,
'T',
461 XmVaCASCADEBUTTON, anti_str,
'A',
462 XmVaCASCADEBUTTON, halo_str,
'H',
463 XmVaCASCADEBUTTON, aux_edge_str,
'E',
464 XtNvisual, vi -> visual,
465 XtNdepth, vi -> depth,
467 XtNborderColor, borcol,
471 XmStringFree (trans_str);
472 XmStringFree (anti_str);
473 XmStringFree (halo_str);
474 XmStringFree (aux_edge_str);
479 off_str = XmStringCreateLocalized ((
char*)
"Off");
480 on_str = XmStringCreateLocalized ((
char*)
"On");
482 transparency_pullright = XmVaCreateSimplePulldownMenu
484 (
char*)
"transparency",
486 transparency_callback,
487 XmVaRADIOBUTTON, off_str,
'f', NULL, NULL,
488 XmVaRADIOBUTTON, on_str,
'n', NULL, NULL,
489 XmNradioBehavior, True,
490 XmNradioAlwaysOne, True,
492 XtNvisual, vi -> visual,
493 XtNdepth, vi -> depth,
495 XtNborderColor, borcol,
499 if (transparency_enabled ==
false) {
500 special_widget = XtNameToWidget(transparency_pullright,
"button_0");
502 XtVaSetValues (special_widget, XmNset, True, NULL);
504 }
else if (transparency_enabled ==
true) {
505 special_widget = XtNameToWidget(transparency_pullright,
"button_1");
507 XtVaSetValues (special_widget, XmNset, True, NULL);
511 (
"G4OpenGLXmViewer::CreateMainWindow",
513 "transparency_enabled in G4OpenGLXmViewer is neither true nor false!!");
517 antialias_pullright = XmVaCreateSimplePulldownMenu
522 XmVaRADIOBUTTON, off_str,
'f', NULL, NULL,
523 XmVaRADIOBUTTON, on_str,
'n', NULL, NULL,
524 XmNradioBehavior, True,
525 XmNradioAlwaysOne, True,
527 XtNvisual, vi -> visual,
528 XtNdepth, vi -> depth,
530 XtNborderColor, borcol,
534 if (antialiasing_enabled ==
false) {
535 special_widget = XtNameToWidget(antialias_pullright,
"button_0");
537 XtVaSetValues (special_widget, XmNset, True, NULL);
539 }
else if (antialiasing_enabled ==
true) {
540 special_widget = XtNameToWidget(antialias_pullright,
"button_1");
542 XtVaSetValues (special_widget, XmNset, True, NULL);
546 (
"G4OpenGLXmViewer::CreateMainWindow",
548 "antialiasing_enabled in G4OpenGLXmViewer is neither true nor false!!");
552 haloing_pullright = XmVaCreateSimplePulldownMenu
557 XmVaRADIOBUTTON, off_str,
'f', NULL, NULL,
558 XmVaRADIOBUTTON, on_str,
'n', NULL, NULL,
559 XmNradioBehavior, True,
560 XmNradioAlwaysOne, True,
562 XtNvisual, vi -> visual,
563 XtNdepth, vi -> depth,
565 XtNborderColor, borcol,
569 if (haloing_enabled ==
false) {
570 special_widget = XtNameToWidget(haloing_pullright,
"button_0");
572 XtVaSetValues (special_widget, XmNset, True, NULL);
574 }
else if (haloing_enabled ==
true) {
575 special_widget = XtNameToWidget(haloing_pullright,
"button_1");
577 XtVaSetValues (special_widget, XmNset, True, NULL);
581 (
"G4OpenGLXmViewer::CreateMainWindow",
583 "haloing_enabled in G4OpenGLXmViewer is neither true nor false!!");
587 aux_edge_pullright = XmVaCreateSimplePulldownMenu
592 XmVaRADIOBUTTON, off_str,
'f', NULL, NULL,
593 XmVaRADIOBUTTON, on_str,
'n', NULL, NULL,
594 XmNradioBehavior, True,
595 XmNradioAlwaysOne, True,
597 XtNvisual, vi -> visual,
598 XtNdepth, vi -> depth,
600 XtNborderColor, borcol,
604 if (!fVP.IsAuxEdgeVisible()) {
605 special_widget = XtNameToWidget(aux_edge_pullright,
"button_0");
607 XtVaSetValues (special_widget, XmNset, True, NULL);
610 special_widget = XtNameToWidget(aux_edge_pullright,
"button_1");
612 XtVaSetValues (special_widget, XmNset, True, NULL);
616 XtManageChild (menubar);
617 frame = XtVaCreateManagedWidget ((
char*)
"frame",
618 xmFrameWidgetClass, main_win,
619 XtNvisual, vi -> visual,
620 XtNdepth, vi -> depth,
622 XtNborderColor, borcol,
626 glxarea = XtVaCreateManagedWidget ((
char*)
"glxarea",
627 xmDrawingAreaWidgetClass,
629 XtNvisual, vi -> visual,
630 XtNdepth, vi -> depth,
632 XtNborderColor, borcol,
637 XmMainWindowSetAreas (main_win,
645 XtRealizeWidget(shell);
650 win = XtWindow (glxarea);
652 glXMakeCurrent (dpy, win, cxMaster);
655 XtAddCallback (glxarea,
660 XtAddCallback (glxarea,
667 G4OpenGLXmViewer::G4OpenGLXmViewer (G4OpenGLSceneHandler& scene):
669 G4OpenGLViewer (scene),
670 G4OpenGLXViewer (scene),
679 drawing_style_pullright (0),
680 background_color_pullright (0),
681 transparency_pullright (0),
682 antialias_pullright (0),
683 haloing_pullright (0),
684 aux_edge_pullright (0),
719 rot_sens_limit (0.0),
720 pan_sens_limit (0.0),
725 rotate_right (false),
728 original_vp(fVP.GetViewpointDirection()),
731 fprotation_button_box (0),
732 fprotation_button1 (0),
733 fprotation_button2 (0),
734 fprotation_slider_box (0),
735 fprotation_slider (0),
736 fprotation_arrow_box (0),
737 fprotation_arrow (0),
740 fppanning_arrows (0),
741 fppanning_slider (0),
755 fpmiscellany_top (0),
761 fpproj_style_box (0),
762 fporthogonal_button (0),
763 fpperspective_button (0),
768 fpprint_style_box (0),
772 fpprint_col_radio1 (0),
773 fpprint_col_radio2 (0),
774 fpprint_style_radio1 (0),
775 fpprint_style_radio2 (0)
779 if (fViewId < 0)
return;
783 void G4OpenGLXmViewer::UpdateControlPanel () {
787 if (fprotation_slider) {
788 fprotation_slider->SetInitialValue(fRot_sens);
789 fprotation_slider->SetMaxValue(rot_sens_limit);
790 fprotation_slider->SetMinValue(0);
792 if (fppanning_slider) {
793 fppanning_slider->SetInitialValue(fPan_sens);
794 fppanning_slider->SetMaxValue(pan_sens_limit);
795 fppanning_slider->SetMinValue(0);
798 fpzoom_slider->SetInitialValue(fVP.GetZoomFactor());
799 fpzoom_slider->SetMinValue(zoom_low);
800 fpzoom_slider->SetMaxValue(zoom_high);
802 if (fpdolly_slider) {
803 fpdolly_slider->SetInitialValue(fVP.GetDolly());
804 fpdolly_slider->SetMinValue(dolly_low);
805 fpdolly_slider->SetMaxValue(dolly_high);
808 if (fpwobble_slider) {
809 fpwobble_slider->SetInitialValue(fVP.GetDolly());
813 fppan_set->SetValue(pan_sens_limit);
817 fprot_set->SetValue(rot_sens_limit);
821 fpzoom_upper->SetValue(zoom_high);
825 fpzoom_lower->SetValue(zoom_low);
828 fpdolly_upper->SetValue(dolly_high);
832 fpdolly_lower->SetValue(dolly_low);
839 G4OpenGLXmViewer::~G4OpenGLXmViewer ()
841 XtDestroyWidget (shell);
844 G4Xt::getInstance () ->RemoveShell (shell);
const char * data() const
G4GLOB_DLL std::ostream G4cerr
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
G4GLOB_DLL std::ostream G4cout