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

#include <G4VisCommandsViewer.hh>

+ Inheritance diagram for G4VisCommandViewerClone:

Public Member Functions

 G4VisCommandViewerClone ()
 
virtual ~G4VisCommandViewerClone ()
 
G4String GetCurrentValue (G4UIcommand *command)
 
void SetNewValue (G4UIcommand *command, G4String newValue)
 
- Public Member Functions inherited from G4VVisCommandViewer
 G4VVisCommandViewer ()
 
virtual ~G4VVisCommandViewer ()
 
- Public Member Functions inherited from G4VVisCommand
 G4VVisCommand ()
 
virtual ~G4VVisCommand ()
 
- Public Member Functions inherited from G4UImessenger
 G4UImessenger ()
 
 G4UImessenger (const G4String &path, const G4String &dsc)
 
virtual ~G4UImessenger ()
 
virtual G4String GetCurrentValue (G4UIcommand *command)
 
virtual void SetNewValue (G4UIcommand *command, G4String newValue)
 
G4bool operator== (const G4UImessenger &messenger) const
 

Additional Inherited Members

- Static Public Member Functions inherited from G4VVisCommand
static void SetVisManager (G4VisManager *)
 
- Protected Member Functions inherited from G4VVisCommandViewer
void SetViewParameters (G4VViewer *, const G4ViewParameters &)
 
void RefreshIfRequired (G4VViewer *)
 
- Protected Member Functions inherited from G4VVisCommand
void UpdateVisManagerScene (const G4String &sceneName="")
 
- Protected Member Functions inherited from G4UImessenger
G4String ItoS (G4int i)
 
G4String DtoS (G4double a)
 
G4String BtoS (G4bool b)
 
G4int StoI (G4String s)
 
G4double StoD (G4String s)
 
G4bool StoB (G4String s)
 
void AddUIcommand (G4UIcommand *newCommand)
 
void CreateDirectory (const G4String &path, const G4String &dsc)
 
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 void ConvertToDoublePair (const G4String &paramString, G4double &xval, G4double &yval)
 
- Protected Attributes inherited from G4UImessenger
G4UIdirectorybaseDir
 
G4String baseDirName
 
- Static Protected Attributes inherited from G4VVisCommand
static G4VisManagerfpVisManager = 0
 
static G4Colour fCurrentColour = G4Colour::White()
 
static G4Colour fCurrentTextColour = G4Colour::Blue()
 
static G4Text::Layout fCurrentTextLayout = G4Text::left
 
static G4double fCurrentLineWidth = 1.
 
static G4ModelingParameters::PVNameCopyNoPath fCurrentTouchablePath
 

Detailed Description

Definition at line 118 of file G4VisCommandsViewer.hh.

Constructor & Destructor Documentation

◆ G4VisCommandViewerClone()

G4VisCommandViewerClone::G4VisCommandViewerClone ( )

Definition at line 377 of file G4VisCommandsViewer.cc.

377 {
378 G4bool omitable;
379 fpCommand = new G4UIcommand ("/vis/viewer/clone", this);
380 fpCommand -> SetGuidance ("Clones viewer.");
381 fpCommand -> SetGuidance
382 ("By default, clones current viewer. Clone becomes current."
383 "\nClone name, if not provided, is derived from the original name."
384 "\n\"/vis/viewer/list\" to see possible viewer names.");
385 G4UIparameter* parameter;
386 parameter = new G4UIparameter ("original-viewer-name", 's', omitable = true);
387 parameter -> SetCurrentAsDefault (true);
388 fpCommand -> SetParameter (parameter);
389 parameter = new G4UIparameter ("clone-name", 's', omitable = true);
390 parameter -> SetDefaultValue ("none");
391 fpCommand -> SetParameter (parameter);
392}
bool G4bool
Definition: G4Types.hh:67

◆ ~G4VisCommandViewerClone()

G4VisCommandViewerClone::~G4VisCommandViewerClone ( )
virtual

Definition at line 394 of file G4VisCommandsViewer.cc.

394 {
395 delete fpCommand;
396}

Member Function Documentation

◆ GetCurrentValue()

G4String G4VisCommandViewerClone::GetCurrentValue ( G4UIcommand command)
virtual

Reimplemented from G4UImessenger.

Definition at line 398 of file G4VisCommandsViewer.cc.

398 {
399 G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
400 G4String originalName = viewer ? viewer -> GetName () : G4String("none");
401 return "\"" + originalName + "\"";
402}
static G4VisManager * fpVisManager

◆ SetNewValue()

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

Reimplemented from G4UImessenger.

Definition at line 404 of file G4VisCommandsViewer.cc.

404 {
405
407
408 G4String originalName, cloneName;
409 std::istringstream is (newValue);
410
411 // Need to handle the possibility that the names contain embedded
412 // blanks within quotation marks...
413 char c;
414 while (is.get(c) && c == ' '){}
415 if (c == '"') {
416 while (is.get(c) && c != '"') {originalName += c;}
417 }
418 else {
419 originalName += c;
420 while (is.get(c) && c != ' ') {originalName += c;}
421 }
422 originalName = originalName.strip (G4String::both, ' ');
423 originalName = originalName.strip (G4String::both, '"');
424
425 G4VViewer* originalViewer = fpVisManager -> GetViewer (originalName);
426 if (!originalViewer) {
427 if (verbosity >= G4VisManager::errors) {
428 G4cout << "ERROR: Viewer \"" << originalName
429 << "\" not found - \"/vis/viewer/list\" to see possibilities."
430 << G4endl;
431 }
432 return;
433 }
434 originalName = originalViewer->GetName(); // Ensures long name.
435
436 while (is.get(c) && c == ' '){}
437 if (c == '"') {
438 while (is.get(c) && c != '"') {cloneName += c;}
439 }
440 else {
441 cloneName += c;
442 while (is.get(c) && c != ' ') {cloneName += c;}
443 }
444 cloneName = cloneName.strip (G4String::both, ' ');
445 cloneName = cloneName.strip (G4String::both, '"');
446
447 G4bool errorWhileNaming = false;
448 if (cloneName == "none") {
449 G4int subID = 0;
450 do {
451 cloneName = originalName;
452 std::ostringstream oss;
453 oss << '-' << subID++;
454 G4String::size_type lastDashPosition, nextSpacePosition;
455 if ((lastDashPosition = cloneName.rfind('-')) != G4String::npos &&
456 (nextSpacePosition = cloneName.find(" ", lastDashPosition)) !=
457 G4String::npos) {
458 cloneName.insert(nextSpacePosition, oss.str());
459 } else {
460 G4String::size_type spacePosition = cloneName.find(' ');
461 if (spacePosition != G4String::npos)
462 cloneName.insert(spacePosition, oss.str());
463 else
464 errorWhileNaming = true;
465 }
466 } while (!errorWhileNaming && fpVisManager -> GetViewer (cloneName));
467 }
468
469 if (errorWhileNaming) {
470 if (verbosity >= G4VisManager::errors) {
471 G4cout << "ERROR: While naming clone viewer \"" << cloneName
472 << "\"."
473 << G4endl;
474 }
475 return;
476 }
477
478 if (fpVisManager -> GetViewer (cloneName)) {
479 if (verbosity >= G4VisManager::errors) {
480 G4cout << "ERROR: Putative clone viewer \"" << cloneName
481 << "\" already exists."
482 << G4endl;
483 }
484 return;
485 }
486
487 G4String windowSizeHint =
488 originalViewer->GetViewParameters().GetXGeometryString();
489
491 G4int keepVerbose = UImanager->GetVerboseLevel();
492 G4int newVerbose(0);
493 if (keepVerbose >= 2 ||
495 newVerbose = 2;
496 UImanager->SetVerboseLevel(newVerbose);
497 UImanager->ApplyCommand(G4String("/vis/viewer/select " + originalName));
498 UImanager->ApplyCommand
499 (G4String("/vis/viewer/create ! \"" + cloneName + "\" " + windowSizeHint));
500 UImanager->ApplyCommand(G4String("/vis/viewer/set/all " + originalName));
501 UImanager->SetVerboseLevel(keepVerbose);
502
503 if (verbosity >= G4VisManager::confirmations) {
504 G4cout << "Viewer \"" << originalName << "\" cloned." << G4endl;
505 G4cout << "Clone \"" << cloneName << "\" now current." << G4endl;
506 }
507}
int G4int
Definition: G4Types.hh:66
#define G4endl
Definition: G4ios.hh:52
G4DLLIMPORT std::ostream G4cout
G4String strip(G4int strip_Type=trailing, char c=' ')
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:369
G4int GetVerboseLevel() const
Definition: G4UImanager.hh:218
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:51
void SetVerboseLevel(G4int val)
Definition: G4UImanager.hh:216
const G4String & GetName() const
const G4ViewParameters & GetViewParameters() const
const G4String & GetXGeometryString() const
static Verbosity GetVerbosity()

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