Geant4 Cross Reference |
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 // 28 // 29 // Andrew Walkden 16th April 1997 30 // G4OpenGLXmMainMenubarCallbacks : 31 // Collection of callback functions 32 // to handle events generated by the 33 // main OpenGLXm window menubar. 34 // 35 // See G4OpenGLXmMainMenubarCallbacks.hh for more information. 36 37 38 #include "G4OpenGLXmViewer.hh" 39 40 #include "G4Xt.hh" 41 42 #include "G4VSceneHandler.hh" 43 44 #include "G4Scene.hh" 45 46 #include "G4OpenGLXmRadioButton.hh" 47 #include "G4OpenGLXmSliderBar.hh" 48 #include "G4OpenGLXmFourArrowButtons.hh" 49 #include "G4OpenGLXmTextField.hh" 50 #include "G4OpenGLXmPushButton.hh" 51 #include "G4OpenGLXmBox.hh" 52 #include "G4OpenGLXmFramedBox.hh" 53 #include "G4OpenGLXmTopLevelShell.hh" 54 #include "G4OpenGLXmSeparator.hh" 55 56 #include <sstream> 57 58 void G4OpenGLXmViewer::actions_callback (Widget w, 59 XtPointer clientData, 60 XtPointer) 61 { 62 63 G4OpenGLXmViewer* pView; 64 G4long choice = (G4long)clientData; 65 66 67 XtVaGetValues (XtParent(w), 68 XmNuserData, &pView, 69 NULL); 70 71 switch (choice) { 72 73 case 0: 74 75 { 76 77 if (!pView->fprotation_top) { 78 std::ostringstream rot_Name; 79 rot_Name << pView->GetSceneHandler()->GetSceneHandlerId() << '-' << pView->fViewId; 80 81 pView->fprotation_top = new G4OpenGLXmTopLevelShell (pView, 82 (char*)rot_Name.str().c_str()); 83 pView->fprotation_button_box = new G4OpenGLXmBox ("Rotation button box", True); 84 85 pView->fprotation_top->AddChild (pView->fprotation_button_box); 86 87 XtCallbackRec* rot_cb_list = new XtCallbackRec[2]; 88 rot_cb_list[0].callback = set_rot_subject_callback; 89 rot_cb_list[0].closure = pView; 90 rot_cb_list[1].callback = NULL; 91 92 pView->fprotation_button1 = new G4OpenGLXmRadioButton 93 ("Object", 94 rot_cb_list, 95 pView->GetViewParameters().GetLightsMoveWithCamera(), 96 0); 97 98 pView->fprotation_button2 = new G4OpenGLXmRadioButton 99 ("Camera", 100 rot_cb_list, 101 !(pView->GetViewParameters().GetLightsMoveWithCamera()), 102 1); 103 104 pView->fprotation_button_box->AddChild (pView->fprotation_button1); 105 pView->fprotation_button_box->AddChild (pView->fprotation_button2); 106 107 pView->fprotation_slider_box = new G4OpenGLXmBox ("Rotation slider box", False); 108 pView->fprotation_top->AddChild (pView->fprotation_slider_box); 109 110 XtCallbackRec* rot_slider_list = new XtCallbackRec[2]; 111 rot_slider_list[0].callback = set_rot_sens_callback; 112 rot_slider_list[0].closure = pView; 113 rot_slider_list[1].callback = NULL; 114 115 pView->fprotation_slider = new G4OpenGLXmSliderBar ("Rotation slider", 116 rot_slider_list, 117 True, 118 2, 119 pView->fRot_sens, 120 pView->rot_sens_limit, 121 0); 122 pView->fprotation_slider_box->AddChild (pView->fprotation_slider); 123 124 pView->fprotation_arrow_box = new G4OpenGLXmBox ("Rotation arrow box", False); 125 pView->fprotation_top->AddChild (pView->fprotation_arrow_box); 126 127 XtCallbackRec** rotation_callbacks = new XtCallbackRec*[4]; 128 for (G4int i = 0; i < 4; i++) { 129 rotation_callbacks[i] = new XtCallbackRec[2]; 130 } 131 rotation_callbacks[0][0].callback = phi_rotation_callback; 132 rotation_callbacks[0][0].closure = pView; 133 rotation_callbacks[0][1].callback = NULL; 134 135 rotation_callbacks[1][0].callback = phi_rotation_callback; 136 rotation_callbacks[1][0].closure = pView; 137 rotation_callbacks[1][1].callback = NULL; 138 139 rotation_callbacks[2][0].callback = theta_rotation_callback; 140 rotation_callbacks[2][0].closure = pView; 141 rotation_callbacks[2][1].callback = NULL; 142 143 rotation_callbacks[3][0].callback = theta_rotation_callback; 144 rotation_callbacks[3][0].closure = pView; 145 rotation_callbacks[3][1].callback = NULL; 146 147 pView->fprotation_arrow = new G4OpenGLXmFourArrowButtons (rotation_callbacks); 148 149 pView->fprotation_arrow_box->AddChild (pView->fprotation_arrow); 150 151 pView->fprotation_top->Realize (); 152 } 153 break; 154 155 } 156 157 158 case 1: 159 { 160 if (!pView->GetSceneHandler()->GetScene()) { 161 break; 162 } 163 if (!pView->fppanning_top) { 164 std::ostringstream pan_Name; 165 pan_Name << pView->GetSceneHandler()->GetSceneHandlerId() << '-' << pView->fViewId; 166 167 pView->fppanning_top = new G4OpenGLXmTopLevelShell (pView, 168 (char*)pan_Name.str().c_str()); 169 170 pView->fppanning_box = new G4OpenGLXmFramedBox ("Pan up-down-left-right", 171 False); 172 173 pView->fppanning_top->AddChild (pView->fppanning_box); 174 175 XtCallbackRec** pan_callbacks = new XtCallbackRec*[4]; 176 for (G4int i = 0; i < 4; i++) { 177 pan_callbacks[i] = new XtCallbackRec[2]; 178 } 179 pan_callbacks[0][0].callback = pan_up_down_callback; 180 pan_callbacks[0][0].closure = pView; 181 pan_callbacks[0][1].callback = NULL; 182 183 pan_callbacks[1][0].callback = pan_up_down_callback; 184 pan_callbacks[1][0].closure = pView; 185 pan_callbacks[1][1].callback = NULL; 186 187 pan_callbacks[2][0].callback = pan_left_right_callback; 188 pan_callbacks[2][0].closure = pView; 189 pan_callbacks[2][1].callback = NULL; 190 191 pan_callbacks[3][0].callback = pan_left_right_callback; 192 pan_callbacks[3][0].closure = pView; 193 pan_callbacks[3][1].callback = NULL; 194 195 pView->fppanning_arrows = new G4OpenGLXmFourArrowButtons (pan_callbacks); 196 197 pView->fppanning_box->AddChild (pView->fppanning_arrows); 198 199 XtCallbackRec* pan_slider_list = new XtCallbackRec[2]; 200 pan_slider_list[0].callback = set_pan_sens_callback; 201 pan_slider_list[0].closure = pView; 202 pan_slider_list[1].callback = NULL; 203 204 pView->fppanning_slider = new G4OpenGLXmSliderBar ("Panning slider", 205 pan_slider_list, 206 True, 207 2, 208 pView->fPan_sens = pView->GetSceneHandler()->GetScene()->GetExtent().GetExtentRadius() / 10.0, 209 pView->pan_sens_limit = pView->GetSceneHandler()->GetScene()->GetExtent().GetExtentRadius(), 210 0); 211 pView->fppanning_box->AddChild (pView->fppanning_slider); 212 213 pView->fpzoom_box = new G4OpenGLXmFramedBox ("Zoom", 214 False); 215 pView->fppanning_top->AddChild (pView->fpzoom_box); 216 217 XtCallbackRec* zoom_slider_list = new XtCallbackRec[2]; 218 zoom_slider_list[0].callback = zoom_callback; 219 zoom_slider_list[0].closure = pView; 220 zoom_slider_list[1].callback = NULL; 221 222 pView->fpzoom_slider = new G4OpenGLXmSliderBar ("Zoom slider", 223 zoom_slider_list, 224 True, 225 2, 226 pView->fVP.GetZoomFactor(), 227 pView->zoom_high, 228 pView->zoom_low); 229 pView->fpzoom_box->AddChild (pView->fpzoom_slider); 230 231 pView->fpdolly_box = new G4OpenGLXmFramedBox ("Dolly", 232 False); 233 pView->fppanning_top->AddChild (pView->fpdolly_box); 234 235 XtCallbackRec* dolly_slider_list = new XtCallbackRec[2]; 236 dolly_slider_list[0].callback = dolly_callback; 237 dolly_slider_list[0].closure = pView; 238 dolly_slider_list[1].callback = NULL; 239 240 pView->fpdolly_slider = new G4OpenGLXmSliderBar ("Dolly slider", 241 dolly_slider_list, 242 True, 243 2, 244 pView->fVP.GetDolly(), 245 pView->dolly_high = pView->GetSceneHandler()->GetScene()->GetExtent().GetExtentRadius(), 246 pView->dolly_low = -(pView->GetSceneHandler()->GetScene()->GetExtent().GetExtentRadius())); 247 // pView->dolly_high, 248 // pView->dolly_low); 249 pView->fpdolly_box->AddChild (pView->fpdolly_slider); 250 251 pView->fppanning_top->Realize (); 252 pView->UpdateControlPanel (); 253 } 254 255 break; 256 257 } 258 case 2: 259 { 260 261 if (!pView->fpsetting_top) { 262 std::ostringstream set_Name; 263 set_Name << pView->GetSceneHandler()->GetSceneHandlerId() << '-' << pView->fViewId; 264 265 pView->fpsetting_top = new G4OpenGLXmTopLevelShell(pView, 266 (char*)set_Name.str().c_str()); 267 268 pView->fpsetting_box = new G4OpenGLXmFramedBox ("Set values for control panels", 269 False); 270 pView->fpsetting_top->AddChild (pView->fpsetting_box); 271 272 pView->fppan_set = new G4OpenGLXmTextField ("Upper limit of pan sensitivity", 273 &(pView->pan_sens_limit)); 274 275 pView->fprot_set = new G4OpenGLXmTextField ("Upper limit of rotation sensitivity", 276 &(pView->rot_sens_limit)); 277 278 pView->fpzoom_upper = new G4OpenGLXmTextField ("Upper limit of zoom", 279 &(pView->zoom_high)); 280 281 pView->fpzoom_lower = new G4OpenGLXmTextField ("Lower limit of zoom", 282 &(pView->zoom_low)); 283 284 pView->fpdolly_upper = new G4OpenGLXmTextField ("Upper limit of dolly", 285 &(pView->dolly_high)); 286 287 pView->fpdolly_lower = new G4OpenGLXmTextField ("Lower limit of dolly", 288 &(pView->dolly_low)); 289 290 XtCallbackRec* ok_list = new XtCallbackRec[2]; 291 ok_list[0].callback = update_panels_callback; 292 ok_list[0].closure = pView; 293 ok_list[1].callback = NULL; 294 295 296 pView->fpok_button = new G4OpenGLXmPushButton ("ok", 297 ok_list); 298 299 pView->fpsetting_box->AddChild (pView->fppan_set); 300 pView->fpsetting_box->AddChild (pView->fprot_set); 301 pView->fpsetting_box->AddChild (pView->fpzoom_upper); 302 pView->fpsetting_box->AddChild (pView->fpzoom_lower); 303 pView->fpsetting_box->AddChild (pView->fpdolly_upper); 304 pView->fpsetting_box->AddChild (pView->fpdolly_lower); 305 pView->fpsetting_box->AddChild (pView->fpok_button); 306 307 pView->fpsetting_top->Realize (); 308 309 } 310 311 break; 312 } 313 314 default: 315 G4Exception 316 ("G4OpenGLXmViewer::actions_callback", 317 "opengl2001", FatalException, 318 "Unrecognised widget child of control_callback"); 319 } 320 321 return; 322 } 323 324 325 326 void G4OpenGLXmViewer::misc_callback (Widget w, 327 XtPointer clientData, 328 XtPointer) 329 { 330 G4OpenGLXmViewer* pView; 331 G4long choice = (G4long)clientData; 332 XtVaGetValues (XtParent(w), 333 XmNuserData, &pView, 334 NULL); 335 336 switch (choice) { 337 338 case 0: 339 { 340 341 if (!pView->fpmiscellany_top) { 342 343 std::ostringstream misc_Name; 344 misc_Name << pView->GetSceneHandler()->GetSceneHandlerId() << '-' << pView->fViewId; 345 346 pView->fpmiscellany_top = new G4OpenGLXmTopLevelShell (pView, 347 (char*)misc_Name.str().c_str()); 348 pView->fpwobble_box = new G4OpenGLXmFramedBox ("Wobble view", 349 True); 350 pView->fpmiscellany_top->AddChild (pView->fpwobble_box); 351 352 XtCallbackRec* wob_cb_list = new XtCallbackRec[2]; 353 wob_cb_list[0].callback = wobble_callback; 354 wob_cb_list[0].closure = pView; 355 wob_cb_list[1].callback = NULL; 356 357 358 pView->fpwobble_button = new G4OpenGLXmPushButton ("Wobble", 359 wob_cb_list); 360 361 XtCallbackRec* wobble_slider_list = new XtCallbackRec[2]; 362 wobble_slider_list[0].callback = set_wob_sens_callback; 363 wobble_slider_list[0].closure = pView; 364 wobble_slider_list[1].callback = NULL; 365 366 pView->fpwobble_slider = new G4OpenGLXmSliderBar ("Wobble slider", 367 wobble_slider_list, 368 True, 369 0, 370 pView->wob_sens, 371 pView->wob_high, 372 pView->wob_low); 373 pView->fpwobble_box->AddChild (pView->fpwobble_button); 374 pView->fpwobble_box->AddChild (pView->fpwobble_slider); 375 376 pView->fpreset_box = new G4OpenGLXmFramedBox ("Reset view", 377 True); 378 pView->fpmiscellany_top->AddChild (pView->fpreset_box); 379 380 XtCallbackRec* rst_cb_list = new XtCallbackRec[3]; 381 rst_cb_list[0].callback = reset_callback; 382 rst_cb_list[0].closure = pView; 383 rst_cb_list[1].callback = update_panels_callback; 384 rst_cb_list[1].closure = pView; 385 rst_cb_list[2].callback = NULL; 386 387 pView->fpreset_button = new G4OpenGLXmPushButton ("Reset", 388 rst_cb_list); 389 390 pView->fpreset_box->AddChild (pView->fpreset_button); 391 392 pView->fpproj_style_box = new G4OpenGLXmFramedBox ("Projection style", 393 True); 394 pView->fpmiscellany_top->AddChild (pView->fpproj_style_box); 395 396 XtCallbackRec* proj_cb_list = new XtCallbackRec[2]; 397 proj_cb_list[0].callback = projection_callback; 398 proj_cb_list[0].closure = pView; 399 proj_cb_list[1].callback = NULL; 400 401 pView->fporthogonal_button = new G4OpenGLXmRadioButton ("Orthographic", 402 proj_cb_list, 403 pView->fVP.GetFieldHalfAngle() > 0. ? False : True, 404 0); 405 406 pView->fpperspective_button = new G4OpenGLXmRadioButton ("Perspective", 407 proj_cb_list, 408 pView->fVP.GetFieldHalfAngle() > 0. ? True : False, 409 1); 410 411 pView->fpfov_text = new G4OpenGLXmTextField ("Field of view 0.1 -> 89.5 degrees.", 412 &(pView->fov)); 413 414 pView->fpproj_style_box->AddChild (pView->fpperspective_button); 415 pView->fpproj_style_box->AddChild (pView->fporthogonal_button); 416 pView->fpproj_style_box->AddChild (pView->fpfov_text); 417 418 pView->fpmiscellany_top->Realize (); 419 420 } 421 422 break; 423 } 424 425 case 1: 426 { 427 G4Xt::getInstance () -> RequireExitSecondaryLoop (OGL_EXIT_CODE); 428 break; 429 } 430 431 case 2: 432 { 433 if (!pView->fpprint_top) { 434 435 std::ostringstream print_Name; 436 print_Name << pView->GetSceneHandler()->GetSceneHandlerId() << '-' << pView->fViewId; 437 438 pView->fpprint_top = new G4OpenGLXmTopLevelShell (pView, 439 (char*)print_Name.str().c_str()); 440 441 pView->fpprint_box = new G4OpenGLXmFramedBox ("Create EPS file of current view", 442 False); 443 444 pView->fpprint_top->AddChild (pView->fpprint_box); 445 446 pView->fpprint_col_box = new G4OpenGLXmFramedBox ("Colour choice", 447 True); 448 pView->fpprint_top->AddChild (pView->fpprint_col_box); 449 450 XtCallbackRec* prcol_cb_list = new XtCallbackRec[2]; 451 prcol_cb_list[0].callback = set_print_colour_callback; 452 prcol_cb_list[0].closure = pView; 453 prcol_cb_list[1].callback = NULL; 454 455 pView->fpprint_col_radio1 = new G4OpenGLXmRadioButton ("Black and white", 456 prcol_cb_list, 457 pView->fPrintColour==false ? True : False, 458 0); 459 460 pView->fpprint_col_radio2 = new G4OpenGLXmRadioButton ("Colour", 461 prcol_cb_list, 462 pView->fPrintColour==true ? True : False, 463 1); 464 465 pView->fpprint_col_box->AddChild (pView->fpprint_col_radio1); 466 pView->fpprint_col_box->AddChild (pView->fpprint_col_radio2); 467 468 pView->fpprint_style_box = new G4OpenGLXmFramedBox ("File type", 469 True); 470 pView->fpprint_top->AddChild (pView->fpprint_style_box); 471 472 XtCallbackRec* prsty_cb_list = new XtCallbackRec[2]; 473 prsty_cb_list[0].callback = set_print_style_callback; 474 prsty_cb_list[0].closure = pView; 475 prsty_cb_list[1].callback = NULL; 476 477 pView->fpprint_style_radio1 = new G4OpenGLXmRadioButton ("Screen dump (pixmap)", 478 prsty_cb_list, 479 pView->fVectoredPs==false ? True : False, 480 0); 481 482 pView->fpprint_style_radio2 = new G4OpenGLXmRadioButton ("PostScript", 483 prsty_cb_list, 484 pView->fVectoredPs==true ? True : False, 485 1); 486 487 pView->fpprint_style_box->AddChild (pView->fpprint_style_radio1); 488 pView->fpprint_style_box->AddChild (pView->fpprint_style_radio2); 489 490 pView->fpprint_text = new G4OpenGLXmTextField ("Name of .eps file to save", 491 (pView->getRealPrintFilename().c_str())); 492 pView->fpprint_box->AddChild (pView->fpprint_text); 493 494 pView->fpprint_line = new G4OpenGLXmSeparator (); 495 pView->fpprint_box->AddChild (pView->fpprint_line); 496 497 XtCallbackRec* pri_cb_list = new XtCallbackRec[2]; 498 pri_cb_list[0].callback = print_callback; 499 pri_cb_list[0].closure = pView; 500 pri_cb_list[1].callback = NULL; 501 502 503 pView->fpprint_button = new G4OpenGLXmPushButton ("Create EPS file", 504 pri_cb_list); 505 506 pView->fpprint_box->AddChild (pView->fpprint_button); 507 pView->fpprint_top->Realize (); 508 509 } 510 511 ///ajw 512 break; 513 } 514 515 default: 516 G4Exception 517 ("G4OpenGLXmViewer::misc_callback", 518 "opengl2002", FatalException, 519 "Unrecognised widget child of misc_callback."); 520 } 521 522 return; 523 524 } 525 526 void G4OpenGLXmViewer::set_wob_sens_callback (Widget w, 527 XtPointer clientData, 528 XtPointer callData) 529 { 530 XmScaleCallbackStruct *cbs = (XmScaleCallbackStruct*) callData; 531 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData; 532 short dp = -1; 533 G4float ten_to_the_dp = 10.; 534 535 XtVaGetValues (w, 536 XmNdecimalPoints, &dp, 537 NULL); 538 539 if (dp == 0) { 540 ten_to_the_dp = 1.; 541 } else if ( dp > 0) { 542 for (G4int i = 1; i < (G4int)dp; i++) { 543 ten_to_the_dp *= 10.; 544 } 545 } else { 546 G4Exception 547 ("G4OpenGLXmViewer::set_wob_sens_callback", 548 "opengl2003", FatalException, 549 "Bad value returned for dp in set_rot_sens_callback"); 550 } 551 552 pView->wob_sens = (G4float)(cbs->value) / ten_to_the_dp; 553 } 554 555 void G4OpenGLXmViewer::update_panels_callback (Widget, 556 XtPointer clientData, 557 XtPointer) 558 { 559 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData; 560 561 if (pView->fppanning_slider) { 562 pView->fppanning_slider->SetMaxValue (pView->pan_sens_limit); 563 } 564 if (pView->fprotation_slider) { 565 pView->fprotation_slider->SetMaxValue (pView->rot_sens_limit); 566 } 567 568 if (pView->fpzoom_slider) { 569 pView->fpzoom_slider->SetMaxValue (pView->zoom_high); 570 pView->fpzoom_slider->SetMinValue (pView->zoom_low); 571 pView->fpzoom_slider->SetInitialValue (pView->fVP.GetZoomFactor()); 572 } 573 574 if (pView->fpdolly_slider) { 575 pView->fpdolly_slider->SetMaxValue (pView->dolly_high); 576 pView->fpdolly_slider->SetMinValue (pView->dolly_low); 577 } 578 } 579