00001 // 00002 // ******************************************************************** 00003 // * License and Disclaimer * 00004 // * * 00005 // * The Geant4 software is copyright of the Copyright Holders of * 00006 // * the Geant4 Collaboration. It is provided under the terms and * 00007 // * conditions of the Geant4 Software License, included in the file * 00008 // * LICENSE and available at http://cern.ch/geant4/license . These * 00009 // * include a list of copyright holders. * 00010 // * * 00011 // * Neither the authors of this software system, nor their employing * 00012 // * institutes,nor the agencies providing financial support for this * 00013 // * work make any representation or warranty, express or implied, * 00014 // * regarding this software system or assume any liability for its * 00015 // * use. Please see the license in the file LICENSE and URL above * 00016 // * for the full disclaimer and the limitation of liability. * 00017 // * * 00018 // * This code implementation is the result of the scientific and * 00019 // * technical work of the GEANT4 collaboration. * 00020 // * By using, copying, modifying or distributing the software (or * 00021 // * any work based on the software) you agree to acknowledge its * 00022 // * use in resulting scientific publications, and indicate your * 00023 // * acceptance of all terms of the Geant4 Software license. * 00024 // ******************************************************************** 00025 // 00026 // 00027 // $Id$ 00028 // 00029 // 00030 // John Allison 27th March 1996 00031 // Abstract interface class for graphics views. 00032 00033 #include "G4VViewer.hh" 00034 00035 #include "G4ios.hh" 00036 #include <sstream> 00037 00038 #include "G4VisManager.hh" 00039 #include "G4VGraphicsSystem.hh" 00040 #include "G4VSceneHandler.hh" 00041 #include "G4Scene.hh" 00042 #include "G4VPhysicalVolume.hh" 00043 #include "G4Transform3D.hh" 00044 00045 G4VViewer::G4VViewer (G4VSceneHandler& sceneHandler, 00046 G4int id, const G4String& name): 00047 fSceneHandler (sceneHandler), 00048 fViewId (id), 00049 //fModified (true), 00050 fNeedKernelVisit (true) 00051 { 00052 if (name == "") { 00053 std::ostringstream ost; 00054 ost << fSceneHandler.GetName () << '-' << fViewId; 00055 fName = ost.str(); 00056 } 00057 else { 00058 fName = name; 00059 } 00060 fShortName = fName (0, fName.find (' ')); 00061 fShortName.strip (); 00062 00063 fVP = G4VisManager::GetInstance()->GetDefaultViewParameters(); 00064 fDefaultVP = fVP; 00065 } 00066 00067 G4VViewer::~G4VViewer () { 00068 fSceneHandler.RemoveViewerFromList(this); 00069 } 00070 00071 void G4VViewer::SetName (const G4String& name) { 00072 fName = name; 00073 fShortName = fName (0, fName.find (' ')); 00074 fShortName.strip (); 00075 } 00076 00077 const G4VisAttributes* G4VViewer::GetApplicableVisAttributes 00078 (const G4VisAttributes* pVisAttribs) const { 00079 // If pVisAttribs is zero, pick up the default vis attributes from 00080 // the view parameters. 00081 if (!pVisAttribs) 00082 pVisAttribs = GetViewParameters ().GetDefaultVisAttributes (); 00083 return pVisAttribs; 00084 } 00085 00086 void G4VViewer::NeedKernelVisit () { 00087 00088 fNeedKernelVisit = true; 00089 00090 // At one time I thought we'd better notify all viewers. But I guess 00091 // each viewer can take care of itself, so the following code is 00092 // redundant (but keep it commented out for now). (John Allison) 00093 // Notify all viewers that a kernel visit is required. 00094 // const G4ViewerList& viewerList = fSceneHandler.GetViewerList (); 00095 // G4ViewerListConstIterator i; 00096 // for (i = viewerList.begin(); i != viewerList.end(); i++) { 00097 // (*i) -> SetNeedKernelVisit (); 00098 // } 00099 // ??...but, there's a problem in OpenGL Stored which seems to 00100 // require *all* viewers to revisit the kernel, so... 00101 /* 00102 const G4ViewerList& viewerList = fSceneHandler.GetViewerList (); 00103 G4ViewerListConstIterator i; 00104 for (i = viewerList.begin(); i != viewerList.end(); i++) { 00105 (*i) -> SetNeedKernelVisit (true); 00106 } 00107 */ 00108 // Feb 2005 - commented out. Let's fix OpenGL if necessary. 00109 } 00110 00111 void G4VViewer::FinishView () {} 00112 00113 void G4VViewer::ShowView () {} 00114 00115 void G4VViewer::ProcessView () 00116 { 00117 // If the scene has changed, or if the concrete viewer has decided 00118 // that it necessary to visit the kernel, perhaps because the view 00119 // parameters have changed significantly (this should be done in the 00120 // concrete viewer's DrawView)... 00121 if (fNeedKernelVisit) { 00122 // Reset flag. This must be done before ProcessScene to prevent 00123 // recursive calls when recomputing transients... 00124 fNeedKernelVisit = false; 00125 fSceneHandler.ClearStore (); 00126 fSceneHandler.ProcessScene (); 00127 } 00128 } 00129 00130 void G4VViewer::SetViewParameters (const G4ViewParameters& vp) { 00131 fVP = vp; 00132 } 00133 00134 std::ostream& operator << (std::ostream& os, const G4VViewer& v) { 00135 os << "View " << v.fName << ":\n"; 00136 os << v.fVP; 00137 return os; 00138 }