Geant4  10.02.p03
G4VisCommandSceneAddScale Class Reference

#include <G4VisCommandsSceneAdd.hh>

Inheritance diagram for G4VisCommandSceneAddScale:
Collaboration diagram for G4VisCommandSceneAddScale:

Public Member Functions

 G4VisCommandSceneAddScale ()
 
virtual ~G4VisCommandSceneAddScale ()
 
G4String GetCurrentValue (G4UIcommand *command)
 
void SetNewValue (G4UIcommand *command, G4String newValue)
 
- Public Member Functions inherited from G4VVisCommandScene
 G4VVisCommandScene ()
 
virtual ~G4VVisCommandScene ()
 
- Public Member Functions inherited from G4VVisCommand
 G4VVisCommand ()
 
virtual ~G4VVisCommand ()
 
- Public Member Functions inherited from G4UImessenger
 G4UImessenger ()
 
 G4UImessenger (const G4String &path, const G4String &dsc, G4bool commandsToBeBroadcasted=true)
 
virtual ~G4UImessenger ()
 
G4bool operator== (const G4UImessenger &messenger) const
 
G4bool CommandsShouldBeInMaster () const
 

Private Member Functions

 G4VisCommandSceneAddScale (const G4VisCommandSceneAddScale &)
 
G4VisCommandSceneAddScaleoperator= (const G4VisCommandSceneAddScale &)
 

Private Attributes

G4UIcommandfpCommand
 

Additional Inherited Members

- Static Public Member Functions inherited from G4VVisCommand
static void SetVisManager (G4VisManager *)
 
static const G4ColourGetCurrentColour ()
 
static G4double GetCurrentLineWidth ()
 
static const G4ColourGetCurrentTextColour ()
 
static G4Text::Layout GetCurrentTextLayout ()
 
static G4double GetCurrentTextSize ()
 
- Protected Member Functions inherited from G4VVisCommandScene
G4String CurrentSceneName ()
 
- Protected Member Functions inherited from G4VVisCommand
void UpdateVisManagerScene (const G4String &sceneName="")
 
- Protected Member Functions inherited from G4UImessenger
G4String ItoS (G4int i)
 
G4String DtoS (G4double a)
 
G4String BtoS (G4bool b)
 
G4int StoI (G4String s)
 
G4double StoD (G4String s)
 
G4bool StoB (G4String s)
 
void AddUIcommand (G4UIcommand *newCommand)
 
void CreateDirectory (const G4String &path, const G4String &dsc, G4bool commandsToBeBroadcasted=true)
 
template<typename T >
T * CreateCommand (const G4String &cname, const G4String &dsc)
 
- Static Protected Member Functions inherited from G4VVisCommand
static G4String ConvertToString (G4double x, G4double y, const char *unitName)
 
static void ConvertToDoublePair (const G4String &paramString, G4double &xval, G4double &yval)
 
- Protected Attributes inherited from G4UImessenger
G4UIdirectorybaseDir
 
G4String baseDirName
 
G4bool commandsShouldBeInMaster
 
- Static Protected Attributes inherited from G4VVisCommand
static G4VisManagerfpVisManager = 0
 
static G4Colour fCurrentColour = G4Colour::White()
 
static G4double fCurrentLineWidth = 1.
 
static G4Colour fCurrentTextColour = G4Colour::Blue()
 
static G4Text::Layout fCurrentTextLayout = G4Text::left
 
static G4double fCurrentTextSize = 12.
 
static G4ModelingParameters::PVNameCopyNoPath fCurrentTouchablePath
 

Detailed Description

Definition at line 343 of file G4VisCommandsSceneAdd.hh.

Constructor & Destructor Documentation

◆ G4VisCommandSceneAddScale() [1/2]

G4VisCommandSceneAddScale::G4VisCommandSceneAddScale ( )

Definition at line 1862 of file G4VisCommandsSceneAdd.cc.

1862  {
1863  G4bool omitable;
1864  fpCommand = new G4UIcommand ("/vis/scene/add/scale", this);
1865  fpCommand -> SetGuidance
1866  ("Adds an annotated scale line to the current scene.");
1867  fpCommand -> SetGuidance
1868  ("If \"unit\" is \"auto\", length is roughly one tenth of the scene extent.");
1869  fpCommand -> SetGuidance
1870  ("If \"direction\" is \"auto\", scale is roughly in the plane of the current view.");
1871  fpCommand -> SetGuidance
1872  ("If \"placement\" is \"auto\", scale is placed at bottom left of current view."
1873  "\n Otherwise placed at (xmid,ymid,zmid).");
1874  fpCommand -> SetGuidance (G4Scale::GetGuidanceString());
1875  G4UIparameter* parameter;
1876  parameter = new G4UIparameter ("length", 'd', omitable = true);
1877  parameter->SetDefaultValue (1.);
1878  fpCommand->SetParameter (parameter);
1879  parameter = new G4UIparameter ("unit", 's', omitable = true);
1880  parameter->SetDefaultValue ("auto");
1881  fpCommand->SetParameter (parameter);
1882  parameter = new G4UIparameter ("direction", 's', omitable = true);
1883  parameter->SetGuidance ("auto|x|y|z");
1884  parameter->SetDefaultValue ("auto");
1885  fpCommand->SetParameter (parameter);
1886  parameter = new G4UIparameter ("red", 'd', omitable = true);
1887  parameter->SetDefaultValue (1.);
1888  fpCommand->SetParameter (parameter);
1889  parameter = new G4UIparameter ("green", 'd', omitable = true);
1890  parameter->SetDefaultValue (0.);
1891  fpCommand->SetParameter (parameter);
1892  parameter = new G4UIparameter ("blue", 'd', omitable = true);
1893  parameter->SetDefaultValue (0.);
1894  fpCommand->SetParameter (parameter);
1895  parameter = new G4UIparameter ("placement", 's', omitable = true);
1896  parameter -> SetParameterCandidates("auto manual");
1897  parameter->SetDefaultValue ("auto");
1898  fpCommand->SetParameter (parameter);
1899  parameter = new G4UIparameter ("xmid", 'd', omitable = true);
1900  parameter->SetDefaultValue (0.);
1901  fpCommand->SetParameter (parameter);
1902  parameter = new G4UIparameter ("ymid", 'd', omitable = true);
1903  parameter->SetDefaultValue (0.);
1904  fpCommand->SetParameter (parameter);
1905  parameter = new G4UIparameter ("zmid", 'd', omitable = true);
1906  parameter->SetDefaultValue (0.);
1907  fpCommand->SetParameter (parameter);
1908  parameter = new G4UIparameter ("unit", 's', omitable = true);
1909  parameter->SetDefaultValue ("m");
1910  fpCommand->SetParameter (parameter);
1911 }
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:152
void SetDefaultValue(const char *theDefaultValue)
bool G4bool
Definition: G4Types.hh:79
static const G4String & GetGuidanceString()
Definition: G4Scale.cc:66
void SetGuidance(const char *theGuidance)
Here is the call graph for this function:

◆ ~G4VisCommandSceneAddScale()

G4VisCommandSceneAddScale::~G4VisCommandSceneAddScale ( )
virtual

Definition at line 1913 of file G4VisCommandsSceneAdd.cc.

1913  {
1914  delete fpCommand;
1915 }

◆ G4VisCommandSceneAddScale() [2/2]

G4VisCommandSceneAddScale::G4VisCommandSceneAddScale ( const G4VisCommandSceneAddScale )
private

Member Function Documentation

◆ GetCurrentValue()

G4String G4VisCommandSceneAddScale::GetCurrentValue ( G4UIcommand command)
virtual

Reimplemented from G4UImessenger.

Definition at line 1917 of file G4VisCommandsSceneAdd.cc.

1917  {
1918  return "";
1919 }

◆ operator=()

G4VisCommandSceneAddScale& G4VisCommandSceneAddScale::operator= ( const G4VisCommandSceneAddScale )
private

◆ SetNewValue()

void G4VisCommandSceneAddScale::SetNewValue ( G4UIcommand command,
G4String  newValue 
)
virtual

Reimplemented from G4UImessenger.

Definition at line 1921 of file G4VisCommandsSceneAdd.cc.

1921  {
1922 
1924  G4bool warn = verbosity >= G4VisManager::warnings;
1925 
1926  G4Scene* pScene = fpVisManager->GetCurrentScene();
1927  if (!pScene) {
1928  if (verbosity >= G4VisManager::errors) {
1929  G4cerr << "ERROR: No current scene. Please create one." << G4endl;
1930  }
1931  return;
1932  } else {
1933  if (pScene->GetExtent().GetExtentRadius() <= 0.) {
1934  if (verbosity >= G4VisManager::errors) {
1935  G4cerr
1936  << "ERROR: Scene has no extent. Add volumes or use \"/vis/scene/add/extent\"."
1937  << G4endl;
1938  }
1939  return;
1940  }
1941  }
1942 
1943  G4double userLength, red, green, blue, xmid, ymid, zmid;
1944  G4String userLengthUnit, direction, auto_manual, positionUnit;
1945  std::istringstream is (newValue);
1946  is >> userLength >> userLengthUnit >> direction
1947  >> red >> green >> blue
1948  >> auto_manual
1949  >> xmid >> ymid >> zmid >> positionUnit;
1950 
1951  G4double length = userLength;
1952  const G4VisExtent& sceneExtent = pScene->GetExtent(); // Existing extent.
1953  if (userLengthUnit == "auto") {
1954  const G4double lengthMax = 0.5 * sceneExtent.GetExtentRadius();
1955  const G4double intLog10Length = std::floor(std::log10(lengthMax));
1956  length = std::pow(10,intLog10Length);
1957  if (5.*length < lengthMax) length *= 5.;
1958  else if (2.*length < lengthMax) length *= 2.;
1959  } else {
1960  length *= G4UIcommand::ValueOf(userLengthUnit);
1961  }
1962  G4String annotation = G4BestUnit(length,"Length");
1963 
1964  G4double unit = G4UIcommand::ValueOf(positionUnit);
1965  xmid *= unit; ymid *= unit; zmid *= unit;
1966 
1967  G4Scale::Direction scaleDirection (G4Scale::x);
1968  if (direction(0) == 'y') scaleDirection = G4Scale::y;
1969  if (direction(0) == 'z') scaleDirection = G4Scale::z;
1970 
1971  G4VViewer* pViewer = fpVisManager->GetCurrentViewer();
1972  if (!pViewer) {
1973  if (verbosity >= G4VisManager::errors) {
1974  G4cerr <<
1975  "ERROR: G4VisCommandSceneAddScale::SetNewValue: no viewer."
1976  "\n Auto direction needs a viewer."
1977  << G4endl;
1978  }
1979  return;
1980  }
1981 
1982  const G4Vector3D& vp =
1984  const G4Vector3D& up =
1985  pViewer->GetViewParameters().GetUpVector();
1986 
1987  if (direction == "auto") { // Takes cue from viewer.
1988  if (std::abs(vp.x()) > std::abs(vp.y()) &&
1989  std::abs(vp.x()) > std::abs(vp.z())) { // x viewpoint
1990  if (std::abs(up.y()) > std::abs(up.z())) scaleDirection = G4Scale::z;
1991  else scaleDirection = G4Scale::y;
1992  }
1993  else if (std::abs(vp.y()) > std::abs(vp.x()) &&
1994  std::abs(vp.y()) > std::abs(vp.z())) { // y viewpoint
1995  if (std::abs(up.x()) > std::abs(up.z())) scaleDirection = G4Scale::z;
1996  else scaleDirection = G4Scale::x;
1997  }
1998  else if (std::abs(vp.z()) > std::abs(vp.x()) &&
1999  std::abs(vp.z()) > std::abs(vp.y())) { // z viewpoint
2000  if (std::abs(up.y()) > std::abs(up.x())) scaleDirection = G4Scale::x;
2001  else scaleDirection = G4Scale::y;
2002  }
2003  }
2004 
2005  G4bool autoPlacing = false; if (auto_manual == "auto") autoPlacing = true;
2006  // Parameters read and interpreted.
2007 
2008  // Useful constants, etc...
2009  const G4double halfLength(length / 2.);
2010  const G4double comfort(0.01); // 0.15 seems too big. 0.05 might be better.
2011  const G4double freeLengthFraction (1. + 2. * comfort);
2012 
2013  const G4double xmin = sceneExtent.GetXmin();
2014  const G4double xmax = sceneExtent.GetXmax();
2015  const G4double ymin = sceneExtent.GetYmin();
2016  const G4double ymax = sceneExtent.GetYmax();
2017  const G4double zmin = sceneExtent.GetZmin();
2018  const G4double zmax = sceneExtent.GetZmax();
2019 
2020  // Test existing extent and issue warnings...
2021  G4bool worried = false;
2022  if (sceneExtent.GetExtentRadius() == 0) {
2023  worried = true;
2024  if (verbosity >= G4VisManager::warnings) {
2025  G4cout <<
2026  "WARNING: Existing scene does not yet have any extent."
2027  "\n Maybe you have not yet added any geometrical object."
2028  << G4endl;
2029  }
2030  }
2031  // Test existing scene for room...
2032  G4bool room = true;
2033  switch (scaleDirection) {
2034  case G4Scale::x:
2035  if (freeLengthFraction * (xmax - xmin) < length) room = false;
2036  break;
2037  case G4Scale::y:
2038  if (freeLengthFraction * (ymax - ymin) < length) room = false;
2039  break;
2040  case G4Scale::z:
2041  if (freeLengthFraction * (zmax - zmin) < length) room = false;
2042  break;
2043  }
2044  if (!room) {
2045  worried = true;
2046  if (verbosity >= G4VisManager::warnings) {
2047  G4cout <<
2048  "WARNING: Not enough room in existing scene. Maybe scale is too long."
2049  << G4endl;
2050  }
2051  }
2052  if (worried) {
2053  if (verbosity >= G4VisManager::warnings) {
2054  G4cout <<
2055  "WARNING: The scale you have asked for is bigger than the existing"
2056  "\n scene. Maybe you have added it too soon. It is recommended that"
2057  "\n you add the scale last so that it can be correctly auto-positioned"
2058  "\n so as not to be obscured by any existing object and so that the"
2059  "\n view parameters can be correctly recalculated."
2060  << G4endl;
2061  }
2062  }
2063 
2064  // Let's go ahead a construct a scale and a scale model. Since the
2065  // placing is done here, this G4Scale is *not* auto-placed...
2066  G4Scale scale(length, annotation, scaleDirection,
2067  false, xmid, ymid, zmid,
2069  G4VisAttributes visAttr(G4Colour(red, green, blue));
2070  scale.SetVisAttributes(visAttr);
2071  G4VModel* model = new G4ScaleModel(scale);
2072  G4String globalDescription = model->GetGlobalDescription();
2073  globalDescription += " (" + newValue + ")";
2074  model->SetGlobalDescription(globalDescription);
2075 
2076  // Now figure out the extent...
2077  //
2078  // From the G4Scale.hh:
2079  //
2080  // This creates a representation of annotated line in the specified
2081  // direction with tick marks at the end. If autoPlacing is true it
2082  // is required to be centred at the front, right, bottom corner of
2083  // the world space, comfortably outside the existing bounding
2084  // box/sphere so that existing objects do not obscure it. Otherwise
2085  // it is required to be drawn with mid-point at (xmid, ymid, zmid).
2086  //
2087  // The auto placing algorithm might be:
2088  // x = xmin + (1 + comfort) * (xmax - xmin)
2089  // y = ymin - comfort * (ymax - ymin)
2090  // z = zmin + (1 + comfort) * (zmax - zmin)
2091  // if direction == x then (x - length,y,z) to (x,y,z)
2092  // if direction == y then (x,y,z) to (x,y + length,z)
2093  // if direction == z then (x,y,z - length) to (x,y,z)
2094  //
2095  // End of clip from G4Scale.hh:
2096  //
2097  // Implement this in two parts. Here, use the scale's extent to
2098  // "expand" the scene's extent. Then rendering - in
2099  // G4VSceneHandler::AddPrimitive(const G4Scale&) - simply has to
2100  // ensure it's within the new extent.
2101  //
2102 
2103  G4double sxmid(xmid), symid(ymid), szmid(zmid);
2104  if (autoPlacing) {
2105  // Aim to place at bottom right of screen in current view.
2106  // Give some comfort zone.
2107  const G4double xComfort = comfort * (xmax - xmin);
2108  const G4double yComfort = comfort * (ymax - ymin);
2109  const G4double zComfort = comfort * (zmax - zmin);
2110  switch (scaleDirection) {
2111  case G4Scale::x:
2112  if (vp.z() > 0.) {
2113  sxmid = xmax + xComfort;
2114  symid = ymin - yComfort;
2115  szmid = zmin - zComfort;
2116  } else {
2117  sxmid = xmin - xComfort;
2118  symid = ymin - yComfort;
2119  szmid = zmax + zComfort;
2120  }
2121  break;
2122  case G4Scale::y:
2123  if (vp.x() > 0.) {
2124  sxmid = xmin - xComfort;
2125  symid = ymax + yComfort;
2126  szmid = zmin - zComfort;
2127  } else {
2128  sxmid = xmax + xComfort;
2129  symid = ymin - yComfort;
2130  szmid = zmin - zComfort;
2131  }
2132  break;
2133  case G4Scale::z:
2134  if (vp.x() > 0.) {
2135  sxmid = xmax + xComfort;
2136  symid = ymin - yComfort;
2137  szmid = zmax + zComfort;
2138  } else {
2139  sxmid = xmin - xComfort;
2140  symid = ymin - yComfort;
2141  szmid = zmax + zComfort;
2142  }
2143  break;
2144  }
2145  }
2146 
2147  /* Old code - kept for future reference.
2148  G4double sxmid(xmid), symid(ymid), szmid(zmid);
2149  if (autoPlacing) {
2150  sxmid = xmin + onePlusComfort * (xmax - xmin);
2151  symid = ymin - comfort * (ymax - ymin);
2152  szmid = zmin + onePlusComfort * (zmax - zmin);
2153  switch (scaleDirection) {
2154  case G4Scale::x:
2155  sxmid -= halfLength;
2156  break;
2157  case G4Scale::y:
2158  symid += halfLength;
2159  break;
2160  case G4Scale::z:
2161  szmid -= halfLength;
2162  break;
2163  }
2164  }
2165  */
2166 
2167  /* sxmin, etc., not actually used. Comment out to prevent compiler
2168  warnings but keep in case need in future. Extract transform and
2169  scaleExtent into reduced code below.
2170  G4double sxmin(sxmid), sxmax(sxmid);
2171  G4double symin(symid), symax(symid);
2172  G4double szmin(szmid), szmax(szmid);
2173  G4Transform3D transform;
2174  G4VisExtent scaleExtent;
2175  switch (scaleDirection) {
2176  case G4Scale::x:
2177  sxmin = sxmid - halfLength;
2178  sxmax = sxmid + halfLength;
2179  scaleExtent = G4VisExtent(-halfLength,halfLength,0,0,0,0);
2180  break;
2181  case G4Scale::y:
2182  symin = symid - halfLength;
2183  symax = symid + halfLength;
2184  transform = G4RotateZ3D(halfpi);
2185  scaleExtent = G4VisExtent(0,0,-halfLength,halfLength,0,0);
2186  break;
2187  case G4Scale::z:
2188  szmin = szmid - halfLength;
2189  szmax = szmid + halfLength;
2190  transform = G4RotateY3D(halfpi);
2191  scaleExtent = G4VisExtent(0,0,0,0,-halfLength,halfLength);
2192  break;
2193  }
2194  */
2195  G4Transform3D transform;
2196  G4VisExtent scaleExtent;
2197  switch (scaleDirection) {
2198  case G4Scale::x:
2199  scaleExtent = G4VisExtent(-halfLength,halfLength,0,0,0,0);
2200  break;
2201  case G4Scale::y:
2202  transform = G4RotateZ3D(halfpi);
2203  scaleExtent = G4VisExtent(0,0,-halfLength,halfLength,0,0);
2204  break;
2205  case G4Scale::z:
2206  transform = G4RotateY3D(halfpi);
2207  scaleExtent = G4VisExtent(0,0,0,0,-halfLength,halfLength);
2208  break;
2209  }
2210  transform = G4Translate3D(sxmid,symid,szmid) * transform;
2212 
2213 
2214  model->SetTransformation(transform);
2215  // Note: it is the responsibility of the model to act upon this, but
2216  // the extent is in local coordinates...
2217  model->SetExtent(scaleExtent);
2218  // This extent gets "added" to existing scene extent in
2219  // AddRunDurationModel below.
2220 
2221  const G4String& currentSceneName = pScene -> GetName ();
2222  G4bool successful = pScene -> AddRunDurationModel (model, warn);
2223  if (successful) {
2224  if (verbosity >= G4VisManager::confirmations) {
2225  G4cout << "Scale of " << annotation
2226  << " added to scene \"" << currentSceneName << "\".";
2227  if (verbosity >= G4VisManager::parameters) {
2228  G4cout << "\n with extent " << scaleExtent
2229  << "\n at " << transform.getRotation()
2230  << transform.getTranslation();
2231  }
2232  G4cout << G4endl;
2233  }
2234  }
2235  else G4VisCommandsSceneAddUnsuccessful(verbosity);
2236  UpdateVisManagerScene (currentSceneName);
2237 }
G4double GetYmin() const
Definition: G4VisExtent.hh:91
G4VViewer * GetCurrentViewer() const
G4double GetXmax() const
Definition: G4VisExtent.hh:90
static const double halfpi
Definition: G4SIunits.hh:76
HepGeom::RotateY3D G4RotateY3D
Definition: test07.cc:36
CLHEP::Hep3Vector getTranslation() const
const G4String & GetGlobalDescription() const
G4Scene * GetCurrentScene() const
G4double GetZmax() const
Definition: G4VisExtent.hh:94
void UpdateVisManagerScene(const G4String &sceneName="")
G4double GetExtentRadius() const
Definition: G4VisExtent.cc:73
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
Direction
Definition: G4Scale.hh:42
void SetExtent(const G4VisExtent &)
static G4double fCurrentTextSize
Definition: test07.cc:36
HepGeom::RotateZ3D G4RotateZ3D
G4double GetXmin() const
Definition: G4VisExtent.hh:89
void SetTransformation(const G4Transform3D &)
const G4Vector3D & GetUpVector() const
static void G4VisCommandsSceneAddUnsuccessful(G4VisManager::Verbosity verbosity)
const G4Vector3D & GetViewpointDirection() const
G4GLOB_DLL std::ostream G4cout
const G4VisExtent & GetExtent() const
bool G4bool
Definition: G4Types.hh:79
Double_t scale
G4double GetZmin() const
Definition: G4VisExtent.hh:93
G4double GetYmax() const
Definition: G4VisExtent.hh:92
static G4double ValueOf(const char *unitName)
Definition: G4UIcommand.cc:308
static Verbosity GetVerbosity()
HepGeom::Translate3D G4Translate3D
const G4ViewParameters & GetViewParameters() const
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
CLHEP::HepRotation getRotation() const
void SetGlobalDescription(const G4String &)
G4GLOB_DLL std::ostream G4cerr
static G4VisManager * fpVisManager
Here is the call graph for this function:

Member Data Documentation

◆ fpCommand

G4UIcommand* G4VisCommandSceneAddScale::fpCommand
private

Definition at line 352 of file G4VisCommandsSceneAdd.hh.


The documentation for this class was generated from the following files: