Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4ToolsSGQtGLES.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26// Guy Barrand 12th March 2021
27
28#include "G4ToolsSGQtGLES.hh"
29
30#define G4TOOLSSG_QT_VIEWER_IN_TAB
31
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
38
39#include "G4UIbatch.hh"
40
41#include <tools/argcv>
42
45("TOOLSSG_QT_GLES",
46 "TSG_QT_GLES",
47 "TOOLSSG_QT_GLES is a graphics driver based on the g4tools tools/sg scene graph logic where\n\
48 the rendering is done with GLES and the windowing is done with Qt.",
49 parent::threeDInteractive)
50,fSGSession(nullptr)
51{}
52
54 delete fSGSession;
55}
56
58 if(fSGSession) return; //done.
59 int* argc = new int;
60 char** argv = nullptr;
61 std::vector<std::string> args;args.push_back("");
62 tools::new_argcv(args,*argc,argv);
63 fSGSession = new toolx::Qt::session(G4cout,*argc,argv);
64 if(!fSGSession->is_valid()) {
65 G4cerr << "G4ToolsSGQtGLES::Initialise : session::is_valid() failed." << G4endl;
66 delete fSGSession;
67 fSGSession = nullptr;
68 return;
69 }
70}
71
73 G4VSceneHandler* pScene = new G4ToolsSGSceneHandler(*this, a_name);
74 return pScene;
75}
76
79 if(!fSGSession) return nullptr;
80 G4VViewer* pView =
81#ifdef G4TOOLSSG_QT_VIEWER_IN_TAB
83#else
85#endif
86 if (pView) {
87 if (pView->GetViewId() < 0) {
88 G4cerr << "G4ToolsSGQtGLES::CreateViewer:"
89 << " ERROR flagged by negative view id in G4ToolsSGViewer creation."
90 << "\n Destroying view and returning null pointer." << G4endl;
91 delete pView;
92 pView = nullptr;
93 }
94 }
95 if (!pView) {
96 G4cerr << "G4ToolsSGQtGLES::CreateViewer: ERROR: null pointer on new G4ToolsSGViewer." << G4endl;
97 return nullptr;
98 }
99 return pView;
100}
101
103{
104 G4bool isCompatible = 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;
128}
bool G4bool
Definition: G4Types.hh:86
G4GLOB_DLL std::ostream G4cerr
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
G4VViewer * CreateViewer(G4VSceneHandler &, const G4String &name="")
toolx::Qt::session * fSGSession
G4bool IsUISessionCompatible() const
virtual ~G4ToolsSGQtGLES()
G4VSceneHandler * CreateSceneHandler(const G4String &name="")
G4UIsession * GetSession() const
Definition: G4UImanager.hh:187
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:77
G4int GetViewId() const