Geant4  9.6.p02
 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$
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 <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 #ifdef G4DEBUG_INTERFACES_COMMON
84  printf("G4Qt::G4Qt try to inited Qt\n");
85 #endif
86  // Check if Qt already init in another external app
87  if(qApp) {
88  externalApp = true;
89  QtInited = TRUE;
90  SetMainInteractor (qApp);
91  SetArguments (a_argn,a_args);
92 
93 #ifdef G4DEBUG_INTERFACES_COMMON
94  printf("G4Qt::G4Qt alredy inited in external \n");
95 #endif
96  } else {
97 
98  if(QtInited==FALSE) { //Qt should be Inited once !
99  // Then two cases :
100  // - It is the first time we create G4UI (argc!=0)
101  // -> Inited and register
102  // - It is the first time we create G4VIS (argc == 0)
103  // -> Inited and NOT register
104 
105  if (a_argn != 0) {
106  argn = a_argn;
107  args = a_args;
108 
109  } else { //argc = 0
110 
111  // FIXME : That's not the good arguments, but I don't know how to get args from other Interactor.
112  // Ex: How to get them from G4Xt ?
113  argn = 1;
114  args = (char **)malloc( 1 * sizeof(char *) );
115  args[0] = (char *)malloc(10 * sizeof(char));
116  strncpy(args[0], "my_app \0", 9);
117  }
118 
119  int *p_argn = (int*)malloc(sizeof(int));
120  *p_argn = argn;
121 #ifdef G4DEBUG_INTERFACES_COMMON
122  printf("G4Qt::G4Qt QAppl \n");
123 #endif
124  new QApplication (*p_argn, args);
125  if(!qApp) {
126 
127  G4cout << "G4Qt : Unable to init Qt." << G4endl;
128  } else {
129  QtInited = TRUE;
130  if (a_argn != 0) {
131 #ifdef G4DEBUG_INTERFACES_COMMON
132  printf("G4Qt::G4Qt SetMainInteractor\n");
133 #endif
134  SetMainInteractor (qApp);
135  }
136  SetArguments (a_argn,a_args);
137 #ifdef G4DEBUG_INTERFACES_COMMON
138  printf("G4Qt::G4Qt inited Qt END\n");
139 #endif
140  }
141  }
142  }
143 #ifdef G4DEBUG_INTERFACES_COMMON
144  if (qApp) {
145  printf("G4Qt::qApp already exist\n");
146  } else {
147  printf("G4Qt::qApp not exist\n");
148  }
149 #endif
150  // AddDispatcher ((G4DispatchFunction)XtDispatchEvent);
151 }
152 /***************************************************************************/
153 G4Qt::~G4Qt (
154 )
155 /***************************************************************************/
157 {
158  if(this==instance) {
159  instance = NULL;
160  }
161 }
162 /***************************************************************************/
163 G4bool G4Qt::Inited (
164 )
165 /***************************************************************************/
167 {
168  return QtInited;
169 }
170 /***************************************************************************/
174 void* G4Qt::GetEvent (
175 )
176 /***************************************************************************/
178 {
179 //FIXME
180 // G4cout << "G4Qt : Rien compris a cette fonction G4Qt::GetEvent." << G4endl;
181 // static XEvent event;
182 // if(appContext==NULL) return NULL;
183 // if(mainApp==NULL) return NULL;
184 // QtAppNextEvent (appContext, &event);
185 // return &event;
186  printf("*");
187  return 0;
188 }
189 /***************************************************************************/
190 void G4Qt::FlushAndWaitExecution (
191 )
192 /***************************************************************************/
194 {
195  // printf("G4Qt::FlushAndWaitExecution :: Flush ....\n");
196  if(!qApp) return;
197  qApp->processEvents();
198 }
199 
200 /***************************************************************************/
201 bool G4Qt::IsExternalApp (
202 )
203 /***************************************************************************/
205 {
206  return externalApp;
207 }
208 
209 #endif
210 
211