source: trunk/source/visualization/OpenGL/src/G4OpenGLXmConvenienceRoutines.cc @ 1337

Last change on this file since 1337 was 1337, checked in by garnier, 14 years ago

tag geant4.9.4 beta 1 + modifs locales

  • Property svn:mime-type set to text/cpp
File size: 14.2 KB
Line 
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.13 2009/02/04 16:48:41 lgarnier Exp $
28// GEANT4 tag $Name: geant4-09-04-beta-01 $
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#include <Xm/Form.h>
44#include <Xm/ToggleB.h>
45#include <Xm/ArrowBG.h>
46#include <Xm/RowColumn.h>
47#include <Xm/TextF.h>
48#include <Xm/Separator.h>
49#include <Xm/Scale.h>
50
51void 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
195void 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
289void 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  Widget sep = XtVaCreateManagedWidget ("sep",
344                                        xmSeparatorWidgetClass,
345                                        *row_col_box,
346                                        XmNorientation, XmHORIZONTAL,
347                                        XtNvisual, pView->vi->visual,
348                                        XtNdepth, pView->vi->depth,
349                                        XtNcolormap, pView->cmap,
350                                        XtNborderColor, pView->borcol,
351                                        XtNbackground, pView->bgnd,
352                                        NULL);
353
354  sep = XtVaCreateManagedWidget ("sep",
355                                 xmSeparatorWidgetClass,
356                                 *row_col_box,
357                                 XmNseparatorType, XmNO_LINE,
358                                 XmNmargin, 1,
359                                 XmNorientation, XmHORIZONTAL,
360                                 XtNvisual, pView->vi->visual,
361                                 XtNdepth, pView->vi->depth,
362                                 XtNcolormap, pView->cmap,
363                                 XtNborderColor, pView->borcol,
364                                 XtNbackground, pView->bgnd,
365                                 NULL);
366}
367
368void G4OpenGLXmViewer::Add_slider_box (char* label_string,
369                                     G4int num_sliders,
370                                     char** slider_names,
371                                     G4OpenGLXmViewer* pView,
372                                     G4double* min_array,
373                                     G4double* max_array,
374                                     G4double* value_array,
375                                     G4bool* show,
376                                     short* decimals,
377                                     unsigned char* orientation,
378                                     unsigned char* direction,
379                                     XtCallbackRec** slider_box_callbacks,
380                                     Widget* parent_widget)
381{
382  XmString slider_name_str = XmStringCreateLocalized((char*) ""); // ...to
383  // initialise to something to avoid pedantic warning.
384  Arg** slider_args;
385  slider_args = new Arg*[num_sliders];
386  Widget slider;
387  G4int j = 0;
388
389  G4int i;
390  for (i = 0; i < num_sliders; i++) {
391    j = 0;
392    slider_args[i] = new Arg[13];
393    slider_name_str = XmStringCreateLtoR (slider_names[i],
394                                          XmFONTLIST_DEFAULT_TAG);
395   
396    XtSetArg (slider_args[i][j],
397              XtNvisual, pView->vi->visual); j++;
398    XtSetArg (slider_args[i][j],
399              XtNdepth, pView->vi->depth); j++;
400    XtSetArg (slider_args[i][j],
401              XtNcolormap, pView->cmap); j++;
402    XtSetArg (slider_args[i][j],
403              XtNborderColor, pView->borcol); j++;
404    XtSetArg (slider_args[i][j],
405              XtNbackground, pView->bgnd); j++;
406   
407    XtSetArg (slider_args[i][j],
408              XmNtitleString, slider_name_str);  j++;
409   
410    XtSetArg (slider_args[i][j],
411              XmNmaximum, G4int(max_array[i] * std::pow(10.0, (G4double)decimals[i]))); j++;
412    XtSetArg (slider_args[i][j],
413              XmNminimum, G4int(min_array[i] * std::pow(10.0, (G4double)decimals[i]))); j++;
414    XtSetArg (slider_args[i][j],
415              XmNvalue, G4int(value_array[i] * std::pow(10.0, (G4double)decimals[i]))); j++;
416    XtSetArg (slider_args[i][j],
417              XmNshowValue, show[i]); j++;
418    XtSetArg (slider_args[i][j],
419              XmNdecimalPoints, decimals[i]); j++;
420   
421    XtSetArg (slider_args[i][j],
422              XmNorientation, orientation[i]);  j++;
423    XtSetArg (slider_args[i][j],
424              XmNprocessingDirection, direction[i]); j++;
425
426  }
427
428  Widget slider_box = XtVaCreateWidget ("slider_box",
429                                        xmRowColumnWidgetClass,
430                                        *parent_widget,
431                                        XmNisHomogeneous, False,
432                                        XtNvisual, pView->vi->visual,
433                                        XtNdepth, pView->vi->depth,
434                                        XtNcolormap, pView->cmap,
435                                        XtNborderColor, pView->borcol,
436                                        XtNbackground, pView->bgnd,
437                                        NULL);
438
439  XmString lab = XmStringCreateLocalized (label_string);
440
441  // Unused!
442  //Widget label = XtVaCreateManagedWidget ("slider_label",
443  //                              xmLabelWidgetClass,
444  //                              slider_box,
445  //                              XmNlabelString, lab,
446  //                              XmNalignment, XmALIGNMENT_CENTER,
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  XmStringFree (lab);
455 
456  for (i = 0; i < num_sliders; i++) {
457   
458    slider = XtCreateManagedWidget (slider_names[i],
459                                    xmScaleWidgetClass,
460                                    slider_box,
461                                    slider_args[i],
462                                    j);
463
464    XtAddCallbacks (slider,
465                   XmNvalueChangedCallback,
466                   slider_box_callbacks[i]);
467   
468    XtAddCallbacks (slider,
469                   XmNdragCallback,
470                   slider_box_callbacks[i]);
471   
472  }
473
474  XtManageChild (slider_box);
475  XmStringFree (slider_name_str);
476
477  for (i = 0; i < num_sliders; i++) {
478
479    delete[] slider_args[i];
480
481  }
482
483  delete[] slider_args;
484
485}
486
487void G4OpenGLXmViewer::get_double_value_callback (Widget w,
488                                                XtPointer clientData,
489                                                XtPointer)
490{
491  G4double* val = (G4double*) clientData;
492  String string;
493
494  XtVaGetValues (w,
495                 XmNvalue, &string,
496                 NULL);
497
498  sscanf (string, "%lg", val);
499
500}
501
502void G4OpenGLXmViewer::get_text_callback (Widget w,
503                                        XtPointer clientData,
504                                        XtPointer)
505{
506  char* txt = (char*)clientData;
507  String string;
508
509  XtVaGetValues (w,
510                 XmNvalue, &string,
511                 NULL);
512
513  sscanf (string, "%s", txt);
514}
515
516G4bool G4OpenGLXmViewer::get_boolean_userData (Widget w)
517{
518  XtPointer userData;
519  XtVaGetValues (w,XmNuserData,&userData,NULL);
520  return (G4bool)(unsigned long)userData;
521}
522
523G4int G4OpenGLXmViewer::get_int_userData (Widget w)
524{
525  XtPointer userData;
526  XtVaGetValues (w,XmNuserData,&userData,NULL);
527  return (G4int)(unsigned long)userData;
528}
529
530#endif
531
532
533
534
535
Note: See TracBrowser for help on using the repository browser.