Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4VRML2FileSceneHandler.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: G4VRML2FileSceneHandler.cc 110513 2018-05-28 07:37:38Z gcosmo $
28 //
29 // G4VRML2FileSceneHandler.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 <cmath>
40 #include <sstream>
41 #include <iomanip>
42 
43 #include "globals.hh"
44 #include "G4VPhysicalVolume.hh"
45 #include "G4LogicalVolume.hh"
46 #include "G4VisManager.hh"
47 #include "G4Point3D.hh"
48 #include "G4VisAttributes.hh"
49 #include "G4VModel.hh"
50 #include "G4Scene.hh"
51 #include "G4Polyhedron.hh"
52 #include "G4Box.hh"
53 #include "G4Cons.hh"
54 #include "G4Polyline.hh"
55 #include "G4Trd.hh"
56 #include "G4Tubs.hh"
57 #include "G4Text.hh"
58 #include "G4Circle.hh"
59 #include "G4Square.hh"
60 
62 #include "G4VRML2FileViewer.hh"
63 #include "G4VRML2File.hh"
64 
65 // CONST
66 
67 const char WRL_FILE_HEADER [] = "g4_";
68 const char DEFAULT_WRL_FILE_NAME[] = "g4.wrl";
69 const char ENV_VRML_VIEWER [] = "G4VRMLFILE_VIEWER";
70 const char NO_VRML_VIEWER [] = "NONE";
71 const char VRMLFILE_DEST_DIR [] = "G4VRMLFILE_DEST_DIR";
72 const int DEFAULT_MAX_WRL_FILE_NUM = 100 ;
73 
74 
76  G4VSceneHandler(system, fSceneIdCount++, name),
77  fSystem(system),
78  fFlagDestOpen( false ),
79  fPVPickable ( false ),
80  fDest()
81 {
82  // output file name
83  strcpy(fVRMLFileName, "");
84 
85  // destination directory
86  if ( getenv( VRMLFILE_DEST_DIR ) == NULL ) {
87  strcpy( fVRMLFileDestDir, "" );
88  } else {
89  strcpy( fVRMLFileDestDir, getenv( VRMLFILE_DEST_DIR ) );
90  }
91 
92 
93  // maximum number of g4.prim files in the dest directory
94  fMaxFileNum = DEFAULT_MAX_WRL_FILE_NUM ; // initialization
95  if ( getenv( "G4VRMLFILE_MAX_FILE_NUM" ) != NULL ) {
96 
97  sscanf( getenv("G4VRMLFILE_MAX_FILE_NUM"), "%d", &fMaxFileNum ) ;
98 
99  } else {
101  }
102  if( fMaxFileNum < 1 ) { fMaxFileNum = 1; }
103 
104 
105  // PV name pickability
106  if( getenv( "G4VRML_PV_PICKABLE" ) != NULL ) {
107 
108  int is_pickable ;
109  sscanf( getenv("G4VRML_PV_PICKABLE"), "%d", &is_pickable ) ;
110 
111  if ( is_pickable ) { SetPVPickability ( true ) ; }
112  }
113 
114  // PV Transparency
116 
117 }
118 
119 
121 {
122 #if defined DEBUG_FR_SCENE
124  G4cout << "***** ~G4VRML2FileSceneHandler" << G4endl;
125 #endif
126  VRMLEndModeling();
127 }
128 
129 
130 #define G4VRML2SCENEHANDLER G4VRML2FileSceneHandler
131 #define IS_CONNECTED this->isConnected()
132 #include "G4VRML2SceneHandlerFunc.icc"
133 #undef IS_CONNECTED
134 #undef G4VRML2SCENEHANDLER
135 
136 
138 {
139  // g4_00.wrl, g4_01.wrl, ..., g4_MAX_FILE_INDEX.wrl
140  const int MAX_FILE_INDEX = fMaxFileNum - 1 ;
141 
142  // dest directory (null if no environmental variables is set)
143  strcpy ( fVRMLFileName, fVRMLFileDestDir) ;
144 
145  // create full path name (default)
147 
148  // Determine VRML file name
149  for( int i = 0 ; i < fMaxFileNum ; i++) {
150 
151  // Message in the final execution
152  if( i == MAX_FILE_INDEX )
153  {
155  G4cout << "===========================================" << G4endl;
156  G4cout << "WARNING MESSAGE from VRML2FILE driver: " << G4endl;
157  G4cout << " This file name is the final one in the " << G4endl;
158  G4cout << " automatic updation of the output file name." << G4endl;
159  G4cout << " You may overwrite existing files, i.e. " << G4endl;
160  G4cout << " g4_XX.wrl. " << G4endl;
161  G4cout << "===========================================" << G4endl;
162  }
163  }
164 
165  // re-determine file name as G4VRMLFILE_DEST_DIR/g4_XX.wrl
166  std::ostringstream filename;
167  filename
169  << std::setw(2) << std::setfill('0') << i << ".wrl";
170  strncpy(fVRMLFileName,filename.str().c_str(),sizeof(fVRMLFileName)-1);
171  fVRMLFileName[sizeof(fVRMLFileName)-1] = '\0';
172 
173  // check validity of the file name
174  std::ifstream fin ;
175  fin.open(fVRMLFileName) ;
176  if(!fin) {
177  // new file
178  fin.close();
179  break;
180  } else {
181  // already exists (try next)
182  fin.close();
183  }
184 
185  } // for
186 
187  // open a VRML 2.0 file with determined file name
189  G4cout << "===========================================" << G4endl;
190  G4cout << "Output VRML 2.0 file: " << fVRMLFileName << G4endl;
191  G4cout << "Maximum number of files in the destination directory: " << fMaxFileNum << G4endl;
192  G4cout << " (Customizable with the environment variable: G4VRMLFILE_MAX_FILE_NUM) " << G4endl;
193  G4cout << "===========================================" << G4endl;
194  }
195  fDest.open(fVRMLFileName) ; fFlagDestOpen = true ;
196 }
197 
198 
200 {
201  char command[256] ;
202  char viewer [256] ;
203  strcpy( viewer, NO_VRML_VIEWER ); // initialization
204  if( getenv( ENV_VRML_VIEWER ) ) {
205  strcpy( viewer, getenv( ENV_VRML_VIEWER ) ) ;
206  }
207 
208  // close VRML file
209  fDest.close(); fFlagDestOpen = false ;
211  G4cout << "*** VRML 2.0 File " << fVRMLFileName << " is generated." << G4endl;
212 
213 
214  // Invoke viewer
215 
216  if ( !strcmp(viewer, NO_VRML_VIEWER )) {
218  G4cout << "MESSAGE from VRML2FILE driver:" << G4endl;
219  G4cout << " Set an environmental variable " ;
221  G4cout << " if you want to visualize the generated VRML file" << G4endl;
222  G4cout << " automatically. For example, " << G4endl;
223  G4cout << " setenv " << ENV_VRML_VIEWER << " vrwave " << G4endl;
224  }
225  } else {
226  std::ostringstream ossCommand;
227  ossCommand << viewer << ' ' << fVRMLFileName;
228  strncpy(command,ossCommand.str().c_str(),sizeof(command)-1);
229  command[sizeof(command)-1] = '\0';
230  (void) system( command );
231  }
232 }
233 
const int DEFAULT_MAX_WRL_FILE_NUM
G4double SetPVTransparency()
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[]
fin
Definition: AddMC.C:2
static Verbosity GetVerbosity()
int G4int
Definition: G4Types.hh:78
void SetPVPickability(G4bool on_off)
G4GLOB_DLL std::ostream G4cout
const char WRL_FILE_HEADER[]
typedef void(XMLCALL *XML_ElementDeclHandler)(void *userData
G4VRML2FileSceneHandler(G4VRML2File &system, const G4String &name="")
const char ENV_VRML_VIEWER[]