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

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

update geant4.9.3 tag

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