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