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