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
RevLine 
[481]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//
[1134]27// $Id: G4Qt.cc,v 1.14 2009/10/07 09:12:35 lgarnier Exp $
[867]28// GEANT4 tag $Name: $
[481]29//
[484]30// L. Garnier
[481]31
[484]32#if defined(G4INTY_BUILD_QT) || defined(G4INTY_USE_QT)
[481]33
34#include <stdlib.h>
35#include <string.h>
36
37#include "G4ios.hh"
38
[484]39#include "G4Qt.hh"
[1158]40#include "G4UIQt.hh"
41#include <qwidget.h>
[481]42
[595]43#include <qapplication.h>
[593]44
45
[484]46G4Qt* G4Qt::instance = NULL;
[481]47
[484]48static G4bool QtInited = FALSE;
49
[481]50/***************************************************************************/
[484]51G4Qt* G4Qt::getInstance (
[481]52)
53/***************************************************************************/
54/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
55{
[484]56 return G4Qt::getInstance (0,NULL,(char*)"Geant4");
[481]57}
58/***************************************************************************/
[484]59G4Qt* G4Qt::getInstance (
[874]60 int a_argn
[481]61,char** a_args
62,char* a_class
63)
64/***************************************************************************/
65/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
66{
67 if (instance==NULL) {
[484]68 instance = new G4Qt(a_argn,a_args,a_class);
[481]69 }
[1158]70#ifdef G4DEBUG_INTERFACES_COMMON
71 printf("G4Qt::getInstance :%d\n",instance);
72#endif
[481]73 return instance;
74}
75/***************************************************************************/
[484]76G4Qt::G4Qt (
[874]77 int a_argn
[481]78,char** a_args
[989]79 ,char* /*a_class */
[481]80)
81/***************************************************************************/
82/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
83{
[876]84 argn = 0;
85 args = NULL;
86
[1120]87#ifdef G4DEBUG_INTERFACES_COMMON
[571]88 printf("G4Qt::G4Qt try to inited Qt\n");
[608]89#endif
[856]90 // Check if Qt already init in another external app
91 if(qApp) {
[876]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
[1120]100#ifdef G4DEBUG_INTERFACES_COMMON
[876]101 printf("G4Qt::G4Qt alredy inited in external \n");
[608]102#endif
[856]103 } else {
[876]104
[856]105 if(QtInited==FALSE) { //Qt should be Inited once !
[874]106 // Then two cases :
107 // - It is the first time we create G4UI (argc!=0)
108 // -> Inited and register
[876]109 // - It is the first time we create G4VIS (argc == 0)
[874]110 // -> Inited and NOT register
[876]111
112 if (a_argn != 0) {
113 argn = a_argn;
114 args = a_args;
[874]115
116 } else { //argc = 0
117
[876]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 }
[874]125
[876]126 int *p_argn = (int*)malloc(sizeof(int));
127 *p_argn = argn;
[856]128#if QT_VERSION < 0x040000
[889]129 qApp = new QApplication (*p_argn, args);
[856]130#else
[889]131 new QApplication (*p_argn, args);
[856]132#endif
133 if(!qApp) {
134
135 G4cout << "G4Qt : Unable to init Qt." << G4endl;
136 } else {
[876]137 QtInited = TRUE;
[874]138 if (a_argn != 0) {
139 SetMainInteractor (qApp);
140 }
[876]141 SetArguments (a_argn,a_args);
[1120]142#ifdef G4DEBUG_INTERFACES_COMMON
[856]143 printf("G4Qt::G4Qt inited Qt END\n");
144#endif
145 }
[481]146 }
147 }
[1120]148#ifdef G4DEBUG_INTERFACES_COMMON
[617]149 if (qApp) {
[1158]150 printf("G4Qt::qApp exist adress:%d\n",this);
[617]151 } else {
152 printf("G4Qt::qApp not exist\n");
153 }
[608]154#endif
[496]155 // AddDispatcher ((G4DispatchFunction)XtDispatchEvent);
[481]156}
157/***************************************************************************/
[484]158G4Qt::~G4Qt (
[481]159)
160/***************************************************************************/
161/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
162{
163 if(this==instance) {
164 instance = NULL;
165 }
166}
167/***************************************************************************/
[484]168G4bool G4Qt::Inited (
[481]169)
170/***************************************************************************/
171/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
172{
[484]173 return QtInited;
[481]174}
175/***************************************************************************/
[850]176/**
177 Si j'ai bien compris, cette fonction ne sert à rien
178 */
[484]179void* G4Qt::GetEvent (
[481]180)
181/***************************************************************************/
182/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
183{
[850]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("*");
[593]192 return 0;
[481]193}
194/***************************************************************************/
[484]195void G4Qt::FlushAndWaitExecution (
[481]196)
197/***************************************************************************/
198/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
199{
[850]200 // printf("G4Qt::FlushAndWaitExecution :: Flush ....\n");
[578]201 if(!qApp) return;
202 qApp->processEvents();
[481]203}
204
[1158]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}
[481]229#endif
230
231
232
Note: See TracBrowser for help on using the repository browser.