G4VisCommands.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/ top level commands - John Allison  5th February 2001
00030 
00031 #include "G4VisCommands.hh"
00032 
00033 #include "G4VisManager.hh"
00034 #include "G4UImanager.hh"
00035 #include "G4UIcmdWithABool.hh"
00036 #include "G4UIcmdWithAString.hh"
00037 #include "G4UIcmdWithoutParameter.hh"
00038 #include "G4RunManager.hh"
00039 #include "G4Run.hh"
00040 #include "G4UIsession.hh"
00041 #include "G4Trajectory.hh"
00042 #include "G4TrajectoryPoint.hh"
00043 #include "G4RichTrajectory.hh"
00044 #include "G4RichTrajectoryPoint.hh"
00045 #include "G4SmoothTrajectory.hh"
00046 #include "G4SmoothTrajectoryPoint.hh"
00047 #include "G4PhysicalVolumeModel.hh"
00048 #include "G4AttDef.hh"
00049 
00051 
00052 G4VisCommandAbortReviewKeptEvents::G4VisCommandAbortReviewKeptEvents () {
00053   G4bool omitable;
00054 
00055   fpCommand = new G4UIcmdWithABool("/vis/abortReviewKeptEvents", this);
00056   fpCommand -> SetGuidance("Abort review of kept events.");
00057   fpCommand -> SetParameterName("abort", omitable=true);
00058   fpCommand -> SetDefaultValue(true);
00059 }
00060 
00061 G4VisCommandAbortReviewKeptEvents::~G4VisCommandAbortReviewKeptEvents () {
00062   delete fpCommand;
00063 }
00064 
00065 G4String G4VisCommandAbortReviewKeptEvents::GetCurrentValue (G4UIcommand*) {
00066   return G4String();
00067 }
00068 
00069 void G4VisCommandAbortReviewKeptEvents::SetNewValue (G4UIcommand*,
00070                                                      G4String newValue) {
00071   fpVisManager->SetAbortReviewKeptEvents(G4UIcommand::ConvertToBool(newValue));
00072   G4cout << "Type \"continue\" to complete the abort." << G4endl;
00073 }
00074 
00076 
00077 G4VisCommandEnable::G4VisCommandEnable () {
00078   G4bool omitable;
00079 
00080   fpCommand = new G4UIcmdWithABool("/vis/enable", this);
00081   fpCommand -> SetGuidance("Enables/disables visualization system.");
00082   fpCommand -> SetParameterName("enabled", omitable=true);
00083   fpCommand -> SetDefaultValue(true);
00084 
00085   fpCommand1 = new G4UIcmdWithoutParameter("/vis/disable", this);
00086   fpCommand1 -> SetGuidance("Disables visualization system.");
00087 }
00088 
00089 G4VisCommandEnable::~G4VisCommandEnable () {
00090   delete fpCommand;
00091   delete fpCommand1;
00092 }
00093 
00094 G4String G4VisCommandEnable::GetCurrentValue (G4UIcommand*) {
00095   return G4String();
00096 }
00097 
00098 void G4VisCommandEnable::SetNewValue (G4UIcommand* command,
00099                                       G4String newValue) {
00100   if (command == fpCommand) {
00101     G4bool enable = G4UIcommand::ConvertToBool(newValue);
00102     if (enable) fpVisManager->Enable();  // Printing is in vis manager.
00103     else fpVisManager->Disable();        // Printing is in vis manager.
00104   } else fpVisManager->Disable();        // Printing is in vis manager.
00105   // Note: Printing is in vis manager.
00106 }
00107 
00109 
00110 G4VisCommandInitialize::G4VisCommandInitialize ()
00111 {
00112   fpCommand = new G4UIcmdWithoutParameter("/vis/initialize", this);
00113   fpCommand -> SetGuidance("Initialise visualisation manager.");
00114 }
00115 
00116 G4VisCommandInitialize::~G4VisCommandInitialize () {
00117   delete fpCommand;
00118 }
00119 
00120 void G4VisCommandInitialize::SetNewValue (G4UIcommand*,
00121                                           G4String) {
00122   fpVisManager->Initialize();
00123 }
00124 
00126 
00127 G4VisCommandList::G4VisCommandList ()
00128 {
00129   G4bool omitable;
00130 
00131   fpCommand = new G4UIcmdWithAString("/vis/list", this);
00132   fpCommand -> SetGuidance("Lists visualization parameters.");
00133   fpCommand -> SetParameterName("verbosity", omitable=true);
00134   fpCommand -> SetDefaultValue("warnings");
00135 }
00136 
00137 G4VisCommandList::~G4VisCommandList ()
00138 {
00139   delete fpCommand;
00140 }
00141 
00142 G4String G4VisCommandList::GetCurrentValue (G4UIcommand*)
00143 {
00144   return "";
00145 }
00146 
00147 void G4VisCommandList::SetNewValue (G4UIcommand*, G4String newValue)
00148 {
00149   G4String& verbosityString = newValue;
00150   G4VisManager::Verbosity verbosity =
00151     fpVisManager->GetVerbosityValue(verbosityString);
00152 
00153   fpVisManager->PrintAvailableGraphicsSystems();
00154   G4cout << G4endl;
00155   fpVisManager->PrintAvailableModels(verbosity);
00156   G4cout << G4endl;
00157   fpVisManager->PrintAvailableUserVisActions(verbosity);
00158   G4cout << G4endl;
00159   fpVisManager->PrintAvailableColours(verbosity);
00160   G4cout << G4endl;
00161   G4UImanager* UImanager = G4UImanager::GetUIpointer();
00162   UImanager->ApplyCommand("/vis/scene/list ! c");
00163   UImanager->ApplyCommand("/vis/viewer/list ! c");
00164 
00165   G4cout <<
00166   "\nAttributes available for modeling and filtering with"
00167   "\n  \"/vis/modeling/trajectories/create/drawByAttribute\" and"
00168   "\n  \"/vis/filtering/trajectories/create/attributeFilter\" commands"
00169   "\nand by picking:"
00170   << G4endl;
00171   G4cout << G4TrajectoriesModel().GetAttDefs();
00172   G4cout << G4RichTrajectory().GetAttDefs()
00173   << G4RichTrajectoryPoint().GetAttDefs();
00174   G4cout << G4SmoothTrajectory().GetAttDefs()
00175   << G4SmoothTrajectoryPoint().GetAttDefs();
00176   G4cout << G4Trajectory().GetAttDefs()
00177   << G4TrajectoryPoint().GetAttDefs();
00178 
00179   G4cout <<
00180   "\nAttributes available for touchables by picking:"
00181   << G4endl;
00182   G4cout << G4PhysicalVolumeModel().GetAttDefs();
00183 
00184   if (verbosity < G4VisManager::parameters)
00185     G4cout <<
00186   "\nTo get more information, \"/vis/list all all\" or use individual commands"
00187   "\n  such as (use \"ls\" or \"help\"):"
00188   "\n    /vis/scene/list all all"
00189   "\n    /vis/viewer/list all all"
00190   "\n    /vis/modeling/trajectories/list"
00191   "\n    /vis/filtering/trajectories/list"
00192            << G4endl;
00193 }
00194 
00196 
00197 G4VisCommandReviewKeptEvents::G4VisCommandReviewKeptEvents ()
00198 {
00199   G4bool omitable;
00200 
00201   fpCommand = new G4UIcmdWithAString("/vis/reviewKeptEvents", this);
00202   fpCommand -> SetGuidance("Review kept events.");
00203   fpCommand -> SetGuidance
00204     ("If a macro file is specified, it is executed for each event.");
00205   fpCommand -> SetGuidance(
00206   "If a macro file is not specified, each event is drawn to the current"
00207   "\nviewer.  After each event, the session is paused.  The user may issue"
00208   "\nany allowed command.  Then enter \"cont[inue]\" to continue to the next"
00209   "\nevent."
00210   "\nUseful commands might be:"
00211   "\n  \"/vis/viewer/...\" to change the view (zoom, set/viewpoint,...)."
00212   "\n  \"/vis/oglx/printEPS\" to get hard copy."
00213   "\n  \"/vis/open\" to get alternative viewer."
00214   "\n  \"/vis/abortReviewKeptEvents\", then \"cont[inue]\", to abort.");
00215   fpCommand -> SetParameterName("macro-file-name", omitable=true);
00216   fpCommand -> SetDefaultValue("");
00217 }
00218 
00219 G4VisCommandReviewKeptEvents::~G4VisCommandReviewKeptEvents ()
00220 {
00221   delete fpCommand;
00222 }
00223 
00224 G4String G4VisCommandReviewKeptEvents::GetCurrentValue (G4UIcommand*)
00225 {
00226   return "";
00227 }
00228 
00229 void G4VisCommandReviewKeptEvents::SetNewValue (G4UIcommand*, G4String newValue)
00230 {
00231   static bool reviewing = false;
00232   if (reviewing) {
00233     G4cout <<
00234       "\"/vis/reviewKeptEvents\" not allowed within an already started review."
00235       "\n  No action taken."
00236            << G4endl;
00237     return;
00238   }
00239 
00240   G4String& macroFileName = newValue;
00241   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
00242 
00243   G4RunManager* runManager = G4RunManager::GetRunManager();
00244   const G4Run* run = runManager? runManager->GetCurrentRun(): 0;
00245   const std::vector<const G4Event*>* events = run? run->GetEventVector(): 0;
00246   size_t nKeptEvents = events? events->size(): 0;
00247 
00248   if (!nKeptEvents) {
00249     if (verbosity >= G4VisManager::errors) {
00250       G4cout <<
00251         "ERROR: G4VisCommandReviewKeptEvents::SetNewValue: No kept events,"
00252         "\n  or kept events not accessible."
00253              << G4endl;
00254     }
00255     return;
00256   }
00257 
00258   G4VViewer* viewer = fpVisManager->GetCurrentViewer();
00259   if (!viewer) {
00260     if (verbosity >= G4VisManager::errors) {
00261       G4cout <<
00262   "ERROR: No current viewer - \"/vis/viewer/list\" to see possibilities."
00263              << G4endl;
00264     }
00265     return;
00266   }
00267 
00268   G4Scene* pScene = fpVisManager->GetCurrentScene();
00269   if (!pScene) {
00270     if (verbosity >= G4VisManager::errors) {
00271       G4cout << "ERROR: No current scene.  Please create one." << G4endl;
00272     }
00273     return;
00274   }
00275 
00276   G4UImanager* UImanager = G4UImanager::GetUIpointer();
00277   G4int keepVerbose = UImanager->GetVerboseLevel();
00278   G4int newVerbose(0);
00279   if (keepVerbose >= 2 || verbosity >= G4VisManager::confirmations)
00280     newVerbose = 2;
00281   UImanager->SetVerboseLevel(newVerbose);
00282 
00283   // Event by event refreshing...
00284   reviewing  = true;
00285   G4bool currentRefreshAtEndOfEvent = pScene->GetRefreshAtEndOfEvent();
00286   pScene->SetRefreshAtEndOfEvent(true);
00287   if (macroFileName.empty()) {
00288 
00289     // Draw to viewer and pause session...
00290     G4UIsession* session = UImanager->GetSession();
00291     for (size_t i = 0; i < nKeptEvents; ++i) {
00292       const G4Event* event = (*events)[i];
00293       if (verbosity >= G4VisManager::warnings) {
00294         G4cout << "Drawing event : " << event->GetEventID() <<
00295           ".  At EndOfEvent, enter any command, then \"cont[inue]\"..."
00296                << G4endl;
00297         static G4bool first = true;
00298         if (first) {
00299           first = false;
00300           G4cout <<
00301   "  Useful commands might be:"
00302   "\n    \"/vis/viewer/...\" to change the view (zoom, set/viewpoint,...)."
00303   "\n    \"/vis/oglx/printEPS\" to get hard copy."
00304   "\n    \"/vis/open\" to get alternative viewer."
00305   "\n    \"/vis/abortReviewKeptEvents\", then \"cont[inue]\", to abort."
00306                  << G4endl;
00307         }
00308       }
00309       fpVisManager->SetRequestedEvent(event);
00310       UImanager->ApplyCommand("/vis/viewer/rebuild");
00311       /* The above command forces a rebuild of the scene, including
00312          the detector.  This is fine for "immediate" viewers - a
00313          refresh requires a rebuild anyway.  But for "stored mode"
00314          viewers, you could, in principle, avoid a rebuild of the
00315          detector with something like the following:
00316       sceneHandler->ClearTransientStore();
00317       viewer->DrawView();
00318       sceneHandler->DrawEvent(event);
00319          but this causes mayhem for "immediate" viewers because
00320          ClearTransientStore issues a DrawView and some curious sort
00321          of recursion takes place.  For "stored" viewers, the event
00322          gets drawn but not the eventID, so something odd is happening
00323          there too.  This needs further investigation - enhanced
00324          features or a complete re-think.
00325       */
00326       UImanager->ApplyCommand("/vis/viewer/flush");
00327       session->PauseSessionStart("EndOfEvent");
00328       fpVisManager->SetRequestedEvent(0);
00329       if (fpVisManager->GetAbortReviewKeptEvents()) break;
00330     }
00331     fpVisManager->SetAbortReviewKeptEvents(false);
00332 
00333   } else {
00334 
00335     // Execute macro file...
00336     for (size_t i = 0; i < nKeptEvents; ++i) {
00337       const G4Event* event = (*events)[i];
00338       if (verbosity >= G4VisManager::warnings) {
00339         G4cout << "Drawing event : " << event->GetEventID()
00340                << " with macro file \"" << macroFileName << G4endl;
00341       }
00342       fpVisManager->SetRequestedEvent(event);
00343       UImanager->ApplyCommand("/control/execute " + macroFileName);
00344       fpVisManager->SetRequestedEvent(0);
00345     }
00346   }
00347   pScene->SetRefreshAtEndOfEvent(currentRefreshAtEndOfEvent);
00348   reviewing  = false;
00349 
00350   UImanager->SetVerboseLevel(keepVerbose);
00351 }
00352 
00354 
00355 G4VisCommandVerbose::G4VisCommandVerbose () {
00356   G4bool omitable;
00357 
00358   fpCommand = new G4UIcmdWithAString("/vis/verbose", this);
00359   for (size_t i = 0; i < G4VisManager::VerbosityGuidanceStrings.size(); ++i) {
00360     fpCommand -> SetGuidance(G4VisManager::VerbosityGuidanceStrings[i]);
00361   }
00362   fpCommand -> SetParameterName("verbosity", omitable=true);
00363   fpCommand -> SetDefaultValue("warnings");
00364 }
00365 
00366 G4VisCommandVerbose::~G4VisCommandVerbose () {
00367   delete fpCommand;
00368 }
00369 
00370 G4String G4VisCommandVerbose::GetCurrentValue (G4UIcommand*) {
00371   return G4String();
00372 }
00373 
00374 void G4VisCommandVerbose::SetNewValue (G4UIcommand*,
00375                                        G4String newValue) {
00376   G4VisManager::Verbosity verbosity =
00377     fpVisManager->GetVerbosityValue(newValue);
00378   fpVisManager->SetVerboseLevel(verbosity);
00379   // Always prints whatever the verbosity...
00380   G4cout << "Visualization verbosity changed to "
00381          << G4VisManager::VerbosityString(verbosity) << G4endl;
00382 }

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