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