#include <G4VisCommandsSceneAdd.hh>
Inheritance diagram for G4VisCommandSceneAddVolume:
Public Member Functions | |
G4VisCommandSceneAddVolume () | |
virtual | ~G4VisCommandSceneAddVolume () |
G4String | GetCurrentValue (G4UIcommand *command) |
void | SetNewValue (G4UIcommand *command, G4String newValue) |
Definition at line 382 of file G4VisCommandsSceneAdd.hh.
G4VisCommandSceneAddVolume::G4VisCommandSceneAddVolume | ( | ) |
Definition at line 2566 of file G4VisCommandsSceneAdd.cc.
References G4Scene::UNLIMITED.
02566 { 02567 G4bool omitable; 02568 fpCommand = new G4UIcommand ("/vis/scene/add/volume", this); 02569 fpCommand -> SetGuidance 02570 ("Adds a physical volume to current scene, with optional clipping volume."); 02571 fpCommand -> SetGuidance 02572 ("If physical-volume-name is \"world\" (the default), the top of the" 02573 "\nmain geometry tree (material world) is added. If \"worlds\", the" 02574 "\ntop of all worlds - material world and parallel worlds, if any - are" 02575 "\nadded. Otherwise a search of all worlds is made, taking the first" 02576 "\nmatching occurence only. To see a representation of the geometry" 02577 "\nhierarchy of the worlds, try \"/vis/drawTree [worlds]\" or one of the" 02578 "\ndriver/browser combinations that have the required functionality, e.g., HepRep."); 02579 fpCommand -> SetGuidance 02580 ("If clip-volume-type is specified, the subsequent parameters are used to" 02581 "\nto define a clipping volume. For example," 02582 "\n\"vis/scene/add/volume ! ! ! -box km 0 1 0 1 0 1\" will draw the world" 02583 "\nwith the positive octant cut away."); 02584 fpCommand -> SetGuidance 02585 ("If clip-volume-type is prepended with '-', the clip-volume is subtracted" 02586 "\n(cutaway). (This is the default if there is no prepended character.)" 02587 "\nIf '*' is prepended, the intersection of the physical-volume and the" 02588 "\nclip-volume is made. (You can make a section/DCUT with a thin box, for" 02589 "\nexample)."); 02590 fpCommand -> SetGuidance 02591 ("For \"box\", the parameters are xmin,xmax,ymin,ymax,zmin,zmax." 02592 "\nOnly \"box\" is programmed at present."); 02593 G4UIparameter* parameter; 02594 parameter = new G4UIparameter ("physical-volume-name", 's', omitable = true); 02595 parameter -> SetDefaultValue ("world"); 02596 fpCommand -> SetParameter (parameter); 02597 parameter = new G4UIparameter ("copy-no", 'i', omitable = true); 02598 parameter -> SetGuidance 02599 ("If negative, matches any copy no. First name match is taken."); 02600 parameter -> SetDefaultValue (-1); 02601 fpCommand -> SetParameter (parameter); 02602 parameter = new G4UIparameter ("depth-of-descent", 'i', omitable = true); 02603 parameter -> SetGuidance 02604 ("Depth of descent of geometry hierarchy. Default = unlimited depth."); 02605 parameter -> SetDefaultValue (G4Scene::UNLIMITED); 02606 fpCommand -> SetParameter (parameter); 02607 parameter = new G4UIparameter ("clip-volume-type", 's', omitable = true); 02608 parameter -> SetParameterCandidates("none box -box *box"); 02609 parameter -> SetDefaultValue ("none"); 02610 parameter -> SetGuidance("[-|*]type. See general guidance."); 02611 fpCommand -> SetParameter (parameter); 02612 parameter = new G4UIparameter ("parameter-unit", 's', omitable = true); 02613 parameter -> SetDefaultValue ("m"); 02614 fpCommand -> SetParameter (parameter); 02615 parameter = new G4UIparameter ("parameter-1", 'd', omitable = true); 02616 parameter -> SetDefaultValue (0.); 02617 fpCommand -> SetParameter (parameter); 02618 parameter = new G4UIparameter ("parameter-2", 'd', omitable = true); 02619 parameter -> SetDefaultValue (0.); 02620 fpCommand -> SetParameter (parameter); 02621 parameter = new G4UIparameter ("parameter-3", 'd', omitable = true); 02622 parameter -> SetDefaultValue (0.); 02623 fpCommand -> SetParameter (parameter); 02624 parameter = new G4UIparameter ("parameter-4", 'd', omitable = true); 02625 parameter -> SetDefaultValue (0.); 02626 fpCommand -> SetParameter (parameter); 02627 parameter = new G4UIparameter ("parameter-5", 'd', omitable = true); 02628 parameter -> SetDefaultValue (0.); 02629 fpCommand -> SetParameter (parameter); 02630 parameter = new G4UIparameter ("parameter-6", 'd', omitable = true); 02631 parameter -> SetDefaultValue (0.); 02632 fpCommand -> SetParameter (parameter); 02633 }
G4VisCommandSceneAddVolume::~G4VisCommandSceneAddVolume | ( | ) | [virtual] |
G4String G4VisCommandSceneAddVolume::GetCurrentValue | ( | G4UIcommand * | command | ) | [virtual] |
void G4VisCommandSceneAddVolume::SetNewValue | ( | G4UIcommand * | command, | |
G4String | newValue | |||
) | [virtual] |
Reimplemented from G4UImessenger.
Definition at line 2643 of file G4VisCommandsSceneAdd.cc.
References G4VisManager::confirmations, G4VisManager::errors, G4VVisCommand::fpVisManager, G4cout, G4endl, G4VisManager::GetCurrentScene(), G4PhysicalVolumeSearchScene::GetFoundDepth(), G4PhysicalVolumeSearchScene::GetFoundFullPVPath(), G4PhysicalVolumeSearchScene::GetFoundTransformation(), G4PhysicalVolumeSearchScene::GetFoundVolume(), G4VPhysicalVolume::GetName(), G4TransportationManager::GetNoWorlds(), G4TransportationManager::GetTransportationManager(), G4VisManager::GetVerbosity(), G4TransportationManager::GetWorldsIterator(), G4PhysicalVolumeModel::intersection, G4PhysicalVolumeModel::subtraction, G4VVisCommand::UpdateVisManagerScene(), G4UIcommand::ValueOf(), and G4VisManager::warnings.
02644 { 02645 02646 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); 02647 G4bool warn = verbosity >= G4VisManager::warnings; 02648 02649 G4Scene* pScene = fpVisManager->GetCurrentScene(); 02650 if (!pScene) { 02651 if (verbosity >= G4VisManager::errors) { 02652 G4cout << "ERROR: No current scene. Please create one." << G4endl; 02653 } 02654 return; 02655 } 02656 02657 G4String name, clipVolumeType, parameterUnit; 02658 G4int copyNo, requestedDepthOfDescent; 02659 G4double param1, param2, param3, param4, param5, param6; 02660 std::istringstream is (newValue); 02661 is >> name >> copyNo >> requestedDepthOfDescent 02662 >> clipVolumeType >> parameterUnit 02663 >> param1 >> param2 >> param3 >> param4 >> param5 >> param6; 02664 G4PhysicalVolumeModel::ClippingMode clippingMode = 02665 G4PhysicalVolumeModel::subtraction; // Default subtraction mode. 02666 if (clipVolumeType[size_t(0)] == '-') { 02667 clipVolumeType = clipVolumeType.substr(1); // Remove first character. 02668 } else if (clipVolumeType[size_t(0)] == '*') { 02669 clippingMode = G4PhysicalVolumeModel::intersection; 02670 clipVolumeType = clipVolumeType.substr(1); 02671 } 02672 G4double unit = G4UIcommand::ValueOf(parameterUnit); 02673 param1 *= unit; param2 *= unit; param3 *= unit; 02674 param4 *= unit; param5 *= unit; param6 *= unit; 02675 02676 G4TransportationManager* transportationManager = 02677 G4TransportationManager::GetTransportationManager (); 02678 02679 size_t nWorlds = transportationManager->GetNoWorlds(); 02680 if (nWorlds > 1) { // Parallel worlds in operation... 02681 if (verbosity >= G4VisManager::warnings) { 02682 static G4bool warned = false; 02683 if (!warned && name != "worlds") { 02684 G4cout << 02685 "WARNING: Parallel worlds in operation. To visualise, specify" 02686 "\n \"worlds\" or the parallel world volume or sub-volume name" 02687 "\n and control visibility with /vis/geometry." 02688 << G4endl; 02689 std::vector<G4VPhysicalVolume*>::iterator iterWorld = 02690 transportationManager->GetWorldsIterator(); 02691 for (size_t i = 0; i < nWorlds; ++i, ++iterWorld) { 02692 G4cout << " World " << i << ": " << (*iterWorld)->GetName() 02693 << G4endl; 02694 warned = true; 02695 } 02696 } 02697 } 02698 } 02699 02700 G4VPhysicalVolume* world = *(transportationManager->GetWorldsIterator()); 02701 02702 if (!world) { 02703 if (verbosity >= G4VisManager::errors) { 02704 G4cout << 02705 "ERROR: G4VisCommandSceneAddVolume::SetNewValue:" 02706 "\n No world. Maybe the geometry has not yet been defined." 02707 "\n Try \"/run/initialize\"" 02708 << G4endl; 02709 } 02710 return; 02711 } 02712 02713 const std::vector<G4Scene::Model>& rdModelList = pScene -> GetRunDurationModelList(); 02714 std::vector<G4Scene::Model>::const_iterator it; 02715 for (it = rdModelList.begin(); it != rdModelList.end(); ++it) { 02716 if (it->fpModel->GetGlobalDescription().find("G4PhysicalVolumeModel") 02717 != std::string::npos) { 02718 if (((G4PhysicalVolumeModel*)(it->fpModel))->GetTopPhysicalVolume () == world) break; 02719 } 02720 } 02721 if (it != rdModelList.end()) { 02722 if (verbosity >= G4VisManager::warnings) { 02723 G4cout << "WARNING: There is already a volume, \"" 02724 << it -> fpModel -> GetGlobalDescription() 02725 << "\",\n in the run-duration model list of scene \"" 02726 << pScene -> GetName() 02727 << "\".\n To get a clean scene:" 02728 << "\n /vis/drawVolume " << name 02729 << "\n or" 02730 << "\n /vis/scene/create" 02731 << "\n /vis/scene/add/volume " << name 02732 << "\n /vis/sceneHandler/attach" 02733 << "\n (and also, if necessary, /vis/viewer/flush)" 02734 << G4endl; 02735 } 02736 return; 02737 } 02738 02739 std::vector<G4PhysicalVolumeModel*> models; 02740 std::vector<G4VPhysicalVolume*> foundVolumes; 02741 G4VPhysicalVolume* foundWorld = 0; 02742 typedef G4PhysicalVolumeModel::G4PhysicalVolumeNodeID PVNodeID; 02743 typedef std::vector<PVNodeID> PVPath; 02744 PVPath foundFullPVPath; 02745 std::vector<G4int> foundDepths; 02746 std::vector<G4Transform3D> transformations; 02747 02748 if (name == "world") { 02749 02750 models.push_back 02751 (new G4PhysicalVolumeModel (world, requestedDepthOfDescent)); 02752 foundVolumes.push_back(world); 02753 foundDepths.push_back(0); 02754 transformations.push_back(G4Transform3D()); 02755 02756 } else if (name == "worlds") { 02757 02758 if (nWorlds == 0) { 02759 if (verbosity >= G4VisManager::warnings) { 02760 G4cout << 02761 "WARNING: G4VisCommandSceneAddVolume::SetNewValue:" 02762 "\n Parallel worlds requested but none exist." 02763 "\n Just adding material world." 02764 << G4endl; 02765 } 02766 } 02767 std::vector<G4VPhysicalVolume*>::iterator iterWorld = 02768 transportationManager->GetWorldsIterator(); 02769 for (size_t i = 0; i < nWorlds; ++i, ++iterWorld) { 02770 models.push_back 02771 (new G4PhysicalVolumeModel (*iterWorld, requestedDepthOfDescent)); 02772 foundVolumes.push_back(*iterWorld); 02773 foundDepths.push_back(0); 02774 transformations.push_back(G4Transform3D()); 02775 } 02776 02777 } else { // Search all worlds... 02778 02779 std::vector<G4VPhysicalVolume*>::iterator iterWorld = 02780 transportationManager->GetWorldsIterator(); 02781 for (size_t i = 0; i < nWorlds; ++i, ++iterWorld) { 02782 G4PhysicalVolumeModel searchModel (*iterWorld); // Unlimited depth. 02783 G4ModelingParameters mp; // Default - no culling. 02784 searchModel.SetModelingParameters (&mp); 02785 G4PhysicalVolumeSearchScene searchScene (&searchModel, name, copyNo); 02786 searchModel.DescribeYourselfTo (searchScene); // Initiate search. 02787 G4VPhysicalVolume* foundVolume = searchScene.GetFoundVolume (); 02788 if (foundVolume) { 02789 foundWorld = *iterWorld; 02790 foundVolumes.push_back(foundVolume); 02791 foundFullPVPath = searchScene.GetFoundFullPVPath(); 02792 foundDepths.push_back(searchScene.GetFoundDepth()); 02793 transformations.push_back(searchScene.GetFoundTransformation()); 02794 break; 02795 } 02796 } 02797 02798 if (foundVolumes.size()) { 02799 for (size_t i = 0; i < foundVolumes.size(); ++i) { 02800 G4PhysicalVolumeModel* foundPVModel = new G4PhysicalVolumeModel 02801 (foundVolumes[i], requestedDepthOfDescent, transformations[i]); 02802 foundFullPVPath.pop_back(); // "Base" is "Found - 1". 02803 foundPVModel->SetBaseFullPVPath(foundFullPVPath); 02804 models.push_back(foundPVModel); 02805 } 02806 } else { 02807 if (verbosity >= G4VisManager::errors) { 02808 G4cout << "ERROR: Volume \"" << name << "\""; 02809 if (copyNo >= 0) { 02810 G4cout << ", copy no. " << copyNo << ","; 02811 } 02812 G4cout << " not found." << G4endl; 02813 } 02814 return; 02815 } 02816 } 02817 02818 if (clipVolumeType == "box") { 02819 const G4double dX = (param2 - param1) / 2.; 02820 const G4double dY = (param4 - param3) / 2.; 02821 const G4double dZ = (param6 - param5) / 2.; 02822 const G4double x0 = (param2 + param1) / 2.; 02823 const G4double y0 = (param4 + param3) / 2.; 02824 const G4double z0 = (param6 + param5) / 2.; 02825 G4VSolid* clippingSolid = 02826 new G4DisplacedSolid 02827 ("_displaced_clipping_box", 02828 new G4Box("_clipping_box",dX,dY,dZ), 02829 G4Translate3D(x0,y0,z0)); 02830 for (size_t i = 0; i < foundVolumes.size(); ++i) { 02831 models[i]->SetClippingSolid(clippingSolid); 02832 models[i]->SetClippingMode(clippingMode); 02833 } 02834 } // If any other shape consider NumberOfRotationSides!!!!!!!!!!! 02835 02836 const G4String& currentSceneName = pScene -> GetName (); 02837 G4bool failure = true; 02838 for (size_t i = 0; i < foundVolumes.size(); ++i) { 02839 G4bool successful = pScene -> AddRunDurationModel (models[i], warn); 02840 if (successful) { 02841 failure = false; 02842 if (verbosity >= G4VisManager::confirmations) { 02843 G4cout << "First occurrence of \"" 02844 << foundVolumes[i] -> GetName () 02845 << "\""; 02846 if (copyNo >= 0) { 02847 G4cout << ", copy no. " << copyNo << ","; 02848 } 02849 G4cout << "\n found "; 02850 if (foundWorld) 02851 G4cout << "in world \"" << foundWorld->GetName() << "\" "; 02852 G4cout << "at depth " << foundDepths[i] 02853 << ",\n with a requested depth of further descent of "; 02854 if (requestedDepthOfDescent < 0) { 02855 G4cout << "<0 (unlimited)"; 02856 } 02857 else { 02858 G4cout << requestedDepthOfDescent; 02859 } 02860 G4cout << ",\n has been added to scene \"" << currentSceneName << "\"." 02861 << G4endl; 02862 } 02863 } 02864 } 02865 02866 if (failure) { 02867 G4VisCommandsSceneAddUnsuccessful(verbosity); 02868 return; 02869 } 02870 02871 UpdateVisManagerScene (currentSceneName); 02872 }