Import Geant4 11.3.0 source tree
This commit is contained in:
@@ -6,6 +6,62 @@ It must **not** be used as a substitute for writing good git commit messages!
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
## 2024-09-13 John Allison (opengl-V11-02-09)
|
||||
- G4OpenGLStoredQtSceneHandler.cc:
|
||||
- G4OpenGLStoredQtSceneHandler::ClearStore():
|
||||
- Commented out some code related to the old scene tree. The old scene
|
||||
tree is currently (partially) disabled, but this code somehow affects
|
||||
the view in rare cases, e.g., after twinkling the volume does not return
|
||||
to its original colour. So I have disabled this, pending a review of
|
||||
the old scene tree.
|
||||
|
||||
## 2024-10-25 John Allison (opengl-V11-02-08)
|
||||
- G4OpenGLQtViewer.cc:
|
||||
- G4OpenGLQtViewer::currentTabActivated(): Fix compilation error, see Bug Report 2633.
|
||||
- Use .data().
|
||||
|
||||
## 2024-09-13 John Allison (opengl-V11-02-07)
|
||||
- G4OpenGLQtViewer.cc:
|
||||
- Comment out code that refers to the old scene tree because it adversely impacts
|
||||
the new scene tree.
|
||||
- I would like to extract the old scene tree code completely, but so far I have
|
||||
found it difficult, since it is so entangled with other code. So my efforts so
|
||||
far have been to bop problems on the head as they arise. Not satisfactory, I
|
||||
know, and I will continue to work on it.
|
||||
|
||||
## 2024-08-13 John Allison (opengl-V11-02-06)
|
||||
- G4OpenGLQtViewer:
|
||||
- Resolve the timing issues around switching to the vis sub-thread with the
|
||||
use of G4CONDITIONWAITLAMBDA.
|
||||
- Fix small memory leak in G4OpenGLQtViewer::DrawText.
|
||||
|
||||
## 2024-07-24 Guy Barrand (opengl-V11-02-05)
|
||||
- G4OpenGLImmediateQtViewer, G4OpenGLStoredQtViewer::ShowView: Qt6: do a:
|
||||
((QApplication*)G4Qt::getInstance ())->processEvents();
|
||||
so that a:
|
||||
/vis/viewer/interpolate viewfiles/movie-1
|
||||
produces truly an animation.
|
||||
|
||||
## 2024-07-12 Guy Barrand (opengl-V11-02-04)
|
||||
- G4OpenGLQtViewer: Qt6: implement ReadyToDraw(). It permits to avoid a crash in case
|
||||
of /run/beamOn in vis.mac at startup (especially on macOS).
|
||||
- G4OpenGLImmediateQtViewer, G4OpenGLStoredQtViewer: Qt5: in Initialise(), displace
|
||||
makeCurrent() after CreateMainWindow(). It avoids a crash in case of /run/beamOn
|
||||
in vis.mac at startup.
|
||||
- G4OpenGLQtViewer: Qt5, Qt6: in DoneWithVisSubThread(), SwitchToMasterThread() protect
|
||||
against a possible null qGLW->context(). It permits to avoid a crash in case of
|
||||
doing /run/beamOn in vis.mac at startup.
|
||||
- G4OpenGLQtViewer, G4OpenGLImmediateQtViewer, G4OpenGLStoredQtViewer: Qt6:
|
||||
remove unused fields: fHasToRepaint, fUpdateGLLock, fQGLWidgetInitialiseCompleted
|
||||
and fPaintEventLock.
|
||||
- G4OpenGLImmediateQtViewer, G4OpenGLStoredQtViewer: Qt6: remove no more needed
|
||||
initializeGL() and showEvent() methods.
|
||||
- G4OpenGLImmediateQtViewer, G4OpenGLStoredQtViewer: Qt6: displace setExportImageFormat("jpg")
|
||||
in Initialise().
|
||||
|
||||
## 2024-06-21 Ben Morgan (opengl-V11-02-03)
|
||||
- Use runtime checks for MT mode where possible.
|
||||
|
||||
## 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.
|
||||
|
||||
@@ -47,7 +47,9 @@ public:
|
||||
const G4String& name = "");
|
||||
~G4OpenGLImmediateQtViewer ();
|
||||
void Initialise ();
|
||||
#if QT_VERSION < 0x060000
|
||||
void initializeGL ();
|
||||
#endif
|
||||
void DrawView ();
|
||||
void resizeGL(int width,int height);
|
||||
void paintGL();
|
||||
@@ -66,7 +68,9 @@ public:
|
||||
}
|
||||
#endif
|
||||
protected:
|
||||
#if QT_VERSION < 0x060000
|
||||
void showEvent(QShowEvent * event );
|
||||
#endif
|
||||
void wheelEvent(QWheelEvent *event);
|
||||
void mousePressEvent(QMouseEvent *event);
|
||||
void mouseMoveEvent(QMouseEvent *event);
|
||||
|
||||
@@ -97,7 +97,17 @@ public:
|
||||
G4OpenGLQtViewer (G4OpenGLSceneHandler& scene);
|
||||
virtual ~G4OpenGLQtViewer ();
|
||||
#ifdef G4MULTITHREADED
|
||||
// In MT mode these functions are called in the following order for each run:
|
||||
// For switching threads in MT mode
|
||||
// Note: the order of calling of MovingToVisSubThread and SwitchToVisSubThread
|
||||
// is undefined, so we have to use mutexes to ensure required information,
|
||||
// namely the vis sub-thread address, is available before moving objects.
|
||||
// To summarise, the order of calling is
|
||||
// DoneWithMasterThread
|
||||
// MovingToVisSubThread ) or ( SwitchToVisSubThread
|
||||
// SwitchToVisSubThread ) ( MovingToVisSubThread
|
||||
// DoneWithVisSubThread
|
||||
// MovingToMasterThread
|
||||
// SwitchToMasterThread
|
||||
// Called on the master thread before starting the vis sub-thread.
|
||||
virtual void DoneWithMasterThread ();
|
||||
// Called on the master thread after starting the vis sub-thread.
|
||||
@@ -116,6 +126,7 @@ private:
|
||||
G4OpenGLQtViewer (const G4OpenGLQtViewer&);
|
||||
G4OpenGLQtViewer& operator= (const G4OpenGLQtViewer&);
|
||||
public:
|
||||
virtual G4bool ReadyToDraw();
|
||||
virtual void updateQWidget()=0;
|
||||
void updateSceneTreeWidget();
|
||||
void updateViewerPropertiesTableWidget();
|
||||
@@ -194,10 +205,12 @@ protected:
|
||||
void savePPMToTemp();
|
||||
int fRecordFrameNumber;
|
||||
|
||||
#if QT_VERSION < 0x060000
|
||||
bool fHasToRepaint;
|
||||
bool fUpdateGLLock;
|
||||
bool fQGLWidgetInitialiseCompleted;
|
||||
bool fPaintEventLock;
|
||||
#endif
|
||||
|
||||
// Flag to indicate that action was initiated by interaction (mouse
|
||||
// click) on the scene tree. It is used and reset in
|
||||
@@ -265,15 +278,6 @@ private:
|
||||
std::string parseSceneTreeElementAndSaveState(QTreeWidgetItem* item, unsigned int level);
|
||||
QString GetCommandParameterList (const G4UIcommand *aCommand);
|
||||
void changeColorAndTransparency(GLuint index, G4Color color);
|
||||
|
||||
#ifdef G4MULTITHREADED
|
||||
inline void SetQGLContextVisSubThread(QThread *th) {
|
||||
fQGLContextVisSubThread = th;
|
||||
}
|
||||
inline void SetQGLContextMainThread(QThread *th) {
|
||||
fQGLContextMainThread = th;
|
||||
}
|
||||
#endif
|
||||
|
||||
QMenu *fContextMenu;
|
||||
QPoint fLastPos1;
|
||||
@@ -386,12 +390,6 @@ private:
|
||||
#ifdef G4MULTITHREADED
|
||||
QThread* fQGLContextVisSubThread;
|
||||
QThread* fQGLContextMainThread;
|
||||
G4Mutex fmWaitForVisSubThreadQtOpenGLContextMoved;
|
||||
G4Mutex fmWaitForVisSubThreadQtOpenGLContextInitialized;
|
||||
G4Condition fc1_VisSubThreadQtOpenGLContextInitialized;
|
||||
G4Condition fc2_VisSubThreadQtOpenGLContextMoved;
|
||||
G4AutoLock* flWaitForVisSubThreadQtOpenGLContextInitialized;
|
||||
G4AutoLock* flWaitForVisSubThreadQtOpenGLContextMoved;
|
||||
#endif
|
||||
|
||||
public Q_SLOTS :
|
||||
|
||||
@@ -49,7 +49,9 @@ public:
|
||||
const G4String& name = "");
|
||||
~G4OpenGLStoredQtViewer ();
|
||||
void Initialise ();
|
||||
#if QT_VERSION < 0x060000
|
||||
void initializeGL ();
|
||||
#endif
|
||||
void DrawView ();
|
||||
void resizeGL(int width,int height);
|
||||
void paintGL();
|
||||
@@ -78,7 +80,9 @@ protected:
|
||||
G4bool POSelected(size_t POListIndex);
|
||||
G4bool TOSelected(size_t TOListIndex);
|
||||
|
||||
#if QT_VERSION < 0x060000
|
||||
void showEvent(QShowEvent * event );
|
||||
#endif
|
||||
void wheelEvent(QWheelEvent *event);
|
||||
void mousePressEvent(QMouseEvent *event);
|
||||
void mouseMoveEvent(QMouseEvent *event);
|
||||
|
||||
@@ -54,10 +54,8 @@ public:
|
||||
virtual ~G4OpenGLXViewer ();
|
||||
void SetView ();
|
||||
void ShowView ();
|
||||
#ifdef G4MULTITHREADED
|
||||
void SwitchToVisSubThread();
|
||||
void SwitchToMasterThread();
|
||||
#endif
|
||||
void DrawText(const G4Text&);
|
||||
|
||||
protected:
|
||||
@@ -82,9 +80,7 @@ protected:
|
||||
XSetWindowAttributes swa;
|
||||
GLXDrawable win;
|
||||
GLXContext cxMaster;
|
||||
#ifdef G4MULTITHREADED
|
||||
GLXContext cxVisSubThread;
|
||||
#endif
|
||||
XEvent event;
|
||||
G4int *attributeList,
|
||||
errorBase,
|
||||
|
||||
@@ -33,12 +33,12 @@
|
||||
#include "G4OpenGLImmediateSceneHandler.hh"
|
||||
|
||||
#include "G4ios.hh"
|
||||
#ifdef G4MULTITHREADED
|
||||
#include "G4Threading.hh"
|
||||
#endif
|
||||
#include <qapplication.h>
|
||||
#include <qtabwidget.h>
|
||||
|
||||
#if 0x060000 <= QT_VERSION
|
||||
#include "G4Qt.hh"
|
||||
#endif
|
||||
|
||||
G4OpenGLImmediateQtViewer::G4OpenGLImmediateQtViewer
|
||||
(G4OpenGLImmediateSceneHandler& sceneHandler,
|
||||
@@ -48,6 +48,7 @@ G4OpenGLImmediateQtViewer::G4OpenGLImmediateQtViewer
|
||||
G4OpenGLQtViewer (sceneHandler),
|
||||
G4OpenGLImmediateViewer (sceneHandler)
|
||||
{
|
||||
#if QT_VERSION < 0x060000
|
||||
fQGLWidgetInitialiseCompleted = false;
|
||||
|
||||
setFocusPolicy(Qt::StrongFocus); // enable keybord events
|
||||
@@ -56,19 +57,20 @@ G4OpenGLImmediateQtViewer::G4OpenGLImmediateQtViewer
|
||||
fUpdateGLLock = false;
|
||||
|
||||
if (fViewId < 0) return; // In case error in base class instantiation.
|
||||
#else
|
||||
setFocusPolicy(Qt::StrongFocus); // enable keybord events
|
||||
#endif
|
||||
}
|
||||
|
||||
G4OpenGLImmediateQtViewer::~G4OpenGLImmediateQtViewer() {
|
||||
// makeCurrent(); // Not sure why this - commented out 12-Apr-2021 JA
|
||||
}
|
||||
G4OpenGLImmediateQtViewer::~G4OpenGLImmediateQtViewer() {}
|
||||
|
||||
void G4OpenGLImmediateQtViewer::Initialise() {
|
||||
#if QT_VERSION < 0x060000
|
||||
makeCurrent();
|
||||
|
||||
fQGLWidgetInitialiseCompleted = false;
|
||||
CreateMainWindow (this,QString(GetName()));
|
||||
|
||||
makeCurrent();
|
||||
glDrawBuffer (GL_BACK);
|
||||
|
||||
// set the good tab active
|
||||
@@ -81,16 +83,13 @@ 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;
|
||||
// Set jpg as default export format for Qt viewer
|
||||
setExportImageFormat("jpg");
|
||||
#endif
|
||||
}
|
||||
|
||||
#if QT_VERSION < 0x060000
|
||||
void G4OpenGLImmediateQtViewer::initializeGL () {
|
||||
|
||||
InitializeGLView ();
|
||||
@@ -113,6 +112,7 @@ void G4OpenGLImmediateQtViewer::initializeGL () {
|
||||
// Set jpg as default export format for Qt viewer
|
||||
setExportImageFormat("jpg");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void G4OpenGLImmediateQtViewer::DrawView() {
|
||||
@@ -123,22 +123,20 @@ void G4OpenGLImmediateQtViewer::DrawView() {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
#ifdef G4MULTITHREADED
|
||||
if (G4Threading::G4GetThreadId() == G4Threading::MASTER_ID) {
|
||||
if (G4Threading::IsMasterThread()) {
|
||||
updateQWidget();
|
||||
}
|
||||
#else
|
||||
updateQWidget();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void G4OpenGLImmediateQtViewer::ComputeView () {
|
||||
|
||||
#if QT_VERSION < 0x060000
|
||||
makeCurrent();
|
||||
// If a double buffer context has been forced upon us, ignore the
|
||||
// back buffer for this OpenGLImmediate view.
|
||||
// glDrawBuffer (GL_FRONT);
|
||||
#endif
|
||||
|
||||
G4ViewParameters::DrawingStyle dstyle = GetViewParameters().GetDrawingStyle();
|
||||
|
||||
@@ -160,7 +158,9 @@ void G4OpenGLImmediateQtViewer::ComputeView () {
|
||||
savePPMToTemp();
|
||||
}
|
||||
|
||||
#if QT_VERSION < 0x060000
|
||||
fHasToRepaint = true;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -173,10 +173,10 @@ void G4OpenGLImmediateQtViewer::resizeGL(
|
||||
if ((aWidth > 0) && (aHeight > 0)) {
|
||||
#if QT_VERSION < 0x060000
|
||||
ResizeWindow(aWidth,aHeight);
|
||||
fHasToRepaint = sizeHasChanged();
|
||||
#else
|
||||
ResizeWindow(devicePixelRatio()*aWidth,devicePixelRatio()*aHeight);
|
||||
#endif
|
||||
fHasToRepaint = sizeHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,6 +189,7 @@ void G4OpenGLImmediateQtViewer::paintGL()
|
||||
//G.Barrand: don't do any change in the GUI here, just "paint" this widget!
|
||||
#endif
|
||||
|
||||
#if QT_VERSION < 0x060000
|
||||
if (fPaintEventLock) {
|
||||
// return ;
|
||||
}
|
||||
@@ -200,7 +201,6 @@ 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)
|
||||
@@ -223,11 +223,14 @@ void G4OpenGLImmediateQtViewer::paintGL()
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
if ((getWinWidth() == 0) && (getWinHeight() == 0)) return; //G.Barrand: needed?
|
||||
#endif
|
||||
|
||||
#if QT_VERSION < 0x060000
|
||||
#else
|
||||
InitializeGLView ();
|
||||
glDrawBuffer (GL_BACK);
|
||||
#endif
|
||||
|
||||
SetView();
|
||||
@@ -235,9 +238,11 @@ void G4OpenGLImmediateQtViewer::paintGL()
|
||||
ClearView (); //ok, put the background correct
|
||||
ComputeView();
|
||||
|
||||
#if QT_VERSION < 0x060000
|
||||
fHasToRepaint = false; // could be set to false by ComputeView
|
||||
|
||||
fPaintEventLock = false;
|
||||
#endif
|
||||
}
|
||||
|
||||
void G4OpenGLImmediateQtViewer::mousePressEvent(QMouseEvent *event)
|
||||
@@ -260,13 +265,14 @@ void G4OpenGLImmediateQtViewer::wheelEvent (QWheelEvent * event)
|
||||
G4wheelEvent(event);
|
||||
}
|
||||
|
||||
#if QT_VERSION < 0x060000
|
||||
void G4OpenGLImmediateQtViewer::showEvent (QShowEvent *)
|
||||
{
|
||||
if (fQGLWidgetInitialiseCompleted) {
|
||||
fHasToRepaint = true;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This function was build in order to make a zoom on double clic event.
|
||||
@@ -313,6 +319,7 @@ void G4OpenGLImmediateQtViewer::paintEvent(QPaintEvent *) {
|
||||
|
||||
|
||||
void G4OpenGLImmediateQtViewer::updateQWidget() {
|
||||
#if QT_VERSION < 0x060000
|
||||
if (fUpdateGLLock) {
|
||||
return;
|
||||
}
|
||||
@@ -323,23 +330,25 @@ void G4OpenGLImmediateQtViewer::updateQWidget() {
|
||||
|
||||
fUpdateGLLock = true;
|
||||
fHasToRepaint= true;
|
||||
#if QT_VERSION < 0x060000
|
||||
repaint();
|
||||
updateViewerPropertiesTableWidget();
|
||||
updateSceneTreeWidget();
|
||||
fUpdateGLLock= false;
|
||||
#else
|
||||
//if (!isCurrentWidget()) return; //G.Barrand: Qt must know if it has to activate paintGL() if the widget is not visible.
|
||||
//G.Barrand: don't do any change in the GUI here, just ask to "paint" this widget!
|
||||
update();
|
||||
#endif
|
||||
fUpdateGLLock= false;
|
||||
}
|
||||
|
||||
|
||||
void G4OpenGLImmediateQtViewer::ShowView (
|
||||
)
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
||||
void G4OpenGLImmediateQtViewer::ShowView ()
|
||||
{
|
||||
#if QT_VERSION < 0x060000
|
||||
fHasToRepaint = true;
|
||||
activateWindow();
|
||||
#else
|
||||
activateWindow();
|
||||
((QApplication*)G4Qt::getInstance ())->processEvents();
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -112,9 +112,6 @@ void G4OpenGLQtViewer::CreateMainWindow (
|
||||
if(fGLWidget) return; //Done.
|
||||
|
||||
fGLWidget = glWidget ;
|
||||
// fGLWidget->makeCurrent();
|
||||
|
||||
G4Qt* interactorManager = G4Qt::getInstance ();
|
||||
|
||||
#if QT_VERSION < 0x060000
|
||||
ResizeWindow(fVP.GetWindowSizeHintX(),fVP.GetWindowSizeHintY());
|
||||
@@ -144,6 +141,7 @@ void G4OpenGLQtViewer::CreateMainWindow (
|
||||
bool isTabbedView = false;
|
||||
if ( fUiQt) {
|
||||
if (!fBatchMode) {
|
||||
G4Qt* interactorManager = G4Qt::getInstance ();
|
||||
if (!interactorManager->IsExternalApp()) {
|
||||
// INIT size
|
||||
fWinSize_x = fVP.GetWindowSizeHintX();
|
||||
@@ -272,15 +270,6 @@ G4OpenGLQtViewer::G4OpenGLQtViewer (
|
||||
,fLastHighlightName(0)
|
||||
,fIsDeleting(false)
|
||||
{
|
||||
#ifdef G4MULTITHREADED
|
||||
flWaitForVisSubThreadQtOpenGLContextInitialized
|
||||
= new G4AutoLock(fmWaitForVisSubThreadQtOpenGLContextInitialized,
|
||||
std::defer_lock);
|
||||
flWaitForVisSubThreadQtOpenGLContextMoved
|
||||
= new G4AutoLock(fmWaitForVisSubThreadQtOpenGLContextMoved,
|
||||
std::defer_lock);
|
||||
#endif
|
||||
|
||||
// launch Qt if not
|
||||
if (QCoreApplication::instance () == NULL) {
|
||||
fBatchMode = true;
|
||||
@@ -525,12 +514,18 @@ G4OpenGLQtViewer::~G4OpenGLQtViewer (
|
||||
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
|
||||
}
|
||||
|
||||
G4bool G4OpenGLQtViewer::ReadyToDraw() {
|
||||
#if QT_VERSION < 0x060000
|
||||
return true;
|
||||
#else
|
||||
if(!fGLWidget) return false;
|
||||
auto* qGLW = dynamic_cast<G4QGLWidgetType*>(fGLWidget);
|
||||
if (!qGLW) return false;
|
||||
return qGLW->isValid();
|
||||
#endif
|
||||
}
|
||||
|
||||
//
|
||||
// Create a popup menu for the widget. This menu is activated by right-mouse click
|
||||
@@ -2416,8 +2411,6 @@ QWidget *G4OpenGLQtViewer::getParentWidget()
|
||||
{
|
||||
// launch Qt if not
|
||||
G4Qt* interactorManager = G4Qt::getInstance ();
|
||||
// G4UImanager* UI =
|
||||
// G4UImanager::GetUIpointer();
|
||||
|
||||
bool found = false;
|
||||
QDialog* dialog = NULL;
|
||||
@@ -2815,9 +2808,7 @@ void G4OpenGLQtViewer::DrawText(const G4Text& g4text)
|
||||
|
||||
if (!fGLWidget) return;
|
||||
|
||||
#ifdef G4MULTITHREADED
|
||||
if (G4Threading::G4GetThreadId() != G4Threading::MASTER_ID) return;
|
||||
#endif
|
||||
if (!G4Threading::IsMasterThread()) return;
|
||||
|
||||
G4VSceneHandler::MarkerSizeType sizeType;
|
||||
G4double size = fSceneHandler.GetMarkerSize(g4text,sizeType);
|
||||
@@ -2833,8 +2824,8 @@ void G4OpenGLQtViewer::DrawText(const G4Text& g4text)
|
||||
const char* textCString = textString.c_str();
|
||||
|
||||
// Calculate move for centre and right adjustment
|
||||
QFontMetrics* f = new QFontMetrics (font);
|
||||
G4double span = f->boundingRect(textCString).width();
|
||||
QFontMetrics f(font);
|
||||
G4double span = f.boundingRect(textCString).width();
|
||||
|
||||
G4double xmove = 0.;
|
||||
G4double ymove = 0.;
|
||||
@@ -4714,10 +4705,10 @@ void G4OpenGLQtViewer::toggleSceneTreeComponentPickingCout(int pickItem) {
|
||||
|
||||
|
||||
void G4OpenGLQtViewer::currentTabActivated(int currentTab) {
|
||||
if (fUiQt->GetViewerTabWidget()->tabText(currentTab) == GetName()) {
|
||||
if (fUiQt->GetViewerTabWidget()->tabText(currentTab) == GetName().data()) {
|
||||
createViewerPropertiesWidget();
|
||||
createPickInfosWidget();
|
||||
createSceneTreeWidget();
|
||||
// createPickInfosWidget(); // Causes a /vis/set/touchable command to do with...
|
||||
// createSceneTreeWidget(); // ...this old scene tree widget (no longer used)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4797,101 +4788,100 @@ QString G4OpenGLQtViewer::GetCommandParameterList (
|
||||
|
||||
#ifdef G4MULTITHREADED
|
||||
|
||||
namespace {
|
||||
G4Mutex visSubThreadMutex = G4MUTEX_INITIALIZER;
|
||||
G4Condition waitForVisSubThreadInitialized = G4CONDITION_INITIALIZER;
|
||||
G4bool visSubThreadEstablished = false;
|
||||
G4bool qObjectsSwitched = false;
|
||||
G4QGLWidgetType* qGLWidget = nullptr;
|
||||
}
|
||||
|
||||
void G4OpenGLQtViewer::DoneWithMasterThread()
|
||||
{
|
||||
// Called by Main Thread !
|
||||
|
||||
// Useful to avoid two vis thread at the same time
|
||||
//G4MUTEXLOCK(&fmWaitForVisSubThreadQtOpenGLContextInitialized);
|
||||
if(!flWaitForVisSubThreadQtOpenGLContextInitialized->owns_lock())
|
||||
flWaitForVisSubThreadQtOpenGLContextInitialized->lock();
|
||||
// Initialise and check qGLWidget - no need to check in subsequent functions
|
||||
qGLWidget = dynamic_cast<G4QGLWidgetType*>(fGLWidget);
|
||||
if (qGLWidget == nullptr) return;
|
||||
|
||||
// Done with master thread
|
||||
qGLWidget->doneCurrent();
|
||||
|
||||
// Set current QThread for the way back
|
||||
fQGLContextMainThread = QThread::currentThread();
|
||||
}
|
||||
|
||||
void G4OpenGLQtViewer::MovingToVisSubThread()
|
||||
{
|
||||
// Still on master thread but vis thread has been launched
|
||||
|
||||
if (qGLWidget == nullptr) return;
|
||||
|
||||
// Wait until SwitchToVisSubThread has found vis sub-thread QThread
|
||||
{
|
||||
G4AutoLock lock(&visSubThreadMutex);
|
||||
G4CONDITIONWAITLAMBDA(&waitForVisSubThreadInitialized, &lock, []{return visSubThreadEstablished;})
|
||||
}
|
||||
|
||||
// Move stuff to sub-thread
|
||||
if(qGLWidget->context()) qGLWidget->context()->moveToThread(fQGLContextVisSubThread);
|
||||
|
||||
// Inform sub-thread
|
||||
G4AutoLock lock(&visSubThreadMutex);
|
||||
qObjectsSwitched = true;
|
||||
lock.unlock();
|
||||
G4CONDITIONBROADCAST(&waitForVisSubThreadInitialized);
|
||||
}
|
||||
|
||||
void G4OpenGLQtViewer::SwitchToVisSubThread()
|
||||
{
|
||||
// Called by VisSub Thread !
|
||||
|
||||
auto qGLW = dynamic_cast<G4QGLWidgetType*> (fGLWidget) ;
|
||||
if (! qGLW) {
|
||||
return;
|
||||
}
|
||||
if (qGLWidget == nullptr) return;
|
||||
|
||||
// Set the current QThread to its static variable
|
||||
SetQGLContextVisSubThread(QThread::currentThread());
|
||||
fQGLContextVisSubThread = QThread::currentThread();
|
||||
|
||||
// - Wait for the vis thread to set its QThread
|
||||
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(!flWaitForVisSubThreadQtOpenGLContextMoved->owns_lock())
|
||||
flWaitForVisSubThreadQtOpenGLContextMoved->lock();
|
||||
// Let MovingToVisSubThread know we have the QThread
|
||||
{
|
||||
G4AutoLock lock(&visSubThreadMutex);
|
||||
visSubThreadEstablished = true;
|
||||
G4CONDITIONBROADCAST(&waitForVisSubThreadInitialized);
|
||||
}
|
||||
|
||||
// Unlock the vis thread if it is Qt Viewer
|
||||
G4CONDITIONWAIT(&fc2_VisSubThreadQtOpenGLContextMoved,
|
||||
flWaitForVisSubThreadQtOpenGLContextMoved);
|
||||
// Wait until MovingToVisSubThread has moved stuff
|
||||
{
|
||||
G4AutoLock lock(&visSubThreadMutex);
|
||||
G4CONDITIONWAITLAMBDA(&waitForVisSubThreadInitialized, &lock, []{return qObjectsSwitched;})
|
||||
}
|
||||
|
||||
// make context current
|
||||
qGLW->makeCurrent();
|
||||
qGLWidget->makeCurrent();
|
||||
}
|
||||
|
||||
void G4OpenGLQtViewer::DoneWithVisSubThread()
|
||||
{
|
||||
// Called by vis sub thread
|
||||
auto qGLW = dynamic_cast<G4QGLWidgetType*> (fGLWidget) ;
|
||||
if (! qGLW) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (qGLWidget == nullptr) return;
|
||||
|
||||
// finish with this vis sub thread context
|
||||
qGLW->doneCurrent();
|
||||
qGLWidget->doneCurrent();
|
||||
|
||||
// and move it back to the main thread
|
||||
qGLW->context()->moveToThread(fQGLContextMainThread);
|
||||
// and move stuff back to the main thread
|
||||
if(qGLWidget->context()) qGLWidget->context()->moveToThread(fQGLContextMainThread);
|
||||
}
|
||||
|
||||
void G4OpenGLQtViewer::SwitchToMasterThread()
|
||||
{
|
||||
// Called by VisSub Thread !
|
||||
// Called by master Thread !
|
||||
|
||||
auto qGLW = dynamic_cast<G4QGLWidgetType*> (fGLWidget) ;
|
||||
if (! qGLW) {
|
||||
return;
|
||||
}
|
||||
if (qGLWidget == nullptr) return;
|
||||
|
||||
// Useful to avoid two vis thread at the same time
|
||||
//G4MUTEXUNLOCK(&fmWaitForVisSubThreadQtOpenGLContextInitialized);
|
||||
if(flWaitForVisSubThreadQtOpenGLContextInitialized->owns_lock())
|
||||
flWaitForVisSubThreadQtOpenGLContextInitialized->unlock();
|
||||
qGLWidget->makeCurrent();
|
||||
|
||||
qGLW->makeCurrent();
|
||||
}
|
||||
|
||||
|
||||
void G4OpenGLQtViewer::MovingToVisSubThread(){
|
||||
// Called by Main Thread !
|
||||
|
||||
auto qGLW = dynamic_cast<G4QGLWidgetType*> (fGLWidget) ;
|
||||
if (! qGLW) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 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(!flWaitForVisSubThreadQtOpenGLContextInitialized->owns_lock())
|
||||
flWaitForVisSubThreadQtOpenGLContextInitialized->lock();
|
||||
|
||||
// - Wait for the vis sub thread to set its QThread
|
||||
G4CONDITIONWAIT(&fc1_VisSubThreadQtOpenGLContextInitialized,
|
||||
flWaitForVisSubThreadQtOpenGLContextInitialized);
|
||||
|
||||
// Set current QThread for the way back
|
||||
SetQGLContextMainThread(QThread::currentThread());
|
||||
|
||||
// finish with this main thread context
|
||||
qGLW->doneCurrent();
|
||||
qGLW->context()->moveToThread(fQGLContextVisSubThread);
|
||||
|
||||
G4CONDITIONBROADCAST(&fc2_VisSubThreadQtOpenGLContextMoved);
|
||||
visSubThreadEstablished = false;
|
||||
qObjectsSwitched = false;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -134,12 +134,17 @@ void G4OpenGLStoredQtSceneHandler::ClearStore () {
|
||||
|
||||
//G4cout << "G4OpenGLStoredQtSceneHandler::ClearStore" << G4endl;
|
||||
|
||||
G4OpenGLStoredSceneHandler::ClearStore (); // Sets need kernel visit, etc.
|
||||
// Should recreate the tree
|
||||
G4OpenGLQtViewer* pGLQtViewer = dynamic_cast<G4OpenGLQtViewer*>(fpViewer);
|
||||
if ( pGLQtViewer ) {
|
||||
pGLQtViewer->clearTreeWidget();
|
||||
}
|
||||
G4OpenGLStoredSceneHandler::ClearStore ();
|
||||
|
||||
// Not needed - the old scene tree is currently (partially) disabled - but
|
||||
// this code somehow affects the view in rare cases, e.g., after twinkling
|
||||
// the volume does not return to its original colour. So I have disabled
|
||||
// this, pending a review of the old scene tree. JA 31/10/24
|
||||
// // Should recreate the tree
|
||||
// G4OpenGLQtViewer* pGLQtViewer = dynamic_cast<G4OpenGLQtViewer*>(fpViewer);
|
||||
// if ( pGLQtViewer ) {
|
||||
// pGLQtViewer->clearTreeWidget();
|
||||
// }
|
||||
}
|
||||
|
||||
void G4OpenGLStoredQtSceneHandler::ClearTransientStore () {
|
||||
|
||||
@@ -33,10 +33,11 @@
|
||||
|
||||
#include "G4OpenGLStoredSceneHandler.hh"
|
||||
#include "G4ios.hh"
|
||||
#ifdef G4MULTITHREADED
|
||||
#include "G4Threading.hh"
|
||||
#endif
|
||||
#include "G4UIQt.hh"
|
||||
#if 0x060000 <= QT_VERSION
|
||||
#include "G4Qt.hh"
|
||||
#endif
|
||||
|
||||
#include <qapplication.h>
|
||||
#include <qtabwidget.h>
|
||||
@@ -52,6 +53,7 @@ G4OpenGLStoredQtViewer::G4OpenGLStoredQtViewer
|
||||
{
|
||||
if (fViewId < 0) return; // In case error in base class instantiation.
|
||||
|
||||
#if QT_VERSION < 0x060000
|
||||
fQGLWidgetInitialiseCompleted = false;
|
||||
|
||||
// Indicates that the widget has no background, i.e. when the widget receives paint events, the background is not automatically repainted. Note: Unlike WA_OpaquePaintEvent, newly exposed areas are never filled with the background (e.g., after showing a window for the first time the user can see "through" it until the application processes the paint events). This flag is set or cleared by the widget's author.
|
||||
@@ -61,22 +63,23 @@ G4OpenGLStoredQtViewer::G4OpenGLStoredQtViewer
|
||||
fHasToRepaint = false;
|
||||
fPaintEventLock = false;
|
||||
fUpdateGLLock = false;
|
||||
#else
|
||||
// Indicates that the widget has no background, i.e. when the widget receives paint events, the background is not automatically repainted. Note: Unlike WA_OpaquePaintEvent, newly exposed areas are never filled with the background (e.g., after showing a window for the first time the user can see "through" it until the application processes the paint events). This flag is set or cleared by the widget's author.
|
||||
G4QGLWidgetType::setAttribute (Qt::WA_NoSystemBackground);
|
||||
|
||||
setFocusPolicy(Qt::StrongFocus); // enable keybord events
|
||||
#endif
|
||||
}
|
||||
|
||||
G4OpenGLStoredQtViewer::~G4OpenGLStoredQtViewer() {
|
||||
// makeCurrent(); // Not sure why this - commented out 12-Apr-2021 JA
|
||||
// this is connect to the Dialog for deleting it properly
|
||||
// when close event.
|
||||
// ((QDialog*)window())->reject();
|
||||
}
|
||||
G4OpenGLStoredQtViewer::~G4OpenGLStoredQtViewer() {}
|
||||
|
||||
void G4OpenGLStoredQtViewer::Initialise() {
|
||||
#if QT_VERSION < 0x060000
|
||||
makeCurrent();
|
||||
|
||||
fQGLWidgetInitialiseCompleted = false;
|
||||
CreateMainWindow (this,QString(GetName()));
|
||||
|
||||
makeCurrent();
|
||||
glDrawBuffer (GL_BACK);
|
||||
|
||||
// set the good tab active
|
||||
@@ -89,16 +92,13 @@ 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;
|
||||
// Set jpg as default export format for Qt viewer
|
||||
setExportImageFormat("jpg");
|
||||
#endif
|
||||
}
|
||||
|
||||
#if QT_VERSION < 0x060000
|
||||
void G4OpenGLStoredQtViewer::initializeGL () {
|
||||
|
||||
InitializeGLView ();
|
||||
@@ -115,6 +115,7 @@ void G4OpenGLStoredQtViewer::initializeGL () {
|
||||
// Set jpg as default export format for Qt viewer
|
||||
setExportImageFormat("jpg");
|
||||
}
|
||||
#endif
|
||||
|
||||
G4bool G4OpenGLStoredQtViewer::CompareForKernelVisit(G4ViewParameters& lastVP)
|
||||
{
|
||||
@@ -228,7 +229,7 @@ void G4OpenGLStoredQtViewer::DrawView () {
|
||||
#if (QT_VERSION < 0x060000) || !defined(G4MULTITHREADED)
|
||||
updateQWidget();
|
||||
#else
|
||||
if (G4Threading::G4GetThreadId() == G4Threading::MASTER_ID) {
|
||||
if (G4Threading::IsMasterThread()) {
|
||||
updateQWidget();
|
||||
} else {
|
||||
update(); //G.Barrand: updateQWidget() induces a crash on run beamOn.
|
||||
@@ -238,7 +239,10 @@ void G4OpenGLStoredQtViewer::DrawView () {
|
||||
|
||||
void G4OpenGLStoredQtViewer::ComputeView () {
|
||||
|
||||
#if QT_VERSION < 0x060000
|
||||
makeCurrent();
|
||||
#endif
|
||||
|
||||
G4ViewParameters::DrawingStyle dstyle = GetViewParameters().GetDrawingStyle();
|
||||
|
||||
//Make sure current viewer is attached and clean...
|
||||
@@ -296,7 +300,9 @@ void G4OpenGLStoredQtViewer::ComputeView () {
|
||||
savePPMToTemp();
|
||||
}
|
||||
|
||||
#if QT_VERSION < 0x060000
|
||||
fHasToRepaint = true;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -311,10 +317,10 @@ void G4OpenGLStoredQtViewer::resizeGL(
|
||||
if ((aWidth > 0) && (aHeight > 0)) {
|
||||
#if QT_VERSION < 0x060000
|
||||
ResizeWindow(aWidth,aHeight);
|
||||
fHasToRepaint = sizeHasChanged();
|
||||
#else
|
||||
ResizeWindow(devicePixelRatio()*aWidth,devicePixelRatio()*aHeight);
|
||||
#endif
|
||||
fHasToRepaint = sizeHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -332,6 +338,7 @@ void G4OpenGLStoredQtViewer::paintGL()
|
||||
//G.Barrand: don't do any change in the GUI here, just "paint" this widget!
|
||||
#endif
|
||||
|
||||
#if QT_VERSION < 0x060000
|
||||
if (fPaintEventLock) {
|
||||
// return ;
|
||||
}
|
||||
@@ -345,7 +352,6 @@ void G4OpenGLStoredQtViewer::paintGL()
|
||||
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
|
||||
@@ -365,6 +371,8 @@ void G4OpenGLStoredQtViewer::paintGL()
|
||||
return;
|
||||
}
|
||||
}
|
||||
#else
|
||||
if ((getWinWidth() == 0) && (getWinHeight() == 0)) return; //G.Barrand: needed?
|
||||
#endif
|
||||
|
||||
#if QT_VERSION < 0x060000
|
||||
@@ -380,9 +388,11 @@ void G4OpenGLStoredQtViewer::paintGL()
|
||||
ClearView (); //ok, put the background correct
|
||||
ComputeView();
|
||||
|
||||
#if QT_VERSION < 0x060000
|
||||
fHasToRepaint = false;
|
||||
|
||||
fPaintEventLock = false;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if QT_VERSION < 0x060000
|
||||
@@ -427,12 +437,14 @@ void G4OpenGLStoredQtViewer::wheelEvent (QWheelEvent * event)
|
||||
G4wheelEvent(event);
|
||||
}
|
||||
|
||||
#if QT_VERSION < 0x060000
|
||||
void G4OpenGLStoredQtViewer::showEvent (QShowEvent *)
|
||||
{
|
||||
if (fQGLWidgetInitialiseCompleted) {
|
||||
fHasToRepaint = true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This function was build in order to make a zoom on double clic event.
|
||||
@@ -460,6 +472,7 @@ void G4OpenGLStoredQtViewer::contextMenuEvent(QContextMenuEvent *e)
|
||||
}
|
||||
|
||||
void G4OpenGLStoredQtViewer::updateQWidget() {
|
||||
#if QT_VERSION < 0x060000
|
||||
if (fUpdateGLLock) {
|
||||
return;
|
||||
}
|
||||
@@ -474,34 +487,24 @@ 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();
|
||||
fUpdateGLLock = false;
|
||||
#else
|
||||
//if (!isCurrentWidget()) return; //G.Barrand: Qt must know if it has to activate paintGL() if the widget is not visible.
|
||||
//G.Barrand: don't do any change in the GUI here, just ask to "paint" this widget!
|
||||
update();
|
||||
#endif
|
||||
fUpdateGLLock = false;
|
||||
}
|
||||
|
||||
void G4OpenGLStoredQtViewer::ShowView (
|
||||
)
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
||||
void G4OpenGLStoredQtViewer::ShowView ()
|
||||
{
|
||||
// glFlush (); // Tentativley offered by JA 29/04/16.
|
||||
|
||||
// Some X servers fail to draw all trajectories, particularly Mac
|
||||
// XQuartz. Revisit this at a future date. Meanwhile, issue an
|
||||
// extra...
|
||||
// ClearView(); // Necessary? JA 29/04/16
|
||||
// DrawView(); // Necessary? JA 29/04/16
|
||||
activateWindow();
|
||||
// glFlush(); // NO NEED and as drawView will already cause a flush
|
||||
// that could do a double flush
|
||||
|
||||
#if 0x060000 <= QT_VERSION
|
||||
((QApplication*)G4Qt::getInstance ())->processEvents();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -89,24 +89,15 @@ extern "C" {
|
||||
}
|
||||
|
||||
void G4OpenGLXViewer::SetView () {
|
||||
#ifdef G4MULTITHREADED
|
||||
if (G4Threading::IsMasterThread()) {
|
||||
glXMakeCurrent (dpy, win, cxMaster);
|
||||
} else {
|
||||
glXMakeCurrent (dpy, win, cxVisSubThread);
|
||||
}
|
||||
#else
|
||||
glXMakeCurrent (dpy, win, cxMaster);
|
||||
#endif
|
||||
G4OpenGLViewer::SetView ();
|
||||
}
|
||||
|
||||
void G4OpenGLXViewer::ShowView () {
|
||||
#ifdef G4MULTITHREADED
|
||||
// G4int thread_id = G4Threading::G4GetThreadId();
|
||||
// G4cout << "G4OpenGLXViewer::ShowView: thread " << thread_id << G4endl;
|
||||
#endif
|
||||
|
||||
// glXWaitGL (); //Wait for effects of all previous OpenGL commands to
|
||||
//be propagated before progressing.
|
||||
// JA: Commented out July 2021 - slows rendering down in some cases and I
|
||||
@@ -131,24 +122,22 @@ void G4OpenGLXViewer::ShowView () {
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef G4MULTITHREADED
|
||||
|
||||
void G4OpenGLXViewer::SwitchToVisSubThread()
|
||||
{
|
||||
// G4cout << "G4OpenGLXViewer::SwitchToVisSubThread" << G4endl;
|
||||
#ifdef G4MULTITHREADED
|
||||
cxVisSubThread = glXCreateContext (dpy, vi, cxMaster, true);
|
||||
glXMakeCurrent (dpy, win, cxVisSubThread);
|
||||
#endif
|
||||
}
|
||||
|
||||
void G4OpenGLXViewer::SwitchToMasterThread()
|
||||
{
|
||||
// G4cout << "G4OpenGLXViewer::SwitchToMasterThread" << G4endl;
|
||||
#ifdef G4MULTITHREADED
|
||||
glXMakeCurrent (dpy, win, cxMaster);
|
||||
// and destroy sub-thread context
|
||||
glXDestroyContext (dpy, cxVisSubThread);
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
void G4OpenGLXViewer::GetXConnection () {
|
||||
// get a connection.
|
||||
|
||||
Reference in New Issue
Block a user