00001 // 00002 // ******************************************************************** 00003 // * License and Disclaimer * 00004 // * * 00005 // * The Geant4 software is copyright of the Copyright Holders of * 00006 // * the Geant4 Collaboration. It is provided under the terms and * 00007 // * conditions of the Geant4 Software License, included in the file * 00008 // * LICENSE and available at http://cern.ch/geant4/license . These * 00009 // * include a list of copyright holders. * 00010 // * * 00011 // * Neither the authors of this software system, nor their employing * 00012 // * institutes,nor the agencies providing financial support for this * 00013 // * work make any representation or warranty, express or implied, * 00014 // * regarding this software system or assume any liability for its * 00015 // * use. Please see the license in the file LICENSE and URL above * 00016 // * for the full disclaimer and the limitation of liability. * 00017 // * * 00018 // * This code implementation is the result of the scientific and * 00019 // * technical work of the GEANT4 collaboration. * 00020 // * By using, copying, modifying or distributing the software (or * 00021 // * any work based on the software) you agree to acknowledge its * 00022 // * use in resulting scientific publications, and indicate your * 00023 // * acceptance of all terms of the Geant4 Software license. * 00024 // ******************************************************************** 00025 // 00026 // 00027 // $Id$ 00028 // 00029 // L. Garnier 00030 00031 #if defined(G4INTY_BUILD_QT) || defined(G4INTY_USE_QT) 00032 00033 #include <stdlib.h> 00034 #include <string.h> 00035 00036 #include "G4ios.hh" 00037 00038 #include "G4Qt.hh" 00039 #include <qwidget.h> 00040 00041 #include <qapplication.h> 00042 00043 00044 G4Qt* G4Qt::instance = NULL; 00045 00046 static G4bool QtInited = FALSE; 00047 00048 /***************************************************************************/ 00049 G4Qt* G4Qt::getInstance ( 00050 ) 00051 /***************************************************************************/ 00053 { 00054 return G4Qt::getInstance (0,NULL,(char*)"Geant4"); 00055 } 00056 /***************************************************************************/ 00057 G4Qt* G4Qt::getInstance ( 00058 int a_argn 00059 ,char** a_args 00060 ,char* a_class 00061 ) 00062 /***************************************************************************/ 00064 { 00065 if (instance==NULL) { 00066 instance = new G4Qt(a_argn,a_args,a_class); 00067 } 00068 return instance; 00069 } 00070 /***************************************************************************/ 00071 G4Qt::G4Qt ( 00072 int a_argn 00073 ,char** a_args 00074 ,char* /*a_class */ 00075 ) 00076 /***************************************************************************/ 00078 { 00079 argn = 0; 00080 args = NULL; 00081 externalApp = false; 00082 00083 #ifdef G4DEBUG_INTERFACES_COMMON 00084 printf("G4Qt::G4Qt try to inited Qt\n"); 00085 #endif 00086 // Check if Qt already init in another external app 00087 if(qApp) { 00088 externalApp = true; 00089 QtInited = TRUE; 00090 SetMainInteractor (qApp); 00091 SetArguments (a_argn,a_args); 00092 00093 #ifdef G4DEBUG_INTERFACES_COMMON 00094 printf("G4Qt::G4Qt alredy inited in external \n"); 00095 #endif 00096 } else { 00097 00098 if(QtInited==FALSE) { //Qt should be Inited once ! 00099 // Then two cases : 00100 // - It is the first time we create G4UI (argc!=0) 00101 // -> Inited and register 00102 // - It is the first time we create G4VIS (argc == 0) 00103 // -> Inited and NOT register 00104 00105 if (a_argn != 0) { 00106 argn = a_argn; 00107 args = a_args; 00108 00109 } else { //argc = 0 00110 00111 // FIXME : That's not the good arguments, but I don't know how to get args from other Interactor. 00112 // Ex: How to get them from G4Xt ? 00113 argn = 1; 00114 args = (char **)malloc( 1 * sizeof(char *) ); 00115 args[0] = (char *)malloc(10 * sizeof(char)); 00116 strncpy(args[0], "my_app \0", 9); 00117 } 00118 00119 int *p_argn = (int*)malloc(sizeof(int)); 00120 *p_argn = argn; 00121 #ifdef G4DEBUG_INTERFACES_COMMON 00122 printf("G4Qt::G4Qt QAppl \n"); 00123 #endif 00124 new QApplication (*p_argn, args); 00125 if(!qApp) { 00126 00127 G4cout << "G4Qt : Unable to init Qt." << G4endl; 00128 } else { 00129 QtInited = TRUE; 00130 if (a_argn != 0) { 00131 #ifdef G4DEBUG_INTERFACES_COMMON 00132 printf("G4Qt::G4Qt SetMainInteractor\n"); 00133 #endif 00134 SetMainInteractor (qApp); 00135 } 00136 SetArguments (a_argn,a_args); 00137 #ifdef G4DEBUG_INTERFACES_COMMON 00138 printf("G4Qt::G4Qt inited Qt END\n"); 00139 #endif 00140 } 00141 } 00142 } 00143 #ifdef G4DEBUG_INTERFACES_COMMON 00144 if (qApp) { 00145 printf("G4Qt::qApp already exist\n"); 00146 } else { 00147 printf("G4Qt::qApp not exist\n"); 00148 } 00149 #endif 00150 // AddDispatcher ((G4DispatchFunction)XtDispatchEvent); 00151 } 00152 /***************************************************************************/ 00153 G4Qt::~G4Qt ( 00154 ) 00155 /***************************************************************************/ 00157 { 00158 if(this==instance) { 00159 instance = NULL; 00160 } 00161 } 00162 /***************************************************************************/ 00163 G4bool G4Qt::Inited ( 00164 ) 00165 /***************************************************************************/ 00167 { 00168 return QtInited; 00169 } 00170 /***************************************************************************/ 00174 void* G4Qt::GetEvent ( 00175 ) 00176 /***************************************************************************/ 00178 { 00179 //FIXME 00180 // G4cout << "G4Qt : Rien compris a cette fonction G4Qt::GetEvent." << G4endl; 00181 // static XEvent event; 00182 // if(appContext==NULL) return NULL; 00183 // if(mainApp==NULL) return NULL; 00184 // QtAppNextEvent (appContext, &event); 00185 // return &event; 00186 printf("*"); 00187 return 0; 00188 } 00189 /***************************************************************************/ 00190 void G4Qt::FlushAndWaitExecution ( 00191 ) 00192 /***************************************************************************/ 00194 { 00195 // printf("G4Qt::FlushAndWaitExecution :: Flush ....\n"); 00196 if(!qApp) return; 00197 qApp->processEvents(); 00198 } 00199 00200 /***************************************************************************/ 00201 bool G4Qt::IsExternalApp ( 00202 ) 00203 /***************************************************************************/ 00205 { 00206 return externalApp; 00207 } 00208 00209 #endif 00210 00211