Import Geant4 11.2.0 source tree

This commit is contained in:
Gabriele Cosmo
2023-12-08 10:43:34 +01:00
parent dd1f179cda
commit 860a2b92bf
3962 changed files with 139318 additions and 164259 deletions
+106 -295
View File
@@ -25,44 +25,39 @@
//
//
//
//
//
// John Allison 27th March 1996
// Abstract interface class for graphics views.
#include "G4VViewer.hh"
#include "G4Timer.hh"
#include "G4ios.hh"
#include <sstream>
#include "G4VisManager.hh"
#include "G4VGraphicsSystem.hh"
#include "G4VSceneHandler.hh"
#include "G4Scene.hh"
#include "G4PhysicalVolumeStore.hh"
#include "G4VPhysicalVolume.hh"
#include "G4Scene.hh"
#include "G4Timer.hh"
#include "G4Transform3D.hh"
#include "G4UImanager.hh"
#include "G4UIsession.hh"
#include "G4VGraphicsSystem.hh"
#include "G4VInteractiveSession.hh"
#include "G4VPhysicalVolume.hh"
#include "G4VSceneHandler.hh"
#include "G4VisManager.hh"
#include "G4ios.hh"
G4VViewer::G4VViewer (G4VSceneHandler& sceneHandler,
G4int id, const G4String& name):
fSceneHandler (sceneHandler),
fViewId (id),
//fModified (true),
fNeedKernelVisit (true)
#include <sstream>
G4VViewer::G4VViewer(G4VSceneHandler& sceneHandler, G4int id, const G4String& name)
: fSceneHandler(sceneHandler), fViewId(id), fNeedKernelVisit(true)
{
if (name == "") {
std::ostringstream ost;
ost << fSceneHandler.GetName () << '-' << fViewId;
ost << fSceneHandler.GetName() << '-' << fViewId;
fName = ost.str();
}
else {
fName = name;
}
fShortName = fName.substr(0, fName.find (' '));
fShortName = fName.substr(0, fName.find(' '));
G4StrUtil::strip(fShortName);
fVP = G4VisManager::GetInstance()->GetDefaultViewParameters();
@@ -71,18 +66,20 @@ fNeedKernelVisit (true)
fSceneTree.SetType(G4SceneTreeItem::root);
}
G4VViewer::~G4VViewer () {
G4VViewer::~G4VViewer()
{
fSceneHandler.RemoveViewerFromList(this);
}
void G4VViewer::SetName (const G4String& name) {
void G4VViewer::SetName(const G4String& name)
{
fName = name;
fShortName = fName.substr(0, fName.find (' '));
fShortName = fName.substr(0, fName.find(' '));
G4StrUtil::strip(fShortName);
}
void G4VViewer::NeedKernelVisit () {
void G4VViewer::NeedKernelVisit()
{
fNeedKernelVisit = true;
// At one time I thought we'd better notify all viewers. But I guess
@@ -104,11 +101,11 @@ void G4VViewer::NeedKernelVisit () {
// Feb 2005 - commented out. Let's fix OpenGL if necessary.
}
void G4VViewer::FinishView () {}
void G4VViewer::FinishView() {}
void G4VViewer::ShowView () {}
void G4VViewer::ShowView() {}
void G4VViewer::ProcessView ()
void G4VViewer::ProcessView()
{
// If the scene has changed, or if the concrete viewer has decided
// that it necessary to visit the kernel, perhaps because the view
@@ -120,43 +117,42 @@ void G4VViewer::ProcessView ()
G4Timer timer;
timer.Start();
fNeedKernelVisit = false;
fSceneHandler.ClearStore ();
fSceneHandler.ProcessScene ();
fSceneHandler.ClearStore();
fSceneHandler.ProcessScene();
UpdateGUISceneTree();
timer.Stop();
fKernelVisitElapsedTimeSeconds = timer.GetRealElapsed();
}
}
void G4VViewer::SetViewParameters (const G4ViewParameters& vp) {
void G4VViewer::SetViewParameters(const G4ViewParameters& vp)
{
fVP = vp;
}
void G4VViewer::SetTouchable
(const std::vector<G4PhysicalVolumeModel::G4PhysicalVolumeNodeID>& fullPath)
void G4VViewer::SetTouchable(
const std::vector<G4PhysicalVolumeModel::G4PhysicalVolumeNodeID>& fullPath)
{
// Set the touchable for /vis/touchable/set/... commands.
std::ostringstream oss;
const auto& pvStore = G4PhysicalVolumeStore::GetInstance();
for (const auto& pvNodeId: fullPath) {
for (const auto& pvNodeId : fullPath) {
const auto& pv = pvNodeId.GetPhysicalVolume();
auto iterator = find(pvStore->cbegin(),pvStore->cend(),pv);
auto iterator = find(pvStore->cbegin(), pvStore->cend(), pv);
if (iterator == pvStore->cend()) {
G4ExceptionDescription ed;
ed << "Volume no longer in physical volume store.";
G4Exception("G4VViewer::SetTouchable", "visman0401", JustWarning, ed);
} else {
oss
<< ' ' << pvNodeId.GetPhysicalVolume()->GetName()
<< ' ' << pvNodeId.GetCopyNo();
}
else {
oss << ' ' << pvNodeId.GetPhysicalVolume()->GetName() << ' ' << pvNodeId.GetCopyNo();
}
}
G4UImanager::GetUIpointer()->ApplyCommand("/vis/set/touchable" + oss.str());
}
void G4VViewer::TouchableSetVisibility
(const std::vector<G4PhysicalVolumeModel::G4PhysicalVolumeNodeID>& fullPath,
G4bool visibiity)
void G4VViewer::TouchableSetVisibility(
const std::vector<G4PhysicalVolumeModel::G4PhysicalVolumeNodeID>& fullPath, G4bool visibiity)
{
// Changes the Vis Attribute Modifiers and scene tree WITHOUT triggering a rebuild.
@@ -169,10 +165,8 @@ void G4VViewer::TouchableSetVisibility
// and set the visibility.
workingVisAtts.SetVisibility(visibiity);
fVP.AddVisAttributesModifier
(G4ModelingParameters::VisAttributesModifier
(workingVisAtts,
G4ModelingParameters::VASVisibility,
fVP.AddVisAttributesModifier(G4ModelingParameters::VisAttributesModifier(
workingVisAtts, G4ModelingParameters::VASVisibility,
G4PhysicalVolumeModel::GetPVNameCopyNoPath(fullPath)));
// G4ModelingParameters::VASVisibility (VAS = Vis Attribute Signifier)
// signifies that it is the visibility that should be picked out
@@ -182,19 +176,20 @@ void G4VViewer::TouchableSetVisibility
// The scene tree works with strings
G4String fullPathString = G4PhysicalVolumeModel::GetPVNamePathString(fullPath);
std::list<G4SceneTreeItem>::iterator foundIter;
if (fSceneTree.FindTouchableFromRoot(fullPathString,foundIter)) {
if (fSceneTree.FindTouchableFromRoot(fullPathString, foundIter)) {
foundIter->AccessVisAttributes().SetVisibility(visibiity);
UpdateGUISceneTree();
} else {
}
else {
G4ExceptionDescription ed;
ed << "Touchable \"" << fullPath << "\" not found";
G4Exception("G4VViewer::TouchableSetVisibility", "visman0402", JustWarning, ed);
}
}
void G4VViewer::TouchableSetColour
(const std::vector<G4PhysicalVolumeModel::G4PhysicalVolumeNodeID>& fullPath,
const G4Colour& colour)
void G4VViewer::TouchableSetColour(
const std::vector<G4PhysicalVolumeModel::G4PhysicalVolumeNodeID>& fullPath,
const G4Colour& colour)
{
// Changes the Vis Attribute Modifiers and scene tree WITHOUT triggering a rebuild.
@@ -207,10 +202,8 @@ void G4VViewer::TouchableSetColour
// and set the colour.
workingVisAtts.SetColour(colour);
fVP.AddVisAttributesModifier
(G4ModelingParameters::VisAttributesModifier
(workingVisAtts,
G4ModelingParameters::VASColour,
fVP.AddVisAttributesModifier(G4ModelingParameters::VisAttributesModifier(
workingVisAtts, G4ModelingParameters::VASColour,
G4PhysicalVolumeModel::GetPVNameCopyNoPath(fullPath)));
// G4ModelingParameters::VASColour (VAS = Vis Attribute Signifier)
// signifies that it is the colour that should be picked out
@@ -220,10 +213,11 @@ void G4VViewer::TouchableSetColour
// The scene tree works with strings
G4String fullPathString = G4PhysicalVolumeModel::GetPVNamePathString(fullPath);
std::list<G4SceneTreeItem>::iterator foundIter;
if (fSceneTree.FindTouchableFromRoot(fullPathString,foundIter)) {
if (fSceneTree.FindTouchableFromRoot(fullPathString, foundIter)) {
foundIter->AccessVisAttributes().SetColour(colour);
UpdateGUISceneTree();
} else {
}
else {
G4ExceptionDescription ed;
ed << "Touchable \"" << fullPath << "\" not found";
G4Exception("G4VViewer::TouchableSetColour", "visman0403", JustWarning, ed);
@@ -240,18 +234,32 @@ void G4VViewer::UpdateGUISceneTree()
void G4VViewer::SceneTreeScene::SetModel(G4VModel* pModel)
{
fpModel = pModel;
// Insert in tree (if not already inserted)
auto& modelType = fpModel->GetType();
auto& modelID = fpModel->GetGlobalDescription();
FindOrInsertModel(modelType,modelID);
auto& modelID = fpModel->GetGlobalDescription();
FindOrInsertModel(modelType, modelID);
auto pvModel = dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
if (pvModel) {
// Limit the expanded depth to limit the number expanded so as not to swamp the GUI
G4int expanded = 0;
for (const auto& dn : pvModel->GetNumberOfTouchables()) {
expanded += dn.second;
if (fMaximumExpandedDepth < dn.first) fMaximumExpandedDepth = dn.first;
if (expanded > fMaximumExpanded) break;
}
}
}
std::list<G4SceneTreeItem>::iterator G4VViewer::SceneTreeScene::FindOrInsertModel
(const G4String& modelType,const G4String& modelID)
std::list<G4SceneTreeItem>::iterator
G4VViewer::SceneTreeScene::FindOrInsertModel(const G4String& modelType, const G4String& modelID)
{
G4SceneTreeItem::Type type = G4SceneTreeItem::unidentified;
if (dynamic_cast<G4PhysicalVolumeModel*>(fpModel)) {
type = G4SceneTreeItem::pvmodel;
} else {
}
else {
type = G4SceneTreeItem::model;
}
@@ -270,21 +278,21 @@ std::list<G4SceneTreeItem>::iterator G4VViewer::SceneTreeScene::FindOrInsertMode
}
if (modelIter == modelItems.end()) {
// Model not seen before
G4SceneTreeItem modelItem(type);
modelItem.SetDescription("model");
modelItem.SetModelType(modelType);
modelItem.SetModelDescription(modelID);
if (pvModelIter != modelItems.end() && // There was pre-existing PV Model...
type == G4SceneTreeItem::pvmodel) { // ...and the new model is also PV...
modelIter = rootItem.InsertChild(++pvModelIter,modelItem); // ...insert after, else...
} else {
modelIter = rootItem.InsertChild(modelIter,modelItem); // ...insert at end
type == G4SceneTreeItem::pvmodel)
{ // ...and the new model is also PV...
modelIter = rootItem.InsertChild(++pvModelIter, modelItem); // ...insert after, else...
}
} else {
else {
modelIter = rootItem.InsertChild(modelIter, modelItem); // ...insert at end
}
}
else {
// Existing model - mark visible == active
modelIter->AccessVisAttributes().SetVisibility(true);
}
@@ -292,6 +300,7 @@ std::list<G4SceneTreeItem>::iterator G4VViewer::SceneTreeScene::FindOrInsertMode
return modelIter;
}
// clang-format off
std::list<G4SceneTreeItem>::iterator G4VViewer::SceneTreeScene::FindOrInsertTouchable
(const G4String& modelID, G4SceneTreeItem& mother,
G4int depth, const G4String& partialPathString, const G4String& fullPathString)
@@ -349,7 +358,7 @@ std::list<G4SceneTreeItem>::iterator G4VViewer::SceneTreeScene::FindOrInsertTouc
// Partial path string refers to the actual volume
// Insert new touchable item
G4SceneTreeItem touchable(G4SceneTreeItem::touchable);
touchable.SetExpanded(depth > 2? false: true);
touchable.SetExpanded(depth > fMaximumExpandedDepth? false: true);
touchable.SetDescription(fpModel->GetCurrentTag());
touchable.SetModelType(fpModel->GetType());
touchable.SetModelDescription(modelID);
@@ -363,7 +372,7 @@ std::list<G4SceneTreeItem>::iterator G4VViewer::SceneTreeScene::FindOrInsertTouc
// Partial path string refers to an ancester - it's what we call a "ghost"
G4SceneTreeItem ghost(G4SceneTreeItem::ghost);
ghost.SetExpanded(depth > 2? false: true);
ghost.SetExpanded(depth > fMaximumExpandedDepth? false: true);
// Create a tag from the partial path
std::istringstream iss(partialPathString);
G4String name, copyNo;
@@ -381,17 +390,19 @@ std::list<G4SceneTreeItem>::iterator G4VViewer::SceneTreeScene::FindOrInsertTouc
return childIter;
}
// clang-format on
void G4VViewer::SceneTreeScene::ProcessVolume(const G4VSolid&)
{
auto& modelType = fpModel->GetType();
auto& modelID = fpModel->GetGlobalDescription();
auto modelIter = FindOrInsertModel(modelType,modelID);
auto& modelID = fpModel->GetGlobalDescription();
auto modelIter = FindOrInsertModel(modelType, modelID);
auto pPVModel = dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
if (pPVModel) { // G4PhysicalVolumeModel
std::ostringstream oss; oss << pPVModel->GetFullPVPath();
std::ostringstream oss;
oss << pPVModel->GetFullPVPath();
G4String fullPathString(oss.str()); // Has a leading space - OK
// Navigate scene tree and find or insert touchables one by one
@@ -401,256 +412,56 @@ void G4VViewer::SceneTreeScene::ProcessVolume(const G4VSolid&)
G4String partialPathString;
auto currentIter = modelIter;
G4int depth = 0;
for (const auto& nodeID: nodeIDs) {
std::ostringstream oss1; oss1 << nodeID;
for (const auto& nodeID : nodeIDs) {
std::ostringstream oss1;
oss1 << nodeID;
partialPathString += ' ' + oss1.str(); // Has a leading space - OK
currentIter = FindOrInsertTouchable
(modelID, *currentIter, ++depth, partialPathString, fullPathString);
currentIter =
FindOrInsertTouchable(modelID, *currentIter, ++depth, partialPathString, fullPathString);
}
} else {
}
else {
// Orphan solid - what to do? Push an empty scene tree item????????????????????????
}
}
std::vector <G4ThreeVector> G4VViewer::ComputeFlyThrough(G4Vector3D* /*aVect*/)
{
enum CurveType {
Bezier,
G4SplineTest};
// Choose a curve type (for testing)
// int myCurveType = Bezier;
// number if step points
G4int stepPoints = 500;
G4Spline spline;
// At the moment we don't use the aVect parameters, but build it here :
// Good step points for exampleB5
spline.AddSplinePoint(G4Vector3D(0,1000,-14000));
spline.AddSplinePoint(G4Vector3D(0,1000,0));
spline.AddSplinePoint(G4Vector3D(-4000,1000,4000));
std::vector <G4ThreeVector> viewVect;
// if(myCurveType == Bezier) {
// Draw the spline
for (G4int i = 0; i < stepPoints; ++i) {
G4float t = (G4float)i / (G4float)stepPoints;
G4Vector3D cameraPosition = spline.GetInterpolatedSplinePoint(t);
// G4Vector3D targetPoint = spline.GetInterpolatedSplinePoint(t);
// viewParam->SetViewAndLights(G4ThreeVector (cameraPosition.x(), cameraPosition.y(), cameraPosition.z()));
// viewParam->SetCurrentTargetPoint(targetPoint);
G4cout << "FLY CR("<< i << "):" << cameraPosition << G4endl;
viewVect.push_back(G4ThreeVector (cameraPosition.x(), cameraPosition.y(), cameraPosition.z()));
}
// } else if (myCurveType == G4SplineTest) {
/*
This method is a inspire from a Bezier curve. The problem of the Bezier curve is that the path does not go straight between two waypoints.
This method add "stay straight" parameter which could be between 0 and 1 where the pass will follow exactly the line between the waypoints
Ex : stay straight = 50%
m1 = 3*(P1+P0)/2
Ex : stay straight = 0%
m1 = (P1+P0)/2
P1
/ \
/ \
a--x--b
/ ° ° \
/ ° ° \
m1 m2
/ \
/ \
/ \
/ \
P0 P2
*/
// G4Vector3D a;
// G4Vector3D b;
// G4Vector3D m1;
// G4Vector3D m2;
// G4Vector3D P0;
// G4Vector3D P1;
// G4Vector3D P2;
// G4double stayStraight = 0;
// G4double bezierSpeed = 0.4; // Spend 40% time in bezier curve (time between m1-m2 is 40% of time between P0-P1)
//
// G4Vector3D firstPoint;
// G4Vector3D lastPoint;
//
// float nbBezierSteps = (stepPoints * bezierSpeed*(1-stayStraight)) * (2./spline.GetNumPoints());
// float nbFirstSteps = ((stepPoints/2-nbBezierSteps/2) /(1+stayStraight)) * (2./spline.GetNumPoints());
//
// // First points
// firstPoint = spline.GetPoint(0);
// lastPoint = (firstPoint + spline.GetPoint(1))/2;
//
// for( float j=0; j<1; j+= 1/nbFirstSteps) {
// G4ThreeVector pt = firstPoint + (lastPoint - firstPoint) * j;
// viewVect.push_back(pt);
// G4cout << "FLY Bezier A1("<< viewVect.size()<< "):" << pt << G4endl;
// }
//
// for (int i = 0; i < spline.GetNumPoints()-2; i++) {
// P0 = spline.GetPoint(i);
// P1 = spline.GetPoint(i+1);
// P2 = spline.GetPoint(i+2);
//
// m1 = P1 - (P1-P0)*(1-stayStraight)/2;
// m2 = P1 + (P2-P1)*(1-stayStraight)/2;
//
// // We have to get straight path from (middile of P0-P1) to (middile of P0-P1 + (dist P0-P1) * stayStraight/2)
// if (stayStraight >0) {
//
// firstPoint = (P0 + P1)/2;
// lastPoint = (P0 + P1)/2 + (P1-P0)*stayStraight/2;
//
// for( float j=0; j<1; j+= 1/(nbFirstSteps*stayStraight)) {
// G4ThreeVector pt = firstPoint + (lastPoint - firstPoint)* j;
// viewVect.push_back(pt);
// G4cout << "FLY Bezier A2("<< viewVect.size()<< "):" << pt << G4endl;
// }
// }
// // Compute Bezier curve
// for( float delta = 0 ; delta < 1 ; delta += 1/nbBezierSteps)
// {
// // The Green Line
// a = m1 + ( (P1 - m1) * delta );
// b = P1 + ( (m2 - P1) * delta );
//
// // Final point
// G4ThreeVector pt = a + ((b-a) * delta );
// viewVect.push_back(pt);
// G4cout << "FLY Bezier("<< viewVect.size()<< "):" << pt << G4endl;
// }
//
// // We have to get straight path
// if (stayStraight >0) {
// firstPoint = (P1 + P2)/2 - (P2-P1)*stayStraight/2;
// lastPoint = (P1 + P2)/2;
//
// for( float j=0; j<1; j+= 1/(nbFirstSteps*stayStraight)) {
// G4ThreeVector pt = firstPoint + (lastPoint - firstPoint)* j;
// viewVect.push_back(pt);
// G4cout << "FLY Bezier B1("<< viewVect.size()<< "):" << pt << G4endl;
// }
// }
// }
//
// // last points
// firstPoint = spline.GetPoint(spline.GetNumPoints()-2);
// lastPoint = spline.GetPoint(spline.GetNumPoints()-1);
// for( float j=1; j>0; j-= 1/nbFirstSteps) {
// G4ThreeVector pt = lastPoint - ((lastPoint-firstPoint)*((1-stayStraight)/2) * j );
// viewVect.push_back(pt);
// G4cout << "FLY Bezier B2("<< viewVect.size()<< "):" << pt << G4endl;
// }
// }
return viewVect;
}
#ifdef G4MULTITHREADED
void G4VViewer::DoneWithMasterThread () {
void G4VViewer::DoneWithMasterThread()
{
// G4cout << "G4VViewer::DoneWithMasterThread" << G4endl;
}
void G4VViewer::MovingToMasterThread () {
void G4VViewer::MovingToMasterThread()
{
// G4cout << "G4VViewer::MovingToMasterThread" << G4endl;
}
void G4VViewer::SwitchToVisSubThread () {
void G4VViewer::SwitchToVisSubThread()
{
// G4cout << "G4VViewer::SwitchToVisSubThread" << G4endl;
}
void G4VViewer::DoneWithVisSubThread () {
void G4VViewer::DoneWithVisSubThread()
{
// G4cout << "G4VViewer::DoneWithVisSubThread" << G4endl;
}
void G4VViewer::MovingToVisSubThread () {
void G4VViewer::MovingToVisSubThread()
{
// G4cout << "G4VViewer::MovingToVisSubThread" << G4endl;
}
void G4VViewer::SwitchToMasterThread () {
void G4VViewer::SwitchToMasterThread()
{
// G4cout << "G4VViewer::SwitchToMasterThread" << G4endl;
}
#endif
std::ostream& operator << (std::ostream& os, const G4VViewer& v) {
std::ostream& operator<<(std::ostream& os, const G4VViewer& v)
{
os << "View " << v.fName << ":\n";
os << v.fVP;
return os;
}
// ===== G4Spline class =====
G4VViewer::G4Spline::G4Spline()
: vp(), delta_t(0)
{
}
G4VViewer::G4Spline::~G4Spline()
{}
// Solve the Catmull-Rom parametric equation for a given time(t) and vector quadruple (p1,p2,p3,p4)
G4Vector3D G4VViewer::G4Spline::CatmullRom_Eq(G4float t, const G4Vector3D& p1, const G4Vector3D& p2, const G4Vector3D& p3, const G4Vector3D& p4)
{
G4float t2 = t * t;
G4float t3 = t2 * t;
G4float b1 = .5 * ( -t3 + 2*t2 - t);
G4float b2 = .5 * ( 3*t3 - 5*t2 + 2);
G4float b3 = .5 * (-3*t3 + 4*t2 + t);
G4float b4 = .5 * ( t3 - t2 );
return (p1*b1 + p2*b2 + p3*b3 + p4*b4);
}
void G4VViewer::G4Spline::AddSplinePoint(const G4Vector3D& v)
{
vp.push_back(v);
delta_t = (G4float)1 / (G4float)vp.size();
}
G4Vector3D G4VViewer::G4Spline::GetPoint(G4int a)
{
return vp[a];
}
G4int G4VViewer::G4Spline::GetNumPoints()
{
return (G4int)vp.size();
}
G4Vector3D G4VViewer::G4Spline::GetInterpolatedSplinePoint(G4float t)
{
// Find out in which interval we are on the spline
G4int p = (G4int)(t / delta_t);
// Compute local control point indices
#define BOUNDS(pp) { if (pp < 0) pp = 0; else if (pp >= (G4int)vp.size()-1) pp = (G4int)vp.size() - 1; }
G4int p0 = p - 1; BOUNDS(p0);
G4int p1 = p; BOUNDS(p1);
G4int p2 = p + 1; BOUNDS(p2);
G4int p3 = p + 2; BOUNDS(p3);
// Relative (local) time
G4float lt = (t - delta_t*p) / delta_t;
// Interpolate
return CatmullRom_Eq(lt, vp[p0], vp[p1], vp[p2], vp[p3]);
}
@@ -340,7 +340,7 @@ G4VisCommandOpen::G4VisCommandOpen() {
parameter->SetGuidance
("integer (pixels) for square window placed by window manager or"
" X-Windows-type geometry string, e.g. 600x600-100+100");
parameter->SetDefaultValue("none");
parameter->SetCurrentAsDefault(true);
fpCommand->SetParameter(parameter);
}
@@ -350,15 +350,24 @@ G4VisCommandOpen::~G4VisCommandOpen() {
G4String G4VisCommandOpen::GetCurrentValue(G4UIcommand*)
{
G4String graphicsSystemName;
G4String graphicsSystemName, windowSizeHint;
auto graphicsSystem = fpVisManager->GetCurrentGraphicsSystem();
if (graphicsSystem) {
graphicsSystemName = graphicsSystem->GetName ();
// Take name and hint from latest graphics system and viewer
graphicsSystemName = graphicsSystem->GetName();
auto viewer = fpVisManager->GetCurrentViewer();
if (viewer) {
windowSizeHint = viewer->GetViewParameters().GetXGeometryString();
}
else { // Viewer not yet created?
windowSizeHint = fpVisManager->GetDefaultXGeometryString();
}
}
else {
graphicsSystemName = "none";
else { // No graphics system yet - must be first time
graphicsSystemName = fpVisManager->GetDefaultGraphicsSystemName();
windowSizeHint = fpVisManager->GetDefaultXGeometryString();
}
return graphicsSystemName;
return graphicsSystemName + ' ' + windowSizeHint;
}
void G4VisCommandOpen::SetNewValue (G4UIcommand* command, G4String newValue)
@@ -370,25 +379,24 @@ void G4VisCommandOpen::SetNewValue (G4UIcommand* command, G4String newValue)
auto errorCode = UImanager->ApplyCommand(G4String("/vis/sceneHandler/create " + systemName));
if (errorCode) {
G4ExceptionDescription ed;
ed << "sub-command \"/vis/sceneHandler/create\" failed.";
command->CommandFailed(errorCode,ed);
G4warn << "sub-command \"/vis/sceneHandler/create\" failed." << G4endl;
goto finish;
}
errorCode = UImanager->ApplyCommand(G4String("/vis/viewer/create ! ! " + windowSizeHint));
if (errorCode) {
G4ExceptionDescription ed;
ed << "sub-command \"/vis/viewer/create\" failed.";
command->CommandFailed(errorCode,ed);
G4warn << "sub-command \"/vis/viewer/create\" failed." << G4endl;
goto finish;
}
finish:
if (errorCode) {
G4ExceptionDescription ed;
ed << "Invoked command has failed - see above. Available graphics systems are:\n ";
fpVisManager->PrintAvailableGraphicsSystems(G4VisManager::warnings,ed);
command->CommandFailed(errorCode,ed);
fpVisManager->PrintAvailableGraphicsSystems(G4VisManager::warnings,G4warn);
if (errorCode != JustWarning) {
G4ExceptionDescription ed;
ed << "Invoked command has failed - see above.";
command->CommandFailed(errorCode,ed);
}
}
}
@@ -166,6 +166,7 @@ void G4VisCommandSceneAddArrow::SetNewValue (G4UIcommand*, G4String newValue)
G4VisCommandSceneAddArrow2D::G4VisCommandSceneAddArrow2D () {
fpCommand = new G4UIcommand("/vis/scene/add/arrow2D", this);
fpCommand -> SetGuidance ("Adds 2D arrow to current scene.");
fpCommand -> SetGuidance ("x,y in range [-1,1]");
G4bool omitable;
G4UIparameter* parameter;
parameter = new G4UIparameter ("x1", 'd', omitable = false);
@@ -1163,6 +1164,7 @@ void G4VisCommandSceneAddLine::Line::operator()
G4VisCommandSceneAddLine2D::G4VisCommandSceneAddLine2D () {
fpCommand = new G4UIcommand("/vis/scene/add/line2D", this);
fpCommand -> SetGuidance ("Adds 2D line to current scene.");
fpCommand -> SetGuidance ("x,y in range [-1,1]");
G4bool omitable;
G4UIparameter* parameter;
parameter = new G4UIparameter ("x1", 'd', omitable = false);
@@ -2658,6 +2660,7 @@ G4VisCommandSceneAddText2D::G4VisCommandSceneAddText2D () {
G4bool omitable;
fpCommand = new G4UIcommand ("/vis/scene/add/text2D", this);
fpCommand -> SetGuidance ("Adds 2D text to current scene.");
fpCommand -> SetGuidance ("x,y in range [-1,1]");
fpCommand -> SetGuidance
("Use \"/vis/set/textColour\" to set colour.");
fpCommand -> SetGuidance
@@ -2727,7 +2730,12 @@ void G4VisCommandSceneAddText2D::SetNewValue (G4UIcommand*, G4String newValue) {
new G4CallbackModel<G4VisCommandSceneAddText2D::G4Text2D>(g4text2D);
model->SetType("Text2D");
model->SetGlobalTag("Text2D");
model->SetGlobalDescription("Text2D: " + newValue);
std::ostringstream oss;
oss << "Text2D: \"" << g4text.GetText()
<< "\" at " << g4text.GetPosition().x() << ',' << g4text.GetPosition().y()
<< " with size " << g4text.GetScreenSize()
<< " with offsets " << g4text.GetXOffset() << ',' << g4text.GetYOffset();
model->SetGlobalDescription(oss.str());
const G4String& currentSceneName = pScene -> GetName ();
G4bool successful = pScene -> AddRunDurationModel (model, warn);
if (successful) {
@@ -146,8 +146,8 @@ G4VisCommandSceneHandlerCreate::G4VisCommandSceneHandlerCreate (): fId (0) {
"\n\"/vis/sceneHandler/attach\".) Invents a scene handler name if not"
"\nsupplied. This scene handler becomes current.");
G4UIparameter* parameter;
parameter = new G4UIparameter ("graphics-system-name",
's', omitable = false);
parameter = new G4UIparameter ("graphics-system-name", 's', omitable = true);
parameter -> SetCurrentAsDefault(true);
const G4GraphicsSystemList& gslist =
fpVisManager -> GetAvailableGraphicsSystems ();
G4String candidates;
@@ -187,14 +187,7 @@ G4String G4VisCommandSceneHandlerCreate::GetCurrentValue(G4UIcommand*) {
graphicsSystemName = graphicsSystem -> GetName ();
}
else {
const G4GraphicsSystemList& gslist =
fpVisManager -> GetAvailableGraphicsSystems ();
if (gslist.size ()) {
graphicsSystemName = gslist [0] -> GetName ();
}
else {
graphicsSystemName = "none";
}
graphicsSystemName = fpVisManager->GetDefaultGraphicsSystemName();
}
return graphicsSystemName + " " + NextName ();
@@ -219,7 +212,7 @@ void G4VisCommandSceneHandlerCreate::SetNewValue (G4UIcommand* command,
" no graphics systems available."
"\n Did you instantiate any in"
" YourVisManager::RegisterGraphicsSystems()?";
command->CommandFailed(ed);
command->CommandFailed(JustWarning,ed);
return;
}
std::size_t iGS; // Selector index.
@@ -253,7 +246,7 @@ void G4VisCommandSceneHandlerCreate::SetNewValue (G4UIcommand* command,
<< "\" requested."
<< "\n Candidates are:";
fpVisManager->PrintAvailableGraphicsSystems(verbosity,ed);
command->CommandFailed(ed);
command->CommandFailed(JustWarning,ed);
return;
}
@@ -283,7 +276,7 @@ void G4VisCommandSceneHandlerCreate::SetNewValue (G4UIcommand* command,
ed << "\"" << gsl[iGSBeingTested]->GetNickname()
<< "\" is not compatible with your chosen session,"
" and no fallback system found.";
command->CommandFailed(ed);
command->CommandFailed(JustWarning,ed);
return;
}
// A fallback system found...but go back and check this too.
@@ -319,7 +312,7 @@ void G4VisCommandSceneHandlerCreate::SetNewValue (G4UIcommand* command,
ed <<
"ERROR: Scene handler \"" << newName
<< "\" already exists.";
command->CommandFailed(ed);
command->CommandFailed(JustWarning,ed);
return;
}
}
@@ -356,7 +349,7 @@ void G4VisCommandSceneHandlerCreate::SetNewValue (G4UIcommand* command,
<< "\" is not the new name \""
<< newName
<< "\".\n Please report to vis coordinator.";
command->CommandFailed(ed);
command->CommandFailed(JustWarning,ed);
return;
}
@@ -420,6 +420,7 @@ void G4VisCommandsTouchable::SetNewValue
G4AxesModel axesModel(0.,0.,0.,length,transform);
axesModel.SetGlobalTag("LocalAxesModel");
axesModel.DescribeYourselfTo(*fpVisManager->GetCurrentSceneHandler());
G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/refresh");
} else {
G4warn << "Touchable not found." << G4endl;
}
@@ -941,7 +941,7 @@ G4VisCommandViewerCreate::G4VisCommandViewerCreate (): fId (0) {
parameter -> SetCurrentAsDefault (true);
fpCommand -> SetParameter (parameter);
parameter = new G4UIparameter ("window-size-hint", 's', omitable = true);
parameter -> SetDefaultValue("none");
parameter -> SetCurrentAsDefault (true);
fpCommand -> SetParameter (parameter);
}
@@ -963,20 +963,32 @@ G4String G4VisCommandViewerCreate::NextName () {
return oss.str();
}
G4String G4VisCommandViewerCreate::GetCurrentValue (G4UIcommand*) {
G4String currentValue;
G4VSceneHandler* currentSceneHandler =
fpVisManager -> GetCurrentSceneHandler ();
if (currentSceneHandler) {
currentValue = currentSceneHandler -> GetName ();
} else {
currentValue = "none";
G4String G4VisCommandViewerCreate::GetCurrentValue (G4UIcommand*)
{
G4String sceneHandlerName;
auto currentSceneHandler = fpVisManager->GetCurrentSceneHandler();
if (currentSceneHandler) { // Get name of last scene handler
sceneHandlerName = currentSceneHandler->GetName();
}
currentValue += ' ';
currentValue += '"';
currentValue += NextName ();
currentValue += '"';
return currentValue;
else { // No scene handler - ensure a warning message
sceneHandlerName = "none";
}
// Default name
const auto& viewerName = NextName();
// Size hint
G4String windowSizeHint;
auto currentViewer = fpVisManager->GetCurrentViewer();
if (currentViewer) { // Get hint from last viewer
windowSizeHint = currentViewer->GetViewParameters().GetXGeometryString();
}
else { // No viewer - must be first time
windowSizeHint = fpVisManager->GetDefaultXGeometryString();
}
// Add quotes around viewer name
return sceneHandlerName + " \"" + viewerName + "\" " + windowSizeHint;
}
void G4VisCommandViewerCreate::SetNewValue (G4UIcommand* command, G4String newValue) {
@@ -99,6 +99,10 @@ G4VisManager::Verbosity G4VisManager::fVerbosity = G4VisManager::warnings;
G4VisManager::G4VisManager (const G4String& verbosityString)
: fVerbose (1)
, fDefaultGraphicsSystemName("OGL") // Override in G4VisExecutive
, fDefaultXGeometryString ("600x600-0+0") // Override in G4VisExecutive
, fDefaultGraphicsSystemBasis ("G4VisManager initialisation")
, fDefaultXGeometryStringBasis("G4VisManager initialisation")
, fInitialised (false)
, fpGraphicsSystem (0)
, fpScene (0)
@@ -672,10 +676,14 @@ void G4VisManager::RegisterMessengers () {
#include <tools/histo/h2d>
namespace {
struct PlotResults {
std::size_t fNumberOfPlots = 0;
std::size_t fTotalEntries = 0;
};
template <typename HT> // tools::histo::h1d, etc
G4bool PrintListOfHnPlots(const G4String& plotType) { // h1, etc.
PlotResults ResultsOfHnPlots(const G4String& plotType) { // h1, etc.
PlotResults plotResults;
auto ui = G4UImanager::GetUIpointer();
G4bool thereArePlots = false;
auto keepControlVerbose = ui->GetVerboseLevel();
ui->SetVerboseLevel(0);
auto status = ui->ApplyCommand("/analysis/" + plotType + "/getVector");
@@ -683,41 +691,46 @@ namespace {
if(status==G4UIcommandStatus::fCommandSucceeded) {
G4String hexString = ui->GetCurrentValues(G4String("/analysis/" + plotType + "/getVector"));
if(hexString.size()) {
void* ptr;
std::istringstream is(hexString);
is >> ptr;
auto _v = (const std::vector<HT*>*)ptr;
auto _n = _v->size();
if (_n > 0) {
thereArePlots = true;
G4String isare("are"),plural("s");
if (_n == 1) {isare = "is"; plural = "";}
G4cout <<
"There " << isare << ' ' << _n << ' ' << plotType << " histogram" << plural
<< G4endl;
if (_n <= 5) {
for (std::size_t i = 0; i < _n; ++i) {
const auto& _h = (*_v)[i];
G4cout
<< std::setw(3) << i
<< " with " << std::setw(6) << _h->entries() << " entries: "
<< _h->get_title() << G4endl;
}
}
void* ptr; std::istringstream is(hexString); is >> ptr;
auto vectorOfPlots = (const std::vector<HT*>*)ptr;
for (std::size_t i = 0; i < vectorOfPlots->size(); ++i) {
auto plot = (*vectorOfPlots)[i];
if (plot == nullptr) continue; // Ignore deleted plots
++plotResults.fNumberOfPlots;
plotResults.fTotalEntries += plot->entries();
}
}
}
return thereArePlots;
return plotResults;
}
void PrintListOfPlots() {
G4bool thereArePlots = false;
if (PrintListOfHnPlots<tools::histo::h1d>("h1")) thereArePlots = true;
if (PrintListOfHnPlots<tools::histo::h2d>("h2")) thereArePlots = true;
if (thereArePlots) {
G4cout <<
"List them with \"/analysis/list\"."
"\nView them with \"/vis/plot\" or \"/vis/reviewPlots\"."
std::size_t numberOfPlots = 0;
std::size_t numberOfEntries = 0;
PlotResults h1results = ResultsOfHnPlots<tools::histo::h1d>("h1");
numberOfPlots += h1results.fNumberOfPlots;
numberOfEntries += h1results.fTotalEntries;
PlotResults h2results = ResultsOfHnPlots<tools::histo::h2d>("h2");
numberOfPlots += h2results.fNumberOfPlots;
numberOfEntries += h2results.fTotalEntries;
if (numberOfPlots > 0) {
G4warn << "There are histograms that can be viewed with visualization:";
if (h1results.fNumberOfPlots > 0) {
G4warn << "\n " << h1results.fNumberOfPlots << " h1 histograms(s)";
}
if (h2results.fNumberOfPlots > 0) {
G4warn << "\n " << h2results.fNumberOfPlots << " h2 histograms(s)";
}
G4warn
<< "\n List them with \"/analysis/list\"."
<< "\n View them immediately with \"/vis/plot\" or \"/vis/reviewPlots\"."
<< G4endl;
if (numberOfEntries == 0) {
G4warn <<
" But...there are no entries. To make your histograms available for"
"\n plotting in this UI session, use CloseFile(false) in your"
"\n EndOfRunAction and Reset() in your BeginOfRunAction."
<< G4endl;
}
}
}
}
@@ -1736,8 +1749,15 @@ void G4VisManager::PrintAvailableGraphicsSystems
// Full output
out << *gs;
}
out << G4endl;
out << std::endl;
}
out << "Default graphics system is: " << fDefaultGraphicsSystemName
<< " (based on " << fDefaultGraphicsSystemBasis << ")."
<< "\nDefault window size hint is: " << fDefaultXGeometryString
<< " (based on " << fDefaultXGeometryStringBasis << ")."
<< "\nNote: Parameters specified on the command line will override these defaults."
<< "\n Use \"vis/open\" without parameters to get these defaults."
<< std::endl;
} else {
out << " NONE!!! None registered - yet! Mmmmm!" << G4endl;
}
@@ -2379,7 +2399,7 @@ void G4VisManager::EndOfRun ()
<< G4endl;
if (fpScene->GetMaxNumberOfKeptEvents() > 0) {
G4warn <<
"\n The number of events in the run exceeded the maximum, "
" The number of events in the run exceeded the maximum, "
<< fpScene->GetMaxNumberOfKeptEvents() <<
", that may be\n kept by the vis manager." <<
"\n The number of events kept by the vis manager can be changed with"