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: G4GMocrenFileViewer.cc,v 1.4 2010-11-10 23:53:23 akimura Exp $ >> 28 // GEANT4 tag $Name: not supported by cvs2svn $ 27 // 29 // 28 // 30 // 29 // Created: Mar. 31, 2009 Akinori Kimura 31 // Created: Mar. 31, 2009 Akinori Kimura 30 // 32 // 31 33 32 34 33 #define __G_ANSI_C__ 35 #define __G_ANSI_C__ 34 #define G4GMocrenFile_STRUCTURE_PRIORITY 1. 36 #define G4GMocrenFile_STRUCTURE_PRIORITY 1. 35 37 36 #include "G4ios.hh" 38 #include "G4ios.hh" 37 #include <cstdio> 39 #include <cstdio> 38 #include <cstring> 40 #include <cstring> 39 #include <cassert> 41 #include <cassert> 40 42 41 #include "G4VisManager.hh" 43 #include "G4VisManager.hh" 42 #include "G4Scene.hh" 44 #include "G4Scene.hh" 43 #include "G4Vector3D.hh" 45 #include "G4Vector3D.hh" 44 #include "G4VisExtent.hh" 46 #include "G4VisExtent.hh" 45 #include "G4LogicalVolume.hh" 47 #include "G4LogicalVolume.hh" 46 #include "G4VSolid.hh" 48 #include "G4VSolid.hh" 47 49 48 #include "G4GMocrenFile.hh" 50 #include "G4GMocrenFile.hh" 49 #include "G4GMocrenFileSceneHandler.hh" 51 #include "G4GMocrenFileSceneHandler.hh" 50 #include "G4GMocrenFileViewer.hh" 52 #include "G4GMocrenFileViewer.hh" 51 #include "G4GMocrenMessenger.hh" 53 #include "G4GMocrenMessenger.hh" 52 54 53 55 54 //----- constants 56 //----- constants 55 57 56 //-- for a debugging 58 //-- for a debugging 57 const G4bool GFDEBUG = false; << 59 const bool GFDEBUG = false; 58 60 59 //----- G4GMocrenFileViewer, constructor 61 //----- G4GMocrenFileViewer, constructor 60 G4GMocrenFileViewer::G4GMocrenFileViewer (G4GM 62 G4GMocrenFileViewer::G4GMocrenFileViewer (G4GMocrenFileSceneHandler& sceneHandler, 61 G4GMocrenMessenger &, << 63 G4GMocrenMessenger & messenger, 62 const G4String& name) 64 const G4String& name) 63 : G4VViewer (sceneHandler, sceneHandler.Incr 65 : G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name), 64 kSceneHandler (sceneHandler) << 66 kSceneHandler (sceneHandler), >> 67 kMessenger(messenger) 65 { 68 { 66 // Set a g4.gdd-file viewer 69 // Set a g4.gdd-file viewer 67 std::strncpy( kG4GddViewer, "gMocren", 8); << 70 std::strcpy( kG4GddViewer, "gMocren" ); 68 if( std::getenv( "G4GMocrenFile_VIEWER" ) != << 71 if( getenv( "G4GMocrenFile_VIEWER" ) != NULL ) { 69 char * env = std::getenv( "G4GMocrenFile_V << 72 std::strcpy( kG4GddViewer, getenv( "G4GMocrenFile_VIEWER" ) ) ; 70 G4int len = (G4int)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 << 79 } 73 } 80 74 81 // string for viewer invocation 75 // string for viewer invocation 82 if ( !std::strcmp( kG4GddViewer, "NONE" ) ) 76 if ( !std::strcmp( kG4GddViewer, "NONE" ) ) { 83 77 84 //std::strcpy( kG4GddViewerInvocation, "" << 78 std::strcpy( kG4GddViewerInvocation, "" ); 85 kG4GddViewerInvocation[0] = '\0'; << 86 } else { 79 } else { 87 80 88 std::strncpy( kG4GddViewerInvocation, kG4G << 81 std::strcpy( kG4GddViewerInvocation, kG4GddViewer ); 89 sizeof(kG4GddViewerInvocation << 82 std::strcat( kG4GddViewerInvocation, " "); 90 kG4GddViewerInvocation[sizeof(kG4GddViewer << 83 std::strcat( kG4GddViewerInvocation, kSceneHandler.GetGddFileName() ); 91 G4int n = sizeof(kG4GddViewerInvocation) << 92 - (G4int)std::strlen(kG4GddViewerI << 93 std::strncat( kG4GddViewerInvocation, " ", << 94 const char * gddfname = kSceneHandler.GetG << 95 G4int len = (G4int)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 } 84 } 105 85 106 } 86 } 107 87 108 //----- G4GMocrenFileViewer, destructor 88 //----- G4GMocrenFileViewer, destructor 109 G4GMocrenFileViewer::~G4GMocrenFileViewer () 89 G4GMocrenFileViewer::~G4GMocrenFileViewer () 110 {} 90 {} 111 91 112 //----- G4GMocrenFileViewer::SetView () 92 //----- G4GMocrenFileViewer::SetView () 113 void G4GMocrenFileViewer::SetView () 93 void G4GMocrenFileViewer::SetView () 114 { 94 { 115 if(GFDEBUG) 95 if(GFDEBUG) 116 if (G4VisManager::GetVerbosity() >= G4VisM 96 if (G4VisManager::GetVerbosity() >= G4VisManager::errors) 117 G4cout << "***** G4GMocrenFileViewer::Se 97 G4cout << "***** G4GMocrenFileViewer::SetView(): No effects" << G4endl; 118 98 119 // Do nothing, since DAWN is running as a di 99 // Do nothing, since DAWN is running as a different process. 120 // SendViewParameters () will do this job in 100 // SendViewParameters () will do this job instead. 121 } 101 } 122 102 123 103 124 //----- G4GMocrenFileViewer::ClearView() 104 //----- G4GMocrenFileViewer::ClearView() 125 void 105 void 126 G4GMocrenFileViewer::ClearView( void ) 106 G4GMocrenFileViewer::ClearView( void ) 127 { 107 { 128 if(GFDEBUG) { << 108 if(GFDEBUG) 129 if (G4VisManager::GetVerbosity() >= G4VisM << 109 if (G4VisManager::GetVerbosity() >= G4VisManager::errors) 130 G4cout << "***** G4GMocrenFileViewer::Cl 110 G4cout << "***** G4GMocrenFileViewer::ClearView (): No effects " << G4endl; 131 } << 111 132 } << 133 //if(kSceneHandler.kGddDest) { 112 //if(kSceneHandler.kGddDest) { 134 //kSceneHandler.kGddDest.close(); 113 //kSceneHandler.kGddDest.close(); 135 // Re-open with same filename... 114 // Re-open with same filename... 136 //kSceneHandler.kGddDest.open(kSceneHandle 115 //kSceneHandler.kGddDest.open(kSceneHandler.kGddFileName); 137 kSceneHandler.kFlagInModeling = false; 116 kSceneHandler.kFlagInModeling = false; 138 kSceneHandler.GFBeginModeling(); 117 kSceneHandler.GFBeginModeling(); 139 //} 118 //} 140 } 119 } 141 120 142 121 143 //----- G4GMocrenFileViewer::DrawView () 122 //----- G4GMocrenFileViewer::DrawView () 144 void G4GMocrenFileViewer::DrawView () 123 void G4GMocrenFileViewer::DrawView () 145 { 124 { 146 if(GFDEBUG) 125 if(GFDEBUG) 147 if (G4VisManager::GetVerbosity() >= G4VisM 126 if (G4VisManager::GetVerbosity() >= G4VisManager::errors) 148 G4cout << "***** G4GMocrenFileViewer::Dr 127 G4cout << "***** G4GMocrenFileViewer::DrawView () " << G4endl; 149 128 150 //----- 129 //----- 151 kSceneHandler.GFBeginModeling() ; 130 kSceneHandler.GFBeginModeling() ; 152 131 153 //----- Always visit G4 kernel 132 //----- Always visit G4 kernel 154 NeedKernelVisit (); 133 NeedKernelVisit (); 155 134 156 //----- Draw 135 //----- Draw 157 G4VViewer::ProcessView () ; 136 G4VViewer::ProcessView () ; 158 137 159 } // G4GMocrenFileViewer::DrawView () 138 } // G4GMocrenFileViewer::DrawView () 160 139 161 140 162 141 163 //----- G4GMocrenFileViewer::ShowView() 142 //----- G4GMocrenFileViewer::ShowView() 164 void G4GMocrenFileViewer::ShowView( void ) 143 void G4GMocrenFileViewer::ShowView( void ) 165 { 144 { 166 if(GFDEBUG) 145 if(GFDEBUG) 167 if (G4VisManager::GetVerbosity() >= G4VisM 146 if (G4VisManager::GetVerbosity() >= G4VisManager::errors) 168 G4cout << "***** G4GMocrenFileViewer::Sh 147 G4cout << "***** G4GMocrenFileViewer::ShowView () " << G4endl; 169 148 170 if( kSceneHandler.GFIsInModeling() ) 149 if( kSceneHandler.GFIsInModeling() ) 171 { 150 { 172 //----- End of modeling 151 //----- End of modeling 173 // !EndModeling, !DrawAll, !CloseDevice, 152 // !EndModeling, !DrawAll, !CloseDevice, 174 // close g4.gdd 153 // close g4.gdd 175 kSceneHandler.GFEndModeling(); 154 kSceneHandler.GFEndModeling(); 176 155 177 //----- Output DAWN GUI file 156 //----- Output DAWN GUI file 178 //SendViewParameters(); 157 //SendViewParameters(); 179 158 180 //----- string for viewer invocation 159 //----- string for viewer invocation 181 if ( !strcmp( kG4GddViewer, "NONE" ) ) { 160 if ( !strcmp( kG4GddViewer, "NONE" ) ) { 182 161 183 kG4GddViewerInvocation[0] = '\0'; << 162 std::strcpy( kG4GddViewerInvocation, "" ); 184 //std::strcpy( kG4GddViewerInvocation, "" ); << 185 } else { 163 } else { 186 164 187 std::strncpy( kG4GddViewerInvocation, << 165 std::strcpy( kG4GddViewerInvocation, kG4GddViewer ); 188 sizeof(kG4GddViewerInvoca << 166 std::strcat( kG4GddViewerInvocation, " "); 189 kG4GddViewerInvocation[sizeof(kG4GddVi << 167 std::strcat( kG4GddViewerInvocation, kSceneHandler.GetGddFileName() ); 190 G4int n = sizeof(kG4GddViewerInvocatio << 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 } 168 } 204 169 205 } 170 } 206 171 207 } // G4GMocrenFileViewer::ShowView() 172 } // G4GMocrenFileViewer::ShowView() 208 173 209 174