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