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

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

tag geant4.9.4 beta 1 + modifs locales

  • Property svn:mime-type set to text/cpp
File size: 6.6 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//
[1255]27// $Id: G4Qt.cc,v 1.17 2010/05/20 07:01:03 lgarnier Exp $
[1337]28// GEANT4 tag $Name: geant4-09-04-beta-01 $
[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 <qwidget.h>
[481]41
[595]42#include <qapplication.h>
[593]43
44
[484]45G4Qt* G4Qt::instance    = NULL;
[481]46
[484]47static G4bool QtInited  = FALSE;
48
[481]49/***************************************************************************/
[484]50G4Qt* G4Qt::getInstance (
[481]51)
52/***************************************************************************/
53/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
54{
[484]55  return G4Qt::getInstance (0,NULL,(char*)"Geant4");
[481]56}
57/***************************************************************************/
[484]58G4Qt* G4Qt::getInstance (
[874]59 int    a_argn
[481]60,char** a_args
61,char*  a_class
62)
63/***************************************************************************/
64/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
65{
66  if (instance==NULL) {
[484]67    instance = new G4Qt(a_argn,a_args,a_class);
[481]68  }
69  return instance;
70}
71/***************************************************************************/
[484]72G4Qt::G4Qt (
[874]73 int    a_argn
[481]74,char** a_args
[989]75 ,char*  /*a_class */
[1163]76 )
[481]77/***************************************************************************/
78/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
79{
[876]80  argn = 0;
81  args = NULL;
82
[1120]83#ifdef G4DEBUG_INTERFACES_COMMON
[571]84  printf("G4Qt::G4Qt try to inited Qt\n");
[608]85#endif
[856]86  // Check if Qt already init in another external app
87  if(qApp) {
[876]88    QtInited  = TRUE;
89    //#if QT_VERSION < 0x040000
90    //      SetMainInteractor (&qApp);
91    //#else
92    SetMainInteractor (qApp);
93    //#endif
94    SetArguments      (a_argn,a_args);
95   
[1120]96#ifdef G4DEBUG_INTERFACES_COMMON
[876]97    printf("G4Qt::G4Qt alredy inited in external \n");
[608]98#endif
[856]99  } else {
[876]100   
[856]101    if(QtInited==FALSE) {  //Qt should be Inited once !
[874]102      // Then two cases :
103      // - It is the first time we create G4UI  (argc!=0)
104      //   -> Inited and register
[876]105      // - It is the first time we create G4VIS  (argc == 0)
[874]106      //   -> Inited and NOT register
[876]107     
108      if (a_argn != 0) {
109        argn = a_argn;
110        args = a_args;
[874]111
112      } else { //argc = 0
113
[876]114        // FIXME : That's not the good arguments, but I don't know how to get args from other Interactor.
115        // Ex: How to get them from G4Xt ?
116        argn = 1;
117        args = (char **)malloc( 1 * sizeof(char *) );
118        args[0] = (char *)malloc(10 * sizeof(char));
119        strncpy(args[0], "my_app \0", 9);
120      }
[874]121
[876]122      int *p_argn = (int*)malloc(sizeof(int));
123      *p_argn = argn;
[856]124#if QT_VERSION < 0x040000
[889]125      qApp = new QApplication (*p_argn, args);
[856]126#else
[1224]127#ifdef G4DEBUG_INTERFACES_COMMON
[1243]128    printf("G4Qt::G4Qt QAppl \n");
[1224]129#endif
[889]130      new QApplication (*p_argn, args);
[856]131#endif
132      if(!qApp) {
133       
134        G4cout        << "G4Qt : Unable to init Qt." << G4endl;
135      } else {
[876]136        QtInited  = TRUE;
[874]137        if (a_argn != 0) {
[1224]138#ifdef G4DEBUG_INTERFACES_COMMON
139        printf("G4Qt::G4Qt SetMainInteractor\n");
140#endif
[874]141          SetMainInteractor (qApp);
142        }
[876]143        SetArguments      (a_argn,a_args);
[1120]144#ifdef G4DEBUG_INTERFACES_COMMON
[856]145        printf("G4Qt::G4Qt inited Qt END\n");
146#endif
147      }
[481]148    }
149  }
[1120]150#ifdef G4DEBUG_INTERFACES_COMMON
[617]151  if (qApp) {
[1248]152    printf("G4Qt::qApp already exist\n");
[617]153  }  else {
154    printf("G4Qt::qApp not exist\n");
155  }
[608]156#endif
[496]157  //  AddDispatcher     ((G4DispatchFunction)XtDispatchEvent);
[481]158}
159/***************************************************************************/
[484]160G4Qt::~G4Qt (
[481]161)
162/***************************************************************************/
163/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
164{
165  if(this==instance) {
166    instance = NULL;
167  }
168}
169/***************************************************************************/
[484]170G4bool G4Qt::Inited (
[481]171)
172/***************************************************************************/
173/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
174{
[484]175  return QtInited;
[481]176}
177/***************************************************************************/
[850]178/**
179  Si j'ai bien compris, cette fonction ne sert à rien
180 */
[484]181void* G4Qt::GetEvent (
[481]182)
183/***************************************************************************/
184/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
185{
[850]186//FIXME
187//   G4cout        << "G4Qt : Rien compris a cette fonction G4Qt::GetEvent." << G4endl;
188//  static XEvent  event;
189//  if(appContext==NULL) return NULL;
190//  if(mainApp==NULL) return NULL;
191//  QtAppNextEvent (appContext, &event);
192//  return         &event;
193  printf("*");
[593]194  return 0;
[481]195}
196/***************************************************************************/
[484]197void G4Qt::FlushAndWaitExecution (
[481]198)
199/***************************************************************************/
200/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
201{
[850]202  //  printf("G4Qt::FlushAndWaitExecution ::  Flush ....\n");
[578]203  if(!qApp) return;
204  qApp->processEvents();
[481]205}
206
207#endif
208
209
Note: See TracBrowser for help on using the repository browser.