G4OpenGLXmPanningCallbacks.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 //
00029 // 
00030 // Andrew Walkden  16th April 1997
00031 // G4OpenGLXmPanningCallbacks : 
00032 //                       Several callback functions used by
00033 //                       elements of the control panel to`pan' 
00034 //                       the view (i.e. move the viewpoint and 
00035 //                       camera positions by equal amounts).
00036 //                       Zoom callback is also here.
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 

Generated on Mon May 27 17:49:11 2013 for Geant4 by  doxygen 1.4.7