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