00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifdef G4VIS_BUILD_OPENGLXM_DRIVER
00039
00040 #include "G4OpenGLXmViewer.hh"
00041 #include "G4VSceneHandler.hh"
00042 #include <Xm/ToggleB.h>
00043
00044 #include "G4Scene.hh"
00045
00046 void G4OpenGLXmViewer::zoom_callback (Widget w,
00047 XtPointer clientData,
00048 XtPointer callData)
00049 {
00050 XmScaleCallbackStruct *cbs = (XmScaleCallbackStruct*) callData;
00051 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData;
00052 short dp = -1;
00053 G4float ten_to_the_dp = 10.;
00054
00055 XtVaGetValues (w,
00056 XmNdecimalPoints, &dp,
00057 NULL);
00058
00059 if (dp == 0) {
00060 ten_to_the_dp = 1.;
00061 } else if ( dp > 0) {
00062 for (G4int i = 1; i < (G4int)dp; i++) {
00063 ten_to_the_dp *= 10.;
00064 }
00065 } else {
00066 G4cout << "dp is " << dp << G4endl;
00067 return;
00068 }
00069
00070
00071 G4double zoomBy = (G4double)(cbs->value) / ten_to_the_dp;
00072 if (zoomBy <= 0.01) {
00073 zoomBy = 0.01;
00074 }
00075
00076 pView->fVP.SetZoomFactor (zoomBy);
00077 pView->SetView ();
00078 pView->ClearView ();
00079 pView -> DrawView ();
00080 }
00081
00082 void G4OpenGLXmViewer::dolly_callback (Widget w,
00083 XtPointer clientData,
00084 XtPointer callData)
00085 {
00086 XmScaleCallbackStruct *cbs = (XmScaleCallbackStruct*) callData;
00087 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData;
00088 short dp = -1;
00089 G4float ten_to_the_dp = 10.;
00090
00091 XtVaGetValues (w,
00092 XmNdecimalPoints, &dp,
00093 NULL);
00094
00095 if (dp == 0) {
00096 ten_to_the_dp = 1.;
00097 } else if ( dp > 0) {
00098 for (G4int i = 1; i < (G4int)dp; i++) {
00099 ten_to_the_dp *= 10.;
00100 }
00101 } else {
00102 G4cout << "dp is " << dp << G4endl;
00103 return;
00104 }
00105
00106 G4double dolly = (G4double)(cbs->value) / ten_to_the_dp;
00107
00108 pView->fVP.SetDolly (dolly);
00109 pView->SetView ();
00110 pView->ClearView ();
00111 pView->DrawView ();
00112
00113 }
00114
00115 void G4OpenGLXmViewer::pan_left_right_callback (Widget w,
00116 XtPointer clientData,
00117 XtPointer callData)
00118 {
00119 XmArrowButtonCallbackStruct *cbs = (XmArrowButtonCallbackStruct*) callData;
00120 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData;
00121
00122 pView->pan_right = get_boolean_userData (w);
00123
00124 if (cbs->reason == XmCR_ARM) {
00125 left_right_pan_callback (pView,NULL);
00126 } else if (cbs->reason == XmCR_DISARM) {
00127 XtRemoveTimeOut (pView->pan_timer);
00128 }
00129 }
00130
00131 void G4OpenGLXmViewer::left_right_pan_callback (XtPointer clientData,
00132 XtIntervalId* timer_id)
00133
00134 {
00135 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData;
00136 G4double delta;
00137
00138 if (pView->pan_right) {
00139 delta = pView->fPan_sens;
00140 } else {
00141 delta = -pView->fPan_sens;
00142 }
00143
00144 G4Point3D stp
00145 = pView -> GetSceneHandler()->GetScene()->GetStandardTargetPoint();
00146
00147 G4Point3D tp = stp + pView -> fVP.GetCurrentTargetPoint ();
00148
00149 const G4Vector3D& upVector = pView->fVP.GetUpVector ();
00150 const G4Vector3D& vpVector = pView->fVP.GetViewpointDirection ();
00151
00152 G4Vector3D unitRight = (upVector.cross (vpVector)).unit();
00153 G4Vector3D unitUp = (vpVector.cross (unitRight)).unit();
00154
00155 tp += delta * unitRight;
00156 pView->fVP.SetCurrentTargetPoint (tp - stp);
00157
00158 pView->SetView ();
00159 pView->ClearView ();
00160 pView->DrawView ();
00161
00162 pView->pan_timer = XtAppAddTimeOut
00163 (pView->app,
00164 timer_id == NULL ? 500 : 1,
00165 left_right_pan_callback,
00166 pView);
00167 }
00168
00169 void G4OpenGLXmViewer::pan_up_down_callback (Widget w,
00170 XtPointer clientData,
00171 XtPointer callData)
00172 {
00173 XmArrowButtonCallbackStruct *cbs = (XmArrowButtonCallbackStruct*) callData;
00174 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData;
00175
00176 pView->pan_up = get_boolean_userData (w);
00177
00178 if (cbs->reason == XmCR_ARM) {
00179 up_down_pan_callback (pView,NULL);
00180 } else if (cbs->reason == XmCR_DISARM) {
00181 XtRemoveTimeOut (pView->pan_timer);
00182 }
00183 }
00184
00185 void G4OpenGLXmViewer::up_down_pan_callback (XtPointer clientData,
00186 XtIntervalId* timer_id)
00187 {
00188 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData;
00189 G4double delta;
00190
00191 if (pView->pan_up) {
00192 delta = pView->fPan_sens;
00193 } else {
00194 delta = -(pView->fPan_sens);
00195 }
00196
00197 G4Point3D stp
00198 = pView -> GetSceneHandler()->GetScene()->GetStandardTargetPoint();
00199 G4Point3D tp = stp + pView -> fVP.GetCurrentTargetPoint ();
00200 const G4Vector3D& upVector = pView->fVP.GetUpVector ();
00201 const G4Vector3D& vpVector = pView->fVP.GetViewpointDirection ();
00202
00203 G4Vector3D unitRight = (upVector.cross (vpVector)).unit();
00204 G4Vector3D unitUp = (vpVector.cross (unitRight)).unit();
00205 tp += delta * unitUp;
00206 pView->fVP.SetCurrentTargetPoint (tp - stp);
00207
00208 pView->SetView ();
00209 pView->ClearView ();
00210 pView->DrawView ();
00211
00212 pView->pan_timer = XtAppAddTimeOut
00213 (pView->app,
00214 timer_id == NULL ? 500 : 1,
00215 up_down_pan_callback,
00216 pView);
00217 }
00218
00219 void G4OpenGLXmViewer::set_pan_sens_callback (Widget w,
00220 XtPointer clientData,
00221 XtPointer callData)
00222 {
00223 XmScaleCallbackStruct *cbs = (XmScaleCallbackStruct*) callData;
00224 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData;
00225 short dp = -1;
00226 G4float ten_to_the_dp = 10.;
00227
00228 XtVaGetValues (w,
00229 XmNdecimalPoints, &dp,
00230 NULL);
00231
00232 if (dp == 0) {
00233 ten_to_the_dp = 1.;
00234 } else if ( dp > 0) {
00235 for (G4int i = 1; i < (G4int)dp; i++) {
00236 ten_to_the_dp *= 10.;
00237 }
00238 } else {
00239 G4cout << "dp is " << dp << G4endl;
00240 return;
00241 }
00242
00243 pView->fPan_sens = (G4double)((cbs->value) / ten_to_the_dp);
00244 }
00245
00246 #endif
00247
00248