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 // F.W. Jones 05012018 27 // F.W. Jones 05012018 28 28 29 #include <stdlib.h> 29 #include <stdlib.h> 30 #include <string.h> 30 #include <string.h> 31 31 32 #include "G4ios.hh" 32 #include "G4ios.hh" 33 33 34 #include "G4SoQt.hh" 34 #include "G4SoQt.hh" 35 //#include "G4Qt.hh" 35 //#include "G4Qt.hh" 36 //#include "G4UImanager.hh" 36 //#include "G4UImanager.hh" 37 37 38 #include <Inventor/Qt/SoQt.h> 38 #include <Inventor/Qt/SoQt.h> 39 #include <QMainWindow> 39 #include <QMainWindow> 40 40 41 #include <qwidget.h> 41 #include <qwidget.h> 42 #include <qapplication.h> 42 #include <qapplication.h> 43 43 44 #ifndef G4GMAKE 44 #ifndef G4GMAKE 45 #include "moc_G4SoQt.cpp" 45 #include "moc_G4SoQt.cpp" 46 #endif 46 #endif 47 47 48 #define G4warn G4cout << 49 << 50 G4SoQt* G4SoQt::instance = NULL; 48 G4SoQt* G4SoQt::instance = NULL; 51 49 52 static G4bool QtInited = FALSE; 50 static G4bool QtInited = FALSE; 53 51 54 52 55 /********************************************* 53 /***************************************************************************/ 56 G4SoQt* G4SoQt::getInstance() 54 G4SoQt* G4SoQt::getInstance() 57 { 55 { 58 if (instance==NULL) { 56 if (instance==NULL) { 59 instance = new G4SoQt(); 57 instance = new G4SoQt(); 60 } 58 } 61 return instance; 59 return instance; 62 } 60 } 63 61 64 62 65 /********************************************* 63 /***************************************************************************/ 66 G4SoQt::G4SoQt() 64 G4SoQt::G4SoQt() 67 // FWJ command-line arguments omitted for time 65 // FWJ command-line arguments omitted for time being 68 //G4SoQt* G4SoQt(int a_argn, char** a_args, ch 66 //G4SoQt* G4SoQt(int a_argn, char** a_args, char*) 69 { 67 { 70 externalApp = false; 68 externalApp = false; 71 69 72 // FWJ in G4Qt this is used. qApp is Qt glo 70 // FWJ in G4Qt this is used. qApp is Qt global pointer 73 // to the (one and only one) QApplication ob 71 // to the (one and only one) QApplication object: 74 // new QApplication (*p_argn, args); 72 // new QApplication (*p_argn, args); 75 // if(!qApp) { 73 // if(!qApp) { 76 74 77 // FWJ detects existence of Qt UI or other r 75 // FWJ detects existence of Qt UI or other running qApp 78 if (qApp) externalApp = true; 76 if (qApp) externalApp = true; 79 77 80 QWidget* mainWin = SoQt::init("Geant4"); 78 QWidget* mainWin = SoQt::init("Geant4"); 81 79 82 // FWJ Cf Xt: 80 // FWJ Cf Xt: 83 QtInited = TRUE; 81 QtInited = TRUE; 84 82 85 // FWJ DEBUG 83 // FWJ DEBUG 86 // G4cout << "G4SoQt: mainWin=" << mainWin 84 // G4cout << "G4SoQt: mainWin=" << mainWin << G4endl; 87 // G4cout << "G4SoQt: toplevelwidget=" << S 85 // G4cout << "G4SoQt: toplevelwidget=" << SoQt::getTopLevelWidget() << G4endl; 88 86 89 // FWJ CAN'T GET MENUBAR THIS WAY OR BY CAST 87 // FWJ CAN'T GET MENUBAR THIS WAY OR BY CAST 90 // QWidget* toplevel = SoQt::getTopLevelWid 88 // QWidget* toplevel = SoQt::getTopLevelWidget(); 91 // QMenuBar* menubar = QMainWindow::menuBar 89 // QMenuBar* menubar = QMainWindow::menuBar(); 92 // G4cout << "G4OpenInventorQtExaminerViewe 90 // G4cout << "G4OpenInventorQtExaminerViewer menubar=" << menubar << G4endl; 93 91 94 92 95 // FWJ will this work? 93 // FWJ will this work? 96 SetMainInteractor(mainWin); 94 SetMainInteractor(mainWin); 97 // SetMainInteractor(qApp); 95 // SetMainInteractor(qApp); 98 // AddDispatcher ((G4DispatchFunction)X 96 // AddDispatcher ((G4DispatchFunction)XtDispatchEvent); 99 97 100 // FWJ no locale for now (see G4Qt.cc) 98 // FWJ no locale for now (see G4Qt.cc) 101 99 102 } 100 } 103 101 104 /********************************************* 102 /***************************************************************************/ 105 G4SoQt::~G4SoQt() 103 G4SoQt::~G4SoQt() 106 { 104 { 107 if(this==instance) { 105 if(this==instance) { 108 instance = NULL; 106 instance = NULL; 109 } 107 } 110 } 108 } 111 109 112 G4bool G4SoQt::Inited() 110 G4bool G4SoQt::Inited() 113 { 111 { 114 return QtInited; 112 return QtInited; 115 } 113 } 116 114 117 /********************************************* 115 /***************************************************************************/ 118 void* G4SoQt::GetEvent() 116 void* G4SoQt::GetEvent() 119 { 117 { 120 return 0; 118 return 0; 121 } 119 } 122 120 123 121 124 /********************************************* 122 /***************************************************************************/ 125 void G4SoQt::FlushAndWaitExecution() 123 void G4SoQt::FlushAndWaitExecution() 126 { 124 { 127 // FWJ the following is used in G4Qt: 125 // FWJ the following is used in G4Qt: 128 // if(!qApp) return; 126 // if(!qApp) return; 129 // This starts the Qt main loop: 127 // This starts the Qt main loop: 130 // qApp->processEvents(); 128 // qApp->processEvents(); 131 129 132 // FWJ no, should be done in secondaryLoop( 130 // FWJ no, should be done in secondaryLoop()! 133 // SoQt::mainLoop(); 131 // SoQt::mainLoop(); 134 } 132 } 135 133 136 134 137 /********************************************* 135 /***************************************************************************/ 138 void G4SoQt::SecondaryLoop() 136 void G4SoQt::SecondaryLoop() 139 { 137 { 140 if (externalApp) return; 138 if (externalApp) return; 141 139 142 // FWJ DEBUG 140 // FWJ DEBUG 143 // G4cout << 141 // G4cout << 144 // "ENTERING OIQT VIEWER SECONDARY LOOP 142 // "ENTERING OIQT VIEWER SECONDARY LOOP" << G4endl; 145 // else 143 // else 146 144 147 G4warn << << 145 G4cout << 148 "ENTERING OIQT VIEWER SECONDARY LOOP... 146 "ENTERING OIQT VIEWER SECONDARY LOOP... PRESS E KEY TO EXIT" << G4endl; 149 147 150 SoQt::mainLoop(); 148 SoQt::mainLoop(); 151 } 149 } 152 150 153 151 154 /********************************************* 152 /***************************************************************************/ 155 void G4SoQt::ExitSecondaryLoop() 153 void G4SoQt::ExitSecondaryLoop() 156 { 154 { 157 // FWJ DEBUG 155 // FWJ DEBUG 158 // G4cout << "G4SoQt: EXIT SECONDARY LOOP 156 // G4cout << "G4SoQt: EXIT SECONDARY LOOP externalApp=" << 159 // externalApp << G4endl; 157 // externalApp << G4endl; 160 158 161 if (externalApp) return; 159 if (externalApp) return; 162 SoQt::exitMainLoop(); 160 SoQt::exitMainLoop(); 163 } 161 } 164 /********************************************* 162 /***************************************************************************/ 165 bool G4SoQt::IsExternalApp() 163 bool G4SoQt::IsExternalApp() 166 { 164 { 167 return externalApp; 165 return externalApp; 168 } 166 } 169 167