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

Last change on this file since 1248 was 1248, checked in by garnier, 14 years ago

test de helpTree update

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