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/ top level commands - John Allison 5t 29 30 #include "G4VisCommands.hh" 31 32 #include "G4VisManager.hh" 33 #include "G4UImanager.hh" 34 #include "G4UIcmdWithABool.hh" 35 #include "G4UIcmdWithAString.hh" 36 #include "G4UIcmdWithoutParameter.hh" 37 #include "G4RunManager.hh" 38 #include "G4RunManagerFactory.hh" 39 #include "G4Run.hh" 40 #include "G4UIsession.hh" 41 #include "G4Trajectory.hh" 42 #include "G4TrajectoryPoint.hh" 43 #include "G4RichTrajectory.hh" 44 #include "G4RichTrajectoryPoint.hh" 45 #include "G4SmoothTrajectory.hh" 46 #include "G4SmoothTrajectoryPoint.hh" 47 #include "G4PhysicalVolumeModel.hh" 48 #include "G4AttDef.hh" 49 50 #define G4warn G4cout 51 52 ////////////// /vis/abortReviewKeptEvents //// 53 54 G4VisCommandAbortReviewKeptEvents::G4VisComman 55 G4bool omitable; 56 57 fpCommand = new G4UIcmdWithABool("/vis/abort 58 fpCommand -> SetGuidance("Abort review of ke 59 fpCommand -> SetParameterName("abort", omita 60 fpCommand -> SetDefaultValue(true); 61 } 62 63 G4VisCommandAbortReviewKeptEvents::~G4VisComma 64 delete fpCommand; 65 } 66 67 G4String G4VisCommandAbortReviewKeptEvents::Ge 68 return G4String(); 69 } 70 71 void G4VisCommandAbortReviewKeptEvents::SetNew 72 73 fpVisManager->SetAbortReviewKeptEvents(G4UIc 74 G4warn << "Type \"continue\" to complete the 75 } 76 77 ////////////// /vis/abortReviewPlots ///////// 78 79 G4VisCommandAbortReviewPlots::G4VisCommandAbor 80 G4bool omitable; 81 82 fpCommand = new G4UIcmdWithABool("/vis/abort 83 fpCommand -> SetGuidance("Abort review of pl 84 fpCommand -> SetParameterName("abort", omita 85 fpCommand -> SetDefaultValue(true); 86 } 87 88 G4VisCommandAbortReviewPlots::~G4VisCommandAbo 89 delete fpCommand; 90 } 91 92 G4String G4VisCommandAbortReviewPlots::GetCurr 93 return G4String(); 94 } 95 96 void G4VisCommandAbortReviewPlots::SetNewValue 97 98 fpVisManager->SetAbortReviewPlots(G4UIcomman 99 G4warn << "Type \"continue\" to complete the 100 } 101 102 ////////////// /vis/drawOnlyToBeKeptEvents /// 103 104 G4VisCommandDrawOnlyToBeKeptEvents::G4VisComma 105 { 106 G4bool omitable; 107 108 fpCommand = new G4UIcmdWithABool("/vis/drawO 109 fpCommand -> SetGuidance 110 ("DURING A RUN draw only those events that h 111 "\nwith G4EventManager::GetEventManager()-> 112 "\nwith \"/event/keepCurrentEvent\"."); 113 fpCommand -> SetGuidance( 114 "To draw selected events the user should set 115 "\n if ( some criterion ) {" 116 "\n G4EventManager::GetEventManager()->Ke 117 "\n }"); 118 fpCommand -> SetParameterName("draw", omitab 119 fpCommand -> SetDefaultValue(true); 120 } 121 122 G4VisCommandDrawOnlyToBeKeptEvents::~G4VisComm 123 delete fpCommand; 124 } 125 126 G4String G4VisCommandDrawOnlyToBeKeptEvents::G 127 return G4String(); 128 } 129 130 void G4VisCommandDrawOnlyToBeKeptEvents::SetNe 131 132 fpVisManager->SetDrawEventOnlyIfToBeKept(G4U 133 G4VisManager::Verbosity verbosity = fpVisMan 134 if (verbosity < G4VisManager::warnings) { 135 if (fpVisManager->GetDrawEventOnlyIfToBeKe 136 G4warn << "Only events that have been ke 137 } else { 138 G4warn << "All events will be drawn." << 139 } 140 } 141 } 142 143 ////////////// /vis/enable /////////////////// 144 145 G4VisCommandEnable::G4VisCommandEnable () { 146 G4bool omitable; 147 148 fpCommand = new G4UIcmdWithABool("/vis/enabl 149 fpCommand -> SetGuidance("Enables/disables v 150 fpCommand -> SetParameterName("enabled", omi 151 fpCommand -> SetDefaultValue(true); 152 153 fpCommand1 = new G4UIcmdWithoutParameter("/v 154 fpCommand1 -> SetGuidance("Disables visualiz 155 } 156 157 G4VisCommandEnable::~G4VisCommandEnable () { 158 delete fpCommand; 159 delete fpCommand1; 160 } 161 162 G4String G4VisCommandEnable::GetCurrentValue ( 163 return G4String(); 164 } 165 166 void G4VisCommandEnable::SetNewValue (G4UIcomm 167 G4String newValue) { 168 if (command == fpCommand) { 169 G4bool enable = G4UIcommand::ConvertToBool 170 if (enable) fpVisManager->Enable(); // Pr 171 else fpVisManager->Disable(); // Pr 172 } else fpVisManager->Disable(); // Pr 173 // Note: Printing is in vis manager. 174 } 175 176 ////////////// /vis/initialize /////////////// 177 178 G4VisCommandInitialize::G4VisCommandInitialize 179 { 180 fpCommand = new G4UIcmdWithoutParameter("/vi 181 fpCommand -> SetGuidance("Initialise visuali 182 } 183 184 G4VisCommandInitialize::~G4VisCommandInitializ 185 delete fpCommand; 186 } 187 188 void G4VisCommandInitialize::SetNewValue (G4UI 189 G4String) { 190 fpVisManager->Initialize(); 191 } 192 193 ////////////// /vis/list ///////////////////// 194 195 G4VisCommandList::G4VisCommandList () 196 { 197 G4bool omitable; 198 199 fpCommand = new G4UIcmdWithAString("/vis/lis 200 fpCommand -> SetGuidance("Lists visualizatio 201 fpCommand -> SetParameterName("verbosity", o 202 fpCommand -> SetDefaultValue("warnings"); 203 } 204 205 G4VisCommandList::~G4VisCommandList () 206 { 207 delete fpCommand; 208 } 209 210 G4String G4VisCommandList::GetCurrentValue (G4 211 { 212 return ""; 213 } 214 215 void G4VisCommandList::SetNewValue (G4UIcomman 216 { 217 G4VisManager::Verbosity verbosity = fpVisMan 218 219 G4VisManager::PrintAvailableVerbosity(G4cout 220 G4cout << G4endl; 221 fpVisManager->PrintAvailableGraphicsSystems( 222 G4cout << G4endl; 223 fpVisManager->PrintAvailableModels(verbosity 224 G4cout << G4endl; 225 fpVisManager->PrintAvailableUserVisActions(v 226 G4cout << G4endl; 227 fpVisManager->PrintAvailableColours(verbosit 228 G4cout << G4endl; 229 G4UImanager* UImanager = G4UImanager::GetUIp 230 UImanager->ApplyCommand("/vis/scene/list ! " 231 G4cout << G4endl; 232 UImanager->ApplyCommand("/vis/viewer/list ! 233 234 G4cout << 235 "\nAttributes available for modeling and fil 236 "\n \"/vis/modeling/trajectories/create/dra 237 "\n \"/vis/filtering/trajectories/create/at 238 "\nand by picking:" 239 << G4endl; 240 G4cout 241 << *G4TrajectoriesModel().GetAttDefs(); 242 G4cout 243 << *G4RichTrajectory().GetAttDefs() 244 << *G4RichTrajectoryPoint().GetAttDefs(); 245 G4cout 246 << *G4SmoothTrajectory().GetAttDefs() 247 << *G4SmoothTrajectoryPoint().GetAttDefs(); 248 G4cout 249 << *G4Trajectory().GetAttDefs() 250 << *G4TrajectoryPoint().GetAttDefs(); 251 252 G4cout << 253 "\nGeometry attributes available for touchab 254 G4cout 255 << *G4PhysicalVolumeModel().GetAttDefs(); 256 257 if (verbosity < G4VisManager::parameters) 258 G4cout << 259 "\nTo get more information, \"/vis/list all\ 260 "\n such as (use \"ls\" or \"help\"):" 261 "\n /vis/scene/list all all" 262 "\n /vis/viewer/list all all" 263 "\n /vis/modeling/trajectories/list" 264 "\n /vis/filtering/trajectories/list" 265 << G4endl; 266 } 267 268 ////////////// /vis/reviewKeptEvents ///////// 269 270 G4VisCommandReviewKeptEvents::G4VisCommandRevi 271 { 272 G4bool omitable; 273 274 fpCommand = new G4UIcmdWithAString("/vis/rev 275 fpCommand -> SetGuidance("Review kept events 276 fpCommand -> SetGuidance 277 ("If a macro file is specified, it is exec 278 fpCommand -> SetGuidance( 279 "If a macro file is not specified, each even 280 "\nviewer. After each event, the session is 281 "\nany allowed command. Then enter \"cont[i 282 "\nevent." 283 "\nUseful commands might be:" 284 "\n \"/vis/viewer/...\" to change the view 285 "\n \"/vis/ogl/export\" to get hard copy." 286 "\n \"/vis/open\" to get alternative viewer 287 "\n \"/vis/abortReviewKeptEvents\", then \" 288 fpCommand -> SetParameterName("macro-file-na 289 fpCommand -> SetDefaultValue(""); 290 } 291 292 G4VisCommandReviewKeptEvents::~G4VisCommandRev 293 { 294 delete fpCommand; 295 } 296 297 G4String G4VisCommandReviewKeptEvents::GetCurr 298 { 299 return ""; 300 } 301 302 void G4VisCommandReviewKeptEvents::SetNewValue 303 { 304 if (fpVisManager->GetReviewingKeptEvents()) 305 G4warn << 306 "\"/vis/reviewKeptEvents\" not allowed w 307 "\n No action taken." 308 << G4endl; 309 return; 310 } 311 312 G4String& macroFileName = newValue; 313 G4VisManager::Verbosity verbosity = fpVisMan 314 315 G4RunManager* runManager = G4RunManagerFacto 316 const G4Run* run = runManager ? runM 317 const std::vector<const G4Event*>* events = 318 run ? run->GetEventVector() : nullptr; 319 size_t nKeptEvents = events ? events->size() 320 321 if (!nKeptEvents) { 322 if (verbosity >= G4VisManager::errors) { 323 G4warn << 324 "ERROR: G4VisCommandReviewKeptEvents::SetNew 325 "\n or kept events not accessible." 326 << G4endl; 327 } 328 return; 329 } 330 331 G4VViewer* viewer = fpVisManager->GetCurrent 332 if (!viewer) { 333 if (verbosity >= G4VisManager::errors) { 334 G4warn << 335 "ERROR: No current viewer - \"/vis/viewer/li 336 << G4endl; 337 } 338 return; 339 } 340 341 G4Scene* pScene = fpVisManager->GetCurrentSc 342 if (!pScene) { 343 if (verbosity >= G4VisManager::errors) { 344 G4warn << "ERROR: No current scene. Ple 345 } 346 return; 347 } 348 349 G4UImanager* UImanager = G4UImanager::GetUIp 350 G4int keepControlVerbose = UImanager->GetVer 351 G4int newVerbose(0); 352 if (keepControlVerbose >= 2 || verbosity >= 353 newVerbose = 2; 354 UImanager->SetVerboseLevel(newVerbose); 355 356 G4VVisManager* keepConcreteInstance = fpVisM 357 fpVisManager->Enable(); 358 359 // Start on clean view 360 UImanager->ApplyCommand("/vis/viewer/rebuild 361 362 // Event by event refreshing... 363 fpVisManager->SetReviewingKeptEvents(true); 364 G4bool currentRefreshAtEndOfEvent = pScene-> 365 pScene->SetRefreshAtEndOfEvent(true); 366 if (macroFileName.empty()) { 367 368 // Draw to viewer and pause session... 369 G4UIsession* session = UImanager->GetSessi 370 for (size_t i = 0; i < nKeptEvents; ++i) { 371 const G4Event* event = (*events)[i]; 372 if (verbosity >= G4VisManager::warnings) 373 G4warn << "Drawing event : " << event->GetEv 374 ". At EndOfEvent, enter any command, then 375 << G4endl; 376 static G4bool first = true; 377 if (first) { 378 first = false; 379 G4warn << 380 " Useful commands might be:" 381 "\n \"/vis/scene/add/trajectories\" if no 382 "\n \"/vis/viewer/...\" to change the vie 383 "\n \"/vis/ogl/export\" to get hard copy. 384 "\n \"/vis/open\" to get alternative view 385 "\n \"/vis/abortReviewKeptEvents\", then 386 << G4endl; 387 } 388 } 389 fpVisManager->SetRequestedEvent(event); 390 UImanager->ApplyCommand("/vis/viewer/reb 391 /* The above command forces a rebuild of 392 the detector. This is fine for "immediate" 393 refresh requires a rebuild anyway. But for 394 viewers, you could, in principle, avoid a r 395 detector with something like the following: 396 sceneHandler->ClearTransientStore(); 397 viewer->DrawView(); 398 sceneHandler->DrawEvent(event); 399 but this causes mayhem for "immediate 400 ClearTransientStore issues a DrawView 401 of recursion takes place. For "store 402 gets drawn but not the eventID, so so 403 there too. This needs further invest 404 features or a complete re-think. 405 */ 406 UImanager->ApplyCommand("/vis/viewer/flu 407 session->PauseSessionStart("EndOfEvent") 408 fpVisManager->SetRequestedEvent(0); 409 if (fpVisManager->GetAbortReviewKeptEven 410 } 411 fpVisManager->SetAbortReviewKeptEvents(fal 412 413 } else { 414 415 // Execute macro file... 416 for (size_t i = 0; i < nKeptEvents; ++i) { 417 const G4Event* event = (*events)[i]; 418 if (verbosity >= G4VisManager::warnings) 419 G4warn << "Drawing event : " << event->GetEv 420 << " with macro file \"" << macroFile 421 } 422 fpVisManager->SetRequestedEvent(event); 423 UImanager->ApplyCommand("/control/execut 424 fpVisManager->SetRequestedEvent(0); 425 } 426 } 427 pScene->SetRefreshAtEndOfEvent(currentRefres 428 fpVisManager->SetReviewingKeptEvents(false); 429 430 if (keepConcreteInstance) fpVisManager->Enab 431 else fpVisManager->Disable(); 432 UImanager->SetVerboseLevel(keepControlVerbos 433 } 434 435 ////////////// /vis/reviewPlots ////////////// 436 437 G4VisCommandReviewPlots::G4VisCommandReviewPlo 438 { 439 fpCommand = new G4UIcmdWithoutParameter("/vi 440 fpCommand -> SetGuidance("Review plots."); 441 fpCommand -> SetGuidance 442 ("Each plot is drawn, one by one, to the cur 443 "\nplot the session is paused. The user ma 444 "\nThen enter \"cont[inue]\" to continue to 445 "\nUseful commands might be:" 446 "\n \"/vis/tsg/export\" to get hard copy." 447 "\n \"/vis/abortReviewPlots\", then \"cont 448 } 449 450 G4VisCommandReviewPlots::~G4VisCommandReviewPl 451 { 452 delete fpCommand; 453 } 454 455 G4String G4VisCommandReviewPlots::GetCurrentVa 456 { 457 return ""; 458 } 459 460 #include <tools/histo/h1d> 461 #include <tools/histo/h2d> 462 463 namespace { 464 template <typename HT> // tools::histo::h1d 465 G4bool ReviewPlots(const G4String& plotType) 466 auto visManager = G4VisManager::GetInstanc 467 auto ui = G4UImanager::GetUIpointer(); 468 auto session = ui->GetSession(); 469 G4bool aborting = false; 470 auto keepControlVerbose = ui->GetVerboseLe 471 ui->SetVerboseLevel(0); 472 auto status = ui->ApplyCommand("/analysis/ 473 ui->SetVerboseLevel(keepControlVerbose); 474 if(status==G4UIcommandStatus::fCommandSucc 475 G4String hexString = ui->GetCurrentValue 476 if(hexString.size()) { 477 void* ptr; 478 std::istringstream is(hexString); 479 is >> ptr; 480 auto _v = (const std::vector<HT*>*)ptr 481 auto _n = _v->size(); 482 for (size_t i = 0; i < _n; ++i) { 483 // Draw then pause session... 484 std::ostringstream oss; 485 oss << "/vis/plot " << plotType << ' 486 ui->ApplyCommand(oss.str()); 487 session->PauseSessionStart("EndOfEve 488 if (visManager->GetAbortReviewPlots( 489 aborting = true; 490 break; 491 } 492 } 493 } 494 } 495 return aborting; 496 } 497 } 498 499 void G4VisCommandReviewPlots::SetNewValue (G4U 500 { 501 if (fpVisManager->GetReviewingPlots()) { 502 G4warn << 503 "\"/vis/reviewPlots\" not allowed within a 504 "\n No action taken." 505 << G4endl; 506 return; 507 } 508 509 auto verbosity = fpVisManager->GetVerbosity( 510 511 auto currentViewer = fpVisManager->GetCurren 512 if (!currentViewer) { 513 if (verbosity >= G4VisManager::errors) { 514 G4warn << 515 "ERROR: No current viewer - \"/vis/viewe 516 << G4endl; 517 } 518 return; 519 } 520 521 if (currentViewer->GetName().find("TOOLSSG") 522 G4warn << 523 "WARNING: Current viewer not able to draw 524 "\n Try \"/vis/open TSG\", then \"/vis/re 525 << G4endl; 526 return; 527 } 528 529 G4Scene* pScene = fpVisManager->GetCurrentSc 530 if (!pScene) { 531 if (verbosity >= G4VisManager::errors) { 532 G4warn << "ERROR: No current scene. Ple 533 } 534 return; 535 } 536 537 auto ui = G4UImanager::GetUIpointer(); 538 539 auto keepControlVerbose = ui->GetVerboseLeve 540 ui->SetVerboseLevel(0); 541 auto keepVisVerbose = fpVisManager->GetVerbo 542 fpVisManager->SetVerboseLevel(G4VisManager:: 543 auto keepEnable = fpVisManager->IsEnabled(); 544 fpVisManager->Enable(); 545 fpVisManager->SetReviewingPlots(true); 546 547 if (ReviewPlots<tools::histo::h1d>("h1")) go 548 if (ReviewPlots<tools::histo::h2d>("h2")) go 549 550 finish: 551 fpVisManager->SetReviewingPlots(false); 552 if (!keepEnable) fpVisManager->Disable(); 553 fpVisManager->SetVerboseLevel(keepVisVerbose 554 ui->SetVerboseLevel(keepControlVerbose); 555 } 556 557 ////////////// /vis/verbose ////////////////// 558 559 G4VisCommandVerbose::G4VisCommandVerbose () { 560 G4bool omitable; 561 562 fpCommand = new G4UIcmdWithAString("/vis/ver 563 for (size_t i = 0; i < G4VisManager::Verbosi 564 fpCommand -> SetGuidance(G4VisManager::Ver 565 } 566 fpCommand -> SetParameterName("verbosity", o 567 fpCommand -> SetDefaultValue(""); 568 } 569 570 G4VisCommandVerbose::~G4VisCommandVerbose () { 571 delete fpCommand; 572 } 573 574 G4String G4VisCommandVerbose::GetCurrentValue 575 return G4String(); 576 } 577 578 void G4VisCommandVerbose::SetNewValue (G4UIcom 579 G4String newValue) { 580 G4VisManager::Verbosity verbosity = 581 fpVisManager->GetVerbosityValue(newValue); 582 fpVisManager->SetVerboseLevel(verbosity); 583 // Always prints whatever the verbosity... 584 G4cout << "Visualization verbosity is now " 585 << G4VisManager::VerbosityString(verbosity) 586 } 587