Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Data Structures | Public Member Functions
G4VisCommandSceneAddLogo Class Reference

#include <G4VisCommandsSceneAdd.hh>

Inheritance diagram for G4VisCommandSceneAddLogo:
G4VVisCommandScene G4VVisCommand G4UImessenger

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
 

Additional Inherited Members

- Static Public Member Functions inherited from G4VVisCommand
static void SetVisManager (G4VisManager *)
 
- 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
 
- Static Protected Attributes inherited from G4VVisCommand
static G4VisManagerfpVisManager = 0
 
static G4Colour fCurrentColour = G4Colour::White()
 
static G4Colour fCurrentTextColour = G4Colour::Blue()
 
static G4Text::Layout fCurrentTextLayout = G4Text::left
 
static G4double fCurrentLineWidth = 1.
 
static
G4ModelingParameters::PVNameCopyNoPath 
fCurrentTouchablePath
 

Detailed Description

Definition at line 254 of file G4VisCommandsSceneAdd.hh.

Constructor & Destructor Documentation

G4VisCommandSceneAddLogo::G4VisCommandSceneAddLogo ( )

Definition at line 1072 of file G4VisCommandsSceneAdd.cc.

References G4UIparameter::SetDefaultValue(), G4UIparameter::SetGuidance(), and G4UIcommand::SetParameter().

1072  {
1073  G4bool omitable;
1074  fpCommand = new G4UIcommand ("/vis/scene/add/logo", this);
1075  fpCommand -> SetGuidance ("Adds a G4 logo to the current scene.");
1076  fpCommand -> SetGuidance
1077  ("If \"unit\" is \"auto\", height is roughly one tenth of scene extent.");
1078  fpCommand -> SetGuidance
1079  ("\"direction\" is that of outward-facing normal to front face of logo."
1080  "\nIf \"direction\" is \"auto\", logo faces the user in the current viewer.");
1081  fpCommand -> SetGuidance
1082  ("\nIf \"placement\" is \"auto\", logo is placed at bottom right of screen"
1083  "\n when viewed from logo direction.");
1084  G4UIparameter* parameter;
1085  parameter = new G4UIparameter ("height", 'd', omitable = true);
1086  parameter->SetDefaultValue (1.);
1087  fpCommand->SetParameter (parameter);
1088  parameter = new G4UIparameter ("unit", 's', omitable = true);
1089  parameter->SetDefaultValue ("auto");
1090  fpCommand->SetParameter (parameter);
1091  parameter = new G4UIparameter ("direction", 's', omitable = true);
1092  parameter->SetGuidance ("auto|[-]x|[-]y|[-]z");
1093  parameter->SetDefaultValue ("auto");
1094  fpCommand->SetParameter (parameter);
1095  parameter = new G4UIparameter ("red", 'd', omitable = true);
1096  parameter->SetDefaultValue (0.);
1097  fpCommand->SetParameter (parameter);
1098  parameter = new G4UIparameter ("green", 'd', omitable = true);
1099  parameter->SetDefaultValue (1.);
1100  fpCommand->SetParameter (parameter);
1101  parameter = new G4UIparameter ("blue", 'd', omitable = true);
1102  parameter->SetDefaultValue (0.);
1103  fpCommand->SetParameter (parameter);
1104  parameter = new G4UIparameter ("placement", 's', omitable = true);
1105  parameter -> SetParameterCandidates("auto manual");
1106  parameter->SetDefaultValue ("auto");
1107  fpCommand->SetParameter (parameter);
1108  parameter = new G4UIparameter ("xmid", 'd', omitable = true);
1109  parameter->SetDefaultValue (0.);
1110  fpCommand->SetParameter (parameter);
1111  parameter = new G4UIparameter ("ymid", 'd', omitable = true);
1112  parameter->SetDefaultValue (0.);
1113  fpCommand->SetParameter (parameter);
1114  parameter = new G4UIparameter ("zmid", 'd', omitable = true);
1115  parameter->SetDefaultValue (0.);
1116  fpCommand->SetParameter (parameter);
1117  parameter = new G4UIparameter ("unit", 's', omitable = true);
1118  parameter->SetDefaultValue ("m");
1119  fpCommand->SetParameter (parameter);
1120 }
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)
G4VisCommandSceneAddLogo::~G4VisCommandSceneAddLogo ( )
virtual

Definition at line 1122 of file G4VisCommandsSceneAdd.cc.

1122  {
1123  delete fpCommand;
1124 }

Member Function Documentation

G4String G4VisCommandSceneAddLogo::GetCurrentValue ( G4UIcommand command)
virtual

Reimplemented from G4UImessenger.

Definition at line 1126 of file G4VisCommandsSceneAdd.cc.

1126  {
1127  return "";
1128 }
void G4VisCommandSceneAddLogo::SetNewValue ( G4UIcommand command,
G4String  newValue 
)
virtual

Reimplemented from G4UImessenger.

Definition at line 1130 of file G4VisCommandsSceneAdd.cc.

References blue, G4VisManager::confirmations, G4VisManager::errors, G4VVisCommand::fpVisManager, G4cout, G4endl, G4VisManager::GetCurrentScene(), G4VisManager::GetCurrentViewer(), G4Scene::GetExtent(), G4VisExtent::GetExtentRadius(), HepGeom::Transform3D::getRotation(), HepGeom::Transform3D::getTranslation(), G4VisManager::GetVerbosity(), G4VViewer::GetViewParameters(), G4ViewParameters::GetViewpointDirection(), G4VisExtent::GetXmax(), G4VisExtent::GetXmin(), G4VisExtent::GetYmax(), G4VisExtent::GetYmin(), G4VisExtent::GetZmax(), G4VisExtent::GetZmin(), python.hepunit::halfpi, G4VisManager::parameters, python.hepunit::pi, red, G4VModel::SetExtent(), G4VisAttributes::SetForceSolid(), G4VModel::SetGlobalDescription(), G4VModel::SetGlobalTag(), G4VModel::SetTransformation(), G4VModel::SetType(), G4VVisCommand::UpdateVisManagerScene(), G4UIcommand::ValueOf(), G4VisManager::warnings, HepGeom::BasicVector3D< T >::x(), HepGeom::BasicVector3D< T >::y(), and HepGeom::BasicVector3D< T >::z().

1130  {
1131 
1133  G4bool warn = verbosity >= G4VisManager::warnings;
1134 
1135  G4Scene* pScene = fpVisManager->GetCurrentScene();
1136  if (!pScene) {
1137  if (verbosity >= G4VisManager::errors) {
1138  G4cout << "ERROR: No current scene. Please create one." << G4endl;
1139  }
1140  return;
1141  }
1142 
1143  G4VViewer* pViewer = fpVisManager->GetCurrentViewer();
1144  if (!pViewer) {
1145  if (verbosity >= G4VisManager::errors) {
1146  G4cout <<
1147  "ERROR: G4VisCommandSceneAddLogo::SetNewValue: no viewer."
1148  "\n Auto direction needs a viewer."
1149  << G4endl;
1150  }
1151  return;
1152  }
1153 
1154  G4double userHeight, red, green, blue, xmid, ymid, zmid;
1155  G4String userHeightUnit, direction, auto_manual, positionUnit;
1156  std::istringstream is (newValue);
1157  is >> userHeight >> userHeightUnit >> direction
1158  >> red >> green >> blue
1159  >> auto_manual
1160  >> xmid >> ymid >> zmid >> positionUnit;
1161 
1162  G4double height = userHeight;
1163  const G4VisExtent& sceneExtent = pScene->GetExtent(); // Existing extent.
1164  if (userHeightUnit == "auto") {
1165  height *= 0.2 * sceneExtent.GetExtentRadius();
1166  } else {
1167  height *= G4UIcommand::ValueOf(userHeightUnit);
1168  }
1169 
1170  G4double unit = G4UIcommand::ValueOf(positionUnit);
1171  xmid *= unit; ymid *= unit; zmid *= unit;
1172 
1173  Direction logoDirection = X; // Initialise to keep some compilers happy.
1174  if (direction == "auto") {
1175  // Take cue from viewer
1176  const G4Vector3D& vp =
1178  if (vp.x() > vp.y() && vp.x() > vp.z()) logoDirection = X;
1179  else if (vp.x() < vp.y() && vp.x() < vp.z()) logoDirection = minusX;
1180  else if (vp.y() > vp.x() && vp.y() > vp.z()) logoDirection = Y;
1181  else if (vp.y() < vp.x() && vp.y() < vp.z()) logoDirection = minusY;
1182  else if (vp.z() > vp.x() && vp.z() > vp.y()) logoDirection = Z;
1183  else if (vp.z() < vp.x() && vp.z() < vp.y()) logoDirection = minusZ;
1184  }
1185  else if (direction(0) == 'x') logoDirection = X;
1186  else if (direction(0) == 'y') logoDirection = Y;
1187  else if (direction(0) == 'z') logoDirection = Z;
1188  else if (direction(0) == '-') {
1189  if (direction(1) == 'x') logoDirection = minusX;
1190  else if (direction(1) == 'y') logoDirection = minusY;
1191  else if (direction(1) == 'z') logoDirection = minusZ;
1192  } else {
1193  if (verbosity >= G4VisManager::errors) {
1194  G4cout << "ERROR: Unrecogniseed direction: \""
1195  << direction << "\"." << G4endl;
1196  return;
1197  }
1198  }
1199 
1200  G4bool autoPlacing = false; if (auto_manual == "auto") autoPlacing = true;
1201  // Parameters read and interpreted.
1202 
1203  // Current scene extent
1204  const G4double xmin = sceneExtent.GetXmin();
1205  const G4double xmax = sceneExtent.GetXmax();
1206  const G4double ymin = sceneExtent.GetYmin();
1207  const G4double ymax = sceneExtent.GetYmax();
1208  const G4double zmin = sceneExtent.GetZmin();
1209  const G4double zmax = sceneExtent.GetZmax();
1210 
1211  // Test existing extent and issue warnings...
1212  G4bool worried = false;
1213  if (sceneExtent.GetExtentRadius() == 0) {
1214  worried = true;
1215  if (verbosity >= G4VisManager::warnings) {
1216  G4cout <<
1217  "WARNING: Existing scene does not yet have any extent."
1218  "\n Maybe you have not yet added any geometrical object."
1219  << G4endl;
1220  }
1221  }
1222 
1223  // Useful constants, etc...
1224  const G4double halfHeight(height / 2.);
1225  const G4double comfort(0.01); // 0.15 seems too big. 0.05 might be better.
1226  const G4double freeHeightFraction (1. + 2. * comfort);
1227 
1228  // Test existing scene for room...
1229  G4bool room = true;
1230  switch (logoDirection) {
1231  case X:
1232  case minusX:
1233  if (freeHeightFraction * (xmax - xmin) < height) room = false; break;
1234  case Y:
1235  case minusY:
1236  if (freeHeightFraction * (ymax - ymin) < height) room = false; break;
1237  case Z:
1238  case minusZ:
1239  if (freeHeightFraction * (zmax - zmin) < height) room = false; break;
1240  }
1241  if (!room) {
1242  worried = true;
1243  if (verbosity >= G4VisManager::warnings) {
1244  G4cout <<
1245  "WARNING: Not enough room in existing scene. Maybe logo is too large."
1246  << G4endl;
1247  }
1248  }
1249  if (worried) {
1250  if (verbosity >= G4VisManager::warnings) {
1251  G4cout <<
1252  "WARNING: The logo you have asked for is bigger than the existing"
1253  "\n scene. Maybe you have added it too soon. It is recommended that"
1254  "\n you add the logo last so that it can be correctly auto-positioned"
1255  "\n so as not to be obscured by any existing object and so that the"
1256  "\n view parameters can be correctly recalculated."
1257  << G4endl;
1258  }
1259  }
1260 
1261  G4double sxmid(xmid), symid(ymid), szmid(zmid);
1262  if (autoPlacing) {
1263  // Aim to place at bottom right of screen when viewed from logoDirection.
1264  // Give some comfort zone.
1265  const G4double xComfort = comfort * (xmax - xmin);
1266  const G4double yComfort = comfort * (ymax - ymin);
1267  const G4double zComfort = comfort * (zmax - zmin);
1268  switch (logoDirection) {
1269  case X: // y-axis up, z-axis to left?
1270  sxmid = xmax + halfHeight + xComfort;
1271  symid = ymin - yComfort;
1272  szmid = zmin - zComfort;
1273  break;
1274  case minusX: // y-axis up, z-axis to right?
1275  sxmid = xmin - halfHeight - xComfort;
1276  symid = ymin - yComfort;
1277  szmid = zmax + zComfort;
1278  break;
1279  case Y: // z-axis up, x-axis to left?
1280  sxmid = xmin - xComfort;
1281  symid = ymax + halfHeight + yComfort;
1282  szmid = zmin - zComfort;
1283  break;
1284  case minusY: // z-axis up, x-axis to right?
1285  sxmid = xmax + xComfort;
1286  symid = ymin - halfHeight - yComfort;
1287  szmid = zmin - zComfort;
1288  break;
1289  case Z: // y-axis up, x-axis to right?
1290  sxmid = xmax + xComfort;
1291  symid = ymin - yComfort;
1292  szmid = zmax + halfHeight + zComfort;
1293  break;
1294  case minusZ: // y-axis up, x-axis to left?
1295  sxmid = xmin - xComfort;
1296  symid = ymin - yComfort;
1297  szmid = zmin - halfHeight - zComfort;
1298  break;
1299  }
1300  }
1301 
1302  G4Transform3D transform;
1303  switch (logoDirection) {
1304  case X: // y-axis up, z-axis to left?
1305  transform = G4RotateY3D(halfpi);
1306  break;
1307  case minusX: // y-axis up, z-axis to right?
1308  transform = G4RotateY3D(-halfpi);
1309  break;
1310  case Y: // z-axis up, x-axis to left?
1311  transform = G4RotateX3D(-halfpi) * G4RotateZ3D(pi);
1312  break;
1313  case minusY: // z-axis up, x-axis to right?
1314  transform = G4RotateX3D(halfpi);
1315  break;
1316  case Z: // y-axis up, x-axis to right?
1317  // No transformation required.
1318  break;
1319  case minusZ: // y-axis up, x-axis to left?
1320  transform = G4RotateY3D(pi);
1321  break;
1322  }
1323  transform = G4Translate3D(sxmid,symid,szmid) * transform;
1324 
1325  G4VisAttributes visAtts(G4Colour(red, green, blue));
1326  visAtts.SetForceSolid(true); // Always solid.
1327 
1328  G4Logo* logo = new G4Logo(height,visAtts);
1329  G4VModel* model =
1331  model->SetType("G4Logo");
1332  model->SetGlobalTag("G4Logo");
1333  model->SetGlobalDescription("G4Logo: " + newValue);
1334  model->SetTransformation(transform);
1335  // Note: it is the responsibility of the model to act upon this, but
1336  // the extent is in local coordinates...
1337  G4double& h = height;
1338  G4double h2 = h/2.;
1339  G4VisExtent extent(-h,h,-h2,h2,-h2,h2);
1340  model->SetExtent(extent);
1341  // This extent gets "added" to existing scene extent in
1342  // AddRunDurationModel below.
1343  const G4String& currentSceneName = pScene -> GetName ();
1344  G4bool successful = pScene -> AddRunDurationModel (model, warn);
1345  if (successful) {
1346  if (verbosity >= G4VisManager::confirmations) {
1347  G4cout << "G4 Logo of height " << userHeight << ' ' << userHeightUnit
1348  << ", " << direction << "-direction, added to scene \""
1349  << currentSceneName << "\"";
1350  if (verbosity >= G4VisManager::parameters) {
1351  G4cout << "\n with extent " << extent
1352  << "\n at " << transform.getRotation()
1353  << transform.getTranslation();
1354  }
1355  G4cout << G4endl;
1356  }
1357  }
1358  else G4VisCommandsSceneAddUnsuccessful(verbosity);
1359  UpdateVisManagerScene (currentSceneName);
1360 }
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 &)
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 &)
const XML_Char XML_Content * model
G4double GetZmax() const
Definition: G4VisExtent.hh:94
static G4double ValueOf(const char *unitName)
Definition: G4UIcommand.cc:294
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
G4VViewer * GetCurrentViewer() const
double G4double
Definition: G4Types.hh:76
CLHEP::Hep3Vector getTranslation() const
void SetGlobalDescription(const G4String &)
G4Scene * GetCurrentScene() const
static G4VisManager * fpVisManager

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