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 // Compound /vis/ commands - John Allison 15t 28 // Compound /vis/ commands - John Allison 15th May 2000 29 29 30 #include "G4VisCommandsCompound.hh" 30 #include "G4VisCommandsCompound.hh" 31 31 32 #include "G4VisManager.hh" 32 #include "G4VisManager.hh" 33 #include "G4UImanager.hh" 33 #include "G4UImanager.hh" 34 #include "G4UIcommandTree.hh" 34 #include "G4UIcommandTree.hh" 35 #include "G4UIcmdWithAString.hh" 35 #include "G4UIcmdWithAString.hh" 36 36 37 #include <sstream> 37 #include <sstream> 38 #include <set> 38 #include <set> 39 39 40 #define G4warn G4cout << 41 << 42 ////////////// /vis/drawTree ///////////////// 40 ////////////// /vis/drawTree /////////////////////////////////////// 43 41 44 G4VisCommandDrawTree::G4VisCommandDrawTree() { 42 G4VisCommandDrawTree::G4VisCommandDrawTree() { 45 G4bool omitable; 43 G4bool omitable; 46 fpCommand = new G4UIcommand("/vis/drawTree", 44 fpCommand = new G4UIcommand("/vis/drawTree", this); 47 fpCommand->SetGuidance 45 fpCommand->SetGuidance 48 ("Produces a representation of the geometr 46 ("Produces a representation of the geometry hierarchy. Further" 49 "\nguidance is given on running the comma 47 "\nguidance is given on running the command. Or look at the guidance" 50 "\nfor \"/vis/ASCIITree/verbose\"."); 48 "\nfor \"/vis/ASCIITree/verbose\"."); 51 fpCommand->SetGuidance("The pre-existing sce 49 fpCommand->SetGuidance("The pre-existing scene and view are preserved."); 52 G4UIparameter* parameter; 50 G4UIparameter* parameter; 53 parameter = new G4UIparameter("physical-volu 51 parameter = new G4UIparameter("physical-volume-name", 's', omitable = true); 54 parameter -> SetDefaultValue("world"); 52 parameter -> SetDefaultValue("world"); 55 fpCommand -> SetParameter (parameter); 53 fpCommand -> SetParameter (parameter); 56 parameter = new G4UIparameter("system", 's', 54 parameter = new G4UIparameter("system", 's', omitable = true); 57 parameter -> SetDefaultValue("ATree"); 55 parameter -> SetDefaultValue("ATree"); 58 fpCommand -> SetParameter (parameter); 56 fpCommand -> SetParameter (parameter); 59 } 57 } 60 58 61 G4VisCommandDrawTree::~G4VisCommandDrawTree() 59 G4VisCommandDrawTree::~G4VisCommandDrawTree() { 62 delete fpCommand; 60 delete fpCommand; 63 } 61 } 64 62 65 void G4VisCommandDrawTree::SetNewValue(G4UIcom 63 void G4VisCommandDrawTree::SetNewValue(G4UIcommand*, G4String newValue) { 66 64 67 G4String pvname, system; 65 G4String pvname, system; 68 std::istringstream is(newValue); 66 std::istringstream is(newValue); 69 is >> pvname >> system; 67 is >> pvname >> system; 70 68 71 // Note: The second parameter, "system", is 69 // Note: The second parameter, "system", is intended to allow the user 72 // a choice of dedicated tree printing/displ 70 // a choice of dedicated tree printing/displaying systems but at present 73 // the only such dedicated system is ASCIITr 71 // the only such dedicated system is ASCIITree. It doesn't make sense to 74 // specify OGLSX, for example. So to avoid 72 // specify OGLSX, for example. So to avoid confusion we restrict this 75 // feature to systems that have "Tree" in th 73 // feature to systems that have "Tree" in the name or nickname. 76 74 77 // Of course, some other systems, such as OG 75 // Of course, some other systems, such as OGLSQt, have a tree browser 78 // built-in. The HepRApp offline browser al 76 // built-in. The HepRApp offline browser also has a tree browser 79 // built in. 77 // built in. 80 78 81 if (!G4StrUtil::contains(system, "Tree")) { << 79 if (!system.contains("Tree")) { 82 system = "ATree"; 80 system = "ATree"; 83 } 81 } 84 82 85 G4VGraphicsSystem* keepSystem = fpVisManager 83 G4VGraphicsSystem* keepSystem = fpVisManager->GetCurrentGraphicsSystem(); 86 G4Scene* keepScene = fpVisManager->GetCurren 84 G4Scene* keepScene = fpVisManager->GetCurrentScene(); 87 G4VSceneHandler* keepSceneHandler = fpVisMan 85 G4VSceneHandler* keepSceneHandler = fpVisManager->GetCurrentSceneHandler(); 88 G4VViewer* keepViewer = fpVisManager->GetCur 86 G4VViewer* keepViewer = fpVisManager->GetCurrentViewer(); 89 G4VisManager::Verbosity keepVisVerbosity = f 87 G4VisManager::Verbosity keepVisVerbosity = fpVisManager->GetVerbosity(); 90 G4bool keepAbleness = fpVisManager->GetConcr << 91 88 92 G4UImanager* UImanager = G4UImanager::GetUIp 89 G4UImanager* UImanager = G4UImanager::GetUIpointer(); 93 G4int keepUIVerbose = UImanager->GetVerboseL 90 G4int keepUIVerbose = UImanager->GetVerboseLevel(); 94 G4int newVerbose(0); 91 G4int newVerbose(0); 95 if (keepUIVerbose >= 2 || 92 if (keepUIVerbose >= 2 || 96 fpVisManager->GetVerbosity() >= G4VisMan 93 fpVisManager->GetVerbosity() >= G4VisManager::confirmations) 97 newVerbose = 2; 94 newVerbose = 2; 98 UImanager->SetVerboseLevel(newVerbose); 95 UImanager->SetVerboseLevel(newVerbose); 99 96 100 auto errorCode = UImanager->ApplyCommand(G4S << 97 G4bool keepAbleness = fpVisManager->GetConcreteInstance()? true: false; 101 if (errorCode == 0) { << 98 >> 99 UImanager->ApplyCommand(G4String("/vis/open " + system)); >> 100 if (fErrorCode == 0) { 102 if (!keepAbleness) { // Enable temporaril 101 if (!keepAbleness) { // Enable temporarily 103 fpVisManager->SetVerboseLevel("Quiet"); 102 fpVisManager->SetVerboseLevel("Quiet"); 104 UImanager->ApplyCommand("/vis/enable"); 103 UImanager->ApplyCommand("/vis/enable"); 105 fpVisManager->SetVerboseLevel(keepVisVer 104 fpVisManager->SetVerboseLevel(keepVisVerbosity); 106 } 105 } 107 UImanager->ApplyCommand("/vis/viewer/reset << 108 UImanager->ApplyCommand(G4String("/vis/dra 106 UImanager->ApplyCommand(G4String("/vis/drawVolume " + pvname)); 109 UImanager->ApplyCommand("/vis/viewer/flush 107 UImanager->ApplyCommand("/vis/viewer/flush"); 110 if (!keepAbleness) { // Disable again 108 if (!keepAbleness) { // Disable again 111 fpVisManager->SetVerboseLevel("Quiet"); 109 fpVisManager->SetVerboseLevel("Quiet"); 112 UImanager->ApplyCommand("/vis/disable"); 110 UImanager->ApplyCommand("/vis/disable"); 113 fpVisManager->SetVerboseLevel(keepVisVer 111 fpVisManager->SetVerboseLevel(keepVisVerbosity); 114 } 112 } 115 if (keepViewer) { 113 if (keepViewer) { 116 if (fpVisManager->GetVerbosity() >= G4Vi 114 if (fpVisManager->GetVerbosity() >= G4VisManager::warnings) { 117 G4warn << "Reverting to " << keepViewe << 115 G4cout << "Reverting to " << keepViewer->GetName() << G4endl; 118 } 116 } 119 fpVisManager->SetCurrentGraphicsSystem(k 117 fpVisManager->SetCurrentGraphicsSystem(keepSystem); 120 fpVisManager->SetCurrentScene(keepScene) 118 fpVisManager->SetCurrentScene(keepScene); 121 fpVisManager->SetCurrentSceneHandler(kee 119 fpVisManager->SetCurrentSceneHandler(keepSceneHandler); 122 fpVisManager->SetCurrentViewer(keepViewe 120 fpVisManager->SetCurrentViewer(keepViewer); 123 } 121 } 124 } 122 } 125 UImanager->SetVerboseLevel(keepUIVerbose); 123 UImanager->SetVerboseLevel(keepUIVerbose); 126 } 124 } 127 125 128 ////////////// /vis/drawView ///////////////// 126 ////////////// /vis/drawView /////////////////////////////////////// 129 127 130 G4VisCommandDrawView::G4VisCommandDrawView() { 128 G4VisCommandDrawView::G4VisCommandDrawView() { 131 G4bool omitable; 129 G4bool omitable; 132 fpCommand = new G4UIcommand("/vis/drawView", 130 fpCommand = new G4UIcommand("/vis/drawView", this); 133 fpCommand->SetGuidance 131 fpCommand->SetGuidance 134 ("Draw view from this angle, etc."); 132 ("Draw view from this angle, etc."); 135 G4UIparameter* parameter; 133 G4UIparameter* parameter; 136 parameter = new G4UIparameter("theta-degrees 134 parameter = new G4UIparameter("theta-degrees", 'd', omitable = true); 137 parameter -> SetDefaultValue(0.); 135 parameter -> SetDefaultValue(0.); 138 fpCommand -> SetParameter (parameter); 136 fpCommand -> SetParameter (parameter); 139 parameter = new G4UIparameter("phi-degrees", 137 parameter = new G4UIparameter("phi-degrees", 'd', omitable = true); 140 parameter -> SetDefaultValue(0.); 138 parameter -> SetDefaultValue(0.); 141 fpCommand -> SetParameter (parameter); 139 fpCommand -> SetParameter (parameter); 142 parameter = new G4UIparameter("pan-right", ' 140 parameter = new G4UIparameter("pan-right", 'd', omitable = true); 143 parameter -> SetDefaultValue(0.); 141 parameter -> SetDefaultValue(0.); 144 fpCommand -> SetParameter (parameter); 142 fpCommand -> SetParameter (parameter); 145 parameter = new G4UIparameter("pan-up", 'd', 143 parameter = new G4UIparameter("pan-up", 'd', omitable = true); 146 parameter -> SetDefaultValue(0.); 144 parameter -> SetDefaultValue(0.); 147 fpCommand -> SetParameter (parameter); 145 fpCommand -> SetParameter (parameter); 148 parameter = new G4UIparameter("pan-unit", 's 146 parameter = new G4UIparameter("pan-unit", 's', omitable = true); 149 parameter -> SetDefaultValue("cm"); 147 parameter -> SetDefaultValue("cm"); 150 fpCommand -> SetParameter (parameter); 148 fpCommand -> SetParameter (parameter); 151 parameter = new G4UIparameter("zoom-factor", 149 parameter = new G4UIparameter("zoom-factor", 'd', omitable = true); 152 parameter -> SetDefaultValue(1.); 150 parameter -> SetDefaultValue(1.); 153 fpCommand -> SetParameter (parameter); 151 fpCommand -> SetParameter (parameter); 154 parameter = new G4UIparameter("dolly", 'd', 152 parameter = new G4UIparameter("dolly", 'd', omitable = true); 155 parameter -> SetDefaultValue(0.); 153 parameter -> SetDefaultValue(0.); 156 fpCommand -> SetParameter (parameter); 154 fpCommand -> SetParameter (parameter); 157 parameter = new G4UIparameter("dolly-unit", 155 parameter = new G4UIparameter("dolly-unit", 's', omitable = true); 158 parameter -> SetDefaultValue("cm"); 156 parameter -> SetDefaultValue("cm"); 159 fpCommand -> SetParameter (parameter); 157 fpCommand -> SetParameter (parameter); 160 } 158 } 161 159 162 G4VisCommandDrawView::~G4VisCommandDrawView() 160 G4VisCommandDrawView::~G4VisCommandDrawView() { 163 delete fpCommand; 161 delete fpCommand; 164 } 162 } 165 163 166 void G4VisCommandDrawView::SetNewValue(G4UIcom 164 void G4VisCommandDrawView::SetNewValue(G4UIcommand*, G4String newValue) { 167 165 168 G4VisManager::Verbosity verbosity = fpVisMan 166 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); 169 167 170 G4VViewer* currentViewer = fpVisManager->Get 168 G4VViewer* currentViewer = fpVisManager->GetCurrentViewer(); 171 if (!currentViewer) { 169 if (!currentViewer) { 172 if (verbosity >= G4VisManager::warnings) { 170 if (verbosity >= G4VisManager::warnings) { 173 G4warn << << 171 G4cout << 174 "WARNING: G4VisCommandsDrawView::SetNewValue 172 "WARNING: G4VisCommandsDrawView::SetNewValue: no current viewer." 175 << G4endl; 173 << G4endl; 176 } 174 } 177 return; 175 return; 178 } 176 } 179 177 180 G4String thetaDeg; 178 G4String thetaDeg; 181 G4String phiDeg; 179 G4String phiDeg; 182 G4String panRight; 180 G4String panRight; 183 G4String panUp; 181 G4String panUp; 184 G4String panUnit; 182 G4String panUnit; 185 G4String zoomFactor; 183 G4String zoomFactor; 186 G4String dolly; 184 G4String dolly; 187 G4String dollyUnit; 185 G4String dollyUnit; 188 std::istringstream is(newValue); 186 std::istringstream is(newValue); 189 is >> thetaDeg >> phiDeg >> panRight >> panU 187 is >> thetaDeg >> phiDeg >> panRight >> panUp >> panUnit 190 >> zoomFactor >> dolly >> dollyUnit; 188 >> zoomFactor >> dolly >> dollyUnit; 191 189 192 G4UImanager* UImanager = G4UImanager::GetUIp 190 G4UImanager* UImanager = G4UImanager::GetUIpointer(); >> 191 G4int keepVerbose = UImanager->GetVerboseLevel(); >> 192 G4int newVerbose(0); >> 193 if (keepVerbose >= 2 || >> 194 fpVisManager->GetVerbosity() >= G4VisManager::confirmations) >> 195 newVerbose = 2; >> 196 UImanager->SetVerboseLevel(newVerbose); 193 G4ViewParameters vp = currentViewer->GetView 197 G4ViewParameters vp = currentViewer->GetViewParameters(); 194 G4bool keepAutoRefresh = vp.IsAutoRefresh(); 198 G4bool keepAutoRefresh = vp.IsAutoRefresh(); 195 vp.SetAutoRefresh(false); 199 vp.SetAutoRefresh(false); 196 currentViewer->SetViewParameters(vp); 200 currentViewer->SetViewParameters(vp); 197 UImanager->ApplyCommand( 201 UImanager->ApplyCommand( 198 G4String("/vis/viewer/set/viewpointThetaPh 202 G4String("/vis/viewer/set/viewpointThetaPhi " + thetaDeg + " " + phiDeg + " deg")); 199 UImanager->ApplyCommand( 203 UImanager->ApplyCommand( 200 G4String("/vis/viewer/panTo " + panRight + 204 G4String("/vis/viewer/panTo " + panRight + " " + panUp + " " + panUnit)); 201 UImanager->ApplyCommand( 205 UImanager->ApplyCommand( 202 G4String("/vis/viewer/zoomTo " + zoomFacto 206 G4String("/vis/viewer/zoomTo " + zoomFactor)); 203 vp = currentViewer->GetViewParameters(); 207 vp = currentViewer->GetViewParameters(); 204 vp.SetAutoRefresh(keepAutoRefresh); 208 vp.SetAutoRefresh(keepAutoRefresh); 205 currentViewer->SetViewParameters(vp); 209 currentViewer->SetViewParameters(vp); 206 UImanager->ApplyCommand( 210 UImanager->ApplyCommand( 207 G4String("/vis/viewer/dollyTo " + dolly + 211 G4String("/vis/viewer/dollyTo " + dolly + " " + dollyUnit)); >> 212 UImanager->SetVerboseLevel(keepVerbose); 208 } 213 } 209 214 210 ////////////// /vis/drawLogicalVolume //////// 215 ////////////// /vis/drawLogicalVolume /////////////////////////////////////// 211 216 212 G4VisCommandDrawLogicalVolume::G4VisCommandDra 217 G4VisCommandDrawLogicalVolume::G4VisCommandDrawLogicalVolume() { 213 fpCommand = new G4UIcommand("/vis/drawLogica 218 fpCommand = new G4UIcommand("/vis/drawLogicalVolume", this); 214 fpCommand->SetGuidance 219 fpCommand->SetGuidance 215 ("Draws logical volume with additional compo 220 ("Draws logical volume with additional components."); 216 fpCommand->SetGuidance 221 fpCommand->SetGuidance 217 ("Synonymous with \"/vis/specify\"."); 222 ("Synonymous with \"/vis/specify\"."); 218 fpCommand->SetGuidance 223 fpCommand->SetGuidance 219 ("Creates a scene consisting of this logical 224 ("Creates a scene consisting of this logical volume and asks the" 220 "\n current viewer to draw it. The scene b 225 "\n current viewer to draw it. The scene becomes current."); 221 const G4UIcommandTree* tree = G4UImanager::G 226 const G4UIcommandTree* tree = G4UImanager::GetUIpointer()->GetTree(); 222 const G4UIcommand* addLogVolCmd = tree->Find 227 const G4UIcommand* addLogVolCmd = tree->FindPath("/vis/scene/add/logicalVolume"); 223 // Pick up guidance from /vis/scene/add/logi 228 // Pick up guidance from /vis/scene/add/logicalVolume 224 CopyGuidanceFrom(addLogVolCmd,fpCommand); 229 CopyGuidanceFrom(addLogVolCmd,fpCommand); 225 // Pick up parameters from /vis/scene/add/lo 230 // Pick up parameters from /vis/scene/add/logicalVolume 226 CopyParametersFrom(addLogVolCmd,fpCommand); 231 CopyParametersFrom(addLogVolCmd,fpCommand); 227 } 232 } 228 233 229 G4VisCommandDrawLogicalVolume::~G4VisCommandDr 234 G4VisCommandDrawLogicalVolume::~G4VisCommandDrawLogicalVolume() { 230 delete fpCommand; 235 delete fpCommand; 231 } 236 } 232 237 233 void G4VisCommandDrawLogicalVolume::SetNewValu 238 void G4VisCommandDrawLogicalVolume::SetNewValue(G4UIcommand*, G4String newValue) { 234 G4VisManager::Verbosity verbosity = fpVisMan 239 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); 235 G4UImanager* UImanager = G4UImanager::GetUIp 240 G4UImanager* UImanager = G4UImanager::GetUIpointer(); >> 241 G4int keepVerbose = UImanager->GetVerboseLevel(); >> 242 G4int newVerbose(0); >> 243 if (keepVerbose >= 2 || verbosity >= G4VisManager::confirmations) >> 244 newVerbose = 2; >> 245 UImanager->SetVerboseLevel(newVerbose); 236 G4VViewer* currentViewer = fpVisManager->Get 246 G4VViewer* currentViewer = fpVisManager->GetCurrentViewer(); 237 const G4ViewParameters& currentViewParams = 247 const G4ViewParameters& currentViewParams = currentViewer->GetViewParameters(); 238 G4bool keepAutoRefresh = currentViewParams.I 248 G4bool keepAutoRefresh = currentViewParams.IsAutoRefresh(); 239 if (keepAutoRefresh) UImanager->ApplyCommand 249 if (keepAutoRefresh) UImanager->ApplyCommand("/vis/viewer/set/autoRefresh false"); 240 UImanager->ApplyCommand("/vis/scene/create") 250 UImanager->ApplyCommand("/vis/scene/create"); 241 UImanager->ApplyCommand(G4String("/vis/scene 251 UImanager->ApplyCommand(G4String("/vis/scene/add/logicalVolume " + newValue)); 242 UImanager->ApplyCommand("/vis/sceneHandler/a 252 UImanager->ApplyCommand("/vis/sceneHandler/attach"); 243 G4ViewParameters::DrawingStyle keepDrawingSt 253 G4ViewParameters::DrawingStyle keepDrawingStyle = currentViewParams.GetDrawingStyle(); 244 if(keepDrawingStyle != G4ViewParameters::wir 254 if(keepDrawingStyle != G4ViewParameters::wireframe) 245 UImanager->ApplyCommand("/vis/viewer/set/s 255 UImanager->ApplyCommand("/vis/viewer/set/style wireframe"); 246 G4bool keepMarkerNotHidden = currentViewPara 256 G4bool keepMarkerNotHidden = currentViewParams.IsMarkerNotHidden(); 247 if (!keepMarkerNotHidden) UImanager->ApplyCo 257 if (!keepMarkerNotHidden) UImanager->ApplyCommand("/vis/viewer/set/hiddenMarker false"); 248 if (keepAutoRefresh) UImanager->ApplyCommand 258 if (keepAutoRefresh) UImanager->ApplyCommand("/vis/viewer/set/autoRefresh true"); >> 259 UImanager->SetVerboseLevel(keepVerbose); 249 if (verbosity >= G4VisManager::warnings) { 260 if (verbosity >= G4VisManager::warnings) { 250 if (keepDrawingStyle != currentViewParams. 261 if (keepDrawingStyle != currentViewParams.GetDrawingStyle()) { 251 G4warn << 262 G4cout 252 << "Drawing style changed to wireframe. 263 << "Drawing style changed to wireframe. To restore previous style:"; 253 G4String style, edge; 264 G4String style, edge; 254 switch (keepDrawingStyle) { 265 switch (keepDrawingStyle) { 255 case G4ViewParameters::wireframe: 266 case G4ViewParameters::wireframe: 256 style = "wireframe"; edge = "false"; 267 style = "wireframe"; edge = "false"; break; 257 case G4ViewParameters::hlr: 268 case G4ViewParameters::hlr: 258 style = "wireframe"; edge = "true"; 269 style = "wireframe"; edge = "true"; break; 259 case G4ViewParameters::hsr: 270 case G4ViewParameters::hsr: 260 style = "surface"; edge = "false"; b 271 style = "surface"; edge = "false"; break; 261 case G4ViewParameters::hlhsr: 272 case G4ViewParameters::hlhsr: 262 style = "surface"; edge = "true"; br 273 style = "surface"; edge = "true"; break; 263 case G4ViewParameters::cloud: 274 case G4ViewParameters::cloud: 264 style = "cloud"; edge = ""; break; 275 style = "cloud"; edge = ""; break; 265 } 276 } 266 G4warn << "\n /vis/viewer/set/style " + << 277 G4cout << "\n /vis/viewer/set/style " + style; 267 if (!edge.empty()) G4warn << "\n /vis/v << 278 if (!edge.empty()) G4cout << "\n /vis/viewer/set/hiddenEdge " + edge; 268 G4warn << G4endl; << 279 G4cout << G4endl; 269 } 280 } 270 if (keepMarkerNotHidden != currentViewPara 281 if (keepMarkerNotHidden != currentViewParams.IsMarkerNotHidden()) { 271 G4warn << 282 G4cout 272 << "Markers changed to \"not hidden\". T 283 << "Markers changed to \"not hidden\". To restore previous condition:" 273 << "\n /vis/viewer/set/hiddenmarker tru 284 << "\n /vis/viewer/set/hiddenmarker true" 274 << G4endl; 285 << G4endl; 275 } 286 } 276 } 287 } 277 static G4bool warned = false; 288 static G4bool warned = false; 278 if (verbosity >= G4VisManager::confirmations 289 if (verbosity >= G4VisManager::confirmations && !warned) { 279 G4cout << 290 G4cout << 280 "NOTE: For systems which are not \"auto-re 291 "NOTE: For systems which are not \"auto-refresh\" you will need to" 281 "\n issue \"/vis/viewer/refresh\" or \"/v 292 "\n issue \"/vis/viewer/refresh\" or \"/vis/viewer/flush\"." 282 << G4endl; 293 << G4endl; 283 warned = true; 294 warned = true; 284 } 295 } 285 } 296 } 286 297 287 ////////////// /vis/drawVolume /////////////// 298 ////////////// /vis/drawVolume /////////////////////////////////////// 288 299 289 G4VisCommandDrawVolume::G4VisCommandDrawVolume 300 G4VisCommandDrawVolume::G4VisCommandDrawVolume() { 290 fpCommand = new G4UIcommand("/vis/drawVolume 301 fpCommand = new G4UIcommand("/vis/drawVolume", this); 291 fpCommand->SetGuidance 302 fpCommand->SetGuidance 292 ("Creates a scene containing this physical v 303 ("Creates a scene containing this physical volume and asks the" 293 "\ncurrent viewer to draw it. The scene be 304 "\ncurrent viewer to draw it. The scene becomes current."); 294 const G4UIcommandTree* tree = G4UImanager::G 305 const G4UIcommandTree* tree = G4UImanager::GetUIpointer()->GetTree(); 295 const G4UIcommand* addVolCmd = tree->FindPat 306 const G4UIcommand* addVolCmd = tree->FindPath("/vis/scene/add/volume"); 296 // Pick up guidance from /vis/scene/add/volu 307 // Pick up guidance from /vis/scene/add/volume 297 CopyGuidanceFrom(addVolCmd,fpCommand); 308 CopyGuidanceFrom(addVolCmd,fpCommand); 298 // Pick up parameters from /vis/scene/add/vo 309 // Pick up parameters from /vis/scene/add/volume 299 CopyParametersFrom(addVolCmd,fpCommand); 310 CopyParametersFrom(addVolCmd,fpCommand); 300 } 311 } 301 312 302 G4VisCommandDrawVolume::~G4VisCommandDrawVolum 313 G4VisCommandDrawVolume::~G4VisCommandDrawVolume() { 303 delete fpCommand; 314 delete fpCommand; 304 } 315 } 305 316 306 void G4VisCommandDrawVolume::SetNewValue(G4UIc 317 void G4VisCommandDrawVolume::SetNewValue(G4UIcommand*, G4String newValue) { 307 G4VisManager::Verbosity verbosity = fpVisMan 318 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); 308 G4UImanager* UImanager = G4UImanager::GetUIp 319 G4UImanager* UImanager = G4UImanager::GetUIpointer(); >> 320 G4int keepVerbose = UImanager->GetVerboseLevel(); >> 321 G4int newVerbose(0); >> 322 if (keepVerbose >= 2 || verbosity >= G4VisManager::confirmations) >> 323 newVerbose = 2; >> 324 UImanager->SetVerboseLevel(newVerbose); 309 UImanager->ApplyCommand("/vis/scene/create") 325 UImanager->ApplyCommand("/vis/scene/create"); 310 UImanager->ApplyCommand(G4String("/vis/scene 326 UImanager->ApplyCommand(G4String("/vis/scene/add/volume " + newValue)); 311 UImanager->ApplyCommand("/vis/sceneHandler/a 327 UImanager->ApplyCommand("/vis/sceneHandler/attach"); >> 328 UImanager->SetVerboseLevel(keepVerbose); 312 static G4bool warned = false; 329 static G4bool warned = false; 313 if (verbosity >= G4VisManager::confirmations 330 if (verbosity >= G4VisManager::confirmations && !warned) { 314 G4cout << 331 G4cout << 315 "NOTE: For systems which are not \"auto- 332 "NOTE: For systems which are not \"auto-refresh\" you will need to" 316 "\n issue \"/vis/viewer/refresh\" or \" 333 "\n issue \"/vis/viewer/refresh\" or \"/vis/viewer/flush\"." 317 << G4endl; 334 << G4endl; 318 warned = true; 335 warned = true; 319 } 336 } 320 } 337 } 321 338 322 ////////////// /vis/open ///////////////////// 339 ////////////// /vis/open /////////////////////////////////////// 323 340 324 G4VisCommandOpen::G4VisCommandOpen() { 341 G4VisCommandOpen::G4VisCommandOpen() { 325 G4bool omitable; 342 G4bool omitable; 326 fpCommand = new G4UIcommand("/vis/open", thi 343 fpCommand = new G4UIcommand("/vis/open", this); 327 fpCommand->SetGuidance 344 fpCommand->SetGuidance 328 ("Creates a scene handler and viewer ready << 345 ("Creates a scene handler ready for drawing."); 329 fpCommand->SetGuidance 346 fpCommand->SetGuidance 330 ("The scene handler and viewer names are a << 347 ("The scene handler becomes current (the name is auto-generated)."); 331 // Pick up guidance from /vis/viewer/create << 332 const G4UIcommandTree* tree = G4UImanager::G << 333 const G4UIcommand* viewerCreateCmd = tree->F << 334 CopyGuidanceFrom(viewerCreateCmd,fpCommand,2 << 335 G4UIparameter* parameter; 348 G4UIparameter* parameter; 336 parameter = new G4UIparameter("graphics-syst << 349 parameter = new G4UIparameter("graphics-system-name", 's', omitable = false); 337 parameter->SetCurrentAsDefault(true); << 338 fpCommand->SetParameter(parameter); 350 fpCommand->SetParameter(parameter); 339 parameter = new G4UIparameter("window-size-h 351 parameter = new G4UIparameter("window-size-hint", 's', omitable = true); 340 parameter->SetGuidance 352 parameter->SetGuidance 341 ("integer (pixels) for square window place 353 ("integer (pixels) for square window placed by window manager or" 342 " X-Windows-type geometry string, e.g. 60 354 " X-Windows-type geometry string, e.g. 600x600-100+100"); 343 parameter->SetCurrentAsDefault(true); << 355 parameter->SetDefaultValue("600"); 344 fpCommand->SetParameter(parameter); 356 fpCommand->SetParameter(parameter); 345 } 357 } 346 358 347 G4VisCommandOpen::~G4VisCommandOpen() { 359 G4VisCommandOpen::~G4VisCommandOpen() { 348 delete fpCommand; 360 delete fpCommand; 349 } 361 } 350 362 351 G4String G4VisCommandOpen::GetCurrentValue(G4U << 363 void G4VisCommandOpen::SetNewValue (G4UIcommand*, G4String newValue) { 352 { << 353 G4String graphicsSystemName, windowSizeHint; << 354 auto graphicsSystem = fpVisManager->GetCurre << 355 if (graphicsSystem) { << 356 // Take name and hint from latest graphics << 357 graphicsSystemName = graphicsSystem->GetNa << 358 auto viewer = fpVisManager->GetCurrentView << 359 if (viewer) { << 360 windowSizeHint = viewer->GetViewParamete << 361 } << 362 else { // Viewer not yet created? << 363 windowSizeHint = fpVisManager->GetDefaul << 364 } << 365 } << 366 else { // No graphics system yet - must be << 367 graphicsSystemName = fpVisManager->GetDefa << 368 windowSizeHint = fpVisManager->GetDefaultX << 369 } << 370 return graphicsSystemName + ' ' + windowSize << 371 } << 372 << 373 void G4VisCommandOpen::SetNewValue (G4UIcomman << 374 { << 375 G4String systemName, windowSizeHint; 364 G4String systemName, windowSizeHint; 376 std::istringstream is(newValue); 365 std::istringstream is(newValue); 377 is >> systemName >> windowSizeHint; 366 is >> systemName >> windowSizeHint; 378 G4UImanager* UImanager = G4UImanager::GetUIp 367 G4UImanager* UImanager = G4UImanager::GetUIpointer(); 379 << 368 G4int keepVerbose = UImanager->GetVerboseLevel(); 380 auto errorCode = UImanager->ApplyCommand(G4S << 369 G4int newVerbose(0); 381 if (errorCode) { << 370 if (keepVerbose >= 2 || 382 G4warn << "sub-command \"/vis/sceneHandler << 371 fpVisManager->GetVerbosity() >= G4VisManager::confirmations) 383 goto finish; << 372 newVerbose = 2; 384 } << 373 UImanager->SetVerboseLevel(newVerbose); 385 << 374 fErrorCode = UImanager->ApplyCommand(G4String("/vis/sceneHandler/create " + systemName)); 386 errorCode = UImanager->ApplyCommand(G4String << 375 if (fErrorCode == 0) { 387 if (errorCode) { << 376 UImanager->ApplyCommand(G4String("/vis/viewer/create ! ! " + windowSizeHint)); 388 G4warn << "sub-command \"/vis/viewer/creat << 377 } else { 389 goto finish; << 378 // Use set to get alphabetical order 390 } << 379 std::set<G4String> candidates; 391 << 380 for (const auto gs: fpVisManager -> GetAvailableGraphicsSystems()) { 392 finish: << 381 // Just list nicknames, but exclude FALLBACK nicknames 393 if (errorCode) { << 382 for (const auto& nickname: gs->GetNicknames()) { 394 fpVisManager->PrintAvailableGraphicsSystem << 383 if (!nickname.contains("FALLBACK")) { 395 if (errorCode != JustWarning) { << 384 candidates.insert(nickname); 396 G4ExceptionDescription ed; << 385 } 397 ed << "Invoked command has failed - see << 386 } 398 command->CommandFailed(errorCode,ed); << 399 } 387 } >> 388 G4cerr << "Candidates are:"; >> 389 for (const auto& candidate: candidates) { >> 390 G4cerr << ' ' << candidate; >> 391 } >> 392 G4cerr << G4endl; 400 } 393 } 401 } << 394 UImanager->SetVerboseLevel(keepVerbose); 402 << 403 ////////////// /vis/plot ///////////////////// << 404 << 405 G4VisCommandPlot::G4VisCommandPlot () << 406 { << 407 G4bool omitable; << 408 G4UIparameter* parameter; << 409 << 410 fpCommand = new G4UIcommand("/vis/plot", thi << 411 fpCommand -> SetGuidance("Draws plots."); << 412 parameter = new G4UIparameter ("type", 's', << 413 parameter -> SetParameterCandidates("h1 h2") << 414 fpCommand -> SetParameter (parameter); << 415 parameter = new G4UIparameter ("id", 'i', om << 416 fpCommand -> SetParameter (parameter); << 417 #ifdef TOOLS_USE_FREETYPE << 418 parameter = new G4UIparameter ("style", 's', << 419 parameter -> SetParameterCandidates("none RO << 420 parameter -> SetDefaultValue("ROOT_default") << 421 fpCommand -> SetParameter (parameter); << 422 #endif << 423 } << 424 << 425 G4VisCommandPlot::~G4VisCommandPlot () << 426 { << 427 delete fpCommand; << 428 } << 429 << 430 G4String G4VisCommandPlot::GetCurrentValue (G4 << 431 { << 432 return ""; << 433 } << 434 << 435 void G4VisCommandPlot::SetNewValue (G4UIcomman << 436 { << 437 auto currentViewer = fpVisManager->GetCurren << 438 if (currentViewer->GetName().find("TOOLSSG") << 439 G4warn << << 440 "WARNING: Current viewer not able to draw << 441 "\n Try \"/vis/open TSG\", then \"/vis/pl << 442 << G4endl; << 443 return; << 444 } << 445 << 446 std::istringstream is (newValue); << 447 G4String type, id; << 448 is >> type >> id; << 449 #ifdef TOOLS_USE_FREETYPE << 450 G4String style; << 451 is >> style; << 452 #endif << 453 << 454 auto keepEnable = fpVisManager->IsEnabled(); << 455 << 456 auto ui = G4UImanager::GetUIpointer(); << 457 ui->ApplyCommand("/vis/enable"); << 458 ui->ApplyCommand("/vis/viewer/resetCameraPar << 459 ui->ApplyCommand("/vis/scene/create"); << 460 ui->ApplyCommand("/vis/scene/endOfEventActio << 461 static G4int plotterID = 0; << 462 std::ostringstream ossPlotter; << 463 ossPlotter << "plotter-" << plotterID++; << 464 const G4String& plotterName = ossPlotter.str << 465 ui->ApplyCommand("/vis/plotter/create " + pl << 466 ui->ApplyCommand("/vis/scene/add/plotter " + << 467 ui->ApplyCommand("/vis/plotter/add/" + type << 468 #ifdef TOOLS_USE_FREETYPE << 469 if (style != "none") { << 470 ui->ApplyCommand("/vis/plotter/addStyle " << 471 } << 472 #endif << 473 ui->ApplyCommand("/vis/sceneHandler/attach") << 474 << 475 if (!keepEnable) { << 476 fpVisManager->Disable(); << 477 G4warn << << 478 "WARNING: drawing was enabled for plotting << 479 << G4endl; << 480 } << 481 } 395 } 482 396 483 ////////////// /vis/specify ////////////////// 397 ////////////// /vis/specify /////////////////////////////////////// 484 398 485 G4VisCommandSpecify::G4VisCommandSpecify() { 399 G4VisCommandSpecify::G4VisCommandSpecify() { 486 G4bool omitable; 400 G4bool omitable; 487 fpCommand = new G4UIcommand("/vis/specify", 401 fpCommand = new G4UIcommand("/vis/specify", this); 488 fpCommand->SetGuidance 402 fpCommand->SetGuidance 489 ("Draws logical volume with Boolean compon 403 ("Draws logical volume with Boolean components, voxels and readout geometry."); 490 fpCommand->SetGuidance 404 fpCommand->SetGuidance 491 ("Synonymous with \"/vis/drawLogicalVolume 405 ("Synonymous with \"/vis/drawLogicalVolume\"."); 492 fpCommand->SetGuidance 406 fpCommand->SetGuidance 493 ("Creates a scene consisting of this logic 407 ("Creates a scene consisting of this logical volume and asks the" 494 "\n current viewer to draw it to the spe 408 "\n current viewer to draw it to the specified depth of descent" 495 "\n showing boolean components (if any), 409 "\n showing boolean components (if any), voxels (if any)," 496 "\n readout geometry (if any), local axe 410 "\n readout geometry (if any), local axes and overlaps (if any)," 497 "\n under control of the appropriate fla 411 "\n under control of the appropriate flag."); 498 fpCommand->SetGuidance 412 fpCommand->SetGuidance 499 ("Note: voxels are not constructed until sta 413 ("Note: voxels are not constructed until start of run - /run/beamOn." 500 "\n (For voxels without a run, \"/run/beam 414 "\n (For voxels without a run, \"/run/beamOn 0\".)"); 501 fpCommand->SetGuidance("The scene becomes cu 415 fpCommand->SetGuidance("The scene becomes current."); 502 G4UIparameter* parameter; 416 G4UIparameter* parameter; 503 parameter = new G4UIparameter("logical-volum 417 parameter = new G4UIparameter("logical-volume-name", 's', omitable = false); 504 fpCommand->SetParameter(parameter); 418 fpCommand->SetParameter(parameter); 505 parameter = new G4UIparameter("depth-of-desc 419 parameter = new G4UIparameter("depth-of-descent", 'i', omitable = true); 506 parameter->SetDefaultValue(1); 420 parameter->SetDefaultValue(1); 507 fpCommand->SetParameter(parameter); 421 fpCommand->SetParameter(parameter); 508 parameter = new G4UIparameter("booleans-flag 422 parameter = new G4UIparameter("booleans-flag", 'b', omitable = true); 509 parameter->SetDefaultValue(true); 423 parameter->SetDefaultValue(true); 510 fpCommand->SetParameter(parameter); 424 fpCommand->SetParameter(parameter); 511 parameter = new G4UIparameter("voxels-flag", 425 parameter = new G4UIparameter("voxels-flag", 'b', omitable = true); 512 parameter->SetDefaultValue(true); 426 parameter->SetDefaultValue(true); 513 fpCommand->SetParameter(parameter); 427 fpCommand->SetParameter(parameter); 514 parameter = new G4UIparameter("readout-flag" 428 parameter = new G4UIparameter("readout-flag", 'b', omitable = true); 515 parameter->SetDefaultValue(true); 429 parameter->SetDefaultValue(true); 516 fpCommand->SetParameter(parameter); 430 fpCommand->SetParameter(parameter); 517 parameter = new G4UIparameter("axes-flag", ' 431 parameter = new G4UIparameter("axes-flag", 'b', omitable = true); 518 parameter->SetDefaultValue(true); 432 parameter->SetDefaultValue(true); 519 parameter -> SetGuidance ("Set \"false\" to 433 parameter -> SetGuidance ("Set \"false\" to suppress axes."); 520 fpCommand->SetParameter(parameter); 434 fpCommand->SetParameter(parameter); 521 parameter = new G4UIparameter("check-overlap 435 parameter = new G4UIparameter("check-overlap-flag", 'b', omitable = true); 522 parameter->SetDefaultValue(true); 436 parameter->SetDefaultValue(true); 523 parameter -> SetGuidance ("Set \"false\" to 437 parameter -> SetGuidance ("Set \"false\" to suppress overlap check."); 524 fpCommand->SetParameter(parameter); 438 fpCommand->SetParameter(parameter); 525 } 439 } 526 440 527 G4VisCommandSpecify::~G4VisCommandSpecify() { 441 G4VisCommandSpecify::~G4VisCommandSpecify() { 528 delete fpCommand; 442 delete fpCommand; 529 } 443 } 530 444 531 void G4VisCommandSpecify::SetNewValue(G4UIcomm 445 void G4VisCommandSpecify::SetNewValue(G4UIcommand*, G4String newValue) { 532 G4VisManager::Verbosity verbosity = fpVisMan 446 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); 533 G4UImanager* UImanager = G4UImanager::GetUIp 447 G4UImanager* UImanager = G4UImanager::GetUIpointer(); >> 448 G4int keepVerbose = UImanager->GetVerboseLevel(); >> 449 G4int newVerbose(0); >> 450 if (keepVerbose >= 2 || verbosity >= G4VisManager::confirmations) >> 451 newVerbose = 2; >> 452 UImanager->SetVerboseLevel(newVerbose); 534 // UImanager->ApplyCommand(G4String("/geomet 453 // UImanager->ApplyCommand(G4String("/geometry/print " + newValue)); 535 UImanager->ApplyCommand("/vis/scene/create") 454 UImanager->ApplyCommand("/vis/scene/create"); 536 UImanager->ApplyCommand(G4String("/vis/scene 455 UImanager->ApplyCommand(G4String("/vis/scene/add/logicalVolume " + newValue)); 537 UImanager->ApplyCommand("/vis/sceneHandler/a 456 UImanager->ApplyCommand("/vis/sceneHandler/attach"); >> 457 UImanager->SetVerboseLevel(keepVerbose); 538 static G4bool warned = false; 458 static G4bool warned = false; 539 if (verbosity >= G4VisManager::confirmations 459 if (verbosity >= G4VisManager::confirmations && !warned) { 540 G4cout << 460 G4cout << 541 "NOTE: For systems which are not \"auto- 461 "NOTE: For systems which are not \"auto-refresh\" you will need to" 542 "\n issue \"/vis/viewer/refresh\" or \" 462 "\n issue \"/vis/viewer/refresh\" or \"/vis/viewer/flush\"." 543 << G4endl; 463 << G4endl; 544 warned = true; 464 warned = true; 545 } 465 } 546 } 466 } 547 467