Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4VisCommandsScene.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//
27
28// /vis/scene commands - John Allison 9th August 1998
29
30#include "G4VisCommandsScene.hh"
31
32#include "G4VisManager.hh"
34#include "G4RunManager.hh"
36#include "G4Run.hh"
38#include "G4ApplicationState.hh"
39#include "G4UImanager.hh"
40#include "G4UIcommand.hh"
41#include "G4UIcmdWithAString.hh"
43#include "G4ios.hh"
44#include <sstream>
45
46#define G4warn G4cout
47
49
51
53 const G4Scene* pScene = fpVisManager -> GetCurrentScene ();
54 G4String currentSceneName = "none";
55 if (pScene) currentSceneName = pScene -> GetName ();
56 return currentSceneName;
57}
58
59////////////// /vis/scene/activateModel ////////////////////////////
60
62 G4bool omitable;
63 fpCommand = new G4UIcommand ("/vis/scene/activateModel", this);
64 fpCommand -> SetGuidance
65 ("Activate or de-activate model.");
66 fpCommand -> SetGuidance
67 ("Attempts to match search string to name of model - use unique sub-string.");
68 fpCommand -> SetGuidance
69 ("Use \"/vis/scene/list\" to see model names.");
70 fpCommand -> SetGuidance
71 ("If name == \"all\" (default), all models are activated.");
72 G4UIparameter* parameter;
73 parameter = new G4UIparameter ("search-string", 's', omitable = true);
74 parameter -> SetDefaultValue ("all");
75 fpCommand -> SetParameter (parameter);
76 parameter = new G4UIparameter ("activate", 'b', omitable = true);
77 parameter -> SetDefaultValue (true);
78 fpCommand -> SetParameter (parameter);
79}
80
82 delete fpCommand;
83}
84
86 return "";
87}
88
90 G4String newValue) {
91
93
94 G4String searchString, activateString;
95 std::istringstream is (newValue);
96 is >> searchString >> activateString;
97 G4bool activate = G4UIcommand::ConvertToBool(activateString);
98
100 if (!pScene) {
101 if (verbosity >= G4VisManager::errors) {
102 G4warn << "ERROR: No current scene. Please create one." << G4endl;
103 }
104 return;
105 }
106
108 if (!pSceneHandler) {
109 if (verbosity >= G4VisManager::errors) {
110 G4warn << "ERROR: No current sceneHandler. Please create one." << G4endl;
111 }
112 return;
113 }
114
115 if (searchString == "all" && !activate) {
116 if (verbosity >= G4VisManager::warnings) {
117 G4warn <<
118 "WARNING: You are not allowed to de-activate all models."
119 "\n Command ignored."
120 << G4endl;
121 }
122 return;
123 }
124
125 G4bool any = false;
126
127 std::vector<G4Scene::Model>& runDurationModelList =
128 pScene->SetRunDurationModelList();
129 for (size_t i = 0; i < runDurationModelList.size(); i++) {
130 const G4String& modelName =
131 runDurationModelList[i].fpModel->GetGlobalDescription();
132 if (searchString == "all" || modelName.find(searchString)
133 != std::string::npos) {
134 any = true;
135 runDurationModelList[i].fActive = activate;
136 if (verbosity >= G4VisManager::warnings) {
137 G4warn << "Model \"" << modelName;
138 if (activate) G4warn << "\" activated.";
139 else G4warn << "\" de-activated.";
140 G4warn << G4endl;
141 }
142 }
143 }
144
145 std::vector<G4Scene::Model>& endOfEventModelList =
146 pScene->SetEndOfEventModelList();
147 for (size_t i = 0; i < endOfEventModelList.size(); i++) {
148 const G4String& modelName =
149 endOfEventModelList[i].fpModel->GetGlobalDescription();
150 if (searchString == "all" || modelName.find(searchString)
151 != std::string::npos) {
152 any = true;
153 endOfEventModelList[i].fActive = activate;
154 if (verbosity >= G4VisManager::warnings) {
155 G4warn << "Model \"" << modelName;
156 if (activate) G4warn << "\" activated.";
157 else G4warn << "\" de-activated.";
158 G4warn << G4endl;
159 }
160 }
161 }
162
163 std::vector<G4Scene::Model>& endOfRunModelList =
164 pScene->SetEndOfRunModelList();
165 for (size_t i = 0; i < endOfRunModelList.size(); i++) {
166 const G4String& modelName =
167 endOfRunModelList[i].fpModel->GetGlobalDescription();
168 if (searchString == "all" || modelName.find(searchString)
169 != std::string::npos) {
170 any = true;
171 endOfRunModelList[i].fActive = activate;
172 if (verbosity >= G4VisManager::warnings) {
173 G4warn << "Model \"" << modelName;
174 if (activate) G4warn << "\" activated.";
175 else G4warn << "\" de-activated.";
176 G4warn << G4endl;
177 }
178 }
179 }
180
181 if (!any) {
182 if (verbosity >= G4VisManager::warnings) {
183 G4warn << "WARNING: No match found." << G4endl;
184 }
185 return;
186 }
187
189}
190
191////////////// /vis/scene/create ///////////////////////////////////////
192
194 G4bool omitable;
195 fpCommand = new G4UIcmdWithAString ("/vis/scene/create", this);
196 fpCommand -> SetGuidance
197 ("Creates an empty scene.");
198 fpCommand -> SetGuidance
199 ("Invents a name if not supplied. This scene becomes current.");
200 fpCommand -> SetParameterName ("scene-name", omitable = true);
201}
202
204 delete fpCommand;
205}
206
207G4String G4VisCommandSceneCreate::NextName () {
208 std::ostringstream oss;
209 oss << "scene-" << fId;
210 return oss.str();
211}
212
214 return "";
215}
216
218
220
221 G4String& newName = newValue;
222 G4String nextName = NextName ();
223
224 if (newName == "") {
225 newName = nextName;
226 }
227 if (newName == nextName) fId++;
228
229 G4SceneList& sceneList = fpVisManager -> SetSceneList ();
230 std::size_t iScene, nScenes = sceneList.size ();
231 for (iScene = 0; iScene < nScenes; ++iScene) {
232 if (sceneList [iScene] -> GetName () == newName) break;
233 }
234 if (iScene < nScenes) {
235 if (verbosity >= G4VisManager::warnings) {
236 G4warn << "WARNING: Scene \"" << newName << "\" already exists."
237 << "\n New scene not created."
238 << G4endl;
239 }
240 } else {
241
242 // Add empty scene data object to list...
243 G4Scene* pScene = new G4Scene (newName);
244 sceneList.push_back (pScene);
245 fpVisManager -> SetCurrentScene (pScene);
246
247 if (verbosity >= G4VisManager::confirmations) {
248 G4cout << "New empty scene \"" << newName << "\" created." << G4endl;
249 }
250 }
251}
252
253////////////// /vis/scene/endOfEventAction ////////////////////////////
254
256 G4bool omitable;
257 fpCommand = new G4UIcommand ("/vis/scene/endOfEventAction", this);
258 fpCommand -> SetGuidance
259 ("Accumulate or refresh the viewer for each new event.");
260 fpCommand -> SetGuidance
261 ("\"accumulate\": viewer accumulates hits, etc., event by event, or");
262 fpCommand -> SetGuidance
263 ("\"refresh\": viewer shows them at end of event or, for direct-screen"
264 "\n viewers, refreshes the screen just before drawing the next event.");
265 G4UIparameter* parameter;
266 parameter = new G4UIparameter ("action", 's', omitable = true);
267 parameter -> SetParameterCandidates ("accumulate refresh");
268 parameter -> SetDefaultValue ("refresh");
269 fpCommand -> SetParameter (parameter);
270 parameter = new G4UIparameter ("maxNumber", 'i', omitable = true);
271 parameter -> SetDefaultValue (100);
272 parameter -> SetGuidance
273 ("Maximum number of events kept. Unlimited if negative.");
274 fpCommand -> SetParameter (parameter);
275}
276
278 delete fpCommand;
279}
280
282 return "";
283}
284
286 G4String newValue) {
287
289
290 G4String action;
291 G4int maxNumberOfKeptEvents;
292 std::istringstream is (newValue);
293 is >> action >> maxNumberOfKeptEvents;
294
296 if (!pScene) {
297 if (verbosity >= G4VisManager::errors) {
298 G4warn << "ERROR: No current scene. Please create one." << G4endl;
299 }
300 return;
301 }
302
304 if (!pSceneHandler) {
305 if (verbosity >= G4VisManager::errors) {
306 G4warn << "ERROR: No current sceneHandler. Please create one." << G4endl;
307 }
308 return;
309 }
310
311 if (action == "accumulate") {
312 pScene->SetRefreshAtEndOfEvent(false);
313 pScene->SetMaxNumberOfKeptEvents(maxNumberOfKeptEvents);
314 }
315 else if (action == "refresh") {
316 if (!pScene->GetRefreshAtEndOfRun()) {
317 if (verbosity >= G4VisManager::errors) {
318 G4warn <<
319 "ERROR: Cannot refresh events unless runs refresh too."
320 "\n Use \"/vis/scene/endOfRun refresh\"."
321 << G4endl;
322 }
323 } else {
324 pScene->SetRefreshAtEndOfEvent(true);
325 pScene->SetMaxNumberOfKeptEvents(maxNumberOfKeptEvents);
326 pSceneHandler->SetMarkForClearingTransientStore(true);
327 }
328 }
329 else {
330 if (verbosity >= G4VisManager::errors) {
331 G4warn <<
332 "ERROR: unrecognised parameter \"" << action << "\"."
333 << G4endl;
334 }
335 return;
336 }
337
338 // Change of transients behaviour, so...
340
341 // Are there any events currently kept...
342 size_t nCurrentlyKept = 0;
344 if(runManager)
345 {
346 const G4Run* currentRun = runManager->GetCurrentRun();
347 if(currentRun)
348 {
349 const std::vector<const G4Event*>* events = currentRun->GetEventVector();
350 if(events)
351 nCurrentlyKept = events->size();
352 }
353 }
354
355 if (verbosity >= G4VisManager::confirmations) {
356 G4cout << "End of event action set to ";
357 if (pScene->GetRefreshAtEndOfEvent()) G4cout << "\"refresh\".";
358 else {
359 G4cout << "\"accumulate\"."
360 "\n Maximum number of events to be kept: "
361 << maxNumberOfKeptEvents
362 << " (unlimited if negative)."
363 "\n This may be changed with, e.g., "
364 "\"/vis/scene/endOfEventAction accumulate 1000\".";
365 }
366 G4cout << G4endl;
367 }
368
369 if (!pScene->GetRefreshAtEndOfEvent() &&
370 maxNumberOfKeptEvents != 0 &&
371 verbosity >= G4VisManager::warnings) {
372 G4warn << "WARNING: ";
373 if (nCurrentlyKept) {
374 G4warn <<
375 "\n There are currently " << nCurrentlyKept
376 << " events kept for refreshing and/or reviewing.";
377 } else {
378 G4warn << "The vis manager will keep ";
379 if (maxNumberOfKeptEvents < 0) G4warn << "an unlimited number of";
380 else G4warn << "up to " << maxNumberOfKeptEvents;
381 G4warn << " events.";
382 if (maxNumberOfKeptEvents > 1 || maxNumberOfKeptEvents < 0)
383 G4warn <<
384 "\n This may use a lot of memory."
385 "\n It may be changed with, e.g., "
386 "\"/vis/scene/endOfEventAction accumulate 10\".";
387 }
388 G4warn << G4endl;
389 }
390}
391
392////////////// /vis/scene/endOfRunAction ////////////////////////////
393
395 G4bool omitable;
396 fpCommand = new G4UIcmdWithAString ("/vis/scene/endOfRunAction", this);
397 fpCommand -> SetGuidance
398 ("Accumulate or refresh the viewer for each new run.");
399 fpCommand -> SetGuidance
400 ("\"accumulate\": viewer accumulates hits, etc., run by run, or");
401 fpCommand -> SetGuidance
402 ("\"refresh\": viewer shows them at end of run or, for direct-screen"
403 "\n viewers, refreshes the screen just before drawing the first"
404 "\n event of the next run.");
405 fpCommand -> SetGuidance ("The detector remains or is redrawn.");
406 fpCommand -> SetParameterName ("action", omitable = true);
407 fpCommand -> SetCandidates ("accumulate refresh");
408 fpCommand -> SetDefaultValue ("refresh");
409}
410
412 delete fpCommand;
413}
414
416 return "";
417}
418
420 G4String newValue) {
421
423
424 G4String action;
425 std::istringstream is (newValue);
426 is >> action;
427
429 if (!pScene) {
430 if (verbosity >= G4VisManager::errors) {
431 G4warn << "ERROR: No current scene. Please create one." << G4endl;
432 }
433 return;
434 }
435
437 if (!pSceneHandler) {
438 if (verbosity >= G4VisManager::errors) {
439 G4warn << "ERROR: No current sceneHandler. Please create one." << G4endl;
440 }
441 return;
442 }
443
444 if (action == "accumulate") {
445 if (pScene->GetRefreshAtEndOfEvent()) {
446 if (verbosity >= G4VisManager::errors) {
447 G4warn <<
448 "ERROR: Cannot accumulate runs unless events accumulate too."
449 "\n Use \"/vis/scene/endOfEventAction accumulate\"."
450 << G4endl;
451 }
452 }
453 else {
454 pScene->SetRefreshAtEndOfRun(false);
455 }
456 }
457 else if (action == "refresh") {
458 pScene->SetRefreshAtEndOfRun(true);
459 pSceneHandler->SetMarkForClearingTransientStore(true);
460 }
461 else {
462 if (verbosity >= G4VisManager::errors) {
463 G4warn <<
464 "ERROR: unrecognised parameter \"" << action << "\"."
465 << G4endl;
466 }
467 return;
468 }
469
470 // Change of transients behaviour, so...
472
473 if (verbosity >= G4VisManager::confirmations) {
474 G4cout << "End of run action set to \"";
475 if (pScene->GetRefreshAtEndOfRun()) G4cout << "refresh";
476 else G4cout << "accumulate";
477 G4cout << "\"" << G4endl;
478 }
479}
480
481////////////// /vis/scene/list ///////////////////////////////////////
482
484 G4bool omitable;
485 fpCommand = new G4UIcommand ("/vis/scene/list", this);
486 fpCommand -> SetGuidance ("Lists scene(s).");
487 fpCommand -> SetGuidance
488 ("\"help /vis/verbose\" for definition of verbosity.");
489 G4UIparameter* parameter;
490 parameter = new G4UIparameter ("scene-name", 's', omitable = true);
491 parameter -> SetDefaultValue ("all");
492 fpCommand -> SetParameter (parameter);
493 parameter = new G4UIparameter ("verbosity", 's', omitable = true);
494 parameter -> SetDefaultValue ("warnings");
495 fpCommand -> SetParameter (parameter);
496}
497
499 delete fpCommand;
500}
501
503 return "";
504}
505
507 G4String name, verbosityString;
508 std::istringstream is (newValue);
509 is >> name >> verbosityString;
510 G4VisManager::Verbosity verbosity =
511 fpVisManager->GetVerbosityValue(verbosityString);
512 const G4Scene* currentScene = fpVisManager -> GetCurrentScene ();
513 G4String currentName;
514 if (currentScene) currentName = currentScene->GetName();
515
516 G4SceneList& sceneList = fpVisManager -> SetSceneList ();
517 std::size_t iScene, nScenes = sceneList.size ();
518 G4bool found = false;
519 for (iScene = 0; iScene < nScenes; ++iScene) {
520 G4Scene* pScene = sceneList [iScene];
521 const G4String& iName = pScene -> GetName ();
522 if (name != "all") {
523 if (name != iName) continue;
524 }
525 found = true;
526 if (iName == currentName) {
527 G4cout << " (current)";
528 }
529 else {
530 G4cout << " ";
531 }
532 G4cout << " scene \"" << iName << "\"";
533 if (verbosity >= G4VisManager::warnings) {
534 std::size_t i;
535 G4cout << "\n Run-duration models:";
536 std::size_t nRunModels = pScene -> GetRunDurationModelList ().size ();
537 if (nRunModels == 0) {
538 G4cout << " none.";
539 }
540 for (i = 0; i < nRunModels; ++i) {
541 if (pScene -> GetRunDurationModelList()[i].fActive)
542 G4cout << "\n Active: ";
543 else G4cout << "\n Inactive: ";
544 G4VModel* pModel = pScene -> GetRunDurationModelList()[i].fpModel;
545 G4cout << pModel -> GetGlobalDescription ();
546 }
547 G4cout << "\n End-of-event models:";
548 std::size_t nEOEModels = pScene -> GetEndOfEventModelList ().size ();
549 if (nEOEModels == 0) {
550 G4cout << " none.";
551 }
552 for (i = 0; i < nEOEModels; ++i) {
553 if (pScene -> GetEndOfEventModelList()[i].fActive)
554 G4cout << "\n Active: ";
555 else G4cout << "\n Inactive: ";
556 G4VModel* pModel = pScene -> GetEndOfEventModelList()[i].fpModel;
557 G4cout << pModel -> GetGlobalDescription ();
558 }
559 G4cout << "\n End-of-run models:";
560 std::size_t nEORModels = pScene -> GetEndOfRunModelList ().size ();
561 if (nEORModels == 0) {
562 G4cout << " none.";
563 }
564 for (i = 0; i < nEORModels; ++i) {
565 if (pScene -> GetEndOfRunModelList()[i].fActive)
566 G4cout << "\n Active: ";
567 else G4cout << "\n Inactive: ";
568 G4VModel* pModel = pScene -> GetEndOfRunModelList()[i].fpModel;
569 G4cout << pModel -> GetGlobalDescription ();
570 }
571 }
572 if (verbosity >= G4VisManager::parameters) {
573 G4cout << "\n " << *sceneList [iScene];
574 }
575 G4cout << G4endl;
576 }
577 if (!found) {
578 G4warn << "No scenes found";
579 if (name != "all") {
580 G4warn << " of name \"" << name << "\"";
581 }
582 G4warn << "." << G4endl;
583 }
584}
585
586////////////// /vis/scene/notifyHandlers /////////////////////////
587
589 G4bool omitable;
590 fpCommand = new G4UIcommand ("/vis/scene/notifyHandlers", this);
591 fpCommand -> SetGuidance
592 ("Notifies scene handlers and forces re-rendering.");
593 fpCommand -> SetGuidance
594 ("Notifies the handler(s) of the specified scene and forces a"
595 "\nreconstruction of any graphical databases."
596 "\nClears and refreshes all viewers of current scene."
597 "\n The default action \"refresh\" does not issue \"update\" (see"
598 "\n /vis/viewer/update)."
599 "\nIf \"flush\" is specified, it issues an \"update\" as well as"
600 "\n \"refresh\" - \"update\" and initiates post-processing"
601 "\n for graphics systems which need it.");
602 fpCommand -> SetGuidance
603 ("The default for <scene-name> is the current scene name.");
604 fpCommand -> SetGuidance
605 ("This command does not change current scene, scene handler or viewer.");
606 G4UIparameter* parameter;
607 parameter = new G4UIparameter ("scene-name", 's',
608 omitable = true);
609 parameter -> SetCurrentAsDefault(true);
610 fpCommand -> SetParameter (parameter);
611 parameter = new G4UIparameter ("refresh-flush", 's',
612 omitable = true);
613 parameter -> SetDefaultValue("refresh");
614 parameter -> SetParameterCandidates("r refresh f flush");
615 fpCommand -> SetParameter (parameter);
616}
617
619 delete fpCommand;
620}
621
623 return CurrentSceneName ();
624}
625
627 G4String newValue) {
628
630
631 G4String sceneName, refresh_flush;
632 std::istringstream is (newValue);
633 is >> sceneName >> refresh_flush;
634 G4bool flush = false;
635 if (refresh_flush[0] == 'f') flush = true;
636
637 const G4SceneList& sceneList = fpVisManager -> GetSceneList ();
638 G4SceneHandlerList& sceneHandlerList =
639 fpVisManager -> SetAvailableSceneHandlers ();
640
641 // Check scene name.
642 const std::size_t nScenes = sceneList.size ();
643 std::size_t iScene;
644 for (iScene = 0; iScene < nScenes; ++iScene) {
645 G4Scene* scene = sceneList [iScene];
646 if (sceneName == scene -> GetName ()) break;
647 }
648 if (iScene >= nScenes ) {
649 if (verbosity >= G4VisManager::warnings) {
650 G4warn << "WARNING: Scene \"" << sceneName << "\" not found."
651 "\n /vis/scene/list to see scenes."
652 << G4endl;
653 }
654 return;
655 }
656
657 // Store current context...
658 G4VSceneHandler* pCurrentSceneHandler =
659 fpVisManager -> GetCurrentSceneHandler();
660 if (!pCurrentSceneHandler) {
661 if (verbosity >= G4VisManager::warnings) {
662 G4warn << "WARNING: No current scene handler."
663 << G4endl;
664 }
665 return;
666 }
667 G4VViewer* pCurrentViewer = fpVisManager -> GetCurrentViewer();
668 if (!pCurrentViewer) {
669 if (verbosity >= G4VisManager::warnings) {
670 G4warn << "WARNING: No current viewer."
671 << G4endl;
672 }
673 return;
674 }
675 G4Scene* pCurrentScene = fpVisManager -> GetCurrentScene();
676 if (!pCurrentScene) {
677 if (verbosity >= G4VisManager::warnings) {
678 G4warn << "WARNING: No current scene."
679 << G4endl;
680 }
681 return;
682 }
683
684 G4VisManager::Verbosity currentVerbosity = fpVisManager -> GetVerbosity();
685
686 // Suppress messages during this process (only print errors)...
687 //fpVisManager -> SetVerboseLevel(G4VisManager::errors);
688
689 // For each scene handler, if it contains the scene, clear and
690 // rebuild the graphical database, then for each viewer set (make
691 // current), clear, (re)draw, and show.
692 const std::size_t nSceneHandlers = sceneHandlerList.size ();
693 for (std::size_t iSH = 0; iSH < nSceneHandlers; ++iSH) {
694 G4VSceneHandler* aSceneHandler = sceneHandlerList [iSH];
695 G4Scene* aScene = aSceneHandler -> GetScene ();
696 if (aScene) {
697 const G4String& aSceneName = aScene -> GetName ();
698 if (sceneName == aSceneName) {
699 aScene->CalculateExtent(); // Check and recalculate extent
700 G4ViewerList& viewerList = aSceneHandler -> SetViewerList ();
701 const std::size_t nViewers = viewerList.size ();
702 for (std::size_t iV = 0; iV < nViewers; ++iV) {
703 G4VViewer* aViewer = viewerList [iV];
704 // Force rebuild of graphical database, if any.
705 aViewer -> NeedKernelVisit();
706 if (aViewer->GetViewParameters().IsAutoRefresh()) {
707 aSceneHandler -> SetCurrentViewer (aViewer);
708 // Ensure consistency of vis manager...
709 fpVisManager -> SetCurrentViewer(aViewer);
710 fpVisManager -> SetCurrentSceneHandler(aSceneHandler);
711 fpVisManager -> SetCurrentScene(aScene);
712 aViewer -> SetView ();
713 aViewer -> ClearView ();
714 aViewer -> DrawView ();
715 if (flush) aViewer -> ShowView ();
716 if (verbosity >= G4VisManager::confirmations) {
717 G4cout << "Viewer \"" << aViewer -> GetName ()
718 << "\" of scene handler \"" << aSceneHandler -> GetName ()
719 << "\"\n ";
720 if (flush) G4cout << "flushed";
721 else G4cout << "refreshed";
722 G4cout << " at request of scene \"" << sceneName
723 << "\"." << G4endl;
724 }
725 } else {
726 if (verbosity >= G4VisManager::confirmations) {
727 G4cout << "NOTE: The scene, \""
728 << sceneName
729 << "\", of viewer \""
730 << aViewer -> GetName ()
731 << "\"\n of scene handler \""
732 << aSceneHandler -> GetName ()
733 << "\" has changed. To see effect,"
734 << "\n \"/vis/viewer/select "
735 << aViewer -> GetShortName ()
736 << "\" and \"/vis/viewer/rebuild\"."
737 << G4endl;
738 }
739 }
740 }
741 }
742 }
743 else {
744 if (verbosity >= G4VisManager::warnings) {
745 G4warn << "WARNING: G4VisCommandSceneNotifyHandlers: scene handler \""
746 << aSceneHandler->GetName()
747 << "\" has a null scene."
748 << G4endl;
749 }
750 }
751 }
752
753 // Reclaim original context - but set viewer first, then scene
754 // handler, because the latter might have been created very recently
755 // and, not yet having a viewer, the current viewer will,
756 // temporarily, refer to another scene handler. SetCurrentViewer
757 // actually resets the scene handler, which is what we don't want,
758 // so we set it again on the next line...
759 fpVisManager -> SetCurrentViewer(pCurrentViewer);
760 fpVisManager -> SetCurrentSceneHandler(pCurrentSceneHandler);
761 fpVisManager -> SetCurrentScene(pCurrentScene);
762 fpVisManager -> SetVerboseLevel(currentVerbosity);
763 // Take care of special case of scene handler with no viewer yet.
764 if (pCurrentSceneHandler) {
765 G4ViewerList& viewerList = pCurrentSceneHandler -> SetViewerList ();
766 const std::size_t nViewers = viewerList.size ();
767 if (nViewers) {
768 pCurrentSceneHandler -> SetCurrentViewer (pCurrentViewer);
769 // JA: I don't think we need this. SetView will be called when needed.
770 // if (pCurrentViewer && pCurrentSceneHandler->GetScene()) {
771 // pCurrentViewer -> SetView ();
772 // }
773 }
774 }
775}
776
777////////////// /vis/scene/removeModel ////////////////////////////
778
780 G4bool omitable;
781 fpCommand = new G4UIcommand ("/vis/scene/removeModel", this);
782 fpCommand -> SetGuidance("Remove model.");
783 fpCommand -> SetGuidance
784 ("Attempts to match search string to name of model - use unique sub-string.");
785 fpCommand -> SetGuidance
786 ("Use \"/vis/scene/list\" to see model names.");
787 G4UIparameter* parameter;
788 parameter = new G4UIparameter ("search-string", 's', omitable = false);
789 fpCommand -> SetParameter (parameter);
790}
791
793 delete fpCommand;
794}
795
797 return "";
798}
799
801 G4String newValue) {
802
804
805 G4String searchString;
806 std::istringstream is (newValue);
807 is >> searchString;
808
810 if (!pScene) {
811 if (verbosity >= G4VisManager::errors) {
812 G4warn << "ERROR: No current scene. Please create one." << G4endl;
813 }
814 return;
815 }
816
818 if (!pSceneHandler) {
819 if (verbosity >= G4VisManager::errors) {
820 G4warn << "ERROR: No current sceneHandler. Please create one." << G4endl;
821 }
822 return;
823 }
824
825 G4bool any = false;
826
827 std::vector<G4Scene::Model>& runDurationModelList =
828 pScene->SetRunDurationModelList();
829 for (size_t i = 0; i < runDurationModelList.size(); i++) {
830 const G4String& modelName =
831 runDurationModelList[i].fpModel->GetGlobalDescription();
832 if (modelName.find(searchString) != std::string::npos) {
833 runDurationModelList.erase(runDurationModelList.begin()+i);
834 any = true;
835 if (verbosity >= G4VisManager::warnings) {
836 G4warn << "Model \"" << modelName << "\" removed." << G4endl;
837 }
838 break; // Allow only one model at a time to be removed.
839 }
840 }
841
842 std::vector<G4Scene::Model>& endOfEventModelList =
843 pScene->SetEndOfEventModelList();
844 for (size_t i = 0; i < endOfEventModelList.size(); i++) {
845 const G4String& modelName =
846 endOfEventModelList[i].fpModel->GetGlobalDescription();
847 if (modelName.find(searchString) != std::string::npos) {
848 endOfEventModelList.erase(endOfEventModelList.begin()+i);
849 any = true;
850 if (verbosity >= G4VisManager::warnings) {
851 G4warn << "Model \"" << modelName << "\" removed." << G4endl;
852 }
853 break; // Allow only one model at a time to be removed.
854 }
855 }
856
857 std::vector<G4Scene::Model>& endOfRunModelList =
858 pScene->SetEndOfRunModelList();
859 for (size_t i = 0; i < endOfRunModelList.size(); i++) {
860 const G4String& modelName =
861 endOfRunModelList[i].fpModel->GetGlobalDescription();
862 if (modelName.find(searchString) != std::string::npos) {
863 endOfRunModelList.erase(endOfRunModelList.begin()+i);
864 any = true;
865 if (verbosity >= G4VisManager::warnings) {
866 G4warn << "Model \"" << modelName << "\" removed." << G4endl;
867 }
868 break; // Allow only one model at a time to be removed.
869 }
870 }
871
872 if (!any) {
873 if (verbosity >= G4VisManager::warnings) {
874 G4warn << "WARNING: No match found." << G4endl;
875 }
876 return;
877 }
878
880}
881
882////////////// /vis/scene/select ///////////////////////////////////////
883
885 G4bool omitable;
886 fpCommand = new G4UIcmdWithAString ("/vis/scene/select", this);
887 fpCommand -> SetGuidance ("Selects a scene");
888 fpCommand -> SetGuidance
889 ("Makes the scene current. \"/vis/scene/list\" to see"
890 "\n possible scene names.");
891 fpCommand -> SetParameterName ("scene-name", omitable = false);
892}
893
895 delete fpCommand;
896}
897
899 return "";
900}
901
903
905
906 G4String& selectName = newValue;
907 G4SceneList& sceneList = fpVisManager -> SetSceneList ();
908 std::size_t iScene, nScenes = sceneList.size ();
909 for (iScene = 0; iScene < nScenes; ++iScene) {
910 if (sceneList [iScene] -> GetName () == selectName) break;
911 }
912 if (iScene >= nScenes) {
913 if (verbosity >= G4VisManager::warnings) {
914 G4warn << "WARNING: Scene \"" << selectName
915 << "\" not found - \"/vis/scene/list\" to see possibilities."
916 << G4endl;
917 }
918 return;
919 }
920
921 if (verbosity >= G4VisManager::confirmations) {
922 G4cout << "Scene \"" << selectName
923 << "\" selected." << G4endl;
924 }
925
926 CheckSceneAndNotifyHandlers (sceneList [iScene]);
927}
928
929////////////// /vis/scene/showExtents ///////////////////////////////////////
930
932 fpCommand = new G4UIcmdWithoutParameter ("/vis/scene/showExtents", this);
933 fpCommand -> SetGuidance ("Prints and draws extents of models in a scene");
934}
935
937 delete fpCommand;
938}
939
941 return "";
942}
943
945
947
948 G4VSceneHandler* pCurrentSceneHandler =
949 fpVisManager -> GetCurrentSceneHandler();
950 if (!pCurrentSceneHandler) {
951 if (verbosity >= G4VisManager::warnings) {
952 G4warn << "WARNING: No current scene handler."
953 << G4endl;
954 }
955 return;
956 }
957 G4VViewer* pCurrentViewer = fpVisManager -> GetCurrentViewer();
958 if (!pCurrentViewer) {
959 if (verbosity >= G4VisManager::warnings) {
960 G4warn << "WARNING: No current viewer."
961 << G4endl;
962 }
963 return;
964 }
965 G4Scene* pCurrentScene = fpVisManager -> GetCurrentScene();
966 if (!pCurrentScene) {
967 if (verbosity >= G4VisManager::warnings) {
968 G4warn << "WARNING: No current scene."
969 << G4endl;
970 }
971 return;
972 }
973
974 G4cout << "\n Run-duration models:";
975 std::size_t nRunModels = pCurrentScene -> GetRunDurationModelList ().size ();
976 if (nRunModels == 0) {
977 G4cout << " none.";
978 }
979 for (std::size_t i = 0; i < nRunModels; ++i) {
980 if (pCurrentScene -> GetRunDurationModelList()[i].fActive)
981 G4cout << "\n Active: ";
982 else G4cout << "\n Inactive: ";
983 G4VModel* pModel = pCurrentScene -> GetRunDurationModelList()[i].fpModel;
984 const G4VisExtent& transformedExtent = pModel -> GetExtent();
985 G4cout << pModel -> GetGlobalDescription ()
986 << "\n" << transformedExtent;
987 DrawExtent(transformedExtent);
988 }
989 G4cout << "\n End-of-event models:";
990 std::size_t nEOEModels = pCurrentScene -> GetEndOfEventModelList ().size ();
991 if (nEOEModels == 0) {
992 G4cout << " none.";
993 }
994 for (std::size_t i = 0; i < nEOEModels; ++i) {
995 if (pCurrentScene -> GetEndOfEventModelList()[i].fActive)
996 G4cout << "\n Active: ";
997 else G4cout << "\n Inactive: ";
998 G4VModel* pModel = pCurrentScene -> GetEndOfEventModelList()[i].fpModel;
999 const G4VisExtent& transformedExtent = pModel -> GetExtent();
1000 G4cout << pModel -> GetGlobalDescription ()
1001 << "\n" << transformedExtent;
1002 DrawExtent(transformedExtent);
1003 }
1004 G4cout << "\n End-of-run models:";
1005 std::size_t nEORModels = pCurrentScene -> GetEndOfRunModelList ().size ();
1006 if (nEORModels == 0) {
1007 G4cout << " none.";
1008 }
1009 for (std::size_t i = 0; i < nEORModels; ++i) {
1010 if (pCurrentScene -> GetEndOfRunModelList()[i].fActive)
1011 G4cout << "\n Active: ";
1012 else G4cout << "\n Inactive: ";
1013 G4VModel* pModel = pCurrentScene -> GetEndOfRunModelList()[i].fpModel;
1014 const G4VisExtent& transformedExtent = pModel -> GetExtent();
1015 G4cout << pModel -> GetGlobalDescription ()
1016 << "\n" << transformedExtent;
1017 DrawExtent(transformedExtent);
1018 }
1019 G4cout << "\n Overall extent:\n";
1020 DrawExtent(pCurrentScene->GetExtent());
1021 G4cout << G4endl;
1022}
#define G4warn
Definition: G4Scene.cc:41
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
static G4RunManager * GetMasterRunManager()
const G4Run * GetCurrentRun() const
Definition: G4Run.hh:49
const std::vector< const G4Event * > * GetEventVector() const
Definition: G4Run.hh:96
std::vector< Model > & SetEndOfRunModelList()
void CalculateExtent()
Definition: G4Scene.cc:64
G4bool GetRefreshAtEndOfEvent() const
void SetRefreshAtEndOfEvent(G4bool)
const G4VisExtent & GetExtent() const
const G4String & GetName() const
std::vector< Model > & SetRunDurationModelList()
std::vector< Model > & SetEndOfEventModelList()
void SetRefreshAtEndOfRun(G4bool)
void SetMaxNumberOfKeptEvents(G4int)
G4bool GetRefreshAtEndOfRun() const
static G4bool ConvertToBool(const char *st)
Definition: G4UIcommand.cc:549
void SetMarkForClearingTransientStore(G4bool)
const G4String & GetName() const
const G4ViewParameters & GetViewParameters() const
void CheckSceneAndNotifyHandlers(G4Scene *=nullptr)
static G4VisManager * fpVisManager
void DrawExtent(const G4VisExtent &)
G4bool IsAutoRefresh() const
G4String GetCurrentValue(G4UIcommand *command)
void SetNewValue(G4UIcommand *command, G4String newValue)
G4String GetCurrentValue(G4UIcommand *command)
void SetNewValue(G4UIcommand *command, G4String newValue)
void SetNewValue(G4UIcommand *command, G4String newValue)
G4String GetCurrentValue(G4UIcommand *command)
void SetNewValue(G4UIcommand *command, G4String newValue)
G4String GetCurrentValue(G4UIcommand *command)
void SetNewValue(G4UIcommand *command, G4String newValue)
G4String GetCurrentValue(G4UIcommand *command)
G4String GetCurrentValue(G4UIcommand *command)
void SetNewValue(G4UIcommand *command, G4String newValue)
G4String GetCurrentValue(G4UIcommand *command)
void SetNewValue(G4UIcommand *command, G4String newValue)
void SetNewValue(G4UIcommand *command, G4String newValue)
G4String GetCurrentValue(G4UIcommand *command)
void SetNewValue(G4UIcommand *command, G4String newValue)
G4String GetCurrentValue(G4UIcommand *command)
G4Scene * GetCurrentScene() const
G4VSceneHandler * GetCurrentSceneHandler() const
static Verbosity GetVerbosity()
void ResetTransientsDrawnFlags()
static Verbosity GetVerbosityValue(const G4String &)