G4OpenGLXmStyleCallbacks.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  16th April 1997
00031 // G4OpenGLXmStyleCallbacks : 
00032 //                       Several callback functions used by
00033 //                       elements of the control panel to
00034 //                       determine how to visualize the view.
00035 
00036 #ifdef G4VIS_BUILD_OPENGLXM_DRIVER
00037 
00038 #include "G4OpenGLXmViewer.hh"
00039 #include "G4SystemOfUnits.hh"
00040 
00041 void G4OpenGLXmViewer::drawing_style_callback (Widget w, 
00042                                              XtPointer clientData, 
00043                                              XtPointer) 
00044 {
00045   G4long choice = (G4long)clientData;
00046   G4OpenGLXmViewer* pView;
00047   XtVaGetValues (XtParent(w),
00048                  XmNuserData, &pView,
00049                  NULL);
00050   G4ViewParameters::DrawingStyle style;
00051 
00052   switch (choice) {
00053     
00054   case 0:
00055     style = G4ViewParameters::wireframe;
00056     break;
00057 
00058   case 1:
00059     style = G4ViewParameters::hlr;
00060     break;
00061 
00062   case 2:
00063     style = G4ViewParameters::hsr;
00064     break;
00065 
00066   case 3:
00067     style = G4ViewParameters::hlhsr;
00068     break;
00069 
00070   default:
00071     style = G4ViewParameters::wireframe;
00072     G4Exception
00073       ("G4OpenGLXmViewer::drawing_style_callback",
00074        "opengl2006", FatalException,
00075        "Unrecognised case in drawing_style_callback.");
00076   }
00077 
00078   pView->fVP.SetDrawingStyle (style);
00079   
00080   pView->SetView ();
00081   pView->ClearView ();
00082   pView->DrawView ();
00083 }
00084 
00085 void G4OpenGLXmViewer::rep_style_callback (Widget w, 
00086                                          XtPointer clientData, 
00087                                          XtPointer) 
00088 {
00089   G4long choice = (G4long)clientData;
00090   G4OpenGLXmViewer* pView;
00091   XtVaGetValues (XtParent(w),
00092                  XmNuserData, &pView,
00093                  NULL);
00094   G4ViewParameters::RepStyle style;
00095 
00096   switch (choice) {
00097     
00098   case 0:
00099     style = G4ViewParameters::polyhedron;
00100     break;
00101 
00102   case 1:
00103     style = G4ViewParameters::nurbs;
00104     break;
00105 
00106   default:
00107     style = G4ViewParameters::polyhedron;
00108     G4Exception
00109       ("G4OpenGLXmViewer::rep_style_callback",
00110        "opengl2007", FatalException,
00111        "Unrecognised case in rep_style_callback.");
00112   }
00113 
00114   pView->fVP.SetRepStyle (style);
00115 
00116   pView->SetView ();
00117   pView->ClearView ();
00118   pView->DrawView ();
00119 }
00120 
00121 void G4OpenGLXmViewer::background_color_callback (Widget w, 
00122                                                 XtPointer clientData, 
00123                                                 XtPointer) 
00124 {
00125   G4long choice = (G4long)clientData;
00126   G4OpenGLXmViewer* pView;
00127   XtVaGetValues (XtParent(w),
00128                  XmNuserData, &pView,
00129                  NULL);
00130 
00131 
00132   //I need to revisit the kernel if the background colour changes and
00133   //hidden line removal is enabled, because hlr drawing utilises the
00134   //background colour in its drawing...
00135   // (Note added by JA 13/9/2005) Background now handled in view
00136   // parameters.  A kernel visit is triggered on change of background.
00137   switch (choice) {
00138     
00139   case 0:
00140     ((G4ViewParameters&)pView->GetViewParameters()).
00141       SetBackgroundColour(G4Colour(1.,1.,1.));  // White
00142     break;
00143 
00144   case 1:
00145     ((G4ViewParameters&)pView->GetViewParameters()).
00146       SetBackgroundColour(G4Colour(0.,0.,0.));  // Black
00147     break;
00148 
00149   default:
00150     G4Exception
00151       ("G4OpenGLXmViewer::background_color_callback",
00152        "opengl2008", FatalException,
00153        "Unrecognised case in background_color_callback.");
00154   }
00155 
00156   pView->SetView ();
00157   pView->ClearView ();
00158   pView->DrawView ();
00159 }
00160 
00161 void G4OpenGLXmViewer::transparency_callback (Widget w, 
00162                                             XtPointer clientData, 
00163                                             XtPointer) 
00164 {
00165   G4long choice = (G4long)clientData;
00166   G4OpenGLXmViewer* pView;
00167   XtVaGetValues (XtParent(w),
00168                  XmNuserData, &pView,
00169                  NULL);
00170 
00171   switch (choice) {
00172     
00173   case 0:
00174     pView->transparency_enabled = false;
00175     break;
00176 
00177   case 1:
00178     pView->transparency_enabled = true;
00179     break;
00180 
00181   default:
00182     G4Exception
00183       ("G4OpenGLXmViewer::transparency_callback",
00184        "opengl2009", FatalException,
00185        "Unrecognised case in transparency_callback.");
00186   }
00187 
00188   pView->SetNeedKernelVisit (true);
00189   pView->SetView ();
00190   pView->ClearView ();
00191   pView->DrawView ();
00192 }
00193 
00194 void G4OpenGLXmViewer::antialias_callback (Widget w, 
00195                                          XtPointer clientData, 
00196                                          XtPointer) 
00197 {
00198   G4long choice = (G4long)clientData;
00199   G4OpenGLXmViewer* pView;
00200   XtVaGetValues (XtParent(w),
00201                  XmNuserData, &pView,
00202                  NULL);
00203 
00204   switch (choice) {
00205     
00206   case 0:
00207     pView->antialiasing_enabled = false;
00208     glDisable (GL_LINE_SMOOTH);
00209     glDisable (GL_POLYGON_SMOOTH);
00210     break;
00211 
00212   case 1:
00213     pView->antialiasing_enabled = true;
00214     glEnable (GL_LINE_SMOOTH);
00215     glHint (GL_LINE_SMOOTH_HINT, GL_NICEST);
00216     glEnable (GL_POLYGON_SMOOTH);
00217     glHint (GL_POLYGON_SMOOTH_HINT, GL_NICEST);
00218     break;
00219 
00220   default:
00221     G4Exception
00222       ("G4OpenGLXmViewer::antialias_callback",
00223        "opengl2010", FatalException,
00224        "Unrecognised case in antialiasing_callback.");
00225   }
00226 
00227   pView->SetView ();
00228   pView->ClearView ();
00229   pView->DrawView ();
00230 }
00231 
00232 void G4OpenGLXmViewer::haloing_callback (Widget w, 
00233                                        XtPointer clientData, 
00234                                        XtPointer) 
00235 {
00236   G4long choice = (G4long)clientData;
00237   G4OpenGLXmViewer* pView;
00238   XtVaGetValues (XtParent(w),
00239                  XmNuserData, &pView,
00240                  NULL);
00241 
00242   switch (choice) {
00243     
00244   case 0:
00245     pView->haloing_enabled = false;
00246     break;
00247 
00248   case 1:
00249     pView->haloing_enabled = true;
00250     break;
00251 
00252   default:
00253     G4Exception
00254       ("G4OpenGLXmViewer::haloing_callback",
00255        "opengl2011", FatalException,
00256        "Unrecognised case in haloing_callback.");
00257   }
00258 
00259   pView->SetView ();
00260   pView->ClearView ();
00261   pView->DrawView ();
00262 }
00263 
00264 void G4OpenGLXmViewer::aux_edge_callback (Widget w, 
00265                                        XtPointer clientData, 
00266                                        XtPointer) 
00267 {
00268   G4long choice = (G4long)clientData;
00269   G4OpenGLXmViewer* pView;
00270   XtVaGetValues (XtParent(w),
00271                  XmNuserData, &pView,
00272                  NULL);
00273 
00274   switch (choice) {
00275     
00276   case 0:
00277     pView->fVP.SetAuxEdgeVisible(false);
00278     break;
00279 
00280   case 1:
00281     pView->fVP.SetAuxEdgeVisible(true);
00282     break;
00283 
00284   default:
00285     G4Exception
00286       ("G4OpenGLXmViewer::aux_edge_callback",
00287        "opengl2012", FatalException,
00288        "Unrecognised case in aux_edge_callback.");
00289   }
00290 
00291   pView->SetNeedKernelVisit (true);
00292   pView->SetView ();
00293   pView->ClearView ();
00294   pView->DrawView ();
00295 }
00296 
00297 void G4OpenGLXmViewer::projection_callback (Widget w, 
00298                                           XtPointer clientData, 
00299                                           XtPointer) 
00300 {
00301   G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*)clientData;
00302 
00303   G4int choice = get_int_userData (w);
00304 
00305   switch (choice) {
00306   case 0:
00307     {
00308       pView->fVP.SetFieldHalfAngle (0.);
00309       break;
00310     }
00311 
00312   case 1:
00313     {
00314       if (pView->fov > 89.5 || pView->fov <= 0.0) {
00315         G4cout << "Field half angle should be 0 < angle <= 89.5 degrees.";
00316         G4cout << G4endl;
00317       }
00318       else {
00319         pView->fVP.SetFieldHalfAngle (pView->fov * deg);
00320       }
00321       break;
00322     }
00323   default:
00324     {
00325       G4Exception
00326         ("G4OpenGLXmViewer::projection_callback",
00327          "opengl2013", FatalException,
00328          "Unrecognised choice made in projection_callback");
00329     }
00330   }
00331 
00332   pView->SetView ();
00333   pView->ClearView ();
00334   pView->DrawView ();
00335 }  
00336 
00337 #endif
00338 

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