Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4VViewer.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$
28 //
29 //
30 // John Allison 27th March 1996
31 // Abstract interface class for graphics views.
32 
33 #include "G4VViewer.hh"
34 
35 #include "G4ios.hh"
36 #include <sstream>
37 
38 #include "G4VisManager.hh"
39 #include "G4VGraphicsSystem.hh"
40 #include "G4VSceneHandler.hh"
41 #include "G4Scene.hh"
42 #include "G4VPhysicalVolume.hh"
43 #include "G4Transform3D.hh"
44 
46  G4int id, const G4String& name):
47 fSceneHandler (sceneHandler),
48 fViewId (id),
49 //fModified (true),
50 fNeedKernelVisit (true)
51 {
52  if (name == "") {
53  std::ostringstream ost;
54  ost << fSceneHandler.GetName () << '-' << fViewId;
55  fName = ost.str();
56  }
57  else {
58  fName = name;
59  }
60  fShortName = fName (0, fName.find (' '));
61  fShortName.strip ();
62 
63  fVP = G4VisManager::GetInstance()->GetDefaultViewParameters();
64  fDefaultVP = fVP;
65 }
66 
69 }
70 
72  fName = name;
73  fShortName = fName (0, fName.find (' '));
74  fShortName.strip ();
75 }
76 
78 (const G4VisAttributes* pVisAttribs) const {
79  // If pVisAttribs is zero, pick up the default vis attributes from
80  // the view parameters.
81  if (!pVisAttribs)
82  pVisAttribs = GetViewParameters ().GetDefaultVisAttributes ();
83  return pVisAttribs;
84 }
85 
87 
88  fNeedKernelVisit = true;
89 
90  // At one time I thought we'd better notify all viewers. But I guess
91  // each viewer can take care of itself, so the following code is
92  // redundant (but keep it commented out for now). (John Allison)
93  // Notify all viewers that a kernel visit is required.
94  // const G4ViewerList& viewerList = fSceneHandler.GetViewerList ();
95  // G4ViewerListConstIterator i;
96  // for (i = viewerList.begin(); i != viewerList.end(); i++) {
97  // (*i) -> SetNeedKernelVisit ();
98  // }
99  // ??...but, there's a problem in OpenGL Stored which seems to
100  // require *all* viewers to revisit the kernel, so...
101  /*
102  const G4ViewerList& viewerList = fSceneHandler.GetViewerList ();
103  G4ViewerListConstIterator i;
104  for (i = viewerList.begin(); i != viewerList.end(); i++) {
105  (*i) -> SetNeedKernelVisit (true);
106  }
107  */
108  // Feb 2005 - commented out. Let's fix OpenGL if necessary.
109 }
110 
112 
114 
116 {
117  // If the scene has changed, or if the concrete viewer has decided
118  // that it necessary to visit the kernel, perhaps because the view
119  // parameters have changed significantly (this should be done in the
120  // concrete viewer's DrawView)...
121  if (fNeedKernelVisit) {
122  // Reset flag. This must be done before ProcessScene to prevent
123  // recursive calls when recomputing transients...
124  fNeedKernelVisit = false;
127  }
128 }
129 
131  fVP = vp;
132 }
133 
134 std::ostream& operator << (std::ostream& os, const G4VViewer& v) {
135  os << "View " << v.fName << ":\n";
136  os << v.fVP;
137  return os;
138 }