Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4OpenGLStoredQtSceneHandler.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//
27//
28//
29// Laurent Garnier 27th October 2011
30
31#ifdef G4VIS_BUILD_OPENGLQT_DRIVER
32
34
37#include "G4Text.hh"
38#include "G4VPhysicalVolume.hh"
39#include "G4OpenGLQtViewer.hh"
40#include <typeinfo>
41#include <sstream>
42
43G4OpenGLStoredQtSceneHandler::G4OpenGLStoredQtSceneHandler
44(G4VGraphicsSystem& system,
45 const G4String& name):
46G4OpenGLStoredSceneHandler (system, name)
47{}
48
49G4OpenGLStoredQtSceneHandler::~G4OpenGLStoredQtSceneHandler ()
50{}
51
52G4bool G4OpenGLStoredQtSceneHandler::ExtraPOProcessing
53(const G4Visible& visible, size_t currentPOListIndex)
54{
55 G4bool usesGLCommands = true;
56
57 try {
58 const G4Text& g4Text = dynamic_cast<const G4Text&>(visible);
59 G4TextPlus* pG4TextPlus = new G4TextPlus(g4Text);
60 pG4TextPlus->fProcessing2D = fProcessing2D;
61 fPOList[currentPOListIndex].fpG4TextPlus = pG4TextPlus;
62 usesGLCommands = false;
63 }
64 catch (const std::bad_cast&) {} // No special action if not text. Just carry on.
65
66 G4PhysicalVolumeModel* pPVModel =
67 dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
68 G4LogicalVolumeModel* pLVModel =
69 dynamic_cast<G4LogicalVolumeModel*>(pPVModel);
70 if (pPVModel && !pLVModel) {
71
72 // This call comes from a G4PhysicalVolumeModel. drawnPVPath is
73 // the path of the current drawn (non-culled) volume in terms of
74 // drawn (non-culled) ancestors. Each node is identified by a
75 // PVNodeID object, which is a physical volume and copy number. It
76 // is a vector of PVNodeIDs corresponding to the geometry hierarchy
77 // actually selected, i.e., not culled.
78 // typedef G4PhysicalVolumeModel::G4PhysicalVolumeNodeID PVNodeID;
79 // typedef std::vector<PVNodeID> PVPath;
80
81 // The simplest algorithm, used by the Open Inventor Driver
82 // developers, is to rely on the fact the G4PhysicalVolumeModel
83 // traverses the geometry hierarchy in an orderly manner. The last
84 // mother, if any, will be the node to which the volume should be
85 // added. So it is enough to keep a map of scene graph nodes keyed
86 // on the volume path ID. Actually, it is enough to use the logical
87 // volume as the key. (An alternative would be to keep the PVNodeID
88 // in the tree and match the PVPath from the root down.)
89
90 // BUT IN OPENGL, IF THERE ARE TRANSPARENT OBJECTS, VOLUMES DO NOT
91 // ARRIVE IN THE ABOVE ORDER. (TRANSPARENT OBJECTS ARE DRWAN
92 // LAST.) SO WE MUST BE MORE SOPHISTICATED IN CONSTRUCTING A
93 // TREE.
94
95 // build a path for tree viewer
96 G4OpenGLQtViewer* pGLViewer = dynamic_cast<G4OpenGLQtViewer*>(fpViewer);
97 if ( pGLViewer ) {
98 pGLViewer->addPVSceneTreeElement(fpModel->GetCurrentDescription(),pPVModel,currentPOListIndex);
99 }
100
101 } else { // Not from a G4PhysicalVolumeModel.
102
103 if (fpModel) {
104
105
106 // build a path for tree viewer
107 G4OpenGLQtViewer* pGLViewer = dynamic_cast<G4OpenGLQtViewer*>(fpViewer);
108 if ( pGLViewer ) {
109 pGLViewer->addNonPVSceneTreeElement(fpModel->GetType(),currentPOListIndex,fpModel->GetCurrentDescription().data(),visible);
110 }
111 }
112 }
113
114 return usesGLCommands;
115}
116
117G4bool G4OpenGLStoredQtSceneHandler::ExtraTOProcessing
118(const G4Visible& visible, size_t currentTOListIndex)
119{
120
121 G4bool usesGLCommands = true;
122
123 try {
124 const G4Text& g4Text = dynamic_cast<const G4Text&>(visible);
125 G4TextPlus* pG4TextPlus = new G4TextPlus(g4Text);
126 pG4TextPlus->fProcessing2D = fProcessing2D;
127 fTOList[currentTOListIndex].fpG4TextPlus = pG4TextPlus;
128 usesGLCommands = false;
129 }
130 catch (const std::bad_cast&) {} // Do nothing if not text.
131
132 return usesGLCommands;
133}
134
135void G4OpenGLStoredQtSceneHandler::ClearStore () {
136
137 //G4cout << "G4OpenGLStoredQtSceneHandler::ClearStore" << G4endl;
138
139 G4OpenGLStoredSceneHandler::ClearStore (); // Sets need kernel visit, etc.
140 // Should recreate the tree
141 G4OpenGLQtViewer* pGLQtViewer = dynamic_cast<G4OpenGLQtViewer*>(fpViewer);
142 if ( pGLQtViewer ) {
143 pGLQtViewer->clearTreeWidget();
144 }
145}
146
147void G4OpenGLStoredQtSceneHandler::ClearTransientStore () {
148
149 //G4cout << "G4OpenGLStoredQtSceneHandler::ClearTransientStore" << G4endl;
150
151 G4OpenGLStoredSceneHandler::ClearTransientStore ();
152
153 // Should recreate the tree
154 // Make sure screen corresponds to graphical database...
155 // FIXME : L.Garnier April 2012 : Could cause a infinite loop ?
156 if (fpViewer) {
157 fpViewer -> SetView ();
158 fpViewer -> ClearView ();
159 fpViewer -> DrawView ();
160 }
161}
162
163void G4OpenGLStoredQtSceneHandler::SetScene(G4Scene* pScene){
164
165 if (pScene != fpScene) {
166 G4OpenGLQtViewer* pGLQtViewer = dynamic_cast<G4OpenGLQtViewer*>(fpViewer);
167 if ( pGLQtViewer ) {
168 pGLQtViewer->clearTreeWidget();
169 }
170 }
172}
173
174#endif
bool G4bool
Definition: G4Types.hh:86
Definition: G4Text.hh:72
virtual void SetScene(G4Scene *)
const char * name(G4int ptype)