Skip to content

Commit

Permalink
Merge remote-tracking branch 'opencor/mapping' into issue2387
Browse files Browse the repository at this point in the history
  • Loading branch information
LafCorentin committed Aug 22, 2020
2 parents c25a36d + 46dcd71 commit 1276bae
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 77 deletions.
Expand Up @@ -97,8 +97,10 @@ void CellMLZincMappingViewZincWidget::changeSource(const QStringList &pZincMeshF
mZincMeshFileNames = pZincMeshFileNames;
initAuxFile();

OpenCMISS::Zinc::Region region = mZincContext.createRegion();
mZincContext.setDefaultRegion(region);
//TODO the emit launched by reset make opencor crashing
//reset();

setup();

setupRegion();

Expand Down
4 changes: 0 additions & 4 deletions src/plugins/miscellaneous/Core/src/filemanager.cpp
Expand Up @@ -62,10 +62,6 @@ FileManager::FileManager()

FileManager::~FileManager()
{
// Delete some internal objects

delete mTimer;

// Remove all the managed files

for (auto file : mFiles) {
Expand Down
Expand Up @@ -501,15 +501,6 @@ PmrWorkspacesWindowWidget::PmrWorkspacesWindowWidget(const QString &pPmrUrl,

//==============================================================================

PmrWorkspacesWindowWidget::~PmrWorkspacesWindowWidget()
{
// Delete some internal objects

delete mTimer;
}

//==============================================================================

void PmrWorkspacesWindowWidget::retranslateUi()
{
// Retranslate our actions
Expand Down
Expand Up @@ -168,7 +168,6 @@ class PmrWorkspacesWindowWidget : public Core::TreeViewWidget
explicit PmrWorkspacesWindowWidget(const QString &pPmrUrl,
PMRSupport::PmrWebService *pPmrWebService,
PmrWorkspacesWindowWindow *pParent);
~PmrWorkspacesWindowWidget() override;

void retranslateUi() override;

Expand Down
146 changes: 89 additions & 57 deletions src/plugins/widget/ZincWidget/src/zincwidget.cpp
Expand Up @@ -81,11 +81,8 @@ void ZincWidget::reset()
disconnect(QOpenGLWidget::context(), &QOpenGLContext::aboutToBeDestroyed,
this, &ZincWidget::contextAboutToBeDestroyed);

// Reset ourselves by (re)creating our OpenGL context

QOpenGLWidget::context()->create();

// Let people know that our old OpenCOR context is to be (was) detroyed
// Get people to reset things by letting them know that our OpenGL context
// is about to be destroyed

emit contextAboutToBeDestroyed();

Expand All @@ -111,7 +108,37 @@ void ZincWidget::setContext(const OpenCMISS::Zinc::Context &pContext)

mContext = pContext;

createSceneViewer();
// Create our scene viewer and have it have the same OpenGL properties as
// QOpenGLWidget

mSceneViewer = mContext.getSceneviewermodule().createSceneviewer(OpenCMISS::Zinc::Sceneviewer::BUFFERING_MODE_DOUBLE,
OpenCMISS::Zinc::Sceneviewer::STEREO_MODE_DEFAULT);

mSceneViewer.setProjectionMode(OpenCMISS::Zinc::Sceneviewer::PROJECTION_MODE_PERSPECTIVE);

checkDevicePixelRatio(true);

// Further customise our scene viewer

mSceneViewer.setScene(mContext.getDefaultRegion().getScene());
mSceneViewer.setScenefilter(mContext.getScenefiltermodule().getDefaultScenefilter());

// Use a white background by default

std::array<double, 4> backgroundColor = { 1.0, 1.0, 1.0, 1.0 };

mSceneViewer.setBackgroundColourRGBA(backgroundColor.data());

// Get ourselves a scene viewer notifier and set its callback to our
// callback class

mSceneViewerNotifier = mSceneViewer.createSceneviewernotifier();

mSceneViewerNotifier.setCallback(mZincWidgetSceneViewerCallback);

// We are all set, so view all of our scene viewer

mSceneViewer.viewAll();
}

//==============================================================================
Expand Down Expand Up @@ -286,79 +313,66 @@ void ZincWidget::viewAll()

//==============================================================================

void ZincWidget::createSceneViewer()
double ZincWidget::fps() const
{
// Create our scene viewer and have it have the same OpenGL properties as
// QOpenGLWidget

mSceneViewer = mContext.getSceneviewermodule().createSceneviewer(OpenCMISS::Zinc::Sceneviewer::BUFFERING_MODE_DOUBLE,
OpenCMISS::Zinc::Sceneviewer::STEREO_MODE_DEFAULT);
// Return our FPS

mSceneViewer.setProjectionMode(OpenCMISS::Zinc::Sceneviewer::PROJECTION_MODE_PERSPECTIVE);
mSceneViewer.setViewportSize(width(), height());

// Further customise our scene viewer
return mFps;
}

mSceneViewer.setScene(mContext.getDefaultRegion().getScene());
mSceneViewer.setScenefilter(mContext.getScenefiltermodule().getDefaultScenefilter());
//==============================================================================

// Use a white background by default
void ZincWidget::checkDevicePixelRatio(bool pForceSettingViewportSize)
{
// Check our device pixel ratio

std::array<double, 4> backgroundColor = { 1.0, 1.0, 1.0, 1.0 };
int newDevicePixelRatio = devicePixelRatio();
bool hasNewDevicePixelRatio = newDevicePixelRatio != mDevicePixelRatio;

mSceneViewer.setBackgroundColourRGBA(backgroundColor.data());
if (pForceSettingViewportSize || hasNewDevicePixelRatio) {
// Keep track of our new device pixel ratio and update the viewport size
// of our scene viewer

// Get ourselves a scene viewer notifier and set its callback to our
// callback class
mDevicePixelRatio = newDevicePixelRatio;

mSceneViewerNotifier = mSceneViewer.createSceneviewernotifier();
mSceneViewer.setViewportSize(newDevicePixelRatio*width(), newDevicePixelRatio*height());

mSceneViewerNotifier.setCallback(mZincWidgetSceneViewerCallback);
// Ask ourselves to resize so that we can properly take advantage of our
// new device pixel ratio

// Reset our device pixel ratio, so that it gets properly set when switching
// from normal DPI to high DPI (on macOS for instance)
if (!pForceSettingViewportSize && hasNewDevicePixelRatio) {
QResizeEvent event(size(), QSize());

mDevicePixelRatio = -1;
resizeEvent(&event);
}

// We are all set, so view all of our scene viewer
// Let people know that our device pixel ratio has changed, if needed

mSceneViewer.viewAll();
if (hasNewDevicePixelRatio) {
emit devicePixelRatioChanged(newDevicePixelRatio);
}
}
}

//==============================================================================

void ZincWidget::updateSceneViewerViewerportSize(int pWidth, int pHeight,
bool pCheckDevicePixelRatio)
void ZincWidget::resetFps()
{
// Update the viewport size of our scene viewer, keeping in mind our device
// pixel ratio
// Reset our FPS internals

int newDevicePixelRatio = devicePixelRatio();
mNbOfFrames = 0;

if (pCheckDevicePixelRatio) {
if (newDevicePixelRatio == mDevicePixelRatio) {
return;
}

// Small hack to force ourselves to resize

resize(pWidth+1, pHeight+1);
resize(pWidth, pHeight);

// Let people know that our device pixel ratio has changed

emit devicePixelRatioChanged(newDevicePixelRatio);
}

mDevicePixelRatio = newDevicePixelRatio;

mSceneViewer.setViewportSize(newDevicePixelRatio*pWidth, newDevicePixelRatio*pHeight);
mFpsClock.start();
}

//==============================================================================

void ZincWidget::initializeGL()
{
// Reset our FPS

resetFps();

// Forward the fact that our context is going to be destroyed

connect(QOpenGLWidget::context(), &QOpenGLContext::aboutToBeDestroyed,
Expand All @@ -373,20 +387,38 @@ void ZincWidget::initializeGL()

void ZincWidget::paintGL()
{
// Have our scene viewer render its scene
// Make sure that we are using the correct device pixel ratio

updateSceneViewerViewerportSize(width(), height(), true);
checkDevicePixelRatio();

// Have our scene viewer render its scene

mSceneViewer.renderScene();

// Update our FPS, if needed

++mNbOfFrames;

int fpsClockElapsed = mFpsClock.elapsed();

if (fpsClockElapsed >= 1000) {
mFps = 1000.0*mNbOfFrames/fpsClockElapsed;

resetFps();
}
}

//==============================================================================

void ZincWidget::resizeGL(int pWidth, int pHeight)
{
// Update the viewport size of our scene viewer
Q_UNUSED(pWidth)
Q_UNUSED(pHeight)

// Update the viewport size of our scene viewer by forcing our device pixel
// ratio to be checked

updateSceneViewerViewerportSize(pWidth, pHeight);
checkDevicePixelRatio(true);
}

//==============================================================================
Expand Down
14 changes: 10 additions & 4 deletions src/plugins/widget/ZincWidget/src/zincwidget.h
Expand Up @@ -31,6 +31,7 @@ along with this program. If not, see <https://gnu.org/licenses>.
//==============================================================================

#include <QOpenGLWidget>
#include <QTime>

//==============================================================================

Expand Down Expand Up @@ -118,6 +119,8 @@ class ZINCWIDGET_EXPORT ZincWidget : public QOpenGLWidget,

void viewAll();

double fps() const;

protected:
void initializeGL() override;
void paintGL() override;
Expand All @@ -142,14 +145,17 @@ class ZINCWIDGET_EXPORT ZincWidget : public QOpenGLWidget,
bool mNeedContextMenu = false;
QMenu *mContextMenu = nullptr;

void createSceneViewer();

void updateSceneViewerViewerportSize(int pWidth, int pHeight,
bool pCheckDevicePixelRatio = false);
QTime mFpsClock;
int mNbOfFrames = 0;
double mFps = 0.0;

OpenCMISS::Zinc::Sceneviewerinput::ButtonType buttonMap(const Qt::MouseButton &pButton) const;
OpenCMISS::Zinc::Sceneviewerinput::ModifierFlags modifierMap(const Qt::KeyboardModifiers &pModifiers) const;

void resetFps();

void checkDevicePixelRatio(bool pForceSettingViewportSize = false);

signals:
void contextAboutToBeDestroyed();
void graphicsInitialized();
Expand Down

0 comments on commit 1276bae

Please sign in to comment.