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: G4VisCommandsViewer.cc 104163 2017-05-15 06:52:42Z gcosmo $ 27 28 28 // /vis/viewer commands - John Allison 25th O 29 // /vis/viewer commands - John Allison 25th October 1998 29 30 30 #include "G4VisCommandsViewer.hh" 31 #include "G4VisCommandsViewer.hh" 31 32 32 #include "G4VisManager.hh" 33 #include "G4VisManager.hh" 33 #include "G4GraphicsSystemList.hh" 34 #include "G4GraphicsSystemList.hh" 34 #include "G4VisCommandsScene.hh" 35 #include "G4VisCommandsScene.hh" 35 #include "G4UImanager.hh" 36 #include "G4UImanager.hh" 36 #include "G4UIcommand.hh" 37 #include "G4UIcommand.hh" 37 #include "G4UIcmdWithoutParameter.hh" 38 #include "G4UIcmdWithoutParameter.hh" 38 #include "G4UIcmdWithAString.hh" 39 #include "G4UIcmdWithAString.hh" 39 #include "G4UIcmdWithADouble.hh" 40 #include "G4UIcmdWithADouble.hh" 40 #include "G4UIcmdWithADoubleAndUnit.hh" 41 #include "G4UIcmdWithADoubleAndUnit.hh" 41 #include "G4UIcmdWith3Vector.hh" 42 #include "G4UIcmdWith3Vector.hh" 42 #include "G4PhysicalVolumesSearchScene.hh" << 43 #include "G4TransportationManager.hh" << 44 #include "G4Point3D.hh" 43 #include "G4Point3D.hh" 45 #include "G4SystemOfUnits.hh" 44 #include "G4SystemOfUnits.hh" 46 #include "G4UnitsTable.hh" 45 #include "G4UnitsTable.hh" 47 #include "G4Filesystem.hh" << 46 #include "G4ios.hh" >> 47 #ifdef G4VIS_USE_STD11 48 #include <chrono> 48 #include <chrono> 49 #include <thread> 49 #include <thread> >> 50 #endif 50 #include <sstream> 51 #include <sstream> 51 #include <fstream> 52 #include <fstream> >> 53 #include <sstream> 52 #include <iomanip> 54 #include <iomanip> 53 #include <cstdio> << 55 #ifdef WIN32 54 #include <regex> 56 #include <regex> 55 #include <set> << 57 #include <filesystem> >> 58 #endif //WIN32 >> 59 >> 60 G4VVisCommandViewer::G4VVisCommandViewer () {} 56 61 57 #define G4warn G4cout << 62 G4VVisCommandViewer::~G4VVisCommandViewer () {} >> 63 >> 64 void G4VVisCommandViewer::SetViewParameters >> 65 (G4VViewer* viewer, const G4ViewParameters& viewParams) { >> 66 viewer->SetViewParameters(viewParams); >> 67 RefreshIfRequired(viewer); >> 68 } >> 69 >> 70 void G4VVisCommandViewer::RefreshIfRequired(G4VViewer* viewer) { >> 71 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); >> 72 G4VSceneHandler* sceneHandler = viewer->GetSceneHandler(); >> 73 const G4ViewParameters& viewParams = viewer->GetViewParameters(); >> 74 if (sceneHandler && sceneHandler->GetScene()) { >> 75 if (viewParams.IsAutoRefresh()) { >> 76 G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/refresh"); >> 77 } >> 78 else { >> 79 if (verbosity >= G4VisManager::warnings) { >> 80 G4cout << "Issue /vis/viewer/refresh or flush to see effect." >> 81 << G4endl; >> 82 } >> 83 } >> 84 } >> 85 } 58 86 59 ////////////// /vis/viewer/addCutawayPlane /// 87 ////////////// /vis/viewer/addCutawayPlane /////////////////////////////////////// 60 88 61 G4VisCommandViewerAddCutawayPlane::G4VisComman 89 G4VisCommandViewerAddCutawayPlane::G4VisCommandViewerAddCutawayPlane () { 62 G4bool omitable; 90 G4bool omitable; 63 fpCommand = new G4UIcommand ("/vis/viewer/ad 91 fpCommand = new G4UIcommand ("/vis/viewer/addCutawayPlane", this); 64 fpCommand -> SetGuidance 92 fpCommand -> SetGuidance 65 ("Add cutaway plane to current viewer."); 93 ("Add cutaway plane to current viewer."); 66 G4UIparameter* parameter; 94 G4UIparameter* parameter; 67 parameter = new G4UIparameter("x",'d',omit 95 parameter = new G4UIparameter("x",'d',omitable = true); 68 parameter -> SetDefaultValue (0); 96 parameter -> SetDefaultValue (0); 69 parameter -> SetGuidance ("Coordinate 97 parameter -> SetGuidance ("Coordinate of point on the plane."); 70 fpCommand->SetParameter(parameter); 98 fpCommand->SetParameter(parameter); 71 parameter = new G4UIparameter("y",'d',omit 99 parameter = new G4UIparameter("y",'d',omitable = true); 72 parameter -> SetDefaultValue (0); 100 parameter -> SetDefaultValue (0); 73 parameter -> SetGuidance ("Coordinate 101 parameter -> SetGuidance ("Coordinate of point on the plane."); 74 fpCommand->SetParameter(parameter); 102 fpCommand->SetParameter(parameter); 75 parameter = new G4UIparameter("z",'d',omit 103 parameter = new G4UIparameter("z",'d',omitable = true); 76 parameter -> SetDefaultValue (0); 104 parameter -> SetDefaultValue (0); 77 parameter -> SetGuidance ("Coordinate 105 parameter -> SetGuidance ("Coordinate of point on the plane."); 78 fpCommand->SetParameter(parameter); 106 fpCommand->SetParameter(parameter); 79 parameter = new G4UIparameter("unit",'s',o 107 parameter = new G4UIparameter("unit",'s',omitable = true); 80 parameter -> SetDefaultValue ("m"); 108 parameter -> SetDefaultValue ("m"); 81 parameter -> SetGuidance ("Unit of poi 109 parameter -> SetGuidance ("Unit of point on the plane."); 82 fpCommand->SetParameter(parameter); 110 fpCommand->SetParameter(parameter); 83 parameter = new G4UIparameter("nx",'d',omi 111 parameter = new G4UIparameter("nx",'d',omitable = true); 84 parameter -> SetDefaultValue (1); 112 parameter -> SetDefaultValue (1); 85 parameter -> SetGuidance ("Component o 113 parameter -> SetGuidance ("Component of plane normal."); 86 fpCommand->SetParameter(parameter); 114 fpCommand->SetParameter(parameter); 87 parameter = new G4UIparameter("ny",'d',omi 115 parameter = new G4UIparameter("ny",'d',omitable = true); 88 parameter -> SetDefaultValue (0); 116 parameter -> SetDefaultValue (0); 89 parameter -> SetGuidance ("Component o 117 parameter -> SetGuidance ("Component of plane normal."); 90 fpCommand->SetParameter(parameter); 118 fpCommand->SetParameter(parameter); 91 parameter = new G4UIparameter("nz",'d',omi 119 parameter = new G4UIparameter("nz",'d',omitable = true); 92 parameter -> SetDefaultValue (0); 120 parameter -> SetDefaultValue (0); 93 parameter -> SetGuidance ("Component o 121 parameter -> SetGuidance ("Component of plane normal."); 94 fpCommand->SetParameter(parameter); 122 fpCommand->SetParameter(parameter); 95 } 123 } 96 124 97 G4VisCommandViewerAddCutawayPlane::~G4VisComma 125 G4VisCommandViewerAddCutawayPlane::~G4VisCommandViewerAddCutawayPlane () { 98 delete fpCommand; 126 delete fpCommand; 99 } 127 } 100 128 101 G4String G4VisCommandViewerAddCutawayPlane::Ge 129 G4String G4VisCommandViewerAddCutawayPlane::GetCurrentValue (G4UIcommand*) { 102 return ""; 130 return ""; 103 } 131 } 104 132 105 void G4VisCommandViewerAddCutawayPlane::SetNew 133 void G4VisCommandViewerAddCutawayPlane::SetNewValue (G4UIcommand*, G4String newValue) { 106 134 107 G4VisManager::Verbosity verbosity = fpVisMan 135 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); 108 136 109 G4VViewer* viewer = fpVisManager -> GetCurre 137 G4VViewer* viewer = fpVisManager -> GetCurrentViewer (); 110 if (!viewer) { 138 if (!viewer) { 111 if (verbosity >= G4VisManager::errors) { 139 if (verbosity >= G4VisManager::errors) { 112 G4warn << << 140 G4cerr << 113 "ERROR: No current viewer - \"/vis/viewer/li 141 "ERROR: No current viewer - \"/vis/viewer/list\" to see possibilities." 114 << G4endl; 142 << G4endl; 115 } 143 } 116 return; 144 return; 117 } 145 } 118 146 119 G4double x, y, z, nx, ny, nz; 147 G4double x, y, z, nx, ny, nz; 120 G4String unit; 148 G4String unit; 121 std::istringstream is (newValue); 149 std::istringstream is (newValue); 122 is >> x >> y >> z >> unit >> nx >> ny >> nz; 150 is >> x >> y >> z >> unit >> nx >> ny >> nz; 123 G4double F = G4UIcommand::ValueOf(unit); 151 G4double F = G4UIcommand::ValueOf(unit); 124 x *= F; y *= F; z *= F; 152 x *= F; y *= F; z *= F; 125 153 126 G4ViewParameters vp = viewer->GetViewParamet 154 G4ViewParameters vp = viewer->GetViewParameters(); 127 // Make sure normal is normalised. << 155 vp.AddCutawayPlane(G4Plane3D(G4Normal3D(nx,ny,nz), G4Point3D(x,y,z))); 128 vp.AddCutawayPlane(G4Plane3D(G4Normal3D(nx,n << 129 if (verbosity >= G4VisManager::confirmations 156 if (verbosity >= G4VisManager::confirmations) { 130 G4cout << "Cutaway planes for viewer \"" < 157 G4cout << "Cutaway planes for viewer \"" << viewer->GetName() << "\" now:"; 131 const G4Planes& cutaways = vp.GetCutawayPl 158 const G4Planes& cutaways = vp.GetCutawayPlanes(); 132 for (std::size_t i = 0; i < cutaways.size( << 159 for (size_t i = 0; i < cutaways.size(); ++i) 133 G4cout << "\n " << i << ": " << cutaway 160 G4cout << "\n " << i << ": " << cutaways[i]; 134 G4cout << G4endl; 161 G4cout << G4endl; 135 } 162 } 136 163 137 SetViewParameters(viewer, vp); 164 SetViewParameters(viewer, vp); 138 } 165 } 139 166 140 ////////////// /vis/viewer/centreOn ////////// << 141 << 142 G4VisCommandViewerCentreOn::G4VisCommandViewer << 143 G4bool omitable; << 144 fpCommandCentreAndZoomInOn = new G4UIcommand << 145 fpCommandCentreAndZoomInOn->SetGuidance << 146 ("Centre and zoom in on the given physical v << 147 fpCommandCentreAndZoomInOn->SetGuidance << 148 ("The names of all volumes in all worlds are << 149 "\ncopy-no is supplied, it matches the copy << 150 "\nform \"/regexp/\", where regexp is a reg << 151 "\nthe match uses the usual rules of regula << 152 "\nOtherwise an exact match is required." << 153 "\nFor example, \"/Shap/\" matches \"Shape1 << 154 fpCommandCentreAndZoomInOn->SetGuidance << 155 ("It may help to see a textual representatio << 156 "\nthe worlds. Try \"/vis/drawTree [worlds] << 157 "\ncombinations that have the required func << 158 fpCommandCentreAndZoomInOn->SetGuidance << 159 ("If there are more than one matching physi << 160 "\nincluded. If this is not what you want, << 161 "\nparticular touchable, then select the t << 162 "\nuse \"/vis/touchable/centreOn\". (You m << 163 G4UIparameter* parameter; << 164 parameter = new G4UIparameter("pv-name",'s' << 165 parameter->SetGuidance ("Physical volum << 166 fpCommandCentreAndZoomInOn->SetParameter(par << 167 parameter = new G4UIparameter("copy-no",'i' << 168 parameter->SetDefaultValue (-1); << 169 parameter->SetGuidance ("Copy number. - << 170 fpCommandCentreAndZoomInOn->SetParameter(par << 171 << 172 fpCommandCentreOn = new G4UIcommand ("/vis/v << 173 fpCommandCentreOn->SetGuidance ("Centre the << 174 // Pick up additional guidance from /vis/vie << 175 CopyGuidanceFrom(fpCommandCentreAndZoomInOn, << 176 // Pick up parameters from /vis/viewer/centr << 177 CopyParametersFrom(fpCommandCentreAndZoomInO << 178 } << 179 << 180 G4VisCommandViewerCentreOn::~G4VisCommandViewe << 181 delete fpCommandCentreAndZoomInOn; << 182 delete fpCommandCentreOn; << 183 } << 184 << 185 G4String G4VisCommandViewerCentreOn::GetCurren << 186 return ""; << 187 } << 188 << 189 void G4VisCommandViewerCentreOn::SetNewValue ( << 190 << 191 G4VisManager::Verbosity verbosity = fpVisMan << 192 G4bool warn = verbosity >= G4VisManager::war << 193 << 194 G4VViewer* currentViewer = fpVisManager -> G << 195 if (!currentViewer) { << 196 if (verbosity >= G4VisManager::errors) { << 197 G4warn << << 198 "ERROR: No current viewer - \"/vis/viewe << 199 << G4endl; << 200 } << 201 return; << 202 } << 203 << 204 G4String pvName; << 205 G4int copyNo; << 206 std::istringstream is (newValue); << 207 is >> pvName >> copyNo; << 208 << 209 // Find physical volumes << 210 G4TransportationManager* transportationManag << 211 G4TransportationManager::GetTransportationMa << 212 std::size_t nWorlds = transportationManager- << 213 std::vector<G4PhysicalVolumesSearchScene::Fi << 214 std::vector<G4VPhysicalVolume*>::iterator it << 215 transportationManager->GetWorldsIterator(); << 216 for (std::size_t i = 0; i < nWorlds; ++i, ++ << 217 G4PhysicalVolumeModel searchModel (*iterWo << 218 G4ModelingParameters mp; // Default - no << 219 searchModel.SetModelingParameters (&mp); << 220 // Find all instances at any position in t << 221 G4PhysicalVolumesSearchScene searchScene ( << 222 searchModel.DescribeYourselfTo (searchScen << 223 for (const auto& findings: searchScene.Get << 224 findingsVector.push_back(findings); << 225 } << 226 } << 227 << 228 if (findingsVector.empty()) { << 229 if (verbosity >= G4VisManager::warnings) { << 230 G4warn << 231 << "WARNING: Volume \"" << pvName << "\" << 232 if (copyNo > 0) { << 233 G4warn << "copy number " << copyNo; << 234 } << 235 G4warn << " not found." << G4endl; << 236 } << 237 return; << 238 } << 239 << 240 // A vector of found paths so that we can hi << 241 std::vector<std::vector<G4PhysicalVolumeMode << 242 << 243 // Use a temporary scene in order to find vi << 244 G4Scene tempScene("Centre Scene"); << 245 G4bool successfullyAdded = true; << 246 for (const auto& findings: findingsVector) { << 247 // To handle paramaterisations we have to << 248 findings.fpFoundPV->SetCopyNo(findings.fFo << 249 // Create a temporary physical volume mode << 250 // They have to be created on the heap bec << 251 // to hang about long enough to be conflat << 252 G4PhysicalVolumeModel* tempPVModel = new G << 253 (findings.fpFoundPV, << 254 0, // Only interested in top volume << 255 findings.fFoundObjectTransformation, << 256 0, // No modelling parameters (these are << 257 true, // Use full extent << 258 findings.fFoundBasePVPath); << 259 // ...and add it to the scene. << 260 auto successful = tempScene.AddRunDuration << 261 if (!successful) { << 262 successfullyAdded = false; << 263 continue; << 264 } << 265 if (verbosity >= G4VisManager::parameters) << 266 G4cout << "\"" << findings.fpFoundPV->Ge << 267 << "\", copy no. " << findings.fFoundPVC << 268 << ",\n found in searched volume \"" << 269 << findings.fpSearchPV->GetName() << 270 << "\" at depth " << findings.fFoundDept << 271 << ",\n base path: \"" << findings.fFou << 272 << ",\n has been added to temporary sce << 273 << G4endl; << 274 } << 275 foundPaths.push_back(findings.fFoundFullPV << 276 } << 277 // Delete temporary physical volume models << 278 for (const auto& sceneModel: tempScene.GetRu << 279 delete sceneModel.fpModel; << 280 } << 281 if (!successfullyAdded) return; << 282 << 283 // Relevant results << 284 const G4VisExtent& newExtent = tempScene.Get << 285 const G4ThreeVector& newTargetPoint = newExt << 286 << 287 G4Scene* currentScene = currentViewer->GetSc << 288 G4ViewParameters saveVP = currentViewer->Get << 289 G4ViewParameters newVP = saveVP; << 290 if (command == fpCommandCentreAndZoomInOn) { << 291 // Calculate the new zoom factor << 292 const G4double zoomFactor << 293 = currentScene->GetExtent().GetExtentRadiu << 294 newVP.SetZoomFactor(zoomFactor); << 295 } << 296 // Change the target point << 297 const G4Point3D& standardTargetPoint = curre << 298 newVP.SetCurrentTargetPoint(newTargetPoint - << 299 << 300 // If this particular view is simple enough << 301 if (currentViewer->GetKernelVisitElapsedTime << 302 // Interpolate << 303 auto keepVisVerbosity = fpVisManager->GetV << 304 fpVisManager->SetVerboseLevel(G4VisManager << 305 if (newVP != saveVP) InterpolateToNewView( << 306 // ...and twinkle << 307 Twinkle(currentViewer,newVP,foundPaths); << 308 fpVisManager->SetVerboseLevel(keepVisVerbo << 309 } << 310 << 311 if (verbosity >= G4VisManager::confirmations << 312 G4cout << 313 << "Viewer \"" << currentViewer->GetName() << 314 << "\" centred "; << 315 if (fpCommandCentreAndZoomInOn) { << 316 G4cout << "and zoomed in"; << 317 } << 318 G4cout << " on physical volume(s) \"" << p << 319 << G4endl; << 320 } << 321 << 322 SetViewParameters(currentViewer, newVP); << 323 } << 324 << 325 ////////////// /vis/viewer/changeCutawayPlane 167 ////////////// /vis/viewer/changeCutawayPlane /////////////////////////////////////// 326 168 327 G4VisCommandViewerChangeCutawayPlane::G4VisCom 169 G4VisCommandViewerChangeCutawayPlane::G4VisCommandViewerChangeCutawayPlane () { 328 G4bool omitable; 170 G4bool omitable; 329 fpCommand = new G4UIcommand ("/vis/viewer/ch 171 fpCommand = new G4UIcommand ("/vis/viewer/changeCutawayPlane", this); 330 fpCommand -> SetGuidance("Change cutaway pla 172 fpCommand -> SetGuidance("Change cutaway plane."); 331 G4UIparameter* parameter; 173 G4UIparameter* parameter; 332 parameter = new G4UIparameter("index",'i', 174 parameter = new G4UIparameter("index",'i',omitable = false); 333 parameter -> SetGuidance ("Index of pl 175 parameter -> SetGuidance ("Index of plane: 0, 1, 2."); 334 fpCommand->SetParameter(parameter); 176 fpCommand->SetParameter(parameter); 335 parameter = new G4UIparameter("x",'d',omit 177 parameter = new G4UIparameter("x",'d',omitable = true); 336 parameter -> SetDefaultValue (0); 178 parameter -> SetDefaultValue (0); 337 parameter -> SetGuidance ("Coordinate 179 parameter -> SetGuidance ("Coordinate of point on the plane."); 338 fpCommand->SetParameter(parameter); 180 fpCommand->SetParameter(parameter); 339 parameter = new G4UIparameter("y",'d',omit 181 parameter = new G4UIparameter("y",'d',omitable = true); 340 parameter -> SetDefaultValue (0); 182 parameter -> SetDefaultValue (0); 341 parameter -> SetGuidance ("Coordinate 183 parameter -> SetGuidance ("Coordinate of point on the plane."); 342 fpCommand->SetParameter(parameter); 184 fpCommand->SetParameter(parameter); 343 parameter = new G4UIparameter("z",'d',omit 185 parameter = new G4UIparameter("z",'d',omitable = true); 344 parameter -> SetDefaultValue (0); 186 parameter -> SetDefaultValue (0); 345 parameter -> SetGuidance ("Coordinate 187 parameter -> SetGuidance ("Coordinate of point on the plane."); 346 fpCommand->SetParameter(parameter); 188 fpCommand->SetParameter(parameter); 347 parameter = new G4UIparameter("unit",'s',o 189 parameter = new G4UIparameter("unit",'s',omitable = true); 348 parameter -> SetDefaultValue ("m"); 190 parameter -> SetDefaultValue ("m"); 349 parameter -> SetGuidance ("Unit of poi 191 parameter -> SetGuidance ("Unit of point on the plane."); 350 fpCommand->SetParameter(parameter); 192 fpCommand->SetParameter(parameter); 351 parameter = new G4UIparameter("nx",'d',omi 193 parameter = new G4UIparameter("nx",'d',omitable = true); 352 parameter -> SetDefaultValue (1); 194 parameter -> SetDefaultValue (1); 353 parameter -> SetGuidance ("Component o 195 parameter -> SetGuidance ("Component of plane normal."); 354 fpCommand->SetParameter(parameter); 196 fpCommand->SetParameter(parameter); 355 parameter = new G4UIparameter("ny",'d',omi 197 parameter = new G4UIparameter("ny",'d',omitable = true); 356 parameter -> SetDefaultValue (0); 198 parameter -> SetDefaultValue (0); 357 parameter -> SetGuidance ("Component o 199 parameter -> SetGuidance ("Component of plane normal."); 358 fpCommand->SetParameter(parameter); 200 fpCommand->SetParameter(parameter); 359 parameter = new G4UIparameter("nz",'d',omi 201 parameter = new G4UIparameter("nz",'d',omitable = true); 360 parameter -> SetDefaultValue (0); 202 parameter -> SetDefaultValue (0); 361 parameter -> SetGuidance ("Component o 203 parameter -> SetGuidance ("Component of plane normal."); 362 fpCommand->SetParameter(parameter); 204 fpCommand->SetParameter(parameter); 363 } 205 } 364 206 365 G4VisCommandViewerChangeCutawayPlane::~G4VisCo 207 G4VisCommandViewerChangeCutawayPlane::~G4VisCommandViewerChangeCutawayPlane () { 366 delete fpCommand; 208 delete fpCommand; 367 } 209 } 368 210 369 G4String G4VisCommandViewerChangeCutawayPlane: 211 G4String G4VisCommandViewerChangeCutawayPlane::GetCurrentValue (G4UIcommand*) { 370 return ""; 212 return ""; 371 } 213 } 372 214 373 void G4VisCommandViewerChangeCutawayPlane::Set 215 void G4VisCommandViewerChangeCutawayPlane::SetNewValue (G4UIcommand*, G4String newValue) { 374 216 375 G4VisManager::Verbosity verbosity = fpVisMan 217 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); 376 218 377 G4VViewer* viewer = fpVisManager -> GetCurre 219 G4VViewer* viewer = fpVisManager -> GetCurrentViewer (); 378 if (!viewer) { 220 if (!viewer) { 379 if (verbosity >= G4VisManager::errors) { 221 if (verbosity >= G4VisManager::errors) { 380 G4warn << << 222 G4cerr << 381 "ERROR: No current viewer - \"/vis/viewer/li 223 "ERROR: No current viewer - \"/vis/viewer/list\" to see possibilities." 382 << G4endl; 224 << G4endl; 383 } 225 } 384 return; 226 return; 385 } 227 } 386 228 387 std::size_t index; << 229 size_t index; 388 G4double x, y, z, nx, ny, nz; 230 G4double x, y, z, nx, ny, nz; 389 G4String unit; 231 G4String unit; 390 std::istringstream is (newValue); 232 std::istringstream is (newValue); 391 is >> index >> x >> y >> z >> unit >> nx >> 233 is >> index >> x >> y >> z >> unit >> nx >> ny >> nz; 392 G4double F = G4UIcommand::ValueOf(unit); 234 G4double F = G4UIcommand::ValueOf(unit); 393 x *= F; y *= F; z *= F; 235 x *= F; y *= F; z *= F; 394 236 395 G4ViewParameters vp = viewer->GetViewParamet 237 G4ViewParameters vp = viewer->GetViewParameters(); 396 // Make sure normal is normalised. << 397 vp.ChangeCutawayPlane(index, 238 vp.ChangeCutawayPlane(index, 398 G4Plane3D(G4Normal3D(nx,ny,nz).unit(), G << 239 G4Plane3D(G4Normal3D(nx,ny,nz), G4Point3D(x,y,z))); 399 if (verbosity >= G4VisManager::confirmations 240 if (verbosity >= G4VisManager::confirmations) { 400 G4cout << "Cutaway planes for viewer \"" < 241 G4cout << "Cutaway planes for viewer \"" << viewer->GetName() << "\" now:"; 401 const G4Planes& cutaways = vp.GetCutawayPl 242 const G4Planes& cutaways = vp.GetCutawayPlanes(); 402 for (std::size_t i = 0; i < cutaways.size( << 243 for (size_t i = 0; i < cutaways.size(); ++i) 403 G4cout << "\n " << i << ": " << cutaway 244 G4cout << "\n " << i << ": " << cutaways[i]; 404 G4cout << G4endl; 245 G4cout << G4endl; 405 } 246 } 406 247 407 SetViewParameters(viewer, vp); 248 SetViewParameters(viewer, vp); 408 } 249 } 409 250 410 ////////////// /vis/viewer/clear ///////////// 251 ////////////// /vis/viewer/clear /////////////////////////////////////// 411 252 412 G4VisCommandViewerClear::G4VisCommandViewerCle 253 G4VisCommandViewerClear::G4VisCommandViewerClear () { 413 G4bool omitable, currentAsDefault; 254 G4bool omitable, currentAsDefault; 414 fpCommand = new G4UIcmdWithAString ("/vis/vi 255 fpCommand = new G4UIcmdWithAString ("/vis/viewer/clear", this); 415 fpCommand -> SetGuidance ("Clears viewer."); 256 fpCommand -> SetGuidance ("Clears viewer."); 416 fpCommand -> SetGuidance 257 fpCommand -> SetGuidance 417 ("By default, clears current viewer. Spec 258 ("By default, clears current viewer. Specified viewer becomes current." 418 "\n\"/vis/viewer/list\" to see possible 259 "\n\"/vis/viewer/list\" to see possible viewer names."); 419 fpCommand -> SetParameterName ("viewer-name" 260 fpCommand -> SetParameterName ("viewer-name", 420 omitable = true, 261 omitable = true, 421 currentAsDefault = true); 262 currentAsDefault = true); 422 } 263 } 423 264 424 G4VisCommandViewerClear::~G4VisCommandViewerCl 265 G4VisCommandViewerClear::~G4VisCommandViewerClear () { 425 delete fpCommand; 266 delete fpCommand; 426 } 267 } 427 268 428 G4String G4VisCommandViewerClear::GetCurrentVa 269 G4String G4VisCommandViewerClear::GetCurrentValue (G4UIcommand*) { 429 G4VViewer* viewer = fpVisManager -> GetCurre 270 G4VViewer* viewer = fpVisManager -> GetCurrentViewer (); 430 return viewer ? viewer -> GetName () : G4Str 271 return viewer ? viewer -> GetName () : G4String("none"); 431 } 272 } 432 273 433 void G4VisCommandViewerClear::SetNewValue (G4U 274 void G4VisCommandViewerClear::SetNewValue (G4UIcommand*, G4String newValue) { 434 275 435 G4VisManager::Verbosity verbosity = fpVisMan 276 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); 436 277 437 G4String& clearName = newValue; 278 G4String& clearName = newValue; 438 G4VViewer* viewer = fpVisManager -> GetViewe 279 G4VViewer* viewer = fpVisManager -> GetViewer (clearName); 439 if (!viewer) { 280 if (!viewer) { 440 if (verbosity >= G4VisManager::errors) { 281 if (verbosity >= G4VisManager::errors) { 441 G4warn << "ERROR: Viewer \"" << clearNam << 282 G4cerr << "ERROR: Viewer \"" << clearName 442 << "\" not found - \"/vis/viewer/list\" 283 << "\" not found - \"/vis/viewer/list\" to see possibilities." 443 << G4endl; 284 << G4endl; 444 } 285 } 445 return; 286 return; 446 } 287 } 447 288 448 viewer->SetView(); 289 viewer->SetView(); 449 viewer->ClearView(); 290 viewer->ClearView(); 450 viewer->FinishView(); 291 viewer->FinishView(); 451 if (verbosity >= G4VisManager::confirmations 292 if (verbosity >= G4VisManager::confirmations) { 452 G4cout << "Viewer \"" << clearName << "\" 293 G4cout << "Viewer \"" << clearName << "\" cleared." << G4endl; 453 } 294 } 454 295 455 } 296 } 456 297 457 ////////////// /vis/viewer/clearCutawayPlanes 298 ////////////// /vis/viewer/clearCutawayPlanes /////////////////////////////////////// 458 299 459 G4VisCommandViewerClearCutawayPlanes::G4VisCom 300 G4VisCommandViewerClearCutawayPlanes::G4VisCommandViewerClearCutawayPlanes () { 460 fpCommand = new G4UIcmdWithoutParameter 301 fpCommand = new G4UIcmdWithoutParameter 461 ("/vis/viewer/clearCutawayPlanes", this); 302 ("/vis/viewer/clearCutawayPlanes", this); 462 fpCommand -> SetGuidance ("Clear cutaway pla 303 fpCommand -> SetGuidance ("Clear cutaway planes of current viewer."); 463 } 304 } 464 305 465 G4VisCommandViewerClearCutawayPlanes::~G4VisCo 306 G4VisCommandViewerClearCutawayPlanes::~G4VisCommandViewerClearCutawayPlanes () { 466 delete fpCommand; 307 delete fpCommand; 467 } 308 } 468 309 469 G4String G4VisCommandViewerClearCutawayPlanes: 310 G4String G4VisCommandViewerClearCutawayPlanes::GetCurrentValue (G4UIcommand*) { 470 return ""; 311 return ""; 471 } 312 } 472 313 473 void G4VisCommandViewerClearCutawayPlanes::Set 314 void G4VisCommandViewerClearCutawayPlanes::SetNewValue (G4UIcommand*, G4String) { 474 315 475 G4VisManager::Verbosity verbosity = fpVisMan 316 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); 476 317 477 G4VViewer* viewer = fpVisManager -> GetCurre 318 G4VViewer* viewer = fpVisManager -> GetCurrentViewer (); 478 if (!viewer) { 319 if (!viewer) { 479 if (verbosity >= G4VisManager::errors) { 320 if (verbosity >= G4VisManager::errors) { 480 G4warn << << 321 G4cerr << 481 "ERROR: No current viewer - \"/vis/viewer/li 322 "ERROR: No current viewer - \"/vis/viewer/list\" to see possibilities." 482 << G4endl; 323 << G4endl; 483 } 324 } 484 return; 325 return; 485 } 326 } 486 327 487 G4ViewParameters vp = viewer->GetViewParamet 328 G4ViewParameters vp = viewer->GetViewParameters(); 488 vp.ClearCutawayPlanes(); 329 vp.ClearCutawayPlanes(); 489 if (verbosity >= G4VisManager::confirmations 330 if (verbosity >= G4VisManager::confirmations) { 490 G4cout << "Cutaway planes for viewer \"" < 331 G4cout << "Cutaway planes for viewer \"" << viewer->GetName() 491 << "\" now cleared." << G4endl; 332 << "\" now cleared." << G4endl; 492 } 333 } 493 334 494 SetViewParameters(viewer, vp); 335 SetViewParameters(viewer, vp); 495 } 336 } 496 337 497 ////////////// /vis/viewer/clearTransients /// 338 ////////////// /vis/viewer/clearTransients ////////////////////////// 498 339 499 G4VisCommandViewerClearTransients::G4VisComman 340 G4VisCommandViewerClearTransients::G4VisCommandViewerClearTransients () { 500 G4bool omitable, currentAsDefault; 341 G4bool omitable, currentAsDefault; 501 fpCommand = new G4UIcmdWithAString ("/vis/vi 342 fpCommand = new G4UIcmdWithAString ("/vis/viewer/clearTransients", this); 502 fpCommand -> SetGuidance ("Clears transients 343 fpCommand -> SetGuidance ("Clears transients from viewer."); 503 fpCommand -> SetGuidance 344 fpCommand -> SetGuidance 504 ("By default, operates on current viewer. S 345 ("By default, operates on current viewer. Specified viewer becomes current." 505 "\n\"/vis/viewer/list\" to see possible 346 "\n\"/vis/viewer/list\" to see possible viewer names."); 506 fpCommand -> SetParameterName ("viewer-name" 347 fpCommand -> SetParameterName ("viewer-name", 507 omitable = true, 348 omitable = true, 508 currentAsDefault = true); 349 currentAsDefault = true); 509 } 350 } 510 351 511 G4VisCommandViewerClearTransients::~G4VisComma 352 G4VisCommandViewerClearTransients::~G4VisCommandViewerClearTransients () { 512 delete fpCommand; 353 delete fpCommand; 513 } 354 } 514 355 515 G4String G4VisCommandViewerClearTransients::Ge 356 G4String G4VisCommandViewerClearTransients::GetCurrentValue (G4UIcommand*) { 516 G4VViewer* viewer = fpVisManager -> GetCurre 357 G4VViewer* viewer = fpVisManager -> GetCurrentViewer (); 517 return viewer ? viewer -> GetName () : G4Str 358 return viewer ? viewer -> GetName () : G4String("none"); 518 } 359 } 519 360 520 void G4VisCommandViewerClearTransients::SetNew 361 void G4VisCommandViewerClearTransients::SetNewValue (G4UIcommand*, G4String newValue) { 521 362 522 G4VisManager::Verbosity verbosity = fpVisMan 363 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); 523 364 524 G4String& clearName = newValue; 365 G4String& clearName = newValue; 525 G4VViewer* viewer = fpVisManager -> GetViewe 366 G4VViewer* viewer = fpVisManager -> GetViewer (clearName); 526 if (!viewer) { 367 if (!viewer) { 527 if (verbosity >= G4VisManager::errors) { 368 if (verbosity >= G4VisManager::errors) { 528 G4warn << "ERROR: Viewer \"" << clearNam << 369 G4cerr << "ERROR: Viewer \"" << clearName 529 << "\" not found - \"/vis/viewer/list\" 370 << "\" not found - \"/vis/viewer/list\" to see possibilities." 530 << G4endl; 371 << G4endl; 531 } 372 } 532 return; 373 return; 533 } 374 } 534 375 535 G4VSceneHandler* sceneHandler = viewer->GetS 376 G4VSceneHandler* sceneHandler = viewer->GetSceneHandler(); 536 sceneHandler->SetMarkForClearingTransientSto 377 sceneHandler->SetMarkForClearingTransientStore(false); 537 fpVisManager->ResetTransientsDrawnFlags(); 378 fpVisManager->ResetTransientsDrawnFlags(); 538 sceneHandler->ClearTransientStore(); 379 sceneHandler->ClearTransientStore(); 539 if (verbosity >= G4VisManager::confirmations 380 if (verbosity >= G4VisManager::confirmations) { 540 G4cout << "Viewer \"" << clearName << "\" 381 G4cout << "Viewer \"" << clearName << "\" cleared of transients." 541 << G4endl; 382 << G4endl; 542 } 383 } 543 384 544 } 385 } 545 386 546 ////////////// /vis/viewer/clearVisAttributesM 387 ////////////// /vis/viewer/clearVisAttributesModifiers /////////////////////////////////////// 547 388 548 G4VisCommandViewerClearVisAttributesModifiers: 389 G4VisCommandViewerClearVisAttributesModifiers::G4VisCommandViewerClearVisAttributesModifiers () { 549 fpCommand = new G4UIcmdWithoutParameter 390 fpCommand = new G4UIcmdWithoutParameter 550 ("/vis/viewer/clearVisAttributesModifiers", 391 ("/vis/viewer/clearVisAttributesModifiers", this); 551 fpCommand -> SetGuidance ("Clear vis attribu 392 fpCommand -> SetGuidance ("Clear vis attribute modifiers of current viewer."); 552 fpCommand -> SetGuidance ("(These are used f 393 fpCommand -> SetGuidance ("(These are used for touchables, etc.)"); 553 } 394 } 554 395 555 G4VisCommandViewerClearVisAttributesModifiers: 396 G4VisCommandViewerClearVisAttributesModifiers::~G4VisCommandViewerClearVisAttributesModifiers () { 556 delete fpCommand; 397 delete fpCommand; 557 } 398 } 558 399 559 G4String G4VisCommandViewerClearVisAttributesM 400 G4String G4VisCommandViewerClearVisAttributesModifiers::GetCurrentValue (G4UIcommand*) { 560 return ""; 401 return ""; 561 } 402 } 562 403 563 void G4VisCommandViewerClearVisAttributesModif 404 void G4VisCommandViewerClearVisAttributesModifiers::SetNewValue (G4UIcommand*, G4String) { 564 405 565 G4VisManager::Verbosity verbosity = fpVisMan 406 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); 566 407 567 G4VViewer* viewer = fpVisManager -> GetCurre 408 G4VViewer* viewer = fpVisManager -> GetCurrentViewer (); 568 if (!viewer) { 409 if (!viewer) { 569 if (verbosity >= G4VisManager::errors) { 410 if (verbosity >= G4VisManager::errors) { 570 G4warn << << 411 G4cerr << 571 "ERROR: No current viewer - \"/vis/viewe 412 "ERROR: No current viewer - \"/vis/viewer/list\" to see possibilities." 572 << G4endl; 413 << G4endl; 573 } 414 } 574 return; 415 return; 575 } 416 } 576 417 577 G4ViewParameters vp = viewer->GetViewParamet 418 G4ViewParameters vp = viewer->GetViewParameters(); 578 vp.ClearVisAttributesModifiers(); 419 vp.ClearVisAttributesModifiers(); 579 if (verbosity >= G4VisManager::confirmations 420 if (verbosity >= G4VisManager::confirmations) { 580 G4cout << "Vis attributes modifiers for vi 421 G4cout << "Vis attributes modifiers for viewer \"" << viewer->GetName() 581 << "\" now cleared." << G4endl; 422 << "\" now cleared." << G4endl; 582 } 423 } 583 424 584 SetViewParameters(viewer, vp); 425 SetViewParameters(viewer, vp); 585 } 426 } 586 427 587 ////////////// /vis/viewer/clone ///////////// 428 ////////////// /vis/viewer/clone /////////////////////////////////////// 588 429 589 G4VisCommandViewerClone::G4VisCommandViewerClo 430 G4VisCommandViewerClone::G4VisCommandViewerClone () { 590 G4bool omitable; 431 G4bool omitable; 591 fpCommand = new G4UIcommand ("/vis/viewer/cl 432 fpCommand = new G4UIcommand ("/vis/viewer/clone", this); 592 fpCommand -> SetGuidance ("Clones viewer."); 433 fpCommand -> SetGuidance ("Clones viewer."); 593 fpCommand -> SetGuidance 434 fpCommand -> SetGuidance 594 ("By default, clones current viewer. Clon 435 ("By default, clones current viewer. Clone becomes current." 595 "\nClone name, if not provided, is derive 436 "\nClone name, if not provided, is derived from the original name." 596 "\n\"/vis/viewer/list\" to see possible 437 "\n\"/vis/viewer/list\" to see possible viewer names."); 597 G4UIparameter* parameter; 438 G4UIparameter* parameter; 598 parameter = new G4UIparameter ("original-vie 439 parameter = new G4UIparameter ("original-viewer-name", 's', omitable = true); 599 parameter -> SetCurrentAsDefault (true); 440 parameter -> SetCurrentAsDefault (true); 600 fpCommand -> SetParameter (parameter); 441 fpCommand -> SetParameter (parameter); 601 parameter = new G4UIparameter ("clone-name", 442 parameter = new G4UIparameter ("clone-name", 's', omitable = true); 602 parameter -> SetDefaultValue ("none"); 443 parameter -> SetDefaultValue ("none"); 603 fpCommand -> SetParameter (parameter); 444 fpCommand -> SetParameter (parameter); 604 } 445 } 605 446 606 G4VisCommandViewerClone::~G4VisCommandViewerCl 447 G4VisCommandViewerClone::~G4VisCommandViewerClone () { 607 delete fpCommand; 448 delete fpCommand; 608 } 449 } 609 450 610 G4String G4VisCommandViewerClone::GetCurrentVa 451 G4String G4VisCommandViewerClone::GetCurrentValue (G4UIcommand*) { 611 G4VViewer* viewer = fpVisManager -> GetCurre 452 G4VViewer* viewer = fpVisManager -> GetCurrentViewer (); 612 G4String originalName = viewer ? viewer -> G 453 G4String originalName = viewer ? viewer -> GetName () : G4String("none"); 613 return "\"" + originalName + "\""; 454 return "\"" + originalName + "\""; 614 } 455 } 615 456 616 void G4VisCommandViewerClone::SetNewValue (G4U 457 void G4VisCommandViewerClone::SetNewValue (G4UIcommand*, G4String newValue) { 617 458 618 G4VisManager::Verbosity verbosity = fpVisMan 459 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); 619 460 620 G4String originalName, cloneName; 461 G4String originalName, cloneName; 621 std::istringstream is (newValue); 462 std::istringstream is (newValue); 622 463 623 // Need to handle the possibility that the n 464 // Need to handle the possibility that the names contain embedded 624 // blanks within quotation marks... 465 // blanks within quotation marks... 625 char c = ' '; 466 char c = ' '; 626 while (is.get(c) && c == ' '){} 467 while (is.get(c) && c == ' '){} 627 if (c == '"') { 468 if (c == '"') { 628 while (is.get(c) && c != '"') {originalNam 469 while (is.get(c) && c != '"') {originalName += c;} 629 } 470 } 630 else { 471 else { 631 originalName += c; 472 originalName += c; 632 while (is.get(c) && c != ' ') {originalNam 473 while (is.get(c) && c != ' ') {originalName += c;} 633 } 474 } 634 G4StrUtil::strip(originalName, ' '); << 475 originalName = originalName.strip (G4String::both, ' '); 635 G4StrUtil::strip(originalName, '"'); << 476 originalName = originalName.strip (G4String::both, '"'); 636 477 637 G4VViewer* originalViewer = fpVisManager -> 478 G4VViewer* originalViewer = fpVisManager -> GetViewer (originalName); 638 if (!originalViewer) { 479 if (!originalViewer) { 639 if (verbosity >= G4VisManager::errors) { 480 if (verbosity >= G4VisManager::errors) { 640 G4warn << "ERROR: Viewer \"" << original << 481 G4cerr << "ERROR: Viewer \"" << originalName 641 << "\" not found - \"/vis/viewer/list\" 482 << "\" not found - \"/vis/viewer/list\" to see possibilities." 642 << G4endl; 483 << G4endl; 643 } 484 } 644 return; 485 return; 645 } 486 } 646 originalName = originalViewer->GetName(); / 487 originalName = originalViewer->GetName(); // Ensures long name. 647 488 648 while (is.get(c) && c == ' '){} 489 while (is.get(c) && c == ' '){} 649 if (c == '"') { 490 if (c == '"') { 650 while (is.get(c) && c != '"') {cloneName + 491 while (is.get(c) && c != '"') {cloneName += c;} 651 } 492 } 652 else { 493 else { 653 cloneName += c; 494 cloneName += c; 654 while (is.get(c) && c != ' ') {cloneName + 495 while (is.get(c) && c != ' ') {cloneName += c;} 655 } 496 } 656 G4StrUtil::strip(cloneName, ' '); << 497 cloneName = cloneName.strip (G4String::both, ' '); 657 G4StrUtil::strip(cloneName, '"'); << 498 cloneName = cloneName.strip (G4String::both, '"'); 658 499 659 G4bool errorWhileNaming = false; 500 G4bool errorWhileNaming = false; 660 if (cloneName == "none") { 501 if (cloneName == "none") { 661 G4int subID = 0; 502 G4int subID = 0; 662 do { 503 do { 663 cloneName = originalName; 504 cloneName = originalName; 664 std::ostringstream oss; 505 std::ostringstream oss; 665 oss << '-' << subID++; 506 oss << '-' << subID++; 666 G4String::size_type lastDashPosition, ne 507 G4String::size_type lastDashPosition, nextSpacePosition; 667 if ((lastDashPosition = cloneName.rfind( 508 if ((lastDashPosition = cloneName.rfind('-')) != G4String::npos && 668 (nextSpacePosition = cloneName.find(" ", l 509 (nextSpacePosition = cloneName.find(" ", lastDashPosition)) != 669 G4String::npos) { 510 G4String::npos) { 670 cloneName.insert(nextSpacePosition, oss.str( 511 cloneName.insert(nextSpacePosition, oss.str()); 671 } else { 512 } else { 672 G4String::size_type spacePosition = cloneNam 513 G4String::size_type spacePosition = cloneName.find(' '); 673 if (spacePosition != G4String::npos) 514 if (spacePosition != G4String::npos) 674 cloneName.insert(spacePosition, oss.str()) 515 cloneName.insert(spacePosition, oss.str()); 675 else 516 else 676 errorWhileNaming = true; 517 errorWhileNaming = true; 677 } 518 } 678 } while (!errorWhileNaming && fpVisManager 519 } while (!errorWhileNaming && fpVisManager -> GetViewer (cloneName)); 679 } 520 } 680 521 681 if (errorWhileNaming) { 522 if (errorWhileNaming) { 682 if (verbosity >= G4VisManager::errors) { 523 if (verbosity >= G4VisManager::errors) { 683 G4warn << "ERROR: While naming clone vie << 524 G4cerr << "ERROR: While naming clone viewer \"" << cloneName 684 << "\"." 525 << "\"." 685 << G4endl; 526 << G4endl; 686 } 527 } 687 return; 528 return; 688 } 529 } 689 530 690 if (fpVisManager -> GetViewer (cloneName)) { 531 if (fpVisManager -> GetViewer (cloneName)) { 691 if (verbosity >= G4VisManager::errors) { 532 if (verbosity >= G4VisManager::errors) { 692 G4warn << "ERROR: Putative clone viewer << 533 G4cerr << "ERROR: Putative clone viewer \"" << cloneName 693 << "\" already exists." 534 << "\" already exists." 694 << G4endl; 535 << G4endl; 695 } 536 } 696 return; 537 return; 697 } 538 } 698 539 699 G4String windowSizeHint = 540 G4String windowSizeHint = 700 originalViewer->GetViewParameters().GetXGe 541 originalViewer->GetViewParameters().GetXGeometryString(); 701 542 702 G4UImanager* UImanager = G4UImanager::GetUIp 543 G4UImanager* UImanager = G4UImanager::GetUIpointer(); >> 544 G4int keepVerbose = UImanager->GetVerboseLevel(); >> 545 G4int newVerbose(0); >> 546 if (keepVerbose >= 2 || >> 547 fpVisManager->GetVerbosity() >= G4VisManager::confirmations) >> 548 newVerbose = 2; >> 549 UImanager->SetVerboseLevel(newVerbose); 703 UImanager->ApplyCommand(G4String("/vis/viewe 550 UImanager->ApplyCommand(G4String("/vis/viewer/select " + originalName)); 704 UImanager->ApplyCommand 551 UImanager->ApplyCommand 705 (G4String("/vis/viewer/create ! \"" + clon 552 (G4String("/vis/viewer/create ! \"" + cloneName + "\" " + windowSizeHint)); 706 UImanager->ApplyCommand(G4String("/vis/viewe 553 UImanager->ApplyCommand(G4String("/vis/viewer/set/all " + originalName)); >> 554 UImanager->SetVerboseLevel(keepVerbose); 707 555 708 if (verbosity >= G4VisManager::confirmations 556 if (verbosity >= G4VisManager::confirmations) { 709 G4cout << "Viewer \"" << originalName << " 557 G4cout << "Viewer \"" << originalName << "\" cloned." << G4endl; 710 G4cout << "Clone \"" << cloneName << "\" n 558 G4cout << "Clone \"" << cloneName << "\" now current." << G4endl; 711 } 559 } 712 } 560 } 713 561 714 ////////////// /vis/viewer/colourByDensity /// << 715 << 716 G4VisCommandViewerColourByDensity::G4VisComman << 717 G4bool omitable; << 718 fpCommand = new G4UIcommand ("/vis/viewer/co << 719 fpCommand -> SetGuidance << 720 ("If a volume has no vis attributes, colour << 721 fpCommand -> SetGuidance << 722 ("Provide algorithm number, e.g., \"1\" (or << 723 "\nThen a unit of density, e.g., \"g/cm3\". << 724 "\nThen parameters for the algorithm assume << 725 fpCommand -> SetGuidance << 726 ("Algorithm 1: Simple algorithm takes 3 para << 727 "\n Volumes with density < d0 are invisibl << 728 "\n Volumes with d0 <= density < d1 have c << 729 "\n Volumes with d1 <= density < d2 have c << 730 "\n Volumes with density > d2 are blue."); << 731 G4UIparameter* parameter; << 732 parameter = new G4UIparameter("n",'i',omit << 733 parameter -> SetGuidance ("Algorithm n << 734 parameter -> SetDefaultValue (1); << 735 fpCommand->SetParameter(parameter); << 736 parameter = new G4UIparameter("unit",'s',o << 737 parameter -> SetGuidance ("Unit of fol << 738 parameter -> SetDefaultValue ("g/cm3"); << 739 fpCommand->SetParameter(parameter); << 740 parameter = new G4UIparameter("d0",'d',omi << 741 parameter -> SetGuidance ("Density par << 742 parameter -> SetDefaultValue (0.5); << 743 fpCommand->SetParameter(parameter); << 744 parameter = new G4UIparameter("d1",'d',omi << 745 parameter -> SetGuidance ("Density par << 746 parameter -> SetDefaultValue (3.0); << 747 fpCommand->SetParameter(parameter); << 748 parameter = new G4UIparameter("d2",'d',omi << 749 parameter -> SetGuidance ("Density par << 750 parameter -> SetDefaultValue (10.0); << 751 fpCommand->SetParameter(parameter); << 752 } << 753 << 754 G4VisCommandViewerColourByDensity::~G4VisComma << 755 delete fpCommand; << 756 } << 757 << 758 G4String G4VisCommandViewerColourByDensity::Ge << 759 return ""; << 760 } << 761 << 762 void G4VisCommandViewerColourByDensity::SetNew << 763 << 764 G4VisManager::Verbosity verbosity = fpVisMan << 765 << 766 G4VViewer* viewer = fpVisManager -> GetCurre << 767 if (!viewer) { << 768 if (verbosity >= G4VisManager::errors) { << 769 G4warn << << 770 "ERROR: No current viewer - \"/vis/viewe << 771 << G4endl; << 772 } << 773 return; << 774 } << 775 G4ViewParameters vp = viewer->GetViewParamet << 776 << 777 G4int algorithmNumber; << 778 G4double d0, d1, d2; << 779 G4String unit; << 780 std::istringstream is (newValue); << 781 is >> algorithmNumber >> unit >> d0 >> d1 >> << 782 << 783 if (algorithmNumber < 0 || algorithmNumber > << 784 if (verbosity >= G4VisManager::errors) { << 785 G4warn << << 786 "ERROR: Unrecognised algorithm number: " << 787 << G4endl; << 788 } << 789 return; << 790 } << 791 << 792 std::vector<G4double> parameters; << 793 if (algorithmNumber > 0) { << 794 const G4String where = "G4VisCommandViewer << 795 G4double valueOfUnit; << 796 // "Volumic Mass" is Michel's phrase for " << 797 if (ProvideValueOfUnit(where,unit,"Volumic << 798 // Successful outcome of unit search << 799 d0 *= valueOfUnit; d1 *= valueOfUnit; d2 << 800 } else { << 801 if (verbosity >= G4VisManager::errors) { << 802 G4warn << << 803 "ERROR: Unrecognised or inappropriate << 804 << G4endl; << 805 } << 806 return; << 807 } << 808 parameters.push_back(d0); << 809 parameters.push_back(d1); << 810 parameters.push_back(d2); << 811 } << 812 vp.SetCBDAlgorithmNumber(algorithmNumber); << 813 vp.SetCBDParameters(parameters); << 814 << 815 if (verbosity >= G4VisManager::confirmations << 816 if (vp.GetCBDAlgorithmNumber() == 0) { << 817 G4cout << "Colour by density deactivated << 818 } else { << 819 G4cout << "Colour by density algorithm " << 820 << " selected for viewer \"" << viewer-> << 821 << "\n Parameters:"; << 822 for (auto p: vp.GetCBDParameters()) { << 823 G4cout << ' ' << G4BestUnit(p,"Volumic << 824 } << 825 G4cout << G4endl; << 826 } << 827 } << 828 << 829 SetViewParameters(viewer, vp); << 830 } << 831 << 832 ////////////// /vis/viewer/copyViewFrom ////// 562 ////////////// /vis/viewer/copyViewFrom ////////////////////////// 833 563 834 G4VisCommandViewerCopyViewFrom::G4VisCommandVi 564 G4VisCommandViewerCopyViewFrom::G4VisCommandViewerCopyViewFrom () { 835 G4bool omitable; 565 G4bool omitable; 836 fpCommand = new G4UIcmdWithAString ("/vis/vi 566 fpCommand = new G4UIcmdWithAString ("/vis/viewer/copyViewFrom", this); 837 fpCommand -> SetGuidance 567 fpCommand -> SetGuidance 838 ("Copy the camera-specific parameters from t 568 ("Copy the camera-specific parameters from the specified viewer."); 839 fpCommand -> SetGuidance 569 fpCommand -> SetGuidance 840 ("Note: To copy ALL view parameters, includi 570 ("Note: To copy ALL view parameters, including scene modifications," 841 "\nuse \"/vis/viewer/set/all\""); 571 "\nuse \"/vis/viewer/set/all\""); 842 fpCommand -> SetParameterName ("from-viewer- 572 fpCommand -> SetParameterName ("from-viewer-name", omitable = false); 843 } 573 } 844 574 845 G4VisCommandViewerCopyViewFrom::~G4VisCommandV 575 G4VisCommandViewerCopyViewFrom::~G4VisCommandViewerCopyViewFrom () { 846 delete fpCommand; 576 delete fpCommand; 847 } 577 } 848 578 849 G4String G4VisCommandViewerCopyViewFrom::GetCu 579 G4String G4VisCommandViewerCopyViewFrom::GetCurrentValue (G4UIcommand*) { 850 return ""; 580 return ""; 851 } 581 } 852 582 853 void G4VisCommandViewerCopyViewFrom::SetNewVal 583 void G4VisCommandViewerCopyViewFrom::SetNewValue (G4UIcommand*, G4String newValue) { 854 584 855 G4VisManager::Verbosity verbosity = fpVisMan 585 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); 856 586 857 G4VViewer* currentViewer = fpVisManager->Get 587 G4VViewer* currentViewer = fpVisManager->GetCurrentViewer(); 858 if (!currentViewer) { 588 if (!currentViewer) { 859 if (verbosity >= G4VisManager::errors) { 589 if (verbosity >= G4VisManager::errors) { 860 G4warn << << 590 G4cerr << 861 "ERROR: G4VisCommandsViewerCopyViewFrom::Set 591 "ERROR: G4VisCommandsViewerCopyViewFrom::SetNewValue: no current viewer." 862 << G4endl; 592 << G4endl; 863 } 593 } 864 return; 594 return; 865 } 595 } 866 596 867 const G4String& fromViewerName = newValue; 597 const G4String& fromViewerName = newValue; 868 G4VViewer* fromViewer = fpVisManager -> GetV 598 G4VViewer* fromViewer = fpVisManager -> GetViewer (fromViewerName); 869 if (!fromViewer) { 599 if (!fromViewer) { 870 if (verbosity >= G4VisManager::errors) { 600 if (verbosity >= G4VisManager::errors) { 871 G4warn << "ERROR: Viewer \"" << fromView << 601 G4cerr << "ERROR: Viewer \"" << fromViewerName 872 << "\" not found - \"/vis/viewer/list\" 602 << "\" not found - \"/vis/viewer/list\" to see possibilities." 873 << G4endl; 603 << G4endl; 874 } 604 } 875 return; 605 return; 876 } 606 } 877 607 878 if (fromViewer == currentViewer) { 608 if (fromViewer == currentViewer) { 879 if (verbosity >= G4VisManager::warnings) { 609 if (verbosity >= G4VisManager::warnings) { 880 G4warn << << 610 G4cout << 881 "WARNING: G4VisCommandsViewerSet::SetN 611 "WARNING: G4VisCommandsViewerSet::SetNewValue:" 882 "\n from-viewer and current viewer ar 612 "\n from-viewer and current viewer are identical." 883 << G4endl; 613 << G4endl; 884 } 614 } 885 return; 615 return; 886 } 616 } 887 617 888 // Copy camera-specific view parameters 618 // Copy camera-specific view parameters 889 G4ViewParameters vp = currentViewer->GetView 619 G4ViewParameters vp = currentViewer->GetViewParameters(); 890 CopyCameraParameters(vp, fromViewer->GetView << 620 const G4ViewParameters& fromVP = fromViewer->GetViewParameters(); >> 621 vp.SetViewpointDirection (fromVP.GetViewpointDirection()); >> 622 vp.SetLightpointDirection (fromVP.GetLightpointDirection()); >> 623 vp.SetLightsMoveWithCamera(fromVP.GetLightsMoveWithCamera()); >> 624 vp.SetUpVector (fromVP.GetUpVector()); >> 625 vp.SetFieldHalfAngle (fromVP.GetFieldHalfAngle()); >> 626 vp.SetZoomFactor (fromVP.GetZoomFactor()); >> 627 vp.SetScaleFactor (fromVP.GetScaleFactor()); >> 628 vp.SetCurrentTargetPoint (fromVP.GetCurrentTargetPoint()); >> 629 vp.SetDolly (fromVP.GetDolly()); 891 SetViewParameters(currentViewer, vp); 630 SetViewParameters(currentViewer, vp); 892 631 893 if (verbosity >= G4VisManager::confirmations 632 if (verbosity >= G4VisManager::confirmations) { 894 G4cout << "Camera parameters of viewer \"" 633 G4cout << "Camera parameters of viewer \"" << currentViewer->GetName() 895 << "\"\n set to those of viewer \"" << f 634 << "\"\n set to those of viewer \"" << fromViewer->GetName() 896 << "\"." 635 << "\"." 897 << G4endl; 636 << G4endl; 898 } 637 } 899 } 638 } 900 639 901 ////////////// /vis/viewer/create //////////// 640 ////////////// /vis/viewer/create /////////////////////////////////////// 902 641 903 G4VisCommandViewerCreate::G4VisCommandViewerCr 642 G4VisCommandViewerCreate::G4VisCommandViewerCreate (): fId (0) { 904 G4bool omitable; 643 G4bool omitable; 905 fpCommand = new G4UIcommand ("/vis/viewer/cr 644 fpCommand = new G4UIcommand ("/vis/viewer/create", this); 906 fpCommand -> SetGuidance 645 fpCommand -> SetGuidance 907 ("Creates a viewer. If the scene handler n << 646 ("Creates a viewer for the specified scene handler."); 908 "\nviewer of that scene handler is create << 909 "\nof the current scene handler is create << 910 fpCommand -> SetGuidance << 911 ("If the viewer name is not specified a na << 912 "\nof the scene handler and a serial numb << 913 fpCommand -> SetGuidance("The scene handler << 914 fpCommand -> SetGuidance << 915 ("(Note: the system adds the graphics syst << 916 "\nfor identification, but for selecting, << 917 "\nup to the first blank are used. For ex << 918 "\n\"viewer-0 (G4OpenGLStoredQt)\", it ma << 919 "\nfor example in \"/vis/viewer/select vi << 920 fpCommand -> SetGuidance << 921 ("Window size and placement hints, e.g. 600x << 922 fpCommand -> SetGuidance << 923 ("- single number, e.g., \"600\": square win << 924 fpCommand -> SetGuidance << 925 ("- two numbers, e.g., \"800x600\": rectangl << 926 fpCommand -> SetGuidance << 927 ("- two numbers plus placement hint, e.g., \ << 928 "\n 600x600 100 pixels left and 100 pixels << 929 fpCommand -> SetGuidance << 930 ("- If not specified, the default is \"600\" << 931 "\n at the window manager's discretion...o << 932 fpCommand -> SetGuidance 647 fpCommand -> SetGuidance 933 ("- This is an X-Windows-type geometry strin << 648 ("Default scene handler is the current scene handler. Invents a name" 934 "\n https://en.wikibooks.org/wiki/Guide_to << 649 "\nif not supplied. (Note: the system adds information to the name" 935 "\n \"Specifying window geometry\"."); << 650 "\nfor identification - only the characters up to the first blank are" >> 651 "\nused for removing, selecting, etc.) This scene handler and viewer" >> 652 "\nbecome current."); 936 G4UIparameter* parameter; 653 G4UIparameter* parameter; 937 parameter = new G4UIparameter ("scene-handle 654 parameter = new G4UIparameter ("scene-handler", 's', omitable = true); 938 parameter -> SetCurrentAsDefault (true); 655 parameter -> SetCurrentAsDefault (true); 939 fpCommand -> SetParameter (parameter); 656 fpCommand -> SetParameter (parameter); 940 parameter = new G4UIparameter ("viewer-name" 657 parameter = new G4UIparameter ("viewer-name", 's', omitable = true); 941 parameter -> SetCurrentAsDefault (true); 658 parameter -> SetCurrentAsDefault (true); 942 fpCommand -> SetParameter (parameter); 659 fpCommand -> SetParameter (parameter); 943 parameter = new G4UIparameter ("window-size- 660 parameter = new G4UIparameter ("window-size-hint", 's', omitable = true); 944 parameter -> SetCurrentAsDefault (true); << 661 parameter->SetGuidance >> 662 ("integer (pixels) for square window placed by window manager or" >> 663 " X-Windows-type geometry string, e.g. 600x600-100+100"); >> 664 parameter->SetDefaultValue("600"); 945 fpCommand -> SetParameter (parameter); 665 fpCommand -> SetParameter (parameter); 946 } 666 } 947 667 948 G4VisCommandViewerCreate::~G4VisCommandViewerC 668 G4VisCommandViewerCreate::~G4VisCommandViewerCreate () { 949 delete fpCommand; 669 delete fpCommand; 950 } 670 } 951 671 952 G4String G4VisCommandViewerCreate::NextName () 672 G4String G4VisCommandViewerCreate::NextName () { 953 std::ostringstream oss; 673 std::ostringstream oss; 954 G4VSceneHandler* sceneHandler = fpVisManager 674 G4VSceneHandler* sceneHandler = fpVisManager -> GetCurrentSceneHandler (); 955 oss << "viewer-" << fId << " ("; 675 oss << "viewer-" << fId << " ("; 956 if (sceneHandler) { 676 if (sceneHandler) { 957 oss << sceneHandler -> GetGraphicsSystem ( 677 oss << sceneHandler -> GetGraphicsSystem () -> GetName (); 958 } 678 } 959 else { 679 else { 960 oss << "no_scene_handlers"; 680 oss << "no_scene_handlers"; 961 } 681 } 962 oss << ")"; 682 oss << ")"; 963 return oss.str(); 683 return oss.str(); 964 } 684 } 965 685 966 G4String G4VisCommandViewerCreate::GetCurrentV << 686 G4String G4VisCommandViewerCreate::GetCurrentValue (G4UIcommand*) { 967 { << 687 G4String currentValue; 968 G4String sceneHandlerName; << 688 G4VSceneHandler* currentSceneHandler = 969 auto currentSceneHandler = fpVisManager->Get << 689 fpVisManager -> GetCurrentSceneHandler (); 970 if (currentSceneHandler) { // Get name of l << 690 if (currentSceneHandler) { 971 sceneHandlerName = currentSceneHandler->Ge << 691 currentValue = currentSceneHandler -> GetName (); 972 } 692 } 973 else { // No scene handler - ensure a warni << 693 else { 974 sceneHandlerName = "none"; << 694 currentValue = "none"; 975 } 695 } >> 696 currentValue += ' '; >> 697 currentValue += '"'; >> 698 currentValue += NextName (); >> 699 currentValue += '"'; 976 700 977 // Default name << 701 currentValue += " 600"; // Default number of pixels for window size hint. 978 const auto& viewerName = NextName(); << 979 << 980 // Size hint << 981 G4String windowSizeHint; << 982 auto currentViewer = fpVisManager->GetCurren << 983 if (currentViewer) { // Get hint from last << 984 windowSizeHint = currentViewer->GetViewPar << 985 } << 986 else { // No viewer - must be first time << 987 windowSizeHint = fpVisManager->GetDefaultX << 988 } << 989 702 990 // Add quotes around viewer name << 703 return currentValue; 991 return sceneHandlerName + " \"" + viewerName << 992 } 704 } 993 705 994 void G4VisCommandViewerCreate::SetNewValue (G4 << 706 void G4VisCommandViewerCreate::SetNewValue (G4UIcommand*, G4String newValue) { 995 707 996 G4VisManager::Verbosity verbosity = fpVisMan 708 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); 997 709 998 G4String sceneHandlerName, newName; 710 G4String sceneHandlerName, newName; 999 G4String windowSizeHintString; 711 G4String windowSizeHintString; 1000 std::istringstream is (newValue); 712 std::istringstream is (newValue); 1001 is >> sceneHandlerName; 713 is >> sceneHandlerName; 1002 714 1003 // Now need to handle the possibility that 715 // Now need to handle the possibility that the second string 1004 // contains embedded blanks within quotatio 716 // contains embedded blanks within quotation marks... 1005 char c = ' '; 717 char c = ' '; 1006 while (is.get(c) && c == ' '){} 718 while (is.get(c) && c == ' '){} 1007 if (c == '"') { 719 if (c == '"') { 1008 while (is.get(c) && c != '"') {newName += 720 while (is.get(c) && c != '"') {newName += c;} 1009 } 721 } 1010 else { 722 else { 1011 newName += c; 723 newName += c; 1012 while (is.get(c) && c != ' ') {newName += 724 while (is.get(c) && c != ' ') {newName += c;} 1013 } 725 } 1014 G4StrUtil::strip(newName, ' '); << 726 newName = newName.strip (G4String::both, ' '); 1015 G4StrUtil::strip(newName, '"'); << 727 newName = newName.strip (G4String::both, '"'); 1016 728 1017 // Now get window size hint... 729 // Now get window size hint... 1018 is >> windowSizeHintString; 730 is >> windowSizeHintString; 1019 731 1020 const G4SceneHandlerList& sceneHandlerList 732 const G4SceneHandlerList& sceneHandlerList = 1021 fpVisManager -> GetAvailableSceneHandlers 733 fpVisManager -> GetAvailableSceneHandlers (); 1022 std::size_t nHandlers = sceneHandlerList.si << 734 G4int nHandlers = sceneHandlerList.size (); 1023 if (nHandlers == 0) { << 735 if (nHandlers <= 0) { 1024 G4ExceptionDescription ed; << 736 if (verbosity >= G4VisManager::errors) { 1025 ed << << 737 G4cerr << 1026 "ERROR: G4VisCommandViewerCreate::SetNewV << 738 "ERROR: G4VisCommandViewerCreate::SetNewValue: no scene handlers." 1027 "\n Create a scene handler with \"/vis/s << 739 "\n Create a scene handler with \"/vis/sceneHandler/create\"" 1028 command->CommandFailed(ed); << 740 << G4endl; >> 741 } 1029 return; 742 return; 1030 } 743 } 1031 744 1032 std::size_t iHandler; << 745 G4int iHandler; 1033 for (iHandler = 0; iHandler < nHandlers; ++ << 746 for (iHandler = 0; iHandler < nHandlers; iHandler++) { 1034 if (sceneHandlerList [iHandler] -> GetNam 747 if (sceneHandlerList [iHandler] -> GetName () == sceneHandlerName) break; 1035 } 748 } 1036 749 1037 if (iHandler >= nHandlers) { << 750 if (iHandler < 0 || iHandler >= nHandlers) { 1038 // Invalid command line argument or none. 751 // Invalid command line argument or none. 1039 // This shouldn't happen!!!!!! 752 // This shouldn't happen!!!!!! 1040 G4ExceptionDescription ed; << 753 if (verbosity >= G4VisManager::errors) { 1041 ed << << 754 G4cout << "G4VisCommandViewerCreate::SetNewValue:" 1042 "G4VisCommandViewerCreate::SetNewValue: i << 755 " invalid scene handler specified." 1043 command->CommandFailed(ed); << 756 << G4endl; >> 757 } 1044 return; 758 return; 1045 } 759 } 1046 760 1047 // Valid index. Set current scene handler 761 // Valid index. Set current scene handler and graphics system in 1048 // preparation for creating viewer. 762 // preparation for creating viewer. 1049 G4VSceneHandler* sceneHandler = sceneHandle 763 G4VSceneHandler* sceneHandler = sceneHandlerList [iHandler]; 1050 if (sceneHandler != fpVisManager -> GetCurr 764 if (sceneHandler != fpVisManager -> GetCurrentSceneHandler ()) { 1051 fpVisManager -> SetCurrentSceneHandler (s 765 fpVisManager -> SetCurrentSceneHandler (sceneHandler); 1052 } 766 } 1053 767 1054 // Now deal with name of viewer. 768 // Now deal with name of viewer. 1055 G4String nextName = NextName (); 769 G4String nextName = NextName (); 1056 if (newName == "") { 770 if (newName == "") { 1057 newName = nextName; 771 newName = nextName; 1058 } 772 } 1059 if (newName == nextName) fId++; 773 if (newName == nextName) fId++; 1060 G4String newShortName = fpVisManager -> Vie 774 G4String newShortName = fpVisManager -> ViewerShortName (newName); 1061 775 1062 for (std::size_t ih = 0; ih < nHandlers; ++ << 776 for (G4int ih = 0; ih < nHandlers; ih++) { 1063 G4VSceneHandler* sh = sceneHandlerList [i 777 G4VSceneHandler* sh = sceneHandlerList [ih]; 1064 const G4ViewerList& viewerList = sh -> Ge 778 const G4ViewerList& viewerList = sh -> GetViewerList (); 1065 for (std::size_t iViewer = 0; iViewer < v << 779 for (size_t iViewer = 0; iViewer < viewerList.size (); iViewer++) { 1066 if (viewerList [iViewer] -> GetShortNam 780 if (viewerList [iViewer] -> GetShortName () == newShortName ) { 1067 G4ExceptionDescription ed; << 781 if (verbosity >= G4VisManager::errors) { 1068 ed << << 782 G4cerr << "ERROR: Viewer \"" << newShortName << "\" already exists." 1069 "ERROR: Viewer \"" << newShortName << "\" a << 783 << G4endl; 1070 command->CommandFailed(ed); << 784 } 1071 return; 785 return; 1072 } 786 } 1073 } 787 } 1074 } 788 } 1075 789 1076 if (fThereWasAViewer && windowSizeHintStrin << 790 // WindowSizeHint and XGeometryString are picked up from the vis 1077 // The user did not specify a window size << 791 // manager in the G4VViewer constructor. In G4VisManager, after Viewer 1078 windowSizeHintString = fExistingVP.GetXGe << 792 // creation, we will store theses parameters in G4ViewParameters. 1079 } << 1080 793 1081 fpVisManager -> CreateViewer (newName,windo 794 fpVisManager -> CreateViewer (newName,windowSizeHintString); 1082 795 1083 // Now we have a new viewer << 1084 G4VViewer* newViewer = fpVisManager -> GetC 796 G4VViewer* newViewer = fpVisManager -> GetCurrentViewer (); 1085 << 1086 if (newViewer && newViewer -> GetName () == 797 if (newViewer && newViewer -> GetName () == newName) { 1087 if (fThereWasAViewer) { << 1088 G4ViewParameters vp = newViewer->GetVie << 1089 // Copy view parameters from existing v << 1090 fExistingVP.SetAutoRefresh(vp.IsAutoRef << 1091 fExistingVP.SetBackgroundColour(vp.GetB << 1092 fExistingVP.SetGlobalMarkerScale(vp.Get << 1093 // ...including window hint paramaters << 1094 fExistingVP.SetXGeometryString(vp.GetXG << 1095 vp = fExistingVP; << 1096 newViewer->SetViewParameters(vp); << 1097 newViewer->AccessSceneTree() = fExistin << 1098 } << 1099 if (verbosity >= G4VisManager::confirmati 798 if (verbosity >= G4VisManager::confirmations) { 1100 G4cout << "New viewer \"" << newName << 799 G4cout << "New viewer \"" << newName << "\" created." << G4endl; 1101 } 800 } 1102 // Keep for next time... << 801 } 1103 fThereWasAViewer = true; << 802 else { 1104 auto viewer = fpVisManager->GetCurrentVie << 803 if (verbosity >= G4VisManager::errors) { 1105 fExistingVP = viewer->GetViewParameters() << 804 if (newViewer) { 1106 fExistingSceneTree = viewer->GetSceneTree << 805 G4cerr << "ERROR: New viewer doesn\'t match!!! Curious!!" << G4endl; 1107 } else { << 806 } else { 1108 G4ExceptionDescription ed; << 807 G4cout << "WARNING: No viewer created." << G4endl; 1109 if (newViewer) { << 808 } 1110 ed << "ERROR: New viewer doesn\'t match << 1111 } else { << 1112 ed << "WARNING: No viewer created."; << 1113 } 809 } 1114 command->CommandFailed(ed); << 1115 return; << 1116 } 810 } 1117 // Refresh if appropriate... 811 // Refresh if appropriate... 1118 if (newViewer) { 812 if (newViewer) { 1119 if (newViewer->GetViewParameters().IsAuto 813 if (newViewer->GetViewParameters().IsAutoRefresh()) { 1120 G4UImanager::GetUIpointer()->ApplyComma 814 G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/refresh"); 1121 } 815 } 1122 else { 816 else { 1123 if (verbosity >= G4VisManager::warnings 817 if (verbosity >= G4VisManager::warnings) { 1124 G4warn << "Issue /vis/viewer/refresh or flu << 818 G4cout << "Issue /vis/viewer/refresh or flush to see effect." 1125 << G4endl; 819 << G4endl; 1126 } 820 } 1127 } 821 } 1128 } 822 } 1129 } 823 } 1130 824 1131 ////////////// /vis/viewer/dolly and dollyTo 825 ////////////// /vis/viewer/dolly and dollyTo //////////////////////////// 1132 826 1133 G4VisCommandViewerDolly::G4VisCommandViewerDo 827 G4VisCommandViewerDolly::G4VisCommandViewerDolly (): 1134 fDollyIncrement (0.), 828 fDollyIncrement (0.), 1135 fDollyTo (0.) 829 fDollyTo (0.) 1136 { 830 { 1137 G4bool omitable, currentAsDefault; 831 G4bool omitable, currentAsDefault; 1138 832 1139 fpCommandDolly = new G4UIcmdWithADoubleAndU 833 fpCommandDolly = new G4UIcmdWithADoubleAndUnit 1140 ("/vis/viewer/dolly", this); 834 ("/vis/viewer/dolly", this); 1141 fpCommandDolly -> SetGuidance 835 fpCommandDolly -> SetGuidance 1142 ("Incremental dolly."); 836 ("Incremental dolly."); 1143 fpCommandDolly -> SetGuidance 837 fpCommandDolly -> SetGuidance 1144 ("Moves the camera incrementally towards 838 ("Moves the camera incrementally towards target point."); 1145 fpCommandDolly -> SetParameterName("increme 839 fpCommandDolly -> SetParameterName("increment", 1146 omitable=true, 840 omitable=true, 1147 currentAsDefault=true); 841 currentAsDefault=true); 1148 fpCommandDolly -> SetDefaultUnit("m"); 842 fpCommandDolly -> SetDefaultUnit("m"); 1149 843 1150 fpCommandDollyTo = new G4UIcmdWithADoubleAn 844 fpCommandDollyTo = new G4UIcmdWithADoubleAndUnit 1151 ("/vis/viewer/dollyTo", this); 845 ("/vis/viewer/dollyTo", this); 1152 fpCommandDollyTo -> SetGuidance 846 fpCommandDollyTo -> SetGuidance 1153 ("Dolly to specific coordinate."); 847 ("Dolly to specific coordinate."); 1154 fpCommandDollyTo -> SetGuidance 848 fpCommandDollyTo -> SetGuidance 1155 ("Places the camera towards target point rel 849 ("Places the camera towards target point relative to standard camera point."); 1156 fpCommandDollyTo -> SetParameterName("dista 850 fpCommandDollyTo -> SetParameterName("distance", 1157 omitable=true, 851 omitable=true, 1158 currentAsDefault=true); 852 currentAsDefault=true); 1159 fpCommandDollyTo -> SetDefaultUnit("m"); 853 fpCommandDollyTo -> SetDefaultUnit("m"); 1160 } 854 } 1161 855 1162 G4VisCommandViewerDolly::~G4VisCommandViewerD 856 G4VisCommandViewerDolly::~G4VisCommandViewerDolly () { 1163 delete fpCommandDolly; 857 delete fpCommandDolly; 1164 delete fpCommandDollyTo; 858 delete fpCommandDollyTo; 1165 } 859 } 1166 860 1167 G4String G4VisCommandViewerDolly::GetCurrentV 861 G4String G4VisCommandViewerDolly::GetCurrentValue (G4UIcommand* command) { 1168 G4String currentValue; 862 G4String currentValue; 1169 if (command == fpCommandDolly) { 863 if (command == fpCommandDolly) { 1170 currentValue = fpCommandDolly->ConvertToS 864 currentValue = fpCommandDolly->ConvertToString(fDollyIncrement, "m"); 1171 } 865 } 1172 else if (command == fpCommandDollyTo) { 866 else if (command == fpCommandDollyTo) { 1173 currentValue = fpCommandDollyTo->ConvertT 867 currentValue = fpCommandDollyTo->ConvertToString(fDollyTo, "m"); 1174 } 868 } 1175 return currentValue; 869 return currentValue; 1176 } 870 } 1177 871 1178 void G4VisCommandViewerDolly::SetNewValue (G4 872 void G4VisCommandViewerDolly::SetNewValue (G4UIcommand* command, 1179 G4String newValue) { 873 G4String newValue) { 1180 874 1181 875 1182 G4VisManager::Verbosity verbosity = fpVisMa 876 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); 1183 877 1184 G4VViewer* currentViewer = fpVisManager->Ge 878 G4VViewer* currentViewer = fpVisManager->GetCurrentViewer(); 1185 if (!currentViewer) { 879 if (!currentViewer) { 1186 if (verbosity >= G4VisManager::errors) { 880 if (verbosity >= G4VisManager::errors) { 1187 G4warn << << 881 G4cerr << 1188 "ERROR: G4VisCommandsViewerDolly::SetNewVal 882 "ERROR: G4VisCommandsViewerDolly::SetNewValue: no current viewer." 1189 << G4endl; 883 << G4endl; 1190 } 884 } 1191 return; 885 return; 1192 } 886 } 1193 887 1194 G4ViewParameters vp = currentViewer->GetVie 888 G4ViewParameters vp = currentViewer->GetViewParameters(); 1195 889 1196 if (command == fpCommandDolly) { 890 if (command == fpCommandDolly) { 1197 fDollyIncrement = fpCommandDolly->GetNewD 891 fDollyIncrement = fpCommandDolly->GetNewDoubleValue(newValue); 1198 vp.IncrementDolly(fDollyIncrement); 892 vp.IncrementDolly(fDollyIncrement); 1199 } 893 } 1200 else if (command == fpCommandDollyTo) { 894 else if (command == fpCommandDollyTo) { 1201 fDollyTo = fpCommandDolly->GetNewDoubleVa 895 fDollyTo = fpCommandDolly->GetNewDoubleValue(newValue); 1202 vp.SetDolly(fDollyTo); 896 vp.SetDolly(fDollyTo); 1203 } 897 } 1204 898 1205 if (verbosity >= G4VisManager::confirmation 899 if (verbosity >= G4VisManager::confirmations) { 1206 G4cout << "Dolly distance changed to " << 900 G4cout << "Dolly distance changed to " << vp.GetDolly() << G4endl; 1207 } 901 } 1208 902 1209 SetViewParameters(currentViewer, vp); 903 SetViewParameters(currentViewer, vp); 1210 } 904 } 1211 905 1212 ////////////// /vis/viewer/flush //////////// 906 ////////////// /vis/viewer/flush /////////////////////////////////////// 1213 907 1214 G4VisCommandViewerFlush::G4VisCommandViewerFl 908 G4VisCommandViewerFlush::G4VisCommandViewerFlush () { 1215 G4bool omitable, currentAsDefault; 909 G4bool omitable, currentAsDefault; 1216 fpCommand = new G4UIcmdWithAString ("/vis/v 910 fpCommand = new G4UIcmdWithAString ("/vis/viewer/flush", this); 1217 fpCommand -> SetGuidance 911 fpCommand -> SetGuidance 1218 ("Compound command: \"/vis/viewer/refresh 912 ("Compound command: \"/vis/viewer/refresh\" + \"/vis/viewer/update\"."); 1219 fpCommand -> SetGuidance 913 fpCommand -> SetGuidance 1220 ("Useful for refreshing and initiating po 914 ("Useful for refreshing and initiating post-processing for graphics" 1221 "\nsystems which need post-processing. 915 "\nsystems which need post-processing. By default, acts on current" 1222 "\nviewer. \"/vis/viewer/list\" to see 916 "\nviewer. \"/vis/viewer/list\" to see possible viewers. Viewer" 1223 "\nbecomes current."); 917 "\nbecomes current."); 1224 fpCommand -> SetParameterName ("viewer-name 918 fpCommand -> SetParameterName ("viewer-name", 1225 omitable = true, 919 omitable = true, 1226 currentAsDefault = true); 920 currentAsDefault = true); 1227 } 921 } 1228 922 1229 G4VisCommandViewerFlush::~G4VisCommandViewerF 923 G4VisCommandViewerFlush::~G4VisCommandViewerFlush () { 1230 delete fpCommand; 924 delete fpCommand; 1231 } 925 } 1232 926 1233 G4String G4VisCommandViewerFlush::GetCurrentV 927 G4String G4VisCommandViewerFlush::GetCurrentValue 1234 (G4UIcommand*) { 928 (G4UIcommand*) { 1235 G4VViewer* viewer = fpVisManager -> GetCurr 929 G4VViewer* viewer = fpVisManager -> GetCurrentViewer (); 1236 return viewer ? viewer -> GetName () : G4St 930 return viewer ? viewer -> GetName () : G4String("none"); 1237 } 931 } 1238 932 1239 void G4VisCommandViewerFlush::SetNewValue (G4 933 void G4VisCommandViewerFlush::SetNewValue (G4UIcommand*, G4String newValue) { 1240 934 1241 G4VisManager::Verbosity verbosity = fpVisMa 935 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); 1242 936 1243 G4String& flushName = newValue; 937 G4String& flushName = newValue; 1244 G4VViewer* viewer = fpVisManager -> GetView 938 G4VViewer* viewer = fpVisManager -> GetViewer (flushName); 1245 if (!viewer) { 939 if (!viewer) { 1246 if (verbosity >= G4VisManager::errors) { 940 if (verbosity >= G4VisManager::errors) { 1247 G4warn << "ERROR: Viewer \"" << flushNa << 941 G4cerr << "ERROR: Viewer \"" << flushName << "\"" << 1248 " not found - \"/vis/viewer/list\"\n to se 942 " not found - \"/vis/viewer/list\"\n to see possibilities." 1249 << G4endl; 943 << G4endl; 1250 } 944 } 1251 return; 945 return; 1252 } 946 } 1253 947 1254 G4UImanager* ui = G4UImanager::GetUIpointer 948 G4UImanager* ui = G4UImanager::GetUIpointer(); >> 949 G4int keepVerbose = ui->GetVerboseLevel(); >> 950 G4int newVerbose(0); >> 951 if (keepVerbose >= 2 || verbosity >= G4VisManager::confirmations) >> 952 newVerbose = 2; >> 953 ui->SetVerboseLevel(newVerbose); 1255 ui->ApplyCommand(G4String("/vis/viewer/refr 954 ui->ApplyCommand(G4String("/vis/viewer/refresh " + flushName)); 1256 ui->ApplyCommand(G4String("/vis/viewer/upda 955 ui->ApplyCommand(G4String("/vis/viewer/update " + flushName)); >> 956 ui->SetVerboseLevel(keepVerbose); 1257 if (verbosity >= G4VisManager::confirmation 957 if (verbosity >= G4VisManager::confirmations) { 1258 G4cout << "Viewer \"" << viewer -> GetNam 958 G4cout << "Viewer \"" << viewer -> GetName () << "\"" 1259 << " flushed." << G4endl; 959 << " flushed." << G4endl; 1260 } 960 } 1261 } 961 } 1262 962 1263 ////////////// /vis/viewer/interpolate ////// 963 ////////////// /vis/viewer/interpolate /////////////////////////////////////// 1264 964 1265 G4VisCommandViewerInterpolate::G4VisCommandVi 965 G4VisCommandViewerInterpolate::G4VisCommandViewerInterpolate () { 1266 G4bool omitable; 966 G4bool omitable; 1267 fpCommand = new G4UIcommand ("/vis/viewer/i 967 fpCommand = new G4UIcommand ("/vis/viewer/interpolate", this); 1268 fpCommand -> SetGuidance 968 fpCommand -> SetGuidance 1269 ("Interpolate views defined by the first ar 969 ("Interpolate views defined by the first argument, which can contain " 1270 "Unix-shell-style pattern matching charact 970 "Unix-shell-style pattern matching characters such as '*', '?' and '[' " 1271 "- see \"man sh\" and look for \"Pattern M 971 "- see \"man sh\" and look for \"Pattern Matching\". The contents " 1272 "of each file are assumed to be \"/vis/vie 972 "of each file are assumed to be \"/vis/viewer\" commands " 1273 "that specify a particular view. The files 973 "that specify a particular view. The files are processed in alphanumeric " 1274 "order of filename. The files may be writt 974 "order of filename. The files may be written by hand or produced by the " 1275 "\"/vis/viewer/save\" command."); 975 "\"/vis/viewer/save\" command."); 1276 fpCommand -> SetGuidance 976 fpCommand -> SetGuidance 1277 ("The default is to search the working dire 977 ("The default is to search the working directory for files with a .g4view " 1278 "extension. Another procedure is to assemb 978 "extension. Another procedure is to assemble view files in a subdirectory, " 1279 "e.g., \"myviews\"; then they can be inter 979 "e.g., \"myviews\"; then they can be interpolated with\n" 1280 "\"/vis/viewer/interpolate myviews\"."); << 980 "\"/vis/viewer/interpolate myviews/*\"."); 1281 fpCommand -> SetGuidance 981 fpCommand -> SetGuidance 1282 ("To export interpolated views to file for 982 ("To export interpolated views to file for a future possible movie, " 1283 "write \"export\" as 5th parameter (OpenGL 983 "write \"export\" as 5th parameter (OpenGL only)."); 1284 G4UIparameter* parameter; 984 G4UIparameter* parameter; 1285 parameter = new G4UIparameter("pattern", 's 985 parameter = new G4UIparameter("pattern", 's', omitable = true); 1286 parameter -> SetGuidance("Pattern that defi 986 parameter -> SetGuidance("Pattern that defines the view files."); 1287 parameter -> SetDefaultValue("*.g4view"); 987 parameter -> SetDefaultValue("*.g4view"); 1288 fpCommand -> SetParameter(parameter); 988 fpCommand -> SetParameter(parameter); 1289 parameter = new G4UIparameter("no-of-points 989 parameter = new G4UIparameter("no-of-points", 'i', omitable = true); 1290 parameter -> SetGuidance ("Number of interp 990 parameter -> SetGuidance ("Number of interpolation points per interval."); 1291 parameter -> SetDefaultValue(50); 991 parameter -> SetDefaultValue(50); 1292 fpCommand -> SetParameter(parameter); 992 fpCommand -> SetParameter(parameter); 1293 parameter = new G4UIparameter("wait-time", 993 parameter = new G4UIparameter("wait-time", 's', omitable = true); 1294 parameter -> SetGuidance("Wait time per int 994 parameter -> SetGuidance("Wait time per interpolated point"); 1295 parameter -> SetDefaultValue("20."); 995 parameter -> SetDefaultValue("20."); 1296 fpCommand -> SetParameter(parameter); 996 fpCommand -> SetParameter(parameter); 1297 parameter = new G4UIparameter("time-unit", 997 parameter = new G4UIparameter("time-unit", 's', omitable = true); 1298 parameter -> SetDefaultValue("millisecond") 998 parameter -> SetDefaultValue("millisecond"); 1299 fpCommand -> SetParameter (parameter); 999 fpCommand -> SetParameter (parameter); 1300 parameter = new G4UIparameter("export", 's' 1000 parameter = new G4UIparameter("export", 's', omitable = true); 1301 parameter -> SetDefaultValue("no"); 1001 parameter -> SetDefaultValue("no"); 1302 fpCommand -> SetParameter (parameter); 1002 fpCommand -> SetParameter (parameter); 1303 } 1003 } 1304 1004 1305 G4VisCommandViewerInterpolate::~G4VisCommandV 1005 G4VisCommandViewerInterpolate::~G4VisCommandViewerInterpolate () { 1306 delete fpCommand; 1006 delete fpCommand; 1307 } 1007 } 1308 1008 1309 G4String G4VisCommandViewerInterpolate::GetCu 1009 G4String G4VisCommandViewerInterpolate::GetCurrentValue (G4UIcommand*) { 1310 return ""; 1010 return ""; 1311 } 1011 } 1312 1012 1313 void G4VisCommandViewerInterpolate::SetNewVal 1013 void G4VisCommandViewerInterpolate::SetNewValue (G4UIcommand*, G4String newValue) { 1314 1014 1315 G4VisManager::Verbosity verbosity = fpVisMa 1015 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); 1316 1016 1317 G4VViewer* currentViewer = fpVisManager->Ge 1017 G4VViewer* currentViewer = fpVisManager->GetCurrentViewer(); 1318 if (!currentViewer) { 1018 if (!currentViewer) { 1319 if (verbosity >= G4VisManager::errors) { 1019 if (verbosity >= G4VisManager::errors) { 1320 G4warn << << 1020 G4cerr << 1321 "ERROR: G4VisCommandViewerInterpolate:: 1021 "ERROR: G4VisCommandViewerInterpolate::SetNewValue: no current viewer." 1322 << G4endl; 1022 << G4endl; 1323 } 1023 } 1324 return; 1024 return; 1325 } 1025 } 1326 1026 1327 G4String pattern; 1027 G4String pattern; 1328 G4int nInterpolationPoints; 1028 G4int nInterpolationPoints; 1329 G4String waitTimePerPointString; 1029 G4String waitTimePerPointString; 1330 G4String timeUnit; 1030 G4String timeUnit; 1331 G4String exportString; 1031 G4String exportString; 1332 1032 1333 std::istringstream iss (newValue); 1033 std::istringstream iss (newValue); 1334 iss 1034 iss 1335 >> pattern 1035 >> pattern 1336 >> nInterpolationPoints 1036 >> nInterpolationPoints 1337 >> waitTimePerPointString 1037 >> waitTimePerPointString 1338 >> timeUnit 1038 >> timeUnit 1339 >> exportString; 1039 >> exportString; 1340 G4String waitTimePerPointDimString(waitTime 1040 G4String waitTimePerPointDimString(waitTimePerPointString + ' ' + timeUnit); 1341 const G4double waitTimePerPoint = 1041 const G4double waitTimePerPoint = 1342 G4UIcommand::ConvertToDimensionedDouble(wai 1042 G4UIcommand::ConvertToDimensionedDouble(waitTimePerPointDimString.c_str()); 1343 G4int waitTimePerPointmilliseconds = waitTi 1043 G4int waitTimePerPointmilliseconds = waitTimePerPoint/millisecond; 1344 if (waitTimePerPointmilliseconds < 0) waitT 1044 if (waitTimePerPointmilliseconds < 0) waitTimePerPointmilliseconds = 0; 1345 1045 1346 G4UImanager* uiManager = G4UImanager::GetUI 1046 G4UImanager* uiManager = G4UImanager::GetUIpointer(); 1347 1047 1348 // Save current view parameters 1048 // Save current view parameters 1349 G4ViewParameters saveVP = currentViewer->Ge 1049 G4ViewParameters saveVP = currentViewer->GetViewParameters(); 1350 1050 1351 // Save current verbosities 1051 // Save current verbosities 1352 G4VisManager::Verbosity keepVisVerbosity = 1052 G4VisManager::Verbosity keepVisVerbosity = fpVisManager->GetVerbosity(); 1353 G4int keepUIVerbosity = uiManager->GetVerbo 1053 G4int keepUIVerbosity = uiManager->GetVerboseLevel(); 1354 1054 1355 // Set verbosities for this operation 1055 // Set verbosities for this operation 1356 fpVisManager->SetVerboseLevel(G4VisManager: 1056 fpVisManager->SetVerboseLevel(G4VisManager::errors); 1357 uiManager->SetVerboseLevel(0); 1057 uiManager->SetVerboseLevel(0); 1358 1058 1359 // Switch off auto-refresh while we read in 1059 // Switch off auto-refresh while we read in the view files (it will be 1360 // restored later). Note: the view files d 1060 // restored later). Note: the view files do not set auto-refresh. 1361 G4ViewParameters non_auto = saveVP; 1061 G4ViewParameters non_auto = saveVP; 1362 non_auto.SetAutoRefresh(false); 1062 non_auto.SetAutoRefresh(false); 1363 currentViewer->SetViewParameters(non_auto); 1063 currentViewer->SetViewParameters(non_auto); 1364 1064 1365 const G4int safety = 99; << 1065 // View vector of way points 1366 G4int safetyCount = 0; << 1066 std::vector<G4ViewParameters> viewVector; 1367 G4fs::path pathPattern = pattern.c_str(); << 1368 1067 1369 // Parent path - add "./" for empty directo << 1068 const G4int safety = 9999; 1370 G4String parentPathString << 1069 G4int safetyCount = 0; 1371 (pathPattern.parent_path().string().length( << 1070 G4String pathname; 1372 pathPattern.parent_path().string() : << 1373 std::string("./")); << 1374 G4fs::path parentPath = parentPathString.c_ << 1375 << 1376 // Fill selected paths << 1377 std::set<G4fs::path> paths; // Use std::se << 1378 << 1379 if (G4fs::is_directory(pathPattern)) { << 1380 << 1381 // The user has specified a directory. Fi << 1382 for (const auto& path: G4fs::directory_it << 1383 if (safetyCount++ >= safety) break; << 1384 paths.insert(path); << 1385 } << 1386 1071 1387 } else { << 1072 #ifndef WIN32 1388 1073 1389 // Assume user has specified a Unix "glob << 1074 // Execute pattern and get resulting list of filles 1390 // Default pattern is *.g4view, which tra << 1075 G4String shellCommand = "echo " + pattern; 1391 // Convert pattern into a regexp << 1076 FILE *filelist = popen(shellCommand.c_str(), "r"); 1392 G4String regexp_pattern("^"); << 1077 if (!filelist) { 1393 for (G4int i = 0; i < (G4int)pattern.leng << 1078 if (verbosity >= G4VisManager::errors) { 1394 if (pattern[i] == '.') { << 1079 G4cerr 1395 regexp_pattern += "\\."; << 1080 << "ERROR: G4VisCommandViewerInterpolate::SetNewValue:" 1396 } else if (pattern[i] == '*') { << 1081 << "\n Error obtaining pipe." 1397 regexp_pattern += ".*"; << 1082 << G4endl; 1398 } else if (pattern[i] == '?') { << 1399 regexp_pattern += "(.{1,1})"; << 1400 } else { << 1401 regexp_pattern += pattern[i]; << 1402 } << 1403 } 1083 } 1404 std::regex regexp(regexp_pattern, std::re << 1084 return; >> 1085 } 1405 1086 1406 for (const auto& path: G4fs::directory_it << 1087 // Build view vector of way points 1407 const auto& pathname = path.path().rela << 1088 const size_t BUFLENGTH = 999999; 1408 if (std::regex_match(pathname, regexp)) << 1089 char buf[BUFLENGTH]; 1409 if (safetyCount++ >= safety) break; << 1090 fgets(buf, BUFLENGTH, filelist); 1410 paths.insert(path); << 1091 std::istringstream fileliststream(buf); 1411 } << 1092 while (fileliststream >> pathname >> 1093 && safetyCount++ < safety) { // Loop checking, 16.02.2016, J.Allison >> 1094 uiManager->ApplyCommand("/control/execute " + pathname); >> 1095 viewVector.push_back(currentViewer->GetViewParameters()); >> 1096 } >> 1097 pclose(filelist); >> 1098 >> 1099 #else // WIN32 (popen is not available in Windows) >> 1100 >> 1101 std::experimental::filesystem::v1::path filePattern(pattern); >> 1102 >> 1103 // Default pattern : *.g4view >> 1104 // Translated to a regexp : ^.*\\.g4view >> 1105 // Convert pattern into a regexp >> 1106 std::string regexp_pattern("^" + filePattern.filename().string()); >> 1107 std::string result_pattern = ""; >> 1108 // Replace '.' by "\\." >> 1109 size_t currentPos = 0; >> 1110 size_t nextPos = 0; >> 1111 std::string currentReplacement = ""; >> 1112 size_t pos1 = regexp_pattern.find('.', nextPos); >> 1113 size_t pos2 = regexp_pattern.find('*', nextPos); >> 1114 size_t pos3 = regexp_pattern.find('?', nextPos); >> 1115 while ((pos1 != std::string::npos) || (pos2 != std::string::npos) || (pos3 != std::string::npos)) { >> 1116 nextPos = pos1; >> 1117 currentReplacement = "\\."; >> 1118 if (pos2 < nextPos) { >> 1119 nextPos = pos2; >> 1120 currentReplacement = ".*"; >> 1121 } >> 1122 if (pos3 < nextPos) { >> 1123 nextPos = pos3; >> 1124 currentReplacement = "(.{1,1})"; >> 1125 } >> 1126 result_pattern += regexp_pattern.substr(currentPos, nextPos - currentPos) + currentReplacement; >> 1127 nextPos++; >> 1128 currentPos = nextPos; >> 1129 pos1 = regexp_pattern.find('.', currentPos); >> 1130 pos2 = regexp_pattern.find('*', currentPos); >> 1131 pos3 = regexp_pattern.find('?', currentPos); >> 1132 } >> 1133 result_pattern += regexp_pattern.substr(currentPos); >> 1134 >> 1135 // Build view vector of way points >> 1136 // Add "./" for empty paths >> 1137 G4String parentPath(filePattern.parent_path().string().length() ? filePattern.parent_path().string() : std::string("./")); >> 1138 // Iterate through files in directory and apply regex match to filter appropriate files >> 1139 std::regex result_pattern_regex (result_pattern, std::regex_constants::basic | std::regex_constants::icase); >> 1140 for (auto iter = std::experimental::filesystem::v1::directory_iterator(parentPath); >> 1141 iter != std::experimental::filesystem::v1::directory_iterator() && safetyCount++ < safety; >> 1142 ++iter) >> 1143 { >> 1144 const auto& file = iter->path(); >> 1145 >> 1146 G4String filename(file.filename().string()); >> 1147 if (std::regex_match(filename, result_pattern_regex)) >> 1148 { >> 1149 uiManager->ApplyCommand("/control/execute " + filename); >> 1150 viewVector.push_back(currentViewer->GetViewParameters()); 1412 } 1151 } 1413 } 1152 } 1414 1153 1415 if (safetyCount > safety) { << 1154 #endif // WIN32 >> 1155 >> 1156 if (safetyCount >= safety) { 1416 if (verbosity >= G4VisManager::errors) { 1157 if (verbosity >= G4VisManager::errors) { 1417 G4warn << << 1158 G4cout << 1418 "/vis/viewer/interpolate:" 1159 "/vis/viewer/interpolate:" 1419 "\n the number of way points has been << 1160 "\n the number of way points exceeds the maximum currently allowed: " 1420 << safety << G4endl; 1161 << safety << G4endl; 1421 } 1162 } >> 1163 return; 1422 } 1164 } 1423 1165 1424 // Fill view vector of way points << 1166 // Interpolate views 1425 std::vector<G4ViewParameters> viewVector; << 1167 safetyCount = 0; 1426 for (const auto& path: paths) { << 1168 do { 1427 uiManager->ApplyCommand("/control/execute << 1169 G4ViewParameters* vp = 1428 G4ViewParameters vp = currentViewer->GetV << 1170 G4ViewParameters::CatmullRomCubicSplineInterpolation(viewVector,nInterpolationPoints); >> 1171 if (!vp) break; // Finished. 1429 // Set original auto-refresh status. 1172 // Set original auto-refresh status. 1430 vp.SetAutoRefresh(saveVP.IsAutoRefresh()) << 1173 vp->SetAutoRefresh(saveVP.IsAutoRefresh()); 1431 viewVector.push_back(vp); << 1174 currentViewer->SetViewParameters(*vp); 1432 } << 1175 currentViewer->RefreshView(); 1433 << 1176 if (exportString == "export" && 1434 InterpolateViews << 1177 currentViewer->GetName().contains("OpenGL")) { 1435 (currentViewer,viewVector, << 1178 uiManager->ApplyCommand("/vis/ogl/export"); 1436 nInterpolationPoints,waitTimePerPointmilli << 1179 } >> 1180 // File-writing viewers need to close the file >> 1181 currentViewer->ShowView(); >> 1182 #ifdef G4VIS_USE_STD11 >> 1183 if (waitTimePerPointmilliseconds > 0) >> 1184 std::this_thread::sleep_for(std::chrono::milliseconds(waitTimePerPointmilliseconds)); >> 1185 #endif >> 1186 } while (safetyCount++ < safety); // Loop checking, 16.02.2016, J.Allison 1437 1187 1438 // Restore original verbosities 1188 // Restore original verbosities 1439 uiManager->SetVerboseLevel(keepUIVerbosity) 1189 uiManager->SetVerboseLevel(keepUIVerbosity); 1440 fpVisManager->SetVerboseLevel(keepVisVerbos 1190 fpVisManager->SetVerboseLevel(keepVisVerbosity); 1441 1191 1442 // Restore original view parameters 1192 // Restore original view parameters 1443 currentViewer->SetViewParameters(saveVP); 1193 currentViewer->SetViewParameters(saveVP); 1444 currentViewer->RefreshView(); 1194 currentViewer->RefreshView(); 1445 if (verbosity >= G4VisManager::confirmation 1195 if (verbosity >= G4VisManager::confirmations) { 1446 G4cout << "Viewer \"" << currentViewer -> 1196 G4cout << "Viewer \"" << currentViewer -> GetName () << "\"" 1447 << " restored." << G4endl; 1197 << " restored." << G4endl; 1448 } 1198 } 1449 } 1199 } 1450 1200 1451 ////////////// /vis/viewer/list ///////////// 1201 ////////////// /vis/viewer/list /////////////////////////////////////// 1452 1202 1453 G4VisCommandViewerList::G4VisCommandViewerLis 1203 G4VisCommandViewerList::G4VisCommandViewerList () { 1454 G4bool omitable; 1204 G4bool omitable; 1455 fpCommand = new G4UIcommand ("/vis/viewer/l 1205 fpCommand = new G4UIcommand ("/vis/viewer/list", this); 1456 fpCommand -> SetGuidance ("Lists viewers(s) 1206 fpCommand -> SetGuidance ("Lists viewers(s)."); 1457 fpCommand -> SetGuidance 1207 fpCommand -> SetGuidance 1458 ("See \"/vis/verbose\" for definition of 1208 ("See \"/vis/verbose\" for definition of verbosity."); 1459 G4UIparameter* parameter; 1209 G4UIparameter* parameter; 1460 parameter = new G4UIparameter("viewer-name" 1210 parameter = new G4UIparameter("viewer-name", 's', 1461 omitable = true); 1211 omitable = true); 1462 parameter -> SetDefaultValue ("all"); 1212 parameter -> SetDefaultValue ("all"); 1463 fpCommand -> SetParameter (parameter); 1213 fpCommand -> SetParameter (parameter); 1464 parameter = new G4UIparameter ("verbosity", 1214 parameter = new G4UIparameter ("verbosity", 's', 1465 omitable = true); 1215 omitable = true); 1466 parameter -> SetDefaultValue ("warnings"); 1216 parameter -> SetDefaultValue ("warnings"); 1467 fpCommand -> SetParameter (parameter); 1217 fpCommand -> SetParameter (parameter); 1468 } 1218 } 1469 1219 1470 G4VisCommandViewerList::~G4VisCommandViewerLi 1220 G4VisCommandViewerList::~G4VisCommandViewerList () { 1471 delete fpCommand; 1221 delete fpCommand; 1472 } 1222 } 1473 1223 1474 G4String G4VisCommandViewerList::GetCurrentVa 1224 G4String G4VisCommandViewerList::GetCurrentValue (G4UIcommand*) { 1475 return ""; 1225 return ""; 1476 } 1226 } 1477 1227 1478 void G4VisCommandViewerList::SetNewValue (G4U 1228 void G4VisCommandViewerList::SetNewValue (G4UIcommand*, G4String newValue) { 1479 G4String name, verbosityString; 1229 G4String name, verbosityString; 1480 std::istringstream is (newValue); 1230 std::istringstream is (newValue); 1481 is >> name >> verbosityString; 1231 is >> name >> verbosityString; 1482 G4String shortName = fpVisManager -> Viewer 1232 G4String shortName = fpVisManager -> ViewerShortName (name); 1483 G4VisManager::Verbosity verbosity = 1233 G4VisManager::Verbosity verbosity = 1484 fpVisManager->GetVerbosityValue(verbosity 1234 fpVisManager->GetVerbosityValue(verbosityString); 1485 1235 1486 const G4VViewer* currentViewer = fpVisManag 1236 const G4VViewer* currentViewer = fpVisManager -> GetCurrentViewer (); 1487 G4String currentViewerShortName; 1237 G4String currentViewerShortName; 1488 if (currentViewer) { 1238 if (currentViewer) { 1489 currentViewerShortName = currentViewer -> 1239 currentViewerShortName = currentViewer -> GetShortName (); 1490 } 1240 } 1491 else { 1241 else { 1492 currentViewerShortName = "none"; 1242 currentViewerShortName = "none"; 1493 } 1243 } 1494 1244 1495 const G4SceneHandlerList& sceneHandlerList 1245 const G4SceneHandlerList& sceneHandlerList = 1496 fpVisManager -> GetAvailableSceneHandlers 1246 fpVisManager -> GetAvailableSceneHandlers (); 1497 std::size_t nHandlers = sceneHandlerList.si << 1247 G4int nHandlers = sceneHandlerList.size (); 1498 G4bool found = false; 1248 G4bool found = false; 1499 G4bool foundCurrent = false; 1249 G4bool foundCurrent = false; 1500 for (std::size_t iHandler = 0; iHandler < n << 1250 for (int iHandler = 0; iHandler < nHandlers; iHandler++) { 1501 G4VSceneHandler* sceneHandler = sceneHand 1251 G4VSceneHandler* sceneHandler = sceneHandlerList [iHandler]; 1502 const G4ViewerList& viewerList = sceneHan 1252 const G4ViewerList& viewerList = sceneHandler -> GetViewerList (); 1503 G4cout 1253 G4cout 1504 << "Scene handler \"" << sceneHandler -> 1254 << "Scene handler \"" << sceneHandler -> GetName () << "\" (" 1505 << sceneHandler->GetGraphicsSystem()->Get 1255 << sceneHandler->GetGraphicsSystem()->GetNickname() << ')'; 1506 const G4Scene* pScene = sceneHandler -> G 1256 const G4Scene* pScene = sceneHandler -> GetScene (); 1507 if (pScene) { 1257 if (pScene) { 1508 G4cout << ", scene \"" << pScene -> Get 1258 G4cout << ", scene \"" << pScene -> GetName () << "\""; 1509 } 1259 } 1510 G4cout << ':'; 1260 G4cout << ':'; 1511 std::size_t nViewers = viewerList.size () << 1261 G4int nViewers = viewerList.size (); 1512 if (nViewers == 0) { 1262 if (nViewers == 0) { 1513 G4cout << "\n No viewers for 1263 G4cout << "\n No viewers for this scene handler." << G4endl; 1514 } 1264 } 1515 else { 1265 else { 1516 for (std::size_t iViewer = 0; iViewer < << 1266 for (int iViewer = 0; iViewer < nViewers; iViewer++) { 1517 const G4VViewer* thisViewer = viewerList [i 1267 const G4VViewer* thisViewer = viewerList [iViewer]; 1518 G4String thisName = thisViewer -> GetName ( 1268 G4String thisName = thisViewer -> GetName (); 1519 G4String thisShortName = thisViewer -> GetS 1269 G4String thisShortName = thisViewer -> GetShortName (); 1520 if (name != "all") { 1270 if (name != "all") { 1521 if (thisShortName != shortName) continue; 1271 if (thisShortName != shortName) continue; 1522 } 1272 } 1523 found = true; 1273 found = true; 1524 G4cout << "\n "; 1274 G4cout << "\n "; 1525 if (thisShortName == currentViewerShortName 1275 if (thisShortName == currentViewerShortName) { 1526 foundCurrent = true; 1276 foundCurrent = true; 1527 G4cout << "(current)"; 1277 G4cout << "(current)"; 1528 } 1278 } 1529 else { 1279 else { 1530 G4cout << " "; 1280 G4cout << " "; 1531 } 1281 } 1532 G4cout << " viewer \"" << thisName << "\""; 1282 G4cout << " viewer \"" << thisName << "\""; 1533 if (verbosity >= G4VisManager::parameters) 1283 if (verbosity >= G4VisManager::parameters) { 1534 G4cout << "\n " << *thisViewer; 1284 G4cout << "\n " << *thisViewer; 1535 } 1285 } 1536 } 1286 } 1537 } 1287 } 1538 G4cout << G4endl; 1288 G4cout << G4endl; 1539 } 1289 } 1540 1290 1541 if (!foundCurrent) { 1291 if (!foundCurrent) { 1542 G4cout << "No valid current viewer - plea 1292 G4cout << "No valid current viewer - please create or select one." 1543 << G4endl; 1293 << G4endl; 1544 } 1294 } 1545 1295 1546 if (!found) { 1296 if (!found) { 1547 G4cout << "No viewers"; 1297 G4cout << "No viewers"; 1548 if (name != "all") { 1298 if (name != "all") { 1549 G4cout << " of name \"" << name << "\"" 1299 G4cout << " of name \"" << name << "\""; 1550 } 1300 } 1551 G4cout << " found." << G4endl; 1301 G4cout << " found." << G4endl; 1552 } 1302 } 1553 } 1303 } 1554 1304 1555 ////////////// /vis/viewer/pan and panTo //// 1305 ////////////// /vis/viewer/pan and panTo //////////////////////////// 1556 1306 1557 G4VisCommandViewerPan::G4VisCommandViewerPan 1307 G4VisCommandViewerPan::G4VisCommandViewerPan (): 1558 fPanIncrementRight (0.), 1308 fPanIncrementRight (0.), 1559 fPanIncrementUp (0.), 1309 fPanIncrementUp (0.), 1560 fPanToRight (0.), 1310 fPanToRight (0.), 1561 fPanToUp (0.) 1311 fPanToUp (0.) 1562 { 1312 { 1563 G4bool omitable; 1313 G4bool omitable; 1564 1314 1565 fpCommandPan = new G4UIcommand 1315 fpCommandPan = new G4UIcommand 1566 ("/vis/viewer/pan", this); 1316 ("/vis/viewer/pan", this); 1567 fpCommandPan -> SetGuidance 1317 fpCommandPan -> SetGuidance 1568 ("Incremental pan."); 1318 ("Incremental pan."); 1569 fpCommandPan -> SetGuidance 1319 fpCommandPan -> SetGuidance 1570 ("Moves the camera incrementally right an 1320 ("Moves the camera incrementally right and up by these amounts (as seen" 1571 "\nfrom viewpoint direction)."); 1321 "\nfrom viewpoint direction)."); 1572 G4UIparameter* parameter; 1322 G4UIparameter* parameter; 1573 parameter = new G4UIparameter("right-increm 1323 parameter = new G4UIparameter("right-increment", 'd', omitable = true); 1574 parameter -> SetCurrentAsDefault (true); 1324 parameter -> SetCurrentAsDefault (true); 1575 fpCommandPan -> SetParameter (parameter); 1325 fpCommandPan -> SetParameter (parameter); 1576 parameter = new G4UIparameter("up-increment 1326 parameter = new G4UIparameter("up-increment", 'd', omitable = true); 1577 parameter -> SetCurrentAsDefault (true); 1327 parameter -> SetCurrentAsDefault (true); 1578 fpCommandPan -> SetParameter (parameter); 1328 fpCommandPan -> SetParameter (parameter); 1579 parameter = new G4UIparameter ("unit", 's', 1329 parameter = new G4UIparameter ("unit", 's', omitable = true); 1580 parameter -> SetDefaultValue ("m"); 1330 parameter -> SetDefaultValue ("m"); 1581 fpCommandPan -> SetParameter (parameter); 1331 fpCommandPan -> SetParameter (parameter); 1582 1332 1583 fpCommandPanTo = new G4UIcommand 1333 fpCommandPanTo = new G4UIcommand 1584 ("/vis/viewer/panTo", this); 1334 ("/vis/viewer/panTo", this); 1585 fpCommandPanTo -> SetGuidance 1335 fpCommandPanTo -> SetGuidance 1586 ("Pan to specific coordinate."); 1336 ("Pan to specific coordinate."); 1587 fpCommandPanTo -> SetGuidance 1337 fpCommandPanTo -> SetGuidance 1588 ("Places the camera in this position righ 1338 ("Places the camera in this position right and up relative to standard" 1589 "\ntarget point (as seen from viewpoint 1339 "\ntarget point (as seen from viewpoint direction)."); 1590 parameter = new G4UIparameter("right", 'd', 1340 parameter = new G4UIparameter("right", 'd', omitable = true); 1591 parameter -> SetCurrentAsDefault (true); 1341 parameter -> SetCurrentAsDefault (true); 1592 fpCommandPanTo -> SetParameter (parameter); 1342 fpCommandPanTo -> SetParameter (parameter); 1593 parameter = new G4UIparameter("up", 'd', om 1343 parameter = new G4UIparameter("up", 'd', omitable = true); 1594 parameter -> SetCurrentAsDefault (true); 1344 parameter -> SetCurrentAsDefault (true); 1595 fpCommandPanTo -> SetParameter (parameter); 1345 fpCommandPanTo -> SetParameter (parameter); 1596 parameter = new G4UIparameter ("unit", 's', 1346 parameter = new G4UIparameter ("unit", 's', omitable = true); 1597 parameter -> SetDefaultValue ("m"); 1347 parameter -> SetDefaultValue ("m"); 1598 fpCommandPanTo -> SetParameter (parameter); 1348 fpCommandPanTo -> SetParameter (parameter); 1599 } 1349 } 1600 1350 1601 G4VisCommandViewerPan::~G4VisCommandViewerPan 1351 G4VisCommandViewerPan::~G4VisCommandViewerPan () { 1602 delete fpCommandPan; 1352 delete fpCommandPan; 1603 delete fpCommandPanTo; 1353 delete fpCommandPanTo; 1604 } 1354 } 1605 1355 1606 G4String G4VisCommandViewerPan::GetCurrentVal 1356 G4String G4VisCommandViewerPan::GetCurrentValue (G4UIcommand* command) { 1607 G4String currentValue; 1357 G4String currentValue; 1608 if (command == fpCommandPan) { 1358 if (command == fpCommandPan) { 1609 currentValue = ConvertToString(fPanIncrem 1359 currentValue = ConvertToString(fPanIncrementRight, fPanIncrementUp, "m"); 1610 } 1360 } 1611 else if (command == fpCommandPanTo) { 1361 else if (command == fpCommandPanTo) { 1612 currentValue = ConvertToString(fPanToRigh 1362 currentValue = ConvertToString(fPanToRight, fPanToUp, "m"); 1613 } 1363 } 1614 return currentValue; 1364 return currentValue; 1615 } 1365 } 1616 1366 1617 void G4VisCommandViewerPan::SetNewValue (G4UI 1367 void G4VisCommandViewerPan::SetNewValue (G4UIcommand* command, 1618 G4String newValue) { 1368 G4String newValue) { 1619 1369 1620 1370 1621 G4VisManager::Verbosity verbosity = fpVisMa 1371 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); 1622 1372 1623 G4VViewer* currentViewer = fpVisManager->Ge 1373 G4VViewer* currentViewer = fpVisManager->GetCurrentViewer(); 1624 if (!currentViewer) { 1374 if (!currentViewer) { 1625 if (verbosity >= G4VisManager::errors) { 1375 if (verbosity >= G4VisManager::errors) { 1626 G4warn << << 1376 G4cerr << 1627 "ERROR: G4VisCommandsViewerPan::SetNewValue 1377 "ERROR: G4VisCommandsViewerPan::SetNewValue: no current viewer." 1628 << G4endl; 1378 << G4endl; 1629 } 1379 } 1630 return; 1380 return; 1631 } 1381 } 1632 1382 1633 G4ViewParameters vp = currentViewer->GetVie 1383 G4ViewParameters vp = currentViewer->GetViewParameters(); 1634 1384 1635 if (command == fpCommandPan) { 1385 if (command == fpCommandPan) { 1636 ConvertToDoublePair(newValue, fPanIncreme 1386 ConvertToDoublePair(newValue, fPanIncrementRight, fPanIncrementUp); 1637 vp.IncrementPan(fPanIncrementRight, fPanI 1387 vp.IncrementPan(fPanIncrementRight, fPanIncrementUp); 1638 } 1388 } 1639 else if (command == fpCommandPanTo) { 1389 else if (command == fpCommandPanTo) { 1640 ConvertToDoublePair(newValue, fPanToRight 1390 ConvertToDoublePair(newValue, fPanToRight, fPanToUp); 1641 vp.SetPan(fPanToRight, fPanToUp); 1391 vp.SetPan(fPanToRight, fPanToUp); 1642 } 1392 } 1643 1393 1644 if (verbosity >= G4VisManager::confirmation 1394 if (verbosity >= G4VisManager::confirmations) { 1645 G4cout << "Current target point now " << 1395 G4cout << "Current target point now " << vp.GetCurrentTargetPoint() 1646 << G4endl; 1396 << G4endl; 1647 } 1397 } 1648 1398 1649 SetViewParameters(currentViewer, vp); 1399 SetViewParameters(currentViewer, vp); 1650 } 1400 } 1651 1401 1652 ////////////// /vis/viewer/rebuild ////////// 1402 ////////////// /vis/viewer/rebuild /////////////////////////////////////// 1653 1403 1654 G4VisCommandViewerRebuild::G4VisCommandViewer 1404 G4VisCommandViewerRebuild::G4VisCommandViewerRebuild () { 1655 G4bool omitable, currentAsDefault; 1405 G4bool omitable, currentAsDefault; 1656 fpCommand = new G4UIcmdWithAString ("/vis/v 1406 fpCommand = new G4UIcmdWithAString ("/vis/viewer/rebuild", this); 1657 fpCommand -> SetGuidance ("Forces rebuild o 1407 fpCommand -> SetGuidance ("Forces rebuild of graphical database."); 1658 fpCommand -> SetGuidance 1408 fpCommand -> SetGuidance 1659 ("By default, acts on current viewer. \" 1409 ("By default, acts on current viewer. \"/vis/viewer/list\"" 1660 "\nto see possible viewers. Viewer beco 1410 "\nto see possible viewers. Viewer becomes current."); 1661 fpCommand -> SetParameterName ("viewer-name 1411 fpCommand -> SetParameterName ("viewer-name", 1662 omitable = true, 1412 omitable = true, 1663 currentAsDefault = true); 1413 currentAsDefault = true); 1664 } 1414 } 1665 1415 1666 G4VisCommandViewerRebuild::~G4VisCommandViewe 1416 G4VisCommandViewerRebuild::~G4VisCommandViewerRebuild () { 1667 delete fpCommand; 1417 delete fpCommand; 1668 } 1418 } 1669 1419 1670 G4String G4VisCommandViewerRebuild::GetCurren 1420 G4String G4VisCommandViewerRebuild::GetCurrentValue (G4UIcommand*) { 1671 G4VViewer* viewer = fpVisManager -> GetCurr 1421 G4VViewer* viewer = fpVisManager -> GetCurrentViewer (); 1672 if (viewer) { 1422 if (viewer) { 1673 return viewer -> GetName (); 1423 return viewer -> GetName (); 1674 } 1424 } 1675 else { 1425 else { 1676 return "none"; 1426 return "none"; 1677 } 1427 } 1678 } 1428 } 1679 1429 1680 void G4VisCommandViewerRebuild::SetNewValue ( 1430 void G4VisCommandViewerRebuild::SetNewValue (G4UIcommand*, G4String newValue) { 1681 1431 1682 G4VisManager::Verbosity verbosity = fpVisMa 1432 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); 1683 1433 1684 G4String& rebuildName = newValue; 1434 G4String& rebuildName = newValue; 1685 1435 1686 G4VViewer* viewer = fpVisManager -> GetView 1436 G4VViewer* viewer = fpVisManager -> GetViewer (rebuildName); 1687 if (!viewer) { 1437 if (!viewer) { 1688 if (verbosity >= G4VisManager::errors) { 1438 if (verbosity >= G4VisManager::errors) { 1689 G4warn << "ERROR: Viewer \"" << rebuild << 1439 G4cerr << "ERROR: Viewer \"" << rebuildName 1690 << "\" not found - \"/vis/viewer/list\ 1440 << "\" not found - \"/vis/viewer/list\" to see possibilities." 1691 << G4endl; 1441 << G4endl; 1692 } 1442 } 1693 return; 1443 return; 1694 } 1444 } 1695 1445 1696 G4VSceneHandler* sceneHandler = viewer->Get 1446 G4VSceneHandler* sceneHandler = viewer->GetSceneHandler(); 1697 if (!sceneHandler) { 1447 if (!sceneHandler) { 1698 if (verbosity >= G4VisManager::errors) { 1448 if (verbosity >= G4VisManager::errors) { 1699 G4warn << "ERROR: Viewer \"" << viewer- << 1449 G4cerr << "ERROR: Viewer \"" << viewer->GetName() << "\"" << 1700 " has no scene handler - report serious bug 1450 " has no scene handler - report serious bug." 1701 << G4endl; 1451 << G4endl; 1702 } 1452 } 1703 return; 1453 return; 1704 } 1454 } 1705 1455 1706 sceneHandler->ClearTransientStore(); 1456 sceneHandler->ClearTransientStore(); 1707 viewer->NeedKernelVisit(); 1457 viewer->NeedKernelVisit(); 1708 viewer->SetView(); 1458 viewer->SetView(); 1709 viewer->ClearView(); 1459 viewer->ClearView(); 1710 viewer->DrawView(); 1460 viewer->DrawView(); 1711 1461 1712 // Check auto-refresh and print confirmatio 1462 // Check auto-refresh and print confirmations. 1713 RefreshIfRequired(viewer); 1463 RefreshIfRequired(viewer); 1714 } 1464 } 1715 1465 1716 ////////////// /vis/viewer/refresh ////////// 1466 ////////////// /vis/viewer/refresh /////////////////////////////////////// 1717 1467 1718 G4VisCommandViewerRefresh::G4VisCommandViewer 1468 G4VisCommandViewerRefresh::G4VisCommandViewerRefresh () { 1719 G4bool omitable, currentAsDefault; 1469 G4bool omitable, currentAsDefault; 1720 fpCommand = new G4UIcmdWithAString ("/vis/v 1470 fpCommand = new G4UIcmdWithAString ("/vis/viewer/refresh", this); 1721 fpCommand -> SetGuidance 1471 fpCommand -> SetGuidance 1722 ("Refreshes viewer."); 1472 ("Refreshes viewer."); 1723 fpCommand -> SetGuidance 1473 fpCommand -> SetGuidance 1724 ("By default, acts on current viewer. \" 1474 ("By default, acts on current viewer. \"/vis/viewer/list\"" 1725 "\nto see possible viewers. Viewer beco 1475 "\nto see possible viewers. Viewer becomes current."); 1726 fpCommand -> SetParameterName ("viewer-name 1476 fpCommand -> SetParameterName ("viewer-name", 1727 omitable = true, 1477 omitable = true, 1728 currentAsDefault = true); 1478 currentAsDefault = true); 1729 } 1479 } 1730 1480 1731 G4VisCommandViewerRefresh::~G4VisCommandViewe 1481 G4VisCommandViewerRefresh::~G4VisCommandViewerRefresh () { 1732 delete fpCommand; 1482 delete fpCommand; 1733 } 1483 } 1734 1484 1735 G4String G4VisCommandViewerRefresh::GetCurren 1485 G4String G4VisCommandViewerRefresh::GetCurrentValue (G4UIcommand*) { 1736 G4VViewer* viewer = fpVisManager -> GetCurr 1486 G4VViewer* viewer = fpVisManager -> GetCurrentViewer (); 1737 return viewer ? viewer -> GetName () : G4St 1487 return viewer ? viewer -> GetName () : G4String("none"); 1738 } 1488 } 1739 1489 1740 void G4VisCommandViewerRefresh::SetNewValue ( 1490 void G4VisCommandViewerRefresh::SetNewValue (G4UIcommand*, G4String newValue) { 1741 1491 1742 G4VisManager::Verbosity verbosity = fpVisMa 1492 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); 1743 G4bool warn(verbosity >= G4VisManager::warn 1493 G4bool warn(verbosity >= G4VisManager::warnings); 1744 1494 1745 G4String& refreshName = newValue; 1495 G4String& refreshName = newValue; 1746 G4VViewer* viewer = fpVisManager -> GetView 1496 G4VViewer* viewer = fpVisManager -> GetViewer (refreshName); 1747 if (!viewer) { 1497 if (!viewer) { 1748 if (verbosity >= G4VisManager::errors) { 1498 if (verbosity >= G4VisManager::errors) { 1749 G4warn << "ERROR: Viewer \"" << refresh << 1499 G4cerr << "ERROR: Viewer \"" << refreshName << "\"" << 1750 " not found - \"/vis/viewer/list\"\n to se 1500 " not found - \"/vis/viewer/list\"\n to see possibilities." 1751 << G4endl; 1501 << G4endl; 1752 } 1502 } 1753 return; 1503 return; 1754 } 1504 } 1755 1505 1756 G4VSceneHandler* sceneHandler = viewer->Get 1506 G4VSceneHandler* sceneHandler = viewer->GetSceneHandler(); 1757 if (!sceneHandler) { 1507 if (!sceneHandler) { 1758 if (verbosity >= G4VisManager::errors) { 1508 if (verbosity >= G4VisManager::errors) { 1759 G4warn << "ERROR: Viewer \"" << refresh << 1509 G4cerr << "ERROR: Viewer \"" << refreshName << "\"" << 1760 " has no scene handler - report serious bug 1510 " has no scene handler - report serious bug." 1761 << G4endl; 1511 << G4endl; 1762 } 1512 } 1763 return; 1513 return; 1764 } 1514 } 1765 1515 1766 G4Scene* scene = sceneHandler->GetScene(); 1516 G4Scene* scene = sceneHandler->GetScene(); 1767 if (!scene) { 1517 if (!scene) { 1768 if (verbosity >= G4VisManager::confirmati 1518 if (verbosity >= G4VisManager::confirmations) { 1769 G4cout << "NOTE: SceneHandler \"" << sc 1519 G4cout << "NOTE: SceneHandler \"" << sceneHandler->GetName() 1770 << "\", to which viewer \"" << refresh 1520 << "\", to which viewer \"" << refreshName << "\"" << 1771 "\n is attached, has no scene - \"/vis/sce 1521 "\n is attached, has no scene - \"/vis/scene/create\" and" 1772 " \"/vis/sceneHandler/attach\"" 1522 " \"/vis/sceneHandler/attach\"" 1773 "\n (or use compound command \"/vis/drawVo 1523 "\n (or use compound command \"/vis/drawVolume\")." 1774 << G4endl; 1524 << G4endl; 1775 } 1525 } 1776 return; 1526 return; 1777 } 1527 } 1778 if (scene->GetRunDurationModelList().empty( 1528 if (scene->GetRunDurationModelList().empty()) { 1779 G4bool successful = scene -> AddWorldIfEm 1529 G4bool successful = scene -> AddWorldIfEmpty (warn); 1780 if (!successful) { 1530 if (!successful) { 1781 if (verbosity >= G4VisManager::warnings 1531 if (verbosity >= G4VisManager::warnings) { 1782 G4warn << << 1532 G4cout << 1783 "WARNING: Scene is empty. Perhaps no geo 1533 "WARNING: Scene is empty. Perhaps no geometry exists." 1784 "\n Try /run/initialize." 1534 "\n Try /run/initialize." 1785 << G4endl; 1535 << G4endl; 1786 } 1536 } 1787 return; 1537 return; 1788 } 1538 } 1789 // Scene has changed. CheckSceneAndNotif << 1539 // Scene has changed. UpdateVisManagerScene issues 1790 // /vis/scene/notifyHandlers, which does 1540 // /vis/scene/notifyHandlers, which does a refresh anyway, so the 1791 // ordinary refresh becomes part of the e 1541 // ordinary refresh becomes part of the else phrase... 1792 CheckSceneAndNotifyHandlers(scene); << 1542 UpdateVisManagerScene(scene->GetName()); 1793 } else { 1543 } else { 1794 if (verbosity >= G4VisManager::confirmati 1544 if (verbosity >= G4VisManager::confirmations) { 1795 G4cout << "Refreshing viewer \"" << vie 1545 G4cout << "Refreshing viewer \"" << viewer -> GetName () << "\"..." 1796 << G4endl; 1546 << G4endl; 1797 } 1547 } 1798 viewer -> SetView (); 1548 viewer -> SetView (); 1799 viewer -> ClearView (); 1549 viewer -> ClearView (); 1800 viewer -> DrawView (); 1550 viewer -> DrawView (); 1801 if (verbosity >= G4VisManager::confirmati 1551 if (verbosity >= G4VisManager::confirmations) { 1802 G4cout << "Viewer \"" << viewer -> GetN 1552 G4cout << "Viewer \"" << viewer -> GetName () << "\"" << " refreshed." 1803 "\n (You might also need \"/vis/viewer/upd 1553 "\n (You might also need \"/vis/viewer/update\".)" << G4endl; 1804 } 1554 } 1805 } 1555 } 1806 } 1556 } 1807 1557 1808 ////////////// /vis/viewer/reset //////////// 1558 ////////////// /vis/viewer/reset /////////////////////////////////////// 1809 1559 1810 G4VisCommandViewerReset::G4VisCommandViewerRe 1560 G4VisCommandViewerReset::G4VisCommandViewerReset () { 1811 G4bool omitable, currentAsDefault; 1561 G4bool omitable, currentAsDefault; 1812 fpCommand = new G4UIcmdWithAString ("/vis/v 1562 fpCommand = new G4UIcmdWithAString ("/vis/viewer/reset", this); 1813 fpCommand -> SetGuidance ("Resets viewer.") 1563 fpCommand -> SetGuidance ("Resets viewer."); 1814 fpCommand -> SetGuidance 1564 fpCommand -> SetGuidance 1815 ("By default, acts on current viewer. \" 1565 ("By default, acts on current viewer. \"/vis/viewer/list\"" 1816 "\nto see possible viewers. Viewer beco 1566 "\nto see possible viewers. Viewer becomes current."); 1817 fpCommand -> SetParameterName ("viewer-name 1567 fpCommand -> SetParameterName ("viewer-name", 1818 omitable = true, 1568 omitable = true, 1819 currentAsDefault = true); 1569 currentAsDefault = true); 1820 } 1570 } 1821 1571 1822 G4VisCommandViewerReset::~G4VisCommandViewerR 1572 G4VisCommandViewerReset::~G4VisCommandViewerReset () { 1823 delete fpCommand; 1573 delete fpCommand; 1824 } 1574 } 1825 1575 1826 G4String G4VisCommandViewerReset::GetCurrentV 1576 G4String G4VisCommandViewerReset::GetCurrentValue (G4UIcommand*) { 1827 G4VViewer* viewer = fpVisManager -> GetCurr 1577 G4VViewer* viewer = fpVisManager -> GetCurrentViewer (); 1828 if (viewer) { 1578 if (viewer) { 1829 return viewer -> GetName (); 1579 return viewer -> GetName (); 1830 } 1580 } 1831 else { 1581 else { 1832 return "none"; 1582 return "none"; 1833 } 1583 } 1834 } 1584 } 1835 1585 1836 void G4VisCommandViewerReset::SetNewValue (G4 1586 void G4VisCommandViewerReset::SetNewValue (G4UIcommand*, G4String newValue) { 1837 1587 1838 G4VisManager::Verbosity verbosity = fpVisMa 1588 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); 1839 1589 1840 G4String& resetName = newValue; 1590 G4String& resetName = newValue; 1841 G4VViewer* viewer = fpVisManager -> GetView 1591 G4VViewer* viewer = fpVisManager -> GetViewer (resetName); 1842 if (!viewer) { 1592 if (!viewer) { 1843 if (verbosity >= G4VisManager::errors) { 1593 if (verbosity >= G4VisManager::errors) { 1844 G4warn << "ERROR: Viewer \"" << resetNa << 1594 G4cerr << "ERROR: Viewer \"" << resetName 1845 << "\" not found - \"/vis/viewer/list\ 1595 << "\" not found - \"/vis/viewer/list\" to see possibilities." 1846 << G4endl; 1596 << G4endl; 1847 } 1597 } 1848 return; 1598 return; 1849 } 1599 } 1850 1600 1851 viewer->ResetView(); 1601 viewer->ResetView(); 1852 RefreshIfRequired(viewer); 1602 RefreshIfRequired(viewer); 1853 } 1603 } 1854 1604 1855 ////////////// /vis/viewer/resetCameraParamet << 1856 << 1857 G4VisCommandViewerResetCameraParameters::G4Vi << 1858 G4bool omitable, currentAsDefault; << 1859 fpCommand = new G4UIcmdWithAString ("/vis/v << 1860 fpCommand -> SetGuidance ("Resets only the << 1861 fpCommand -> SetGuidance << 1862 ("By default, acts on current viewer. \"/v << 1863 "\nto see possible viewers. Viewer become << 1864 fpCommand -> SetParameterName ("viewer-name << 1865 omitable = t << 1866 currentAsDef << 1867 } << 1868 << 1869 G4VisCommandViewerResetCameraParameters::~G4V << 1870 delete fpCommand; << 1871 } << 1872 << 1873 G4String G4VisCommandViewerResetCameraParamet << 1874 G4VViewer* viewer = fpVisManager -> GetCurr << 1875 if (viewer) { << 1876 return viewer -> GetName (); << 1877 } << 1878 else { << 1879 return "none"; << 1880 } << 1881 } << 1882 << 1883 void G4VisCommandViewerResetCameraParameters: << 1884 << 1885 G4VisManager::Verbosity verbosity = fpVisMa << 1886 << 1887 G4String& resetName = newValue; << 1888 G4VViewer* viewer = fpVisManager -> GetView << 1889 if (!viewer) { << 1890 if (verbosity >= G4VisManager::errors) { << 1891 G4warn << "ERROR: Viewer \"" << resetNa << 1892 << "\" not found - \"/vis/viewer/list\" << 1893 << G4endl; << 1894 } << 1895 return; << 1896 } << 1897 << 1898 G4ViewParameters newVP = viewer->GetViewPar << 1899 CopyCameraParameters(newVP,viewer->GetDefau << 1900 viewer->SetViewParameters(newVP); << 1901 RefreshIfRequired(viewer); << 1902 } << 1903 << 1904 ////////////// /vis/viewer/save ///////////// 1605 ////////////// /vis/viewer/save /////////////////////////////////////// 1905 1606 1906 G4VisCommandViewerSave::G4VisCommandViewerSav 1607 G4VisCommandViewerSave::G4VisCommandViewerSave () { 1907 G4bool omitable; 1608 G4bool omitable; 1908 fpCommand = new G4UIcmdWithAString ("/vis/v 1609 fpCommand = new G4UIcmdWithAString ("/vis/viewer/save", this); 1909 fpCommand -> SetGuidance 1610 fpCommand -> SetGuidance 1910 ("Write commands that define the current vi 1611 ("Write commands that define the current view to file."); 1911 fpCommand -> SetGuidance 1612 fpCommand -> SetGuidance 1912 ("Read them back into the same or any viewe 1613 ("Read them back into the same or any viewer with \"/control/execute\"."); 1913 fpCommand -> SetGuidance 1614 fpCommand -> SetGuidance 1914 ("If the filename is omitted the view is sa 1615 ("If the filename is omitted the view is saved to a file " 1915 "\"g4_nn.g4view\", where nn is a sequentia 1616 "\"g4_nn.g4view\", where nn is a sequential two-digit number."); 1916 fpCommand -> SetGuidance 1617 fpCommand -> SetGuidance 1917 ("If the filename is \"-\", the data are wr 1618 ("If the filename is \"-\", the data are written to G4cout."); 1918 fpCommand -> SetGuidance 1619 fpCommand -> SetGuidance 1919 ("If you are wanting to save views for futu 1620 ("If you are wanting to save views for future interpolation a recommended " 1920 "procedure is: save views to \"g4_nn.g4vie 1621 "procedure is: save views to \"g4_nn.g4view\", as above, then move the files " 1921 "into a sub-directory, say, \"views\", the 1622 "into a sub-directory, say, \"views\", then interpolate with" 1922 "\"/vis/viewer/interpolate views\""); << 1623 "\"/vis/viewer/interpolate views/\" (note the trailing \'/\')."); 1923 fpCommand -> SetParameterName ("filename", 1624 fpCommand -> SetParameterName ("filename", omitable = true); 1924 fpCommand -> SetDefaultValue (""); 1625 fpCommand -> SetDefaultValue (""); 1925 } 1626 } 1926 1627 1927 G4VisCommandViewerSave::~G4VisCommandViewerSa 1628 G4VisCommandViewerSave::~G4VisCommandViewerSave () { 1928 delete fpCommand; 1629 delete fpCommand; 1929 } 1630 } 1930 1631 1931 G4String G4VisCommandViewerSave::GetCurrentVa 1632 G4String G4VisCommandViewerSave::GetCurrentValue 1932 (G4UIcommand*) { 1633 (G4UIcommand*) { 1933 return ""; 1634 return ""; 1934 } 1635 } 1935 1636 1936 namespace { 1637 namespace { 1937 void WriteCommands 1638 void WriteCommands 1938 (std::ostream& os, 1639 (std::ostream& os, 1939 const G4ViewParameters& vp, 1640 const G4ViewParameters& vp, 1940 const G4Point3D& stp) // Standard Target 1641 const G4Point3D& stp) // Standard Target Point 1941 { 1642 { 1942 os 1643 os 1943 << vp.CameraAndLightingCommands(stp) 1644 << vp.CameraAndLightingCommands(stp) 1944 << vp.DrawingStyleCommands() 1645 << vp.DrawingStyleCommands() 1945 << vp.SceneModifyingCommands() 1646 << vp.SceneModifyingCommands() 1946 << vp.TouchableCommands() 1647 << vp.TouchableCommands() 1947 << vp.TimeWindowCommands() << 1948 << std::endl; 1648 << std::endl; 1949 } 1649 } 1950 } 1650 } 1951 1651 1952 void G4VisCommandViewerSave::SetNewValue (G4U 1652 void G4VisCommandViewerSave::SetNewValue (G4UIcommand*, G4String newValue) { 1953 1653 1954 G4VisManager::Verbosity verbosity = fpVisMa 1654 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); 1955 1655 1956 const G4VViewer* currentViewer = fpVisManag 1656 const G4VViewer* currentViewer = fpVisManager->GetCurrentViewer(); 1957 if (!currentViewer) { 1657 if (!currentViewer) { 1958 if (verbosity >= G4VisManager::errors) { 1658 if (verbosity >= G4VisManager::errors) { 1959 G4warn << << 1659 G4cerr << 1960 "ERROR: G4VisCommandsViewerSave::SetNew 1660 "ERROR: G4VisCommandsViewerSave::SetNewValue: no current viewer." 1961 << G4endl; 1661 << G4endl; 1962 } 1662 } 1963 return; 1663 return; 1964 } 1664 } 1965 1665 1966 const G4Scene* currentScene = currentViewer 1666 const G4Scene* currentScene = currentViewer->GetSceneHandler()->GetScene(); 1967 if (!currentScene) { 1667 if (!currentScene) { 1968 if (verbosity >= G4VisManager::errors) { 1668 if (verbosity >= G4VisManager::errors) { 1969 G4warn << << 1669 G4cerr << 1970 "ERROR: G4VisCommandsViewerSave::SetNew 1670 "ERROR: G4VisCommandsViewerSave::SetNewValue: no current scene." 1971 << G4endl; 1671 << G4endl; 1972 } 1672 } 1973 return; 1673 return; 1974 } 1674 } 1975 1675 1976 // Get view parameters and ther relevant in 1676 // Get view parameters and ther relevant information. 1977 G4ViewParameters vp = currentViewer->GetVie 1677 G4ViewParameters vp = currentViewer->GetViewParameters(); 1978 // Concatenate any private vis attributes m 1678 // Concatenate any private vis attributes modifiers... 1979 const std::vector<G4ModelingParameters::Vis 1679 const std::vector<G4ModelingParameters::VisAttributesModifier>* 1980 privateVAMs = currentViewer->GetPrivateVisA 1680 privateVAMs = currentViewer->GetPrivateVisAttributesModifiers(); 1981 if (privateVAMs) { 1681 if (privateVAMs) { 1982 std::vector<G4ModelingParameters::VisAttr 1682 std::vector<G4ModelingParameters::VisAttributesModifier>::const_iterator i; 1983 for (i = privateVAMs->begin(); i != priva 1683 for (i = privateVAMs->begin(); i != privateVAMs->end(); ++i) { 1984 vp.AddVisAttributesModifier(*i); 1684 vp.AddVisAttributesModifier(*i); 1985 } 1685 } 1986 } 1686 } 1987 const G4Point3D& stp = currentScene->GetSta 1687 const G4Point3D& stp = currentScene->GetStandardTargetPoint(); 1988 1688 1989 G4String filename = newValue; 1689 G4String filename = newValue; 1990 1690 1991 if (newValue.length() == 0) { 1691 if (newValue.length() == 0) { 1992 // Null filename - generate a filename 1692 // Null filename - generate a filename 1993 const G4int maxNoOfFiles = 100; 1693 const G4int maxNoOfFiles = 100; 1994 static G4int sequenceNumber = 0; 1694 static G4int sequenceNumber = 0; 1995 if (sequenceNumber >= maxNoOfFiles) { 1695 if (sequenceNumber >= maxNoOfFiles) { 1996 if (verbosity >= G4VisManager::errors) 1696 if (verbosity >= G4VisManager::errors) { 1997 G4warn << 1697 G4cerr 1998 << "ERROR: G4VisCommandsViewerSave::S 1698 << "ERROR: G4VisCommandsViewerSave::SetNewValue: Maximum number, " 1999 << maxNoOfFiles 1699 << maxNoOfFiles 2000 << ", of files exceeded." 1700 << ", of files exceeded." 2001 << G4endl; 1701 << G4endl; 2002 } 1702 } 2003 return; 1703 return; 2004 } 1704 } 2005 std::ostringstream oss; 1705 std::ostringstream oss; 2006 oss << std::setw(2) << std::setfill('0') 1706 oss << std::setw(2) << std::setfill('0') << sequenceNumber++; 2007 filename = "g4_" + oss.str() + ".g4view"; 1707 filename = "g4_" + oss.str() + ".g4view"; 2008 } 1708 } 2009 1709 2010 if (filename == "-") { 1710 if (filename == "-") { 2011 // Write to standard output 1711 // Write to standard output 2012 WriteCommands(G4cout,vp,stp); 1712 WriteCommands(G4cout,vp,stp); 2013 } else { 1713 } else { 2014 // Write to file - but add extension if n 1714 // Write to file - but add extension if not prescribed 2015 if (!G4StrUtil::contains(filename, '.')) << 1715 if (!filename.contains('.')) { 2016 // No extension supplied - add .g4view 1716 // No extension supplied - add .g4view 2017 filename += ".g4view"; 1717 filename += ".g4view"; 2018 } 1718 } 2019 std::ofstream ofs(filename); 1719 std::ofstream ofs(filename); 2020 if (!ofs) { 1720 if (!ofs) { 2021 if (verbosity >= G4VisManager::errors) 1721 if (verbosity >= G4VisManager::errors) { 2022 G4warn << << 1722 G4cerr << 2023 "ERROR: G4VisCommandsViewerSave::SetN 1723 "ERROR: G4VisCommandsViewerSave::SetNewValue: Trouble opening file \"" 2024 << filename << "\"." 1724 << filename << "\"." 2025 << G4endl; 1725 << G4endl; 2026 } 1726 } 2027 ofs.close(); 1727 ofs.close(); 2028 return; 1728 return; 2029 } 1729 } 2030 WriteCommands(ofs,vp,stp); 1730 WriteCommands(ofs,vp,stp); 2031 ofs.close(); 1731 ofs.close(); 2032 } 1732 } 2033 1733 2034 if (verbosity >= G4VisManager::warnings) { 1734 if (verbosity >= G4VisManager::warnings) { 2035 G4warn << "Viewer \"" << currentViewer -> << 1735 G4cout << "Viewer \"" << currentViewer -> GetName () 2036 << "\"" << " saved to "; 1736 << "\"" << " saved to "; 2037 if (filename == "-") { 1737 if (filename == "-") { 2038 G4warn << "G4cout."; << 1738 G4cout << "G4cout."; 2039 } else { 1739 } else { 2040 G4warn << "file \'" << filename << "\". << 1740 G4cout << "file \'" << filename << "\"." << 2041 "\n Read the view back into this or an 1741 "\n Read the view back into this or any viewer with" 2042 "\n \"/control/execute " << filename < 1742 "\n \"/control/execute " << filename << "\" or use" 2043 "\n \"/vis/viewer/interpolate\" if you 1743 "\n \"/vis/viewer/interpolate\" if you have several saved files -" 2044 "\n see \"help /vis/viewer/interpolate 1744 "\n see \"help /vis/viewer/interpolate\" for guidance."; 2045 } 1745 } 2046 G4warn << G4endl; << 1746 G4cout << G4endl; 2047 } 1747 } 2048 } 1748 } 2049 1749 2050 ////////////// /vis/viewer/scale and scaleTo 1750 ////////////// /vis/viewer/scale and scaleTo //////////////////////////// 2051 1751 2052 G4VisCommandViewerScale::G4VisCommandViewerSc 1752 G4VisCommandViewerScale::G4VisCommandViewerScale (): 2053 fScaleMultiplier (G4Vector3D (1., 1., 1.)), 1753 fScaleMultiplier (G4Vector3D (1., 1., 1.)), 2054 fScaleTo (G4Vector3D (1., 1., 1.)) 1754 fScaleTo (G4Vector3D (1., 1., 1.)) 2055 { 1755 { 2056 G4bool omitable, currentAsDefault; 1756 G4bool omitable, currentAsDefault; 2057 1757 2058 fpCommandScale = new G4UIcmdWith3Vector 1758 fpCommandScale = new G4UIcmdWith3Vector 2059 ("/vis/viewer/scale", this); 1759 ("/vis/viewer/scale", this); 2060 fpCommandScale -> SetGuidance ("Incremental 1760 fpCommandScale -> SetGuidance ("Incremental (non-uniform) scaling."); 2061 fpCommandScale -> SetGuidance 1761 fpCommandScale -> SetGuidance 2062 ("Multiplies components of current scalin 1762 ("Multiplies components of current scaling by components of this factor." 2063 "\n Scales (x,y,z) by corresponding comp 1763 "\n Scales (x,y,z) by corresponding components of the resulting factor."); 2064 fpCommandScale -> SetGuidance 1764 fpCommandScale -> SetGuidance 2065 (""); 1765 (""); 2066 fpCommandScale -> SetParameterName 1766 fpCommandScale -> SetParameterName 2067 ("x-scale-multiplier","y-scale-multiplier 1767 ("x-scale-multiplier","y-scale-multiplier","z-scale-multiplier", 2068 omitable=true, currentAsDefault=true); 1768 omitable=true, currentAsDefault=true); 2069 1769 2070 fpCommandScaleTo = new G4UIcmdWith3Vector 1770 fpCommandScaleTo = new G4UIcmdWith3Vector 2071 ("/vis/viewer/scaleTo", this); 1771 ("/vis/viewer/scaleTo", this); 2072 fpCommandScaleTo -> SetGuidance ("Absolute 1772 fpCommandScaleTo -> SetGuidance ("Absolute (non-uniform) scaling."); 2073 fpCommandScaleTo -> SetGuidance 1773 fpCommandScaleTo -> SetGuidance 2074 ("Scales (x,y,z) by corresponding compone 1774 ("Scales (x,y,z) by corresponding components of this factor."); 2075 fpCommandScaleTo -> SetParameterName 1775 fpCommandScaleTo -> SetParameterName 2076 ("x-scale-factor","y-scale-factor","z-sca 1776 ("x-scale-factor","y-scale-factor","z-scale-factor", 2077 omitable=true, currentAsDefault=true); 1777 omitable=true, currentAsDefault=true); 2078 } 1778 } 2079 1779 2080 G4VisCommandViewerScale::~G4VisCommandViewerS 1780 G4VisCommandViewerScale::~G4VisCommandViewerScale () { 2081 delete fpCommandScale; 1781 delete fpCommandScale; 2082 delete fpCommandScaleTo; 1782 delete fpCommandScaleTo; 2083 } 1783 } 2084 1784 2085 G4String G4VisCommandViewerScale::GetCurrentV 1785 G4String G4VisCommandViewerScale::GetCurrentValue (G4UIcommand* command) { 2086 G4String currentValue; 1786 G4String currentValue; 2087 if (command == fpCommandScale) { 1787 if (command == fpCommandScale) { 2088 currentValue = fpCommandScale->ConvertToS 1788 currentValue = fpCommandScale->ConvertToString(G4ThreeVector(fScaleMultiplier)); 2089 } 1789 } 2090 else if (command == fpCommandScaleTo) { 1790 else if (command == fpCommandScaleTo) { 2091 currentValue = fpCommandScaleTo->ConvertT 1791 currentValue = fpCommandScaleTo->ConvertToString(G4ThreeVector(fScaleTo)); 2092 } 1792 } 2093 return currentValue; 1793 return currentValue; 2094 } 1794 } 2095 1795 2096 void G4VisCommandViewerScale::SetNewValue (G4 1796 void G4VisCommandViewerScale::SetNewValue (G4UIcommand* command, 2097 G4String newValue) { 1797 G4String newValue) { 2098 1798 2099 1799 2100 G4VisManager::Verbosity verbosity = fpVisMa 1800 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); 2101 1801 2102 G4VViewer* currentViewer = fpVisManager->Ge 1802 G4VViewer* currentViewer = fpVisManager->GetCurrentViewer(); 2103 if (!currentViewer) { 1803 if (!currentViewer) { 2104 if (verbosity >= G4VisManager::errors) { 1804 if (verbosity >= G4VisManager::errors) { 2105 G4warn << << 1805 G4cerr << 2106 "ERROR: G4VisCommandsViewerScale::SetNewVal 1806 "ERROR: G4VisCommandsViewerScale::SetNewValue: no current viewer." 2107 << G4endl; 1807 << G4endl; 2108 } 1808 } 2109 return; 1809 return; 2110 } 1810 } 2111 1811 2112 G4ViewParameters vp = currentViewer->GetVie 1812 G4ViewParameters vp = currentViewer->GetViewParameters(); 2113 1813 2114 if (command == fpCommandScale) { 1814 if (command == fpCommandScale) { 2115 fScaleMultiplier = fpCommandScale->GetNew 1815 fScaleMultiplier = fpCommandScale->GetNew3VectorValue(newValue); 2116 vp.MultiplyScaleFactor(fScaleMultiplier); 1816 vp.MultiplyScaleFactor(fScaleMultiplier); 2117 } 1817 } 2118 else if (command == fpCommandScaleTo) { 1818 else if (command == fpCommandScaleTo) { 2119 fScaleTo = fpCommandScale->GetNew3VectorV 1819 fScaleTo = fpCommandScale->GetNew3VectorValue(newValue); 2120 vp.SetScaleFactor(fScaleTo); 1820 vp.SetScaleFactor(fScaleTo); 2121 } 1821 } 2122 1822 2123 if (verbosity >= G4VisManager::confirmation 1823 if (verbosity >= G4VisManager::confirmations) { 2124 G4cout << "Scale factor changed to " << v 1824 G4cout << "Scale factor changed to " << vp.GetScaleFactor() << G4endl; 2125 } 1825 } 2126 1826 2127 SetViewParameters(currentViewer, vp); 1827 SetViewParameters(currentViewer, vp); 2128 } 1828 } 2129 1829 2130 ////////////// /vis/viewer/select /////////// 1830 ////////////// /vis/viewer/select /////////////////////////////////////// 2131 1831 2132 G4VisCommandViewerSelect::G4VisCommandViewerS 1832 G4VisCommandViewerSelect::G4VisCommandViewerSelect () { 2133 G4bool omitable; 1833 G4bool omitable; 2134 fpCommand = new G4UIcmdWithAString ("/vis/v 1834 fpCommand = new G4UIcmdWithAString ("/vis/viewer/select", this); 2135 fpCommand -> SetGuidance ("Selects viewer." 1835 fpCommand -> SetGuidance ("Selects viewer."); 2136 fpCommand -> SetGuidance 1836 fpCommand -> SetGuidance 2137 ("Specify viewer by name. \"/vis/viewer/ 1837 ("Specify viewer by name. \"/vis/viewer/list\" to see possible viewers."); 2138 fpCommand -> SetParameterName ("viewer-name 1838 fpCommand -> SetParameterName ("viewer-name", omitable = false); 2139 } 1839 } 2140 1840 2141 G4VisCommandViewerSelect::~G4VisCommandViewer 1841 G4VisCommandViewerSelect::~G4VisCommandViewerSelect () { 2142 delete fpCommand; 1842 delete fpCommand; 2143 } 1843 } 2144 1844 2145 G4String G4VisCommandViewerSelect::GetCurrent 1845 G4String G4VisCommandViewerSelect::GetCurrentValue (G4UIcommand*) { 2146 return ""; 1846 return ""; 2147 } 1847 } 2148 1848 2149 void G4VisCommandViewerSelect::SetNewValue (G 1849 void G4VisCommandViewerSelect::SetNewValue (G4UIcommand*, G4String newValue) { 2150 1850 2151 G4VisManager::Verbosity verbosity = fpVisMa 1851 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); 2152 1852 2153 G4String& selectName = newValue; 1853 G4String& selectName = newValue; 2154 G4VViewer* viewer = fpVisManager -> GetView 1854 G4VViewer* viewer = fpVisManager -> GetViewer (selectName); 2155 1855 2156 if (!viewer) { 1856 if (!viewer) { 2157 if (verbosity >= G4VisManager::errors) { 1857 if (verbosity >= G4VisManager::errors) { 2158 G4warn << "ERROR: Viewer \"" << selectN << 1858 G4cerr << "ERROR: Viewer \"" << selectName << "\""; 2159 G4warn << " not found - \"/vis/viewer/l << 1859 G4cerr << " not found - \"/vis/viewer/list\"" 2160 "\n to see possibilities." 1860 "\n to see possibilities." 2161 << G4endl; 1861 << G4endl; 2162 } 1862 } 2163 return; 1863 return; 2164 } 1864 } 2165 1865 2166 if (viewer == fpVisManager -> GetCurrentVie 1866 if (viewer == fpVisManager -> GetCurrentViewer ()) { 2167 if (verbosity >= G4VisManager::warnings) 1867 if (verbosity >= G4VisManager::warnings) { 2168 G4warn << "WARNING: Viewer \"" << viewe << 1868 G4cout << "WARNING: Viewer \"" << viewer -> GetName () << "\"" 2169 << " already selected." << G4endl; 1869 << " already selected." << G4endl; 2170 } 1870 } 2171 return; 1871 return; 2172 } 1872 } 2173 1873 2174 // Set pointers, call SetView and print con 1874 // Set pointers, call SetView and print confirmation. 2175 fpVisManager -> SetCurrentViewer (viewer); 1875 fpVisManager -> SetCurrentViewer (viewer); 2176 1876 2177 RefreshIfRequired(viewer); 1877 RefreshIfRequired(viewer); 2178 << 2179 // Update GUI scene tree (make sure it's in << 2180 viewer->UpdateGUISceneTree(); << 2181 } 1878 } 2182 1879 2183 ////////////// /vis/viewer/update /////////// 1880 ////////////// /vis/viewer/update /////////////////////////////////////// 2184 1881 2185 G4VisCommandViewerUpdate::G4VisCommandViewerU 1882 G4VisCommandViewerUpdate::G4VisCommandViewerUpdate () { 2186 G4bool omitable, currentAsDefault; 1883 G4bool omitable, currentAsDefault; 2187 fpCommand = new G4UIcmdWithAString ("/vis/v 1884 fpCommand = new G4UIcmdWithAString ("/vis/viewer/update", this); 2188 fpCommand -> SetGuidance 1885 fpCommand -> SetGuidance 2189 ("Triggers graphical database post-proces 1886 ("Triggers graphical database post-processing for viewers" 2190 "\nusing that technique."); 1887 "\nusing that technique."); 2191 fpCommand -> SetGuidance 1888 fpCommand -> SetGuidance 2192 ("For such viewers the view only becomes 1889 ("For such viewers the view only becomes visible with this command." 2193 "\nBy default, acts on current viewer. 1890 "\nBy default, acts on current viewer. \"/vis/viewer/list\"" 2194 "\nto see possible viewers. Viewer beco 1891 "\nto see possible viewers. Viewer becomes current."); 2195 fpCommand -> SetParameterName ("viewer-name 1892 fpCommand -> SetParameterName ("viewer-name", 2196 omitable = true, 1893 omitable = true, 2197 currentAsDefault = true); 1894 currentAsDefault = true); 2198 } 1895 } 2199 1896 2200 G4VisCommandViewerUpdate::~G4VisCommandViewer 1897 G4VisCommandViewerUpdate::~G4VisCommandViewerUpdate () { 2201 delete fpCommand; 1898 delete fpCommand; 2202 } 1899 } 2203 1900 2204 G4String G4VisCommandViewerUpdate::GetCurrent 1901 G4String G4VisCommandViewerUpdate::GetCurrentValue (G4UIcommand*) { 2205 G4VViewer* viewer = fpVisManager -> GetCurr 1902 G4VViewer* viewer = fpVisManager -> GetCurrentViewer (); 2206 if (viewer) { 1903 if (viewer) { 2207 return viewer -> GetName (); 1904 return viewer -> GetName (); 2208 } 1905 } 2209 else { 1906 else { 2210 return "none"; 1907 return "none"; 2211 } 1908 } 2212 } 1909 } 2213 1910 2214 void G4VisCommandViewerUpdate::SetNewValue (G 1911 void G4VisCommandViewerUpdate::SetNewValue (G4UIcommand*, G4String newValue) { 2215 1912 2216 G4VisManager::Verbosity verbosity = fpVisMa 1913 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); 2217 1914 2218 G4String& updateName = newValue; 1915 G4String& updateName = newValue; 2219 1916 2220 G4VViewer* viewer = fpVisManager -> GetView 1917 G4VViewer* viewer = fpVisManager -> GetViewer (updateName); 2221 if (!viewer) { 1918 if (!viewer) { 2222 if (verbosity >= G4VisManager::errors) { 1919 if (verbosity >= G4VisManager::errors) { 2223 G4warn << << 1920 G4cout << 2224 "WARNING: command \"/vis/viewer/update\" co 1921 "WARNING: command \"/vis/viewer/update\" could not be applied: no current viewer." 2225 << G4endl; 1922 << G4endl; 2226 } 1923 } 2227 return; 1924 return; 2228 } 1925 } 2229 1926 2230 G4VSceneHandler* sceneHandler = viewer->Get 1927 G4VSceneHandler* sceneHandler = viewer->GetSceneHandler(); 2231 if (!sceneHandler) { 1928 if (!sceneHandler) { 2232 if (verbosity >= G4VisManager::errors) { 1929 if (verbosity >= G4VisManager::errors) { 2233 G4warn << "ERROR: Viewer \"" << updateN << 1930 G4cerr << "ERROR: Viewer \"" << updateName << "\"" << 2234 " has no scene handler - report serious bug 1931 " has no scene handler - report serious bug." 2235 << G4endl; 1932 << G4endl; 2236 } 1933 } 2237 return; 1934 return; 2238 } 1935 } 2239 1936 2240 G4Scene* scene = sceneHandler->GetScene(); 1937 G4Scene* scene = sceneHandler->GetScene(); 2241 if (!scene) { 1938 if (!scene) { 2242 if (verbosity >= G4VisManager::confirmati 1939 if (verbosity >= G4VisManager::confirmations) { 2243 G4cout << "NOTE: SceneHandler \"" << sc 1940 G4cout << "NOTE: SceneHandler \"" << sceneHandler->GetName() 2244 << "\", to which viewer \"" << updateN 1941 << "\", to which viewer \"" << updateName << "\"" << 2245 "\n is attached, has no scene - \"/vis/sce 1942 "\n is attached, has no scene - \"/vis/scene/create\" and" 2246 " \"/vis/sceneHandler/attach\"" 1943 " \"/vis/sceneHandler/attach\"" 2247 "\n (or use compound command \"/vis/drawVo 1944 "\n (or use compound command \"/vis/drawVolume\")." 2248 << G4endl; 1945 << G4endl; 2249 } 1946 } 2250 return; 1947 return; 2251 } 1948 } 2252 1949 2253 if (verbosity >= G4VisManager::confirmation 1950 if (verbosity >= G4VisManager::confirmations) { 2254 G4cout << "Viewer \"" << viewer -> GetNam 1951 G4cout << "Viewer \"" << viewer -> GetName () << "\""; 2255 G4cout << " post-processing triggered." < 1952 G4cout << " post-processing triggered." << G4endl; 2256 } 1953 } 2257 viewer -> ShowView (); 1954 viewer -> ShowView (); 2258 // Assume future need to "refresh" transien 1955 // Assume future need to "refresh" transients... 2259 sceneHandler -> SetMarkForClearingTransient 1956 sceneHandler -> SetMarkForClearingTransientStore(true); 2260 } 1957 } 2261 1958 2262 ////////////// /vis/viewer/zoom and zoomTo // 1959 ////////////// /vis/viewer/zoom and zoomTo //////////////////////////// 2263 1960 2264 G4VisCommandViewerZoom::G4VisCommandViewerZoo 1961 G4VisCommandViewerZoom::G4VisCommandViewerZoom (): 2265 fZoomMultiplier (1.), 1962 fZoomMultiplier (1.), 2266 fZoomTo (1.) 1963 fZoomTo (1.) 2267 { 1964 { 2268 G4bool omitable, currentAsDefault; 1965 G4bool omitable, currentAsDefault; 2269 1966 2270 fpCommandZoom = new G4UIcmdWithADouble 1967 fpCommandZoom = new G4UIcmdWithADouble 2271 ("/vis/viewer/zoom", this); 1968 ("/vis/viewer/zoom", this); 2272 fpCommandZoom -> SetGuidance ("Incremental 1969 fpCommandZoom -> SetGuidance ("Incremental zoom."); 2273 fpCommandZoom -> SetGuidance 1970 fpCommandZoom -> SetGuidance 2274 ("Multiplies current magnification by thi 1971 ("Multiplies current magnification by this factor."); 2275 fpCommandZoom -> SetParameterName("multipli 1972 fpCommandZoom -> SetParameterName("multiplier", 2276 omitable=true, 1973 omitable=true, 2277 currentAsDefault=true); 1974 currentAsDefault=true); 2278 1975 2279 fpCommandZoomTo = new G4UIcmdWithADouble 1976 fpCommandZoomTo = new G4UIcmdWithADouble 2280 ("/vis/viewer/zoomTo", this); 1977 ("/vis/viewer/zoomTo", this); 2281 fpCommandZoomTo -> SetGuidance ("Absolute z 1978 fpCommandZoomTo -> SetGuidance ("Absolute zoom."); 2282 fpCommandZoomTo -> SetGuidance 1979 fpCommandZoomTo -> SetGuidance 2283 ("Magnifies standard magnification by thi 1980 ("Magnifies standard magnification by this factor."); 2284 fpCommandZoomTo -> SetParameterName("factor 1981 fpCommandZoomTo -> SetParameterName("factor", 2285 omitable=true, 1982 omitable=true, 2286 currentAsDefault=true); 1983 currentAsDefault=true); 2287 } 1984 } 2288 1985 2289 G4VisCommandViewerZoom::~G4VisCommandViewerZo 1986 G4VisCommandViewerZoom::~G4VisCommandViewerZoom () { 2290 delete fpCommandZoom; 1987 delete fpCommandZoom; 2291 delete fpCommandZoomTo; 1988 delete fpCommandZoomTo; 2292 } 1989 } 2293 1990 2294 G4String G4VisCommandViewerZoom::GetCurrentVa 1991 G4String G4VisCommandViewerZoom::GetCurrentValue (G4UIcommand* command) { 2295 G4String currentValue; 1992 G4String currentValue; 2296 if (command == fpCommandZoom) { 1993 if (command == fpCommandZoom) { 2297 currentValue = fpCommandZoom->ConvertToSt 1994 currentValue = fpCommandZoom->ConvertToString(fZoomMultiplier); 2298 } 1995 } 2299 else if (command == fpCommandZoomTo) { 1996 else if (command == fpCommandZoomTo) { 2300 currentValue = fpCommandZoomTo->ConvertTo 1997 currentValue = fpCommandZoomTo->ConvertToString(fZoomTo); 2301 } 1998 } 2302 return currentValue; 1999 return currentValue; 2303 } 2000 } 2304 2001 2305 void G4VisCommandViewerZoom::SetNewValue (G4U 2002 void G4VisCommandViewerZoom::SetNewValue (G4UIcommand* command, 2306 G4String newValue) { 2003 G4String newValue) { 2307 2004 2308 2005 2309 G4VisManager::Verbosity verbosity = fpVisMa 2006 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); 2310 2007 2311 G4VViewer* currentViewer = fpVisManager->Ge 2008 G4VViewer* currentViewer = fpVisManager->GetCurrentViewer(); 2312 if (!currentViewer) { 2009 if (!currentViewer) { 2313 if (verbosity >= G4VisManager::errors) { 2010 if (verbosity >= G4VisManager::errors) { 2314 G4warn << << 2011 G4cerr << 2315 "ERROR: G4VisCommandsViewerZoom::SetNewValu 2012 "ERROR: G4VisCommandsViewerZoom::SetNewValue: no current viewer." 2316 << G4endl; 2013 << G4endl; 2317 } 2014 } 2318 return; 2015 return; 2319 } 2016 } 2320 2017 2321 G4ViewParameters vp = currentViewer->GetVie 2018 G4ViewParameters vp = currentViewer->GetViewParameters(); 2322 2019 2323 if (command == fpCommandZoom) { 2020 if (command == fpCommandZoom) { 2324 fZoomMultiplier = fpCommandZoom->GetNewDo 2021 fZoomMultiplier = fpCommandZoom->GetNewDoubleValue(newValue); 2325 vp.MultiplyZoomFactor(fZoomMultiplier); 2022 vp.MultiplyZoomFactor(fZoomMultiplier); 2326 } 2023 } 2327 else if (command == fpCommandZoomTo) { 2024 else if (command == fpCommandZoomTo) { 2328 fZoomTo = fpCommandZoom->GetNewDoubleValu 2025 fZoomTo = fpCommandZoom->GetNewDoubleValue(newValue); 2329 vp.SetZoomFactor(fZoomTo); 2026 vp.SetZoomFactor(fZoomTo); 2330 } 2027 } 2331 2028 2332 if (verbosity >= G4VisManager::confirmation 2029 if (verbosity >= G4VisManager::confirmations) { 2333 G4cout << "Zoom factor changed to " << vp 2030 G4cout << "Zoom factor changed to " << vp.GetZoomFactor() << G4endl; 2334 } 2031 } 2335 2032 2336 SetViewParameters(currentViewer, vp); 2033 SetViewParameters(currentViewer, vp); 2337 } 2034 } 2338 2035