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