source: trunk/source/visualization/OpenGL/src/G4OpenGLXmPanningCallbacks.cc@ 1138

Last change on this file since 1138 was 1137, checked in by garnier, 16 years ago

en cours de debug

  • Property svn:mime-type set to text/cpp
File size: 7.6 KB
RevLine 
[529]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//
[1137]27// $Id: G4OpenGLXmPanningCallbacks.cc,v 1.11 2009/10/20 12:47:45 lgarnier Exp $
[911]28// GEANT4 tag $Name: $
[529]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"
[914]42#include "G4VSceneHandler.hh"
43#include <Xm/ToggleB.h>
44
[529]45#include "G4Scene.hh"
46
47void G4OpenGLXmViewer::zoom_callback (Widget w,
48 XtPointer clientData,
49 XtPointer callData)
50{
[1137]51
[529]52 XmScaleCallbackStruct *cbs = (XmScaleCallbackStruct*) callData;
53 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData;
54 short dp = -1;
55 G4float ten_to_the_dp = 10.;
56
[1137]57 // No callback allowed when no scene
58 if (!pView->GetSceneHandler()->GetScene()) {
59 return;
60 }
61
[529]62 XtVaGetValues (w,
63 XmNdecimalPoints, &dp,
64 NULL);
65
66 if (dp == 0) {
67 ten_to_the_dp = 1.;
68 } else if ( dp > 0) {
69 for (G4int i = 1; i < (G4int)dp; i++) {
70 ten_to_the_dp *= 10.;
71 }
72 } else {
73 G4cout << "dp is " << dp << G4endl;
74 return;
75 }
76
77
78 G4double zoomBy = (G4double)(cbs->value) / ten_to_the_dp;
79 if (zoomBy <= 0.01) {
80 zoomBy = 0.01;
81 }
82
83 pView->fVP.SetZoomFactor (zoomBy);
[1041]84 pView->SetView ();
85 pView->ClearView ();
86 pView -> DrawView ();
[529]87}
88
89void G4OpenGLXmViewer::dolly_callback (Widget w,
90 XtPointer clientData,
91 XtPointer callData)
92{
[1137]93
[529]94 XmScaleCallbackStruct *cbs = (XmScaleCallbackStruct*) callData;
95 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData;
96 short dp = -1;
97 G4float ten_to_the_dp = 10.;
98
[1137]99 // No callback allowed when no scene
100 if (!pView->GetSceneHandler()->GetScene()) {
101 return;
102 }
103
[529]104 XtVaGetValues (w,
105 XmNdecimalPoints, &dp,
106 NULL);
107
108 if (dp == 0) {
109 ten_to_the_dp = 1.;
110 } else if ( dp > 0) {
111 for (G4int i = 1; i < (G4int)dp; i++) {
112 ten_to_the_dp *= 10.;
113 }
114 } else {
115 G4cout << "dp is " << dp << G4endl;
116 return;
117 }
118
119 G4double dolly = (G4double)(cbs->value) / ten_to_the_dp;
120
121 pView->fVP.SetDolly (dolly);
[1041]122 pView->SetView ();
123 pView->ClearView ();
124 pView->DrawView ();
[529]125
126}
127
128void G4OpenGLXmViewer::pan_left_right_callback (Widget w,
129 XtPointer clientData,
130 XtPointer callData)
131{
132 XmArrowButtonCallbackStruct *cbs = (XmArrowButtonCallbackStruct*) callData;
133 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData;
134
135 pView->pan_right = get_boolean_userData (w);
136
137 if (cbs->reason == XmCR_ARM) {
138 left_right_pan_callback (pView,NULL);
139 } else if (cbs->reason == XmCR_DISARM) {
140 XtRemoveTimeOut (pView->pan_timer);
141 }
142}
143
144void G4OpenGLXmViewer::left_right_pan_callback (XtPointer clientData,
145 XtIntervalId* timer_id)
146
147{
[1137]148
[529]149 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData;
150 G4double delta;
151
[1137]152 // No callback allowed when no scene
153 if (!pView->GetSceneHandler()->GetScene()) {
154 return;
155 }
156
[529]157 if (pView->pan_right) {
158 delta = (G4double)pView->pan_sens;
159 } else {
160 delta = -((G4double)pView->pan_sens);
161 }
162
163 G4Point3D stp
164 = pView -> GetSceneHandler()->GetScene()->GetStandardTargetPoint();
165
166 G4Point3D tp = stp + pView -> fVP.GetCurrentTargetPoint ();
167
168 const G4Vector3D& upVector = pView->fVP.GetUpVector ();
169 const G4Vector3D& vpVector = pView->fVP.GetViewpointDirection ();
170
171 G4Vector3D unitRight = (upVector.cross (vpVector)).unit();
172 G4Vector3D unitUp = (vpVector.cross (unitRight)).unit();
173
174 tp += delta * unitRight;
175 pView->fVP.SetCurrentTargetPoint (tp - stp);
176
[1041]177 pView->SetView ();
178 pView->ClearView ();
179 pView->DrawView ();
[529]180
181 pView->pan_timer = XtAppAddTimeOut
182 (pView->app,
183 timer_id == NULL ? 500 : 1,
184 left_right_pan_callback,
185 pView);
186}
187
188void G4OpenGLXmViewer::pan_up_down_callback (Widget w,
189 XtPointer clientData,
190 XtPointer callData)
191{
192 XmArrowButtonCallbackStruct *cbs = (XmArrowButtonCallbackStruct*) callData;
193 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData;
194
195 pView->pan_up = get_boolean_userData (w);
196
197 if (cbs->reason == XmCR_ARM) {
198 up_down_pan_callback (pView,NULL);
199 } else if (cbs->reason == XmCR_DISARM) {
200 XtRemoveTimeOut (pView->pan_timer);
201 }
202}
203
204void G4OpenGLXmViewer::up_down_pan_callback (XtPointer clientData,
205 XtIntervalId* timer_id)
206{
[1137]207
[529]208 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData;
209 G4double delta;
210
[1137]211 // No callback allowed when no scene
212 if (!pView->GetSceneHandler()->GetScene()) {
213 return;
214 }
[529]215 if (pView->pan_up) {
216 delta = (G4double)pView->pan_sens;
217 } else {
218 delta = -((G4double)pView->pan_sens);
219 }
220
221 G4Point3D stp
222 = pView -> GetSceneHandler()->GetScene()->GetStandardTargetPoint();
223 G4Point3D tp = stp + pView -> fVP.GetCurrentTargetPoint ();
224 const G4Vector3D& upVector = pView->fVP.GetUpVector ();
225 const G4Vector3D& vpVector = pView->fVP.GetViewpointDirection ();
226
227 G4Vector3D unitRight = (upVector.cross (vpVector)).unit();
228 G4Vector3D unitUp = (vpVector.cross (unitRight)).unit();
229 tp += delta * unitUp;
230 pView->fVP.SetCurrentTargetPoint (tp - stp);
231
[1041]232 pView->SetView ();
233 pView->ClearView ();
234 pView->DrawView ();
[529]235
236 pView->pan_timer = XtAppAddTimeOut
237 (pView->app,
238 timer_id == NULL ? 500 : 1,
239 up_down_pan_callback,
240 pView);
241}
242
243void G4OpenGLXmViewer::set_pan_sens_callback (Widget w,
244 XtPointer clientData,
245 XtPointer callData)
246{
247 XmScaleCallbackStruct *cbs = (XmScaleCallbackStruct*) callData;
248 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData;
249 short dp = -1;
250 G4float ten_to_the_dp = 10.;
251
252 XtVaGetValues (w,
253 XmNdecimalPoints, &dp,
254 NULL);
255
256 if (dp == 0) {
257 ten_to_the_dp = 1.;
258 } else if ( dp > 0) {
259 for (G4int i = 1; i < (G4int)dp; i++) {
260 ten_to_the_dp *= 10.;
261 }
262 } else {
263 G4cout << "dp is " << dp << G4endl;
264 return;
265 }
266
267 pView->pan_sens = (G4double)((cbs->value) / ten_to_the_dp);
268}
269
270#endif
271
272
Note: See TracBrowser for help on using the repository browser.