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