[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 | // |
---|
[1134] | 27 | // $Id: G4Qt.cc,v 1.14 2009/10/07 09:12:35 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" |
---|
[1158] | 40 | #include "G4UIQt.hh" |
---|
| 41 | #include <qwidget.h> |
---|
[481] | 42 | |
---|
[595] | 43 | #include <qapplication.h> |
---|
[593] | 44 | |
---|
| 45 | |
---|
[484] | 46 | G4Qt* G4Qt::instance = NULL; |
---|
[481] | 47 | |
---|
[484] | 48 | static G4bool QtInited = FALSE; |
---|
| 49 | |
---|
[481] | 50 | /***************************************************************************/ |
---|
[484] | 51 | G4Qt* G4Qt::getInstance ( |
---|
[481] | 52 | ) |
---|
| 53 | /***************************************************************************/ |
---|
| 54 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
| 55 | { |
---|
[484] | 56 | return G4Qt::getInstance (0,NULL,(char*)"Geant4"); |
---|
[481] | 57 | } |
---|
| 58 | /***************************************************************************/ |
---|
[484] | 59 | G4Qt* G4Qt::getInstance ( |
---|
[874] | 60 | int a_argn |
---|
[481] | 61 | ,char** a_args |
---|
| 62 | ,char* a_class |
---|
| 63 | ) |
---|
| 64 | /***************************************************************************/ |
---|
| 65 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
| 66 | { |
---|
| 67 | if (instance==NULL) { |
---|
[484] | 68 | instance = new G4Qt(a_argn,a_args,a_class); |
---|
[481] | 69 | } |
---|
[1158] | 70 | #ifdef G4DEBUG_INTERFACES_COMMON |
---|
| 71 | printf("G4Qt::getInstance :%d\n",instance); |
---|
| 72 | #endif |
---|
[481] | 73 | return instance; |
---|
| 74 | } |
---|
| 75 | /***************************************************************************/ |
---|
[484] | 76 | G4Qt::G4Qt ( |
---|
[874] | 77 | int a_argn |
---|
[481] | 78 | ,char** a_args |
---|
[989] | 79 | ,char* /*a_class */ |
---|
[1163] | 80 | ) |
---|
| 81 | :fG4UI(NULL) |
---|
[481] | 82 | /***************************************************************************/ |
---|
| 83 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
| 84 | { |
---|
[876] | 85 | argn = 0; |
---|
| 86 | args = NULL; |
---|
| 87 | |
---|
[1120] | 88 | #ifdef G4DEBUG_INTERFACES_COMMON |
---|
[571] | 89 | printf("G4Qt::G4Qt try to inited Qt\n"); |
---|
[608] | 90 | #endif |
---|
[856] | 91 | // Check if Qt already init in another external app |
---|
| 92 | if(qApp) { |
---|
[876] | 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 | |
---|
[1120] | 101 | #ifdef G4DEBUG_INTERFACES_COMMON |
---|
[876] | 102 | printf("G4Qt::G4Qt alredy inited in external \n"); |
---|
[608] | 103 | #endif |
---|
[856] | 104 | } else { |
---|
[876] | 105 | |
---|
[856] | 106 | if(QtInited==FALSE) { //Qt should be Inited once ! |
---|
[874] | 107 | // Then two cases : |
---|
| 108 | // - It is the first time we create G4UI (argc!=0) |
---|
| 109 | // -> Inited and register |
---|
[876] | 110 | // - It is the first time we create G4VIS (argc == 0) |
---|
[874] | 111 | // -> Inited and NOT register |
---|
[876] | 112 | |
---|
| 113 | if (a_argn != 0) { |
---|
| 114 | argn = a_argn; |
---|
| 115 | args = a_args; |
---|
[874] | 116 | |
---|
| 117 | } else { //argc = 0 |
---|
| 118 | |
---|
[876] | 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 | } |
---|
[874] | 126 | |
---|
[876] | 127 | int *p_argn = (int*)malloc(sizeof(int)); |
---|
| 128 | *p_argn = argn; |
---|
[856] | 129 | #if QT_VERSION < 0x040000 |
---|
[889] | 130 | qApp = new QApplication (*p_argn, args); |
---|
[856] | 131 | #else |
---|
[889] | 132 | new QApplication (*p_argn, args); |
---|
[856] | 133 | #endif |
---|
| 134 | if(!qApp) { |
---|
| 135 | |
---|
| 136 | G4cout << "G4Qt : Unable to init Qt." << G4endl; |
---|
| 137 | } else { |
---|
[876] | 138 | QtInited = TRUE; |
---|
[874] | 139 | if (a_argn != 0) { |
---|
| 140 | SetMainInteractor (qApp); |
---|
| 141 | } |
---|
[876] | 142 | SetArguments (a_argn,a_args); |
---|
[1120] | 143 | #ifdef G4DEBUG_INTERFACES_COMMON |
---|
[856] | 144 | printf("G4Qt::G4Qt inited Qt END\n"); |
---|
| 145 | #endif |
---|
| 146 | } |
---|
[481] | 147 | } |
---|
| 148 | } |
---|
[1120] | 149 | #ifdef G4DEBUG_INTERFACES_COMMON |
---|
[617] | 150 | if (qApp) { |
---|
[1158] | 151 | printf("G4Qt::qApp exist adress:%d\n",this); |
---|
[617] | 152 | } else { |
---|
| 153 | printf("G4Qt::qApp not exist\n"); |
---|
| 154 | } |
---|
[608] | 155 | #endif |
---|
[496] | 156 | // AddDispatcher ((G4DispatchFunction)XtDispatchEvent); |
---|
[481] | 157 | } |
---|
| 158 | /***************************************************************************/ |
---|
[484] | 159 | G4Qt::~G4Qt ( |
---|
[481] | 160 | ) |
---|
| 161 | /***************************************************************************/ |
---|
| 162 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
| 163 | { |
---|
| 164 | if(this==instance) { |
---|
| 165 | instance = NULL; |
---|
| 166 | } |
---|
| 167 | } |
---|
| 168 | /***************************************************************************/ |
---|
[484] | 169 | G4bool G4Qt::Inited ( |
---|
[481] | 170 | ) |
---|
| 171 | /***************************************************************************/ |
---|
| 172 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
| 173 | { |
---|
[484] | 174 | return QtInited; |
---|
[481] | 175 | } |
---|
| 176 | /***************************************************************************/ |
---|
[850] | 177 | /** |
---|
| 178 | Si j'ai bien compris, cette fonction ne sert à rien |
---|
| 179 | */ |
---|
[484] | 180 | void* G4Qt::GetEvent ( |
---|
[481] | 181 | ) |
---|
| 182 | /***************************************************************************/ |
---|
| 183 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
| 184 | { |
---|
[850] | 185 | //FIXME |
---|
| 186 | // G4cout << "G4Qt : Rien compris a cette fonction G4Qt::GetEvent." << G4endl; |
---|
| 187 | // static XEvent event; |
---|
| 188 | // if(appContext==NULL) return NULL; |
---|
| 189 | // if(mainApp==NULL) return NULL; |
---|
| 190 | // QtAppNextEvent (appContext, &event); |
---|
| 191 | // return &event; |
---|
| 192 | printf("*"); |
---|
[593] | 193 | return 0; |
---|
[481] | 194 | } |
---|
| 195 | /***************************************************************************/ |
---|
[484] | 196 | void G4Qt::FlushAndWaitExecution ( |
---|
[481] | 197 | ) |
---|
| 198 | /***************************************************************************/ |
---|
| 199 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
| 200 | { |
---|
[850] | 201 | // printf("G4Qt::FlushAndWaitExecution :: Flush ....\n"); |
---|
[578] | 202 | if(!qApp) return; |
---|
| 203 | qApp->processEvents(); |
---|
[481] | 204 | } |
---|
| 205 | |
---|
[1158] | 206 | /***************************************************************************/ |
---|
| 207 | void G4Qt::SetG4UI ( |
---|
| 208 | G4UIQt* ui |
---|
| 209 | ) |
---|
| 210 | /***************************************************************************/ |
---|
| 211 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
| 212 | { |
---|
[1163] | 213 | #ifdef G4DEBUG_INTERFACES_COMMON |
---|
| 214 | printf("G4Qt::SetG4UI \n"); |
---|
| 215 | #endif |
---|
[1158] | 216 | fG4UI = ui; |
---|
| 217 | } |
---|
| 218 | |
---|
| 219 | /***************************************************************************/ |
---|
| 220 | bool G4Qt::AddTabVisWidget ( |
---|
| 221 | QWidget * vis |
---|
[1179] | 222 | ,QString name |
---|
| 223 | ,int sizeX |
---|
| 224 | ,int sizeY |
---|
[1158] | 225 | ) |
---|
| 226 | /***************************************************************************/ |
---|
| 227 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
| 228 | { |
---|
[1163] | 229 | if (fG4UI != NULL) { |
---|
[1179] | 230 | fG4UI->AddTabVisWidget(vis,name,sizeX,sizeY); |
---|
[1158] | 231 | return true; |
---|
| 232 | } |
---|
| 233 | return false; |
---|
| 234 | } |
---|
[481] | 235 | #endif |
---|
| 236 | |
---|
| 237 | |
---|
| 238 | |
---|