G4OpenGLXmViewer.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 //
00029 // 
00030 // Andrew Walkden  10th February 1997
00031 // G4OpenGLXmViewer : Class derived from G4OpenGLXViewer, to provide
00032 //                  (Motif) widget OpenGL functionality for GEANT4.
00033 
00034 #ifdef G4VIS_BUILD_OPENGLXM_DRIVER
00035 
00036 #include "globals.hh"
00037 
00038 #include "G4OpenGLXmViewer.hh"
00039 #include "G4OpenGLSceneHandler.hh"
00040 
00041 #include "G4VisExtent.hh"
00042 #include "G4LogicalVolume.hh"
00043 #include "G4VSolid.hh"
00044 #include "G4Point3D.hh"
00045 #include "G4Normal3D.hh"
00046 
00047 #include "G4Scene.hh"
00048 
00049 #include "G4OpenGLXmSliderBar.hh"
00050 #include "G4OpenGLXmTextField.hh"
00051 
00052 #include "G4Xt.hh"
00053 #include <X11/Shell.h>
00054 #include <Xm/MainW.h>
00055 #include <Xm/Frame.h>
00056 #include <Xm/DrawingA.h>
00057 
00058 #include <sstream>
00059 
00060 void G4OpenGLXmViewer::ShowView () {
00061 
00062   G4Xt::getInstance () -> SecondaryLoop ();
00063 
00064 }
00065 
00066 void G4OpenGLXmViewer::ResetView () {
00067   // reset global parameters
00068   G4OpenGLViewer::ResetView();
00069 
00070   //reset Xm parameteres
00071   zoom_high  = fVP.GetZoomFactor() * 10.0;
00072   zoom_low = fVP.GetZoomFactor() / 10.0;
00073   rot_sens_limit = 90.;
00074   wob_low = 0.;
00075   wob_high = 50.;
00076   wob_sens = 20.;
00077   
00078   bool firstInit = true;
00079   if (GetSceneHandler() != NULL) {
00080     if (GetSceneHandler()->GetScene() != NULL) {
00081       firstInit = false;
00082     }
00083   }
00084   if (firstInit) {
00085     pan_sens_limit = 100.;
00086     fPan_sens = pan_sens_limit / 10.0;
00087     dolly_low  = fVP.GetDolly() - 1000.0;
00088     dolly_high = fVP.GetDolly() + 1000.0;
00089   } else {
00090     fPan_sens = GetSceneHandler()->GetScene()->GetExtent().GetExtentRadius() / 10.0;
00091     pan_sens_limit = GetSceneHandler()->GetScene()->GetExtent().GetExtentRadius();
00092     
00093     dolly_high = GetSceneHandler()->GetScene()->GetExtent().GetExtentRadius();
00094     dolly_low = -(GetSceneHandler()->GetScene()->GetExtent().GetExtentRadius());
00095   }
00096 
00097   UpdateControlPanel ();
00098 
00099 
00100   // FIXME : L.Garnier 12 Oct 2011
00101   // Has also to change the Camera/Object, but tricky to do...  
00102 
00103 }
00104 
00105 
00106 void G4OpenGLXmViewer::GetXmConnection () {
00107   
00108   G4Xt* interactorManager = G4Xt::getInstance ();
00109   toplevel = (Widget)interactorManager->GetMainInteractor();
00110   app      = XtWidgetToApplicationContext(toplevel);
00111 
00112   if (!toplevel) {
00113     fViewId = -1;  // This flags an error.
00114     G4cerr << "G4OpenGLXmViewer::GetXmConnection unable to Initialize"
00115       " application context." << G4endl;
00116     return;
00117   }
00118 
00119   // Better to put this in an X11 resource file !!!
00120   std::ostringstream oss;
00121   oss <<
00122     "*glxarea*width: " << fVP.GetWindowSizeHintX() << "\n"
00123     "*glxarea*height: " << fVP.GetWindowSizeHintY() << "\n"
00124     /*
00125     // Tried this as a replacement for the above two lines, but
00126     // sub-windows (rotation, etc.) came same size!!
00127     "*geometry: " << fVP.GetXGeometryString() << "\n"
00128     */
00129     "*frame*x: 10\n"
00130     "*frame*y: 10\n"
00131     "*frame*topOffset: 10\n"
00132     "*frame*bottomOffset: 10\n"
00133     "*frame*rightOffset: 10\n"
00134     "*frame*leftOffset: 10\n"
00135     "*frame*shadowType: SHADOW_IN\n"
00136     "*frame*useColorObj: False\n"
00137     "*frame*primaryColorSetId: 3\n"
00138     "*frame*secondaryColorSetId: 3\n"
00139     "*menubar*useColorObj: False\n"
00140     "*menubar*primaryColorSetId: 3\n"
00141     "*menubar*secondaryColorSetId: 3\n"
00142     "*toplevel*useColorObj: False\n"
00143     "*toplevel*primaryColorSetId: 3\n"
00144     "*toplevel*secondaryColorSetId: 3\n";
00145   interactorManager->PutStringInResourceDatabase ((char*)oss.str().c_str());
00146 
00147   //  interactorManager->AddSecondaryLoopPostAction ((G4SecondaryLoopAction)G4OpenGLXmViewerSecondaryLoopPostAction);
00148   
00149   shell = XtAppCreateShell ((String)fName.data(),(String)fName.data(),topLevelShellWidgetClass,XtDisplay(toplevel),NULL,0); 
00150   interactorManager->AddShell (shell);
00151 
00152   dpy = XtDisplay (shell);
00153 
00154   if (!dpy) {
00155     fViewId = -1;  // This flags an error.
00156     G4cerr << "G4OpenGLXmViewer::GetXmConnection unable to connect to display."
00157          << G4endl;
00158     return;
00159   }
00160 
00161   if (!glXQueryExtension (dpy, &errorBase, &eventBase)) {
00162     fViewId = -1;  // This flags an error.
00163     G4cerr << "G4OpenGLXmViewer::GetXmConnection. X Server has no GLX extension."
00164          << G4endl;;
00165     return;
00166   }
00167 }
00168 
00169 void G4OpenGLXmViewer::CreateMainWindow () {
00170 
00171   bgnd = XWhitePixelOfScreen (XtScreen(shell));
00172   borcol = XBlackPixelOfScreen (XtScreen(shell));
00173   
00174   ResizeWindow(fVP.GetWindowSizeHintX(),fVP.GetWindowSizeHintY());
00175 
00176   G4int x_origin = fVP.GetWindowAbsoluteLocationHintX(DisplayWidth(dpy, vi -> screen));
00177 
00178   // FIXME,  screen size != window size on MAC, but I don't know have to get the menuBar
00179   // size on MAC. L.Garnier 01/2009
00180   G4int y_origin = fVP.GetWindowAbsoluteLocationHintY(DisplayHeight(dpy, vi -> screen));
00181 
00182   if (fVP.IsWindowSizeHintX () && fVP.IsWindowLocationHintX () && fVP.IsWindowLocationHintY ()) {
00183     XtVaSetValues (shell, 
00184                    XtNvisual, vi -> visual, 
00185                    XtNdepth, vi -> depth,
00186                    XtNcolormap, cmap, 
00187                    XtNwidth, getWinWidth(),
00188                    XtNheight, getWinHeight(),
00189                    XtNx, x_origin,
00190                    XtNy, y_origin,
00191                    XtNborderColor, &borcol,
00192                    XtNbackground, &bgnd,
00193                    XmNtitle, fName.data(),
00194                    NULL);
00195   } else if (fVP.IsWindowSizeHintX () && !(fVP.IsWindowLocationHintX () || fVP.IsWindowLocationHintY ())) {
00196     XtVaSetValues (shell, 
00197                    XtNvisual, vi -> visual, 
00198                    XtNdepth, vi -> depth,
00199                    XtNcolormap, cmap, 
00200                    XtNwidth, getWinWidth(),
00201                    XtNheight, getWinHeight(),
00202                    XtNborderColor, &borcol,
00203                    XtNbackground, &bgnd,
00204                    XmNtitle, fName.data(),
00205                    NULL);
00206   } else if ((!fVP.IsWindowSizeHintX ()) && fVP.IsWindowLocationHintX () && fVP.IsWindowLocationHintY ()) {
00207     XtVaSetValues (shell, 
00208                    XtNvisual, vi -> visual, 
00209                    XtNdepth, vi -> depth,
00210                    XtNcolormap, cmap, 
00211                    XtNx, x_origin,
00212                    XtNy, y_origin,
00213                    XtNborderColor, &borcol,
00214                    XtNbackground, &bgnd,
00215                    XmNtitle, fName.data(),
00216                    NULL);
00217   } else {
00218     XtVaSetValues (shell, 
00219                    XtNvisual, vi -> visual, 
00220                    XtNdepth, vi -> depth,
00221                    XtNcolormap, cmap, 
00222                    XtNborderColor, &borcol,
00223                    XtNbackground, &bgnd,
00224                    XmNtitle, fName.data(),
00225                    NULL);
00226   }
00227 
00228 
00229   main_win = XtVaCreateManagedWidget ("main_win", 
00230                                       xmMainWindowWidgetClass,
00231                                       shell,
00232                                       XtNvisual, vi -> visual, 
00233                                       XtNdepth, vi -> depth, 
00234                                       XtNcolormap, cmap, 
00235                                       XtNborderColor, borcol,
00236                                       XtNbackground, bgnd,
00237                                       NULL);
00238 
00239   //*********Create a menu bar for the window********
00240   style_str = XmStringCreateLocalized ((char*)"Style");
00241   actions_str = XmStringCreateLocalized ((char*)"Actions");
00242   misc_str = XmStringCreateLocalized ((char*)"Miscellany");
00243   spec_str = XmStringCreateLocalized ((char*)"Special");
00244 
00245   menubar = XmVaCreateSimpleMenuBar (main_win,
00246                                      (char*)"menubar",
00247                                      XmVaCASCADEBUTTON, style_str, 'S',
00248                                      XmVaCASCADEBUTTON, actions_str, 'A',
00249                                      XmVaCASCADEBUTTON, misc_str, 'M',
00250                                      XmVaCASCADEBUTTON, spec_str, 'p',
00251                                      XtNvisual, vi -> visual, 
00252                                      XtNdepth, vi -> depth, 
00253                                      XtNcolormap, cmap, 
00254                                      XtNborderColor, borcol,
00255                                      XtNbackground, bgnd,
00256                                      NULL);
00257 
00258   XmStringFree (style_str);
00259   XmStringFree (actions_str);
00260   XmStringFree (misc_str);
00261   XmStringFree (spec_str);
00262 
00263   G4cout << "Created menubar" << G4endl;
00264 
00265 
00266   //*********Create style pulldown menu on menubar*********
00267   rep_str = XmStringCreateLocalized ((char*)"Representation");
00268   draw_str = XmStringCreateLocalized ((char*)"Drawing");
00269   bgnd_str = XmStringCreateLocalized ((char*)"Background color");
00270 
00271   style_cascade = XmVaCreateSimplePulldownMenu
00272     (menubar,
00273      (char*)"style",
00274      0,
00275      NULL,
00276      XmVaCASCADEBUTTON, rep_str, 'R',
00277      XmVaCASCADEBUTTON, draw_str, 'D',
00278      XmVaCASCADEBUTTON, bgnd_str, 'B',
00279      XtNvisual, vi -> visual, 
00280      XtNdepth, vi -> depth, 
00281      XtNcolormap, cmap, 
00282      XtNborderColor, borcol,
00283      XtNbackground, bgnd,
00284      NULL);
00285   
00286   XmStringFree (rep_str);
00287   XmStringFree (draw_str);
00288   XmStringFree (bgnd_str);
00289 
00290   //  G4cout << "Created Style pulldown menu" << G4endl;
00291 
00292   //Add Representation pullright menu to style cascade...
00293   polyhedron_str = XmStringCreateLocalized ((char*)"Polyhedron");
00294   nurbs_str = XmStringCreateLocalized ((char*)"NURBS");
00295 
00296   rep_style_pullright = XmVaCreateSimplePulldownMenu 
00297     (style_cascade,
00298      (char*)"rep_style",
00299      0,
00300      rep_style_callback,
00301      XmVaRADIOBUTTON, polyhedron_str, 'P', NULL, NULL,
00302      XmVaRADIOBUTTON, nurbs_str, 'N', NULL, NULL,
00303      XmNradioBehavior, True, 
00304      XmNradioAlwaysOne, True, 
00305      XmNuserData, this, 
00306      XtNvisual, vi -> visual, 
00307      XtNdepth, vi -> depth, 
00308      XtNcolormap, cmap, 
00309      XtNborderColor, borcol,
00310      XtNbackground, bgnd,
00311      NULL);
00312   
00313   Widget special_widget;
00314 
00315   G4ViewParameters::RepStyle style;
00316   style = fVP.GetRepStyle();
00317   
00318   if (style == G4ViewParameters::polyhedron) {
00319     special_widget = XtNameToWidget(rep_style_pullright, "button_0");
00320     if(special_widget) {
00321       XtVaSetValues (special_widget, XmNset, True, NULL);
00322     }
00323   } else if (style == G4ViewParameters::nurbs) {
00324     special_widget = XtNameToWidget(rep_style_pullright, "button_1");
00325     if(special_widget) {
00326       XtVaSetValues (special_widget, XmNset, True, NULL);
00327     }
00328   } else {
00329     G4Exception
00330       ("G4OpenGLXmViewer::CreateMainWindow",
00331        "opengl2014", FatalException,
00332        "Invalid Representation style");
00333   }
00334   XmStringFree (polyhedron_str);
00335   XmStringFree (nurbs_str);
00336   
00337   //  G4cout << "Created Representation pulldown menu" << G4endl;
00338 
00339   //Add Drawing pullright menu to style cascade...
00340   wireframe_str = XmStringCreateLocalized ((char*)"Wireframe");
00341   hlr_str = XmStringCreateLocalized ((char*)"Hidden line removal");
00342   hsr_str = XmStringCreateLocalized ((char*)"Hidden surface removal");
00343   hlhsr_str = XmStringCreateLocalized ((char*)"Hidden line and surface removal");
00344 
00345   drawing_style_pullright = XmVaCreateSimplePulldownMenu 
00346     (style_cascade,
00347      (char*)"drawing_style",
00348      1,
00349      drawing_style_callback,
00350      XmVaRADIOBUTTON, wireframe_str, 'W', NULL, NULL,
00351      XmVaRADIOBUTTON, hlr_str, 'L', NULL, NULL,
00352      XmVaRADIOBUTTON, hsr_str, 'S', NULL, NULL,
00353      XmVaRADIOBUTTON, hlhsr_str, 'H', NULL, NULL,
00354      XmNradioBehavior, True, 
00355      XmNradioAlwaysOne, True, 
00356      XmNuserData, this,
00357      XtNvisual, vi -> visual, 
00358      XtNdepth, vi -> depth, 
00359      XtNcolormap, cmap, 
00360      XtNborderColor, borcol,
00361      XtNbackground, bgnd,
00362      NULL);
00363   
00364   G4ViewParameters::DrawingStyle d_style;
00365   d_style = fVP.GetDrawingStyle();
00366   
00367   if (d_style == G4ViewParameters::wireframe) {
00368     special_widget = XtNameToWidget(drawing_style_pullright, "button_0");
00369     if(special_widget) {
00370       XtVaSetValues (special_widget, XmNset, True, NULL);
00371     }
00372   } else if (d_style == G4ViewParameters::hlr) {
00373     special_widget = XtNameToWidget(drawing_style_pullright, "button_1");
00374     if(special_widget) {
00375       XtVaSetValues (special_widget, XmNset, True, NULL);
00376     }
00377   } else if (d_style == G4ViewParameters::hsr) {
00378     special_widget = XtNameToWidget(drawing_style_pullright, "button_2");
00379     if(special_widget) {
00380       XtVaSetValues (special_widget, XmNset, True, NULL);
00381     }
00382   } else if (d_style == G4ViewParameters::hlhsr) {
00383     special_widget = XtNameToWidget(drawing_style_pullright, "button_3");
00384     if(special_widget) {
00385       XtVaSetValues (special_widget, XmNset, True, NULL);
00386     }
00387   } else {
00388     G4Exception
00389       ("G4OpenGLXmViewer::CreateMainWindow",
00390        "opengl2015", FatalException,
00391        "Invalid Drawing style in G4OpenGLXmViewer::CreateContext");
00392   }
00393 
00394   XmStringFree (wireframe_str);
00395   XmStringFree (hlr_str);
00396   XmStringFree (hsr_str);
00397   XmStringFree (hlhsr_str);
00398 
00399   //  G4cout << "Created Drawing pullright menu" << G4endl;
00400 
00401   //Add Drawing pullright menu to style cascade...
00402   white_str = XmStringCreateLocalized ((char*)"White");
00403   black_str = XmStringCreateLocalized ((char*)"Black");
00404 
00405   background_color_pullright = XmVaCreateSimplePulldownMenu 
00406     (style_cascade,
00407      (char*)"background_color",
00408      2,
00409      background_color_callback,
00410      XmVaRADIOBUTTON, white_str, 'W', NULL, NULL,
00411      XmVaRADIOBUTTON, black_str, 'B', NULL, NULL,
00412      XmNradioBehavior, True, 
00413      XmNradioAlwaysOne, True, 
00414      XmNuserData, this,
00415      XtNvisual, vi -> visual, 
00416      XtNdepth, vi -> depth, 
00417      XtNcolormap, cmap, 
00418      XtNborderColor, borcol,
00419      XtNbackground, bgnd,
00420      NULL);
00421   
00422   if (background.GetRed() == 1. &&
00423       background.GetGreen() == 1. &&
00424       background.GetBlue() == 1.) {
00425     special_widget = XtNameToWidget(background_color_pullright, "button_0");
00426     if(special_widget) {
00427       XtVaSetValues (special_widget, XmNset, True, NULL);
00428     }
00429   } else {
00430     special_widget = XtNameToWidget(background_color_pullright, "button_1");
00431     if(special_widget) {
00432       XtVaSetValues (special_widget, XmNset, True, NULL);
00433     }
00434   }
00435 
00436   XmStringFree (white_str);
00437   XmStringFree (black_str);
00438 
00439   //  G4cout << "Created Background color pullright menu" << G4endl;
00440 
00441   //*********Create actions pulldown menu on menubar*********
00442   rot_str = XmStringCreateLocalized ((char*)"Rotation control panel");
00443   pan_str = XmStringCreateLocalized ((char*)"Panning control panel");
00444   set_str = XmStringCreateLocalized ((char*)"Set control panel limits");
00445 
00446   actions_cascade = XmVaCreateSimplePulldownMenu
00447     (menubar,
00448      (char*)"actions",
00449      1,
00450      actions_callback,
00451      XmVaPUSHBUTTON, rot_str, 'R', NULL, NULL,
00452      XmVaPUSHBUTTON, pan_str, 'P', NULL, NULL,
00453      XmVaPUSHBUTTON, set_str, 'S', NULL, NULL,
00454      XmNuserData, this, 
00455      XtNvisual, vi -> visual, 
00456      XtNdepth, vi -> depth, 
00457      XtNcolormap, cmap, 
00458      XtNborderColor, borcol,
00459      XtNbackground, bgnd,
00460      NULL);
00461   
00462   XmStringFree (rot_str);
00463   XmStringFree (pan_str);
00464   XmStringFree (set_str);
00465   G4cout << "Created Actions pulldown menu" << G4endl;
00466 
00467   misc_str = XmStringCreateLocalized ((char*)"Miscellany control panel");
00468   exit_str = XmStringCreateLocalized ((char*)"Exit to G4Vis>");
00469   print_str = XmStringCreateLocalized ((char*)"Create .eps file");
00470 
00471   //*********Create miscellany pulldown menu on menubar*********
00472   misc_cascade = XmVaCreateSimplePulldownMenu
00473     (menubar,
00474      (char*)"miscellany",
00475      2,
00476      misc_callback,
00477      XmVaPUSHBUTTON, misc_str, 'M', NULL, NULL,
00478      XmVaPUSHBUTTON, exit_str, 'E', NULL, NULL,
00479      XmVaPUSHBUTTON, print_str, 'P', NULL, NULL,
00480      XmNuserData, this,
00481      XtNvisual, vi -> visual, 
00482      XtNdepth, vi -> depth, 
00483      XtNcolormap, cmap, 
00484      XtNborderColor, borcol,
00485      XtNbackground, bgnd,
00486      NULL);
00487   
00488   XmStringFree (misc_str);
00489   XmStringFree (exit_str);
00490   XmStringFree (print_str);
00491   G4cout << "Created Miscellany pulldown menu" << G4endl;
00492 
00493   trans_str = XmStringCreateLocalized ((char*)"Transparency");
00494   anti_str = XmStringCreateLocalized ((char*)"Antialiasing");
00495   halo_str = XmStringCreateLocalized ((char*)"Haloing");
00496   aux_edge_str = XmStringCreateLocalized ((char*)"Auxiliary edges");
00497 
00498   //*********Create special pulldown menu on menubar*********
00499   spec_cascade = XmVaCreateSimplePulldownMenu
00500     (menubar,
00501      (char*)"special",
00502      3,
00503      NULL,
00504      XmVaCASCADEBUTTON, trans_str, 'T',
00505      XmVaCASCADEBUTTON, anti_str, 'A',
00506      XmVaCASCADEBUTTON, halo_str, 'H',
00507      XmVaCASCADEBUTTON, aux_edge_str, 'E',
00508      XtNvisual, vi -> visual, 
00509      XtNdepth, vi -> depth, 
00510      XtNcolormap, cmap, 
00511      XtNborderColor, borcol,
00512      XtNbackground, bgnd,
00513      NULL);
00514   
00515   XmStringFree (trans_str);
00516   XmStringFree (anti_str);
00517   XmStringFree (halo_str);
00518   XmStringFree (aux_edge_str);
00519 
00520   //  G4cout << "Created Special pulldown menu" << G4endl;
00521 
00522   //Add Transparency pullright menu to special cascade...
00523   off_str = XmStringCreateLocalized ((char*)"Off");
00524   on_str = XmStringCreateLocalized ((char*)"On");
00525 
00526   transparency_pullright = XmVaCreateSimplePulldownMenu 
00527     (spec_cascade,
00528      (char*)"transparency",
00529      0,
00530      transparency_callback,
00531      XmVaRADIOBUTTON, off_str, 'f', NULL, NULL,
00532      XmVaRADIOBUTTON, on_str, 'n', NULL, NULL,
00533      XmNradioBehavior, True, 
00534      XmNradioAlwaysOne, True, 
00535      XmNuserData, this,
00536      XtNvisual, vi -> visual, 
00537      XtNdepth, vi -> depth, 
00538      XtNcolormap, cmap, 
00539      XtNborderColor, borcol,
00540      XtNbackground, bgnd,
00541      NULL);
00542   
00543   if (transparency_enabled == false) {
00544     special_widget = XtNameToWidget(transparency_pullright, "button_0");
00545     if(special_widget) {
00546       XtVaSetValues (special_widget, XmNset, True, NULL);
00547     }
00548   } else if (transparency_enabled == true) {
00549     special_widget = XtNameToWidget(transparency_pullright, "button_1");
00550     if(special_widget) {
00551       XtVaSetValues (special_widget, XmNset, True, NULL);
00552     }
00553   } else {
00554     G4Exception
00555       ("G4OpenGLXmViewer::CreateMainWindow",
00556        "opengl2016", FatalException,
00557        "transparency_enabled in G4OpenGLXmViewer is neither true nor false!!");
00558   }
00559 
00560   //Add antialias pullright menu to special cascade...
00561   antialias_pullright = XmVaCreateSimplePulldownMenu 
00562     (spec_cascade,
00563      (char*)"antialias",
00564      1,
00565      antialias_callback,
00566      XmVaRADIOBUTTON, off_str, 'f', NULL, NULL,
00567      XmVaRADIOBUTTON, on_str, 'n', NULL, NULL,
00568      XmNradioBehavior, True, 
00569      XmNradioAlwaysOne, True, 
00570      XmNuserData, this,
00571      XtNvisual, vi -> visual, 
00572      XtNdepth, vi -> depth, 
00573      XtNcolormap, cmap, 
00574      XtNborderColor, borcol,
00575      XtNbackground, bgnd,
00576      NULL);
00577   
00578   if (antialiasing_enabled == false) {
00579     special_widget = XtNameToWidget(antialias_pullright, "button_0");
00580     if(special_widget) {
00581       XtVaSetValues (special_widget, XmNset, True, NULL);
00582     }
00583   } else if (antialiasing_enabled == true) {
00584     special_widget = XtNameToWidget(antialias_pullright, "button_1");
00585     if(special_widget) {
00586       XtVaSetValues (special_widget, XmNset, True, NULL);
00587     }
00588   } else {
00589     G4Exception
00590       ("G4OpenGLXmViewer::CreateMainWindow",
00591        "opengl2017", FatalException,
00592        "antialiasing_enabled in G4OpenGLXmViewer is neither true nor false!!");
00593   }
00594 
00595   //Add Haloing pullright menu to special cascade...
00596   haloing_pullright = XmVaCreateSimplePulldownMenu 
00597     (spec_cascade,
00598      (char*)"haloing",
00599      2,
00600      haloing_callback,
00601      XmVaRADIOBUTTON, off_str, 'f', NULL, NULL,
00602      XmVaRADIOBUTTON, on_str, 'n', NULL, NULL,
00603      XmNradioBehavior, True, 
00604      XmNradioAlwaysOne, True, 
00605      XmNuserData, this,
00606      XtNvisual, vi -> visual, 
00607      XtNdepth, vi -> depth, 
00608      XtNcolormap, cmap, 
00609      XtNborderColor, borcol,
00610      XtNbackground, bgnd,
00611      NULL);
00612   
00613   if (haloing_enabled == false) {
00614     special_widget = XtNameToWidget(haloing_pullright, "button_0");
00615     if(special_widget) {
00616       XtVaSetValues (special_widget, XmNset, True, NULL);
00617     }
00618   } else if (haloing_enabled == true) {
00619     special_widget = XtNameToWidget(haloing_pullright, "button_1");
00620     if(special_widget) {
00621       XtVaSetValues (special_widget, XmNset, True, NULL);
00622     }
00623   } else {
00624     G4Exception
00625       ("G4OpenGLXmViewer::CreateMainWindow",
00626        "opengl2018", FatalException,
00627        "haloing_enabled in G4OpenGLXmViewer is neither true nor false!!");
00628   }
00629 
00630   //Add Aux_Edge pullright menu to special cascade...
00631   aux_edge_pullright = XmVaCreateSimplePulldownMenu 
00632     (spec_cascade,
00633      (char*)"aux_edge",
00634      3,
00635      aux_edge_callback,
00636      XmVaRADIOBUTTON, off_str, 'f', NULL, NULL,
00637      XmVaRADIOBUTTON, on_str, 'n', NULL, NULL,
00638      XmNradioBehavior, True, 
00639      XmNradioAlwaysOne, True, 
00640      XmNuserData, this,
00641      XtNvisual, vi -> visual, 
00642      XtNdepth, vi -> depth, 
00643      XtNcolormap, cmap, 
00644      XtNborderColor, borcol,
00645      XtNbackground, bgnd,
00646      NULL);
00647   
00648   if (!fVP.IsAuxEdgeVisible()) {
00649     special_widget = XtNameToWidget(aux_edge_pullright, "button_0");
00650     if(special_widget) {
00651       XtVaSetValues (special_widget, XmNset, True, NULL);
00652     }
00653   } else {
00654     special_widget = XtNameToWidget(aux_edge_pullright, "button_1");
00655     if(special_widget) {
00656       XtVaSetValues (special_widget, XmNset, True, NULL);
00657     }
00658   }
00659 
00660   XtManageChild (menubar);
00661   frame = XtVaCreateManagedWidget ((char*)"frame",
00662                                    xmFrameWidgetClass, main_win,
00663                                    XtNvisual, vi -> visual, 
00664                                    XtNdepth, vi -> depth, 
00665                                    XtNcolormap, cmap, 
00666                                    XtNborderColor, borcol,
00667                                    XtNbackground, bgnd,
00668                                    NULL);
00669 
00670   glxarea = XtVaCreateManagedWidget ((char*)"glxarea", 
00671                                      xmDrawingAreaWidgetClass,
00672                                      frame,
00673                                      XtNvisual, vi -> visual, 
00674                                      XtNdepth, vi -> depth, 
00675                                      XtNcolormap, cmap, 
00676                                      XtNborderColor, borcol,
00677                                      XtNbackground, bgnd,
00678                                      NULL);
00679   
00680 
00681   XmMainWindowSetAreas (main_win,  // main widget, children are specified 
00682                         menubar,   // widget to use as menu bar
00683                         NULL,      // widget to use as command window
00684                         NULL,      // widget for horizontal scroll bar
00685                         NULL,      // widget for vertical scroll bar
00686                         frame      // widget to be used for work window
00687                         );
00688 
00689   XtRealizeWidget(shell);
00690   
00691   // Once widget is realized (ie, associated with a created X window), we
00692   // can bind the OpenGL rendering context to the window.
00693 
00694   win = XtWindow (glxarea);
00695 
00696   glXMakeCurrent (dpy, win, cx);
00697 
00698   // This should be add AFTER glXMakeCurrent done because it will fire a resizeCallback
00699   XtAddCallback (glxarea, 
00700                  XmNresizeCallback, 
00701                  resize_callback, 
00702                  this);
00703 
00704   XtAddCallback (glxarea, 
00705                  XmNexposeCallback, 
00706                  expose_callback, 
00707                  this);
00708 
00709 }
00710 
00711 G4OpenGLXmViewer::G4OpenGLXmViewer (G4OpenGLSceneHandler& scene):
00712 G4VViewer (scene, -1),
00713 G4OpenGLViewer (scene),
00714 G4OpenGLXViewer (scene),
00715 fov (0.0),
00716 original_vp(fVP.GetViewpointDirection()),
00717 frameNo (0),
00718 fprotation_top (0),
00719 fprotation_slider (0),
00720 fppanning_top (0),
00721 fppanning_slider (0),
00722 fpzoom_slider (0),
00723 fpdolly_slider (0),
00724 fpsetting_top (0),
00725 fppan_set (0),
00726 fprot_set (0),
00727 fpzoom_upper (0),
00728 fpzoom_lower (0),
00729 fpdolly_upper (0),
00730 fpdolly_lower (0),
00731 fpmiscellany_top (0),
00732 fpwobble_slider (0),
00733 fpprint_top (0)
00734 {
00735   GetXmConnection ();
00736   ResetView();
00737   if (fViewId < 0) return;
00738 }
00739 
00740 
00741 void G4OpenGLXmViewer::UpdateControlPanel () {
00742 
00743   // set new values
00744 
00745   if (fprotation_slider) {
00746     fprotation_slider->SetInitialValue(fRot_sens);
00747     fprotation_slider->SetMaxValue(rot_sens_limit);
00748     fprotation_slider->SetMinValue(0);
00749   }
00750   if (fppanning_slider) {
00751     fppanning_slider->SetInitialValue(fPan_sens);
00752     fppanning_slider->SetMaxValue(pan_sens_limit);
00753     fppanning_slider->SetMinValue(0);
00754   }
00755   if (fpzoom_slider) {
00756     fpzoom_slider->SetInitialValue(fVP.GetZoomFactor());
00757     fpzoom_slider->SetMinValue(zoom_low);
00758     fpzoom_slider->SetMaxValue(zoom_high);
00759   }
00760   if (fpdolly_slider) {
00761     fpdolly_slider->SetInitialValue(fVP.GetDolly());
00762     fpdolly_slider->SetMinValue(dolly_low);
00763     fpdolly_slider->SetMaxValue(dolly_high);
00764   }
00765 
00766   if (fpwobble_slider) {
00767     fpwobble_slider->SetInitialValue(fVP.GetDolly());
00768   }
00769 
00770   if (fppan_set) {
00771     fppan_set->SetValue(pan_sens_limit);
00772   }
00773 
00774   if (fprot_set) {
00775     fprot_set->SetValue(rot_sens_limit);
00776   }
00777 
00778   if (fpzoom_upper) {
00779     fpzoom_upper->SetValue(zoom_high);
00780   }
00781 
00782   if (fpzoom_lower) {
00783     fpzoom_lower->SetValue(zoom_low);
00784   }
00785   if (fpdolly_upper) {
00786     fpdolly_upper->SetValue(dolly_high);
00787   }
00788 
00789   if (fpdolly_lower) {
00790     fpdolly_lower->SetValue(dolly_low);
00791   }
00792 
00793 
00794 }
00795 
00796 
00797 G4OpenGLXmViewer::~G4OpenGLXmViewer ()
00798 {
00799   XtDestroyWidget  (shell);
00800   win = 0; // ...to avoid XDestroyWindow in G4OpenGLXViewer base class
00801   // because XtDestroyWidget has already destroyed it.
00802   G4Xt::getInstance () ->RemoveShell (shell);
00803 
00804 /******************************
00805   if (fprotation_top) {
00806     delete fprotation_top;
00807   }
00808 
00809   if (fppanning_top) {
00810     delete fppanning_top;
00811   }
00812 
00813   if (fpsetting_top) {
00814     delete fpsetting_top;
00815   }
00816 
00817   if (fpmiscellany_top) {
00818     delete fpmiscellany_top;
00819   }
00820 ******************************/
00821 
00822 }
00823 
00824 #endif

Generated on Mon May 27 17:49:11 2013 for Geant4 by  doxygen 1.4.7