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 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /visualization/OpenGL/src/G4OpenGLXmPanningCallbacks.cc (Version 11.3.0) and /visualization/OpenGL/src/G4OpenGLXmPanningCallbacks.cc (Version 9.4.p3)


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