00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #define __G_ANSI_C__
00034
00035
00036
00037
00038 #include <fstream>
00039 #include <stdlib.h>
00040 #include <string.h>
00041 #include "globals.hh"
00042 #include "G4VisManager.hh"
00043 #include "G4FRConst.hh"
00044 #include "G4DAWNFILE.hh"
00045 #include "G4DAWNFILESceneHandler.hh"
00046 #include "G4DAWNFILEViewer.hh"
00047 #include "G4Point3D.hh"
00048 #include "G4VisAttributes.hh"
00049 #include "G4Scene.hh"
00050 #include "G4Transform3D.hh"
00051 #include "G4Polyhedron.hh"
00052 #include "G4Box.hh"
00053 #include "G4Cons.hh"
00054 #include "G4Polyline.hh"
00055 #include "G4Trd.hh"
00056 #include "G4Tubs.hh"
00057 #include "G4Trap.hh"
00058 #include "G4Torus.hh"
00059 #include "G4Sphere.hh"
00060 #include "G4Para.hh"
00061 #include "G4Text.hh"
00062 #include "G4Circle.hh"
00063 #include "G4Square.hh"
00064 #include "G4VPhysicalVolume.hh"
00065
00066
00067 const char FR_ENV_CULL_INVISIBLE_OBJECTS [] = "G4DAWN_CULL_INVISIBLE_OBJECTS";
00068 const char G4PRIM_FILE_HEADER [] = "g4_";
00069 const char DEFAULT_G4PRIM_FILE_NAME[] = "g4_00.prim";
00070
00071
00072
00073
00074
00075
00076 const int FR_MAX_FILE_NUM = 100 ;
00077
00078
00080
00082
00083
00084
00085 G4DAWNFILESceneHandler::G4DAWNFILESceneHandler (G4DAWNFILE& system, const G4String& name):
00086 G4VSceneHandler (system, fSceneIdCount++, name) ,
00087 fSystem (system) ,
00088 fPrimDest () ,
00089 FRflag_in_modeling (false) ,
00090 flag_saving_g4_prim (false) ,
00091 COMMAND_BUF_SIZE (G4FRofstream::SEND_BUFMAX),
00092 fPrec (9), fPrec2 (16)
00093 {
00094
00095 if ( getenv( "G4DAWNFILE_DEST_DIR" ) == NULL ) {
00096 strcpy( fG4PrimDestDir , "" ) ;
00097 strcpy( fG4PrimFileName, DEFAULT_G4PRIM_FILE_NAME );
00098 } else {
00099 strcpy( fG4PrimDestDir , getenv( "G4DAWNFILE_DEST_DIR" ) );
00100 strcpy( fG4PrimFileName, DEFAULT_G4PRIM_FILE_NAME );
00101 }
00102
00103
00104 fMaxFileNum = FR_MAX_FILE_NUM ;
00105 if ( getenv( "G4DAWNFILE_MAX_FILE_NUM" ) != NULL ) {
00106
00107 sscanf( getenv("G4DAWNFILE_MAX_FILE_NUM"), "%d", &fMaxFileNum ) ;
00108
00109 } else {
00110 fMaxFileNum = FR_MAX_FILE_NUM ;
00111 }
00112 if( fMaxFileNum < 1 ) { fMaxFileNum = 1 ; }
00113
00114
00115
00116 if( getenv( "G4DAWNFILE_PRECISION" ) != NULL ) {
00117 sscanf( getenv("G4DAWNFILE_PRECISION"), "%d", &fPrec ) ;
00118 } else {
00119 fPrec = 9 ;
00120 }
00121 fPrec2 = fPrec + 7 ;
00122
00123 }
00124
00125
00126
00127 G4DAWNFILESceneHandler::~G4DAWNFILESceneHandler ()
00128 {
00129 #if defined DEBUG_FR_SCENE
00130 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00131 G4cout << "***** ~G4DAWNFILESceneHandler" << G4endl;
00132 #endif
00133 if (fPrimDest.IsOpen())
00134 {
00135
00136
00137
00138 FREndModeling();
00139 }
00140 }
00141
00142
00143 void G4DAWNFILESceneHandler::SetG4PrimFileName()
00144 {
00145
00146 const int MAX_FILE_INDEX = fMaxFileNum - 1 ;
00147
00148
00149 strcpy ( fG4PrimFileName, fG4PrimDestDir) ;
00150
00151
00152 strcat ( fG4PrimFileName, DEFAULT_G4PRIM_FILE_NAME );
00153
00154
00155 for( int i = 0 ; i < fMaxFileNum ; i++) {
00156
00157
00158 if( i == MAX_FILE_INDEX )
00159 {
00160 if (G4VisManager::GetVerbosity() >= G4VisManager::errors) {
00161 G4cout << "===========================================" << G4endl;
00162 G4cout << "WARNING MESSAGE from DAWNFILE driver: " << G4endl;
00163 G4cout << " This file name is the final one in the " << G4endl;
00164 G4cout << " automatic updation of the output file name." << G4endl;
00165 G4cout << " You may overwrite existing files, i.e. " << G4endl;
00166 G4cout << " g4_XX.prim and g4_XX.eps " << G4endl;
00167 G4cout << "===========================================" << G4endl;
00168 }
00169 }
00170
00171
00172 if( i >= 0 && i <= 9 ) {
00173 sprintf( fG4PrimFileName, "%s%s%s%d.prim" , fG4PrimDestDir, G4PRIM_FILE_HEADER, "0", i );
00174 } else {
00175 sprintf( fG4PrimFileName, "%s%s%d.prim" , fG4PrimDestDir, G4PRIM_FILE_HEADER, i );
00176 }
00177
00178
00179 std::ifstream fin ;
00180 fin.open(fG4PrimFileName) ;
00181 if(!fin) {
00182
00183 fin.close();
00184 break;
00185 } else {
00186
00187 fin.close();
00188 }
00189
00190 }
00191
00192 G4cout << "=========================================== " << G4endl;
00193 G4cout << "Output file: " << fG4PrimFileName << G4endl;
00194 G4cout << "Destination directory (current dir if NULL): " << fG4PrimDestDir << G4endl;
00195 G4cout << "Maximal number of files in the destination directory: " << fMaxFileNum << G4endl;
00196 G4cout << "Note: " << G4endl;
00197 G4cout << " * The maximal number is customizable as: " << G4endl;
00198 G4cout << " % setenv G4DAWNFILE_MAX_FILE_NUM number " << G4endl;
00199 G4cout << " * The destination directory is customizable as:" << G4endl;
00200 G4cout << " % setenv G4DAWNFILE_DEST_DIR dir_name/ " << G4endl;
00201 G4cout << " ** Do not forget \"/\" at the end of the " << G4endl;
00202 G4cout << " dir_name, e.g. \"./tmp/\". " << G4endl;
00203 G4cout << "=========================================== " << G4endl;
00204
00205 }
00206
00207
00208
00209 void G4DAWNFILESceneHandler::BeginSavingG4Prim( void )
00210 {
00211 #if defined DEBUG_FR_SCENE
00212 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00213 G4cout << "***** BeginSavingG4Prim (called)\n";
00214 #endif
00215
00216 if( !IsSavingG4Prim() )
00217 {
00218 #if defined DEBUG_FR_SCENE
00219 if (G4VisManager::GetVerbosity() >= G4VisManager::errors) {
00220 G4cout << "***** (started) " ;
00221 G4cout << "(open g4.prim, ##)" << G4endl;
00222 }
00223 #endif
00224 SetG4PrimFileName() ;
00225 fPrimDest.Open(fG4PrimFileName) ;
00226
00227 SendStr( FR_G4_PRIM_HEADER ) ;
00228 flag_saving_g4_prim = true ;
00229 }
00230 }
00231
00232 void G4DAWNFILESceneHandler::EndSavingG4Prim ( void )
00233 {
00234 #if defined DEBUG_FR_SCENE
00235 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00236 G4cout << "***** EndSavingG4Prim (called)\n";
00237 #endif
00238
00239 if( IsSavingG4Prim() )
00240 {
00241 #if defined DEBUG_FR_SCENE
00242 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00243 G4cout << "***** (started) (close g4.prim)" << G4endl;
00244 #endif
00245 fPrimDest.Close() ;
00246 flag_saving_g4_prim = false ;
00247 }
00248 }
00249
00250
00251
00252 void G4DAWNFILESceneHandler::FRBeginModeling( void )
00253 {
00254 if( !FRIsInModeling() )
00255 {
00256 #if defined DEBUG_FR_SCENE
00257 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00258 G4cout << "***** G4DAWNFILESceneHandler::FRBeginModeling (called & started)" << G4endl;
00259 #endif
00260
00261
00262 BeginSavingG4Prim();
00263
00264
00265 SendBoundingBox();
00266
00267
00268 #if defined DEBUG_FR_SCENE
00269 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00270 G4cout << "***** (!SetCamera in FRBeginModeling())" << G4endl;
00271 #endif
00272 SendStr( FR_SET_CAMERA );
00273
00274
00275 #if defined DEBUG_FR_SCENE
00276 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00277 G4cout << "***** (!OpenDevice in FRBeginModeling())" << G4endl;
00278 #endif
00279 SendStr( FR_OPEN_DEVICE );
00280
00281
00282 #if defined DEBUG_FR_SCENE
00283 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00284 G4cout << "***** (!BeginModeling in FRBeginModeling())" << G4endl;
00285 #endif
00286 SendStr( FR_BEGIN_MODELING ); FRflag_in_modeling = true ;
00287
00288 }
00289
00290 }
00291
00292
00294
00296
00297 #define G4FRSCENEHANDLER G4DAWNFILESceneHandler
00298 #include "G4FRSceneFunc.icc"
00299 #undef G4FRSCENEHANDLER
00300
00302
00304
00305
00306 G4int G4DAWNFILESceneHandler::fSceneIdCount = 0;