Geant4 11.4.0
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, const 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 (const 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 902 of file G4VisCommandsViewer.cc.

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

◆ ~G4VisCommandViewerCreate()

G4VisCommandViewerCreate::~G4VisCommandViewerCreate ( )
virtual

Definition at line 947 of file G4VisCommandsViewer.cc.

947 {
948 delete fpCommand;
949}

Member Function Documentation

◆ GetCurrentValue()

G4String G4VisCommandViewerCreate::GetCurrentValue ( G4UIcommand * command)
virtual

Reimplemented from G4UImessenger.

Definition at line 965 of file G4VisCommandsViewer.cc.

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

◆ SetNewValue()

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

Reimplemented from G4UImessenger.

Definition at line 993 of file G4VisCommandsViewer.cc.

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

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