34 #ifdef G4VIS_BUILD_OPENGLXM_DRIVER
53 #include <X11/Shell.h>
56 #include <Xm/DrawingA.h>
60 void G4OpenGLXmViewer::ShowView () {
62 G4Xt::getInstance () -> SecondaryLoop ();
66 void 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 ();
106 void 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."
169 void 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,
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,
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,
218 XtVaSetValues (shell,
219 XtNvisual, vi -> visual,
220 XtNdepth, vi -> depth,
222 XtNborderColor, &borcol,
223 XtNbackground, &bgnd,
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 draw_str = XmStringCreateLocalized ((
char*)
"Drawing");
268 bgnd_str = XmStringCreateLocalized ((
char*)
"Background color");
270 style_cascade = XmVaCreateSimplePulldownMenu
275 XmVaCASCADEBUTTON, draw_str,
'D',
276 XmVaCASCADEBUTTON, bgnd_str,
'B',
277 XtNvisual, vi -> visual,
278 XtNdepth, vi -> depth,
280 XtNborderColor, borcol,
284 XmStringFree (draw_str);
285 XmStringFree (bgnd_str);
290 wireframe_str = XmStringCreateLocalized ((
char*)
"Wireframe");
291 hlr_str = XmStringCreateLocalized ((
char*)
"Hidden line removal");
292 hsr_str = XmStringCreateLocalized ((
char*)
"Hidden surface removal");
293 hlhsr_str = XmStringCreateLocalized ((
char*)
"Hidden line and surface removal");
295 drawing_style_pullright = XmVaCreateSimplePulldownMenu
297 (
char*)
"drawing_style",
299 drawing_style_callback,
300 XmVaRADIOBUTTON, wireframe_str,
'W', NULL, NULL,
301 XmVaRADIOBUTTON, hlr_str,
'L', NULL, NULL,
302 XmVaRADIOBUTTON, hsr_str,
'S', NULL, NULL,
303 XmVaRADIOBUTTON, hlhsr_str,
'H', NULL, NULL,
304 XmNradioBehavior, True,
305 XmNradioAlwaysOne, True,
307 XtNvisual, vi -> visual,
308 XtNdepth, vi -> depth,
310 XtNborderColor, borcol,
314 Widget special_widget;
317 d_style = fVP.GetDrawingStyle();
320 special_widget = XtNameToWidget(drawing_style_pullright,
"button_0");
322 XtVaSetValues (special_widget, XmNset, True, NULL);
325 special_widget = XtNameToWidget(drawing_style_pullright,
"button_1");
327 XtVaSetValues (special_widget, XmNset, True, NULL);
330 special_widget = XtNameToWidget(drawing_style_pullright,
"button_2");
332 XtVaSetValues (special_widget, XmNset, True, NULL);
335 special_widget = XtNameToWidget(drawing_style_pullright,
"button_3");
337 XtVaSetValues (special_widget, XmNset, True, NULL);
341 (
"G4OpenGLXmViewer::CreateMainWindow",
343 "Invalid Drawing style in G4OpenGLXmViewer::CreateContext");
346 XmStringFree (wireframe_str);
347 XmStringFree (hlr_str);
348 XmStringFree (hsr_str);
349 XmStringFree (hlhsr_str);
354 white_str = XmStringCreateLocalized ((
char*)
"White");
355 black_str = XmStringCreateLocalized ((
char*)
"Black");
357 background_color_pullright = XmVaCreateSimplePulldownMenu
359 (
char*)
"background_color",
361 background_color_callback,
362 XmVaRADIOBUTTON, white_str,
'W', NULL, NULL,
363 XmVaRADIOBUTTON, black_str,
'B', NULL, NULL,
364 XmNradioBehavior, True,
365 XmNradioAlwaysOne, True,
367 XtNvisual, vi -> visual,
368 XtNdepth, vi -> depth,
370 XtNborderColor, borcol,
374 if (background.GetRed() == 1. &&
375 background.GetGreen() == 1. &&
376 background.GetBlue() == 1.) {
377 special_widget = XtNameToWidget(background_color_pullright,
"button_0");
379 XtVaSetValues (special_widget, XmNset, True, NULL);
382 special_widget = XtNameToWidget(background_color_pullright,
"button_1");
384 XtVaSetValues (special_widget, XmNset, True, NULL);
388 XmStringFree (white_str);
389 XmStringFree (black_str);
394 rot_str = XmStringCreateLocalized ((
char*)
"Rotation control panel");
395 pan_str = XmStringCreateLocalized ((
char*)
"Panning control panel");
396 set_str = XmStringCreateLocalized ((
char*)
"Set control panel limits");
398 actions_cascade = XmVaCreateSimplePulldownMenu
403 XmVaPUSHBUTTON, rot_str,
'R', NULL, NULL,
404 XmVaPUSHBUTTON, pan_str,
'P', NULL, NULL,
405 XmVaPUSHBUTTON, set_str,
'S', NULL, NULL,
407 XtNvisual, vi -> visual,
408 XtNdepth, vi -> depth,
410 XtNborderColor, borcol,
414 XmStringFree (rot_str);
415 XmStringFree (pan_str);
416 XmStringFree (set_str);
419 misc_str = XmStringCreateLocalized ((
char*)
"Miscellany control panel");
420 exit_str = XmStringCreateLocalized ((
char*)
"Exit to G4Vis>");
421 print_str = XmStringCreateLocalized ((
char*)
"Create .eps file");
424 misc_cascade = XmVaCreateSimplePulldownMenu
429 XmVaPUSHBUTTON, misc_str,
'M', NULL, NULL,
430 XmVaPUSHBUTTON, exit_str,
'E', NULL, NULL,
431 XmVaPUSHBUTTON, print_str,
'P', NULL, NULL,
433 XtNvisual, vi -> visual,
434 XtNdepth, vi -> depth,
436 XtNborderColor, borcol,
440 XmStringFree (misc_str);
441 XmStringFree (exit_str);
442 XmStringFree (print_str);
445 trans_str = XmStringCreateLocalized ((
char*)
"Transparency");
446 anti_str = XmStringCreateLocalized ((
char*)
"Antialiasing");
447 halo_str = XmStringCreateLocalized ((
char*)
"Haloing");
448 aux_edge_str = XmStringCreateLocalized ((
char*)
"Auxiliary edges");
451 spec_cascade = XmVaCreateSimplePulldownMenu
456 XmVaCASCADEBUTTON, trans_str,
'T',
457 XmVaCASCADEBUTTON, anti_str,
'A',
458 XmVaCASCADEBUTTON, halo_str,
'H',
459 XmVaCASCADEBUTTON, aux_edge_str,
'E',
460 XtNvisual, vi -> visual,
461 XtNdepth, vi -> depth,
463 XtNborderColor, borcol,
467 XmStringFree (trans_str);
468 XmStringFree (anti_str);
469 XmStringFree (halo_str);
470 XmStringFree (aux_edge_str);
475 off_str = XmStringCreateLocalized ((
char*)
"Off");
476 on_str = XmStringCreateLocalized ((
char*)
"On");
478 transparency_pullright = XmVaCreateSimplePulldownMenu
480 (
char*)
"transparency",
482 transparency_callback,
483 XmVaRADIOBUTTON, off_str,
'f', NULL, NULL,
484 XmVaRADIOBUTTON, on_str,
'n', NULL, NULL,
485 XmNradioBehavior, True,
486 XmNradioAlwaysOne, True,
488 XtNvisual, vi -> visual,
489 XtNdepth, vi -> depth,
491 XtNborderColor, borcol,
495 if (transparency_enabled ==
false) {
496 special_widget = XtNameToWidget(transparency_pullright,
"button_0");
498 XtVaSetValues (special_widget, XmNset, True, NULL);
500 }
else if (transparency_enabled ==
true) {
501 special_widget = XtNameToWidget(transparency_pullright,
"button_1");
503 XtVaSetValues (special_widget, XmNset, True, NULL);
507 (
"G4OpenGLXmViewer::CreateMainWindow",
509 "transparency_enabled in G4OpenGLXmViewer is neither true nor false!!");
513 antialias_pullright = XmVaCreateSimplePulldownMenu
518 XmVaRADIOBUTTON, off_str,
'f', NULL, NULL,
519 XmVaRADIOBUTTON, on_str,
'n', NULL, NULL,
520 XmNradioBehavior, True,
521 XmNradioAlwaysOne, True,
523 XtNvisual, vi -> visual,
524 XtNdepth, vi -> depth,
526 XtNborderColor, borcol,
530 if (antialiasing_enabled ==
false) {
531 special_widget = XtNameToWidget(antialias_pullright,
"button_0");
533 XtVaSetValues (special_widget, XmNset, True, NULL);
535 }
else if (antialiasing_enabled ==
true) {
536 special_widget = XtNameToWidget(antialias_pullright,
"button_1");
538 XtVaSetValues (special_widget, XmNset, True, NULL);
542 (
"G4OpenGLXmViewer::CreateMainWindow",
544 "antialiasing_enabled in G4OpenGLXmViewer is neither true nor false!!");
548 haloing_pullright = XmVaCreateSimplePulldownMenu
553 XmVaRADIOBUTTON, off_str,
'f', NULL, NULL,
554 XmVaRADIOBUTTON, on_str,
'n', NULL, NULL,
555 XmNradioBehavior, True,
556 XmNradioAlwaysOne, True,
558 XtNvisual, vi -> visual,
559 XtNdepth, vi -> depth,
561 XtNborderColor, borcol,
565 if (haloing_enabled ==
false) {
566 special_widget = XtNameToWidget(haloing_pullright,
"button_0");
568 XtVaSetValues (special_widget, XmNset, True, NULL);
570 }
else if (haloing_enabled ==
true) {
571 special_widget = XtNameToWidget(haloing_pullright,
"button_1");
573 XtVaSetValues (special_widget, XmNset, True, NULL);
577 (
"G4OpenGLXmViewer::CreateMainWindow",
579 "haloing_enabled in G4OpenGLXmViewer is neither true nor false!!");
583 aux_edge_pullright = XmVaCreateSimplePulldownMenu
588 XmVaRADIOBUTTON, off_str,
'f', NULL, NULL,
589 XmVaRADIOBUTTON, on_str,
'n', NULL, NULL,
590 XmNradioBehavior, True,
591 XmNradioAlwaysOne, True,
593 XtNvisual, vi -> visual,
594 XtNdepth, vi -> depth,
596 XtNborderColor, borcol,
600 if (!fVP.IsAuxEdgeVisible()) {
601 special_widget = XtNameToWidget(aux_edge_pullright,
"button_0");
603 XtVaSetValues (special_widget, XmNset, True, NULL);
606 special_widget = XtNameToWidget(aux_edge_pullright,
"button_1");
608 XtVaSetValues (special_widget, XmNset, True, NULL);
612 XtManageChild (menubar);
613 frame = XtVaCreateManagedWidget ((
char*)
"frame",
614 xmFrameWidgetClass, main_win,
615 XtNvisual, vi -> visual,
616 XtNdepth, vi -> depth,
618 XtNborderColor, borcol,
622 glxarea = XtVaCreateManagedWidget ((
char*)
"glxarea",
623 xmDrawingAreaWidgetClass,
625 XtNvisual, vi -> visual,
626 XtNdepth, vi -> depth,
628 XtNborderColor, borcol,
633 XmMainWindowSetAreas (main_win,
641 XtRealizeWidget(shell);
646 win = XtWindow (glxarea);
648 glXMakeCurrent (dpy, win, cx);
651 XtAddCallback (glxarea,
656 XtAddCallback (glxarea,
663 G4OpenGLXmViewer::G4OpenGLXmViewer (G4OpenGLSceneHandler& scene):
665 G4OpenGLViewer (scene),
666 G4OpenGLXViewer (scene),
675 drawing_style_pullright (0),
676 background_color_pullright (0),
677 transparency_pullright (0),
678 antialias_pullright (0),
679 haloing_pullright (0),
680 aux_edge_pullright (0),
715 rot_sens_limit (0.0),
716 pan_sens_limit (0.0),
721 rotate_right (false),
724 original_vp(fVP.GetViewpointDirection()),
727 fprotation_button_box (0),
728 fprotation_button1 (0),
729 fprotation_button2 (0),
730 fprotation_slider_box (0),
731 fprotation_slider (0),
732 fprotation_arrow_box (0),
733 fprotation_arrow (0),
736 fppanning_arrows (0),
737 fppanning_slider (0),
751 fpmiscellany_top (0),
757 fpproj_style_box (0),
758 fporthogonal_button (0),
759 fpperspective_button (0),
764 fpprint_style_box (0),
768 fpprint_col_radio1 (0),
769 fpprint_col_radio2 (0),
770 fpprint_style_radio1 (0),
771 fpprint_style_radio2 (0)
775 if (fViewId < 0)
return;
779 void G4OpenGLXmViewer::UpdateControlPanel () {
783 if (fprotation_slider) {
784 fprotation_slider->SetInitialValue(fRot_sens);
785 fprotation_slider->SetMaxValue(rot_sens_limit);
786 fprotation_slider->SetMinValue(0);
788 if (fppanning_slider) {
789 fppanning_slider->SetInitialValue(fPan_sens);
790 fppanning_slider->SetMaxValue(pan_sens_limit);
791 fppanning_slider->SetMinValue(0);
794 fpzoom_slider->SetInitialValue(fVP.GetZoomFactor());
795 fpzoom_slider->SetMinValue(zoom_low);
796 fpzoom_slider->SetMaxValue(zoom_high);
798 if (fpdolly_slider) {
799 fpdolly_slider->SetInitialValue(fVP.GetDolly());
800 fpdolly_slider->SetMinValue(dolly_low);
801 fpdolly_slider->SetMaxValue(dolly_high);
804 if (fpwobble_slider) {
805 fpwobble_slider->SetInitialValue(fVP.GetDolly());
809 fppan_set->SetValue(pan_sens_limit);
813 fprot_set->SetValue(rot_sens_limit);
817 fpzoom_upper->SetValue(zoom_high);
821 fpzoom_lower->SetValue(zoom_low);
824 fpdolly_upper->SetValue(dolly_high);
828 fpdolly_lower->SetValue(dolly_low);
835 G4OpenGLXmViewer::~G4OpenGLXmViewer ()
837 XtDestroyWidget (shell);
840 G4Xt::getInstance () ->RemoveShell (shell);
G4GLOB_DLL std::ostream G4cout
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
const char * data() const
G4GLOB_DLL std::ostream G4cerr