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