G4XXXFileViewer.cc

Go to the documentation of this file.
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  7th March 2006
00031 // A template for a file-writing graphics driver.
00032 //?? Lines beginning like this require specialisation for your driver.
00033 
00034 #include "G4XXXFileViewer.hh"
00035 
00036 #include "G4VSceneHandler.hh"
00037 #include "G4XXXFileSceneHandler.hh"
00038 #include <sstream>
00039 
00040 void G4XXXFileViewer::FileWriter::Close()
00041 {
00042   if (fOpen) {
00043     G4cout << "Closing file " << fFileName << G4endl;
00044     fFile.close();
00045     fOpen = false;
00046   }
00047 }
00048 
00049 void G4XXXFileViewer::FileWriter::WriteItem(const G4String& item)
00050 {
00051   if (!fOpen)
00052     {
00053       std::ifstream ifs;
00054       std::ostringstream oss;
00055       G4int i = 0;
00056       do {
00057         oss.str("");
00058         oss << "g4_" << i << ".XXXFile";
00059         ifs.open(oss.str().c_str());
00060         if (!ifs) break;  // Doesn't exist, so can open a new file.
00061         else ifs.close();
00062         ++i;
00063       } while(true);
00064       fFileName = oss.str();
00065       G4cout << "Opening file " << fFileName << G4endl;
00066       fFile.open(fFileName.c_str());
00067       fOpen = true;
00068     }
00069   if (fFile.good()) fFile << item << std::endl;
00070   else G4cout << "G4XXXFileViewer::FileWriter::WriteItem: ERROR" << G4endl;
00071 }
00072 
00073 G4XXXFileViewer::G4XXXFileViewer
00074 (G4VSceneHandler& sceneHandler, const G4String& name):
00075   G4VViewer(sceneHandler, sceneHandler.IncrementViewCount(), name)
00076 {}
00077 
00078 G4XXXFileViewer::~G4XXXFileViewer()
00079 {
00080   fFileWriter.Close();
00081 }
00082 
00083 void G4XXXFileViewer::SetView() {
00084 #ifdef G4XXXFileDEBUG
00085   G4cout << "G4XXXFileViewer::SetView() called." << G4endl;
00086 #endif
00087 }
00088 
00089 void G4XXXFileViewer::ClearView() {
00090 #ifdef G4XXXFileDEBUG
00091   G4cout << "G4XXXFileViewer::ClearView() called." << G4endl;
00092 #endif
00093   fFileWriter.Rewind();
00094 }
00095 
00096 void G4XXXFileViewer::DrawView() {
00097 #ifdef G4XXXFileDEBUG
00098   G4cout << "G4XXXFileViewer::DrawView() called." << G4endl;
00099 #endif
00100 
00101   // First, a view should decide when to re-visit the G4 kernel.
00102   // Sometimes it might not be necessary, e.g., if the scene is stored
00103   // in a graphical database (e.g., OpenGL's display lists) and only
00104   // the viewing angle has changed.  But graphics systems without a
00105   // graphical database will always need to visit the G4 kernel.
00106 
00107   NeedKernelVisit ();  // Default is - always visit G4 kernel.
00108   // Note: this routine sets the fNeedKernelVisit flag of *all* the
00109   // views of the scene.
00110 
00111   ProcessView ();      // The basic logic is here.
00112 
00113   // Then a view may have more to do, e.g., display the graphical
00114   // database.  That code should come here...
00115 
00116   // ...before finally...
00117   FinishView ();       // Flush streams and/or swap buffers.
00118 }
00119 
00120 void G4XXXFileViewer::ShowView() {
00121 #ifdef G4XXXFileDEBUG
00122   G4cout << "G4XXXFileViewer::ShowView() called." << G4endl;
00123 #endif
00124   fFileWriter.Close();
00125 }

Generated on Mon May 27 17:50:28 2013 for Geant4 by  doxygen 1.4.7