Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4OpenGLXmViewerMessenger.cc
Go to the documentation of this file.
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
29
30#include "G4SystemOfUnits.hh"
31#include "G4OpenGLXmViewer.hh"
33
34#include "G4UImanager.hh"
35#include "G4UIcommand.hh"
36#include "G4UIdirectory.hh"
38#include "G4UIcmdWithADouble.hh"
39
40#include "G4VisManager.hh"
41
42G4OpenGLXmViewerMessenger* G4OpenGLXmViewerMessenger::fpInstance = 0;
43
45{
46 if (!fpInstance) fpInstance = new G4OpenGLXmViewerMessenger;
47 return fpInstance;
48}
49
50G4OpenGLXmViewerMessenger::G4OpenGLXmViewerMessenger()
51{
52 G4bool omitable;
53
54 fpDirectory = new G4UIdirectory("/vis/oglxm/");
55 fpDirectory->SetGuidance("G4OpenGLXmViewer commands.");
56
57 fpDirectorySet = new G4UIdirectory ("/vis/oglxm/set/");
58 fpDirectorySet->SetGuidance("G4OpenGLXmViewer set commands.");
59
60 fpCommandSetDollyHigh =
61 new G4UIcmdWithADoubleAndUnit("/vis/oglxm/set/dolly-high", this);
62 fpCommandSetDollyHigh->SetGuidance("Higher limit of dolly slider.");
63 fpCommandSetDollyHigh->SetParameterName("dolly-high", omitable = false);
64
65 fpCommandSetDollyLow =
66 new G4UIcmdWithADoubleAndUnit("/vis/oglxm/set/dolly-low", this);
67 fpCommandSetDollyLow->SetGuidance("Lower limit of dolly slider.");
68 fpCommandSetDollyLow->SetParameterName("dolly-low", omitable = false);
69
70 fpCommandSetPanHigh =
71 new G4UIcmdWithADoubleAndUnit("/vis/oglxm/set/pan-high", this);
72 fpCommandSetPanHigh->SetGuidance("Higher limit of pan slider.");
73 fpCommandSetPanHigh->SetParameterName("pan-high", omitable = false);
74
75 fpCommandSetRotationHigh =
76 new G4UIcmdWithADoubleAndUnit("/vis/oglxm/set/rotation-high", this);
77 fpCommandSetRotationHigh->SetGuidance("Higher limit of rotation slider.");
78 fpCommandSetRotationHigh->SetParameterName("rotation-high", omitable = false);
79
80 fpCommandSetZoomHigh =
81 new G4UIcmdWithADouble("/vis/oglxm/set/zoom-high", this);
82 fpCommandSetZoomHigh->SetGuidance("Higher limit of zoom slider.");
83 fpCommandSetZoomHigh->SetParameterName("zoom-high", omitable = false);
84
85 fpCommandSetZoomLow =
86 new G4UIcmdWithADouble("/vis/oglxm/set/zoom-low", this);
87 fpCommandSetZoomLow->SetGuidance("Lower limit of zoom slider.");
88 fpCommandSetZoomLow->SetParameterName("zoom-low", omitable = false);
89}
90
92{
93 delete fpCommandSetZoomLow;
94 delete fpCommandSetZoomHigh;
95 delete fpCommandSetRotationHigh;
96 delete fpCommandSetPanHigh;
97 delete fpCommandSetDollyLow;
98 delete fpCommandSetDollyHigh;
99 delete fpDirectorySet;
100 delete fpDirectory;
101}
102
104(G4UIcommand* command, G4String newValue)
105{
107
108 G4VViewer* pVViewer = pVisManager->GetCurrentViewer();
109
110 if (!pVViewer) {
111 G4cout <<
112 "G4OpenGLXmViewerMessenger::SetNewValue: No current viewer."
113 "\n \"/vis/open\", or similar, to get one."
114 << G4endl;
115 return;
116 }
117
118 G4OpenGLXmViewer* pViewer = dynamic_cast<G4OpenGLXmViewer*>(pVViewer);
119
120 if (!pViewer) {
121 G4cout <<
122 "G4OpenGLXmViewerMessenger::SetNewValue: Current viewer is not of type"
123 "\n OGLIXm or OGLSXm. Use \"/vis/viewer/select\" or \"/vis/open\"."
124 << G4endl;
125 return;
126 }
127
128 G4bool panningControlPanel = true;
129 G4bool rotationControlPanel = true;
130
131 if (command == fpCommandSetDollyHigh)
132 {
133 if (pViewer->fpdolly_slider)
134 {
135 pViewer->dolly_high =
136 fpCommandSetDollyHigh->GetNewDoubleValue(newValue);
137 pViewer->fpdolly_slider->SetMaxValue (pViewer->dolly_high);
138 if (pViewer->fVP.GetDolly() > pViewer->dolly_high)
139 {
140 pViewer->fpdolly_slider->SetInitialValue (pViewer->dolly_high);
141 pViewer->fVP.SetDolly(pViewer->dolly_high);
142 }
143 else
144 {
145 pViewer->fpdolly_slider->SetInitialValue (pViewer->fVP.GetDolly());
146 }
147 }
148 else
149 {
150 panningControlPanel = false;
151 }
152 }
153
154 else if (command == fpCommandSetDollyLow)
155 {
156 if (pViewer->fpdolly_slider)
157 {
158 pViewer->dolly_low =
159 fpCommandSetDollyLow->GetNewDoubleValue(newValue);
160 pViewer->fpdolly_slider->SetMinValue (pViewer->dolly_low);
161 if (pViewer->fVP.GetDolly() < pViewer->dolly_low)
162 {
163 pViewer->fpdolly_slider->SetInitialValue (pViewer->dolly_low);
164 pViewer->fVP.SetDolly(pViewer->dolly_low);
165 }
166 else
167 {
168 pViewer->fpdolly_slider->SetInitialValue (pViewer->fVP.GetDolly());
169 }
170 }
171 else
172 {
173 panningControlPanel = false;
174 }
175 }
176
177 else if (command == fpCommandSetPanHigh)
178 {
179 if (pViewer->fppanning_slider)
180 {
181 pViewer->pan_sens_limit =
182 fpCommandSetPanHigh->GetNewDoubleValue(newValue);
183 pViewer->fppanning_slider->SetMaxValue (pViewer->pan_sens_limit);
184 pViewer->fppanning_slider->SetInitialValue (pViewer->pan_sens_limit / 2.);
185 }
186 else
187 {
188 panningControlPanel = false;
189 }
190 }
191
192 else if (command == fpCommandSetRotationHigh)
193 {
194 if (pViewer->fprotation_slider)
195 {
196 // Internally in OpenGLXm, it's in degrees...
197 pViewer->rot_sens_limit =
198 fpCommandSetRotationHigh->GetNewDoubleValue(newValue) / deg;
199 pViewer->fprotation_slider->SetMaxValue (pViewer->rot_sens_limit);
200 pViewer->fprotation_slider->SetInitialValue (pViewer->rot_sens_limit / 2.);
201 }
202 else
203 {
204 rotationControlPanel = false;
205 }
206 }
207
208 else if (command == fpCommandSetZoomHigh)
209 {
210 if (pViewer->fpzoom_slider)
211 {
212 pViewer->zoom_high =
213 fpCommandSetZoomHigh->GetNewDoubleValue(newValue);
214 pViewer->fpzoom_slider->SetMaxValue (pViewer->zoom_high);
215 pViewer->fpzoom_slider->SetInitialValue (pViewer->fVP.GetZoomFactor());
216 if (pViewer->fVP.GetZoomFactor() > pViewer->zoom_high)
217 {
218 pViewer->fpzoom_slider->SetInitialValue (pViewer->zoom_high);
219 pViewer->fVP.SetZoomFactor(pViewer->zoom_high);
220 }
221 else
222 {
223 pViewer->fpzoom_slider->SetInitialValue (pViewer->fVP.GetZoomFactor());
224 }
225 }
226 else
227 {
228 panningControlPanel = false;
229 }
230 }
231
232 else if (command == fpCommandSetZoomLow)
233 {
234 if (pViewer->fpzoom_slider)
235 {
236 pViewer->zoom_low =
237 fpCommandSetZoomLow->GetNewDoubleValue(newValue);
238 pViewer->fpzoom_slider->SetMinValue (pViewer->zoom_low);
239 pViewer->fpzoom_slider->SetInitialValue (pViewer->fVP.GetZoomFactor());
240 if (pViewer->fVP.GetZoomFactor() < pViewer->zoom_low)
241 {
242 pViewer->fpzoom_slider->SetInitialValue (pViewer->zoom_low);
243 pViewer->fVP.SetZoomFactor(pViewer->zoom_low);
244 }
245 else
246 {
247 pViewer->fpzoom_slider->SetInitialValue (pViewer->fVP.GetZoomFactor());
248 }
249 }
250 else
251 {
252 panningControlPanel = false;
253 }
254 }
255
256 if (!panningControlPanel)
257 {
258 G4cout <<
259 "G4OpenGLXmViewerMessenger::SetNewValue: pull down panning"
260 "\n control panel and re-issue command."
261 << G4endl;
262 return;
263 }
264
265 if (!rotationControlPanel)
266 {
267 G4cout <<
268 "G4OpenGLXmViewerMessenger::SetNewValue: pull down rotation"
269 "\n control panel and re-issue command."
270 << G4endl;
271 return;
272 }
273
274 G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/rebuild");
275}
bool G4bool
Definition G4Types.hh:86
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
static G4OpenGLXmViewerMessenger * GetInstance()
void SetNewValue(G4UIcommand *, G4String)
G4OpenGLXmSliderBar * fppanning_slider
G4OpenGLXmSliderBar * fprotation_slider
G4OpenGLXmSliderBar * fpzoom_slider
G4OpenGLXmSliderBar * fpdolly_slider
static G4double GetNewDoubleValue(const char *paramString)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
static G4double GetNewDoubleValue(const char *paramString)
void SetGuidance(const char *aGuidance)
G4int ApplyCommand(const char *aCommand)
static G4UImanager * GetUIpointer()
G4ViewParameters fVP
Definition G4VViewer.hh:257
G4double GetZoomFactor() const
void SetDolly(G4double dolly)
void SetZoomFactor(G4double zoomFactor)
G4double GetDolly() const
G4VViewer * GetCurrentViewer() const
static G4VisManager * GetInstance()