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