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

#include <G4VisCommandsViewer.hh>

+ Inheritance diagram for G4VisCommandViewerSave:

Public Member Functions

 G4VisCommandViewerSave ()
 
virtual ~G4VisCommandViewerSave ()
 
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 248 of file G4VisCommandsViewer.hh.

Constructor & Destructor Documentation

◆ G4VisCommandViewerSave()

G4VisCommandViewerSave::G4VisCommandViewerSave ( )

Definition at line 1313 of file G4VisCommandsViewer.cc.

1313 {
1314 G4bool omitable;
1315 fpCommand = new G4UIcmdWithAString ("/vis/viewer/save", this);
1316 fpCommand -> SetGuidance
1317 ("Write commands that define the current view to file.");
1318 fpCommand -> SetParameterName ("file-name", omitable = true);
1319 fpCommand -> SetDefaultValue ("G4cout");
1320}
bool G4bool
Definition: G4Types.hh:67

◆ ~G4VisCommandViewerSave()

G4VisCommandViewerSave::~G4VisCommandViewerSave ( )
virtual

Definition at line 1322 of file G4VisCommandsViewer.cc.

1322 {
1323 delete fpCommand;
1324}

Member Function Documentation

◆ GetCurrentValue()

G4String G4VisCommandViewerSave::GetCurrentValue ( G4UIcommand command)
virtual

Reimplemented from G4UImessenger.

Definition at line 1326 of file G4VisCommandsViewer.cc.

1327 {
1328 return "";
1329}

◆ SetNewValue()

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

Reimplemented from G4UImessenger.

Definition at line 1346 of file G4VisCommandsViewer.cc.

1346 {
1347
1349
1350 const G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
1351 if (!currentViewer) {
1352 if (verbosity >= G4VisManager::errors) {
1353 G4cout <<
1354 "ERROR: G4VisCommandsViewerSave::SetNewValue: no current viewer."
1355 << G4endl;
1356 }
1357 return;
1358 }
1359
1360 const G4Scene* currentScene = currentViewer->GetSceneHandler()->GetScene();
1361 if (!currentScene) {
1362 if (verbosity >= G4VisManager::errors) {
1363 G4cout <<
1364 "ERROR: G4VisCommandsViewerSave::SetNewValue: no current scene."
1365 << G4endl;
1366 }
1367 return;
1368 }
1369
1370 std::ofstream ofs;
1371 if (newValue != "G4cout") {
1372 // Check if file exists
1373 std::ifstream ifs(newValue);
1374 if (ifs) {
1375 if (verbosity >= G4VisManager::errors) {
1376 G4cout <<
1377 "ERROR: G4VisCommandsViewerSave::SetNewValue: File \""
1378 << newValue << "\" already exists."
1379 << G4endl;
1380 }
1381 ifs.close();
1382 return;
1383 }
1384 ofs.open(newValue);
1385 if (!ofs) {
1386 if (verbosity >= G4VisManager::errors) {
1387 G4cout <<
1388 "ERROR: G4VisCommandsViewerSave::SetNewValue: Trouble opening file \""
1389 << newValue << "\"."
1390 << G4endl;
1391 }
1392 ofs.close();
1393 return;
1394 }
1395 }
1396
1397 const G4ViewParameters& vp = currentViewer->GetViewParameters();
1398 const G4Point3D& stp = currentScene->GetStandardTargetPoint();
1399
1400 if (newValue == "G4cout") {
1401 WriteCommands(G4cout,vp,stp);
1402 } else {
1403 WriteCommands(ofs,vp,stp);
1404 ofs.close();
1405 }
1406
1407 if (verbosity >= G4VisManager::confirmations) {
1408 G4cout << "Viewer \"" << currentViewer -> GetName ()
1409 << "\"" << " saved to ";
1410 if (newValue == "G4cout") {
1411 G4cout << "G4cout.";
1412 } else {
1413 G4cout << "file \'" << newValue << "\".";
1414 }
1415 G4cout << G4endl;
1416 }
1417}
#define G4endl
Definition: G4ios.hh:52
G4DLLIMPORT std::ostream G4cout
const G4Point3D & GetStandardTargetPoint() const
G4Scene * GetScene() const
const G4ViewParameters & GetViewParameters() const
G4VSceneHandler * GetSceneHandler() const
static G4VisManager * fpVisManager
G4VViewer * GetCurrentViewer() const
static Verbosity GetVerbosity()

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