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

Last change on this file since 1039 was 1038, checked in by garnier, 17 years ago

en test pour les refresh, ne marche pas bien

  • Property svn:mime-type set to text/cpp
File size: 7.0 KB
Line 
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.10 2009/02/04 16:48:41 lgarnier Exp $
28// GEANT4 tag $Name: $
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
47void 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->RepaintGLView ();
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->RepaintGLView ();
109
110}
111
112void G4OpenGLXmViewer::pan_left_right_callback (Widget w,
113 XtPointer clientData,
114 XtPointer callData)
115{
116 XmArrowButtonCallbackStruct *cbs = (XmArrowButtonCallbackStruct*) callData;
117 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData;
118
119 pView->pan_right = get_boolean_userData (w);
120
121 if (cbs->reason == XmCR_ARM) {
122 left_right_pan_callback (pView,NULL);
123 } else if (cbs->reason == XmCR_DISARM) {
124 XtRemoveTimeOut (pView->pan_timer);
125 }
126}
127
128void G4OpenGLXmViewer::left_right_pan_callback (XtPointer clientData,
129 XtIntervalId* timer_id)
130
131{
132 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData;
133 G4double delta;
134
135 if (pView->pan_right) {
136 delta = (G4double)pView->pan_sens;
137 } else {
138 delta = -((G4double)pView->pan_sens);
139 }
140
141 G4Point3D stp
142 = pView -> GetSceneHandler()->GetScene()->GetStandardTargetPoint();
143
144 G4Point3D tp = stp + pView -> fVP.GetCurrentTargetPoint ();
145
146 const G4Vector3D& upVector = pView->fVP.GetUpVector ();
147 const G4Vector3D& vpVector = pView->fVP.GetViewpointDirection ();
148
149 G4Vector3D unitRight = (upVector.cross (vpVector)).unit();
150 G4Vector3D unitUp = (vpVector.cross (unitRight)).unit();
151
152 tp += delta * unitRight;
153 pView->fVP.SetCurrentTargetPoint (tp - stp);
154
155 pView->RepaintGLView ();
156
157 pView->pan_timer = XtAppAddTimeOut
158 (pView->app,
159 timer_id == NULL ? 500 : 1,
160 left_right_pan_callback,
161 pView);
162}
163
164void G4OpenGLXmViewer::pan_up_down_callback (Widget w,
165 XtPointer clientData,
166 XtPointer callData)
167{
168 XmArrowButtonCallbackStruct *cbs = (XmArrowButtonCallbackStruct*) callData;
169 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData;
170
171 pView->pan_up = get_boolean_userData (w);
172
173 if (cbs->reason == XmCR_ARM) {
174 up_down_pan_callback (pView,NULL);
175 } else if (cbs->reason == XmCR_DISARM) {
176 XtRemoveTimeOut (pView->pan_timer);
177 }
178}
179
180void G4OpenGLXmViewer::up_down_pan_callback (XtPointer clientData,
181 XtIntervalId* timer_id)
182{
183 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData;
184 G4double delta;
185
186 if (pView->pan_up) {
187 delta = (G4double)pView->pan_sens;
188 } else {
189 delta = -((G4double)pView->pan_sens);
190 }
191
192 G4Point3D stp
193 = pView -> GetSceneHandler()->GetScene()->GetStandardTargetPoint();
194 G4Point3D tp = stp + pView -> fVP.GetCurrentTargetPoint ();
195 const G4Vector3D& upVector = pView->fVP.GetUpVector ();
196 const G4Vector3D& vpVector = pView->fVP.GetViewpointDirection ();
197
198 G4Vector3D unitRight = (upVector.cross (vpVector)).unit();
199 G4Vector3D unitUp = (vpVector.cross (unitRight)).unit();
200 tp += delta * unitUp;
201 pView->fVP.SetCurrentTargetPoint (tp - stp);
202
203 pView->RepaintGLView();
204
205 pView->pan_timer = XtAppAddTimeOut
206 (pView->app,
207 timer_id == NULL ? 500 : 1,
208 up_down_pan_callback,
209 pView);
210}
211
212void G4OpenGLXmViewer::set_pan_sens_callback (Widget w,
213 XtPointer clientData,
214 XtPointer callData)
215{
216 XmScaleCallbackStruct *cbs = (XmScaleCallbackStruct*) callData;
217 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData;
218 short dp = -1;
219 G4float ten_to_the_dp = 10.;
220
221 XtVaGetValues (w,
222 XmNdecimalPoints, &dp,
223 NULL);
224
225 if (dp == 0) {
226 ten_to_the_dp = 1.;
227 } else if ( dp > 0) {
228 for (G4int i = 1; i < (G4int)dp; i++) {
229 ten_to_the_dp *= 10.;
230 }
231 } else {
232 G4cout << "dp is " << dp << G4endl;
233 return;
234 }
235
236 pView->pan_sens = (G4double)((cbs->value) / ten_to_the_dp);
237}
238
239#endif
240
241
Note: See TracBrowser for help on using the repository browser.