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