Geant4-11
G4ToolsSGXtGLES.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 "G4ToolsSGXtGLES.hh"
29
30#include "G4ToolsSGViewer.hh"
31#include <tools/Xt/sg_viewer>
32
33#include "G4Xt.hh"
34
37public:
38 session(std::ostream& a_out,int a_argc,char** a_argv)
39 :parent(a_out,a_argc,a_argv)
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;}
43 m_app_widget = (Widget)G4Xt::getInstance()->GetMainInteractor();
44 m_app_context = ::XtWidgetToApplicationContext(m_app_widget);
45 }
46 virtual ~session() {}
47protected:
48 session(const session& a_from):parent(a_from){}
49 session& operator=(const session& a_from){parent::operator=(a_from);return *this;}
50};
51
52#include <tools/argcv>
53
56("TOOLSSG_XT_GLES",
57 "TSG_XT_GLES",
58 "TOOLSSG_XT_GLES is a graphics driver based on the g4tools tools/sg scene graph logic where\n\
59 the rendering is done with GLES and the windowing is done with the Xt toolkit.",
60 parent::threeDInteractive)
61,fSGSession(nullptr)
62{}
63
65 delete fSGSession;
66}
67
69 if(fSGSession) return; //done.
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);
74 if(!fSGSession->is_valid()) {
75 G4cerr << "G4ToolsSGXtGLES::Initialise : session::is_valid() failed." << G4endl;
76 delete fSGSession;
77 fSGSession = nullptr;
78 return;
79 }
80}
81
83 G4VSceneHandler* pScene = new G4ToolsSGSceneHandler(*this, a_name);
84 return pScene;
85}
86
89 if(!fSGSession) return nullptr;
90 G4VViewer* pView =
92 if (pView) {
93 if (pView->GetViewId() < 0) {
94 G4cerr <<
95 "G4ToolsSGXtGLES::CreateViewer: ERROR flagged by negative"
96 " view id in G4ToolsSGViewer creation."
97 "\n Destroying view and returning null pointer."
98 << G4endl;
99 delete pView;
100 pView = nullptr;
101 }
102 }
103 if (!pView) {
104 G4cerr <<
105 "G4ToolsSGXtGLES::CreateViewer: ERROR: null pointer on new G4ToolsSGViewer."
106 << G4endl;
107 }
108 return pView;
109}
110
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;
137}
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="")
G4bool IsUISessionCompatible() const
tools::Xt::session * fSGSession
G4VSceneHandler * CreateSceneHandler(const G4String &name="")
virtual ~G4ToolsSGXtGLES()
G4Interactor GetMainInteractor()
G4int GetViewId() const
static G4Xt * getInstance()
Definition: G4Xt.cc:55
session(std::ostream &a_out, int a_argc, char **a_argv)
virtual ~session()
tools::Xt::session parent
session & operator=(const session &a_from)
session(const session &a_from)
static G4UIterminal * session