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