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

#include <G4VisCommandsSceneHandler.hh>

+ Inheritance diagram for G4VisCommandSceneHandlerCreate:

Public Member Functions

 G4VisCommandSceneHandlerCreate ()
 
 ~G4VisCommandSceneHandlerCreate ()
 
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 ()
 
virtual G4String GetCurrentValue (G4UIcommand *command)
 
virtual void SetNewValue (G4UIcommand *command, G4String newValue)
 
G4bool operator== (const G4UImessenger &messenger) const
 
G4bool operator!= (const G4UImessenger &messenger) const
 
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 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
 

Detailed Description

Definition at line 49 of file G4VisCommandsSceneHandler.hh.

Constructor & Destructor Documentation

◆ G4VisCommandSceneHandlerCreate()

G4VisCommandSceneHandlerCreate::G4VisCommandSceneHandlerCreate ( )

Definition at line 139 of file G4VisCommandsSceneHandler.cc.

139 : fId (0) {
140 G4bool omitable;
141 fpCommand = new G4UIcommand ("/vis/sceneHandler/create", this);
142 fpCommand -> SetGuidance
143 ("Creates an scene handler for a specific graphics system.");
144 fpCommand -> SetGuidance
145 ("Attaches current scene, if any. (You can change attached scenes with"
146 "\n\"/vis/sceneHandler/attach\".) Invents a scene handler name if not"
147 "\nsupplied. This scene handler becomes current.");
148 G4UIparameter* parameter;
149 parameter = new G4UIparameter ("graphics-system-name",
150 's', omitable = false);
151 const G4GraphicsSystemList& gslist =
152 fpVisManager -> GetAvailableGraphicsSystems ();
153 G4String candidates;
154 for (const auto gs: gslist) {
155 const G4String& name = gs -> GetName ();
156 candidates += name + ' ';
157 for (const auto& nickname: gs -> GetNicknames ()) {
158 if (G4StrUtil::contains(nickname, "FALLBACK")) continue;
159 if (nickname != name) candidates += nickname + ' ';
160 }
161 }
162 G4StrUtil::strip(candidates);
163 parameter -> SetParameterCandidates(candidates);
164 fpCommand -> SetParameter (parameter);
165 parameter = new G4UIparameter
166 ("scene-handler-name", 's', omitable = true);
167 parameter -> SetCurrentAsDefault (true);
168 fpCommand -> SetParameter (parameter);
169}
bool G4bool
Definition: G4Types.hh:86
static G4VisManager * fpVisManager
const char * name(G4int ptype)
void strip(G4String &str, char ch=' ')
Remove leading and trailing characters from string.
G4bool contains(const G4String &str, std::string_view ss)
Check if a string contains a given substring.

◆ ~G4VisCommandSceneHandlerCreate()

G4VisCommandSceneHandlerCreate::~G4VisCommandSceneHandlerCreate ( )

Definition at line 171 of file G4VisCommandsSceneHandler.cc.

171 {
172 delete fpCommand;
173}

Member Function Documentation

◆ GetCurrentValue()

G4String G4VisCommandSceneHandlerCreate::GetCurrentValue ( G4UIcommand command)
virtual

Reimplemented from G4UImessenger.

Definition at line 181 of file G4VisCommandsSceneHandler.cc.

181 {
182
183 G4String graphicsSystemName;
184 const G4VGraphicsSystem* graphicsSystem =
185 fpVisManager -> GetCurrentGraphicsSystem ();
186 if (graphicsSystem) {
187 graphicsSystemName = graphicsSystem -> GetName ();
188 }
189 else {
190 const G4GraphicsSystemList& gslist =
191 fpVisManager -> GetAvailableGraphicsSystems ();
192 if (gslist.size ()) {
193 graphicsSystemName = gslist [0] -> GetName ();
194 }
195 else {
196 graphicsSystemName = "none";
197 }
198 }
199
200 return graphicsSystemName + " " + NextName ();
201}

◆ SetNewValue()

void G4VisCommandSceneHandlerCreate::SetNewValue ( G4UIcommand command,
G4String  newValue 
)
virtual

Reimplemented from G4UImessenger.

Definition at line 203 of file G4VisCommandsSceneHandler.cc.

204 {
205
207
208 G4String graphicsSystem, newName;
209 std::istringstream is (newValue);
210 is >> graphicsSystem >> newName;
211
212 const G4GraphicsSystemList& gsl =
213 fpVisManager -> GetAvailableGraphicsSystems ();
214 std::size_t nSystems = gsl.size ();
215 if (nSystems <= 0) {
217 ed <<
218 "ERROR: G4VisCommandSceneHandlerCreate::SetNewValue:"
219 " no graphics systems available."
220 "\n Did you instantiate any in"
221 " YourVisManager::RegisterGraphicsSystems()?";
222 command->CommandFailed(ed);
223 return;
224 }
225 std::size_t iGS; // Selector index.
226 G4bool found = false;
227 for (iGS = 0; iGS < nSystems; ++iGS) {
228 const auto& gs = gsl[iGS];
229 if (G4StrUtil::icompare(graphicsSystem, gs->GetName()) == 0) {
230 found = true;
231 break; // Match found
232 } else {
233 const auto& nicknames = gs->GetNicknames();
234 for (std::size_t i = 0; i < nicknames.size(); ++i) {
235 const auto& nickname = nicknames[i];
236 if (G4StrUtil::icompare(graphicsSystem, nickname) == 0) {
237 found = true;
238 break; // Match found
239 }
240 }
241 if (found) {
242 break; // Match found
243 }
244 }
245 }
246 if (!found) {
247 // Shouldn't happen, since graphicsSystem should be a candidate
249 ed <<
250 "ERROR: G4VisCommandSceneHandlerCreate::SetNewValue:"
251 "\n Invalid graphics system \""
252 << graphicsSystem
253 << "\" requested."
254 << "\n Candidates are:";
256 command->CommandFailed(ed);
257 return;
258 }
259
260 // Check UI session compatibility.
261 G4bool fallback = false;
262 G4int loopCounter = 0;
263 while (!gsl[iGS]->IsUISessionCompatible()) {
264 std::size_t iGSBeingTested = iGS;
265 // Not compatible, search for a fallback
266 fallback = false;
267 G4String fallbackNickname = gsl[iGS]->GetNickname() + "_FALLBACK";
268 for (iGS = 0; iGS < nSystems; iGS++) {
269 const auto& nicknames = gsl[iGS]->GetNicknames();
270 for (std::size_t i = 0; i < nicknames.size(); ++i) {
271 const auto& nickname = nicknames[i];
272 if (G4StrUtil::icompare(fallbackNickname, nickname) == 0) {
273 fallback = true;
274 break; // Match found
275 }
276 }
277 if (fallback) {
278 break; // Match found
279 }
280 }
281 if (iGS >= nSystems || loopCounter >=3) {
283 ed << "\"" << gsl[iGSBeingTested]->GetNickname()
284 << "\" is not compatible with your chosen session,"
285 " and no fallback system found.";
286 command->CommandFailed(ed);
287 return;
288 }
289 // A fallback system found...but go back and check this too.
290 ++loopCounter;
291 }
292
293 // A graphics system has been found
294 G4VGraphicsSystem* pSystem = gsl [iGS];
295
296 if (fallback && verbosity >= G4VisManager::warnings) {
297 G4warn << "WARNING: G4VisCommandSceneHandlerCreate::SetNewValue:"
298 "\n Using fallback graphics system: "
299 << pSystem -> GetName ()
300 << " ("
301 << pSystem -> GetNickname ()
302 << ')'
303 << G4endl;
304 }
305
306 // Now deal with name of scene handler.
307 G4String nextName = NextName ();
308 if (newName == "") {
309 newName = nextName;
310 }
311 if (newName == nextName) fId++;
312
313 const G4SceneHandlerList& list = fpVisManager -> GetAvailableSceneHandlers ();
314 std::size_t iScene;
315 for (iScene = 0; iScene < list.size (); ++iScene) {
316 G4VSceneHandler* sceneHandler = list [iScene];
317 if (sceneHandler -> GetName () == newName) {
319 ed <<
320 "ERROR: Scene handler \"" << newName
321 << "\" already exists.";
322 command->CommandFailed(ed);
323 return;
324 }
325 }
326
327 // If there is an existing viewer, store its view parameters
329 fThereWasAViewer = true;
331 }
332
333 // Set current graphics system in preparation for
334 // creating scene handler.
335 fpVisManager -> SetCurrentGraphicsSystem (pSystem);
336 if (verbosity >= G4VisManager::confirmations) {
337 G4cout << "Graphics system set to "
338 << pSystem -> GetName ()
339 << " ("
340 << pSystem -> GetNickname ()
341 << ')'
342 << G4endl;
343 }
344
345 //Create scene handler.
346 fpVisManager -> CreateSceneHandler (newName);
347 if (fpVisManager -> GetCurrentSceneHandler () -> GetName () != newName) {
349 ed <<
350 "ERROR: G4VisCommandSceneHandlerCreate::SetNewValue:"
351 " Curious name mismatch."
352 "\n Current name \""
353 << fpVisManager -> GetCurrentSceneHandler () -> GetName ()
354 << "\" is not the new name \""
355 << newName
356 << "\".\n Please report to vis coordinator.";
357 command->CommandFailed(ed);
358 return;
359 }
360
361 if (verbosity >= G4VisManager::confirmations)
362 G4cout << "New scene handler \"" << newName << "\" created." << G4endl;
363
364 if (fpVisManager -> GetCurrentScene ()) {
365 auto errorCode = G4UImanager::GetUIpointer () -> ApplyCommand ("/vis/sceneHandler/attach");
366 if (errorCode) {
368 ed << "sub-command \"/vis/sceneHandler/attach\" failed.";
369 command->CommandFailed(errorCode,ed);
370 return;
371 }
372 }
373}
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
#define G4warn
Definition: G4Scene.cc:41
int G4int
Definition: G4Types.hh:85
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
void CommandFailed(G4int errCode, G4ExceptionDescription &ed)
Definition: G4UIcommand.hh:179
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:77
const G4ViewParameters & GetViewParameters() const
static G4ViewParameters fExistingVP
static G4bool fThereWasAViewer
void PrintAvailableGraphicsSystems(Verbosity, std::ostream &=G4cout) const
G4VViewer * GetCurrentViewer() const
static Verbosity GetVerbosity()
G4int icompare(std::string_view lhs, std::string_view rhs)
Case insensitive comparison of two strings.

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