Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4VisCommandSceneAddLogo Class Reference

#include <G4VisCommandsSceneAdd.hh>

Inheritance diagram for G4VisCommandSceneAddLogo:
Collaboration diagram for G4VisCommandSceneAddLogo:

Public Member Functions

 G4VisCommandSceneAddLogo ()
 
virtual ~G4VisCommandSceneAddLogo ()
 
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
 

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 G4int fErrorCode = 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 273 of file G4VisCommandsSceneAdd.hh.

Constructor & Destructor Documentation

G4VisCommandSceneAddLogo::G4VisCommandSceneAddLogo ( )

Definition at line 1255 of file G4VisCommandsSceneAdd.cc.

1255  {
1256  G4bool omitable;
1257  fpCommand = new G4UIcommand ("/vis/scene/add/logo", this);
1258  fpCommand -> SetGuidance ("Adds a G4 logo to the current scene.");
1259  fpCommand -> SetGuidance
1260  ("If \"unit\" is \"auto\", height is roughly one tenth of scene extent.");
1261  fpCommand -> SetGuidance
1262  ("\"direction\" is that of outward-facing normal to front face of logo."
1263  "\nIf \"direction\" is \"auto\", logo faces the user in the current viewer.");
1264  fpCommand -> SetGuidance
1265  ("\nIf \"placement\" is \"auto\", logo is placed at bottom right of screen"
1266  "\n when viewed from logo direction.");
1267  G4UIparameter* parameter;
1268  parameter = new G4UIparameter ("height", 'd', omitable = true);
1269  parameter->SetDefaultValue (1.);
1270  fpCommand->SetParameter (parameter);
1271  parameter = new G4UIparameter ("unit", 's', omitable = true);
1272  parameter->SetDefaultValue ("auto");
1273  fpCommand->SetParameter (parameter);
1274  parameter = new G4UIparameter ("direction", 's', omitable = true);
1275  parameter->SetGuidance ("auto|[-]x|[-]y|[-]z");
1276  parameter->SetDefaultValue ("auto");
1277  fpCommand->SetParameter (parameter);
1278  parameter = new G4UIparameter ("red", 'd', omitable = true);
1279  parameter->SetDefaultValue (0.);
1280  fpCommand->SetParameter (parameter);
1281  parameter = new G4UIparameter ("green", 'd', omitable = true);
1282  parameter->SetDefaultValue (1.);
1283  fpCommand->SetParameter (parameter);
1284  parameter = new G4UIparameter ("blue", 'd', omitable = true);
1285  parameter->SetDefaultValue (0.);
1286  fpCommand->SetParameter (parameter);
1287  parameter = new G4UIparameter ("placement", 's', omitable = true);
1288  parameter -> SetParameterCandidates("auto manual");
1289  parameter->SetDefaultValue ("auto");
1290  fpCommand->SetParameter (parameter);
1291  parameter = new G4UIparameter ("xmid", 'd', omitable = true);
1292  parameter->SetDefaultValue (0.);
1293  fpCommand->SetParameter (parameter);
1294  parameter = new G4UIparameter ("ymid", 'd', omitable = true);
1295  parameter->SetDefaultValue (0.);
1296  fpCommand->SetParameter (parameter);
1297  parameter = new G4UIparameter ("zmid", 'd', omitable = true);
1298  parameter->SetDefaultValue (0.);
1299  fpCommand->SetParameter (parameter);
1300  parameter = new G4UIparameter ("unit", 's', omitable = true);
1301  parameter->SetDefaultValue ("m");
1302  fpCommand->SetParameter (parameter);
1303 }
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:152
void SetDefaultValue(const char *theDefaultValue)
bool G4bool
Definition: G4Types.hh:79
void SetGuidance(const char *theGuidance)

Here is the call graph for this function:

G4VisCommandSceneAddLogo::~G4VisCommandSceneAddLogo ( )
virtual

Definition at line 1305 of file G4VisCommandsSceneAdd.cc.

1305  {
1306  delete fpCommand;
1307 }

Member Function Documentation

G4String G4VisCommandSceneAddLogo::GetCurrentValue ( G4UIcommand command)
virtual

Reimplemented from G4UImessenger.

Definition at line 1309 of file G4VisCommandsSceneAdd.cc.

1309  {
1310  return "";
1311 }
void G4VisCommandSceneAddLogo::SetNewValue ( G4UIcommand command,
G4String  newValue 
)
virtual

Reimplemented from G4UImessenger.

Definition at line 1313 of file G4VisCommandsSceneAdd.cc.

1313  {
1314 
1316  G4bool warn = verbosity >= G4VisManager::warnings;
1317 
1318  G4Scene* pScene = fpVisManager->GetCurrentScene();
1319  if (!pScene) {
1320  if (verbosity >= G4VisManager::errors) {
1321  G4cerr << "ERROR: No current scene. Please create one." << G4endl;
1322  }
1323  return;
1324  } else {
1325  if (pScene->GetExtent().GetExtentRadius() <= 0.) {
1326  if (verbosity >= G4VisManager::errors) {
1327  G4cerr
1328  << "ERROR: Scene has no extent. Add volumes or use \"/vis/scene/add/extent\"."
1329  << G4endl;
1330  }
1331  return;
1332  }
1333  }
1334 
1335  G4VViewer* pViewer = fpVisManager->GetCurrentViewer();
1336  if (!pViewer) {
1337  if (verbosity >= G4VisManager::errors) {
1338  G4cerr <<
1339  "ERROR: G4VisCommandSceneAddLogo::SetNewValue: no viewer."
1340  "\n Auto direction needs a viewer."
1341  << G4endl;
1342  }
1343  return;
1344  }
1345 
1346  G4double userHeight, red, green, blue, xmid, ymid, zmid;
1347  G4String userHeightUnit, direction, auto_manual, positionUnit;
1348  std::istringstream is (newValue);
1349  is >> userHeight >> userHeightUnit >> direction
1350  >> red >> green >> blue
1351  >> auto_manual
1352  >> xmid >> ymid >> zmid >> positionUnit;
1353 
1354  G4double height = userHeight;
1355  const G4VisExtent& sceneExtent = pScene->GetExtent(); // Existing extent.
1356  if (userHeightUnit == "auto") {
1357  height *= 0.2 * sceneExtent.GetExtentRadius();
1358  } else {
1359  height *= G4UIcommand::ValueOf(userHeightUnit);
1360  }
1361 
1362  G4double unit = G4UIcommand::ValueOf(positionUnit);
1363  xmid *= unit; ymid *= unit; zmid *= unit;
1364 
1365  Direction logoDirection = X; // Initialise to keep some compilers happy.
1366  if (direction == "auto") {
1367  // Take cue from viewer
1368  const G4Vector3D& vp =
1370  if (vp.x() > vp.y() && vp.x() > vp.z()) logoDirection = X;
1371  else if (vp.x() < vp.y() && vp.x() < vp.z()) logoDirection = minusX;
1372  else if (vp.y() > vp.x() && vp.y() > vp.z()) logoDirection = Y;
1373  else if (vp.y() < vp.x() && vp.y() < vp.z()) logoDirection = minusY;
1374  else if (vp.z() > vp.x() && vp.z() > vp.y()) logoDirection = Z;
1375  else if (vp.z() < vp.x() && vp.z() < vp.y()) logoDirection = minusZ;
1376  }
1377  else if (direction(0) == 'x') logoDirection = X;
1378  else if (direction(0) == 'y') logoDirection = Y;
1379  else if (direction(0) == 'z') logoDirection = Z;
1380  else if (direction(0) == '-') {
1381  if (direction(1) == 'x') logoDirection = minusX;
1382  else if (direction(1) == 'y') logoDirection = minusY;
1383  else if (direction(1) == 'z') logoDirection = minusZ;
1384  } else {
1385  if (verbosity >= G4VisManager::errors) {
1386  G4cerr << "ERROR: Unrecogniseed direction: \""
1387  << direction << "\"." << G4endl;
1388  return;
1389  }
1390  }
1391 
1392  G4bool autoPlacing = false; if (auto_manual == "auto") autoPlacing = true;
1393  // Parameters read and interpreted.
1394 
1395  // Current scene extent
1396  const G4double xmin = sceneExtent.GetXmin();
1397  const G4double xmax = sceneExtent.GetXmax();
1398  const G4double ymin = sceneExtent.GetYmin();
1399  const G4double ymax = sceneExtent.GetYmax();
1400  const G4double zmin = sceneExtent.GetZmin();
1401  const G4double zmax = sceneExtent.GetZmax();
1402 
1403  // Test existing extent and issue warnings...
1404  G4bool worried = false;
1405  if (sceneExtent.GetExtentRadius() == 0) {
1406  worried = true;
1407  if (verbosity >= G4VisManager::warnings) {
1408  G4cout <<
1409  "WARNING: Existing scene does not yet have any extent."
1410  "\n Maybe you have not yet added any geometrical object."
1411  << G4endl;
1412  }
1413  }
1414 
1415  // Useful constants, etc...
1416  const G4double halfHeight(height / 2.);
1417  const G4double comfort(0.01); // 0.15 seems too big. 0.05 might be better.
1418  const G4double freeHeightFraction (1. + 2. * comfort);
1419 
1420  // Test existing scene for room...
1421  G4bool room = true;
1422  switch (logoDirection) {
1423  case X:
1424  case minusX:
1425  if (freeHeightFraction * (xmax - xmin) < height) room = false;
1426  break;
1427  case Y:
1428  case minusY:
1429  if (freeHeightFraction * (ymax - ymin) < height) room = false;
1430  break;
1431  case Z:
1432  case minusZ:
1433  if (freeHeightFraction * (zmax - zmin) < height) room = false;
1434  break;
1435  }
1436  if (!room) {
1437  worried = true;
1438  if (verbosity >= G4VisManager::warnings) {
1439  G4cout <<
1440  "WARNING: Not enough room in existing scene. Maybe logo is too large."
1441  << G4endl;
1442  }
1443  }
1444  if (worried) {
1445  if (verbosity >= G4VisManager::warnings) {
1446  G4cout <<
1447  "WARNING: The logo you have asked for is bigger than the existing"
1448  "\n scene. Maybe you have added it too soon. It is recommended that"
1449  "\n you add the logo last so that it can be correctly auto-positioned"
1450  "\n so as not to be obscured by any existing object and so that the"
1451  "\n view parameters can be correctly recalculated."
1452  << G4endl;
1453  }
1454  }
1455 
1456  G4double sxmid(xmid), symid(ymid), szmid(zmid);
1457  if (autoPlacing) {
1458  // Aim to place at bottom right of screen when viewed from logoDirection.
1459  // Give some comfort zone.
1460  const G4double xComfort = comfort * (xmax - xmin);
1461  const G4double yComfort = comfort * (ymax - ymin);
1462  const G4double zComfort = comfort * (zmax - zmin);
1463  switch (logoDirection) {
1464  case X: // y-axis up, z-axis to left?
1465  sxmid = xmax + halfHeight + xComfort;
1466  symid = ymin - yComfort;
1467  szmid = zmin - zComfort;
1468  break;
1469  case minusX: // y-axis up, z-axis to right?
1470  sxmid = xmin - halfHeight - xComfort;
1471  symid = ymin - yComfort;
1472  szmid = zmax + zComfort;
1473  break;
1474  case Y: // z-axis up, x-axis to left?
1475  sxmid = xmin - xComfort;
1476  symid = ymax + halfHeight + yComfort;
1477  szmid = zmin - zComfort;
1478  break;
1479  case minusY: // z-axis up, x-axis to right?
1480  sxmid = xmax + xComfort;
1481  symid = ymin - halfHeight - yComfort;
1482  szmid = zmin - zComfort;
1483  break;
1484  case Z: // y-axis up, x-axis to right?
1485  sxmid = xmax + xComfort;
1486  symid = ymin - yComfort;
1487  szmid = zmax + halfHeight + zComfort;
1488  break;
1489  case minusZ: // y-axis up, x-axis to left?
1490  sxmid = xmin - xComfort;
1491  symid = ymin - yComfort;
1492  szmid = zmin - halfHeight - zComfort;
1493  break;
1494  }
1495  }
1496 
1497  G4Transform3D transform;
1498  switch (logoDirection) {
1499  case X: // y-axis up, z-axis to left?
1500  transform = G4RotateY3D(halfpi);
1501  break;
1502  case minusX: // y-axis up, z-axis to right?
1503  transform = G4RotateY3D(-halfpi);
1504  break;
1505  case Y: // z-axis up, x-axis to left?
1506  transform = G4RotateX3D(-halfpi) * G4RotateZ3D(pi);
1507  break;
1508  case minusY: // z-axis up, x-axis to right?
1509  transform = G4RotateX3D(halfpi);
1510  break;
1511  case Z: // y-axis up, x-axis to right?
1512  // No transformation required.
1513  break;
1514  case minusZ: // y-axis up, x-axis to left?
1515  transform = G4RotateY3D(pi);
1516  break;
1517  }
1518  transform = G4Translate3D(sxmid,symid,szmid) * transform;
1519 
1520  G4VisAttributes visAtts(G4Colour(red, green, blue));
1521  visAtts.SetForceSolid(true); // Always solid.
1522 
1523  G4Logo* logo = new G4Logo(height,visAtts);
1524  G4VModel* model =
1526  model->SetType("G4Logo");
1527  model->SetGlobalTag("G4Logo");
1528  model->SetGlobalDescription("G4Logo: " + newValue);
1529  model->SetTransformation(transform);
1530  // Note: it is the responsibility of the model to act upon this, but
1531  // the extent is in local coordinates...
1532  G4double& h = height;
1533  G4double h2 = h/2.;
1534  G4VisExtent extent(-h,h,-h2,h2,-h2,h2);
1535  model->SetExtent(extent);
1536  // This extent gets "added" to existing scene extent in
1537  // AddRunDurationModel below.
1538  const G4String& currentSceneName = pScene -> GetName ();
1539  G4bool successful = pScene -> AddRunDurationModel (model, warn);
1540  if (successful) {
1541  if (verbosity >= G4VisManager::confirmations) {
1542  G4cout << "G4 Logo of height " << userHeight << ' ' << userHeightUnit
1543  << ", " << direction << "-direction, added to scene \""
1544  << currentSceneName << "\"";
1545  if (verbosity >= G4VisManager::parameters) {
1546  G4cout << "\n with extent " << extent
1547  << "\n at " << transform.getRotation()
1548  << transform.getTranslation();
1549  }
1550  G4cout << G4endl;
1551  }
1552  }
1553  else G4VisCommandsSceneAddUnsuccessful(verbosity);
1554  UpdateVisManagerScene (currentSceneName);
1555 }
void SetGlobalTag(const G4String &)
HepGeom::RotateX3D G4RotateX3D
HepGeom::RotateY3D G4RotateY3D
Definition: test07.cc:36
G4double GetXmin() const
Definition: G4VisExtent.hh:89
void UpdateVisManagerScene(const G4String &sceneName="")
const G4ViewParameters & GetViewParameters() const
G4double GetXmax() const
Definition: G4VisExtent.hh:90
void SetExtent(const G4VisExtent &)
Definition: test07.cc:36
HepGeom::RotateZ3D G4RotateZ3D
void SetTransformation(const G4Transform3D &)
static void G4VisCommandsSceneAddUnsuccessful(G4VisManager::Verbosity verbosity)
G4double GetExtentRadius() const
Definition: G4VisExtent.cc:73
const G4Vector3D & GetViewpointDirection() const
G4GLOB_DLL std::ostream G4cout
const G4VisExtent & GetExtent() const
G4double GetYmax() const
Definition: G4VisExtent.hh:92
CLHEP::HepRotation getRotation() const
bool G4bool
Definition: G4Types.hh:79
void SetType(const G4String &)
G4double GetZmax() const
Definition: G4VisExtent.hh:94
static G4double ValueOf(const char *unitName)
Definition: G4UIcommand.cc:309
G4double GetZmin() const
Definition: G4VisExtent.hh:93
static Verbosity GetVerbosity()
HepGeom::Translate3D G4Translate3D
G4double GetYmin() const
Definition: G4VisExtent.hh:91
#define G4endl
Definition: G4ios.hh:61
static constexpr double pi
Definition: G4SIunits.hh:75
G4VViewer * GetCurrentViewer() const
static constexpr double halfpi
Definition: G4SIunits.hh:77
double G4double
Definition: G4Types.hh:76
CLHEP::Hep3Vector getTranslation() const
const XML_Char XML_Content * model
Definition: expat.h:151
void SetGlobalDescription(const G4String &)
G4Scene * GetCurrentScene() const
G4GLOB_DLL std::ostream G4cerr
static G4VisManager * fpVisManager

Here is the call graph for this function:


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