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 // $Id$ 27 // 28 // 28 // 29 // 29 // Andrew Walkden 16th April 1997 30 // Andrew Walkden 16th April 1997 30 // G4OpenGLXmPanningCallbacks : 31 // G4OpenGLXmPanningCallbacks : 31 // Several callback func 32 // Several callback functions used by 32 // elements of the contr 33 // elements of the control panel to`pan' 33 // the view (i.e. move t 34 // the view (i.e. move the viewpoint and 34 // camera positions by e 35 // camera positions by equal amounts). 35 // Zoom callback is also 36 // Zoom callback is also here. 36 37 >> 38 #ifdef G4VIS_BUILD_OPENGLXM_DRIVER >> 39 37 #include "G4OpenGLXmViewer.hh" 40 #include "G4OpenGLXmViewer.hh" 38 #include "G4VSceneHandler.hh" 41 #include "G4VSceneHandler.hh" 39 #include <Xm/ToggleB.h> 42 #include <Xm/ToggleB.h> 40 43 41 #include "G4Scene.hh" 44 #include "G4Scene.hh" 42 45 43 void G4OpenGLXmViewer::zoom_callback (Widget w 46 void G4OpenGLXmViewer::zoom_callback (Widget w, 44 XtPointer clientData, 47 XtPointer clientData, 45 XtPointer callData) 48 XtPointer callData) 46 { 49 { 47 XmScaleCallbackStruct *cbs = (XmScaleCallbac 50 XmScaleCallbackStruct *cbs = (XmScaleCallbackStruct*) callData; 48 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer* 51 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData; 49 short dp = -1; 52 short dp = -1; 50 G4float ten_to_the_dp = 10.; 53 G4float ten_to_the_dp = 10.; 51 54 52 XtVaGetValues (w, 55 XtVaGetValues (w, 53 XmNdecimalPoints, &dp, 56 XmNdecimalPoints, &dp, 54 NULL); 57 NULL); 55 58 56 if (dp == 0) { 59 if (dp == 0) { 57 ten_to_the_dp = 1.; 60 ten_to_the_dp = 1.; 58 } else if ( dp > 0) { 61 } else if ( dp > 0) { 59 for (G4int i = 1; i < (G4int)dp; i++) { 62 for (G4int i = 1; i < (G4int)dp; i++) { 60 ten_to_the_dp *= 10.; 63 ten_to_the_dp *= 10.; 61 } 64 } 62 } else { 65 } else { 63 G4cout << "dp is " << dp << G4endl; 66 G4cout << "dp is " << dp << G4endl; 64 return; 67 return; 65 } 68 } 66 69 67 70 68 G4double zoomBy = (G4double)(cbs->value) / t 71 G4double zoomBy = (G4double)(cbs->value) / ten_to_the_dp; 69 if (zoomBy <= 0.01) { 72 if (zoomBy <= 0.01) { 70 zoomBy = 0.01; 73 zoomBy = 0.01; 71 } 74 } 72 75 73 pView->fVP.SetZoomFactor (zoomBy); 76 pView->fVP.SetZoomFactor (zoomBy); 74 pView->SetView (); 77 pView->SetView (); 75 pView->ClearView (); 78 pView->ClearView (); 76 pView -> DrawView (); 79 pView -> DrawView (); 77 } 80 } 78 81 79 void G4OpenGLXmViewer::dolly_callback (Widget 82 void G4OpenGLXmViewer::dolly_callback (Widget w, 80 XtPointer clientData, 83 XtPointer clientData, 81 XtPointer callData) 84 XtPointer callData) 82 { 85 { 83 XmScaleCallbackStruct *cbs = (XmScaleCallbac 86 XmScaleCallbackStruct *cbs = (XmScaleCallbackStruct*) callData; 84 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer* 87 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData; 85 short dp = -1; 88 short dp = -1; 86 G4float ten_to_the_dp = 10.; 89 G4float ten_to_the_dp = 10.; 87 90 88 XtVaGetValues (w, 91 XtVaGetValues (w, 89 XmNdecimalPoints, &dp, 92 XmNdecimalPoints, &dp, 90 NULL); 93 NULL); 91 94 92 if (dp == 0) { 95 if (dp == 0) { 93 ten_to_the_dp = 1.; 96 ten_to_the_dp = 1.; 94 } else if ( dp > 0) { 97 } else if ( dp > 0) { 95 for (G4int i = 1; i < (G4int)dp; i++) { 98 for (G4int i = 1; i < (G4int)dp; i++) { 96 ten_to_the_dp *= 10.; 99 ten_to_the_dp *= 10.; 97 } 100 } 98 } else { 101 } else { 99 G4cout << "dp is " << dp << G4endl; 102 G4cout << "dp is " << dp << G4endl; 100 return; 103 return; 101 } 104 } 102 105 103 G4double dolly = (G4double)(cbs->value) / te 106 G4double dolly = (G4double)(cbs->value) / ten_to_the_dp; 104 107 105 pView->fVP.SetDolly (dolly); 108 pView->fVP.SetDolly (dolly); 106 pView->SetView (); 109 pView->SetView (); 107 pView->ClearView (); 110 pView->ClearView (); 108 pView->DrawView (); 111 pView->DrawView (); 109 112 110 } 113 } 111 114 112 void G4OpenGLXmViewer::pan_left_right_callback 115 void G4OpenGLXmViewer::pan_left_right_callback (Widget w, 113 XtPointer clientData, 116 XtPointer clientData, 114 XtPointer callData) 117 XtPointer callData) 115 { 118 { 116 XmArrowButtonCallbackStruct *cbs = (XmArrowB 119 XmArrowButtonCallbackStruct *cbs = (XmArrowButtonCallbackStruct*) callData; 117 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer* 120 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData; 118 121 119 pView->pan_right = get_boolean_userData (w); 122 pView->pan_right = get_boolean_userData (w); 120 123 121 if (cbs->reason == XmCR_ARM) { 124 if (cbs->reason == XmCR_ARM) { 122 left_right_pan_callback (pView,NULL); 125 left_right_pan_callback (pView,NULL); 123 } else if (cbs->reason == XmCR_DISARM) { 126 } else if (cbs->reason == XmCR_DISARM) { 124 XtRemoveTimeOut (pView->pan_timer); 127 XtRemoveTimeOut (pView->pan_timer); 125 } 128 } 126 } 129 } 127 130 128 void G4OpenGLXmViewer::left_right_pan_callback 131 void G4OpenGLXmViewer::left_right_pan_callback (XtPointer clientData, 129 XtIntervalId* timer_id) 132 XtIntervalId* timer_id) 130 133 131 { 134 { 132 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer* 135 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData; 133 G4double delta; 136 G4double delta; 134 137 135 if (pView->pan_right) { 138 if (pView->pan_right) { 136 delta = pView->fPan_sens; 139 delta = pView->fPan_sens; 137 } else { 140 } else { 138 delta = -pView->fPan_sens; 141 delta = -pView->fPan_sens; 139 } 142 } 140 143 141 G4Point3D stp 144 G4Point3D stp 142 = pView -> GetSceneHandler()->GetScene()-> 145 = pView -> GetSceneHandler()->GetScene()->GetStandardTargetPoint(); 143 146 144 G4Point3D tp = stp + pView -> fVP.GetCurrent 147 G4Point3D tp = stp + pView -> fVP.GetCurrentTargetPoint (); 145 148 146 const G4Vector3D& upVector = pView->fVP.GetU 149 const G4Vector3D& upVector = pView->fVP.GetUpVector (); 147 const G4Vector3D& vpVector = pView->fVP.GetV 150 const G4Vector3D& vpVector = pView->fVP.GetViewpointDirection (); 148 151 149 G4Vector3D unitRight = (upVector.cross (vpVe 152 G4Vector3D unitRight = (upVector.cross (vpVector)).unit(); 150 G4Vector3D unitUp = (vpVector.cross (unit 153 G4Vector3D unitUp = (vpVector.cross (unitRight)).unit(); 151 154 152 tp += delta * unitRight; 155 tp += delta * unitRight; 153 pView->fVP.SetCurrentTargetPoint (tp - stp); 156 pView->fVP.SetCurrentTargetPoint (tp - stp); 154 157 155 pView->SetView (); 158 pView->SetView (); 156 pView->ClearView (); 159 pView->ClearView (); 157 pView->DrawView (); 160 pView->DrawView (); 158 161 159 pView->pan_timer = XtAppAddTimeOut 162 pView->pan_timer = XtAppAddTimeOut 160 (pView->app, 163 (pView->app, 161 timer_id == NULL ? 500 : 1, 164 timer_id == NULL ? 500 : 1, 162 left_right_pan_callback, 165 left_right_pan_callback, 163 pView); 166 pView); 164 } 167 } 165 168 166 void G4OpenGLXmViewer::pan_up_down_callback (W 169 void G4OpenGLXmViewer::pan_up_down_callback (Widget w, 167 XtPointer clientData, 170 XtPointer clientData, 168 XtPointer callData) 171 XtPointer callData) 169 { 172 { 170 XmArrowButtonCallbackStruct *cbs = (XmArrowB 173 XmArrowButtonCallbackStruct *cbs = (XmArrowButtonCallbackStruct*) callData; 171 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer* 174 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData; 172 175 173 pView->pan_up = get_boolean_userData (w); 176 pView->pan_up = get_boolean_userData (w); 174 177 175 if (cbs->reason == XmCR_ARM) { 178 if (cbs->reason == XmCR_ARM) { 176 up_down_pan_callback (pView,NULL); 179 up_down_pan_callback (pView,NULL); 177 } else if (cbs->reason == XmCR_DISARM) { 180 } else if (cbs->reason == XmCR_DISARM) { 178 XtRemoveTimeOut (pView->pan_timer); 181 XtRemoveTimeOut (pView->pan_timer); 179 } 182 } 180 } 183 } 181 184 182 void G4OpenGLXmViewer::up_down_pan_callback (X 185 void G4OpenGLXmViewer::up_down_pan_callback (XtPointer clientData, 183 XtIntervalId* timer_id) 186 XtIntervalId* timer_id) 184 { 187 { 185 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer* 188 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData; 186 G4double delta; 189 G4double delta; 187 190 188 if (pView->pan_up) { 191 if (pView->pan_up) { 189 delta = pView->fPan_sens; 192 delta = pView->fPan_sens; 190 } else { 193 } else { 191 delta = -(pView->fPan_sens); 194 delta = -(pView->fPan_sens); 192 } 195 } 193 196 194 G4Point3D stp 197 G4Point3D stp 195 = pView -> GetSceneHandler()->GetScene()-> 198 = pView -> GetSceneHandler()->GetScene()->GetStandardTargetPoint(); 196 G4Point3D tp = stp + pView -> fVP.GetCurrent 199 G4Point3D tp = stp + pView -> fVP.GetCurrentTargetPoint (); 197 const G4Vector3D& upVector = pView->fVP.GetU 200 const G4Vector3D& upVector = pView->fVP.GetUpVector (); 198 const G4Vector3D& vpVector = pView->fVP.GetV 201 const G4Vector3D& vpVector = pView->fVP.GetViewpointDirection (); 199 202 200 G4Vector3D unitRight = (upVector.cross (vpVe 203 G4Vector3D unitRight = (upVector.cross (vpVector)).unit(); 201 G4Vector3D unitUp = (vpVector.cross (unit 204 G4Vector3D unitUp = (vpVector.cross (unitRight)).unit(); 202 tp += delta * unitUp; 205 tp += delta * unitUp; 203 pView->fVP.SetCurrentTargetPoint (tp - stp); 206 pView->fVP.SetCurrentTargetPoint (tp - stp); 204 207 205 pView->SetView (); 208 pView->SetView (); 206 pView->ClearView (); 209 pView->ClearView (); 207 pView->DrawView (); 210 pView->DrawView (); 208 211 209 pView->pan_timer = XtAppAddTimeOut 212 pView->pan_timer = XtAppAddTimeOut 210 (pView->app, 213 (pView->app, 211 timer_id == NULL ? 500 : 1, 214 timer_id == NULL ? 500 : 1, 212 up_down_pan_callback, 215 up_down_pan_callback, 213 pView); 216 pView); 214 } 217 } 215 218 216 void G4OpenGLXmViewer::set_pan_sens_callback ( 219 void G4OpenGLXmViewer::set_pan_sens_callback (Widget w, 217 XtPointer clientData, 220 XtPointer clientData, 218 XtPointer callData) 221 XtPointer callData) 219 { 222 { 220 XmScaleCallbackStruct *cbs = (XmScaleCallbac 223 XmScaleCallbackStruct *cbs = (XmScaleCallbackStruct*) callData; 221 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer* 224 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData; 222 short dp = -1; 225 short dp = -1; 223 G4float ten_to_the_dp = 10.; 226 G4float ten_to_the_dp = 10.; 224 227 225 XtVaGetValues (w, 228 XtVaGetValues (w, 226 XmNdecimalPoints, &dp, 229 XmNdecimalPoints, &dp, 227 NULL); 230 NULL); 228 231 229 if (dp == 0) { 232 if (dp == 0) { 230 ten_to_the_dp = 1.; 233 ten_to_the_dp = 1.; 231 } else if ( dp > 0) { 234 } else if ( dp > 0) { 232 for (G4int i = 1; i < (G4int)dp; i++) { 235 for (G4int i = 1; i < (G4int)dp; i++) { 233 ten_to_the_dp *= 10.; 236 ten_to_the_dp *= 10.; 234 } 237 } 235 } else { 238 } else { 236 G4cout << "dp is " << dp << G4endl; 239 G4cout << "dp is " << dp << G4endl; 237 return; 240 return; 238 } 241 } 239 242 240 pView->fPan_sens = (G4double)((cbs->value) / 243 pView->fPan_sens = (G4double)((cbs->value) / ten_to_the_dp); 241 } 244 } >> 245 >> 246 #endif >> 247 >> 248 242 249