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