Geant4_10
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 74547 2013-10-14 12:51:17Z 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 #ifdef G4DEBUG_INTERFACES_COMMON
85  printf("G4Qt::G4Qt try to inited Qt\n");
86 #endif
87  // Check if Qt already init in another external app
88  if(qApp) {
89  externalApp = true;
90  QtInited = TRUE;
91  SetMainInteractor (qApp);
92  SetArguments (a_argn,a_args);
93 
94 #ifdef G4DEBUG_INTERFACES_COMMON
95  printf("G4Qt::G4Qt alredy inited in external \n");
96 #endif
97  } else {
98 
99  if(QtInited==FALSE) { //Qt should be Inited once !
100  // Then two cases :
101  // - It is the first time we create G4UI (argc!=0)
102  // -> Inited and register
103  // - It is the first time we create G4VIS (argc == 0)
104  // -> Inited and NOT register
105 
106  if (a_argn != 0) {
107  argn = a_argn;
108  args = a_args;
109 
110  } else { //argc = 0
111 
112  // FIXME : That's not the good arguments, but I don't know how to get args from other Interactor.
113  // Ex: How to get them from G4Xt ?
114  argn = 1;
115  args = (char **)malloc( 1 * sizeof(char *) );
116  args[0] = (char *)malloc(10 * sizeof(char));
117  strncpy(args[0], "my_app \0", 9);
118  }
119 
120  int *p_argn = (int*)malloc(sizeof(int));
121  *p_argn = argn;
122 #ifdef G4DEBUG_INTERFACES_COMMON
123  printf("G4Qt::G4Qt QAppl \n");
124 #endif
125  new QApplication (*p_argn, args);
126  if(!qApp) {
127 
128  G4UImanager* UImanager = G4UImanager::GetUIpointer();
129  G4int verbose = UImanager->GetVerboseLevel();
130  if (verbose >= 2) {
131  G4cout << "G4Qt : Unable to init Qt." << G4endl;
132  }
133  } else {
134  QtInited = TRUE;
135  if (a_argn != 0) {
136 #ifdef G4DEBUG_INTERFACES_COMMON
137  printf("G4Qt::G4Qt SetMainInteractor\n");
138 #endif
139  SetMainInteractor (qApp);
140  }
141  SetArguments (a_argn,a_args);
142 #ifdef G4DEBUG_INTERFACES_COMMON
143  printf("G4Qt::G4Qt inited Qt END\n");
144 #endif
145  }
146  }
147  }
148 #ifdef G4DEBUG_INTERFACES_COMMON
149  if (qApp) {
150  printf("G4Qt::qApp already exist\n");
151  } else {
152  printf("G4Qt::qApp not exist\n");
153  }
154 #endif
155  // AddDispatcher ((G4DispatchFunction)XtDispatchEvent);
156 }
157 /***************************************************************************/
158 G4Qt::~G4Qt (
159 )
160 /***************************************************************************/
162 {
163  if(this==instance) {
164  instance = NULL;
165  }
166 }
167 /***************************************************************************/
168 G4bool G4Qt::Inited (
169 )
170 /***************************************************************************/
172 {
173  return QtInited;
174 }
175 /***************************************************************************/
176 void* G4Qt::GetEvent (
177 )
178 /***************************************************************************/
180 {
181  return 0;
182 }
183 /***************************************************************************/
184 void G4Qt::FlushAndWaitExecution (
185 )
186 /***************************************************************************/
188 {
189  if(!qApp) return;
190  qApp->processEvents();
191 }
192 
193 /***************************************************************************/
194 bool G4Qt::IsExternalApp (
195 )
196 /***************************************************************************/
198 {
199  return externalApp;
200 }
201 
202 #endif
203 
204 
G4int GetVerboseLevel() const
Definition: G4UImanager.hh:227
int G4int
Definition: G4Types.hh:78
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
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
printf("%d Experimental points found\n", nlines)
void * malloc(size_t __size)
Definition: hjmalloc.cc:30