// // ******************************************************************** // * License and Disclaimer * // * * // * The Geant4 software is copyright of the Copyright Holders of * // * the Geant4 Collaboration. It is provided under the terms and * // * conditions of the Geant4 Software License, included in the file * // * LICENSE and available at http://cern.ch/geant4/license . These * // * include a list of copyright holders. * // * * // * Neither the authors of this software system, nor their employing * // * institutes,nor the agencies providing financial support for this * // * work make any representation or warranty, express or implied, * // * regarding this software system or assume any liability for its * // * use. Please see the license in the file LICENSE and URL above * // * for the full disclaimer and the limitation of liability. * // * * // * This code implementation is the result of the scientific and * // * technical work of the GEANT4 collaboration. * // * By using, copying, modifying or distributing the software (or * // * any work based on the software) you agree to acknowledge its * // * use in resulting scientific publications, and indicate your * // * acceptance of all terms of the Geant4 Software license. * // ******************************************************************** // // // // // John Allison 24th January 1998. #ifndef G4VISEXECUTIVE_ICC #define G4VISEXECUTIVE_ICC // Filter/Model Factories #include "G4HitFilterFactories.hh" #include "G4DigiFilterFactories.hh" #include "G4TrajectoryFilterFactories.hh" #include "G4TrajectoryModelFactories.hh" // Supported drivers... // Not needing external packages or libraries... #include "G4ASCIITree.hh" // no_geant4_module_check #include "G4DAWNFILE.hh" // no_geant4_module_check #include "G4RayTracer.hh" // no_geant4_module_check #include "G4VRML2File.hh" // no_geant4_module_check #include "G4GMocrenFile.hh" // no_geant4_module_check #include "G4ToolsSGOffscreen.hh" // no_geant4_module_check // Needing external packages or libraries... #ifdef G4VIS_USE_OPENGLX #include "G4OpenGLImmediateX.hh" // no_geant4_module_check #include "G4OpenGLStoredX.hh" // no_geant4_module_check #endif #ifdef G4VIS_USE_OPENGLWIN32 #include "G4OpenGLImmediateWin32.hh" // no_geant4_module_check #include "G4OpenGLStoredWin32.hh" // no_geant4_module_check #endif #ifdef G4VIS_USE_OPENGLXM #include "G4OpenGLImmediateXm.hh" // no_geant4_module_check #include "G4OpenGLStoredXm.hh" // no_geant4_module_check #endif #ifdef G4VIS_USE_OPENGLQT #include "G4OpenGLImmediateQt.hh" // no_geant4_module_check #include "G4OpenGLStoredQt.hh" // no_geant4_module_check #endif #ifdef G4VIS_USE_OIX #include "G4OpenInventorX.hh" // no_geant4_module_check #include "G4OpenInventorXtExtended.hh" // no_geant4_module_check #endif #ifdef G4VIS_USE_OIQT #include "G4OpenInventorQt.hh" // no_geant4_module_check #endif #ifdef G4VIS_USE_OIWIN32 #include "G4OpenInventorWin32.hh" // no_geant4_module_check #endif #ifdef G4VIS_USE_RAYTRACERX #include "G4RayTracerX.hh" // no_geant4_module_check #endif #ifdef G4VIS_USE_RAYTRACER_QT #include "G4RayTracerQt.hh" // no_geant4_module_check #endif #ifdef G4VIS_USE_TOOLSSG_X11_GLES #include "G4ToolsSGX11GLES.hh" // no_geant4_module_check #endif #ifdef G4VIS_USE_TOOLSSG_X11_ZB #include "G4ToolsSGX11ZB.hh" // no_geant4_module_check #endif #ifdef G4VIS_USE_TOOLSSG_WINDOWS_GLES #include "G4ToolsSGWindowsGLES.hh" // no_geant4_module_check #endif #ifdef G4VIS_USE_TOOLSSG_WINDOWS_ZB #include "G4ToolsSGWindowsZB.hh" // no_geant4_module_check #endif #ifdef G4VIS_USE_TOOLSSG_XT_GLES #include "G4ToolsSGXtGLES.hh" // no_geant4_module_check #endif #ifdef G4VIS_USE_TOOLSSG_XT_ZB #include "G4ToolsSGXtZB.hh" // no_geant4_module_check #endif #ifdef G4VIS_USE_TOOLSSG_QT_GLES #include "G4ToolsSGQtGLES.hh" // no_geant4_module_check #endif #ifdef G4VIS_USE_TOOLSSG_QT_ZB #include "G4ToolsSGQtZB.hh" // no_geant4_module_check #endif #ifdef G4VIS_USE_VTK #include "G4Vtk.hh" // no_geant4_module_check #include "G4VtkOffscreen.hh" // no_geant4_module_check #undef G4VIS_USE_OPENGLQT #undef G4VIS_USE_OPENGLXM #undef G4VIS_USE_OPENGLX #undef G4VIS_USE_OPENGLWIN32 #endif #ifdef G4VIS_USE_VTK_QT #include "G4VtkQt.hh" // no_geant4_module_check #endif #include "G4UImanager.hh" #include "G4UIsession.hh" #include "G4UIbatch.hh" #include #include #define G4warn G4cout // The inline keyword prevents the compiler making an external // reference even though they cannot actually be inlined since they // are virtual functions. This prevents a "multiple definition" error // if it is included in more than one file. However, as explained in // the class description in G4VisExecutive.hh, it should never be // necessary to #include "G4VisExecutive.hh" in more than one file // since after instantiation the object can be treated as a // G4VisManager. inline G4VisExecutive::G4VisExecutive(int argc, char** argv, const G4String& system, const G4String& verbosityString): G4VisManager(verbosityString), fSelected(false) { fUserArgc = argc; fUserArgv = argv; fUserSpecifiedSystem = system; } inline G4VisExecutive::G4VisExecutive (const G4String& verbosityString): G4VisManager(verbosityString) , fUserArgc(0) // >0 if argc is provided by the user... , fUserArgv(nullptr) , fSelected(false) {} inline const G4String& G4VisExecutive::GetDefaultGraphicsSystemName () { if (fSelected) return fDefaultGraphicsSystemName; if (fUserArgc > 0) SetDefaultsByArgument(fUserSpecifiedSystem); if (!fSelected) SetDefaultsByEnvironment(); if (!fSelected && fUserArgc > 0) SetDefaultsByFile(fUserArgc, fUserArgv); if (!fSelected) { SetDefaultsByBatch(); if (fSelected) { // No UI session // Deal with this later - the user may have specified a system // on the command line - see G4VisCommandSceneHandlerCreate. return fDefaultGraphicsSystemName; } } if (!fSelected) SetDefaultsByBuildFlags(); if (GetVerbosity() >= warnings) { G4warn << "Default graphics system is: " << fDefaultGraphicsSystemName << " (based on " << fDefaultGraphicsSystemBasis << ")." << "\nDefault window size hint is: " << fDefaultXGeometryString << " (based on " << fDefaultXGeometryStringBasis << ")." << "\nNote: Parameters specified on the command line will override these defaults." << "\n Use \"vis/open\" without parameters to get these defaults." << G4endl; } return fDefaultGraphicsSystemName; } inline void G4VisExecutive::SetDefaultsByArgument(const G4String& system) { // 1st priority: selection by G4VisExecutive argument if (!system.empty()) { fDefaultGraphicsSystemName = system; fDefaultGraphicsSystemBasis = "G4VisExecuitive argument"; fSelected = true; } } inline void G4VisExecutive::SetDefaultsByEnvironment() { // 2nd priority: by environment variable if (auto g4env = std::getenv("G4VIS_DEFAULT_DRIVER")) { G4String graphicsSystem, windowSizeHint; std::istringstream iss(g4env); iss >> graphicsSystem >> windowSizeHint; if (!graphicsSystem.empty()) { fDefaultGraphicsSystemName = graphicsSystem; fDefaultGraphicsSystemBasis = "environment G4VIS_DEFAULT_DRIVER"; fSelected = true; } if (!windowSizeHint.empty()) { fDefaultXGeometryString = windowSizeHint; fDefaultXGeometryStringBasis = "environment G4VIS_DEFAULT_DRIVER"; } } } inline void G4VisExecutive::SetDefaultsByFile(int argc, char** argv) { // 3rd priority: in $HOME/.g4session // Find ~/.g4session - simply return if it does not exist const char* home = std::getenv("HOME"); if (home == nullptr) return; G4String homedir = home; #ifndef WIN32 G4String filename = homedir + "/.g4session"; #else G4String filename = homedir + "\\.g4session"; #endif std::ifstream g4session(filename); if (g4session.fail()) return; // Find app name if (argc < 1) return; G4String appInput = argv[0]; G4String appName = ""; size_t islash = appInput.find_last_of("/\\"); if (islash == G4String::npos) appName = appInput; else appName = appInput.substr(islash + 1, appInput.size() - islash - 1); // Scan ~/.g4session G4String line; // First line is the user-chosen default: session, graphics system, windo wize hint G4String applicableSession, applicableGraphicsSystem, applicableWindowSizeHint; std::getline(g4session,line); auto hash = line.find_first_of('#'); line = line.substr(0,hash); std::istringstream iss(line); iss >> applicableSession >> applicableGraphicsSystem >> applicableWindowSizeHint; // Read subsequent lines while (g4session.good()) { G4String app, session, graphicsSystem, windowSizeHint; std::getline(g4session,line); hash = line.find_first_of('#'); line = line.substr(0,hash); std::istringstream iss1(line); iss1 >> app >> session >> graphicsSystem >> windowSizeHint; if (app == appName) { if (!session.empty()) applicableSession = session; // See G4UIExecutive if (!graphicsSystem.empty()) applicableGraphicsSystem = graphicsSystem; if (!windowSizeHint.empty()) applicableWindowSizeHint = windowSizeHint; } } if (!applicableGraphicsSystem.empty()) { fDefaultGraphicsSystemName = applicableGraphicsSystem; fDefaultGraphicsSystemBasis = "~/.g4session"; fSelected = true; } if (!applicableWindowSizeHint.empty()) { fDefaultXGeometryString = applicableWindowSizeHint; fDefaultXGeometryStringBasis = "~/.g4session"; } } inline void G4VisExecutive::SetDefaultsByBatch() { // 4th, special case for batch session G4UIsession* session = G4UImanager::GetUIpointer()->GetBaseSession(); if (session == nullptr // Usual case - pure batch || dynamic_cast(session)) { // From a macro from batch // Actually, in this case, we wish to force the user to specify a driver fDefaultGraphicsSystemName = "NO_UI_SESSION"; fDefaultGraphicsSystemBasis = "no UI session"; fSelected = true; // To prevent any further selection } } inline void G4VisExecutive::SetDefaultsByBuildFlags() { // 5th, by cpp flags #if defined G4VIS_USE_TOOLSSG_QT_GLES || G4VIS_USE_TOOLSSG_X11_GLES ||\ G4VIS_USE_TOOLSSG_XT_GLES || G4VIS_USE_TOOLSSG_WINDOWS_GLES fDefaultGraphicsSystemName = "TSG"; #elif defined G4VIS_USE_OPENGLQT || G4VIS_USE_OPENGLXM ||\ G4VIS_USE_OPENGLX || G4VIS_USE_OPENGLWIN32 fDefaultGraphicsSystemName = "OGL"; #elif defined G4VIS_USE_OI || G4VIS_USE_OIX fDefaultGraphicsSystemName = "OI"; #elif defined G4VIS_USE_VTK || G4VIS_USE_VTK_QT fDefaultGraphicsSystemName = "Vtk"; #elif defined G4VIS_USE_TOOLSSG_QT_ZB || G4VIS_USE_TOOLSSG_X11_ZB ||\ G4VIS_USE_TOOLSSG_XT_ZB || G4VIS_USE_TOOLSSG_WINDOWS_ZB fDefaultGraphicsSystemName = "TSG"; #else // Choose a graphics system not needing external packages or libraries fDefaultGraphicsSystemName = "TSG_OFFSCREEN"; #endif fDefaultGraphicsSystemBasis = "build flags"; fSelected = true; } inline void G4VisExecutive::RegisterGraphicsSystems () { // Graphics Systems not needing external packages or libraries... RegisterGraphicsSystem (new G4ASCIITree); RegisterGraphicsSystem (new G4DAWNFILE); RegisterGraphicsSystem (new G4RayTracer); RegisterGraphicsSystem (new G4VRML2File); RegisterGraphicsSystem (new G4GMocrenFile); G4VGraphicsSystem* tsg_offscreen = new G4ToolsSGOffscreen; RegisterGraphicsSystem(tsg_offscreen); tsg_offscreen->AddNickname("TSG_FILE"); // Graphics systems needing external packages or libraries... // Register OGL family of drivers with their normal names, // super-abbreviated names and fallback names where approproiate. #ifdef G4VIS_USE_OPENGLQT G4VGraphicsSystem* ogliqt = new G4OpenGLImmediateQt; G4VGraphicsSystem* oglsqt = new G4OpenGLStoredQt; RegisterGraphicsSystem(ogliqt); RegisterGraphicsSystem(oglsqt); ogliqt->AddNickname("OGLI"); oglsqt->AddNickname("OGLS"); #endif #ifdef G4VIS_USE_OPENGLXM G4VGraphicsSystem* oglixm = new G4OpenGLImmediateXm; G4VGraphicsSystem* oglsxm = new G4OpenGLStoredXm; RegisterGraphicsSystem(oglixm); RegisterGraphicsSystem(oglsxm); # ifdef G4VIS_USE_OPENGLQT oglixm->AddNickname("OGLIQt_FALLBACK"); oglsxm->AddNickname("OGLSQt_FALLBACK"); # else oglixm->AddNickname("OGLI"); oglsxm->AddNickname("OGLS"); # endif #endif #ifdef G4VIS_USE_OPENGLX G4VGraphicsSystem* oglix = new G4OpenGLImmediateX; G4VGraphicsSystem* oglsx = new G4OpenGLStoredX; RegisterGraphicsSystem(oglix); RegisterGraphicsSystem(oglsx); # ifdef G4VIS_USE_OPENGLQT oglix->AddNickname("OGLIQt_FALLBACK"); oglsx->AddNickname("OGLSQt_FALLBACK"); # endif # ifdef G4VIS_USE_OPENGLXM oglix->AddNickname("OGLIXm_FALLBACK"); oglsx->AddNickname("OGLSXm_FALLBACK"); # endif # if defined(G4VIS_USE_OPENGLQT) || (G4VIS_USE_OPENGLXM) # else oglix->AddNickname("OGLI"); oglsx->AddNickname("OGLS"); # endif #endif #ifdef G4VIS_USE_OPENGLWIN32 G4VGraphicsSystem* ogliwin32 = new G4OpenGLImmediateWin32; G4VGraphicsSystem* oglswin32 = new G4OpenGLStoredWin32; RegisterGraphicsSystem(ogliwin32); RegisterGraphicsSystem(oglswin32); # ifdef G4VIS_USE_OPENGLQT ogliwin32->AddNickname("OGLIQt_FALLBACK"); oglswin32->AddNickname("OGLSQt_FALLBACK"); # else ogliwin32->AddNickname("OGLI"); oglswin32->AddNickname("OGLS"); # endif #endif // Register OI graphics system with super-abbreviated nickname #ifdef G4VIS_USE_OI G4VGraphicsSystem* oi = 0; # ifdef G4VIS_USE_OIX oi = new G4OpenInventorX; # elif defined(G4VIS_USE_OIQT) oi = new G4OpenInventorQt; # elif defined(G4VIS_USE_OIWIN32) oi = new G4OpenInventorWin32; # endif if(oi) { RegisterGraphicsSystem(oi); oi->AddNickname("OI"); } #endif // The new, extended OI is registered separately for now. #ifdef G4VIS_USE_OIX RegisterGraphicsSystem(new G4OpenInventorXtExtended); #endif #ifdef G4VIS_USE_RAYTRACERX RegisterGraphicsSystem(new G4RayTracerX); #endif #ifdef G4VIS_USE_RAYTRACER_QT RegisterGraphicsSystem(new G4RayTracerQt); #endif #ifdef G4VIS_USE_TOOLSSG_X11_GLES G4VGraphicsSystem* tsg_x11_gles = new G4ToolsSGX11GLES; RegisterGraphicsSystem(tsg_x11_gles); tsg_x11_gles->AddNickname("TSGX11"); #ifdef G4VIS_USE_TOOLSSG_XT_GLES tsg_x11_gles->AddNickname("TSG_XT_GLES_FALLBACK"); #endif #ifdef G4VIS_USE_TOOLSSG_QT_GLES #ifndef G4VIS_USE_TOOLSSG_XT_GLES tsg_x11_gles->AddNickname("TSG_QT_GLES_FALLBACK"); #endif #endif #endif #ifdef G4VIS_USE_TOOLSSG_X11_ZB G4VGraphicsSystem* tsg_x11_zb = new G4ToolsSGX11ZB; RegisterGraphicsSystem(tsg_x11_zb); tsg_x11_zb->AddNickname("TSGX11ZB"); #endif #ifdef G4VIS_USE_TOOLSSG_XT_GLES G4VGraphicsSystem* tsg_xt_gles = new G4ToolsSGXtGLES; RegisterGraphicsSystem(tsg_xt_gles); tsg_xt_gles->AddNickname("TSGXt"); #ifdef G4VIS_USE_TOOLSSG_QT_GLES tsg_xt_gles->AddNickname("TSG_QT_GLES_FALLBACK"); #endif #endif #ifdef G4VIS_USE_TOOLSSG_XT_ZB G4VGraphicsSystem* tsg_xt_zb = new G4ToolsSGXtZB; RegisterGraphicsSystem(tsg_xt_zb); tsg_xt_zb->AddNickname("TSGXtZB"); #endif #ifdef G4VIS_USE_TOOLSSG_QT_GLES G4VGraphicsSystem* tsg_qt_gles = new G4ToolsSGQtGLES; RegisterGraphicsSystem(tsg_qt_gles); tsg_qt_gles->AddNickname("TSGQt"); #endif #ifdef G4VIS_USE_TOOLSSG_QT_ZB G4VGraphicsSystem* tsg_qt_zb = new G4ToolsSGQtZB; RegisterGraphicsSystem(tsg_qt_zb); tsg_qt_zb->AddNickname("TSGQtZB"); #endif #ifdef G4VIS_USE_TOOLSSG_WINDOWS_GLES G4VGraphicsSystem* tsg_windows_gles = new G4ToolsSGWindowsGLES; RegisterGraphicsSystem(tsg_windows_gles); #endif #ifdef G4VIS_USE_TOOLSSG_WINDOWS_ZB G4VGraphicsSystem* tsg_windows_zb = new G4ToolsSGWindowsZB; RegisterGraphicsSystem(tsg_windows_zb); #endif #ifdef G4VIS_USE_TOOLSSG_QT_GLES tsg_qt_gles->AddNickname("TSG"); tsg_qt_gles->AddNickname("OGL"); #ifdef G4VIS_USE_TOOLSSG_QT_ZB tsg_qt_zb->AddNickname("TSGZB"); #endif #elif defined(G4VIS_USE_TOOLSSG_XT_GLES) tsg_xt_gles->AddNickname("TSG"); tsg_xt_gles->AddNickname("OGL"); #ifdef G4VIS_USE_TOOLSSG_XT_ZB tsg_xt_zb->AddNickname("TSGZB"); #endif #elif defined(G4VIS_USE_TOOLSSG_X11_GLES) tsg_x11_gles->AddNickname("TSG"); tsg_x11_gles->AddNickname("OGL"); #ifdef G4VIS_USE_TOOLSSG_X11_ZB tsg_x11_zb->AddNickname("TSGZB"); #endif #elif defined(G4VIS_USE_TOOLSSG_WINDOWS_GLES) tsg_windows_gles->AddNickname("TSG"); tsg_windows_gles->AddNickname("OGL"); #ifdef G4VIS_USE_TOOLSSG_WINDOWS_ZB tsg_windows_zb->AddNickname("TSGZB"); #endif #else #ifdef G4VIS_USE_TOOLSSG_QT_ZB tsg_qt_zb->AddNickname("TSG"); tsg_qt_zb->AddNickname("OGL"); #elif G4VIS_USE_TOOLSSG_WINDOWS_ZB tsg_windows_zb->AddNickname("TSG"); tsg_windows_zb->AddNickname("OGL"); #else tsg_offscreen->AddNickname("TSG"); tsg_offscreen->AddNickname("OGL"); #endif #endif #ifdef G4VIS_USE_VTK if (GetVerbosity() >= startup) { G4cout << " VTK: OpenGL-based drivers suppressed because of compatibility issues." << G4endl; } G4Vtk* vtkN = new G4Vtk(); G4VtkOffscreen* vtkOS = new G4VtkOffscreen(); RegisterGraphicsSystem(vtkN); RegisterGraphicsSystem(vtkOS); # ifdef G4VIS_USE_VTK_QT vtkN->AddNickname("VTKQt_FALLBACK"); # endif #endif #ifdef G4VIS_USE_VTK_QT G4VtkQt* vtkQt = new G4VtkQt(); RegisterGraphicsSystem(vtkQt); vtkQt->AddNickname("VTKQt"); #endif #ifdef G4VIS_USE_VTK_QT vtkQt->AddNickname("Vtk"); vtkQt->AddNickname("VTK"); #elif defined(G4VIS_USE_VTK) vtkN->AddNickname("Vtk"); vtkN->AddNickname("VTK"); #endif } // See comments about inlining above. inline void G4VisExecutive::RegisterModelFactories() { // Trajectory draw models RegisterModelFactory(new G4TrajectoryGenericDrawerFactory()); RegisterModelFactory(new G4TrajectoryDrawByAttributeFactory()); RegisterModelFactory(new G4TrajectoryDrawByChargeFactory()); RegisterModelFactory(new G4TrajectoryDrawByOriginVolumeFactory()); RegisterModelFactory(new G4TrajectoryDrawByParticleIDFactory()); RegisterModelFactory(new G4TrajectoryDrawByEncounteredVolumeFactory()); // Trajectory filter models RegisterModelFactory(new G4TrajectoryAttributeFilterFactory()); RegisterModelFactory(new G4TrajectoryChargeFilterFactory()); RegisterModelFactory(new G4TrajectoryOriginVolumeFilterFactory()); RegisterModelFactory(new G4TrajectoryParticleFilterFactory()); RegisterModelFactory(new G4TrajectoryEncounteredVolumeFilterFactory()); // Hit filter models RegisterModelFactory(new G4HitAttributeFilterFactory()); // Digi filter models RegisterModelFactory(new G4DigiAttributeFilterFactory()); } #endif