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