Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // 26 // >> 27 // $Id$ 27 // 28 // 28 // 29 // 29 // Created: Mar. 31, 2009 Akinori Kimura 30 // Created: Mar. 31, 2009 Akinori Kimura 30 // 31 // 31 32 32 33 33 #define __G_ANSI_C__ 34 #define __G_ANSI_C__ 34 #define G4GMocrenFile_STRUCTURE_PRIORITY 1. 35 #define G4GMocrenFile_STRUCTURE_PRIORITY 1. 35 36 36 #include "G4ios.hh" 37 #include "G4ios.hh" 37 #include <cstdio> 38 #include <cstdio> 38 #include <cstring> 39 #include <cstring> 39 #include <cassert> 40 #include <cassert> 40 41 41 #include "G4VisManager.hh" 42 #include "G4VisManager.hh" 42 #include "G4Scene.hh" 43 #include "G4Scene.hh" 43 #include "G4Vector3D.hh" 44 #include "G4Vector3D.hh" 44 #include "G4VisExtent.hh" 45 #include "G4VisExtent.hh" 45 #include "G4LogicalVolume.hh" 46 #include "G4LogicalVolume.hh" 46 #include "G4VSolid.hh" 47 #include "G4VSolid.hh" 47 48 48 #include "G4GMocrenFile.hh" 49 #include "G4GMocrenFile.hh" 49 #include "G4GMocrenFileSceneHandler.hh" 50 #include "G4GMocrenFileSceneHandler.hh" 50 #include "G4GMocrenFileViewer.hh" 51 #include "G4GMocrenFileViewer.hh" 51 #include "G4GMocrenMessenger.hh" 52 #include "G4GMocrenMessenger.hh" 52 53 53 54 54 //----- constants 55 //----- constants 55 56 56 //-- for a debugging 57 //-- for a debugging 57 const G4bool GFDEBUG = false; << 58 const bool GFDEBUG = false; 58 59 59 //----- G4GMocrenFileViewer, constructor 60 //----- G4GMocrenFileViewer, constructor 60 G4GMocrenFileViewer::G4GMocrenFileViewer (G4GM 61 G4GMocrenFileViewer::G4GMocrenFileViewer (G4GMocrenFileSceneHandler& sceneHandler, 61 G4GMocrenMessenger &, << 62 G4GMocrenMessenger & messenger, 62 const G4String& name) 63 const G4String& name) 63 : G4VViewer (sceneHandler, sceneHandler.Incr 64 : G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name), 64 kSceneHandler (sceneHandler) << 65 kSceneHandler (sceneHandler), >> 66 kMessenger(messenger) 65 { 67 { 66 // Set a g4.gdd-file viewer 68 // Set a g4.gdd-file viewer 67 std::strncpy( kG4GddViewer, "gMocren", 8); << 69 std::strncpy( kG4GddViewer, "gMocren", 7); 68 if( std::getenv( "G4GMocrenFile_VIEWER" ) != << 70 if( getenv( "G4GMocrenFile_VIEWER" ) != NULL ) { 69 char * env = std::getenv( "G4GMocrenFile_V << 71 char * env = getenv( "G4GMocrenFile_VIEWER" ); 70 G4int len = (G4int)std::strlen(env); << 72 std::strncpy( kG4GddViewer, env, std::strlen(env)); 71 if(len >= 32) { << 72 G4Exception("G4GMocrenFileViewer::G4GMoc << 73 "gMocren1000", FatalExceptio << 74 "Invalid length of string se << 75 } << 76 std::strncpy( kG4GddViewer, env, sizeof(kG << 77 kG4GddViewer[sizeof(kG4GddViewer) - 1] = ' << 78 //std::strcpy( kG4GddViewer, getenv( "G4GM 73 //std::strcpy( kG4GddViewer, getenv( "G4GMocrenFile_VIEWER" ) ) ; 79 } 74 } 80 75 81 // string for viewer invocation 76 // string for viewer invocation 82 if ( !std::strcmp( kG4GddViewer, "NONE" ) ) 77 if ( !std::strcmp( kG4GddViewer, "NONE" ) ) { 83 78 84 //std::strcpy( kG4GddViewerInvocation, "" 79 //std::strcpy( kG4GddViewerInvocation, "" ); 85 kG4GddViewerInvocation[0] = '\0'; 80 kG4GddViewerInvocation[0] = '\0'; 86 } else { 81 } else { 87 82 88 std::strncpy( kG4GddViewerInvocation, kG4G << 83 std::strncpy( kG4GddViewerInvocation, kG4GddViewer, std::strlen(kG4GddViewer)); 89 sizeof(kG4GddViewerInvocation << 84 std::strncat( kG4GddViewerInvocation, " ", 1); 90 kG4GddViewerInvocation[sizeof(kG4GddViewer << 91 G4int n = sizeof(kG4GddViewerInvocation) << 92 - (G4int)std::strlen(kG4GddViewerI << 93 std::strncat( kG4GddViewerInvocation, " ", << 94 const char * gddfname = kSceneHandler.GetG 85 const char * gddfname = kSceneHandler.GetGddFileName(); 95 G4int len = (G4int)std::strlen(gddfname); << 86 std::strncat( kG4GddViewerInvocation, gddfname, std::strlen(gddfname) ); 96 if(len >= 64) { << 97 G4Exception("G4GMocrenFileViewer::G4GMoc << 98 "gMocren1001", FatalExceptio << 99 "Invalid length of the GDD f << 100 } << 101 n = sizeof(kG4GddViewerInvocation) << 102 - (G4int)std::strlen(kG4GddViewerInvocat << 103 std::strncat( kG4GddViewerInvocation, gddf << 104 } 87 } 105 88 106 } 89 } 107 90 108 //----- G4GMocrenFileViewer, destructor 91 //----- G4GMocrenFileViewer, destructor 109 G4GMocrenFileViewer::~G4GMocrenFileViewer () 92 G4GMocrenFileViewer::~G4GMocrenFileViewer () 110 {} 93 {} 111 94 112 //----- G4GMocrenFileViewer::SetView () 95 //----- G4GMocrenFileViewer::SetView () 113 void G4GMocrenFileViewer::SetView () 96 void G4GMocrenFileViewer::SetView () 114 { 97 { 115 if(GFDEBUG) 98 if(GFDEBUG) 116 if (G4VisManager::GetVerbosity() >= G4VisM 99 if (G4VisManager::GetVerbosity() >= G4VisManager::errors) 117 G4cout << "***** G4GMocrenFileViewer::Se 100 G4cout << "***** G4GMocrenFileViewer::SetView(): No effects" << G4endl; 118 101 119 // Do nothing, since DAWN is running as a di 102 // Do nothing, since DAWN is running as a different process. 120 // SendViewParameters () will do this job in 103 // SendViewParameters () will do this job instead. 121 } 104 } 122 105 123 106 124 //----- G4GMocrenFileViewer::ClearView() 107 //----- G4GMocrenFileViewer::ClearView() 125 void 108 void 126 G4GMocrenFileViewer::ClearView( void ) 109 G4GMocrenFileViewer::ClearView( void ) 127 { 110 { 128 if(GFDEBUG) { << 111 if(GFDEBUG) 129 if (G4VisManager::GetVerbosity() >= G4VisM << 112 if (G4VisManager::GetVerbosity() >= G4VisManager::errors) 130 G4cout << "***** G4GMocrenFileViewer::Cl 113 G4cout << "***** G4GMocrenFileViewer::ClearView (): No effects " << G4endl; 131 } << 114 132 } << 133 //if(kSceneHandler.kGddDest) { 115 //if(kSceneHandler.kGddDest) { 134 //kSceneHandler.kGddDest.close(); 116 //kSceneHandler.kGddDest.close(); 135 // Re-open with same filename... 117 // Re-open with same filename... 136 //kSceneHandler.kGddDest.open(kSceneHandle 118 //kSceneHandler.kGddDest.open(kSceneHandler.kGddFileName); 137 kSceneHandler.kFlagInModeling = false; 119 kSceneHandler.kFlagInModeling = false; 138 kSceneHandler.GFBeginModeling(); 120 kSceneHandler.GFBeginModeling(); 139 //} 121 //} 140 } 122 } 141 123 142 124 143 //----- G4GMocrenFileViewer::DrawView () 125 //----- G4GMocrenFileViewer::DrawView () 144 void G4GMocrenFileViewer::DrawView () 126 void G4GMocrenFileViewer::DrawView () 145 { 127 { 146 if(GFDEBUG) 128 if(GFDEBUG) 147 if (G4VisManager::GetVerbosity() >= G4VisM 129 if (G4VisManager::GetVerbosity() >= G4VisManager::errors) 148 G4cout << "***** G4GMocrenFileViewer::Dr 130 G4cout << "***** G4GMocrenFileViewer::DrawView () " << G4endl; 149 131 150 //----- 132 //----- 151 kSceneHandler.GFBeginModeling() ; 133 kSceneHandler.GFBeginModeling() ; 152 134 153 //----- Always visit G4 kernel 135 //----- Always visit G4 kernel 154 NeedKernelVisit (); 136 NeedKernelVisit (); 155 137 156 //----- Draw 138 //----- Draw 157 G4VViewer::ProcessView () ; 139 G4VViewer::ProcessView () ; 158 140 159 } // G4GMocrenFileViewer::DrawView () 141 } // G4GMocrenFileViewer::DrawView () 160 142 161 143 162 144 163 //----- G4GMocrenFileViewer::ShowView() 145 //----- G4GMocrenFileViewer::ShowView() 164 void G4GMocrenFileViewer::ShowView( void ) 146 void G4GMocrenFileViewer::ShowView( void ) 165 { 147 { 166 if(GFDEBUG) 148 if(GFDEBUG) 167 if (G4VisManager::GetVerbosity() >= G4VisM 149 if (G4VisManager::GetVerbosity() >= G4VisManager::errors) 168 G4cout << "***** G4GMocrenFileViewer::Sh 150 G4cout << "***** G4GMocrenFileViewer::ShowView () " << G4endl; 169 151 170 if( kSceneHandler.GFIsInModeling() ) 152 if( kSceneHandler.GFIsInModeling() ) 171 { 153 { 172 //----- End of modeling 154 //----- End of modeling 173 // !EndModeling, !DrawAll, !CloseDevice, 155 // !EndModeling, !DrawAll, !CloseDevice, 174 // close g4.gdd 156 // close g4.gdd 175 kSceneHandler.GFEndModeling(); 157 kSceneHandler.GFEndModeling(); 176 158 177 //----- Output DAWN GUI file 159 //----- Output DAWN GUI file 178 //SendViewParameters(); 160 //SendViewParameters(); 179 161 180 //----- string for viewer invocation 162 //----- string for viewer invocation 181 if ( !strcmp( kG4GddViewer, "NONE" ) ) { 163 if ( !strcmp( kG4GddViewer, "NONE" ) ) { 182 164 183 kG4GddViewerInvocation[0] = '\0'; 165 kG4GddViewerInvocation[0] = '\0'; 184 //std::strcpy( kG4GddViewerInvocation, "" ); 166 //std::strcpy( kG4GddViewerInvocation, "" ); 185 } else { 167 } else { 186 168 187 std::strncpy( kG4GddViewerInvocation, << 169 std::strncpy( kG4GddViewerInvocation, kG4GddViewer, std::strlen(kG4GddViewer)); 188 sizeof(kG4GddViewerInvoca << 170 std::strncat( kG4GddViewerInvocation, " ", 1); 189 kG4GddViewerInvocation[sizeof(kG4GddVi << 171 const char * gddfname = kSceneHandler.GetGddFileName(); 190 G4int n = sizeof(kG4GddViewerInvocatio << 172 std::strncat( kG4GddViewerInvocation, gddfname, std::strlen(gddfname)); 191 - (G4int)std::strlen(kG4GddVie << 192 std::strncat( kG4GddViewerInvocation, << 193 const char * gddfname = kSceneHandler. << 194 G4int len = (G4int)std::strlen(gddfnam << 195 if(len >= 64) { << 196 G4Exception("G4GMocrenFileViewer::Sh << 197 "gMocren1002", FatalExce << 198 "Invalid length of the G << 199 } << 200 n = sizeof(kG4GddViewerInvocation) << 201 - (G4int)std::strlen(kG4GddViewerInv << 202 std::strncat( kG4GddViewerInvocation, << 203 } 173 } 204 174 205 } 175 } 206 176 207 } // G4GMocrenFileViewer::ShowView() 177 } // G4GMocrenFileViewer::ShowView() 208 178 209 179