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/sceneHandler commands - John Allison 28 // /vis/sceneHandler commands - John Allison 10th October 1998 29 29 30 #include "G4VisCommandsSceneHandler.hh" 30 #include "G4VisCommandsSceneHandler.hh" 31 31 32 #include "G4VisManager.hh" 32 #include "G4VisManager.hh" 33 #include "G4GraphicsSystemList.hh" 33 #include "G4GraphicsSystemList.hh" 34 #include "G4VisCommandsScene.hh" 34 #include "G4VisCommandsScene.hh" 35 #include "G4UImanager.hh" 35 #include "G4UImanager.hh" 36 #include "G4UIcommand.hh" 36 #include "G4UIcommand.hh" 37 #include "G4UIcmdWithAString.hh" 37 #include "G4UIcmdWithAString.hh" 38 #include "G4ios.hh" 38 #include "G4ios.hh" 39 #include <sstream> 39 #include <sstream> 40 40 41 #define G4warn G4cout << 42 << 43 ////////////// /vis/sceneHandler/attach ////// 41 ////////////// /vis/sceneHandler/attach /////////////////////////////////////// 44 42 45 G4VisCommandSceneHandlerAttach::G4VisCommandSc 43 G4VisCommandSceneHandlerAttach::G4VisCommandSceneHandlerAttach () { 46 G4bool omitable, currentAsDefault; 44 G4bool omitable, currentAsDefault; 47 fpCommand = new G4UIcmdWithAString ("/vis/sc 45 fpCommand = new G4UIcmdWithAString ("/vis/sceneHandler/attach", this); 48 fpCommand -> SetGuidance ("Attaches scene to 46 fpCommand -> SetGuidance ("Attaches scene to current scene handler."); 49 fpCommand -> SetGuidance 47 fpCommand -> SetGuidance 50 ("If scene-name is omitted, current scene 48 ("If scene-name is omitted, current scene is attached. To see scenes and" 51 "\nscene handlers, use \"/vis/scene/list\" a 49 "\nscene handlers, use \"/vis/scene/list\" and \"/vis/sceneHandler/list\""); 52 fpCommand -> SetParameterName ("scene-name", 50 fpCommand -> SetParameterName ("scene-name", 53 omitable = true, 51 omitable = true, 54 currentAsDefault = true); 52 currentAsDefault = true); 55 } 53 } 56 54 57 G4VisCommandSceneHandlerAttach::~G4VisCommandS 55 G4VisCommandSceneHandlerAttach::~G4VisCommandSceneHandlerAttach () { 58 delete fpCommand; 56 delete fpCommand; 59 } 57 } 60 58 61 G4String G4VisCommandSceneHandlerAttach::GetCu 59 G4String G4VisCommandSceneHandlerAttach::GetCurrentValue (G4UIcommand*) { 62 G4Scene* pScene = fpVisManager -> GetCurrent 60 G4Scene* pScene = fpVisManager -> GetCurrentScene (); 63 return pScene ? pScene -> GetName () : G4Str 61 return pScene ? pScene -> GetName () : G4String(""); 64 } 62 } 65 63 66 void G4VisCommandSceneHandlerAttach::SetNewVal 64 void G4VisCommandSceneHandlerAttach::SetNewValue (G4UIcommand*, 67 G4String newValue) { 65 G4String newValue) { 68 66 69 G4VisManager::Verbosity verbosity = fpVisMan 67 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); 70 68 71 G4String& sceneName = newValue; 69 G4String& sceneName = newValue; 72 70 73 if (sceneName.length () == 0) { 71 if (sceneName.length () == 0) { 74 if (verbosity >= G4VisManager::warnings) { 72 if (verbosity >= G4VisManager::warnings) { 75 G4cout << 73 G4cout << 76 "WARNING: No scene specified. Maybe there a 74 "WARNING: No scene specified. Maybe there are no scenes available" 77 "\n yet. Please create one." << G4endl; 75 "\n yet. Please create one." << G4endl; 78 } 76 } 79 return; 77 return; 80 } 78 } 81 79 82 G4VSceneHandler* pSceneHandler = fpVisManage 80 G4VSceneHandler* pSceneHandler = fpVisManager -> GetCurrentSceneHandler (); 83 if (!pSceneHandler) { 81 if (!pSceneHandler) { 84 if (verbosity >= G4VisManager::errors) { 82 if (verbosity >= G4VisManager::errors) { 85 G4warn << << 83 G4cerr << 86 "ERROR: Current scene handler not define 84 "ERROR: Current scene handler not defined. Please select or create one." 87 << G4endl; 85 << G4endl; 88 } 86 } 89 return; 87 return; 90 } 88 } 91 89 92 G4SceneList& sceneList = fpVisManager -> Set 90 G4SceneList& sceneList = fpVisManager -> SetSceneList (); 93 91 94 if (sceneList.empty ()) { 92 if (sceneList.empty ()) { 95 if (verbosity >= G4VisManager::errors) { 93 if (verbosity >= G4VisManager::errors) { 96 G4warn << << 94 G4cerr << 97 "ERROR: No valid scenes available yet. 95 "ERROR: No valid scenes available yet. Please create one." 98 << G4endl; 96 << G4endl; 99 } 97 } 100 return; 98 return; 101 } 99 } 102 100 103 std::size_t iScene, nScenes = sceneList.size << 101 G4int iScene, nScenes = sceneList.size (); 104 for (iScene = 0; iScene < nScenes; ++iScene) << 102 for (iScene = 0; iScene < nScenes; iScene++) { 105 if (sceneList [iScene] -> GetName () == sc 103 if (sceneList [iScene] -> GetName () == sceneName) break; 106 } 104 } 107 if (iScene < nScenes) { 105 if (iScene < nScenes) { 108 G4Scene* pScene = sceneList [iScene]; 106 G4Scene* pScene = sceneList [iScene]; 109 pSceneHandler -> SetScene (pScene); 107 pSceneHandler -> SetScene (pScene); 110 // Make sure scene is current... 108 // Make sure scene is current... 111 fpVisManager -> SetCurrentScene (pScene); 109 fpVisManager -> SetCurrentScene (pScene); 112 // Refresh viewer, if any (only if auto-re 110 // Refresh viewer, if any (only if auto-refresh)... 113 G4VViewer* pViewer = pSceneHandler -> GetC 111 G4VViewer* pViewer = pSceneHandler -> GetCurrentViewer(); 114 if (pViewer && pViewer -> GetViewParameter 112 if (pViewer && pViewer -> GetViewParameters().IsAutoRefresh()) { 115 pViewer -> SetView (); 113 pViewer -> SetView (); 116 pViewer -> ClearView (); 114 pViewer -> ClearView (); 117 pViewer -> DrawView (); 115 pViewer -> DrawView (); 118 } 116 } 119 if (verbosity >= G4VisManager::confirmatio 117 if (verbosity >= G4VisManager::confirmations) { 120 G4cout << "Scene \"" << sceneName 118 G4cout << "Scene \"" << sceneName 121 << "\" attached to scene handler \"" 119 << "\" attached to scene handler \"" 122 << pSceneHandler -> GetName () << 120 << pSceneHandler -> GetName () << 123 ".\n (You may have to refresh with \"/vis/v 121 ".\n (You may have to refresh with \"/vis/viewer/flush\" if view" 124 " is not \"auto-refresh\".)" 122 " is not \"auto-refresh\".)" 125 << G4endl; 123 << G4endl; 126 } 124 } 127 } 125 } 128 else { 126 else { 129 if (verbosity >= G4VisManager::errors) { 127 if (verbosity >= G4VisManager::errors) { 130 G4warn << "ERROR: Scene \"" << sceneName << 128 G4cerr << "ERROR: Scene \"" << sceneName 131 << "\" not found. Use \"/vis/scene/lis 129 << "\" not found. Use \"/vis/scene/list\" to see possibilities." 132 << G4endl; 130 << G4endl; 133 } 131 } 134 } 132 } 135 } 133 } 136 134 137 ////////////// /vis/sceneHandler/create ////// 135 ////////////// /vis/sceneHandler/create /////////////////////////////////////// 138 136 139 G4VisCommandSceneHandlerCreate::G4VisCommandSc 137 G4VisCommandSceneHandlerCreate::G4VisCommandSceneHandlerCreate (): fId (0) { 140 G4bool omitable; 138 G4bool omitable; 141 fpCommand = new G4UIcommand ("/vis/sceneHand 139 fpCommand = new G4UIcommand ("/vis/sceneHandler/create", this); 142 fpCommand -> SetGuidance 140 fpCommand -> SetGuidance 143 ("Creates an scene handler for a specific 141 ("Creates an scene handler for a specific graphics system."); 144 fpCommand -> SetGuidance 142 fpCommand -> SetGuidance 145 ("Attaches current scene, if any. (You ca 143 ("Attaches current scene, if any. (You can change attached scenes with" 146 "\n\"/vis/sceneHandler/attach\".) Invent 144 "\n\"/vis/sceneHandler/attach\".) Invents a scene handler name if not" 147 "\nsupplied. This scene handler becomes 145 "\nsupplied. This scene handler becomes current."); 148 G4UIparameter* parameter; 146 G4UIparameter* parameter; 149 parameter = new G4UIparameter ("graphics-sys << 147 parameter = new G4UIparameter ("graphics-system-name", 150 parameter -> SetCurrentAsDefault(true); << 148 's', omitable = false); 151 const G4GraphicsSystemList& gslist = 149 const G4GraphicsSystemList& gslist = 152 fpVisManager -> GetAvailableGraphicsSystems << 150 fpVisManager -> GetAvailableGraphicsSystems (); 153 G4String candidates = "NO_UI_SESSION "; // << 151 G4String candidates; 154 for (const auto gs: gslist) { 152 for (const auto gs: gslist) { 155 const G4String& name = gs -> GetName (); 153 const G4String& name = gs -> GetName (); 156 candidates += name + ' '; 154 candidates += name + ' '; 157 for (const auto& nickname: gs -> GetNickna 155 for (const auto& nickname: gs -> GetNicknames ()) { 158 if (G4StrUtil::contains(nickname, "FALLB << 159 if (nickname != name) candidates += nick 156 if (nickname != name) candidates += nickname + ' '; 160 } 157 } 161 } 158 } 162 G4StrUtil::strip(candidates); << 159 candidates = candidates.strip (); 163 parameter -> SetParameterCandidates(candidat 160 parameter -> SetParameterCandidates(candidates); 164 fpCommand -> SetParameter (parameter); 161 fpCommand -> SetParameter (parameter); 165 parameter = new G4UIparameter 162 parameter = new G4UIparameter 166 ("scene-handler-name", 's', omitable = tru 163 ("scene-handler-name", 's', omitable = true); 167 parameter -> SetCurrentAsDefault (true); 164 parameter -> SetCurrentAsDefault (true); 168 fpCommand -> SetParameter (parameter); 165 fpCommand -> SetParameter (parameter); 169 } 166 } 170 167 171 G4VisCommandSceneHandlerCreate::~G4VisCommandS 168 G4VisCommandSceneHandlerCreate::~G4VisCommandSceneHandlerCreate () { 172 delete fpCommand; 169 delete fpCommand; 173 } 170 } 174 171 175 G4String G4VisCommandSceneHandlerCreate::NextN 172 G4String G4VisCommandSceneHandlerCreate::NextName () { 176 std::ostringstream oss; 173 std::ostringstream oss; 177 oss << "scene-handler-" << fId; 174 oss << "scene-handler-" << fId; 178 return oss.str(); 175 return oss.str(); 179 } 176 } 180 177 181 G4String G4VisCommandSceneHandlerCreate::GetCu 178 G4String G4VisCommandSceneHandlerCreate::GetCurrentValue(G4UIcommand*) { 182 179 183 G4String graphicsSystemName; 180 G4String graphicsSystemName; 184 const G4VGraphicsSystem* graphicsSystem = 181 const G4VGraphicsSystem* graphicsSystem = 185 fpVisManager -> GetCurrentGraphicsSystem ( 182 fpVisManager -> GetCurrentGraphicsSystem (); 186 if (graphicsSystem) { 183 if (graphicsSystem) { 187 graphicsSystemName = graphicsSystem -> Get 184 graphicsSystemName = graphicsSystem -> GetName (); 188 } 185 } 189 else { 186 else { 190 graphicsSystemName = fpVisManager->GetDefa << 187 const G4GraphicsSystemList& gslist = >> 188 fpVisManager -> GetAvailableGraphicsSystems (); >> 189 if (gslist.size ()) { >> 190 graphicsSystemName = gslist [0] -> GetName (); >> 191 } >> 192 else { >> 193 graphicsSystemName = "none"; >> 194 } 191 } 195 } 192 196 193 return graphicsSystemName + " " + NextName ( 197 return graphicsSystemName + " " + NextName (); 194 } 198 } 195 199 196 void G4VisCommandSceneHandlerCreate::SetNewVal 200 void G4VisCommandSceneHandlerCreate::SetNewValue (G4UIcommand* command, 197 G4String newValue) { 201 G4String newValue) { 198 202 199 G4VisManager::Verbosity verbosity = fpVisMan 203 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); 200 204 201 G4String graphicsSystem, newName; 205 G4String graphicsSystem, newName; 202 std::istringstream is (newValue); 206 std::istringstream is (newValue); 203 is >> graphicsSystem >> newName; 207 is >> graphicsSystem >> newName; 204 208 205 const G4GraphicsSystemList& gsl = 209 const G4GraphicsSystemList& gsl = 206 fpVisManager -> GetAvailableGraphicsSystem 210 fpVisManager -> GetAvailableGraphicsSystems (); 207 std::size_t nSystems = gsl.size (); << 211 G4int nSystems = gsl.size (); 208 if (nSystems <= 0) { 212 if (nSystems <= 0) { 209 G4ExceptionDescription ed; << 213 if (verbosity >= G4VisManager::errors) { 210 ed << << 214 G4cerr << "ERROR: G4VisCommandSceneHandlerCreate::SetNewValue:" 211 "ERROR: G4VisCommandSceneHandlerCreate::Se << 215 " no graphics systems available." 212 " no graphics systems available." << 216 "\n Did you instantiate any in" 213 "\n Did you instantiate any in" << 217 " YourVisManager::RegisterGraphicsSystems()?" 214 " YourVisManager::RegisterGraphicsSystems( << 218 << G4endl; 215 command->CommandFailed(ed); << 219 } 216 return; 220 return; 217 } 221 } 218 std::size_t iGS; // Selector index. << 222 G4int iGS; // Selector index. 219 G4bool found = false; 223 G4bool found = false; 220 for (iGS = 0; iGS < nSystems; ++iGS) { << 224 for (iGS = 0; iGS < nSystems; iGS++) { 221 const auto& gs = gsl[iGS]; 225 const auto& gs = gsl[iGS]; 222 if (G4StrUtil::icompare(graphicsSystem, gs << 226 if (graphicsSystem.compareTo(gs->GetName(), G4String::ignoreCase) == 0) { 223 found = true; 227 found = true; 224 break; // Match found 228 break; // Match found 225 } else { 229 } else { 226 const auto& nicknames = gs->GetNicknames 230 const auto& nicknames = gs->GetNicknames(); 227 for (std::size_t i = 0; i < nicknames.si << 231 for (size_t i = 0; i < nicknames.size(); ++i) { 228 const auto& nickname = nicknames[i]; 232 const auto& nickname = nicknames[i]; 229 if (G4StrUtil::icompare(graphicsSystem << 233 if (graphicsSystem.compareTo (nickname, G4String::ignoreCase) == 0) { 230 found = true; 234 found = true; 231 break; // Match found 235 break; // Match found 232 } 236 } 233 } 237 } 234 if (found) { 238 if (found) { 235 break; // Match found 239 break; // Match found 236 } 240 } 237 } 241 } 238 } 242 } 239 if (!found) { 243 if (!found) { 240 if (graphicsSystem == "NO_UI_SESSION") { << 244 // Invalid command line argument or none. 241 G4Exception << 245 // This shouldn't happen!!!!!! 242 ("G4VisCommandSceneHandlerCreate::SetNew << 246 if (verbosity >= G4VisManager::errors) { 243 "This looks like an attempt to use run- << 247 G4cerr << 244 "\nYou have issued \"/vis/open\" or \"/ << 248 "ERROR: G4VisCommandSceneHandlerCreate::SetNewValue:" 245 "\na parameter for the vis driver. This << 249 "\n invalid graphics system \"" 246 "\na UI session, and only if it is inst << 250 << graphicsSystem 247 "\n\"/vis/open\" command. So:" << 251 << "\" requested." 248 "\na) It is not allowed in batch mode. << 252 << G4endl; 249 "\n some graphics with a file-writing << 250 "\n request a specific driver on the << 251 "\n \"/vis/open TSG_OFFSCREEN\". See, << 252 "\nb) If you want to exploit this featu << 253 "\n the instantiation of the UI sessi << 254 "\n practice in order to capture outp << 255 return; << 256 } 253 } 257 // Shouldn't happen, since graphicsSystem << 258 G4ExceptionDescription ed; << 259 ed << << 260 "ERROR: G4VisCommandSceneHandlerCreate::Se << 261 "\n Invalid graphics system \"" << 262 << graphicsSystem << 263 << "\" requested." << 264 << "\n Candidates are:"; << 265 fpVisManager->PrintAvailableGraphicsSystem << 266 command->CommandFailed(ed); << 267 return; 254 return; 268 } 255 } 269 256 270 // Check UI session compatibility. 257 // Check UI session compatibility. 271 G4bool fallback = false; 258 G4bool fallback = false; 272 G4int loopCounter = 0; 259 G4int loopCounter = 0; 273 while (!gsl[iGS]->IsUISessionCompatible()) { 260 while (!gsl[iGS]->IsUISessionCompatible()) { 274 std::size_t iGSBeingTested = iGS; << 261 G4int iGSBeingTested = iGS; 275 // Not compatible, search for a fallback 262 // Not compatible, search for a fallback 276 fallback = false; 263 fallback = false; 277 G4String fallbackNickname = gsl[iGS]->GetN 264 G4String fallbackNickname = gsl[iGS]->GetNickname() + "_FALLBACK"; 278 for (iGS = 0; iGS < nSystems; iGS++) { 265 for (iGS = 0; iGS < nSystems; iGS++) { 279 const auto& nicknames = gsl[iGS]->GetNic 266 const auto& nicknames = gsl[iGS]->GetNicknames(); 280 for (std::size_t i = 0; i < nicknames.si << 267 for (size_t i = 0; i < nicknames.size(); ++i) { 281 const auto& nickname = nicknames[i]; 268 const auto& nickname = nicknames[i]; 282 if (G4StrUtil::icompare(fallbackNickna << 269 if (fallbackNickname.compareTo (nickname, G4String::ignoreCase) == 0) { 283 fallback = true; 270 fallback = true; 284 break; // Match found 271 break; // Match found 285 } 272 } 286 } 273 } 287 if (fallback) { 274 if (fallback) { 288 break; // Match found 275 break; // Match found 289 } 276 } 290 } 277 } 291 if (iGS >= nSystems || loopCounter >=3) { << 278 if (iGS < 0 || iGS >= nSystems || loopCounter >=3) { 292 G4ExceptionDescription ed; << 279 std::ostringstream oss; 293 ed << "\"" << gsl[iGSBeingTested]->GetNi << 280 oss << "\"" << gsl[iGSBeingTested]->GetNickname() 294 << "\" is not compatible with the sessio << 281 << "\" is not compatible with your chosen session," 295 "\nand no fallback system found. Make su << 282 " and no fallback system found."; 296 "\ninstantiated _before_ you create a gr << 283 if (verbosity >= G4VisManager::errors) { 297 G4Exception("G4VisCommandSceneHandlerCre << 284 G4cerr << "ERROR: G4VisCommandSceneHandlerCreate::SetNewValue: " 298 "visman1002", JustWarning, e << 285 << oss.str() << G4endl; >> 286 } >> 287 command->CommandFailed(oss); 299 return; 288 return; 300 } 289 } 301 // A fallback system found...but go back 290 // A fallback system found...but go back and check this too. 302 ++loopCounter; 291 ++loopCounter; 303 } 292 } 304 293 305 // A graphics system has been found 294 // A graphics system has been found 306 G4VGraphicsSystem* pSystem = gsl [iGS]; 295 G4VGraphicsSystem* pSystem = gsl [iGS]; 307 296 308 if (fallback && verbosity >= G4VisManager::w 297 if (fallback && verbosity >= G4VisManager::warnings) { 309 G4warn << "WARNING: G4VisCommandSceneHandl << 298 G4cout << "WARNING: G4VisCommandSceneHandlerCreate::SetNewValue:" 310 "\n Using fallback graphics system: " 299 "\n Using fallback graphics system: " 311 << pSystem -> GetName () 300 << pSystem -> GetName () 312 << " (" 301 << " (" 313 << pSystem -> GetNickname () 302 << pSystem -> GetNickname () 314 << ')' 303 << ')' 315 << G4endl; 304 << G4endl; 316 } 305 } 317 306 >> 307 // Set current graphics system in preparation for >> 308 // creating scene handler. >> 309 fpVisManager -> SetCurrentGraphicsSystem (pSystem); >> 310 if (verbosity >= G4VisManager::confirmations) { >> 311 G4cout << "Graphics system set to " >> 312 << pSystem -> GetName () >> 313 << " (" >> 314 << pSystem -> GetNickname () >> 315 << ')' >> 316 << G4endl; >> 317 } >> 318 318 // Now deal with name of scene handler. 319 // Now deal with name of scene handler. 319 G4String nextName = NextName (); 320 G4String nextName = NextName (); 320 if (newName == "") { 321 if (newName == "") { 321 newName = nextName; 322 newName = nextName; 322 } 323 } 323 if (newName == nextName) fId++; 324 if (newName == nextName) fId++; 324 325 325 const G4SceneHandlerList& list = fpVisManage 326 const G4SceneHandlerList& list = fpVisManager -> GetAvailableSceneHandlers (); 326 std::size_t iScene; << 327 size_t iScene; 327 for (iScene = 0; iScene < list.size (); ++iS << 328 for (iScene = 0; iScene < list.size (); iScene++) { 328 G4VSceneHandler* sceneHandler = list [iSce 329 G4VSceneHandler* sceneHandler = list [iScene]; 329 if (sceneHandler -> GetName () == newName) 330 if (sceneHandler -> GetName () == newName) { 330 G4ExceptionDescription ed; << 331 if (verbosity >= G4VisManager::errors) { 331 ed << << 332 G4cerr << "ERROR: Scene handler \"" << newName 332 "ERROR: Scene handler \"" << newName << 333 << "\" already exists." << G4endl; 333 << "\" already exists."; << 334 } 334 command->CommandFailed(ed); << 335 return; 335 return; 336 } 336 } 337 } 337 } 338 338 339 // If there is an existing viewer, store its << 340 if (fpVisManager->GetCurrentViewer()) { << 341 fThereWasAViewer = true; << 342 auto viewer = fpVisManager->GetCurrentView << 343 fExistingVP = viewer->GetViewParameters(); << 344 fExistingSceneTree = viewer->AccessSceneTr << 345 } << 346 << 347 // Set current graphics system in preparatio << 348 // creating scene handler. << 349 fpVisManager -> SetCurrentGraphicsSystem (pS << 350 if (verbosity >= G4VisManager::confirmations << 351 G4cout << "Graphics system set to " << 352 << pSystem -> GetName () << 353 << " (" << 354 << pSystem -> GetNickname () << 355 << ')' << 356 << G4endl; << 357 } << 358 << 359 //Create scene handler. 339 //Create scene handler. 360 fpVisManager -> CreateSceneHandler (newName) 340 fpVisManager -> CreateSceneHandler (newName); 361 if (fpVisManager -> GetCurrentSceneHandler ( 341 if (fpVisManager -> GetCurrentSceneHandler () -> GetName () != newName) { 362 G4ExceptionDescription ed; << 342 if (verbosity >= G4VisManager::errors) { 363 ed << << 343 G4cerr << "ERROR: G4VisCommandSceneHandlerCreate::SetNewValue:" 364 "ERROR: G4VisCommandSceneHandlerCreate::Se << 344 " Curious name mismatch." 365 " Curious name mismatch." << 345 "\n Current name \"" 366 "\n Current name \"" << 346 << fpVisManager -> GetCurrentSceneHandler () -> GetName () 367 << fpVisManager -> GetCurrentSceneHandler << 347 << "\" is not the new name \"" 368 << "\" is not the new name \"" << 348 << newName 369 << newName << 349 << "\".\n Please report to vis coordinator." 370 << "\".\n Please report to vis coordinato << 350 << G4endl; 371 command->CommandFailed(ed); << 351 } 372 return; 352 return; 373 } 353 } 374 354 375 if (verbosity >= G4VisManager::confirmations << 355 if (verbosity >= G4VisManager::confirmations) { 376 G4cout << "New scene handler \"" << newNam 356 G4cout << "New scene handler \"" << newName << "\" created." << G4endl; 377 << 378 if (fpVisManager -> GetCurrentScene ()) { << 379 auto errorCode = G4UImanager::GetUIpointer << 380 if (errorCode) { << 381 G4ExceptionDescription ed; << 382 ed << "sub-command \"/vis/sceneHandler/a << 383 command->CommandFailed(errorCode,ed); << 384 return; << 385 } << 386 } 357 } >> 358 >> 359 // Attach scene. >> 360 if (fpVisManager -> GetCurrentScene ()) >> 361 G4UImanager::GetUIpointer () -> ApplyCommand ("/vis/sceneHandler/attach"); 387 } 362 } 388 363 389 ////////////// /vis/sceneHandler/list //////// 364 ////////////// /vis/sceneHandler/list /////////////////////////////////////// 390 365 391 G4VisCommandSceneHandlerList::G4VisCommandScen 366 G4VisCommandSceneHandlerList::G4VisCommandSceneHandlerList () { 392 G4bool omitable; 367 G4bool omitable; 393 fpCommand = new G4UIcommand ("/vis/sceneHand 368 fpCommand = new G4UIcommand ("/vis/sceneHandler/list", this); 394 fpCommand -> SetGuidance ("Lists scene handl 369 fpCommand -> SetGuidance ("Lists scene handler(s)."); 395 fpCommand -> SetGuidance 370 fpCommand -> SetGuidance 396 ("\"help /vis/verbose\" for definition of 371 ("\"help /vis/verbose\" for definition of verbosity."); 397 G4UIparameter* parameter; 372 G4UIparameter* parameter; 398 parameter = new G4UIparameter("scene-handler 373 parameter = new G4UIparameter("scene-handler-name", 's', omitable = true); 399 parameter -> SetDefaultValue ("all"); 374 parameter -> SetDefaultValue ("all"); 400 fpCommand -> SetParameter (parameter); 375 fpCommand -> SetParameter (parameter); 401 parameter = new G4UIparameter ("verbosity", 376 parameter = new G4UIparameter ("verbosity", 's', omitable = true); 402 parameter -> SetDefaultValue ("warnings"); 377 parameter -> SetDefaultValue ("warnings"); 403 fpCommand -> SetParameter (parameter); 378 fpCommand -> SetParameter (parameter); 404 } 379 } 405 380 406 G4VisCommandSceneHandlerList::~G4VisCommandSce 381 G4VisCommandSceneHandlerList::~G4VisCommandSceneHandlerList () { 407 delete fpCommand; 382 delete fpCommand; 408 } 383 } 409 384 410 G4String G4VisCommandSceneHandlerList::GetCurr 385 G4String G4VisCommandSceneHandlerList::GetCurrentValue (G4UIcommand*) { 411 return ""; 386 return ""; 412 } 387 } 413 388 414 void G4VisCommandSceneHandlerList::SetNewValue 389 void G4VisCommandSceneHandlerList::SetNewValue (G4UIcommand*, 415 G4String newValue) { 390 G4String newValue) { 416 G4String name, verbosityString; 391 G4String name, verbosityString; 417 std::istringstream is (newValue); 392 std::istringstream is (newValue); 418 is >> name >> verbosityString; 393 is >> name >> verbosityString; 419 G4VisManager::Verbosity verbosity = 394 G4VisManager::Verbosity verbosity = 420 fpVisManager->GetVerbosityValue(verbosityS 395 fpVisManager->GetVerbosityValue(verbosityString); 421 const G4VSceneHandler* currentSceneHandler = 396 const G4VSceneHandler* currentSceneHandler = 422 fpVisManager -> GetCurrentSceneHandler (); 397 fpVisManager -> GetCurrentSceneHandler (); 423 G4String currentName; 398 G4String currentName; 424 if (currentSceneHandler) currentName = curre 399 if (currentSceneHandler) currentName = currentSceneHandler->GetName(); 425 400 426 const G4SceneHandlerList& list = fpVisManage 401 const G4SceneHandlerList& list = fpVisManager -> GetAvailableSceneHandlers (); 427 G4bool found = false; 402 G4bool found = false; 428 for (std::size_t iSH = 0; iSH < list.size () << 403 for (size_t iSH = 0; iSH < list.size (); iSH++) { 429 const G4String& iName = list [iSH] -> GetN 404 const G4String& iName = list [iSH] -> GetName (); 430 if (name != "all") { 405 if (name != "all") { 431 if (name != iName) continue; 406 if (name != iName) continue; 432 } 407 } 433 found = true; 408 found = true; 434 if (iName == currentName) { 409 if (iName == currentName) { 435 G4cout << " (current)"; 410 G4cout << " (current)"; 436 } 411 } 437 else { 412 else { 438 G4cout << " "; 413 G4cout << " "; 439 } 414 } 440 G4cout << " scene handler \"" << list [iSH 415 G4cout << " scene handler \"" << list [iSH] -> GetName () << "\"" 441 << " (" << list [iSH] -> GetGraphicsSyste 416 << " (" << list [iSH] -> GetGraphicsSystem () -> GetName () << ")"; 442 if (verbosity >= G4VisManager::parameters) 417 if (verbosity >= G4VisManager::parameters) { 443 G4cout << "\n " << *(list [iSH]); 418 G4cout << "\n " << *(list [iSH]); 444 } 419 } 445 G4cout << G4endl; 420 G4cout << G4endl; 446 } 421 } 447 if (!found) { 422 if (!found) { 448 G4cout << "No scene handlers found"; 423 G4cout << "No scene handlers found"; 449 if (name != "all") { 424 if (name != "all") { 450 G4cout << " of name \"" << name << "\""; 425 G4cout << " of name \"" << name << "\""; 451 } 426 } 452 G4cout << "." << G4endl; 427 G4cout << "." << G4endl; 453 } 428 } 454 } 429 } 455 430 456 ////////////// /vis/sceneHandler/select ////// 431 ////////////// /vis/sceneHandler/select /////////////////////////////////////// 457 432 458 G4VisCommandSceneHandlerSelect::G4VisCommandSc 433 G4VisCommandSceneHandlerSelect::G4VisCommandSceneHandlerSelect () { 459 G4bool omitable; 434 G4bool omitable; 460 fpCommand = new G4UIcmdWithAString ("/vis/sc 435 fpCommand = new G4UIcmdWithAString ("/vis/sceneHandler/select", this); 461 fpCommand -> SetGuidance ("Selects a scene h 436 fpCommand -> SetGuidance ("Selects a scene handler."); 462 fpCommand -> SetGuidance 437 fpCommand -> SetGuidance 463 ("Makes the scene handler current. \"/vis 438 ("Makes the scene handler current. \"/vis/sceneHandler/list\" to see" 464 "\n possible scene handler names."); 439 "\n possible scene handler names."); 465 fpCommand -> SetParameterName ("scene-handle 440 fpCommand -> SetParameterName ("scene-handler-name", 466 omitable = false); 441 omitable = false); 467 } 442 } 468 443 469 G4VisCommandSceneHandlerSelect::~G4VisCommandS 444 G4VisCommandSceneHandlerSelect::~G4VisCommandSceneHandlerSelect () { 470 delete fpCommand; 445 delete fpCommand; 471 } 446 } 472 447 473 G4String G4VisCommandSceneHandlerSelect::GetCu 448 G4String G4VisCommandSceneHandlerSelect::GetCurrentValue (G4UIcommand*) { 474 return ""; 449 return ""; 475 } 450 } 476 451 477 void G4VisCommandSceneHandlerSelect::SetNewVal 452 void G4VisCommandSceneHandlerSelect::SetNewValue (G4UIcommand*, 478 G4String newValue) { 453 G4String newValue) { 479 454 480 G4VisManager::Verbosity verbosity = fpVisMan 455 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); 481 456 482 G4String& selectName = newValue; 457 G4String& selectName = newValue; 483 const G4SceneHandlerList& list = fpVisManage 458 const G4SceneHandlerList& list = fpVisManager -> GetAvailableSceneHandlers (); 484 459 485 std::size_t iSH; << 460 size_t iSH; 486 for (iSH = 0; iSH < list.size (); iSH++) { 461 for (iSH = 0; iSH < list.size (); iSH++) { 487 if (list [iSH] -> GetName () == selectName 462 if (list [iSH] -> GetName () == selectName) break; 488 } 463 } 489 if (iSH < list.size ()) { 464 if (iSH < list.size ()) { 490 if (fpVisManager -> GetCurrentSceneHandler 465 if (fpVisManager -> GetCurrentSceneHandler () -> GetName () 491 == selectName) { 466 == selectName) { 492 if (verbosity >= G4VisManager::confirmat 467 if (verbosity >= G4VisManager::confirmations) { 493 G4cout << "Scene handler \"" << selectName < 468 G4cout << "Scene handler \"" << selectName << "\"" 494 << " already selected." << G4endl; 469 << " already selected." << G4endl; 495 } 470 } 496 } 471 } 497 else { 472 else { 498 if (verbosity >= G4VisManager::confirmat 473 if (verbosity >= G4VisManager::confirmations) { 499 G4cout << "Scene handler \"" << selectName < 474 G4cout << "Scene handler \"" << selectName << "\"" 500 << " being selected." << G4endl; 475 << " being selected." << G4endl; 501 } 476 } 502 fpVisManager -> SetCurrentSceneHandler ( 477 fpVisManager -> SetCurrentSceneHandler (list [iSH]); 503 } 478 } 504 } 479 } 505 else { 480 else { 506 if (verbosity >= G4VisManager::errors) { 481 if (verbosity >= G4VisManager::errors) { 507 G4warn << "ERROR: Scene handler \"" << s << 482 G4cerr << "ERROR: Scene handler \"" << selectName << "\"" 508 << " not found - \"/vis/sceneHandler/li 483 << " not found - \"/vis/sceneHandler/list\" to see possibilities." 509 << G4endl; 484 << G4endl; 510 } 485 } 511 } 486 } 512 } 487 } 513 488