Geant4  10.03.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4XXXFileViewer.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: G4XXXFileViewer.cc 66373 2012-12-18 09:41:34Z gcosmo $
28 //
29 //
30 // John Allison 7th March 2006
31 // A template for a file-writing graphics driver.
32 //?? Lines beginning like this require specialisation for your driver.
33 
34 #include "G4XXXFileViewer.hh"
35 
36 #include "G4VSceneHandler.hh"
37 #include "G4XXXFileSceneHandler.hh"
38 #include <sstream>
39 
41 {
42  if (fOpen) {
43  G4cout << "Closing file " << fFileName << G4endl;
44  fFile.close();
45  fOpen = false;
46  }
47 }
48 
50 {
51  if (!fOpen)
52  {
53  std::ifstream ifs;
54  std::ostringstream oss;
55  G4int i = 0;
56  do {
57  oss.str("");
58  oss << "g4_" << i << ".XXXFile";
59  ifs.open(oss.str().c_str());
60  if (!ifs) break; // Doesn't exist, so can open a new file.
61  else ifs.close();
62  ++i;
63  } while(true);
64  fFileName = oss.str();
65  G4cout << "Opening file " << fFileName << G4endl;
66  fFile.open(fFileName.c_str());
67  fOpen = true;
68  }
69  if (fFile.good()) fFile << item << std::endl;
70  else G4cout << "G4XXXFileViewer::FileWriter::WriteItem: ERROR" << G4endl;
71 }
72 
74 (G4VSceneHandler& sceneHandler, const G4String& name):
75  G4VViewer(sceneHandler, sceneHandler.IncrementViewCount(), name)
76 {}
77 
79 {
80  fFileWriter.Close();
81 }
82 
84 #ifdef G4XXXFileDEBUG
85  G4cout << "G4XXXFileViewer::SetView() called." << G4endl;
86 #endif
87 }
88 
90 #ifdef G4XXXFileDEBUG
91  G4cout << "G4XXXFileViewer::ClearView() called." << G4endl;
92 #endif
93  fFileWriter.Rewind();
94 }
95 
97 #ifdef G4XXXFileDEBUG
98  G4cout << "G4XXXFileViewer::DrawView() called." << G4endl;
99 #endif
100 
101  // First, a view should decide when to re-visit the G4 kernel.
102  // Sometimes it might not be necessary, e.g., if the scene is stored
103  // in a graphical database (e.g., OpenGL's display lists) and only
104  // the viewing angle has changed. But graphics systems without a
105  // graphical database will always need to visit the G4 kernel.
106 
107  NeedKernelVisit (); // Default is - always visit G4 kernel.
108  // Note: this routine sets the fNeedKernelVisit flag of *all* the
109  // views of the scene.
110 
111  ProcessView (); // The basic logic is here.
112 
113  // Then a view may have more to do, e.g., display the graphical
114  // database. That code should come here...
115 
116  // ...before finally...
117  FinishView (); // Flush streams and/or swap buffers.
118 }
119 
121 #ifdef G4XXXFileDEBUG
122  G4cout << "G4XXXFileViewer::ShowView() called." << G4endl;
123 #endif
124  fFileWriter.Close();
125 }
const XML_Char * name
Definition: expat.h:151
G4int IncrementViewCount()
int G4int
Definition: G4Types.hh:78
G4VViewer(G4VSceneHandler &, G4int id, const G4String &name="")
Definition: G4VViewer.cc:46
void WriteItem(const G4String &item)
G4GLOB_DLL std::ostream G4cout
G4XXXFileViewer(G4VSceneHandler &, const G4String &name)
virtual ~G4XXXFileViewer()
void NeedKernelVisit()
Definition: G4VViewer.cc:78
#define G4endl
Definition: G4ios.hh:61
void ProcessView()
Definition: G4VViewer.cc:105
virtual void FinishView()
Definition: G4VViewer.cc:101