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

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

fichiers manquants

  • Property svn:mime-type set to text/cpp
File size: 6.3 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//
[989]27// $Id: G4Qt.cc,v 1.13 2009/03/31 09:03:58 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"
[481]40
[595]41#include <qapplication.h>
[593]42
43
[484]44G4Qt* G4Qt::instance    = NULL;
[481]45
[484]46static G4bool QtInited  = FALSE;
47
[481]48/***************************************************************************/
[484]49G4Qt* G4Qt::getInstance (
[481]50)
51/***************************************************************************/
52/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
53{
[484]54  return G4Qt::getInstance (0,NULL,(char*)"Geant4");
[481]55}
56/***************************************************************************/
[484]57G4Qt* G4Qt::getInstance (
[874]58 int    a_argn
[481]59,char** a_args
60,char*  a_class
61)
62/***************************************************************************/
63/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
64{
65  if (instance==NULL) {
[484]66    instance = new G4Qt(a_argn,a_args,a_class);
[481]67  }
68  return instance;
69}
70/***************************************************************************/
[484]71G4Qt::G4Qt (
[874]72 int    a_argn
[481]73,char** a_args
[989]74 ,char*  /*a_class */
[481]75)
76/***************************************************************************/
77/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
78{
[876]79  argn = 0;
80  args = NULL;
81
[874]82#ifdef G4DEBUG
[571]83  printf("G4Qt::G4Qt try to inited Qt\n");
[608]84#endif
[856]85  // Check if Qt already init in another external app
86  if(qApp) {
[876]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   
[874]95#ifdef G4DEBUG
[876]96    printf("G4Qt::G4Qt alredy inited in external \n");
[608]97#endif
[856]98  } else {
[876]99   
[856]100    if(QtInited==FALSE) {  //Qt should be Inited once !
[874]101      // Then two cases :
102      // - It is the first time we create G4UI  (argc!=0)
103      //   -> Inited and register
[876]104      // - It is the first time we create G4VIS  (argc == 0)
[874]105      //   -> Inited and NOT register
[876]106     
107      if (a_argn != 0) {
108        argn = a_argn;
109        args = a_args;
[874]110
111      } else { //argc = 0
112
[876]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      }
[874]120
[876]121      int *p_argn = (int*)malloc(sizeof(int));
122      *p_argn = argn;
[856]123#if QT_VERSION < 0x040000
[889]124      qApp = new QApplication (*p_argn, args);
[856]125#else
[889]126      new QApplication (*p_argn, args);
[856]127#endif
128      if(!qApp) {
129       
130        G4cout        << "G4Qt : Unable to init Qt." << G4endl;
131      } else {
[876]132        QtInited  = TRUE;
[874]133        if (a_argn != 0) {
134          SetMainInteractor (qApp);
135        }
[876]136        SetArguments      (a_argn,a_args);
[874]137#ifdef G4DEBUG
[856]138        printf("G4Qt::G4Qt inited Qt END\n");
139#endif
140      }
[481]141    }
142  }
[874]143#ifdef G4DEBUG
[617]144  if (qApp) {
[606]145    printf("G4Qt::qApp exist\n");
[617]146  }  else {
147    printf("G4Qt::qApp not exist\n");
148  }
[608]149#endif
[496]150  //  AddDispatcher     ((G4DispatchFunction)XtDispatchEvent);
[481]151}
152/***************************************************************************/
[484]153G4Qt::~G4Qt (
[481]154)
155/***************************************************************************/
156/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
157{
158  if(this==instance) {
159    instance = NULL;
160  }
161}
162/***************************************************************************/
[484]163G4bool G4Qt::Inited (
[481]164)
165/***************************************************************************/
166/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
167{
[484]168  return QtInited;
[481]169}
170/***************************************************************************/
[850]171/**
172  Si j'ai bien compris, cette fonction ne sert à rien
173 */
[484]174void* G4Qt::GetEvent (
[481]175)
176/***************************************************************************/
177/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
178{
[850]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("*");
[593]187  return 0;
[481]188}
189/***************************************************************************/
[484]190void G4Qt::FlushAndWaitExecution (
[481]191)
192/***************************************************************************/
193/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
194{
[850]195  //  printf("G4Qt::FlushAndWaitExecution ::  Flush ....\n");
[578]196  if(!qApp) return;
197  qApp->processEvents();
[481]198}
199
200#endif
201
202
203
Note: See TracBrowser for help on using the repository browser.