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