[531] | 1 | // |
---|
| 2 | // ******************************************************************** |
---|
| 3 | // * License and Disclaimer * |
---|
| 4 | // * * |
---|
| 5 | // * The Geant4 software is copyright of the Copyright Holders of * |
---|
| 6 | // * the Geant4 Collaboration. It is provided under the terms and * |
---|
| 7 | // * conditions of the Geant4 Software License, included in the file * |
---|
| 8 | // * LICENSE and available at http://cern.ch/geant4/license . These * |
---|
| 9 | // * include a list of copyright holders. * |
---|
| 10 | // * * |
---|
| 11 | // * Neither the authors of this software system, nor their employing * |
---|
| 12 | // * institutes,nor the agencies providing financial support for this * |
---|
| 13 | // * work make any representation or warranty, express or implied, * |
---|
| 14 | // * regarding this software system or assume any liability for its * |
---|
| 15 | // * use. Please see the license in the file LICENSE and URL above * |
---|
| 16 | // * for the full disclaimer and the limitation of liability. * |
---|
| 17 | // * * |
---|
| 18 | // * This code implementation is the result of the scientific and * |
---|
| 19 | // * technical work of the GEANT4 collaboration. * |
---|
| 20 | // * By using, copying, modifying or distributing the software (or * |
---|
| 21 | // * any work based on the software) you agree to acknowledge its * |
---|
| 22 | // * use in resulting scientific publications, and indicate your * |
---|
| 23 | // * acceptance of all terms of the Geant4 Software license. * |
---|
| 24 | // ******************************************************************** |
---|
| 25 | // |
---|
| 26 | // |
---|
[1274] | 27 | // $Id: G4VisCommandsCompound.cc,v 1.40 2010/05/20 07:54:01 allison Exp $ |
---|
[1346] | 28 | // GEANT4 tag $Name: $ |
---|
[531] | 29 | |
---|
| 30 | // Compound /vis/ commands - John Allison 15th May 2000 |
---|
| 31 | |
---|
| 32 | #include "G4VisCommandsCompound.hh" |
---|
| 33 | |
---|
| 34 | #include "G4VisManager.hh" |
---|
| 35 | #include "G4UImanager.hh" |
---|
| 36 | #include "G4UIcmdWithAString.hh" |
---|
| 37 | |
---|
| 38 | #include <sstream> |
---|
| 39 | |
---|
| 40 | ////////////// /vis/drawTree /////////////////////////////////////// |
---|
| 41 | |
---|
| 42 | G4VisCommandDrawTree::G4VisCommandDrawTree() { |
---|
| 43 | G4bool omitable; |
---|
| 44 | fpCommand = new G4UIcommand("/vis/drawTree", this); |
---|
| 45 | fpCommand->SetGuidance |
---|
| 46 | ("(DTREE) Creates a scene consisting of this physical volume and" |
---|
| 47 | "\n produces a representation of the geometry hieracrhy."); |
---|
| 48 | fpCommand->SetGuidance("The scene becomes current."); |
---|
| 49 | G4UIparameter* parameter; |
---|
| 50 | parameter = new G4UIparameter("physical-volume-name", 's', omitable = true); |
---|
| 51 | parameter -> SetDefaultValue("world"); |
---|
| 52 | fpCommand -> SetParameter (parameter); |
---|
| 53 | parameter = new G4UIparameter("system", 's', omitable = true); |
---|
| 54 | parameter -> SetDefaultValue("ATree"); |
---|
| 55 | fpCommand -> SetParameter (parameter); |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | G4VisCommandDrawTree::~G4VisCommandDrawTree() { |
---|
| 59 | delete fpCommand; |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | void G4VisCommandDrawTree::SetNewValue(G4UIcommand*, G4String newValue) { |
---|
| 63 | |
---|
| 64 | G4String pvname, system; |
---|
| 65 | std::istringstream is(newValue); |
---|
| 66 | is >> pvname >> system; |
---|
| 67 | |
---|
[1274] | 68 | G4VGraphicsSystem* keepSystem = fpVisManager->GetCurrentGraphicsSystem(); |
---|
| 69 | G4Scene* keepScene = fpVisManager->GetCurrentScene(); |
---|
| 70 | G4VSceneHandler* keepSceneHandler = fpVisManager->GetCurrentSceneHandler(); |
---|
| 71 | G4VViewer* keepViewer = fpVisManager->GetCurrentViewer(); |
---|
| 72 | |
---|
[531] | 73 | G4UImanager* UImanager = G4UImanager::GetUIpointer(); |
---|
| 74 | G4int keepVerbose = UImanager->GetVerboseLevel(); |
---|
| 75 | G4int newVerbose(0); |
---|
| 76 | if (keepVerbose >= 2 || |
---|
| 77 | fpVisManager->GetVerbosity() >= G4VisManager::confirmations) |
---|
| 78 | newVerbose = 2; |
---|
| 79 | UImanager->SetVerboseLevel(newVerbose); |
---|
| 80 | UImanager->ApplyCommand(G4String("/vis/open " + system)); |
---|
| 81 | UImanager->ApplyCommand(G4String("/vis/drawVolume " + pvname)); |
---|
| 82 | UImanager->ApplyCommand("/vis/viewer/flush"); |
---|
| 83 | UImanager->SetVerboseLevel(keepVerbose); |
---|
[1274] | 84 | |
---|
| 85 | if (keepViewer) { |
---|
| 86 | if (fpVisManager->GetVerbosity() >= G4VisManager::warnings) { |
---|
| 87 | G4cout << "Reverting to " << keepViewer->GetName() << G4endl; |
---|
| 88 | } |
---|
| 89 | fpVisManager->SetCurrentGraphicsSystem(keepSystem); |
---|
| 90 | fpVisManager->SetCurrentScene(keepScene); |
---|
| 91 | fpVisManager->SetCurrentSceneHandler(keepSceneHandler); |
---|
| 92 | fpVisManager->SetCurrentViewer(keepViewer); |
---|
| 93 | } |
---|
[531] | 94 | } |
---|
| 95 | |
---|
| 96 | ////////////// /vis/drawView /////////////////////////////////////// |
---|
| 97 | |
---|
| 98 | G4VisCommandDrawView::G4VisCommandDrawView() { |
---|
| 99 | G4bool omitable; |
---|
| 100 | fpCommand = new G4UIcommand("/vis/drawView", this); |
---|
| 101 | fpCommand->SetGuidance |
---|
| 102 | ("Draw view from this angle, etc."); |
---|
| 103 | G4UIparameter* parameter; |
---|
| 104 | parameter = new G4UIparameter("theta-degrees", 'd', omitable = true); |
---|
| 105 | parameter -> SetDefaultValue(0.); |
---|
| 106 | fpCommand -> SetParameter (parameter); |
---|
| 107 | parameter = new G4UIparameter("phi-degrees", 'd', omitable = true); |
---|
| 108 | parameter -> SetDefaultValue(0.); |
---|
| 109 | fpCommand -> SetParameter (parameter); |
---|
| 110 | parameter = new G4UIparameter("pan-right", 'd', omitable = true); |
---|
| 111 | parameter -> SetDefaultValue(0.); |
---|
| 112 | fpCommand -> SetParameter (parameter); |
---|
| 113 | parameter = new G4UIparameter("pan-up", 'd', omitable = true); |
---|
| 114 | parameter -> SetDefaultValue(0.); |
---|
| 115 | fpCommand -> SetParameter (parameter); |
---|
| 116 | parameter = new G4UIparameter("pan-unit", 's', omitable = true); |
---|
| 117 | parameter -> SetDefaultValue("cm"); |
---|
| 118 | fpCommand -> SetParameter (parameter); |
---|
| 119 | parameter = new G4UIparameter("zoom-factor", 'd', omitable = true); |
---|
| 120 | parameter -> SetDefaultValue(1.); |
---|
| 121 | fpCommand -> SetParameter (parameter); |
---|
| 122 | parameter = new G4UIparameter("dolly", 'd', omitable = true); |
---|
| 123 | parameter -> SetDefaultValue(0.); |
---|
| 124 | fpCommand -> SetParameter (parameter); |
---|
| 125 | parameter = new G4UIparameter("dolly-unit", 's', omitable = true); |
---|
| 126 | parameter -> SetDefaultValue("cm"); |
---|
| 127 | fpCommand -> SetParameter (parameter); |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | G4VisCommandDrawView::~G4VisCommandDrawView() { |
---|
| 131 | delete fpCommand; |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | void G4VisCommandDrawView::SetNewValue(G4UIcommand*, G4String newValue) { |
---|
| 135 | |
---|
| 136 | G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); |
---|
| 137 | |
---|
| 138 | G4VViewer* currentViewer = fpVisManager->GetCurrentViewer(); |
---|
| 139 | if (!currentViewer) { |
---|
| 140 | if (verbosity >= G4VisManager::warnings) { |
---|
| 141 | G4cout << |
---|
| 142 | "WARNING: G4VisCommandsDrawView::SetNewValue: no current viewer." |
---|
| 143 | << G4endl; |
---|
| 144 | } |
---|
| 145 | return; |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | G4String thetaDeg; |
---|
| 149 | G4String phiDeg; |
---|
| 150 | G4String panRight; |
---|
| 151 | G4String panUp; |
---|
| 152 | G4String panUnit; |
---|
| 153 | G4String zoomFactor; |
---|
| 154 | G4String dolly; |
---|
| 155 | G4String dollyUnit; |
---|
| 156 | std::istringstream is(newValue); |
---|
| 157 | is >> thetaDeg >> phiDeg >> panRight >> panUp >> panUnit |
---|
| 158 | >> zoomFactor >> dolly >> dollyUnit; |
---|
| 159 | |
---|
| 160 | G4UImanager* UImanager = G4UImanager::GetUIpointer(); |
---|
| 161 | G4int keepVerbose = UImanager->GetVerboseLevel(); |
---|
| 162 | G4int newVerbose(0); |
---|
| 163 | if (keepVerbose >= 2 || |
---|
| 164 | fpVisManager->GetVerbosity() >= G4VisManager::confirmations) |
---|
| 165 | newVerbose = 2; |
---|
| 166 | UImanager->SetVerboseLevel(newVerbose); |
---|
| 167 | G4ViewParameters vp = currentViewer->GetViewParameters(); |
---|
| 168 | G4bool keepAutoRefresh = vp.IsAutoRefresh(); |
---|
| 169 | vp.SetAutoRefresh(false); |
---|
| 170 | currentViewer->SetViewParameters(vp); |
---|
| 171 | UImanager->ApplyCommand( |
---|
| 172 | G4String("/vis/viewer/set/viewpointThetaPhi " + thetaDeg + " " + phiDeg + " deg")); |
---|
| 173 | UImanager->ApplyCommand( |
---|
| 174 | G4String("/vis/viewer/panTo " + panRight + " " + panUp + " " + panUnit)); |
---|
| 175 | UImanager->ApplyCommand( |
---|
| 176 | G4String("/vis/viewer/zoomTo " + zoomFactor)); |
---|
| 177 | vp = currentViewer->GetViewParameters(); |
---|
| 178 | vp.SetAutoRefresh(keepAutoRefresh); |
---|
| 179 | currentViewer->SetViewParameters(vp); |
---|
| 180 | UImanager->ApplyCommand( |
---|
| 181 | G4String("/vis/viewer/dollyTo " + dolly + " " + dollyUnit)); |
---|
| 182 | UImanager->SetVerboseLevel(keepVerbose); |
---|
| 183 | } |
---|
| 184 | |
---|
| 185 | ////////////// /vis/drawVolume /////////////////////////////////////// |
---|
| 186 | |
---|
| 187 | G4VisCommandDrawVolume::G4VisCommandDrawVolume() { |
---|
| 188 | G4bool omitable; |
---|
| 189 | fpCommand = new G4UIcmdWithAString("/vis/drawVolume", this); |
---|
| 190 | fpCommand->SetGuidance |
---|
| 191 | ("Creates a scene containing this physical volume and asks the" |
---|
| 192 | "\ncurrent viewer to draw it. The scene becomes current."); |
---|
| 193 | fpCommand -> SetGuidance |
---|
| 194 | ("If physical-volume-name is \"world\" (the default), the main geometry" |
---|
| 195 | "\ntree (material world) is drawn. If \"worlds\", all worlds - material" |
---|
| 196 | "\nworld and parallel worlds, if any - are drawn. Otherwise a search of" |
---|
| 197 | "\nall worlds is made, taking the first matching occurence only. To see" |
---|
| 198 | "\na representation of the geometry hierarchy of the worlds, try" |
---|
| 199 | "\n\"/vis/drawTree [worlds]\" or one of the driver/browser combinations" |
---|
[631] | 200 | "\nthat have the required functionality, e.g., HepRep"); |
---|
[531] | 201 | fpCommand->SetParameterName("physical-volume-name", omitable = true); |
---|
| 202 | fpCommand->SetDefaultValue("world"); |
---|
| 203 | } |
---|
| 204 | |
---|
| 205 | G4VisCommandDrawVolume::~G4VisCommandDrawVolume() { |
---|
| 206 | delete fpCommand; |
---|
| 207 | } |
---|
| 208 | |
---|
| 209 | void G4VisCommandDrawVolume::SetNewValue(G4UIcommand*, G4String newValue) { |
---|
| 210 | G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); |
---|
| 211 | G4UImanager* UImanager = G4UImanager::GetUIpointer(); |
---|
| 212 | G4int keepVerbose = UImanager->GetVerboseLevel(); |
---|
| 213 | G4int newVerbose(0); |
---|
| 214 | if (keepVerbose >= 2 || verbosity >= G4VisManager::confirmations) |
---|
| 215 | newVerbose = 2; |
---|
| 216 | UImanager->SetVerboseLevel(newVerbose); |
---|
| 217 | UImanager->ApplyCommand("/vis/scene/create"); |
---|
| 218 | UImanager->ApplyCommand(G4String("/vis/scene/add/volume " + newValue)); |
---|
| 219 | UImanager->ApplyCommand("/vis/sceneHandler/attach"); |
---|
| 220 | UImanager->SetVerboseLevel(keepVerbose); |
---|
| 221 | static G4bool warned = false; |
---|
[593] | 222 | if (verbosity >= G4VisManager::confirmations && !warned) { |
---|
[531] | 223 | G4cout << |
---|
[593] | 224 | "NOTE: For systems which are not \"auto-refresh\" you will need to" |
---|
[531] | 225 | "\n issue \"/vis/viewer/refresh\" or \"/vis/viewer/flush\"." |
---|
| 226 | << G4endl; |
---|
| 227 | warned = true; |
---|
| 228 | } |
---|
| 229 | } |
---|
| 230 | |
---|
| 231 | ////////////// /vis/open /////////////////////////////////////// |
---|
| 232 | |
---|
| 233 | G4VisCommandOpen::G4VisCommandOpen() { |
---|
| 234 | G4bool omitable; |
---|
| 235 | fpCommand = new G4UIcommand("/vis/open", this); |
---|
| 236 | fpCommand->SetGuidance |
---|
| 237 | ("Creates a scene handler ready for drawing."); |
---|
| 238 | fpCommand->SetGuidance |
---|
| 239 | ("The scene handler becomes current (the name is auto-generated)."); |
---|
| 240 | G4UIparameter* parameter; |
---|
| 241 | parameter = new G4UIparameter("graphics-system-name", 's', omitable = false); |
---|
| 242 | const G4GraphicsSystemList& gslist = |
---|
| 243 | fpVisManager->GetAvailableGraphicsSystems(); |
---|
| 244 | G4String candidates; |
---|
| 245 | for (size_t igslist = 0; igslist < gslist.size(); igslist++) { |
---|
| 246 | const G4String& name = gslist[igslist]->GetName(); |
---|
| 247 | const G4String& nickname = gslist[igslist]->GetNickname(); |
---|
| 248 | if (nickname.isNull()) { |
---|
| 249 | candidates += name; |
---|
| 250 | } |
---|
| 251 | else { |
---|
| 252 | candidates += nickname; |
---|
| 253 | } |
---|
| 254 | candidates += " "; |
---|
| 255 | } |
---|
| 256 | candidates = candidates.strip(); |
---|
| 257 | parameter->SetParameterCandidates(candidates); |
---|
| 258 | fpCommand->SetParameter(parameter); |
---|
| 259 | parameter = new G4UIparameter("window-size-hint", 's', omitable = true); |
---|
| 260 | parameter->SetGuidance |
---|
| 261 | ("integer (pixels) for square window placed by window manager or" |
---|
| 262 | " X-Windows-type geometry string, e.g. 600x600-100+100"); |
---|
| 263 | parameter->SetDefaultValue("600"); |
---|
| 264 | fpCommand->SetParameter(parameter); |
---|
| 265 | } |
---|
| 266 | |
---|
| 267 | G4VisCommandOpen::~G4VisCommandOpen() { |
---|
| 268 | delete fpCommand; |
---|
| 269 | } |
---|
| 270 | |
---|
| 271 | void G4VisCommandOpen::SetNewValue (G4UIcommand*, G4String newValue) { |
---|
| 272 | G4String systemName, windowSizeHint; |
---|
| 273 | std::istringstream is(newValue); |
---|
| 274 | is >> systemName >> windowSizeHint; |
---|
| 275 | G4UImanager* UImanager = G4UImanager::GetUIpointer(); |
---|
| 276 | G4int keepVerbose = UImanager->GetVerboseLevel(); |
---|
| 277 | G4int newVerbose(0); |
---|
| 278 | if (keepVerbose >= 2 || |
---|
| 279 | fpVisManager->GetVerbosity() >= G4VisManager::confirmations) |
---|
| 280 | newVerbose = 2; |
---|
| 281 | UImanager->SetVerboseLevel(newVerbose); |
---|
| 282 | UImanager->ApplyCommand(G4String("/vis/sceneHandler/create " + systemName)); |
---|
| 283 | UImanager->ApplyCommand(G4String("/vis/viewer/create ! ! " + windowSizeHint)); |
---|
| 284 | UImanager->SetVerboseLevel(keepVerbose); |
---|
| 285 | } |
---|
| 286 | |
---|
| 287 | ////////////// /vis/specify /////////////////////////////////////// |
---|
| 288 | |
---|
| 289 | G4VisCommandSpecify::G4VisCommandSpecify() { |
---|
| 290 | G4bool omitable; |
---|
| 291 | fpCommand = new G4UIcommand("/vis/specify", this); |
---|
| 292 | fpCommand->SetGuidance |
---|
| 293 | ("Draws logical volume with Boolean components, voxels and readout geometry."); |
---|
| 294 | fpCommand->SetGuidance |
---|
| 295 | ("Creates a scene consisting of this logical volume and asks the" |
---|
| 296 | "\n current viewer to draw it to the specified depth of descent" |
---|
| 297 | "\n showing boolean components (if any), voxels (if any)" |
---|
| 298 | "\n and readout geometry (if any), under control of the appropriate flag."); |
---|
| 299 | fpCommand->SetGuidance |
---|
| 300 | ("Note: voxels are not constructed until start of run - /run/beamOn."); |
---|
| 301 | fpCommand->SetGuidance("The scene becomes current."); |
---|
| 302 | G4UIparameter* parameter; |
---|
| 303 | parameter = new G4UIparameter("logical-volume-name", 's', omitable = false); |
---|
| 304 | fpCommand->SetParameter(parameter); |
---|
| 305 | parameter = new G4UIparameter("depth-of-descent", 'i', omitable = true); |
---|
| 306 | parameter->SetDefaultValue(1); |
---|
| 307 | fpCommand->SetParameter(parameter); |
---|
| 308 | parameter = new G4UIparameter("booleans-flag", 'b', omitable = true); |
---|
| 309 | parameter->SetDefaultValue(true); |
---|
| 310 | fpCommand->SetParameter(parameter); |
---|
| 311 | parameter = new G4UIparameter("voxels-flag", 'b', omitable = true); |
---|
| 312 | parameter->SetDefaultValue(true); |
---|
| 313 | fpCommand->SetParameter(parameter); |
---|
| 314 | parameter = new G4UIparameter("readout-flag", 'b', omitable = true); |
---|
| 315 | parameter->SetDefaultValue(true); |
---|
| 316 | fpCommand->SetParameter(parameter); |
---|
| 317 | } |
---|
| 318 | |
---|
| 319 | G4VisCommandSpecify::~G4VisCommandSpecify() { |
---|
| 320 | delete fpCommand; |
---|
| 321 | } |
---|
| 322 | |
---|
| 323 | void G4VisCommandSpecify::SetNewValue(G4UIcommand*, G4String newValue) { |
---|
| 324 | G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); |
---|
| 325 | G4UImanager* UImanager = G4UImanager::GetUIpointer(); |
---|
| 326 | G4int keepVerbose = UImanager->GetVerboseLevel(); |
---|
| 327 | G4int newVerbose(0); |
---|
| 328 | if (keepVerbose >= 2 || verbosity >= G4VisManager::confirmations) |
---|
| 329 | newVerbose = 2; |
---|
| 330 | UImanager->SetVerboseLevel(newVerbose); |
---|
| 331 | // UImanager->ApplyCommand(G4String("/geometry/print " + newValue)); |
---|
| 332 | UImanager->ApplyCommand("/vis/scene/create"); |
---|
| 333 | UImanager->ApplyCommand(G4String("/vis/scene/add/logicalVolume " + newValue)); |
---|
| 334 | UImanager->ApplyCommand("/vis/sceneHandler/attach"); |
---|
| 335 | UImanager->SetVerboseLevel(keepVerbose); |
---|
| 336 | static G4bool warned = false; |
---|
[593] | 337 | if (verbosity >= G4VisManager::confirmations && !warned) { |
---|
[531] | 338 | G4cout << |
---|
[593] | 339 | "NOTE: For systems which are not \"auto-refresh\" you will need to" |
---|
[531] | 340 | "\n issue \"/vis/viewer/refresh\" or \"/vis/viewer/flush\"." |
---|
| 341 | << G4endl; |
---|
| 342 | warned = true; |
---|
| 343 | } |
---|
| 344 | } |
---|