G4VisCommandsViewer.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 
00029 // /vis/viewer commands - John Allison  25th October 1998
00030 
00031 #include "G4VisCommandsViewer.hh"
00032 
00033 #include "G4VisManager.hh"
00034 #include "G4GraphicsSystemList.hh"
00035 #include "G4VisCommandsScene.hh"
00036 #include "G4UImanager.hh"
00037 #include "G4UIcommand.hh"
00038 #include "G4UIcmdWithoutParameter.hh"
00039 #include "G4UIcmdWithAString.hh"
00040 #include "G4UIcmdWithADouble.hh"
00041 #include "G4UIcmdWithADoubleAndUnit.hh"
00042 #include "G4UIcmdWith3Vector.hh"
00043 #include "G4Point3D.hh"
00044 #include "G4UnitsTable.hh"
00045 #include "G4ios.hh"
00046 #include <sstream>
00047 #include <fstream>
00048 
00049 G4VVisCommandViewer::G4VVisCommandViewer () {}
00050 
00051 G4VVisCommandViewer::~G4VVisCommandViewer () {}
00052 
00053 void G4VVisCommandViewer::SetViewParameters
00054 (G4VViewer* viewer, const G4ViewParameters& viewParams) {
00055   viewer->SetViewParameters(viewParams);
00056   RefreshIfRequired(viewer);
00057 }
00058 
00059 void G4VVisCommandViewer::RefreshIfRequired(G4VViewer* viewer) {
00060   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
00061   G4VSceneHandler* sceneHandler = viewer->GetSceneHandler();
00062   const G4ViewParameters& viewParams = viewer->GetViewParameters();
00063   if (sceneHandler && sceneHandler->GetScene()) {
00064     if (viewParams.IsAutoRefresh()) {
00065       G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/refresh");
00066     }
00067     else {
00068       if (verbosity >= G4VisManager::warnings) {
00069         G4cout << "Issue /vis/viewer/refresh or flush to see effect."
00070                << G4endl;
00071       }
00072     }
00073   }
00074 }
00075 
00077 
00078 G4VisCommandViewerAddCutawayPlane::G4VisCommandViewerAddCutawayPlane () {
00079   G4bool omitable;
00080   fpCommand = new G4UIcommand ("/vis/viewer/addCutawayPlane", this);
00081   fpCommand -> SetGuidance
00082     ("Add cutaway plane to current viewer.");
00083   G4UIparameter* parameter;
00084   parameter  =  new G4UIparameter("x",'d',omitable = true);
00085   parameter  -> SetDefaultValue  (0);
00086   parameter  -> SetGuidance      ("Coordinate of point on the plane.");
00087   fpCommand->SetParameter(parameter);
00088   parameter  =  new G4UIparameter("y",'d',omitable = true);
00089   parameter  -> SetDefaultValue  (0);
00090   parameter  -> SetGuidance      ("Coordinate of point on the plane.");
00091   fpCommand->SetParameter(parameter);
00092   parameter  =  new G4UIparameter("z",'d',omitable = true);
00093   parameter  -> SetDefaultValue  (0);
00094   parameter  -> SetGuidance      ("Coordinate of point on the plane.");
00095   fpCommand->SetParameter(parameter);
00096   parameter  =  new G4UIparameter("unit",'s',omitable = true);
00097   parameter  -> SetDefaultValue  ("m");
00098   parameter  -> SetGuidance      ("Unit of point on the plane.");
00099   fpCommand->SetParameter(parameter);
00100   parameter  =  new G4UIparameter("nx",'d',omitable = true);
00101   parameter  -> SetDefaultValue  (1);
00102   parameter  -> SetGuidance      ("Component of plane normal.");
00103   fpCommand->SetParameter(parameter);
00104   parameter  =  new G4UIparameter("ny",'d',omitable = true);
00105   parameter  -> SetDefaultValue  (0);
00106   parameter  -> SetGuidance      ("Component of plane normal.");
00107   fpCommand->SetParameter(parameter);
00108   parameter  =  new G4UIparameter("nz",'d',omitable = true);
00109   parameter  -> SetDefaultValue  (0);
00110   parameter  -> SetGuidance      ("Component of plane normal.");
00111   fpCommand->SetParameter(parameter);
00112 }
00113 
00114 G4VisCommandViewerAddCutawayPlane::~G4VisCommandViewerAddCutawayPlane () {
00115   delete fpCommand;
00116 }
00117 
00118 G4String G4VisCommandViewerAddCutawayPlane::GetCurrentValue (G4UIcommand*) {
00119   return "";
00120 }
00121 
00122 void G4VisCommandViewerAddCutawayPlane::SetNewValue (G4UIcommand*, G4String newValue) {
00123 
00124   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
00125 
00126   G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
00127   if (!viewer) {
00128     if (verbosity >= G4VisManager::errors) {
00129       G4cout <<
00130   "ERROR: No current viewer - \"/vis/viewer/list\" to see possibilities."
00131              << G4endl;
00132     }
00133     return;
00134   }
00135 
00136   G4double x, y, z, nx, ny, nz;
00137   G4String unit;
00138   std::istringstream is (newValue);
00139   is >> x >> y >> z >> unit >> nx >> ny >> nz;
00140   G4double F = G4UIcommand::ValueOf(unit);
00141   x *= F; y *= F; z *= F;
00142 
00143   G4ViewParameters vp = viewer->GetViewParameters();
00144   vp.AddCutawayPlane(G4Plane3D(G4Normal3D(nx,ny,nz), G4Point3D(x,y,z)));
00145   if (verbosity >= G4VisManager::confirmations) {
00146     G4cout << "Cutaway planes for viewer \"" << viewer->GetName() << "\" now:";
00147     const G4Planes& cutaways = vp.GetCutawayPlanes();
00148     for (size_t i = 0; i < cutaways.size(); ++i)
00149       G4cout << "\n  " << i << ": " << cutaways[i];
00150     G4cout << G4endl;
00151   }
00152 
00153   SetViewParameters(viewer, vp);
00154 }
00155 
00157 
00158 G4VisCommandViewerChangeCutawayPlane::G4VisCommandViewerChangeCutawayPlane () {
00159   G4bool omitable;
00160   fpCommand = new G4UIcommand ("/vis/viewer/changeCutawayPlane", this);
00161   fpCommand -> SetGuidance("Change cutaway plane.");
00162   G4UIparameter* parameter;
00163   parameter  =  new G4UIparameter("index",'i',omitable = false);
00164   parameter  -> SetGuidance      ("Index of plane: 0, 1, 2.");
00165   fpCommand->SetParameter(parameter);
00166   parameter  =  new G4UIparameter("x",'d',omitable = true);
00167   parameter  -> SetDefaultValue  (0);
00168   parameter  -> SetGuidance      ("Coordinate of point on the plane.");
00169   fpCommand->SetParameter(parameter);
00170   parameter  =  new G4UIparameter("y",'d',omitable = true);
00171   parameter  -> SetDefaultValue  (0);
00172   parameter  -> SetGuidance      ("Coordinate of point on the plane.");
00173   fpCommand->SetParameter(parameter);
00174   parameter  =  new G4UIparameter("z",'d',omitable = true);
00175   parameter  -> SetDefaultValue  (0);
00176   parameter  -> SetGuidance      ("Coordinate of point on the plane.");
00177   fpCommand->SetParameter(parameter);
00178   parameter  =  new G4UIparameter("unit",'s',omitable = true);
00179   parameter  -> SetDefaultValue  ("m");
00180   parameter  -> SetGuidance      ("Unit of point on the plane.");
00181   fpCommand->SetParameter(parameter);
00182   parameter  =  new G4UIparameter("nx",'d',omitable = true);
00183   parameter  -> SetDefaultValue  (1);
00184   parameter  -> SetGuidance      ("Component of plane normal.");
00185   fpCommand->SetParameter(parameter);
00186   parameter  =  new G4UIparameter("ny",'d',omitable = true);
00187   parameter  -> SetDefaultValue  (0);
00188   parameter  -> SetGuidance      ("Component of plane normal.");
00189   fpCommand->SetParameter(parameter);
00190   parameter  =  new G4UIparameter("nz",'d',omitable = true);
00191   parameter  -> SetDefaultValue  (0);
00192   parameter  -> SetGuidance      ("Component of plane normal.");
00193   fpCommand->SetParameter(parameter);
00194 }
00195 
00196 G4VisCommandViewerChangeCutawayPlane::~G4VisCommandViewerChangeCutawayPlane () {
00197   delete fpCommand;
00198 }
00199 
00200 G4String G4VisCommandViewerChangeCutawayPlane::GetCurrentValue (G4UIcommand*) {
00201   return "";
00202 }
00203 
00204 void G4VisCommandViewerChangeCutawayPlane::SetNewValue (G4UIcommand*, G4String newValue) {
00205 
00206   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
00207 
00208   G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
00209   if (!viewer) {
00210     if (verbosity >= G4VisManager::errors) {
00211       G4cout <<
00212   "ERROR: No current viewer - \"/vis/viewer/list\" to see possibilities."
00213              << G4endl;
00214     }
00215     return;
00216   }
00217 
00218   size_t index;
00219   G4double x, y, z, nx, ny, nz;
00220   G4String unit;
00221   std::istringstream is (newValue);
00222   is >> index >> x >> y >> z >> unit >> nx >> ny >> nz;
00223   G4double F = G4UIcommand::ValueOf(unit);
00224   x *= F; y *= F; z *= F;
00225 
00226   G4ViewParameters vp = viewer->GetViewParameters();
00227   vp.ChangeCutawayPlane(index,
00228                         G4Plane3D(G4Normal3D(nx,ny,nz), G4Point3D(x,y,z)));
00229   if (verbosity >= G4VisManager::confirmations) {
00230     G4cout << "Cutaway planes for viewer \"" << viewer->GetName() << "\" now:";
00231     const G4Planes& cutaways = vp.GetCutawayPlanes();
00232     for (size_t i = 0; i < cutaways.size(); ++i)
00233       G4cout << "\n  " << i << ": " << cutaways[i];
00234     G4cout << G4endl;
00235   }
00236 
00237   SetViewParameters(viewer, vp);
00238 }
00239 
00241 
00242 G4VisCommandViewerClear::G4VisCommandViewerClear () {
00243   G4bool omitable, currentAsDefault;
00244   fpCommand = new G4UIcmdWithAString ("/vis/viewer/clear", this);
00245   fpCommand -> SetGuidance ("Clears viewer.");
00246   fpCommand -> SetGuidance 
00247     ("By default, clears current viewer.  Specified viewer becomes current."
00248      "\n\"/vis/viewer/list\" to see  possible viewer names.");
00249   fpCommand -> SetParameterName ("viewer-name",
00250                                  omitable = true,
00251                                  currentAsDefault = true);
00252 }
00253 
00254 G4VisCommandViewerClear::~G4VisCommandViewerClear () {
00255   delete fpCommand;
00256 }
00257 
00258 G4String G4VisCommandViewerClear::GetCurrentValue (G4UIcommand*) {
00259   G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
00260   return viewer ? viewer -> GetName () : G4String("none");
00261 }
00262 
00263 void G4VisCommandViewerClear::SetNewValue (G4UIcommand*, G4String newValue) {
00264 
00265   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
00266 
00267   G4String& clearName = newValue;
00268   G4VViewer* viewer = fpVisManager -> GetViewer (clearName);
00269   if (!viewer) {
00270     if (verbosity >= G4VisManager::errors) {
00271       G4cout << "ERROR: Viewer \"" << clearName
00272              << "\" not found - \"/vis/viewer/list\" to see possibilities."
00273              << G4endl;
00274     }
00275     return;
00276   }
00277 
00278   viewer->ClearView();
00279   viewer->FinishView();
00280   if (verbosity >= G4VisManager::confirmations) {
00281     G4cout << "Viewer \"" << clearName << "\" cleared." << G4endl;
00282   }
00283 
00284 }
00285 
00287 
00288 G4VisCommandViewerClearCutawayPlanes::G4VisCommandViewerClearCutawayPlanes () {
00289   fpCommand = new G4UIcmdWithoutParameter
00290     ("/vis/viewer/clearCutawayPlanes", this);
00291   fpCommand -> SetGuidance ("Clear cutaway planes of current viewer.");
00292 }
00293 
00294 G4VisCommandViewerClearCutawayPlanes::~G4VisCommandViewerClearCutawayPlanes () {
00295   delete fpCommand;
00296 }
00297 
00298 G4String G4VisCommandViewerClearCutawayPlanes::GetCurrentValue (G4UIcommand*) {
00299   return "";
00300 }
00301 
00302 void G4VisCommandViewerClearCutawayPlanes::SetNewValue (G4UIcommand*, G4String) {
00303 
00304   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
00305 
00306   G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
00307   if (!viewer) {
00308     if (verbosity >= G4VisManager::errors) {
00309       G4cout <<
00310   "ERROR: No current viewer - \"/vis/viewer/list\" to see possibilities."
00311              << G4endl;
00312     }
00313     return;
00314   }
00315 
00316   G4ViewParameters vp = viewer->GetViewParameters();
00317   vp.ClearCutawayPlanes();
00318   if (verbosity >= G4VisManager::confirmations) {
00319     G4cout << "Cutaway planes for viewer \"" << viewer->GetName()
00320            << "\" now cleared." << G4endl;
00321   }
00322 
00323   SetViewParameters(viewer, vp);
00324 }
00325 
00327 
00328 G4VisCommandViewerClearTransients::G4VisCommandViewerClearTransients () {
00329   G4bool omitable, currentAsDefault;
00330   fpCommand = new G4UIcmdWithAString ("/vis/viewer/clearTransients", this);
00331   fpCommand -> SetGuidance ("Clears transients from viewer.");
00332   fpCommand -> SetGuidance 
00333   ("By default, operates on current viewer.  Specified viewer becomes current."
00334      "\n\"/vis/viewer/list\" to see  possible viewer names.");
00335   fpCommand -> SetParameterName ("viewer-name",
00336                                  omitable = true,
00337                                  currentAsDefault = true);
00338 }
00339 
00340 G4VisCommandViewerClearTransients::~G4VisCommandViewerClearTransients () {
00341   delete fpCommand;
00342 }
00343 
00344 G4String G4VisCommandViewerClearTransients::GetCurrentValue (G4UIcommand*) {
00345   G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
00346   return viewer ? viewer -> GetName () : G4String("none");
00347 }
00348 
00349 void G4VisCommandViewerClearTransients::SetNewValue (G4UIcommand*, G4String newValue) {
00350 
00351   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
00352 
00353   G4String& clearName = newValue;
00354   G4VViewer* viewer = fpVisManager -> GetViewer (clearName);
00355   if (!viewer) {
00356     if (verbosity >= G4VisManager::errors) {
00357       G4cout << "ERROR: Viewer \"" << clearName
00358              << "\" not found - \"/vis/viewer/list\" to see possibilities."
00359              << G4endl;
00360     }
00361     return;
00362   }
00363 
00364   G4VSceneHandler* sceneHandler = viewer->GetSceneHandler();
00365   sceneHandler->SetMarkForClearingTransientStore(false);
00366   fpVisManager->ResetTransientsDrawnFlags();
00367   sceneHandler->ClearTransientStore();
00368   if (verbosity >= G4VisManager::confirmations) {
00369     G4cout << "Viewer \"" << clearName << "\" cleared of transients."
00370            << G4endl;
00371   }
00372 
00373 }
00374 
00376 
00377 G4VisCommandViewerClone::G4VisCommandViewerClone () {
00378   G4bool omitable;
00379   fpCommand = new G4UIcommand ("/vis/viewer/clone", this);
00380   fpCommand -> SetGuidance ("Clones viewer.");
00381   fpCommand -> SetGuidance 
00382     ("By default, clones current viewer.  Clone becomes current."
00383      "\nClone name, if not provided, is derived from the original name."
00384      "\n\"/vis/viewer/list\" to see  possible viewer names.");
00385   G4UIparameter* parameter;
00386   parameter = new G4UIparameter ("original-viewer-name", 's', omitable = true);
00387   parameter -> SetCurrentAsDefault (true);
00388   fpCommand -> SetParameter (parameter);
00389   parameter = new G4UIparameter ("clone-name", 's', omitable = true);
00390   parameter -> SetDefaultValue ("none");
00391   fpCommand -> SetParameter (parameter);
00392 }
00393 
00394 G4VisCommandViewerClone::~G4VisCommandViewerClone () {
00395   delete fpCommand;
00396 }
00397 
00398 G4String G4VisCommandViewerClone::GetCurrentValue (G4UIcommand*) {
00399   G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
00400   G4String originalName = viewer ? viewer -> GetName () : G4String("none");
00401   return "\"" + originalName + "\"";
00402 }
00403 
00404 void G4VisCommandViewerClone::SetNewValue (G4UIcommand*, G4String newValue) {
00405 
00406   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
00407 
00408   G4String originalName, cloneName;
00409   std::istringstream is (newValue);
00410 
00411   // Need to handle the possibility that the names contain embedded
00412   // blanks within quotation marks...
00413   char c;
00414   while (is.get(c) && c == ' '){}
00415   if (c == '"') {
00416     while (is.get(c) && c != '"') {originalName += c;}
00417   }
00418   else {
00419     originalName += c;
00420     while (is.get(c) && c != ' ') {originalName += c;}
00421   }
00422   originalName = originalName.strip (G4String::both, ' ');
00423   originalName = originalName.strip (G4String::both, '"');
00424 
00425   G4VViewer* originalViewer = fpVisManager -> GetViewer (originalName);
00426   if (!originalViewer) {
00427     if (verbosity >= G4VisManager::errors) {
00428       G4cout << "ERROR: Viewer \"" << originalName
00429              << "\" not found - \"/vis/viewer/list\" to see possibilities."
00430              << G4endl;
00431     }
00432     return;
00433   }
00434   originalName = originalViewer->GetName();  // Ensures long name.
00435 
00436   while (is.get(c) && c == ' '){}
00437   if (c == '"') {
00438     while (is.get(c) && c != '"') {cloneName += c;}
00439   }
00440   else {
00441     cloneName += c;
00442     while (is.get(c) && c != ' ') {cloneName += c;}
00443   }
00444   cloneName = cloneName.strip (G4String::both, ' ');
00445   cloneName = cloneName.strip (G4String::both, '"');
00446 
00447   G4bool errorWhileNaming = false;
00448   if (cloneName == "none") {
00449     G4int subID = 0;
00450     do {
00451       cloneName = originalName;
00452       std::ostringstream oss;
00453       oss << '-' << subID++;
00454       G4String::size_type lastDashPosition, nextSpacePosition;
00455       if ((lastDashPosition = cloneName.rfind('-')) !=  G4String::npos &&
00456           (nextSpacePosition = cloneName.find(" ", lastDashPosition)) !=
00457           G4String::npos) {
00458         cloneName.insert(nextSpacePosition, oss.str());
00459       } else {
00460         G4String::size_type spacePosition = cloneName.find(' ');
00461         if (spacePosition != G4String::npos)
00462           cloneName.insert(spacePosition, oss.str());
00463         else
00464           errorWhileNaming = true;
00465       }
00466     } while (!errorWhileNaming && fpVisManager -> GetViewer (cloneName));
00467   }
00468 
00469   if (errorWhileNaming) {
00470     if (verbosity >= G4VisManager::errors) {
00471       G4cout << "ERROR: While naming clone viewer \"" << cloneName
00472              << "\"."
00473              << G4endl;
00474     }
00475     return;
00476   }
00477 
00478   if (fpVisManager -> GetViewer (cloneName)) {
00479     if (verbosity >= G4VisManager::errors) {
00480       G4cout << "ERROR: Putative clone viewer \"" << cloneName
00481              << "\" already exists."
00482              << G4endl;
00483     }
00484     return;
00485   }
00486 
00487   G4String windowSizeHint =
00488     originalViewer->GetViewParameters().GetXGeometryString();
00489 
00490   G4UImanager* UImanager = G4UImanager::GetUIpointer();
00491   G4int keepVerbose = UImanager->GetVerboseLevel();
00492   G4int newVerbose(0);
00493   if (keepVerbose >= 2 ||
00494       fpVisManager->GetVerbosity() >= G4VisManager::confirmations)
00495     newVerbose = 2;
00496   UImanager->SetVerboseLevel(newVerbose);
00497   UImanager->ApplyCommand(G4String("/vis/viewer/select " + originalName));
00498   UImanager->ApplyCommand
00499     (G4String("/vis/viewer/create ! \"" + cloneName + "\" " + windowSizeHint));
00500   UImanager->ApplyCommand(G4String("/vis/viewer/set/all " + originalName));
00501   UImanager->SetVerboseLevel(keepVerbose);
00502 
00503   if (verbosity >= G4VisManager::confirmations) {
00504     G4cout << "Viewer \"" << originalName << "\" cloned." << G4endl;
00505     G4cout << "Clone \"" << cloneName << "\" now current." << G4endl;
00506   }
00507 }
00508 
00510 
00511 G4VisCommandViewerCopyViewFrom::G4VisCommandViewerCopyViewFrom () {
00512   G4bool omitable;
00513   fpCommand = new G4UIcmdWithAString ("/vis/viewer/copyViewFrom", this);
00514   fpCommand -> SetGuidance
00515   ("Copy the camera-specific parameters from the specified viewer.");
00516   fpCommand -> SetGuidance
00517   ("Note: To copy scene modifications - style, etc. - please use"
00518    "\n\"/vis/viewer/set/all\"");
00519   fpCommand -> SetParameterName ("from-viewer-name", omitable = false);
00520 }
00521 
00522 G4VisCommandViewerCopyViewFrom::~G4VisCommandViewerCopyViewFrom () {
00523   delete fpCommand;
00524 }
00525 
00526 G4String G4VisCommandViewerCopyViewFrom::GetCurrentValue (G4UIcommand*) {
00527   return "";
00528 }
00529 
00530 void G4VisCommandViewerCopyViewFrom::SetNewValue (G4UIcommand*, G4String newValue) {
00531 
00532   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
00533 
00534   G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
00535   if (!currentViewer) {
00536     if (verbosity >= G4VisManager::errors) {
00537       G4cout << 
00538   "ERROR: G4VisCommandsViewerCopyViewFrom::SetNewValue: no current viewer."
00539              << G4endl;
00540     }
00541     return;
00542   }
00543 
00544   const G4String& fromViewerName = newValue;
00545   G4VViewer* fromViewer = fpVisManager -> GetViewer (fromViewerName);
00546   if (!fromViewer) {
00547     if (verbosity >= G4VisManager::errors) {
00548       G4cout << "ERROR: Viewer \"" << fromViewerName
00549              << "\" not found - \"/vis/viewer/list\" to see possibilities."
00550              << G4endl;
00551     }
00552     return;
00553   }
00554 
00555   if (fromViewer == currentViewer) {
00556     if (verbosity >= G4VisManager::warnings) {
00557       G4cout <<
00558         "WARNING: G4VisCommandsViewerSet::SetNewValue:"
00559         "\n  from-viewer and current viewer are identical."
00560              << G4endl;
00561     }
00562     return;
00563   }
00564 
00565   // Copy camera-specific view parameters
00566   G4ViewParameters vp = currentViewer->GetViewParameters();
00567   const G4ViewParameters& fromVP = fromViewer->GetViewParameters();
00568   vp.SetViewpointDirection  (fromVP.GetViewpointDirection());
00569   vp.SetLightpointDirection (fromVP.GetLightpointDirection());
00570   vp.SetLightsMoveWithCamera(fromVP.GetLightsMoveWithCamera());
00571   vp.SetUpVector            (fromVP.GetUpVector());
00572   vp.SetFieldHalfAngle      (fromVP.GetFieldHalfAngle());
00573   vp.SetZoomFactor          (fromVP.GetZoomFactor());
00574   vp.SetScaleFactor         (fromVP.GetScaleFactor());
00575   vp.SetCurrentTargetPoint  (fromVP.GetCurrentTargetPoint());
00576   vp.SetDolly               (fromVP.GetDolly());
00577   SetViewParameters(currentViewer, vp);
00578   
00579   if (verbosity >= G4VisManager::confirmations) {
00580     G4cout << "Camera parameters of viewer \"" << currentViewer->GetName()
00581            << "\"\n  set to those of viewer \"" << fromViewer->GetName()
00582            << "\"."
00583            << G4endl;
00584   }
00585 }
00586 
00588 
00589 G4VisCommandViewerCreate::G4VisCommandViewerCreate (): fId (0) {
00590   G4bool omitable;
00591   fpCommand = new G4UIcommand ("/vis/viewer/create", this);
00592   fpCommand -> SetGuidance
00593     ("Creates a viewer for the specified scene handler.");
00594   fpCommand -> SetGuidance
00595     ("Default scene handler is the current scene handler.  Invents a name"
00596      "\nif not supplied.  (Note: the system adds information to the name"
00597      "\nfor identification - only the characters up to the first blank are"
00598      "\nused for removing, selecting, etc.)  This scene handler and viewer"
00599      "\nbecome current.");
00600   G4UIparameter* parameter;
00601   parameter = new G4UIparameter ("scene-handler", 's', omitable = true);
00602   parameter -> SetCurrentAsDefault (true);
00603   fpCommand -> SetParameter (parameter);
00604   parameter = new G4UIparameter ("viewer-name", 's', omitable = true);
00605   parameter -> SetCurrentAsDefault (true);
00606   fpCommand -> SetParameter (parameter);
00607   parameter = new G4UIparameter ("window-size-hint", 's', omitable = true);
00608   parameter->SetGuidance
00609     ("integer (pixels) for square window placed by window manager or"
00610      " X-Windows-type geometry string, e.g. 600x600-100+100");
00611   parameter->SetDefaultValue("600");
00612   fpCommand -> SetParameter (parameter);
00613 }
00614 
00615 G4VisCommandViewerCreate::~G4VisCommandViewerCreate () {
00616   delete fpCommand;
00617 }
00618 
00619 G4String G4VisCommandViewerCreate::NextName () {
00620   std::ostringstream oss;
00621   G4VSceneHandler* sceneHandler = fpVisManager -> GetCurrentSceneHandler ();
00622   oss << "viewer-" << fId << " (";
00623   if (sceneHandler) {
00624     oss << sceneHandler -> GetGraphicsSystem () -> GetName ();
00625   }
00626   else {
00627     oss << "no_scene_handlers";
00628   }
00629   oss << ")";
00630   return oss.str();
00631 }
00632 
00633 G4String G4VisCommandViewerCreate::GetCurrentValue (G4UIcommand*) {
00634   G4String currentValue;
00635   G4VSceneHandler* currentSceneHandler =
00636     fpVisManager -> GetCurrentSceneHandler ();
00637   if (currentSceneHandler) {
00638     currentValue = currentSceneHandler -> GetName ();
00639   }
00640   else {
00641     currentValue = "none";
00642   }
00643   currentValue += ' ';
00644   currentValue += '"';
00645   currentValue += NextName ();
00646   currentValue += '"';
00647 
00648   currentValue += " 600";  // Default number of pixels for window size hint.
00649 
00650   return currentValue;
00651 }
00652 
00653 void G4VisCommandViewerCreate::SetNewValue (G4UIcommand*, G4String newValue) {
00654 
00655   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
00656 
00657   G4String sceneHandlerName, newName;
00658   G4String windowSizeHintString;
00659   std::istringstream is (newValue);
00660   is >> sceneHandlerName;
00661 
00662   // Now need to handle the possibility that the second string
00663   // contains embedded blanks within quotation marks...
00664   char c;
00665   while (is.get(c) && c == ' '){}
00666   if (c == '"') {
00667     while (is.get(c) && c != '"') {newName += c;}
00668   }
00669   else {
00670     newName += c;
00671     while (is.get(c) && c != ' ') {newName += c;}
00672   }
00673   newName = newName.strip (G4String::both, ' ');
00674   newName = newName.strip (G4String::both, '"');
00675 
00676   // Now get window size hint...
00677   is >> windowSizeHintString;
00678 
00679   const G4SceneHandlerList& sceneHandlerList =
00680     fpVisManager -> GetAvailableSceneHandlers ();
00681   G4int nHandlers = sceneHandlerList.size ();
00682   if (nHandlers <= 0) {
00683     if (verbosity >= G4VisManager::errors) {
00684       G4cout <<
00685         "ERROR: G4VisCommandViewerCreate::SetNewValue: no scene handlers."
00686         "\n  Create a scene handler with \"/vis/sceneHandler/create\""
00687              << G4endl;
00688     }
00689     return;
00690   }
00691 
00692   G4int iHandler;
00693   for (iHandler = 0; iHandler < nHandlers; iHandler++) {
00694     if (sceneHandlerList [iHandler] -> GetName () == sceneHandlerName) break;
00695   }
00696 
00697   if (iHandler < 0 || iHandler >= nHandlers) {
00698     // Invalid command line argument or none.
00699     // This shouldn't happen!!!!!!
00700     if (verbosity >= G4VisManager::errors) {
00701       G4cout << "G4VisCommandViewerCreate::SetNewValue:"
00702         " invalid scene handler specified."
00703             << G4endl;
00704     }
00705     return;
00706   }
00707 
00708   // Valid index.  Set current scene handler and graphics system in
00709   // preparation for creating viewer.
00710   G4VSceneHandler* sceneHandler = sceneHandlerList [iHandler];
00711   if (sceneHandler != fpVisManager -> GetCurrentSceneHandler ()) {
00712     fpVisManager -> SetCurrentSceneHandler (sceneHandler);
00713   }
00714 
00715   // Now deal with name of viewer.
00716   G4String nextName = NextName ();
00717   if (newName == "") {
00718     newName = nextName;
00719   }
00720   if (newName == nextName) fId++;
00721   G4String newShortName = fpVisManager -> ViewerShortName (newName);
00722 
00723   for (G4int ih = 0; ih < nHandlers; ih++) {
00724     G4VSceneHandler* sh = sceneHandlerList [ih];
00725     const G4ViewerList& viewerList = sh -> GetViewerList ();
00726     for (size_t iViewer = 0; iViewer < viewerList.size (); iViewer++) {
00727       if (viewerList [iViewer] -> GetShortName () == newShortName ) {
00728         if (verbosity >= G4VisManager::errors) {
00729           G4cout << "ERROR: Viewer \"" << newShortName << "\" already exists."
00730                  << G4endl;
00731         }
00732         return;
00733       }
00734     }
00735   }
00736 
00737   // WindowSizeHint and XGeometryString are picked up from the vis
00738   // manager in the G4VViewer constructor. In G4VisManager, after Viewer
00739   // creation, we will store theses parameters in G4ViewParameters.
00740 
00741   fpVisManager -> CreateViewer (newName,windowSizeHintString);
00742 
00743   G4VViewer* newViewer = fpVisManager -> GetCurrentViewer ();
00744   if (newViewer && newViewer -> GetName () == newName) {
00745     if (verbosity >= G4VisManager::confirmations) {
00746       G4cout << "New viewer \"" << newName << "\" created." << G4endl;
00747     }
00748   }
00749   else {
00750     if (verbosity >= G4VisManager::errors) {
00751       if (newViewer) {
00752         G4cout << "ERROR: New viewer doesn\'t match!!!  Curious!!" << G4endl;
00753       } else {
00754         G4cout << "WARNING: No viewer created." << G4endl;
00755       }
00756     }
00757   }
00758   // Refresh if appropriate...
00759   if (newViewer) {
00760     if (newViewer->GetViewParameters().IsAutoRefresh()) {
00761       G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/refresh");
00762     }
00763     else {
00764       if (verbosity >= G4VisManager::warnings) {
00765         G4cout << "Issue /vis/viewer/refresh or flush to see effect."
00766                << G4endl;
00767       }
00768     }
00769   }
00770 }
00771 
00773 
00774 G4VisCommandViewerDolly::G4VisCommandViewerDolly ():
00775   fDollyIncrement  (0.),
00776   fDollyTo (0.)
00777 {
00778   G4bool omitable, currentAsDefault;
00779 
00780   fpCommandDolly = new G4UIcmdWithADoubleAndUnit
00781     ("/vis/viewer/dolly", this);
00782   fpCommandDolly -> SetGuidance
00783     ("Incremental dolly.");
00784   fpCommandDolly -> SetGuidance
00785     ("Moves the camera incrementally towards target point.");
00786   fpCommandDolly -> SetParameterName("increment",
00787                                      omitable=true,
00788                                      currentAsDefault=true);
00789   fpCommandDolly -> SetDefaultUnit("m");
00790 
00791   fpCommandDollyTo = new G4UIcmdWithADoubleAndUnit
00792     ("/vis/viewer/dollyTo", this);
00793   fpCommandDollyTo -> SetGuidance
00794     ("Dolly to specific coordinate.");
00795   fpCommandDollyTo -> SetGuidance
00796  ("Places the camera towards target point relative to standard camera point.");
00797   fpCommandDollyTo -> SetParameterName("distance",
00798                                        omitable=true,
00799                                        currentAsDefault=true);
00800   fpCommandDollyTo -> SetDefaultUnit("m");
00801 }
00802 
00803 G4VisCommandViewerDolly::~G4VisCommandViewerDolly () {
00804   delete fpCommandDolly;
00805   delete fpCommandDollyTo;
00806 }
00807 
00808 G4String G4VisCommandViewerDolly::GetCurrentValue (G4UIcommand* command) {
00809   G4String currentValue;
00810   if (command == fpCommandDolly) {
00811     currentValue = fpCommandDolly->ConvertToString(fDollyIncrement, "m");
00812   }
00813   else if (command == fpCommandDollyTo) {
00814     currentValue = fpCommandDollyTo->ConvertToString(fDollyTo, "m");
00815   }
00816   return currentValue;
00817 }
00818 
00819 void G4VisCommandViewerDolly::SetNewValue (G4UIcommand* command,
00820                                            G4String newValue) {
00821 
00822 
00823   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
00824 
00825   G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
00826   if (!currentViewer) {
00827     if (verbosity >= G4VisManager::errors) {
00828       G4cout <<
00829         "ERROR: G4VisCommandsViewerDolly::SetNewValue: no current viewer."
00830              << G4endl;
00831     }
00832     return;
00833   }
00834 
00835   G4ViewParameters vp = currentViewer->GetViewParameters();
00836 
00837   if (command == fpCommandDolly) {
00838     fDollyIncrement = fpCommandDolly->GetNewDoubleValue(newValue);
00839     vp.IncrementDolly(fDollyIncrement);
00840   }
00841   else if (command == fpCommandDollyTo) {
00842     fDollyTo = fpCommandDolly->GetNewDoubleValue(newValue);
00843     vp.SetDolly(fDollyTo);
00844   }
00845 
00846   if (verbosity >= G4VisManager::confirmations) {
00847     G4cout << "Dolly distance changed to " << vp.GetDolly() << G4endl;
00848   }
00849 
00850   SetViewParameters(currentViewer, vp);
00851 }
00852 
00854 
00855 G4VisCommandViewerFlush::G4VisCommandViewerFlush () {
00856   G4bool omitable, currentAsDefault;
00857   fpCommand = new G4UIcmdWithAString ("/vis/viewer/flush", this);
00858   fpCommand -> SetGuidance
00859     ("Compound command: \"/vis/viewer/refresh\" + \"/vis/viewer/update\".");
00860   fpCommand -> SetGuidance
00861     ("Useful for refreshing and initiating post-processing for graphics"
00862      "\nsystems which need post-processing.  By default, acts on current"
00863      "\nviewer.  \"/vis/viewer/list\" to see possible viewers.  Viewer"
00864      "\nbecomes current.");
00865   fpCommand -> SetParameterName ("viewer-name",
00866                                  omitable = true,
00867                                  currentAsDefault = true);
00868 }
00869 
00870 G4VisCommandViewerFlush::~G4VisCommandViewerFlush () {
00871   delete fpCommand;
00872 }
00873 
00874 G4String G4VisCommandViewerFlush::GetCurrentValue 
00875 (G4UIcommand*) {
00876   G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
00877   return viewer ? viewer -> GetName () : G4String("none");
00878 }
00879 
00880 void G4VisCommandViewerFlush::SetNewValue (G4UIcommand*, G4String newValue) {
00881 
00882   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
00883 
00884   G4String& flushName = newValue;
00885   G4VViewer* viewer = fpVisManager -> GetViewer (flushName);
00886   if (!viewer) {
00887     if (verbosity >= G4VisManager::errors) {
00888       G4cout << "ERROR: Viewer \"" << flushName << "\"" <<
00889         " not found - \"/vis/viewer/list\"\n  to see possibilities."
00890              << G4endl;
00891     }
00892     return;
00893   }
00894 
00895   G4UImanager* ui = G4UImanager::GetUIpointer();
00896   G4int keepVerbose = ui->GetVerboseLevel();
00897   G4int newVerbose(0);
00898   if (keepVerbose >= 2 || verbosity >= G4VisManager::confirmations)
00899     newVerbose = 2;
00900   ui->SetVerboseLevel(newVerbose);
00901   ui->ApplyCommand(G4String("/vis/viewer/refresh " + flushName));
00902   ui->ApplyCommand(G4String("/vis/viewer/update " + flushName));
00903   ui->SetVerboseLevel(keepVerbose);
00904   if (verbosity >= G4VisManager::confirmations) {
00905     G4cout << "Viewer \"" << viewer -> GetName () << "\""
00906            << " flushed." << G4endl;
00907   }
00908 }
00909 
00911 
00912 G4VisCommandViewerList::G4VisCommandViewerList () {
00913   G4bool omitable;
00914   fpCommand = new G4UIcommand ("/vis/viewer/list", this);
00915   fpCommand -> SetGuidance ("Lists viewers(s).");
00916   fpCommand -> SetGuidance
00917     ("See \"/vis/verbose\" for definition of verbosity.");
00918   G4UIparameter* parameter;
00919   parameter = new G4UIparameter("viewer-name", 's',
00920                                 omitable = true);
00921   parameter -> SetDefaultValue ("all");
00922   fpCommand -> SetParameter (parameter);
00923   parameter = new G4UIparameter ("verbosity", 's',
00924                                  omitable = true);
00925   parameter -> SetDefaultValue ("warnings");
00926   fpCommand -> SetParameter (parameter);
00927 }
00928 
00929 G4VisCommandViewerList::~G4VisCommandViewerList () {
00930   delete fpCommand;
00931 }
00932 
00933 G4String G4VisCommandViewerList::GetCurrentValue (G4UIcommand*) {
00934   return "";
00935 }
00936 
00937 void G4VisCommandViewerList::SetNewValue (G4UIcommand*, G4String newValue) {
00938   G4String name, verbosityString;
00939   std::istringstream is (newValue);
00940   is >> name >> verbosityString;
00941   G4String shortName = fpVisManager -> ViewerShortName (name);
00942   G4VisManager::Verbosity verbosity =
00943     fpVisManager->GetVerbosityValue(verbosityString);
00944 
00945   const G4VViewer* currentViewer = fpVisManager -> GetCurrentViewer ();
00946   G4String currentViewerShortName;
00947   if (currentViewer) {
00948     currentViewerShortName = currentViewer -> GetShortName ();
00949   }
00950   else {
00951     currentViewerShortName = "none";
00952   }
00953 
00954   const G4SceneHandlerList& sceneHandlerList =
00955     fpVisManager -> GetAvailableSceneHandlers ();
00956   G4int nHandlers = sceneHandlerList.size ();
00957   G4bool found = false;
00958   G4bool foundCurrent = false;
00959   for (int iHandler = 0; iHandler < nHandlers; iHandler++) {
00960     G4VSceneHandler* sceneHandler = sceneHandlerList [iHandler];
00961     const G4ViewerList& viewerList = sceneHandler -> GetViewerList ();
00962     G4cout << "Scene handler \"" << sceneHandler -> GetName ();
00963     const G4Scene* pScene = sceneHandler -> GetScene ();
00964     if (pScene) {
00965       G4cout << "\", scene \"" << pScene -> GetName () << "\":";
00966     }
00967     G4int nViewers = viewerList.size ();
00968     if (nViewers == 0) {
00969       G4cout << "\n            No viewers for this scene handler." << G4endl;
00970     }
00971     else {
00972       for (int iViewer = 0; iViewer < nViewers; iViewer++) {
00973         const G4VViewer* thisViewer = viewerList [iViewer];
00974         G4String thisName = thisViewer -> GetName ();
00975         G4String thisShortName = thisViewer -> GetShortName ();
00976         if (name != "all") {
00977           if (thisShortName != shortName) continue;
00978         }
00979         found = true;
00980         G4cout << "\n  ";
00981         if (thisShortName == currentViewerShortName) {
00982           foundCurrent = true;
00983           G4cout << "(current)";
00984         }
00985         else {
00986           G4cout << "         ";
00987         }
00988         G4cout << " viewer \"" << thisName << "\"";
00989         if (verbosity >= G4VisManager::parameters) {
00990           G4cout << "\n  " << *thisViewer;
00991         }
00992       }
00993     }
00994     G4cout << G4endl;
00995   }
00996 
00997   if (!foundCurrent) {
00998     G4cout << "No valid current viewer - please create or select one."
00999            << G4endl;
01000   }
01001 
01002   if (!found) {
01003     G4cout << "No viewers";
01004     if (name != "all") {
01005       G4cout << " of name \"" << name << "\"";
01006     }
01007     G4cout << " found." << G4endl;
01008   }
01009 }
01010 
01012 
01013 G4VisCommandViewerPan::G4VisCommandViewerPan ():
01014   fPanIncrementRight  (0.),
01015   fPanIncrementUp  (0.),
01016   fPanToRight (0.),
01017   fPanToUp (0.)
01018 {
01019   G4bool omitable;
01020 
01021   fpCommandPan = new G4UIcommand
01022     ("/vis/viewer/pan", this);
01023   fpCommandPan -> SetGuidance
01024     ("Incremental pan.");
01025   fpCommandPan -> SetGuidance
01026     ("Moves the camera incrementally right and up by these amounts (as seen"
01027      "\nfrom viewpoint direction).");
01028   G4UIparameter* parameter;
01029   parameter = new G4UIparameter("right-increment", 'd', omitable = true);
01030   parameter -> SetCurrentAsDefault (true);
01031   fpCommandPan -> SetParameter (parameter);
01032   parameter = new G4UIparameter("up-increment", 'd', omitable = true);
01033   parameter -> SetCurrentAsDefault (true);
01034   fpCommandPan -> SetParameter (parameter);
01035   parameter = new G4UIparameter ("unit", 's', omitable = true);
01036   parameter -> SetDefaultValue ("m");
01037   fpCommandPan -> SetParameter (parameter);
01038 
01039   fpCommandPanTo = new G4UIcommand
01040     ("/vis/viewer/panTo", this);
01041   fpCommandPanTo -> SetGuidance
01042     ("Pan to specific coordinate.");
01043   fpCommandPanTo -> SetGuidance
01044     ("Places the camera in this position right and up relative to standard"
01045      "\ntarget point (as seen from viewpoint direction).");
01046   parameter = new G4UIparameter("right", 'd', omitable = true);
01047   parameter -> SetCurrentAsDefault (true);
01048   fpCommandPanTo -> SetParameter (parameter);
01049   parameter = new G4UIparameter("up", 'd', omitable = true);
01050   parameter -> SetCurrentAsDefault (true);
01051   fpCommandPanTo -> SetParameter (parameter);
01052   parameter = new G4UIparameter ("unit", 's', omitable = true);
01053   parameter -> SetDefaultValue ("m");
01054   fpCommandPanTo -> SetParameter (parameter);
01055 }
01056 
01057 G4VisCommandViewerPan::~G4VisCommandViewerPan () {
01058   delete fpCommandPan;
01059   delete fpCommandPanTo;
01060 }
01061 
01062 G4String G4VisCommandViewerPan::GetCurrentValue (G4UIcommand* command) {
01063   G4String currentValue;
01064   if (command == fpCommandPan) {
01065     currentValue = ConvertToString(fPanIncrementRight, fPanIncrementUp, "m");
01066   }
01067   else if (command == fpCommandPanTo) {
01068     currentValue = ConvertToString(fPanToRight, fPanToUp, "m");
01069   }
01070   return currentValue;
01071 }
01072 
01073 void G4VisCommandViewerPan::SetNewValue (G4UIcommand* command,
01074                                          G4String newValue) {
01075 
01076 
01077   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
01078 
01079   G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
01080   if (!currentViewer) {
01081     if (verbosity >= G4VisManager::errors) {
01082       G4cout <<
01083         "ERROR: G4VisCommandsViewerPan::SetNewValue: no current viewer."
01084              << G4endl;
01085     }
01086     return;
01087   }
01088 
01089   G4ViewParameters vp = currentViewer->GetViewParameters();
01090 
01091   if (command == fpCommandPan) {
01092     ConvertToDoublePair(newValue, fPanIncrementRight, fPanIncrementUp);
01093     vp.IncrementPan(fPanIncrementRight, fPanIncrementUp);
01094   }
01095   else if (command == fpCommandPanTo) {
01096     ConvertToDoublePair(newValue, fPanToRight, fPanToUp);
01097     vp.SetPan(fPanToRight, fPanToUp);
01098   }
01099 
01100   if (verbosity >= G4VisManager::confirmations) {
01101     G4cout << "Current target point now " << vp.GetCurrentTargetPoint()
01102            << G4endl;
01103   }
01104 
01105   SetViewParameters(currentViewer, vp);
01106 }
01107 
01109 
01110 G4VisCommandViewerRebuild::G4VisCommandViewerRebuild () {
01111   G4bool omitable, currentAsDefault;
01112   fpCommand = new G4UIcmdWithAString ("/vis/viewer/rebuild", this);
01113   fpCommand -> SetGuidance ("Forces rebuild of graphical database.");
01114   fpCommand -> SetGuidance 
01115     ("By default, acts on current viewer.  \"/vis/viewer/list\""
01116      "\nto see possible viewers.  Viewer becomes current.");
01117   fpCommand -> SetParameterName ("viewer-name",
01118                                  omitable = true,
01119                                  currentAsDefault = true);
01120 }
01121 
01122 G4VisCommandViewerRebuild::~G4VisCommandViewerRebuild () {
01123   delete fpCommand;
01124 }
01125 
01126 G4String G4VisCommandViewerRebuild::GetCurrentValue (G4UIcommand*) {
01127   G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
01128   if (viewer) {
01129     return viewer -> GetName ();
01130   }
01131   else {
01132     return "none";
01133   }
01134 }
01135 
01136 void G4VisCommandViewerRebuild::SetNewValue (G4UIcommand*, G4String newValue) {
01137 
01138   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
01139 
01140   G4String& rebuildName = newValue;
01141 
01142   G4VViewer* viewer = fpVisManager -> GetViewer (rebuildName);
01143   if (!viewer) {
01144     if (verbosity >= G4VisManager::errors) {
01145       G4cout << "ERROR: Viewer \"" << rebuildName
01146              << "\" not found - \"/vis/viewer/list\" to see possibilities."
01147              << G4endl;
01148     }
01149     return;
01150   }
01151 
01152   G4VSceneHandler* sceneHandler = viewer->GetSceneHandler();
01153   if (!sceneHandler) {
01154     if (verbosity >= G4VisManager::errors) {
01155       G4cout << "ERROR: Viewer \"" << viewer->GetName() << "\"" <<
01156         " has no scene handler - report serious bug."
01157              << G4endl;
01158     }
01159     return;
01160   }
01161 
01162   sceneHandler->ClearTransientStore();
01163   viewer->NeedKernelVisit();
01164   viewer->SetView();
01165   viewer->ClearView();
01166   viewer->DrawView();
01167 
01168   // Check auto-refresh and print confirmations.
01169   RefreshIfRequired(viewer);
01170 }
01171 
01173 
01174 G4VisCommandViewerRefresh::G4VisCommandViewerRefresh () {
01175   G4bool omitable, currentAsDefault;
01176   fpCommand = new G4UIcmdWithAString ("/vis/viewer/refresh", this);
01177   fpCommand -> SetGuidance
01178     ("Refreshes viewer.");
01179   fpCommand -> SetGuidance 
01180     ("By default, acts on current viewer.  \"/vis/viewer/list\""
01181      "\nto see possible viewers.  Viewer becomes current.");
01182   fpCommand -> SetParameterName ("viewer-name",
01183                                  omitable = true,
01184                                  currentAsDefault = true);
01185 }
01186 
01187 G4VisCommandViewerRefresh::~G4VisCommandViewerRefresh () {
01188   delete fpCommand;
01189 }
01190 
01191 G4String G4VisCommandViewerRefresh::GetCurrentValue (G4UIcommand*) {
01192   G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
01193   return viewer ? viewer -> GetName () : G4String("none");
01194 }
01195 
01196 void G4VisCommandViewerRefresh::SetNewValue (G4UIcommand*, G4String newValue) {
01197 
01198   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
01199   G4bool warn(verbosity >= G4VisManager::warnings);
01200 
01201   G4String& refreshName = newValue;
01202   G4VViewer* viewer = fpVisManager -> GetViewer (refreshName);
01203   if (!viewer) {
01204     if (verbosity >= G4VisManager::errors) {
01205       G4cout << "ERROR: Viewer \"" << refreshName << "\"" <<
01206         " not found - \"/vis/viewer/list\"\n  to see possibilities."
01207              << G4endl;
01208     }
01209     return;
01210   }
01211 
01212   G4VSceneHandler* sceneHandler = viewer->GetSceneHandler();
01213   if (!sceneHandler) {
01214     if (verbosity >= G4VisManager::errors) {
01215       G4cout << "ERROR: Viewer \"" << refreshName << "\"" <<
01216         " has no scene handler - report serious bug."
01217              << G4endl;
01218     }
01219     return;
01220   }
01221 
01222   G4Scene* scene = sceneHandler->GetScene();
01223   if (!scene) {
01224     if (verbosity >= G4VisManager::confirmations) {
01225       G4cout << "NOTE: SceneHandler \"" << sceneHandler->GetName()
01226              << "\", to which viewer \"" << refreshName << "\"" <<
01227         "\n  is attached, has no scene - \"/vis/scene/create\" and"
01228         " \"/vis/sceneHandler/attach\""
01229         "\n  (or use compound command \"/vis/drawVolume\")."
01230              << G4endl;
01231     }
01232     return;
01233   }
01234   if (scene->GetRunDurationModelList().empty()) {
01235     G4bool successful = scene -> AddWorldIfEmpty (warn);
01236     if (!successful) {
01237       if (verbosity >= G4VisManager::warnings) {
01238         G4cout <<
01239           "WARNING: Scene is empty.  Perhaps no geometry exists."
01240           "\n  Try /run/initialize."
01241                << G4endl;
01242       }
01243       return;
01244     }
01245     // Scene has changed.  UpdateVisManagerScene issues
01246     // /vis/scene/notifyHandlers, which does a refresh anyway, so the
01247     // ordinary refresh becomes part of the else phrase...
01248     UpdateVisManagerScene(scene->GetName());
01249   } else {
01250     if (verbosity >= G4VisManager::confirmations) {
01251       G4cout << "Refreshing viewer \"" << viewer -> GetName () << "\"..."
01252              << G4endl;
01253     }
01254     viewer -> SetView ();
01255     viewer -> ClearView ();
01256     viewer -> DrawView ();
01257     if (verbosity >= G4VisManager::confirmations) {
01258       G4cout << "Viewer \"" << viewer -> GetName () << "\"" << " refreshed."
01259         "\n  (You might also need \"/vis/viewer/update\".)" << G4endl;
01260     }
01261   }
01262 }
01263 
01265 
01266 G4VisCommandViewerReset::G4VisCommandViewerReset () {
01267   G4bool omitable, currentAsDefault;
01268   fpCommand = new G4UIcmdWithAString ("/vis/viewer/reset", this);
01269   fpCommand -> SetGuidance ("Resets viewer.");
01270   fpCommand -> SetGuidance 
01271     ("By default, acts on current viewer.  \"/vis/viewer/list\""
01272      "\nto see possible viewers.  Viewer becomes current.");
01273   fpCommand -> SetParameterName ("viewer-name",
01274                                  omitable = true,
01275                                  currentAsDefault = true);
01276 }
01277 
01278 G4VisCommandViewerReset::~G4VisCommandViewerReset () {
01279   delete fpCommand;
01280 }
01281 
01282 G4String G4VisCommandViewerReset::GetCurrentValue (G4UIcommand*) {
01283   G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
01284   if (viewer) {
01285     return viewer -> GetName ();
01286   }
01287   else {
01288     return "none";
01289   }
01290 }
01291 
01292 void G4VisCommandViewerReset::SetNewValue (G4UIcommand*, G4String newValue) {
01293 
01294   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
01295 
01296   G4String& resetName = newValue;
01297   G4VViewer* viewer = fpVisManager -> GetViewer (resetName);
01298   if (!viewer) {
01299     if (verbosity >= G4VisManager::errors) {
01300       G4cout << "ERROR: Viewer \"" << resetName
01301              << "\" not found - \"/vis/viewer/list\" to see possibilities."
01302              << G4endl;
01303     }
01304     return;
01305   }
01306 
01307   viewer->ResetView();
01308   RefreshIfRequired(viewer);
01309 }
01310 
01312 
01313 G4VisCommandViewerSave::G4VisCommandViewerSave () {
01314   G4bool omitable;
01315   fpCommand = new G4UIcmdWithAString ("/vis/viewer/save", this);
01316   fpCommand -> SetGuidance
01317   ("Write commands that define the current view to file.");
01318   fpCommand -> SetParameterName ("file-name", omitable = true);
01319   fpCommand -> SetDefaultValue ("G4cout");
01320 }
01321 
01322 G4VisCommandViewerSave::~G4VisCommandViewerSave () {
01323   delete fpCommand;
01324 }
01325 
01326 G4String G4VisCommandViewerSave::GetCurrentValue
01327 (G4UIcommand*) {
01328   return "";
01329 }
01330 
01331 namespace {
01332   void WriteCommands
01333   (std::ostream& os,
01334    const G4ViewParameters& vp,
01335    const G4Point3D& stp)
01336   {
01337     os
01338     << vp.CameraAndLightingCommands(stp)
01339     << vp.DrawingStyleCommands()
01340     << vp.SceneModifyingCommands()
01341     << vp.TouchableCommands()
01342     << std::endl;
01343   }
01344 }
01345 
01346 void G4VisCommandViewerSave::SetNewValue (G4UIcommand*, G4String newValue) {
01347   
01348   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
01349   
01350   const G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
01351   if (!currentViewer) {
01352     if (verbosity >= G4VisManager::errors) {
01353       G4cout <<
01354       "ERROR: G4VisCommandsViewerSave::SetNewValue: no current viewer."
01355       << G4endl;
01356     }
01357     return;
01358   }
01359   
01360   const G4Scene* currentScene = currentViewer->GetSceneHandler()->GetScene();
01361   if (!currentScene) {
01362     if (verbosity >= G4VisManager::errors) {
01363       G4cout <<
01364       "ERROR: G4VisCommandsViewerSave::SetNewValue: no current scene."
01365       << G4endl;
01366     }
01367     return;
01368   }
01369   
01370   std::ofstream ofs;
01371   if (newValue != "G4cout") {
01372     // Check if file exists
01373     std::ifstream ifs(newValue);
01374     if (ifs) {
01375       if (verbosity >= G4VisManager::errors) {
01376         G4cout <<
01377         "ERROR: G4VisCommandsViewerSave::SetNewValue: File \""
01378         << newValue << "\" already exists."
01379         << G4endl;
01380       }
01381       ifs.close();
01382       return;
01383     }
01384     ofs.open(newValue);
01385     if (!ofs) {
01386       if (verbosity >= G4VisManager::errors) {
01387         G4cout <<
01388         "ERROR: G4VisCommandsViewerSave::SetNewValue: Trouble opening file \""
01389         << newValue << "\"."
01390         << G4endl;
01391       }
01392       ofs.close();
01393       return;
01394     }
01395   }
01396   
01397   const G4ViewParameters& vp = currentViewer->GetViewParameters();
01398   const G4Point3D& stp = currentScene->GetStandardTargetPoint();
01399   
01400   if (newValue == "G4cout") {
01401     WriteCommands(G4cout,vp,stp);
01402   } else {
01403     WriteCommands(ofs,vp,stp);
01404     ofs.close();
01405   }
01406 
01407   if (verbosity >= G4VisManager::confirmations) {
01408     G4cout << "Viewer \"" << currentViewer -> GetName ()
01409     << "\"" << " saved to ";
01410     if (newValue == "G4cout") {
01411       G4cout << "G4cout.";
01412     } else {
01413       G4cout << "file \'" << newValue << "\".";
01414     }
01415     G4cout << G4endl;
01416   }
01417 }
01418 
01420 
01421 G4VisCommandViewerScale::G4VisCommandViewerScale ():
01422   fScaleMultiplier (G4Vector3D (1., 1., 1.)),
01423   fScaleTo         (G4Vector3D (1., 1., 1.))
01424 {
01425   G4bool omitable, currentAsDefault;
01426 
01427   fpCommandScale = new G4UIcmdWith3Vector
01428     ("/vis/viewer/scale", this);
01429   fpCommandScale -> SetGuidance ("Incremental (non-uniform) scaling.");
01430   fpCommandScale -> SetGuidance
01431     ("Multiplies components of current scaling by components of this factor."
01432      "\n Scales (x,y,z) by corresponding components of the resulting factor.");
01433   fpCommandScale -> SetGuidance
01434     ("");
01435   fpCommandScale -> SetParameterName
01436     ("x-scale-multiplier","y-scale-multiplier","z-scale-multiplier",
01437      omitable=true, currentAsDefault=true);
01438 
01439   fpCommandScaleTo = new G4UIcmdWith3Vector
01440     ("/vis/viewer/scaleTo", this);
01441   fpCommandScaleTo -> SetGuidance ("Absolute (non-uniform) scaling.");
01442   fpCommandScaleTo -> SetGuidance
01443     ("Scales (x,y,z) by corresponding components of this factor.");
01444   fpCommandScaleTo -> SetParameterName
01445     ("x-scale-factor","y-scale-factor","z-scale-factor",
01446      omitable=true, currentAsDefault=true);
01447 }
01448 
01449 G4VisCommandViewerScale::~G4VisCommandViewerScale () {
01450   delete fpCommandScale;
01451   delete fpCommandScaleTo;
01452 }
01453 
01454 G4String G4VisCommandViewerScale::GetCurrentValue (G4UIcommand* command) {
01455   G4String currentValue;
01456   if (command == fpCommandScale) {
01457     currentValue = fpCommandScale->ConvertToString(G4ThreeVector(fScaleMultiplier));
01458   }
01459   else if (command == fpCommandScaleTo) {
01460     currentValue = fpCommandScaleTo->ConvertToString(G4ThreeVector(fScaleTo));
01461   }
01462   return currentValue;
01463 }
01464 
01465 void G4VisCommandViewerScale::SetNewValue (G4UIcommand* command,
01466                                            G4String newValue) {
01467 
01468 
01469   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
01470 
01471   G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
01472   if (!currentViewer) {
01473     if (verbosity >= G4VisManager::errors) {
01474       G4cout <<
01475         "ERROR: G4VisCommandsViewerScale::SetNewValue: no current viewer."
01476              << G4endl;
01477     }
01478     return;
01479   }
01480 
01481   G4ViewParameters vp = currentViewer->GetViewParameters();
01482 
01483   if (command == fpCommandScale) {
01484     fScaleMultiplier = fpCommandScale->GetNew3VectorValue(newValue);
01485     vp.MultiplyScaleFactor(fScaleMultiplier);
01486   }
01487   else if (command == fpCommandScaleTo) {
01488     fScaleTo = fpCommandScale->GetNew3VectorValue(newValue);
01489     vp.SetScaleFactor(fScaleTo);
01490   }
01491 
01492   if (verbosity >= G4VisManager::confirmations) {
01493     G4cout << "Scale factor changed to " << vp.GetScaleFactor() << G4endl;
01494   }
01495 
01496   SetViewParameters(currentViewer, vp);
01497 }
01498 
01500 
01501 G4VisCommandViewerSelect::G4VisCommandViewerSelect () {
01502   G4bool omitable;
01503   fpCommand = new G4UIcmdWithAString ("/vis/viewer/select", this);
01504   fpCommand -> SetGuidance ("Selects viewer.");
01505   fpCommand -> SetGuidance
01506     ("Specify viewer by name.  \"/vis/viewer/list\" to see possible viewers.");
01507   fpCommand -> SetParameterName ("viewer-name", omitable = false);
01508 }
01509 
01510 G4VisCommandViewerSelect::~G4VisCommandViewerSelect () {
01511   delete fpCommand;
01512 }
01513 
01514 G4String G4VisCommandViewerSelect::GetCurrentValue (G4UIcommand*) {
01515   return "";
01516 }
01517 
01518 void G4VisCommandViewerSelect::SetNewValue (G4UIcommand*, G4String newValue) {
01519 
01520   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
01521 
01522   G4String& selectName = newValue;
01523   G4VViewer* viewer = fpVisManager -> GetViewer (selectName);
01524 
01525   if (!viewer) {
01526     if (verbosity >= G4VisManager::errors) {
01527       G4cout << "ERROR: Viewer \"" << selectName << "\"";
01528       G4cout << " not found - \"/vis/viewer/list\""
01529         "\n  to see possibilities."
01530              << G4endl;
01531     }
01532     return;
01533   }
01534 
01535   if (viewer == fpVisManager -> GetCurrentViewer ()) {
01536     if (verbosity >= G4VisManager::warnings) {
01537       G4cout << "WARNING: Viewer \"" << viewer -> GetName () << "\""
01538              << " already selected." << G4endl;
01539     }
01540     return;
01541   }
01542 
01543   fpVisManager -> SetCurrentViewer (viewer);  // Prints confirmation.
01544 
01545   RefreshIfRequired(viewer);
01546 }
01547 
01549 
01550 G4VisCommandViewerUpdate::G4VisCommandViewerUpdate () {
01551   G4bool omitable, currentAsDefault;
01552   fpCommand = new G4UIcmdWithAString ("/vis/viewer/update", this);
01553   fpCommand -> SetGuidance
01554     ("Triggers graphical database post-processing for viewers"
01555      "\nusing that technique.");
01556   fpCommand -> SetGuidance
01557     ("For such viewers the view only becomes visible with this command."
01558      "\nBy default, acts on current viewer.  \"/vis/viewer/list\""
01559      "\nto see possible viewers.  Viewer becomes current.");
01560   fpCommand -> SetParameterName ("viewer-name",
01561                                  omitable = true,
01562                                  currentAsDefault = true);
01563 }
01564 
01565 G4VisCommandViewerUpdate::~G4VisCommandViewerUpdate () {
01566   delete fpCommand;
01567 }
01568 
01569 G4String G4VisCommandViewerUpdate::GetCurrentValue (G4UIcommand*) {
01570   G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
01571   if (viewer) {
01572     return viewer -> GetName ();
01573   }
01574   else {
01575     return "none";
01576   }
01577 }
01578 
01579 void G4VisCommandViewerUpdate::SetNewValue (G4UIcommand*, G4String newValue) {
01580 
01581   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
01582 
01583   G4String& updateName = newValue;
01584 
01585   G4VViewer* viewer = fpVisManager -> GetViewer (updateName);
01586   if (!viewer) {
01587     if (verbosity >= G4VisManager::errors) {
01588       G4cout <<
01589         "ERROR: G4VisCommandsViewerUpdate::SetNewValue: no current viewer."
01590              << G4endl;
01591     }
01592     return;
01593   }
01594 
01595   G4VSceneHandler* sceneHandler = viewer->GetSceneHandler();
01596   if (!sceneHandler) {
01597     if (verbosity >= G4VisManager::errors) {
01598       G4cout << "ERROR: Viewer \"" << updateName << "\"" <<
01599         " has no scene handler - report serious bug."
01600              << G4endl;
01601     }
01602     return;
01603   }
01604 
01605   G4Scene* scene = sceneHandler->GetScene();
01606   if (!scene) {
01607     if (verbosity >= G4VisManager::confirmations) {
01608       G4cout << "NOTE: SceneHandler \"" << sceneHandler->GetName()
01609              << "\", to which viewer \"" << updateName << "\"" <<
01610         "\n  is attached, has no scene - \"/vis/scene/create\" and"
01611         " \"/vis/sceneHandler/attach\""
01612         "\n  (or use compound command \"/vis/drawVolume\")."
01613              << G4endl;
01614     }
01615     return;
01616   }
01617 
01618   if (verbosity >= G4VisManager::confirmations) {
01619     G4cout << "Viewer \"" << viewer -> GetName () << "\"";
01620     G4cout << " post-processing triggered." << G4endl;
01621   }
01622   viewer -> ShowView ();
01623   // Assume future need to "refresh" transients...
01624   sceneHandler -> SetMarkForClearingTransientStore(true);
01625 }
01626 
01628 
01629 G4VisCommandViewerZoom::G4VisCommandViewerZoom ():
01630   fZoomMultiplier (1.),
01631   fZoomTo         (1.)
01632 {
01633   G4bool omitable, currentAsDefault;
01634 
01635   fpCommandZoom = new G4UIcmdWithADouble
01636     ("/vis/viewer/zoom", this);
01637   fpCommandZoom -> SetGuidance ("Incremental zoom.");
01638   fpCommandZoom -> SetGuidance
01639     ("Multiplies current magnification by this factor.");
01640   fpCommandZoom -> SetParameterName("multiplier",
01641                                      omitable=true,
01642                                      currentAsDefault=true);
01643 
01644   fpCommandZoomTo = new G4UIcmdWithADouble
01645     ("/vis/viewer/zoomTo", this);
01646   fpCommandZoomTo -> SetGuidance ("Absolute zoom.");
01647   fpCommandZoomTo -> SetGuidance
01648     ("Magnifies standard magnification by this factor.");
01649   fpCommandZoomTo -> SetParameterName("factor",
01650                                        omitable=true,
01651                                        currentAsDefault=true);
01652 }
01653 
01654 G4VisCommandViewerZoom::~G4VisCommandViewerZoom () {
01655   delete fpCommandZoom;
01656   delete fpCommandZoomTo;
01657 }
01658 
01659 G4String G4VisCommandViewerZoom::GetCurrentValue (G4UIcommand* command) {
01660   G4String currentValue;
01661   if (command == fpCommandZoom) {
01662     currentValue = fpCommandZoom->ConvertToString(fZoomMultiplier);
01663   }
01664   else if (command == fpCommandZoomTo) {
01665     currentValue = fpCommandZoomTo->ConvertToString(fZoomTo);
01666   }
01667   return currentValue;
01668 }
01669 
01670 void G4VisCommandViewerZoom::SetNewValue (G4UIcommand* command,
01671                                           G4String newValue) {
01672 
01673 
01674   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
01675 
01676   G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
01677   if (!currentViewer) {
01678     if (verbosity >= G4VisManager::errors) {
01679       G4cout <<
01680         "ERROR: G4VisCommandsViewerZoom::SetNewValue: no current viewer."
01681              << G4endl;
01682     }
01683     return;
01684   }
01685 
01686   G4ViewParameters vp = currentViewer->GetViewParameters();
01687 
01688   if (command == fpCommandZoom) {
01689     fZoomMultiplier = fpCommandZoom->GetNewDoubleValue(newValue);
01690     vp.MultiplyZoomFactor(fZoomMultiplier);
01691   }
01692   else if (command == fpCommandZoomTo) {
01693     fZoomTo = fpCommandZoom->GetNewDoubleValue(newValue);
01694     vp.SetZoomFactor(fZoomTo);
01695   }
01696 
01697   if (verbosity >= G4VisManager::confirmations) {
01698     G4cout << "Zoom factor changed to " << vp.GetZoomFactor() << G4endl;
01699   }
01700 
01701   SetViewParameters(currentViewer, vp);
01702 }

Generated on Mon May 27 17:50:15 2013 for Geant4 by  doxygen 1.4.7