Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // 26 // 27 27 28 // /vis/touchable commands - John Allison 14t 28 // /vis/touchable commands - John Allison 14th May 2014 29 29 30 #include "G4VisCommandsTouchable.hh" 30 #include "G4VisCommandsTouchable.hh" 31 31 32 #include "G4UImanager.hh" 32 #include "G4UImanager.hh" 33 #include "G4UIcmdWithAString.hh" 33 #include "G4UIcmdWithAString.hh" 34 #include "G4UIcmdWithoutParameter.hh" 34 #include "G4UIcmdWithoutParameter.hh" 35 #include "G4UIcmdWithABool.hh" 35 #include "G4UIcmdWithABool.hh" 36 #include "G4TransportationManager.hh" 36 #include "G4TransportationManager.hh" 37 #include "G4TouchableUtils.hh" 37 #include "G4TouchableUtils.hh" 38 #include "G4PhysicalVolumesSearchScene.hh" 38 #include "G4PhysicalVolumesSearchScene.hh" 39 #include "G4AttDef.hh" 39 #include "G4AttDef.hh" 40 #include "G4AttValue.hh" 40 #include "G4AttValue.hh" 41 #include "G4AttCheck.hh" 41 #include "G4AttCheck.hh" 42 #include "G4AxesModel.hh" 42 #include "G4AxesModel.hh" 43 43 44 #define G4warn G4cout << 45 << 46 G4VisCommandsTouchable::G4VisCommandsTouchable 44 G4VisCommandsTouchable::G4VisCommandsTouchable() 47 { 45 { 48 G4bool omitable; 46 G4bool omitable; 49 47 50 fpCommandCentreAndZoomInOn = new G4UIcmdWith 48 fpCommandCentreAndZoomInOn = new G4UIcmdWithoutParameter("/vis/touchable/centreAndZoomInOn",this); 51 fpCommandCentreAndZoomInOn->SetGuidance ("Ce 49 fpCommandCentreAndZoomInOn->SetGuidance ("Centre and zoom in on the current touchable."); 52 fpCommandCentreAndZoomInOn->SetGuidance 50 fpCommandCentreAndZoomInOn->SetGuidance 53 ("Use \"/vis/set/touchable\" to set current 51 ("Use \"/vis/set/touchable\" to set current touchable."); 54 fpCommandCentreAndZoomInOn->SetGuidance 52 fpCommandCentreAndZoomInOn->SetGuidance 55 ("You may also need \"/vis/touchable/findPat 53 ("You may also need \"/vis/touchable/findPath\"."); 56 fpCommandCentreAndZoomInOn->SetGuidance 54 fpCommandCentreAndZoomInOn->SetGuidance 57 ("Use \"/vis/touchable/set\" to set attribut 55 ("Use \"/vis/touchable/set\" to set attributes."); 58 56 59 fpCommandCentreOn = new G4UIcmdWithoutParame 57 fpCommandCentreOn = new G4UIcmdWithoutParameter("/vis/touchable/centreOn",this); 60 fpCommandCentreOn->SetGuidance ("Centre the 58 fpCommandCentreOn->SetGuidance ("Centre the view on the current touchable."); 61 // Pick up additional guidance from /vis/vie 59 // Pick up additional guidance from /vis/viewer/centreAndZoomInOn 62 CopyGuidanceFrom(fpCommandCentreAndZoomInOn, 60 CopyGuidanceFrom(fpCommandCentreAndZoomInOn,fpCommandCentreOn,1); 63 61 64 fpCommandDraw = new G4UIcmdWithABool("/vis/t << 62 fpCommandDraw = new G4UIcmdWithoutParameter("/vis/touchable/draw",this); 65 fpCommandDraw->SetGuidance("Draw touchable." 63 fpCommandDraw->SetGuidance("Draw touchable."); 66 fpCommandDraw->SetGuidance << 67 ("If parameter == true, also draw extent as << 68 // Pick up additional guidance from /vis/vie 64 // Pick up additional guidance from /vis/viewer/centreAndZoomInOn 69 CopyGuidanceFrom(fpCommandCentreAndZoomInOn, 65 CopyGuidanceFrom(fpCommandCentreAndZoomInOn,fpCommandDraw,1); 70 fpCommandDraw->SetParameterName("extent", om << 71 fpCommandDraw->SetDefaultValue(false); << 72 66 73 fpCommandDump = new G4UIcmdWithoutParameter( 67 fpCommandDump = new G4UIcmdWithoutParameter("/vis/touchable/dump",this); 74 fpCommandDump->SetGuidance("Dump touchable a 68 fpCommandDump->SetGuidance("Dump touchable attributes."); 75 // Pick up additional guidance from /vis/vie 69 // Pick up additional guidance from /vis/viewer/centreAndZoomInOn 76 CopyGuidanceFrom(fpCommandCentreAndZoomInOn, 70 CopyGuidanceFrom(fpCommandCentreAndZoomInOn,fpCommandDump,1); 77 71 78 fpCommandExtentForField = new G4UIcmdWithABo 72 fpCommandExtentForField = new G4UIcmdWithABool("/vis/touchable/extentForField",this); 79 fpCommandExtentForField->SetGuidance("Set ex 73 fpCommandExtentForField->SetGuidance("Set extent for field."); 80 fpCommandExtentForField->SetGuidance("If par 74 fpCommandExtentForField->SetGuidance("If parameter == true, also draw."); 81 // Pick up additional guidance from /vis/vie 75 // Pick up additional guidance from /vis/viewer/centreAndZoomInOn 82 CopyGuidanceFrom(fpCommandCentreAndZoomInOn, 76 CopyGuidanceFrom(fpCommandCentreAndZoomInOn,fpCommandExtentForField,1); 83 fpCommandExtentForField->SetParameterName("d 77 fpCommandExtentForField->SetParameterName("draw", omitable = true); 84 fpCommandExtentForField->SetDefaultValue(fal 78 fpCommandExtentForField->SetDefaultValue(false); 85 79 86 fpCommandFindPath = new G4UIcommand("/vis/to 80 fpCommandFindPath = new G4UIcommand("/vis/touchable/findPath",this); 87 fpCommandFindPath->SetGuidance 81 fpCommandFindPath->SetGuidance 88 ("Prints the path to touchable and its logic 82 ("Prints the path to touchable and its logical volume mother" 89 "\ngiven a physical volume name and copy no 83 "\ngiven a physical volume name and copy no."); 90 fpCommandFindPath -> SetGuidance 84 fpCommandFindPath -> SetGuidance 91 ("A search of all worlds is made and all phy 85 ("A search of all worlds is made and all physical volume names are" 92 "\nmatched against the argument of this com 86 "\nmatched against the argument of this command. If this is of the" 93 "\nform \"/regexp/\", where regexp is a reg 87 "\nform \"/regexp/\", where regexp is a regular expression (see C++ regex)," 94 "\nthe physical volume name is matched agai 88 "\nthe physical volume name is matched against regexp by the usual rules" 95 "\nof regular expression matching. Otherwis 89 "\nof regular expression matching. Otherwise an exact match is required." 96 "\nFor example, \"/Shap/\" matches \"Shape1 90 "\nFor example, \"/Shap/\" matches \"Shape1\" and \"Shape2\"."); 97 fpCommandFindPath -> SetGuidance 91 fpCommandFindPath -> SetGuidance 98 ("It may help to see a textual representatio 92 ("It may help to see a textual representation of the geometry hierarchy of" 99 "\nthe worlds. Try \"/vis/drawTree [worlds] 93 "\nthe worlds. Try \"/vis/drawTree [worlds]\" or one of the driver/browser" 100 "\ncombinations that have the required func 94 "\ncombinations that have the required functionality, e.g., HepRep."); 101 G4UIparameter* parameter; 95 G4UIparameter* parameter; 102 parameter = new G4UIparameter ("physical-vol 96 parameter = new G4UIparameter ("physical-volume-name", 's', omitable = true); 103 parameter -> SetDefaultValue ("world"); 97 parameter -> SetDefaultValue ("world"); 104 fpCommandFindPath -> SetParameter (parameter 98 fpCommandFindPath -> SetParameter (parameter); 105 parameter = new G4UIparameter ("copy-no", 'i 99 parameter = new G4UIparameter ("copy-no", 'i', omitable = true); 106 parameter -> SetGuidance ("If negative, matc 100 parameter -> SetGuidance ("If negative, matches any copy no."); 107 parameter -> SetDefaultValue (-1); 101 parameter -> SetDefaultValue (-1); 108 fpCommandFindPath -> SetParameter (parameter 102 fpCommandFindPath -> SetParameter (parameter); 109 103 110 fpCommandLocalAxes = new G4UIcmdWithoutParam 104 fpCommandLocalAxes = new G4UIcmdWithoutParameter("/vis/touchable/localAxes",this); 111 fpCommandLocalAxes->SetGuidance("Draw local 105 fpCommandLocalAxes->SetGuidance("Draw local axes."); 112 // Pick up additional guidance from /vis/vie 106 // Pick up additional guidance from /vis/viewer/centreAndZoomInOn 113 CopyGuidanceFrom(fpCommandCentreAndZoomInOn, 107 CopyGuidanceFrom(fpCommandCentreAndZoomInOn,fpCommandLocalAxes,1); 114 108 115 fpCommandShowExtent = new G4UIcmdWithABool(" 109 fpCommandShowExtent = new G4UIcmdWithABool("/vis/touchable/showExtent",this); 116 fpCommandShowExtent->SetGuidance("Print exte 110 fpCommandShowExtent->SetGuidance("Print extent of touchable."); 117 fpCommandShowExtent->SetGuidance("If paramet 111 fpCommandShowExtent->SetGuidance("If parameter == true, also draw."); 118 // Pick up additional guidance from /vis/vie 112 // Pick up additional guidance from /vis/viewer/centreAndZoomInOn 119 CopyGuidanceFrom(fpCommandCentreAndZoomInOn, 113 CopyGuidanceFrom(fpCommandCentreAndZoomInOn,fpCommandShowExtent,1); 120 fpCommandShowExtent->SetParameterName("draw" 114 fpCommandShowExtent->SetParameterName("draw", omitable = true); 121 fpCommandShowExtent->SetDefaultValue(false); 115 fpCommandShowExtent->SetDefaultValue(false); 122 116 123 fpCommandTwinkle = new G4UIcmdWithoutParamet << 124 fpCommandTwinkle->SetGuidance("Cause touchab << 125 // Pick up additional guidance from /vis/vie << 126 CopyGuidanceFrom(fpCommandCentreAndZoomInOn, << 127 << 128 fpCommandVolumeForField = new G4UIcmdWithABo 117 fpCommandVolumeForField = new G4UIcmdWithABool("/vis/touchable/volumeForField",this); 129 fpCommandVolumeForField->SetGuidance("Set vo 118 fpCommandVolumeForField->SetGuidance("Set volume for field."); 130 fpCommandVolumeForField->SetGuidance("If par 119 fpCommandVolumeForField->SetGuidance("If parameter == true, also draw."); 131 // Pick up additional guidance from /vis/vie 120 // Pick up additional guidance from /vis/viewer/centreAndZoomInOn 132 CopyGuidanceFrom(fpCommandCentreAndZoomInOn, 121 CopyGuidanceFrom(fpCommandCentreAndZoomInOn,fpCommandVolumeForField,1); 133 fpCommandVolumeForField->SetParameterName("d 122 fpCommandVolumeForField->SetParameterName("draw", omitable = true); 134 fpCommandVolumeForField->SetDefaultValue(fal 123 fpCommandVolumeForField->SetDefaultValue(false); 135 } 124 } 136 125 137 G4VisCommandsTouchable::~G4VisCommandsTouchabl 126 G4VisCommandsTouchable::~G4VisCommandsTouchable() { 138 delete fpCommandVolumeForField; 127 delete fpCommandVolumeForField; 139 delete fpCommandTwinkle; << 140 delete fpCommandShowExtent; 128 delete fpCommandShowExtent; 141 delete fpCommandLocalAxes; 129 delete fpCommandLocalAxes; 142 delete fpCommandFindPath; 130 delete fpCommandFindPath; 143 delete fpCommandExtentForField; 131 delete fpCommandExtentForField; 144 delete fpCommandDump; 132 delete fpCommandDump; 145 delete fpCommandDraw; 133 delete fpCommandDraw; 146 delete fpCommandCentreAndZoomInOn; 134 delete fpCommandCentreAndZoomInOn; 147 delete fpCommandCentreOn; 135 delete fpCommandCentreOn; 148 } 136 } 149 137 150 G4String G4VisCommandsTouchable::GetCurrentVal 138 G4String G4VisCommandsTouchable::GetCurrentValue(G4UIcommand*) { 151 return ""; 139 return ""; 152 } 140 } 153 141 154 void G4VisCommandsTouchable::SetNewValue 142 void G4VisCommandsTouchable::SetNewValue 155 (G4UIcommand* command, G4String newValue) 143 (G4UIcommand* command, G4String newValue) 156 { 144 { 157 G4VisManager::Verbosity verbosity = fpVisMan 145 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); 158 G4bool warn = verbosity >= G4VisManager::war 146 G4bool warn = verbosity >= G4VisManager::warnings; 159 147 160 G4UImanager* UImanager = G4UImanager::GetUIp 148 G4UImanager* UImanager = G4UImanager::GetUIpointer(); 161 149 162 G4TransportationManager* transportationManag 150 G4TransportationManager* transportationManager = 163 G4TransportationManager::GetTransportationMa 151 G4TransportationManager::GetTransportationManager (); 164 152 165 size_t nWorlds = transportationManager->GetN 153 size_t nWorlds = transportationManager->GetNoWorlds(); 166 154 167 G4VPhysicalVolume* world = *(transportationM 155 G4VPhysicalVolume* world = *(transportationManager->GetWorldsIterator()); 168 if (!world) { 156 if (!world) { 169 if (verbosity >= G4VisManager::errors) { 157 if (verbosity >= G4VisManager::errors) { 170 G4warn << << 158 G4cerr << 171 "ERROR: G4VisCommandsTouchable::SetNewVa 159 "ERROR: G4VisCommandsTouchable::SetNewValue:" 172 "\n No world. Maybe the geometry has n 160 "\n No world. Maybe the geometry has not yet been defined." 173 "\n Try \"/run/initialize\"" 161 "\n Try \"/run/initialize\"" 174 << G4endl; 162 << G4endl; 175 } 163 } 176 return; 164 return; 177 } 165 } 178 166 179 if (command == fpCommandDump) { << 180 << 181 G4PhysicalVolumeModel::TouchableProperties << 182 G4TouchableUtils::FindTouchableProperties( << 183 if (properties.fpTouchablePV) { << 184 // To handle parameterisations we have t << 185 properties.fpTouchablePV->SetCopyNo(prop << 186 G4PhysicalVolumeModel tempPVModel << 187 (properties.fpTouchablePV, << 188 G4PhysicalVolumeModel::UNLIMITED, << 189 properties.fTouchableGlobalTransform, << 190 nullptr, // Modelling parameters (not u << 191 true, // use full extent (prevents calc << 192 properties.fTouchableBaseFullPVPath); << 193 const std::map<G4String,G4AttDef>* attDe << 194 std::vector<G4AttValue>* attValues = tem << 195 G4cout << G4AttCheck(attValues,attDefs); << 196 delete attValues; << 197 const auto lv = properties.fpTouchablePV << 198 const auto polyhedron = lv->GetSolid()-> << 199 if (polyhedron) { << 200 polyhedron->SetVisAttributes(lv->GetVi << 201 G4cout << "\nLocal polyhedron coordina << 202 const G4Transform3D& transform = tempP << 203 polyhedron->Transform(transform); << 204 G4cout << "\nGlobal polyhedron coordin << 205 } << 206 } else { << 207 G4warn << "Touchable not found." << G4en << 208 } << 209 return; << 210 << 211 } else if (command == fpCommandFindPath) { << 212 << 213 G4String pvName; << 214 G4int copyNo; << 215 std::istringstream iss(newValue); << 216 iss >> pvName >> copyNo; << 217 std::vector<G4PhysicalVolumesSearchScene:: << 218 std::vector<G4VPhysicalVolume*>::iterator << 219 transportationManager->GetWorldsIterator() << 220 for (size_t i = 0; i < nWorlds; ++i, ++ite << 221 G4PhysicalVolumeModel searchModel (*iter << 222 G4ModelingParameters mp; // Default - n << 223 searchModel.SetModelingParameters (&mp); << 224 // Find all instances at any position in << 225 G4PhysicalVolumesSearchScene searchScene << 226 searchModel.DescribeYourselfTo (searchSc << 227 for (const auto& findings: searchScene.G << 228 findingsVector.push_back(findings); << 229 } << 230 } << 231 for (const auto& findings: findingsVector) << 232 G4cout << 233 << findings.fFoundBasePVPath << 234 << ' ' << findings.fpFoundPV->GetName() << 235 << ' ' << findings.fFoundPVCopyNo << 236 << " (mother logical volume: " << 237 << findings.fpFoundPV->GetMotherLogical( << 238 << ')' << 239 << G4endl; << 240 } << 241 if (findingsVector.size()) { << 242 G4cout << 243 << "Use this to set a particular touchab << 244 << "\nor to see overlaps: \"/vis/drawLog << 245 << G4endl; << 246 } else { << 247 G4warn << pvName; << 248 if (copyNo >= 0) G4warn << ':' << copyNo << 249 G4warn << " not found" << G4endl; << 250 } << 251 return; << 252 } << 253 << 254 G4VViewer* currentViewer = fpVisManager -> G 167 G4VViewer* currentViewer = fpVisManager -> GetCurrentViewer (); 255 if (!currentViewer) { 168 if (!currentViewer) { 256 if (verbosity >= G4VisManager::errors) { 169 if (verbosity >= G4VisManager::errors) { 257 G4warn << << 170 G4cerr << 258 "ERROR: No current viewer - \"/vis/viewe 171 "ERROR: No current viewer - \"/vis/viewer/list\" to see possibilities." 259 << G4endl; 172 << G4endl; 260 } 173 } 261 return; 174 return; 262 } 175 } 263 176 264 G4Scene* currentScene = fpVisManager->GetCur 177 G4Scene* currentScene = fpVisManager->GetCurrentScene(); 265 if (!currentScene) { 178 if (!currentScene) { 266 if (verbosity >= G4VisManager::errors) { 179 if (verbosity >= G4VisManager::errors) { 267 G4warn << << 180 G4cerr << 268 "ERROR: No current scene - \"/vis/scene/ 181 "ERROR: No current scene - \"/vis/scene/list\" to see possibilities." 269 << G4endl; 182 << G4endl; 270 } 183 } 271 return; 184 return; 272 } 185 } 273 186 274 if (command == fpCommandCentreOn || command 187 if (command == fpCommandCentreOn || command == fpCommandCentreAndZoomInOn) { 275 << 188 276 // For twinkling... << 277 std::vector<std::vector<G4PhysicalVolumeMo << 278 << 279 G4PhysicalVolumeModel::TouchableProperties 189 G4PhysicalVolumeModel::TouchableProperties properties = 280 G4TouchableUtils::FindTouchableProperties( 190 G4TouchableUtils::FindTouchableProperties(fCurrentTouchableProperties.fTouchablePath); 281 if (properties.fpTouchablePV) { 191 if (properties.fpTouchablePV) { 282 // To handle parameterisations, set copy 192 // To handle parameterisations, set copy number 283 properties.fpTouchablePV->SetCopyNo(prop 193 properties.fpTouchablePV->SetCopyNo(properties.fCopyNo); 284 G4PhysicalVolumeModel tempPVModel 194 G4PhysicalVolumeModel tempPVModel 285 (properties.fpTouchablePV, 195 (properties.fpTouchablePV, 286 G4PhysicalVolumeModel::UNLIMITED, 196 G4PhysicalVolumeModel::UNLIMITED, 287 properties.fTouchableGlobalTransform, 197 properties.fTouchableGlobalTransform, 288 nullptr, // Modelling parameters (not u 198 nullptr, // Modelling parameters (not used) 289 true, // use full extent (prevents calc 199 true, // use full extent (prevents calculating own extent, which crashes) 290 properties.fTouchableBaseFullPVPath); 200 properties.fTouchableBaseFullPVPath); 291 touchables.push_back(properties.fTouchab << 292 // Use a temporary scene in order to fin 201 // Use a temporary scene in order to find vis extent 293 G4Scene tempScene("Centre Scene"); 202 G4Scene tempScene("Centre Scene"); 294 G4bool successful = tempScene.AddRunDura 203 G4bool successful = tempScene.AddRunDurationModel(&tempPVModel,warn); 295 if (!successful) return; << 204 if (successful) { 296 if (verbosity >= G4VisManager::parameter << 205 if (verbosity >= G4VisManager::confirmations) { 297 G4cout << 206 G4cout 298 << "Touchable " << fCurrentTouchablePr << 207 << "Touchable " << fCurrentTouchableProperties.fTouchablePath 299 << ",\n has been added to temporary s << 208 << ",\n has been added to temporary scene \"" << tempScene.GetName() << "\"." 300 << G4endl; << 209 << G4endl; >> 210 } 301 } 211 } 302 << 303 const G4VisExtent& newExtent = tempScene 212 const G4VisExtent& newExtent = tempScene.GetExtent(); 304 const G4ThreeVector& newTargetPoint = ne 213 const G4ThreeVector& newTargetPoint = newExtent.GetExtentCentre(); 305 G4ViewParameters saveVP = currentViewer- 214 G4ViewParameters saveVP = currentViewer->GetViewParameters(); 306 G4ViewParameters newVP = saveVP; 215 G4ViewParameters newVP = saveVP; 307 if (command == fpCommandCentreAndZoomInO 216 if (command == fpCommandCentreAndZoomInOn) { 308 // Calculate the new zoom factor 217 // Calculate the new zoom factor 309 const G4double zoomFactor 218 const G4double zoomFactor 310 = currentScene->GetExtent().GetExtentR 219 = currentScene->GetExtent().GetExtentRadius()/newExtent.GetExtentRadius(); 311 newVP.SetZoomFactor(zoomFactor); 220 newVP.SetZoomFactor(zoomFactor); 312 } 221 } 313 // Change the target point 222 // Change the target point 314 const G4Point3D& standardTargetPoint = c 223 const G4Point3D& standardTargetPoint = currentScene->GetStandardTargetPoint(); 315 newVP.SetCurrentTargetPoint(newTargetPoi 224 newVP.SetCurrentTargetPoint(newTargetPoint - standardTargetPoint); 316 << 317 // Interpolate 225 // Interpolate 318 auto keepVisVerbose = fpVisManager->GetV << 226 InterpolateToNewView(currentViewer, saveVP, newVP); 319 fpVisManager->SetVerboseLevel(G4VisManag << 320 if (newVP != saveVP) InterpolateToNewVie << 321 // ...and twinkle << 322 Twinkle(currentViewer,newVP,touchables); << 323 fpVisManager->SetVerboseLevel(keepVisVer << 324 << 325 if (verbosity >= G4VisManager::confirmat 227 if (verbosity >= G4VisManager::confirmations) { 326 G4cout 228 G4cout 327 << "Viewer \"" << currentViewer->GetNa 229 << "Viewer \"" << currentViewer->GetName() 328 << "\" centred "; 230 << "\" centred "; 329 if (fpCommandCentreAndZoomInOn) { 231 if (fpCommandCentreAndZoomInOn) { 330 G4cout << "and zoomed in"; 232 G4cout << "and zoomed in"; 331 } 233 } 332 G4cout << " on touchable\n" << fCurren 234 G4cout << " on touchable\n" << fCurrentTouchableProperties.fTouchablePath 333 << G4endl; 235 << G4endl; 334 } 236 } 335 SetViewParameters(currentViewer, newVP); 237 SetViewParameters(currentViewer, newVP); 336 } else { 238 } else { 337 G4warn << "Touchable not found." << G4en << 239 G4cout << "Touchable not found." << G4endl; 338 } 240 } 339 return; 241 return; 340 242 341 } else if (command == fpCommandDraw) { 243 } else if (command == fpCommandDraw) { 342 244 343 G4PhysicalVolumeModel::TouchableProperties 245 G4PhysicalVolumeModel::TouchableProperties properties = 344 G4TouchableUtils::FindTouchableProperties( 246 G4TouchableUtils::FindTouchableProperties(fCurrentTouchableProperties.fTouchablePath); 345 if (properties.fpTouchablePV) { 247 if (properties.fpTouchablePV) { 346 // To handle parameterisations we have t << 248 // To handle paramaterisations we have to set the copy number 347 properties.fpTouchablePV->SetCopyNo(prop 249 properties.fpTouchablePV->SetCopyNo(properties.fCopyNo); 348 G4PhysicalVolumeModel* pvModel = new G4P 250 G4PhysicalVolumeModel* pvModel = new G4PhysicalVolumeModel 349 (properties.fpTouchablePV, 251 (properties.fpTouchablePV, 350 G4PhysicalVolumeModel::UNLIMITED, 252 G4PhysicalVolumeModel::UNLIMITED, 351 properties.fTouchableGlobalTransform, 253 properties.fTouchableGlobalTransform, 352 nullptr, // Modelling parameters (not u 254 nullptr, // Modelling parameters (not used) 353 true, // use full extent (prevents calc 255 true, // use full extent (prevents calculating own extent, which crashes) 354 properties.fTouchableBaseFullPVPath); 256 properties.fTouchableBaseFullPVPath); 355 257 >> 258 G4int keepVerbose = UImanager->GetVerboseLevel(); >> 259 G4int newVerbose(0); >> 260 if (keepVerbose >= 2 || verbosity >= G4VisManager::confirmations) >> 261 newVerbose = 2; >> 262 UImanager->SetVerboseLevel(newVerbose); 356 UImanager->ApplyCommand("/vis/scene/crea 263 UImanager->ApplyCommand("/vis/scene/create"); 357 currentScene = fpVisManager->GetCurrentS 264 currentScene = fpVisManager->GetCurrentScene(); // New current scene 358 G4bool successful = currentScene->AddRun 265 G4bool successful = currentScene->AddRunDurationModel(pvModel,warn); 359 UImanager->ApplyCommand("/vis/sceneHandl 266 UImanager->ApplyCommand("/vis/sceneHandler/attach"); >> 267 UImanager->SetVerboseLevel(keepVerbose); 360 268 361 if (successful) { 269 if (successful) { 362 if (fpCommandDraw->GetNewBoolValue(new << 363 const auto& extent = pvModel->GetExt << 364 const G4double halfX = (extent.GetXm << 365 const G4double halfY = (extent.GetYm << 366 const G4double halfZ = (extent.GetZm << 367 G4Box extentBox("extent",halfX,halfY << 368 G4VisAttributes extentVA; << 369 extentVA.SetForceWireframe(); << 370 fpVisManager->Draw(extentBox,extentV << 371 } << 372 if (verbosity >= G4VisManager::confirm 270 if (verbosity >= G4VisManager::confirmations) { 373 G4cout << "\"" << properties.fpTouch 271 G4cout << "\"" << properties.fpTouchablePV->GetName() 374 << "\", copy no. " << properties.fCo << 272 << "\", copy no. " << properties.fCopyNo << " drawn" 375 if (fpCommandDraw->GetNewBoolValue(n << 273 << G4endl; 376 G4cout << " with extent box"; << 377 } << 378 G4cout << '.' << G4endl; << 379 } 274 } 380 } else { 275 } else { 381 G4VisCommandsSceneAddUnsuccessful(verb 276 G4VisCommandsSceneAddUnsuccessful(verbosity); 382 } 277 } 383 } else { 278 } else { 384 G4warn << "Touchable not found." << G4en << 279 G4cout << "Touchable not found." << G4endl; >> 280 } >> 281 return; >> 282 >> 283 } else if (command == fpCommandDump) { >> 284 >> 285 G4PhysicalVolumeModel::TouchableProperties properties = >> 286 G4TouchableUtils::FindTouchableProperties(fCurrentTouchableProperties.fTouchablePath); >> 287 if (properties.fpTouchablePV) { >> 288 // To handle paramaterisations we have to set the copy number >> 289 properties.fpTouchablePV->SetCopyNo(properties.fCopyNo); >> 290 G4PhysicalVolumeModel tempPVModel >> 291 (properties.fpTouchablePV, >> 292 G4PhysicalVolumeModel::UNLIMITED, >> 293 properties.fTouchableGlobalTransform, >> 294 nullptr, // Modelling parameters (not used) >> 295 true, // use full extent (prevents calculating own extent, which crashes) >> 296 properties.fTouchableBaseFullPVPath); >> 297 const std::map<G4String,G4AttDef>* attDefs = tempPVModel.GetAttDefs(); >> 298 std::vector<G4AttValue>* attValues = tempPVModel.CreateCurrentAttValues(); >> 299 G4cout << G4AttCheck(attValues,attDefs); >> 300 delete attValues; >> 301 G4Polyhedron* polyhedron = >> 302 properties.fpTouchablePV->GetLogicalVolume()->GetSolid()->GetPolyhedron(); >> 303 G4cout << "\nLocal polyhedron coordinates:\n" << *polyhedron; >> 304 const G4Transform3D& transform = tempPVModel.GetCurrentTransform(); >> 305 polyhedron->Transform(transform); >> 306 G4cout << "\nGlobal polyhedron coordinates:\n" << *polyhedron; >> 307 } else { >> 308 G4cout << "Touchable not found." << G4endl; 385 } 309 } 386 return; 310 return; 387 311 388 } else if (command == fpCommandExtentForFiel 312 } else if (command == fpCommandExtentForField) { 389 313 390 G4PhysicalVolumeModel::TouchableProperties 314 G4PhysicalVolumeModel::TouchableProperties properties = 391 G4TouchableUtils::FindTouchableProperties( 315 G4TouchableUtils::FindTouchableProperties(fCurrentTouchableProperties.fTouchablePath); 392 if (properties.fpTouchablePV) { 316 if (properties.fpTouchablePV) { 393 G4VisExtent extent 317 G4VisExtent extent 394 = properties.fpTouchablePV->GetLogicalVo 318 = properties.fpTouchablePV->GetLogicalVolume()->GetSolid()->GetExtent(); 395 extent.Transform(properties.fTouchableGl 319 extent.Transform(properties.fTouchableGlobalTransform); 396 fCurrentExtentForField = extent; 320 fCurrentExtentForField = extent; 397 fCurrrentPVFindingsForField.clear(); 321 fCurrrentPVFindingsForField.clear(); 398 if (verbosity >= G4VisManager::confirmat 322 if (verbosity >= G4VisManager::confirmations) { 399 G4cout << "Extent for field set to " < 323 G4cout << "Extent for field set to " << extent 400 << "\nVolume for field has been cleare 324 << "\nVolume for field has been cleared." 401 << G4endl; 325 << G4endl; 402 } 326 } 403 if (fpCommandExtentForField->GetNewBoolV 327 if (fpCommandExtentForField->GetNewBoolValue(newValue)) { 404 DrawExtent(extent); 328 DrawExtent(extent); 405 } 329 } 406 } else { 330 } else { 407 G4warn << "Touchable not found." << G4en << 331 G4cout << "Touchable not found." << G4endl; 408 } 332 } 409 return; 333 return; 410 334 411 } else if (command == fpCommandLocalAxes) { << 335 } else if (command == fpCommandFindPath) { 412 336 413 G4PhysicalVolumeModel::TouchableProperties << 337 G4String pvName; 414 G4TouchableUtils::FindTouchableProperties( << 338 G4int copyNo; 415 if (properties.fpTouchablePV) { << 339 std::istringstream iss(newValue); 416 const auto& transform = fCurrentTouchabl << 340 iss >> pvName >> copyNo; 417 const auto& extent = fCurrentTouchablePr << 341 std::vector<G4PhysicalVolumesSearchScene::Findings> findingsVector; 418 const G4double lengthMax = extent.GetExt << 342 std::vector<G4VPhysicalVolume*>::iterator iterWorld = 419 const G4double intLog10LengthMax = std:: << 343 transportationManager->GetWorldsIterator(); 420 G4double length = std::pow(10,intLog10Le << 344 for (size_t i = 0; i < nWorlds; ++i, ++iterWorld) { 421 if (5.*length < lengthMax) length *= 5.; << 345 G4PhysicalVolumeModel searchModel (*iterWorld); // Unlimited depth. 422 else if (2.*length < lengthMax) length * << 346 G4ModelingParameters mp; // Default - no culling. 423 G4AxesModel axesModel(0.,0.,0.,length,tr << 347 searchModel.SetModelingParameters (&mp); 424 axesModel.SetGlobalTag("LocalAxesModel") << 348 // Find all instances at any position in the tree 425 axesModel.DescribeYourselfTo(*fpVisManag << 349 G4PhysicalVolumesSearchScene searchScene (&searchModel, pvName, copyNo); 426 G4UImanager::GetUIpointer()->ApplyComman << 350 searchModel.DescribeYourselfTo (searchScene); // Initiate search. >> 351 for (const auto& findings: searchScene.GetFindings()) { >> 352 findingsVector.push_back(findings); >> 353 } >> 354 } >> 355 for (const auto& findings: findingsVector) { >> 356 G4cout >> 357 << findings.fFoundBasePVPath >> 358 << ' ' << findings.fpFoundPV->GetName() >> 359 << ' ' << findings.fFoundPVCopyNo >> 360 << " (mother logical volume: " >> 361 << findings.fpFoundPV->GetMotherLogical()->GetName() >> 362 << ')' >> 363 << G4endl; >> 364 } >> 365 if (findingsVector.size()) { >> 366 G4cout >> 367 << "Use this to set a particular touchable with \"/vis/set/touchable <path>\"" >> 368 << "\nor to see overlaps: \"/vis/drawLogicalVolume <mother-logical-volume-name>\"" >> 369 << G4endl; 427 } else { 370 } else { 428 G4warn << "Touchable not found." << G4en << 371 G4cout << pvName; >> 372 if (copyNo >= 0) G4cout << ':' << copyNo; >> 373 G4cout << " not found" << G4endl; 429 } 374 } 430 return; << 375 >> 376 } else if (command == fpCommandLocalAxes) { >> 377 >> 378 const auto& transform = fCurrentTouchableProperties.fTouchableGlobalTransform; >> 379 const auto& extent = fCurrentTouchableProperties.fpTouchablePV->GetLogicalVolume()->GetSolid()->GetExtent(); >> 380 const G4double lengthMax = extent.GetExtentRadius()/2.; >> 381 const G4double intLog10LengthMax = std::floor(std::log10(lengthMax)); >> 382 G4double length = std::pow(10,intLog10LengthMax); >> 383 if (5.*length < lengthMax) length *= 5.; >> 384 else if (2.*length < lengthMax) length *= 2.; >> 385 G4AxesModel axesModel(0.,0.,0.,length,transform); >> 386 axesModel.SetGlobalTag("LocalAxesModel"); >> 387 axesModel.DescribeYourselfTo(*fpVisManager->GetCurrentSceneHandler()); 431 388 432 } else if (command == fpCommandShowExtent) { 389 } else if (command == fpCommandShowExtent) { 433 390 434 G4PhysicalVolumeModel::TouchableProperties 391 G4PhysicalVolumeModel::TouchableProperties properties = 435 G4TouchableUtils::FindTouchableProperties( 392 G4TouchableUtils::FindTouchableProperties(fCurrentTouchableProperties.fTouchablePath); 436 if (properties.fpTouchablePV) { 393 if (properties.fpTouchablePV) { 437 G4VisExtent extent 394 G4VisExtent extent 438 = properties.fpTouchablePV->GetLogicalVo 395 = properties.fpTouchablePV->GetLogicalVolume()->GetSolid()->GetExtent(); 439 extent.Transform(properties.fTouchableGl 396 extent.Transform(properties.fTouchableGlobalTransform); 440 G4cout << extent << G4endl; 397 G4cout << extent << G4endl; 441 if (fpCommandShowExtent->GetNewBoolValue 398 if (fpCommandShowExtent->GetNewBoolValue(newValue)) DrawExtent(extent); 442 } else { 399 } else { 443 G4warn << "Touchable not found." << G4en << 400 G4cout << "Touchable not found." << G4endl; 444 } << 445 return; << 446 << 447 } else if (command == fpCommandTwinkle) { << 448 << 449 G4PhysicalVolumeModel::TouchableProperties << 450 G4TouchableUtils::FindTouchableProperties( << 451 if (properties.fpTouchablePV) { << 452 std::vector<std::vector<G4PhysicalVolume << 453 touchables.push_back(properties.fTouchab << 454 auto keepVisVerbose = fpVisManager->GetV << 455 fpVisManager->SetVerboseLevel(G4VisManag << 456 auto keepVP = currentViewer->GetViewPara << 457 Twinkle(currentViewer,currentViewer->Get << 458 SetViewParameters(currentViewer, keepVP) << 459 fpVisManager->SetVerboseLevel(keepVisVer << 460 } else { << 461 G4warn << "Touchable not found." << G4en << 462 } 401 } 463 return; 402 return; 464 403 465 } else if (command == fpCommandVolumeForFiel 404 } else if (command == fpCommandVolumeForField) { 466 405 467 G4PhysicalVolumeModel::TouchableProperties 406 G4PhysicalVolumeModel::TouchableProperties properties = 468 G4TouchableUtils::FindTouchableProperties( 407 G4TouchableUtils::FindTouchableProperties(fCurrentTouchableProperties.fTouchablePath); 469 if (properties.fpTouchablePV) { 408 if (properties.fpTouchablePV) { 470 G4VisExtent extent 409 G4VisExtent extent 471 = properties.fpTouchablePV->GetLogicalVo 410 = properties.fpTouchablePV->GetLogicalVolume()->GetSolid()->GetExtent(); 472 extent.Transform(properties.fTouchableGl 411 extent.Transform(properties.fTouchableGlobalTransform); 473 fCurrentExtentForField = extent; 412 fCurrentExtentForField = extent; 474 fCurrrentPVFindingsForField.clear(); 413 fCurrrentPVFindingsForField.clear(); 475 fCurrrentPVFindingsForField.push_back 414 fCurrrentPVFindingsForField.push_back 476 (G4PhysicalVolumesSearchScene::Findings( 415 (G4PhysicalVolumesSearchScene::Findings(properties)); 477 if (verbosity >= G4VisManager::confirmat 416 if (verbosity >= G4VisManager::confirmations) { 478 G4cout 417 G4cout 479 << "Volume for field set to " << prope 418 << "Volume for field set to " << properties.fpTouchablePV->GetName() 480 << ':' << properties.fCopyNo 419 << ':' << properties.fCopyNo 481 << " at " << properties.fTouchableBase 420 << " at " << properties.fTouchableBaseFullPVPath 482 << G4endl; 421 << G4endl; 483 } 422 } 484 if (fpCommandVolumeForField->GetNewBoolV 423 if (fpCommandVolumeForField->GetNewBoolValue(newValue)) { 485 DrawExtent(extent); 424 DrawExtent(extent); 486 } 425 } 487 } else { 426 } else { 488 G4warn << "Touchable not found." << G4en << 427 G4cout << "Touchable not found." << G4endl; 489 } 428 } 490 return; 429 return; 491 430 492 } else { 431 } else { 493 432 494 if (verbosity >= G4VisManager::errors) { 433 if (verbosity >= G4VisManager::errors) { 495 G4warn << << 434 G4cerr << 496 "ERROR: G4VisCommandsTouchable::SetNewVa 435 "ERROR: G4VisCommandsTouchable::SetNewValue: unrecognised command." 497 << G4endl; 436 << G4endl; 498 } 437 } 499 return; 438 return; 500 } 439 } 501 } 440 } 502 441