Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // 26 // 27 // 27 // 28 // L. Garnier 28 // L. Garnier 29 29 30 #include "G4Qt.hh" 30 #include "G4Qt.hh" 31 31 32 #include "G4UImanager.hh" 32 #include "G4UImanager.hh" 33 #include "G4ios.hh" 33 #include "G4ios.hh" 34 34 35 #include <qapplication.h> 35 #include <qapplication.h> 36 #include <qwidget.h> 36 #include <qwidget.h> 37 37 38 #include <cstdlib> 38 #include <cstdlib> 39 #include <cstring> 39 #include <cstring> 40 40 41 #ifdef G4VIS_USE_VTK_QT 41 #ifdef G4VIS_USE_VTK_QT 42 # include "QVTKOpenGLNativeWidget.h" 42 # include "QVTKOpenGLNativeWidget.h" 43 # include <qsurfaceformat.h> 43 # include <qsurfaceformat.h> 44 #endif 44 #endif 45 45 46 G4Qt* G4Qt::instance = nullptr; 46 G4Qt* G4Qt::instance = nullptr; 47 47 48 static G4bool QtInited = false; 48 static G4bool QtInited = false; 49 49 50 /********************************************* 50 /***************************************************************************/ 51 G4Qt* G4Qt::getInstance() 51 G4Qt* G4Qt::getInstance() 52 /********************************************* 52 /***************************************************************************/ 53 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 53 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ 54 { 54 { 55 return G4Qt::getInstance(0, nullptr, (char*) 55 return G4Qt::getInstance(0, nullptr, (char*)"Geant4"); 56 } 56 } 57 /********************************************* 57 /***************************************************************************/ 58 G4Qt* G4Qt::getInstance(int a_argn, char** a_a 58 G4Qt* G4Qt::getInstance(int a_argn, char** a_args, char* a_class) 59 /********************************************* 59 /***************************************************************************/ 60 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 60 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ 61 { 61 { 62 if (instance == nullptr) { 62 if (instance == nullptr) { 63 instance = new G4Qt(a_argn, a_args, a_clas 63 instance = new G4Qt(a_argn, a_args, a_class); 64 } 64 } 65 return instance; 65 return instance; 66 } 66 } 67 /********************************************* 67 /***************************************************************************/ 68 G4Qt::G4Qt(int a_argn, char** a_args, char* /* 68 G4Qt::G4Qt(int a_argn, char** a_args, char* /*a_class */ 69 ) 69 ) 70 /********************************************* 70 /***************************************************************************/ 71 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 71 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ 72 { 72 { 73 argn = 0; 73 argn = 0; 74 args = nullptr; 74 args = nullptr; 75 externalApp = false; 75 externalApp = false; 76 76 77 // Check if Qt already init in another exter 77 // Check if Qt already init in another external app 78 if (qApp) { 78 if (qApp) { 79 externalApp = true; 79 externalApp = true; 80 QtInited = true; 80 QtInited = true; 81 SetMainInteractor(qApp); 81 SetMainInteractor(qApp); 82 SetArguments(a_argn, a_args); 82 SetArguments(a_argn, a_args); 83 } 83 } 84 else { 84 else { 85 if (! QtInited) { // Qt should be Inited 85 if (! QtInited) { // Qt should be Inited once ! 86 // Then two cases : 86 // Then two cases : 87 // - It is the first time we create G4UI 87 // - It is the first time we create G4UI (argc!=0) 88 // -> Inited and register 88 // -> Inited and register 89 // - It is the first time we create G4VI 89 // - It is the first time we create G4VIS (argc == 0) 90 // -> Inited and NOT register 90 // -> Inited and NOT register 91 91 92 if (a_argn != 0) { 92 if (a_argn != 0) { 93 argn = a_argn; 93 argn = a_argn; 94 args = a_args; 94 args = a_args; 95 } 95 } 96 else { // argc = 0 96 else { // argc = 0 97 97 98 // FIXME : That's not the good argumen 98 // FIXME : That's not the good arguments, but I don't know how to get args from other 99 // Interactor. Ex: How to get them fro 99 // Interactor. Ex: How to get them from G4Xt ? 100 argn = 1; 100 argn = 1; 101 args = (char**)malloc(1 * sizeof(char* 101 args = (char**)malloc(1 * sizeof(char*)); 102 args[0] = (char*)malloc(10 * sizeof(ch 102 args[0] = (char*)malloc(10 * sizeof(char)); 103 strncpy(args[0], "my_app \0", 9); 103 strncpy(args[0], "my_app \0", 9); 104 } 104 } 105 105 106 int* p_argn = (int*)malloc(sizeof(int)); 106 int* p_argn = (int*)malloc(sizeof(int)); 107 *p_argn = argn; 107 *p_argn = argn; 108 #ifdef WIN32 108 #ifdef WIN32 109 qApp->setAttribute(Qt::AA_UseDesktopOpen 109 qApp->setAttribute(Qt::AA_UseDesktopOpenGL); 110 #endif 110 #endif 111 111 112 #ifdef G4VIS_USE_VTK_QT 112 #ifdef G4VIS_USE_VTK_QT 113 QSurfaceFormat::setDefaultFormat(QVTKOpe 113 QSurfaceFormat::setDefaultFormat(QVTKOpenGLNativeWidget::defaultFormat()); 114 #endif 114 #endif 115 new QApplication(*p_argn, args); 115 new QApplication(*p_argn, args); 116 if (! qApp) { 116 if (! qApp) { 117 G4UImanager* UImanager = G4UImanager:: 117 G4UImanager* UImanager = G4UImanager::GetUIpointer(); 118 G4int verbose = UImanager->GetVerboseL 118 G4int verbose = UImanager->GetVerboseLevel(); 119 if (verbose >= 2) { 119 if (verbose >= 2) { 120 G4cout << "G4Qt : Unable to init Qt. 120 G4cout << "G4Qt : Unable to init Qt." << G4endl; 121 } 121 } 122 } 122 } 123 else { 123 else { 124 QtInited = true; 124 QtInited = true; 125 if (a_argn != 0) { 125 if (a_argn != 0) { 126 SetMainInteractor(qApp); 126 SetMainInteractor(qApp); 127 } 127 } 128 SetArguments(a_argn, a_args); 128 SetArguments(a_argn, a_args); 129 } 129 } 130 } 130 } 131 } 131 } 132 // AddDispatcher ((G4DispatchFunction)X 132 // AddDispatcher ((G4DispatchFunction)XtDispatchEvent); 133 133 134 /* 134 /* 135 * On some non-English locale, comma is used 135 * On some non-English locale, comma is used for the decimal separator instead of dot 136 * bringing to weird behavior of strtod (str 136 * bringing to weird behavior of strtod (string to double) function in user application. 137 * This is "by design" from Qt, see https:// 137 * This is "by design" from Qt, see https://bugreports.qt-project.org/browse/QTBUG-10994 138 * 138 * 139 * $ LC_NUMERIC=fr_FR.UTF-8 ./qtstrtod 139 * $ LC_NUMERIC=fr_FR.UTF-8 ./qtstrtod 140 * strtod(0.1) = 0 140 * strtod(0.1) = 0 141 * $ LC_NUMERIC=C ./qtstrtod 141 * $ LC_NUMERIC=C ./qtstrtod 142 * strtod(0.1) = 0.1 142 * strtod(0.1) = 0.1 143 * 143 * 144 * Jerome Suhard, jerome@suhard.fr 144 * Jerome Suhard, jerome@suhard.fr 145 */ 145 */ 146 146 147 // explicitly set the LC_NUMBERIC locale to 147 // explicitly set the LC_NUMBERIC locale to "C" 148 setlocale(LC_NUMERIC, "C"); 148 setlocale(LC_NUMERIC, "C"); 149 } 149 } 150 /********************************************* 150 /***************************************************************************/ 151 G4Qt::~G4Qt() 151 G4Qt::~G4Qt() 152 /********************************************* 152 /***************************************************************************/ 153 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 153 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ 154 { 154 { 155 if (this == instance) { 155 if (this == instance) { 156 instance = nullptr; 156 instance = nullptr; 157 } 157 } 158 } 158 } 159 /********************************************* 159 /***************************************************************************/ 160 G4bool G4Qt::Inited() 160 G4bool G4Qt::Inited() 161 /********************************************* 161 /***************************************************************************/ 162 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 162 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ 163 { 163 { 164 return QtInited; 164 return QtInited; 165 } 165 } 166 /********************************************* 166 /***************************************************************************/ 167 void* G4Qt::GetEvent() 167 void* G4Qt::GetEvent() 168 /********************************************* 168 /***************************************************************************/ 169 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 169 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ 170 { 170 { 171 return nullptr; 171 return nullptr; 172 } 172 } 173 /********************************************* 173 /***************************************************************************/ 174 void G4Qt::FlushAndWaitExecution() 174 void G4Qt::FlushAndWaitExecution() 175 /********************************************* 175 /***************************************************************************/ 176 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 176 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ 177 { 177 { 178 if (! qApp) return; 178 if (! qApp) return; 179 qApp->processEvents(); 179 qApp->processEvents(); 180 } 180 } 181 181 182 /********************************************* 182 /***************************************************************************/ 183 bool G4Qt::IsExternalApp() 183 bool G4Qt::IsExternalApp() 184 /********************************************* 184 /***************************************************************************/ 185 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 185 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ 186 { 186 { 187 return externalApp; 187 return externalApp; 188 } 188 } 189 189