| 1 | //
|
|---|
| 2 | // ********************************************************************
|
|---|
| 3 | // * License and Disclaimer *
|
|---|
| 4 | // * *
|
|---|
| 5 | // * The Geant4 software is copyright of the Copyright Holders of *
|
|---|
| 6 | // * the Geant4 Collaboration. It is provided under the terms and *
|
|---|
| 7 | // * conditions of the Geant4 Software License, included in the file *
|
|---|
| 8 | // * LICENSE and available at http://cern.ch/geant4/license . These *
|
|---|
| 9 | // * include a list of copyright holders. *
|
|---|
| 10 | // * *
|
|---|
| 11 | // * Neither the authors of this software system, nor their employing *
|
|---|
| 12 | // * institutes,nor the agencies providing financial support for this *
|
|---|
| 13 | // * work make any representation or warranty, express or implied, *
|
|---|
| 14 | // * regarding this software system or assume any liability for its *
|
|---|
| 15 | // * use. Please see the license in the file LICENSE and URL above *
|
|---|
| 16 | // * for the full disclaimer and the limitation of liability. *
|
|---|
| 17 | // * *
|
|---|
| 18 | // * This code implementation is the result of the scientific and *
|
|---|
| 19 | // * technical work of the GEANT4 collaboration. *
|
|---|
| 20 | // * By using, copying, modifying or distributing the software (or *
|
|---|
| 21 | // * any work based on the software) you agree to acknowledge its *
|
|---|
| 22 | // * use in resulting scientific publications, and indicate your *
|
|---|
| 23 | // * acceptance of all terms of the Geant4 Software license. *
|
|---|
| 24 | // ********************************************************************
|
|---|
| 25 | //
|
|---|
| 26 | //
|
|---|
| 27 | // $Id: G4VisCommandsViewer.cc,v 1.76 2010/05/29 21:20:20 allison Exp $
|
|---|
| 28 | // GEANT4 tag $Name: $
|
|---|
| 29 |
|
|---|
| 30 | // /vis/viewer commands - John Allison 25th October 1998
|
|---|
| 31 |
|
|---|
| 32 | #include "G4VisCommandsViewer.hh"
|
|---|
| 33 |
|
|---|
| 34 | #include "G4VisManager.hh"
|
|---|
| 35 | #include "G4GraphicsSystemList.hh"
|
|---|
| 36 | #include "G4VisCommandsScene.hh"
|
|---|
| 37 | #include "G4UImanager.hh"
|
|---|
| 38 | #include "G4UIcommand.hh"
|
|---|
| 39 | #include "G4UIcmdWithoutParameter.hh"
|
|---|
| 40 | #include "G4UIcmdWithAString.hh"
|
|---|
| 41 | #include "G4UIcmdWithADouble.hh"
|
|---|
| 42 | #include "G4UIcmdWithADoubleAndUnit.hh"
|
|---|
| 43 | #include "G4UIcmdWith3Vector.hh"
|
|---|
| 44 | #include "G4UnitsTable.hh"
|
|---|
| 45 | #include "G4ios.hh"
|
|---|
| 46 | #include <sstream>
|
|---|
| 47 |
|
|---|
| 48 | G4VVisCommandViewer::G4VVisCommandViewer () {}
|
|---|
| 49 |
|
|---|
| 50 | G4VVisCommandViewer::~G4VVisCommandViewer () {}
|
|---|
| 51 |
|
|---|
| 52 | void G4VVisCommandViewer::SetViewParameters
|
|---|
| 53 | (G4VViewer* viewer, const G4ViewParameters& viewParams) {
|
|---|
| 54 | G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
|
|---|
| 55 | viewer->SetViewParameters(viewParams);
|
|---|
| 56 | G4VSceneHandler* sceneHandler = viewer->GetSceneHandler();
|
|---|
| 57 | if (sceneHandler && sceneHandler->GetScene()) {
|
|---|
| 58 | if (viewParams.IsAutoRefresh()) {
|
|---|
| 59 | G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/refresh");
|
|---|
| 60 | }
|
|---|
| 61 | else {
|
|---|
| 62 | if (verbosity >= G4VisManager::confirmations) {
|
|---|
| 63 | G4cout << "Issue /vis/viewer/refresh to see effect." << G4endl;
|
|---|
| 64 | }
|
|---|
| 65 | }
|
|---|
| 66 | }
|
|---|
| 67 | }
|
|---|
| 68 |
|
|---|
| 69 | ////////////// /vis/viewer/addCutawayPlane ///////////////////////////////////////
|
|---|
| 70 |
|
|---|
| 71 | G4VisCommandViewerAddCutawayPlane::G4VisCommandViewerAddCutawayPlane () {
|
|---|
| 72 | G4bool omitable;
|
|---|
| 73 | fpCommand = new G4UIcommand ("/vis/viewer/addCutawayPlane", this);
|
|---|
| 74 | fpCommand -> SetGuidance
|
|---|
| 75 | ("Add cutaway plane to current viewer.");
|
|---|
| 76 | G4UIparameter* parameter;
|
|---|
| 77 | parameter = new G4UIparameter("x",'d',omitable = true);
|
|---|
| 78 | parameter -> SetDefaultValue (0);
|
|---|
| 79 | parameter -> SetGuidance ("Coordinate of point on the plane.");
|
|---|
| 80 | fpCommand->SetParameter(parameter);
|
|---|
| 81 | parameter = new G4UIparameter("y",'d',omitable = true);
|
|---|
| 82 | parameter -> SetDefaultValue (0);
|
|---|
| 83 | parameter -> SetGuidance ("Coordinate of point on the plane.");
|
|---|
| 84 | fpCommand->SetParameter(parameter);
|
|---|
| 85 | parameter = new G4UIparameter("z",'d',omitable = true);
|
|---|
| 86 | parameter -> SetDefaultValue (0);
|
|---|
| 87 | parameter -> SetGuidance ("Coordinate of point on the plane.");
|
|---|
| 88 | fpCommand->SetParameter(parameter);
|
|---|
| 89 | parameter = new G4UIparameter("unit",'s',omitable = true);
|
|---|
| 90 | parameter -> SetDefaultValue ("m");
|
|---|
| 91 | parameter -> SetGuidance ("Unit of point on the plane.");
|
|---|
| 92 | fpCommand->SetParameter(parameter);
|
|---|
| 93 | parameter = new G4UIparameter("nx",'d',omitable = true);
|
|---|
| 94 | parameter -> SetDefaultValue (1);
|
|---|
| 95 | parameter -> SetGuidance ("Component of plane normal.");
|
|---|
| 96 | fpCommand->SetParameter(parameter);
|
|---|
| 97 | parameter = new G4UIparameter("ny",'d',omitable = true);
|
|---|
| 98 | parameter -> SetDefaultValue (0);
|
|---|
| 99 | parameter -> SetGuidance ("Component of plane normal.");
|
|---|
| 100 | fpCommand->SetParameter(parameter);
|
|---|
| 101 | parameter = new G4UIparameter("nz",'d',omitable = true);
|
|---|
| 102 | parameter -> SetDefaultValue (0);
|
|---|
| 103 | parameter -> SetGuidance ("Component of plane normal.");
|
|---|
| 104 | fpCommand->SetParameter(parameter);
|
|---|
| 105 | }
|
|---|
| 106 |
|
|---|
| 107 | G4VisCommandViewerAddCutawayPlane::~G4VisCommandViewerAddCutawayPlane () {
|
|---|
| 108 | delete fpCommand;
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 | G4String G4VisCommandViewerAddCutawayPlane::GetCurrentValue (G4UIcommand*) {
|
|---|
| 112 | return "";
|
|---|
| 113 | }
|
|---|
| 114 |
|
|---|
| 115 | void G4VisCommandViewerAddCutawayPlane::SetNewValue (G4UIcommand*, G4String newValue) {
|
|---|
| 116 |
|
|---|
| 117 | G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
|
|---|
| 118 |
|
|---|
| 119 | G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
|
|---|
| 120 | if (!viewer) {
|
|---|
| 121 | if (verbosity >= G4VisManager::errors) {
|
|---|
| 122 | G4cout <<
|
|---|
| 123 | "ERROR: No current viewer - \"/vis/viewer/list\" to see possibilities."
|
|---|
| 124 | << G4endl;
|
|---|
| 125 | }
|
|---|
| 126 | return;
|
|---|
| 127 | }
|
|---|
| 128 |
|
|---|
| 129 | G4double x, y, z, nx, ny, nz;
|
|---|
| 130 | G4String unit;
|
|---|
| 131 | std::istringstream is (newValue);
|
|---|
| 132 | is >> x >> y >> z >> unit >> nx >> ny >> nz;
|
|---|
| 133 | G4double F = G4UIcommand::ValueOf(unit);
|
|---|
| 134 | x *= F; y *= F; z *= F;
|
|---|
| 135 |
|
|---|
| 136 | G4ViewParameters vp = viewer->GetViewParameters();
|
|---|
| 137 | vp.AddCutawayPlane(G4Plane3D(G4Normal3D(nx,ny,nz), G4Point3D(x,y,z)));
|
|---|
| 138 | if (verbosity >= G4VisManager::confirmations) {
|
|---|
| 139 | G4cout << "Cutaway planes for viewer \"" << viewer->GetName() << "\" now:";
|
|---|
| 140 | const G4Planes& cutaways = vp.GetCutawayPlanes();
|
|---|
| 141 | for (size_t i = 0; i < cutaways.size(); ++i)
|
|---|
| 142 | G4cout << "\n " << i << ": " << cutaways[i];
|
|---|
| 143 | G4cout << G4endl;
|
|---|
| 144 | }
|
|---|
| 145 |
|
|---|
| 146 | SetViewParameters(viewer, vp);
|
|---|
| 147 | }
|
|---|
| 148 |
|
|---|
| 149 | ////////////// /vis/viewer/changeCutawayPlane ///////////////////////////////////////
|
|---|
| 150 |
|
|---|
| 151 | G4VisCommandViewerChangeCutawayPlane::G4VisCommandViewerChangeCutawayPlane () {
|
|---|
| 152 | G4bool omitable;
|
|---|
| 153 | fpCommand = new G4UIcommand ("/vis/viewer/changeCutawayPlane", this);
|
|---|
| 154 | fpCommand -> SetGuidance("Change cutaway plane.");
|
|---|
| 155 | G4UIparameter* parameter;
|
|---|
| 156 | parameter = new G4UIparameter("index",'i',omitable = false);
|
|---|
| 157 | parameter -> SetGuidance ("Index of plane: 0, 1, 2.");
|
|---|
| 158 | fpCommand->SetParameter(parameter);
|
|---|
| 159 | parameter = new G4UIparameter("x",'d',omitable = true);
|
|---|
| 160 | parameter -> SetDefaultValue (0);
|
|---|
| 161 | parameter -> SetGuidance ("Coordinate of point on the plane.");
|
|---|
| 162 | fpCommand->SetParameter(parameter);
|
|---|
| 163 | parameter = new G4UIparameter("y",'d',omitable = true);
|
|---|
| 164 | parameter -> SetDefaultValue (0);
|
|---|
| 165 | parameter -> SetGuidance ("Coordinate of point on the plane.");
|
|---|
| 166 | fpCommand->SetParameter(parameter);
|
|---|
| 167 | parameter = new G4UIparameter("z",'d',omitable = true);
|
|---|
| 168 | parameter -> SetDefaultValue (0);
|
|---|
| 169 | parameter -> SetGuidance ("Coordinate of point on the plane.");
|
|---|
| 170 | fpCommand->SetParameter(parameter);
|
|---|
| 171 | parameter = new G4UIparameter("unit",'s',omitable = true);
|
|---|
| 172 | parameter -> SetDefaultValue ("m");
|
|---|
| 173 | parameter -> SetGuidance ("Unit of point on the plane.");
|
|---|
| 174 | fpCommand->SetParameter(parameter);
|
|---|
| 175 | parameter = new G4UIparameter("nx",'d',omitable = true);
|
|---|
| 176 | parameter -> SetDefaultValue (1);
|
|---|
| 177 | parameter -> SetGuidance ("Component of plane normal.");
|
|---|
| 178 | fpCommand->SetParameter(parameter);
|
|---|
| 179 | parameter = new G4UIparameter("ny",'d',omitable = true);
|
|---|
| 180 | parameter -> SetDefaultValue (0);
|
|---|
| 181 | parameter -> SetGuidance ("Component of plane normal.");
|
|---|
| 182 | fpCommand->SetParameter(parameter);
|
|---|
| 183 | parameter = new G4UIparameter("nz",'d',omitable = true);
|
|---|
| 184 | parameter -> SetDefaultValue (0);
|
|---|
| 185 | parameter -> SetGuidance ("Component of plane normal.");
|
|---|
| 186 | fpCommand->SetParameter(parameter);
|
|---|
| 187 | }
|
|---|
| 188 |
|
|---|
| 189 | G4VisCommandViewerChangeCutawayPlane::~G4VisCommandViewerChangeCutawayPlane () {
|
|---|
| 190 | delete fpCommand;
|
|---|
| 191 | }
|
|---|
| 192 |
|
|---|
| 193 | G4String G4VisCommandViewerChangeCutawayPlane::GetCurrentValue (G4UIcommand*) {
|
|---|
| 194 | return "";
|
|---|
| 195 | }
|
|---|
| 196 |
|
|---|
| 197 | void G4VisCommandViewerChangeCutawayPlane::SetNewValue (G4UIcommand*, G4String newValue) {
|
|---|
| 198 |
|
|---|
| 199 | G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
|
|---|
| 200 |
|
|---|
| 201 | G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
|
|---|
| 202 | if (!viewer) {
|
|---|
| 203 | if (verbosity >= G4VisManager::errors) {
|
|---|
| 204 | G4cout <<
|
|---|
| 205 | "ERROR: No current viewer - \"/vis/viewer/list\" to see possibilities."
|
|---|
| 206 | << G4endl;
|
|---|
| 207 | }
|
|---|
| 208 | return;
|
|---|
| 209 | }
|
|---|
| 210 |
|
|---|
| 211 | size_t index;
|
|---|
| 212 | G4double x, y, z, nx, ny, nz;
|
|---|
| 213 | G4String unit;
|
|---|
| 214 | std::istringstream is (newValue);
|
|---|
| 215 | is >> index >> x >> y >> z >> unit >> nx >> ny >> nz;
|
|---|
| 216 | G4double F = G4UIcommand::ValueOf(unit);
|
|---|
| 217 | x *= F; y *= F; z *= F;
|
|---|
| 218 |
|
|---|
| 219 | G4ViewParameters vp = viewer->GetViewParameters();
|
|---|
| 220 | vp.ChangeCutawayPlane(index,
|
|---|
| 221 | G4Plane3D(G4Normal3D(nx,ny,nz), G4Point3D(x,y,z)));
|
|---|
| 222 | if (verbosity >= G4VisManager::confirmations) {
|
|---|
| 223 | G4cout << "Cutaway planes for viewer \"" << viewer->GetName() << "\" now:";
|
|---|
| 224 | const G4Planes& cutaways = vp.GetCutawayPlanes();
|
|---|
| 225 | for (size_t i = 0; i < cutaways.size(); ++i)
|
|---|
| 226 | G4cout << "\n " << i << ": " << cutaways[i];
|
|---|
| 227 | G4cout << G4endl;
|
|---|
| 228 | }
|
|---|
| 229 |
|
|---|
| 230 | SetViewParameters(viewer, vp);
|
|---|
| 231 | }
|
|---|
| 232 |
|
|---|
| 233 | ////////////// /vis/viewer/clear ///////////////////////////////////////
|
|---|
| 234 |
|
|---|
| 235 | G4VisCommandViewerClear::G4VisCommandViewerClear () {
|
|---|
| 236 | G4bool omitable, currentAsDefault;
|
|---|
| 237 | fpCommand = new G4UIcmdWithAString ("/vis/viewer/clear", this);
|
|---|
| 238 | fpCommand -> SetGuidance ("Clears viewer.");
|
|---|
| 239 | fpCommand -> SetGuidance
|
|---|
| 240 | ("By default, clears current viewer. Specified viewer becomes current."
|
|---|
| 241 | "\n\"/vis/viewer/list\" to see possible viewer names.");
|
|---|
| 242 | fpCommand -> SetParameterName ("viewer-name",
|
|---|
| 243 | omitable = true,
|
|---|
| 244 | currentAsDefault = true);
|
|---|
| 245 | }
|
|---|
| 246 |
|
|---|
| 247 | G4VisCommandViewerClear::~G4VisCommandViewerClear () {
|
|---|
| 248 | delete fpCommand;
|
|---|
| 249 | }
|
|---|
| 250 |
|
|---|
| 251 | G4String G4VisCommandViewerClear::GetCurrentValue (G4UIcommand*) {
|
|---|
| 252 | G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
|
|---|
| 253 | return viewer ? viewer -> GetName () : G4String("none");
|
|---|
| 254 | }
|
|---|
| 255 |
|
|---|
| 256 | void G4VisCommandViewerClear::SetNewValue (G4UIcommand*, G4String newValue) {
|
|---|
| 257 |
|
|---|
| 258 | G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
|
|---|
| 259 |
|
|---|
| 260 | G4String& clearName = newValue;
|
|---|
| 261 | G4VViewer* viewer = fpVisManager -> GetViewer (clearName);
|
|---|
| 262 | if (!viewer) {
|
|---|
| 263 | if (verbosity >= G4VisManager::errors) {
|
|---|
| 264 | G4cout << "ERROR: Viewer \"" << clearName
|
|---|
| 265 | << "\" not found - \"/vis/viewer/list\" to see possibilities."
|
|---|
| 266 | << G4endl;
|
|---|
| 267 | }
|
|---|
| 268 | return;
|
|---|
| 269 | }
|
|---|
| 270 |
|
|---|
| 271 | viewer->ClearView();
|
|---|
| 272 | viewer->FinishView();
|
|---|
| 273 | if (verbosity >= G4VisManager::confirmations) {
|
|---|
| 274 | G4cout << "Viewer \"" << clearName << "\" cleared." << G4endl;
|
|---|
| 275 | }
|
|---|
| 276 |
|
|---|
| 277 | }
|
|---|
| 278 |
|
|---|
| 279 | ////////////// /vis/viewer/clearCutawayPlanes ///////////////////////////////////////
|
|---|
| 280 |
|
|---|
| 281 | G4VisCommandViewerClearCutawayPlanes::G4VisCommandViewerClearCutawayPlanes () {
|
|---|
| 282 | fpCommand = new G4UIcmdWithoutParameter
|
|---|
| 283 | ("/vis/viewer/clearCutawayPlanes", this);
|
|---|
| 284 | fpCommand -> SetGuidance ("Clear cutaway planes of current viewer.");
|
|---|
| 285 | }
|
|---|
| 286 |
|
|---|
| 287 | G4VisCommandViewerClearCutawayPlanes::~G4VisCommandViewerClearCutawayPlanes () {
|
|---|
| 288 | delete fpCommand;
|
|---|
| 289 | }
|
|---|
| 290 |
|
|---|
| 291 | G4String G4VisCommandViewerClearCutawayPlanes::GetCurrentValue (G4UIcommand*) {
|
|---|
| 292 | return "";
|
|---|
| 293 | }
|
|---|
| 294 |
|
|---|
| 295 | void G4VisCommandViewerClearCutawayPlanes::SetNewValue (G4UIcommand*, G4String) {
|
|---|
| 296 |
|
|---|
| 297 | G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
|
|---|
| 298 |
|
|---|
| 299 | G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
|
|---|
| 300 | if (!viewer) {
|
|---|
| 301 | if (verbosity >= G4VisManager::errors) {
|
|---|
| 302 | G4cout <<
|
|---|
| 303 | "ERROR: No current viewer - \"/vis/viewer/list\" to see possibilities."
|
|---|
| 304 | << G4endl;
|
|---|
| 305 | }
|
|---|
| 306 | return;
|
|---|
| 307 | }
|
|---|
| 308 |
|
|---|
| 309 | G4ViewParameters vp = viewer->GetViewParameters();
|
|---|
| 310 | vp.ClearCutawayPlanes();
|
|---|
| 311 | if (verbosity >= G4VisManager::confirmations) {
|
|---|
| 312 | G4cout << "Cutaway planes for viewer \"" << viewer->GetName()
|
|---|
| 313 | << "\" now cleared." << G4endl;
|
|---|
| 314 | }
|
|---|
| 315 |
|
|---|
| 316 | SetViewParameters(viewer, vp);
|
|---|
| 317 | }
|
|---|
| 318 |
|
|---|
| 319 | ////////////// /vis/viewer/clearTransients //////////////////////////
|
|---|
| 320 |
|
|---|
| 321 | G4VisCommandViewerClearTransients::G4VisCommandViewerClearTransients () {
|
|---|
| 322 | G4bool omitable, currentAsDefault;
|
|---|
| 323 | fpCommand = new G4UIcmdWithAString ("/vis/viewer/clearTransients", this);
|
|---|
| 324 | fpCommand -> SetGuidance ("Clears transients from viewer.");
|
|---|
| 325 | fpCommand -> SetGuidance
|
|---|
| 326 | ("By default, operates on current viewer. Specified viewer becomes current."
|
|---|
| 327 | "\n\"/vis/viewer/list\" to see possible viewer names.");
|
|---|
| 328 | fpCommand -> SetParameterName ("viewer-name",
|
|---|
| 329 | omitable = true,
|
|---|
| 330 | currentAsDefault = true);
|
|---|
| 331 | }
|
|---|
| 332 |
|
|---|
| 333 | G4VisCommandViewerClearTransients::~G4VisCommandViewerClearTransients () {
|
|---|
| 334 | delete fpCommand;
|
|---|
| 335 | }
|
|---|
| 336 |
|
|---|
| 337 | G4String G4VisCommandViewerClearTransients::GetCurrentValue (G4UIcommand*) {
|
|---|
| 338 | G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
|
|---|
| 339 | return viewer ? viewer -> GetName () : G4String("none");
|
|---|
| 340 | }
|
|---|
| 341 |
|
|---|
| 342 | void G4VisCommandViewerClearTransients::SetNewValue (G4UIcommand*, G4String newValue) {
|
|---|
| 343 |
|
|---|
| 344 | G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
|
|---|
| 345 |
|
|---|
| 346 | G4String& clearName = newValue;
|
|---|
| 347 | G4VViewer* viewer = fpVisManager -> GetViewer (clearName);
|
|---|
| 348 | if (!viewer) {
|
|---|
| 349 | if (verbosity >= G4VisManager::errors) {
|
|---|
| 350 | G4cout << "ERROR: Viewer \"" << clearName
|
|---|
| 351 | << "\" not found - \"/vis/viewer/list\" to see possibilities."
|
|---|
| 352 | << G4endl;
|
|---|
| 353 | }
|
|---|
| 354 | return;
|
|---|
| 355 | }
|
|---|
| 356 |
|
|---|
| 357 | G4VSceneHandler* sceneHandler = viewer->GetSceneHandler();
|
|---|
| 358 | sceneHandler->SetMarkForClearingTransientStore(false);
|
|---|
| 359 | fpVisManager->ResetTransientsDrawnFlags();
|
|---|
| 360 | sceneHandler->ClearTransientStore();
|
|---|
| 361 | if (verbosity >= G4VisManager::confirmations) {
|
|---|
| 362 | G4cout << "Viewer \"" << clearName << "\" cleared of transients."
|
|---|
| 363 | << G4endl;
|
|---|
| 364 | }
|
|---|
| 365 |
|
|---|
| 366 | }
|
|---|
| 367 |
|
|---|
| 368 | ////////////// /vis/viewer/clone ///////////////////////////////////////
|
|---|
| 369 |
|
|---|
| 370 | G4VisCommandViewerClone::G4VisCommandViewerClone () {
|
|---|
| 371 | G4bool omitable;
|
|---|
| 372 | fpCommand = new G4UIcommand ("/vis/viewer/clone", this);
|
|---|
| 373 | fpCommand -> SetGuidance ("Clones viewer.");
|
|---|
| 374 | fpCommand -> SetGuidance
|
|---|
| 375 | ("By default, clones current viewer. Clone becomes current."
|
|---|
| 376 | "\nClone name, if not provided, is derived from the original name."
|
|---|
| 377 | "\n\"/vis/viewer/list\" to see possible viewer names.");
|
|---|
| 378 | G4UIparameter* parameter;
|
|---|
| 379 | parameter = new G4UIparameter ("original-viewer-name", 's', omitable = true);
|
|---|
| 380 | parameter -> SetCurrentAsDefault (true);
|
|---|
| 381 | fpCommand -> SetParameter (parameter);
|
|---|
| 382 | parameter = new G4UIparameter ("clone-name", 's', omitable = true);
|
|---|
| 383 | parameter -> SetDefaultValue ("none");
|
|---|
| 384 | fpCommand -> SetParameter (parameter);
|
|---|
| 385 | }
|
|---|
| 386 |
|
|---|
| 387 | G4VisCommandViewerClone::~G4VisCommandViewerClone () {
|
|---|
| 388 | delete fpCommand;
|
|---|
| 389 | }
|
|---|
| 390 |
|
|---|
| 391 | G4String G4VisCommandViewerClone::GetCurrentValue (G4UIcommand*) {
|
|---|
| 392 | G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
|
|---|
| 393 | G4String originalName = viewer ? viewer -> GetName () : G4String("none");
|
|---|
| 394 | return "\"" + originalName + "\"";
|
|---|
| 395 | }
|
|---|
| 396 |
|
|---|
| 397 | void G4VisCommandViewerClone::SetNewValue (G4UIcommand*, G4String newValue) {
|
|---|
| 398 |
|
|---|
| 399 | G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
|
|---|
| 400 |
|
|---|
| 401 | G4String originalName, cloneName;
|
|---|
| 402 | std::istringstream is (newValue);
|
|---|
| 403 |
|
|---|
| 404 | // Need to handle the possibility that the names contain embedded
|
|---|
| 405 | // blanks within quotation marks...
|
|---|
| 406 | char c;
|
|---|
| 407 | while (is.get(c) && c == ' '){}
|
|---|
| 408 | if (c == '"') {
|
|---|
| 409 | while (is.get(c) && c != '"') {originalName += c;}
|
|---|
| 410 | }
|
|---|
| 411 | else {
|
|---|
| 412 | originalName += c;
|
|---|
| 413 | while (is.get(c) && c != ' ') {originalName += c;}
|
|---|
| 414 | }
|
|---|
| 415 | originalName = originalName.strip (G4String::both, ' ');
|
|---|
| 416 | originalName = originalName.strip (G4String::both, '"');
|
|---|
| 417 |
|
|---|
| 418 | G4VViewer* originalViewer = fpVisManager -> GetViewer (originalName);
|
|---|
| 419 | if (!originalViewer) {
|
|---|
| 420 | if (verbosity >= G4VisManager::errors) {
|
|---|
| 421 | G4cout << "ERROR: Viewer \"" << originalName
|
|---|
| 422 | << "\" not found - \"/vis/viewer/list\" to see possibilities."
|
|---|
| 423 | << G4endl;
|
|---|
| 424 | }
|
|---|
| 425 | return;
|
|---|
| 426 | }
|
|---|
| 427 | originalName = originalViewer->GetName(); // Ensures long name.
|
|---|
| 428 |
|
|---|
| 429 | while (is.get(c) && c == ' '){}
|
|---|
| 430 | if (c == '"') {
|
|---|
| 431 | while (is.get(c) && c != '"') {cloneName += c;}
|
|---|
| 432 | }
|
|---|
| 433 | else {
|
|---|
| 434 | cloneName += c;
|
|---|
| 435 | while (is.get(c) && c != ' ') {cloneName += c;}
|
|---|
| 436 | }
|
|---|
| 437 | cloneName = cloneName.strip (G4String::both, ' ');
|
|---|
| 438 | cloneName = cloneName.strip (G4String::both, '"');
|
|---|
| 439 |
|
|---|
| 440 | if (cloneName == "none") {
|
|---|
| 441 | G4int subID = 0;
|
|---|
| 442 | do {
|
|---|
| 443 | cloneName = originalName;
|
|---|
| 444 | std::ostringstream oss;
|
|---|
| 445 | oss << '-' << subID++;
|
|---|
| 446 | G4String::size_type lastDashPosition, nextSpacePosition;
|
|---|
| 447 | if ((lastDashPosition = cloneName.rfind('-')) != G4String::npos &&
|
|---|
| 448 | (nextSpacePosition = cloneName.find(" ", lastDashPosition)) !=
|
|---|
| 449 | G4String::npos) {
|
|---|
| 450 | cloneName.insert(nextSpacePosition, oss.str());
|
|---|
| 451 | } else {
|
|---|
| 452 | cloneName.insert(cloneName.find(' '), oss.str());
|
|---|
| 453 | }
|
|---|
| 454 | } while (fpVisManager -> GetViewer (cloneName));
|
|---|
| 455 | }
|
|---|
| 456 |
|
|---|
| 457 | if (fpVisManager -> GetViewer (cloneName)) {
|
|---|
| 458 | if (verbosity >= G4VisManager::errors) {
|
|---|
| 459 | G4cout << "ERROR: Putative clone viewer \"" << cloneName
|
|---|
| 460 | << "\" already exists."
|
|---|
| 461 | << G4endl;
|
|---|
| 462 | }
|
|---|
| 463 | return;
|
|---|
| 464 | }
|
|---|
| 465 |
|
|---|
| 466 | G4String windowSizeHint =
|
|---|
| 467 | originalViewer->GetViewParameters().GetXGeometryString();
|
|---|
| 468 |
|
|---|
| 469 | G4UImanager* UImanager = G4UImanager::GetUIpointer();
|
|---|
| 470 | G4int keepVerbose = UImanager->GetVerboseLevel();
|
|---|
| 471 | G4int newVerbose(0);
|
|---|
| 472 | if (keepVerbose >= 2 ||
|
|---|
| 473 | fpVisManager->GetVerbosity() >= G4VisManager::confirmations)
|
|---|
| 474 | newVerbose = 2;
|
|---|
| 475 | UImanager->SetVerboseLevel(newVerbose);
|
|---|
| 476 | UImanager->ApplyCommand(G4String("/vis/viewer/select " + originalName));
|
|---|
| 477 | UImanager->ApplyCommand
|
|---|
| 478 | (G4String("/vis/viewer/create ! \"" + cloneName + "\" " + windowSizeHint));
|
|---|
| 479 | UImanager->ApplyCommand(G4String("/vis/viewer/set/all " + originalName));
|
|---|
| 480 | UImanager->SetVerboseLevel(keepVerbose);
|
|---|
| 481 |
|
|---|
| 482 | if (verbosity >= G4VisManager::confirmations) {
|
|---|
| 483 | G4cout << "Viewer \"" << originalName << "\" cloned." << G4endl;
|
|---|
| 484 | G4cout << "Clone \"" << cloneName << "\" now current." << G4endl;
|
|---|
| 485 | }
|
|---|
| 486 | }
|
|---|
| 487 |
|
|---|
| 488 | ////////////// /vis/viewer/create ///////////////////////////////////////
|
|---|
| 489 |
|
|---|
| 490 | G4VisCommandViewerCreate::G4VisCommandViewerCreate (): fId (0) {
|
|---|
| 491 | G4bool omitable;
|
|---|
| 492 | fpCommand = new G4UIcommand ("/vis/viewer/create", this);
|
|---|
| 493 | fpCommand -> SetGuidance
|
|---|
| 494 | ("Creates a viewer for the specified scene handler.");
|
|---|
| 495 | fpCommand -> SetGuidance
|
|---|
| 496 | ("Default scene handler is the current scene handler. Invents a name"
|
|---|
| 497 | "\nif not supplied. (Note: the system adds information to the name"
|
|---|
| 498 | "\nfor identification - only the characters up to the first blank are"
|
|---|
| 499 | "\nused for removing, selecting, etc.) This scene handler and viewer"
|
|---|
| 500 | "\nbecome current.");
|
|---|
| 501 | G4UIparameter* parameter;
|
|---|
| 502 | parameter = new G4UIparameter ("scene-handler", 's', omitable = true);
|
|---|
| 503 | parameter -> SetCurrentAsDefault (true);
|
|---|
| 504 | fpCommand -> SetParameter (parameter);
|
|---|
| 505 | parameter = new G4UIparameter ("viewer-name", 's', omitable = true);
|
|---|
| 506 | parameter -> SetCurrentAsDefault (true);
|
|---|
| 507 | fpCommand -> SetParameter (parameter);
|
|---|
| 508 | parameter = new G4UIparameter ("window-size-hint", 's', omitable = true);
|
|---|
| 509 | parameter->SetGuidance
|
|---|
| 510 | ("integer (pixels) for square window placed by window manager or"
|
|---|
| 511 | " X-Windows-type geometry string, e.g. 600x600-100+100");
|
|---|
| 512 | parameter->SetDefaultValue("600");
|
|---|
| 513 | fpCommand -> SetParameter (parameter);
|
|---|
| 514 | }
|
|---|
| 515 |
|
|---|
| 516 | G4VisCommandViewerCreate::~G4VisCommandViewerCreate () {
|
|---|
| 517 | delete fpCommand;
|
|---|
| 518 | }
|
|---|
| 519 |
|
|---|
| 520 | G4String G4VisCommandViewerCreate::NextName () {
|
|---|
| 521 | std::ostringstream oss;
|
|---|
| 522 | G4VSceneHandler* sceneHandler = fpVisManager -> GetCurrentSceneHandler ();
|
|---|
| 523 | oss << "viewer-" << fId << " (";
|
|---|
| 524 | if (sceneHandler) {
|
|---|
| 525 | oss << sceneHandler -> GetGraphicsSystem () -> GetName ();
|
|---|
| 526 | }
|
|---|
| 527 | else {
|
|---|
| 528 | oss << "no_scene_handlers";
|
|---|
| 529 | }
|
|---|
| 530 | oss << ")";
|
|---|
| 531 | return oss.str();
|
|---|
| 532 | }
|
|---|
| 533 |
|
|---|
| 534 | G4String G4VisCommandViewerCreate::GetCurrentValue (G4UIcommand*) {
|
|---|
| 535 | G4String currentValue;
|
|---|
| 536 | G4VSceneHandler* currentSceneHandler =
|
|---|
| 537 | fpVisManager -> GetCurrentSceneHandler ();
|
|---|
| 538 | if (currentSceneHandler) {
|
|---|
| 539 | currentValue = currentSceneHandler -> GetName ();
|
|---|
| 540 | }
|
|---|
| 541 | else {
|
|---|
| 542 | currentValue = "none";
|
|---|
| 543 | }
|
|---|
| 544 | currentValue += ' ';
|
|---|
| 545 | currentValue += '"';
|
|---|
| 546 | currentValue += NextName ();
|
|---|
| 547 | currentValue += '"';
|
|---|
| 548 |
|
|---|
| 549 | currentValue += " 600"; // Default number of pixels for window size hint.
|
|---|
| 550 |
|
|---|
| 551 | return currentValue;
|
|---|
| 552 | }
|
|---|
| 553 |
|
|---|
| 554 | void G4VisCommandViewerCreate::SetNewValue (G4UIcommand*, G4String newValue) {
|
|---|
| 555 |
|
|---|
| 556 | G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
|
|---|
| 557 |
|
|---|
| 558 | G4String sceneHandlerName, newName;
|
|---|
| 559 | G4String windowSizeHintString;
|
|---|
| 560 | std::istringstream is (newValue);
|
|---|
| 561 | is >> sceneHandlerName;
|
|---|
| 562 |
|
|---|
| 563 | // Now need to handle the possibility that the second string
|
|---|
| 564 | // contains embedded blanks within quotation marks...
|
|---|
| 565 | char c;
|
|---|
| 566 | while (is.get(c) && c == ' '){}
|
|---|
| 567 | if (c == '"') {
|
|---|
| 568 | while (is.get(c) && c != '"') {newName += c;}
|
|---|
| 569 | }
|
|---|
| 570 | else {
|
|---|
| 571 | newName += c;
|
|---|
| 572 | while (is.get(c) && c != ' ') {newName += c;}
|
|---|
| 573 | }
|
|---|
| 574 | newName = newName.strip (G4String::both, ' ');
|
|---|
| 575 | newName = newName.strip (G4String::both, '"');
|
|---|
| 576 |
|
|---|
| 577 | // Now get window size hint...
|
|---|
| 578 | is >> windowSizeHintString;
|
|---|
| 579 |
|
|---|
| 580 | const G4SceneHandlerList& sceneHandlerList =
|
|---|
| 581 | fpVisManager -> GetAvailableSceneHandlers ();
|
|---|
| 582 | G4int nHandlers = sceneHandlerList.size ();
|
|---|
| 583 | if (nHandlers <= 0) {
|
|---|
| 584 | if (verbosity >= G4VisManager::errors) {
|
|---|
| 585 | G4cout <<
|
|---|
| 586 | "ERROR: G4VisCommandViewerCreate::SetNewValue: no scene handlers."
|
|---|
| 587 | "\n Create a scene handler with \"/vis/sceneHandler/create\""
|
|---|
| 588 | << G4endl;
|
|---|
| 589 | }
|
|---|
| 590 | return;
|
|---|
| 591 | }
|
|---|
| 592 |
|
|---|
| 593 | G4int iHandler;
|
|---|
| 594 | for (iHandler = 0; iHandler < nHandlers; iHandler++) {
|
|---|
| 595 | if (sceneHandlerList [iHandler] -> GetName () == sceneHandlerName) break;
|
|---|
| 596 | }
|
|---|
| 597 |
|
|---|
| 598 | if (iHandler < 0 || iHandler >= nHandlers) {
|
|---|
| 599 | // Invalid command line argument or none.
|
|---|
| 600 | // This shouldn't happen!!!!!!
|
|---|
| 601 | if (verbosity >= G4VisManager::errors) {
|
|---|
| 602 | G4cout << "G4VisCommandViewerCreate::SetNewValue:"
|
|---|
| 603 | " invalid scene handler specified."
|
|---|
| 604 | << G4endl;
|
|---|
| 605 | }
|
|---|
| 606 | return;
|
|---|
| 607 | }
|
|---|
| 608 |
|
|---|
| 609 | // Valid index. Set current scene handler and graphics system in
|
|---|
| 610 | // preparation for creating viewer.
|
|---|
| 611 | G4VSceneHandler* sceneHandler = sceneHandlerList [iHandler];
|
|---|
| 612 | if (sceneHandler != fpVisManager -> GetCurrentSceneHandler ()) {
|
|---|
| 613 | fpVisManager -> SetCurrentSceneHandler (sceneHandler);
|
|---|
| 614 | }
|
|---|
| 615 |
|
|---|
| 616 | // Now deal with name of viewer.
|
|---|
| 617 | G4String nextName = NextName ();
|
|---|
| 618 | if (newName == "") {
|
|---|
| 619 | newName = nextName;
|
|---|
| 620 | }
|
|---|
| 621 | if (newName == nextName) fId++;
|
|---|
| 622 | G4String newShortName = fpVisManager -> ViewerShortName (newName);
|
|---|
| 623 |
|
|---|
| 624 | for (iHandler = 0; iHandler < nHandlers; iHandler++) {
|
|---|
| 625 | G4VSceneHandler* sceneHandler = sceneHandlerList [iHandler];
|
|---|
| 626 | const G4ViewerList& viewerList = sceneHandler -> GetViewerList ();
|
|---|
| 627 | for (size_t iViewer = 0; iViewer < viewerList.size (); iViewer++) {
|
|---|
| 628 | if (viewerList [iViewer] -> GetShortName () == newShortName ) {
|
|---|
| 629 | if (verbosity >= G4VisManager::errors) {
|
|---|
| 630 | G4cout << "ERROR: Viewer \"" << newShortName << "\" already exists."
|
|---|
| 631 | << G4endl;
|
|---|
| 632 | }
|
|---|
| 633 | return;
|
|---|
| 634 | }
|
|---|
| 635 | }
|
|---|
| 636 | }
|
|---|
| 637 |
|
|---|
| 638 | // WindowSizeHint and XGeometryString are picked up from the vis
|
|---|
| 639 | // manager in the G4VViewer constructor. In G4VisManager, after Viewer
|
|---|
| 640 | // creation, we will store theses parameters in G4ViewParameters.
|
|---|
| 641 |
|
|---|
| 642 | fpVisManager -> CreateViewer (newName,windowSizeHintString);
|
|---|
| 643 |
|
|---|
| 644 | G4VViewer* newViewer = fpVisManager -> GetCurrentViewer ();
|
|---|
| 645 | if (newViewer && newViewer -> GetName () == newName) {
|
|---|
| 646 | if (verbosity >= G4VisManager::confirmations) {
|
|---|
| 647 | G4cout << "New viewer \"" << newName << "\" created." << G4endl;
|
|---|
| 648 | }
|
|---|
| 649 | }
|
|---|
| 650 | else {
|
|---|
| 651 | if (verbosity >= G4VisManager::errors) {
|
|---|
| 652 | if (newViewer) {
|
|---|
| 653 | G4cout << "ERROR: New viewer doesn\'t match!!! Curious!!" << G4endl;
|
|---|
| 654 | } else {
|
|---|
| 655 | G4cout << "WARNING: No viewer created." << G4endl;
|
|---|
| 656 | }
|
|---|
| 657 | }
|
|---|
| 658 | }
|
|---|
| 659 | // Refresh if appropriate...
|
|---|
| 660 | if (newViewer) {
|
|---|
| 661 | if (newViewer->GetViewParameters().IsAutoRefresh()) {
|
|---|
| 662 | G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/refresh");
|
|---|
| 663 | }
|
|---|
| 664 | else {
|
|---|
| 665 | if (verbosity >= G4VisManager::confirmations) {
|
|---|
| 666 | G4cout << "Issue /vis/viewer/refresh to see effect." << G4endl;
|
|---|
| 667 | }
|
|---|
| 668 | }
|
|---|
| 669 | }
|
|---|
| 670 | }
|
|---|
| 671 |
|
|---|
| 672 | ////////////// /vis/viewer/dolly and dollyTo ////////////////////////////
|
|---|
| 673 |
|
|---|
| 674 | G4VisCommandViewerDolly::G4VisCommandViewerDolly ():
|
|---|
| 675 | fDollyIncrement (0.),
|
|---|
| 676 | fDollyTo (0.)
|
|---|
| 677 | {
|
|---|
| 678 | G4bool omitable, currentAsDefault;
|
|---|
| 679 |
|
|---|
| 680 | fpCommandDolly = new G4UIcmdWithADoubleAndUnit
|
|---|
| 681 | ("/vis/viewer/dolly", this);
|
|---|
| 682 | fpCommandDolly -> SetGuidance
|
|---|
| 683 | ("Incremental dolly.");
|
|---|
| 684 | fpCommandDolly -> SetGuidance
|
|---|
| 685 | ("Moves the camera incrementally towards target point.");
|
|---|
| 686 | fpCommandDolly -> SetParameterName("increment",
|
|---|
| 687 | omitable=true,
|
|---|
| 688 | currentAsDefault=true);
|
|---|
| 689 | fpCommandDolly -> SetDefaultUnit("m");
|
|---|
| 690 |
|
|---|
| 691 | fpCommandDollyTo = new G4UIcmdWithADoubleAndUnit
|
|---|
| 692 | ("/vis/viewer/dollyTo", this);
|
|---|
| 693 | fpCommandDollyTo -> SetGuidance
|
|---|
| 694 | ("Dolly to specific coordinate.");
|
|---|
| 695 | fpCommandDollyTo -> SetGuidance
|
|---|
| 696 | ("Places the camera towards target point relative to standard camera point.");
|
|---|
| 697 | fpCommandDollyTo -> SetParameterName("distance",
|
|---|
| 698 | omitable=true,
|
|---|
| 699 | currentAsDefault=true);
|
|---|
| 700 | fpCommandDollyTo -> SetDefaultUnit("m");
|
|---|
| 701 | }
|
|---|
| 702 |
|
|---|
| 703 | G4VisCommandViewerDolly::~G4VisCommandViewerDolly () {
|
|---|
| 704 | delete fpCommandDolly;
|
|---|
| 705 | delete fpCommandDollyTo;
|
|---|
| 706 | }
|
|---|
| 707 |
|
|---|
| 708 | G4String G4VisCommandViewerDolly::GetCurrentValue (G4UIcommand* command) {
|
|---|
| 709 | G4String currentValue;
|
|---|
| 710 | if (command == fpCommandDolly) {
|
|---|
| 711 | currentValue = fpCommandDolly->ConvertToString(fDollyIncrement, "m");
|
|---|
| 712 | }
|
|---|
| 713 | else if (command == fpCommandDollyTo) {
|
|---|
| 714 | currentValue = fpCommandDollyTo->ConvertToString(fDollyTo, "m");
|
|---|
| 715 | }
|
|---|
| 716 | return currentValue;
|
|---|
| 717 | }
|
|---|
| 718 |
|
|---|
| 719 | void G4VisCommandViewerDolly::SetNewValue (G4UIcommand* command,
|
|---|
| 720 | G4String newValue) {
|
|---|
| 721 |
|
|---|
| 722 |
|
|---|
| 723 | G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
|
|---|
| 724 |
|
|---|
| 725 | G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
|
|---|
| 726 | if (!currentViewer) {
|
|---|
| 727 | if (verbosity >= G4VisManager::errors) {
|
|---|
| 728 | G4cout <<
|
|---|
| 729 | "ERROR: G4VisCommandsViewerDolly::SetNewValue: no current viewer."
|
|---|
| 730 | << G4endl;
|
|---|
| 731 | }
|
|---|
| 732 | return;
|
|---|
| 733 | }
|
|---|
| 734 |
|
|---|
| 735 | G4ViewParameters vp = currentViewer->GetViewParameters();
|
|---|
| 736 |
|
|---|
| 737 | if (command == fpCommandDolly) {
|
|---|
| 738 | fDollyIncrement = fpCommandDolly->GetNewDoubleValue(newValue);
|
|---|
| 739 | vp.IncrementDolly(fDollyIncrement);
|
|---|
| 740 | }
|
|---|
| 741 | else if (command == fpCommandDollyTo) {
|
|---|
| 742 | fDollyTo = fpCommandDolly->GetNewDoubleValue(newValue);
|
|---|
| 743 | vp.SetDolly(fDollyTo);
|
|---|
| 744 | }
|
|---|
| 745 |
|
|---|
| 746 | if (verbosity >= G4VisManager::confirmations) {
|
|---|
| 747 | G4cout << "Dolly distance changed to " << vp.GetDolly() << G4endl;
|
|---|
| 748 | }
|
|---|
| 749 |
|
|---|
| 750 | SetViewParameters(currentViewer, vp);
|
|---|
| 751 | }
|
|---|
| 752 |
|
|---|
| 753 | ////////////// /vis/viewer/flush ///////////////////////////////////////
|
|---|
| 754 |
|
|---|
| 755 | G4VisCommandViewerFlush::G4VisCommandViewerFlush () {
|
|---|
| 756 | G4bool omitable, currentAsDefault;
|
|---|
| 757 | fpCommand = new G4UIcmdWithAString ("/vis/viewer/flush", this);
|
|---|
| 758 | fpCommand -> SetGuidance
|
|---|
| 759 | ("Compound command: \"/vis/viewer/refresh\" + \"/vis/viewer/update\".");
|
|---|
| 760 | fpCommand -> SetGuidance
|
|---|
| 761 | ("Useful for refreshing and initiating post-processing for graphics"
|
|---|
| 762 | "\nsystems which need post-processing. By default, acts on current"
|
|---|
| 763 | "\nviewer. \"/vis/viewer/list\" to see possible viewers. Viewer"
|
|---|
| 764 | "\nbecomes current.");
|
|---|
| 765 | fpCommand -> SetParameterName ("viewer-name",
|
|---|
| 766 | omitable = true,
|
|---|
| 767 | currentAsDefault = true);
|
|---|
| 768 | }
|
|---|
| 769 |
|
|---|
| 770 | G4VisCommandViewerFlush::~G4VisCommandViewerFlush () {
|
|---|
| 771 | delete fpCommand;
|
|---|
| 772 | }
|
|---|
| 773 |
|
|---|
| 774 | G4String G4VisCommandViewerFlush::GetCurrentValue
|
|---|
| 775 | (G4UIcommand*) {
|
|---|
| 776 | G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
|
|---|
| 777 | return viewer ? viewer -> GetName () : G4String("none");
|
|---|
| 778 | }
|
|---|
| 779 |
|
|---|
| 780 | void G4VisCommandViewerFlush::SetNewValue (G4UIcommand*, G4String newValue) {
|
|---|
| 781 |
|
|---|
| 782 | G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
|
|---|
| 783 |
|
|---|
| 784 | G4String& flushName = newValue;
|
|---|
| 785 | G4VViewer* viewer = fpVisManager -> GetViewer (flushName);
|
|---|
| 786 | if (!viewer) {
|
|---|
| 787 | if (verbosity >= G4VisManager::errors) {
|
|---|
| 788 | G4cout << "ERROR: Viewer \"" << flushName << "\"" <<
|
|---|
| 789 | " not found - \"/vis/viewer/list\"\n to see possibilities."
|
|---|
| 790 | << G4endl;
|
|---|
| 791 | }
|
|---|
| 792 | return;
|
|---|
| 793 | }
|
|---|
| 794 |
|
|---|
| 795 | G4UImanager* ui = G4UImanager::GetUIpointer();
|
|---|
| 796 | G4int keepVerbose = ui->GetVerboseLevel();
|
|---|
| 797 | G4int newVerbose(0);
|
|---|
| 798 | if (keepVerbose >= 2 || verbosity >= G4VisManager::confirmations)
|
|---|
| 799 | newVerbose = 2;
|
|---|
| 800 | ui->SetVerboseLevel(newVerbose);
|
|---|
| 801 | ui->ApplyCommand(G4String("/vis/viewer/refresh " + flushName));
|
|---|
| 802 | ui->ApplyCommand(G4String("/vis/viewer/update " + flushName));
|
|---|
| 803 | ui->SetVerboseLevel(keepVerbose);
|
|---|
| 804 | if (verbosity >= G4VisManager::confirmations) {
|
|---|
| 805 | G4cout << "Viewer \"" << viewer -> GetName () << "\""
|
|---|
| 806 | << " flushed." << G4endl;
|
|---|
| 807 | }
|
|---|
| 808 | }
|
|---|
| 809 |
|
|---|
| 810 | ////////////// /vis/viewer/list ///////////////////////////////////////
|
|---|
| 811 |
|
|---|
| 812 | G4VisCommandViewerList::G4VisCommandViewerList () {
|
|---|
| 813 | G4bool omitable;
|
|---|
| 814 | fpCommand = new G4UIcommand ("/vis/viewer/list", this);
|
|---|
| 815 | fpCommand -> SetGuidance ("Lists viewers(s).");
|
|---|
| 816 | fpCommand -> SetGuidance
|
|---|
| 817 | ("See \"/vis/verbose\" for definition of verbosity.");
|
|---|
| 818 | G4UIparameter* parameter;
|
|---|
| 819 | parameter = new G4UIparameter("viewer-name", 's',
|
|---|
| 820 | omitable = true);
|
|---|
| 821 | parameter -> SetDefaultValue ("all");
|
|---|
| 822 | fpCommand -> SetParameter (parameter);
|
|---|
| 823 | parameter = new G4UIparameter ("verbosity", 's',
|
|---|
| 824 | omitable = true);
|
|---|
| 825 | parameter -> SetDefaultValue ("warnings");
|
|---|
| 826 | fpCommand -> SetParameter (parameter);
|
|---|
| 827 | }
|
|---|
| 828 |
|
|---|
| 829 | G4VisCommandViewerList::~G4VisCommandViewerList () {
|
|---|
| 830 | delete fpCommand;
|
|---|
| 831 | }
|
|---|
| 832 |
|
|---|
| 833 | G4String G4VisCommandViewerList::GetCurrentValue (G4UIcommand*) {
|
|---|
| 834 | return "";
|
|---|
| 835 | }
|
|---|
| 836 |
|
|---|
| 837 | void G4VisCommandViewerList::SetNewValue (G4UIcommand*, G4String newValue) {
|
|---|
| 838 | G4String name, verbosityString;
|
|---|
| 839 | std::istringstream is (newValue);
|
|---|
| 840 | is >> name >> verbosityString;
|
|---|
| 841 | G4String shortName = fpVisManager -> ViewerShortName (name);
|
|---|
| 842 | G4VisManager::Verbosity verbosity =
|
|---|
| 843 | fpVisManager->GetVerbosityValue(verbosityString);
|
|---|
| 844 |
|
|---|
| 845 | const G4VViewer* currentViewer = fpVisManager -> GetCurrentViewer ();
|
|---|
| 846 | G4String currentViewerShortName;
|
|---|
| 847 | if (currentViewer) {
|
|---|
| 848 | currentViewerShortName = currentViewer -> GetShortName ();
|
|---|
| 849 | }
|
|---|
| 850 | else {
|
|---|
| 851 | currentViewerShortName = "none";
|
|---|
| 852 | }
|
|---|
| 853 |
|
|---|
| 854 | const G4SceneHandlerList& sceneHandlerList = fpVisManager -> GetAvailableSceneHandlers ();
|
|---|
| 855 | G4int nHandlers = sceneHandlerList.size ();
|
|---|
| 856 | G4bool found = false;
|
|---|
| 857 | G4bool foundCurrent = false;
|
|---|
| 858 | for (int iHandler = 0; iHandler < nHandlers; iHandler++) {
|
|---|
| 859 | G4VSceneHandler* sceneHandler = sceneHandlerList [iHandler];
|
|---|
| 860 | const G4ViewerList& viewerList = sceneHandler -> GetViewerList ();
|
|---|
| 861 | G4cout << "Scene handler \"" << sceneHandler -> GetName ();
|
|---|
| 862 | const G4Scene* pScene = sceneHandler -> GetScene ();
|
|---|
| 863 | if (pScene) {
|
|---|
| 864 | G4cout << "\", scene \"" << pScene -> GetName () << "\":";
|
|---|
| 865 | }
|
|---|
| 866 | G4int nViewers = viewerList.size ();
|
|---|
| 867 | if (nViewers == 0) {
|
|---|
| 868 | G4cout << "\n No viewers for this scene handler." << G4endl;
|
|---|
| 869 | }
|
|---|
| 870 | else {
|
|---|
| 871 | for (int iViewer = 0; iViewer < nViewers; iViewer++) {
|
|---|
| 872 | const G4VViewer* thisViewer = viewerList [iViewer];
|
|---|
| 873 | G4String thisName = thisViewer -> GetName ();
|
|---|
| 874 | G4String thisShortName = thisViewer -> GetShortName ();
|
|---|
| 875 | if (name != "all") {
|
|---|
| 876 | if (thisShortName != shortName) continue;
|
|---|
| 877 | }
|
|---|
| 878 | found = true;
|
|---|
| 879 | G4cout << "\n ";
|
|---|
| 880 | if (thisShortName == currentViewerShortName) {
|
|---|
| 881 | foundCurrent = true;
|
|---|
| 882 | G4cout << "(current)";
|
|---|
| 883 | }
|
|---|
| 884 | else {
|
|---|
| 885 | G4cout << " ";
|
|---|
| 886 | }
|
|---|
| 887 | G4cout << " viewer \"" << thisName << "\"";
|
|---|
| 888 | if (verbosity >= G4VisManager::parameters) {
|
|---|
| 889 | G4cout << "\n " << *thisViewer;
|
|---|
| 890 | }
|
|---|
| 891 | }
|
|---|
| 892 | }
|
|---|
| 893 | G4cout << G4endl;
|
|---|
| 894 | }
|
|---|
| 895 |
|
|---|
| 896 | if (!foundCurrent) {
|
|---|
| 897 | G4cout << "No valid current viewer - please create or select one."
|
|---|
| 898 | << G4endl;
|
|---|
| 899 | }
|
|---|
| 900 |
|
|---|
| 901 | if (!found) {
|
|---|
| 902 | G4cout << "No viewers";
|
|---|
| 903 | if (name != "all") {
|
|---|
| 904 | G4cout << " of name \"" << name << "\"";
|
|---|
| 905 | }
|
|---|
| 906 | G4cout << " found." << G4endl;
|
|---|
| 907 | }
|
|---|
| 908 | }
|
|---|
| 909 |
|
|---|
| 910 | ////////////// /vis/viewer/pan and panTo ////////////////////////////
|
|---|
| 911 |
|
|---|
| 912 | G4VisCommandViewerPan::G4VisCommandViewerPan ():
|
|---|
| 913 | fPanIncrementRight (0.),
|
|---|
| 914 | fPanIncrementUp (0.),
|
|---|
| 915 | fPanToRight (0.),
|
|---|
| 916 | fPanToUp (0.)
|
|---|
| 917 | {
|
|---|
| 918 | G4bool omitable;
|
|---|
| 919 |
|
|---|
| 920 | fpCommandPan = new G4UIcommand
|
|---|
| 921 | ("/vis/viewer/pan", this);
|
|---|
| 922 | fpCommandPan -> SetGuidance
|
|---|
| 923 | ("Incremental pan.");
|
|---|
| 924 | fpCommandPan -> SetGuidance
|
|---|
| 925 | ("Moves the camera incrementally right and up by these amounts (as seen"
|
|---|
| 926 | "\nfrom viewpoint direction).");
|
|---|
| 927 | G4UIparameter* parameter;
|
|---|
| 928 | parameter = new G4UIparameter("right-increment", 'd', omitable = true);
|
|---|
| 929 | parameter -> SetCurrentAsDefault (true);
|
|---|
| 930 | fpCommandPan -> SetParameter (parameter);
|
|---|
| 931 | parameter = new G4UIparameter("up-increment", 'd', omitable = true);
|
|---|
| 932 | parameter -> SetCurrentAsDefault (true);
|
|---|
| 933 | fpCommandPan -> SetParameter (parameter);
|
|---|
| 934 | parameter = new G4UIparameter ("unit", 's', omitable = true);
|
|---|
| 935 | parameter -> SetDefaultValue ("m");
|
|---|
| 936 | fpCommandPan -> SetParameter (parameter);
|
|---|
| 937 |
|
|---|
| 938 | fpCommandPanTo = new G4UIcommand
|
|---|
| 939 | ("/vis/viewer/panTo", this);
|
|---|
| 940 | fpCommandPanTo -> SetGuidance
|
|---|
| 941 | ("Pan to specific coordinate.");
|
|---|
| 942 | fpCommandPanTo -> SetGuidance
|
|---|
| 943 | ("Places the camera in this position right and up relative to standard"
|
|---|
| 944 | "\ntarget point (as seen from viewpoint direction).");
|
|---|
| 945 | parameter = new G4UIparameter("right", 'd', omitable = true);
|
|---|
| 946 | parameter -> SetCurrentAsDefault (true);
|
|---|
| 947 | fpCommandPanTo -> SetParameter (parameter);
|
|---|
| 948 | parameter = new G4UIparameter("up", 'd', omitable = true);
|
|---|
| 949 | parameter -> SetCurrentAsDefault (true);
|
|---|
| 950 | fpCommandPanTo -> SetParameter (parameter);
|
|---|
| 951 | parameter = new G4UIparameter ("unit", 's', omitable = true);
|
|---|
| 952 | parameter -> SetDefaultValue ("m");
|
|---|
| 953 | fpCommandPanTo -> SetParameter (parameter);
|
|---|
| 954 | }
|
|---|
| 955 |
|
|---|
| 956 | G4VisCommandViewerPan::~G4VisCommandViewerPan () {
|
|---|
| 957 | delete fpCommandPan;
|
|---|
| 958 | delete fpCommandPanTo;
|
|---|
| 959 | }
|
|---|
| 960 |
|
|---|
| 961 | G4String G4VisCommandViewerPan::GetCurrentValue (G4UIcommand* command) {
|
|---|
| 962 | G4String currentValue;
|
|---|
| 963 | if (command == fpCommandPan) {
|
|---|
| 964 | currentValue = ConvertToString(fPanIncrementRight, fPanIncrementUp, "m");
|
|---|
| 965 | }
|
|---|
| 966 | else if (command == fpCommandPanTo) {
|
|---|
| 967 | currentValue = ConvertToString(fPanToRight, fPanToUp, "m");
|
|---|
| 968 | }
|
|---|
| 969 | return currentValue;
|
|---|
| 970 | }
|
|---|
| 971 |
|
|---|
| 972 | void G4VisCommandViewerPan::SetNewValue (G4UIcommand* command,
|
|---|
| 973 | G4String newValue) {
|
|---|
| 974 |
|
|---|
| 975 |
|
|---|
| 976 | G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
|
|---|
| 977 |
|
|---|
| 978 | G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
|
|---|
| 979 | if (!currentViewer) {
|
|---|
| 980 | if (verbosity >= G4VisManager::errors) {
|
|---|
| 981 | G4cout <<
|
|---|
| 982 | "ERROR: G4VisCommandsViewerPan::SetNewValue: no current viewer."
|
|---|
| 983 | << G4endl;
|
|---|
| 984 | }
|
|---|
| 985 | return;
|
|---|
| 986 | }
|
|---|
| 987 |
|
|---|
| 988 | G4ViewParameters vp = currentViewer->GetViewParameters();
|
|---|
| 989 |
|
|---|
| 990 | if (command == fpCommandPan) {
|
|---|
| 991 | ConvertToDoublePair(newValue, fPanIncrementRight, fPanIncrementUp);
|
|---|
| 992 | vp.IncrementPan(fPanIncrementRight, fPanIncrementUp);
|
|---|
| 993 | }
|
|---|
| 994 | else if (command == fpCommandPanTo) {
|
|---|
| 995 | ConvertToDoublePair(newValue, fPanToRight, fPanToUp);
|
|---|
| 996 | vp.SetPan(fPanToRight, fPanToUp);
|
|---|
| 997 | }
|
|---|
| 998 |
|
|---|
| 999 | if (verbosity >= G4VisManager::confirmations) {
|
|---|
| 1000 | G4cout << "Current target point now " << vp.GetCurrentTargetPoint()
|
|---|
| 1001 | << G4endl;
|
|---|
| 1002 | }
|
|---|
| 1003 |
|
|---|
| 1004 | SetViewParameters(currentViewer, vp);
|
|---|
| 1005 | }
|
|---|
| 1006 |
|
|---|
| 1007 | ////////////// /vis/viewer/rebuild ///////////////////////////////////////
|
|---|
| 1008 |
|
|---|
| 1009 | G4VisCommandViewerRebuild::G4VisCommandViewerRebuild () {
|
|---|
| 1010 | G4bool omitable, currentAsDefault;
|
|---|
| 1011 | fpCommand = new G4UIcmdWithAString ("/vis/viewer/rebuild", this);
|
|---|
| 1012 | fpCommand -> SetGuidance ("Forces rebuild of graphical database.");
|
|---|
| 1013 | fpCommand -> SetGuidance
|
|---|
| 1014 | ("By default, acts on current viewer. \"/vis/viewer/list\""
|
|---|
| 1015 | "\nto see possible viewers. Viewer becomes current.");
|
|---|
| 1016 | fpCommand -> SetParameterName ("viewer-name",
|
|---|
| 1017 | omitable = true,
|
|---|
| 1018 | currentAsDefault = true);
|
|---|
| 1019 | }
|
|---|
| 1020 |
|
|---|
| 1021 | G4VisCommandViewerRebuild::~G4VisCommandViewerRebuild () {
|
|---|
| 1022 | delete fpCommand;
|
|---|
| 1023 | }
|
|---|
| 1024 |
|
|---|
| 1025 | G4String G4VisCommandViewerRebuild::GetCurrentValue (G4UIcommand*) {
|
|---|
| 1026 | G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
|
|---|
| 1027 | if (viewer) {
|
|---|
| 1028 | return viewer -> GetName ();
|
|---|
| 1029 | }
|
|---|
| 1030 | else {
|
|---|
| 1031 | return "none";
|
|---|
| 1032 | }
|
|---|
| 1033 | }
|
|---|
| 1034 |
|
|---|
| 1035 | void G4VisCommandViewerRebuild::SetNewValue (G4UIcommand*, G4String newValue) {
|
|---|
| 1036 |
|
|---|
| 1037 | G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
|
|---|
| 1038 |
|
|---|
| 1039 | G4String& rebuildName = newValue;
|
|---|
| 1040 |
|
|---|
| 1041 | G4VViewer* viewer = fpVisManager -> GetViewer (rebuildName);
|
|---|
| 1042 | if (!viewer) {
|
|---|
| 1043 | if (verbosity >= G4VisManager::errors) {
|
|---|
| 1044 | G4cout << "ERROR: Viewer \"" << rebuildName
|
|---|
| 1045 | << "\" not found - \"/vis/viewer/list\" to see possibilities."
|
|---|
| 1046 | << G4endl;
|
|---|
| 1047 | }
|
|---|
| 1048 | return;
|
|---|
| 1049 | }
|
|---|
| 1050 |
|
|---|
| 1051 | G4VSceneHandler* sceneHandler = viewer->GetSceneHandler();
|
|---|
| 1052 | if (!sceneHandler) {
|
|---|
| 1053 | if (verbosity >= G4VisManager::errors) {
|
|---|
| 1054 | G4cout << "ERROR: Viewer \"" << viewer->GetName() << "\"" <<
|
|---|
| 1055 | " has no scene handler - report serious bug."
|
|---|
| 1056 | << G4endl;
|
|---|
| 1057 | }
|
|---|
| 1058 | return;
|
|---|
| 1059 | }
|
|---|
| 1060 |
|
|---|
| 1061 | sceneHandler->ClearTransientStore();
|
|---|
| 1062 | viewer->NeedKernelVisit();
|
|---|
| 1063 | viewer->SetView();
|
|---|
| 1064 | viewer->ClearView();
|
|---|
| 1065 | viewer->DrawView();
|
|---|
| 1066 |
|
|---|
| 1067 | // Check auto-refresh and print confirmations, but without changing
|
|---|
| 1068 | // view paramters...
|
|---|
| 1069 | SetViewParameters(viewer, viewer->GetViewParameters());
|
|---|
| 1070 | }
|
|---|
| 1071 |
|
|---|
| 1072 | ////////////// /vis/viewer/refresh ///////////////////////////////////////
|
|---|
| 1073 |
|
|---|
| 1074 | G4VisCommandViewerRefresh::G4VisCommandViewerRefresh () {
|
|---|
| 1075 | G4bool omitable, currentAsDefault;
|
|---|
| 1076 | fpCommand = new G4UIcmdWithAString ("/vis/viewer/refresh", this);
|
|---|
| 1077 | fpCommand -> SetGuidance
|
|---|
| 1078 | ("Refreshes viewer.");
|
|---|
| 1079 | fpCommand -> SetGuidance
|
|---|
| 1080 | ("By default, acts on current viewer. \"/vis/viewer/list\""
|
|---|
| 1081 | "\nto see possible viewers. Viewer becomes current.");
|
|---|
| 1082 | fpCommand -> SetParameterName ("viewer-name",
|
|---|
| 1083 | omitable = true,
|
|---|
| 1084 | currentAsDefault = true);
|
|---|
| 1085 | }
|
|---|
| 1086 |
|
|---|
| 1087 | G4VisCommandViewerRefresh::~G4VisCommandViewerRefresh () {
|
|---|
| 1088 | delete fpCommand;
|
|---|
| 1089 | }
|
|---|
| 1090 |
|
|---|
| 1091 | G4String G4VisCommandViewerRefresh::GetCurrentValue (G4UIcommand*) {
|
|---|
| 1092 | G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
|
|---|
| 1093 | return viewer ? viewer -> GetName () : G4String("none");
|
|---|
| 1094 | }
|
|---|
| 1095 |
|
|---|
| 1096 | void G4VisCommandViewerRefresh::SetNewValue (G4UIcommand*, G4String newValue) {
|
|---|
| 1097 |
|
|---|
| 1098 | G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
|
|---|
| 1099 | G4bool warn(verbosity >= G4VisManager::warnings);
|
|---|
| 1100 |
|
|---|
| 1101 | G4String& refreshName = newValue;
|
|---|
| 1102 | G4VViewer* viewer = fpVisManager -> GetViewer (refreshName);
|
|---|
| 1103 | if (!viewer) {
|
|---|
| 1104 | if (verbosity >= G4VisManager::errors) {
|
|---|
| 1105 | G4cout << "ERROR: Viewer \"" << refreshName << "\"" <<
|
|---|
| 1106 | " not found - \"/vis/viewer/list\"\n to see possibilities."
|
|---|
| 1107 | << G4endl;
|
|---|
| 1108 | }
|
|---|
| 1109 | return;
|
|---|
| 1110 | }
|
|---|
| 1111 |
|
|---|
| 1112 | G4VSceneHandler* sceneHandler = viewer->GetSceneHandler();
|
|---|
| 1113 | if (!sceneHandler) {
|
|---|
| 1114 | if (verbosity >= G4VisManager::errors) {
|
|---|
| 1115 | G4cout << "ERROR: Viewer \"" << refreshName << "\"" <<
|
|---|
| 1116 | " has no scene handler - report serious bug."
|
|---|
| 1117 | << G4endl;
|
|---|
| 1118 | }
|
|---|
| 1119 | return;
|
|---|
| 1120 | }
|
|---|
| 1121 |
|
|---|
| 1122 | G4Scene* scene = sceneHandler->GetScene();
|
|---|
| 1123 | if (!scene) {
|
|---|
| 1124 | if (verbosity >= G4VisManager::confirmations) {
|
|---|
| 1125 | G4cout << "NOTE: SceneHandler \"" << sceneHandler->GetName()
|
|---|
| 1126 | << "\", to which viewer \"" << refreshName << "\"" <<
|
|---|
| 1127 | "\n is attached, has no scene - \"/vis/scene/create\" and"
|
|---|
| 1128 | " \"/vis/sceneHandler/attach\""
|
|---|
| 1129 | "\n (or use compound command \"/vis/drawVolume\")."
|
|---|
| 1130 | << G4endl;
|
|---|
| 1131 | }
|
|---|
| 1132 | return;
|
|---|
| 1133 | }
|
|---|
| 1134 | if (scene->GetRunDurationModelList().empty()) {
|
|---|
| 1135 | G4bool successful = scene -> AddWorldIfEmpty (warn);
|
|---|
| 1136 | if (!successful) {
|
|---|
| 1137 | if (verbosity >= G4VisManager::warnings) {
|
|---|
| 1138 | G4cout <<
|
|---|
| 1139 | "WARNING: Scene is empty. Perhaps no geometry exists."
|
|---|
| 1140 | "\n Try /run/initialize."
|
|---|
| 1141 | << G4endl;
|
|---|
| 1142 | }
|
|---|
| 1143 | return;
|
|---|
| 1144 | }
|
|---|
| 1145 | // Scene has changed. UpdateVisManagerScene issues
|
|---|
| 1146 | // /vis/scene/notifyHandlers, which does a refresh anyway, so the
|
|---|
| 1147 | // ordinary refresh becomes part of the else phrase...
|
|---|
| 1148 | UpdateVisManagerScene(scene->GetName());
|
|---|
| 1149 | } else {
|
|---|
| 1150 | if (verbosity >= G4VisManager::confirmations) {
|
|---|
| 1151 | G4cout << "Refreshing viewer \"" << viewer -> GetName () << "\"..."
|
|---|
| 1152 | << G4endl;
|
|---|
| 1153 | }
|
|---|
| 1154 | viewer -> SetView ();
|
|---|
| 1155 | viewer -> ClearView ();
|
|---|
| 1156 | viewer -> DrawView ();
|
|---|
| 1157 | if (verbosity >= G4VisManager::confirmations) {
|
|---|
| 1158 | G4cout << "Viewer \"" << viewer -> GetName () << "\"" << " refreshed."
|
|---|
| 1159 | "\n (You might also need \"/vis/viewer/update\".)" << G4endl;
|
|---|
| 1160 | }
|
|---|
| 1161 | }
|
|---|
| 1162 | }
|
|---|
| 1163 |
|
|---|
| 1164 | ////////////// /vis/viewer/reset ///////////////////////////////////////
|
|---|
| 1165 |
|
|---|
| 1166 | G4VisCommandViewerReset::G4VisCommandViewerReset () {
|
|---|
| 1167 | G4bool omitable, currentAsDefault;
|
|---|
| 1168 | fpCommand = new G4UIcmdWithAString ("/vis/viewer/reset", this);
|
|---|
| 1169 | fpCommand -> SetGuidance ("Resets viewer.");
|
|---|
| 1170 | fpCommand -> SetGuidance
|
|---|
| 1171 | ("By default, acts on current viewer. \"/vis/viewer/list\""
|
|---|
| 1172 | "\nto see possible viewers. Viewer becomes current.");
|
|---|
| 1173 | fpCommand -> SetParameterName ("viewer-name",
|
|---|
| 1174 | omitable = true,
|
|---|
| 1175 | currentAsDefault = true);
|
|---|
| 1176 | }
|
|---|
| 1177 |
|
|---|
| 1178 | G4VisCommandViewerReset::~G4VisCommandViewerReset () {
|
|---|
| 1179 | delete fpCommand;
|
|---|
| 1180 | }
|
|---|
| 1181 |
|
|---|
| 1182 | G4String G4VisCommandViewerReset::GetCurrentValue (G4UIcommand*) {
|
|---|
| 1183 | G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
|
|---|
| 1184 | if (viewer) {
|
|---|
| 1185 | return viewer -> GetName ();
|
|---|
| 1186 | }
|
|---|
| 1187 | else {
|
|---|
| 1188 | return "none";
|
|---|
| 1189 | }
|
|---|
| 1190 | }
|
|---|
| 1191 |
|
|---|
| 1192 | void G4VisCommandViewerReset::SetNewValue (G4UIcommand*, G4String newValue) {
|
|---|
| 1193 |
|
|---|
| 1194 | G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
|
|---|
| 1195 |
|
|---|
| 1196 | G4String& resetName = newValue;
|
|---|
| 1197 | G4VViewer* viewer = fpVisManager -> GetViewer (resetName);
|
|---|
| 1198 | if (!viewer) {
|
|---|
| 1199 | if (verbosity >= G4VisManager::errors) {
|
|---|
| 1200 | G4cout << "ERROR: Viewer \"" << resetName
|
|---|
| 1201 | << "\" not found - \"/vis/viewer/list\" to see possibilities."
|
|---|
| 1202 | << G4endl;
|
|---|
| 1203 | }
|
|---|
| 1204 | return;
|
|---|
| 1205 | }
|
|---|
| 1206 |
|
|---|
| 1207 | SetViewParameters(viewer, viewer->GetDefaultViewParameters());
|
|---|
| 1208 | }
|
|---|
| 1209 |
|
|---|
| 1210 | ////////////// /vis/viewer/scale and scaleTo ////////////////////////////
|
|---|
| 1211 |
|
|---|
| 1212 | G4VisCommandViewerScale::G4VisCommandViewerScale ():
|
|---|
| 1213 | fScaleMultiplier (G4Vector3D (1., 1., 1.)),
|
|---|
| 1214 | fScaleTo (G4Vector3D (1., 1., 1.))
|
|---|
| 1215 | {
|
|---|
| 1216 | G4bool omitable, currentAsDefault;
|
|---|
| 1217 |
|
|---|
| 1218 | fpCommandScale = new G4UIcmdWith3Vector
|
|---|
| 1219 | ("/vis/viewer/scale", this);
|
|---|
| 1220 | fpCommandScale -> SetGuidance ("Incremental (non-uniform) scaling.");
|
|---|
| 1221 | fpCommandScale -> SetGuidance
|
|---|
| 1222 | ("Multiplies components of current scaling by components of this factor."
|
|---|
| 1223 | "\n Scales (x,y,z) by corresponding components of the resulting factor.");
|
|---|
| 1224 | fpCommandScale -> SetGuidance
|
|---|
| 1225 | ("");
|
|---|
| 1226 | fpCommandScale -> SetParameterName
|
|---|
| 1227 | ("x-scale-multiplier","y-scale-multiplier","z-scale-multiplier",
|
|---|
| 1228 | omitable=true, currentAsDefault=true);
|
|---|
| 1229 |
|
|---|
| 1230 | fpCommandScaleTo = new G4UIcmdWith3Vector
|
|---|
| 1231 | ("/vis/viewer/scaleTo", this);
|
|---|
| 1232 | fpCommandScaleTo -> SetGuidance ("Absolute (non-uniform) scaling.");
|
|---|
| 1233 | fpCommandScaleTo -> SetGuidance
|
|---|
| 1234 | ("Scales (x,y,z) by corresponding components of this factor.");
|
|---|
| 1235 | fpCommandScaleTo -> SetParameterName
|
|---|
| 1236 | ("x-scale-factor","y-scale-factor","z-scale-factor",
|
|---|
| 1237 | omitable=true, currentAsDefault=true);
|
|---|
| 1238 | }
|
|---|
| 1239 |
|
|---|
| 1240 | G4VisCommandViewerScale::~G4VisCommandViewerScale () {
|
|---|
| 1241 | delete fpCommandScale;
|
|---|
| 1242 | delete fpCommandScaleTo;
|
|---|
| 1243 | }
|
|---|
| 1244 |
|
|---|
| 1245 | G4String G4VisCommandViewerScale::GetCurrentValue (G4UIcommand* command) {
|
|---|
| 1246 | G4String currentValue;
|
|---|
| 1247 | if (command == fpCommandScale) {
|
|---|
| 1248 | currentValue = fpCommandScale->ConvertToString(G4ThreeVector(fScaleMultiplier));
|
|---|
| 1249 | }
|
|---|
| 1250 | else if (command == fpCommandScaleTo) {
|
|---|
| 1251 | currentValue = fpCommandScaleTo->ConvertToString(G4ThreeVector(fScaleTo));
|
|---|
| 1252 | }
|
|---|
| 1253 | return currentValue;
|
|---|
| 1254 | }
|
|---|
| 1255 |
|
|---|
| 1256 | void G4VisCommandViewerScale::SetNewValue (G4UIcommand* command,
|
|---|
| 1257 | G4String newValue) {
|
|---|
| 1258 |
|
|---|
| 1259 |
|
|---|
| 1260 | G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
|
|---|
| 1261 |
|
|---|
| 1262 | G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
|
|---|
| 1263 | if (!currentViewer) {
|
|---|
| 1264 | if (verbosity >= G4VisManager::errors) {
|
|---|
| 1265 | G4cout <<
|
|---|
| 1266 | "ERROR: G4VisCommandsViewerScale::SetNewValue: no current viewer."
|
|---|
| 1267 | << G4endl;
|
|---|
| 1268 | }
|
|---|
| 1269 | return;
|
|---|
| 1270 | }
|
|---|
| 1271 |
|
|---|
| 1272 | G4ViewParameters vp = currentViewer->GetViewParameters();
|
|---|
| 1273 |
|
|---|
| 1274 | if (command == fpCommandScale) {
|
|---|
| 1275 | fScaleMultiplier = fpCommandScale->GetNew3VectorValue(newValue);
|
|---|
| 1276 | vp.MultiplyScaleFactor(fScaleMultiplier);
|
|---|
| 1277 | }
|
|---|
| 1278 | else if (command == fpCommandScaleTo) {
|
|---|
| 1279 | fScaleTo = fpCommandScale->GetNew3VectorValue(newValue);
|
|---|
| 1280 | vp.SetScaleFactor(fScaleTo);
|
|---|
| 1281 | }
|
|---|
| 1282 |
|
|---|
| 1283 | if (verbosity >= G4VisManager::confirmations) {
|
|---|
| 1284 | G4cout << "Scale factor changed to " << vp.GetScaleFactor() << G4endl;
|
|---|
| 1285 | }
|
|---|
| 1286 |
|
|---|
| 1287 | SetViewParameters(currentViewer, vp);
|
|---|
| 1288 | }
|
|---|
| 1289 |
|
|---|
| 1290 | ////////////// /vis/viewer/select ///////////////////////////////////////
|
|---|
| 1291 |
|
|---|
| 1292 | G4VisCommandViewerSelect::G4VisCommandViewerSelect () {
|
|---|
| 1293 | G4bool omitable;
|
|---|
| 1294 | fpCommand = new G4UIcmdWithAString ("/vis/viewer/select", this);
|
|---|
| 1295 | fpCommand -> SetGuidance ("Selects viewer.");
|
|---|
| 1296 | fpCommand -> SetGuidance
|
|---|
| 1297 | ("Specify viewer by name. \"/vis/viewer/list\" to see possible viewers.");
|
|---|
| 1298 | fpCommand -> SetParameterName ("viewer-name", omitable = false);
|
|---|
| 1299 | }
|
|---|
| 1300 |
|
|---|
| 1301 | G4VisCommandViewerSelect::~G4VisCommandViewerSelect () {
|
|---|
| 1302 | delete fpCommand;
|
|---|
| 1303 | }
|
|---|
| 1304 |
|
|---|
| 1305 | G4String G4VisCommandViewerSelect::GetCurrentValue (G4UIcommand*) {
|
|---|
| 1306 | return "";
|
|---|
| 1307 | }
|
|---|
| 1308 |
|
|---|
| 1309 | void G4VisCommandViewerSelect::SetNewValue (G4UIcommand*, G4String newValue) {
|
|---|
| 1310 |
|
|---|
| 1311 | G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
|
|---|
| 1312 |
|
|---|
| 1313 | G4String& selectName = newValue;
|
|---|
| 1314 | G4VViewer* viewer = fpVisManager -> GetViewer (selectName);
|
|---|
| 1315 |
|
|---|
| 1316 | if (!viewer) {
|
|---|
| 1317 | if (verbosity >= G4VisManager::errors) {
|
|---|
| 1318 | G4cout << "ERROR: Viewer \"" << selectName << "\"";
|
|---|
| 1319 | G4cout << " not found - \"/vis/viewer/list\""
|
|---|
| 1320 | "\n to see possibilities."
|
|---|
| 1321 | << G4endl;
|
|---|
| 1322 | }
|
|---|
| 1323 | return;
|
|---|
| 1324 | }
|
|---|
| 1325 |
|
|---|
| 1326 | if (viewer == fpVisManager -> GetCurrentViewer ()) {
|
|---|
| 1327 | if (verbosity >= G4VisManager::warnings) {
|
|---|
| 1328 | G4cout << "WARNING: Viewer \"" << viewer -> GetName () << "\""
|
|---|
| 1329 | << " already selected." << G4endl;
|
|---|
| 1330 | }
|
|---|
| 1331 | return;
|
|---|
| 1332 | }
|
|---|
| 1333 |
|
|---|
| 1334 | fpVisManager -> SetCurrentViewer (viewer); // Prints confirmation.
|
|---|
| 1335 |
|
|---|
| 1336 | SetViewParameters(viewer, viewer->GetViewParameters());
|
|---|
| 1337 | }
|
|---|
| 1338 |
|
|---|
| 1339 | ////////////// /vis/viewer/update ///////////////////////////////////////
|
|---|
| 1340 |
|
|---|
| 1341 | G4VisCommandViewerUpdate::G4VisCommandViewerUpdate () {
|
|---|
| 1342 | G4bool omitable, currentAsDefault;
|
|---|
| 1343 | fpCommand = new G4UIcmdWithAString ("/vis/viewer/update", this);
|
|---|
| 1344 | fpCommand -> SetGuidance
|
|---|
| 1345 | ("Triggers graphical database post-processing for viewers"
|
|---|
| 1346 | "\nusing that technique.");
|
|---|
| 1347 | fpCommand -> SetGuidance
|
|---|
| 1348 | ("For such viewers the view only becomes visible with this command."
|
|---|
| 1349 | "\nBy default, acts on current viewer. \"/vis/viewer/list\""
|
|---|
| 1350 | "\nto see possible viewers. Viewer becomes current.");
|
|---|
| 1351 | fpCommand -> SetParameterName ("viewer-name",
|
|---|
| 1352 | omitable = true,
|
|---|
| 1353 | currentAsDefault = true);
|
|---|
| 1354 | }
|
|---|
| 1355 |
|
|---|
| 1356 | G4VisCommandViewerUpdate::~G4VisCommandViewerUpdate () {
|
|---|
| 1357 | delete fpCommand;
|
|---|
| 1358 | }
|
|---|
| 1359 |
|
|---|
| 1360 | G4String G4VisCommandViewerUpdate::GetCurrentValue (G4UIcommand*) {
|
|---|
| 1361 | G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
|
|---|
| 1362 | if (viewer) {
|
|---|
| 1363 | return viewer -> GetName ();
|
|---|
| 1364 | }
|
|---|
| 1365 | else {
|
|---|
| 1366 | return "none";
|
|---|
| 1367 | }
|
|---|
| 1368 | }
|
|---|
| 1369 |
|
|---|
| 1370 | void G4VisCommandViewerUpdate::SetNewValue (G4UIcommand*, G4String newValue) {
|
|---|
| 1371 |
|
|---|
| 1372 | G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
|
|---|
| 1373 |
|
|---|
| 1374 | G4String& updateName = newValue;
|
|---|
| 1375 |
|
|---|
| 1376 | G4VViewer* viewer = fpVisManager -> GetViewer (updateName);
|
|---|
| 1377 | if (!viewer) {
|
|---|
| 1378 | if (verbosity >= G4VisManager::errors) {
|
|---|
| 1379 | G4cout <<
|
|---|
| 1380 | "ERROR: G4VisCommandsViewerUpdate::SetNewValue: no current viewer."
|
|---|
| 1381 | << G4endl;
|
|---|
| 1382 | }
|
|---|
| 1383 | return;
|
|---|
| 1384 | }
|
|---|
| 1385 |
|
|---|
| 1386 | G4VSceneHandler* sceneHandler = viewer->GetSceneHandler();
|
|---|
| 1387 | if (!sceneHandler) {
|
|---|
| 1388 | if (verbosity >= G4VisManager::errors) {
|
|---|
| 1389 | G4cout << "ERROR: Viewer \"" << updateName << "\"" <<
|
|---|
| 1390 | " has no scene handler - report serious bug."
|
|---|
| 1391 | << G4endl;
|
|---|
| 1392 | }
|
|---|
| 1393 | return;
|
|---|
| 1394 | }
|
|---|
| 1395 |
|
|---|
| 1396 | G4Scene* scene = sceneHandler->GetScene();
|
|---|
| 1397 | if (!scene) {
|
|---|
| 1398 | if (verbosity >= G4VisManager::confirmations) {
|
|---|
| 1399 | G4cout << "NOTE: SceneHandler \"" << sceneHandler->GetName()
|
|---|
| 1400 | << "\", to which viewer \"" << updateName << "\"" <<
|
|---|
| 1401 | "\n is attached, has no scene - \"/vis/scene/create\" and"
|
|---|
| 1402 | " \"/vis/sceneHandler/attach\""
|
|---|
| 1403 | "\n (or use compound command \"/vis/drawVolume\")."
|
|---|
| 1404 | << G4endl;
|
|---|
| 1405 | }
|
|---|
| 1406 | return;
|
|---|
| 1407 | }
|
|---|
| 1408 |
|
|---|
| 1409 | if (viewer) {
|
|---|
| 1410 | if (verbosity >= G4VisManager::confirmations) {
|
|---|
| 1411 | G4cout << "Viewer \"" << viewer -> GetName () << "\"";
|
|---|
| 1412 | G4cout << " post-processing triggered." << G4endl;
|
|---|
| 1413 | }
|
|---|
| 1414 | viewer -> ShowView ();
|
|---|
| 1415 | // Assume future need to "refresh" transients...
|
|---|
| 1416 | sceneHandler -> SetMarkForClearingTransientStore(true);
|
|---|
| 1417 | }
|
|---|
| 1418 | else {
|
|---|
| 1419 | if (verbosity >= G4VisManager::errors) {
|
|---|
| 1420 | G4cout << "ERROR: Viewer \"" << updateName << "\"";
|
|---|
| 1421 | G4cout << " not found - \"/vis/viewer/list\""
|
|---|
| 1422 | "\n to see possibilities." << G4endl;
|
|---|
| 1423 | }
|
|---|
| 1424 | }
|
|---|
| 1425 | }
|
|---|
| 1426 |
|
|---|
| 1427 | ////////////// /vis/viewer/zoom and zoomTo ////////////////////////////
|
|---|
| 1428 |
|
|---|
| 1429 | G4VisCommandViewerZoom::G4VisCommandViewerZoom ():
|
|---|
| 1430 | fZoomMultiplier (1.),
|
|---|
| 1431 | fZoomTo (1.)
|
|---|
| 1432 | {
|
|---|
| 1433 | G4bool omitable, currentAsDefault;
|
|---|
| 1434 |
|
|---|
| 1435 | fpCommandZoom = new G4UIcmdWithADouble
|
|---|
| 1436 | ("/vis/viewer/zoom", this);
|
|---|
| 1437 | fpCommandZoom -> SetGuidance ("Incremental zoom.");
|
|---|
| 1438 | fpCommandZoom -> SetGuidance
|
|---|
| 1439 | ("Multiplies current magnification by this factor.");
|
|---|
| 1440 | fpCommandZoom -> SetParameterName("multiplier",
|
|---|
| 1441 | omitable=true,
|
|---|
| 1442 | currentAsDefault=true);
|
|---|
| 1443 |
|
|---|
| 1444 | fpCommandZoomTo = new G4UIcmdWithADouble
|
|---|
| 1445 | ("/vis/viewer/zoomTo", this);
|
|---|
| 1446 | fpCommandZoomTo -> SetGuidance ("Absolute zoom.");
|
|---|
| 1447 | fpCommandZoomTo -> SetGuidance
|
|---|
| 1448 | ("Magnifies standard magnification by this factor.");
|
|---|
| 1449 | fpCommandZoomTo -> SetParameterName("factor",
|
|---|
| 1450 | omitable=true,
|
|---|
| 1451 | currentAsDefault=true);
|
|---|
| 1452 | }
|
|---|
| 1453 |
|
|---|
| 1454 | G4VisCommandViewerZoom::~G4VisCommandViewerZoom () {
|
|---|
| 1455 | delete fpCommandZoom;
|
|---|
| 1456 | delete fpCommandZoomTo;
|
|---|
| 1457 | }
|
|---|
| 1458 |
|
|---|
| 1459 | G4String G4VisCommandViewerZoom::GetCurrentValue (G4UIcommand* command) {
|
|---|
| 1460 | G4String currentValue;
|
|---|
| 1461 | if (command == fpCommandZoom) {
|
|---|
| 1462 | currentValue = fpCommandZoom->ConvertToString(fZoomMultiplier);
|
|---|
| 1463 | }
|
|---|
| 1464 | else if (command == fpCommandZoomTo) {
|
|---|
| 1465 | currentValue = fpCommandZoomTo->ConvertToString(fZoomTo);
|
|---|
| 1466 | }
|
|---|
| 1467 | return currentValue;
|
|---|
| 1468 | }
|
|---|
| 1469 |
|
|---|
| 1470 | void G4VisCommandViewerZoom::SetNewValue (G4UIcommand* command,
|
|---|
| 1471 | G4String newValue) {
|
|---|
| 1472 |
|
|---|
| 1473 |
|
|---|
| 1474 | G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
|
|---|
| 1475 |
|
|---|
| 1476 | G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
|
|---|
| 1477 | if (!currentViewer) {
|
|---|
| 1478 | if (verbosity >= G4VisManager::errors) {
|
|---|
| 1479 | G4cout <<
|
|---|
| 1480 | "ERROR: G4VisCommandsViewerZoom::SetNewValue: no current viewer."
|
|---|
| 1481 | << G4endl;
|
|---|
| 1482 | }
|
|---|
| 1483 | return;
|
|---|
| 1484 | }
|
|---|
| 1485 |
|
|---|
| 1486 | G4ViewParameters vp = currentViewer->GetViewParameters();
|
|---|
| 1487 |
|
|---|
| 1488 | if (command == fpCommandZoom) {
|
|---|
| 1489 | fZoomMultiplier = fpCommandZoom->GetNewDoubleValue(newValue);
|
|---|
| 1490 | vp.MultiplyZoomFactor(fZoomMultiplier);
|
|---|
| 1491 | }
|
|---|
| 1492 | else if (command == fpCommandZoomTo) {
|
|---|
| 1493 | fZoomTo = fpCommandZoom->GetNewDoubleValue(newValue);
|
|---|
| 1494 | vp.SetZoomFactor(fZoomTo);
|
|---|
| 1495 | }
|
|---|
| 1496 |
|
|---|
| 1497 | if (verbosity >= G4VisManager::confirmations) {
|
|---|
| 1498 | G4cout << "Zoom factor changed to " << vp.GetZoomFactor() << G4endl;
|
|---|
| 1499 | }
|
|---|
| 1500 |
|
|---|
| 1501 | SetViewParameters(currentViewer, vp);
|
|---|
| 1502 | }
|
|---|