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