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

Last change on this file since 1155 was 1155, checked in by garnier, 15 years ago

CVS update

  • Property svn:mime-type set to text/cpp
File size: 6.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.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
41#include <qapplication.h>
42
43
44G4Qt* G4Qt::instance    = NULL;
45
46static G4bool QtInited  = FALSE;
47
48/***************************************************************************/
49G4Qt* G4Qt::getInstance (
50)
51/***************************************************************************/
52/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
53{
54  return G4Qt::getInstance (0,NULL,(char*)"Geant4");
55}
56/***************************************************************************/
57G4Qt* G4Qt::getInstance (
58 int    a_argn
59,char** a_args
60,char*  a_class
61)
62/***************************************************************************/
63/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
64{
65  if (instance==NULL) {
66    instance = new G4Qt(a_argn,a_args,a_class);
67  }
68  return instance;
69}
70/***************************************************************************/
71G4Qt::G4Qt (
72 int    a_argn
73,char** a_args
74 ,char*  /*a_class */
75)
76/***************************************************************************/
77/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
78{
79  argn = 0;
80  args = NULL;
81
82#ifdef G4DEBUG_INTERFACES_COMMON
83  printf("G4Qt::G4Qt try to inited Qt\n");
84#endif
85  // Check if Qt already init in another external app
86  if(qApp) {
87    QtInited  = TRUE;
88    //#if QT_VERSION < 0x040000
89    //      SetMainInteractor (&qApp);
90    //#else
91    SetMainInteractor (qApp);
92    //#endif
93    SetArguments      (a_argn,a_args);
94   
95#ifdef G4DEBUG_INTERFACES_COMMON
96    printf("G4Qt::G4Qt alredy inited in external \n");
97#endif
98  } else {
99   
100    if(QtInited==FALSE) {  //Qt should be Inited once !
101      // Then two cases :
102      // - It is the first time we create G4UI  (argc!=0)
103      //   -> Inited and register
104      // - It is the first time we create G4VIS  (argc == 0)
105      //   -> Inited and NOT register
106     
107      if (a_argn != 0) {
108        argn = a_argn;
109        args = a_args;
110
111      } else { //argc = 0
112
113        // FIXME : That's not the good arguments, but I don't know how to get args from other Interactor.
114        // Ex: How to get them from G4Xt ?
115        argn = 1;
116        args = (char **)malloc( 1 * sizeof(char *) );
117        args[0] = (char *)malloc(10 * sizeof(char));
118        strncpy(args[0], "my_app \0", 9);
119      }
120
121      int *p_argn = (int*)malloc(sizeof(int));
122      *p_argn = argn;
123#if QT_VERSION < 0x040000
124      qApp = new QApplication (*p_argn, args);
125#else
126      new QApplication (*p_argn, args);
127#endif
128      if(!qApp) {
129       
130        G4cout        << "G4Qt : Unable to init Qt." << G4endl;
131      } else {
132        QtInited  = TRUE;
133        if (a_argn != 0) {
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 exist\n");
146  }  else {
147    printf("G4Qt::qApp not exist\n");
148  }
149#endif
150  //  AddDispatcher     ((G4DispatchFunction)XtDispatchEvent);
151}
152/***************************************************************************/
153G4Qt::~G4Qt (
154)
155/***************************************************************************/
156/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
157{
158  if(this==instance) {
159    instance = NULL;
160  }
161}
162/***************************************************************************/
163G4bool G4Qt::Inited (
164)
165/***************************************************************************/
166/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
167{
168  return QtInited;
169}
170/***************************************************************************/
171/**
172  Si j'ai bien compris, cette fonction ne sert à rien
173 */
174void* G4Qt::GetEvent (
175)
176/***************************************************************************/
177/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
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/***************************************************************************/
190void G4Qt::FlushAndWaitExecution (
191)
192/***************************************************************************/
193/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
194{
195  //  printf("G4Qt::FlushAndWaitExecution ::  Flush ....\n");
196  if(!qApp) return;
197  qApp->processEvents();
198}
199
200#endif
201
202
203
Note: See TracBrowser for help on using the repository browser.