46 G4bool omitable, currentAsDefault;
48 fpCommand -> SetGuidance (
"Attaches scene to current scene handler.");
49 fpCommand -> SetGuidance
50 (
"If scene-name is omitted, current scene is attached. To see scenes and"
51 "\nscene handlers, use \"/vis/scene/list\" and \"/vis/sceneHandler/list\"");
52 fpCommand -> SetParameterName (
"scene-name",
54 currentAsDefault =
true);
63 return pScene ? pScene -> GetName () :
G4String(
"");
73 if (sceneName.length () == 0) {
76 "WARNING: No scene specified. Maybe there are no scenes available"
77 "\n yet. Please create one." <<
G4endl;
86 "ERROR: Current scene handler not defined. Please select or create one."
94 if (sceneList.empty ()) {
97 "ERROR: No valid scenes available yet. Please create one."
103 std::size_t iScene, nScenes = sceneList.size ();
104 for (iScene = 0; iScene < nScenes; ++iScene) {
105 if (sceneList [iScene] -> GetName () == sceneName)
break;
107 if (iScene < nScenes) {
108 G4Scene* pScene = sceneList [iScene];
109 pSceneHandler -> SetScene (pScene);
113 G4VViewer* pViewer = pSceneHandler -> GetCurrentViewer();
114 if (pViewer && pViewer -> GetViewParameters().IsAutoRefresh()) {
115 pViewer -> SetView ();
116 pViewer -> ClearView ();
117 pViewer -> DrawView ();
120 G4cout <<
"Scene \"" << sceneName
121 <<
"\" attached to scene handler \""
122 << pSceneHandler -> GetName () <<
123 ".\n (You may have to refresh with \"/vis/viewer/flush\" if view"
124 " is not \"auto-refresh\".)"
130 G4warn <<
"ERROR: Scene \"" << sceneName
131 <<
"\" not found. Use \"/vis/scene/list\" to see possibilities."
141 fpCommand =
new G4UIcommand (
"/vis/sceneHandler/create",
this);
142 fpCommand -> SetGuidance
143 (
"Creates an scene handler for a specific graphics system.");
144 fpCommand -> SetGuidance
145 (
"Attaches current scene, if any. (You can change attached scenes with"
146 "\n\"/vis/sceneHandler/attach\".) Invents a scene handler name if not"
147 "\nsupplied. This scene handler becomes current.");
150 's', omitable =
false);
154 for (
const auto gs: gslist) {
155 const G4String& name = gs -> GetName ();
156 candidates += name +
' ';
157 for (
const auto& nickname: gs -> GetNicknames ()) {
159 if (nickname != name) candidates += nickname +
' ';
163 parameter -> SetParameterCandidates(candidates);
164 fpCommand -> SetParameter (parameter);
166 (
"scene-handler-name",
's', omitable =
true);
167 parameter -> SetCurrentAsDefault (
true);
168 fpCommand -> SetParameter (parameter);
175G4String G4VisCommandSceneHandlerCreate::NextName () {
176 std::ostringstream oss;
177 oss <<
"scene-handler-" << fId;
186 if (graphicsSystem) {
187 graphicsSystemName = graphicsSystem -> GetName ();
192 if (gslist.size ()) {
193 graphicsSystemName = gslist [0] -> GetName ();
196 graphicsSystemName =
"none";
200 return graphicsSystemName +
" " + NextName ();
209 std::istringstream is (newValue);
210 is >> graphicsSystem >> newName;
214 std::size_t nSystems = gsl.size ();
218 "ERROR: G4VisCommandSceneHandlerCreate::SetNewValue:"
219 " no graphics systems available."
220 "\n Did you instantiate any in"
221 " YourVisManager::RegisterGraphicsSystems()?";
227 for (iGS = 0; iGS < nSystems; ++iGS) {
228 const auto& gs = gsl[iGS];
233 const auto& nicknames = gs->GetNicknames();
234 for (std::size_t i = 0; i < nicknames.size(); ++i) {
235 const auto& nickname = nicknames[i];
250 "ERROR: G4VisCommandSceneHandlerCreate::SetNewValue:"
251 "\n Invalid graphics system \""
254 <<
"\n Candidates are:";
262 G4int loopCounter = 0;
263 while (!gsl[iGS]->IsUISessionCompatible()) {
264 std::size_t iGSBeingTested = iGS;
267 G4String fallbackNickname = gsl[iGS]->GetNickname() +
"_FALLBACK";
268 for (iGS = 0; iGS < nSystems; iGS++) {
269 const auto& nicknames = gsl[iGS]->GetNicknames();
270 for (std::size_t i = 0; i < nicknames.size(); ++i) {
271 const auto& nickname = nicknames[i];
281 if (iGS >= nSystems || loopCounter >=3) {
283 ed <<
"\"" << gsl[iGSBeingTested]->GetNickname()
284 <<
"\" is not compatible with your chosen session,"
285 " and no fallback system found.";
297 G4warn <<
"WARNING: G4VisCommandSceneHandlerCreate::SetNewValue:"
298 "\n Using fallback graphics system: "
299 << pSystem -> GetName ()
301 << pSystem -> GetNickname ()
311 if (newName == nextName) fId++;
315 for (iScene = 0; iScene < list.size (); ++iScene) {
317 if (sceneHandler -> GetName () == newName) {
320 "ERROR: Scene handler \"" << newName
321 <<
"\" already exists.";
337 G4cout <<
"Graphics system set to "
338 << pSystem -> GetName ()
340 << pSystem -> GetNickname ()
347 if (
fpVisManager -> GetCurrentSceneHandler () -> GetName () != newName) {
350 "ERROR: G4VisCommandSceneHandlerCreate::SetNewValue:"
351 " Curious name mismatch."
353 <<
fpVisManager -> GetCurrentSceneHandler () -> GetName ()
354 <<
"\" is not the new name \""
356 <<
"\".\n Please report to vis coordinator.";
362 G4cout <<
"New scene handler \"" << newName <<
"\" created." <<
G4endl;
368 ed <<
"sub-command \"/vis/sceneHandler/attach\" failed.";
379 fpCommand =
new G4UIcommand (
"/vis/sceneHandler/list",
this);
380 fpCommand -> SetGuidance (
"Lists scene handler(s).");
381 fpCommand -> SetGuidance
382 (
"\"help /vis/verbose\" for definition of verbosity.");
384 parameter =
new G4UIparameter(
"scene-handler-name",
's', omitable =
true);
385 parameter -> SetDefaultValue (
"all");
386 fpCommand -> SetParameter (parameter);
387 parameter =
new G4UIparameter (
"verbosity",
's', omitable =
true);
388 parameter -> SetDefaultValue (
"warnings");
389 fpCommand -> SetParameter (parameter);
403 std::istringstream is (newValue);
404 is >> name >> verbosityString;
410 if (currentSceneHandler) currentName = currentSceneHandler->
GetName();
414 for (std::size_t iSH = 0; iSH < list.size (); ++iSH) {
415 const G4String& iName = list [iSH] -> GetName ();
417 if (name != iName)
continue;
420 if (iName == currentName) {
426 G4cout <<
" scene handler \"" << list [iSH] -> GetName () <<
"\""
427 <<
" (" << list [iSH] -> GetGraphicsSystem () -> GetName () <<
")";
429 G4cout <<
"\n " << *(list [iSH]);
434 G4cout <<
"No scene handlers found";
436 G4cout <<
" of name \"" << name <<
"\"";
447 fpCommand -> SetGuidance (
"Selects a scene handler.");
448 fpCommand -> SetGuidance
449 (
"Makes the scene handler current. \"/vis/sceneHandler/list\" to see"
450 "\n possible scene handler names.");
451 fpCommand -> SetParameterName (
"scene-handler-name",
472 for (iSH = 0; iSH < list.size (); iSH++) {
473 if (list [iSH] -> GetName () == selectName)
break;
475 if (iSH < list.size ()) {
476 if (
fpVisManager -> GetCurrentSceneHandler () -> GetName ()
479 G4cout <<
"Scene handler \"" << selectName <<
"\""
480 <<
" already selected." <<
G4endl;
485 G4cout <<
"Scene handler \"" << selectName <<
"\""
486 <<
" being selected." <<
G4endl;
493 G4warn <<
"ERROR: Scene handler \"" << selectName <<
"\""
494 <<
" not found - \"/vis/sceneHandler/list\" to see possibilities."
std::ostringstream G4ExceptionDescription
G4GLOB_DLL std::ostream G4cout
void CommandFailed(G4int errCode, G4ExceptionDescription &ed)
static G4UImanager * GetUIpointer()
const G4String & GetName() const
const G4ViewParameters & GetViewParameters() const
static G4ViewParameters fExistingVP
static G4VisManager * fpVisManager
static G4bool fThereWasAViewer
G4String GetCurrentValue(G4UIcommand *command)
G4VisCommandSceneHandlerAttach()
~G4VisCommandSceneHandlerAttach()
void SetNewValue(G4UIcommand *command, G4String newValue)
~G4VisCommandSceneHandlerCreate()
G4String GetCurrentValue(G4UIcommand *command)
void SetNewValue(G4UIcommand *command, G4String newValue)
G4VisCommandSceneHandlerCreate()
G4String GetCurrentValue(G4UIcommand *command)
G4VisCommandSceneHandlerList()
~G4VisCommandSceneHandlerList()
void SetNewValue(G4UIcommand *command, G4String newValue)
G4VisCommandSceneHandlerSelect()
~G4VisCommandSceneHandlerSelect()
void SetNewValue(G4UIcommand *command, G4String newValue)
G4String GetCurrentValue(G4UIcommand *command)
void PrintAvailableGraphicsSystems(Verbosity, std::ostream &=G4cout) const
G4VViewer * GetCurrentViewer() const
static Verbosity GetVerbosity()
static Verbosity GetVerbosityValue(const G4String &)
G4int icompare(std::string_view lhs, std::string_view rhs)
Case insensitive comparison of two strings.
void strip(G4String &str, char ch=' ')
Remove leading and trailing characters from string.
G4bool contains(const G4String &str, std::string_view ss)
Check if a string contains a given substring.