615 {
616
618
619 G4String originalName, cloneName;
620 std::istringstream is (newValue);
621
622
623
624 char c = ' ';
625 while (is.get(c) && c == ' '){}
626 if (c == '"') {
627 while (is.get(c) && c != '"') {originalName += c;}
628 }
629 else {
630 originalName += c;
631 while (is.get(c) && c != ' ') {originalName += c;}
632 }
635
636 G4VViewer* originalViewer =
fpVisManager -> GetViewer (originalName);
637 if (!originalViewer) {
639 G4warn <<
"ERROR: Viewer \"" << originalName
640 << "\" not found - \"/vis/viewer/list\" to see possibilities."
642 }
643 return;
644 }
645 originalName = originalViewer->
GetName();
646
647 while (is.get(c) && c == ' '){}
648 if (c == '"') {
649 while (is.get(c) && c != '"') {cloneName += c;}
650 }
651 else {
652 cloneName += c;
653 while (is.get(c) && c != ' ') {cloneName += c;}
654 }
657
658 G4bool errorWhileNaming =
false;
659 if (cloneName == "none") {
661 do {
662 cloneName = originalName;
663 std::ostringstream oss;
664 oss << '-' << subID++;
665 G4String::size_type lastDashPosition, nextSpacePosition;
666 if ((lastDashPosition = cloneName.rfind('-')) != G4String::npos &&
667 (nextSpacePosition = cloneName.find(" ", lastDashPosition)) !=
668 G4String::npos) {
669 cloneName.insert(nextSpacePosition, oss.str());
670 } else {
671 G4String::size_type spacePosition = cloneName.find(' ');
672 if (spacePosition != G4String::npos)
673 cloneName.insert(spacePosition, oss.str());
674 else
675 errorWhileNaming = true;
676 }
677 }
while (!errorWhileNaming &&
fpVisManager -> GetViewer (cloneName));
678 }
679
680 if (errorWhileNaming) {
682 G4warn <<
"ERROR: While naming clone viewer \"" << cloneName
683 << "\"."
685 }
686 return;
687 }
688
691 G4warn <<
"ERROR: Putative clone viewer \"" << cloneName
692 << "\" already exists."
694 }
695 return;
696 }
697
698 G4String windowSizeHint =
700
702 UImanager->
ApplyCommand(G4String(
"/vis/viewer/select " + originalName));
704 (G4String("/vis/viewer/create ! \"" + cloneName + "\" " + windowSizeHint));
705 UImanager->
ApplyCommand(G4String(
"/vis/viewer/set/all " + originalName));
706
708 G4cout <<
"Viewer \"" << originalName <<
"\" cloned." <<
G4endl;
709 G4cout <<
"Clone \"" << cloneName <<
"\" now current." <<
G4endl;
710 }
711}
G4GLOB_DLL std::ostream G4cout
G4int ApplyCommand(const char *aCommand)
static G4UImanager * GetUIpointer()
const G4String & GetName() const
const G4ViewParameters & GetViewParameters() const
const G4String & GetXGeometryString() const
void strip(G4String &str, char ch=' ')
Remove leading and trailing characters from string.