Import Geant4 11.2.0.beta source tree

This commit is contained in:
Gabriele Cosmo
2023-06-30 09:09:57 +02:00
parent aef78ca386
commit dd1f179cda
3780 changed files with 212808 additions and 142780 deletions
@@ -44,6 +44,8 @@
#include "G4VPhysicalVolume.hh"
#include "G4Transform3D.hh"
#include "G4UImanager.hh"
#include "G4UIsession.hh"
#include "G4VInteractiveSession.hh"
G4VViewer::G4VViewer (G4VSceneHandler& sceneHandler,
G4int id, const G4String& name):
@@ -65,6 +67,8 @@ fNeedKernelVisit (true)
fVP = G4VisManager::GetInstance()->GetDefaultViewParameters();
fDefaultVP = fVP;
fSceneTree.SetType(G4SceneTreeItem::root);
}
G4VViewer::~G4VViewer () {
@@ -118,6 +122,7 @@ void G4VViewer::ProcessView ()
fNeedKernelVisit = false;
fSceneHandler.ClearStore ();
fSceneHandler.ProcessScene ();
UpdateGUISceneTree();
timer.Stop();
fKernelVisitElapsedTimeSeconds = timer.GetRealElapsed();
}
@@ -139,7 +144,7 @@ void G4VViewer::SetTouchable
if (iterator == pvStore->cend()) {
G4ExceptionDescription ed;
ed << "Volume no longer in physical volume store.";
G4Exception("G4VViewer::SetTouchable", "visman0501", JustWarning, ed);
G4Exception("G4VViewer::SetTouchable", "visman0401", JustWarning, ed);
} else {
oss
<< ' ' << pvNodeId.GetPhysicalVolume()->GetName()
@@ -153,7 +158,7 @@ void G4VViewer::TouchableSetVisibility
(const std::vector<G4PhysicalVolumeModel::G4PhysicalVolumeNodeID>& fullPath,
G4bool visibiity)
{
// Changes the Vis Attribute Modifiers WITHOUT triggering a rebuild.
// Changes the Vis Attribute Modifiers and scene tree WITHOUT triggering a rebuild.
// The following is equivalent to
// G4UImanager::GetUIpointer()->ApplyCommand("/vis/touchable/set/visibility ...");
@@ -172,13 +177,26 @@ void G4VViewer::TouchableSetVisibility
// G4ModelingParameters::VASVisibility (VAS = Vis Attribute Signifier)
// signifies that it is the visibility that should be picked out
// and merged with the touchable's normal vis attributes.
// Find scene tree item and set visibility
// The scene tree works with strings
G4String fullPathString = G4PhysicalVolumeModel::GetPVNamePathString(fullPath);
std::list<G4SceneTreeItem>::iterator foundIter;
if (fSceneTree.FindTouchableFromRoot(fullPathString,foundIter)) {
foundIter->AccessVisAttributes().SetVisibility(visibiity);
UpdateGUISceneTree();
} 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)
{
// Changes the Vis Attribute Modifiers WITHOUT triggering a rebuild.
// Changes the Vis Attribute Modifiers and scene tree WITHOUT triggering a rebuild.
// The following is equivalent to
// G4UImanager::GetUIpointer()->ApplyCommand("/vis/touchable/set/colour ...");
@@ -197,6 +215,201 @@ void G4VViewer::TouchableSetColour
// G4ModelingParameters::VASColour (VAS = Vis Attribute Signifier)
// signifies that it is the colour that should be picked out
// and merged with the touchable's normal vis attributes.
// Find scene tree item and set colour
// The scene tree works with strings
G4String fullPathString = G4PhysicalVolumeModel::GetPVNamePathString(fullPath);
std::list<G4SceneTreeItem>::iterator foundIter;
if (fSceneTree.FindTouchableFromRoot(fullPathString,foundIter)) {
foundIter->AccessVisAttributes().SetColour(colour);
UpdateGUISceneTree();
} else {
G4ExceptionDescription ed;
ed << "Touchable \"" << fullPath << "\" not found";
G4Exception("G4VViewer::TouchableSetColour", "visman0403", JustWarning, ed);
}
}
void G4VViewer::UpdateGUISceneTree()
{
G4UImanager* UI = G4UImanager::GetUIpointer();
auto uiWindow = dynamic_cast<G4VInteractiveSession*>(UI->GetG4UIWindow());
if (uiWindow) uiWindow->UpdateSceneTree(fSceneTree);
}
void G4VViewer::SceneTreeScene::SetModel(G4VModel* pModel)
{
fpModel = pModel;
auto& modelType = fpModel->GetType();
auto& modelID = fpModel->GetGlobalDescription();
FindOrInsertModel(modelType,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 {
type = G4SceneTreeItem::model;
}
auto& rootItem = fpViewer->fSceneTree;
rootItem.SetDescription(fpViewer->GetName());
// Find appropriate model
auto& modelItems = rootItem.AccessChildren();
auto modelIter = modelItems.begin();
auto pvModelIter = modelItems.end();
for (; modelIter != modelItems.end(); ++modelIter) {
if (modelIter->GetType() == G4SceneTreeItem::pvmodel) {
pvModelIter = modelIter; // Last PV model
}
if (modelIter->GetModelDescription() == modelID) break;
}
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
}
} else {
// Existing model - mark visible == active
modelIter->AccessVisAttributes().SetVisibility(true);
}
return modelIter;
}
std::list<G4SceneTreeItem>::iterator G4VViewer::SceneTreeScene::FindOrInsertTouchable
(const G4String& modelID, G4SceneTreeItem& mother,
G4int depth, const G4String& partialPathString, const G4String& fullPathString)
{
auto pPVModel = dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
if (pPVModel == nullptr) {
G4ExceptionDescription ed;
ed << fpModel->GetType() << ": not a Physical VolumeModel";
G4Exception("G4VViewer::SceneTreeScene::FindOrInsertTouchable", "visman0404", FatalException, ed);
}
auto& children = mother.AccessChildren();
auto childIter = children.begin();
for (; childIter != children.end(); ++childIter) {
if (childIter->GetPVPath() == partialPathString) break;
}
if (childIter != children.end()) {
// Item already exists
if (childIter->GetType() == G4SceneTreeItem::ghost) {
// Previously it was a ghost - but maybe this time it's real
if (partialPathString == fullPathString) {
// Partial path string refers to the actual volume so it's a touchable
childIter->SetType(G4SceneTreeItem::touchable);
// Populate with information
childIter->SetDescription(fpModel->GetCurrentTag());
childIter->SetModelType(fpModel->GetType());
childIter->SetModelDescription(modelID);
childIter->SetPVPath(partialPathString);
if (fpVisAttributes) childIter->SetVisAttributes(*fpVisAttributes);
if (pPVModel) childIter->SetAttDefs(pPVModel->GetAttDefs());
if (pPVModel) childIter->SetAttValues(pPVModel->CreateCurrentAttValues());
} // Partial path string refers to an ancester - do nothing
} else {
// Already a pre-existing full touchable
if (partialPathString == fullPathString) {
// Partial path string refers to the actual volume
// Replace vis attributes (if any) - they might have changed
if (fpVisAttributes) childIter->SetVisAttributes(*fpVisAttributes);
} // Partial path string refers to an ancester - do nothing
}
} else {
// Item does not yet exist
if (partialPathString == fullPathString) {
// Partial path string refers to the actual volume
// Insert new touchable item
G4SceneTreeItem touchable(G4SceneTreeItem::touchable);
touchable.SetExpanded(depth > 2? false: true);
touchable.SetDescription(fpModel->GetCurrentTag());
touchable.SetModelType(fpModel->GetType());
touchable.SetModelDescription(modelID);
touchable.SetPVPath(partialPathString);
if (fpVisAttributes) touchable.SetVisAttributes(*fpVisAttributes);
if (pPVModel) touchable.SetAttDefs(pPVModel->GetAttDefs());
if (pPVModel) touchable.SetAttValues(pPVModel->CreateCurrentAttValues());
childIter = mother.InsertChild(childIter,touchable);
} else {
// Partial path string refers to an ancester - it's what we call a "ghost"
G4SceneTreeItem ghost(G4SceneTreeItem::ghost);
ghost.SetExpanded(depth > 2? false: true);
// Create a tag from the partial path
std::istringstream iss(partialPathString);
G4String name, copyNo;
while (iss >> name >> copyNo);
std::ostringstream oss;
oss << name << ':' << copyNo;
ghost.SetDescription(oss.str());
ghost.SetModelType(fpModel->GetType());
ghost.SetModelDescription(modelID);
ghost.SetPVPath(partialPathString);
ghost.AccessVisAttributes().SetVisibility(false);
childIter = mother.InsertChild(childIter,ghost);
}
}
return childIter;
}
void G4VViewer::SceneTreeScene::ProcessVolume(const G4VSolid&)
{
auto& modelType = fpModel->GetType();
auto& modelID = fpModel->GetGlobalDescription();
auto modelIter = FindOrInsertModel(modelType,modelID);
auto pPVModel = dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
if (pPVModel) { // G4PhysicalVolumeModel
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
const auto& nodeIDs = pPVModel->GetFullPVPath(); // std::vector<G4PhysicalVolumeNodeID>
// Work down the path - "name id", then "name id name id", etc.
G4String partialPathString;
auto currentIter = modelIter;
G4int depth = 0;
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);
}
} else {
// Orphan solid - what to do? Push an empty scene tree item????????????????????????
}
}
std::vector <G4ThreeVector> G4VViewer::ComputeFlyThrough(G4Vector3D* /*aVect*/)