197 {
198
200
201 G4String graphicsSystem, newName;
202 std::istringstream is (newValue);
203 is >> graphicsSystem >> newName;
204
205 const G4GraphicsSystemList& gsl =
207 std::size_t nSystems = gsl.size ();
208 if (nSystems <= 0) {
210 ed <<
211 "ERROR: G4VisCommandSceneHandlerCreate::SetNewValue:"
212 " no graphics systems available."
213 "\n Did you instantiate any in"
214 " YourVisManager::RegisterGraphicsSystems()?";
216 return;
217 }
218 std::size_t iGS;
220 for (iGS = 0; iGS < nSystems; ++iGS) {
221 const auto& gs = gsl[iGS];
223 found = true;
224 break;
225 } else {
226 const auto& nicknames = gs->GetNicknames();
227 for (const auto& nickname : nicknames) {
229 found = true;
230 break;
231 }
232 }
233 if (found) {
234 break;
235 }
236 }
237 }
238 if (!found) {
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.");
254 return;
255 }
256
258 ed <<
259 "ERROR: G4VisCommandSceneHandlerCreate::SetNewValue:"
260 "\n Invalid graphics system \""
261 << graphicsSystem
262 << "\" requested."
263 << "\n Candidates are:";
264 fpVisManager->PrintAvailableGraphicsSystems(verbosity,ed);
266 return;
267 }
268
269
271 G4int loopCounter = 0;
272 while (!gsl[iGS]->IsUISessionCompatible()) {
273 std::size_t iGSBeingTested = iGS;
274
275 fallback = false;
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) {
281 fallback = true;
282 break;
283 }
284 }
285 if (fallback) {
286 break;
287 }
288 }
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",
297 return;
298 }
299
300 ++loopCounter;
301 }
302
303
304 G4VGraphicsSystem* pSystem = gsl [iGS];
305
307 G4warn <<
"WARNING: G4VisCommandSceneHandlerCreate::SetNewValue:"
308 "\n Using fallback graphics system: "
309 << pSystem -> GetName ()
310 << " ("
311 << pSystem -> GetNickname ()
312 << ')'
314 }
315
316
317 G4String nextName = NextName ();
318 if (newName == "") {
319 newName = nextName;
320 }
321 if (newName == nextName) fId++;
322
323 const G4SceneHandlerList& list =
fpVisManager -> GetAvailableSceneHandlers ();
324 std::size_t iScene;
325 for (iScene = 0; iScene < list.size (); ++iScene) {
326 G4VSceneHandler* sceneHandler = list [iScene];
327 if (sceneHandler -> GetName () == newName) {
329 ed <<
330 "ERROR: Scene handler \"" << newName
331 << "\" already exists.";
333 return;
334 }
335 }
336
337
343 }
344
345
346
349 G4cout <<
"Graphics system set to "
350 << pSystem -> GetName ()
351 << " ("
352 << pSystem -> GetNickname ()
353 << ')'
355 }
356
357
359 if (
fpVisManager -> GetCurrentSceneHandler () -> GetName () != newName) {
361 ed <<
362 "ERROR: G4VisCommandSceneHandlerCreate::SetNewValue:"
363 " Curious name mismatch."
364 "\n Current name \""
365 <<
fpVisManager -> GetCurrentSceneHandler () -> GetName ()
366 << "\" is not the new name \""
367 << newName
368 << "\".\n Please report to vis coordinator.";
370 return;
371 }
372
374 G4cout <<
"New scene handler \"" << newName <<
"\" created." <<
G4endl;
375
378 if (errorCode) {
380 ed << "sub-command \"/vis/sceneHandler/attach\" failed.";
382 return;
383 }
384 }
385}
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
G4GLOB_DLL std::ostream G4cout
void CommandFailed(G4int errCode, G4ExceptionDescription &ed)
static G4UImanager * GetUIpointer()
static G4ViewParameters fExistingVP
static G4SceneTreeItem fExistingSceneTree
static G4bool fThereWasAViewer
G4int icompare(std::string_view lhs, std::string_view rhs)
Case insensitive comparison of two strings.