Geant4 Cross Reference |
1 // 1 2 // ******************************************* 3 // * License and Disclaimer 4 // * 5 // * The Geant4 software is copyright of th 6 // * the Geant4 Collaboration. It is provided 7 // * conditions of the Geant4 Software License 8 // * LICENSE and available at http://cern.ch/ 9 // * include a list of copyright holders. 10 // * 11 // * Neither the authors of this software syst 12 // * institutes,nor the agencies providing fin 13 // * work make any representation or warran 14 // * regarding this software system or assum 15 // * use. Please see the license in the file 16 // * for the full disclaimer and the limitatio 17 // * 18 // * This code implementation is the result 19 // * technical work of the GEANT4 collaboratio 20 // * By using, copying, modifying or distri 21 // * any work based on the software) you ag 22 // * use in resulting scientific publicati 23 // * acceptance of all terms of the Geant4 Sof 24 // ******************************************* 25 // 26 // 27 28 // /vis/touchable commands - John Allison 14t 29 30 #include "G4VisCommandsTouchable.hh" 31 32 #include "G4UImanager.hh" 33 #include "G4UIcmdWithAString.hh" 34 #include "G4UIcmdWithoutParameter.hh" 35 #include "G4UIcmdWithABool.hh" 36 #include "G4TransportationManager.hh" 37 #include "G4TouchableUtils.hh" 38 #include "G4PhysicalVolumesSearchScene.hh" 39 #include "G4AttDef.hh" 40 #include "G4AttValue.hh" 41 #include "G4AttCheck.hh" 42 #include "G4AxesModel.hh" 43 44 #define G4warn G4cout 45 46 G4VisCommandsTouchable::G4VisCommandsTouchable 47 { 48 G4bool omitable; 49 50 fpCommandCentreAndZoomInOn = new G4UIcmdWith 51 fpCommandCentreAndZoomInOn->SetGuidance ("Ce 52 fpCommandCentreAndZoomInOn->SetGuidance 53 ("Use \"/vis/set/touchable\" to set current 54 fpCommandCentreAndZoomInOn->SetGuidance 55 ("You may also need \"/vis/touchable/findPat 56 fpCommandCentreAndZoomInOn->SetGuidance 57 ("Use \"/vis/touchable/set\" to set attribut 58 59 fpCommandCentreOn = new G4UIcmdWithoutParame 60 fpCommandCentreOn->SetGuidance ("Centre the 61 // Pick up additional guidance from /vis/vie 62 CopyGuidanceFrom(fpCommandCentreAndZoomInOn, 63 64 fpCommandDraw = new G4UIcmdWithABool("/vis/t 65 fpCommandDraw->SetGuidance("Draw touchable." 66 fpCommandDraw->SetGuidance 67 ("If parameter == true, also draw extent as 68 // Pick up additional guidance from /vis/vie 69 CopyGuidanceFrom(fpCommandCentreAndZoomInOn, 70 fpCommandDraw->SetParameterName("extent", om 71 fpCommandDraw->SetDefaultValue(false); 72 73 fpCommandDump = new G4UIcmdWithoutParameter( 74 fpCommandDump->SetGuidance("Dump touchable a 75 // Pick up additional guidance from /vis/vie 76 CopyGuidanceFrom(fpCommandCentreAndZoomInOn, 77 78 fpCommandExtentForField = new G4UIcmdWithABo 79 fpCommandExtentForField->SetGuidance("Set ex 80 fpCommandExtentForField->SetGuidance("If par 81 // Pick up additional guidance from /vis/vie 82 CopyGuidanceFrom(fpCommandCentreAndZoomInOn, 83 fpCommandExtentForField->SetParameterName("d 84 fpCommandExtentForField->SetDefaultValue(fal 85 86 fpCommandFindPath = new G4UIcommand("/vis/to 87 fpCommandFindPath->SetGuidance 88 ("Prints the path to touchable and its logic 89 "\ngiven a physical volume name and copy no 90 fpCommandFindPath -> SetGuidance 91 ("A search of all worlds is made and all phy 92 "\nmatched against the argument of this com 93 "\nform \"/regexp/\", where regexp is a reg 94 "\nthe physical volume name is matched agai 95 "\nof regular expression matching. Otherwis 96 "\nFor example, \"/Shap/\" matches \"Shape1 97 fpCommandFindPath -> SetGuidance 98 ("It may help to see a textual representatio 99 "\nthe worlds. Try \"/vis/drawTree [worlds] 100 "\ncombinations that have the required func 101 G4UIparameter* parameter; 102 parameter = new G4UIparameter ("physical-vol 103 parameter -> SetDefaultValue ("world"); 104 fpCommandFindPath -> SetParameter (parameter 105 parameter = new G4UIparameter ("copy-no", 'i 106 parameter -> SetGuidance ("If negative, matc 107 parameter -> SetDefaultValue (-1); 108 fpCommandFindPath -> SetParameter (parameter 109 110 fpCommandLocalAxes = new G4UIcmdWithoutParam 111 fpCommandLocalAxes->SetGuidance("Draw local 112 // Pick up additional guidance from /vis/vie 113 CopyGuidanceFrom(fpCommandCentreAndZoomInOn, 114 115 fpCommandShowExtent = new G4UIcmdWithABool(" 116 fpCommandShowExtent->SetGuidance("Print exte 117 fpCommandShowExtent->SetGuidance("If paramet 118 // Pick up additional guidance from /vis/vie 119 CopyGuidanceFrom(fpCommandCentreAndZoomInOn, 120 fpCommandShowExtent->SetParameterName("draw" 121 fpCommandShowExtent->SetDefaultValue(false); 122 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 129 fpCommandVolumeForField->SetGuidance("Set vo 130 fpCommandVolumeForField->SetGuidance("If par 131 // Pick up additional guidance from /vis/vie 132 CopyGuidanceFrom(fpCommandCentreAndZoomInOn, 133 fpCommandVolumeForField->SetParameterName("d 134 fpCommandVolumeForField->SetDefaultValue(fal 135 } 136 137 G4VisCommandsTouchable::~G4VisCommandsTouchabl 138 delete fpCommandVolumeForField; 139 delete fpCommandTwinkle; 140 delete fpCommandShowExtent; 141 delete fpCommandLocalAxes; 142 delete fpCommandFindPath; 143 delete fpCommandExtentForField; 144 delete fpCommandDump; 145 delete fpCommandDraw; 146 delete fpCommandCentreAndZoomInOn; 147 delete fpCommandCentreOn; 148 } 149 150 G4String G4VisCommandsTouchable::GetCurrentVal 151 return ""; 152 } 153 154 void G4VisCommandsTouchable::SetNewValue 155 (G4UIcommand* command, G4String newValue) 156 { 157 G4VisManager::Verbosity verbosity = fpVisMan 158 G4bool warn = verbosity >= G4VisManager::war 159 160 G4UImanager* UImanager = G4UImanager::GetUIp 161 162 G4TransportationManager* transportationManag 163 G4TransportationManager::GetTransportationMa 164 165 size_t nWorlds = transportationManager->GetN 166 167 G4VPhysicalVolume* world = *(transportationM 168 if (!world) { 169 if (verbosity >= G4VisManager::errors) { 170 G4warn << 171 "ERROR: G4VisCommandsTouchable::SetNewVa 172 "\n No world. Maybe the geometry has n 173 "\n Try \"/run/initialize\"" 174 << G4endl; 175 } 176 return; 177 } 178 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 255 if (!currentViewer) { 256 if (verbosity >= G4VisManager::errors) { 257 G4warn << 258 "ERROR: No current viewer - \"/vis/viewe 259 << G4endl; 260 } 261 return; 262 } 263 264 G4Scene* currentScene = fpVisManager->GetCur 265 if (!currentScene) { 266 if (verbosity >= G4VisManager::errors) { 267 G4warn << 268 "ERROR: No current scene - \"/vis/scene/ 269 << G4endl; 270 } 271 return; 272 } 273 274 if (command == fpCommandCentreOn || command 275 276 // For twinkling... 277 std::vector<std::vector<G4PhysicalVolumeMo 278 279 G4PhysicalVolumeModel::TouchableProperties 280 G4TouchableUtils::FindTouchableProperties( 281 if (properties.fpTouchablePV) { 282 // To handle parameterisations, set copy 283 properties.fpTouchablePV->SetCopyNo(prop 284 G4PhysicalVolumeModel tempPVModel 285 (properties.fpTouchablePV, 286 G4PhysicalVolumeModel::UNLIMITED, 287 properties.fTouchableGlobalTransform, 288 nullptr, // Modelling parameters (not u 289 true, // use full extent (prevents calc 290 properties.fTouchableBaseFullPVPath); 291 touchables.push_back(properties.fTouchab 292 // Use a temporary scene in order to fin 293 G4Scene tempScene("Centre Scene"); 294 G4bool successful = tempScene.AddRunDura 295 if (!successful) return; 296 if (verbosity >= G4VisManager::parameter 297 G4cout 298 << "Touchable " << fCurrentTouchablePr 299 << ",\n has been added to temporary s 300 << G4endl; 301 } 302 303 const G4VisExtent& newExtent = tempScene 304 const G4ThreeVector& newTargetPoint = ne 305 G4ViewParameters saveVP = currentViewer- 306 G4ViewParameters newVP = saveVP; 307 if (command == fpCommandCentreAndZoomInO 308 // Calculate the new zoom factor 309 const G4double zoomFactor 310 = currentScene->GetExtent().GetExtentR 311 newVP.SetZoomFactor(zoomFactor); 312 } 313 // Change the target point 314 const G4Point3D& standardTargetPoint = c 315 newVP.SetCurrentTargetPoint(newTargetPoi 316 317 // Interpolate 318 auto keepVisVerbose = fpVisManager->GetV 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 326 G4cout 327 << "Viewer \"" << currentViewer->GetNa 328 << "\" centred "; 329 if (fpCommandCentreAndZoomInOn) { 330 G4cout << "and zoomed in"; 331 } 332 G4cout << " on touchable\n" << fCurren 333 << G4endl; 334 } 335 SetViewParameters(currentViewer, newVP); 336 } else { 337 G4warn << "Touchable not found." << G4en 338 } 339 return; 340 341 } else if (command == fpCommandDraw) { 342 343 G4PhysicalVolumeModel::TouchableProperties 344 G4TouchableUtils::FindTouchableProperties( 345 if (properties.fpTouchablePV) { 346 // To handle parameterisations we have t 347 properties.fpTouchablePV->SetCopyNo(prop 348 G4PhysicalVolumeModel* pvModel = new G4P 349 (properties.fpTouchablePV, 350 G4PhysicalVolumeModel::UNLIMITED, 351 properties.fTouchableGlobalTransform, 352 nullptr, // Modelling parameters (not u 353 true, // use full extent (prevents calc 354 properties.fTouchableBaseFullPVPath); 355 356 UImanager->ApplyCommand("/vis/scene/crea 357 currentScene = fpVisManager->GetCurrentS 358 G4bool successful = currentScene->AddRun 359 UImanager->ApplyCommand("/vis/sceneHandl 360 361 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 373 G4cout << "\"" << properties.fpTouch 374 << "\", copy no. " << properties.fCo 375 if (fpCommandDraw->GetNewBoolValue(n 376 G4cout << " with extent box"; 377 } 378 G4cout << '.' << G4endl; 379 } 380 } else { 381 G4VisCommandsSceneAddUnsuccessful(verb 382 } 383 } else { 384 G4warn << "Touchable not found." << G4en 385 } 386 return; 387 388 } else if (command == fpCommandExtentForFiel 389 390 G4PhysicalVolumeModel::TouchableProperties 391 G4TouchableUtils::FindTouchableProperties( 392 if (properties.fpTouchablePV) { 393 G4VisExtent extent 394 = properties.fpTouchablePV->GetLogicalVo 395 extent.Transform(properties.fTouchableGl 396 fCurrentExtentForField = extent; 397 fCurrrentPVFindingsForField.clear(); 398 if (verbosity >= G4VisManager::confirmat 399 G4cout << "Extent for field set to " < 400 << "\nVolume for field has been cleare 401 << G4endl; 402 } 403 if (fpCommandExtentForField->GetNewBoolV 404 DrawExtent(extent); 405 } 406 } else { 407 G4warn << "Touchable not found." << G4en 408 } 409 return; 410 411 } else if (command == fpCommandLocalAxes) { 412 413 G4PhysicalVolumeModel::TouchableProperties 414 G4TouchableUtils::FindTouchableProperties( 415 if (properties.fpTouchablePV) { 416 const auto& transform = fCurrentTouchabl 417 const auto& extent = fCurrentTouchablePr 418 const G4double lengthMax = extent.GetExt 419 const G4double intLog10LengthMax = std:: 420 G4double length = std::pow(10,intLog10Le 421 if (5.*length < lengthMax) length *= 5.; 422 else if (2.*length < lengthMax) length * 423 G4AxesModel axesModel(0.,0.,0.,length,tr 424 axesModel.SetGlobalTag("LocalAxesModel") 425 axesModel.DescribeYourselfTo(*fpVisManag 426 G4UImanager::GetUIpointer()->ApplyComman 427 } else { 428 G4warn << "Touchable not found." << G4en 429 } 430 return; 431 432 } else if (command == fpCommandShowExtent) { 433 434 G4PhysicalVolumeModel::TouchableProperties 435 G4TouchableUtils::FindTouchableProperties( 436 if (properties.fpTouchablePV) { 437 G4VisExtent extent 438 = properties.fpTouchablePV->GetLogicalVo 439 extent.Transform(properties.fTouchableGl 440 G4cout << extent << G4endl; 441 if (fpCommandShowExtent->GetNewBoolValue 442 } else { 443 G4warn << "Touchable not found." << G4en 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 } 463 return; 464 465 } else if (command == fpCommandVolumeForFiel 466 467 G4PhysicalVolumeModel::TouchableProperties 468 G4TouchableUtils::FindTouchableProperties( 469 if (properties.fpTouchablePV) { 470 G4VisExtent extent 471 = properties.fpTouchablePV->GetLogicalVo 472 extent.Transform(properties.fTouchableGl 473 fCurrentExtentForField = extent; 474 fCurrrentPVFindingsForField.clear(); 475 fCurrrentPVFindingsForField.push_back 476 (G4PhysicalVolumesSearchScene::Findings( 477 if (verbosity >= G4VisManager::confirmat 478 G4cout 479 << "Volume for field set to " << prope 480 << ':' << properties.fCopyNo 481 << " at " << properties.fTouchableBase 482 << G4endl; 483 } 484 if (fpCommandVolumeForField->GetNewBoolV 485 DrawExtent(extent); 486 } 487 } else { 488 G4warn << "Touchable not found." << G4en 489 } 490 return; 491 492 } else { 493 494 if (verbosity >= G4VisManager::errors) { 495 G4warn << 496 "ERROR: G4VisCommandsTouchable::SetNewVa 497 << G4endl; 498 } 499 return; 500 } 501 } 502