g4display
Loading...
Searching...
No Matches
g4display_example.cc
Go to the documentation of this file.
1// geant4
2#include "G4VisExecutive.hh"
3#include "G4RunManagerFactory.hh"
4
5// g4display
6#include "g4SceneProperties.h"
7#include "g4display.h"
8#include "g4display_options.h"
9
10// gemc
11#include "glogger.h"
12
13// qt
14#include <QApplication>
15#include <QMainWindow>
16#include <QTimer>
17
18int main(int argc, char* argv[]) {
19
20 // Initialize options and logging
21 auto gopts = std::make_shared<GOptions>(argc, argv, g4display::defineOptions());
22 auto log = std::make_shared<GLogger>(gopts, SFUNCTION_NAME, G4DISPLAY_LOGGER);
23
24 log->info(0, "Starting g4display example...", gopts);
25
26 // Optional GUI setup (only if --gui is passed)
27 QApplication* app = nullptr;
28 QMainWindow* window = nullptr;
29
30 if (gopts->getSwitch("gui")) {
31 log->info(0, "g4display", "Running in GUI mode...");
32 app = new QApplication(argc, argv);
33 window = new QMainWindow();
34 window->setWindowTitle(QString::fromUtf8("displayUI example"));
35 }
36
37 auto visManager = new G4VisExecutive;
38 visManager->Initialize();
39
40 auto g4SceneProperties = new G4SceneProperties(gopts);
41
42 // If GUI, show the window and run Qt loop
43 if (gopts->getSwitch("gui")) {
44 auto g4display = new G4Display(gopts, window);
45 window->setCentralWidget(g4display);
46 window->show();
47
48 /* ---------- quit after 0.5s ---------- */
49 QTimer::singleShot(500, [] {
50 QCoreApplication::quit(); // stop the event loop
51 });
52
53 int appResult = QApplication::exec();
54
55 // Clean up GUI resources
56 delete g4display;
57 delete window;
58 delete app;
59
60 // Clean up Geant4 and custom logic
61 delete g4SceneProperties;
62 delete visManager;
63
64 return appResult;
65 }
66
67 // CLI mode
68 log->info(0, "Running g4display in command line mode...");
69
70
71 delete g4SceneProperties;
72 delete visManager;
73
74 return EXIT_SUCCESS;
75}
The main widget for controlling Geant4 visualization.
Definition g4display.h:24
Initializes scene properties for the Geant4 visualization.
int main(int argc, char *argv[])
constexpr const char * G4DISPLAY_LOGGER
GOptions defineOptions()