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 27 28 // /vis/scene commands - John Allison 9th Aug 28 // /vis/scene commands - John Allison 9th August 1998 29 29 30 #include "G4VisCommandsScene.hh" 30 #include "G4VisCommandsScene.hh" 31 31 32 #include "G4VisManager.hh" 32 #include "G4VisManager.hh" 33 #include "G4TransportationManager.hh" 33 #include "G4TransportationManager.hh" 34 #include "G4RunManager.hh" 34 #include "G4RunManager.hh" 35 #include "G4RunManagerFactory.hh" 35 #include "G4RunManagerFactory.hh" 36 #include "G4Run.hh" 36 #include "G4Run.hh" 37 #include "G4PhysicalVolumeModel.hh" 37 #include "G4PhysicalVolumeModel.hh" 38 #include "G4ApplicationState.hh" 38 #include "G4ApplicationState.hh" 39 #include "G4UImanager.hh" 39 #include "G4UImanager.hh" 40 #include "G4UIcommand.hh" 40 #include "G4UIcommand.hh" 41 #include "G4UIcmdWithAString.hh" 41 #include "G4UIcmdWithAString.hh" 42 #include "G4UIcmdWithoutParameter.hh" 42 #include "G4UIcmdWithoutParameter.hh" 43 #include "G4ios.hh" 43 #include "G4ios.hh" 44 #include <sstream> 44 #include <sstream> 45 45 46 #define G4warn G4cout << 47 << 48 G4VVisCommandScene::G4VVisCommandScene () {} 46 G4VVisCommandScene::G4VVisCommandScene () {} 49 47 50 G4VVisCommandScene::~G4VVisCommandScene () {} 48 G4VVisCommandScene::~G4VVisCommandScene () {} 51 49 52 G4String G4VVisCommandScene::CurrentSceneName 50 G4String G4VVisCommandScene::CurrentSceneName () { 53 const G4Scene* pScene = fpVisManager -> GetC 51 const G4Scene* pScene = fpVisManager -> GetCurrentScene (); 54 G4String currentSceneName = "none"; 52 G4String currentSceneName = "none"; 55 if (pScene) currentSceneName = pScene -> Get 53 if (pScene) currentSceneName = pScene -> GetName (); 56 return currentSceneName; 54 return currentSceneName; 57 } 55 } 58 56 59 ////////////// /vis/scene/activateModel ////// 57 ////////////// /vis/scene/activateModel //////////////////////////// 60 58 61 G4VisCommandSceneActivateModel::G4VisCommandSc 59 G4VisCommandSceneActivateModel::G4VisCommandSceneActivateModel () { 62 G4bool omitable; 60 G4bool omitable; 63 fpCommand = new G4UIcommand ("/vis/scene/act 61 fpCommand = new G4UIcommand ("/vis/scene/activateModel", this); 64 fpCommand -> SetGuidance 62 fpCommand -> SetGuidance 65 ("Activate or de-activate model."); 63 ("Activate or de-activate model."); 66 fpCommand -> SetGuidance 64 fpCommand -> SetGuidance 67 ("Attempts to match search string to name 65 ("Attempts to match search string to name of model - use unique sub-string."); 68 fpCommand -> SetGuidance 66 fpCommand -> SetGuidance 69 ("Use \"/vis/scene/list\" to see model nam 67 ("Use \"/vis/scene/list\" to see model names."); 70 fpCommand -> SetGuidance 68 fpCommand -> SetGuidance 71 ("If name == \"all\" (default), all models 69 ("If name == \"all\" (default), all models are activated."); 72 G4UIparameter* parameter; 70 G4UIparameter* parameter; 73 parameter = new G4UIparameter ("search-strin 71 parameter = new G4UIparameter ("search-string", 's', omitable = true); 74 parameter -> SetDefaultValue ("all"); 72 parameter -> SetDefaultValue ("all"); 75 fpCommand -> SetParameter (parameter); 73 fpCommand -> SetParameter (parameter); 76 parameter = new G4UIparameter ("activate", ' 74 parameter = new G4UIparameter ("activate", 'b', omitable = true); 77 parameter -> SetDefaultValue (true); 75 parameter -> SetDefaultValue (true); 78 fpCommand -> SetParameter (parameter); 76 fpCommand -> SetParameter (parameter); 79 } 77 } 80 78 81 G4VisCommandSceneActivateModel::~G4VisCommandS 79 G4VisCommandSceneActivateModel::~G4VisCommandSceneActivateModel () { 82 delete fpCommand; 80 delete fpCommand; 83 } 81 } 84 82 85 G4String G4VisCommandSceneActivateModel::GetCu 83 G4String G4VisCommandSceneActivateModel::GetCurrentValue(G4UIcommand*) { 86 return ""; 84 return ""; 87 } 85 } 88 86 89 void G4VisCommandSceneActivateModel::SetNewVal 87 void G4VisCommandSceneActivateModel::SetNewValue (G4UIcommand*, 90 G4String newValue) { 88 G4String newValue) { 91 89 92 G4VisManager::Verbosity verbosity = fpVisMan 90 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); 93 91 94 G4String searchString, activateString; 92 G4String searchString, activateString; 95 std::istringstream is (newValue); 93 std::istringstream is (newValue); 96 // Need to handle the possibility that the s << 94 is >> searchString >> activateString; 97 // contains embedded blanks within quotation << 98 // (This arises if the search string is auto << 99 // global description, as in G4UIQt, clickin << 100 auto lastQuotationMark = newValue.find_last_ << 101 if (lastQuotationMark != std::string::npos) << 102 auto firstQuotationMark = newValue.find_fi << 103 if (lastQuotationMark != firstQuotationMar << 104 // Note: there must not be more quotatio << 105 searchString = newValue.substr << 106 (firstQuotationMark + 1, lastQuotationMa << 107 activateString = newValue.substr(lastQuo << 108 // Perhaps we ought to check number of q << 109 G4int nQuotes = 0; << 110 for (auto c : newValue) { << 111 if (c == '"') nQuotes++; << 112 } << 113 if (nQuotes > 2) { << 114 G4ExceptionDescription ed; << 115 ed << "More than 2 quotation marks in << 116 G4Exception("G4VisCommandSceneActivate << 117 } << 118 } << 119 } << 120 else { << 121 // None or one quotation marks - just inpu << 122 is >> searchString >> activateString; << 123 } << 124 G4bool activate = G4UIcommand::ConvertToBool 95 G4bool activate = G4UIcommand::ConvertToBool(activateString); 125 96 126 G4Scene* pScene = fpVisManager->GetCurrentSc 97 G4Scene* pScene = fpVisManager->GetCurrentScene(); 127 if (!pScene) { 98 if (!pScene) { 128 if (verbosity >= G4VisManager::errors) { 99 if (verbosity >= G4VisManager::errors) { 129 G4warn << "ERROR: No current scene. Ple << 100 G4cerr << "ERROR: No current scene. Please create one." << G4endl; 130 } 101 } 131 return; 102 return; 132 } 103 } 133 104 134 G4VSceneHandler* pSceneHandler = fpVisManage 105 G4VSceneHandler* pSceneHandler = fpVisManager->GetCurrentSceneHandler(); 135 if (!pSceneHandler) { 106 if (!pSceneHandler) { 136 if (verbosity >= G4VisManager::errors) { 107 if (verbosity >= G4VisManager::errors) { 137 G4warn << "ERROR: No current sceneHandle << 108 G4cerr << "ERROR: No current sceneHandler. Please create one." << G4endl; 138 } 109 } 139 return; 110 return; 140 } 111 } 141 112 142 if (searchString == "all" && !activate) { 113 if (searchString == "all" && !activate) { 143 if (verbosity >= G4VisManager::warnings) { 114 if (verbosity >= G4VisManager::warnings) { 144 G4warn << << 115 G4cout << 145 "WARNING: You are not allowed to de-activate 116 "WARNING: You are not allowed to de-activate all models." 146 "\n Command ignored." 117 "\n Command ignored." 147 << G4endl; 118 << G4endl; 148 } 119 } 149 return; 120 return; 150 } 121 } 151 122 152 G4bool any = false; 123 G4bool any = false; 153 124 154 std::vector<G4Scene::Model>& runDurationMode 125 std::vector<G4Scene::Model>& runDurationModelList = 155 pScene->SetRunDurationModelList(); 126 pScene->SetRunDurationModelList(); 156 for (size_t i = 0; i < runDurationModelList. 127 for (size_t i = 0; i < runDurationModelList.size(); i++) { 157 const G4String& modelName = runDurationMod << 128 const G4String& modelName = 158 if (searchString == "all" || modelName.fin << 129 runDurationModelList[i].fpModel->GetGlobalDescription(); >> 130 if (searchString == "all" || modelName.find(searchString) >> 131 != std::string::npos) { 159 any = true; 132 any = true; 160 runDurationModelList[i].fActive = activa 133 runDurationModelList[i].fActive = activate; 161 if (verbosity >= G4VisManager::warnings) 134 if (verbosity >= G4VisManager::warnings) { 162 G4warn << "Model \"" << modelName; << 135 G4cout << "Model \"" << modelName; 163 if (activate) G4warn << "\" activated."; << 136 if (activate) G4cout << "\" activated."; 164 else G4warn << "\" de-activated."; << 137 else G4cout << "\" de-activated."; 165 G4warn << G4endl; << 138 G4cout << G4endl; 166 } 139 } 167 } 140 } 168 } 141 } 169 142 170 std::vector<G4Scene::Model>& endOfEventModel 143 std::vector<G4Scene::Model>& endOfEventModelList = 171 pScene->SetEndOfEventModelList(); 144 pScene->SetEndOfEventModelList(); 172 for (size_t i = 0; i < endOfEventModelList.s 145 for (size_t i = 0; i < endOfEventModelList.size(); i++) { 173 const G4String& modelName = endOfEventMode << 146 const G4String& modelName = 174 if (searchString == "all" || modelName.fin << 147 endOfEventModelList[i].fpModel->GetGlobalDescription(); >> 148 if (searchString == "all" || modelName.find(searchString) >> 149 != std::string::npos) { 175 any = true; 150 any = true; 176 endOfEventModelList[i].fActive = activat 151 endOfEventModelList[i].fActive = activate; 177 if (verbosity >= G4VisManager::warnings) 152 if (verbosity >= G4VisManager::warnings) { 178 G4warn << "Model \"" << modelName; << 153 G4cout << "Model \"" << modelName; 179 if (activate) G4warn << "\" activated."; << 154 if (activate) G4cout << "\" activated."; 180 else G4warn << "\" de-activated."; << 155 else G4cout << "\" de-activated."; 181 G4warn << G4endl; << 156 G4cout << G4endl; 182 } 157 } 183 } 158 } 184 } 159 } 185 160 186 std::vector<G4Scene::Model>& endOfRunModelLi 161 std::vector<G4Scene::Model>& endOfRunModelList = 187 pScene->SetEndOfRunModelList(); 162 pScene->SetEndOfRunModelList(); 188 for (size_t i = 0; i < endOfRunModelList.siz 163 for (size_t i = 0; i < endOfRunModelList.size(); i++) { 189 const G4String& modelName = endOfRunModelL << 164 const G4String& modelName = 190 if (searchString == "all" || modelName.fin << 165 endOfRunModelList[i].fpModel->GetGlobalDescription(); >> 166 if (searchString == "all" || modelName.find(searchString) >> 167 != std::string::npos) { 191 any = true; 168 any = true; 192 endOfRunModelList[i].fActive = activate; 169 endOfRunModelList[i].fActive = activate; 193 if (verbosity >= G4VisManager::warnings) 170 if (verbosity >= G4VisManager::warnings) { 194 G4warn << "Model \"" << modelName; << 171 G4cout << "Model \"" << modelName; 195 if (activate) G4warn << "\" activated."; << 172 if (activate) G4cout << "\" activated."; 196 else G4warn << "\" de-activated."; << 173 else G4cout << "\" de-activated."; 197 G4warn << G4endl; << 174 G4cout << G4endl; 198 } 175 } 199 } 176 } 200 } 177 } 201 178 202 if (!any) { 179 if (!any) { 203 if (verbosity >= G4VisManager::warnings) { 180 if (verbosity >= G4VisManager::warnings) { 204 G4warn << "WARNING: No match found." << << 181 G4cout << "WARNING: No match found." << G4endl; 205 } 182 } 206 return; 183 return; 207 } 184 } 208 185 209 CheckSceneAndNotifyHandlers (pScene); 186 CheckSceneAndNotifyHandlers (pScene); 210 } 187 } 211 188 212 ////////////// /vis/scene/create ///////////// 189 ////////////// /vis/scene/create /////////////////////////////////////// 213 190 214 G4VisCommandSceneCreate::G4VisCommandSceneCrea 191 G4VisCommandSceneCreate::G4VisCommandSceneCreate (): fId (0) { 215 G4bool omitable; 192 G4bool omitable; 216 fpCommand = new G4UIcmdWithAString ("/vis/sc 193 fpCommand = new G4UIcmdWithAString ("/vis/scene/create", this); 217 fpCommand -> SetGuidance 194 fpCommand -> SetGuidance 218 ("Creates an empty scene."); 195 ("Creates an empty scene."); 219 fpCommand -> SetGuidance 196 fpCommand -> SetGuidance 220 ("Invents a name if not supplied. This sc 197 ("Invents a name if not supplied. This scene becomes current."); 221 fpCommand -> SetParameterName ("scene-name", 198 fpCommand -> SetParameterName ("scene-name", omitable = true); 222 } 199 } 223 200 224 G4VisCommandSceneCreate::~G4VisCommandSceneCre 201 G4VisCommandSceneCreate::~G4VisCommandSceneCreate () { 225 delete fpCommand; 202 delete fpCommand; 226 } 203 } 227 204 228 G4String G4VisCommandSceneCreate::NextName () 205 G4String G4VisCommandSceneCreate::NextName () { 229 std::ostringstream oss; 206 std::ostringstream oss; 230 oss << "scene-" << fId; 207 oss << "scene-" << fId; 231 return oss.str(); 208 return oss.str(); 232 } 209 } 233 210 234 G4String G4VisCommandSceneCreate::GetCurrentVa 211 G4String G4VisCommandSceneCreate::GetCurrentValue (G4UIcommand*) { 235 return ""; 212 return ""; 236 } 213 } 237 214 238 void G4VisCommandSceneCreate::SetNewValue (G4U 215 void G4VisCommandSceneCreate::SetNewValue (G4UIcommand*, G4String newValue) { 239 216 240 G4VisManager::Verbosity verbosity = fpVisMan 217 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); 241 218 242 G4String& newName = newValue; 219 G4String& newName = newValue; 243 G4String nextName = NextName (); 220 G4String nextName = NextName (); 244 221 245 if (newName == "") { 222 if (newName == "") { 246 newName = nextName; 223 newName = nextName; 247 } 224 } 248 if (newName == nextName) fId++; 225 if (newName == nextName) fId++; 249 226 250 G4SceneList& sceneList = fpVisManager -> Set 227 G4SceneList& sceneList = fpVisManager -> SetSceneList (); 251 std::size_t iScene, nScenes = sceneList.size << 228 G4int iScene, nScenes = sceneList.size (); 252 for (iScene = 0; iScene < nScenes; ++iScene) << 229 for (iScene = 0; iScene < nScenes; iScene++) { 253 if (sceneList [iScene] -> GetName () == ne 230 if (sceneList [iScene] -> GetName () == newName) break; 254 } 231 } 255 if (iScene < nScenes) { 232 if (iScene < nScenes) { 256 if (verbosity >= G4VisManager::warnings) { 233 if (verbosity >= G4VisManager::warnings) { 257 G4warn << "WARNING: Scene \"" << newName << 234 G4cout << "WARNING: Scene \"" << newName << "\" already exists." 258 << "\n New scene not created." 235 << "\n New scene not created." 259 << G4endl; 236 << G4endl; 260 } 237 } 261 } else { 238 } else { 262 239 263 // Add empty scene data object to list... 240 // Add empty scene data object to list... 264 G4Scene* pScene = new G4Scene (newName); 241 G4Scene* pScene = new G4Scene (newName); 265 sceneList.push_back (pScene); 242 sceneList.push_back (pScene); 266 fpVisManager -> SetCurrentScene (pScene); 243 fpVisManager -> SetCurrentScene (pScene); 267 244 268 if (verbosity >= G4VisManager::confirmatio 245 if (verbosity >= G4VisManager::confirmations) { 269 G4cout << "New empty scene \"" << newNam 246 G4cout << "New empty scene \"" << newName << "\" created." << G4endl; 270 } 247 } 271 } 248 } 272 } 249 } 273 250 274 ////////////// /vis/scene/endOfEventAction /// 251 ////////////// /vis/scene/endOfEventAction //////////////////////////// 275 252 276 G4VisCommandSceneEndOfEventAction::G4VisComman 253 G4VisCommandSceneEndOfEventAction::G4VisCommandSceneEndOfEventAction () { 277 G4bool omitable; 254 G4bool omitable; 278 fpCommand = new G4UIcommand ("/vis/scene/end 255 fpCommand = new G4UIcommand ("/vis/scene/endOfEventAction", this); 279 fpCommand -> SetGuidance 256 fpCommand -> SetGuidance 280 ("Accumulate or refresh the viewer for eac 257 ("Accumulate or refresh the viewer for each new event."); 281 fpCommand -> SetGuidance 258 fpCommand -> SetGuidance 282 ("\"accumulate\": viewer accumulates hits, 259 ("\"accumulate\": viewer accumulates hits, etc., event by event, or"); 283 fpCommand -> SetGuidance 260 fpCommand -> SetGuidance 284 ("\"refresh\": viewer shows them at end of 261 ("\"refresh\": viewer shows them at end of event or, for direct-screen" 285 "\n viewers, refreshes the screen just b 262 "\n viewers, refreshes the screen just before drawing the next event."); 286 G4UIparameter* parameter; 263 G4UIparameter* parameter; 287 parameter = new G4UIparameter ("action", 's' 264 parameter = new G4UIparameter ("action", 's', omitable = true); 288 parameter -> SetParameterCandidates ("accumu 265 parameter -> SetParameterCandidates ("accumulate refresh"); 289 parameter -> SetDefaultValue ("refresh"); 266 parameter -> SetDefaultValue ("refresh"); 290 fpCommand -> SetParameter (parameter); 267 fpCommand -> SetParameter (parameter); 291 parameter = new G4UIparameter ("maxNumber", 268 parameter = new G4UIparameter ("maxNumber", 'i', omitable = true); 292 parameter -> SetDefaultValue (100); 269 parameter -> SetDefaultValue (100); 293 parameter -> SetGuidance 270 parameter -> SetGuidance 294 ("Maximum number of events kept. Unlimited 271 ("Maximum number of events kept. Unlimited if negative."); 295 fpCommand -> SetParameter (parameter); 272 fpCommand -> SetParameter (parameter); 296 } 273 } 297 274 298 G4VisCommandSceneEndOfEventAction::~G4VisComma 275 G4VisCommandSceneEndOfEventAction::~G4VisCommandSceneEndOfEventAction () { 299 delete fpCommand; 276 delete fpCommand; 300 } 277 } 301 278 302 G4String G4VisCommandSceneEndOfEventAction::Ge 279 G4String G4VisCommandSceneEndOfEventAction::GetCurrentValue(G4UIcommand*) { 303 return ""; 280 return ""; 304 } 281 } 305 282 306 void G4VisCommandSceneEndOfEventAction::SetNew 283 void G4VisCommandSceneEndOfEventAction::SetNewValue (G4UIcommand*, 307 G4String newValue) { 284 G4String newValue) { 308 285 309 G4VisManager::Verbosity verbosity = fpVisMan 286 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); 310 287 311 G4String action; 288 G4String action; 312 G4int maxNumberOfKeptEvents; 289 G4int maxNumberOfKeptEvents; 313 std::istringstream is (newValue); 290 std::istringstream is (newValue); 314 is >> action >> maxNumberOfKeptEvents; 291 is >> action >> maxNumberOfKeptEvents; 315 292 316 G4Scene* pScene = fpVisManager->GetCurrentSc 293 G4Scene* pScene = fpVisManager->GetCurrentScene(); 317 if (!pScene) { 294 if (!pScene) { 318 if (verbosity >= G4VisManager::errors) { 295 if (verbosity >= G4VisManager::errors) { 319 G4warn << "ERROR: No current scene. Ple << 296 G4cerr << "ERROR: No current scene. Please create one." << G4endl; 320 } 297 } 321 return; 298 return; 322 } 299 } 323 300 324 G4VSceneHandler* pSceneHandler = fpVisManage 301 G4VSceneHandler* pSceneHandler = fpVisManager->GetCurrentSceneHandler(); 325 if (!pSceneHandler) { 302 if (!pSceneHandler) { 326 if (verbosity >= G4VisManager::errors) { 303 if (verbosity >= G4VisManager::errors) { 327 G4warn << "ERROR: No current sceneHandle << 304 G4cerr << "ERROR: No current sceneHandler. Please create one." << G4endl; 328 } 305 } 329 return; 306 return; 330 } 307 } 331 308 332 if (action == "accumulate") { 309 if (action == "accumulate") { 333 pScene->SetRefreshAtEndOfEvent(false); 310 pScene->SetRefreshAtEndOfEvent(false); 334 pScene->SetMaxNumberOfKeptEvents(maxNumber 311 pScene->SetMaxNumberOfKeptEvents(maxNumberOfKeptEvents); 335 } 312 } 336 else if (action == "refresh") { 313 else if (action == "refresh") { 337 if (!pScene->GetRefreshAtEndOfRun()) { 314 if (!pScene->GetRefreshAtEndOfRun()) { 338 if (verbosity >= G4VisManager::errors) { 315 if (verbosity >= G4VisManager::errors) { 339 G4warn << << 316 G4cerr << 340 "ERROR: Cannot refresh events unless runs 317 "ERROR: Cannot refresh events unless runs refresh too." 341 "\n Use \"/vis/scene/endOfRun refresh\"." 318 "\n Use \"/vis/scene/endOfRun refresh\"." 342 << G4endl; 319 << G4endl; 343 } 320 } 344 } else { 321 } else { 345 pScene->SetRefreshAtEndOfEvent(true); 322 pScene->SetRefreshAtEndOfEvent(true); 346 pScene->SetMaxNumberOfKeptEvents(maxNumb 323 pScene->SetMaxNumberOfKeptEvents(maxNumberOfKeptEvents); 347 pSceneHandler->SetMarkForClearingTransie 324 pSceneHandler->SetMarkForClearingTransientStore(true); 348 } 325 } 349 } 326 } 350 else { 327 else { 351 if (verbosity >= G4VisManager::errors) { 328 if (verbosity >= G4VisManager::errors) { 352 G4warn << << 329 G4cerr << 353 "ERROR: unrecognised parameter \"" << action 330 "ERROR: unrecognised parameter \"" << action << "\"." 354 << G4endl; 331 << G4endl; 355 } 332 } 356 return; 333 return; 357 } 334 } 358 335 359 // Change of transients behaviour, so... 336 // Change of transients behaviour, so... 360 fpVisManager->ResetTransientsDrawnFlags(); 337 fpVisManager->ResetTransientsDrawnFlags(); 361 338 362 // Are there any events currently kept... 339 // Are there any events currently kept... 363 size_t nCurrentlyKept = 0; 340 size_t nCurrentlyKept = 0; 364 G4RunManager* runManager = G4RunManagerFacto 341 G4RunManager* runManager = G4RunManagerFactory::GetMasterRunManager(); 365 if(runManager) 342 if(runManager) 366 { 343 { 367 const G4Run* currentRun = runManager->GetC 344 const G4Run* currentRun = runManager->GetCurrentRun(); 368 if(currentRun) 345 if(currentRun) 369 { 346 { 370 const std::vector<const G4Event*>* event 347 const std::vector<const G4Event*>* events = currentRun->GetEventVector(); 371 if(events) 348 if(events) 372 nCurrentlyKept = events->size(); 349 nCurrentlyKept = events->size(); 373 } 350 } 374 } 351 } 375 352 376 if (verbosity >= G4VisManager::confirmations 353 if (verbosity >= G4VisManager::confirmations) { 377 G4cout << "End of event action set to "; 354 G4cout << "End of event action set to "; 378 if (pScene->GetRefreshAtEndOfEvent()) G4co 355 if (pScene->GetRefreshAtEndOfEvent()) G4cout << "\"refresh\"."; 379 else { 356 else { 380 G4cout << "\"accumulate\"." 357 G4cout << "\"accumulate\"." 381 "\n Maximum number of events to be kept: " 358 "\n Maximum number of events to be kept: " 382 << maxNumberOfKeptEvents 359 << maxNumberOfKeptEvents 383 << " (unlimited if negative)." 360 << " (unlimited if negative)." 384 "\n This may be changed with, e.g., " 361 "\n This may be changed with, e.g., " 385 "\"/vis/scene/endOfEventAction accumulate 10 362 "\"/vis/scene/endOfEventAction accumulate 1000\"."; 386 } 363 } 387 G4cout << G4endl; 364 G4cout << G4endl; 388 } 365 } 389 366 390 if (!pScene->GetRefreshAtEndOfEvent() && 367 if (!pScene->GetRefreshAtEndOfEvent() && 391 maxNumberOfKeptEvents != 0 && 368 maxNumberOfKeptEvents != 0 && 392 verbosity >= G4VisManager::warnings) { 369 verbosity >= G4VisManager::warnings) { 393 G4warn << "WARNING: "; << 370 G4cout << "WARNING: "; 394 if (nCurrentlyKept) { 371 if (nCurrentlyKept) { 395 G4warn << << 372 G4cout << 396 "\n There are currently " << nCurrentlyKept 373 "\n There are currently " << nCurrentlyKept 397 << " events kept for refreshing and/or 374 << " events kept for refreshing and/or reviewing."; 398 } else { 375 } else { 399 G4warn << "The vis manager will keep "; << 376 G4cout << "The vis manager will keep "; 400 if (maxNumberOfKeptEvents < 0) G4warn << << 377 if (maxNumberOfKeptEvents < 0) G4cout << "an unlimited number of"; 401 else G4warn << "up to " << maxNumberOfKe << 378 else G4cout << "up to " << maxNumberOfKeptEvents; 402 G4warn << " events."; << 379 G4cout << " events."; 403 if (maxNumberOfKeptEvents > 1 || maxNumb 380 if (maxNumberOfKeptEvents > 1 || maxNumberOfKeptEvents < 0) 404 G4warn << << 381 G4cout << 405 "\n This may use a lot of memory." 382 "\n This may use a lot of memory." 406 "\n It may be changed with, e.g., " 383 "\n It may be changed with, e.g., " 407 "\"/vis/scene/endOfEventAction accumulate 384 "\"/vis/scene/endOfEventAction accumulate 10\"."; 408 } 385 } 409 G4warn << G4endl; << 386 G4cout << G4endl; 410 } 387 } 411 } 388 } 412 389 413 ////////////// /vis/scene/endOfRunAction ///// 390 ////////////// /vis/scene/endOfRunAction //////////////////////////// 414 391 415 G4VisCommandSceneEndOfRunAction::G4VisCommandS 392 G4VisCommandSceneEndOfRunAction::G4VisCommandSceneEndOfRunAction () { 416 G4bool omitable; 393 G4bool omitable; 417 fpCommand = new G4UIcmdWithAString ("/vis/sc 394 fpCommand = new G4UIcmdWithAString ("/vis/scene/endOfRunAction", this); 418 fpCommand -> SetGuidance 395 fpCommand -> SetGuidance 419 ("Accumulate or refresh the viewer for eac 396 ("Accumulate or refresh the viewer for each new run."); 420 fpCommand -> SetGuidance 397 fpCommand -> SetGuidance 421 ("\"accumulate\": viewer accumulates hits, 398 ("\"accumulate\": viewer accumulates hits, etc., run by run, or"); 422 fpCommand -> SetGuidance 399 fpCommand -> SetGuidance 423 ("\"refresh\": viewer shows them at end of 400 ("\"refresh\": viewer shows them at end of run or, for direct-screen" 424 "\n viewers, refreshes the screen just b 401 "\n viewers, refreshes the screen just before drawing the first" 425 "\n event of the next run."); 402 "\n event of the next run."); 426 fpCommand -> SetGuidance ("The detector rema 403 fpCommand -> SetGuidance ("The detector remains or is redrawn."); 427 fpCommand -> SetParameterName ("action", omi 404 fpCommand -> SetParameterName ("action", omitable = true); 428 fpCommand -> SetCandidates ("accumulate refr 405 fpCommand -> SetCandidates ("accumulate refresh"); 429 fpCommand -> SetDefaultValue ("refresh"); 406 fpCommand -> SetDefaultValue ("refresh"); 430 } 407 } 431 408 432 G4VisCommandSceneEndOfRunAction::~G4VisCommand 409 G4VisCommandSceneEndOfRunAction::~G4VisCommandSceneEndOfRunAction () { 433 delete fpCommand; 410 delete fpCommand; 434 } 411 } 435 412 436 G4String G4VisCommandSceneEndOfRunAction::GetC 413 G4String G4VisCommandSceneEndOfRunAction::GetCurrentValue(G4UIcommand*) { 437 return ""; 414 return ""; 438 } 415 } 439 416 440 void G4VisCommandSceneEndOfRunAction::SetNewVa 417 void G4VisCommandSceneEndOfRunAction::SetNewValue (G4UIcommand*, 441 G4String newValue) { 418 G4String newValue) { 442 419 443 G4VisManager::Verbosity verbosity = fpVisMan 420 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); 444 421 445 G4String action; 422 G4String action; 446 std::istringstream is (newValue); 423 std::istringstream is (newValue); 447 is >> action; 424 is >> action; 448 425 449 G4Scene* pScene = fpVisManager->GetCurrentSc 426 G4Scene* pScene = fpVisManager->GetCurrentScene(); 450 if (!pScene) { 427 if (!pScene) { 451 if (verbosity >= G4VisManager::errors) { 428 if (verbosity >= G4VisManager::errors) { 452 G4warn << "ERROR: No current scene. Ple << 429 G4cerr << "ERROR: No current scene. Please create one." << G4endl; 453 } 430 } 454 return; 431 return; 455 } 432 } 456 433 457 G4VSceneHandler* pSceneHandler = fpVisManage 434 G4VSceneHandler* pSceneHandler = fpVisManager->GetCurrentSceneHandler(); 458 if (!pSceneHandler) { 435 if (!pSceneHandler) { 459 if (verbosity >= G4VisManager::errors) { 436 if (verbosity >= G4VisManager::errors) { 460 G4warn << "ERROR: No current sceneHandle << 437 G4cerr << "ERROR: No current sceneHandler. Please create one." << G4endl; 461 } 438 } 462 return; 439 return; 463 } 440 } 464 441 465 if (action == "accumulate") { 442 if (action == "accumulate") { 466 if (pScene->GetRefreshAtEndOfEvent()) { 443 if (pScene->GetRefreshAtEndOfEvent()) { 467 if (verbosity >= G4VisManager::errors) { 444 if (verbosity >= G4VisManager::errors) { 468 G4warn << << 445 G4cerr << 469 "ERROR: Cannot accumulate runs unless even 446 "ERROR: Cannot accumulate runs unless events accumulate too." 470 "\n Use \"/vis/scene/endOfEventAction acc 447 "\n Use \"/vis/scene/endOfEventAction accumulate\"." 471 << G4endl; 448 << G4endl; 472 } 449 } 473 } 450 } 474 else { 451 else { 475 pScene->SetRefreshAtEndOfRun(false); 452 pScene->SetRefreshAtEndOfRun(false); 476 } 453 } 477 } 454 } 478 else if (action == "refresh") { 455 else if (action == "refresh") { 479 pScene->SetRefreshAtEndOfRun(true); 456 pScene->SetRefreshAtEndOfRun(true); 480 pSceneHandler->SetMarkForClearingTransient 457 pSceneHandler->SetMarkForClearingTransientStore(true); 481 } 458 } 482 else { 459 else { 483 if (verbosity >= G4VisManager::errors) { 460 if (verbosity >= G4VisManager::errors) { 484 G4warn << << 461 G4cerr << 485 "ERROR: unrecognised parameter \"" << action 462 "ERROR: unrecognised parameter \"" << action << "\"." 486 << G4endl; 463 << G4endl; 487 } 464 } 488 return; 465 return; 489 } 466 } 490 467 491 // Change of transients behaviour, so... 468 // Change of transients behaviour, so... 492 fpVisManager->ResetTransientsDrawnFlags(); 469 fpVisManager->ResetTransientsDrawnFlags(); 493 470 494 if (verbosity >= G4VisManager::confirmations 471 if (verbosity >= G4VisManager::confirmations) { 495 G4cout << "End of run action set to \""; 472 G4cout << "End of run action set to \""; 496 if (pScene->GetRefreshAtEndOfRun()) G4cout 473 if (pScene->GetRefreshAtEndOfRun()) G4cout << "refresh"; 497 else G4cout << "accumulate"; 474 else G4cout << "accumulate"; 498 G4cout << "\"" << G4endl; 475 G4cout << "\"" << G4endl; 499 } 476 } 500 } 477 } 501 478 502 ////////////// /vis/scene/list /////////////// 479 ////////////// /vis/scene/list /////////////////////////////////////// 503 480 504 G4VisCommandSceneList::G4VisCommandSceneList ( 481 G4VisCommandSceneList::G4VisCommandSceneList () { 505 G4bool omitable; 482 G4bool omitable; 506 fpCommand = new G4UIcommand ("/vis/scene/lis 483 fpCommand = new G4UIcommand ("/vis/scene/list", this); 507 fpCommand -> SetGuidance ("Lists scene(s).") 484 fpCommand -> SetGuidance ("Lists scene(s)."); 508 fpCommand -> SetGuidance 485 fpCommand -> SetGuidance 509 ("\"help /vis/verbose\" for definition of 486 ("\"help /vis/verbose\" for definition of verbosity."); 510 G4UIparameter* parameter; 487 G4UIparameter* parameter; 511 parameter = new G4UIparameter ("scene-name", 488 parameter = new G4UIparameter ("scene-name", 's', omitable = true); 512 parameter -> SetDefaultValue ("all"); 489 parameter -> SetDefaultValue ("all"); 513 fpCommand -> SetParameter (parameter); 490 fpCommand -> SetParameter (parameter); 514 parameter = new G4UIparameter ("verbosity", 491 parameter = new G4UIparameter ("verbosity", 's', omitable = true); 515 parameter -> SetDefaultValue ("warnings"); 492 parameter -> SetDefaultValue ("warnings"); 516 fpCommand -> SetParameter (parameter); 493 fpCommand -> SetParameter (parameter); 517 } 494 } 518 495 519 G4VisCommandSceneList::~G4VisCommandSceneList 496 G4VisCommandSceneList::~G4VisCommandSceneList () { 520 delete fpCommand; 497 delete fpCommand; 521 } 498 } 522 499 523 G4String G4VisCommandSceneList::GetCurrentValu 500 G4String G4VisCommandSceneList::GetCurrentValue (G4UIcommand*) { 524 return ""; 501 return ""; 525 } 502 } 526 503 527 void G4VisCommandSceneList::SetNewValue (G4UIc 504 void G4VisCommandSceneList::SetNewValue (G4UIcommand*, G4String newValue) { 528 G4String name, verbosityString; 505 G4String name, verbosityString; 529 std::istringstream is (newValue); 506 std::istringstream is (newValue); 530 is >> name >> verbosityString; 507 is >> name >> verbosityString; 531 G4VisManager::Verbosity verbosity = 508 G4VisManager::Verbosity verbosity = 532 fpVisManager->GetVerbosityValue(verbosityS 509 fpVisManager->GetVerbosityValue(verbosityString); 533 const G4Scene* currentScene = fpVisManager - 510 const G4Scene* currentScene = fpVisManager -> GetCurrentScene (); 534 G4String currentName; 511 G4String currentName; 535 if (currentScene) currentName = currentScene 512 if (currentScene) currentName = currentScene->GetName(); 536 513 537 G4SceneList& sceneList = fpVisManager -> Set 514 G4SceneList& sceneList = fpVisManager -> SetSceneList (); 538 std::size_t iScene, nScenes = sceneList.size << 515 G4int iScene, nScenes = sceneList.size (); 539 G4bool found = false; 516 G4bool found = false; 540 for (iScene = 0; iScene < nScenes; ++iScene) << 517 for (iScene = 0; iScene < nScenes; iScene++) { 541 G4Scene* pScene = sceneList [iScene]; 518 G4Scene* pScene = sceneList [iScene]; 542 const G4String& iName = pScene -> GetName 519 const G4String& iName = pScene -> GetName (); 543 if (name != "all") { 520 if (name != "all") { 544 if (name != iName) continue; 521 if (name != iName) continue; 545 } 522 } 546 found = true; 523 found = true; 547 if (iName == currentName) { 524 if (iName == currentName) { 548 G4cout << " (current)"; 525 G4cout << " (current)"; 549 } 526 } 550 else { 527 else { 551 G4cout << " "; 528 G4cout << " "; 552 } 529 } 553 G4cout << " scene \"" << iName << "\""; 530 G4cout << " scene \"" << iName << "\""; 554 if (verbosity >= G4VisManager::warnings) { 531 if (verbosity >= G4VisManager::warnings) { 555 std::size_t i; << 532 G4int i; 556 G4cout << "\n Run-duration models:"; 533 G4cout << "\n Run-duration models:"; 557 std::size_t nRunModels = pScene -> GetRu << 534 G4int nRunModels = pScene -> GetRunDurationModelList ().size (); 558 if (nRunModels == 0) { 535 if (nRunModels == 0) { 559 G4cout << " none."; 536 G4cout << " none."; 560 } 537 } 561 for (i = 0; i < nRunModels; ++i) { << 538 for (i = 0; i < nRunModels; i++) { 562 if (pScene -> GetRunDurationModelList()[i].f 539 if (pScene -> GetRunDurationModelList()[i].fActive) 563 G4cout << "\n Active: "; 540 G4cout << "\n Active: "; 564 else G4cout << "\n Inactive: "; 541 else G4cout << "\n Inactive: "; 565 G4VModel* pModel = pScene -> GetRunDurationM 542 G4VModel* pModel = pScene -> GetRunDurationModelList()[i].fpModel; 566 G4cout << pModel -> GetGlobalDescription (); 543 G4cout << pModel -> GetGlobalDescription (); 567 } 544 } 568 G4cout << "\n End-of-event models:"; 545 G4cout << "\n End-of-event models:"; 569 std::size_t nEOEModels = pScene -> GetEn << 546 G4int nEOEModels = pScene -> GetEndOfEventModelList ().size (); 570 if (nEOEModels == 0) { 547 if (nEOEModels == 0) { 571 G4cout << " none."; 548 G4cout << " none."; 572 } 549 } 573 for (i = 0; i < nEOEModels; ++i) { << 550 for (i = 0; i < nEOEModels; i++) { 574 if (pScene -> GetEndOfEventModelList()[i].fA 551 if (pScene -> GetEndOfEventModelList()[i].fActive) 575 G4cout << "\n Active: "; 552 G4cout << "\n Active: "; 576 else G4cout << "\n Inactive: "; 553 else G4cout << "\n Inactive: "; 577 G4VModel* pModel = pScene -> GetEndOfEventMo 554 G4VModel* pModel = pScene -> GetEndOfEventModelList()[i].fpModel; 578 G4cout << pModel -> GetGlobalDescription (); 555 G4cout << pModel -> GetGlobalDescription (); 579 } 556 } 580 G4cout << "\n End-of-run models:"; 557 G4cout << "\n End-of-run models:"; 581 std::size_t nEORModels = pScene -> GetEn << 558 G4int nEORModels = pScene -> GetEndOfRunModelList ().size (); 582 if (nEORModels == 0) { 559 if (nEORModels == 0) { 583 G4cout << " none."; 560 G4cout << " none."; 584 } 561 } 585 for (i = 0; i < nEORModels; ++i) { << 562 for (i = 0; i < nEORModels; i++) { 586 if (pScene -> GetEndOfRunModelList()[i].fAct 563 if (pScene -> GetEndOfRunModelList()[i].fActive) 587 G4cout << "\n Active: "; 564 G4cout << "\n Active: "; 588 else G4cout << "\n Inactive: "; 565 else G4cout << "\n Inactive: "; 589 G4VModel* pModel = pScene -> GetEndOfRunMode 566 G4VModel* pModel = pScene -> GetEndOfRunModelList()[i].fpModel; 590 G4cout << pModel -> GetGlobalDescription (); 567 G4cout << pModel -> GetGlobalDescription (); 591 } 568 } 592 } 569 } 593 if (verbosity >= G4VisManager::parameters) 570 if (verbosity >= G4VisManager::parameters) { 594 G4cout << "\n " << *sceneList [iScene]; 571 G4cout << "\n " << *sceneList [iScene]; 595 } 572 } 596 G4cout << G4endl; 573 G4cout << G4endl; 597 } 574 } 598 if (!found) { 575 if (!found) { 599 G4warn << "No scenes found"; << 576 G4cout << "No scenes found"; 600 if (name != "all") { 577 if (name != "all") { 601 G4warn << " of name \"" << name << "\""; << 578 G4cout << " of name \"" << name << "\""; 602 } 579 } 603 G4warn << "." << G4endl; << 580 G4cout << "." << G4endl; 604 } 581 } 605 } 582 } 606 583 607 ////////////// /vis/scene/notifyHandlers ///// 584 ////////////// /vis/scene/notifyHandlers ///////////////////////// 608 585 609 G4VisCommandSceneNotifyHandlers::G4VisCommandS 586 G4VisCommandSceneNotifyHandlers::G4VisCommandSceneNotifyHandlers () { 610 G4bool omitable; 587 G4bool omitable; 611 fpCommand = new G4UIcommand ("/vis/scene/not 588 fpCommand = new G4UIcommand ("/vis/scene/notifyHandlers", this); 612 fpCommand -> SetGuidance 589 fpCommand -> SetGuidance 613 ("Notifies scene handlers and forces re-re 590 ("Notifies scene handlers and forces re-rendering."); 614 fpCommand -> SetGuidance 591 fpCommand -> SetGuidance 615 ("Notifies the handler(s) of the specified 592 ("Notifies the handler(s) of the specified scene and forces a" 616 "\nreconstruction of any graphical databa 593 "\nreconstruction of any graphical databases." 617 "\nClears and refreshes all viewers of cu 594 "\nClears and refreshes all viewers of current scene." 618 "\n The default action \"refresh\" does 595 "\n The default action \"refresh\" does not issue \"update\" (see" 619 "\n /vis/viewer/update)." 596 "\n /vis/viewer/update)." 620 "\nIf \"flush\" is specified, it issues a 597 "\nIf \"flush\" is specified, it issues an \"update\" as well as" 621 "\n \"refresh\" - \"update\" and initiat 598 "\n \"refresh\" - \"update\" and initiates post-processing" 622 "\n for graphics systems which need it." 599 "\n for graphics systems which need it."); 623 fpCommand -> SetGuidance 600 fpCommand -> SetGuidance 624 ("The default for <scene-name> is the curr 601 ("The default for <scene-name> is the current scene name."); 625 fpCommand -> SetGuidance 602 fpCommand -> SetGuidance 626 ("This command does not change current sce 603 ("This command does not change current scene, scene handler or viewer."); 627 G4UIparameter* parameter; 604 G4UIparameter* parameter; 628 parameter = new G4UIparameter ("scene-name", 605 parameter = new G4UIparameter ("scene-name", 's', 629 omitable = true); 606 omitable = true); 630 parameter -> SetCurrentAsDefault(true); 607 parameter -> SetCurrentAsDefault(true); 631 fpCommand -> SetParameter (parameter); 608 fpCommand -> SetParameter (parameter); 632 parameter = new G4UIparameter ("refresh-flus 609 parameter = new G4UIparameter ("refresh-flush", 's', 633 omitable = true); 610 omitable = true); 634 parameter -> SetDefaultValue("refresh"); 611 parameter -> SetDefaultValue("refresh"); 635 parameter -> SetParameterCandidates("r refre 612 parameter -> SetParameterCandidates("r refresh f flush"); 636 fpCommand -> SetParameter (parameter); 613 fpCommand -> SetParameter (parameter); 637 } 614 } 638 615 639 G4VisCommandSceneNotifyHandlers::~G4VisCommand 616 G4VisCommandSceneNotifyHandlers::~G4VisCommandSceneNotifyHandlers () { 640 delete fpCommand; 617 delete fpCommand; 641 } 618 } 642 619 643 G4String G4VisCommandSceneNotifyHandlers::GetC 620 G4String G4VisCommandSceneNotifyHandlers::GetCurrentValue(G4UIcommand*) { 644 return CurrentSceneName (); 621 return CurrentSceneName (); 645 } 622 } 646 623 647 void G4VisCommandSceneNotifyHandlers::SetNewVa 624 void G4VisCommandSceneNotifyHandlers::SetNewValue (G4UIcommand*, 648 G4String newValue) { 625 G4String newValue) { 649 626 650 G4VisManager::Verbosity verbosity = fpVisMan 627 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); 651 628 652 G4String sceneName, refresh_flush; 629 G4String sceneName, refresh_flush; 653 std::istringstream is (newValue); 630 std::istringstream is (newValue); 654 is >> sceneName >> refresh_flush; 631 is >> sceneName >> refresh_flush; 655 G4bool flush = false; 632 G4bool flush = false; 656 if (refresh_flush[0] == 'f') flush = true; << 633 if (refresh_flush(0) == 'f') flush = true; 657 634 658 const G4SceneList& sceneList = fpVisManager 635 const G4SceneList& sceneList = fpVisManager -> GetSceneList (); 659 G4SceneHandlerList& sceneHandlerList = 636 G4SceneHandlerList& sceneHandlerList = 660 fpVisManager -> SetAvailableSceneHandlers 637 fpVisManager -> SetAvailableSceneHandlers (); 661 638 662 // Check scene name. 639 // Check scene name. 663 const std::size_t nScenes = sceneList.size ( << 640 const G4int nScenes = sceneList.size (); 664 std::size_t iScene; << 641 G4int iScene; 665 for (iScene = 0; iScene < nScenes; ++iScene) << 642 for (iScene = 0; iScene < nScenes; iScene++) { 666 G4Scene* scene = sceneList [iScene]; 643 G4Scene* scene = sceneList [iScene]; 667 if (sceneName == scene -> GetName ()) brea 644 if (sceneName == scene -> GetName ()) break; 668 } 645 } 669 if (iScene >= nScenes ) { 646 if (iScene >= nScenes ) { 670 if (verbosity >= G4VisManager::warnings) { 647 if (verbosity >= G4VisManager::warnings) { 671 G4warn << "WARNING: Scene \"" << sceneNa << 648 G4cout << "WARNING: Scene \"" << sceneName << "\" not found." 672 "\n /vis/scene/list to see scenes." 649 "\n /vis/scene/list to see scenes." 673 << G4endl; 650 << G4endl; 674 } 651 } 675 return; 652 return; 676 } 653 } 677 654 678 // Store current context... 655 // Store current context... 679 G4VSceneHandler* pCurrentSceneHandler = 656 G4VSceneHandler* pCurrentSceneHandler = 680 fpVisManager -> GetCurrentSceneHandler(); 657 fpVisManager -> GetCurrentSceneHandler(); 681 if (!pCurrentSceneHandler) { 658 if (!pCurrentSceneHandler) { 682 if (verbosity >= G4VisManager::warnings) { 659 if (verbosity >= G4VisManager::warnings) { 683 G4warn << "WARNING: No current scene han << 660 G4cout << "WARNING: No current scene handler." 684 << G4endl; 661 << G4endl; 685 } 662 } 686 return; 663 return; 687 } 664 } 688 G4VViewer* pCurrentViewer = fpVisManager -> 665 G4VViewer* pCurrentViewer = fpVisManager -> GetCurrentViewer(); 689 if (!pCurrentViewer) { 666 if (!pCurrentViewer) { 690 if (verbosity >= G4VisManager::warnings) { 667 if (verbosity >= G4VisManager::warnings) { 691 G4warn << "WARNING: No current viewer." << 668 G4cout << "WARNING: No current viewer." 692 << G4endl; 669 << G4endl; 693 } 670 } 694 return; 671 return; 695 } 672 } 696 G4Scene* pCurrentScene = fpVisManager -> Get 673 G4Scene* pCurrentScene = fpVisManager -> GetCurrentScene(); 697 if (!pCurrentScene) { 674 if (!pCurrentScene) { 698 if (verbosity >= G4VisManager::warnings) { 675 if (verbosity >= G4VisManager::warnings) { 699 G4warn << "WARNING: No current scene." << 676 G4cout << "WARNING: No current scene." 700 << G4endl; 677 << G4endl; 701 } 678 } 702 return; 679 return; 703 } 680 } 704 681 705 G4VisManager::Verbosity currentVerbosity = f 682 G4VisManager::Verbosity currentVerbosity = fpVisManager -> GetVerbosity(); 706 683 707 // Suppress messages during this process (on 684 // Suppress messages during this process (only print errors)... 708 //fpVisManager -> SetVerboseLevel(G4VisManag 685 //fpVisManager -> SetVerboseLevel(G4VisManager::errors); 709 686 710 // For each scene handler, if it contains th 687 // For each scene handler, if it contains the scene, clear and 711 // rebuild the graphical database, then for 688 // rebuild the graphical database, then for each viewer set (make 712 // current), clear, (re)draw, and show. 689 // current), clear, (re)draw, and show. 713 const std::size_t nSceneHandlers = sceneHand << 690 const G4int nSceneHandlers = sceneHandlerList.size (); 714 for (std::size_t iSH = 0; iSH < nSceneHandle << 691 for (G4int iSH = 0; iSH < nSceneHandlers; iSH++) { 715 G4VSceneHandler* aSceneHandler = sceneHand 692 G4VSceneHandler* aSceneHandler = sceneHandlerList [iSH]; 716 G4Scene* aScene = aSceneHandler -> GetScen 693 G4Scene* aScene = aSceneHandler -> GetScene (); 717 if (aScene) { 694 if (aScene) { 718 const G4String& aSceneName = aScene -> G 695 const G4String& aSceneName = aScene -> GetName (); 719 if (sceneName == aSceneName) { 696 if (sceneName == aSceneName) { 720 aScene->CalculateExtent(); // Check and rec 697 aScene->CalculateExtent(); // Check and recalculate extent 721 G4ViewerList& viewerList = aSceneHandler -> 698 G4ViewerList& viewerList = aSceneHandler -> SetViewerList (); 722 const std::size_t nViewers = viewerList.size << 699 const G4int nViewers = viewerList.size (); 723 for (std::size_t iV = 0; iV < nViewers; ++iV << 700 for (G4int iV = 0; iV < nViewers; iV++) { 724 G4VViewer* aViewer = viewerList [iV]; 701 G4VViewer* aViewer = viewerList [iV]; 725 // Force rebuild of graphical database, if 702 // Force rebuild of graphical database, if any. 726 aViewer -> NeedKernelVisit(); 703 aViewer -> NeedKernelVisit(); 727 if (aViewer->GetViewParameters().IsAutoRef 704 if (aViewer->GetViewParameters().IsAutoRefresh()) { 728 aSceneHandler -> SetCurrentViewer (aView 705 aSceneHandler -> SetCurrentViewer (aViewer); 729 // Ensure consistency of vis manager... 706 // Ensure consistency of vis manager... 730 fpVisManager -> SetCurrentViewer(aViewer 707 fpVisManager -> SetCurrentViewer(aViewer); 731 fpVisManager -> SetCurrentSceneHandler(a 708 fpVisManager -> SetCurrentSceneHandler(aSceneHandler); 732 fpVisManager -> SetCurrentScene(aScene); 709 fpVisManager -> SetCurrentScene(aScene); 733 aViewer -> SetView (); 710 aViewer -> SetView (); 734 aViewer -> ClearView (); 711 aViewer -> ClearView (); 735 aViewer -> DrawView (); 712 aViewer -> DrawView (); 736 if (flush) aViewer -> ShowView (); 713 if (flush) aViewer -> ShowView (); 737 if (verbosity >= G4VisManager::confirmat 714 if (verbosity >= G4VisManager::confirmations) { 738 G4cout << "Viewer \"" << aViewer -> Ge 715 G4cout << "Viewer \"" << aViewer -> GetName () 739 << "\" of scene handler \"" << aScene 716 << "\" of scene handler \"" << aSceneHandler -> GetName () 740 << "\"\n "; 717 << "\"\n "; 741 if (flush) G4cout << "flushed"; 718 if (flush) G4cout << "flushed"; 742 else G4cout << "refreshed"; 719 else G4cout << "refreshed"; 743 G4cout << " at request of scene \"" << 720 G4cout << " at request of scene \"" << sceneName 744 << "\"." << G4endl; 721 << "\"." << G4endl; 745 } 722 } 746 } else { 723 } else { 747 if (verbosity >= G4VisManager::confirmat 724 if (verbosity >= G4VisManager::confirmations) { 748 G4cout << "NOTE: The scene, \"" 725 G4cout << "NOTE: The scene, \"" 749 << sceneName 726 << sceneName 750 << "\", of viewer \"" 727 << "\", of viewer \"" 751 << aViewer -> GetName () 728 << aViewer -> GetName () 752 << "\"\n of scene handler \"" 729 << "\"\n of scene handler \"" 753 << aSceneHandler -> GetName () 730 << aSceneHandler -> GetName () 754 << "\" has changed. To see effect," 731 << "\" has changed. To see effect," 755 << "\n \"/vis/viewer/select " 732 << "\n \"/vis/viewer/select " 756 << aViewer -> GetShortName () 733 << aViewer -> GetShortName () 757 << "\" and \"/vis/viewer/rebuild\"." 734 << "\" and \"/vis/viewer/rebuild\"." 758 << G4endl; 735 << G4endl; 759 } 736 } 760 } 737 } 761 } 738 } 762 } 739 } 763 } 740 } 764 else { 741 else { 765 if (verbosity >= G4VisManager::warnings) 742 if (verbosity >= G4VisManager::warnings) { 766 G4warn << "WARNING: G4VisCommandSceneNotifyH << 743 G4cout << "WARNING: G4VisCommandSceneNotifyHandlers: scene handler \"" 767 << aSceneHandler->GetName() 744 << aSceneHandler->GetName() 768 << "\" has a null scene." 745 << "\" has a null scene." 769 << G4endl; 746 << G4endl; 770 } 747 } 771 } 748 } 772 } 749 } 773 750 774 // Reclaim original context - but set viewer 751 // Reclaim original context - but set viewer first, then scene 775 // handler, because the latter might have be 752 // handler, because the latter might have been created very recently 776 // and, not yet having a viewer, the current 753 // and, not yet having a viewer, the current viewer will, 777 // temporarily, refer to another scene handl 754 // temporarily, refer to another scene handler. SetCurrentViewer 778 // actually resets the scene handler, which 755 // actually resets the scene handler, which is what we don't want, 779 // so we set it again on the next line... 756 // so we set it again on the next line... 780 fpVisManager -> SetCurrentViewer(pCurrentVie 757 fpVisManager -> SetCurrentViewer(pCurrentViewer); 781 fpVisManager -> SetCurrentSceneHandler(pCurr 758 fpVisManager -> SetCurrentSceneHandler(pCurrentSceneHandler); 782 fpVisManager -> SetCurrentScene(pCurrentScen 759 fpVisManager -> SetCurrentScene(pCurrentScene); 783 fpVisManager -> SetVerboseLevel(currentVerbo 760 fpVisManager -> SetVerboseLevel(currentVerbosity); 784 // Take care of special case of scene handle 761 // Take care of special case of scene handler with no viewer yet. 785 if (pCurrentSceneHandler) { 762 if (pCurrentSceneHandler) { 786 G4ViewerList& viewerList = pCurrentSceneHa 763 G4ViewerList& viewerList = pCurrentSceneHandler -> SetViewerList (); 787 const std::size_t nViewers = viewerList.si << 764 const G4int nViewers = viewerList.size (); 788 if (nViewers) { 765 if (nViewers) { 789 pCurrentSceneHandler -> SetCurrentViewer 766 pCurrentSceneHandler -> SetCurrentViewer (pCurrentViewer); 790 // JA: I don't think we need this. SetVi 767 // JA: I don't think we need this. SetView will be called when needed. 791 // if (pCurrentViewer && pCurrentSceneHa 768 // if (pCurrentViewer && pCurrentSceneHandler->GetScene()) { 792 // pCurrentViewer -> SetView (); 769 // pCurrentViewer -> SetView (); 793 // } 770 // } 794 } 771 } 795 } 772 } 796 } 773 } 797 774 798 ////////////// /vis/scene/removeModel //////// << 799 << 800 G4VisCommandSceneRemoveModel::G4VisCommandScen << 801 G4bool omitable; << 802 fpCommand = new G4UIcommand ("/vis/scene/rem << 803 fpCommand -> SetGuidance("Remove model."); << 804 fpCommand -> SetGuidance << 805 ("Attempts to match search string to name of << 806 fpCommand -> SetGuidance << 807 ("Use \"/vis/scene/list\" to see model names << 808 G4UIparameter* parameter; << 809 parameter = new G4UIparameter ("search-strin << 810 fpCommand -> SetParameter (parameter); << 811 } << 812 << 813 G4VisCommandSceneRemoveModel::~G4VisCommandSce << 814 delete fpCommand; << 815 } << 816 << 817 G4String G4VisCommandSceneRemoveModel::GetCurr << 818 return ""; << 819 } << 820 << 821 void G4VisCommandSceneRemoveModel::SetNewValue << 822 G4String newValue) { << 823 << 824 G4VisManager::Verbosity verbosity = fpVisMan << 825 << 826 G4String searchString; << 827 std::istringstream is (newValue); << 828 is >> searchString; << 829 << 830 G4Scene* pScene = fpVisManager->GetCurrentSc << 831 if (!pScene) { << 832 if (verbosity >= G4VisManager::errors) { << 833 G4warn << "ERROR: No current scene. Ple << 834 } << 835 return; << 836 } << 837 << 838 G4VSceneHandler* pSceneHandler = fpVisManage << 839 if (!pSceneHandler) { << 840 if (verbosity >= G4VisManager::errors) { << 841 G4warn << "ERROR: No current sceneHandle << 842 } << 843 return; << 844 } << 845 << 846 G4bool any = false; << 847 << 848 std::vector<G4Scene::Model>& runDurationMode << 849 pScene->SetRunDurationModelList(); << 850 for (size_t i = 0; i < runDurationModelList. << 851 const G4String& modelName = << 852 runDurationModelList[i].fpModel->GetGlobal << 853 if (modelName.find(searchString) != std::s << 854 runDurationModelList.erase(runDurationMo << 855 any = true; << 856 if (verbosity >= G4VisManager::warnings) << 857 G4warn << "Model \"" << modelName << "\" rem << 858 } << 859 break; // Allow only one model at a tim << 860 } << 861 } << 862 << 863 std::vector<G4Scene::Model>& endOfEventModel << 864 pScene->SetEndOfEventModelList(); << 865 for (size_t i = 0; i < endOfEventModelList.s << 866 const G4String& modelName = << 867 endOfEventModelList[i].fpModel->GetGlobalD << 868 if (modelName.find(searchString) != std::s << 869 endOfEventModelList.erase(endOfEventMode << 870 any = true; << 871 if (verbosity >= G4VisManager::warnings) << 872 G4warn << "Model \"" << modelName << "\" rem << 873 } << 874 break; // Allow only one model at a tim << 875 } << 876 } << 877 << 878 std::vector<G4Scene::Model>& endOfRunModelLi << 879 pScene->SetEndOfRunModelList(); << 880 for (size_t i = 0; i < endOfRunModelList.siz << 881 const G4String& modelName = << 882 endOfRunModelList[i].fpModel->GetGlobalDes << 883 if (modelName.find(searchString) != std::s << 884 endOfRunModelList.erase(endOfRunModelLis << 885 any = true; << 886 if (verbosity >= G4VisManager::warnings) << 887 G4warn << "Model \"" << modelName << "\" rem << 888 } << 889 break; // Allow only one model at a tim << 890 } << 891 } << 892 << 893 if (!any) { << 894 if (verbosity >= G4VisManager::warnings) { << 895 G4warn << "WARNING: No match found." << << 896 } << 897 return; << 898 } << 899 << 900 CheckSceneAndNotifyHandlers (pScene); << 901 } << 902 << 903 ////////////// /vis/scene/select ///////////// 775 ////////////// /vis/scene/select /////////////////////////////////////// 904 776 905 G4VisCommandSceneSelect::G4VisCommandSceneSele 777 G4VisCommandSceneSelect::G4VisCommandSceneSelect () { 906 G4bool omitable; 778 G4bool omitable; 907 fpCommand = new G4UIcmdWithAString ("/vis/sc 779 fpCommand = new G4UIcmdWithAString ("/vis/scene/select", this); 908 fpCommand -> SetGuidance ("Selects a scene") 780 fpCommand -> SetGuidance ("Selects a scene"); 909 fpCommand -> SetGuidance 781 fpCommand -> SetGuidance 910 ("Makes the scene current. \"/vis/scene/lis 782 ("Makes the scene current. \"/vis/scene/list\" to see" 911 "\n possible scene names."); 783 "\n possible scene names."); 912 fpCommand -> SetParameterName ("scene-name", 784 fpCommand -> SetParameterName ("scene-name", omitable = false); 913 } 785 } 914 786 915 G4VisCommandSceneSelect::~G4VisCommandSceneSel 787 G4VisCommandSceneSelect::~G4VisCommandSceneSelect () { 916 delete fpCommand; 788 delete fpCommand; 917 } 789 } 918 790 919 G4String G4VisCommandSceneSelect::GetCurrentVa 791 G4String G4VisCommandSceneSelect::GetCurrentValue (G4UIcommand*) { 920 return ""; 792 return ""; 921 } 793 } 922 794 923 void G4VisCommandSceneSelect::SetNewValue (G4U 795 void G4VisCommandSceneSelect::SetNewValue (G4UIcommand*, G4String newValue) { 924 796 925 G4VisManager::Verbosity verbosity = fpVisMan 797 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); 926 798 927 G4String& selectName = newValue; 799 G4String& selectName = newValue; 928 G4SceneList& sceneList = fpVisManager -> Set 800 G4SceneList& sceneList = fpVisManager -> SetSceneList (); 929 std::size_t iScene, nScenes = sceneList.size << 801 G4int iScene, nScenes = sceneList.size (); 930 for (iScene = 0; iScene < nScenes; ++iScene) << 802 for (iScene = 0; iScene < nScenes; iScene++) { 931 if (sceneList [iScene] -> GetName () == se 803 if (sceneList [iScene] -> GetName () == selectName) break; 932 } 804 } 933 if (iScene >= nScenes) { 805 if (iScene >= nScenes) { 934 if (verbosity >= G4VisManager::warnings) { 806 if (verbosity >= G4VisManager::warnings) { 935 G4warn << "WARNING: Scene \"" << selectN << 807 G4cout << "WARNING: Scene \"" << selectName 936 << "\" not found - \"/vis/scene/list\" t 808 << "\" not found - \"/vis/scene/list\" to see possibilities." 937 << G4endl; 809 << G4endl; 938 } 810 } 939 return; 811 return; 940 } 812 } 941 813 942 if (verbosity >= G4VisManager::confirmations 814 if (verbosity >= G4VisManager::confirmations) { 943 G4cout << "Scene \"" << selectName 815 G4cout << "Scene \"" << selectName 944 << "\" selected." << G4endl; 816 << "\" selected." << G4endl; 945 } 817 } 946 818 947 CheckSceneAndNotifyHandlers (sceneList [iSce 819 CheckSceneAndNotifyHandlers (sceneList [iScene]); 948 } 820 } 949 821 950 ////////////// /vis/scene/showExtents //////// 822 ////////////// /vis/scene/showExtents /////////////////////////////////////// 951 823 952 G4VisCommandSceneShowExtents::G4VisCommandScen 824 G4VisCommandSceneShowExtents::G4VisCommandSceneShowExtents () { 953 fpCommand = new G4UIcmdWithoutParameter ("/v 825 fpCommand = new G4UIcmdWithoutParameter ("/vis/scene/showExtents", this); 954 fpCommand -> SetGuidance ("Prints and draws 826 fpCommand -> SetGuidance ("Prints and draws extents of models in a scene"); 955 } 827 } 956 828 957 G4VisCommandSceneShowExtents::~G4VisCommandSce 829 G4VisCommandSceneShowExtents::~G4VisCommandSceneShowExtents () { 958 delete fpCommand; 830 delete fpCommand; 959 } 831 } 960 832 961 G4String G4VisCommandSceneShowExtents::GetCurr 833 G4String G4VisCommandSceneShowExtents::GetCurrentValue (G4UIcommand*) { 962 return ""; 834 return ""; 963 } 835 } 964 836 965 void G4VisCommandSceneShowExtents::SetNewValue 837 void G4VisCommandSceneShowExtents::SetNewValue (G4UIcommand*, G4String) { 966 838 967 G4VisManager::Verbosity verbosity = fpVisMan 839 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); 968 840 969 G4VSceneHandler* pCurrentSceneHandler = 841 G4VSceneHandler* pCurrentSceneHandler = 970 fpVisManager -> GetCurrentSceneHandler(); 842 fpVisManager -> GetCurrentSceneHandler(); 971 if (!pCurrentSceneHandler) { 843 if (!pCurrentSceneHandler) { 972 if (verbosity >= G4VisManager::warnings) { 844 if (verbosity >= G4VisManager::warnings) { 973 G4warn << "WARNING: No current scene han << 845 G4cout << "WARNING: No current scene handler." 974 << G4endl; 846 << G4endl; 975 } 847 } 976 return; 848 return; 977 } 849 } 978 G4VViewer* pCurrentViewer = fpVisManager -> 850 G4VViewer* pCurrentViewer = fpVisManager -> GetCurrentViewer(); 979 if (!pCurrentViewer) { 851 if (!pCurrentViewer) { 980 if (verbosity >= G4VisManager::warnings) { 852 if (verbosity >= G4VisManager::warnings) { 981 G4warn << "WARNING: No current viewer." << 853 G4cout << "WARNING: No current viewer." 982 << G4endl; 854 << G4endl; 983 } 855 } 984 return; 856 return; 985 } 857 } 986 G4Scene* pCurrentScene = fpVisManager -> Get 858 G4Scene* pCurrentScene = fpVisManager -> GetCurrentScene(); 987 if (!pCurrentScene) { 859 if (!pCurrentScene) { 988 if (verbosity >= G4VisManager::warnings) { 860 if (verbosity >= G4VisManager::warnings) { 989 G4warn << "WARNING: No current scene." << 861 G4cout << "WARNING: No current scene." 990 << G4endl; 862 << G4endl; 991 } 863 } 992 return; 864 return; 993 } 865 } 994 866 995 G4cout << "\n Run-duration models:"; 867 G4cout << "\n Run-duration models:"; 996 std::size_t nRunModels = pCurrentScene -> Ge << 868 G4int nRunModels = pCurrentScene -> GetRunDurationModelList ().size (); 997 if (nRunModels == 0) { 869 if (nRunModels == 0) { 998 G4cout << " none."; 870 G4cout << " none."; 999 } 871 } 1000 for (std::size_t i = 0; i < nRunModels; ++i << 872 for (G4int i = 0; i < nRunModels; i++) { 1001 if (pCurrentScene -> GetRunDurationModelL 873 if (pCurrentScene -> GetRunDurationModelList()[i].fActive) 1002 G4cout << "\n Active: "; 874 G4cout << "\n Active: "; 1003 else G4cout << "\n Inactive: "; 875 else G4cout << "\n Inactive: "; 1004 G4VModel* pModel = pCurrentScene -> GetRu 876 G4VModel* pModel = pCurrentScene -> GetRunDurationModelList()[i].fpModel; 1005 const G4VisExtent& transformedExtent = pM << 877 const G4VisExtent& transformedExtent = pModel -> GetTransformedExtent(); 1006 G4cout << pModel -> GetGlobalDescription 878 G4cout << pModel -> GetGlobalDescription () 1007 << "\n" << transformedExtent; 879 << "\n" << transformedExtent; 1008 DrawExtent(transformedExtent); 880 DrawExtent(transformedExtent); 1009 } 881 } 1010 G4cout << "\n End-of-event models:"; 882 G4cout << "\n End-of-event models:"; 1011 std::size_t nEOEModels = pCurrentScene -> G << 883 G4int nEOEModels = pCurrentScene -> GetEndOfEventModelList ().size (); 1012 if (nEOEModels == 0) { 884 if (nEOEModels == 0) { 1013 G4cout << " none."; 885 G4cout << " none."; 1014 } 886 } 1015 for (std::size_t i = 0; i < nEOEModels; ++i << 887 for (G4int i = 0; i < nEOEModels; i++) { 1016 if (pCurrentScene -> GetEndOfEventModelLi 888 if (pCurrentScene -> GetEndOfEventModelList()[i].fActive) 1017 G4cout << "\n Active: "; 889 G4cout << "\n Active: "; 1018 else G4cout << "\n Inactive: "; 890 else G4cout << "\n Inactive: "; 1019 G4VModel* pModel = pCurrentScene -> GetEn 891 G4VModel* pModel = pCurrentScene -> GetEndOfEventModelList()[i].fpModel; 1020 const G4VisExtent& transformedExtent = pM << 892 const G4VisExtent& transformedExtent = pModel -> GetTransformedExtent(); 1021 G4cout << pModel -> GetGlobalDescription 893 G4cout << pModel -> GetGlobalDescription () 1022 << "\n" << transformedExtent; 894 << "\n" << transformedExtent; 1023 DrawExtent(transformedExtent); 895 DrawExtent(transformedExtent); 1024 } 896 } 1025 G4cout << "\n End-of-run models:"; 897 G4cout << "\n End-of-run models:"; 1026 std::size_t nEORModels = pCurrentScene -> G << 898 G4int nEORModels = pCurrentScene -> GetEndOfRunModelList ().size (); 1027 if (nEORModels == 0) { 899 if (nEORModels == 0) { 1028 G4cout << " none."; 900 G4cout << " none."; 1029 } 901 } 1030 for (std::size_t i = 0; i < nEORModels; ++i << 902 for (G4int i = 0; i < nEORModels; i++) { 1031 if (pCurrentScene -> GetEndOfRunModelList 903 if (pCurrentScene -> GetEndOfRunModelList()[i].fActive) 1032 G4cout << "\n Active: "; 904 G4cout << "\n Active: "; 1033 else G4cout << "\n Inactive: "; 905 else G4cout << "\n Inactive: "; 1034 G4VModel* pModel = pCurrentScene -> GetEn 906 G4VModel* pModel = pCurrentScene -> GetEndOfRunModelList()[i].fpModel; 1035 const G4VisExtent& transformedExtent = pM << 907 const G4VisExtent& transformedExtent = pModel -> GetTransformedExtent(); 1036 G4cout << pModel -> GetGlobalDescription 908 G4cout << pModel -> GetGlobalDescription () 1037 << "\n" << transformedExtent; 909 << "\n" << transformedExtent; 1038 DrawExtent(transformedExtent); 910 DrawExtent(transformedExtent); 1039 } 911 } 1040 G4cout << "\n Overall extent:\n"; 912 G4cout << "\n Overall extent:\n"; 1041 DrawExtent(pCurrentScene->GetExtent()); 913 DrawExtent(pCurrentScene->GetExtent()); 1042 G4cout << G4endl; 914 G4cout << G4endl; 1043 } 915 } 1044 916