g4dialog
Loading...
Searching...
No Matches
g4dialog_example.cc
Go to the documentation of this file.
1
23// geant4
24#include "G4VisExecutive.hh"
25#include "G4RunManagerFactory.hh"
26
27// g4dialog
28#include "g4dialog.h"
29#include "g4dialog_options.h"
30
31// qt
32#include <QApplication>
33#include <QMainWindow>
34#include <QTimer>
35
43int main(int argc, char* argv[]) {
44 // Initialize options and logging (framework-provided).
45 auto gopts = std::make_shared<GOptions>(argc, argv, g4dialog::defineOptions());
46 auto log = std::make_shared<GLogger>(gopts, SFUNCTION_NAME, G4DIALOG_LOGGER);
47 auto gui = gopts->getSwitch("gui");
48 auto timeout = gopts->getScalarDouble("tt");
49 int ret = EXIT_SUCCESS;
50
51 log->info(0, "Starting g4dialog example...");
52
53 // Optional GUI setup (only if --gui is passed).
54 QApplication* app = nullptr;
55 QMainWindow* window = nullptr;
56
57 if (gui) {
58 log->info(0, "g4dialog", "Running in GUI mode...");
59 app = new QApplication(argc, argv);
60 window = new QMainWindow();
61 window->setWindowTitle(QString::fromUtf8("displayUI example"));
62 }
63
64 // Initialize Geant4 visualization manager so that UI/vis-related commands are available.
65 auto visManager = new G4VisExecutive;
66 visManager->Initialize();
67
68 // If GUI, show the window and run Qt loop.
69 if (gui) {
70 auto* g4dialog = new G4Dialog(gopts, window);
71 window->setCentralWidget(g4dialog);
72 window->show();
73
74 // Quit after timeout (useful for automated testing or demos).
75 QTimer::singleShot(timeout, [] {
76 QCoreApplication::quit(); // stop the event loop
77 });
78
79 ret = QApplication::exec();
80
81 // Explicit cleanup (Qt parent ownership covers most UI elements, but keep this obvious here).
82 delete g4dialog;
83 delete window;
84 delete app;
85 }
86 else {
87 // CLI mode: no Qt loop is started; this path is useful as a smoke test for options/logging setup.
88 log->info(0, "Running g4dialog in command line mode...");
89 }
90
91 // Cleanup Geant4 visualization manager.
92 delete visManager;
93
94 return ret;
95}
Main widget for the G4Dialog module.
Definition g4dialog.h:26
constexpr const char * G4DIALOG_LOGGER
Logger name used by the G4Dialog module.
#define SFUNCTION_NAME
GOptions defineOptions()
Define the command-line and configuration options for the G4Dialog module.
int main(int argc, char *argv[])