Geant4 11.1.1
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 <stdlib.h>
31#include <string.h>
32
33#include "G4ios.hh"
34
35#include "G4Qt.hh"
36#include "G4UImanager.hh"
37#include <qwidget.h>
38
39#include <qapplication.h>
40
41#ifdef G4VIS_USE_VTK_QT
42#include <qsurfaceformat.h>
43#include "QVTKOpenGLNativeWidget.h"
44#endif
45
46G4Qt* G4Qt::instance = NULL;
47
48static G4bool QtInited = FALSE;
49
50/***************************************************************************/
52)
53/***************************************************************************/
54/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
55{
56 return G4Qt::getInstance (0,NULL,(char*)"Geant4");
57}
58/***************************************************************************/
60 int a_argn
61,char** a_args
62,char* a_class
63)
64/***************************************************************************/
65/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
66{
67 if (instance==NULL) {
68 instance = new G4Qt(a_argn,a_args,a_class);
69 }
70 return instance;
71}
72/***************************************************************************/
73G4Qt::G4Qt (
74 int a_argn
75,char** a_args
76 ,char* /*a_class */
77 )
78/***************************************************************************/
79/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
80{
81 argn = 0;
82 args = NULL;
83 externalApp = false;
84
85 // Check if Qt already init in another external app
86 if(qApp) {
87 externalApp = true;
88 QtInited = TRUE;
89 SetMainInteractor (qApp);
90 SetArguments (a_argn,a_args);
91
92 } else {
93
94 if(QtInited==FALSE) { //Qt should be Inited once !
95 // Then two cases :
96 // - It is the first time we create G4UI (argc!=0)
97 // -> Inited and register
98 // - It is the first time we create G4VIS (argc == 0)
99 // -> Inited and NOT register
100
101 if (a_argn != 0) {
102 argn = a_argn;
103 args = a_args;
104
105 } else { //argc = 0
106
107 // FIXME : That's not the good arguments, but I don't know how to get args from other Interactor.
108 // Ex: How to get them from G4Xt ?
109 argn = 1;
110 args = (char **)malloc( 1 * sizeof(char *) );
111 args[0] = (char *)malloc(10 * sizeof(char));
112 strncpy(args[0], "my_app \0", 9);
113 }
114
115 int *p_argn = (int*)malloc(sizeof(int));
116 *p_argn = argn;
117#ifdef WIN32
118 qApp->setAttribute( Qt::AA_UseDesktopOpenGL );
119#endif
120
121#ifdef G4VIS_USE_VTK_QT
122 QSurfaceFormat::setDefaultFormat(QVTKOpenGLNativeWidget::defaultFormat());
123#endif
124 new QApplication (*p_argn, args);
125 if(!qApp) {
126
128 G4int verbose = UImanager->GetVerboseLevel();
129 if (verbose >= 2) {
130 G4cout << "G4Qt : Unable to init Qt." << G4endl;
131 }
132 } else {
133 QtInited = TRUE;
134 if (a_argn != 0) {
135 SetMainInteractor (qApp);
136 }
137 SetArguments (a_argn,a_args);
138 }
139 }
140 }
141 // AddDispatcher ((G4DispatchFunction)XtDispatchEvent);
142
143 /*
144 * On some non-English locale, comma is used for the decimal separator instead of dot
145 * bringing to weird behavior of strtod (string to double) function in user application.
146 * This is "by design" from Qt, see https://bugreports.qt-project.org/browse/QTBUG-10994
147 *
148 * $ LC_NUMERIC=fr_FR.UTF-8 ./qtstrtod
149 * strtod(0.1) = 0
150 * $ LC_NUMERIC=C ./qtstrtod
151 * strtod(0.1) = 0.1
152 *
153 * Jerome Suhard, [email protected]
154 */
155
156 // explicitly set the LC_NUMBERIC locale to "C"
157 setlocale (LC_NUMERIC, "C");
158}
159/***************************************************************************/
161)
162/***************************************************************************/
163/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
164{
165 if(this==instance) {
166 instance = NULL;
167 }
168}
169/***************************************************************************/
171)
172/***************************************************************************/
173/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
174{
175 return QtInited;
176}
177/***************************************************************************/
179)
180/***************************************************************************/
181/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
182{
183 return 0;
184}
185/***************************************************************************/
187)
188/***************************************************************************/
189/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
190{
191 if(!qApp) return;
192 qApp->processEvents();
193}
194
195/***************************************************************************/
197)
198/***************************************************************************/
199/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
200{
201 return externalApp;
202}
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
Definition: G4Qt.hh:49
static G4Qt * getInstance()
Definition: G4Qt.cc:51
void FlushAndWaitExecution()
Definition: G4Qt.cc:186
G4bool Inited()
Definition: G4Qt.cc:170
void * GetEvent()
Definition: G4Qt.cc:178
bool IsExternalApp()
Definition: G4Qt.cc:196
virtual ~G4Qt()
Definition: G4Qt.cc:160
G4int GetVerboseLevel() const
Definition: G4UImanager.hh:200
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:77
void SetMainInteractor(G4Interactor)
void SetArguments(int, char **)
#define TRUE
Definition: globals.hh:41
#define FALSE
Definition: globals.hh:38