Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // 26 // 27 // 27 // 28 // 28 // 29 // Andrew Walkden 16th April 1997 29 // Andrew Walkden 16th April 1997 30 // G4OpenGLXmPanningCallbacks : 30 // G4OpenGLXmPanningCallbacks : 31 // Several callback func 31 // Several callback functions used by 32 // elements of the contr 32 // elements of the control panel to`pan' 33 // the view (i.e. move t 33 // the view (i.e. move the viewpoint and 34 // camera positions by e 34 // camera positions by equal amounts). 35 // Zoom callback is also 35 // Zoom callback is also here. 36 36 >> 37 #ifdef G4VIS_BUILD_OPENGLXM_DRIVER >> 38 37 #include "G4OpenGLXmViewer.hh" 39 #include "G4OpenGLXmViewer.hh" 38 #include "G4VSceneHandler.hh" 40 #include "G4VSceneHandler.hh" 39 #include <Xm/ToggleB.h> 41 #include <Xm/ToggleB.h> 40 42 41 #include "G4Scene.hh" 43 #include "G4Scene.hh" 42 44 43 void G4OpenGLXmViewer::zoom_callback (Widget w 45 void G4OpenGLXmViewer::zoom_callback (Widget w, 44 XtPointer clientData, 46 XtPointer clientData, 45 XtPointer callData) 47 XtPointer callData) 46 { 48 { 47 XmScaleCallbackStruct *cbs = (XmScaleCallbac 49 XmScaleCallbackStruct *cbs = (XmScaleCallbackStruct*) callData; 48 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer* 50 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData; 49 short dp = -1; 51 short dp = -1; 50 G4float ten_to_the_dp = 10.; 52 G4float ten_to_the_dp = 10.; 51 53 52 XtVaGetValues (w, 54 XtVaGetValues (w, 53 XmNdecimalPoints, &dp, 55 XmNdecimalPoints, &dp, 54 NULL); 56 NULL); 55 57 56 if (dp == 0) { 58 if (dp == 0) { 57 ten_to_the_dp = 1.; 59 ten_to_the_dp = 1.; 58 } else if ( dp > 0) { 60 } else if ( dp > 0) { 59 for (G4int i = 1; i < (G4int)dp; i++) { 61 for (G4int i = 1; i < (G4int)dp; i++) { 60 ten_to_the_dp *= 10.; 62 ten_to_the_dp *= 10.; 61 } 63 } 62 } else { 64 } else { 63 G4cout << "dp is " << dp << G4endl; 65 G4cout << "dp is " << dp << G4endl; 64 return; 66 return; 65 } 67 } 66 68 67 69 68 G4double zoomBy = (G4double)(cbs->value) / t 70 G4double zoomBy = (G4double)(cbs->value) / ten_to_the_dp; 69 if (zoomBy <= 0.01) { 71 if (zoomBy <= 0.01) { 70 zoomBy = 0.01; 72 zoomBy = 0.01; 71 } 73 } 72 74 73 pView->fVP.SetZoomFactor (zoomBy); 75 pView->fVP.SetZoomFactor (zoomBy); 74 pView->SetView (); 76 pView->SetView (); 75 pView->ClearView (); 77 pView->ClearView (); 76 pView -> DrawView (); 78 pView -> DrawView (); 77 } 79 } 78 80 79 void G4OpenGLXmViewer::dolly_callback (Widget 81 void G4OpenGLXmViewer::dolly_callback (Widget w, 80 XtPointer clientData, 82 XtPointer clientData, 81 XtPointer callData) 83 XtPointer callData) 82 { 84 { 83 XmScaleCallbackStruct *cbs = (XmScaleCallbac 85 XmScaleCallbackStruct *cbs = (XmScaleCallbackStruct*) callData; 84 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer* 86 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData; 85 short dp = -1; 87 short dp = -1; 86 G4float ten_to_the_dp = 10.; 88 G4float ten_to_the_dp = 10.; 87 89 88 XtVaGetValues (w, 90 XtVaGetValues (w, 89 XmNdecimalPoints, &dp, 91 XmNdecimalPoints, &dp, 90 NULL); 92 NULL); 91 93 92 if (dp == 0) { 94 if (dp == 0) { 93 ten_to_the_dp = 1.; 95 ten_to_the_dp = 1.; 94 } else if ( dp > 0) { 96 } else if ( dp > 0) { 95 for (G4int i = 1; i < (G4int)dp; i++) { 97 for (G4int i = 1; i < (G4int)dp; i++) { 96 ten_to_the_dp *= 10.; 98 ten_to_the_dp *= 10.; 97 } 99 } 98 } else { 100 } else { 99 G4cout << "dp is " << dp << G4endl; 101 G4cout << "dp is " << dp << G4endl; 100 return; 102 return; 101 } 103 } 102 104 103 G4double dolly = (G4double)(cbs->value) / te 105 G4double dolly = (G4double)(cbs->value) / ten_to_the_dp; 104 106 105 pView->fVP.SetDolly (dolly); 107 pView->fVP.SetDolly (dolly); 106 pView->SetView (); 108 pView->SetView (); 107 pView->ClearView (); 109 pView->ClearView (); 108 pView->DrawView (); 110 pView->DrawView (); 109 111 110 } 112 } 111 113 112 void G4OpenGLXmViewer::pan_left_right_callback 114 void G4OpenGLXmViewer::pan_left_right_callback (Widget w, 113 XtPointer clientData, 115 XtPointer clientData, 114 XtPointer callData) 116 XtPointer callData) 115 { 117 { 116 XmArrowButtonCallbackStruct *cbs = (XmArrowB 118 XmArrowButtonCallbackStruct *cbs = (XmArrowButtonCallbackStruct*) callData; 117 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer* 119 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData; 118 120 119 pView->pan_right = get_boolean_userData (w); 121 pView->pan_right = get_boolean_userData (w); 120 122 121 if (cbs->reason == XmCR_ARM) { 123 if (cbs->reason == XmCR_ARM) { 122 left_right_pan_callback (pView,NULL); 124 left_right_pan_callback (pView,NULL); 123 } else if (cbs->reason == XmCR_DISARM) { 125 } else if (cbs->reason == XmCR_DISARM) { 124 XtRemoveTimeOut (pView->pan_timer); 126 XtRemoveTimeOut (pView->pan_timer); 125 } 127 } 126 } 128 } 127 129 128 void G4OpenGLXmViewer::left_right_pan_callback 130 void G4OpenGLXmViewer::left_right_pan_callback (XtPointer clientData, 129 XtIntervalId* timer_id) 131 XtIntervalId* timer_id) 130 132 131 { 133 { 132 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer* 134 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData; 133 G4double delta; 135 G4double delta; 134 136 135 if (pView->pan_right) { 137 if (pView->pan_right) { 136 delta = pView->fPan_sens; 138 delta = pView->fPan_sens; 137 } else { 139 } else { 138 delta = -pView->fPan_sens; 140 delta = -pView->fPan_sens; 139 } 141 } 140 142 141 G4Point3D stp 143 G4Point3D stp 142 = pView -> GetSceneHandler()->GetScene()-> 144 = pView -> GetSceneHandler()->GetScene()->GetStandardTargetPoint(); 143 145 144 G4Point3D tp = stp + pView -> fVP.GetCurrent 146 G4Point3D tp = stp + pView -> fVP.GetCurrentTargetPoint (); 145 147 146 const G4Vector3D& upVector = pView->fVP.GetU 148 const G4Vector3D& upVector = pView->fVP.GetUpVector (); 147 const G4Vector3D& vpVector = pView->fVP.GetV 149 const G4Vector3D& vpVector = pView->fVP.GetViewpointDirection (); 148 150 149 G4Vector3D unitRight = (upVector.cross (vpVe 151 G4Vector3D unitRight = (upVector.cross (vpVector)).unit(); 150 G4Vector3D unitUp = (vpVector.cross (unit 152 G4Vector3D unitUp = (vpVector.cross (unitRight)).unit(); 151 153 152 tp += delta * unitRight; 154 tp += delta * unitRight; 153 pView->fVP.SetCurrentTargetPoint (tp - stp); 155 pView->fVP.SetCurrentTargetPoint (tp - stp); 154 156 155 pView->SetView (); 157 pView->SetView (); 156 pView->ClearView (); 158 pView->ClearView (); 157 pView->DrawView (); 159 pView->DrawView (); 158 160 159 pView->pan_timer = XtAppAddTimeOut 161 pView->pan_timer = XtAppAddTimeOut 160 (pView->app, 162 (pView->app, 161 timer_id == NULL ? 500 : 1, 163 timer_id == NULL ? 500 : 1, 162 left_right_pan_callback, 164 left_right_pan_callback, 163 pView); 165 pView); 164 } 166 } 165 167 166 void G4OpenGLXmViewer::pan_up_down_callback (W 168 void G4OpenGLXmViewer::pan_up_down_callback (Widget w, 167 XtPointer clientData, 169 XtPointer clientData, 168 XtPointer callData) 170 XtPointer callData) 169 { 171 { 170 XmArrowButtonCallbackStruct *cbs = (XmArrowB 172 XmArrowButtonCallbackStruct *cbs = (XmArrowButtonCallbackStruct*) callData; 171 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer* 173 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData; 172 174 173 pView->pan_up = get_boolean_userData (w); 175 pView->pan_up = get_boolean_userData (w); 174 176 175 if (cbs->reason == XmCR_ARM) { 177 if (cbs->reason == XmCR_ARM) { 176 up_down_pan_callback (pView,NULL); 178 up_down_pan_callback (pView,NULL); 177 } else if (cbs->reason == XmCR_DISARM) { 179 } else if (cbs->reason == XmCR_DISARM) { 178 XtRemoveTimeOut (pView->pan_timer); 180 XtRemoveTimeOut (pView->pan_timer); 179 } 181 } 180 } 182 } 181 183 182 void G4OpenGLXmViewer::up_down_pan_callback (X 184 void G4OpenGLXmViewer::up_down_pan_callback (XtPointer clientData, 183 XtIntervalId* timer_id) 185 XtIntervalId* timer_id) 184 { 186 { 185 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer* 187 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData; 186 G4double delta; 188 G4double delta; 187 189 188 if (pView->pan_up) { 190 if (pView->pan_up) { 189 delta = pView->fPan_sens; 191 delta = pView->fPan_sens; 190 } else { 192 } else { 191 delta = -(pView->fPan_sens); 193 delta = -(pView->fPan_sens); 192 } 194 } 193 195 194 G4Point3D stp 196 G4Point3D stp 195 = pView -> GetSceneHandler()->GetScene()-> 197 = pView -> GetSceneHandler()->GetScene()->GetStandardTargetPoint(); 196 G4Point3D tp = stp + pView -> fVP.GetCurrent 198 G4Point3D tp = stp + pView -> fVP.GetCurrentTargetPoint (); 197 const G4Vector3D& upVector = pView->fVP.GetU 199 const G4Vector3D& upVector = pView->fVP.GetUpVector (); 198 const G4Vector3D& vpVector = pView->fVP.GetV 200 const G4Vector3D& vpVector = pView->fVP.GetViewpointDirection (); 199 201 200 G4Vector3D unitRight = (upVector.cross (vpVe 202 G4Vector3D unitRight = (upVector.cross (vpVector)).unit(); 201 G4Vector3D unitUp = (vpVector.cross (unit 203 G4Vector3D unitUp = (vpVector.cross (unitRight)).unit(); 202 tp += delta * unitUp; 204 tp += delta * unitUp; 203 pView->fVP.SetCurrentTargetPoint (tp - stp); 205 pView->fVP.SetCurrentTargetPoint (tp - stp); 204 206 205 pView->SetView (); 207 pView->SetView (); 206 pView->ClearView (); 208 pView->ClearView (); 207 pView->DrawView (); 209 pView->DrawView (); 208 210 209 pView->pan_timer = XtAppAddTimeOut 211 pView->pan_timer = XtAppAddTimeOut 210 (pView->app, 212 (pView->app, 211 timer_id == NULL ? 500 : 1, 213 timer_id == NULL ? 500 : 1, 212 up_down_pan_callback, 214 up_down_pan_callback, 213 pView); 215 pView); 214 } 216 } 215 217 216 void G4OpenGLXmViewer::set_pan_sens_callback ( 218 void G4OpenGLXmViewer::set_pan_sens_callback (Widget w, 217 XtPointer clientData, 219 XtPointer clientData, 218 XtPointer callData) 220 XtPointer callData) 219 { 221 { 220 XmScaleCallbackStruct *cbs = (XmScaleCallbac 222 XmScaleCallbackStruct *cbs = (XmScaleCallbackStruct*) callData; 221 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer* 223 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData; 222 short dp = -1; 224 short dp = -1; 223 G4float ten_to_the_dp = 10.; 225 G4float ten_to_the_dp = 10.; 224 226 225 XtVaGetValues (w, 227 XtVaGetValues (w, 226 XmNdecimalPoints, &dp, 228 XmNdecimalPoints, &dp, 227 NULL); 229 NULL); 228 230 229 if (dp == 0) { 231 if (dp == 0) { 230 ten_to_the_dp = 1.; 232 ten_to_the_dp = 1.; 231 } else if ( dp > 0) { 233 } else if ( dp > 0) { 232 for (G4int i = 1; i < (G4int)dp; i++) { 234 for (G4int i = 1; i < (G4int)dp; i++) { 233 ten_to_the_dp *= 10.; 235 ten_to_the_dp *= 10.; 234 } 236 } 235 } else { 237 } else { 236 G4cout << "dp is " << dp << G4endl; 238 G4cout << "dp is " << dp << G4endl; 237 return; 239 return; 238 } 240 } 239 241 240 pView->fPan_sens = (G4double)((cbs->value) / 242 pView->fPan_sens = (G4double)((cbs->value) / ten_to_the_dp); 241 } 243 } >> 244 >> 245 #endif >> 246 >> 247 242 248