| [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 | //
|
|---|
| [874] | 27 | // $Id: G4Qt.cc,v 1.10 2008/10/24 13:23:22 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] | 44 | G4Qt* G4Qt::instance = NULL;
|
|---|
| [481] | 45 |
|
|---|
| [484] | 46 | static G4bool QtInited = FALSE;
|
|---|
| 47 |
|
|---|
| [481] | 48 | /***************************************************************************/
|
|---|
| [484] | 49 | G4Qt* G4Qt::getInstance (
|
|---|
| [481] | 50 | )
|
|---|
| 51 | /***************************************************************************/
|
|---|
| 52 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
|---|
| 53 | {
|
|---|
| [484] | 54 | return G4Qt::getInstance (0,NULL,(char*)"Geant4");
|
|---|
| [481] | 55 | }
|
|---|
| 56 | /***************************************************************************/
|
|---|
| [484] | 57 | G4Qt* 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] | 71 | G4Qt::G4Qt (
|
|---|
| [874] | 72 | int a_argn
|
|---|
| [481] | 73 | ,char** a_args
|
|---|
| 74 | ,char* a_class
|
|---|
| 75 | )
|
|---|
| 76 | /***************************************************************************/
|
|---|
| 77 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
|---|
| 78 | {
|
|---|
| [874] | 79 | #ifdef G4DEBUG
|
|---|
| [571] | 80 | printf("G4Qt::G4Qt try to inited Qt\n");
|
|---|
| [608] | 81 | #endif
|
|---|
| [856] | 82 | // Check if Qt already init in another external app
|
|---|
| 83 | if(qApp) {
|
|---|
| [606] | 84 | QtInited = TRUE;
|
|---|
| [850] | 85 | //#if QT_VERSION < 0x040000
|
|---|
| 86 | // SetMainInteractor (&qApp);
|
|---|
| 87 | //#else
|
|---|
| [606] | 88 | SetMainInteractor (qApp);
|
|---|
| [850] | 89 | //#endif
|
|---|
| [874] | 90 | SetArguments (a_argn,a_args);
|
|---|
| 91 |
|
|---|
| 92 | #ifdef G4DEBUG
|
|---|
| [856] | 93 | printf("G4Qt::G4Qt alredy inited in external \n");
|
|---|
| [608] | 94 | #endif
|
|---|
| [856] | 95 | } else {
|
|---|
| 96 |
|
|---|
| 97 | if(QtInited==FALSE) { //Qt should be Inited once !
|
|---|
| [874] | 98 | // Then two cases :
|
|---|
| 99 | // - It is the first time we create G4UI (argc!=0)
|
|---|
| 100 | // -> Inited and register
|
|---|
| 101 | // - It is the first time we create G4VIS (arc == 0)
|
|---|
| 102 | // -> Inited and NOT register
|
|---|
| 103 |
|
|---|
| 104 | int argc;
|
|---|
| 105 | char ** test;
|
|---|
| 106 | if (a_argn != 0) {
|
|---|
| 107 | SetArguments (a_argn,a_args);
|
|---|
| 108 | #ifdef G4DEBUG
|
|---|
| 109 | printf("G4Qt::G4Qt inited, first time creating UI \n");
|
|---|
| [856] | 110 | #endif
|
|---|
| [874] | 111 | } else { //argc = 0
|
|---|
| 112 | test = GetArguments(&argc);
|
|---|
| 113 |
|
|---|
| 114 | #ifdef G4DEBUG
|
|---|
| 115 |
|
|---|
| 116 | printf("G4Qt::G4Qt inited, create new QtVis\n");
|
|---|
| 117 | printf("G4Qt::G4Qt arguments avant %s\n",a_args[0]);
|
|---|
| 118 | printf("G4Qt::G4Qt arguments avant %s\n",a_args[1]);
|
|---|
| 119 | printf("G4Qt::G4Qt arguments avant %s\n",a_args[2]);
|
|---|
| 120 | printf("G4Qt::G4Qt arguments avant %s\n",a_args[3]);
|
|---|
| 121 | printf("G4Qt::G4Qt arguments apres %d\n",argc);
|
|---|
| 122 | printf("G4Qt::G4Qt arguments apres %s \n",test[0]);
|
|---|
| 123 | printf("G4Qt::G4Qt arguments apres %s \n",test[1]);
|
|---|
| 124 | printf("G4Qt::G4Qt arguments apres %s \n",test[2]);
|
|---|
| 125 | printf("G4Qt::G4Qt arguments apres %s \n",test[3]);
|
|---|
| 126 | #endif
|
|---|
| 127 | if (argc == 0) {
|
|---|
| 128 | G4cout << "G4Qt : Unable to init Qt." << G4endl;
|
|---|
| 129 | return;
|
|---|
| 130 | }
|
|---|
| 131 | }
|
|---|
| [856] | 132 | #if QT_VERSION < 0x040000
|
|---|
| [874] | 133 | qApp = new QApplication (a_argn, a_args);
|
|---|
| [856] | 134 | // QApplication qApp(a_argn, a_args);
|
|---|
| 135 | // if(&qApp == NULL) {
|
|---|
| 136 | #else
|
|---|
| [874] | 137 | new QApplication (a_argn, a_args);
|
|---|
| [856] | 138 | #endif
|
|---|
| [874] | 139 |
|
|---|
| [856] | 140 | if(!qApp) {
|
|---|
| 141 |
|
|---|
| 142 | G4cout << "G4Qt : Unable to init Qt." << G4endl;
|
|---|
| 143 | } else {
|
|---|
| [874] | 144 | if (a_argn != 0) {
|
|---|
| 145 | SetMainInteractor (qApp);
|
|---|
| 146 | SetArguments (a_argn,a_args);
|
|---|
| 147 | }
|
|---|
| [856] | 148 | QtInited = TRUE;
|
|---|
| [874] | 149 | #ifdef G4DEBUG
|
|---|
| [856] | 150 | printf("G4Qt::G4Qt inited Qt END\n");
|
|---|
| 151 | #endif
|
|---|
| 152 | }
|
|---|
| [481] | 153 | }
|
|---|
| 154 | }
|
|---|
| [874] | 155 | #ifdef G4DEBUG
|
|---|
| [617] | 156 | if (qApp) {
|
|---|
| [606] | 157 | printf("G4Qt::qApp exist\n");
|
|---|
| [617] | 158 | } else {
|
|---|
| 159 | printf("G4Qt::qApp not exist\n");
|
|---|
| 160 | }
|
|---|
| [608] | 161 | #endif
|
|---|
| [496] | 162 | // AddDispatcher ((G4DispatchFunction)XtDispatchEvent);
|
|---|
| [481] | 163 | }
|
|---|
| 164 | /***************************************************************************/
|
|---|
| [484] | 165 | G4Qt::~G4Qt (
|
|---|
| [481] | 166 | )
|
|---|
| 167 | /***************************************************************************/
|
|---|
| 168 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
|---|
| 169 | {
|
|---|
| 170 | if(this==instance) {
|
|---|
| 171 | instance = NULL;
|
|---|
| 172 | }
|
|---|
| 173 | }
|
|---|
| 174 | /***************************************************************************/
|
|---|
| [484] | 175 | G4bool G4Qt::Inited (
|
|---|
| [481] | 176 | )
|
|---|
| 177 | /***************************************************************************/
|
|---|
| 178 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
|---|
| 179 | {
|
|---|
| [484] | 180 | return QtInited;
|
|---|
| [481] | 181 | }
|
|---|
| 182 | /***************************************************************************/
|
|---|
| [850] | 183 | /**
|
|---|
| 184 | Si j'ai bien compris, cette fonction ne sert à rien
|
|---|
| 185 | */
|
|---|
| [484] | 186 | void* G4Qt::GetEvent (
|
|---|
| [481] | 187 | )
|
|---|
| 188 | /***************************************************************************/
|
|---|
| 189 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
|---|
| 190 | {
|
|---|
| [850] | 191 | //FIXME
|
|---|
| 192 | // G4cout << "G4Qt : Rien compris a cette fonction G4Qt::GetEvent." << G4endl;
|
|---|
| 193 | // static XEvent event;
|
|---|
| 194 | // if(appContext==NULL) return NULL;
|
|---|
| 195 | // if(mainApp==NULL) return NULL;
|
|---|
| 196 | // QtAppNextEvent (appContext, &event);
|
|---|
| 197 | // return &event;
|
|---|
| 198 | printf("*");
|
|---|
| [593] | 199 | return 0;
|
|---|
| [481] | 200 | }
|
|---|
| 201 | /***************************************************************************/
|
|---|
| [484] | 202 | void G4Qt::FlushAndWaitExecution (
|
|---|
| [481] | 203 | )
|
|---|
| 204 | /***************************************************************************/
|
|---|
| 205 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
|---|
| 206 | {
|
|---|
| [850] | 207 | // printf("G4Qt::FlushAndWaitExecution :: Flush ....\n");
|
|---|
| [578] | 208 | if(!qApp) return;
|
|---|
| 209 | qApp->processEvents();
|
|---|
| [481] | 210 | }
|
|---|
| 211 |
|
|---|
| 212 | #endif
|
|---|
| 213 |
|
|---|
| 214 |
|
|---|
| 215 |
|
|---|