Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
G4OpenGLXmConvenienceRoutines.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// G4OpenGLXmConvenienceRoutines :
32// Collection of routines to facilitate
33// the addition of simple push button boxes,
34// and slider bars to the control panel.
35//
36// See G4OpenGLXmConvenienceRoutines.hh for more information.
37
38#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
39
40#include "G4OpenGLXmViewer.hh"
41
42#include <Xm/Form.h>
43#include <Xm/ToggleB.h>
44#include <Xm/ArrowBG.h>
45#include <Xm/RowColumn.h>
46#include <Xm/TextF.h>
47#include <Xm/Separator.h>
48#include <Xm/Scale.h>
49
50void G4OpenGLXmViewer::Add_four_arrow_buttons (G4OpenGLXmViewer* pView,
51 XtCallbackRec** arrow_callbacks,
52 Widget* parent_widget) {
53
54 Widget arrow_form = XtVaCreateWidget
55 ("arrow_form",
56 xmFormWidgetClass,
57 *parent_widget,
58 XmNfractionBase, 3,
59 XtNvisual, pView->vi->visual,
60 XtNdepth, pView->vi->depth,
61 XtNcolormap, pView->cmap,
62 XtNborderColor, pView->borcol,
63 XtNbackground, pView->bgnd,
64 NULL);
65
66 Widget arrow = XtVaCreateManagedWidget
67 ("up_arrow",
68 xmArrowButtonGadgetClass,
69 arrow_form,
70 XmNtopAttachment, XmATTACH_POSITION,
71 XmNtopPosition, 0,
72 XmNbottomAttachment, XmATTACH_POSITION,
73 XmNbottomPosition, 1,
74 XmNleftAttachment, XmATTACH_POSITION,
75 XmNleftPosition, 1,
76 XmNrightAttachment, XmATTACH_POSITION,
77 XmNrightPosition, 2,
78 XmNarrowDirection, XmARROW_UP,
79 NULL);
80
81 XtVaSetValues (arrow,
82 XmNuserData, True,
83 NULL);
84
85 XtAddCallbacks (arrow,
86 XmNactivateCallback,
87 arrow_callbacks[0]);
88
89 XtAddCallbacks (arrow,
90 XmNarmCallback,
91 arrow_callbacks[0]);
92
93 XtAddCallbacks (arrow,
94 XmNdisarmCallback,
95 arrow_callbacks[0]);
96
97 arrow = XtVaCreateManagedWidget
98 ("down_arrow",
99 xmArrowButtonGadgetClass,
100 arrow_form,
101 XmNtopAttachment, XmATTACH_POSITION,
102 XmNtopPosition, 2,
103 XmNbottomAttachment, XmATTACH_POSITION,
104 XmNbottomPosition, 3,
105 XmNleftAttachment, XmATTACH_POSITION,
106 XmNleftPosition, 1,
107 XmNrightAttachment, XmATTACH_POSITION,
108 XmNrightPosition, 2,
109 XmNarrowDirection, XmARROW_DOWN,
110 NULL);
111
112 XtVaSetValues (arrow,
113 XmNuserData, False,
114 NULL);
115
116 XtAddCallbacks (arrow,
117 XmNactivateCallback,
118 arrow_callbacks[1]);
119
120 XtAddCallbacks (arrow,
121 XmNarmCallback,
122 arrow_callbacks[1]);
123
124 XtAddCallbacks (arrow,
125 XmNdisarmCallback,
126 arrow_callbacks[1]);
127
128 arrow = XtVaCreateManagedWidget
129 ("left_arrow",
130 xmArrowButtonGadgetClass,
131 arrow_form,
132 XmNtopAttachment, XmATTACH_POSITION,
133 XmNtopPosition, 1,
134 XmNbottomAttachment, XmATTACH_POSITION,
135 XmNbottomPosition, 2,
136 XmNleftAttachment, XmATTACH_POSITION,
137 XmNleftPosition, 0,
138 XmNrightAttachment, XmATTACH_POSITION,
139 XmNrightPosition, 1,
140 XmNarrowDirection, XmARROW_LEFT,
141 NULL);
142
143 XtVaSetValues (arrow,
144 XmNuserData, False,
145 NULL);
146
147 XtAddCallbacks (arrow,
148 XmNactivateCallback,
149 arrow_callbacks[2]);
150
151 XtAddCallbacks (arrow,
152 XmNarmCallback,
153 arrow_callbacks[2]);
154
155 XtAddCallbacks (arrow,
156 XmNdisarmCallback,
157 arrow_callbacks[2]);
158
159 arrow = XtVaCreateManagedWidget
160 ("right_arrow",
161 xmArrowButtonGadgetClass,
162 arrow_form,
163 XmNtopAttachment, XmATTACH_POSITION,
164 XmNtopPosition, 1,
165 XmNbottomAttachment, XmATTACH_POSITION,
166 XmNbottomPosition, 2,
167 XmNleftAttachment, XmATTACH_POSITION,
168 XmNleftPosition, 2,
169 XmNrightAttachment, XmATTACH_POSITION,
170 XmNrightPosition, 3,
171 XmNarrowDirection, XmARROW_RIGHT,
172 NULL);
173
174 XtVaSetValues (arrow,
175 XmNuserData, True,
176 NULL);
177
178 XtAddCallbacks (arrow,
179 XmNactivateCallback,
180 arrow_callbacks[3]);
181
182 XtAddCallbacks (arrow,
183 XmNarmCallback,
184 arrow_callbacks[3]);
185
186 XtAddCallbacks (arrow,
187 XmNdisarmCallback,
188 arrow_callbacks[3]);
189
190 XtManageChild (arrow_form);
191
192}
193
194void G4OpenGLXmViewer::Add_radio_box (char* label_string,
195 Widget* parent_widget,
196 XtCallbackRec* radio_box_callback,
197 G4int num_buttons,
198 G4int default_button,
199 char* radio_box_name,
200 char** button_names,
201 G4OpenGLXmViewer* pView)
202{
203 XmString button_str = XmStringCreateLocalized((char*) ""); // ...to
204 // initialise to something to avoid pedantic warning.
205 Arg** args;
206 args = new Arg* [num_buttons];
207 Widget button;
208
209 G4int i;
210 for (i = 0; i < num_buttons; i++) {
211
212 args[i] = new Arg[7];
213 button_str = XmStringCreateLocalized (button_names[i]);
214
215 XtSetArg (args[i][0], XtNvisual, pView->vi->visual);
216 XtSetArg (args[i][1], XtNdepth, pView->vi->depth);
217 XtSetArg (args[i][2], XtNcolormap, pView->cmap);
218 XtSetArg (args[i][3], XtNborderColor, pView->borcol);
219 XtSetArg (args[i][4], XtNbackground, pView->bgnd);
220 XtSetArg (args[i][5], XmNlabelString, button_str);
221
222 if (i == default_button) {
223 XtSetArg (args[i][6], XmNset, True);
224 } else {
225 XtSetArg (args[i][6], XmNset, False);
226 }
227 }
228
229 Widget radio_box = XtVaCreateWidget (radio_box_name,
230 xmRowColumnWidgetClass,
231 *parent_widget,
232 XmNisHomogeneous, False,
233 XmNradioBehavior, True,
234 XmNradioAlwaysOne, True,
235 XmNuserData, pView,
236 XtNvisual, pView->vi->visual,
237 XtNdepth, pView->vi->depth,
238 XtNcolormap, pView->cmap,
239 XtNborderColor, pView->borcol,
240 XtNbackground, pView->bgnd,
241 NULL);
242
243 XmString lab = XmStringCreateLocalized (label_string);
244
245 // Unused!
246 //Widget label = XtVaCreateManagedWidget ("radio_label",
247 // xmLabelWidgetClass,
248 // radio_box,
249 // XmNalignment, XmALIGNMENT_CENTER,
250 // XmNlabelString, lab,
251 // XtNvisual, pView->vi->visual,
252 // XtNdepth, pView->vi->depth,
253 // XtNcolormap, pView->cmap,
254 // XtNborderColor, pView->borcol,
255 // XtNbackground, pView->bgnd,
256 // NULL);
257
258 XmStringFree (lab);
259
260 for (i = 0; i < num_buttons; i++) {
261 button = XtCreateManagedWidget (button_names[i],
262 xmToggleButtonWidgetClass,
263 radio_box,
264 args[i],
265 7);
266 XtVaSetValues (button,
267 XmNuserData, i,
268 NULL);
269
270 XtAddCallbacks (button,
271 XmNarmCallback,
272 radio_box_callback);
273 }
274
275 XtManageChild (radio_box);
276
277 XmStringFree (button_str);
278
279 for (i = 0; i < num_buttons; i++) {
280
281 delete[] args[i];
282
283 }
284
285 delete[] args;
286}
287
288void G4OpenGLXmViewer::Add_set_field (char* w_name,
289 char* w_text,
290 Widget* row_col_box,
291 Widget* wid,
292 G4double* val,
293 G4OpenGLXmViewer* pView)
294{
295
296 char local_w_text[50];
297 strcpy (local_w_text, w_text);
298
299 char label_name[50];
300 strcpy (label_name, w_name);
301 strcat (label_name, "_label");
302
303 char text_field_name[50];
304 strcpy (text_field_name, w_name);
305 strcat (text_field_name, "_text_field");
306
307 XmString local_text = XmStringCreateLocalized (local_w_text);
308
309 // Unused!
310 // Widget label = XtVaCreateManagedWidget (label_name,
311 // xmLabelWidgetClass,
312 // *row_col_box,
313 // XmNlabelString, local_text,
314 // XtNvisual, pView->vi->visual,
315 // XtNdepth, pView->vi->depth,
316 // XtNcolormap, pView->cmap,
317 // XtNborderColor, pView->borcol,
318 // XtNbackground, pView->bgnd,
319 // NULL);
320
321 XmStringFree (local_text);
322
323 char initial[50];
324 sprintf (initial, "%6.2f", *val);
325
326 *wid = XtVaCreateManagedWidget (text_field_name,
327 xmTextFieldWidgetClass,
328 *row_col_box,
329 XmNvalue, (String)initial,
330 XtNvisual, pView->vi->visual,
331 XtNdepth, pView->vi->depth,
332 XtNcolormap, pView->cmap,
333 XtNborderColor, pView->borcol,
334 XtNbackground, pView->bgnd,
335 NULL);
336
337 XtAddCallback (*wid,
338 XmNvalueChangedCallback,
339 get_double_value_callback,
340 val);
341
342 /* Not actually used - comment out to prevent compiler warnings.
343 Instead, just in case it matters, just invoke
344 XtVaCreateManagedWidget (JA)
345 Widget sep = XtVaCreateManagedWidget ("sep",
346 xmSeparatorWidgetClass,
347 *row_col_box,
348 XmNorientation, XmHORIZONTAL,
349 XtNvisual, pView->vi->visual,
350 XtNdepth, pView->vi->depth,
351 XtNcolormap, pView->cmap,
352 XtNborderColor, pView->borcol,
353 XtNbackground, pView->bgnd,
354 NULL);
355 sep = XtVaCreateManagedWidget ("sep",
356 xmSeparatorWidgetClass,
357 *row_col_box,
358 XmNseparatorType, XmNO_LINE,
359 XmNmargin, 1,
360 XmNorientation, XmHORIZONTAL,
361 XtNvisual, pView->vi->visual,
362 XtNdepth, pView->vi->depth,
363 XtNcolormap, pView->cmap,
364 XtNborderColor, pView->borcol,
365 XtNbackground, pView->bgnd,
366 NULL);
367 */
368 XtVaCreateManagedWidget ("sep",
369 xmSeparatorWidgetClass,
370 *row_col_box,
371 XmNseparatorType, XmNO_LINE,
372 XmNmargin, 1,
373 XmNorientation, XmHORIZONTAL,
374 XtNvisual, pView->vi->visual,
375 XtNdepth, pView->vi->depth,
376 XtNcolormap, pView->cmap,
377 XtNborderColor, pView->borcol,
378 XtNbackground, pView->bgnd,
379 NULL);
380}
381
382void G4OpenGLXmViewer::Add_slider_box (char* label_string,
383 G4int num_sliders,
384 char** slider_names,
385 G4OpenGLXmViewer* pView,
386 G4double* min_array,
387 G4double* max_array,
388 G4double* value_array,
389 G4bool* show,
390 short* decimals,
391 unsigned char* orientation,
392 unsigned char* direction,
393 XtCallbackRec** slider_box_callbacks,
394 Widget* parent_widget)
395{
396 XmString slider_name_str = XmStringCreateLocalized((char*) ""); // ...to
397 // initialise to something to avoid pedantic warning.
398 Arg** slider_args;
399 slider_args = new Arg*[num_sliders];
400 Widget slider;
401 G4int j = 0;
402
403 G4int i;
404 for (i = 0; i < num_sliders; i++) {
405 j = 0;
406 slider_args[i] = new Arg[13];
407 slider_name_str = XmStringCreateLtoR (slider_names[i],
408 XmFONTLIST_DEFAULT_TAG);
409
410 XtSetArg (slider_args[i][j],
411 XtNvisual, pView->vi->visual); j++;
412 XtSetArg (slider_args[i][j],
413 XtNdepth, pView->vi->depth); j++;
414 XtSetArg (slider_args[i][j],
415 XtNcolormap, pView->cmap); j++;
416 XtSetArg (slider_args[i][j],
417 XtNborderColor, pView->borcol); j++;
418 XtSetArg (slider_args[i][j],
419 XtNbackground, pView->bgnd); j++;
420
421 XtSetArg (slider_args[i][j],
422 XmNtitleString, slider_name_str); j++;
423
424 XtSetArg (slider_args[i][j],
425 XmNmaximum, G4int(max_array[i] * std::pow(10.0, (G4double)decimals[i]))); j++;
426 XtSetArg (slider_args[i][j],
427 XmNminimum, G4int(min_array[i] * std::pow(10.0, (G4double)decimals[i]))); j++;
428 XtSetArg (slider_args[i][j],
429 XmNvalue, G4int(value_array[i] * std::pow(10.0, (G4double)decimals[i]))); j++;
430 XtSetArg (slider_args[i][j],
431 XmNshowValue, show[i]); j++;
432 XtSetArg (slider_args[i][j],
433 XmNdecimalPoints, decimals[i]); j++;
434
435 XtSetArg (slider_args[i][j],
436 XmNorientation, orientation[i]); j++;
437 XtSetArg (slider_args[i][j],
438 XmNprocessingDirection, direction[i]); j++;
439
440 }
441
442 Widget slider_box = XtVaCreateWidget ("slider_box",
443 xmRowColumnWidgetClass,
444 *parent_widget,
445 XmNisHomogeneous, False,
446 XtNvisual, pView->vi->visual,
447 XtNdepth, pView->vi->depth,
448 XtNcolormap, pView->cmap,
449 XtNborderColor, pView->borcol,
450 XtNbackground, pView->bgnd,
451 NULL);
452
453 XmString lab = XmStringCreateLocalized (label_string);
454
455 // Unused!
456 //Widget label = XtVaCreateManagedWidget ("slider_label",
457 // xmLabelWidgetClass,
458 // slider_box,
459 // XmNlabelString, lab,
460 // XmNalignment, XmALIGNMENT_CENTER,
461 // XtNvisual, pView->vi->visual,
462 // XtNdepth, pView->vi->depth,
463 // XtNcolormap, pView->cmap,
464 // XtNborderColor, pView->borcol,
465 // XtNbackground, pView->bgnd,
466 // NULL);
467
468 XmStringFree (lab);
469
470 for (i = 0; i < num_sliders; i++) {
471
472 slider = XtCreateManagedWidget (slider_names[i],
473 xmScaleWidgetClass,
474 slider_box,
475 slider_args[i],
476 j);
477
478 XtAddCallbacks (slider,
479 XmNvalueChangedCallback,
480 slider_box_callbacks[i]);
481
482 XtAddCallbacks (slider,
483 XmNdragCallback,
484 slider_box_callbacks[i]);
485
486 }
487
488 XtManageChild (slider_box);
489 XmStringFree (slider_name_str);
490
491 for (i = 0; i < num_sliders; i++) {
492
493 delete[] slider_args[i];
494
495 }
496
497 delete[] slider_args;
498
499}
500
501void G4OpenGLXmViewer::get_double_value_callback (Widget w,
502 XtPointer clientData,
503 XtPointer)
504{
505 G4double* val = (G4double*) clientData;
506 String string;
507
508 XtVaGetValues (w,
509 XmNvalue, &string,
510 NULL);
511
512 sscanf (string, "%lg", val);
513
514}
515
516void G4OpenGLXmViewer::get_text_callback (Widget w,
517 XtPointer clientData,
518 XtPointer)
519{
520 char* txt = (char*)clientData;
521 String string;
522
523 XtVaGetValues (w,
524 XmNvalue, &string,
525 NULL);
526
527 sscanf (string, "%s", txt);
528}
529
530G4bool G4OpenGLXmViewer::get_boolean_userData (Widget w)
531{
532 XtPointer userData;
533 XtVaGetValues (w,XmNuserData,&userData,NULL);
534 return (G4bool)(((unsigned long)userData)&0xffff);
535}
536
537G4int G4OpenGLXmViewer::get_int_userData (Widget w)
538{
539 XtPointer userData;
540 XtVaGetValues (w,XmNuserData,&userData,NULL);
541 return (G4int)(unsigned long)userData;
542}
543
544#endif
545
546
547
548
549
double G4double
Definition: G4Types.hh:64
int G4int
Definition: G4Types.hh:66
bool G4bool
Definition: G4Types.hh:67
#define userData
Definition: xmlparse.cc:555