Geant4  10.02.p03
G4VisCommandSceneAddLogo Class Reference

#include <G4VisCommandsSceneAdd.hh>

Inheritance diagram for G4VisCommandSceneAddLogo:
Collaboration diagram for G4VisCommandSceneAddLogo:

Classes

struct  G4Logo
 

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
 

Private Types

enum  Direction {
  X, minusX, Y, minusY,
  Z, minusZ
}
 

Private Member Functions

 G4VisCommandSceneAddLogo (const G4VisCommandSceneAddLogo &)
 
G4VisCommandSceneAddLogooperator= (const G4VisCommandSceneAddLogo &)
 

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

Member Enumeration Documentation

◆ Direction

Constructor & Destructor Documentation

◆ G4VisCommandSceneAddLogo() [1/2]

G4VisCommandSceneAddLogo::G4VisCommandSceneAddLogo ( )

Definition at line 1254 of file G4VisCommandsSceneAdd.cc.

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

Definition at line 1304 of file G4VisCommandsSceneAdd.cc.

1304  {
1305  delete fpCommand;
1306 }

◆ G4VisCommandSceneAddLogo() [2/2]

G4VisCommandSceneAddLogo::G4VisCommandSceneAddLogo ( const G4VisCommandSceneAddLogo )
private

Member Function Documentation

◆ GetCurrentValue()

G4String G4VisCommandSceneAddLogo::GetCurrentValue ( G4UIcommand command)
virtual

Reimplemented from G4UImessenger.

Definition at line 1308 of file G4VisCommandsSceneAdd.cc.

1308  {
1309  return "";
1310 }

◆ operator=()

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

◆ SetNewValue()

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

Reimplemented from G4UImessenger.

Definition at line 1312 of file G4VisCommandsSceneAdd.cc.

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

Definition at line 292 of file G4VisCommandsSceneAdd.hh.


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