G4VisCommandViewerClone Class Reference

#include <G4VisCommandsViewer.hh>

Inheritance diagram for G4VisCommandViewerClone:

G4VVisCommandViewer G4VVisCommand G4UImessenger

Public Member Functions

 G4VisCommandViewerClone ()
virtual ~G4VisCommandViewerClone ()
G4String GetCurrentValue (G4UIcommand *command)
void SetNewValue (G4UIcommand *command, G4String newValue)

Detailed Description

Definition at line 118 of file G4VisCommandsViewer.hh.


Constructor & Destructor Documentation

G4VisCommandViewerClone::G4VisCommandViewerClone (  ) 

Definition at line 377 of file G4VisCommandsViewer.cc.

00377                                                   {
00378   G4bool omitable;
00379   fpCommand = new G4UIcommand ("/vis/viewer/clone", this);
00380   fpCommand -> SetGuidance ("Clones viewer.");
00381   fpCommand -> SetGuidance 
00382     ("By default, clones current viewer.  Clone becomes current."
00383      "\nClone name, if not provided, is derived from the original name."
00384      "\n\"/vis/viewer/list\" to see  possible viewer names.");
00385   G4UIparameter* parameter;
00386   parameter = new G4UIparameter ("original-viewer-name", 's', omitable = true);
00387   parameter -> SetCurrentAsDefault (true);
00388   fpCommand -> SetParameter (parameter);
00389   parameter = new G4UIparameter ("clone-name", 's', omitable = true);
00390   parameter -> SetDefaultValue ("none");
00391   fpCommand -> SetParameter (parameter);
00392 }

G4VisCommandViewerClone::~G4VisCommandViewerClone (  )  [virtual]

Definition at line 394 of file G4VisCommandsViewer.cc.

00394                                                    {
00395   delete fpCommand;
00396 }


Member Function Documentation

G4String G4VisCommandViewerClone::GetCurrentValue ( G4UIcommand command  )  [virtual]

Reimplemented from G4UImessenger.

Definition at line 398 of file G4VisCommandsViewer.cc.

References G4VVisCommand::fpVisManager.

00398                                                                {
00399   G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
00400   G4String originalName = viewer ? viewer -> GetName () : G4String("none");
00401   return "\"" + originalName + "\"";
00402 }

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

Reimplemented from G4UImessenger.

Definition at line 404 of file G4VisCommandsViewer.cc.

References G4UImanager::ApplyCommand(), G4String::both, G4VisManager::confirmations, G4VisManager::errors, G4VVisCommand::fpVisManager, G4cout, G4endl, G4VViewer::GetName(), G4UImanager::GetUIpointer(), G4UImanager::GetVerboseLevel(), G4VisManager::GetVerbosity(), G4VViewer::GetViewParameters(), G4ViewParameters::GetXGeometryString(), G4UImanager::SetVerboseLevel(), and G4String::strip().

00404                                                                           {
00405 
00406   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
00407 
00408   G4String originalName, cloneName;
00409   std::istringstream is (newValue);
00410 
00411   // Need to handle the possibility that the names contain embedded
00412   // blanks within quotation marks...
00413   char c;
00414   while (is.get(c) && c == ' '){}
00415   if (c == '"') {
00416     while (is.get(c) && c != '"') {originalName += c;}
00417   }
00418   else {
00419     originalName += c;
00420     while (is.get(c) && c != ' ') {originalName += c;}
00421   }
00422   originalName = originalName.strip (G4String::both, ' ');
00423   originalName = originalName.strip (G4String::both, '"');
00424 
00425   G4VViewer* originalViewer = fpVisManager -> GetViewer (originalName);
00426   if (!originalViewer) {
00427     if (verbosity >= G4VisManager::errors) {
00428       G4cout << "ERROR: Viewer \"" << originalName
00429              << "\" not found - \"/vis/viewer/list\" to see possibilities."
00430              << G4endl;
00431     }
00432     return;
00433   }
00434   originalName = originalViewer->GetName();  // Ensures long name.
00435 
00436   while (is.get(c) && c == ' '){}
00437   if (c == '"') {
00438     while (is.get(c) && c != '"') {cloneName += c;}
00439   }
00440   else {
00441     cloneName += c;
00442     while (is.get(c) && c != ' ') {cloneName += c;}
00443   }
00444   cloneName = cloneName.strip (G4String::both, ' ');
00445   cloneName = cloneName.strip (G4String::both, '"');
00446 
00447   G4bool errorWhileNaming = false;
00448   if (cloneName == "none") {
00449     G4int subID = 0;
00450     do {
00451       cloneName = originalName;
00452       std::ostringstream oss;
00453       oss << '-' << subID++;
00454       G4String::size_type lastDashPosition, nextSpacePosition;
00455       if ((lastDashPosition = cloneName.rfind('-')) !=  G4String::npos &&
00456           (nextSpacePosition = cloneName.find(" ", lastDashPosition)) !=
00457           G4String::npos) {
00458         cloneName.insert(nextSpacePosition, oss.str());
00459       } else {
00460         G4String::size_type spacePosition = cloneName.find(' ');
00461         if (spacePosition != G4String::npos)
00462           cloneName.insert(spacePosition, oss.str());
00463         else
00464           errorWhileNaming = true;
00465       }
00466     } while (!errorWhileNaming && fpVisManager -> GetViewer (cloneName));
00467   }
00468 
00469   if (errorWhileNaming) {
00470     if (verbosity >= G4VisManager::errors) {
00471       G4cout << "ERROR: While naming clone viewer \"" << cloneName
00472              << "\"."
00473              << G4endl;
00474     }
00475     return;
00476   }
00477 
00478   if (fpVisManager -> GetViewer (cloneName)) {
00479     if (verbosity >= G4VisManager::errors) {
00480       G4cout << "ERROR: Putative clone viewer \"" << cloneName
00481              << "\" already exists."
00482              << G4endl;
00483     }
00484     return;
00485   }
00486 
00487   G4String windowSizeHint =
00488     originalViewer->GetViewParameters().GetXGeometryString();
00489 
00490   G4UImanager* UImanager = G4UImanager::GetUIpointer();
00491   G4int keepVerbose = UImanager->GetVerboseLevel();
00492   G4int newVerbose(0);
00493   if (keepVerbose >= 2 ||
00494       fpVisManager->GetVerbosity() >= G4VisManager::confirmations)
00495     newVerbose = 2;
00496   UImanager->SetVerboseLevel(newVerbose);
00497   UImanager->ApplyCommand(G4String("/vis/viewer/select " + originalName));
00498   UImanager->ApplyCommand
00499     (G4String("/vis/viewer/create ! \"" + cloneName + "\" " + windowSizeHint));
00500   UImanager->ApplyCommand(G4String("/vis/viewer/set/all " + originalName));
00501   UImanager->SetVerboseLevel(keepVerbose);
00502 
00503   if (verbosity >= G4VisManager::confirmations) {
00504     G4cout << "Viewer \"" << originalName << "\" cloned." << G4endl;
00505     G4cout << "Clone \"" << cloneName << "\" now current." << G4endl;
00506   }
00507 }


The documentation for this class was generated from the following files:
Generated on Mon May 27 17:53:47 2013 for Geant4 by  doxygen 1.4.7