1771 {
1772
1775
1777 if (!pScene) {
1779 G4cout <<
"ERROR: No current scene. Please create one." <<
G4endl;
1780 }
1781 return;
1782 }
1783
1784 G4double userLength, red, green, blue, xmid, ymid, zmid;
1785 G4String userLengthUnit, direction, auto_manual, positionUnit;
1786 std::istringstream is (newValue);
1787 is >> userLength >> userLengthUnit >> direction
1788 >> red >> green >> blue
1789 >> auto_manual
1790 >> xmid >> ymid >> zmid >> positionUnit;
1791
1794 if (userLengthUnit == "auto") {
1796 G4double intLog10Length = std::floor(std::log10(length));
1797 length = std::pow(10,intLog10Length);
1798 } else {
1800 }
1802
1804 xmid *= unit; ymid *= unit; zmid *= unit;
1805
1807 if (direction(0) ==
'y') scaleDirection =
G4Scale::y;
1808 if (direction(0) ==
'z') scaleDirection =
G4Scale::z;
1809
1811 if (!pViewer) {
1814 "ERROR: G4VisCommandSceneAddScale::SetNewValue: no viewer."
1815 "\n Auto direction needs a viewer."
1817 }
1818 return;
1819 }
1820
1825
1826 if (direction == "auto") {
1827 if (std::abs(vp.
x()) > std::abs(vp.
y()) &&
1828 std::abs(vp.
x()) > std::abs(vp.
z())) {
1829 if (std::abs(up.
y()) > std::abs(up.
z())) scaleDirection =
G4Scale::z;
1831 }
1832 else if (std::abs(vp.
y()) > std::abs(vp.
x()) &&
1833 std::abs(vp.
y()) > std::abs(vp.
z())) {
1834 if (std::abs(up.
x()) > std::abs(up.
z())) scaleDirection =
G4Scale::z;
1836 }
1837 else if (std::abs(vp.
z()) > std::abs(vp.
x()) &&
1838 std::abs(vp.
z()) > std::abs(vp.
y())) {
1839 if (std::abs(up.
y()) > std::abs(up.
x())) scaleDirection =
G4Scale::x;
1841 }
1842 }
1843
1844 G4bool autoPlacing =
false;
if (auto_manual ==
"auto") autoPlacing =
true;
1845
1846
1847
1848 const G4double halfLength(length / 2.);
1850 const G4double freeLengthFraction (1. + 2. * comfort);
1851
1858
1859
1862 worried = true;
1865 "WARNING: Existing scene does not yet have any extent."
1866 "\n Maybe you have not yet added any geometrical object."
1868 }
1869 }
1870
1872 switch (scaleDirection) {
1874 if (freeLengthFraction * (xmax - xmin) < length) room = false; break;
1876 if (freeLengthFraction * (ymax - ymin) < length) room = false; break;
1878 if (freeLengthFraction * (zmax - zmin) < length) room = false; break;
1879 }
1880 if (!room) {
1881 worried = true;
1884 "WARNING: Not enough room in existing scene. Maybe scale is too long."
1886 }
1887 }
1888 if (worried) {
1891 "WARNING: The scale you have asked for is bigger than the existing"
1892 "\n scene. Maybe you have added it too soon. It is recommended that"
1893 "\n you add the scale last so that it can be correctly auto-positioned"
1894 "\n so as not to be obscured by any existing object and so that the"
1895 "\n view parameters can be correctly recalculated."
1897 }
1898 }
1899
1900
1901
1902 G4Scale scale(length, annotation, scaleDirection,
1903 false, xmid, ymid, zmid);
1905
1906
1907
1908
1909 scale.SetVisAttributes(pVisAttr);
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939 G4double sxmid(xmid), symid(ymid), szmid(zmid);
1940 if (autoPlacing) {
1941
1942
1943 const G4double xComfort = comfort * (xmax - xmin);
1944 const G4double yComfort = comfort * (ymax - ymin);
1945 const G4double zComfort = comfort * (zmax - zmin);
1946 switch (scaleDirection) {
1949 sxmid = xmax + xComfort;
1950 symid = ymin - yComfort;
1951 szmid = zmin - zComfort;
1952 } else {
1953 sxmid = xmin - xComfort;
1954 symid = ymin - yComfort;
1955 szmid = zmax + zComfort;
1956 }
1957 break;
1960 sxmid = xmin - xComfort;
1961 symid = ymax + yComfort;
1962 szmid = zmin - zComfort;
1963 } else {
1964 sxmid = xmax + xComfort;
1965 symid = ymin - yComfort;
1966 szmid = zmin - zComfort;
1967 }
1968 break;
1971 sxmid = xmax + xComfort;
1972 symid = ymin - yComfort;
1973 szmid = zmax + zComfort;
1974 } else {
1975 sxmid = xmin - xComfort;
1976 symid = ymin - yComfort;
1977 szmid = zmax + zComfort;
1978 }
1979 break;
1980 }
1981 }
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2033 switch (scaleDirection) {
2035 scaleExtent =
G4VisExtent(-halfLength,halfLength,0,0,0,0);
2036 break;
2039 scaleExtent =
G4VisExtent(0,0,-halfLength,halfLength,0,0);
2040 break;
2043 scaleExtent =
G4VisExtent(0,0,0,0,-halfLength,halfLength);
2044 break;
2045 }
2047
2048
2049
2051
2052
2054
2055
2056
2057 const G4String& currentSceneName = pScene -> GetName ();
2058 G4bool successful = pScene -> AddRunDurationModel (model, warn);
2059 if (successful) {
2061 G4cout <<
"Scale of " << annotation
2062 << " added to scene \"" << currentSceneName << "\".";
2064 G4cout <<
"\n with extent " << scaleExtent
2067 }
2069 }
2070 }
2071 else G4VisCommandsSceneAddUnsuccessful(verbosity);
2073}
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
G4DLLIMPORT std::ostream G4cout
const G4VisExtent & GetExtent() const
static G4double ValueOf(const char *unitName)
void SetExtent(const G4VisExtent &)
void SetTransformation(const G4Transform3D &)
const G4ViewParameters & GetViewParameters() const
static G4VisManager * fpVisManager
void UpdateVisManagerScene(const G4String &sceneName="")
const G4Vector3D & GetViewpointDirection() const
const G4Vector3D & GetUpVector() const
G4double GetExtentRadius() const
G4Scene * GetCurrentScene() const
G4VViewer * GetCurrentViewer() const
static Verbosity GetVerbosity()