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 "G4ToolsSGXtGLES.hh" 28 #include "G4ToolsSGXtGLES.hh" 29 29 30 #include "G4ToolsSGViewer.hh" 30 #include "G4ToolsSGViewer.hh" 31 #include <toolx/Xt/sg_viewer> << 31 #include <tools/Xt/sg_viewer> 32 32 33 #include "G4Xt.hh" 33 #include "G4Xt.hh" 34 34 35 class session : public toolx::Xt::session { << 35 class session : public tools::Xt::session { 36 using parent = toolx::Xt::session; << 36 typedef tools::Xt::session parent; 37 public: 37 public: 38 session(std::ostream& a_out) << 38 session(std::ostream& a_out,int a_argc,char** a_argv) 39 :parent(a_out) << 39 :parent(a_out,a_argc,a_argv) 40 { 40 { >> 41 if(m_app_widget) {::XtDestroyWidget(m_app_widget);m_app_widget = nullptr;} >> 42 if(m_app_context) {::XtDestroyApplicationContext(m_app_context);m_app_context = nullptr;} 41 m_app_widget = (Widget)G4Xt::getInstance() 43 m_app_widget = (Widget)G4Xt::getInstance()->GetMainInteractor(); 42 m_app_context = ::XtWidgetToApplicationCon 44 m_app_context = ::XtWidgetToApplicationContext(m_app_widget); 43 m_app_owner = false; << 44 } 45 } 45 virtual ~session() {} 46 virtual ~session() {} 46 protected: 47 protected: 47 session(const session& a_from):parent(a_from 48 session(const session& a_from):parent(a_from){} 48 session& operator=(const session& a_from){pa 49 session& operator=(const session& a_from){parent::operator=(a_from);return *this;} 49 }; 50 }; 50 51 >> 52 #include <tools/argcv> >> 53 51 G4ToolsSGXtGLES::G4ToolsSGXtGLES(): 54 G4ToolsSGXtGLES::G4ToolsSGXtGLES(): 52 parent 55 parent 53 ("TOOLSSG_XT_GLES", 56 ("TOOLSSG_XT_GLES", 54 "TSG_XT_GLES", 57 "TSG_XT_GLES", 55 "TOOLSSG_XT_GLES is a graphics driver based o 58 "TOOLSSG_XT_GLES is a graphics driver based on the g4tools tools/sg scene graph logic where\n\ 56 the rendering is done with GLES and the windo 59 the rendering is done with GLES and the windowing is done with the Xt toolkit.", 57 parent::threeDInteractive) 60 parent::threeDInteractive) 58 ,fSGSession(nullptr) 61 ,fSGSession(nullptr) 59 {} 62 {} 60 63 61 G4ToolsSGXtGLES::~G4ToolsSGXtGLES() { 64 G4ToolsSGXtGLES::~G4ToolsSGXtGLES() { 62 delete fSGSession; 65 delete fSGSession; 63 } 66 } 64 67 65 void G4ToolsSGXtGLES::Initialise() { 68 void G4ToolsSGXtGLES::Initialise() { 66 if(fSGSession) return; //done. 69 if(fSGSession) return; //done. 67 fSGSession = new session(G4cout); << 70 int* argc = new int; >> 71 char** argv = nullptr; >> 72 tools::new_argcv(std::vector<std::string>(),*argc,argv); >> 73 fSGSession = new session(G4cout,*argc,argv); 68 if(!fSGSession->is_valid()) { 74 if(!fSGSession->is_valid()) { 69 G4cerr << "G4ToolsSGXtGLES::Initialise : s 75 G4cerr << "G4ToolsSGXtGLES::Initialise : session::is_valid() failed." << G4endl; 70 delete fSGSession; 76 delete fSGSession; 71 fSGSession = nullptr; 77 fSGSession = nullptr; 72 return; 78 return; 73 } 79 } 74 } 80 } 75 81 76 G4VSceneHandler* G4ToolsSGXtGLES::CreateSceneH 82 G4VSceneHandler* G4ToolsSGXtGLES::CreateSceneHandler(const G4String& a_name) { 77 G4VSceneHandler* pScene = new G4ToolsSGScene 83 G4VSceneHandler* pScene = new G4ToolsSGSceneHandler(*this, a_name); 78 return pScene; 84 return pScene; 79 } 85 } 80 86 81 G4VViewer* G4ToolsSGXtGLES::CreateViewer(G4VSc 87 G4VViewer* G4ToolsSGXtGLES::CreateViewer(G4VSceneHandler& a_scene,const G4String& a_name) { 82 if(!fSGSession) Initialise(); 88 if(!fSGSession) Initialise(); 83 if(!fSGSession) return nullptr; 89 if(!fSGSession) return nullptr; 84 G4VViewer* pView = 90 G4VViewer* pView = 85 new G4ToolsSGViewer<toolx::Xt::session,too << 91 new G4ToolsSGViewer<tools::Xt::session,tools::Xt::sg_viewer>(*fSGSession,(G4ToolsSGSceneHandler&)a_scene,a_name); 86 if (pView) { 92 if (pView) { 87 if (pView->GetViewId() < 0) { 93 if (pView->GetViewId() < 0) { 88 G4cerr << 94 G4cerr << 89 "G4ToolsSGXtGLES::CreateViewer: ERROR fl 95 "G4ToolsSGXtGLES::CreateViewer: ERROR flagged by negative" 90 " view id in G4ToolsSGViewer creation." 96 " view id in G4ToolsSGViewer creation." 91 "\n Destroying view and returning null p 97 "\n Destroying view and returning null pointer." 92 << G4endl; 98 << G4endl; 93 delete pView; 99 delete pView; 94 pView = nullptr; 100 pView = nullptr; 95 } 101 } 96 } 102 } 97 if (!pView) { 103 if (!pView) { 98 G4cerr << 104 G4cerr << 99 "G4ToolsSGXtGLES::CreateViewer: ERROR: nul 105 "G4ToolsSGXtGLES::CreateViewer: ERROR: null pointer on new G4ToolsSGViewer." 100 << G4endl; 106 << G4endl; 101 } 107 } 102 return pView; 108 return pView; >> 109 } >> 110 >> 111 G4bool G4ToolsSGXtGLES::IsUISessionCompatible () const >> 112 { >> 113 G4bool isCompatible = false; >> 114 // G4UImanager* ui = G4UImanager::GetUIpointer(); >> 115 // G4UIsession* session = ui->GetSession(); >> 116 // >> 117 // // If session is a batch session, it may be: >> 118 // // a) this is a batch job (the user has not instantiated any UI session); >> 119 // // b) we are currently processing a UI command, in which case the UI >> 120 // // manager creates a temporary batch session and to find out if there is >> 121 // // a genuine UI session that the user has instantiated we must drill >> 122 // // down through previous sessions to a possible non-batch session. >> 123 // while (G4UIbatch* batch = dynamic_cast<G4UIbatch*>(session)) { >> 124 // session = batch->GetPreviousSession(); >> 125 // } >> 126 // >> 127 // // Qt windows are only appropriate in a Qt session. >> 128 // if (session) { >> 129 // // If non-zero, this is the originating non-batch session >> 130 // // The user has instantiated a UI session... >> 131 // if (dynamic_cast<G4UIQt*>(session)) { >> 132 // // ...and it's a G4UIQt session, which is OK. >> 133 isCompatible = true; >> 134 // } >> 135 // } >> 136 return isCompatible; 103 } 137 } 104 138