ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4OpenGLXmMainMenubarCallbacks.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4OpenGLXmMainMenubarCallbacks.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 //
29 // Andrew Walkden 16th April 1997
30 // G4OpenGLXmMainMenubarCallbacks :
31 // Collection of callback functions
32 // to handle events generated by the
33 // main OpenGLXm window menubar.
34 //
35 // See G4OpenGLXmMainMenubarCallbacks.hh for more information.
36 
37 
38 #ifdef G4VIS_BUILD_OPENGLXM_DRIVER
39 
40 #include "G4OpenGLXmViewer.hh"
41 
42 #include "G4Xt.hh"
43 
44 #include "G4VSceneHandler.hh"
45 
46 #include "G4Scene.hh"
47 
48 #include "G4OpenGLXmRadioButton.hh"
49 #include "G4OpenGLXmSliderBar.hh"
51 #include "G4OpenGLXmTextField.hh"
52 #include "G4OpenGLXmPushButton.hh"
53 #include "G4OpenGLXmBox.hh"
54 #include "G4OpenGLXmFramedBox.hh"
56 #include "G4OpenGLXmSeparator.hh"
57 
58 #include <sstream>
59 
60 void G4OpenGLXmViewer::actions_callback (Widget w,
61  XtPointer clientData,
62  XtPointer)
63 {
64 
65  G4OpenGLXmViewer* pView;
66  G4long choice = (G4long)clientData;
67 
68 
69  XtVaGetValues (XtParent(w),
70  XmNuserData, &pView,
71  NULL);
72 
73  switch (choice) {
74 
75  case 0:
76 
77  {
78 
79  if (!pView->fprotation_top) {
80  std::ostringstream rot_Name;
81  rot_Name << pView->GetSceneHandler()->GetSceneHandlerId() << '-' << pView->fViewId;
82 
83  pView->fprotation_top = new G4OpenGLXmTopLevelShell (pView,
84  (char*)rot_Name.str().c_str());
85  pView->fprotation_button_box = new G4OpenGLXmBox ("Rotation button box", True);
86 
87  pView->fprotation_top->AddChild (pView->fprotation_button_box);
88 
89  XtCallbackRec* rot_cb_list = new XtCallbackRec[2];
90  rot_cb_list[0].callback = set_rot_subject_callback;
91  rot_cb_list[0].closure = pView;
92  rot_cb_list[1].callback = NULL;
93 
94  pView->fprotation_button1 = new G4OpenGLXmRadioButton
95  ("Object",
96  rot_cb_list,
97  pView->GetViewParameters().GetLightsMoveWithCamera(),
98  0);
99 
100  pView->fprotation_button2 = new G4OpenGLXmRadioButton
101  ("Camera",
102  rot_cb_list,
103  !(pView->GetViewParameters().GetLightsMoveWithCamera()),
104  1);
105 
106  pView->fprotation_button_box->AddChild (pView->fprotation_button1);
107  pView->fprotation_button_box->AddChild (pView->fprotation_button2);
108 
109  pView->fprotation_slider_box = new G4OpenGLXmBox ("Rotation slider box", False);
110  pView->fprotation_top->AddChild (pView->fprotation_slider_box);
111 
112  XtCallbackRec* rot_slider_list = new XtCallbackRec[2];
113  rot_slider_list[0].callback = set_rot_sens_callback;
114  rot_slider_list[0].closure = pView;
115  rot_slider_list[1].callback = NULL;
116 
117  pView->fprotation_slider = new G4OpenGLXmSliderBar ("Rotation slider",
118  rot_slider_list,
119  True,
120  2,
121  pView->fRot_sens,
122  pView->rot_sens_limit,
123  0);
124  pView->fprotation_slider_box->AddChild (pView->fprotation_slider);
125 
126  pView->fprotation_arrow_box = new G4OpenGLXmBox ("Rotation arrow box", False);
127  pView->fprotation_top->AddChild (pView->fprotation_arrow_box);
128 
129  XtCallbackRec** rotation_callbacks = new XtCallbackRec*[4];
130  for (G4int i = 0; i < 4; i++) {
131  rotation_callbacks[i] = new XtCallbackRec[2];
132  }
133  rotation_callbacks[0][0].callback = phi_rotation_callback;
134  rotation_callbacks[0][0].closure = pView;
135  rotation_callbacks[0][1].callback = NULL;
136 
137  rotation_callbacks[1][0].callback = phi_rotation_callback;
138  rotation_callbacks[1][0].closure = pView;
139  rotation_callbacks[1][1].callback = NULL;
140 
141  rotation_callbacks[2][0].callback = theta_rotation_callback;
142  rotation_callbacks[2][0].closure = pView;
143  rotation_callbacks[2][1].callback = NULL;
144 
145  rotation_callbacks[3][0].callback = theta_rotation_callback;
146  rotation_callbacks[3][0].closure = pView;
147  rotation_callbacks[3][1].callback = NULL;
148 
149  pView->fprotation_arrow = new G4OpenGLXmFourArrowButtons (rotation_callbacks);
150 
151  pView->fprotation_arrow_box->AddChild (pView->fprotation_arrow);
152 
153  pView->fprotation_top->Realize ();
154  }
155  break;
156 
157  }
158 
159 
160  case 1:
161  {
162  if (!pView->GetSceneHandler()->GetScene()) {
163  break;
164  }
165  if (!pView->fppanning_top) {
166  std::ostringstream pan_Name;
167  pan_Name << pView->GetSceneHandler()->GetSceneHandlerId() << '-' << pView->fViewId;
168 
169  pView->fppanning_top = new G4OpenGLXmTopLevelShell (pView,
170  (char*)pan_Name.str().c_str());
171 
172  pView->fppanning_box = new G4OpenGLXmFramedBox ("Pan up-down-left-right",
173  False);
174 
175  pView->fppanning_top->AddChild (pView->fppanning_box);
176 
177  XtCallbackRec** pan_callbacks = new XtCallbackRec*[4];
178  for (G4int i = 0; i < 4; i++) {
179  pan_callbacks[i] = new XtCallbackRec[2];
180  }
181  pan_callbacks[0][0].callback = pan_up_down_callback;
182  pan_callbacks[0][0].closure = pView;
183  pan_callbacks[0][1].callback = NULL;
184 
185  pan_callbacks[1][0].callback = pan_up_down_callback;
186  pan_callbacks[1][0].closure = pView;
187  pan_callbacks[1][1].callback = NULL;
188 
189  pan_callbacks[2][0].callback = pan_left_right_callback;
190  pan_callbacks[2][0].closure = pView;
191  pan_callbacks[2][1].callback = NULL;
192 
193  pan_callbacks[3][0].callback = pan_left_right_callback;
194  pan_callbacks[3][0].closure = pView;
195  pan_callbacks[3][1].callback = NULL;
196 
197  pView->fppanning_arrows = new G4OpenGLXmFourArrowButtons (pan_callbacks);
198 
199  pView->fppanning_box->AddChild (pView->fppanning_arrows);
200 
201  XtCallbackRec* pan_slider_list = new XtCallbackRec[2];
202  pan_slider_list[0].callback = set_pan_sens_callback;
203  pan_slider_list[0].closure = pView;
204  pan_slider_list[1].callback = NULL;
205 
206  pView->fppanning_slider = new G4OpenGLXmSliderBar ("Panning slider",
207  pan_slider_list,
208  True,
209  2,
210  pView->fPan_sens = pView->GetSceneHandler()->GetScene()->GetExtent().GetExtentRadius() / 10.0,
211  pView->pan_sens_limit = pView->GetSceneHandler()->GetScene()->GetExtent().GetExtentRadius(),
212  0);
213  pView->fppanning_box->AddChild (pView->fppanning_slider);
214 
215  pView->fpzoom_box = new G4OpenGLXmFramedBox ("Zoom",
216  False);
217  pView->fppanning_top->AddChild (pView->fpzoom_box);
218 
219  XtCallbackRec* zoom_slider_list = new XtCallbackRec[2];
220  zoom_slider_list[0].callback = zoom_callback;
221  zoom_slider_list[0].closure = pView;
222  zoom_slider_list[1].callback = NULL;
223 
224  pView->fpzoom_slider = new G4OpenGLXmSliderBar ("Zoom slider",
225  zoom_slider_list,
226  True,
227  2,
228  pView->fVP.GetZoomFactor(),
229  pView->zoom_high,
230  pView->zoom_low);
231  pView->fpzoom_box->AddChild (pView->fpzoom_slider);
232 
233  pView->fpdolly_box = new G4OpenGLXmFramedBox ("Dolly",
234  False);
235  pView->fppanning_top->AddChild (pView->fpdolly_box);
236 
237  XtCallbackRec* dolly_slider_list = new XtCallbackRec[2];
238  dolly_slider_list[0].callback = dolly_callback;
239  dolly_slider_list[0].closure = pView;
240  dolly_slider_list[1].callback = NULL;
241 
242  pView->fpdolly_slider = new G4OpenGLXmSliderBar ("Dolly slider",
243  dolly_slider_list,
244  True,
245  2,
246  pView->fVP.GetDolly(),
247  pView->dolly_high = pView->GetSceneHandler()->GetScene()->GetExtent().GetExtentRadius(),
248  pView->dolly_low = -(pView->GetSceneHandler()->GetScene()->GetExtent().GetExtentRadius()));
249  // pView->dolly_high,
250  // pView->dolly_low);
251  pView->fpdolly_box->AddChild (pView->fpdolly_slider);
252 
253  pView->fppanning_top->Realize ();
254  pView->UpdateControlPanel ();
255  }
256 
257  break;
258 
259  }
260  case 2:
261  {
262 
263  if (!pView->fpsetting_top) {
264  std::ostringstream set_Name;
265  set_Name << pView->GetSceneHandler()->GetSceneHandlerId() << '-' << pView->fViewId;
266 
267  pView->fpsetting_top = new G4OpenGLXmTopLevelShell(pView,
268  (char*)set_Name.str().c_str());
269 
270  pView->fpsetting_box = new G4OpenGLXmFramedBox ("Set values for control panels",
271  False);
272  pView->fpsetting_top->AddChild (pView->fpsetting_box);
273 
274  pView->fppan_set = new G4OpenGLXmTextField ("Upper limit of pan sensitivity",
275  &(pView->pan_sens_limit));
276 
277  pView->fprot_set = new G4OpenGLXmTextField ("Upper limit of rotation sensitivity",
278  &(pView->rot_sens_limit));
279 
280  pView->fpzoom_upper = new G4OpenGLXmTextField ("Upper limit of zoom",
281  &(pView->zoom_high));
282 
283  pView->fpzoom_lower = new G4OpenGLXmTextField ("Lower limit of zoom",
284  &(pView->zoom_low));
285 
286  pView->fpdolly_upper = new G4OpenGLXmTextField ("Upper limit of dolly",
287  &(pView->dolly_high));
288 
289  pView->fpdolly_lower = new G4OpenGLXmTextField ("Lower limit of dolly",
290  &(pView->dolly_low));
291 
292  XtCallbackRec* ok_list = new XtCallbackRec[2];
293  ok_list[0].callback = update_panels_callback;
294  ok_list[0].closure = pView;
295  ok_list[1].callback = NULL;
296 
297 
298  pView->fpok_button = new G4OpenGLXmPushButton ("ok",
299  ok_list);
300 
301  pView->fpsetting_box->AddChild (pView->fppan_set);
302  pView->fpsetting_box->AddChild (pView->fprot_set);
303  pView->fpsetting_box->AddChild (pView->fpzoom_upper);
304  pView->fpsetting_box->AddChild (pView->fpzoom_lower);
305  pView->fpsetting_box->AddChild (pView->fpdolly_upper);
306  pView->fpsetting_box->AddChild (pView->fpdolly_lower);
307  pView->fpsetting_box->AddChild (pView->fpok_button);
308 
309  pView->fpsetting_top->Realize ();
310 
311  }
312 
313  break;
314  }
315 
316  default:
318  ("G4OpenGLXmViewer::actions_callback",
319  "opengl2001", FatalException,
320  "Unrecognised widget child of control_callback");
321  }
322 
323  return;
324 }
325 
326 
327 
328 void G4OpenGLXmViewer::misc_callback (Widget w,
329  XtPointer clientData,
330  XtPointer)
331 {
332  G4OpenGLXmViewer* pView;
333  G4long choice = (G4long)clientData;
334  XtVaGetValues (XtParent(w),
335  XmNuserData, &pView,
336  NULL);
337 
338  switch (choice) {
339 
340  case 0:
341  {
342 
343  if (!pView->fpmiscellany_top) {
344 
345  std::ostringstream misc_Name;
346  misc_Name << pView->GetSceneHandler()->GetSceneHandlerId() << '-' << pView->fViewId;
347 
348  pView->fpmiscellany_top = new G4OpenGLXmTopLevelShell (pView,
349  (char*)misc_Name.str().c_str());
350  pView->fpwobble_box = new G4OpenGLXmFramedBox ("Wobble view",
351  True);
352  pView->fpmiscellany_top->AddChild (pView->fpwobble_box);
353 
354  XtCallbackRec* wob_cb_list = new XtCallbackRec[2];
355  wob_cb_list[0].callback = wobble_callback;
356  wob_cb_list[0].closure = pView;
357  wob_cb_list[1].callback = NULL;
358 
359 
360  pView->fpwobble_button = new G4OpenGLXmPushButton ("Wobble",
361  wob_cb_list);
362 
363  XtCallbackRec* wobble_slider_list = new XtCallbackRec[2];
364  wobble_slider_list[0].callback = set_wob_sens_callback;
365  wobble_slider_list[0].closure = pView;
366  wobble_slider_list[1].callback = NULL;
367 
368  pView->fpwobble_slider = new G4OpenGLXmSliderBar ("Wobble slider",
369  wobble_slider_list,
370  True,
371  0,
372  pView->wob_sens,
373  pView->wob_high,
374  pView->wob_low);
375  pView->fpwobble_box->AddChild (pView->fpwobble_button);
376  pView->fpwobble_box->AddChild (pView->fpwobble_slider);
377 
378  pView->fpreset_box = new G4OpenGLXmFramedBox ("Reset view",
379  True);
380  pView->fpmiscellany_top->AddChild (pView->fpreset_box);
381 
382  XtCallbackRec* rst_cb_list = new XtCallbackRec[3];
383  rst_cb_list[0].callback = reset_callback;
384  rst_cb_list[0].closure = pView;
385  rst_cb_list[1].callback = update_panels_callback;
386  rst_cb_list[1].closure = pView;
387  rst_cb_list[2].callback = NULL;
388 
389  pView->fpreset_button = new G4OpenGLXmPushButton ("Reset",
390  rst_cb_list);
391 
392  pView->fpreset_box->AddChild (pView->fpreset_button);
393 
394  pView->fpproj_style_box = new G4OpenGLXmFramedBox ("Projection style",
395  True);
396  pView->fpmiscellany_top->AddChild (pView->fpproj_style_box);
397 
398  XtCallbackRec* proj_cb_list = new XtCallbackRec[2];
399  proj_cb_list[0].callback = projection_callback;
400  proj_cb_list[0].closure = pView;
401  proj_cb_list[1].callback = NULL;
402 
403  pView->fporthogonal_button = new G4OpenGLXmRadioButton ("Orthographic",
404  proj_cb_list,
405  pView->fVP.GetFieldHalfAngle() > 0. ? False : True,
406  0);
407 
408  pView->fpperspective_button = new G4OpenGLXmRadioButton ("Perspective",
409  proj_cb_list,
410  pView->fVP.GetFieldHalfAngle() > 0. ? True : False,
411  1);
412 
413  pView->fpfov_text = new G4OpenGLXmTextField ("Field of view 0.1 -> 89.5 degrees.",
414  &(pView->fov));
415 
416  pView->fpproj_style_box->AddChild (pView->fpperspective_button);
417  pView->fpproj_style_box->AddChild (pView->fporthogonal_button);
418  pView->fpproj_style_box->AddChild (pView->fpfov_text);
419 
420  pView->fpmiscellany_top->Realize ();
421 
422  }
423 
424  break;
425  }
426 
427  case 1:
428  {
429  G4Xt::getInstance () -> RequireExitSecondaryLoop (OGL_EXIT_CODE);
430  break;
431  }
432 
433  case 2:
434  {
435  if (!pView->fpprint_top) {
436 
437  std::ostringstream print_Name;
438  print_Name << pView->GetSceneHandler()->GetSceneHandlerId() << '-' << pView->fViewId;
439 
440  pView->fpprint_top = new G4OpenGLXmTopLevelShell (pView,
441  (char*)print_Name.str().c_str());
442 
443  pView->fpprint_box = new G4OpenGLXmFramedBox ("Create EPS file of current view",
444  False);
445 
446  pView->fpprint_top->AddChild (pView->fpprint_box);
447 
448  pView->fpprint_col_box = new G4OpenGLXmFramedBox ("Colour choice",
449  True);
450  pView->fpprint_top->AddChild (pView->fpprint_col_box);
451 
452  XtCallbackRec* prcol_cb_list = new XtCallbackRec[2];
453  prcol_cb_list[0].callback = set_print_colour_callback;
454  prcol_cb_list[0].closure = pView;
455  prcol_cb_list[1].callback = NULL;
456 
457  pView->fpprint_col_radio1 = new G4OpenGLXmRadioButton ("Black and white",
458  prcol_cb_list,
459  pView->fPrintColour==false ? True : False,
460  0);
461 
462  pView->fpprint_col_radio2 = new G4OpenGLXmRadioButton ("Colour",
463  prcol_cb_list,
464  pView->fPrintColour==true ? True : False,
465  1);
466 
467  pView->fpprint_col_box->AddChild (pView->fpprint_col_radio1);
468  pView->fpprint_col_box->AddChild (pView->fpprint_col_radio2);
469 
470  pView->fpprint_style_box = new G4OpenGLXmFramedBox ("File type",
471  True);
472  pView->fpprint_top->AddChild (pView->fpprint_style_box);
473 
474  XtCallbackRec* prsty_cb_list = new XtCallbackRec[2];
475  prsty_cb_list[0].callback = set_print_style_callback;
476  prsty_cb_list[0].closure = pView;
477  prsty_cb_list[1].callback = NULL;
478 
479  pView->fpprint_style_radio1 = new G4OpenGLXmRadioButton ("Screen dump (pixmap)",
480  prsty_cb_list,
481  pView->fVectoredPs==false ? True : False,
482  0);
483 
484  pView->fpprint_style_radio2 = new G4OpenGLXmRadioButton ("PostScript",
485  prsty_cb_list,
486  pView->fVectoredPs==true ? True : False,
487  1);
488 
489  pView->fpprint_style_box->AddChild (pView->fpprint_style_radio1);
490  pView->fpprint_style_box->AddChild (pView->fpprint_style_radio2);
491 
492  pView->fpprint_text = new G4OpenGLXmTextField ("Name of .eps file to save",
493  (pView->getRealPrintFilename().c_str()));
494  pView->fpprint_box->AddChild (pView->fpprint_text);
495 
496  pView->fpprint_line = new G4OpenGLXmSeparator ();
497  pView->fpprint_box->AddChild (pView->fpprint_line);
498 
499  XtCallbackRec* pri_cb_list = new XtCallbackRec[2];
500  pri_cb_list[0].callback = print_callback;
501  pri_cb_list[0].closure = pView;
502  pri_cb_list[1].callback = NULL;
503 
504 
505  pView->fpprint_button = new G4OpenGLXmPushButton ("Create EPS file",
506  pri_cb_list);
507 
508  pView->fpprint_box->AddChild (pView->fpprint_button);
509  pView->fpprint_top->Realize ();
510 
511  }
512 
514  break;
515  }
516 
517  default:
519  ("G4OpenGLXmViewer::misc_callback",
520  "opengl2002", FatalException,
521  "Unrecognised widget child of misc_callback.");
522  }
523 
524  return;
525 
526 }
527 
528 void G4OpenGLXmViewer::set_wob_sens_callback (Widget w,
529  XtPointer clientData,
530  XtPointer callData)
531 {
532  XmScaleCallbackStruct *cbs = (XmScaleCallbackStruct*) callData;
533  G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData;
534  short dp = -1;
535  G4float ten_to_the_dp = 10.;
536 
537  XtVaGetValues (w,
538  XmNdecimalPoints, &dp,
539  NULL);
540 
541  if (dp == 0) {
542  ten_to_the_dp = 1.;
543  } else if ( dp > 0) {
544  for (G4int i = 1; i < (G4int)dp; i++) {
545  ten_to_the_dp *= 10.;
546  }
547  } else {
549  ("G4OpenGLXmViewer::set_wob_sens_callback",
550  "opengl2003", FatalException,
551  "Bad value returned for dp in set_rot_sens_callback");
552  }
553 
554  pView->wob_sens = (G4float)(cbs->value) / ten_to_the_dp;
555 }
556 
557 void G4OpenGLXmViewer::update_panels_callback (Widget,
558  XtPointer clientData,
559  XtPointer)
560 {
561  G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData;
562 
563  if (pView->fppanning_slider) {
564  pView->fppanning_slider->SetMaxValue (pView->pan_sens_limit);
565  }
566  if (pView->fprotation_slider) {
567  pView->fprotation_slider->SetMaxValue (pView->rot_sens_limit);
568  }
569 
570  if (pView->fpzoom_slider) {
571  pView->fpzoom_slider->SetMaxValue (pView->zoom_high);
572  pView->fpzoom_slider->SetMinValue (pView->zoom_low);
573  pView->fpzoom_slider->SetInitialValue (pView->fVP.GetZoomFactor());
574  }
575 
576  if (pView->fpdolly_slider) {
577  pView->fpdolly_slider->SetMaxValue (pView->dolly_high);
578  pView->fpdolly_slider->SetMinValue (pView->dolly_low);
579  }
580 }
581 
582 #endif