#include <G4VisCommandsSceneAdd.hh>
Inheritance diagram for G4VisCommandSceneAddLogo:
Public Member Functions | |
G4VisCommandSceneAddLogo () | |
virtual | ~G4VisCommandSceneAddLogo () |
G4String | GetCurrentValue (G4UIcommand *command) |
void | SetNewValue (G4UIcommand *command, G4String newValue) |
Data Structures | |
struct | G4Logo |
Definition at line 253 of file G4VisCommandsSceneAdd.hh.
G4VisCommandSceneAddLogo::G4VisCommandSceneAddLogo | ( | ) |
Definition at line 1191 of file G4VisCommandsSceneAdd.cc.
References G4UIparameter::SetDefaultValue(), G4UIparameter::SetGuidance(), and G4UIcommand::SetParameter().
01191 { 01192 G4bool omitable; 01193 fpCommand = new G4UIcommand ("/vis/scene/add/logo", this); 01194 fpCommand -> SetGuidance ("Adds a G4 logo to the current scene."); 01195 G4UIparameter* parameter; 01196 parameter = new G4UIparameter ("height", 'd', omitable = true); 01197 parameter->SetDefaultValue (1.); 01198 fpCommand->SetParameter (parameter); 01199 parameter = new G4UIparameter ("unit", 's', omitable = true); 01200 parameter->SetGuidance 01201 ("auto or valid length unit - defaults to auto." 01202 "\nIf auto, height is roughly one tenth of scene extent."); 01203 parameter->SetDefaultValue ("auto"); 01204 fpCommand->SetParameter (parameter); 01205 parameter = new G4UIparameter ("direction", 's', omitable = true); 01206 parameter->SetGuidance 01207 ("auto|[-]x|[-]y|[-]z - defaults to auto." 01208 "\nDirection of outward-facing normal to front face of logo." 01209 "\nIf automatic, logo faces the user in the current viewer."); 01210 parameter->SetDefaultValue ("auto"); 01211 fpCommand->SetParameter (parameter); 01212 parameter = new G4UIparameter ("red", 'd', omitable = true); 01213 parameter->SetDefaultValue (0.); 01214 fpCommand->SetParameter (parameter); 01215 parameter = new G4UIparameter ("green", 'd', omitable = true); 01216 parameter->SetDefaultValue (1.); 01217 fpCommand->SetParameter (parameter); 01218 parameter = new G4UIparameter ("blue", 'd', omitable = true); 01219 parameter->SetDefaultValue (0.); 01220 fpCommand->SetParameter (parameter); 01221 parameter = new G4UIparameter ("auto|manual", 's', omitable = true); 01222 parameter->SetGuidance 01223 ("Automatic placement or manual placement at (xmid,ymid,zmid)."); 01224 parameter->SetGuidance 01225 ("If automatic, placed at bottom right of screen when viewed from"); 01226 parameter->SetGuidance 01227 ("logo direction."); 01228 parameter -> SetParameterCandidates("auto manual"); 01229 parameter->SetDefaultValue ("auto"); 01230 fpCommand->SetParameter (parameter); 01231 parameter = new G4UIparameter ("xmid", 'd', omitable = true); 01232 parameter->SetDefaultValue (0.); 01233 fpCommand->SetParameter (parameter); 01234 parameter = new G4UIparameter ("ymid", 'd', omitable = true); 01235 parameter->SetDefaultValue (0.); 01236 fpCommand->SetParameter (parameter); 01237 parameter = new G4UIparameter ("zmid", 'd', omitable = true); 01238 parameter->SetDefaultValue (0.); 01239 fpCommand->SetParameter (parameter); 01240 parameter = new G4UIparameter ("unit", 's', omitable = true); 01241 parameter->SetDefaultValue ("m"); 01242 fpCommand->SetParameter (parameter); 01243 }
G4VisCommandSceneAddLogo::~G4VisCommandSceneAddLogo | ( | ) | [virtual] |
G4String G4VisCommandSceneAddLogo::GetCurrentValue | ( | G4UIcommand * | command | ) | [virtual] |
void G4VisCommandSceneAddLogo::SetNewValue | ( | G4UIcommand * | command, | |
G4String | newValue | |||
) | [virtual] |
Reimplemented from G4UImessenger.
Definition at line 1253 of file G4VisCommandsSceneAdd.cc.
References G4VisManager::confirmations, G4VisManager::errors, G4VVisCommand::fpVisManager, G4cout, G4endl, G4VisManager::GetCurrentScene(), G4VisManager::GetCurrentViewer(), G4Scene::GetExtent(), G4VisExtent::GetExtentRadius(), G4VisManager::GetVerbosity(), G4VViewer::GetViewParameters(), G4ViewParameters::GetViewpointDirection(), G4VisExtent::GetXmax(), G4VisExtent::GetXmin(), G4VisExtent::GetYmax(), G4VisExtent::GetYmin(), G4VisExtent::GetZmax(), G4VisExtent::GetZmin(), G4VisManager::parameters, G4INCL::Math::pi, G4VModel::SetExtent(), G4VisAttributes::SetForceSolid(), G4VModel::SetGlobalDescription(), G4VModel::SetGlobalTag(), G4VModel::SetTransformation(), G4VModel::SetType(), G4VVisCommand::UpdateVisManagerScene(), G4UIcommand::ValueOf(), and G4VisManager::warnings.
01253 { 01254 01255 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); 01256 G4bool warn = verbosity >= G4VisManager::warnings; 01257 01258 G4Scene* pScene = fpVisManager->GetCurrentScene(); 01259 if (!pScene) { 01260 if (verbosity >= G4VisManager::errors) { 01261 G4cout << "ERROR: No current scene. Please create one." << G4endl; 01262 } 01263 return; 01264 } 01265 01266 G4VViewer* pViewer = fpVisManager->GetCurrentViewer(); 01267 if (!pViewer) { 01268 if (verbosity >= G4VisManager::errors) { 01269 G4cout << 01270 "ERROR: G4VisCommandSceneAddLogo::SetNewValue: no viewer." 01271 "\n Auto direction needs a viewer." 01272 << G4endl; 01273 } 01274 return; 01275 } 01276 01277 G4double userHeight, red, green, blue, xmid, ymid, zmid; 01278 G4String userHeightUnit, direction, auto_manual, positionUnit; 01279 std::istringstream is (newValue); 01280 is >> userHeight >> userHeightUnit >> direction 01281 >> red >> green >> blue 01282 >> auto_manual 01283 >> xmid >> ymid >> zmid >> positionUnit; 01284 01285 G4double height = userHeight; 01286 const G4VisExtent& sceneExtent = pScene->GetExtent(); // Existing extent. 01287 if (userHeightUnit == "auto") { 01288 height *= 0.2 * sceneExtent.GetExtentRadius(); 01289 } else { 01290 height *= G4UIcommand::ValueOf(userHeightUnit); 01291 } 01292 01293 G4double unit = G4UIcommand::ValueOf(positionUnit); 01294 xmid *= unit; ymid *= unit; zmid *= unit; 01295 01296 Direction logoDirection = X; // Initialise to keep some compilers happy. 01297 if (direction == "auto") { 01298 // Take cue from viewer 01299 const G4Vector3D& vp = 01300 pViewer->GetViewParameters().GetViewpointDirection(); 01301 if (vp.x() > vp.y() && vp.x() > vp.z()) logoDirection = X; 01302 else if (vp.x() < vp.y() && vp.x() < vp.z()) logoDirection = minusX; 01303 else if (vp.y() > vp.x() && vp.y() > vp.z()) logoDirection = Y; 01304 else if (vp.y() < vp.x() && vp.y() < vp.z()) logoDirection = minusY; 01305 else if (vp.z() > vp.x() && vp.z() > vp.y()) logoDirection = Z; 01306 else if (vp.z() < vp.x() && vp.z() < vp.y()) logoDirection = minusZ; 01307 } 01308 else if (direction(0) == 'x') logoDirection = X; 01309 else if (direction(0) == 'y') logoDirection = Y; 01310 else if (direction(0) == 'z') logoDirection = Z; 01311 else if (direction(0) == '-') { 01312 if (direction(1) == 'x') logoDirection = minusX; 01313 else if (direction(1) == 'y') logoDirection = minusY; 01314 else if (direction(1) == 'z') logoDirection = minusZ; 01315 } else { 01316 if (verbosity >= G4VisManager::errors) { 01317 G4cout << "ERROR: Unrecogniseed direction: \"" 01318 << direction << "\"." << G4endl; 01319 return; 01320 } 01321 } 01322 01323 G4bool autoPlacing = false; if (auto_manual == "auto") autoPlacing = true; 01324 // Parameters read and interpreted. 01325 01326 // Current scene extent 01327 const G4double xmin = sceneExtent.GetXmin(); 01328 const G4double xmax = sceneExtent.GetXmax(); 01329 const G4double ymin = sceneExtent.GetYmin(); 01330 const G4double ymax = sceneExtent.GetYmax(); 01331 const G4double zmin = sceneExtent.GetZmin(); 01332 const G4double zmax = sceneExtent.GetZmax(); 01333 01334 // Test existing extent and issue warnings... 01335 G4bool worried = false; 01336 if (sceneExtent.GetExtentRadius() == 0) { 01337 worried = true; 01338 if (verbosity >= G4VisManager::warnings) { 01339 G4cout << 01340 "WARNING: Existing scene does not yet have any extent." 01341 "\n Maybe you have not yet added any geometrical object." 01342 << G4endl; 01343 } 01344 } 01345 01346 // Useful constants, etc... 01347 const G4double halfHeight(height / 2.); 01348 const G4double comfort(0.01); // 0.15 seems too big. 0.05 might be better. 01349 const G4double freeHeightFraction (1. + 2. * comfort); 01350 01351 // Test existing scene for room... 01352 G4bool room = true; 01353 switch (logoDirection) { 01354 case X: 01355 case minusX: 01356 if (freeHeightFraction * (xmax - xmin) < height) room = false; break; 01357 case Y: 01358 case minusY: 01359 if (freeHeightFraction * (ymax - ymin) < height) room = false; break; 01360 case Z: 01361 case minusZ: 01362 if (freeHeightFraction * (zmax - zmin) < height) room = false; break; 01363 } 01364 if (!room) { 01365 worried = true; 01366 if (verbosity >= G4VisManager::warnings) { 01367 G4cout << 01368 "WARNING: Not enough room in existing scene. Maybe logo is too large." 01369 << G4endl; 01370 } 01371 } 01372 if (worried) { 01373 if (verbosity >= G4VisManager::warnings) { 01374 G4cout << 01375 "WARNING: The logo you have asked for is bigger than the existing" 01376 "\n scene. Maybe you have added it too soon. It is recommended that" 01377 "\n you add the logo last so that it can be correctly auto-positioned" 01378 "\n so as not to be obscured by any existing object and so that the" 01379 "\n view parameters can be correctly recalculated." 01380 << G4endl; 01381 } 01382 } 01383 01384 G4double sxmid(xmid), symid(ymid), szmid(zmid); 01385 if (autoPlacing) { 01386 // Aim to place at bottom right of screen when viewed from logoDirection. 01387 // Give some comfort zone. 01388 const G4double xComfort = comfort * (xmax - xmin); 01389 const G4double yComfort = comfort * (ymax - ymin); 01390 const G4double zComfort = comfort * (zmax - zmin); 01391 switch (logoDirection) { 01392 case X: // y-axis up, z-axis to left? 01393 sxmid = xmax + halfHeight + xComfort; 01394 symid = ymin - yComfort; 01395 szmid = zmin - zComfort; 01396 break; 01397 case minusX: // y-axis up, z-axis to right? 01398 sxmid = xmin - halfHeight - xComfort; 01399 symid = ymin - yComfort; 01400 szmid = zmax + zComfort; 01401 break; 01402 case Y: // z-axis up, x-axis to left? 01403 sxmid = xmin - xComfort; 01404 symid = ymax + halfHeight + yComfort; 01405 szmid = zmin - zComfort; 01406 break; 01407 case minusY: // z-axis up, x-axis to right? 01408 sxmid = xmax + xComfort; 01409 symid = ymin - halfHeight - yComfort; 01410 szmid = zmin - zComfort; 01411 break; 01412 case Z: // y-axis up, x-axis to right? 01413 sxmid = xmax + xComfort; 01414 symid = ymin - yComfort; 01415 szmid = zmax + halfHeight + zComfort; 01416 break; 01417 case minusZ: // y-axis up, x-axis to left? 01418 sxmid = xmin - xComfort; 01419 symid = ymin - yComfort; 01420 szmid = zmin - halfHeight - zComfort; 01421 break; 01422 } 01423 } 01424 01425 G4Transform3D transform; 01426 switch (logoDirection) { 01427 case X: // y-axis up, z-axis to left? 01428 transform = G4RotateY3D(halfpi); 01429 break; 01430 case minusX: // y-axis up, z-axis to right? 01431 transform = G4RotateY3D(-halfpi); 01432 break; 01433 case Y: // z-axis up, x-axis to left? 01434 transform = G4RotateX3D(-halfpi) * G4RotateZ3D(pi); 01435 break; 01436 case minusY: // z-axis up, x-axis to right? 01437 transform = G4RotateX3D(halfpi); 01438 break; 01439 case Z: // y-axis up, x-axis to right? 01440 // No transformation required. 01441 break; 01442 case minusZ: // y-axis up, x-axis to left? 01443 transform = G4RotateY3D(pi); 01444 break; 01445 } 01446 transform = G4Translate3D(sxmid,symid,szmid) * transform; 01447 01448 G4VisAttributes visAtts(G4Colour(red, green, blue)); 01449 visAtts.SetForceSolid(true); // Always solid. 01450 01451 G4Logo* logo = new G4Logo(height,visAtts); 01452 G4VModel* model = 01453 new G4CallbackModel<G4VisCommandSceneAddLogo::G4Logo>(logo); 01454 model->SetType("G4Logo"); 01455 model->SetGlobalTag("G4Logo"); 01456 model->SetGlobalDescription("G4Logo: " + newValue); 01457 model->SetTransformation(transform); 01458 // Note: it is the responsibility of the model to act upon this, but 01459 // the extent is in local coordinates... 01460 G4double& h = height; 01461 G4double h2 = h/2.; 01462 G4VisExtent extent(-h,h,-h2,h2,-h2,h2); 01463 model->SetExtent(extent); 01464 // This extent gets "added" to existing scene extent in 01465 // AddRunDurationModel below. 01466 const G4String& currentSceneName = pScene -> GetName (); 01467 G4bool successful = pScene -> AddRunDurationModel (model, warn); 01468 if (successful) { 01469 if (verbosity >= G4VisManager::confirmations) { 01470 G4cout << "G4 Logo of height " << userHeight << ' ' << userHeightUnit 01471 << ", " << direction << "-direction, added to scene \"" 01472 << currentSceneName << "\""; 01473 if (verbosity >= G4VisManager::parameters) { 01474 G4cout << "\n with extent " << extent 01475 << "\n at " << transform.getRotation() 01476 << transform.getTranslation(); 01477 } 01478 G4cout << G4endl; 01479 } 01480 } 01481 else G4VisCommandsSceneAddUnsuccessful(verbosity); 01482 UpdateVisManagerScene (currentSceneName); 01483 }