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