source: trunk/source/interfaces/common/src/G4Qt.cc@ 1282

Last change on this file since 1282 was 1255, checked in by garnier, 16 years ago

remove cycle dependency

  • Property svn:mime-type set to text/cpp
File size: 6.6 KB
Line 
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,v 1.17 2010/05/20 07:01:03 lgarnier Exp $
28// GEANT4 tag $Name: $
29//
30// L. Garnier
31
32#if defined(G4INTY_BUILD_QT) || defined(G4INTY_USE_QT)
33
34#include <stdlib.h>
35#include <string.h>
36
37#include "G4ios.hh"
38
39#include "G4Qt.hh"
40#include <qwidget.h>
41
42#include <qapplication.h>
43
44
45G4Qt* G4Qt::instance = NULL;
46
47static G4bool QtInited = FALSE;
48
49/***************************************************************************/
50G4Qt* G4Qt::getInstance (
51)
52/***************************************************************************/
53/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
54{
55 return G4Qt::getInstance (0,NULL,(char*)"Geant4");
56}
57/***************************************************************************/
58G4Qt* G4Qt::getInstance (
59 int a_argn
60,char** a_args
61,char* a_class
62)
63/***************************************************************************/
64/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
65{
66 if (instance==NULL) {
67 instance = new G4Qt(a_argn,a_args,a_class);
68 }
69 return instance;
70}
71/***************************************************************************/
72G4Qt::G4Qt (
73 int a_argn
74,char** a_args
75 ,char* /*a_class */
76 )
77/***************************************************************************/
78/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
79{
80 argn = 0;
81 args = NULL;
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 QtInited = TRUE;
89 //#if QT_VERSION < 0x040000
90 // SetMainInteractor (&qApp);
91 //#else
92 SetMainInteractor (qApp);
93 //#endif
94 SetArguments (a_argn,a_args);
95
96#ifdef G4DEBUG_INTERFACES_COMMON
97 printf("G4Qt::G4Qt alredy inited in external \n");
98#endif
99 } else {
100
101 if(QtInited==FALSE) { //Qt should be Inited once !
102 // Then two cases :
103 // - It is the first time we create G4UI (argc!=0)
104 // -> Inited and register
105 // - It is the first time we create G4VIS (argc == 0)
106 // -> Inited and NOT register
107
108 if (a_argn != 0) {
109 argn = a_argn;
110 args = a_args;
111
112 } else { //argc = 0
113
114 // FIXME : That's not the good arguments, but I don't know how to get args from other Interactor.
115 // Ex: How to get them from G4Xt ?
116 argn = 1;
117 args = (char **)malloc( 1 * sizeof(char *) );
118 args[0] = (char *)malloc(10 * sizeof(char));
119 strncpy(args[0], "my_app \0", 9);
120 }
121
122 int *p_argn = (int*)malloc(sizeof(int));
123 *p_argn = argn;
124#if QT_VERSION < 0x040000
125 qApp = new QApplication (*p_argn, args);
126#else
127#ifdef G4DEBUG_INTERFACES_COMMON
128 printf("G4Qt::G4Qt QAppl \n");
129#endif
130 new QApplication (*p_argn, args);
131#endif
132 if(!qApp) {
133
134 G4cout << "G4Qt : Unable to init Qt." << G4endl;
135 } else {
136 QtInited = TRUE;
137 if (a_argn != 0) {
138#ifdef G4DEBUG_INTERFACES_COMMON
139 printf("G4Qt::G4Qt SetMainInteractor\n");
140#endif
141 SetMainInteractor (qApp);
142 }
143 SetArguments (a_argn,a_args);
144#ifdef G4DEBUG_INTERFACES_COMMON
145 printf("G4Qt::G4Qt inited Qt END\n");
146#endif
147 }
148 }
149 }
150#ifdef G4DEBUG_INTERFACES_COMMON
151 if (qApp) {
152 printf("G4Qt::qApp already exist\n");
153 } else {
154 printf("G4Qt::qApp not exist\n");
155 }
156#endif
157 // AddDispatcher ((G4DispatchFunction)XtDispatchEvent);
158}
159/***************************************************************************/
160G4Qt::~G4Qt (
161)
162/***************************************************************************/
163/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
164{
165 if(this==instance) {
166 instance = NULL;
167 }
168}
169/***************************************************************************/
170G4bool G4Qt::Inited (
171)
172/***************************************************************************/
173/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
174{
175 return QtInited;
176}
177/***************************************************************************/
178/**
179 Si j'ai bien compris, cette fonction ne sert à rien
180 */
181void* G4Qt::GetEvent (
182)
183/***************************************************************************/
184/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
185{
186//FIXME
187// G4cout << "G4Qt : Rien compris a cette fonction G4Qt::GetEvent." << G4endl;
188// static XEvent event;
189// if(appContext==NULL) return NULL;
190// if(mainApp==NULL) return NULL;
191// QtAppNextEvent (appContext, &event);
192// return &event;
193 printf("*");
194 return 0;
195}
196/***************************************************************************/
197void G4Qt::FlushAndWaitExecution (
198)
199/***************************************************************************/
200/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
201{
202 // printf("G4Qt::FlushAndWaitExecution :: Flush ....\n");
203 if(!qApp) return;
204 qApp->processEvents();
205}
206
207#endif
208
209
Note: See TracBrowser for help on using the repository browser.