g4display
Loading...
Searching...
No Matches
g4display_example.cc
Go to the documentation of this file.
1
17// geant4
18#include "G4VisExecutive.hh"
19#include "G4RunManagerFactory.hh"
20
21// g4display
22#include "g4SceneProperties.h"
23#include "g4display.h"
24#include "g4display_options.h"
25
26// gemc
27#include "glogger.h"
28
29// qt
30#include <QApplication>
31#include <QMainWindow>
32#include <QTimer>
33
34int main(int argc, char* argv[]) {
35 // Initialize options and logging.
36 // GOptions is configured with the g4display option schema, which includes view/camera/dawn/text options.
37 auto gopts = std::make_shared<GOptions>(argc, argv, g4display::defineOptions());
38 auto log = std::make_shared<GLogger>(gopts, SFUNCTION_NAME, G4DISPLAY_LOGGER);
39 auto gui = gopts->getSwitch("gui");
40 auto timeout = gopts->getScalarDouble("tt");
41 int ret = EXIT_SUCCESS;
42
43 log->info(0, "Starting g4display example...");
44
45 // Optional GUI setup (only if --gui is passed).
46 // Qt objects are created dynamically to keep CLI mode lightweight.
47 QApplication* app = nullptr;
48 QMainWindow* window = nullptr;
49
50 if (gui) {
51 log->info(0, "g4display", "Running in GUI mode...");
52 app = new QApplication(argc, argv);
53 window = new QMainWindow();
54 window->setWindowTitle(QString::fromUtf8("g4display example"));
55 }
56
57 // Initialize Geant4 visualization manager.
58 auto visManager = new G4VisExecutive;
59 visManager->Initialize();
60
61 // Build scene properties helper (command list generation based on options).
62 auto g4SceneProperties = new G4SceneProperties(gopts);
63
64 // If GUI, show the window and run Qt loop.
65 if (gui) {
67 auto g4display = new G4Display(gopts, window);
68 window->setCentralWidget(g4display);
69 window->show();
71
72 // Quit after timeout (milliseconds). This allows automated tests/demos without manual close.
73 QTimer::singleShot(timeout, [] {
74 QCoreApplication::quit(); // stop the event loop
75 });
76
77 ret = QApplication::exec();
78
79 // Clean up GUI resources.
80 delete g4display;
81 delete window;
82 delete app;
83 }
84 else {
85 // CLI mode: the example currently only initializes infrastructure and exits.
86 // A future CLI extension could apply g4SceneProperties->scene_commands(...) to the Geant4 UI manager.
87 log->info(0, "Running g4display in command line mode...");
88 }
89
90 delete g4SceneProperties;
91 delete visManager;
92
93 return ret;
94}
Main GUI container for Geant4 visualization controls.
Definition g4display.h:35
Helper for constructing Geant4 visualization command sequences.
Declaration of the G4SceneProperties helper used to initialize Geant4 scene visualization.
Declaration of the G4Display main widget.
Option structures and helpers for g4display configuration.
constexpr const char * G4DISPLAY_LOGGER
#define SFUNCTION_NAME
GOptions defineOptions()
Define the full set of g4display options.
int main(int argc, char *argv[])