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.22 2001/09/10 10:56:55 johna Exp $ >> 25 // GEANT4 tag $Name: geant4-05-01-patch-01 $ 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 "g4std/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* command) { 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* command, 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 G4std::ostrstream ost (nextName, 20); 178 return oss.str(); << 210 ost << "scene-handler-" << fId << G4std::ends; >> 211 return nextName; 179 } 212 } 180 213 181 G4String G4VisCommandSceneHandlerCreate::GetCu << 214 G4String G4VisCommandSceneHandlerCreate::GetCurrentValue >> 215 (G4UIcommand* command) { 182 216 183 G4String graphicsSystemName; 217 G4String graphicsSystemName; 184 const G4VGraphicsSystem* graphicsSystem = 218 const G4VGraphicsSystem* graphicsSystem = 185 fpVisManager -> GetCurrentGraphicsSystem ( 219 fpVisManager -> GetCurrentGraphicsSystem (); 186 if (graphicsSystem) { 220 if (graphicsSystem) { 187 graphicsSystemName = graphicsSystem -> Get 221 graphicsSystemName = graphicsSystem -> GetName (); 188 } 222 } 189 else { 223 else { 190 graphicsSystemName = fpVisManager->GetDefa << 224 const G4GraphicsSystemList& gslist = >> 225 fpVisManager -> GetAvailableGraphicsSystems (); >> 226 if (gslist.size ()) { >> 227 graphicsSystemName = gslist [0] -> GetName (); >> 228 } >> 229 else { >> 230 graphicsSystemName = "none"; >> 231 } 191 } 232 } 192 233 193 return graphicsSystemName + " " + NextName ( 234 return graphicsSystemName + " " + NextName (); 194 } 235 } 195 236 196 void G4VisCommandSceneHandlerCreate::SetNewVal 237 void G4VisCommandSceneHandlerCreate::SetNewValue (G4UIcommand* command, 197 G4String newValue) { << 238 G4String newValue) { 198 239 199 G4VisManager::Verbosity verbosity = fpVisMan 240 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); 200 241 201 G4String graphicsSystem, newName; 242 G4String graphicsSystem, newName; 202 std::istringstream is (newValue); << 243 G4std::istrstream is ((char*)newValue.data()); 203 is >> graphicsSystem >> newName; 244 is >> graphicsSystem >> newName; 204 245 205 const G4GraphicsSystemList& gsl = 246 const G4GraphicsSystemList& gsl = 206 fpVisManager -> GetAvailableGraphicsSystem 247 fpVisManager -> GetAvailableGraphicsSystems (); 207 std::size_t nSystems = gsl.size (); << 248 int nSystems = gsl.size (); 208 if (nSystems <= 0) { 249 if (nSystems <= 0) { 209 G4ExceptionDescription ed; << 250 if (verbosity >= G4VisManager::errors) { 210 ed << << 251 G4cout << "ERROR: G4VisCommandSceneHandlerCreate::SetNewValue:" 211 "ERROR: G4VisCommandSceneHandlerCreate::Se << 252 " no graphics systems available." 212 " no graphics systems available." << 253 "\n Did you instantiate any in" 213 "\n Did you instantiate any in" << 254 " YourVisManager::RegisterGraphicsSystems()?" 214 " YourVisManager::RegisterGraphicsSystems( << 255 << G4endl; 215 command->CommandFailed(ed); << 256 } 216 return; 257 return; 217 } 258 } 218 std::size_t iGS; // Selector index. << 259 int iGS; // Selector index. 219 G4bool found = false; << 260 for (iGS = 0; iGS < nSystems; iGS++) { 220 for (iGS = 0; iGS < nSystems; ++iGS) { << 261 if (graphicsSystem.compareTo (gsl [iGS] -> GetName (), 221 const auto& gs = gsl[iGS]; << 262 G4String::ignoreCase) == 0 || 222 if (G4StrUtil::icompare(graphicsSystem, gs << 263 graphicsSystem.compareTo (gsl [iGS] -> GetNickname (), 223 found = true; << 264 G4String::ignoreCase) == 0) { 224 break; // Match found << 265 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 } 266 } 238 } 267 } 239 if (!found) { << 268 if (iGS < 0 || iGS >= nSystems) { 240 if (graphicsSystem == "NO_UI_SESSION") { << 269 // Invalid command line argument or non. 241 G4Exception << 270 // This shouldn't happen!!!!!! 242 ("G4VisCommandSceneHandlerCreate::SetNew << 271 if (verbosity >= G4VisManager::errors) { 243 "This looks like an attempt to use run- << 272 G4cout << "ERROR: G4VisCommandSceneHandlerCreate::SetNewValue:" 244 "\nYou have issued \"/vis/open\" or \"/ << 273 " invalid graphics system specified." 245 "\na parameter for the vis driver. This << 274 << 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 } 275 } 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; 276 return; 268 } 277 } 269 << 278 // Valid index. Set current graphics system in preparation for 270 // Check UI session compatibility. << 279 // 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]; 280 G4VGraphicsSystem* pSystem = gsl [iGS]; 307 << 281 fpVisManager -> SetCurrentGraphicsSystem (pSystem); 308 if (fallback && verbosity >= G4VisManager::w << 282 if (verbosity >= G4VisManager::confirmations) { 309 G4warn << "WARNING: G4VisCommandSceneHandl << 283 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 } 284 } 317 285 318 // Now deal with name of scene handler. 286 // Now deal with name of scene handler. 319 G4String nextName = NextName (); 287 G4String nextName = NextName (); 320 if (newName == "") { 288 if (newName == "") { 321 newName = nextName; 289 newName = nextName; 322 } 290 } 323 if (newName == nextName) fId++; 291 if (newName == nextName) fId++; 324 292 325 const G4SceneHandlerList& list = fpVisManage 293 const G4SceneHandlerList& list = fpVisManager -> GetAvailableSceneHandlers (); 326 std::size_t iScene; << 294 size_t iScene; 327 for (iScene = 0; iScene < list.size (); ++iS << 295 for (iScene = 0; iScene < list.size (); iScene++) { 328 G4VSceneHandler* sceneHandler = list [iSce 296 G4VSceneHandler* sceneHandler = list [iScene]; 329 if (sceneHandler -> GetName () == newName) 297 if (sceneHandler -> GetName () == newName) { 330 G4ExceptionDescription ed; << 298 if (verbosity >= G4VisManager::errors) { 331 ed << << 299 G4cout << "ERROR: Scene handler \"" << newName 332 "ERROR: Scene handler \"" << newName << 300 << "\" already exists." << G4endl; 333 << "\" already exists."; << 301 } 334 command->CommandFailed(ed); << 335 return; 302 return; 336 } 303 } 337 } 304 } 338 305 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. 306 //Create scene handler. 360 fpVisManager -> CreateSceneHandler (newName) 307 fpVisManager -> CreateSceneHandler (newName); 361 if (fpVisManager -> GetCurrentSceneHandler ( << 308 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; 309 return; 373 } << 374 310 375 if (verbosity >= G4VisManager::confirmations << 311 if (verbosity >= G4VisManager::confirmations) { 376 G4cout << "New scene handler \"" << newNam 312 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 } 313 } >> 314 >> 315 // Attach scene. >> 316 if (fpVisManager -> GetCurrentScene ()) >> 317 G4UImanager::GetUIpointer () -> ApplyCommand ("/vis/sceneHandler/attach"); >> 318 >> 319 UpdateCandidateLists (); 387 } 320 } 388 321 389 ////////////// /vis/sceneHandler/list //////// 322 ////////////// /vis/sceneHandler/list /////////////////////////////////////// 390 323 391 G4VisCommandSceneHandlerList::G4VisCommandScen 324 G4VisCommandSceneHandlerList::G4VisCommandSceneHandlerList () { 392 G4bool omitable; 325 G4bool omitable; 393 fpCommand = new G4UIcommand ("/vis/sceneHand 326 fpCommand = new G4UIcommand ("/vis/sceneHandler/list", this); >> 327 fpCommand -> SetGuidance >> 328 ("/vis/sceneHandler/list [<scene-handler-name>] [<verbosity>]"); 394 fpCommand -> SetGuidance ("Lists scene handl 329 fpCommand -> SetGuidance ("Lists scene handler(s)."); >> 330 fpCommand -> SetGuidance ("<scene-handler-name> default is \"all\""); 395 fpCommand -> SetGuidance 331 fpCommand -> SetGuidance 396 ("\"help /vis/verbose\" for definition of << 332 ("See /vis/verbose for definition of verbosity."); 397 G4UIparameter* parameter; 333 G4UIparameter* parameter; 398 parameter = new G4UIparameter("scene-handler << 334 parameter = new G4UIparameter("scene-handler-name", 's', >> 335 omitable = true); >> 336 parameter -> SetCurrentAsDefault (false); 399 parameter -> SetDefaultValue ("all"); 337 parameter -> SetDefaultValue ("all"); 400 fpCommand -> SetParameter (parameter); 338 fpCommand -> SetParameter (parameter); 401 parameter = new G4UIparameter ("verbosity", << 339 parameter = new G4UIparameter ("verbosity", 's', 402 parameter -> SetDefaultValue ("warnings"); << 340 omitable = true); >> 341 parameter -> SetCurrentAsDefault (false); >> 342 parameter -> SetDefaultValue (0); 403 fpCommand -> SetParameter (parameter); 343 fpCommand -> SetParameter (parameter); >> 344 sceneHandlerNameCommands.push_back (fpCommand); 404 } 345 } 405 346 406 G4VisCommandSceneHandlerList::~G4VisCommandSce 347 G4VisCommandSceneHandlerList::~G4VisCommandSceneHandlerList () { 407 delete fpCommand; 348 delete fpCommand; 408 } 349 } 409 350 410 G4String G4VisCommandSceneHandlerList::GetCurr << 351 G4String G4VisCommandSceneHandlerList::GetCurrentValue (G4UIcommand* command) { 411 return ""; 352 return ""; 412 } 353 } 413 354 414 void G4VisCommandSceneHandlerList::SetNewValue << 355 void G4VisCommandSceneHandlerList::SetNewValue (G4UIcommand* command, 415 G4String newValue) { << 356 G4String newValue) { 416 G4String name, verbosityString; 357 G4String name, verbosityString; 417 std::istringstream is (newValue); << 358 G4std::istrstream is ((char*)newValue.data()); 418 is >> name >> verbosityString; 359 is >> name >> verbosityString; 419 G4VisManager::Verbosity verbosity = 360 G4VisManager::Verbosity verbosity = 420 fpVisManager->GetVerbosityValue(verbosityS 361 fpVisManager->GetVerbosityValue(verbosityString); 421 const G4VSceneHandler* currentSceneHandler = << 422 fpVisManager -> GetCurrentSceneHandler (); << 423 G4String currentName; << 424 if (currentSceneHandler) currentName = curre << 425 362 426 const G4SceneHandlerList& list = fpVisManage 363 const G4SceneHandlerList& list = fpVisManager -> GetAvailableSceneHandlers (); 427 G4bool found = false; 364 G4bool found = false; 428 for (std::size_t iSH = 0; iSH < list.size () << 365 for (size_t iSH = 0; iSH < list.size (); iSH++) { 429 const G4String& iName = list [iSH] -> GetN << 430 if (name != "all") { 366 if (name != "all") { 431 if (name != iName) continue; << 367 if (name != list [iSH] -> GetName ()) continue; 432 } 368 } 433 found = true; 369 found = true; 434 if (iName == currentName) { << 370 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 371 << " (" << list [iSH] -> GetGraphicsSystem () -> GetName () << ")"; 442 if (verbosity >= G4VisManager::parameters) 372 if (verbosity >= G4VisManager::parameters) { 443 G4cout << "\n " << *(list [iSH]); 373 G4cout << "\n " << *(list [iSH]); 444 } 374 } 445 G4cout << G4endl; 375 G4cout << G4endl; 446 } 376 } 447 if (!found) { 377 if (!found) { 448 G4cout << "No scene handlers found"; 378 G4cout << "No scene handlers found"; 449 if (name != "all") { 379 if (name != "all") { 450 G4cout << " of name \"" << name << "\""; 380 G4cout << " of name \"" << name << "\""; 451 } 381 } 452 G4cout << "." << G4endl; 382 G4cout << "." << G4endl; 453 } 383 } 454 } 384 } 455 385 >> 386 ////////////// /vis/sceneHandler/remove /////////////////////////////////////// >> 387 >> 388 G4VisCommandSceneHandlerRemove::G4VisCommandSceneHandlerRemove () { >> 389 G4bool omitable, currentAsDefault; >> 390 fpCommand = new G4UIcmdWithAString ("/vis/sceneHandler/remove", this); >> 391 fpCommand -> SetGuidance ("/vis/sceneHandler/remove <scene-handler-name>"); >> 392 fpCommand -> SetGuidance ("Removes scene handlers."); >> 393 fpCommand -> SetGuidance >> 394 ("Specify scene handler by name (\"/vis/sceneHandler/list\"" >> 395 "\n to see possibilities)."); >> 396 fpCommand -> SetParameterName ("scene-handler-name", >> 397 omitable = false, >> 398 currentAsDefault = true); >> 399 sceneHandlerNameCommands.push_back (fpCommand); >> 400 } >> 401 >> 402 G4VisCommandSceneHandlerRemove::~G4VisCommandSceneHandlerRemove () { >> 403 delete fpCommand; >> 404 } >> 405 >> 406 G4String G4VisCommandSceneHandlerRemove::GetCurrentValue (G4UIcommand* command) { >> 407 G4VSceneHandler* sceneHandler = fpVisManager -> GetCurrentSceneHandler (); >> 408 if (sceneHandler) { >> 409 return sceneHandler -> GetName (); >> 410 } >> 411 else { >> 412 return "none"; >> 413 } >> 414 } >> 415 >> 416 void G4VisCommandSceneHandlerRemove::SetNewValue (G4UIcommand* command, >> 417 G4String newValue) { >> 418 >> 419 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); >> 420 >> 421 G4String& removeName = newValue; >> 422 G4VSceneHandler* currentSceneHandler = >> 423 fpVisManager -> GetCurrentSceneHandler (); >> 424 G4String currentName; >> 425 if (currentSceneHandler) { >> 426 currentName = currentSceneHandler -> GetName (); >> 427 } >> 428 >> 429 G4SceneHandlerList& list = fpVisManager -> SetAvailableSceneHandlers (); >> 430 G4SceneHandlerListIterator iSH; >> 431 for (iSH = list.begin(); iSH != list.end(); ++iSH) { >> 432 if ((*iSH) -> GetName () == removeName) break; >> 433 } >> 434 >> 435 if (iSH == list.end()) { >> 436 if (verbosity >= G4VisManager::errors) { >> 437 G4cout << "ERROR: Scene handler \"" << removeName << >> 438 "\" not found - \"/vis/sceneHandler/list\" to see possibilities." >> 439 << G4endl; >> 440 } >> 441 return; >> 442 } >> 443 >> 444 if (verbosity >= G4VisManager::confirmations) { >> 445 G4cout << "Scene handler \"" << removeName << "\" removed." << G4endl; >> 446 } >> 447 if (removeName == currentName) { >> 448 fpVisManager -> DeleteCurrentSceneHandler (); >> 449 } >> 450 else { >> 451 list.erase (iSH); >> 452 if (verbosity >= G4VisManager::confirmations) { >> 453 G4cout << "Current scene handler unchanged." << G4endl; >> 454 } >> 455 } >> 456 >> 457 UpdateCandidateLists (); >> 458 } >> 459 456 ////////////// /vis/sceneHandler/select ////// 460 ////////////// /vis/sceneHandler/select /////////////////////////////////////// 457 461 458 G4VisCommandSceneHandlerSelect::G4VisCommandSc 462 G4VisCommandSceneHandlerSelect::G4VisCommandSceneHandlerSelect () { 459 G4bool omitable; << 463 G4bool omitable, currentAsDefault; 460 fpCommand = new G4UIcmdWithAString ("/vis/sc 464 fpCommand = new G4UIcmdWithAString ("/vis/sceneHandler/select", this); 461 fpCommand -> SetGuidance ("Selects a scene h << 465 fpCommand -> SetGuidance ("/vis/sceneHandler/select [<scene-handler-name>]"); 462 fpCommand -> SetGuidance << 466 fpCommand -> SetGuidance ("Selects current scene handler."); 463 ("Makes the scene handler current. \"/vis << 467 fpCommand -> SetGuidance 464 "\n possible scene handler names."); << 468 ("Specify scene handler by name (\"/vis/sceneHandler/list\"" >> 469 "\n to see possibilities)."); 465 fpCommand -> SetParameterName ("scene-handle 470 fpCommand -> SetParameterName ("scene-handler-name", 466 omitable = false); << 471 omitable = true, >> 472 currentAsDefault = true); >> 473 sceneHandlerNameCommands.push_back (fpCommand); 467 } 474 } 468 475 469 G4VisCommandSceneHandlerSelect::~G4VisCommandS 476 G4VisCommandSceneHandlerSelect::~G4VisCommandSceneHandlerSelect () { 470 delete fpCommand; 477 delete fpCommand; 471 } 478 } 472 479 473 G4String G4VisCommandSceneHandlerSelect::GetCu << 480 G4String G4VisCommandSceneHandlerSelect::GetCurrentValue 474 return ""; << 481 (G4UIcommand* command) { >> 482 G4VSceneHandler* sceneHandler = fpVisManager -> GetCurrentSceneHandler (); >> 483 if (sceneHandler) { >> 484 return sceneHandler -> GetName (); >> 485 } >> 486 else { >> 487 return "none"; >> 488 } 475 } 489 } 476 490 477 void G4VisCommandSceneHandlerSelect::SetNewVal << 491 void G4VisCommandSceneHandlerSelect::SetNewValue (G4UIcommand* command, 478 G4String newValue) { << 492 G4String newValue) { 479 493 480 G4VisManager::Verbosity verbosity = fpVisMan 494 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); 481 495 482 G4String& selectName = newValue; 496 G4String& selectName = newValue; 483 const G4SceneHandlerList& list = fpVisManage 497 const G4SceneHandlerList& list = fpVisManager -> GetAvailableSceneHandlers (); 484 498 485 std::size_t iSH; << 499 size_t iSH; 486 for (iSH = 0; iSH < list.size (); iSH++) { 500 for (iSH = 0; iSH < list.size (); iSH++) { 487 if (list [iSH] -> GetName () == selectName 501 if (list [iSH] -> GetName () == selectName) break; 488 } 502 } 489 if (iSH < list.size ()) { 503 if (iSH < list.size ()) { 490 if (fpVisManager -> GetCurrentSceneHandler 504 if (fpVisManager -> GetCurrentSceneHandler () -> GetName () 491 == selectName) { 505 == selectName) { 492 if (verbosity >= G4VisManager::confirmat 506 if (verbosity >= G4VisManager::confirmations) { 493 G4cout << "Scene handler \"" << selectName < 507 G4cout << "Scene handler \"" << selectName << "\"" 494 << " already selected." << G4endl; 508 << " already selected." << G4endl; 495 } 509 } 496 } 510 } 497 else { 511 else { 498 if (verbosity >= G4VisManager::confirmat 512 if (verbosity >= G4VisManager::confirmations) { 499 G4cout << "Scene handler \"" << selectName < 513 G4cout << "Scene handler \"" << selectName << "\"" 500 << " being selected." << G4endl; 514 << " being selected." << G4endl; 501 } 515 } 502 fpVisManager -> SetCurrentSceneHandler ( 516 fpVisManager -> SetCurrentSceneHandler (list [iSH]); 503 } 517 } 504 } 518 } 505 else { 519 else { 506 if (verbosity >= G4VisManager::errors) { 520 if (verbosity >= G4VisManager::errors) { 507 G4warn << "ERROR: Scene handler \"" << s << 521 G4cout << "ERROR: Scene handler \"" << selectName << "\"" 508 << " not found - \"/vis/sceneHandler/li << 522 << " not found - \"/vis/sceneHandler/list\"" >> 523 "\n to see possibilities." 509 << G4endl; 524 << G4endl; 510 } 525 } 511 } 526 } 512 } 527 } 513 528