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