Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer << 3 // * DISCLAIMER * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th << 5 // * The following disclaimer summarizes all the specific disclaimers * 6 // * the Geant4 Collaboration. It is provided << 6 // * of contributors to this software. The specific disclaimers,which * 7 // * conditions of the Geant4 Software License << 7 // * govern, are listed with their locations in: * 8 // * LICENSE and available at http://cern.ch/ << 8 // * http://cern.ch/geant4/license * 9 // * include a list of copyright holders. << 10 // * 9 // * * 11 // * Neither the authors of this software syst 10 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 11 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 12 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 13 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file << 14 // * use. * 16 // * for the full disclaimer and the limitatio << 17 // * 15 // * * 18 // * This code implementation is the result << 16 // * This code implementation is the intellectual property of the * 19 // * technical work of the GEANT4 collaboratio << 17 // * GEANT4 collaboration. * 20 // * By using, copying, modifying or distri << 18 // * By copying, distributing or modifying the Program (or any work * 21 // * any work based on the software) you ag << 19 // * based on the Program) you indicate your acceptance of this * 22 // * use in resulting scientific publicati << 20 // * statement, and all its terms. * 23 // * acceptance of all terms of the Geant4 Sof << 24 // ******************************************* 21 // ******************************************************************** 25 // 22 // 26 // 23 // >> 24 // $Id: G4DAWNFILESceneHandler.cc,v 1.13 2003/06/16 17:13:29 gunter Exp $ >> 25 // GEANT4 tag $Name: geant4-07-00-patch-01 $ 27 // 26 // 28 // Satoshi TANAKA 27 // Satoshi TANAKA 29 // DAWNFILE scene. 28 // DAWNFILE scene. 30 29 >> 30 31 #define __G_ANSI_C__ 31 #define __G_ANSI_C__ 32 32 33 // #define DEBUG_FR_SCENE 33 // #define DEBUG_FR_SCENE 34 34 35 //----- header files << 35 //----- header files 36 #include <fstream> 36 #include <fstream> 37 #include <stdlib.h> 37 #include <stdlib.h> 38 #include <string.h> 38 #include <string.h> 39 #include <sstream> << 40 #include <iomanip> << 41 #include "globals.hh" 39 #include "globals.hh" 42 #include "G4VisManager.hh" << 43 #include "G4FRConst.hh" 40 #include "G4FRConst.hh" 44 #include "G4DAWNFILE.hh" 41 #include "G4DAWNFILE.hh" 45 #include "G4DAWNFILESceneHandler.hh" 42 #include "G4DAWNFILESceneHandler.hh" 46 #include "G4DAWNFILEViewer.hh" 43 #include "G4DAWNFILEViewer.hh" 47 #include "G4Point3D.hh" 44 #include "G4Point3D.hh" 48 #include "G4VisAttributes.hh" 45 #include "G4VisAttributes.hh" 49 #include "G4Scene.hh" 46 #include "G4Scene.hh" 50 #include "G4Transform3D.hh" 47 #include "G4Transform3D.hh" 51 #include "G4Polyhedron.hh" 48 #include "G4Polyhedron.hh" 52 #include "G4Box.hh" 49 #include "G4Box.hh" 53 #include "G4Cons.hh" 50 #include "G4Cons.hh" 54 #include "G4Polyline.hh" 51 #include "G4Polyline.hh" 55 #include "G4Trd.hh" 52 #include "G4Trd.hh" 56 #include "G4Tubs.hh" 53 #include "G4Tubs.hh" 57 #include "G4Trap.hh" 54 #include "G4Trap.hh" 58 #include "G4Torus.hh" 55 #include "G4Torus.hh" 59 #include "G4Sphere.hh" 56 #include "G4Sphere.hh" 60 #include "G4Para.hh" 57 #include "G4Para.hh" 61 #include "G4Text.hh" 58 #include "G4Text.hh" 62 #include "G4Circle.hh" 59 #include "G4Circle.hh" 63 #include "G4Square.hh" 60 #include "G4Square.hh" >> 61 #include "G4ModelingParameters.hh" 64 #include "G4VPhysicalVolume.hh" 62 #include "G4VPhysicalVolume.hh" 65 63 66 //----- constants 64 //----- constants 67 const char FR_ENV_CULL_INVISIBLE_OBJECTS[] = " << 65 const char FR_ENV_CULL_INVISIBLE_OBJECTS [] = "G4DAWN_CULL_INVISIBLE_OBJECTS"; 68 const char G4PRIM_FILE_HEADER[] = " << 66 const char G4PRIM_FILE_HEADER [] = "g4_"; 69 const char DEFAULT_G4PRIM_FILE_NAME[] = " << 67 const char DEFAULT_G4PRIM_FILE_NAME[] = "g4_00.prim"; 70 const int FR_MAX_FILE_NUM = 100; << 68 >> 69 // const int FR_MAX_FILE_NUM = 1 ; >> 70 // const int FR_MAX_FILE_NUM = 5 ; >> 71 // const int FR_MAX_FILE_NUM = 10 ; >> 72 // const int FR_MAX_FILE_NUM = 15 ; >> 73 // const int FR_MAX_FILE_NUM = 20 ; >> 74 const int FR_MAX_FILE_NUM = 100 ; >> 75 71 76 72 /////////////////////////// 77 /////////////////////////// 73 // Driver-dependent part // 78 // Driver-dependent part // 74 /////////////////////////// 79 /////////////////////////// 75 80 76 //----- G4DAWNFILESceneHandler, constructor << 81 77 G4DAWNFILESceneHandler::G4DAWNFILESceneHandler << 82 //----- G4DAWNFILESceneHandler, constructor 78 << 83 G4DAWNFILESceneHandler::G4DAWNFILESceneHandler (G4DAWNFILE& system, const G4String& name): 79 : G4VSceneHandler(system, fSceneIdCount++, n << 84 G4VSceneHandler (system, fSceneIdCount++, name) , 80 , fSystem(system) << 85 fSystem (system) , 81 , fPrimDest() << 86 fPrimDest () , 82 , FRflag_in_modeling(false) << 87 FRflag_in_modeling (false) , 83 , flag_saving_g4_prim(false) << 88 flag_saving_g4_prim (false) , 84 , COMMAND_BUF_SIZE(G4FRofstream::SEND_BUFMAX << 89 COMMAND_BUF_SIZE (G4FRofstream::SEND_BUFMAX), 85 , fPrec(9) << 90 fPrec (9), fPrec2 (16) 86 , fPrec2(16) << 87 { 91 { 88 // g4.prim filename and its directory << 92 // count instantiated scenes 89 if(std::getenv("G4DAWNFILE_DEST_DIR") == NUL << 93 fSceneCount++; 90 { << 91 strcpy(fG4PrimDestDir, ""); << 92 strcpy(fG4PrimFileName, DEFAULT_G4PRIM_FIL << 93 } << 94 else << 95 { << 96 strcpy(fG4PrimDestDir, std::getenv("G4DAWN << 97 strcpy(fG4PrimFileName, DEFAULT_G4PRIM_FIL << 98 } << 99 << 100 // maximum number of g4.prim files in the de << 101 fMaxFileNum = FR_MAX_FILE_NUM; // initializ << 102 if(std::getenv("G4DAWNFILE_MAX_FILE_NUM") != << 103 { << 104 sscanf(std::getenv("G4DAWNFILE_MAX_FILE_NU << 105 } << 106 else << 107 { << 108 fMaxFileNum = FR_MAX_FILE_NUM; << 109 } << 110 if(fMaxFileNum < 1) << 111 { << 112 fMaxFileNum = 1; << 113 } << 114 << 115 //----- precision control << 116 if(std::getenv("G4DAWNFILE_PRECISION") != NU << 117 { << 118 sscanf(std::getenv("G4DAWNFILE_PRECISION") << 119 } << 120 else << 121 { << 122 fPrec = 9; << 123 } << 124 fPrec2 = fPrec + 7; << 125 } << 126 94 127 //----- G4DAWNFILESceneHandler, destructor << 95 // g4.prim filename and its directory 128 G4DAWNFILESceneHandler::~G4DAWNFILESceneHandle << 96 if ( getenv( "G4DAWNFILE_DEST_DIR" ) == NULL ) { >> 97 strcpy( fG4PrimDestDir , "" ) ; // output dir >> 98 strcpy( fG4PrimFileName, DEFAULT_G4PRIM_FILE_NAME ); // filename >> 99 } else { >> 100 strcpy( fG4PrimDestDir , getenv( "G4DAWNFILE_DEST_DIR" ) ); // output dir >> 101 strcpy( fG4PrimFileName, DEFAULT_G4PRIM_FILE_NAME ); // filename >> 102 } >> 103 >> 104 // maximum number of g4.prim files in the dest directory >> 105 fMaxFileNum = FR_MAX_FILE_NUM ; // initialization >> 106 if ( getenv( "G4DAWNFILE_MAX_FILE_NUM" ) != NULL ) { >> 107 >> 108 sscanf( getenv("G4DAWNFILE_MAX_FILE_NUM"), "%d", &fMaxFileNum ) ; >> 109 >> 110 } else { >> 111 fMaxFileNum = FR_MAX_FILE_NUM ; >> 112 } >> 113 if( fMaxFileNum < 1 ) { fMaxFileNum = 1 ; } >> 114 >> 115 >> 116 //----- precision control >> 117 if( getenv( "G4DAWNFILE_PRECISION" ) != NULL ) { >> 118 sscanf( getenv("G4DAWNFILE_PRECISION"), "%d", &fPrec ) ; >> 119 } else { >> 120 fPrec = 9 ; >> 121 } >> 122 fPrec2 = fPrec + 7 ; >> 123 >> 124 } >> 125 >> 126 >> 127 //----- G4DAWNFILESceneHandler, destructor >> 128 G4DAWNFILESceneHandler::~G4DAWNFILESceneHandler () 129 { 129 { 130 #if defined DEBUG_FR_SCENE 130 #if defined DEBUG_FR_SCENE 131 if(G4VisManager::GetVerbosity() >= G4VisMana << 131 G4cerr << "***** ~G4DAWNFILESceneHandler" << G4endl; 132 G4cout << "***** ~G4DAWNFILESceneHandler" << 132 #endif 133 #endif << 133 fSceneCount--; 134 if(fPrimDest.IsOpen()) << 134 ClearStore (); // clear current scene 135 { << 135 136 //----- End of modeling << 137 // !EndModeling, !DrawAll, !CloseDevice, << 138 // close g4.prim << 139 FREndModeling(); << 140 } << 141 } 136 } 142 137 143 //----- 138 //----- 144 void G4DAWNFILESceneHandler::SetG4PrimFileName << 139 void G4DAWNFILESceneHandler::SetG4PrimFileName() 145 { 140 { 146 // g4_0000.prim, g4_0001.prim, ..., g4_MAX_F << 141 // g4_00.prim, g4_01.prim, ..., g4_MAX_FILE_INDEX.prim 147 const int MAX_FILE_INDEX = fMaxFileNum - 1; << 142 const int MAX_FILE_INDEX = fMaxFileNum - 1 ; >> 143 >> 144 // dest directory (null if no environmental variables is set) >> 145 strcpy ( fG4PrimFileName, fG4PrimDestDir) ; 148 146 149 // dest directory (null if no environmental << 147 // create full path name (default) 150 strcpy(fG4PrimFileName, fG4PrimDestDir); << 148 strcat ( fG4PrimFileName, DEFAULT_G4PRIM_FILE_NAME ); 151 149 152 // create full path name (default) << 150 // Automatic updation of file names 153 strcat(fG4PrimFileName, DEFAULT_G4PRIM_FILE_ << 151 for( int i = 0 ; i < fMaxFileNum ; i++) { >> 152 >> 153 // Message in the final execution >> 154 if( i == MAX_FILE_INDEX ) >> 155 { >> 156 G4cerr << "===========================================" << G4endl; >> 157 G4cerr << "WARNING MESSAGE from DAWNFILE driver: " << G4endl; >> 158 G4cerr << " This file name is the final one in the " << G4endl; >> 159 G4cerr << " automatic updation of the output file name." << G4endl; >> 160 G4cerr << " You may overwrite existing files, i.e. " << G4endl; >> 161 G4cerr << " g4_XX.prim and g4_XX.eps " << G4endl; >> 162 G4cerr << "===========================================" << G4endl; >> 163 } >> 164 >> 165 // re-determine file name as G4DAWNFILE_DEST_DIR/g4_XX.prim >> 166 if( i >= 0 && i <= 9 ) { >> 167 sprintf( fG4PrimFileName, "%s%s%s%d.prim" , fG4PrimDestDir, G4PRIM_FILE_HEADER, "0", i ); >> 168 } else { >> 169 sprintf( fG4PrimFileName, "%s%s%d.prim" , fG4PrimDestDir, G4PRIM_FILE_HEADER, i ); >> 170 } >> 171 >> 172 // check validity of the file name >> 173 std::ifstream fin ; >> 174 fin.open(fG4PrimFileName) ; >> 175 if(!fin) { >> 176 // new file >> 177 fin.close(); >> 178 break; >> 179 } else { >> 180 // already exists (try next) >> 181 fin.close(); >> 182 } >> 183 >> 184 } // for >> 185 >> 186 G4cerr << "=========================================== " << G4endl; >> 187 G4cerr << "Output file: " << fG4PrimFileName << G4endl; >> 188 G4cerr << "Destination directory (current dir if NULL): " << fG4PrimDestDir << G4endl; >> 189 G4cerr << "Maximal number of files in the destination directory: " << fMaxFileNum << G4endl; >> 190 G4cerr << "Note: " << G4endl; >> 191 G4cerr << " * The maximal number is customizable as: " << G4endl; >> 192 G4cerr << " % setenv G4DAWNFILE_MAX_FILE_NUM number " << G4endl; >> 193 G4cerr << " * The destination directory is customizable as:" << G4endl; >> 194 G4cerr << " % setenv G4DAWNFILE_DEST_DIR dir_name/ " << G4endl; >> 195 G4cerr << " ** Do not forget \"/\" at the end of the " << G4endl; >> 196 G4cerr << " dir_name, e.g. \"./tmp/\". " << G4endl; >> 197 G4cerr << "=========================================== " << G4endl; 154 198 155 // Automatic updation of file names << 199 } // G4DAWNFILESceneHandler::SetG4PrimFileName() 156 for(int i = 0; i < fMaxFileNum; i++) << 157 { << 158 // Message in the final execution << 159 if(i == MAX_FILE_INDEX) << 160 { << 161 if(G4VisManager::GetVerbosity() >= G4Vis << 162 { << 163 G4cout << "=========================== << 164 G4cout << "WARNING MESSAGE from DAWNFI << 165 G4cout << " This file name is the fin << 166 G4cout << " automatic updation of the << 167 G4cout << " You may overwrite existin << 168 G4cout << " g4_XXXX.prim and g4_XXXX. << 169 G4cout << "=========================== << 170 } << 171 } << 172 << 173 // re-determine file name as G4DAWNFILE_DE << 174 std::ostringstream filename; << 175 filename << fG4PrimDestDir << G4PRIM_FILE_ << 176 << std::setfill('0') << i << ".pr << 177 strncpy(fG4PrimFileName, filename.str().c_ << 178 sizeof(fG4PrimFileName) - 1); << 179 fG4PrimFileName[sizeof(fG4PrimFileName) - << 180 << 181 // check validity of the file name << 182 std::ifstream fin; << 183 fin.open(fG4PrimFileName); << 184 if(!fin) << 185 { << 186 // new file << 187 fin.close(); << 188 break; << 189 } << 190 else << 191 { << 192 // already exists (try next) << 193 fin.close(); << 194 } << 195 << 196 } // for << 197 << 198 G4cout << "================================= << 199 G4cout << "Output file: " << fG4PrimFileName << 200 G4cout << "Destination directory (current di << 201 << G4endl; << 202 G4cout << "Maximal number of files in the de << 203 << fMaxFileNum << G4endl; << 204 G4cout << "Note: << 205 G4cout << " * The maximal number is customi << 206 G4cout << " % setenv G4DAWNFILE_MAX_F << 207 G4cout << " * The destination directory is << 208 G4cout << " % setenv G4DAWNFILE_DEST_ << 209 G4cout << " ** Do not forget \"/\" at th << 210 G4cout << " dir_name, e.g. \"./tmp/\" << 211 G4cout << "================================= << 212 200 213 } // G4DAWNFILESceneHandler::SetG4PrimFileNam << 214 201 215 //----- 202 //----- 216 void G4DAWNFILESceneHandler::BeginSavingG4Prim << 203 void G4DAWNFILESceneHandler::BeginSavingG4Prim( void ) 217 { 204 { 218 #if defined DEBUG_FR_SCENE 205 #if defined DEBUG_FR_SCENE 219 if(G4VisManager::GetVerbosity() >= G4VisMana << 206 G4cerr << "***** BeginSavingG4Prim (called)\n"; 220 G4cout << "***** BeginSavingG4Prim (called << 221 #endif 207 #endif 222 208 223 if(!IsSavingG4Prim()) << 209 if( !IsSavingG4Prim() ) 224 { << 210 { 225 #if defined DEBUG_FR_SCENE 211 #if defined DEBUG_FR_SCENE 226 if(G4VisManager::GetVerbosity() >= G4VisMa << 212 G4cerr << "***** (started) " ; 227 { << 213 G4cerr << "(open g4.prim, ##)" << G4endl; 228 G4cout << "***** (star << 229 G4cout << "(open g4.prim, ##)" << G4endl << 230 } << 231 #endif 214 #endif 232 SetG4PrimFileName(); // result set to fG4 << 215 SetG4PrimFileName() ; // result set to fG4PrimFileName 233 fPrimDest.Open(fG4PrimFileName); << 216 fPrimDest.Open(fG4PrimFileName) ; 234 217 235 SendStr(FR_G4_PRIM_HEADER); << 218 SendStr( FR_G4_PRIM_HEADER ) ; 236 flag_saving_g4_prim = true; << 219 flag_saving_g4_prim = true ; 237 } << 220 } 238 } 221 } 239 222 240 void G4DAWNFILESceneHandler::EndSavingG4Prim(v << 223 void G4DAWNFILESceneHandler::EndSavingG4Prim ( void ) 241 { 224 { 242 #if defined DEBUG_FR_SCENE 225 #if defined DEBUG_FR_SCENE 243 if(G4VisManager::GetVerbosity() >= G4VisMana << 226 G4cerr << "***** EndSavingG4Prim (called)\n"; 244 G4cout << "***** EndSavingG4Prim (called)\ << 245 #endif 227 #endif 246 228 247 if(IsSavingG4Prim()) << 229 if( IsSavingG4Prim() ) 248 { << 230 { 249 #if defined DEBUG_FR_SCENE 231 #if defined DEBUG_FR_SCENE 250 if(G4VisManager::GetVerbosity() >= G4VisMa << 232 G4cerr << "***** (started) (close g4.prim)" << G4endl; 251 G4cout << "***** (starte << 252 #endif 233 #endif 253 fPrimDest.Close(); << 234 fPrimDest.Close() ; 254 flag_saving_g4_prim = false; << 235 flag_saving_g4_prim = false ; 255 } << 236 } 256 } 237 } 257 238 258 //----- << 239 259 void G4DAWNFILESceneHandler::FRBeginModeling(v << 240 //----- >> 241 void G4DAWNFILESceneHandler::FRBeginModeling( void ) 260 { 242 { 261 if(!FRIsInModeling()) << 243 if( !FRIsInModeling() ) 262 { << 244 { 263 #if defined DEBUG_FR_SCENE 245 #if defined DEBUG_FR_SCENE 264 if(G4VisManager::GetVerbosity() >= G4VisMa << 246 G4cerr << "***** G4DAWNFILESceneHandler::FRBeginModeling (called & started)" << G4endl; 265 G4cout << 266 << "***** G4DAWNFILESceneHandler::FRBe << 267 << G4endl; << 268 #endif 247 #endif 269 248 270 //----- Send saving command and heading co << 249 //----- Send saving command and heading comment 271 BeginSavingG4Prim(); << 250 BeginSavingG4Prim(); 272 251 273 //----- Send bounding box command << 252 //----- Send bounding box command 274 SendBoundingBox(); << 253 SendBoundingBox(); 275 254 276 //----- send SET_CAMERA command << 255 //----- send SET_CAMERA command 277 #if defined DEBUG_FR_SCENE 256 #if defined DEBUG_FR_SCENE 278 if(G4VisManager::GetVerbosity() >= G4VisMa << 257 G4cerr << "***** (!SetCamera in FRBeginModeling())" << G4endl; 279 G4cout << "***** (!SetCamera in FRBegi << 280 #endif 258 #endif 281 SendStr(FR_SET_CAMERA); << 259 SendStr( FR_SET_CAMERA ); 282 260 283 //----- open device << 261 //----- open device 284 #if defined DEBUG_FR_SCENE 262 #if defined DEBUG_FR_SCENE 285 if(G4VisManager::GetVerbosity() >= G4VisMa << 263 G4cerr << "***** (!OpenDevice in FRBeginModeling())" << G4endl; 286 G4cout << "***** (!OpenDevice in FRBeg << 287 #endif 264 #endif 288 SendStr(FR_OPEN_DEVICE); << 265 SendStr( FR_OPEN_DEVICE ); 289 266 290 //----- begin sending primitives << 267 //----- begin sending primitives 291 #if defined DEBUG_FR_SCENE 268 #if defined DEBUG_FR_SCENE 292 if(G4VisManager::GetVerbosity() >= G4VisMa << 269 G4cerr << "***** (!BeginModeling in FRBeginModeling())" << G4endl; 293 G4cout << "***** (!BeginModeling in FR << 294 #endif 270 #endif 295 SendStr(FR_BEGIN_MODELING); << 271 SendStr( FR_BEGIN_MODELING ); FRflag_in_modeling = true ; 296 FRflag_in_modeling = true; << 272 >> 273 } // if >> 274 >> 275 } 297 276 298 } // if << 299 } << 300 277 301 ///////////////////////////////////////// 278 ///////////////////////////////////////// 302 // Common to DAWN and DAWNFILE drivers // 279 // Common to DAWN and DAWNFILE drivers // 303 ///////////////////////////////////////// 280 ///////////////////////////////////////// 304 281 305 #define G4FRSCENEHANDLER G4DAWNFILESceneHandle << 282 #define G4FRSCENEHANDLER G4DAWNFILESceneHandler 306 #include "G4FRSceneFunc.icc" 283 #include "G4FRSceneFunc.icc" 307 #undef G4FRSCENEHANDLER << 284 #undef G4FRSCENEHANDLER 308 285 309 ////////////////////// 286 ////////////////////// 310 // static variables // 287 // static variables // 311 ////////////////////// 288 ////////////////////// 312 289 313 //----- static variables << 290 //----- static variables 314 G4int G4DAWNFILESceneHandler::fSceneIdCount = << 291 G4int G4DAWNFILESceneHandler::fSceneIdCount = 0; >> 292 >> 293 G4int G4DAWNFILESceneHandler::fSceneCount = 0; >> 294 // num of existing instances 315 295