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