| [531] | 1 | //
|
|---|
| 2 | // ********************************************************************
|
|---|
| 3 | // * License and Disclaimer *
|
|---|
| 4 | // * *
|
|---|
| 5 | // * The Geant4 software is copyright of the Copyright Holders of *
|
|---|
| 6 | // * the Geant4 Collaboration. It is provided under the terms and *
|
|---|
| 7 | // * conditions of the Geant4 Software License, included in the file *
|
|---|
| 8 | // * LICENSE and available at http://cern.ch/geant4/license . These *
|
|---|
| 9 | // * include a list of copyright holders. *
|
|---|
| 10 | // * *
|
|---|
| 11 | // * Neither the authors of this software system, nor their employing *
|
|---|
| 12 | // * institutes,nor the agencies providing financial support for this *
|
|---|
| 13 | // * work make any representation or warranty, express or implied, *
|
|---|
| 14 | // * regarding this software system or assume any liability for its *
|
|---|
| 15 | // * use. Please see the license in the file LICENSE and URL above *
|
|---|
| 16 | // * for the full disclaimer and the limitation of liability. *
|
|---|
| 17 | // * *
|
|---|
| 18 | // * This code implementation is the result of the scientific and *
|
|---|
| 19 | // * technical work of the GEANT4 collaboration. *
|
|---|
| 20 | // * By using, copying, modifying or distributing the software (or *
|
|---|
| 21 | // * any work based on the software) you agree to acknowledge its *
|
|---|
| 22 | // * use in resulting scientific publications, and indicate your *
|
|---|
| 23 | // * acceptance of all terms of the Geant4 Software license. *
|
|---|
| 24 | // ********************************************************************
|
|---|
| 25 | //
|
|---|
| 26 | //
|
|---|
| [846] | 27 | // $Id: G4VisCommandsViewer.cc,v 1.70 2008/04/30 10:07:28 allison Exp $
|
|---|
| [850] | 28 | // GEANT4 tag $Name: HEAD $
|
|---|
| [531] | 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
|
|---|
| [593] | 75 | ("Add cutaway plane to current viewer.");
|
|---|
| [531] | 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;
|
|---|
| [846] | 407 | while (is.get(c) && c == ' '){}
|
|---|
| [531] | 408 | if (c == '"') {
|
|---|
| [846] | 409 | while (is.get(c) && c != '"') {originalName += c;}
|
|---|
| [531] | 410 | }
|
|---|
| 411 | else {
|
|---|
| 412 | originalName += c;
|
|---|
| [846] | 413 | while (is.get(c) && c != ' ') {originalName += c;}
|
|---|
| [531] | 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 |
|
|---|
| [846] | 429 | while (is.get(c) && c == ' '){}
|
|---|
| [531] | 430 | if (c == '"') {
|
|---|
| [846] | 431 | while (is.get(c) && c != '"') {cloneName += c;}
|
|---|
| [531] | 432 | }
|
|---|
| 433 | else {
|
|---|
| 434 | cloneName += c;
|
|---|
| [846] | 435 | while (is.get(c) && c != ' ') {cloneName += c;}
|
|---|
| [531] | 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 |
|
|---|
| [891] | 490 | G4VisCommandViewerCreate::G4VisCommandViewerCreate ():
|
|---|
| [896] | 491 | fId (0)
|
|---|
| 492 | {
|
|---|
| [531] | 493 | G4bool omitable;
|
|---|
| 494 | fpCommand = new G4UIcommand ("/vis/viewer/create", this);
|
|---|
| 495 | fpCommand -> SetGuidance
|
|---|
| 496 | ("Creates a viewer for the specified scene handler.");
|
|---|
| 497 | fpCommand -> SetGuidance
|
|---|
| 498 | ("Default scene handler is the current scene handler. Invents a name"
|
|---|
| 499 | "\nif not supplied. (Note: the system adds information to the name"
|
|---|
| 500 | "\nfor identification - only the characters up to the first blank are"
|
|---|
| 501 | "\nused for removing, selecting, etc.) This scene handler and viewer"
|
|---|
| 502 | "\nbecome current.");
|
|---|
| 503 | G4UIparameter* parameter;
|
|---|
| 504 | parameter = new G4UIparameter ("scene-handler", 's', omitable = true);
|
|---|
| 505 | parameter -> SetCurrentAsDefault (true);
|
|---|
| 506 | fpCommand -> SetParameter (parameter);
|
|---|
| 507 | parameter = new G4UIparameter ("viewer-name", 's', omitable = true);
|
|---|
| 508 | parameter -> SetCurrentAsDefault (true);
|
|---|
| 509 | fpCommand -> SetParameter (parameter);
|
|---|
| 510 | parameter = new G4UIparameter ("window-size-hint", 's', omitable = true);
|
|---|
| 511 | parameter->SetGuidance
|
|---|
| 512 | ("integer (pixels) for square window placed by window manager or"
|
|---|
| 513 | " X-Windows-type geometry string, e.g. 600x600-100+100");
|
|---|
| 514 | parameter->SetDefaultValue("600");
|
|---|
| 515 | fpCommand -> SetParameter (parameter);
|
|---|
| 516 | }
|
|---|
| 517 |
|
|---|
| 518 | G4VisCommandViewerCreate::~G4VisCommandViewerCreate () {
|
|---|
| 519 | delete fpCommand;
|
|---|
| 520 | }
|
|---|
| 521 |
|
|---|
| 522 | G4String G4VisCommandViewerCreate::NextName () {
|
|---|
| 523 | std::ostringstream oss;
|
|---|
| 524 | G4VSceneHandler* sceneHandler = fpVisManager -> GetCurrentSceneHandler ();
|
|---|
| 525 | oss << "viewer-" << fId << " (";
|
|---|
| 526 | if (sceneHandler) {
|
|---|
| 527 | oss << sceneHandler -> GetGraphicsSystem () -> GetName ();
|
|---|
| 528 | }
|
|---|
| 529 | else {
|
|---|
| 530 | oss << "no_scene_handlers";
|
|---|
| 531 | }
|
|---|
| 532 | oss << ")";
|
|---|
| 533 | return oss.str();
|
|---|
| 534 | }
|
|---|
| 535 |
|
|---|
| 536 | G4String G4VisCommandViewerCreate::GetCurrentValue (G4UIcommand*) {
|
|---|
| 537 | G4String currentValue;
|
|---|
| 538 | G4VSceneHandler* currentSceneHandler =
|
|---|
| 539 | fpVisManager -> GetCurrentSceneHandler ();
|
|---|
| 540 | if (currentSceneHandler) {
|
|---|
| 541 | currentValue = currentSceneHandler -> GetName ();
|
|---|
| 542 | }
|
|---|
| 543 | else {
|
|---|
| 544 | currentValue = "none";
|
|---|
| 545 | }
|
|---|
| 546 | currentValue += ' ';
|
|---|
| 547 | currentValue += '"';
|
|---|
| 548 | currentValue += NextName ();
|
|---|
| 549 | currentValue += '"';
|
|---|
| 550 |
|
|---|
| 551 | currentValue += " 600"; // Default number of pixels for window size hint.
|
|---|
| 552 |
|
|---|
| 553 | return currentValue;
|
|---|
| 554 | }
|
|---|
| 555 |
|
|---|
| 556 | void G4VisCommandViewerCreate::SetNewValue (G4UIcommand*, G4String newValue) {
|
|---|
| 557 |
|
|---|
| 558 | G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
|
|---|
| 559 |
|
|---|
| 560 | G4String sceneHandlerName, newName;
|
|---|
| 561 | G4String windowSizeHintString;
|
|---|
| 562 | std::istringstream is (newValue);
|
|---|
| 563 | is >> sceneHandlerName;
|
|---|
| 564 |
|
|---|
| 565 | // Now need to handle the possibility that the second string
|
|---|
| 566 | // contains embedded blanks within quotation marks...
|
|---|
| 567 | char c;
|
|---|
| [846] | 568 | while (is.get(c) && c == ' '){}
|
|---|
| [531] | 569 | if (c == '"') {
|
|---|
| [846] | 570 | while (is.get(c) && c != '"') {newName += c;}
|
|---|
| [531] | 571 | }
|
|---|
| 572 | else {
|
|---|
| 573 | newName += c;
|
|---|
| [846] | 574 | while (is.get(c) && c != ' ') {newName += c;}
|
|---|
| [531] | 575 | }
|
|---|
| 576 | newName = newName.strip (G4String::both, ' ');
|
|---|
| 577 | newName = newName.strip (G4String::both, '"');
|
|---|
| 578 |
|
|---|
| 579 | // Now get window size hint...
|
|---|
| 580 | is >> windowSizeHintString;
|
|---|
| 581 |
|
|---|
| 582 | const G4SceneHandlerList& sceneHandlerList =
|
|---|
| 583 | fpVisManager -> GetAvailableSceneHandlers ();
|
|---|
| 584 | G4int nHandlers = sceneHandlerList.size ();
|
|---|
| 585 | if (nHandlers <= 0) {
|
|---|
| 586 | if (verbosity >= G4VisManager::errors) {
|
|---|
| 587 | G4cout <<
|
|---|
| 588 | "ERROR: G4VisCommandViewerCreate::SetNewValue: no scene handlers."
|
|---|
| 589 | "\n Create a scene handler with \"/vis/sceneHandler/create\""
|
|---|
| 590 | << G4endl;
|
|---|
| 591 | }
|
|---|
| 592 | return;
|
|---|
| 593 | }
|
|---|
| 594 |
|
|---|
| 595 | G4int iHandler;
|
|---|
| 596 | for (iHandler = 0; iHandler < nHandlers; iHandler++) {
|
|---|
| 597 | if (sceneHandlerList [iHandler] -> GetName () == sceneHandlerName) break;
|
|---|
| 598 | }
|
|---|
| 599 |
|
|---|
| 600 | if (iHandler < 0 || iHandler >= nHandlers) {
|
|---|
| 601 | // Invalid command line argument or none.
|
|---|
| 602 | // This shouldn't happen!!!!!!
|
|---|
| 603 | if (verbosity >= G4VisManager::errors) {
|
|---|
| 604 | G4cout << "G4VisCommandViewerCreate::SetNewValue:"
|
|---|
| 605 | " invalid scene handler specified."
|
|---|
| 606 | << G4endl;
|
|---|
| 607 | }
|
|---|
| 608 | return;
|
|---|
| 609 | }
|
|---|
| 610 |
|
|---|
| 611 | // Valid index. Set current scene handler and graphics system in
|
|---|
| 612 | // preparation for creating viewer.
|
|---|
| 613 | G4VSceneHandler* sceneHandler = sceneHandlerList [iHandler];
|
|---|
| 614 | if (sceneHandler != fpVisManager -> GetCurrentSceneHandler ()) {
|
|---|
| 615 | fpVisManager -> SetCurrentSceneHandler (sceneHandler);
|
|---|
| 616 | }
|
|---|
| 617 |
|
|---|
| 618 | // Now deal with name of viewer.
|
|---|
| 619 | G4String nextName = NextName ();
|
|---|
| 620 | if (newName == "") {
|
|---|
| 621 | newName = nextName;
|
|---|
| 622 | }
|
|---|
| 623 | if (newName == nextName) fId++;
|
|---|
| 624 | G4String newShortName = fpVisManager -> ViewerShortName (newName);
|
|---|
| 625 |
|
|---|
| 626 | for (iHandler = 0; iHandler < nHandlers; iHandler++) {
|
|---|
| 627 | G4VSceneHandler* sceneHandler = sceneHandlerList [iHandler];
|
|---|
| 628 | const G4ViewerList& viewerList = sceneHandler -> GetViewerList ();
|
|---|
| 629 | for (size_t iViewer = 0; iViewer < viewerList.size (); iViewer++) {
|
|---|
| 630 | if (viewerList [iViewer] -> GetShortName () == newShortName ) {
|
|---|
| 631 | if (verbosity >= G4VisManager::errors) {
|
|---|
| 632 | G4cout << "ERROR: Viewer \"" << newShortName << "\" already exists."
|
|---|
| 633 | << G4endl;
|
|---|
| 634 | }
|
|---|
| 635 | return;
|
|---|
| 636 | }
|
|---|
| 637 | }
|
|---|
| 638 | }
|
|---|
| 639 |
|
|---|
| [891] | 640 |
|
|---|
| [531] | 641 | // Parse windowSizeHintString to extract first field for backwards
|
|---|
| 642 | // compatibility...
|
|---|
| 643 | std::istringstream issw;
|
|---|
| 644 | G4int windowSizeHint;
|
|---|
| 645 | size_t i;
|
|---|
| [891] | 646 | #ifdef G4DEBUG
|
|---|
| 647 | printf("G4VisCommandViewerCreate::SetNewValue string\n");
|
|---|
| 648 | #endif
|
|---|
| [531] | 649 | for (i = 0; i < windowSizeHintString.size(); ++i) {
|
|---|
| 650 | char c = windowSizeHintString[i];
|
|---|
| [891] | 651 | #ifdef G4DEBUG
|
|---|
| 652 | printf("%c",c);
|
|---|
| 653 | #endif
|
|---|
| [531] | 654 | if (c == 'x' || c == 'X' || c == '+' || c == '-') break;
|
|---|
| 655 | }
|
|---|
| [891] | 656 | #ifdef G4DEBUG
|
|---|
| 657 | printf("\n");
|
|---|
| 658 | #endif
|
|---|
| [531] | 659 | if (i != windowSizeHintString.size()) {
|
|---|
| 660 | // x or X or + or - found - must be a X-Window-type geometry string...
|
|---|
| 661 | // Pick out the first field for backwards compatibility...
|
|---|
| 662 | issw.str(windowSizeHintString.substr(0,i));
|
|---|
| 663 | issw >> windowSizeHint;
|
|---|
| 664 | } else { // ...old-style integer...
|
|---|
| 665 | issw.str(windowSizeHintString);
|
|---|
| 666 | if (!(issw >> windowSizeHint)) {
|
|---|
| 667 | if (verbosity >= G4VisManager::errors) {
|
|---|
| 668 | G4cout << "ERROR: Unrecognised geometry string \""
|
|---|
| 669 | << windowSizeHintString
|
|---|
| 670 | << "\". Using 600."
|
|---|
| 671 | << G4endl;
|
|---|
| 672 | }
|
|---|
| 673 | windowSizeHint = 600;
|
|---|
| 674 | }
|
|---|
| 675 | // Reconstitute windowSizeHintString...
|
|---|
| 676 | std::ostringstream ossw;
|
|---|
| 677 | ossw << windowSizeHint << 'x' << windowSizeHint;
|
|---|
| 678 | windowSizeHintString = ossw.str();
|
|---|
| 679 | }
|
|---|
| 680 | // WindowSizeHint and XGeometryString are picked up from the vis
|
|---|
| 681 | // manager in the G4VViewer constructor. They have to be held by
|
|---|
| 682 | // the vis manager until the viewer is contructed - next line...
|
|---|
| 683 |
|
|---|
| [896] | 684 | fpVisManager -> CreateViewer (newName,windowSizeHintString);
|
|---|
| [891] | 685 |
|
|---|
| [531] | 686 | G4VViewer* newViewer = fpVisManager -> GetCurrentViewer ();
|
|---|
| 687 | if (newViewer && newViewer -> GetName () == newName) {
|
|---|
| 688 | if (verbosity >= G4VisManager::confirmations) {
|
|---|
| 689 | G4cout << "New viewer \"" << newName << "\" created." << G4endl;
|
|---|
| 690 | }
|
|---|
| 691 | }
|
|---|
| 692 | else {
|
|---|
| 693 | if (verbosity >= G4VisManager::errors) {
|
|---|
| 694 | if (newViewer) {
|
|---|
| 695 | G4cout << "ERROR: New viewer doesn\'t match!!! Curious!!" << G4endl;
|
|---|
| 696 | } else {
|
|---|
| 697 | G4cout << "WARNING: No viewer created." << G4endl;
|
|---|
| 698 | }
|
|---|
| 699 | }
|
|---|
| 700 | }
|
|---|
| 701 | // Refresh if appropriate...
|
|---|
| 702 | if (newViewer) {
|
|---|
| 703 | if (newViewer->GetViewParameters().IsAutoRefresh()) {
|
|---|
| 704 | G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/refresh");
|
|---|
| 705 | }
|
|---|
| 706 | else {
|
|---|
| 707 | if (verbosity >= G4VisManager::confirmations) {
|
|---|
| 708 | G4cout << "Issue /vis/viewer/refresh to see effect." << G4endl;
|
|---|
| 709 | }
|
|---|
| 710 | }
|
|---|
| 711 | }
|
|---|
| 712 | }
|
|---|
| 713 |
|
|---|
| 714 | ////////////// /vis/viewer/dolly and dollyTo ////////////////////////////
|
|---|
| 715 |
|
|---|
| 716 | G4VisCommandViewerDolly::G4VisCommandViewerDolly ():
|
|---|
| 717 | fDollyIncrement (0.),
|
|---|
| 718 | fDollyTo (0.)
|
|---|
| 719 | {
|
|---|
| 720 | G4bool omitable, currentAsDefault;
|
|---|
| 721 |
|
|---|
| 722 | fpCommandDolly = new G4UIcmdWithADoubleAndUnit
|
|---|
| 723 | ("/vis/viewer/dolly", this);
|
|---|
| 724 | fpCommandDolly -> SetGuidance
|
|---|
| 725 | ("Incremental dolly.");
|
|---|
| 726 | fpCommandDolly -> SetGuidance
|
|---|
| 727 | ("Moves the camera incrementally towards target point.");
|
|---|
| 728 | fpCommandDolly -> SetParameterName("increment",
|
|---|
| 729 | omitable=true,
|
|---|
| 730 | currentAsDefault=true);
|
|---|
| 731 | fpCommandDolly -> SetDefaultUnit("m");
|
|---|
| 732 |
|
|---|
| 733 | fpCommandDollyTo = new G4UIcmdWithADoubleAndUnit
|
|---|
| 734 | ("/vis/viewer/dollyTo", this);
|
|---|
| 735 | fpCommandDollyTo -> SetGuidance
|
|---|
| 736 | ("Dolly to specific coordinate.");
|
|---|
| 737 | fpCommandDollyTo -> SetGuidance
|
|---|
| 738 | ("Places the camera towards target point relative to standard camera point.");
|
|---|
| 739 | fpCommandDollyTo -> SetParameterName("distance",
|
|---|
| 740 | omitable=true,
|
|---|
| 741 | currentAsDefault=true);
|
|---|
| 742 | fpCommandDollyTo -> SetDefaultUnit("m");
|
|---|
| 743 | }
|
|---|
| 744 |
|
|---|
| 745 | G4VisCommandViewerDolly::~G4VisCommandViewerDolly () {
|
|---|
| 746 | delete fpCommandDolly;
|
|---|
| 747 | delete fpCommandDollyTo;
|
|---|
| 748 | }
|
|---|
| 749 |
|
|---|
| 750 | G4String G4VisCommandViewerDolly::GetCurrentValue (G4UIcommand* command) {
|
|---|
| 751 | G4String currentValue;
|
|---|
| 752 | if (command == fpCommandDolly) {
|
|---|
| 753 | currentValue = fpCommandDolly->ConvertToString(fDollyIncrement, "m");
|
|---|
| 754 | }
|
|---|
| 755 | else if (command == fpCommandDollyTo) {
|
|---|
| 756 | currentValue = fpCommandDollyTo->ConvertToString(fDollyTo, "m");
|
|---|
| 757 | }
|
|---|
| 758 | return currentValue;
|
|---|
| 759 | }
|
|---|
| 760 |
|
|---|
| 761 | void G4VisCommandViewerDolly::SetNewValue (G4UIcommand* command,
|
|---|
| 762 | G4String newValue) {
|
|---|
| 763 |
|
|---|
| 764 |
|
|---|
| 765 | G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
|
|---|
| 766 |
|
|---|
| 767 | G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
|
|---|
| 768 | if (!currentViewer) {
|
|---|
| 769 | if (verbosity >= G4VisManager::errors) {
|
|---|
| 770 | G4cout <<
|
|---|
| 771 | "ERROR: G4VisCommandsViewerDolly::SetNewValue: no current viewer."
|
|---|
| 772 | << G4endl;
|
|---|
| 773 | }
|
|---|
| 774 | return;
|
|---|
| 775 | }
|
|---|
| 776 |
|
|---|
| 777 | G4ViewParameters vp = currentViewer->GetViewParameters();
|
|---|
| 778 |
|
|---|
| 779 | if (command == fpCommandDolly) {
|
|---|
| 780 | fDollyIncrement = fpCommandDolly->GetNewDoubleValue(newValue);
|
|---|
| 781 | vp.IncrementDolly(fDollyIncrement);
|
|---|
| 782 | }
|
|---|
| 783 | else if (command == fpCommandDollyTo) {
|
|---|
| 784 | fDollyTo = fpCommandDolly->GetNewDoubleValue(newValue);
|
|---|
| 785 | vp.SetDolly(fDollyTo);
|
|---|
| 786 | }
|
|---|
| 787 |
|
|---|
| 788 | if (verbosity >= G4VisManager::confirmations) {
|
|---|
| 789 | G4cout << "Dolly distance changed to " << vp.GetDolly() << G4endl;
|
|---|
| 790 | }
|
|---|
| 791 |
|
|---|
| 792 | SetViewParameters(currentViewer, vp);
|
|---|
| 793 | }
|
|---|
| 794 |
|
|---|
| 795 | ////////////// /vis/viewer/flush ///////////////////////////////////////
|
|---|
| 796 |
|
|---|
| 797 | G4VisCommandViewerFlush::G4VisCommandViewerFlush () {
|
|---|
| 798 | G4bool omitable, currentAsDefault;
|
|---|
| 799 | fpCommand = new G4UIcmdWithAString ("/vis/viewer/flush", this);
|
|---|
| 800 | fpCommand -> SetGuidance
|
|---|
| 801 | ("Compound command: \"/vis/viewer/refresh\" + \"/vis/viewer/update\".");
|
|---|
| 802 | fpCommand -> SetGuidance
|
|---|
| 803 | ("Useful for refreshing and initiating post-processing for graphics"
|
|---|
| 804 | "\nsystems which need post-processing. By default, acts on current"
|
|---|
| 805 | "\nviewer. \"/vis/viewer/list\" to see possible viewers. Viewer"
|
|---|
| 806 | "\nbecomes current.");
|
|---|
| 807 | fpCommand -> SetParameterName ("viewer-name",
|
|---|
| 808 | omitable = true,
|
|---|
| 809 | currentAsDefault = true);
|
|---|
| 810 | }
|
|---|
| 811 |
|
|---|
| 812 | G4VisCommandViewerFlush::~G4VisCommandViewerFlush () {
|
|---|
| 813 | delete fpCommand;
|
|---|
| 814 | }
|
|---|
| 815 |
|
|---|
| 816 | G4String G4VisCommandViewerFlush::GetCurrentValue
|
|---|
| 817 | (G4UIcommand*) {
|
|---|
| 818 | G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
|
|---|
| 819 | return viewer ? viewer -> GetName () : G4String("none");
|
|---|
| 820 | }
|
|---|
| 821 |
|
|---|
| 822 | void G4VisCommandViewerFlush::SetNewValue (G4UIcommand*, G4String newValue) {
|
|---|
| 823 |
|
|---|
| 824 | G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
|
|---|
| 825 |
|
|---|
| 826 | G4String& flushName = newValue;
|
|---|
| 827 | G4VViewer* viewer = fpVisManager -> GetViewer (flushName);
|
|---|
| 828 | if (!viewer) {
|
|---|
| 829 | if (verbosity >= G4VisManager::errors) {
|
|---|
| 830 | G4cout << "ERROR: Viewer \"" << flushName << "\"" <<
|
|---|
| 831 | " not found - \"/vis/viewer/list\"\n to see possibilities."
|
|---|
| 832 | << G4endl;
|
|---|
| 833 | }
|
|---|
| 834 | return;
|
|---|
| 835 | }
|
|---|
| 836 |
|
|---|
| 837 | G4UImanager* ui = G4UImanager::GetUIpointer();
|
|---|
| 838 | G4int keepVerbose = ui->GetVerboseLevel();
|
|---|
| 839 | G4int newVerbose(0);
|
|---|
| 840 | if (keepVerbose >= 2 || verbosity >= G4VisManager::confirmations)
|
|---|
| 841 | newVerbose = 2;
|
|---|
| 842 | ui->SetVerboseLevel(newVerbose);
|
|---|
| 843 | ui->ApplyCommand(G4String("/vis/viewer/refresh " + flushName));
|
|---|
| 844 | ui->ApplyCommand(G4String("/vis/viewer/update " + flushName));
|
|---|
| 845 | ui->SetVerboseLevel(keepVerbose);
|
|---|
| 846 | if (verbosity >= G4VisManager::confirmations) {
|
|---|
| 847 | G4cout << "Viewer \"" << viewer -> GetName () << "\""
|
|---|
| 848 | << " flushed." << G4endl;
|
|---|
| 849 | }
|
|---|
| 850 | }
|
|---|
| 851 |
|
|---|
| 852 | ////////////// /vis/viewer/list ///////////////////////////////////////
|
|---|
| 853 |
|
|---|
| 854 | G4VisCommandViewerList::G4VisCommandViewerList () {
|
|---|
| 855 | G4bool omitable;
|
|---|
| 856 | fpCommand = new G4UIcommand ("/vis/viewer/list", this);
|
|---|
| 857 | fpCommand -> SetGuidance ("Lists viewers(s).");
|
|---|
| 858 | fpCommand -> SetGuidance
|
|---|
| 859 | ("See \"/vis/verbose\" for definition of verbosity.");
|
|---|
| 860 | G4UIparameter* parameter;
|
|---|
| 861 | parameter = new G4UIparameter("viewer-name", 's',
|
|---|
| 862 | omitable = true);
|
|---|
| 863 | parameter -> SetDefaultValue ("all");
|
|---|
| 864 | fpCommand -> SetParameter (parameter);
|
|---|
| 865 | parameter = new G4UIparameter ("verbosity", 's',
|
|---|
| 866 | omitable = true);
|
|---|
| 867 | parameter -> SetDefaultValue ("warnings");
|
|---|
| 868 | fpCommand -> SetParameter (parameter);
|
|---|
| 869 | }
|
|---|
| 870 |
|
|---|
| 871 | G4VisCommandViewerList::~G4VisCommandViewerList () {
|
|---|
| 872 | delete fpCommand;
|
|---|
| 873 | }
|
|---|
| 874 |
|
|---|
| 875 | G4String G4VisCommandViewerList::GetCurrentValue (G4UIcommand*) {
|
|---|
| 876 | return "";
|
|---|
| 877 | }
|
|---|
| 878 |
|
|---|
| 879 | void G4VisCommandViewerList::SetNewValue (G4UIcommand*, G4String newValue) {
|
|---|
| 880 | G4String name, verbosityString;
|
|---|
| 881 | std::istringstream is (newValue);
|
|---|
| 882 | is >> name >> verbosityString;
|
|---|
| 883 | G4String shortName = fpVisManager -> ViewerShortName (name);
|
|---|
| 884 | G4VisManager::Verbosity verbosity =
|
|---|
| 885 | fpVisManager->GetVerbosityValue(verbosityString);
|
|---|
| 886 |
|
|---|
| 887 | const G4VViewer* currentViewer = fpVisManager -> GetCurrentViewer ();
|
|---|
| 888 | G4String currentViewerShortName;
|
|---|
| 889 | if (currentViewer) {
|
|---|
| 890 | currentViewerShortName = currentViewer -> GetShortName ();
|
|---|
| 891 | }
|
|---|
| 892 | else {
|
|---|
| 893 | currentViewerShortName = "none";
|
|---|
| 894 | }
|
|---|
| 895 |
|
|---|
| 896 | const G4SceneHandlerList& sceneHandlerList = fpVisManager -> GetAvailableSceneHandlers ();
|
|---|
| 897 | G4int nHandlers = sceneHandlerList.size ();
|
|---|
| 898 | G4bool found = false;
|
|---|
| 899 | G4bool foundCurrent = false;
|
|---|
| 900 | for (int iHandler = 0; iHandler < nHandlers; iHandler++) {
|
|---|
| 901 | G4VSceneHandler* sceneHandler = sceneHandlerList [iHandler];
|
|---|
| 902 | const G4ViewerList& viewerList = sceneHandler -> GetViewerList ();
|
|---|
| 903 | G4cout << "Scene handler \"" << sceneHandler -> GetName ();
|
|---|
| 904 | const G4Scene* pScene = sceneHandler -> GetScene ();
|
|---|
| 905 | if (pScene) {
|
|---|
| 906 | G4cout << "\", scene \"" << pScene -> GetName () << "\":";
|
|---|
| 907 | }
|
|---|
| 908 | G4int nViewers = viewerList.size ();
|
|---|
| 909 | if (nViewers == 0) {
|
|---|
| 910 | G4cout << "\n No viewers for this scene handler." << G4endl;
|
|---|
| 911 | }
|
|---|
| 912 | else {
|
|---|
| 913 | for (int iViewer = 0; iViewer < nViewers; iViewer++) {
|
|---|
| 914 | const G4VViewer* thisViewer = viewerList [iViewer];
|
|---|
| 915 | G4String thisName = thisViewer -> GetName ();
|
|---|
| 916 | G4String thisShortName = thisViewer -> GetShortName ();
|
|---|
| 917 | if (name != "all") {
|
|---|
| 918 | if (thisShortName != shortName) continue;
|
|---|
| 919 | }
|
|---|
| 920 | found = true;
|
|---|
| 921 | G4cout << "\n ";
|
|---|
| 922 | if (thisShortName == currentViewerShortName) {
|
|---|
| 923 | foundCurrent = true;
|
|---|
| 924 | G4cout << "(current)";
|
|---|
| 925 | }
|
|---|
| 926 | else {
|
|---|
| 927 | G4cout << " ";
|
|---|
| 928 | }
|
|---|
| 929 | G4cout << " viewer \"" << thisName << "\"";
|
|---|
| 930 | if (verbosity >= G4VisManager::parameters) {
|
|---|
| 931 | G4cout << "\n " << *thisViewer;
|
|---|
| 932 | }
|
|---|
| 933 | }
|
|---|
| 934 | }
|
|---|
| 935 | G4cout << G4endl;
|
|---|
| 936 | }
|
|---|
| 937 |
|
|---|
| 938 | if (!foundCurrent) {
|
|---|
| 939 | G4cout << "No valid current viewer - please create or select one."
|
|---|
| 940 | << G4endl;
|
|---|
| 941 | }
|
|---|
| 942 |
|
|---|
| 943 | if (!found) {
|
|---|
| 944 | G4cout << "No viewers";
|
|---|
| 945 | if (name != "all") {
|
|---|
| 946 | G4cout << " of name \"" << name << "\"";
|
|---|
| 947 | }
|
|---|
| 948 | G4cout << " found." << G4endl;
|
|---|
| 949 | }
|
|---|
| 950 | }
|
|---|
| 951 |
|
|---|
| 952 | ////////////// /vis/viewer/pan and panTo ////////////////////////////
|
|---|
| 953 |
|
|---|
| 954 | G4VisCommandViewerPan::G4VisCommandViewerPan ():
|
|---|
| 955 | fPanIncrementRight (0.),
|
|---|
| 956 | fPanIncrementUp (0.),
|
|---|
| 957 | fPanToRight (0.),
|
|---|
| 958 | fPanToUp (0.)
|
|---|
| 959 | {
|
|---|
| 960 | G4bool omitable;
|
|---|
| 961 |
|
|---|
| 962 | fpCommandPan = new G4UIcommand
|
|---|
| 963 | ("/vis/viewer/pan", this);
|
|---|
| 964 | fpCommandPan -> SetGuidance
|
|---|
| 965 | ("Incremental pan.");
|
|---|
| 966 | fpCommandPan -> SetGuidance
|
|---|
| 967 | ("Moves the camera incrementally right and up by these amounts (as seen"
|
|---|
| 968 | "\nfrom viewpoint direction).");
|
|---|
| 969 | G4UIparameter* parameter;
|
|---|
| 970 | parameter = new G4UIparameter("right-increment", 'd', omitable = true);
|
|---|
| 971 | parameter -> SetCurrentAsDefault (true);
|
|---|
| 972 | fpCommandPan -> SetParameter (parameter);
|
|---|
| 973 | parameter = new G4UIparameter("up-increment", 'd', omitable = true);
|
|---|
| 974 | parameter -> SetCurrentAsDefault (true);
|
|---|
| 975 | fpCommandPan -> SetParameter (parameter);
|
|---|
| 976 | parameter = new G4UIparameter ("unit", 's', omitable = true);
|
|---|
| 977 | parameter -> SetDefaultValue ("m");
|
|---|
| 978 | fpCommandPan -> SetParameter (parameter);
|
|---|
| 979 |
|
|---|
| 980 | fpCommandPanTo = new G4UIcommand
|
|---|
| 981 | ("/vis/viewer/panTo", this);
|
|---|
| 982 | fpCommandPanTo -> SetGuidance
|
|---|
| 983 | ("Pan to specific coordinate.");
|
|---|
| 984 | fpCommandPanTo -> SetGuidance
|
|---|
| 985 | ("Places the camera in this position right and up relative to standard"
|
|---|
| 986 | "\ntarget point (as seen from viewpoint direction).");
|
|---|
| 987 | parameter = new G4UIparameter("right", 'd', omitable = true);
|
|---|
| 988 | parameter -> SetCurrentAsDefault (true);
|
|---|
| 989 | fpCommandPanTo -> SetParameter (parameter);
|
|---|
| 990 | parameter = new G4UIparameter("up", 'd', omitable = true);
|
|---|
| 991 | parameter -> SetCurrentAsDefault (true);
|
|---|
| 992 | fpCommandPanTo -> SetParameter (parameter);
|
|---|
| 993 | parameter = new G4UIparameter ("unit", 's', omitable = true);
|
|---|
| 994 | parameter -> SetDefaultValue ("m");
|
|---|
| 995 | fpCommandPanTo -> SetParameter (parameter);
|
|---|
| 996 | }
|
|---|
| 997 |
|
|---|
| 998 | G4VisCommandViewerPan::~G4VisCommandViewerPan () {
|
|---|
| 999 | delete fpCommandPan;
|
|---|
| 1000 | delete fpCommandPanTo;
|
|---|
| 1001 | }
|
|---|
| 1002 |
|
|---|
| 1003 | G4String G4VisCommandViewerPan::GetCurrentValue (G4UIcommand* command) {
|
|---|
| 1004 | G4String currentValue;
|
|---|
| 1005 | if (command == fpCommandPan) {
|
|---|
| 1006 | currentValue = ConvertToString(fPanIncrementRight, fPanIncrementUp, "m");
|
|---|
| 1007 | }
|
|---|
| 1008 | else if (command == fpCommandPanTo) {
|
|---|
| 1009 | currentValue = ConvertToString(fPanToRight, fPanToUp, "m");
|
|---|
| 1010 | }
|
|---|
| 1011 | return currentValue;
|
|---|
| 1012 | }
|
|---|
| 1013 |
|
|---|
| 1014 | void G4VisCommandViewerPan::SetNewValue (G4UIcommand* command,
|
|---|
| 1015 | G4String newValue) {
|
|---|
| 1016 |
|
|---|
| 1017 |
|
|---|
| 1018 | G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
|
|---|
| 1019 |
|
|---|
| 1020 | G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
|
|---|
| 1021 | if (!currentViewer) {
|
|---|
| 1022 | if (verbosity >= G4VisManager::errors) {
|
|---|
| 1023 | G4cout <<
|
|---|
| 1024 | "ERROR: G4VisCommandsViewerPan::SetNewValue: no current viewer."
|
|---|
| 1025 | << G4endl;
|
|---|
| 1026 | }
|
|---|
| 1027 | return;
|
|---|
| 1028 | }
|
|---|
| 1029 |
|
|---|
| 1030 | G4ViewParameters vp = currentViewer->GetViewParameters();
|
|---|
| 1031 |
|
|---|
| 1032 | if (command == fpCommandPan) {
|
|---|
| 1033 | ConvertToDoublePair(newValue, fPanIncrementRight, fPanIncrementUp);
|
|---|
| 1034 | vp.IncrementPan(fPanIncrementRight, fPanIncrementUp);
|
|---|
| 1035 | }
|
|---|
| 1036 | else if (command == fpCommandPanTo) {
|
|---|
| 1037 | ConvertToDoublePair(newValue, fPanToRight, fPanToUp);
|
|---|
| 1038 | vp.SetPan(fPanToRight, fPanToUp);
|
|---|
| 1039 | }
|
|---|
| 1040 |
|
|---|
| 1041 | if (verbosity >= G4VisManager::confirmations) {
|
|---|
| 1042 | G4cout << "Current target point now " << vp.GetCurrentTargetPoint()
|
|---|
| 1043 | << G4endl;
|
|---|
| 1044 | }
|
|---|
| 1045 |
|
|---|
| 1046 | SetViewParameters(currentViewer, vp);
|
|---|
| 1047 | }
|
|---|
| 1048 |
|
|---|
| 1049 | ////////////// /vis/viewer/rebuild ///////////////////////////////////////
|
|---|
| 1050 |
|
|---|
| 1051 | G4VisCommandViewerRebuild::G4VisCommandViewerRebuild () {
|
|---|
| 1052 | G4bool omitable, currentAsDefault;
|
|---|
| 1053 | fpCommand = new G4UIcmdWithAString ("/vis/viewer/rebuild", this);
|
|---|
| 1054 | fpCommand -> SetGuidance ("Forces rebuild of graphical database.");
|
|---|
| 1055 | fpCommand -> SetGuidance
|
|---|
| 1056 | ("By default, acts on current viewer. \"/vis/viewer/list\""
|
|---|
| 1057 | "\nto see possible viewers. Viewer becomes current.");
|
|---|
| 1058 | fpCommand -> SetParameterName ("viewer-name",
|
|---|
| 1059 | omitable = true,
|
|---|
| 1060 | currentAsDefault = true);
|
|---|
| 1061 | }
|
|---|
| 1062 |
|
|---|
| 1063 | G4VisCommandViewerRebuild::~G4VisCommandViewerRebuild () {
|
|---|
| 1064 | delete fpCommand;
|
|---|
| 1065 | }
|
|---|
| 1066 |
|
|---|
| 1067 | G4String G4VisCommandViewerRebuild::GetCurrentValue (G4UIcommand*) {
|
|---|
| 1068 | G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
|
|---|
| 1069 | if (viewer) {
|
|---|
| 1070 | return viewer -> GetName ();
|
|---|
| 1071 | }
|
|---|
| 1072 | else {
|
|---|
| 1073 | return "none";
|
|---|
| 1074 | }
|
|---|
| 1075 | }
|
|---|
| 1076 |
|
|---|
| 1077 | void G4VisCommandViewerRebuild::SetNewValue (G4UIcommand*, G4String newValue) {
|
|---|
| 1078 |
|
|---|
| 1079 | G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
|
|---|
| 1080 |
|
|---|
| 1081 | G4String& rebuildName = newValue;
|
|---|
| 1082 | G4VViewer* viewer = fpVisManager -> GetViewer (rebuildName);
|
|---|
| 1083 | if (!viewer) {
|
|---|
| 1084 | if (verbosity >= G4VisManager::errors) {
|
|---|
| 1085 | G4cout << "ERROR: Viewer \"" << rebuildName
|
|---|
| 1086 | << "\" not found - \"/vis/viewer/list\" to see possibilities."
|
|---|
| 1087 | << G4endl;
|
|---|
| 1088 | }
|
|---|
| 1089 | return;
|
|---|
| 1090 | }
|
|---|
| 1091 |
|
|---|
| 1092 | viewer->NeedKernelVisit();
|
|---|
| 1093 |
|
|---|
| 1094 | // Check auto-refresh and print confirmations, but without changing
|
|---|
| 1095 | // view paramters...
|
|---|
| 1096 | SetViewParameters(viewer, viewer->GetViewParameters());
|
|---|
| 1097 | }
|
|---|
| 1098 |
|
|---|
| 1099 | ////////////// /vis/viewer/refresh ///////////////////////////////////////
|
|---|
| 1100 |
|
|---|
| 1101 | G4VisCommandViewerRefresh::G4VisCommandViewerRefresh () {
|
|---|
| 1102 | G4bool omitable, currentAsDefault;
|
|---|
| 1103 | fpCommand = new G4UIcmdWithAString ("/vis/viewer/refresh", this);
|
|---|
| 1104 | fpCommand -> SetGuidance
|
|---|
| 1105 | ("Refreshes viewer.");
|
|---|
| 1106 | fpCommand -> SetGuidance
|
|---|
| 1107 | ("By default, acts on current viewer. \"/vis/viewer/list\""
|
|---|
| 1108 | "\nto see possible viewers. Viewer becomes current.");
|
|---|
| 1109 | fpCommand -> SetParameterName ("viewer-name",
|
|---|
| 1110 | omitable = true,
|
|---|
| 1111 | currentAsDefault = true);
|
|---|
| 1112 | }
|
|---|
| 1113 |
|
|---|
| 1114 | G4VisCommandViewerRefresh::~G4VisCommandViewerRefresh () {
|
|---|
| 1115 | delete fpCommand;
|
|---|
| 1116 | }
|
|---|
| 1117 |
|
|---|
| 1118 | G4String G4VisCommandViewerRefresh::GetCurrentValue (G4UIcommand*) {
|
|---|
| 1119 | G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
|
|---|
| 1120 | return viewer ? viewer -> GetName () : G4String("none");
|
|---|
| 1121 | }
|
|---|
| 1122 |
|
|---|
| 1123 | void G4VisCommandViewerRefresh::SetNewValue (G4UIcommand*, G4String newValue) {
|
|---|
| 1124 |
|
|---|
| 1125 | G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
|
|---|
| 1126 | G4bool warn(verbosity >= G4VisManager::warnings);
|
|---|
| 1127 |
|
|---|
| 1128 | G4String& refreshName = newValue;
|
|---|
| 1129 | G4VViewer* viewer = fpVisManager -> GetViewer (refreshName);
|
|---|
| 1130 | if (!viewer) {
|
|---|
| 1131 | if (verbosity >= G4VisManager::errors) {
|
|---|
| 1132 | G4cout << "ERROR: Viewer \"" << refreshName << "\"" <<
|
|---|
| 1133 | " not found - \"/vis/viewer/list\"\n to see possibilities."
|
|---|
| 1134 | << G4endl;
|
|---|
| 1135 | }
|
|---|
| 1136 | return;
|
|---|
| 1137 | }
|
|---|
| 1138 |
|
|---|
| 1139 | G4VSceneHandler* sceneHandler = viewer->GetSceneHandler();
|
|---|
| 1140 | if (!sceneHandler) {
|
|---|
| 1141 | if (verbosity >= G4VisManager::errors) {
|
|---|
| 1142 | G4cout << "ERROR: Viewer \"" << refreshName << "\"" <<
|
|---|
| 1143 | " has no scene handler - report serious bug."
|
|---|
| 1144 | << G4endl;
|
|---|
| 1145 | }
|
|---|
| 1146 | return;
|
|---|
| 1147 | }
|
|---|
| 1148 |
|
|---|
| 1149 | G4Scene* scene = sceneHandler->GetScene();
|
|---|
| 1150 | if (!scene) {
|
|---|
| [593] | 1151 | if (verbosity >= G4VisManager::confirmations) {
|
|---|
| 1152 | G4cout << "NOTE: SceneHandler \"" << sceneHandler->GetName()
|
|---|
| [531] | 1153 | << "\", to which viewer \"" << refreshName << "\"" <<
|
|---|
| 1154 | "\n is attached, has no scene - \"/vis/scene/create\" and"
|
|---|
| 1155 | " \"/vis/sceneHandler/attach\""
|
|---|
| 1156 | "\n (or use compound command \"/vis/drawVolume\")."
|
|---|
| 1157 | << G4endl;
|
|---|
| 1158 | }
|
|---|
| 1159 | return;
|
|---|
| 1160 | }
|
|---|
| 1161 | if (scene->GetRunDurationModelList().empty()) {
|
|---|
| 1162 | G4bool successful = scene -> AddWorldIfEmpty (warn);
|
|---|
| 1163 | if (!successful) {
|
|---|
| 1164 | if (verbosity >= G4VisManager::warnings) {
|
|---|
| 1165 | G4cout <<
|
|---|
| 1166 | "WARNING: Scene is empty. Perhaps no geometry exists."
|
|---|
| 1167 | "\n Try /run/initialize."
|
|---|
| 1168 | << G4endl;
|
|---|
| 1169 | }
|
|---|
| 1170 | return;
|
|---|
| 1171 | }
|
|---|
| 1172 | // Scene has changed. UpdateVisManagerScene issues
|
|---|
| 1173 | // /vis/scene/notifyHandlers, which does a refresh anyway, so the
|
|---|
| 1174 | // ordinary refresh becomes part of the else phrase...
|
|---|
| 1175 | UpdateVisManagerScene(scene->GetName());
|
|---|
| 1176 | } else {
|
|---|
| 1177 | if (verbosity >= G4VisManager::confirmations) {
|
|---|
| 1178 | G4cout << "Refreshing viewer \"" << viewer -> GetName () << "\"..."
|
|---|
| 1179 | << G4endl;
|
|---|
| 1180 | }
|
|---|
| 1181 | viewer -> SetView ();
|
|---|
| 1182 | viewer -> ClearView ();
|
|---|
| 1183 | viewer -> DrawView ();
|
|---|
| 1184 | if (verbosity >= G4VisManager::confirmations) {
|
|---|
| 1185 | G4cout << "Viewer \"" << viewer -> GetName () << "\"" << " refreshed."
|
|---|
| 1186 | "\n (You might also need \"/vis/viewer/update\".)" << G4endl;
|
|---|
| 1187 | }
|
|---|
| 1188 | }
|
|---|
| 1189 | }
|
|---|
| 1190 |
|
|---|
| 1191 | ////////////// /vis/viewer/reset ///////////////////////////////////////
|
|---|
| 1192 |
|
|---|
| 1193 | G4VisCommandViewerReset::G4VisCommandViewerReset () {
|
|---|
| 1194 | G4bool omitable, currentAsDefault;
|
|---|
| 1195 | fpCommand = new G4UIcmdWithAString ("/vis/viewer/reset", this);
|
|---|
| 1196 | fpCommand -> SetGuidance ("Resets viewer.");
|
|---|
| 1197 | fpCommand -> SetGuidance
|
|---|
| 1198 | ("By default, acts on current viewer. \"/vis/viewer/list\""
|
|---|
| 1199 | "\nto see possible viewers. Viewer becomes current.");
|
|---|
| 1200 | fpCommand -> SetParameterName ("viewer-name",
|
|---|
| 1201 | omitable = true,
|
|---|
| 1202 | currentAsDefault = true);
|
|---|
| 1203 | }
|
|---|
| 1204 |
|
|---|
| 1205 | G4VisCommandViewerReset::~G4VisCommandViewerReset () {
|
|---|
| 1206 | delete fpCommand;
|
|---|
| 1207 | }
|
|---|
| 1208 |
|
|---|
| 1209 | G4String G4VisCommandViewerReset::GetCurrentValue (G4UIcommand*) {
|
|---|
| 1210 | G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
|
|---|
| 1211 | if (viewer) {
|
|---|
| 1212 | return viewer -> GetName ();
|
|---|
| 1213 | }
|
|---|
| 1214 | else {
|
|---|
| 1215 | return "none";
|
|---|
| 1216 | }
|
|---|
| 1217 | }
|
|---|
| 1218 |
|
|---|
| 1219 | void G4VisCommandViewerReset::SetNewValue (G4UIcommand*, G4String newValue) {
|
|---|
| 1220 |
|
|---|
| 1221 | G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
|
|---|
| 1222 |
|
|---|
| 1223 | G4String& resetName = newValue;
|
|---|
| 1224 | G4VViewer* viewer = fpVisManager -> GetViewer (resetName);
|
|---|
| 1225 | if (!viewer) {
|
|---|
| 1226 | if (verbosity >= G4VisManager::errors) {
|
|---|
| 1227 | G4cout << "ERROR: Viewer \"" << resetName
|
|---|
| 1228 | << "\" not found - \"/vis/viewer/list\" to see possibilities."
|
|---|
| 1229 | << G4endl;
|
|---|
| 1230 | }
|
|---|
| 1231 | return;
|
|---|
| 1232 | }
|
|---|
| 1233 |
|
|---|
| 1234 | SetViewParameters(viewer, viewer->GetDefaultViewParameters());
|
|---|
| 1235 | }
|
|---|
| 1236 |
|
|---|
| 1237 | ////////////// /vis/viewer/scale and scaleTo ////////////////////////////
|
|---|
| 1238 |
|
|---|
| 1239 | G4VisCommandViewerScale::G4VisCommandViewerScale ():
|
|---|
| 1240 | fScaleMultiplier (G4Vector3D (1., 1., 1.)),
|
|---|
| 1241 | fScaleTo (G4Vector3D (1., 1., 1.))
|
|---|
| 1242 | {
|
|---|
| 1243 | G4bool omitable, currentAsDefault;
|
|---|
| 1244 |
|
|---|
| 1245 | fpCommandScale = new G4UIcmdWith3Vector
|
|---|
| 1246 | ("/vis/viewer/scale", this);
|
|---|
| 1247 | fpCommandScale -> SetGuidance ("Incremental (non-uniform) scaling.");
|
|---|
| 1248 | fpCommandScale -> SetGuidance
|
|---|
| 1249 | ("Multiplies components of current scaling by components of this factor."
|
|---|
| 1250 | "\n Scales (x,y,z) by corresponding components of the resulting factor.");
|
|---|
| 1251 | fpCommandScale -> SetGuidance
|
|---|
| 1252 | ("");
|
|---|
| 1253 | fpCommandScale -> SetParameterName
|
|---|
| 1254 | ("x-scale-multiplier","y-scale-multiplier","z-scale-multiplier",
|
|---|
| 1255 | omitable=true, currentAsDefault=true);
|
|---|
| 1256 |
|
|---|
| 1257 | fpCommandScaleTo = new G4UIcmdWith3Vector
|
|---|
| 1258 | ("/vis/viewer/scaleTo", this);
|
|---|
| 1259 | fpCommandScaleTo -> SetGuidance ("Absolute (non-uniform) scaling.");
|
|---|
| 1260 | fpCommandScaleTo -> SetGuidance
|
|---|
| 1261 | ("Scales (x,y,z) by corresponding components of this factor.");
|
|---|
| 1262 | fpCommandScaleTo -> SetParameterName
|
|---|
| 1263 | ("x-scale-factor","y-scale-factor","z-scale-factor",
|
|---|
| 1264 | omitable=true, currentAsDefault=true);
|
|---|
| 1265 | }
|
|---|
| 1266 |
|
|---|
| 1267 | G4VisCommandViewerScale::~G4VisCommandViewerScale () {
|
|---|
| 1268 | delete fpCommandScale;
|
|---|
| 1269 | delete fpCommandScaleTo;
|
|---|
| 1270 | }
|
|---|
| 1271 |
|
|---|
| 1272 | G4String G4VisCommandViewerScale::GetCurrentValue (G4UIcommand* command) {
|
|---|
| 1273 | G4String currentValue;
|
|---|
| 1274 | if (command == fpCommandScale) {
|
|---|
| 1275 | currentValue = fpCommandScale->ConvertToString(G4ThreeVector(fScaleMultiplier));
|
|---|
| 1276 | }
|
|---|
| 1277 | else if (command == fpCommandScaleTo) {
|
|---|
| 1278 | currentValue = fpCommandScaleTo->ConvertToString(G4ThreeVector(fScaleTo));
|
|---|
| 1279 | }
|
|---|
| 1280 | return currentValue;
|
|---|
| 1281 | }
|
|---|
| 1282 |
|
|---|
| 1283 | void G4VisCommandViewerScale::SetNewValue (G4UIcommand* command,
|
|---|
| 1284 | G4String newValue) {
|
|---|
| 1285 |
|
|---|
| 1286 |
|
|---|
| 1287 | G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
|
|---|
| 1288 |
|
|---|
| 1289 | G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
|
|---|
| 1290 | if (!currentViewer) {
|
|---|
| 1291 | if (verbosity >= G4VisManager::errors) {
|
|---|
| 1292 | G4cout <<
|
|---|
| 1293 | "ERROR: G4VisCommandsViewerScale::SetNewValue: no current viewer."
|
|---|
| 1294 | << G4endl;
|
|---|
| 1295 | }
|
|---|
| 1296 | return;
|
|---|
| 1297 | }
|
|---|
| 1298 |
|
|---|
| 1299 | G4ViewParameters vp = currentViewer->GetViewParameters();
|
|---|
| 1300 |
|
|---|
| 1301 | if (command == fpCommandScale) {
|
|---|
| 1302 | fScaleMultiplier = fpCommandScale->GetNew3VectorValue(newValue);
|
|---|
| 1303 | vp.MultiplyScaleFactor(fScaleMultiplier);
|
|---|
| 1304 | }
|
|---|
| 1305 | else if (command == fpCommandScaleTo) {
|
|---|
| 1306 | fScaleTo = fpCommandScale->GetNew3VectorValue(newValue);
|
|---|
| 1307 | vp.SetScaleFactor(fScaleTo);
|
|---|
| 1308 | }
|
|---|
| 1309 |
|
|---|
| 1310 | if (verbosity >= G4VisManager::confirmations) {
|
|---|
| 1311 | G4cout << "Scale factor changed to " << vp.GetScaleFactor() << G4endl;
|
|---|
| 1312 | }
|
|---|
| 1313 |
|
|---|
| 1314 | SetViewParameters(currentViewer, vp);
|
|---|
| 1315 | }
|
|---|
| 1316 |
|
|---|
| 1317 | ////////////// /vis/viewer/select ///////////////////////////////////////
|
|---|
| 1318 |
|
|---|
| 1319 | G4VisCommandViewerSelect::G4VisCommandViewerSelect () {
|
|---|
| 1320 | G4bool omitable;
|
|---|
| 1321 | fpCommand = new G4UIcmdWithAString ("/vis/viewer/select", this);
|
|---|
| 1322 | fpCommand -> SetGuidance ("Selects viewer.");
|
|---|
| 1323 | fpCommand -> SetGuidance
|
|---|
| 1324 | ("Specify viewer by name. \"/vis/viewer/list\" to see possible viewers.");
|
|---|
| 1325 | fpCommand -> SetParameterName ("viewer-name", omitable = false);
|
|---|
| 1326 | }
|
|---|
| 1327 |
|
|---|
| 1328 | G4VisCommandViewerSelect::~G4VisCommandViewerSelect () {
|
|---|
| 1329 | delete fpCommand;
|
|---|
| 1330 | }
|
|---|
| 1331 |
|
|---|
| 1332 | G4String G4VisCommandViewerSelect::GetCurrentValue (G4UIcommand*) {
|
|---|
| 1333 | return "";
|
|---|
| 1334 | }
|
|---|
| 1335 |
|
|---|
| 1336 | void G4VisCommandViewerSelect::SetNewValue (G4UIcommand*, G4String newValue) {
|
|---|
| 1337 |
|
|---|
| 1338 | G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
|
|---|
| 1339 |
|
|---|
| 1340 | G4String& selectName = newValue;
|
|---|
| 1341 | G4VViewer* viewer = fpVisManager -> GetViewer (selectName);
|
|---|
| 1342 |
|
|---|
| 1343 | if (!viewer) {
|
|---|
| 1344 | if (verbosity >= G4VisManager::errors) {
|
|---|
| 1345 | G4cout << "ERROR: Viewer \"" << selectName << "\"";
|
|---|
| 1346 | G4cout << " not found - \"/vis/viewer/list\""
|
|---|
| 1347 | "\n to see possibilities."
|
|---|
| 1348 | << G4endl;
|
|---|
| 1349 | }
|
|---|
| 1350 | return;
|
|---|
| 1351 | }
|
|---|
| 1352 |
|
|---|
| 1353 | if (viewer == fpVisManager -> GetCurrentViewer ()) {
|
|---|
| 1354 | if (verbosity >= G4VisManager::warnings) {
|
|---|
| 1355 | G4cout << "WARNING: Viewer \"" << viewer -> GetName () << "\""
|
|---|
| 1356 | << " already selected." << G4endl;
|
|---|
| 1357 | }
|
|---|
| 1358 | return;
|
|---|
| 1359 | }
|
|---|
| 1360 |
|
|---|
| 1361 | fpVisManager -> SetCurrentViewer (viewer); // Prints confirmation.
|
|---|
| 1362 |
|
|---|
| 1363 | SetViewParameters(viewer, viewer->GetViewParameters());
|
|---|
| 1364 | }
|
|---|
| 1365 |
|
|---|
| 1366 | ////////////// /vis/viewer/update ///////////////////////////////////////
|
|---|
| 1367 |
|
|---|
| 1368 | G4VisCommandViewerUpdate::G4VisCommandViewerUpdate () {
|
|---|
| 1369 | G4bool omitable, currentAsDefault;
|
|---|
| 1370 | fpCommand = new G4UIcmdWithAString ("/vis/viewer/update", this);
|
|---|
| 1371 | fpCommand -> SetGuidance
|
|---|
| 1372 | ("Triggers graphical database post-processing for viewers"
|
|---|
| 1373 | "\nusing that technique.");
|
|---|
| 1374 | fpCommand -> SetGuidance
|
|---|
| 1375 | ("For such viewers the view only becomes visible with this command."
|
|---|
| 1376 | "\nBy default, acts on current viewer. \"/vis/viewer/list\""
|
|---|
| 1377 | "\nto see possible viewers. Viewer becomes current.");
|
|---|
| 1378 | fpCommand -> SetParameterName ("viewer-name",
|
|---|
| 1379 | omitable = true,
|
|---|
| 1380 | currentAsDefault = true);
|
|---|
| 1381 | }
|
|---|
| 1382 |
|
|---|
| 1383 | G4VisCommandViewerUpdate::~G4VisCommandViewerUpdate () {
|
|---|
| 1384 | delete fpCommand;
|
|---|
| 1385 | }
|
|---|
| 1386 |
|
|---|
| 1387 | G4String G4VisCommandViewerUpdate::GetCurrentValue (G4UIcommand*) {
|
|---|
| 1388 | G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
|
|---|
| 1389 | if (viewer) {
|
|---|
| 1390 | return viewer -> GetName ();
|
|---|
| 1391 | }
|
|---|
| 1392 | else {
|
|---|
| 1393 | return "none";
|
|---|
| 1394 | }
|
|---|
| 1395 | }
|
|---|
| 1396 |
|
|---|
| 1397 | void G4VisCommandViewerUpdate::SetNewValue (G4UIcommand*, G4String newValue) {
|
|---|
| 1398 |
|
|---|
| 1399 | G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
|
|---|
| 1400 |
|
|---|
| 1401 | G4String& updateName = newValue;
|
|---|
| 1402 |
|
|---|
| 1403 | G4VViewer* viewer = fpVisManager -> GetViewer (updateName);
|
|---|
| 1404 | if (!viewer) {
|
|---|
| 1405 | if (verbosity >= G4VisManager::errors) {
|
|---|
| 1406 | G4cout <<
|
|---|
| 1407 | "ERROR: G4VisCommandsViewerUpdate::SetNewValue: no current viewer."
|
|---|
| 1408 | << G4endl;
|
|---|
| 1409 | }
|
|---|
| 1410 | return;
|
|---|
| 1411 | }
|
|---|
| 1412 |
|
|---|
| 1413 | G4VSceneHandler* sceneHandler = viewer->GetSceneHandler();
|
|---|
| 1414 | if (!sceneHandler) {
|
|---|
| 1415 | if (verbosity >= G4VisManager::errors) {
|
|---|
| 1416 | G4cout << "ERROR: Viewer \"" << updateName << "\"" <<
|
|---|
| 1417 | " has no scene handler - report serious bug."
|
|---|
| 1418 | << G4endl;
|
|---|
| 1419 | }
|
|---|
| 1420 | return;
|
|---|
| 1421 | }
|
|---|
| 1422 |
|
|---|
| 1423 | G4Scene* scene = sceneHandler->GetScene();
|
|---|
| 1424 | if (!scene) {
|
|---|
| [593] | 1425 | if (verbosity >= G4VisManager::confirmations) {
|
|---|
| 1426 | G4cout << "NOTE: SceneHandler \"" << sceneHandler->GetName()
|
|---|
| [531] | 1427 | << "\", to which viewer \"" << updateName << "\"" <<
|
|---|
| 1428 | "\n is attached, has no scene - \"/vis/scene/create\" and"
|
|---|
| 1429 | " \"/vis/sceneHandler/attach\""
|
|---|
| 1430 | "\n (or use compound command \"/vis/drawVolume\")."
|
|---|
| 1431 | << G4endl;
|
|---|
| 1432 | }
|
|---|
| 1433 | return;
|
|---|
| 1434 | }
|
|---|
| 1435 |
|
|---|
| 1436 | if (viewer) {
|
|---|
| 1437 | if (verbosity >= G4VisManager::confirmations) {
|
|---|
| 1438 | G4cout << "Viewer \"" << viewer -> GetName () << "\"";
|
|---|
| 1439 | G4cout << " post-processing triggered." << G4endl;
|
|---|
| 1440 | }
|
|---|
| 1441 | viewer -> ShowView ();
|
|---|
| 1442 | // Assume future need to "refresh" transients...
|
|---|
| 1443 | sceneHandler -> SetMarkForClearingTransientStore(true);
|
|---|
| 1444 | }
|
|---|
| 1445 | else {
|
|---|
| 1446 | if (verbosity >= G4VisManager::errors) {
|
|---|
| 1447 | G4cout << "ERROR: Viewer \"" << updateName << "\"";
|
|---|
| 1448 | G4cout << " not found - \"/vis/viewer/list\""
|
|---|
| 1449 | "\n to see possibilities." << G4endl;
|
|---|
| 1450 | }
|
|---|
| 1451 | }
|
|---|
| 1452 | }
|
|---|
| 1453 |
|
|---|
| 1454 | ////////////// /vis/viewer/zoom and zoomTo ////////////////////////////
|
|---|
| 1455 |
|
|---|
| 1456 | G4VisCommandViewerZoom::G4VisCommandViewerZoom ():
|
|---|
| 1457 | fZoomMultiplier (1.),
|
|---|
| 1458 | fZoomTo (1.)
|
|---|
| 1459 | {
|
|---|
| 1460 | G4bool omitable, currentAsDefault;
|
|---|
| 1461 |
|
|---|
| 1462 | fpCommandZoom = new G4UIcmdWithADouble
|
|---|
| 1463 | ("/vis/viewer/zoom", this);
|
|---|
| 1464 | fpCommandZoom -> SetGuidance ("Incremental zoom.");
|
|---|
| 1465 | fpCommandZoom -> SetGuidance
|
|---|
| 1466 | ("Multiplies current magnification by this factor.");
|
|---|
| 1467 | fpCommandZoom -> SetParameterName("multiplier",
|
|---|
| 1468 | omitable=true,
|
|---|
| 1469 | currentAsDefault=true);
|
|---|
| 1470 |
|
|---|
| 1471 | fpCommandZoomTo = new G4UIcmdWithADouble
|
|---|
| 1472 | ("/vis/viewer/zoomTo", this);
|
|---|
| 1473 | fpCommandZoomTo -> SetGuidance ("Absolute zoom.");
|
|---|
| 1474 | fpCommandZoomTo -> SetGuidance
|
|---|
| 1475 | ("Magnifies standard magnification by this factor.");
|
|---|
| 1476 | fpCommandZoomTo -> SetParameterName("factor",
|
|---|
| 1477 | omitable=true,
|
|---|
| 1478 | currentAsDefault=true);
|
|---|
| 1479 | }
|
|---|
| 1480 |
|
|---|
| 1481 | G4VisCommandViewerZoom::~G4VisCommandViewerZoom () {
|
|---|
| 1482 | delete fpCommandZoom;
|
|---|
| 1483 | delete fpCommandZoomTo;
|
|---|
| 1484 | }
|
|---|
| 1485 |
|
|---|
| 1486 | G4String G4VisCommandViewerZoom::GetCurrentValue (G4UIcommand* command) {
|
|---|
| 1487 | G4String currentValue;
|
|---|
| 1488 | if (command == fpCommandZoom) {
|
|---|
| 1489 | currentValue = fpCommandZoom->ConvertToString(fZoomMultiplier);
|
|---|
| 1490 | }
|
|---|
| 1491 | else if (command == fpCommandZoomTo) {
|
|---|
| 1492 | currentValue = fpCommandZoomTo->ConvertToString(fZoomTo);
|
|---|
| 1493 | }
|
|---|
| 1494 | return currentValue;
|
|---|
| 1495 | }
|
|---|
| 1496 |
|
|---|
| 1497 | void G4VisCommandViewerZoom::SetNewValue (G4UIcommand* command,
|
|---|
| 1498 | G4String newValue) {
|
|---|
| 1499 |
|
|---|
| 1500 |
|
|---|
| 1501 | G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
|
|---|
| 1502 |
|
|---|
| 1503 | G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
|
|---|
| 1504 | if (!currentViewer) {
|
|---|
| 1505 | if (verbosity >= G4VisManager::errors) {
|
|---|
| 1506 | G4cout <<
|
|---|
| 1507 | "ERROR: G4VisCommandsViewerZoom::SetNewValue: no current viewer."
|
|---|
| 1508 | << G4endl;
|
|---|
| 1509 | }
|
|---|
| 1510 | return;
|
|---|
| 1511 | }
|
|---|
| 1512 |
|
|---|
| 1513 | G4ViewParameters vp = currentViewer->GetViewParameters();
|
|---|
| 1514 |
|
|---|
| 1515 | if (command == fpCommandZoom) {
|
|---|
| 1516 | fZoomMultiplier = fpCommandZoom->GetNewDoubleValue(newValue);
|
|---|
| 1517 | vp.MultiplyZoomFactor(fZoomMultiplier);
|
|---|
| 1518 | }
|
|---|
| 1519 | else if (command == fpCommandZoomTo) {
|
|---|
| 1520 | fZoomTo = fpCommandZoom->GetNewDoubleValue(newValue);
|
|---|
| 1521 | vp.SetZoomFactor(fZoomTo);
|
|---|
| 1522 | }
|
|---|
| 1523 |
|
|---|
| 1524 | if (verbosity >= G4VisManager::confirmations) {
|
|---|
| 1525 | G4cout << "Zoom factor changed to " << vp.GetZoomFactor() << G4endl;
|
|---|
| 1526 | }
|
|---|
| 1527 |
|
|---|
| 1528 | SetViewParameters(currentViewer, vp);
|
|---|
| 1529 | }
|
|---|
| [891] | 1530 |
|
|---|
| 1531 |
|
|---|