Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4VisCommandSceneAddLogo Class Reference

#include <G4VisCommandsSceneAdd.hh>

+ Inheritance 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)
 
virtual ~G4UImessenger ()
 
virtual G4String GetCurrentValue (G4UIcommand *command)
 
virtual void SetNewValue (G4UIcommand *command, G4String newValue)
 
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)
 
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 253 of file G4VisCommandsSceneAdd.hh.

Constructor & Destructor Documentation

◆ G4VisCommandSceneAddLogo()

G4VisCommandSceneAddLogo::G4VisCommandSceneAddLogo ( )

Definition at line 1191 of file G4VisCommandsSceneAdd.cc.

1191 {
1192 G4bool omitable;
1193 fpCommand = new G4UIcommand ("/vis/scene/add/logo", this);
1194 fpCommand -> SetGuidance ("Adds a G4 logo to the current scene.");
1195 G4UIparameter* parameter;
1196 parameter = new G4UIparameter ("height", 'd', omitable = true);
1197 parameter->SetDefaultValue (1.);
1198 fpCommand->SetParameter (parameter);
1199 parameter = new G4UIparameter ("unit", 's', omitable = true);
1200 parameter->SetGuidance
1201 ("auto or valid length unit - defaults to auto."
1202 "\nIf auto, height is roughly one tenth of scene extent.");
1203 parameter->SetDefaultValue ("auto");
1204 fpCommand->SetParameter (parameter);
1205 parameter = new G4UIparameter ("direction", 's', omitable = true);
1206 parameter->SetGuidance
1207 ("auto|[-]x|[-]y|[-]z - defaults to auto."
1208 "\nDirection of outward-facing normal to front face of logo."
1209 "\nIf automatic, logo faces the user in the current viewer.");
1210 parameter->SetDefaultValue ("auto");
1211 fpCommand->SetParameter (parameter);
1212 parameter = new G4UIparameter ("red", 'd', omitable = true);
1213 parameter->SetDefaultValue (0.);
1214 fpCommand->SetParameter (parameter);
1215 parameter = new G4UIparameter ("green", 'd', omitable = true);
1216 parameter->SetDefaultValue (1.);
1217 fpCommand->SetParameter (parameter);
1218 parameter = new G4UIparameter ("blue", 'd', omitable = true);
1219 parameter->SetDefaultValue (0.);
1220 fpCommand->SetParameter (parameter);
1221 parameter = new G4UIparameter ("auto|manual", 's', omitable = true);
1222 parameter->SetGuidance
1223 ("Automatic placement or manual placement at (xmid,ymid,zmid).");
1224 parameter->SetGuidance
1225 ("If automatic, placed at bottom right of screen when viewed from");
1226 parameter->SetGuidance
1227 ("logo direction.");
1228 parameter -> SetParameterCandidates("auto manual");
1229 parameter->SetDefaultValue ("auto");
1230 fpCommand->SetParameter (parameter);
1231 parameter = new G4UIparameter ("xmid", 'd', omitable = true);
1232 parameter->SetDefaultValue (0.);
1233 fpCommand->SetParameter (parameter);
1234 parameter = new G4UIparameter ("ymid", 'd', omitable = true);
1235 parameter->SetDefaultValue (0.);
1236 fpCommand->SetParameter (parameter);
1237 parameter = new G4UIparameter ("zmid", 'd', omitable = true);
1238 parameter->SetDefaultValue (0.);
1239 fpCommand->SetParameter (parameter);
1240 parameter = new G4UIparameter ("unit", 's', omitable = true);
1241 parameter->SetDefaultValue ("m");
1242 fpCommand->SetParameter (parameter);
1243}
bool G4bool
Definition: G4Types.hh:67
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:147
void SetDefaultValue(const char *theDefaultValue)
void SetGuidance(const char *theGuidance)

◆ ~G4VisCommandSceneAddLogo()

G4VisCommandSceneAddLogo::~G4VisCommandSceneAddLogo ( )
virtual

Definition at line 1245 of file G4VisCommandsSceneAdd.cc.

1245 {
1246 delete fpCommand;
1247}

Member Function Documentation

◆ GetCurrentValue()

G4String G4VisCommandSceneAddLogo::GetCurrentValue ( G4UIcommand command)
virtual

Reimplemented from G4UImessenger.

Definition at line 1249 of file G4VisCommandsSceneAdd.cc.

1249 {
1250 return "";
1251}

◆ SetNewValue()

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

Reimplemented from G4UImessenger.

Definition at line 1253 of file G4VisCommandsSceneAdd.cc.

1253 {
1254
1256 G4bool warn = verbosity >= G4VisManager::warnings;
1257
1259 if (!pScene) {
1260 if (verbosity >= G4VisManager::errors) {
1261 G4cout << "ERROR: No current scene. Please create one." << G4endl;
1262 }
1263 return;
1264 }
1265
1267 if (!pViewer) {
1268 if (verbosity >= G4VisManager::errors) {
1269 G4cout <<
1270 "ERROR: G4VisCommandSceneAddLogo::SetNewValue: no viewer."
1271 "\n Auto direction needs a viewer."
1272 << G4endl;
1273 }
1274 return;
1275 }
1276
1277 G4double userHeight, red, green, blue, xmid, ymid, zmid;
1278 G4String userHeightUnit, direction, auto_manual, positionUnit;
1279 std::istringstream is (newValue);
1280 is >> userHeight >> userHeightUnit >> direction
1281 >> red >> green >> blue
1282 >> auto_manual
1283 >> xmid >> ymid >> zmid >> positionUnit;
1284
1285 G4double height = userHeight;
1286 const G4VisExtent& sceneExtent = pScene->GetExtent(); // Existing extent.
1287 if (userHeightUnit == "auto") {
1288 height *= 0.2 * sceneExtent.GetExtentRadius();
1289 } else {
1290 height *= G4UIcommand::ValueOf(userHeightUnit);
1291 }
1292
1293 G4double unit = G4UIcommand::ValueOf(positionUnit);
1294 xmid *= unit; ymid *= unit; zmid *= unit;
1295
1296 Direction logoDirection = X; // Initialise to keep some compilers happy.
1297 if (direction == "auto") {
1298 // Take cue from viewer
1299 const G4Vector3D& vp =
1301 if (vp.x() > vp.y() && vp.x() > vp.z()) logoDirection = X;
1302 else if (vp.x() < vp.y() && vp.x() < vp.z()) logoDirection = minusX;
1303 else if (vp.y() > vp.x() && vp.y() > vp.z()) logoDirection = Y;
1304 else if (vp.y() < vp.x() && vp.y() < vp.z()) logoDirection = minusY;
1305 else if (vp.z() > vp.x() && vp.z() > vp.y()) logoDirection = Z;
1306 else if (vp.z() < vp.x() && vp.z() < vp.y()) logoDirection = minusZ;
1307 }
1308 else if (direction(0) == 'x') logoDirection = X;
1309 else if (direction(0) == 'y') logoDirection = Y;
1310 else if (direction(0) == 'z') logoDirection = Z;
1311 else if (direction(0) == '-') {
1312 if (direction(1) == 'x') logoDirection = minusX;
1313 else if (direction(1) == 'y') logoDirection = minusY;
1314 else if (direction(1) == 'z') logoDirection = minusZ;
1315 } else {
1316 if (verbosity >= G4VisManager::errors) {
1317 G4cout << "ERROR: Unrecogniseed direction: \""
1318 << direction << "\"." << G4endl;
1319 return;
1320 }
1321 }
1322
1323 G4bool autoPlacing = false; if (auto_manual == "auto") autoPlacing = true;
1324 // Parameters read and interpreted.
1325
1326 // Current scene extent
1327 const G4double xmin = sceneExtent.GetXmin();
1328 const G4double xmax = sceneExtent.GetXmax();
1329 const G4double ymin = sceneExtent.GetYmin();
1330 const G4double ymax = sceneExtent.GetYmax();
1331 const G4double zmin = sceneExtent.GetZmin();
1332 const G4double zmax = sceneExtent.GetZmax();
1333
1334 // Test existing extent and issue warnings...
1335 G4bool worried = false;
1336 if (sceneExtent.GetExtentRadius() == 0) {
1337 worried = true;
1338 if (verbosity >= G4VisManager::warnings) {
1339 G4cout <<
1340 "WARNING: Existing scene does not yet have any extent."
1341 "\n Maybe you have not yet added any geometrical object."
1342 << G4endl;
1343 }
1344 }
1345
1346 // Useful constants, etc...
1347 const G4double halfHeight(height / 2.);
1348 const G4double comfort(0.01); // 0.15 seems too big. 0.05 might be better.
1349 const G4double freeHeightFraction (1. + 2. * comfort);
1350
1351 // Test existing scene for room...
1352 G4bool room = true;
1353 switch (logoDirection) {
1354 case X:
1355 case minusX:
1356 if (freeHeightFraction * (xmax - xmin) < height) room = false; break;
1357 case Y:
1358 case minusY:
1359 if (freeHeightFraction * (ymax - ymin) < height) room = false; break;
1360 case Z:
1361 case minusZ:
1362 if (freeHeightFraction * (zmax - zmin) < height) room = false; break;
1363 }
1364 if (!room) {
1365 worried = true;
1366 if (verbosity >= G4VisManager::warnings) {
1367 G4cout <<
1368 "WARNING: Not enough room in existing scene. Maybe logo is too large."
1369 << G4endl;
1370 }
1371 }
1372 if (worried) {
1373 if (verbosity >= G4VisManager::warnings) {
1374 G4cout <<
1375 "WARNING: The logo you have asked for is bigger than the existing"
1376 "\n scene. Maybe you have added it too soon. It is recommended that"
1377 "\n you add the logo last so that it can be correctly auto-positioned"
1378 "\n so as not to be obscured by any existing object and so that the"
1379 "\n view parameters can be correctly recalculated."
1380 << G4endl;
1381 }
1382 }
1383
1384 G4double sxmid(xmid), symid(ymid), szmid(zmid);
1385 if (autoPlacing) {
1386 // Aim to place at bottom right of screen when viewed from logoDirection.
1387 // Give some comfort zone.
1388 const G4double xComfort = comfort * (xmax - xmin);
1389 const G4double yComfort = comfort * (ymax - ymin);
1390 const G4double zComfort = comfort * (zmax - zmin);
1391 switch (logoDirection) {
1392 case X: // y-axis up, z-axis to left?
1393 sxmid = xmax + halfHeight + xComfort;
1394 symid = ymin - yComfort;
1395 szmid = zmin - zComfort;
1396 break;
1397 case minusX: // y-axis up, z-axis to right?
1398 sxmid = xmin - halfHeight - xComfort;
1399 symid = ymin - yComfort;
1400 szmid = zmax + zComfort;
1401 break;
1402 case Y: // z-axis up, x-axis to left?
1403 sxmid = xmin - xComfort;
1404 symid = ymax + halfHeight + yComfort;
1405 szmid = zmin - zComfort;
1406 break;
1407 case minusY: // z-axis up, x-axis to right?
1408 sxmid = xmax + xComfort;
1409 symid = ymin - halfHeight - yComfort;
1410 szmid = zmin - zComfort;
1411 break;
1412 case Z: // y-axis up, x-axis to right?
1413 sxmid = xmax + xComfort;
1414 symid = ymin - yComfort;
1415 szmid = zmax + halfHeight + zComfort;
1416 break;
1417 case minusZ: // y-axis up, x-axis to left?
1418 sxmid = xmin - xComfort;
1419 symid = ymin - yComfort;
1420 szmid = zmin - halfHeight - zComfort;
1421 break;
1422 }
1423 }
1424
1425 G4Transform3D transform;
1426 switch (logoDirection) {
1427 case X: // y-axis up, z-axis to left?
1428 transform = G4RotateY3D(halfpi);
1429 break;
1430 case minusX: // y-axis up, z-axis to right?
1431 transform = G4RotateY3D(-halfpi);
1432 break;
1433 case Y: // z-axis up, x-axis to left?
1434 transform = G4RotateX3D(-halfpi) * G4RotateZ3D(pi);
1435 break;
1436 case minusY: // z-axis up, x-axis to right?
1437 transform = G4RotateX3D(halfpi);
1438 break;
1439 case Z: // y-axis up, x-axis to right?
1440 // No transformation required.
1441 break;
1442 case minusZ: // y-axis up, x-axis to left?
1443 transform = G4RotateY3D(pi);
1444 break;
1445 }
1446 transform = G4Translate3D(sxmid,symid,szmid) * transform;
1447
1448 G4VisAttributes visAtts(G4Colour(red, green, blue));
1449 visAtts.SetForceSolid(true); // Always solid.
1450
1451 G4Logo* logo = new G4Logo(height,visAtts);
1452 G4VModel* model =
1454 model->SetType("G4Logo");
1455 model->SetGlobalTag("G4Logo");
1456 model->SetGlobalDescription("G4Logo: " + newValue);
1457 model->SetTransformation(transform);
1458 // Note: it is the responsibility of the model to act upon this, but
1459 // the extent is in local coordinates...
1460 G4double& h = height;
1461 G4double h2 = h/2.;
1462 G4VisExtent extent(-h,h,-h2,h2,-h2,h2);
1463 model->SetExtent(extent);
1464 // This extent gets "added" to existing scene extent in
1465 // AddRunDurationModel below.
1466 const G4String& currentSceneName = pScene -> GetName ();
1467 G4bool successful = pScene -> AddRunDurationModel (model, warn);
1468 if (successful) {
1469 if (verbosity >= G4VisManager::confirmations) {
1470 G4cout << "G4 Logo of height " << userHeight << ' ' << userHeightUnit
1471 << ", " << direction << "-direction, added to scene \""
1472 << currentSceneName << "\"";
1473 if (verbosity >= G4VisManager::parameters) {
1474 G4cout << "\n with extent " << extent
1475 << "\n at " << transform.getRotation()
1476 << transform.getTranslation();
1477 }
1478 G4cout << G4endl;
1479 }
1480 }
1481 else G4VisCommandsSceneAddUnsuccessful(verbosity);
1482 UpdateVisManagerScene (currentSceneName);
1483}
HepGeom::RotateZ3D G4RotateZ3D
HepGeom::Translate3D G4Translate3D
HepGeom::RotateX3D G4RotateX3D
HepGeom::RotateY3D G4RotateY3D
double G4double
Definition: G4Types.hh:64
#define G4endl
Definition: G4ios.hh:52
G4DLLIMPORT std::ostream G4cout
const G4VisExtent & GetExtent() const
static G4double ValueOf(const char *unitName)
Definition: G4UIcommand.cc:288
void SetType(const G4String &)
void SetGlobalDescription(const G4String &)
void SetGlobalTag(const G4String &)
void SetExtent(const G4VisExtent &)
void SetTransformation(const G4Transform3D &)
const G4ViewParameters & GetViewParameters() const
static G4VisManager * fpVisManager
void UpdateVisManagerScene(const G4String &sceneName="")
const G4Vector3D & GetViewpointDirection() const
G4double GetYmin() const
Definition: G4VisExtent.hh:91
G4double GetXmax() const
Definition: G4VisExtent.hh:90
G4double GetExtentRadius() const
Definition: G4VisExtent.cc:73
G4double GetYmax() const
Definition: G4VisExtent.hh:92
G4double GetZmax() const
Definition: G4VisExtent.hh:94
G4double GetZmin() const
Definition: G4VisExtent.hh:93
G4double GetXmin() const
Definition: G4VisExtent.hh:89
G4Scene * GetCurrentScene() const
G4VViewer * GetCurrentViewer() const
static Verbosity GetVerbosity()
CLHEP::HepRotation getRotation() const
CLHEP::Hep3Vector getTranslation() const

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