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

Last change on this file since 1160 was 1158, checked in by garnier, 16 years ago

mise en place de Vis dans UI

  • Property svn:mime-type set to text/cpp
File size: 7.2 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.14 2009/10/07 09:12:35 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 "G4UIQt.hh"
41#include <qwidget.h>
42
43#include <qapplication.h>
44
45
46G4Qt* G4Qt::instance = NULL;
47
48static G4bool QtInited = FALSE;
49
50/***************************************************************************/
51G4Qt* G4Qt::getInstance (
52)
53/***************************************************************************/
54/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
55{
56 return G4Qt::getInstance (0,NULL,(char*)"Geant4");
57}
58/***************************************************************************/
59G4Qt* G4Qt::getInstance (
60 int a_argn
61,char** a_args
62,char* a_class
63)
64/***************************************************************************/
65/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
66{
67 if (instance==NULL) {
68 instance = new G4Qt(a_argn,a_args,a_class);
69 }
70#ifdef G4DEBUG_INTERFACES_COMMON
71 printf("G4Qt::getInstance :%d\n",instance);
72#endif
73 return instance;
74}
75/***************************************************************************/
76G4Qt::G4Qt (
77 int a_argn
78,char** a_args
79 ,char* /*a_class */
80)
81/***************************************************************************/
82/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
83{
84 argn = 0;
85 args = NULL;
86
87#ifdef G4DEBUG_INTERFACES_COMMON
88 printf("G4Qt::G4Qt try to inited Qt\n");
89#endif
90 // Check if Qt already init in another external app
91 if(qApp) {
92 QtInited = TRUE;
93 //#if QT_VERSION < 0x040000
94 // SetMainInteractor (&qApp);
95 //#else
96 SetMainInteractor (qApp);
97 //#endif
98 SetArguments (a_argn,a_args);
99
100#ifdef G4DEBUG_INTERFACES_COMMON
101 printf("G4Qt::G4Qt alredy inited in external \n");
102#endif
103 } else {
104
105 if(QtInited==FALSE) { //Qt should be Inited once !
106 // Then two cases :
107 // - It is the first time we create G4UI (argc!=0)
108 // -> Inited and register
109 // - It is the first time we create G4VIS (argc == 0)
110 // -> Inited and NOT register
111
112 if (a_argn != 0) {
113 argn = a_argn;
114 args = a_args;
115
116 } else { //argc = 0
117
118 // FIXME : That's not the good arguments, but I don't know how to get args from other Interactor.
119 // Ex: How to get them from G4Xt ?
120 argn = 1;
121 args = (char **)malloc( 1 * sizeof(char *) );
122 args[0] = (char *)malloc(10 * sizeof(char));
123 strncpy(args[0], "my_app \0", 9);
124 }
125
126 int *p_argn = (int*)malloc(sizeof(int));
127 *p_argn = argn;
128#if QT_VERSION < 0x040000
129 qApp = new QApplication (*p_argn, args);
130#else
131 new QApplication (*p_argn, args);
132#endif
133 if(!qApp) {
134
135 G4cout << "G4Qt : Unable to init Qt." << G4endl;
136 } else {
137 QtInited = TRUE;
138 if (a_argn != 0) {
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 exist adress:%d\n",this);
151 } else {
152 printf("G4Qt::qApp not exist\n");
153 }
154#endif
155 // AddDispatcher ((G4DispatchFunction)XtDispatchEvent);
156}
157/***************************************************************************/
158G4Qt::~G4Qt (
159)
160/***************************************************************************/
161/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
162{
163 if(this==instance) {
164 instance = NULL;
165 }
166}
167/***************************************************************************/
168G4bool G4Qt::Inited (
169)
170/***************************************************************************/
171/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
172{
173 return QtInited;
174}
175/***************************************************************************/
176/**
177 Si j'ai bien compris, cette fonction ne sert à rien
178 */
179void* G4Qt::GetEvent (
180)
181/***************************************************************************/
182/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
183{
184//FIXME
185// G4cout << "G4Qt : Rien compris a cette fonction G4Qt::GetEvent." << G4endl;
186// static XEvent event;
187// if(appContext==NULL) return NULL;
188// if(mainApp==NULL) return NULL;
189// QtAppNextEvent (appContext, &event);
190// return &event;
191 printf("*");
192 return 0;
193}
194/***************************************************************************/
195void G4Qt::FlushAndWaitExecution (
196)
197/***************************************************************************/
198/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
199{
200 // printf("G4Qt::FlushAndWaitExecution :: Flush ....\n");
201 if(!qApp) return;
202 qApp->processEvents();
203}
204
205/***************************************************************************/
206void G4Qt::SetG4UI (
207 G4UIQt* ui
208)
209/***************************************************************************/
210/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
211{
212 fG4UI = ui;
213}
214
215/***************************************************************************/
216bool G4Qt::AddTabVisWidget (
217 QWidget * vis
218 ,QString name
219)
220/***************************************************************************/
221/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
222{
223 if (fG4UI) {
224 fG4UI->AddTabVisWidget(vis,name);
225 return true;
226 }
227 return false;
228}
229#endif
230
231
232
Note: See TracBrowser for help on using the repository browser.