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