#include <G4VisCommandsViewer.hh>
Inheritance diagram for G4VisCommandViewerSave:
Public Member Functions | |
G4VisCommandViewerSave () | |
virtual | ~G4VisCommandViewerSave () |
G4String | GetCurrentValue (G4UIcommand *command) |
void | SetNewValue (G4UIcommand *command, G4String newValue) |
Definition at line 248 of file G4VisCommandsViewer.hh.
G4VisCommandViewerSave::G4VisCommandViewerSave | ( | ) |
Definition at line 1313 of file G4VisCommandsViewer.cc.
01313 { 01314 G4bool omitable; 01315 fpCommand = new G4UIcmdWithAString ("/vis/viewer/save", this); 01316 fpCommand -> SetGuidance 01317 ("Write commands that define the current view to file."); 01318 fpCommand -> SetParameterName ("file-name", omitable = true); 01319 fpCommand -> SetDefaultValue ("G4cout"); 01320 }
G4VisCommandViewerSave::~G4VisCommandViewerSave | ( | ) | [virtual] |
G4String G4VisCommandViewerSave::GetCurrentValue | ( | G4UIcommand * | command | ) | [virtual] |
void G4VisCommandViewerSave::SetNewValue | ( | G4UIcommand * | command, | |
G4String | newValue | |||
) | [virtual] |
Reimplemented from G4UImessenger.
Definition at line 1346 of file G4VisCommandsViewer.cc.
References G4VisManager::confirmations, G4VisManager::errors, G4VVisCommand::fpVisManager, G4cout, G4endl, G4VisManager::GetCurrentViewer(), G4VSceneHandler::GetScene(), G4VViewer::GetSceneHandler(), G4Scene::GetStandardTargetPoint(), G4VisManager::GetVerbosity(), and G4VViewer::GetViewParameters().
01346 { 01347 01348 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); 01349 01350 const G4VViewer* currentViewer = fpVisManager->GetCurrentViewer(); 01351 if (!currentViewer) { 01352 if (verbosity >= G4VisManager::errors) { 01353 G4cout << 01354 "ERROR: G4VisCommandsViewerSave::SetNewValue: no current viewer." 01355 << G4endl; 01356 } 01357 return; 01358 } 01359 01360 const G4Scene* currentScene = currentViewer->GetSceneHandler()->GetScene(); 01361 if (!currentScene) { 01362 if (verbosity >= G4VisManager::errors) { 01363 G4cout << 01364 "ERROR: G4VisCommandsViewerSave::SetNewValue: no current scene." 01365 << G4endl; 01366 } 01367 return; 01368 } 01369 01370 std::ofstream ofs; 01371 if (newValue != "G4cout") { 01372 // Check if file exists 01373 std::ifstream ifs(newValue); 01374 if (ifs) { 01375 if (verbosity >= G4VisManager::errors) { 01376 G4cout << 01377 "ERROR: G4VisCommandsViewerSave::SetNewValue: File \"" 01378 << newValue << "\" already exists." 01379 << G4endl; 01380 } 01381 ifs.close(); 01382 return; 01383 } 01384 ofs.open(newValue); 01385 if (!ofs) { 01386 if (verbosity >= G4VisManager::errors) { 01387 G4cout << 01388 "ERROR: G4VisCommandsViewerSave::SetNewValue: Trouble opening file \"" 01389 << newValue << "\"." 01390 << G4endl; 01391 } 01392 ofs.close(); 01393 return; 01394 } 01395 } 01396 01397 const G4ViewParameters& vp = currentViewer->GetViewParameters(); 01398 const G4Point3D& stp = currentScene->GetStandardTargetPoint(); 01399 01400 if (newValue == "G4cout") { 01401 WriteCommands(G4cout,vp,stp); 01402 } else { 01403 WriteCommands(ofs,vp,stp); 01404 ofs.close(); 01405 } 01406 01407 if (verbosity >= G4VisManager::confirmations) { 01408 G4cout << "Viewer \"" << currentViewer -> GetName () 01409 << "\"" << " saved to "; 01410 if (newValue == "G4cout") { 01411 G4cout << "G4cout."; 01412 } else { 01413 G4cout << "file \'" << newValue << "\"."; 01414 } 01415 G4cout << G4endl; 01416 } 01417 }