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