File indexing completed on 2025-01-18 09:59:23
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031 #ifndef G4VISEXECUTIVE_ICC
0032 #define G4VISEXECUTIVE_ICC
0033
0034
0035 #include "G4HitFilterFactories.hh"
0036 #include "G4DigiFilterFactories.hh"
0037 #include "G4TrajectoryFilterFactories.hh"
0038 #include "G4TrajectoryModelFactories.hh"
0039
0040
0041
0042 #include "G4ASCIITree.hh" // no_geant4_module_check
0043 #include "G4DAWNFILE.hh" // no_geant4_module_check
0044 #include "G4HepRepFile.hh" // no_geant4_module_check
0045 #include "G4RayTracer.hh" // no_geant4_module_check
0046 #include "G4VRML2File.hh" // no_geant4_module_check
0047 #include "G4GMocrenFile.hh" // no_geant4_module_check
0048 #include "G4ToolsSGOffscreen.hh" // no_geant4_module_check
0049
0050
0051 #ifdef G4VIS_USE_OPENGLX
0052 #include "G4OpenGLImmediateX.hh" // no_geant4_module_check
0053 #include "G4OpenGLStoredX.hh" // no_geant4_module_check
0054 #endif
0055
0056 #ifdef G4VIS_USE_OPENGLWIN32
0057 #include "G4OpenGLImmediateWin32.hh" // no_geant4_module_check
0058 #include "G4OpenGLStoredWin32.hh" // no_geant4_module_check
0059 #endif
0060
0061 #ifdef G4VIS_USE_OPENGLXM
0062 #include "G4OpenGLImmediateXm.hh" // no_geant4_module_check
0063 #include "G4OpenGLStoredXm.hh" // no_geant4_module_check
0064 #endif
0065
0066 #ifdef G4VIS_USE_OPENGLQT
0067 #include "G4OpenGLImmediateQt.hh" // no_geant4_module_check
0068 #include "G4OpenGLStoredQt.hh" // no_geant4_module_check
0069 #endif
0070
0071 #ifdef G4VIS_USE_OIX
0072 #include "G4OpenInventorX.hh" // no_geant4_module_check
0073 #include "G4OpenInventorXtExtended.hh" // no_geant4_module_check
0074 #endif
0075
0076 #ifdef G4VIS_USE_OIQT
0077 #include "G4OpenInventorQt.hh" // no_geant4_module_check
0078 #endif
0079
0080 #ifdef G4VIS_USE_OIWIN32
0081 #include "G4OpenInventorWin32.hh" // no_geant4_module_check
0082 #endif
0083
0084 #ifdef G4VIS_USE_RAYTRACERX
0085 #include "G4RayTracerX.hh" // no_geant4_module_check
0086 #endif
0087
0088 #ifdef G4VIS_USE_QT3D
0089 #include "G4Qt3D.hh" // no_geant4_module_check
0090 #endif
0091
0092 #ifdef G4VIS_USE_TOOLSSG_X11_GLES
0093 #include "G4ToolsSGX11GLES.hh" // no_geant4_module_check
0094 #endif
0095
0096 #ifdef G4VIS_USE_TOOLSSG_X11_ZB
0097 #include "G4ToolsSGX11ZB.hh" // no_geant4_module_check
0098 #endif
0099
0100 #ifdef G4VIS_USE_TOOLSSG_WINDOWS_GLES
0101 #include "G4ToolsSGWindowsGLES.hh" // no_geant4_module_check
0102 #endif
0103
0104 #ifdef G4VIS_USE_TOOLSSG_WINDOWS_ZB
0105 #include "G4ToolsSGWindowsZB.hh" // no_geant4_module_check
0106 #endif
0107
0108 #ifdef G4VIS_USE_TOOLSSG_XT_GLES
0109 #include "G4ToolsSGXtGLES.hh" // no_geant4_module_check
0110 #endif
0111
0112 #ifdef G4VIS_USE_TOOLSSG_XT_ZB
0113 #include "G4ToolsSGXtZB.hh" // no_geant4_module_check
0114 #endif
0115
0116 #ifdef G4VIS_USE_TOOLSSG_QT_GLES
0117 #include "G4ToolsSGQtGLES.hh" // no_geant4_module_check
0118 #endif
0119
0120 #ifdef G4VIS_USE_TOOLSSG_QT_ZB
0121 #include "G4ToolsSGQtZB.hh" // no_geant4_module_check
0122 #endif
0123
0124 #ifdef G4VIS_USE_VTK
0125 #include "G4Vtk.hh" // no_geant4_module_check
0126 #include "G4VtkOffscreen.hh" // no_geant4_module_check
0127 #undef G4VIS_USE_TOOLSSG_X11_GLES
0128 #undef G4VIS_USE_TOOLSSG_XT_GLES
0129 #undef G4VIS_USE_TOOLSSG_QT_GLES
0130 #undef G4VIS_USE_TOOLSSG_WINDOWS_GLES
0131 #undef G4VIS_USE_OPENGLQT
0132 #undef G4VIS_USE_OPENGLXM
0133 #undef G4VIS_USE_OPENGLX
0134 #undef G4VIS_USE_OPENGLWIN32
0135 #endif
0136
0137 #ifdef G4VIS_USE_VTK_QT
0138 #include "G4VtkQt.hh" // no_geant4_module_check
0139 #endif
0140
0141 #if defined (G4VIS_USE_OPENGLQT) || (G4VIS_USE_TOOLSSG_QT_GLES)
0142 #include <QtGlobal>
0143 #endif
0144
0145 #include "G4UImanager.hh"
0146 #include "G4UIsession.hh"
0147 #include "G4UIbatch.hh"
0148
0149 #include <cstdlib>
0150 #include <sstream>
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161 inline
0162 G4VisExecutive::G4VisExecutive(int argc, char** argv, const G4String& system,
0163 const G4String& verbosityString):
0164 G4VisManager(verbosityString),
0165 fSelected(false)
0166 {
0167 if (!fSelected) SetDefaultsByArgument(system);
0168 if (!fSelected) SetDefaultsByEnvironment();
0169 if (!fSelected) SetDefaultsByFile(argc, argv);
0170 if (!fSelected) SetDefaultsByBatch();
0171 if (!fSelected) SetDefaultsByBuildFlags();
0172 }
0173
0174 inline
0175 G4VisExecutive::G4VisExecutive (const G4String& verbosityString):
0176 G4VisManager(verbosityString),
0177 fSelected(false)
0178 {
0179 if (!fSelected) SetDefaultsByEnvironment();
0180 if (!fSelected) SetDefaultsByBatch();
0181 if (!fSelected) SetDefaultsByBuildFlags();
0182 }
0183
0184 inline
0185 void G4VisExecutive::SetDefaultsByArgument(const G4String& system)
0186 {
0187
0188 if (!system.empty()) {
0189 fDefaultGraphicsSystemName = system;
0190 fDefaultGraphicsSystemBasis = "G4VisExecuitive argument";
0191 fSelected = true;
0192 }
0193 }
0194
0195 inline
0196 void G4VisExecutive::SetDefaultsByEnvironment()
0197 {
0198
0199 if (auto g4env = std::getenv("G4VIS_DEFAULT_DRIVER")) {
0200 G4String graphicsSystem, windowSizeHint;
0201 std::istringstream iss(g4env);
0202 iss >> graphicsSystem >> windowSizeHint;
0203 if (!graphicsSystem.empty()) {
0204 fDefaultGraphicsSystemName = graphicsSystem;
0205 fDefaultGraphicsSystemBasis = "environment G4VIS_DEFAULT_DRIVER";
0206 fSelected = true;
0207 }
0208 if (!windowSizeHint.empty()) {
0209 fDefaultXGeometryString = windowSizeHint;
0210 fDefaultXGeometryStringBasis = "environment G4VIS_DEFAULT_DRIVER";
0211 }
0212 }
0213 }
0214
0215 inline
0216 void G4VisExecutive::SetDefaultsByFile(int argc, char** argv)
0217 {
0218
0219
0220
0221 const char* home = std::getenv("HOME");
0222 if (home == nullptr) return;
0223 G4String homedir = home;
0224 #ifndef WIN32
0225 G4String filename = homedir + "/.g4session";
0226 #else
0227 G4String filename = homedir + "\\.g4session";
0228 #endif
0229 std::ifstream g4session(filename);
0230 if (g4session.fail()) return;
0231
0232
0233 if (argc < 1) return;
0234 G4String appInput = argv[0];
0235 G4String appName = "";
0236 size_t islash = appInput.find_last_of("/\\");
0237 if (islash == G4String::npos) appName = appInput;
0238 else appName = appInput.substr(islash + 1, appInput.size() - islash - 1);
0239
0240
0241 G4String line;
0242
0243 G4String applicableSession, applicableGraphicsSystem, applicableWindowSizeHint;
0244 std::getline(g4session,line);
0245 auto hash = line.find_first_of('#'); line = line.substr(0,hash);
0246 std::istringstream iss(line);
0247 iss >> applicableSession >> applicableGraphicsSystem >> applicableWindowSizeHint;
0248
0249 while (g4session.good()) {
0250 G4String app, session, graphicsSystem, windowSizeHint;
0251 std::getline(g4session,line);
0252 hash = line.find_first_of('#'); line = line.substr(0,hash);
0253 std::istringstream iss1(line);
0254 iss1 >> app >> session >> graphicsSystem >> windowSizeHint;
0255 if (app == appName) {
0256 if (!session.empty()) applicableSession = session;
0257 if (!graphicsSystem.empty()) applicableGraphicsSystem = graphicsSystem;
0258 if (!windowSizeHint.empty()) applicableWindowSizeHint = windowSizeHint;
0259 }
0260 }
0261
0262 if (!applicableGraphicsSystem.empty()) {
0263 fDefaultGraphicsSystemName = applicableGraphicsSystem;
0264 fDefaultGraphicsSystemBasis = "~/.g4session";
0265 fSelected = true;
0266 }
0267 if (!applicableWindowSizeHint.empty()) {
0268 fDefaultXGeometryString = applicableWindowSizeHint;
0269 fDefaultXGeometryStringBasis = "~/.g4session";
0270 }
0271 }
0272
0273 inline
0274 void G4VisExecutive::SetDefaultsByBatch()
0275 {
0276
0277 G4UIsession* session = G4UImanager::GetUIpointer()->GetBaseSession();
0278 if (session == nullptr
0279 || dynamic_cast<G4UIbatch*>(session)) {
0280
0281 fDefaultGraphicsSystemName = "TSG_OFFSCREEN";
0282 fDefaultGraphicsSystemBasis = "batch session";
0283 fSelected = true;
0284 }
0285 }
0286
0287 inline
0288 void G4VisExecutive::SetDefaultsByBuildFlags()
0289 {
0290
0291 #if defined G4VIS_USE_OPENGLQT || G4VIS_USE_OPENGLXM ||\
0292 G4VIS_USE_OPENGLX || G4VIS_USE_OPENGLWIN32
0293 fDefaultGraphicsSystemName = "OGL";
0294 #elif defined G4VIS_USE_OI || G4VIS_USE_OIX
0295 fDefaultGraphicsSystemName = "OI";
0296 #elif defined G4VIS_USE_TOOLSSG_QT_GLES || G4VIS_USE_TOOLSSG_X11_GLES ||\
0297 G4VIS_USE_TOOLSSG_XT_GLES || G4VIS_USE_TOOLSSG_WINDOWS_GLES
0298 fDefaultGraphicsSystemName = "TSG";
0299 #elif defined G4VIS_USE_VTK || G4VIS_USE_VTK_QT
0300 fDefaultGraphicsSystemName = "Vtk";
0301 #elif defined G4VIS_USE_TOOLSSG_QT_ZB || G4VIS_USE_TOOLSSG_X11_ZB ||\
0302 G4VIS_USE_TOOLSSG_XT_ZB || G4VIS_USE_TOOLSSG_WINDOWS_ZB
0303 fDefaultGraphicsSystemName = "TSG";
0304 #elif defined G4VIS_USE_QT3D
0305 fDefaultGraphicsSystemName = "Qt3D";
0306 #else
0307
0308 fDefaultGraphicsSystemName = "TSG_OFFSCREEN";
0309 #endif
0310 fDefaultGraphicsSystemBasis = "build flags";
0311 fSelected = true;
0312 }
0313
0314 inline void
0315 G4VisExecutive::RegisterGraphicsSystems () {
0316
0317
0318 RegisterGraphicsSystem (new G4ASCIITree);
0319 RegisterGraphicsSystem (new G4DAWNFILE);
0320 RegisterGraphicsSystem (new G4HepRepFile);
0321 RegisterGraphicsSystem (new G4RayTracer);
0322 RegisterGraphicsSystem (new G4VRML2File);
0323 RegisterGraphicsSystem (new G4GMocrenFile);
0324 RegisterGraphicsSystem (new G4ToolsSGOffscreen);
0325 G4VGraphicsSystem* tsg_offscreen = new G4ToolsSGOffscreen;
0326 RegisterGraphicsSystem(tsg_offscreen);
0327 tsg_offscreen->AddNickname("TSG_FILE");
0328
0329
0330
0331
0332
0333 #ifdef G4VIS_USE_OPENGLQT
0334 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
0335 G4VGraphicsSystem* ogliqt = new G4OpenGLImmediateQt;
0336 G4VGraphicsSystem* oglsqt = new G4OpenGLStoredQt;
0337 RegisterGraphicsSystem(ogliqt);
0338 RegisterGraphicsSystem(oglsqt);
0339 ogliqt->AddNickname("OGLI");
0340 oglsqt->AddNickname("OGL");
0341 oglsqt->AddNickname("OGLS");
0342 #endif
0343 #endif
0344
0345 #ifdef G4VIS_USE_OPENGLXM
0346 G4VGraphicsSystem* oglixm = new G4OpenGLImmediateXm;
0347 G4VGraphicsSystem* oglsxm = new G4OpenGLStoredXm;
0348 RegisterGraphicsSystem(oglixm);
0349 RegisterGraphicsSystem(oglsxm);
0350 # ifdef G4VIS_USE_OPENGLQT
0351 oglixm->AddNickname("OGLIQt_FALLBACK");
0352 oglsxm->AddNickname("OGLSQt_FALLBACK");
0353 # else
0354 oglixm->AddNickname("OGLI");
0355 oglsxm->AddNickname("OGL");
0356 oglsxm->AddNickname("OGLS");
0357 # endif
0358 #endif
0359
0360 #ifdef G4VIS_USE_OPENGLX
0361 G4VGraphicsSystem* oglix = new G4OpenGLImmediateX;
0362 G4VGraphicsSystem* oglsx = new G4OpenGLStoredX;
0363 RegisterGraphicsSystem(oglix);
0364 RegisterGraphicsSystem(oglsx);
0365 # ifdef G4VIS_USE_OPENGLQT
0366 oglix->AddNickname("OGLIQt_FALLBACK");
0367 oglsx->AddNickname("OGLSQt_FALLBACK");
0368 # endif
0369 # ifdef G4VIS_USE_OPENGLXM
0370 oglix->AddNickname("OGLIXm_FALLBACK");
0371 oglsx->AddNickname("OGLSXm_FALLBACK");
0372 # endif
0373 # if defined(G4VIS_USE_OPENGLQT) || (G4VIS_USE_OPENGLXM)
0374 # else
0375 oglix->AddNickname("OGLI");
0376 oglsx->AddNickname("OGL");
0377 oglsx->AddNickname("OGLS");
0378 # endif
0379 #endif
0380
0381 #ifdef G4VIS_USE_OPENGLWIN32
0382 G4VGraphicsSystem* ogliwin32 = new G4OpenGLImmediateWin32;
0383 G4VGraphicsSystem* oglswin32 = new G4OpenGLStoredWin32;
0384 RegisterGraphicsSystem(ogliwin32);
0385 RegisterGraphicsSystem(oglswin32);
0386 # ifdef G4VIS_USE_OPENGLQT
0387 ogliwin32->AddNickname("OGLIQt_FALLBACK");
0388 oglswin32->AddNickname("OGLSQt_FALLBACK");
0389 # else
0390 ogliwin32->AddNickname("OGLI");
0391 oglswin32->AddNickname("OGL");
0392 oglswin32->AddNickname("OGLS");
0393 # endif
0394 #endif
0395
0396
0397 #ifdef G4VIS_USE_OI
0398 G4VGraphicsSystem* oi = 0;
0399 # ifdef G4VIS_USE_OIX
0400 oi = new G4OpenInventorX;
0401 # elif defined(G4VIS_USE_OIQT)
0402 oi = new G4OpenInventorQt;
0403 # elif defined(G4VIS_USE_OIWIN32)
0404 oi = new G4OpenInventorWin32;
0405 # endif
0406 if(oi)
0407 {
0408 RegisterGraphicsSystem(oi);
0409 oi->AddNickname("OI");
0410 }
0411 #endif
0412
0413
0414 #ifdef G4VIS_USE_OIX
0415 RegisterGraphicsSystem(new G4OpenInventorXtExtended);
0416 #endif
0417
0418 #ifdef G4VIS_USE_RAYTRACERX
0419 RegisterGraphicsSystem(new G4RayTracerX);
0420 #endif
0421
0422 #ifdef G4VIS_USE_QT3D
0423 RegisterGraphicsSystem(new G4Qt3D);
0424 #endif
0425
0426 #ifdef G4VIS_USE_TOOLSSG_X11_GLES
0427 G4VGraphicsSystem* tsg_x11_gles = new G4ToolsSGX11GLES;
0428 RegisterGraphicsSystem(tsg_x11_gles);
0429 tsg_x11_gles->AddNickname("TSGX11");
0430 #ifdef G4VIS_USE_TOOLSSG_XT_GLES
0431 tsg_x11_gles->AddNickname("TSG_XT_GLES_FALLBACK");
0432 #endif
0433 #ifdef G4VIS_USE_TOOLSSG_QT_GLES
0434 #ifndef G4VIS_USE_TOOLSSG_XT_GLES
0435 tsg_x11_gles->AddNickname("TSG_QT_GLES_FALLBACK");
0436 #endif
0437 #endif
0438 #endif
0439
0440 #ifdef G4VIS_USE_TOOLSSG_X11_ZB
0441 G4VGraphicsSystem* tsg_x11_zb = new G4ToolsSGX11ZB;
0442 RegisterGraphicsSystem(tsg_x11_zb);
0443 tsg_x11_zb->AddNickname("TSGX11ZB");
0444 #endif
0445
0446 #ifdef G4VIS_USE_TOOLSSG_XT_GLES
0447 G4VGraphicsSystem* tsg_xt_gles = new G4ToolsSGXtGLES;
0448 RegisterGraphicsSystem(tsg_xt_gles);
0449 tsg_xt_gles->AddNickname("TSGXt");
0450 #ifdef G4VIS_USE_TOOLSSG_QT_GLES
0451 tsg_xt_gles->AddNickname("TSG_QT_GLES_FALLBACK");
0452 #endif
0453 #endif
0454
0455 #ifdef G4VIS_USE_TOOLSSG_XT_ZB
0456 G4VGraphicsSystem* tsg_xt_zb = new G4ToolsSGXtZB;
0457 RegisterGraphicsSystem(tsg_xt_zb);
0458 tsg_xt_zb->AddNickname("TSGXtZB");
0459 #endif
0460
0461 #ifdef G4VIS_USE_TOOLSSG_QT_GLES
0462 G4VGraphicsSystem* tsg_qt_gles = new G4ToolsSGQtGLES;
0463 RegisterGraphicsSystem(tsg_qt_gles);
0464 tsg_qt_gles->AddNickname("TSGQt");
0465 #endif
0466
0467 #ifdef G4VIS_USE_TOOLSSG_QT_ZB
0468 G4VGraphicsSystem* tsg_qt_zb = new G4ToolsSGQtZB;
0469 RegisterGraphicsSystem(tsg_qt_zb);
0470 tsg_qt_zb->AddNickname("TSGQtZB");
0471 #endif
0472
0473 #ifdef G4VIS_USE_TOOLSSG_WINDOWS_GLES
0474 G4VGraphicsSystem* tsg_windows_gles = new G4ToolsSGWindowsGLES;
0475 RegisterGraphicsSystem(tsg_windows_gles);
0476 #endif
0477
0478 #ifdef G4VIS_USE_TOOLSSG_WINDOWS_ZB
0479 G4VGraphicsSystem* tsg_windows_zb = new G4ToolsSGWindowsZB;
0480 RegisterGraphicsSystem(tsg_windows_zb);
0481 #endif
0482
0483 #ifdef G4VIS_USE_TOOLSSG_QT_GLES
0484 tsg_qt_gles->AddNickname("TSG");
0485 # if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
0486 if (GetVerbosity() >= startup) {
0487 G4cout << " Qt6: Asking ToolsSG to stand in for OpenGL" << G4endl;
0488 tsg_qt_gles->AddNickname("OGL");
0489 }
0490 # endif
0491 #elif defined(G4VIS_USE_TOOLSSG_XT_GLES)
0492 tsg_xt_gles->AddNickname("TSG");
0493 #elif defined(G4VIS_USE_TOOLSSG_X11_GLES)
0494 tsg_x11_gles->AddNickname("TSG");
0495 #elif defined(G4VIS_USE_TOOLSSG_WINDOWS_GLES)
0496 tsg_windows_gles->AddNickname("TSG");
0497 #else
0498 #ifdef G4VIS_USE_TOOLSSG_QT_ZB
0499 tsg_qt_zb->AddNickname("TSG");
0500 #elif G4VIS_USE_TOOLSSG_WINDOWS_ZB
0501 tsg_windows_zb->AddNickname("TSG");
0502 #else
0503 tsg_offscreen->AddNickname("TSG");
0504 #endif
0505 #endif
0506
0507 #ifdef G4VIS_USE_VTK
0508 if (GetVerbosity() >= startup) {
0509 G4cout
0510 << " VTK: OpenGL-based drivers suppressed because of compatibility issues."
0511 << G4endl;
0512 }
0513 G4Vtk* vtkN = new G4Vtk();
0514 G4VtkOffscreen* vtkOS = new G4VtkOffscreen();
0515 RegisterGraphicsSystem(vtkN);
0516 RegisterGraphicsSystem(vtkOS);
0517 # ifdef G4VIS_USE_VTK_QT
0518 vtkN->AddNickname("VTKQt_FALLBACK");
0519 # endif
0520 #endif
0521
0522 #ifdef G4VIS_USE_VTK_QT
0523 G4VtkQt* vtkQt = new G4VtkQt();
0524 RegisterGraphicsSystem(vtkQt);
0525 vtkQt->AddNickname("VTKQt");
0526 #endif
0527
0528 #ifdef G4VIS_USE_VTK_QT
0529 vtkQt->AddNickname("Vtk");
0530 vtkQt->AddNickname("VTK");
0531 #elif defined(G4VIS_USE_VTK)
0532 vtkN->AddNickname("Vtk");
0533 vtkN->AddNickname("VTK");
0534 #endif
0535 }
0536
0537
0538 inline void
0539 G4VisExecutive::RegisterModelFactories()
0540 {
0541
0542 RegisterModelFactory(new G4TrajectoryGenericDrawerFactory());
0543 RegisterModelFactory(new G4TrajectoryDrawByAttributeFactory());
0544 RegisterModelFactory(new G4TrajectoryDrawByChargeFactory());
0545 RegisterModelFactory(new G4TrajectoryDrawByOriginVolumeFactory());
0546 RegisterModelFactory(new G4TrajectoryDrawByParticleIDFactory());
0547 RegisterModelFactory(new G4TrajectoryDrawByEncounteredVolumeFactory());
0548
0549
0550 RegisterModelFactory(new G4TrajectoryAttributeFilterFactory());
0551 RegisterModelFactory(new G4TrajectoryChargeFilterFactory());
0552 RegisterModelFactory(new G4TrajectoryOriginVolumeFilterFactory());
0553 RegisterModelFactory(new G4TrajectoryParticleFilterFactory());
0554 RegisterModelFactory(new G4TrajectoryEncounteredVolumeFilterFactory());
0555
0556
0557 RegisterModelFactory(new G4HitAttributeFilterFactory());
0558
0559
0560 RegisterModelFactory(new G4DigiAttributeFilterFactory());
0561 }
0562
0563 #endif