Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4Qt.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//
27//
28// L. Garnier
29
30#include "G4Qt.hh"
31
32#include "G4UImanager.hh"
33#include "G4ios.hh"
34
35#include <qapplication.h>
36#include <qwidget.h>
37
38#include <cstdlib>
39#include <cstring>
40
41#ifdef G4VIS_USE_VTK_QT
42# include "QVTKOpenGLNativeWidget.h"
43# include <qsurfaceformat.h>
44#endif
45
46#ifdef TOOLS_USE_GL_VERSION_3_2
47#if QT_VERSION < 0x060000
48# include <qgl.h>
49#else
50 #ifndef G4VIS_USE_VTK_QT
51 #include <qsurfaceformat.h>
52 #endif
53#endif
54#endif
55
56G4Qt* G4Qt::instance = nullptr;
57
58static G4bool QtInited = false;
59
60/***************************************************************************/
62/***************************************************************************/
63/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
64{
65 return G4Qt::getInstance(0, nullptr, (char*)"Geant4");
66}
67/***************************************************************************/
68G4Qt* G4Qt::getInstance(int a_argn, char** a_args, char* a_class)
69/***************************************************************************/
70/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
71{
72 if (instance == nullptr) {
73 instance = new G4Qt(a_argn, a_args, a_class);
74 }
75 return instance;
76}
77/***************************************************************************/
78G4Qt::G4Qt(int a_argn, char** a_args, char* /*a_class */
79)
80/***************************************************************************/
81/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
82{
83 argn = 0;
84 args = nullptr;
85 externalApp = false;
86
87 // Check if Qt already init in another external app
88 if (qApp) {
89 externalApp = true;
90 QtInited = true;
92 SetArguments(a_argn, a_args);
93 }
94 else {
95 if (! QtInited) { // Qt should be Inited once !
96 // Then two cases :
97 // - It is the first time we create G4UI (argc!=0)
98 // -> Inited and register
99 // - It is the first time we create G4VIS (argc == 0)
100 // -> Inited and NOT register
101
102 if (a_argn != 0) {
103 argn = a_argn;
104 args = a_args;
105 }
106 else { // argc = 0
107
108 // FIXME : That's not the good arguments, but I don't know how to get args from other
109 // Interactor. Ex: How to get them from G4Xt ?
110 argn = 1;
111 args = (char**)malloc(1 * sizeof(char*));
112 args[0] = (char*)malloc(10 * sizeof(char));
113 strncpy(args[0], "my_app \0", 9);
114 }
115
116 int* p_argn = (int*)malloc(sizeof(int));
117 *p_argn = argn;
118#ifdef WIN32
119 qApp->setAttribute(Qt::AA_UseDesktopOpenGL);
120#endif
121
122#ifdef G4VIS_USE_VTK_QT
123 QSurfaceFormat::setDefaultFormat(QVTKOpenGLNativeWidget::defaultFormat());
124#endif
125
126#ifdef TOOLS_USE_GL_VERSION_3_2
127 #if QT_VERSION < 0x060000
128 QGLFormat format = QGLFormat::defaultFormat();
129 format.setVersion(3,2);
130 format.setProfile(QGLFormat::CoreProfile);
131 QGLFormat::setDefaultFormat(format);
132 #else
133 #ifndef G4VIS_USE_VTK_QT
134 QSurfaceFormat format = QSurfaceFormat::defaultFormat();
135 format.setVersion(3,2);
136 format.setProfile(QSurfaceFormat::CoreProfile);
137 QSurfaceFormat::setDefaultFormat(format);
138 #endif
139 #endif
140#endif
141
142 new QApplication(*p_argn, args);
143 if (! qApp) {
144 G4UImanager* UImanager = G4UImanager::GetUIpointer();
145 G4int verbose = UImanager->GetVerboseLevel();
146 if (verbose >= 2) {
147 G4cout << "G4Qt : Unable to init Qt." << G4endl;
148 }
149 }
150 else {
151 QtInited = true;
152 if (a_argn != 0) {
153 SetMainInteractor(qApp);
154 }
155 SetArguments(a_argn, a_args);
156 }
157 }
158 }
159 // AddDispatcher ((G4DispatchFunction)XtDispatchEvent);
160
161 /*
162 * On some non-English locale, comma is used for the decimal separator instead of dot
163 * bringing to weird behavior of strtod (string to double) function in user application.
164 * This is "by design" from Qt, see https://bugreports.qt-project.org/browse/QTBUG-10994
165 *
166 * $ LC_NUMERIC=fr_FR.UTF-8 ./qtstrtod
167 * strtod(0.1) = 0
168 * $ LC_NUMERIC=C ./qtstrtod
169 * strtod(0.1) = 0.1
170 *
171 * Jerome Suhard, jerome@suhard.fr
172 */
173
174 // explicitly set the LC_NUMBERIC locale to "C"
175 setlocale(LC_NUMERIC, "C");
176}
177/***************************************************************************/
179/***************************************************************************/
180/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
181{
182 if (this == instance) {
183 instance = nullptr;
184 }
185}
186/***************************************************************************/
188/***************************************************************************/
189/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
190{
191 return QtInited;
192}
193/***************************************************************************/
195/***************************************************************************/
196/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
197{
198 return nullptr;
199}
200/***************************************************************************/
202/***************************************************************************/
203/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
204{
205 if (! qApp) return;
206 qApp->processEvents();
207}
208
209/***************************************************************************/
211/***************************************************************************/
212/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
213{
214 return externalApp;
215}
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
Definition G4Qt.hh:50
G4bool Inited() override
Definition G4Qt.cc:187
static G4Qt * getInstance()
Definition G4Qt.cc:61
void * GetEvent() override
Definition G4Qt.cc:194
bool IsExternalApp()
Definition G4Qt.cc:210
void FlushAndWaitExecution() override
Definition G4Qt.cc:201
~G4Qt() override
Definition G4Qt.cc:178
G4int GetVerboseLevel() const
static G4UImanager * GetUIpointer()
void SetMainInteractor(G4Interactor)
void SetArguments(int, char **)
voidp malloc(uInt size)