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 // $Id: G4VisCommands.cc,v 1.24 2009-03-09 12:42:00 allison Exp $ 27 28 28 // /vis/set - John Allison 21st March 2012 29 // /vis/set - John Allison 21st March 2012 29 // Set quantities for use in appropriate futur 30 // Set quantities for use in appropriate future commands. 30 31 31 #include "G4VisCommandsSet.hh" 32 #include "G4VisCommandsSet.hh" 32 33 33 #include "G4UIcommand.hh" 34 #include "G4UIcommand.hh" 34 #include "G4UIcmdWithAnInteger.hh" << 35 #include "G4UIcmdWithADouble.hh" 35 #include "G4UIcmdWithADouble.hh" 36 #include "G4UIcmdWithAString.hh" 36 #include "G4UIcmdWithAString.hh" 37 #include "G4UIcmdWithABool.hh" << 37 #include <cctype> 38 #include "G4TouchablePropertiesScene.hh" << 39 #include "G4TransportationManager.hh" << 40 #include "G4BoundingExtentScene.hh" << 41 << 42 #include <sstream> 38 #include <sstream> 43 #include <utility> << 44 << 45 #define G4warn G4cout << 46 << 47 ////////////// /vis/set/arrow3DLineSegmentsPer << 48 << 49 G4VisCommandSetArrow3DLineSegmentsPerCircle::G << 50 { << 51 G4bool omitable; << 52 fpCommand = new G4UIcmdWithAnInteger("/vis/s << 53 fpCommand->SetGuidance << 54 ("Defines number of line segments per circle << 55 " for future \"/vis/scene/add/\" commands." << 56 fpCommand->SetParameterName ("number", omita << 57 fpCommand->SetDefaultValue (6); << 58 fpCommand->SetRange("number >= 3"); << 59 } << 60 << 61 G4VisCommandSetArrow3DLineSegmentsPerCircle::~ << 62 { << 63 delete fpCommand; << 64 } << 65 << 66 G4String G4VisCommandSetArrow3DLineSegmentsPer << 67 { << 68 return G4String(); << 69 } << 70 << 71 void G4VisCommandSetArrow3DLineSegmentsPerCirc << 72 { << 73 G4VisManager::Verbosity verbosity = fpVisMan << 74 << 75 fCurrentArrow3DLineSegmentsPerCircle = fpCom << 76 << 77 if (verbosity >= G4VisManager::confirmations << 78 G4cout << << 79 "Number of line segments per circle for dr << 80 "\n \"/vis/scene/add/\" commands has been << 81 << fCurrentArrow3DLineSegmentsPerCircle << 82 << G4endl; << 83 } << 84 } << 85 39 86 ////////////// /vis/set/colour /////////////// 40 ////////////// /vis/set/colour //////////////////////////////////// 87 41 88 G4VisCommandSetColour::G4VisCommandSetColour ( 42 G4VisCommandSetColour::G4VisCommandSetColour () 89 { 43 { 90 G4bool omitable; 44 G4bool omitable; 91 fpCommand = new G4UIcommand("/vis/set/colour 45 fpCommand = new G4UIcommand("/vis/set/colour", this); 92 fpCommand->SetGuidance 46 fpCommand->SetGuidance 93 ("Defines colour and opacity for future \"/v << 47 ("Defines colour and opacity for future \"/vis/scene/add/\" commands."); 94 fpCommand->SetGuidance 48 fpCommand->SetGuidance 95 ("(Except \"/vis/scene/add/text\" commands - << 49 ("(Except \"/vis/scene/add/text\" commands - see \"/vis/set/textColour\".)"); 96 fpCommand->SetGuidance(ConvertToColourGuidan << 97 fpCommand->SetGuidance("Default: white and o 50 fpCommand->SetGuidance("Default: white and opaque."); 98 G4UIparameter* parameter; 51 G4UIparameter* parameter; 99 parameter = new G4UIparameter ("red", 's', o 52 parameter = new G4UIparameter ("red", 's', omitable = true); 100 parameter->SetGuidance 53 parameter->SetGuidance 101 ("Red component or a string, e.g., \"cyan\" << 54 ("Red component or a string, e.g., \"cyan\" (green and blue parameters are ignored)."); 102 parameter->SetDefaultValue ("1."); 55 parameter->SetDefaultValue ("1."); 103 fpCommand->SetParameter (parameter); 56 fpCommand->SetParameter (parameter); 104 parameter = new G4UIparameter ("green", 'd', 57 parameter = new G4UIparameter ("green", 'd', omitable = true); 105 parameter->SetDefaultValue (1.); 58 parameter->SetDefaultValue (1.); 106 fpCommand->SetParameter (parameter); 59 fpCommand->SetParameter (parameter); 107 parameter = new G4UIparameter ("blue", 'd', 60 parameter = new G4UIparameter ("blue", 'd', omitable = true); 108 parameter->SetDefaultValue (1.); 61 parameter->SetDefaultValue (1.); 109 fpCommand->SetParameter (parameter); 62 fpCommand->SetParameter (parameter); 110 parameter = new G4UIparameter ("alpha", 'd', 63 parameter = new G4UIparameter ("alpha", 'd', omitable = true); 111 parameter->SetDefaultValue (1.); 64 parameter->SetDefaultValue (1.); 112 parameter->SetGuidance ("Opacity"); 65 parameter->SetGuidance ("Opacity"); 113 fpCommand->SetParameter (parameter); 66 fpCommand->SetParameter (parameter); 114 } 67 } 115 68 116 G4VisCommandSetColour::~G4VisCommandSetColour 69 G4VisCommandSetColour::~G4VisCommandSetColour () 117 { 70 { 118 delete fpCommand; 71 delete fpCommand; 119 } 72 } 120 73 121 G4String G4VisCommandSetColour::GetCurrentValu 74 G4String G4VisCommandSetColour::GetCurrentValue (G4UIcommand*) 122 { 75 { 123 return G4String(); 76 return G4String(); 124 } 77 } 125 78 126 void G4VisCommandSetColour::SetNewValue (G4UIc 79 void G4VisCommandSetColour::SetNewValue (G4UIcommand*, G4String newValue) 127 { 80 { 128 G4VisManager::Verbosity verbosity = fpVisMan 81 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); 129 82 130 G4String redOrString; 83 G4String redOrString; 131 G4double green, blue, opacity; 84 G4double green, blue, opacity; 132 std::istringstream iss(newValue); 85 std::istringstream iss(newValue); 133 iss >> redOrString >> green >> blue >> opaci 86 iss >> redOrString >> green >> blue >> opacity; 134 87 135 ConvertToColour(fCurrentColour, redOrString, << 88 G4Colour colour(1,1,1,1); // Default white and opaque. 136 << 89 if (std::isalpha(redOrString(0))) { 137 if (verbosity >= G4VisManager::confirmations << 90 if (!G4Colour::GetColour(redOrString, colour)) { 138 G4cout << << 91 if (verbosity >= G4VisManager::warnings) { 139 "Colour for future \"/vis/scene/add/\" com << 92 G4cout << "WARNING: Colour \"" << redOrString 140 << fCurrentColour << << 93 << "\" not found. Defaulting to white and opaque." 141 ".\n(Except \"/vis/scene/add/text\" comman << 94 << G4endl; 142 << G4endl; << 95 } >> 96 } >> 97 } else { >> 98 colour = G4Colour >> 99 (G4UIcommand::ConvertToDouble(redOrString), green, blue); 143 } 100 } 144 } << 101 // Add opacity 145 << 102 fCurrentColour = G4Colour 146 ////////////// /vis/set/extentForField /////// << 103 (colour.GetRed(), colour.GetGreen(), colour.GetBlue(), opacity); 147 << 148 G4VisCommandSetExtentForField::G4VisCommandSet << 149 { << 150 G4bool omitable; << 151 fpCommand = new G4UIcommand("/vis/set/extent << 152 fpCommand->SetGuidance << 153 ("Sets an extent for future \"/vis/scene/add << 154 fpCommand->SetGuidance << 155 ("The default is a null extent, which is int << 156 "\nextent of the whole scene."); << 157 G4UIparameter* parameter; << 158 parameter = new G4UIparameter ("xmin", 'd', << 159 fpCommand->SetParameter (parameter); << 160 parameter = new G4UIparameter ("xmax", 'd', << 161 fpCommand->SetParameter (parameter); << 162 parameter = new G4UIparameter ("ymin", 'd', << 163 fpCommand->SetParameter (parameter); << 164 parameter = new G4UIparameter ("ymax", 'd', << 165 fpCommand->SetParameter (parameter); << 166 parameter = new G4UIparameter ("zmin", 'd', << 167 fpCommand->SetParameter (parameter); << 168 parameter = new G4UIparameter ("zmax", 'd', << 169 fpCommand->SetParameter (parameter); << 170 parameter = new G4UIparameter ("unit", 's', << 171 fpCommand->SetParameter (parameter); << 172 } << 173 << 174 G4VisCommandSetExtentForField::~G4VisCommandSe << 175 { << 176 delete fpCommand; << 177 } << 178 << 179 G4String G4VisCommandSetExtentForField::GetCur << 180 { << 181 return G4String(); << 182 } << 183 << 184 void G4VisCommandSetExtentForField::SetNewValu << 185 { << 186 G4VisManager::Verbosity verbosity = fpVisMan << 187 << 188 G4double xmin, xmax, ymin, ymax, zmin, zmax; << 189 G4String unitString; << 190 std::istringstream iss(newValue); << 191 iss >> xmin >> xmax >> ymin >> ymax >> zmin << 192 G4double unit = G4UIcommand::ValueOf(unitStr << 193 xmin *= unit; xmax *= unit; << 194 ymin *= unit; ymax *= unit; << 195 zmin *= unit; zmax *= unit; << 196 << 197 fCurrentExtentForField = G4VisExtent(xmin,xm << 198 fCurrrentPVFindingsForField.clear(); << 199 104 200 if (verbosity >= G4VisManager::confirmations 105 if (verbosity >= G4VisManager::confirmations) { 201 G4cout << 106 G4cout << 202 "Extent for future \"/vis/scene/add/*Field << 107 "Colour for future \"/vis/scene/add/\" commands has been set to " 203 << fCurrentExtentForField << 108 << fCurrentColour << 204 << "\nVolume for field has been cleared." << 109 ".\n(Except \"/vis/scene/add/text\" commands - use \"/vis/set/textColour\".)" 205 << G4endl; << 110 << G4endl; 206 } 111 } 207 } 112 } 208 113 209 ////////////// /vis/set/lineWidth //////////// 114 ////////////// /vis/set/lineWidth //////////////////////////////////// 210 115 211 G4VisCommandSetLineWidth::G4VisCommandSetLineW 116 G4VisCommandSetLineWidth::G4VisCommandSetLineWidth () 212 { 117 { 213 G4bool omitable; 118 G4bool omitable; 214 fpCommand = new G4UIcmdWithADouble("/vis/set 119 fpCommand = new G4UIcmdWithADouble("/vis/set/lineWidth", this); 215 fpCommand->SetGuidance 120 fpCommand->SetGuidance 216 ("Defines line width for future \"/vis/scene << 121 ("Defines lineWidth for future \"/vis/scene/add/\" commands."); 217 "\nSee \"/vis/viewer/set/lineWidth\" for mo << 218 fpCommand->SetParameterName ("lineWidth", om 122 fpCommand->SetParameterName ("lineWidth", omitable = true); 219 fpCommand->SetDefaultValue (1.); 123 fpCommand->SetDefaultValue (1.); 220 fpCommand->SetRange("lineWidth >= 1."); 124 fpCommand->SetRange("lineWidth >= 1."); 221 } 125 } 222 126 223 G4VisCommandSetLineWidth::~G4VisCommandSetLine 127 G4VisCommandSetLineWidth::~G4VisCommandSetLineWidth () 224 { 128 { 225 delete fpCommand; 129 delete fpCommand; 226 } 130 } 227 131 228 G4String G4VisCommandSetLineWidth::GetCurrentV 132 G4String G4VisCommandSetLineWidth::GetCurrentValue (G4UIcommand*) 229 { 133 { 230 return G4String(); 134 return G4String(); 231 } 135 } 232 136 233 void G4VisCommandSetLineWidth::SetNewValue (G4 137 void G4VisCommandSetLineWidth::SetNewValue (G4UIcommand*, G4String newValue) 234 { 138 { 235 G4VisManager::Verbosity verbosity = fpVisMan 139 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); 236 140 237 fCurrentLineWidth = fpCommand->GetNewDoubleV 141 fCurrentLineWidth = fpCommand->GetNewDoubleValue(newValue); 238 142 239 if (verbosity >= G4VisManager::warnings) { << 143 if (verbosity >= G4VisManager::confirmations) { 240 G4warn << << 144 G4cout << 241 "Line width for *future* \"/vis/scene/add/ << 145 "Line width for future \"/vis/scene/add/\" commands has been set to " 242 << fCurrentLineWidth << << 146 << fCurrentLineWidth 243 "\nSee \"/vis/viewer/set/lineWidth\" for m << 147 << G4endl; 244 << G4endl; << 245 } 148 } 246 } 149 } 247 150 248 ////////////// /vis/set/textColour /////////// 151 ////////////// /vis/set/textColour //////////////////////////////////// 249 152 250 G4VisCommandSetTextColour::G4VisCommandSetText 153 G4VisCommandSetTextColour::G4VisCommandSetTextColour () 251 { 154 { 252 G4bool omitable; 155 G4bool omitable; 253 fpCommand = new G4UIcommand("/vis/set/textCo 156 fpCommand = new G4UIcommand("/vis/set/textColour", this); 254 fpCommand->SetGuidance 157 fpCommand->SetGuidance 255 ("Defines colour and opacity for future \" 158 ("Defines colour and opacity for future \"/vis/scene/add/text\" commands."); 256 fpCommand->SetGuidance(ConvertToColourGuidan << 257 fpCommand->SetGuidance("Default: blue and op 159 fpCommand->SetGuidance("Default: blue and opaque."); 258 G4UIparameter* parameter; 160 G4UIparameter* parameter; 259 parameter = new G4UIparameter ("red", 's', o 161 parameter = new G4UIparameter ("red", 's', omitable = true); 260 parameter->SetGuidance 162 parameter->SetGuidance 261 ("Red component or a string, e.g., \"cyan\ 163 ("Red component or a string, e.g., \"cyan\" (green and blue parameters are ignored)."); 262 parameter->SetDefaultValue ("0."); 164 parameter->SetDefaultValue ("0."); 263 fpCommand->SetParameter (parameter); 165 fpCommand->SetParameter (parameter); 264 parameter = new G4UIparameter ("green", 'd', 166 parameter = new G4UIparameter ("green", 'd', omitable = true); 265 parameter->SetDefaultValue (0.); 167 parameter->SetDefaultValue (0.); 266 fpCommand->SetParameter (parameter); 168 fpCommand->SetParameter (parameter); 267 parameter = new G4UIparameter ("blue", 'd', 169 parameter = new G4UIparameter ("blue", 'd', omitable = true); 268 parameter->SetDefaultValue (1.); 170 parameter->SetDefaultValue (1.); 269 fpCommand->SetParameter (parameter); 171 fpCommand->SetParameter (parameter); 270 parameter = new G4UIparameter ("alpha", 'd', 172 parameter = new G4UIparameter ("alpha", 'd', omitable = true); 271 parameter->SetDefaultValue (1.); 173 parameter->SetDefaultValue (1.); 272 parameter->SetGuidance ("Opacity"); 174 parameter->SetGuidance ("Opacity"); 273 fpCommand->SetParameter (parameter); 175 fpCommand->SetParameter (parameter); 274 } 176 } 275 177 276 G4VisCommandSetTextColour::~G4VisCommandSetTex 178 G4VisCommandSetTextColour::~G4VisCommandSetTextColour () 277 { 179 { 278 delete fpCommand; 180 delete fpCommand; 279 } 181 } 280 182 281 G4String G4VisCommandSetTextColour::GetCurrent 183 G4String G4VisCommandSetTextColour::GetCurrentValue (G4UIcommand*) 282 { 184 { 283 return G4String(); 185 return G4String(); 284 } 186 } 285 187 286 void G4VisCommandSetTextColour::SetNewValue (G 188 void G4VisCommandSetTextColour::SetNewValue (G4UIcommand*, G4String newValue) 287 { 189 { 288 G4VisManager::Verbosity verbosity = fpVisMan 190 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); 289 191 290 G4String redOrString; 192 G4String redOrString; 291 G4double green, blue, opacity; 193 G4double green, blue, opacity; 292 std::istringstream iss(newValue); 194 std::istringstream iss(newValue); 293 iss >> redOrString >> green >> blue >> opaci 195 iss >> redOrString >> green >> blue >> opacity; 294 196 295 ConvertToColour(fCurrentTextColour, redOrStr << 197 G4Colour colour(0,0,1,1); // Default blue and opaque. >> 198 if (std::isalpha(redOrString(0))) { >> 199 if (!G4Colour::GetColour(redOrString, colour)) { >> 200 if (verbosity >= G4VisManager::warnings) { >> 201 G4cout << "WARNING: Text colour \"" << redOrString >> 202 << "\" not found. Defaulting to blue and opaque." >> 203 << G4endl; >> 204 } >> 205 } >> 206 } else { >> 207 colour = G4Colour >> 208 (G4UIcommand::ConvertToDouble(redOrString), green, blue); >> 209 } >> 210 // Add opacity >> 211 fCurrentTextColour = G4Colour >> 212 (colour.GetRed(), colour.GetGreen(), colour.GetBlue(), opacity); 296 213 297 if (verbosity >= G4VisManager::confirmations 214 if (verbosity >= G4VisManager::confirmations) { 298 G4cout << 215 G4cout << 299 "Colour for future \"/vis/scene/add/text 216 "Colour for future \"/vis/scene/add/text\" commands has been set to " 300 << fCurrentTextColour << '.' 217 << fCurrentTextColour << '.' 301 << G4endl; 218 << G4endl; 302 } 219 } 303 } 220 } 304 221 305 ////////////// /vis/set/textLayout /////////// 222 ////////////// /vis/set/textLayout //////////////////////////////////// 306 223 307 G4VisCommandSetTextLayout::G4VisCommandSetText 224 G4VisCommandSetTextLayout::G4VisCommandSetTextLayout () 308 { 225 { 309 G4bool omitable; 226 G4bool omitable; 310 fpCommand = new G4UIcmdWithAString("/vis/set 227 fpCommand = new G4UIcmdWithAString("/vis/set/textLayout", this); 311 fpCommand->SetGuidance 228 fpCommand->SetGuidance 312 ("Defines layout future \"/vis/scene/add/t 229 ("Defines layout future \"/vis/scene/add/text\" commands."); 313 fpCommand->SetGuidance 230 fpCommand->SetGuidance 314 ("\"left\" (default) for left justificatio 231 ("\"left\" (default) for left justification to provided coordinate."); 315 fpCommand->SetGuidance 232 fpCommand->SetGuidance 316 ("\"centre\" or \"center\" for text center 233 ("\"centre\" or \"center\" for text centered on provided coordinate."); 317 fpCommand->SetGuidance 234 fpCommand->SetGuidance 318 ("\"right\" for right justification to pro 235 ("\"right\" for right justification to provided coordinate."); 319 fpCommand->SetGuidance("Default: left."); 236 fpCommand->SetGuidance("Default: left."); 320 fpCommand->SetParameterName("layout", omitab 237 fpCommand->SetParameterName("layout", omitable = true); 321 fpCommand->SetCandidates ("left centre cente 238 fpCommand->SetCandidates ("left centre center right"); 322 fpCommand->SetDefaultValue ("left"); 239 fpCommand->SetDefaultValue ("left"); 323 } 240 } 324 241 325 G4VisCommandSetTextLayout::~G4VisCommandSetTex 242 G4VisCommandSetTextLayout::~G4VisCommandSetTextLayout () 326 { 243 { 327 delete fpCommand; 244 delete fpCommand; 328 } 245 } 329 246 330 G4String G4VisCommandSetTextLayout::GetCurrent 247 G4String G4VisCommandSetTextLayout::GetCurrentValue (G4UIcommand*) 331 { 248 { 332 return G4String(); 249 return G4String(); 333 } 250 } 334 251 335 void G4VisCommandSetTextLayout::SetNewValue (G 252 void G4VisCommandSetTextLayout::SetNewValue (G4UIcommand*, G4String newValue) 336 { 253 { 337 G4Text::Layout layout = G4Text::left; 254 G4Text::Layout layout = G4Text::left; 338 if (newValue == "left") layout = G4Text::lef 255 if (newValue == "left") layout = G4Text::left; 339 else if (newValue == "centre" || newValue == 256 else if (newValue == "centre" || newValue == "center") 340 layout = G4Text::centre; 257 layout = G4Text::centre; 341 else if (newValue == "right") layout = G4Tex 258 else if (newValue == "right") layout = G4Text::right; 342 259 343 fCurrentTextLayout = layout; 260 fCurrentTextLayout = layout; 344 261 345 G4VisManager::Verbosity verbosity = fpVisMan 262 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); 346 if (verbosity >= G4VisManager::confirmations 263 if (verbosity >= G4VisManager::confirmations) { 347 G4cout << "Text layout (for future \"text\ 264 G4cout << "Text layout (for future \"text\" commands) has been set to \"" 348 << fCurrentTextLayout << "\"." 265 << fCurrentTextLayout << "\"." 349 << G4endl; 266 << G4endl; 350 } 267 } 351 } 268 } 352 269 353 ////////////// /vis/set/textSize ///////////// << 354 << 355 G4VisCommandSetTextSize::G4VisCommandSetTextSi << 356 { << 357 G4bool omitable; << 358 fpCommand = new G4UIcmdWithADouble("/vis/set << 359 fpCommand->SetGuidance << 360 ("Defines text size (pixels) for future \"/v << 361 fpCommand->SetParameterName ("textSize", omi << 362 fpCommand->SetDefaultValue (12.); // pixels << 363 fpCommand->SetRange("textSize >= 8."); << 364 } << 365 << 366 G4VisCommandSetTextSize::~G4VisCommandSetTextS << 367 { << 368 delete fpCommand; << 369 } << 370 << 371 G4String G4VisCommandSetTextSize::GetCurrentVa << 372 { << 373 return G4String(); << 374 } << 375 << 376 void G4VisCommandSetTextSize::SetNewValue (G4U << 377 { << 378 G4VisManager::Verbosity verbosity = fpVisMan << 379 << 380 fCurrentTextSize = fpCommand->GetNewDoubleVa << 381 << 382 if (verbosity >= G4VisManager::confirmations << 383 G4cout << << 384 "Text size for future \"/vis/scene/add/\" << 385 << fCurrentTextSize << 386 << G4endl; << 387 } << 388 } << 389 << 390 ////////////// /vis/set/touchable //////////// 270 ////////////// /vis/set/touchable //////////////////////////////////// 391 271 392 G4VisCommandSetTouchable::G4VisCommandSetTouch 272 G4VisCommandSetTouchable::G4VisCommandSetTouchable () 393 { 273 { 394 G4bool omitable; 274 G4bool omitable; 395 G4UIparameter* parameter; 275 G4UIparameter* parameter; 396 fpCommand = new G4UIcommand("/vis/set/toucha 276 fpCommand = new G4UIcommand("/vis/set/touchable", this); 397 fpCommand->SetGuidance 277 fpCommand->SetGuidance 398 ("Defines touchable for future \"/vis/toucha 278 ("Defines touchable for future \"/vis/touchable/set/\" commands."); 399 fpCommand->SetGuidance 279 fpCommand->SetGuidance 400 ("Please provide a list of space-separated p 280 ("Please provide a list of space-separated physical volume names and" 401 "\ncopy number pairs starting at the world 281 "\ncopy number pairs starting at the world volume, e.g:" 402 "\n /vis/set/touchable World 0 Envelope 0 282 "\n /vis/set/touchable World 0 Envelope 0 Shape1 0" 403 "\n(To get list of touchables, use \"/vis/d 283 "\n(To get list of touchables, use \"/vis/drawTree\")" 404 "\n(To save, use \"/vis/viewer/save\")"); 284 "\n(To save, use \"/vis/viewer/save\")"); 405 parameter = new G4UIparameter ("list", 's', << 285 parameter = new G4UIparameter ("list", 's', omitable = false); 406 parameter->SetGuidance 286 parameter->SetGuidance 407 ("List of physical volume names and copy num 287 ("List of physical volume names and copy number pairs"); 408 fpCommand->SetParameter (parameter); 288 fpCommand->SetParameter (parameter); 409 } 289 } 410 290 411 G4VisCommandSetTouchable::~G4VisCommandSetTouc 291 G4VisCommandSetTouchable::~G4VisCommandSetTouchable () 412 { 292 { 413 delete fpCommand; 293 delete fpCommand; 414 } 294 } 415 295 416 G4String G4VisCommandSetTouchable::GetCurrentV 296 G4String G4VisCommandSetTouchable::GetCurrentValue (G4UIcommand*) 417 { 297 { 418 return G4String(); 298 return G4String(); 419 } 299 } 420 300 421 void G4VisCommandSetTouchable::SetNewValue (G4 301 void G4VisCommandSetTouchable::SetNewValue (G4UIcommand*, G4String newValue) 422 { 302 { 423 G4VisManager::Verbosity verbosity = fpVisMan 303 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); 424 << 425 if (newValue.empty()) { << 426 fCurrentTouchableProperties = G4PhysicalVo << 427 if (verbosity >= G4VisManager::confirmatio << 428 G4cout << << 429 "Current touchable reset to: " << fCurre << 430 << G4endl; << 431 } << 432 return; << 433 } << 434 304 435 G4ModelingParameters::PVNameCopyNoPath curre 305 G4ModelingParameters::PVNameCopyNoPath currentTouchablePath; 436 << 306 437 // Algorithm from Josuttis p.476. 307 // Algorithm from Josuttis p.476. 438 G4String::size_type iBegin, iEnd; 308 G4String::size_type iBegin, iEnd; 439 iBegin = newValue.find_first_not_of(' '); 309 iBegin = newValue.find_first_not_of(' '); 440 while (iBegin != G4String::npos) { 310 while (iBegin != G4String::npos) { 441 iEnd = newValue.find_first_of(' ',iBegin); 311 iEnd = newValue.find_first_of(' ',iBegin); 442 if (iEnd == G4String::npos) { 312 if (iEnd == G4String::npos) { 443 iEnd = newValue.length(); 313 iEnd = newValue.length(); 444 } 314 } 445 const G4String& name(newValue.substr(iBegi << 315 G4String name(newValue.substr(iBegin,iEnd-iBegin)); 446 iBegin = newValue.find_first_not_of(' ',iE 316 iBegin = newValue.find_first_not_of(' ',iEnd); 447 if (iBegin == G4String::npos) { 317 if (iBegin == G4String::npos) { 448 if (verbosity >= G4VisManager::warnings) 318 if (verbosity >= G4VisManager::warnings) { 449 G4warn << << 319 G4cout << 450 "WARNING: G4VisCommandSetTouchable::Se 320 "WARNING: G4VisCommandSetTouchable::SetNewValue" 451 "\n A pair not found. (There should be an << 321 "\n A pair not found. (Did you have an even number of parameters?)" 452 "\n Command ignored." 322 "\n Command ignored." 453 << G4endl; 323 << G4endl; 454 return; 324 return; 455 } 325 } 456 } 326 } 457 iEnd = newValue.find_first_of(' ',iBegin); 327 iEnd = newValue.find_first_of(' ',iBegin); 458 if (iEnd == G4String::npos) { 328 if (iEnd == G4String::npos) { 459 iEnd = newValue.length(); 329 iEnd = newValue.length(); 460 } 330 } 461 G4int copyNo; 331 G4int copyNo; 462 std::istringstream iss(newValue.substr(iBe 332 std::istringstream iss(newValue.substr(iBegin,iEnd-iBegin)); 463 if (!(iss >> copyNo)) { 333 if (!(iss >> copyNo)) { 464 if (verbosity >= G4VisManager::warnings) 334 if (verbosity >= G4VisManager::warnings) { 465 G4warn << << 335 G4cout << 466 "WARNING: G4VisCommandSetTouchable::Se 336 "WARNING: G4VisCommandSetTouchable::SetNewValue" 467 "\n Error reading copy number - it wa 337 "\n Error reading copy number - it was not numeric?" 468 "\n Command ignored." 338 "\n Command ignored." 469 << G4endl; 339 << G4endl; 470 return; 340 return; 471 } 341 } 472 } 342 } 473 currentTouchablePath.push_back 343 currentTouchablePath.push_back 474 (G4ModelingParameters::PVNameCopyNo(name,c 344 (G4ModelingParameters::PVNameCopyNo(name,copyNo)); 475 iBegin = newValue.find_first_not_of(' ',iE 345 iBegin = newValue.find_first_not_of(' ',iEnd); 476 } 346 } 477 << 347 478 // Check validity << 348 fCurrentTouchablePath = currentTouchablePath; 479 G4bool successful = false; << 349 480 G4TransportationManager* transportationManag << 481 G4TransportationManager::GetTransportationMa << 482 size_t nWorlds = transportationManager->GetN << 483 std::vector<G4VPhysicalVolume*>::iterator it << 484 transportationManager->GetWorldsIterator(); << 485 for (size_t i = 0; i < nWorlds; ++i, ++iterW << 486 G4PhysicalVolumeModel pvModel (*iterWorld) << 487 G4ModelingParameters mp; // Default - no << 488 pvModel.SetModelingParameters (&mp); << 489 G4TouchablePropertiesScene scene (&pvModel << 490 pvModel.DescribeYourselfTo (scene); // In << 491 if (scene.GetFoundTouchableProperties().fp << 492 successful = true; << 493 fCurrentTouchableProperties = scene.GetF << 494 break; // Found, so no need to scan mor << 495 } << 496 } << 497 << 498 if (successful) { << 499 if (verbosity >= G4VisManager::confirmatio << 500 G4cout << << 501 "Current touchable: " << fCurrentTouchab << 502 << G4endl; << 503 return; << 504 } << 505 } else { << 506 if (verbosity >= G4VisManager::warnings) { << 507 G4warn << << 508 "WARNING: G4VisCommandSetTouchable::SetN << 509 "\n Touchable not found." << 510 << G4endl; << 511 return; << 512 } << 513 } << 514 } << 515 << 516 ////////////// /vis/set/volumeForField /////// << 517 << 518 G4VisCommandSetVolumeForField::G4VisCommandSet << 519 { << 520 G4bool omitable; << 521 G4UIparameter* parameter; << 522 fpCommand = new G4UIcommand("/vis/set/volume << 523 fpCommand->SetGuidance << 524 ("Sets a volume for \"/vis/scene/add/*Field\ << 525 fpCommand->SetGuidance << 526 ("Takes a volume name or a /regular expressi << 527 "\n\"/vis/drawVolume\""); << 528 parameter = new G4UIparameter ("physical-vol << 529 fpCommand -> SetParameter (parameter); << 530 parameter = new G4UIparameter ("copy-no", 'i << 531 parameter -> SetGuidance ("If negative, matc << 532 parameter -> SetDefaultValue (-1); << 533 fpCommand -> SetParameter (parameter); << 534 parameter = new G4UIparameter ("draw", 'b', << 535 parameter -> SetGuidance ("If true, draw ext << 536 parameter -> SetDefaultValue (false); << 537 fpCommand -> SetParameter (parameter); << 538 } << 539 << 540 G4VisCommandSetVolumeForField::~G4VisCommandSe << 541 { << 542 delete fpCommand; << 543 } << 544 << 545 G4String G4VisCommandSetVolumeForField::GetCur << 546 { << 547 return G4String(); << 548 } << 549 << 550 void G4VisCommandSetVolumeForField::SetNewValu << 551 { << 552 G4VisManager::Verbosity verbosity = fpVisMan << 553 << 554 G4String name, drawString; << 555 G4int copyNo; << 556 std::istringstream is (newValue); << 557 is >> name >> copyNo >> drawString; << 558 G4bool draw = G4UIcmdWithABool::ConvertToBoo << 559 << 560 G4TransportationManager* transportationManag << 561 G4TransportationManager::GetTransportationMa << 562 size_t nWorlds = transportationManager->GetN << 563 std::vector<G4VPhysicalVolume*>::iterator it << 564 transportationManager->GetWorldsIterator(); << 565 fCurrrentPVFindingsForField.clear(); << 566 G4BoundingExtentScene extentScene; << 567 for (size_t i = 0; i < nWorlds; ++i, ++iterW << 568 G4PhysicalVolumeModel searchModel (*iterWo << 569 G4ModelingParameters mp; // Default - no << 570 searchModel.SetModelingParameters (&mp); << 571 // Find all instances at any position in t << 572 G4PhysicalVolumesSearchScene searchScene ( << 573 searchModel.DescribeYourselfTo (searchScen << 574 for (const auto& findings: searchScene.Get << 575 fCurrrentPVFindingsForField.push_back(fi << 576 G4VisExtent extent = findings.fpFoundPV- << 577 extent.Transform(findings.fFoundObjectTr << 578 extentScene.AccrueBoundingExtent(extent) << 579 } << 580 } << 581 << 582 if (fCurrrentPVFindingsForField.empty()) { << 583 if (verbosity >= G4VisManager::errors) { << 584 G4warn << "ERROR: Volume \"" << name << << 585 if (copyNo >= 0) { << 586 G4warn << ", copy no. " << copyNo << " << 587 } << 588 G4warn << " not found." << G4endl; << 589 } << 590 return; << 591 } << 592 << 593 fCurrentExtentForField = extentScene.GetExte << 594 << 595 if (draw) DrawExtent(fCurrentExtentForField) << 596 << 597 if (verbosity >= G4VisManager::confirmations 350 if (verbosity >= G4VisManager::confirmations) { 598 for (const auto& findings: fCurrrentPVFind << 351 G4cout << fCurrentTouchablePath 599 G4cout << 352 << G4endl; 600 << "\"" << findings.fpFoundPV->GetName() << 601 << "\", copy no. " << findings.fFoundPVC << 602 << ", found\nin searched volume \"" << 603 << findings.fpSearchPV->GetName() << 604 << "\" at depth " << findings.fFoundDept << 605 << ",\nbase path: \"" << findings.fFound << 606 << "\",\nand has been set as volume for << 607 << G4endl; << 608 } << 609 } 353 } 610 } 354 } >> 355 611 356