G4VisCommandsSet.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: G4VisCommands.cc,v 1.24 2009-03-09 12:42:00 allison Exp $
00028 // GEANT4 tag $Name: not supported by cvs2svn $
00029 
00030 // /vis/set - John Allison  21st March 2012
00031 // Set quantities for use in appropriate future commands.
00032 
00033 #include "G4VisCommandsSet.hh"
00034 
00035 #include "G4UIcommand.hh"
00036 #include "G4UIcmdWithADouble.hh"
00037 #include "G4UIcmdWithAString.hh"
00038 #include <cctype>
00039 #include <sstream>
00040 
00042 
00043 G4VisCommandSetColour::G4VisCommandSetColour ()
00044 {
00045   G4bool omitable;
00046   fpCommand = new G4UIcommand("/vis/set/colour", this);
00047   fpCommand->SetGuidance
00048     ("Defines colour and opacity for future \"/vis/scene/add/\" commands.");
00049   fpCommand->SetGuidance
00050     ("(Except \"/vis/scene/add/text\" commands - see \"/vis/set/textColour\".)");
00051   fpCommand->SetGuidance("Default: white and opaque.");
00052   G4UIparameter* parameter;
00053   parameter = new G4UIparameter ("red", 's', omitable = true);
00054   parameter->SetGuidance
00055     ("Red component or a string, e.g., \"cyan\" (green and blue parameters are ignored).");
00056   parameter->SetDefaultValue ("1.");
00057   fpCommand->SetParameter (parameter);
00058   parameter = new G4UIparameter ("green", 'd', omitable = true);
00059   parameter->SetDefaultValue (1.);
00060   fpCommand->SetParameter (parameter);
00061   parameter = new G4UIparameter ("blue", 'd', omitable = true);
00062   parameter->SetDefaultValue (1.);
00063   fpCommand->SetParameter (parameter);
00064   parameter = new G4UIparameter ("alpha", 'd', omitable = true);
00065   parameter->SetDefaultValue (1.);
00066   parameter->SetGuidance ("Opacity");
00067   fpCommand->SetParameter (parameter);
00068 }
00069 
00070 G4VisCommandSetColour::~G4VisCommandSetColour ()
00071 {
00072   delete fpCommand;
00073 }
00074 
00075 G4String G4VisCommandSetColour::GetCurrentValue (G4UIcommand*)
00076 {
00077   return G4String();
00078 }
00079 
00080 void G4VisCommandSetColour::SetNewValue (G4UIcommand*, G4String newValue)
00081 {
00082   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
00083 
00084   G4String redOrString;
00085   G4double green, blue, opacity;
00086   std::istringstream iss(newValue);
00087   iss >> redOrString >> green >> blue >> opacity;
00088 
00089   G4Colour colour(1,1,1,1);  // Default white and opaque.
00090   if (std::isalpha(redOrString(0))) {
00091     if (!G4Colour::GetColour(redOrString, colour)) {
00092       if (verbosity >= G4VisManager::warnings) {
00093         G4cout << "WARNING: Colour \"" << redOrString
00094                << "\" not found.  Defaulting to white and opaque."
00095                << G4endl;
00096       }
00097     }
00098   } else {
00099     colour = G4Colour
00100       (G4UIcommand::ConvertToDouble(redOrString), green, blue);
00101   }
00102   // Add opacity
00103   fCurrentColour = G4Colour
00104     (colour.GetRed(), colour.GetGreen(), colour.GetBlue(), opacity);
00105 
00106   if (verbosity >= G4VisManager::confirmations) {
00107     G4cout <<
00108       "Colour for future \"/vis/scene/add/\" commands has been set to "
00109            << fCurrentColour <<
00110       ".\n(Except \"/vis/scene/add/text\" commands - use \"/vis/set/textColour\".)"
00111            << G4endl;
00112   }
00113 }
00114 
00116 
00117 G4VisCommandSetLineWidth::G4VisCommandSetLineWidth ()
00118 {
00119   G4bool omitable;
00120   fpCommand = new G4UIcmdWithADouble("/vis/set/lineWidth", this);
00121   fpCommand->SetGuidance
00122     ("Defines lineWidth for future \"/vis/scene/add/\" commands.");
00123   fpCommand->SetParameterName ("lineWidth", omitable = true);
00124   fpCommand->SetDefaultValue (1.);
00125   fpCommand->SetRange("lineWidth >= 1.");
00126 }
00127 
00128 G4VisCommandSetLineWidth::~G4VisCommandSetLineWidth ()
00129 {
00130   delete fpCommand;
00131 }
00132 
00133 G4String G4VisCommandSetLineWidth::GetCurrentValue (G4UIcommand*)
00134 {
00135   return G4String();
00136 }
00137 
00138 void G4VisCommandSetLineWidth::SetNewValue (G4UIcommand*, G4String newValue)
00139 {
00140   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
00141 
00142   fCurrentLineWidth = fpCommand->GetNewDoubleValue(newValue);
00143 
00144   if (verbosity >= G4VisManager::confirmations) {
00145     G4cout <<
00146       "Line width for future \"/vis/scene/add/\" commands has been set to "
00147            << fCurrentLineWidth
00148            << G4endl;
00149   }
00150 }
00151 
00153 
00154 G4VisCommandSetTextColour::G4VisCommandSetTextColour ()
00155 {
00156   G4bool omitable;
00157   fpCommand = new G4UIcommand("/vis/set/textColour", this);
00158   fpCommand->SetGuidance
00159     ("Defines colour and opacity for future \"/vis/scene/add/text\" commands.");
00160   fpCommand->SetGuidance("Default: blue and opaque.");
00161   G4UIparameter* parameter;
00162   parameter = new G4UIparameter ("red", 's', omitable = true);
00163   parameter->SetGuidance
00164     ("Red component or a string, e.g., \"cyan\" (green and blue parameters are ignored).");
00165   parameter->SetDefaultValue ("0.");
00166   fpCommand->SetParameter (parameter);
00167   parameter = new G4UIparameter ("green", 'd', omitable = true);
00168   parameter->SetDefaultValue (0.);
00169   fpCommand->SetParameter (parameter);
00170   parameter = new G4UIparameter ("blue", 'd', omitable = true);
00171   parameter->SetDefaultValue (1.);
00172   fpCommand->SetParameter (parameter);
00173   parameter = new G4UIparameter ("alpha", 'd', omitable = true);
00174   parameter->SetDefaultValue (1.);
00175   parameter->SetGuidance ("Opacity");
00176   fpCommand->SetParameter (parameter);
00177 }
00178 
00179 G4VisCommandSetTextColour::~G4VisCommandSetTextColour ()
00180 {
00181   delete fpCommand;
00182 }
00183 
00184 G4String G4VisCommandSetTextColour::GetCurrentValue (G4UIcommand*)
00185 {
00186   return G4String();
00187 }
00188 
00189 void G4VisCommandSetTextColour::SetNewValue (G4UIcommand*, G4String newValue)
00190 {
00191   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
00192 
00193   G4String redOrString;
00194   G4double green, blue, opacity;
00195   std::istringstream iss(newValue);
00196   iss >> redOrString >> green >> blue >> opacity;
00197 
00198   G4Colour colour(0,0,1,1);  // Default blue and opaque.
00199   if (std::isalpha(redOrString(0))) {
00200     if (!G4Colour::GetColour(redOrString, colour)) {
00201       if (verbosity >= G4VisManager::warnings) {
00202         G4cout << "WARNING: Text colour \"" << redOrString
00203                << "\" not found.  Defaulting to blue and opaque."
00204                << G4endl;
00205       }
00206     }
00207   } else {
00208     colour = G4Colour
00209       (G4UIcommand::ConvertToDouble(redOrString), green, blue);
00210   }
00211   // Add opacity
00212   fCurrentTextColour = G4Colour
00213     (colour.GetRed(), colour.GetGreen(), colour.GetBlue(), opacity);
00214 
00215   if (verbosity >= G4VisManager::confirmations) {
00216     G4cout <<
00217       "Colour for future \"/vis/scene/add/text\" commands has been set to "
00218            << fCurrentTextColour << '.'
00219            << G4endl;
00220   }
00221 }
00222 
00224 
00225 G4VisCommandSetTextLayout::G4VisCommandSetTextLayout ()
00226 {
00227   G4bool omitable;
00228   fpCommand = new G4UIcmdWithAString("/vis/set/textLayout", this);
00229   fpCommand->SetGuidance
00230     ("Defines layout future \"/vis/scene/add/text\" commands.");
00231   fpCommand->SetGuidance
00232     ("\"left\" (default) for left justification to provided coordinate.");
00233   fpCommand->SetGuidance
00234     ("\"centre\" or \"center\" for text centered on provided coordinate.");
00235   fpCommand->SetGuidance
00236     ("\"right\" for right justification to provided coordinate.");
00237   fpCommand->SetGuidance("Default: left.");
00238   fpCommand->SetParameterName("layout", omitable = true);
00239   fpCommand->SetCandidates ("left centre center right");
00240   fpCommand->SetDefaultValue ("left");
00241 }
00242 
00243 G4VisCommandSetTextLayout::~G4VisCommandSetTextLayout ()
00244 {
00245   delete fpCommand;
00246 }
00247 
00248 G4String G4VisCommandSetTextLayout::GetCurrentValue (G4UIcommand*)
00249 {
00250   return G4String();
00251 }
00252 
00253 void G4VisCommandSetTextLayout::SetNewValue (G4UIcommand*, G4String newValue)
00254 {
00255   G4Text::Layout layout = G4Text::left;
00256   if (newValue == "left") layout = G4Text::left;
00257   else if (newValue == "centre" || newValue == "center")
00258     layout = G4Text::centre;
00259   else if (newValue == "right") layout = G4Text::right;
00260 
00261   fCurrentTextLayout = layout;
00262 
00263   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
00264   if (verbosity >= G4VisManager::confirmations) {
00265     G4cout << "Text layout (for future \"text\" commands) has been set to \""
00266            << fCurrentTextLayout << "\"."
00267            << G4endl;
00268   }
00269 }
00270 
00272 
00273 G4VisCommandSetTouchable::G4VisCommandSetTouchable ()
00274 {
00275   G4bool omitable;
00276   G4UIparameter* parameter;
00277   fpCommand = new G4UIcommand("/vis/set/touchable", this);
00278   fpCommand->SetGuidance
00279   ("Defines touchable for future \"/vis/touchable/set/\" commands.");
00280   fpCommand->SetGuidance
00281   ("Please provide a list of space-separated physical volume names and"
00282    "\ncopy number pairs starting at the world volume, e.g:"
00283    "\n/vis/set/touchable World 0 Envelope 0 Shape1 0");
00284   parameter = new G4UIparameter ("list", 's', omitable = false);
00285   parameter->SetGuidance
00286   ("List of physical volume names and copy number pairs");
00287   fpCommand->SetParameter (parameter);
00288 }
00289 
00290 G4VisCommandSetTouchable::~G4VisCommandSetTouchable ()
00291 {
00292   delete fpCommand;
00293 }
00294 
00295 G4String G4VisCommandSetTouchable::GetCurrentValue (G4UIcommand*)
00296 {
00297   return G4String();
00298 }
00299 
00300 void G4VisCommandSetTouchable::SetNewValue (G4UIcommand*, G4String newValue)
00301 {
00302   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
00303   
00304   G4ModelingParameters::PVNameCopyNoPath currentTouchablePath;
00305   
00306   // Algorithm from Josuttis p.476.
00307   G4String::size_type iBegin, iEnd;
00308   iBegin = newValue.find_first_not_of(' ');
00309   while (iBegin != G4String::npos) {
00310     iEnd = newValue.find_first_of(' ',iBegin);
00311     if (iEnd == G4String::npos) {
00312       iEnd = newValue.length();
00313     }
00314     G4String name(newValue.substr(iBegin,iEnd-iBegin));
00315     iBegin = newValue.find_first_not_of(' ',iEnd);
00316     if (iBegin == G4String::npos) {
00317       if (verbosity >= G4VisManager::warnings) {
00318         G4cout <<
00319         "WARNING: G4VisCommandSetTouchable::SetNewValue"
00320         "\n  A pair not found.  (Did you have an even number of parameters?)"
00321         "\n  Command ignored."
00322         << G4endl;
00323         return;
00324       }
00325     }
00326     iEnd = newValue.find_first_of(' ',iBegin);
00327     if (iEnd == G4String::npos) {
00328       iEnd = newValue.length();
00329     }
00330     G4int copyNo;
00331     std::istringstream iss(newValue.substr(iBegin,iEnd-iBegin));
00332     if (!(iss >> copyNo)) {
00333       if (verbosity >= G4VisManager::warnings) {
00334         G4cout <<
00335         "WARNING: G4VisCommandSetTouchable::SetNewValue"
00336         "\n  Error reading copy number - it was not numeric?"
00337         "\n  Command ignored."
00338         << G4endl;
00339         return;
00340       }
00341     }
00342     currentTouchablePath.push_back
00343     (G4ModelingParameters::PVNameCopyNo(name,copyNo));
00344     iBegin = newValue.find_first_not_of(' ',iEnd);
00345   }
00346   
00347   fCurrentTouchablePath = currentTouchablePath;
00348   
00349   if (verbosity >= G4VisManager::confirmations) {
00350     G4cout    << fCurrentTouchablePath
00351     << G4endl;
00352   }
00353 }
00354 

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