Import Geant4 11.3.0.beta source tree

This commit is contained in:
Gabriele Cosmo
2024-06-28 13:08:51 +02:00
parent f7b23877ed
commit e58e650b32
5232 changed files with 239416 additions and 244360 deletions
+38
View File
@@ -6,6 +6,44 @@ It must **not** be used as a substitute for writing good git commit messages!
-------------------------------------------------------------------------------
## 2024-05-30 Guy Barrand (opengl-V11-02-02)
- G4OpenGLImmediateQtViewer, G4OpenGLStoredQtViewer: Qt6: remove the usage of a paintEvent(),
the paintGL() should be sufficient. Having an extra paintEvent() is confusing.
- G4OpenGLImmediateQtViewer, G4OpenGLStoredQtViewer: Qt6: updateQWidget: use update() to trigger
a repaint. It is what is documented.
- G4OpenGLImmediateQtViewer, G4OpenGLStoredQtViewer: Qt6: Initialise(): do a:
if(G4QGLWidgetType::isValid())
before the glDrawBuffer(GL_BACK). It avoids a crash at startup on macOS.
Do the same on the ClearView(), SetView().
- G4OpenGLViewer: have ClearView(), SetView(), ResetView() virtual so that we can do a
if(G4QGLWidgetType::isValid())
in viewers ClearView(), SetView().
- G4OpenGLQtViewer: updatePickInfosWidget, G4MouseReleaseEvent: Qt6: have a "makeCurrent,ResizeGL".
G4OpenGLImmediateQtViewer, G4OpenGLStoredQtViewer: Qt6: DrawView(): have a:
if(IsGettingPickInfos()) {
paintGL();
return;
}
These modifications permit to restore picking. The today code has some "glGetIntegerv(GL_VIEWPORT)"
done "out of makeCurrent()" that returns now, with Qt6::QOpenGLWidget, bad sizes. The
"makeCurrent(), ResizeGL" restores good values, and the upper modifications in DrawView() enforces
a paintGL() within the "makeCurrent()". Picking looks ok with these modifications.
- G4OpenGLQtViewer: G4OpenGLStoredQtViewer: Qt6: have ResizeWindow using glWidget->devicePixelRatio().
To have good size handling on macOS (it looks ok to have this on Linux and Windows, then no need
to "#ifdef __APPLE__").
- G4OpenGLQtViewer: Qt6: DrawText(): we implemented a "2D draw text" (with code found on stackoverflow)
since the renderText() method is no more here on the new Qt6 QOpenGLWidget.
## 2024-05-13 Guy Barrand (opengl-V11-02-01)
- G4OpenGLQtViewer: MT: have the variables mWaitForVisSubThreadQtOpenGLContextMoved,
mWaitForVisSubThreadQtOpenGLContextInitialized,
c1_VisSubThreadQtOpenGLContextInitialized, c2_VisSubThreadQtOpenGLContextMoved local
to the G4OpenGLQtViewer class. It avoids dead-locks in case of multiple OGLI, OGLS viewers
if doing a "/run/beamOn" in each of them.
## 2024-01-11 Ben Morgan (opengl-V11-02-00)
- Make headers of implementation detail classes private.
## 2023-09-05 Ben Morgan (opengl-V11-01-13)
- Set AUTOMOC property on module when Qt used.
@@ -53,7 +53,18 @@ public:
void paintGL();
void updateQWidget();
void ShowView ();
#if QT_VERSION < 0x060000
#else
//G.Barrand: macOS: to avoid a crash at startup at first gl call.
virtual void ClearView() {
if(!G4QGLWidgetType::isValid()) return;
G4OpenGLViewer::ClearView();
}
virtual void SetView() {
if(!G4QGLWidgetType::isValid()) return;
G4OpenGLViewer::SetView();
}
#endif
protected:
void showEvent(QShowEvent * event );
void wheelEvent(QWheelEvent *event);
@@ -64,7 +75,9 @@ protected:
void contextMenuEvent(QContextMenuEvent *e);
void keyPressEvent (QKeyEvent * event);
void keyReleaseEvent (QKeyEvent * event);
#if QT_VERSION < 0x060000
void paintEvent(QPaintEvent *event);
#endif
private:
void ComputeView ();
@@ -386,12 +386,14 @@ private:
#ifdef G4MULTITHREADED
QThread* fQGLContextVisSubThread;
QThread* fQGLContextMainThread;
G4Mutex fmWaitForVisSubThreadQtOpenGLContextMoved;
G4Mutex fmWaitForVisSubThreadQtOpenGLContextInitialized;
G4Condition fc1_VisSubThreadQtOpenGLContextInitialized;
G4Condition fc2_VisSubThreadQtOpenGLContextMoved;
G4AutoLock* flWaitForVisSubThreadQtOpenGLContextInitialized;
G4AutoLock* flWaitForVisSubThreadQtOpenGLContextMoved;
#endif
// safe to use in serial mode
G4AutoLock* lWaitForVisSubThreadQtOpenGLContextInitialized;
G4AutoLock* lWaitForVisSubThreadQtOpenGLContextMoved;
public Q_SLOTS :
void startPauseVideo();
@@ -56,6 +56,18 @@ public:
void updateQWidget();
void ShowView ();
void DisplayTimePOColourModification (G4Colour&,size_t);
#if QT_VERSION < 0x060000
#else
//G.Barrand: macOS: to avoid a crash at startup at first gl call.
virtual void ClearView() {
if(!G4QGLWidgetType::isValid()) return;
G4OpenGLViewer::ClearView();
}
virtual void SetView() {
if(!G4QGLWidgetType::isValid()) return;
G4OpenGLViewer::SetView();
}
#endif
protected:
@@ -75,11 +87,11 @@ protected:
void contextMenuEvent(QContextMenuEvent *e);
void keyPressEvent (QKeyEvent * event);
void keyReleaseEvent (QKeyEvent * event);
#if QT_VERSION < 0x060000
void paintEvent(QPaintEvent *event);
#endif
private:
void ComputeView ();
// QImage glBufferImage;
};
#endif
@@ -101,7 +101,7 @@ class G4OpenGLViewer: virtual public G4VViewer {
friend class G4OpenGLViewerMessenger;
public:
void ClearView ();
virtual void ClearView ();
void ClearViewWithoutFlush ();
virtual bool exportImage(std::string name="", int width=-1, int height=-1);
@@ -116,8 +116,8 @@ private:
G4OpenGLViewer& operator= (const G4OpenGLViewer&);
protected:
void SetView ();
void ResetView ();
virtual void SetView ();
virtual void ResetView ();
virtual void DrawText(const G4Text&);
void ChangePointSize(G4double size);
@@ -178,6 +178,8 @@ protected:
GLdouble near, GLdouble far);
// Redefinition on glFrustum to solve precision issues
bool IsGettingPickInfos() const {return fIsGettingPickInfos;}
G4bool fPrintColour;
G4bool fVectoredPs;
+41 -35
View File
@@ -1,21 +1,23 @@
# - G4OpenGL module build definition
# Define the Geant4 Module.
# The base set of G4OpenGL classes are all private because fundamentally they
# are never exposed outside of the category.
geant4_add_module(G4OpenGL
PUBLIC_HEADERS
PRIVATE_HEADERS
G4gl2ps.hh
G4OpenGL.hh
G4OpenGLFontBaseStore.hh
G4OpenGLImmediateViewer.hh
G4OpenGLImmediateSceneHandler.hh
G4OpenGLViewer.hh
G4OpenGLStoredViewer.hh
G4OpenGLStoredSceneHandler.hh
G4OpenGLFontBaseStore.hh
G4OpenGLSceneHandler.hh
G4OpenGLSceneHandler.icc
G4OpenGLViewerMessenger.hh
G4OpenGLTransform3D.hh
G4OpenGLViewer.hh
G4OpenGLViewerMessenger.hh
G4VisFeaturesOfOpenGL.hh
G4gl2ps.hh
SOURCES
G4OpenGLImmediateViewer.cc
G4OpenGLImmediateSceneHandler.cc
@@ -27,38 +29,29 @@ geant4_add_module(G4OpenGL
G4OpenGLViewerMessenger.cc
G4OpenGLTransform3D.cc
G4VisFeaturesOfOpenGL.cc
G4gl2ps.cc )
G4gl2ps.cc)
geant4_module_link_libraries(G4OpenGL
PUBLIC
G4globman
G4graphics_reps
G4hepgeometry
G4intercoms
G4vis_management
PRIVATE
G4globman
G4graphics_reps
G4geometrymng
G4hepgeometry
G4intercoms
G4modeling
G4run)
# Minor hack: G4modeling is a private dependency, unless Qt is activated when it
# becomes a public dependency. CMake will deduplicate the link in favour of PUBLIC
# when appropriate, but we can't then check consistency reliably. So we have to
# make the link dependent on building for Qt...
# Another demonstratation of awkward vis system of more than one driver per library...
if(GEANT4_USE_QT)
geant4_module_link_libraries(G4OpenGL PUBLIC G4modeling)
else()
geant4_module_link_libraries(G4OpenGL PRIVATE G4modeling)
endif()
#----------------------------------------------------------------------------
# Add X11 OpenGL Support if requested
if(GEANT4_USE_OPENGL_X11)
geant4_module_sources(G4OpenGL
PUBLIC_HEADERS
G4OpenGLImmediateX.hh
G4OpenGLImmediateXViewer.hh
G4OpenGLStoredX.hh
PRIVATE_HEADERS
G4OpenGLImmediateXViewer.hh
G4OpenGLStoredXViewer.hh
G4OpenGLXViewer.hh
SOURCES
@@ -80,10 +73,11 @@ if(GEANT4_USE_XM)
geant4_module_sources(G4OpenGL
PUBLIC_HEADERS
G4OpenGLImmediateXm.hh
G4OpenGLImmediateXmViewer.hh
G4OpenGLStoredXm.hh
G4OpenGLStoredXmViewer.hh
G4OpenGLXm.hh
PRIVATE_HEADERS
G4OpenGLImmediateXmViewer.hh
G4OpenGLStoredXmViewer.hh
G4OpenGLXmBox.hh
G4OpenGLXmFourArrowButtons.hh
G4OpenGLXmFramedBox.hh
@@ -130,7 +124,7 @@ if(GEANT4_USE_XM)
# Special case of building Xm without X11
if(NOT GEANT4_USE_OPENGL_X11)
geant4_module_sources(G4OpenGL PUBLIC_HEADERS G4OpenGLXViewer.hh SOURCES G4OpenGLXViewer.cc)
geant4_module_sources(G4OpenGL PRIVATE_HEADERS G4OpenGLXViewer.hh SOURCES G4OpenGLXViewer.cc)
geant4_module_compile_definitions(G4OpenGL PRIVATE G4VIS_BUILD_OPENGLX_DRIVER)
endif()
@@ -140,16 +134,16 @@ if(GEANT4_USE_XM)
PRIVATE G4VIS_BUILD_OPENGLXM_DRIVER)
# Add in Xm and needed modules
geant4_module_link_libraries(G4OpenGL PUBLIC Motif::Xm PRIVATE G4UIimplementation)
geant4_module_link_libraries(G4OpenGL PRIVATE Motif::Xm G4UIimplementation)
endif()
# Common X11/Xm link libraries
if(GEANT4_USE_OPENGL_X11 OR GEANT4_USE_XM)
geant4_module_link_libraries(G4OpenGL PUBLIC X11::SM X11::ICE X11::X11 X11::Xext X11::Xmu)
geant4_module_link_libraries(G4OpenGL PRIVATE X11::SM X11::ICE X11::X11 X11::Xext X11::Xmu)
if(APPLE)
geant4_module_link_libraries(G4OpenGL PUBLIC XQuartzGL::GL)
geant4_module_link_libraries(G4OpenGL PRIVATE XQuartzGL::GL)
else()
geant4_module_link_libraries(G4OpenGL PUBLIC OpenGL::GL)
geant4_module_link_libraries(G4OpenGL PRIVATE OpenGL::GL)
endif()
endif()
@@ -159,12 +153,13 @@ if(GEANT4_USE_QT)
geant4_module_sources(G4OpenGL
PUBLIC_HEADERS
G4OpenGLImmediateQt.hh
G4OpenGLImmediateQtViewer.hh
G4OpenGLStoredQt.hh
G4OpenGLQt.hh
PRIVATE_HEADERS
G4OpenGLImmediateQtViewer.hh
G4OpenGLQtExportDialog.hh
G4OpenGLQtMovieDialog.hh
G4OpenGLQtViewer.hh
G4OpenGLStoredQt.hh
G4OpenGLStoredQtSceneHandler.hh
G4OpenGLStoredQtViewer.hh
SOURCES
@@ -185,10 +180,20 @@ if(GEANT4_USE_QT)
# Add in Qt libraries and geant4 modules
geant4_module_link_libraries(G4OpenGL
PUBLIC Qt${QT_VERSION_MAJOR}::OpenGL Qt${QT_VERSION_MAJOR}::Gui Qt${QT_VERSION_MAJOR}::Widgets OpenGL::GL
PRIVATE G4UIimplementation)
PRIVATE
G4UIimplementation
OpenGL::GL
Qt${QT_VERSION_MAJOR}::OpenGL
Qt${QT_VERSION_MAJOR}::Gui
Qt${QT_VERSION_MAJOR}::Widgets)
geant4_set_module_property(G4OpenGL PROPERTY AUTOMOC ON)
# Minor hack for MOC-ing. Qt's moc requires visibility of the private headers
# - Will not affect external consumers and should be minimal impact interanally
# as this is a leaf category
geant4_module_include_directories(G4OpenGL
PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/private>)
if(QT_VERSION_MAJOR GREATER 5)
geant4_module_link_libraries(G4OpenGL PRIVATE Qt${QT_VERSION_MAJOR}::OpenGLWidgets)
@@ -202,8 +207,9 @@ if(GEANT4_USE_OPENGL_WIN32)
geant4_module_sources(G4OpenGL
PUBLIC_HEADERS
G4OpenGLImmediateWin32.hh
G4OpenGLImmediateWin32Viewer.hh
G4OpenGLStoredWin32.hh
PRIVATE_HEADERS
G4OpenGLImmediateWin32Viewer.hh
G4OpenGLStoredWin32Viewer.hh
G4OpenGLWin32Viewer.hh
SOURCES
@@ -218,6 +224,6 @@ if(GEANT4_USE_OPENGL_WIN32)
PUBLIC G4VIS_USE_OPENGLWIN32
PRIVATE G4VIS_BUILD_OPENGLWIN32_DRIVER)
geant4_module_link_libraries(G4OpenGL PUBLIC OpenGL::GL)
geant4_module_link_libraries(G4OpenGL PRIVATE OpenGL::GL)
endif()
@@ -63,6 +63,7 @@ G4OpenGLImmediateQtViewer::~G4OpenGLImmediateQtViewer() {
}
void G4OpenGLImmediateQtViewer::Initialise() {
#if QT_VERSION < 0x060000
makeCurrent();
fQGLWidgetInitialiseCompleted = false;
@@ -79,6 +80,15 @@ void G4OpenGLImmediateQtViewer::Initialise() {
}
fQGLWidgetInitialiseCompleted = true;
#else
fQGLWidgetInitialiseCompleted = false;
CreateMainWindow (this,QString(GetName()));
if(G4QGLWidgetType::isValid()) { //G.Barrand: macOS: isValid() needed at startup.
makeCurrent();
glDrawBuffer (GL_BACK);
}
fQGLWidgetInitialiseCompleted = true;
#endif
}
void G4OpenGLImmediateQtViewer::initializeGL () {
@@ -106,6 +116,13 @@ void G4OpenGLImmediateQtViewer::initializeGL () {
void G4OpenGLImmediateQtViewer::DrawView() {
#if QT_VERSION < 0x060000
#else
if(IsGettingPickInfos()) {
paintGL();
return;
}
#endif
#ifdef G4MULTITHREADED
if (G4Threading::G4GetThreadId() == G4Threading::MASTER_ID) {
updateQWidget();
@@ -154,7 +171,11 @@ void G4OpenGLImmediateQtViewer::resizeGL(
,int aHeight)
{
if ((aWidth > 0) && (aHeight > 0)) {
#if QT_VERSION < 0x060000
ResizeWindow(aWidth,aHeight);
#else
ResizeWindow(devicePixelRatio()*aWidth,devicePixelRatio()*aHeight);
#endif
fHasToRepaint = sizeHasChanged();
}
}
@@ -162,7 +183,11 @@ void G4OpenGLImmediateQtViewer::resizeGL(
void G4OpenGLImmediateQtViewer::paintGL()
{
#if QT_VERSION < 0x060000
updateToolbarAndMouseContextMenu();
#else
//G.Barrand: don't do any change in the GUI here, just "paint" this widget!
#endif
if (fPaintEventLock) {
// return ;
@@ -175,6 +200,7 @@ void G4OpenGLImmediateQtViewer::paintGL()
return;
}
#if QT_VERSION < 0x060000
// DO NOT RESIZE IF SIZE HAS NOT CHANGE
if ( !fHasToRepaint) {
// L. Garnier : Trap to get the size with mac OSX 10.6 and Qt 4.6(devel)
@@ -197,6 +223,12 @@ void G4OpenGLImmediateQtViewer::paintGL()
}
}
}
#endif
#if QT_VERSION < 0x060000
#else
InitializeGLView ();
#endif
SetView();
@@ -261,6 +293,7 @@ void G4OpenGLImmediateQtViewer::contextMenuEvent(QContextMenuEvent *e)
G4manageContextMenuEvent(e);
}
#if QT_VERSION < 0x060000
void G4OpenGLImmediateQtViewer::paintEvent(QPaintEvent *) {
if (! fQGLWidgetInitialiseCompleted) {
return;
@@ -276,6 +309,7 @@ void G4OpenGLImmediateQtViewer::paintEvent(QPaintEvent *) {
#endif
}
}
#endif
void G4OpenGLImmediateQtViewer::updateQWidget() {
@@ -289,9 +323,14 @@ void G4OpenGLImmediateQtViewer::updateQWidget() {
fUpdateGLLock = true;
fHasToRepaint= true;
#if QT_VERSION < 0x060000
repaint();
updateViewerPropertiesTableWidget();
updateSceneTreeWidget();
#else
//G.Barrand: don't do any change in the GUI here, just ask to "paint" this widget!
update();
#endif
fUpdateGLLock= false;
}
@@ -100,17 +100,6 @@
#include "moc_G4OpenGLQtViewer.cpp"
#endif
namespace
{
G4Mutex mWaitForVisSubThreadQtOpenGLContextMoved = G4MUTEX_INITIALIZER;
G4Mutex mWaitForVisSubThreadQtOpenGLContextInitialized = G4MUTEX_INITIALIZER;
// avoid unused variable warning
#ifdef G4MULTITHREADED
G4Condition c1_VisSubThreadQtOpenGLContextInitialized = G4CONDITION_INITIALIZER;
G4Condition c2_VisSubThreadQtOpenGLContextMoved = G4CONDITION_INITIALIZER;
#endif
}
//////////////////////////////////////////////////////////////////////////////
void G4OpenGLQtViewer::CreateMainWindow (
G4QGLWidgetType* glWidget
@@ -127,7 +116,11 @@ void G4OpenGLQtViewer::CreateMainWindow (
G4Qt* interactorManager = G4Qt::getInstance ();
#if QT_VERSION < 0x060000
ResizeWindow(fVP.GetWindowSizeHintX(),fVP.GetWindowSizeHintY());
#else
ResizeWindow(glWidget->devicePixelRatio()*fVP.GetWindowSizeHintX(),glWidget->devicePixelRatio()*fVP.GetWindowSizeHintY());
#endif
// FIXME L.Garnier 9/11/09 Has to be check !!!
// Qt UI with Qt Vis
@@ -162,6 +155,10 @@ void G4OpenGLQtViewer::CreateMainWindow (
this,
SLOT(currentTabActivated(int)));
#if QT_VERSION < 0x060000
#else
createViewerPropertiesWidget();
#endif
}
createSceneTreeWidget();
@@ -275,12 +272,14 @@ G4OpenGLQtViewer::G4OpenGLQtViewer (
,fLastHighlightName(0)
,fIsDeleting(false)
{
lWaitForVisSubThreadQtOpenGLContextInitialized
= new G4AutoLock(mWaitForVisSubThreadQtOpenGLContextInitialized,
#ifdef G4MULTITHREADED
flWaitForVisSubThreadQtOpenGLContextInitialized
= new G4AutoLock(fmWaitForVisSubThreadQtOpenGLContextInitialized,
std::defer_lock);
lWaitForVisSubThreadQtOpenGLContextMoved
= new G4AutoLock(mWaitForVisSubThreadQtOpenGLContextMoved,
flWaitForVisSubThreadQtOpenGLContextMoved
= new G4AutoLock(fmWaitForVisSubThreadQtOpenGLContextMoved,
std::defer_lock);
#endif
// launch Qt if not
if (QCoreApplication::instance () == NULL) {
@@ -522,11 +521,14 @@ G4OpenGLQtViewer::~G4OpenGLQtViewer (
delete fTreeIconOpen;
delete fTreeIconClosed;
G4cout <<removeTempFolder().toStdString().c_str() <<G4endl;
delete lWaitForVisSubThreadQtOpenGLContextInitialized;
delete lWaitForVisSubThreadQtOpenGLContextMoved;
#if QT_VERSION < 0x060000
G4cout <<removeTempFolder().toStdString().c_str() <<G4endl; //G.Barrand: with Qt6, it crashes at exit if the viewer is in a detached dialog window.
#endif
#ifdef G4MULTITHREADED
delete flWaitForVisSubThreadQtOpenGLContextInitialized;
delete flWaitForVisSubThreadQtOpenGLContextMoved;
#endif
}
@@ -1266,6 +1268,12 @@ void G4OpenGLQtViewer::G4MousePressEvent(QMouseEvent *evnt)
*/
void G4OpenGLQtViewer::G4MouseReleaseEvent(QMouseEvent *evnt)
{
#if QT_VERSION < 0x060000
#else
{auto* qGLW = dynamic_cast<G4QGLWidgetType*> (fGLWidget) ;
if (qGLW) qGLW->makeCurrent();}
ResizeGLView();
#endif
GLint viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);
@@ -2707,6 +2715,91 @@ void G4OpenGLQtViewer::setCheckComponent(QTreeWidgetItem* item,bool check)
}
}
#if QT_VERSION < 0x060000
#else
//G.Barrand : from stackoverflow "How to render text with QOpenGLWidget":
static void transform_point(GLdouble out[4], const GLdouble m[16], const GLdouble in[4])
{
#define M(row,col) m[col*4+row]
out[0] =
M(0, 0) * in[0] + M(0, 1) * in[1] + M(0, 2) * in[2] + M(0, 3) * in[3];
out[1] =
M(1, 0) * in[0] + M(1, 1) * in[1] + M(1, 2) * in[2] + M(1, 3) * in[3];
out[2] =
M(2, 0) * in[0] + M(2, 1) * in[1] + M(2, 2) * in[2] + M(2, 3) * in[3];
out[3] =
M(3, 0) * in[0] + M(3, 1) * in[1] + M(3, 2) * in[2] + M(3, 3) * in[3];
#undef M
}
inline GLint project_point(GLdouble objx, GLdouble objy, GLdouble objz,
const GLdouble model[16], const GLdouble proj[16],
const GLint viewport[4],
GLdouble * winx, GLdouble * winy, GLdouble * winz)
{
GLdouble in[4], out[4];
in[0] = objx;
in[1] = objy;
in[2] = objz;
in[3] = 1.0;
transform_point(out, model, in);
transform_point(in, proj, out);
if (in[3] == 0.0)
return GL_FALSE;
in[0] /= in[3];
in[1] /= in[3];
in[2] /= in[3];
*winx = viewport[0] + (1 + in[0]) * viewport[2] / 2;
*winy = viewport[1] + (1 + in[1]) * viewport[3] / 2;
*winz = (1 + in[2]) / 2;
return GL_TRUE;
}
static void render_text(QOpenGLWidget& widget,
double world_x, double world_y, double world_z,
double offset_x, double offset_y,
const QFont& font,
const QColor& color,
const char* text)
{
GLdouble model[4][4];
glGetDoublev(GL_MODELVIEW_MATRIX, &model[0][0]);
GLdouble proj[4][4];
glGetDoublev(GL_PROJECTION_MATRIX, &proj[0][0]);
GLint view[4];
glGetIntegerv(GL_VIEWPORT, &view[0]);
GLdouble textPosX = 0, textPosY = 0, textPosZ = 0;
project_point(world_x, world_y, world_z,
&model[0][0], &proj[0][0], &view[0],
&textPosX, &textPosY, &textPosZ);
textPosX /= GLdouble(widget.devicePixelRatio());
textPosY /= GLdouble(widget.devicePixelRatio());
textPosY = GLdouble(widget.height()) - textPosY; // y is inverted
textPosX += offset_x;
textPosY += offset_y;
GLboolean GL_BLEND_enabled = glIsEnabled(GL_BLEND);
QPainter painter(&widget);
painter.setPen(color);
painter.setFont(font);
painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
painter.drawText(textPosX, textPosY, text);
painter.end();
if(GL_BLEND_enabled==GL_TRUE) {
::glEnable(GL_BLEND);
::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
}
#endif
void G4OpenGLQtViewer::DrawText(const G4Text& g4text)
{
@@ -2733,22 +2826,18 @@ void G4OpenGLQtViewer::DrawText(const G4Text& g4text)
font.setPointSizeF(size);
const G4Colour& c = fSceneHandler.GetTextColour(g4text);
glColor4d(c.GetRed(),c.GetGreen(),c.GetBlue(),c.GetAlpha());
G4Point3D position = g4text.GetPosition();
const G4String& textString = g4text.GetText();
const char* textCString = textString.c_str();
glRasterPos3d(position.x(),position.y(),position.z());
// Calculate move for centre and right adjustment
QFontMetrics* f = new QFontMetrics (font);
G4double span = f->boundingRect(textCString).width();
// Marked as such due to current un-use when building with Qt6
// See use of renderText at end of function.
[[maybe_unused]] G4double xmove = 0.;
[[maybe_unused]] G4double ymove = 0.;
G4double xmove = 0.;
G4double ymove = 0.;
switch (g4text.GetLayout()) {
case G4Text::left: break;
@@ -2760,6 +2849,9 @@ void G4OpenGLQtViewer::DrawText(const G4Text& g4text)
xmove += g4text.GetXOffset();
ymove += g4text.GetYOffset();
#if QT_VERSION < 0x060000
glColor4d(c.GetRed(),c.GetGreen(),c.GetBlue(),c.GetAlpha());
glRasterPos3d(position.x(),position.y(),position.z());
// xmove, ymove in pixels - or are they?
#ifdef __APPLE__
const G4double fudgeFactor = 2.;
@@ -2768,8 +2860,6 @@ void G4OpenGLQtViewer::DrawText(const G4Text& g4text)
#endif
xmove *= fudgeFactor;
ymove *= fudgeFactor;
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
qGLW->renderText
((position.x()+(2*xmove)/getWinWidth()),
(position.y()+(2*ymove)/getWinHeight()),
@@ -2777,7 +2867,14 @@ void G4OpenGLQtViewer::DrawText(const G4Text& g4text)
textCString,
font);
#else
// Not yet obvious how to do this in Qt6....
QColor color((int)(c.GetRed()*255),
(int)(c.GetGreen()*255),
(int)(c.GetBlue()*255),
(int)(c.GetAlpha()*255));
render_text(*qGLW,
position.x(),position.y(),position.z(),
xmove,ymove,
font,color,textCString);
#endif
}
}
@@ -4450,6 +4547,12 @@ void G4OpenGLQtViewer::updatePickInfosWidget(int aX, int aY) {
createPickInfosWidget();
}
#if QT_VERSION < 0x060000
#else
{auto* qGLW = dynamic_cast<G4QGLWidgetType*> (fGLWidget) ;
if (qGLW) qGLW->makeCurrent();}
ResizeGLView();
#endif
const std::vector < G4OpenGLViewerPickMap* > & pickMapVector = GetPickDetails(aX,aY);
// remove all previous widgets
@@ -4699,9 +4802,9 @@ void G4OpenGLQtViewer::DoneWithMasterThread()
// Called by Main Thread !
// Useful to avoid two vis thread at the same time
//G4MUTEXLOCK(&mWaitForVisSubThreadQtOpenGLContextInitialized);
if(!lWaitForVisSubThreadQtOpenGLContextInitialized->owns_lock())
lWaitForVisSubThreadQtOpenGLContextInitialized->lock();
//G4MUTEXLOCK(&fmWaitForVisSubThreadQtOpenGLContextInitialized);
if(!flWaitForVisSubThreadQtOpenGLContextInitialized->owns_lock())
flWaitForVisSubThreadQtOpenGLContextInitialized->lock();
}
void G4OpenGLQtViewer::SwitchToVisSubThread()
@@ -4717,15 +4820,15 @@ void G4OpenGLQtViewer::SwitchToVisSubThread()
SetQGLContextVisSubThread(QThread::currentThread());
// - Wait for the vis thread to set its QThread
G4CONDITIONBROADCAST(&c1_VisSubThreadQtOpenGLContextInitialized);
G4CONDITIONBROADCAST(&fc1_VisSubThreadQtOpenGLContextInitialized);
// a condition without a locked mutex is an undefined behavior.
// we check if the mutex owns the lock, and if not, we lock it
if(!lWaitForVisSubThreadQtOpenGLContextMoved->owns_lock())
lWaitForVisSubThreadQtOpenGLContextMoved->lock();
if(!flWaitForVisSubThreadQtOpenGLContextMoved->owns_lock())
flWaitForVisSubThreadQtOpenGLContextMoved->lock();
// Unlock the vis thread if it is Qt Viewer
G4CONDITIONWAIT(&c2_VisSubThreadQtOpenGLContextMoved,
lWaitForVisSubThreadQtOpenGLContextMoved);
G4CONDITIONWAIT(&fc2_VisSubThreadQtOpenGLContextMoved,
flWaitForVisSubThreadQtOpenGLContextMoved);
// make context current
qGLW->makeCurrent();
@@ -4756,9 +4859,9 @@ void G4OpenGLQtViewer::SwitchToMasterThread()
}
// Useful to avoid two vis thread at the same time
//G4MUTEXUNLOCK(&mWaitForVisSubThreadQtOpenGLContextInitialized);
if(lWaitForVisSubThreadQtOpenGLContextInitialized->owns_lock())
lWaitForVisSubThreadQtOpenGLContextInitialized->unlock();
//G4MUTEXUNLOCK(&fmWaitForVisSubThreadQtOpenGLContextInitialized);
if(flWaitForVisSubThreadQtOpenGLContextInitialized->owns_lock())
flWaitForVisSubThreadQtOpenGLContextInitialized->unlock();
qGLW->makeCurrent();
}
@@ -4774,12 +4877,12 @@ void G4OpenGLQtViewer::MovingToVisSubThread(){
// a condition without a locked mutex is an undefined behavior.
// we check if the mutex owns the lock, and if not, we lock it
if(!lWaitForVisSubThreadQtOpenGLContextInitialized->owns_lock())
lWaitForVisSubThreadQtOpenGLContextInitialized->lock();
if(!flWaitForVisSubThreadQtOpenGLContextInitialized->owns_lock())
flWaitForVisSubThreadQtOpenGLContextInitialized->lock();
// - Wait for the vis sub thread to set its QThread
G4CONDITIONWAIT(&c1_VisSubThreadQtOpenGLContextInitialized,
lWaitForVisSubThreadQtOpenGLContextInitialized);
G4CONDITIONWAIT(&fc1_VisSubThreadQtOpenGLContextInitialized,
flWaitForVisSubThreadQtOpenGLContextInitialized);
// Set current QThread for the way back
SetQGLContextMainThread(QThread::currentThread());
@@ -4788,7 +4891,7 @@ void G4OpenGLQtViewer::MovingToVisSubThread(){
qGLW->doneCurrent();
qGLW->context()->moveToThread(fQGLContextVisSubThread);
G4CONDITIONBROADCAST(&c2_VisSubThreadQtOpenGLContextMoved);
G4CONDITIONBROADCAST(&fc2_VisSubThreadQtOpenGLContextMoved);
}
#endif
@@ -71,6 +71,7 @@ G4OpenGLStoredQtViewer::~G4OpenGLStoredQtViewer() {
}
void G4OpenGLStoredQtViewer::Initialise() {
#if QT_VERSION < 0x060000
makeCurrent();
fQGLWidgetInitialiseCompleted = false;
@@ -87,6 +88,15 @@ void G4OpenGLStoredQtViewer::Initialise() {
}
fQGLWidgetInitialiseCompleted = true;
#else
fQGLWidgetInitialiseCompleted = false;
CreateMainWindow (this,QString(GetName()));
if(G4QGLWidgetType::isValid()) { //G.Barrand: macOS: isValid() needed at startup.
makeCurrent();
glDrawBuffer (GL_BACK);
}
fQGLWidgetInitialiseCompleted = true;
#endif
}
void G4OpenGLStoredQtViewer::initializeGL () {
@@ -208,7 +218,22 @@ G4bool G4OpenGLStoredQtViewer::TOSelected(size_t)
}
void G4OpenGLStoredQtViewer::DrawView () {
#if QT_VERSION < 0x060000
#else
if(IsGettingPickInfos()) {
paintGL();
return;
}
#endif
#if (QT_VERSION < 0x060000) || !defined(G4MULTITHREADED)
updateQWidget();
#else
if (G4Threading::G4GetThreadId() == G4Threading::MASTER_ID) {
updateQWidget();
} else {
update(); //G.Barrand: updateQWidget() induces a crash on run beamOn.
}
#endif
}
void G4OpenGLStoredQtViewer::ComputeView () {
@@ -284,7 +309,11 @@ void G4OpenGLStoredQtViewer::resizeGL(
{
// Set new size, it will be update when next Repaint()->SetView() called
if ((aWidth > 0) && (aHeight > 0)) {
#if QT_VERSION < 0x060000
ResizeWindow(aWidth,aHeight);
#else
ResizeWindow(devicePixelRatio()*aWidth,devicePixelRatio()*aHeight);
#endif
fHasToRepaint = sizeHasChanged();
}
}
@@ -297,7 +326,11 @@ void G4OpenGLStoredQtViewer::resizeGL(
void G4OpenGLStoredQtViewer::paintGL()
{
#if QT_VERSION < 0x060000
updateToolbarAndMouseContextMenu();
#else
//G.Barrand: don't do any change in the GUI here, just "paint" this widget!
#endif
if (fPaintEventLock) {
// return ;
@@ -311,6 +344,8 @@ void G4OpenGLStoredQtViewer::paintGL()
fPaintEventLock = false;
return;
}
#if QT_VERSION < 0x060000
// DO NOT RESIZE IF SIZE HAS NOT CHANGE :
// WHEN CLICK ON THE FRAME FOR EXAMPLE
// EXECEPT WHEN MOUSE MOVE EVENT
@@ -330,6 +365,13 @@ void G4OpenGLStoredQtViewer::paintGL()
return;
}
}
#endif
#if QT_VERSION < 0x060000
#else
InitializeGLView ();
#endif
// Ensure that we really draw the BACK buffer
glDrawBuffer (GL_BACK);
@@ -343,6 +385,7 @@ void G4OpenGLStoredQtViewer::paintGL()
fPaintEventLock = false;
}
#if QT_VERSION < 0x060000
void G4OpenGLStoredQtViewer::paintEvent(QPaintEvent *) {
if (! fQGLWidgetInitialiseCompleted) {
return;
@@ -362,6 +405,7 @@ void G4OpenGLStoredQtViewer::paintEvent(QPaintEvent *) {
#endif
}
}
#endif
void G4OpenGLStoredQtViewer::mousePressEvent(QMouseEvent *event)
{
@@ -430,10 +474,15 @@ void G4OpenGLStoredQtViewer::updateQWidget() {
// The widget's rendering context will become the current context and initializeGL()
// will be called if it hasn't already been called.
// Copies the back buffer of a double-buffered context to the front buffer.
#if QT_VERSION < 0x060000
repaint(); // will read scene tree state
// updateGL() // From J.Allison picking branch
updateViewerPropertiesTableWidget();
updateSceneTreeWidget();
#else
//G.Barrand: don't do any change in the GUI here, just ask to "paint" this widget!
update();
#endif
fUpdateGLLock = false;
}