Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4VisCommandViewerCreate Class Reference

#include <G4VisCommandsViewer.hh>

+ Inheritance diagram for G4VisCommandViewerCreate:

Public Member Functions

 G4VisCommandViewerCreate ()
 
virtual ~G4VisCommandViewerCreate ()
 
G4String GetCurrentValue (G4UIcommand *command)
 
void SetNewValue (G4UIcommand *command, G4String newValue)
 
- Public Member Functions inherited from G4VVisCommand
 G4VVisCommand ()
 
virtual ~G4VVisCommand ()
 
- Public Member Functions inherited from G4UImessenger
 G4UImessenger ()=default
 
 G4UImessenger (const G4String &path, const G4String &dsc, G4bool commandsToBeBroadcasted=true)
 
virtual ~G4UImessenger ()
 
G4bool CommandsShouldBeInMaster () const
 

Additional Inherited Members

- Static Public Member Functions inherited from G4VVisCommand
static G4VisManagerGetVisManager ()
 
static void SetVisManager (G4VisManager *pVisManager)
 
static const G4ColourGetCurrentTextColour ()
 
- Protected Member Functions inherited from G4VVisCommand
void SetViewParameters (G4VViewer *viewer, const G4ViewParameters &viewParams)
 
void RefreshIfRequired (G4VViewer *viewer)
 
void InterpolateViews (G4VViewer *currentViewer, std::vector< G4ViewParameters > viewVector, const G4int nInterpolationPoints=50, const G4int waitTimePerPointmilliseconds=20, const G4String exportString="")
 
void InterpolateToNewView (G4VViewer *currentViewer, const G4ViewParameters &oldVP, const G4ViewParameters &newVP, const G4int nInterpolationPoints=50, const G4int waitTimePerPointmilliseconds=20, const G4String exportString="")
 
void Twinkle (G4VViewer *currentViewer, const G4ViewParameters &baseVP, const std::vector< std::vector< G4PhysicalVolumeModel::G4PhysicalVolumeNodeID > > &paths)
 
const G4StringConvertToColourGuidance ()
 
void ConvertToColour (G4Colour &colour, const G4String &redOrString, G4double green, G4double blue, G4double opacity)
 
G4bool ProvideValueOfUnit (const G4String &where, const G4String &unit, const G4String &category, G4double &value)
 
void CopyCameraParameters (G4ViewParameters &target, const G4ViewParameters &from)
 
void CheckSceneAndNotifyHandlers (G4Scene *=nullptr)
 
G4bool CheckView ()
 
void G4VisCommandsSceneAddUnsuccessful (G4VisManager::Verbosity verbosity)
 
void CopyGuidanceFrom (const G4UIcommand *fromCmd, G4UIcommand *toCmd, G4int startLine=0)
 
void CopyParametersFrom (const G4UIcommand *fromCmd, G4UIcommand *toCmd)
 
void DrawExtent (const G4VisExtent &)
 
- Protected Member Functions inherited from G4UImessenger
G4String ItoS (G4int i)
 
G4String LtoS (G4long l)
 
G4String DtoS (G4double a)
 
G4String BtoS (G4bool b)
 
G4int StoI (const G4String &s)
 
G4long StoL (const G4String &s)
 
G4double StoD (const G4String &s)
 
G4bool StoB (G4String s)
 
void AddUIcommand (G4UIcommand *newCommand)
 
void CreateDirectory (const G4String &path, const G4String &dsc, G4bool commandsToBeBroadcasted=true)
 
template<typename T >
T * CreateCommand (const G4String &cname, const G4String &dsc)
 
- Static Protected Member Functions inherited from G4VVisCommand
static G4String ConvertToString (G4double x, G4double y, const char *unitName)
 
static G4bool ConvertToDoublePair (const G4String &paramString, G4double &xval, G4double &yval)
 
- Protected Attributes inherited from G4UImessenger
G4UIdirectorybaseDir = nullptr
 
G4String baseDirName = ""
 
G4bool commandsShouldBeInMaster = false
 
- Static Protected Attributes inherited from G4VVisCommand
static G4VisManagerfpVisManager = nullptr
 
static G4int fCurrentArrow3DLineSegmentsPerCircle = 6
 
static G4Colour fCurrentColour = G4Colour::White()
 
static G4double fCurrentLineWidth = 1.
 
static G4Colour fCurrentTextColour = G4Colour::Blue()
 
static G4Text::Layout fCurrentTextLayout = G4Text::left
 
static G4double fCurrentTextSize = 12.
 
static G4PhysicalVolumeModel::TouchableProperties fCurrentTouchableProperties
 
static G4VisExtent fCurrentExtentForField
 
static std::vector< G4PhysicalVolumesSearchScene::FindingsfCurrrentPVFindingsForField
 
static G4bool fThereWasAViewer = false
 
static G4ViewParameters fExistingVP
 
static G4SceneTreeItem fExistingSceneTree
 

Detailed Description

Definition at line 168 of file G4VisCommandsViewer.hh.

Constructor & Destructor Documentation

◆ G4VisCommandViewerCreate()

G4VisCommandViewerCreate::G4VisCommandViewerCreate ( )

Definition at line 903 of file G4VisCommandsViewer.cc.

903 : fId (0) {
904 G4bool omitable;
905 fpCommand = new G4UIcommand ("/vis/viewer/create", this);
906 fpCommand -> SetGuidance
907 ("Creates a viewer. If the scene handler name is specified, then a"
908 "\nviewer of that scene handler is created. Otherwise, a viewer"
909 "\nof the current scene handler is created.");
910 fpCommand -> SetGuidance
911 ("If the viewer name is not specified a name is generated from the name"
912 "\nof the scene handler and a serial number.");
913 fpCommand -> SetGuidance("The scene handler and viewer become current.");
914 fpCommand -> SetGuidance
915 ("(Note: the system adds the graphics system name to the viewer name"
916 "\nfor identification, but for selecting, copying, etc., only characters"
917 "\nup to the first blank are used. For example, if the viewer name is"
918 "\n\"viewer-0 (G4OpenGLStoredQt)\", it may be referenced by \"viewer-0\","
919 "\nfor example in \"/vis/viewer/select viewer-0\".)");
920 fpCommand -> SetGuidance
921 ("Window size and placement hints, e.g. 600x600-100+100 (in pixels):");
922 fpCommand -> SetGuidance
923 ("- single number, e.g., \"600\": square window;");
924 fpCommand -> SetGuidance
925 ("- two numbers, e.g., \"800x600\": rectangluar window;");
926 fpCommand -> SetGuidance
927 ("- two numbers plus placement hint, e.g., \"600x600-100+100\" places window of size"
928 "\n 600x600 100 pixels left and 100 pixels down from top right corner.");
929 fpCommand -> SetGuidance
930 ("- If not specified, the default is \"600\", i.e., 600 pixels square, placed"
931 "\n at the window manager's discretion...or picked up from the previous viewer.");
932 fpCommand -> SetGuidance
933 ("- This is an X-Windows-type geometry string, see:"
934 "\n https://en.wikibooks.org/wiki/Guide_to_X11/Starting_Programs,"
935 "\n \"Specifying window geometry\".");
936 G4UIparameter* parameter;
937 parameter = new G4UIparameter ("scene-handler", 's', omitable = true);
938 parameter -> SetCurrentAsDefault (true);
939 fpCommand -> SetParameter (parameter);
940 parameter = new G4UIparameter ("viewer-name", 's', omitable = true);
941 parameter -> SetCurrentAsDefault (true);
942 fpCommand -> SetParameter (parameter);
943 parameter = new G4UIparameter ("window-size-hint", 's', omitable = true);
944 parameter -> SetCurrentAsDefault (true);
945 fpCommand -> SetParameter (parameter);
946}
bool G4bool
Definition G4Types.hh:86

◆ ~G4VisCommandViewerCreate()

G4VisCommandViewerCreate::~G4VisCommandViewerCreate ( )
virtual

Definition at line 948 of file G4VisCommandsViewer.cc.

948 {
949 delete fpCommand;
950}

Member Function Documentation

◆ GetCurrentValue()

G4String G4VisCommandViewerCreate::GetCurrentValue ( G4UIcommand * command)
virtual

Reimplemented from G4UImessenger.

Definition at line 966 of file G4VisCommandsViewer.cc.

967{
968 G4String sceneHandlerName;
969 auto currentSceneHandler = fpVisManager->GetCurrentSceneHandler();
970 if (currentSceneHandler) { // Get name of last scene handler
971 sceneHandlerName = currentSceneHandler->GetName();
972 }
973 else { // No scene handler - ensure a warning message
974 sceneHandlerName = "none";
975 }
976
977 // Default name
978 const auto& viewerName = NextName();
979
980 // Size hint
981 G4String windowSizeHint;
982 auto currentViewer = fpVisManager->GetCurrentViewer();
983 if (currentViewer) { // Get hint from last viewer
984 windowSizeHint = currentViewer->GetViewParameters().GetXGeometryString();
985 }
986 else { // No viewer - must be first time
987 windowSizeHint = fpVisManager->GetDefaultXGeometryString();
988 }
989
990 // Add quotes around viewer name
991 return sceneHandlerName + " \"" + viewerName + "\" " + windowSizeHint;
992}
static G4VisManager * fpVisManager
G4VViewer * GetCurrentViewer() const
G4VSceneHandler * GetCurrentSceneHandler() const
const G4String & GetDefaultXGeometryString() const

◆ SetNewValue()

void G4VisCommandViewerCreate::SetNewValue ( G4UIcommand * command,
G4String newValue )
virtual

Reimplemented from G4UImessenger.

Definition at line 994 of file G4VisCommandsViewer.cc.

994 {
995
997
998 G4String sceneHandlerName, newName;
999 G4String windowSizeHintString;
1000 std::istringstream is (newValue);
1001 is >> sceneHandlerName;
1002
1003 // Now need to handle the possibility that the second string
1004 // contains embedded blanks within quotation marks...
1005 char c = ' ';
1006 while (is.get(c) && c == ' '){}
1007 if (c == '"') {
1008 while (is.get(c) && c != '"') {newName += c;}
1009 }
1010 else {
1011 newName += c;
1012 while (is.get(c) && c != ' ') {newName += c;}
1013 }
1014 G4StrUtil::strip(newName, ' ');
1015 G4StrUtil::strip(newName, '"');
1016
1017 // Now get window size hint...
1018 is >> windowSizeHintString;
1019
1020 const G4SceneHandlerList& sceneHandlerList =
1021 fpVisManager -> GetAvailableSceneHandlers ();
1022 std::size_t nHandlers = sceneHandlerList.size ();
1023 if (nHandlers == 0) {
1025 ed <<
1026 "ERROR: G4VisCommandViewerCreate::SetNewValue: no scene handlers."
1027 "\n Create a scene handler with \"/vis/sceneHandler/create\"";
1028 command->CommandFailed(ed);
1029 return;
1030 }
1031
1032 std::size_t iHandler;
1033 for (iHandler = 0; iHandler < nHandlers; ++iHandler) {
1034 if (sceneHandlerList [iHandler] -> GetName () == sceneHandlerName) break;
1035 }
1036
1037 if (iHandler >= nHandlers) {
1038 // Invalid command line argument or none.
1039 // This shouldn't happen!!!!!!
1041 ed <<
1042 "G4VisCommandViewerCreate::SetNewValue: invalid scene handler specified.";
1043 command->CommandFailed(ed);
1044 return;
1045 }
1046
1047 // Valid index. Set current scene handler and graphics system in
1048 // preparation for creating viewer.
1049 G4VSceneHandler* sceneHandler = sceneHandlerList [iHandler];
1050 if (sceneHandler != fpVisManager -> GetCurrentSceneHandler ()) {
1051 fpVisManager -> SetCurrentSceneHandler (sceneHandler);
1052 }
1053
1054 // Now deal with name of viewer.
1055 G4String nextName = NextName ();
1056 if (newName == "") {
1057 newName = nextName;
1058 }
1059 if (newName == nextName) fId++;
1060 G4String newShortName = fpVisManager -> ViewerShortName (newName);
1061
1062 for (std::size_t ih = 0; ih < nHandlers; ++ih) {
1063 G4VSceneHandler* sh = sceneHandlerList [ih];
1064 const G4ViewerList& viewerList = sh -> GetViewerList ();
1065 for (std::size_t iViewer = 0; iViewer < viewerList.size (); iViewer++) {
1066 if (viewerList [iViewer] -> GetShortName () == newShortName ) {
1068 ed <<
1069 "ERROR: Viewer \"" << newShortName << "\" already exists.";
1070 command->CommandFailed(ed);
1071 return;
1072 }
1073 }
1074 }
1075
1076 if (fThereWasAViewer) {
1077 // ...and if it's still current...
1078 auto existingViewer = fpVisManager->GetCurrentViewer();
1079 if (existingViewer) {
1080 // ...bring view parameters up to date...
1081 fExistingVP = existingViewer->GetViewParameters();
1082 fExistingSceneTree = existingViewer->AccessSceneTree();
1083 }
1084 }
1085
1086 if (fThereWasAViewer && windowSizeHintString == "none") {
1087 // The user did not specify a window size hint - get from existing VPs
1088 windowSizeHintString = fExistingVP.GetXGeometryString();
1089 }
1090
1091 fpVisManager -> CreateViewer (newName,windowSizeHintString);
1092
1093 // Now we have a new viewer
1094 G4VViewer* newViewer = fpVisManager -> GetCurrentViewer ();
1095
1096 if (newViewer && newViewer -> GetName () == newName) {
1097 if (fThereWasAViewer) {
1098 G4ViewParameters vp = newViewer->GetViewParameters();
1099 // Copy view parameters from existing viewer, except for...
1102 // ...including window hint paramaters that have been set already above...
1104 vp = fExistingVP;
1105 newViewer->SetViewParameters(vp);
1106 newViewer->AccessSceneTree() = fExistingSceneTree;
1107 }
1108 if (verbosity >= G4VisManager::confirmations) {
1109 G4cout << "New viewer \"" << newName << "\" created." << G4endl;
1110 }
1111 // Keep for next time...
1112 fThereWasAViewer = true;
1113 auto viewer = fpVisManager->GetCurrentViewer();
1114 fExistingVP = viewer->GetViewParameters();
1115 fExistingSceneTree = viewer->AccessSceneTree();
1116 } else {
1118 if (newViewer) {
1119 ed << "ERROR: New viewer doesn\'t match!!! Curious!!";
1120 } else {
1121 ed << "WARNING: No viewer created.";
1122 }
1123 command->CommandFailed(ed);
1124 return;
1125 }
1126 // Refresh if appropriate...
1127 if (newViewer) {
1128 if (newViewer->GetViewParameters().IsAutoRefresh()) {
1129 G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/refresh");
1130 }
1131 else {
1132 if (verbosity >= G4VisManager::warnings) {
1133 G4warn << "Issue /vis/viewer/refresh or flush to see effect."
1134 << G4endl;
1135 }
1136 }
1137 }
1138}
std::ostringstream G4ExceptionDescription
#define G4warn
Definition G4Scene.cc:41
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
void CommandFailed(G4int errCode, G4ExceptionDescription &ed)
G4int ApplyCommand(const char *aCommand)
static G4UImanager * GetUIpointer()
const G4ViewParameters & GetViewParameters() const
G4SceneTreeItem & AccessSceneTree()
Definition G4VViewer.hh:191
void SetViewParameters(const G4ViewParameters &vp)
Definition G4VViewer.cc:128
static G4ViewParameters fExistingVP
static G4SceneTreeItem fExistingSceneTree
static G4bool fThereWasAViewer
void SetAutoRefresh(G4bool)
void SetBackgroundColour(const G4Colour &)
const G4String & GetXGeometryString() const
const G4Colour & GetBackgroundColour() const
void SetXGeometryString(const G4String &)
G4bool IsAutoRefresh() const
static Verbosity GetVerbosity()

The documentation for this class was generated from the following files: