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