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 // Guy Barrand 12th March 2021 26 // Guy Barrand 12th March 2021 27 27 28 #include "G4ToolsSGQtGLES.hh" 28 #include "G4ToolsSGQtGLES.hh" 29 29 30 #include "G4ToolsSGQtGLESViewer.hh" << 30 #define G4TOOLSSG_QT_VIEWER_IN_TAB 31 31 32 #include "G4Qt.hh" << 32 #ifdef G4TOOLSSG_QT_VIEWER_IN_TAB >> 33 #include "G4ToolsSGQtViewer.hh" >> 34 #else >> 35 #include "G4ToolsSGViewer.hh" >> 36 #include <toolx/Qt/sg_viewer> >> 37 #endif 33 38 34 #include "G4UIbatch.hh" 39 #include "G4UIbatch.hh" 35 40 >> 41 #include <tools/argcv> >> 42 36 G4ToolsSGQtGLES::G4ToolsSGQtGLES(): 43 G4ToolsSGQtGLES::G4ToolsSGQtGLES(): 37 parent 44 parent 38 ("TOOLSSG_QT_GLES", 45 ("TOOLSSG_QT_GLES", 39 "TSG_QT_GLES", 46 "TSG_QT_GLES", 40 "TOOLSSG_QT_GLES is a graphics driver based o 47 "TOOLSSG_QT_GLES is a graphics driver based on the g4tools tools/sg scene graph logic where\n\ 41 the rendering is done with GLES and the windo 48 the rendering is done with GLES and the windowing is done with Qt.", 42 parent::threeDInteractive) 49 parent::threeDInteractive) 43 ,fSGSession(nullptr) 50 ,fSGSession(nullptr) 44 {} 51 {} 45 52 46 G4ToolsSGQtGLES::~G4ToolsSGQtGLES() { 53 G4ToolsSGQtGLES::~G4ToolsSGQtGLES() { 47 delete fSGSession; 54 delete fSGSession; 48 } 55 } 49 56 50 void G4ToolsSGQtGLES::Initialise() { 57 void G4ToolsSGQtGLES::Initialise() { 51 if(fSGSession) return; //done. 58 if(fSGSession) return; //done. 52 G4Qt* interactorManager = G4Qt::getInstance( << 59 int* argc = new int; 53 auto* _qapp = (QApplication*)interactorMana << 60 char** argv = nullptr; 54 if(!_qapp) { << 61 std::vector<std::string> args;args.push_back(""); 55 G4cerr << "G4ToolsSGQtGLES::Initialise : G << 62 tools::new_argcv(args,*argc,argv); 56 return; << 63 fSGSession = new toolx::Qt::session(G4cout,*argc,argv); 57 } << 58 fSGSession = new toolx::Qt::session(G4cout,_ << 59 if(!fSGSession->is_valid()) { 64 if(!fSGSession->is_valid()) { 60 G4cerr << "G4ToolsSGQtGLES::Initialise : s 65 G4cerr << "G4ToolsSGQtGLES::Initialise : session::is_valid() failed." << G4endl; 61 delete fSGSession; 66 delete fSGSession; 62 fSGSession = nullptr; 67 fSGSession = nullptr; 63 return; 68 return; 64 } 69 } 65 } 70 } 66 71 67 G4VSceneHandler* G4ToolsSGQtGLES::CreateSceneH 72 G4VSceneHandler* G4ToolsSGQtGLES::CreateSceneHandler(const G4String& a_name) { 68 G4VSceneHandler* pScene = new G4ToolsSGScene 73 G4VSceneHandler* pScene = new G4ToolsSGSceneHandler(*this, a_name); 69 return pScene; 74 return pScene; 70 } 75 } 71 76 72 G4VViewer* G4ToolsSGQtGLES::CreateViewer(G4VSc 77 G4VViewer* G4ToolsSGQtGLES::CreateViewer(G4VSceneHandler& a_scene,const G4String& a_name) { 73 if(!fSGSession) Initialise(); 78 if(!fSGSession) Initialise(); 74 if(!fSGSession) return nullptr; 79 if(!fSGSession) return nullptr; 75 G4VViewer* pView = new G4ToolsSGQtGLESViewer << 80 G4VViewer* pView = >> 81 #ifdef G4TOOLSSG_QT_VIEWER_IN_TAB >> 82 new G4ToolsSGQtViewer(*fSGSession,(G4ToolsSGSceneHandler&)a_scene,a_name); >> 83 #else >> 84 new G4ToolsSGViewer<toolx::Qt::session,toolx::Qt::sg_viewer>(*fSGSession,(G4ToolsSGSceneHandler&)a_scene,a_name); >> 85 #endif 76 if (pView) { 86 if (pView) { 77 if (pView->GetViewId() < 0) { 87 if (pView->GetViewId() < 0) { 78 G4cerr << "G4ToolsSGQtGLES::CreateViewer 88 G4cerr << "G4ToolsSGQtGLES::CreateViewer:" 79 << " ERROR flagged by negative vi 89 << " ERROR flagged by negative view id in G4ToolsSGViewer creation." 80 << "\n Destroying view and return 90 << "\n Destroying view and returning null pointer." << G4endl; 81 delete pView; 91 delete pView; 82 pView = nullptr; 92 pView = nullptr; 83 } 93 } 84 } 94 } 85 if (!pView) { 95 if (!pView) { 86 G4cerr << "G4ToolsSGQtGLES::CreateViewer: 96 G4cerr << "G4ToolsSGQtGLES::CreateViewer: ERROR: null pointer on new G4ToolsSGViewer." << G4endl; 87 return nullptr; 97 return nullptr; 88 } 98 } 89 return pView; 99 return pView; 90 } 100 } 91 101 92 G4bool G4ToolsSGQtGLES::IsUISessionCompatible 102 G4bool G4ToolsSGQtGLES::IsUISessionCompatible () const 93 { 103 { 94 // Qt windows require a Qt session. << 104 G4bool isCompatible = false; 95 G4UIsession* baseSession = G4UImanager::GetU << 105 G4UImanager* ui = G4UImanager::GetUIpointer(); 96 if (dynamic_cast<G4UIQt*>(baseSession) != nu << 106 G4UIsession* session = ui->GetSession(); 97 return false; << 107 >> 108 // If session is a batch session, it may be: >> 109 // a) this is a batch job (the user has not instantiated any UI session); >> 110 // b) we are currently processing a UI command, in which case the UI >> 111 // manager creates a temporary batch session and to find out if there is >> 112 // a genuine UI session that the user has instantiated we must drill >> 113 // down through previous sessions to a possible non-batch session. >> 114 while (G4UIbatch* batch = dynamic_cast<G4UIbatch*>(session)) { >> 115 session = batch->GetPreviousSession(); >> 116 } >> 117 >> 118 // Qt windows are only appropriate in a Qt session. >> 119 if (session) { >> 120 // If non-zero, this is the originating non-batch session >> 121 // The user has instantiated a UI session... >> 122 if (dynamic_cast<G4UIQt*>(session)) { >> 123 // ...and it's a G4UIQt session, which is OK. >> 124 isCompatible = true; >> 125 } >> 126 } >> 127 return isCompatible; 98 } 128 } 99 129