Import Geant4 11.3.0 source tree

This commit is contained in:
Gabriele Cosmo
2024-12-06 11:11:40 +01:00
parent e58e650b32
commit 32390e802b
1984 changed files with 98713 additions and 83996 deletions
+12
View File
@@ -6,6 +6,18 @@ It must **not** be used as a substitute for writing good git commit messages!
-------------------------------------------------------------------------------
## 2024-08-14 John Allison (visQt3D-V11-02-03)
- G4Qt3DViewer:
- Resolve the timing issues around switching to the vis sub-thread with the
use of G4CONDITIONWAITLAMBDA.
## 2024-07-12 Guy Barrand (visQt3D-V11-02-02)
- G4Qt3DViewer: implement a resizeEvent() method to avoid a bad aspect ratio at viewer creation.
- G4Qt3DSceneHandler: in AddPrimitive(G4Polyline), stay with the Qt5 code. The one for Qt6 using
Qt3DCore::QGeometryView is crashy.
- G4Qt3DViewer: in MovingToVisSubThread(), SwitchToMasterThread() protect against nullptr for p1, p2.
It permits to avoid crash in case of doing /run/beamOn in vis.mac at startup.
## 2024-05-23 Guy Barrand (visQt3D-V11-02-01)
- G4Qt3DSceneHandler::EstablishG4Qt3DQEntities(): have a missing:
fpPhysicalVolumeObjects.clear();
@@ -53,6 +53,7 @@ public:
void SwitchToMasterThread();
protected:
virtual void resizeEvent(QResizeEvent*);
void KernelVisitDecision ();
G4bool CompareForKernelVisit(G4ViewParameters&);
@@ -361,19 +361,10 @@ void G4Qt3DSceneHandler::AddPrimitive(const G4Polyline& polyline)
polylineEntity->addComponent(material);
auto renderer = new Qt3DRender::QGeometryRenderer;
#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
auto geometryView = new Qt3DCore::QGeometryView(polylineGeometry);
geometryView->setObjectName("polylineGeometryView");
geometryView->setGeometry(polylineGeometry);
geometryView->setVertexCount((G4int)(2*nLines));
geometryView->setPrimitiveType(Qt3DCore::QGeometryView::Lines);
renderer->setView(geometryView);
#else
renderer->setObjectName("polylineRenderer");
renderer->setGeometry(polylineGeometry);
renderer->setVertexCount(2*(G4int)nLines);
renderer->setPrimitiveType(Qt3DRender::QGeometryRenderer::Lines);
#endif
polylineEntity->addComponent(renderer);
}
+77 -30
View File
@@ -63,9 +63,6 @@ void G4Qt3DViewer::Initialise()
return;
}
fUIWidget = QWidget::createWindowContainer(this);
fUIWidget->setMinimumSize(QSize(200, 100));
fUIWidget->setMaximumSize(screen()->size());
// fUIWidget->setFocusPolicy(Qt::NoFocus); //??
uiQt->AddTabWidget(fUIWidget,QString(fName));
setRootEntity(fQt3DSceneHandler.fpQt3DScene);
@@ -76,6 +73,10 @@ G4Qt3DViewer::~G4Qt3DViewer()
setRootEntity(nullptr);
}
void G4Qt3DViewer::resizeEvent(QResizeEvent*) {
SetView();
}
void G4Qt3DViewer::SetView()
{
// Background colour
@@ -158,77 +159,123 @@ void G4Qt3DViewer::DrawView()
void G4Qt3DViewer::ShowView()
{
#if QT_VERSION < 0x060000
// show() may only be called from master thread
if (G4Threading::IsMasterThread()) {
show();
}
// The way Qt seems to work, we don't seem to need a show() anyway, but
// we'll leave it in - it seems not to have any effect, good or bad.
#endif
}
void G4Qt3DViewer::FinishView()
{
#if QT_VERSION < 0x060000
if (G4Threading::IsMasterThread()) {
show();
}
#endif
}
// Note: the order of calling of MovingToVisSubThread and SwitchToVisSubThread
// is undefined. The order of calling is
// DoneWithMasterThread
// MovingToVisSubThread ) or ( SwitchToVisSubThread
// SwitchToVisSubThread ) ( MovingToVisSubThread
// DoneWithVisSubThread
// MovingToMasterThread
// SwitchToMasterThread
// So regarding the move/switch to the vis sub-thread, we have to employ mutex locks and conditions.
// If the viewer wishes to accept drawing from the vis sub-thread, Qt3D has to moveToThread.
// But at this point we are still on the master thread and the value of the sub-thread's QThread is
// not known. So it has to wait - a conditional wait, conditional on establishment of the sub-thread
// and the provision of a pointer to the QThread version of the vis sub-thread. In turn, the
// sub-thread has to wait until the QObjects have been moved to the sub-thread.
namespace {
QThread* masterQThread = nullptr;
QThread* visSubThreadQThread = nullptr;
G4Mutex visSubThreadMutex = G4MUTEX_INITIALIZER;
G4Condition waitForVisSubThreadInitialized = G4CONDITION_INITIALIZER;
G4bool visSubThreadEstablished = false;
G4bool qObjectsSwitched = false;
}
# include <chrono>
void G4Qt3DViewer::MovingToVisSubThread()
// Still on master thread but vis thread has been launched
{
#ifdef G4QT3DDEBUG
G4cout << "G4Qt3DViewer::MovingToVisSubThread" << G4endl;
#endif
// Still on master thread but vis thread has been launched
// Make note of master QThread
masterQThread = QThread::currentThread();
// Wait until SwitchToVisSubThread has found vis sub-thread QThread
std::this_thread::sleep_for(std::chrono::milliseconds(100));
{
G4AutoLock lock(&visSubThreadMutex);
G4CONDITIONWAITLAMBDA(&waitForVisSubThreadInitialized, &lock, []{return visSubThreadEstablished;})
}
// Move relevant stuff to vis sub-thread QThread
auto p1 = fQt3DSceneHandler.fpQt3DScene->parent();
auto p2 = p1->parent();
p2->moveToThread(visSubThreadQThread);
if(p1) {
auto p2 = p1->parent();
if(p2) {
p2->moveToThread(visSubThreadQThread);
} else {
p1->moveToThread(visSubThreadQThread);
}
}
// Inform sub-thread
G4AutoLock lock(&visSubThreadMutex);
qObjectsSwitched = true;
lock.unlock();
G4CONDITIONBROADCAST(&waitForVisSubThreadInitialized);
}
void G4Qt3DViewer::SwitchToVisSubThread()
// On vis sub-thread before any drawing
{
#ifdef G4QT3DDEBUG
G4cout << "G4Qt3DViewer::SwitchToVisSubThread" << G4endl;
#endif
// On vis sub-thread before any drawing
// Make note of vis-subthread QThread for MovingToVisSubThread
visSubThreadQThread = QThread::currentThread();
// Wait until SwitchToVisSubThread has moved stuff
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
// Let MovingToVisSubThread know we have the QThread
{
G4AutoLock lock(&visSubThreadMutex);
visSubThreadEstablished = true;
G4CONDITIONBROADCAST(&waitForVisSubThreadInitialized);
}
// Wait until MovingToVisSubThread has moved stuff
{
G4AutoLock lock(&visSubThreadMutex);
G4CONDITIONWAITLAMBDA(&waitForVisSubThreadInitialized, &lock, []{return qObjectsSwitched;})
}
}
void G4Qt3DViewer::MovingToMasterThread()
// On vis sub-thread just before exit
{
#ifdef G4QT3DDEBUG
G4cout << "G4Qt3DViewer::MovingToMasterThread" << G4endl;
#endif
// On vis sub-thread just before exit
// Move relevant stuff to master QThread.
auto p1 = fQt3DSceneHandler.fpQt3DScene->parent();
auto p2 = p1->parent();
p2->moveToThread(masterQThread);
// Zero - will be different next run
if(p1) {
auto p2 = p1->parent();
if(p2) {
p2->moveToThread(masterQThread);
} else {
p1->moveToThread(masterQThread);
}
}
// Reset
visSubThreadQThread = nullptr;
qObjectsSwitched = false;
}
void G4Qt3DViewer::SwitchToMasterThread()
// On master thread after vis sub-thread has terminated
{
#ifdef G4QT3DDEBUG
G4cout << "G4Qt3DViewer::SwitchToMasterThread" << G4endl;
#endif
// On master thread after vis sub-thread has terminated
// Nothing to do
visSubThreadEstablished = false;
}
void G4Qt3DViewer::KernelVisitDecision () {