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