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.");
149 parameter =
new G4UIparameter (
"graphics-system-name",
's', omitable =
true);
150 parameter -> SetCurrentAsDefault(
true);
153 G4String candidates =
"NO_UI_SESSION ";
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);
202 std::istringstream is (newValue);
203 is >> graphicsSystem >> newName;
207 std::size_t nSystems = gsl.size ();
211 "ERROR: G4VisCommandSceneHandlerCreate::SetNewValue:"
212 " no graphics systems available."
213 "\n Did you instantiate any in"
214 " YourVisManager::RegisterGraphicsSystems()?";
220 for (iGS = 0; iGS < nSystems; ++iGS) {
221 const auto& gs = gsl[iGS];
226 const auto& nicknames = gs->GetNicknames();
227 for (
const auto& nickname : nicknames) {
239 if (graphicsSystem ==
"NO_UI_SESSION") {
241 (
"G4VisCommandSceneHandlerCreate::SetNewValue",
"visman1001",
JustWarning,
242 "This looks like an attempt to use run-time vis driver selection."
243 "\nYou have issued \"/vis/open\" or \"/vis/sceneHandler/create\" without"
244 "\na parameter for the vis driver. This is allowed only if you instantiate"
245 "\na UI session, and only if it is instantiated *before* the first"
246 "\n\"/vis/open\" command. So:"
247 "\na) It is not allowed in batch mode. If you really want to create"
248 "\n some graphics with a file-writing driver in batch mode, you must"
249 "\n request a specific driver on the \"/vis/open\" command line, e.g.,"
250 "\n \"/vis/open TSG_OFFSCREEN\". See, examples/basic/B1/tsg_offscreen.mac."
251 "\nb) If you want to exploit this feature in interactive mode, simply move"
252 "\n the instantiation of the UI session earlier. In any case, this is good"
253 "\n practice in order to capture output in a GUI session.");
259 "ERROR: G4VisCommandSceneHandlerCreate::SetNewValue:"
260 "\n Invalid graphics system \""
263 <<
"\n Candidates are:";
264 fpVisManager->PrintAvailableGraphicsSystems(verbosity,ed);
271 G4int loopCounter = 0;
272 while (!gsl[iGS]->IsUISessionCompatible()) {
273 std::size_t iGSBeingTested = iGS;
276 G4String fallbackNickname = gsl[iGS]->GetNickname() +
"_FALLBACK";
277 for (iGS = 0; iGS < nSystems; iGS++) {
278 const auto& nicknames = gsl[iGS]->GetNicknames();
279 for (
const auto& nickname : nicknames) {
289 if (iGS >= nSystems || loopCounter >=3) {
291 ed <<
"\"" << gsl[iGSBeingTested]->GetNickname()
292 <<
"\" is not compatible with the session,"
293 "\nand no fallback system found. Make sure your session is"
294 "\ninstantiated _before_ you create a graphics system.";
295 G4Exception(
"G4VisCommandSceneHandlerCreate::SetNewValue",
307 G4warn <<
"WARNING: G4VisCommandSceneHandlerCreate::SetNewValue:"
308 "\n Using fallback graphics system: "
309 << pSystem -> GetName ()
311 << pSystem -> GetNickname ()
321 if (newName == nextName) fId++;
325 for (iScene = 0; iScene < list.size (); ++iScene) {
327 if (sceneHandler -> GetName () == newName) {
330 "ERROR: Scene handler \"" << newName
331 <<
"\" already exists.";
349 G4cout <<
"Graphics system set to "
350 << pSystem -> GetName ()
352 << pSystem -> GetNickname ()
359 if (
fpVisManager -> GetCurrentSceneHandler () -> GetName () != newName) {
362 "ERROR: G4VisCommandSceneHandlerCreate::SetNewValue:"
363 " Curious name mismatch."
365 <<
fpVisManager -> GetCurrentSceneHandler () -> GetName ()
366 <<
"\" is not the new name \""
368 <<
"\".\n Please report to vis coordinator.";
374 G4cout <<
"New scene handler \"" << newName <<
"\" created." <<
G4endl;
380 ed <<
"sub-command \"/vis/sceneHandler/attach\" failed.";
415 std::istringstream is (newValue);
416 is >> name >> verbosityString;
422 if (currentSceneHandler) currentName = currentSceneHandler->
GetName();
426 for (
const auto* iSH : list) {
427 const G4String& iName = iSH -> GetName ();
429 if (name != iName)
continue;
432 if (iName == currentName) {
438 G4cout <<
" scene handler \"" << iSH -> GetName () <<
"\""
439 <<
" (" << iSH -> GetGraphicsSystem () -> GetName () <<
")";
446 G4cout <<
"No scene handlers found";
448 G4cout <<
" of name \"" << name <<
"\"";