[529] | 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 | // |
---|
[915] | 27 | // $Id: G4OpenGLXmViewer.cc,v 1.30 2009/02/04 16:48:41 lgarnier Exp $ |
---|
[906] | 28 | // GEANT4 tag $Name: $ |
---|
[529] | 29 | // |
---|
| 30 | // |
---|
| 31 | // Andrew Walkden 10th February 1997 |
---|
| 32 | // G4OpenGLXmViewer : Class derived from G4OpenGLXViewer, to provide |
---|
| 33 | // (Motif) widget OpenGL functionality for GEANT4. |
---|
| 34 | |
---|
| 35 | #ifdef G4VIS_BUILD_OPENGLXM_DRIVER |
---|
| 36 | |
---|
| 37 | #include "globals.hh" |
---|
| 38 | |
---|
| 39 | #include "G4OpenGLXmViewer.hh" |
---|
[914] | 40 | #include "G4OpenGLSceneHandler.hh" |
---|
[529] | 41 | |
---|
| 42 | #include "G4VisExtent.hh" |
---|
| 43 | #include "G4LogicalVolume.hh" |
---|
| 44 | #include "G4VSolid.hh" |
---|
| 45 | #include "G4Point3D.hh" |
---|
| 46 | #include "G4Normal3D.hh" |
---|
| 47 | |
---|
| 48 | #include "G4OpenGLXmSliderBar.hh" |
---|
| 49 | |
---|
[1009] | 50 | #include "G4StateManager.hh" |
---|
| 51 | |
---|
[529] | 52 | #include "G4Xt.hh" |
---|
| 53 | #include <X11/Shell.h> |
---|
[915] | 54 | #include <Xm/MainW.h> |
---|
| 55 | #include <Xm/Frame.h> |
---|
| 56 | #include <Xm/DrawingA.h> |
---|
[529] | 57 | |
---|
| 58 | #include <sstream> |
---|
| 59 | |
---|
| 60 | void G4OpenGLXmViewer::ShowView () { |
---|
[1009] | 61 | #ifdef G4DEBUG_VIS_OGL |
---|
| 62 | printf("G4OpenGLXmViewer::ShowView vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\n"); |
---|
| 63 | #endif |
---|
| 64 | G4StateManager* stateManager = G4StateManager::GetStateManager(); |
---|
| 65 | G4ApplicationState state = stateManager->GetCurrentState(); |
---|
[1036] | 66 | // if (state == G4State_Idle) { |
---|
[1009] | 67 | #ifdef G4DEBUG_VIS_OGL |
---|
| 68 | printf("G4OpenGLXmViewer::ShowView LOOOOOOOOOOOOOOOPPPPPPPPPPP\n"); |
---|
| 69 | #endif |
---|
| 70 | G4Xt::getInstance () -> SecondaryLoop (); |
---|
| 71 | #ifdef G4DEBUG_VIS_OGL |
---|
[1036] | 72 | printf("G4OpenGLXmViewer::ShowView LOOOOOOOOOOOOOOOPPPPPPPPPPP END\n"); |
---|
[1009] | 73 | #endif |
---|
[1036] | 74 | // } |
---|
| 75 | #ifdef G4DEBUG_VIS_OGL |
---|
| 76 | printf("G4OpenGLXmViewer::Showiew END ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n"); |
---|
| 77 | #endif |
---|
[529] | 78 | } |
---|
| 79 | |
---|
| 80 | void G4OpenGLXmViewer::GetXmConnection () { |
---|
| 81 | |
---|
| 82 | G4Xt* interactorManager = G4Xt::getInstance (); |
---|
| 83 | toplevel = (Widget)interactorManager->GetMainInteractor(); |
---|
| 84 | app = XtWidgetToApplicationContext(toplevel); |
---|
| 85 | |
---|
| 86 | if (!toplevel) { |
---|
| 87 | fViewId = -1; // This flags an error. |
---|
| 88 | G4cerr << "G4OpenGLXmViewer::GetXmConnection unable to Initialize" |
---|
| 89 | " application context." << G4endl; |
---|
| 90 | return; |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | // Better to put this in an X11 resource file !!! |
---|
| 94 | std::ostringstream oss; |
---|
| 95 | oss << |
---|
| 96 | "*glxarea*width: " << fVP.GetWindowSizeHintX() << "\n" |
---|
| 97 | "*glxarea*height: " << fVP.GetWindowSizeHintY() << "\n" |
---|
| 98 | /* |
---|
| 99 | // Tried this as a replacement for the above two lines, but |
---|
| 100 | // sub-windows (rotation, etc.) came same size!! |
---|
| 101 | "*geometry: " << fVP.GetXGeometryString() << "\n" |
---|
| 102 | */ |
---|
| 103 | "*frame*x: 10\n" |
---|
| 104 | "*frame*y: 10\n" |
---|
| 105 | "*frame*topOffset: 10\n" |
---|
| 106 | "*frame*bottomOffset: 10\n" |
---|
| 107 | "*frame*rightOffset: 10\n" |
---|
| 108 | "*frame*leftOffset: 10\n" |
---|
| 109 | "*frame*shadowType: SHADOW_IN\n" |
---|
| 110 | "*frame*useColorObj: False\n" |
---|
| 111 | "*frame*primaryColorSetId: 3\n" |
---|
| 112 | "*frame*secondaryColorSetId: 3\n" |
---|
| 113 | "*menubar*useColorObj: False\n" |
---|
| 114 | "*menubar*primaryColorSetId: 3\n" |
---|
| 115 | "*menubar*secondaryColorSetId: 3\n" |
---|
| 116 | "*toplevel*useColorObj: False\n" |
---|
| 117 | "*toplevel*primaryColorSetId: 3\n" |
---|
| 118 | "*toplevel*secondaryColorSetId: 3\n"; |
---|
| 119 | interactorManager->PutStringInResourceDatabase ((char*)oss.str().c_str()); |
---|
| 120 | |
---|
| 121 | // interactorManager->AddSecondaryLoopPostAction ((G4SecondaryLoopAction)G4OpenGLXmViewerSecondaryLoopPostAction); |
---|
| 122 | |
---|
| 123 | shell = XtAppCreateShell ((String)fName.data(),(String)fName.data(),topLevelShellWidgetClass,XtDisplay(toplevel),NULL,0); |
---|
| 124 | interactorManager->AddShell (shell); |
---|
| 125 | |
---|
| 126 | dpy = XtDisplay (shell); |
---|
| 127 | |
---|
| 128 | if (!dpy) { |
---|
| 129 | fViewId = -1; // This flags an error. |
---|
| 130 | G4cerr << "G4OpenGLXmViewer::GetXmConnection unable to connect to display." |
---|
| 131 | << G4endl; |
---|
| 132 | return; |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | if (!glXQueryExtension (dpy, &errorBase, &eventBase)) { |
---|
| 136 | fViewId = -1; // This flags an error. |
---|
| 137 | G4cerr << "G4OpenGLXmViewer::GetXmConnection. X Server has no GLX extension." |
---|
| 138 | << G4endl;; |
---|
| 139 | return; |
---|
| 140 | } |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | void G4OpenGLXmViewer::CreateMainWindow () { |
---|
| 144 | |
---|
| 145 | bgnd = XWhitePixelOfScreen (XtScreen(shell)); |
---|
| 146 | borcol = XBlackPixelOfScreen (XtScreen(shell)); |
---|
| 147 | |
---|
[898] | 148 | G4int x_origin = fVP.GetWindowAbsoluteLocationHintX(DisplayWidth(dpy, vi -> screen)); |
---|
[912] | 149 | |
---|
| 150 | // FIXME, screen size != window size on MAC, but I don't know have to get the menuBar |
---|
| 151 | // size on MAC. L.Garnier 01/2009 |
---|
[898] | 152 | G4int y_origin = fVP.GetWindowAbsoluteLocationHintY(DisplayHeight(dpy, vi -> screen)); |
---|
| 153 | |
---|
[912] | 154 | if (fVP.IsWindowSizeHintX () && fVP.IsWindowLocationHintX () && fVP.IsWindowLocationHintY ()) { |
---|
| 155 | XtVaSetValues (shell, |
---|
| 156 | XtNvisual, vi -> visual, |
---|
| 157 | XtNdepth, vi -> depth, |
---|
| 158 | XtNcolormap, cmap, |
---|
[1037] | 159 | XtNwidth, getWinWidth(), |
---|
| 160 | XtNheight, getWinHeight(), |
---|
[912] | 161 | XtNx, x_origin, |
---|
| 162 | XtNy, y_origin, |
---|
| 163 | XtNborderColor, &borcol, |
---|
| 164 | XtNbackground, &bgnd, |
---|
| 165 | XmNtitle, fName.data(), |
---|
| 166 | NULL); |
---|
| 167 | } else if (fVP.IsWindowSizeHintX () && !(fVP.IsWindowLocationHintX () || fVP.IsWindowLocationHintY ())) { |
---|
| 168 | XtVaSetValues (shell, |
---|
| 169 | XtNvisual, vi -> visual, |
---|
| 170 | XtNdepth, vi -> depth, |
---|
| 171 | XtNcolormap, cmap, |
---|
[1037] | 172 | XtNwidth, getWinWidth(), |
---|
| 173 | XtNheight, getWinHeight(), |
---|
[912] | 174 | XtNborderColor, &borcol, |
---|
| 175 | XtNbackground, &bgnd, |
---|
| 176 | XmNtitle, fName.data(), |
---|
| 177 | NULL); |
---|
| 178 | } else if ((!fVP.IsWindowSizeHintX ()) && fVP.IsWindowLocationHintX () && fVP.IsWindowLocationHintY ()) { |
---|
| 179 | XtVaSetValues (shell, |
---|
| 180 | XtNvisual, vi -> visual, |
---|
| 181 | XtNdepth, vi -> depth, |
---|
| 182 | XtNcolormap, cmap, |
---|
| 183 | XtNx, x_origin, |
---|
| 184 | XtNy, y_origin, |
---|
| 185 | XtNborderColor, &borcol, |
---|
| 186 | XtNbackground, &bgnd, |
---|
| 187 | XmNtitle, fName.data(), |
---|
| 188 | NULL); |
---|
| 189 | } else { |
---|
| 190 | XtVaSetValues (shell, |
---|
| 191 | XtNvisual, vi -> visual, |
---|
| 192 | XtNdepth, vi -> depth, |
---|
| 193 | XtNcolormap, cmap, |
---|
| 194 | XtNborderColor, &borcol, |
---|
| 195 | XtNbackground, &bgnd, |
---|
| 196 | XmNtitle, fName.data(), |
---|
| 197 | NULL); |
---|
| 198 | } |
---|
[529] | 199 | |
---|
[912] | 200 | |
---|
[529] | 201 | main_win = XtVaCreateManagedWidget ("main_win", |
---|
| 202 | xmMainWindowWidgetClass, |
---|
| 203 | shell, |
---|
| 204 | XtNvisual, vi -> visual, |
---|
| 205 | XtNdepth, vi -> depth, |
---|
| 206 | XtNcolormap, cmap, |
---|
| 207 | XtNborderColor, borcol, |
---|
| 208 | XtNbackground, bgnd, |
---|
| 209 | NULL); |
---|
| 210 | |
---|
| 211 | //*********Create a menu bar for the window******** |
---|
| 212 | style_str = XmStringCreateLocalized ((char*)"Style"); |
---|
| 213 | actions_str = XmStringCreateLocalized ((char*)"Actions"); |
---|
| 214 | misc_str = XmStringCreateLocalized ((char*)"Miscellany"); |
---|
| 215 | spec_str = XmStringCreateLocalized ((char*)"Special"); |
---|
| 216 | |
---|
| 217 | menubar = XmVaCreateSimpleMenuBar (main_win, |
---|
| 218 | (char*)"menubar", |
---|
| 219 | XmVaCASCADEBUTTON, style_str, 'S', |
---|
| 220 | XmVaCASCADEBUTTON, actions_str, 'A', |
---|
| 221 | XmVaCASCADEBUTTON, misc_str, 'M', |
---|
| 222 | XmVaCASCADEBUTTON, spec_str, 'p', |
---|
| 223 | XtNvisual, vi -> visual, |
---|
| 224 | XtNdepth, vi -> depth, |
---|
| 225 | XtNcolormap, cmap, |
---|
| 226 | XtNborderColor, borcol, |
---|
| 227 | XtNbackground, bgnd, |
---|
| 228 | NULL); |
---|
| 229 | |
---|
| 230 | XmStringFree (style_str); |
---|
| 231 | XmStringFree (actions_str); |
---|
| 232 | XmStringFree (misc_str); |
---|
| 233 | XmStringFree (spec_str); |
---|
| 234 | |
---|
| 235 | G4cout << "Created menubar" << G4endl; |
---|
| 236 | |
---|
| 237 | |
---|
| 238 | //*********Create style pulldown menu on menubar********* |
---|
| 239 | rep_str = XmStringCreateLocalized ((char*)"Representation"); |
---|
| 240 | draw_str = XmStringCreateLocalized ((char*)"Drawing"); |
---|
| 241 | bgnd_str = XmStringCreateLocalized ((char*)"Background color"); |
---|
| 242 | |
---|
| 243 | style_cascade = XmVaCreateSimplePulldownMenu |
---|
| 244 | (menubar, |
---|
| 245 | (char*)"style", |
---|
| 246 | 0, |
---|
| 247 | NULL, |
---|
| 248 | XmVaCASCADEBUTTON, rep_str, 'R', |
---|
| 249 | XmVaCASCADEBUTTON, draw_str, 'D', |
---|
| 250 | XmVaCASCADEBUTTON, bgnd_str, 'B', |
---|
| 251 | XtNvisual, vi -> visual, |
---|
| 252 | XtNdepth, vi -> depth, |
---|
| 253 | XtNcolormap, cmap, |
---|
| 254 | XtNborderColor, borcol, |
---|
| 255 | XtNbackground, bgnd, |
---|
| 256 | NULL); |
---|
| 257 | |
---|
| 258 | XmStringFree (rep_str); |
---|
| 259 | XmStringFree (draw_str); |
---|
| 260 | XmStringFree (bgnd_str); |
---|
| 261 | |
---|
| 262 | // G4cout << "Created Style pulldown menu" << G4endl; |
---|
| 263 | |
---|
| 264 | //Add Representation pullright menu to style cascade... |
---|
| 265 | polyhedron_str = XmStringCreateLocalized ((char*)"Polyhedron"); |
---|
| 266 | nurbs_str = XmStringCreateLocalized ((char*)"NURBS"); |
---|
| 267 | |
---|
| 268 | rep_style_pullright = XmVaCreateSimplePulldownMenu |
---|
| 269 | (style_cascade, |
---|
| 270 | (char*)"rep_style", |
---|
| 271 | 0, |
---|
| 272 | rep_style_callback, |
---|
| 273 | XmVaRADIOBUTTON, polyhedron_str, 'P', NULL, NULL, |
---|
| 274 | XmVaRADIOBUTTON, nurbs_str, 'N', NULL, NULL, |
---|
| 275 | XmNradioBehavior, True, |
---|
| 276 | XmNradioAlwaysOne, True, |
---|
| 277 | XmNuserData, this, |
---|
| 278 | XtNvisual, vi -> visual, |
---|
| 279 | XtNdepth, vi -> depth, |
---|
| 280 | XtNcolormap, cmap, |
---|
| 281 | XtNborderColor, borcol, |
---|
| 282 | XtNbackground, bgnd, |
---|
| 283 | NULL); |
---|
| 284 | |
---|
| 285 | Widget special_widget; |
---|
| 286 | |
---|
| 287 | G4ViewParameters::RepStyle style; |
---|
| 288 | style = fVP.GetRepStyle(); |
---|
| 289 | |
---|
| 290 | if (style == G4ViewParameters::polyhedron) { |
---|
| 291 | special_widget = XtNameToWidget(rep_style_pullright, "button_0"); |
---|
| 292 | if(special_widget) { |
---|
| 293 | XtVaSetValues (special_widget, XmNset, True, NULL); |
---|
| 294 | } |
---|
| 295 | } else if (style == G4ViewParameters::nurbs) { |
---|
| 296 | special_widget = XtNameToWidget(rep_style_pullright, "button_1"); |
---|
| 297 | if(special_widget) { |
---|
| 298 | XtVaSetValues (special_widget, XmNset, True, NULL); |
---|
| 299 | } |
---|
| 300 | } else { |
---|
| 301 | G4Exception("Invalid Representation style in G4OpenGLXmViewer::CreateContext"); |
---|
| 302 | } |
---|
| 303 | XmStringFree (polyhedron_str); |
---|
| 304 | XmStringFree (nurbs_str); |
---|
| 305 | |
---|
| 306 | // G4cout << "Created Representation pulldown menu" << G4endl; |
---|
| 307 | |
---|
| 308 | //Add Drawing pullright menu to style cascade... |
---|
| 309 | wireframe_str = XmStringCreateLocalized ((char*)"Wireframe"); |
---|
| 310 | hlr_str = XmStringCreateLocalized ((char*)"Hidden line removal"); |
---|
| 311 | hsr_str = XmStringCreateLocalized ((char*)"Hidden surface removal"); |
---|
| 312 | hlhsr_str = XmStringCreateLocalized ((char*)"Hidden line and surface removal"); |
---|
| 313 | |
---|
| 314 | drawing_style_pullright = XmVaCreateSimplePulldownMenu |
---|
| 315 | (style_cascade, |
---|
| 316 | (char*)"drawing_style", |
---|
| 317 | 1, |
---|
| 318 | drawing_style_callback, |
---|
| 319 | XmVaRADIOBUTTON, wireframe_str, 'W', NULL, NULL, |
---|
| 320 | XmVaRADIOBUTTON, hlr_str, 'L', NULL, NULL, |
---|
| 321 | XmVaRADIOBUTTON, hsr_str, 'S', NULL, NULL, |
---|
| 322 | XmVaRADIOBUTTON, hlhsr_str, 'H', NULL, NULL, |
---|
| 323 | XmNradioBehavior, True, |
---|
| 324 | XmNradioAlwaysOne, True, |
---|
| 325 | XmNuserData, this, |
---|
| 326 | XtNvisual, vi -> visual, |
---|
| 327 | XtNdepth, vi -> depth, |
---|
| 328 | XtNcolormap, cmap, |
---|
| 329 | XtNborderColor, borcol, |
---|
| 330 | XtNbackground, bgnd, |
---|
| 331 | NULL); |
---|
| 332 | |
---|
| 333 | G4ViewParameters::DrawingStyle d_style; |
---|
| 334 | d_style = fVP.GetDrawingStyle(); |
---|
| 335 | |
---|
| 336 | if (d_style == G4ViewParameters::wireframe) { |
---|
| 337 | special_widget = XtNameToWidget(drawing_style_pullright, "button_0"); |
---|
| 338 | if(special_widget) { |
---|
| 339 | XtVaSetValues (special_widget, XmNset, True, NULL); |
---|
| 340 | } |
---|
| 341 | } else if (d_style == G4ViewParameters::hlr) { |
---|
| 342 | special_widget = XtNameToWidget(drawing_style_pullright, "button_1"); |
---|
| 343 | if(special_widget) { |
---|
| 344 | XtVaSetValues (special_widget, XmNset, True, NULL); |
---|
| 345 | } |
---|
| 346 | } else if (d_style == G4ViewParameters::hsr) { |
---|
| 347 | special_widget = XtNameToWidget(drawing_style_pullright, "button_2"); |
---|
| 348 | if(special_widget) { |
---|
| 349 | XtVaSetValues (special_widget, XmNset, True, NULL); |
---|
| 350 | } |
---|
| 351 | } else if (d_style == G4ViewParameters::hlhsr) { |
---|
| 352 | special_widget = XtNameToWidget(drawing_style_pullright, "button_3"); |
---|
| 353 | if(special_widget) { |
---|
| 354 | XtVaSetValues (special_widget, XmNset, True, NULL); |
---|
| 355 | } |
---|
| 356 | } else { |
---|
| 357 | G4Exception("Invalid Drawing style in G4OpenGLXmViewer::CreateContext"); |
---|
| 358 | } |
---|
| 359 | |
---|
| 360 | XmStringFree (wireframe_str); |
---|
| 361 | XmStringFree (hlr_str); |
---|
| 362 | XmStringFree (hsr_str); |
---|
| 363 | XmStringFree (hlhsr_str); |
---|
| 364 | |
---|
| 365 | // G4cout << "Created Drawing pullright menu" << G4endl; |
---|
| 366 | |
---|
| 367 | //Add Drawing pullright menu to style cascade... |
---|
| 368 | white_str = XmStringCreateLocalized ((char*)"White"); |
---|
| 369 | black_str = XmStringCreateLocalized ((char*)"Black"); |
---|
| 370 | |
---|
| 371 | background_color_pullright = XmVaCreateSimplePulldownMenu |
---|
| 372 | (style_cascade, |
---|
| 373 | (char*)"background_color", |
---|
| 374 | 2, |
---|
| 375 | background_color_callback, |
---|
| 376 | XmVaRADIOBUTTON, white_str, 'W', NULL, NULL, |
---|
| 377 | XmVaRADIOBUTTON, black_str, 'B', NULL, NULL, |
---|
| 378 | XmNradioBehavior, True, |
---|
| 379 | XmNradioAlwaysOne, True, |
---|
| 380 | XmNuserData, this, |
---|
| 381 | XtNvisual, vi -> visual, |
---|
| 382 | XtNdepth, vi -> depth, |
---|
| 383 | XtNcolormap, cmap, |
---|
| 384 | XtNborderColor, borcol, |
---|
| 385 | XtNbackground, bgnd, |
---|
| 386 | NULL); |
---|
| 387 | |
---|
| 388 | if (background.GetRed() == 1. && |
---|
| 389 | background.GetGreen() == 1. && |
---|
| 390 | background.GetBlue() == 1.) { |
---|
| 391 | special_widget = XtNameToWidget(background_color_pullright, "button_0"); |
---|
| 392 | if(special_widget) { |
---|
| 393 | XtVaSetValues (special_widget, XmNset, True, NULL); |
---|
| 394 | } |
---|
| 395 | } else { |
---|
| 396 | special_widget = XtNameToWidget(background_color_pullright, "button_1"); |
---|
| 397 | if(special_widget) { |
---|
| 398 | XtVaSetValues (special_widget, XmNset, True, NULL); |
---|
| 399 | } |
---|
| 400 | } |
---|
| 401 | |
---|
| 402 | XmStringFree (white_str); |
---|
| 403 | XmStringFree (black_str); |
---|
| 404 | |
---|
| 405 | // G4cout << "Created Background color pullright menu" << G4endl; |
---|
| 406 | |
---|
| 407 | //*********Create actions pulldown menu on menubar********* |
---|
| 408 | rot_str = XmStringCreateLocalized ((char*)"Rotation control panel"); |
---|
| 409 | pan_str = XmStringCreateLocalized ((char*)"Panning control panel"); |
---|
| 410 | set_str = XmStringCreateLocalized ((char*)"Set control panel limits"); |
---|
| 411 | |
---|
| 412 | actions_cascade = XmVaCreateSimplePulldownMenu |
---|
| 413 | (menubar, |
---|
| 414 | (char*)"actions", |
---|
| 415 | 1, |
---|
| 416 | actions_callback, |
---|
| 417 | XmVaPUSHBUTTON, rot_str, 'R', NULL, NULL, |
---|
| 418 | XmVaPUSHBUTTON, pan_str, 'P', NULL, NULL, |
---|
| 419 | XmVaPUSHBUTTON, set_str, 'S', NULL, NULL, |
---|
| 420 | XmNuserData, this, |
---|
| 421 | XtNvisual, vi -> visual, |
---|
| 422 | XtNdepth, vi -> depth, |
---|
| 423 | XtNcolormap, cmap, |
---|
| 424 | XtNborderColor, borcol, |
---|
| 425 | XtNbackground, bgnd, |
---|
| 426 | NULL); |
---|
| 427 | |
---|
| 428 | XmStringFree (rot_str); |
---|
| 429 | XmStringFree (pan_str); |
---|
| 430 | XmStringFree (set_str); |
---|
| 431 | G4cout << "Created Actions pulldown menu" << G4endl; |
---|
| 432 | |
---|
| 433 | misc_str = XmStringCreateLocalized ((char*)"Miscellany control panel"); |
---|
| 434 | exit_str = XmStringCreateLocalized ((char*)"Exit to G4Vis>"); |
---|
| 435 | print_str = XmStringCreateLocalized ((char*)"Create .eps file"); |
---|
| 436 | |
---|
| 437 | //*********Create miscellany pulldown menu on menubar********* |
---|
| 438 | misc_cascade = XmVaCreateSimplePulldownMenu |
---|
| 439 | (menubar, |
---|
| 440 | (char*)"miscellany", |
---|
| 441 | 2, |
---|
| 442 | misc_callback, |
---|
| 443 | XmVaPUSHBUTTON, misc_str, 'M', NULL, NULL, |
---|
| 444 | XmVaPUSHBUTTON, exit_str, 'E', NULL, NULL, |
---|
| 445 | XmVaPUSHBUTTON, print_str, 'P', NULL, NULL, |
---|
| 446 | XmNuserData, this, |
---|
| 447 | XtNvisual, vi -> visual, |
---|
| 448 | XtNdepth, vi -> depth, |
---|
| 449 | XtNcolormap, cmap, |
---|
| 450 | XtNborderColor, borcol, |
---|
| 451 | XtNbackground, bgnd, |
---|
| 452 | NULL); |
---|
| 453 | |
---|
| 454 | XmStringFree (misc_str); |
---|
| 455 | XmStringFree (exit_str); |
---|
| 456 | XmStringFree (print_str); |
---|
| 457 | G4cout << "Created Miscellany pulldown menu" << G4endl; |
---|
| 458 | |
---|
| 459 | trans_str = XmStringCreateLocalized ((char*)"Transparency"); |
---|
| 460 | anti_str = XmStringCreateLocalized ((char*)"Antialiasing"); |
---|
| 461 | halo_str = XmStringCreateLocalized ((char*)"Haloing"); |
---|
| 462 | aux_edge_str = XmStringCreateLocalized ((char*)"Auxiliary edges"); |
---|
| 463 | |
---|
| 464 | //*********Create special pulldown menu on menubar********* |
---|
| 465 | spec_cascade = XmVaCreateSimplePulldownMenu |
---|
| 466 | (menubar, |
---|
| 467 | (char*)"special", |
---|
| 468 | 3, |
---|
| 469 | NULL, |
---|
| 470 | XmVaCASCADEBUTTON, trans_str, 'T', |
---|
| 471 | XmVaCASCADEBUTTON, anti_str, 'A', |
---|
| 472 | XmVaCASCADEBUTTON, halo_str, 'H', |
---|
| 473 | XmVaCASCADEBUTTON, aux_edge_str, 'E', |
---|
| 474 | XtNvisual, vi -> visual, |
---|
| 475 | XtNdepth, vi -> depth, |
---|
| 476 | XtNcolormap, cmap, |
---|
| 477 | XtNborderColor, borcol, |
---|
| 478 | XtNbackground, bgnd, |
---|
| 479 | NULL); |
---|
| 480 | |
---|
| 481 | XmStringFree (trans_str); |
---|
| 482 | XmStringFree (anti_str); |
---|
| 483 | XmStringFree (halo_str); |
---|
| 484 | XmStringFree (aux_edge_str); |
---|
| 485 | |
---|
| 486 | // G4cout << "Created Special pulldown menu" << G4endl; |
---|
| 487 | |
---|
| 488 | //Add Transparency pullright menu to special cascade... |
---|
| 489 | off_str = XmStringCreateLocalized ((char*)"Off"); |
---|
| 490 | on_str = XmStringCreateLocalized ((char*)"On"); |
---|
| 491 | |
---|
| 492 | transparency_pullright = XmVaCreateSimplePulldownMenu |
---|
| 493 | (spec_cascade, |
---|
| 494 | (char*)"transparency", |
---|
| 495 | 0, |
---|
| 496 | transparency_callback, |
---|
| 497 | XmVaRADIOBUTTON, off_str, 'f', NULL, NULL, |
---|
| 498 | XmVaRADIOBUTTON, on_str, 'n', NULL, NULL, |
---|
| 499 | XmNradioBehavior, True, |
---|
| 500 | XmNradioAlwaysOne, True, |
---|
| 501 | XmNuserData, this, |
---|
| 502 | XtNvisual, vi -> visual, |
---|
| 503 | XtNdepth, vi -> depth, |
---|
| 504 | XtNcolormap, cmap, |
---|
| 505 | XtNborderColor, borcol, |
---|
| 506 | XtNbackground, bgnd, |
---|
| 507 | NULL); |
---|
| 508 | |
---|
| 509 | if (transparency_enabled == false) { |
---|
| 510 | special_widget = XtNameToWidget(transparency_pullright, "button_0"); |
---|
| 511 | if(special_widget) { |
---|
| 512 | XtVaSetValues (special_widget, XmNset, True, NULL); |
---|
| 513 | } |
---|
| 514 | } else if (transparency_enabled == true) { |
---|
| 515 | special_widget = XtNameToWidget(transparency_pullright, "button_1"); |
---|
| 516 | if(special_widget) { |
---|
| 517 | XtVaSetValues (special_widget, XmNset, True, NULL); |
---|
| 518 | } |
---|
| 519 | } else { |
---|
| 520 | G4Exception("transparency_enabled in G4OpenGLXmViewer is neither true nor false!!"); |
---|
| 521 | } |
---|
| 522 | |
---|
| 523 | //Add antialias pullright menu to special cascade... |
---|
| 524 | antialias_pullright = XmVaCreateSimplePulldownMenu |
---|
| 525 | (spec_cascade, |
---|
| 526 | (char*)"antialias", |
---|
| 527 | 1, |
---|
| 528 | antialias_callback, |
---|
| 529 | XmVaRADIOBUTTON, off_str, 'f', NULL, NULL, |
---|
| 530 | XmVaRADIOBUTTON, on_str, 'n', NULL, NULL, |
---|
| 531 | XmNradioBehavior, True, |
---|
| 532 | XmNradioAlwaysOne, True, |
---|
| 533 | XmNuserData, this, |
---|
| 534 | XtNvisual, vi -> visual, |
---|
| 535 | XtNdepth, vi -> depth, |
---|
| 536 | XtNcolormap, cmap, |
---|
| 537 | XtNborderColor, borcol, |
---|
| 538 | XtNbackground, bgnd, |
---|
| 539 | NULL); |
---|
| 540 | |
---|
| 541 | if (antialiasing_enabled == false) { |
---|
| 542 | special_widget = XtNameToWidget(antialias_pullright, "button_0"); |
---|
| 543 | if(special_widget) { |
---|
| 544 | XtVaSetValues (special_widget, XmNset, True, NULL); |
---|
| 545 | } |
---|
| 546 | } else if (antialiasing_enabled == true) { |
---|
| 547 | special_widget = XtNameToWidget(antialias_pullright, "button_1"); |
---|
| 548 | if(special_widget) { |
---|
| 549 | XtVaSetValues (special_widget, XmNset, True, NULL); |
---|
| 550 | } |
---|
| 551 | } else { |
---|
| 552 | G4Exception("antialiasing_enabled in G4OpenGLXmViewer is neither true nor false!!"); |
---|
| 553 | } |
---|
| 554 | |
---|
| 555 | //Add Haloing pullright menu to special cascade... |
---|
| 556 | haloing_pullright = XmVaCreateSimplePulldownMenu |
---|
| 557 | (spec_cascade, |
---|
| 558 | (char*)"haloing", |
---|
| 559 | 2, |
---|
| 560 | haloing_callback, |
---|
| 561 | XmVaRADIOBUTTON, off_str, 'f', NULL, NULL, |
---|
| 562 | XmVaRADIOBUTTON, on_str, 'n', NULL, NULL, |
---|
| 563 | XmNradioBehavior, True, |
---|
| 564 | XmNradioAlwaysOne, True, |
---|
| 565 | XmNuserData, this, |
---|
| 566 | XtNvisual, vi -> visual, |
---|
| 567 | XtNdepth, vi -> depth, |
---|
| 568 | XtNcolormap, cmap, |
---|
| 569 | XtNborderColor, borcol, |
---|
| 570 | XtNbackground, bgnd, |
---|
| 571 | NULL); |
---|
| 572 | |
---|
| 573 | if (haloing_enabled == false) { |
---|
| 574 | special_widget = XtNameToWidget(haloing_pullright, "button_0"); |
---|
| 575 | if(special_widget) { |
---|
| 576 | XtVaSetValues (special_widget, XmNset, True, NULL); |
---|
| 577 | } |
---|
| 578 | } else if (haloing_enabled == true) { |
---|
| 579 | special_widget = XtNameToWidget(haloing_pullright, "button_1"); |
---|
| 580 | if(special_widget) { |
---|
| 581 | XtVaSetValues (special_widget, XmNset, True, NULL); |
---|
| 582 | } |
---|
| 583 | } else { |
---|
| 584 | G4Exception("haloing_enabled in G4OpenGLXmViewer is neither true nor false!!"); |
---|
| 585 | } |
---|
| 586 | |
---|
| 587 | //Add Aux_Edge pullright menu to special cascade... |
---|
| 588 | aux_edge_pullright = XmVaCreateSimplePulldownMenu |
---|
| 589 | (spec_cascade, |
---|
| 590 | (char*)"aux_edge", |
---|
| 591 | 3, |
---|
| 592 | aux_edge_callback, |
---|
| 593 | XmVaRADIOBUTTON, off_str, 'f', NULL, NULL, |
---|
| 594 | XmVaRADIOBUTTON, on_str, 'n', NULL, NULL, |
---|
| 595 | XmNradioBehavior, True, |
---|
| 596 | XmNradioAlwaysOne, True, |
---|
| 597 | XmNuserData, this, |
---|
| 598 | XtNvisual, vi -> visual, |
---|
| 599 | XtNdepth, vi -> depth, |
---|
| 600 | XtNcolormap, cmap, |
---|
| 601 | XtNborderColor, borcol, |
---|
| 602 | XtNbackground, bgnd, |
---|
| 603 | NULL); |
---|
| 604 | |
---|
| 605 | if (!fVP.IsAuxEdgeVisible()) { |
---|
| 606 | special_widget = XtNameToWidget(aux_edge_pullright, "button_0"); |
---|
| 607 | if(special_widget) { |
---|
| 608 | XtVaSetValues (special_widget, XmNset, True, NULL); |
---|
| 609 | } |
---|
| 610 | } else { |
---|
| 611 | special_widget = XtNameToWidget(aux_edge_pullright, "button_1"); |
---|
| 612 | if(special_widget) { |
---|
| 613 | XtVaSetValues (special_widget, XmNset, True, NULL); |
---|
| 614 | } |
---|
| 615 | } |
---|
| 616 | |
---|
| 617 | XtManageChild (menubar); |
---|
| 618 | frame = XtVaCreateManagedWidget ((char*)"frame", |
---|
| 619 | xmFrameWidgetClass, main_win, |
---|
| 620 | XtNvisual, vi -> visual, |
---|
| 621 | XtNdepth, vi -> depth, |
---|
| 622 | XtNcolormap, cmap, |
---|
| 623 | XtNborderColor, borcol, |
---|
| 624 | XtNbackground, bgnd, |
---|
| 625 | NULL); |
---|
| 626 | |
---|
| 627 | glxarea = XtVaCreateManagedWidget ((char*)"glxarea", |
---|
| 628 | xmDrawingAreaWidgetClass, |
---|
| 629 | frame, |
---|
| 630 | XtNvisual, vi -> visual, |
---|
| 631 | XtNdepth, vi -> depth, |
---|
| 632 | XtNcolormap, cmap, |
---|
| 633 | XtNborderColor, borcol, |
---|
| 634 | XtNbackground, bgnd, |
---|
| 635 | NULL); |
---|
| 636 | |
---|
| 637 | |
---|
| 638 | XmMainWindowSetAreas (main_win, // main widget, children are specified |
---|
| 639 | menubar, // widget to use as menu bar |
---|
| 640 | NULL, // widget to use as command window |
---|
| 641 | NULL, // widget for horizontal scroll bar |
---|
| 642 | NULL, // widget for vertical scroll bar |
---|
| 643 | frame // widget to be used for work window |
---|
| 644 | ); |
---|
| 645 | |
---|
| 646 | XtRealizeWidget(shell); |
---|
| 647 | |
---|
| 648 | // Once widget is realized (ie, associated with a created X window), we |
---|
| 649 | // can bind the OpenGL rendering context to the window. |
---|
| 650 | |
---|
[976] | 651 | win = XtWindow (glxarea); |
---|
[529] | 652 | |
---|
[976] | 653 | glXMakeCurrent (dpy, win, cx); |
---|
[529] | 654 | |
---|
[906] | 655 | // This should be add AFTER glXMakeCurrent done because it will fire a resizeCallback |
---|
| 656 | XtAddCallback (glxarea, |
---|
[908] | 657 | XmNresizeCallback, |
---|
| 658 | resize_callback, |
---|
| 659 | this); |
---|
[906] | 660 | |
---|
| 661 | XtAddCallback (glxarea, |
---|
| 662 | XmNexposeCallback, |
---|
| 663 | expose_callback, |
---|
| 664 | this); |
---|
| 665 | |
---|
[529] | 666 | } |
---|
| 667 | |
---|
| 668 | G4OpenGLXmViewer::G4OpenGLXmViewer (G4OpenGLSceneHandler& scene): |
---|
| 669 | G4VViewer (scene, -1), |
---|
| 670 | G4OpenGLViewer (scene), |
---|
| 671 | G4OpenGLXViewer (scene), |
---|
| 672 | zoom_high (fVP.GetZoomFactor() * 10.0), |
---|
| 673 | zoom_low (fVP.GetZoomFactor() / 10.0), |
---|
| 674 | dolly_low (fVP.GetDolly() - 1000.0), |
---|
| 675 | dolly_high (fVP.GetDolly() + 1000.0), |
---|
| 676 | fov (0.0), |
---|
| 677 | rot_sens_limit (90.), |
---|
| 678 | pan_sens_limit (100.), |
---|
[593] | 679 | rot_sens (1.), |
---|
[529] | 680 | wob_sens (20.), |
---|
| 681 | original_vp(fVP.GetViewpointDirection()), |
---|
| 682 | frameNo (0), |
---|
| 683 | fprotation_top (0), |
---|
| 684 | fprotation_slider (0), |
---|
| 685 | fppanning_top (0), |
---|
| 686 | fppanning_slider (0), |
---|
| 687 | fpzoom_slider (0), |
---|
| 688 | fpdolly_slider (0), |
---|
| 689 | fpsetting_top (0), |
---|
| 690 | fpmiscellany_top (0), |
---|
| 691 | fpprint_top (0) |
---|
| 692 | { |
---|
| 693 | GetXmConnection (); |
---|
| 694 | if (fViewId < 0) return; |
---|
| 695 | } |
---|
| 696 | |
---|
| 697 | G4OpenGLXmViewer::~G4OpenGLXmViewer () |
---|
| 698 | { |
---|
| 699 | XtDestroyWidget (shell); |
---|
[976] | 700 | win = 0; // ...to avoid XDestroyWindow in G4OpenGLXViewer base class |
---|
[529] | 701 | // because XtDestroyWidget has already destroyed it. |
---|
| 702 | G4Xt::getInstance () ->RemoveShell (shell); |
---|
| 703 | |
---|
| 704 | /****************************** |
---|
| 705 | if (fprotation_top) { |
---|
| 706 | delete fprotation_top; |
---|
| 707 | } |
---|
| 708 | |
---|
| 709 | if (fppanning_top) { |
---|
| 710 | delete fppanning_top; |
---|
| 711 | } |
---|
| 712 | |
---|
| 713 | if (fpsetting_top) { |
---|
| 714 | delete fpsetting_top; |
---|
| 715 | } |
---|
| 716 | |
---|
| 717 | if (fpmiscellany_top) { |
---|
| 718 | delete fpmiscellany_top; |
---|
| 719 | } |
---|
| 720 | ******************************/ |
---|
| 721 | |
---|
| 722 | } |
---|
| 723 | |
---|
| 724 | #endif |
---|