source: trunk/geant4/visualization/OpenGL/src/G4OpenGLXmPanningCallbacks.cc @ 529

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

r658@mac-90108: laurentgarnier | 2007-06-25 12:02:16 +0200
import de visualisation

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