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