Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4VRML1FileSceneHandler.cc
이 파일의 문서화 페이지로 가기
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: G4VRML1FileSceneHandler.cc 110513 2018-05-28 07:37:38Z gcosmo $
28 //
29 // G4VRML1FileSceneHandler.cc
30 // Satoshi Tanaka & Yasuhide Sawada
31 
32 
33 //#define DEBUG_FR_SCENE
34 
35 #include <fstream>
36 #include <stdio.h>
37 #include <string.h>
38 #include <stdlib.h>
39 #include <sstream>
40 #include <iomanip>
41 
42 #include "globals.hh"
43 #include "G4VisManager.hh"
44 #include "G4Scene.hh"
45 #include "G4VPhysicalVolume.hh"
46 #include "G4LogicalVolume.hh"
47 #include "G4Point3D.hh"
48 #include "G4VisAttributes.hh"
49 #include "G4Polyhedron.hh"
50 #include "G4Box.hh"
51 #include "G4Cons.hh"
52 #include "G4Polyline.hh"
53 #include "G4Trd.hh"
54 #include "G4Tubs.hh"
55 #include "G4Trap.hh"
56 #include "G4Para.hh"
57 #include "G4Torus.hh"
58 #include "G4Sphere.hh"
59 #include "G4Text.hh"
60 #include "G4Circle.hh"
61 #include "G4Square.hh"
62 
64 #include "G4VRML1FileViewer.hh"
65 #include "G4VRML1File.hh"
66 
67 // CONST
68 
69 const char WRL_FILE_HEADER [] = "g4_";
70 const char DEFAULT_WRL_FILE_NAME[] = "g4.wrl";
71 const char ENV_VRML_VIEWER [] = "G4VRMLFILE_VIEWER";
72 const char NO_VRML_VIEWER [] = "NONE";
73 const char VRMLFILE_DEST_DIR [] = "G4VRMLFILE_DEST_DIR";
74 const int DEFAULT_MAX_WRL_FILE_NUM = 100 ;
75 
77  G4VSceneHandler(system, fSceneIdCount++, name),
78  fSystem(system),
79  fDest() ,
80  fFlagDestOpen( false )
81 {
82  fCurrentDEF = "";
83  strcpy(fVRMLFileName, "");
84 
85  if ( getenv( VRMLFILE_DEST_DIR ) == NULL ) {
86  strcpy( fVRMLFileDestDir, "" );
87  } else {
88  strcpy( fVRMLFileDestDir, getenv( VRMLFILE_DEST_DIR ) );
89  }
90 
91  // maximum number of g4.wrl files in the dest directory
92  fMaxFileNum = DEFAULT_MAX_WRL_FILE_NUM ; // initialization
93  if ( getenv( "G4VRMLFILE_MAX_FILE_NUM" ) != NULL ) {
94 
95  sscanf( getenv("G4VRMLFILE_MAX_FILE_NUM"), "%d", &fMaxFileNum ) ;
96 
97  } else {
99  }
100  if( fMaxFileNum < 1 ) { fMaxFileNum = 1; }
101 
102 }
103 
104 
106 {
107 #if defined DEBUG_FR_SCENE
109  G4cout << "***** ~G4VRML1FileSceneHandler" << G4endl;
110 #endif
111  VRMLEndModeling();
112 }
113 
114 
115 #define G4VRML1SCENEHANDLER G4VRML1FileSceneHandler
116 #define IS_CONNECTED this->isConnected()
117 #include "G4VRML1SceneHandlerFunc.icc"
118 #undef IS_CONNECTED
119 #undef G4VRML1SCENEHANDLER
120 
121 
123 {
124  // g4_00.wrl, g4_01.wrl, ..., g4_MAX_FILE_INDEX.wrl
125  const int MAX_FILE_INDEX = fMaxFileNum - 1 ;
126 
127  // dest directory (null if no environmental variables is set)
128  strcpy ( fVRMLFileName, fVRMLFileDestDir) ;
129 
130  // create (full) path name (default)
132 
133  // Determine VRML file name
134  for( int i = 0 ; i < fMaxFileNum ; i++) {
135 
136  // Message in the final execution
137  if( i == MAX_FILE_INDEX )
138  {
140  G4cout << "===========================================" << G4endl;
141  G4cout << "WARNING MESSAGE from VRML1FILE driver: " << G4endl;
142  G4cout << " This file name is the final one in the " << G4endl;
143  G4cout << " automatic updation of the output file name." << G4endl;
144  G4cout << " You may overwrite existing files, i.e. " << G4endl;
145  G4cout << " g4_XX.wrl. " << G4endl;
146  G4cout << "===========================================" << G4endl;
147  }
148  }
149 
150  // re-determine file name as G4VRMLFILE_DEST_DIR/g4_XX.wrl
151  std::ostringstream filename;
152  filename
154  << std::setw(2) << std::setfill('0') << i << ".wrl";
155  strncpy(fVRMLFileName,filename.str().c_str(),sizeof(fVRMLFileName)-1);
156  fVRMLFileName[sizeof(fVRMLFileName)-1] = '\0';
157 
158  // check validity of the file name
159  std::ifstream fin ;
160  fin.open(fVRMLFileName) ;
161  if(!fin) {
162  // new file
163  fin.close();
164  break;
165  } else {
166  // already exists (try next)
167  fin.close();
168  }
169 
170 
171  } // for
172 
173  // open a VRML 1.0 file with determined file name
175  G4cout << "===========================================" << G4endl;
176  G4cout << "Output VRML 1.0 file: " << fVRMLFileName << G4endl;
177  G4cout << "Maximum number of files in the destination directory: " << fMaxFileNum << G4endl;
178  G4cout << " (Customizable with the environment variable: G4VRMLFILE_MAX_FILE_NUM) " << G4endl;
179  G4cout << "===========================================" << G4endl;
180  }
181  fDest.open(fVRMLFileName) ; fFlagDestOpen = true ;
182 }
183 
184 
186 {
187  char command[256] ;
188  char viewer [256] ;
189  strcpy( viewer, NO_VRML_VIEWER ); // initialization
190  if( getenv( ENV_VRML_VIEWER ) ) {
191  strcpy( viewer, getenv( ENV_VRML_VIEWER ) ) ;
192  }
193 
194  // close VRML file
195  fDest.close(); fFlagDestOpen = false ;
197  G4cout << "*** VRML 1.0 File " << fVRMLFileName << " is generated." << G4endl;
198 
199 
200  // Invoke viewer
201 
202  if ( !strcmp(viewer, NO_VRML_VIEWER )) {
204  G4cout << "MESSAGE from VRML1FILE driver:" << G4endl;
205  G4cout << " Set an environmental variable " ;
207  G4cout << " if you want to visualize the generated VRML file" << G4endl;
208  G4cout << " automatically. For example, " << G4endl;
209  G4cout << " setenv " << ENV_VRML_VIEWER << " vrweb " << G4endl;
210  }
211  } else {
212  std::ostringstream ossCommand;
213  ossCommand << viewer << ' ' << fVRMLFileName;
214  strncpy(command,ossCommand.str().c_str(),sizeof(command)-1);
215  command[sizeof(command)-1] = '\0';
216  (void) system( command );
217  }
218 }
219 
const int DEFAULT_MAX_WRL_FILE_NUM
const XML_Char * name
Definition: expat.h:151
system("rm -rf microbeam.root")
const char NO_VRML_VIEWER[]
const char VRMLFILE_DEST_DIR[]
#define G4endl
Definition: G4ios.hh:61
const char DEFAULT_WRL_FILE_NAME[]
G4VRML1FileSceneHandler(G4VRML1File &system, const G4String &name="")
fin
Definition: AddMC.C:2
static Verbosity GetVerbosity()
int G4int
Definition: G4Types.hh:78
G4GLOB_DLL std::ostream G4cout
const char WRL_FILE_HEADER[]
typedef void(XMLCALL *XML_ElementDeclHandler)(void *userData
const char ENV_VRML_VIEWER[]