[531] | 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 | // |
---|
[593] | 27 | // $Id: G4VViewer.cc,v 1.24 2007/01/05 16:25:15 allison Exp $ |
---|
[850] | 28 | // GEANT4 tag $Name: HEAD $ |
---|
[531] | 29 | // |
---|
| 30 | // |
---|
| 31 | // John Allison 27th March 1996 |
---|
| 32 | // Abstract interface class for graphics views. |
---|
| 33 | |
---|
| 34 | #include "G4VViewer.hh" |
---|
| 35 | |
---|
| 36 | #include "G4ios.hh" |
---|
| 37 | #include <sstream> |
---|
| 38 | |
---|
| 39 | #include "G4VisManager.hh" |
---|
| 40 | #include "G4VGraphicsSystem.hh" |
---|
| 41 | #include "G4VSceneHandler.hh" |
---|
| 42 | #include "G4Scene.hh" |
---|
| 43 | #include "G4VPhysicalVolume.hh" |
---|
| 44 | #include "G4Transform3D.hh" |
---|
| 45 | |
---|
| 46 | G4VViewer::G4VViewer (G4VSceneHandler& sceneHandler, |
---|
| 47 | G4int id, const G4String& name): |
---|
| 48 | fSceneHandler (sceneHandler), |
---|
| 49 | fViewId (id), |
---|
| 50 | //fModified (true), |
---|
| 51 | fNeedKernelVisit (true) |
---|
| 52 | { |
---|
| 53 | if (name == "") { |
---|
| 54 | std::ostringstream ost; |
---|
| 55 | ost << fSceneHandler.GetName () << '-' << fViewId; |
---|
| 56 | fName = ost.str(); |
---|
| 57 | } |
---|
| 58 | else { |
---|
| 59 | fName = name; |
---|
| 60 | } |
---|
| 61 | fShortName = fName (0, fName.find (' ')); |
---|
| 62 | fShortName.strip (); |
---|
| 63 | |
---|
| 64 | G4VisManager* pVisMan = G4VisManager::GetInstance(); |
---|
| 65 | G4int xHint, yHint; |
---|
| 66 | pVisMan->GetWindowSizeHint(xHint, yHint); |
---|
| 67 | const G4String& XGeometryString = pVisMan->GetXGeometryString(); |
---|
| 68 | fVP.SetWindowSizeHint(xHint,yHint); |
---|
| 69 | fVP.SetXGeometryString(XGeometryString); |
---|
| 70 | fDefaultVP.SetWindowSizeHint(xHint,yHint); |
---|
| 71 | fDefaultVP.SetXGeometryString(XGeometryString); |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | G4VViewer::~G4VViewer () {} |
---|
| 75 | |
---|
| 76 | void G4VViewer::SetName (const G4String& name) { |
---|
| 77 | fName = name; |
---|
| 78 | fShortName = fName (0, fName.find (' ')); |
---|
| 79 | fShortName.strip (); |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | const G4VisAttributes* G4VViewer::GetApplicableVisAttributes |
---|
| 83 | (const G4VisAttributes* pVisAttribs) const { |
---|
[593] | 84 | // If pVisAttribs is zero, pick up the default vis attributes from |
---|
[531] | 85 | // the view parameters. |
---|
| 86 | if (!pVisAttribs) |
---|
| 87 | pVisAttribs = GetViewParameters ().GetDefaultVisAttributes (); |
---|
| 88 | return pVisAttribs; |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | void G4VViewer::NeedKernelVisit () { |
---|
| 92 | |
---|
| 93 | fNeedKernelVisit = true; |
---|
| 94 | |
---|
| 95 | // At one time I thought we'd better notify all viewers. But I guess |
---|
| 96 | // each viewer can take care of itself, so the following code is |
---|
| 97 | // redundant (but keep it commented out for now). (John Allison) |
---|
| 98 | // Notify all viewers that a kernel visit is required. |
---|
| 99 | // const G4ViewerList& viewerList = fSceneHandler.GetViewerList (); |
---|
| 100 | // G4ViewerListConstIterator i; |
---|
| 101 | // for (i = viewerList.begin(); i != viewerList.end(); i++) { |
---|
| 102 | // (*i) -> SetNeedKernelVisit (); |
---|
| 103 | // } |
---|
| 104 | // ??...but, there's a problem in OpenGL Stored which seems to |
---|
| 105 | // require *all* viewers to revisit the kernel, so... |
---|
| 106 | /* |
---|
| 107 | const G4ViewerList& viewerList = fSceneHandler.GetViewerList (); |
---|
| 108 | G4ViewerListConstIterator i; |
---|
| 109 | for (i = viewerList.begin(); i != viewerList.end(); i++) { |
---|
| 110 | (*i) -> SetNeedKernelVisit (true); |
---|
| 111 | } |
---|
| 112 | */ |
---|
| 113 | // Feb 2005 - commented out. Let's fix OpenGL if necessary. |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | void G4VViewer::FinishView () {} |
---|
| 117 | |
---|
| 118 | void G4VViewer::ShowView () {} |
---|
| 119 | |
---|
| 120 | void G4VViewer::ProcessView () |
---|
| 121 | { |
---|
| 122 | // If ClearStore has been requested, e.g., if the scene has changed, |
---|
| 123 | // or if the concrete viewer has decided that it necessary to visit |
---|
| 124 | // the kernel, perhaps because the view parameters have changed |
---|
| 125 | // significantly (this should be done in the concrete viewer's |
---|
| 126 | // DrawView)... |
---|
| 127 | if (fNeedKernelVisit) { |
---|
| 128 | // Reset flag. This must be done before ProcessScene to prevent |
---|
| 129 | // recursive calls when recomputing transients... |
---|
| 130 | fNeedKernelVisit = false; |
---|
| 131 | fSceneHandler.ProcessScene (*this); |
---|
| 132 | } |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | void G4VViewer::SetViewParameters (const G4ViewParameters& vp) { |
---|
| 136 | fVP = vp; |
---|
| 137 | } |
---|
| 138 | |
---|
| 139 | std::ostream& operator << (std::ostream& os, const G4VViewer& v) { |
---|
| 140 | os << "View " << v.fName << ":\n"; |
---|
| 141 | os << v.fVP; |
---|
| 142 | return os; |
---|
| 143 | } |
---|