Commit 6956268f authored by Utkarsh Ayachit's avatar Utkarsh Ayachit

updates to handle Qt/VTK OpenGL api changes.

1. handle API changes in QVTKOpenGLWidget, QVTKOpenGLNativeWidget.
2. on macOS use QVTKOpenGLNativeWidget, on Windows and linux we
   QVTKOpenGLWidget. This makes it possible to support active stereo
   (quad buffer based stereo) on linux/windows.
parent 39539f5f
......@@ -89,6 +89,8 @@ void vtkSMViewProxyInteractorHelper::SetupInteractor(vtkRenderWindowInteractor*
this->Interactor->AddObserver(vtkCommand::InteractionEvent, this->Observer);
this->Interactor->AddObserver(vtkCommand::EndInteractionEvent, this->Observer);
this->Interactor->AddObserver(vtkCommand::TimerEvent, this->Observer);
this->Interactor->AddObserver(vtkCommand::WindowResizeEvent, this->Observer);
}
}
......@@ -121,6 +123,10 @@ void vtkSMViewProxyInteractorHelper::Execute(vtkObject* caller, unsigned long ev
assert(iren);
switch (event)
{
case vtkCommand::WindowResizeEvent:
this->Resize();
break;
case vtkCommand::RenderEvent:
this->CleanupTimer();
this->Render();
......@@ -215,6 +221,19 @@ void vtkSMViewProxyInteractorHelper::Render()
}
}
//----------------------------------------------------------------------------
void vtkSMViewProxyInteractorHelper::Resize()
{
if (auto iren = this->GetInteractor())
{
int size[2];
iren->GetSize(size);
vtkSMPropertyHelper(this->ViewProxy, "ViewSize").Set(size, 2);
this->ViewProxy->UpdateProperty("ViewSize");
}
}
//----------------------------------------------------------------------------
void vtkSMViewProxyInteractorHelper::PrintSelf(ostream& os, vtkIndent indent)
{
......
......@@ -94,6 +94,7 @@ protected:
void Execute(vtkObject* caller, unsigned long event, void* calldata);
void Render();
void CleanupTimer();
void Resize();
//@}
vtkCommand* Observer;
......
......@@ -196,13 +196,11 @@ public:
this->Timer.setSingleShot(true);
this->Timer.setInterval(0);
QSurfaceFormat fmt = QSurfaceFormat::defaultFormat();
fmt.setSamples(8);
this->Widget->setFormat(fmt);
this->Widget->setEnableHiDPI(true);
this->Window->SetMultiSamples(8);
this->Widget->setEnableHiDPI(true);
this->Widget->setObjectName("1QVTKWidget0");
this->Widget->SetRenderWindow(this->Window.Get());
this->Widget->setRenderWindow(this->Window.Get());
this->ContextView->SetRenderWindow(this->Window.Get());
this->ChartXY->SetAutoSize(true);
......@@ -210,7 +208,7 @@ public:
this->ChartXY->SetForceAxesToBounds(true);
this->ChartXY->SetZoomWithMouseWheel(false);
this->ContextView->GetScene()->AddItem(this->ChartXY.GetPointer());
this->ContextView->SetInteractor(this->Widget->GetInteractor());
this->ContextView->SetInteractor(this->Widget->interactor());
this->ContextView->GetRenderWindow()->SetLineSmoothing(true);
this->ChartXY->SetActionToButton(vtkChart::PAN, -1);
......
......@@ -423,12 +423,17 @@ void pqCollaborationManager::updateEnabledState()
//-----------------------------------------------------------------------------
void pqCollaborationManager::attachMouseListenerTo3DViews()
{
QWidget* mainWidget = pqCoreUtilities::mainWidget();
foreach (pqQVTKWidget* widget, mainWidget->findChildren<pqQVTKWidget*>())
{
QObject::connect(widget, SIGNAL(mouseEvent(QMouseEvent*)), this,
SLOT(updateMousePointerLocation(QMouseEvent*)), Qt::UniqueConnection);
}
// I am deliberately commenting this out. Collaboration is slated for
// deprecation. Since we removed the unnecessary `mouseEvent`, it no longer
// possible to support this. Rather than add more code to support a deprecated
// use-case, we just drop it for now.
// QWidget* mainWidget = pqCoreUtilities::mainWidget();
// foreach (pqQVTKWidget* widget, mainWidget->findChildren<pqQVTKWidget*>())
//{
// QObject::connect(widget, SIGNAL(mouseEvent(QMouseEvent*)), this,
// SLOT(updateMousePointerLocation(QMouseEvent*)), Qt::UniqueConnection);
//}
}
//-----------------------------------------------------------------------------
......
......@@ -179,8 +179,8 @@ void pqComparativeContextView::updateViewWidgets()
cntxtView->UpdateVTKObjects();
pqQVTKWidgetBase* wdg = new pqQVTKWidgetBase();
wdg->SetRenderWindow(cntxtView->GetContextView()->GetRenderWindow());
cntxtView->SetupInteractor(wdg->GetInteractor());
wdg->setRenderWindow(cntxtView->GetContextView()->GetRenderWindow());
cntxtView->SetupInteractor(wdg->interactor());
wdg->installEventFilter(this);
wdg->setContextMenuPolicy(Qt::NoContextMenu);
this->Internal->RenderWidgets[key] = wdg;
......
......@@ -166,8 +166,8 @@ void pqComparativeRenderView::updateViewWidgets(QWidget* container /*=NULL*/)
renView->UpdateVTKObjects();
pqQVTKWidget* wdg = new pqQVTKWidget();
wdg->SetRenderWindow(renView->GetRenderWindow());
renView->SetupInteractor(wdg->GetInteractor());
wdg->setRenderWindow(renView->GetRenderWindow());
renView->SetupInteractor(wdg->interactor());
wdg->setSession(compView->GetSession());
wdg->installEventFilter(this);
wdg->setContextMenuPolicy(Qt::NoContextMenu);
......
......@@ -52,6 +52,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "vtkPVDataInformation.h"
#include "vtkPVXMLElement.h"
#include "vtkProcessModule.h"
#include "vtkRenderWindow.h"
#include "vtkSMContextViewProxy.h"
#include "vtkSMPropertyHelper.h"
#include "vtkSMSelectionHelper.h"
......@@ -66,10 +67,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <QPointer>
#include <QVariant>
#if QT_VERSION >= 0x050000
#include <QSurfaceFormat>
#endif
// Command implementation
class pqContextView::command : public vtkCommand
{
......@@ -132,31 +129,23 @@ pqContextView::~pqContextView()
//-----------------------------------------------------------------------------
QWidget* pqContextView::createWidget()
{
vtkSMContextViewProxy* proxy = this->getContextViewProxy();
Q_ASSERT(proxy);
// Enable multisample for chart views when not running tests. Multisamples
// is disabled for testing to avoid failures due to antialiasing
// differences.
bool use_multisampling = (!vtksys::SystemTools::HasEnv("DASHBOARD_TEST_FROM_CTEST"));
auto renWin = proxy->GetRenderWindow();
renWin->SetMultiSamples(use_multisampling ? 8 : 0);
pqQVTKWidget* vtkwidget = new pqQVTKWidget();
#if QT_VERSION >= 0x050000
if (!vtksys::SystemTools::HasEnv("DASHBOARD_TEST_FROM_CTEST"))
{
// Enable multisample for chart views when not running tests. Multisamples
// is disabled for testing to avoid failures due to antialiasing
// differences.
QSurfaceFormat fmt = QSurfaceFormat::defaultFormat();
fmt.setSamples(8);
vtkwidget->setFormat(fmt);
}
#else
// don't use caching for charts since the charts don't seem to render
// correctly when an overlapping window is present, unlike 3D views.
vtkwidget->setAutomaticImageCacheEnabled(false);
#endif
vtkwidget->setViewProxy(this->getProxy());
vtkwidget->setContextMenuPolicy(Qt::NoContextMenu);
vtkwidget->installEventFilter(this);
vtkSMContextViewProxy* proxy = this->getContextViewProxy();
Q_ASSERT(proxy);
vtkwidget->SetRenderWindow(proxy->GetRenderWindow());
proxy->SetupInteractor(vtkwidget->GetInteractor());
vtkwidget->setRenderWindow(proxy->GetRenderWindow());
proxy->SetupInteractor(vtkwidget->interactor());
return vtkwidget;
}
......
......@@ -54,6 +54,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "pqConsoleWidgetEventTranslator.h"
#include "pqDoubleLineEditEventPlayer.h"
#include "pqDoubleLineEditEventTranslator.h"
#include "pqEventDispatcher.h"
#include "pqFileDialogEventPlayer.h"
#include "pqFileDialogEventTranslator.h"
#include "pqFlatTreeViewEventPlayer.h"
......@@ -322,6 +323,7 @@ public:
{
this->OldSize = widget->size();
widget->resize(size);
pqEventDispatcher::processEventsAndWait(10);
}
}
~WidgetSizer()
......
......@@ -77,7 +77,7 @@ public:
void init()
{
vtkNew<pqQVTKWidgetBaseRenderWindowType> renWin;
this->View->SetRenderWindow(renWin.Get());
this->View->setRenderWindow(renWin.Get());
this->ContextView->SetRenderWindow(renWin.Get());
#if defined(Q_WS_WIN) || defined(Q_OS_WIN)
......@@ -162,13 +162,13 @@ void pqMultiSliceAxisWidget::renderView()
// bug 0013947
// on Mac OSX don't render into invalid drawable, all subsequent
// OpenGL calls fail with invalid framebuffer operation.
vtkRenderWindow* renWin = this->Internal->View->GetRenderWindow();
vtkRenderWindow* renWin = this->Internal->View->renderWindow();
if (!renWin->IsDrawable())
{
return;
}
this->Internal->View->GetRenderWindow()->Render();
renWin->Render();
}
// ----------------------------------------------------------------------------
......
......@@ -143,7 +143,7 @@ QWidget* pqMultiSliceView::createWidget()
vtkSMRenderViewProxy* renModule = this->getRenderViewProxy();
if (this->InternalWidget && renModule)
{
this->InternalWidget->SetRenderWindow(renModule->GetRenderWindow());
this->InternalWidget->setRenderWindow(renModule->GetRenderWindow());
}
for (int cc = 0; cc < 3; cc++)
......
......@@ -99,8 +99,8 @@ QWidget* pqPythonView::createWidget()
vtkwidget->setContextMenuPolicy(Qt::NoContextMenu);
vtkwidget->installEventFilter(this);
vtkwidget->SetRenderWindow(viewProxy->GetRenderWindow());
viewProxy->SetupInteractor(vtkwidget->GetInteractor());
vtkwidget->setRenderWindow(viewProxy->GetRenderWindow());
viewProxy->SetupInteractor(vtkwidget->interactor());
return vtkwidget;
}
......
......@@ -54,8 +54,6 @@ pqQVTKWidget::pqQVTKWidget(QWidget* parentObject, Qt::WindowFlags f)
: Superclass(parentObject, f)
, SizePropertyName("ViewSize")
{
this->connect(this, SIGNAL(resized()), SLOT(updateSizeProperties()));
// disable HiDPI if we are running tests
this->setEnableHiDPI(vtksys::SystemTools::GetEnv("DASHBOARD_TEST_FROM_CTEST") ? false : true);
}
......@@ -65,22 +63,6 @@ pqQVTKWidget::~pqQVTKWidget()
{
}
//----------------------------------------------------------------------------
void pqQVTKWidget::updateSizeProperties()
{
if (this->ViewProxy)
{
BEGIN_UNDO_EXCLUDE();
int view_size[2];
view_size[0] = this->size().width() * this->GetInteractorAdapter()->GetDevicePixelRatio();
view_size[1] = this->size().height() * this->GetInteractorAdapter()->GetDevicePixelRatio();
vtkSMPropertyHelper(this->ViewProxy, this->SizePropertyName.toLocal8Bit().data())
.Set(view_size, 2);
this->ViewProxy->UpdateProperty(this->SizePropertyName.toLocal8Bit().data());
END_UNDO_EXCLUDE();
}
}
//----------------------------------------------------------------------------
void pqQVTKWidget::setViewProxy(vtkSMProxy* view)
{
......
......@@ -91,9 +91,6 @@ protected:
bool renderVTK();
bool canRender();
private slots:
void updateSizeProperties();
private:
Q_DISABLE_COPY(pqQVTKWidget)
vtkSmartPointer<vtkSMProxy> ViewProxy;
......
......@@ -32,12 +32,19 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef pqQVTKWidgetBase_h
#define pqQVTKWidgetBase_h
// It might possible to replace QVTKOpenGLWidget by QVTKOpenGLNativeWidget here,
// eg, if you need to work with native widgets only. However this is not tested nor recommended.
#if defined(__APPLE__)
// on macOS, we never use QVTKOpenGLWidget, but always the
// QVTKOpenGLNativeWidget. QVTKOpenGLWidget which uses `QWidget::createWindowContainer`
// is not portable and only needed when quad-buffer stereo is being used. Since
// macOS doesn't support quad-buffer stereo, there's no need to use the
// non-portable version.
#include "QVTKOpenGLNativeWidget.h"
using pqQVTKWidgetBase = QVTKOpenGLNativeWidget;
#else
#include "QVTKOpenGLWidget.h"
using pqQVTKWidgetBase = QVTKOpenGLWidget;
#endif
class vtkGenericOpenGLRenderWindow;
typedef QVTKOpenGLWidget pqQVTKWidgetBase;
typedef vtkGenericOpenGLRenderWindow pqQVTKWidgetBaseRenderWindowType;
#endif
/*=========================================================================
Program: ParaView
Module: pqQVTKWidgetEventPlayer.cxx
Module: pqQVTKWidgetEventPlayer.cxx
Copyright (c) 2005-2008 Sandia Corporation, Kitware Inc.
All rights reserved.
......@@ -29,7 +29,6 @@ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=========================================================================*/
#include "pqQVTKWidgetEventPlayer.h"
#include <QApplication>
......@@ -37,10 +36,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <QRegExp>
#include <QtDebug>
#include <QtDebug>
#include "QVTKOpenGLNativeWidget.h"
#include "QVTKOpenGLWidget.h"
#include "QVTKOpenGLWindow.h"
#include "pqEventDispatcher.h"
pqQVTKWidgetEventPlayer::pqQVTKWidgetEventPlayer(QObject* p)
......@@ -98,7 +96,7 @@ bool pqQVTKWidgetEventPlayer::playEvent(
// be propagated back to the internal QVTKOpenGLWindow when being fired
// explicitly on the widget instance. We have to use a custom event
// callback in this case to ensure that events are passed to the window.
qvtkWidget->testingEvent(&e);
qApp->notify(qvtkWidget->embeddedOpenGLWindow(), &e);
}
if (qvtkNativeWidget != nullptr)
......
......@@ -45,6 +45,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "QVTKOpenGLNativeWidget.h"
#include "QVTKOpenGLWidget.h"
#include "QVTKOpenGLWindow.h"
pqQVTKWidgetEventTranslator::pqQVTKWidgetEventTranslator(QObject* p)
: pqWidgetEventTranslator(p)
......@@ -72,13 +73,13 @@ bool pqQVTKWidgetEventTranslator::translateEvent(
QVTKOpenGLWidget* const qvtkWidget = qobject_cast<QVTKOpenGLWidget*>(Object);
if (qvtkWidget != nullptr)
{
rw = qvtkWidget->GetRenderWindow();
rw = qvtkWidget->renderWindow();
}
QVTKOpenGLNativeWidget* const qvtkNativeWidget = qobject_cast<QVTKOpenGLNativeWidget*>(Object);
if (qvtkNativeWidget != nullptr)
{
rw = qvtkNativeWidget->GetRenderWindow();
rw = qvtkNativeWidget->renderWindow();
}
// Could not find a render window, don't translate the event
......
......@@ -184,10 +184,10 @@ QWidget* pqRenderView::createWidget()
if (pqQVTKWidgetBase* qvtkwidget = qobject_cast<pqQVTKWidgetBase*>(vtkwidget))
{
vtkSMRenderViewProxy* renModule = this->getRenderViewProxy();
qvtkwidget->SetRenderWindow(renModule->GetRenderWindow());
qvtkwidget->setRenderWindow(renModule->GetRenderWindow());
// This is needed to ensure that the interactor is initialized with
// ParaView specific interactor styles etc.
renModule->SetupInteractor(qvtkwidget->GetInteractor());
renModule->SetupInteractor(qvtkwidget->interactor());
}
return vtkwidget;
}
......@@ -894,13 +894,8 @@ void pqRenderView::onInteractionModeChange()
//-----------------------------------------------------------------------------
void pqRenderView::setCursor(const QCursor& c)
{
QWidget* widget = this->widget();
if (pqQVTKWidgetBase* qvtkwidget = qobject_cast<pqQVTKWidgetBase*>(widget))
if (QWidget* wdg = this->widget())
{
qvtkwidget->setQVTKCursor(c);
}
else
{
widget->setCursor(c);
wdg->setCursor(c);
}
}
Subproject commit c6a09043b7685bdbbb16a8115aa13231664f3901
Subproject commit 4e0bc0fa6aada0bf777bb92a905b21ff5d0510d5
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment