source: trunk/source/visualization/OpenGL/src/G4OpenGLXmViewerMessenger.cc@ 1048

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

update

  • Property svn:mime-type set to text/cpp
File size: 8.8 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<<<<<<< G4OpenGLXmViewerMessenger.cc
28// $Id: G4OpenGLXmViewerMessenger.cc,v 1.4 2006/06/29 21:20:18 gunter Exp $
29// GEANT4 tag $Name: geant4-09-02-ref-02 $
30=======
31// $Id: G4OpenGLXmViewerMessenger.cc,v 1.5 2009/01/19 16:53:42 lgarnier Exp $
32// GEANT4 tag $Name: $
33>>>>>>> 1.5
34
35#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
36
37#include "G4OpenGLXmViewerMessenger.hh"
38
39#include "G4OpenGLXmViewer.hh"
40#include "G4OpenGLXmSliderBar.hh"
41
42#include "G4UImanager.hh"
43#include "G4UIcommand.hh"
44#include "G4UIdirectory.hh"
45#include "G4UIcmdWithADoubleAndUnit.hh"
46#include "G4UIcmdWithADouble.hh"
47
48#include "G4VisManager.hh"
49
50G4OpenGLXmViewerMessenger* G4OpenGLXmViewerMessenger::fpInstance = 0;
51
52G4OpenGLXmViewerMessenger* G4OpenGLXmViewerMessenger::GetInstance()
53{
54 if (!fpInstance) fpInstance = new G4OpenGLXmViewerMessenger;
55 return fpInstance;
56}
57
58G4OpenGLXmViewerMessenger::G4OpenGLXmViewerMessenger()
59{
60 G4bool omitable;
61
62 fpDirectory = new G4UIdirectory("/vis/oglxm/");
63 fpDirectory->SetGuidance("G4OpenGLXmViewer commands.");
64
65 fpDirectorySet = new G4UIdirectory ("/vis/oglxm/set/");
66 fpDirectorySet->SetGuidance("G4OpenGLXmViewer set commands.");
67
68 fpCommandSetDollyHigh =
69 new G4UIcmdWithADoubleAndUnit("/vis/oglxm/set/dolly-high", this);
70 fpCommandSetDollyHigh->SetGuidance("Higher limit of dolly slider.");
71 fpCommandSetDollyHigh->SetParameterName("dolly-high", omitable = false);
72
73 fpCommandSetDollyLow =
74 new G4UIcmdWithADoubleAndUnit("/vis/oglxm/set/dolly-low", this);
75 fpCommandSetDollyLow->SetGuidance("Lower limit of dolly slider.");
76 fpCommandSetDollyLow->SetParameterName("dolly-low", omitable = false);
77
78 fpCommandSetPanHigh =
79 new G4UIcmdWithADoubleAndUnit("/vis/oglxm/set/pan-high", this);
80 fpCommandSetPanHigh->SetGuidance("Higher limit of pan slider.");
81 fpCommandSetPanHigh->SetParameterName("pan-high", omitable = false);
82
83 fpCommandSetRotationHigh =
84 new G4UIcmdWithADoubleAndUnit("/vis/oglxm/set/rotation-high", this);
85 fpCommandSetRotationHigh->SetGuidance("Higher limit of rotation slider.");
86 fpCommandSetRotationHigh->SetParameterName("rotation-high", omitable = false);
87
88 fpCommandSetZoomHigh =
89 new G4UIcmdWithADouble("/vis/oglxm/set/zoom-high", this);
90 fpCommandSetZoomHigh->SetGuidance("Higher limit of zoom slider.");
91 fpCommandSetZoomHigh->SetParameterName("zoom-high", omitable = false);
92
93 fpCommandSetZoomLow =
94 new G4UIcmdWithADouble("/vis/oglxm/set/zoom-low", this);
95 fpCommandSetZoomLow->SetGuidance("Lower limit of zoom slider.");
96 fpCommandSetZoomLow->SetParameterName("zoom-low", omitable = false);
97}
98
99G4OpenGLXmViewerMessenger::~G4OpenGLXmViewerMessenger ()
100{
101 delete fpCommandSetZoomLow;
102 delete fpCommandSetZoomHigh;
103 delete fpCommandSetRotationHigh;
104 delete fpCommandSetPanHigh;
105 delete fpCommandSetDollyLow;
106 delete fpCommandSetDollyHigh;
107 delete fpDirectorySet;
108 delete fpDirectory;
109}
110
111void G4OpenGLXmViewerMessenger::SetNewValue
112(G4UIcommand* command, G4String newValue)
113{
114 G4VisManager* pVisManager = G4VisManager::GetInstance();
115
116 G4VViewer* pVViewer = pVisManager->GetCurrentViewer();
117
118 if (!pVViewer) {
119 G4cout <<
120 "G4OpenGLXmViewerMessenger::SetNewValue: No current viewer."
121 "\n \"/vis/open\", or similar, to get one."
122 << G4endl;
123 return;
124 }
125
126 G4OpenGLXmViewer* pViewer = dynamic_cast<G4OpenGLXmViewer*>(pVViewer);
127
128 if (!pViewer) {
129 G4cout <<
130 "G4OpenGLXmViewerMessenger::SetNewValue: Current viewer is not of type"
131 "\n OGLIXm or OGLSXm. Use \"/vis/viewer/select\" or \"/vis/open\"."
132 << G4endl;
133 return;
134 }
135
136 G4bool panningControlPanel = true;
137 G4bool rotationControlPanel = true;
138
139 if (command == fpCommandSetDollyHigh)
140 {
141 if (pViewer->fpdolly_slider)
142 {
143 pViewer->dolly_high =
144 fpCommandSetDollyHigh->GetNewDoubleValue(newValue);
145 pViewer->fpdolly_slider->SetMaxValue (pViewer->dolly_high);
146 if (pViewer->fVP.GetDolly() > pViewer->dolly_high)
147 {
148 pViewer->fpdolly_slider->SetInitialValue (pViewer->dolly_high);
149 pViewer->fVP.SetDolly(pViewer->dolly_high);
150 }
151 else
152 {
153 pViewer->fpdolly_slider->SetInitialValue (pViewer->fVP.GetDolly());
154 }
155 }
156 else
157 {
158 panningControlPanel = false;
159 }
160 }
161
162 else if (command == fpCommandSetDollyLow)
163 {
164 if (pViewer->fpdolly_slider)
165 {
166 pViewer->dolly_low =
167 fpCommandSetDollyLow->GetNewDoubleValue(newValue);
168 pViewer->fpdolly_slider->SetMinValue (pViewer->dolly_low);
169 if (pViewer->fVP.GetDolly() < pViewer->dolly_low)
170 {
171 pViewer->fpdolly_slider->SetInitialValue (pViewer->dolly_low);
172 pViewer->fVP.SetDolly(pViewer->dolly_low);
173 }
174 else
175 {
176 pViewer->fpdolly_slider->SetInitialValue (pViewer->fVP.GetDolly());
177 }
178 }
179 else
180 {
181 panningControlPanel = false;
182 }
183 }
184
185 else if (command == fpCommandSetPanHigh)
186 {
187 if (pViewer->fppanning_slider)
188 {
189 pViewer->pan_sens_limit =
190 fpCommandSetPanHigh->GetNewDoubleValue(newValue);
191 pViewer->fppanning_slider->SetMaxValue (pViewer->pan_sens_limit);
192 pViewer->fppanning_slider->SetInitialValue (pViewer->pan_sens_limit / 2.);
193 }
194 else
195 {
196 panningControlPanel = false;
197 }
198 }
199
200 else if (command == fpCommandSetRotationHigh)
201 {
202 if (pViewer->fprotation_slider)
203 {
204 // Internally in OpenGLXm, it's in degrees...
205 pViewer->rot_sens_limit =
206 fpCommandSetRotationHigh->GetNewDoubleValue(newValue) / deg;
207 pViewer->fprotation_slider->SetMaxValue (pViewer->rot_sens_limit);
208 pViewer->fprotation_slider->SetInitialValue (pViewer->rot_sens_limit / 2.);
209 }
210 else
211 {
212 rotationControlPanel = false;
213 }
214 }
215
216 else if (command == fpCommandSetZoomHigh)
217 {
218 if (pViewer->fpzoom_slider)
219 {
220 pViewer->zoom_high =
221 fpCommandSetZoomHigh->GetNewDoubleValue(newValue);
222 pViewer->fpzoom_slider->SetMaxValue (pViewer->zoom_high);
223 pViewer->fpzoom_slider->SetInitialValue (pViewer->fVP.GetZoomFactor());
224 if (pViewer->fVP.GetZoomFactor() > pViewer->zoom_high)
225 {
226 pViewer->fpzoom_slider->SetInitialValue (pViewer->zoom_high);
227 pViewer->fVP.SetZoomFactor(pViewer->zoom_high);
228 }
229 else
230 {
231 pViewer->fpzoom_slider->SetInitialValue (pViewer->fVP.GetZoomFactor());
232 }
233 }
234 else
235 {
236 panningControlPanel = false;
237 }
238 }
239
240 else if (command == fpCommandSetZoomLow)
241 {
242 if (pViewer->fpzoom_slider)
243 {
244 pViewer->zoom_low =
245 fpCommandSetZoomLow->GetNewDoubleValue(newValue);
246 pViewer->fpzoom_slider->SetMinValue (pViewer->zoom_low);
247 pViewer->fpzoom_slider->SetInitialValue (pViewer->fVP.GetZoomFactor());
248 if (pViewer->fVP.GetZoomFactor() < pViewer->zoom_low)
249 {
250 pViewer->fpzoom_slider->SetInitialValue (pViewer->zoom_low);
251 pViewer->fVP.SetZoomFactor(pViewer->zoom_low);
252 }
253 else
254 {
255 pViewer->fpzoom_slider->SetInitialValue (pViewer->fVP.GetZoomFactor());
256 }
257 }
258 else
259 {
260 panningControlPanel = false;
261 }
262 }
263
264 if (!panningControlPanel)
265 {
266 G4cout <<
267 "G4OpenGLXmViewerMessenger::SetNewValue: pull down panning"
268 "\n control panel and re-issue command."
269 << G4endl;
270 return;
271 }
272
273 if (!rotationControlPanel)
274 {
275 G4cout <<
276 "G4OpenGLXmViewerMessenger::SetNewValue: pull down rotation"
277 "\n control panel and re-issue command."
278 << G4endl;
279 return;
280 }
281
282 G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/rebuild");
283}
284
285#endif
Note: See TracBrowser for help on using the repository browser.