Commit 175183fc authored by ledig's avatar ledig
Browse files

[FIX] Graphics Initialization in MSVC

parent 31db74e7
......@@ -39,7 +39,11 @@ IF( CMAKE_HOST_SYSTEM MATCHES Darwin )
LIST( APPEND GUI_QT4_MOC_HDRS platformDependent/WQtGLWidgetMac.h )
ELSE()
LIST( APPEND GUI_QT4_MOC_HDRS platformDependent/WQtGLWidgetAll.h )
IF( CMAKE_GENERATOR MATCHES "Visual Studio" )
LIST( APPEND GUI_QT4_MOC_HDRS platformDependent/WQtGLWidgetWin.h )
ELSE( CMAKE_GENERATOR MATCHES "Visual Studio" )
LIST( APPEND GUI_QT4_MOC_HDRS platformDependent/WQtGLWidgetAll.h )
ENDIF( CMAKE_GENERATOR MATCHES "Visual Studio" )
ENDIF()
QT4_WRAP_CPP(GUI_QT4_MOC_SRCS ${GUI_QT4_MOC_HDRS} )
......@@ -50,9 +54,15 @@ IF( CMAKE_HOST_SYSTEM MATCHES Darwin )
"platformDependent/WQtGLWidgetMac.cpp"
"platformDependent/WQtGLWidgetMac.h" )
ELSE()
FILE( GLOB GUIQT4_PLATFORMDEPENDENT_SRC
"platformDependent/WQtGLWidgetAll.cpp"
"platformDependent/WQtGLWidgetAll.h" )
IF( CMAKE_GENERATOR MATCHES "Visual Studio" )
FILE( GLOB GUIQT4_PLATFORMDEPENDENT_SRC
"platformDependent/WQtGLWidgetWin.cpp"
"platformDependent/WQtGLWidgetWin.h" )
ELSE( CMAKE_GENERATOR MATCHES "Visual Studio" )
FILE( GLOB GUIQT4_PLATFORMDEPENDENT_SRC
"platformDependent/WQtGLWidgetAll.cpp"
"platformDependent/WQtGLWidgetAll.h" )
ENDIF( CMAKE_GENERATOR MATCHES "Visual Studio" )
ENDIF()
SET( LIB_NAME "${OWguiqt4Name}" )
......
......@@ -198,20 +198,33 @@ void WMainWindow::setupGUI()
bool hideWidget;
if( !( WPreferences::getPreference( "qt4gui.hideAxial", &hideWidget ) && hideWidget) )
{
#ifndef _MSC_VER
m_navAxial = boost::shared_ptr< WQtNavGLWidget >( new WQtNavGLWidget( "Axial View", this, "Axial Slice", m_mainGLWidget.get() ) );
#else
m_navAxial = boost::shared_ptr< WQtNavGLWidget >( new WQtNavGLWidget( "Axial View", this, "Axial Slice" ) );
#endif
m_navAxial->setFeatures( QDockWidget::AllDockWidgetFeatures );
addDockWidget( Qt::LeftDockWidgetArea, m_navAxial.get() );
}
if( !( WPreferences::getPreference( "qt4gui.hideCoronal", &hideWidget ) && hideWidget) )
{
#ifndef _MSC_VER
m_navCoronal = boost::shared_ptr< WQtNavGLWidget >( new WQtNavGLWidget( "Coronal View", this, "Coronal Slice", m_mainGLWidget.get() ) );
#else
m_navCoronal = boost::shared_ptr< WQtNavGLWidget >( new WQtNavGLWidget( "Coronal View", this, "Coronal Slice" ) );
#endif
m_navCoronal->setFeatures( QDockWidget::AllDockWidgetFeatures );
addDockWidget( Qt::LeftDockWidgetArea, m_navCoronal.get() );
}
if( !( WPreferences::getPreference( "qt4gui.hideSagittal", &hideWidget ) && hideWidget) )
{
#ifndef _MSC_VER
m_navSagittal =
boost::shared_ptr< WQtNavGLWidget >( new WQtNavGLWidget( "Sagittal View", this, "Sagittal Slice", m_mainGLWidget.get() ) );
#else
m_navSagittal =
boost::shared_ptr< WQtNavGLWidget >( new WQtNavGLWidget( "Sagittal View", this, "Sagittal Slice" ) );
#endif
m_navSagittal->setFeatures( QDockWidget::AllDockWidgetFeatures );
addDockWidget( Qt::LeftDockWidgetArea, m_navSagittal.get() );
}
......
......@@ -26,11 +26,16 @@
#define WQTGLWIDGET_H
#if defined( __APPLE__ )
#include "platformDependent/WQtGLWidgetMac.h"
typedef WQtGLWidgetMac WQtGLWidget;
#include "platformDependent/WQtGLWidgetMac.h"
typedef WQtGLWidgetMac WQtGLWidget;
#else
#include "platformDependent/WQtGLWidgetAll.h"
typedef WQtGLWidgetAll WQtGLWidget;
#ifdef _MSC_VER
#include "platformDependent/WQtGLWidgetWin.h"
typedef WQtGLWidgetWin WQtGLWidget;
#else
#include "platformDependent/WQtGLWidgetAll.h"
typedef WQtGLWidgetAll WQtGLWidget;
#endif
#endif
#endif // WQTGLWIDGET_H
......@@ -50,7 +50,11 @@ WQtNavGLWidget::WQtNavGLWidget( QString title, QWidget* parent, std::string slid
m_layout = new QVBoxLayout();
#ifndef _MSC_VER
m_glWidget = boost::shared_ptr<WQtGLWidget>( new WQtGLWidget( title.toStdString(), panel, WGECamera::ORTHOGRAPHIC, shareWidget ) );
#else
m_glWidget = boost::shared_ptr<WQtGLWidget>( new WQtGLWidget( title.toStdString(), panel, WGECamera::ORTHOGRAPHIC ) );
#endif
setMinimumSize( 160, 240 );
setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
......
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#include <string>
#include <iostream>
#include <QtGui/QKeyEvent>
#include "WQtGLWidgetWin.h"
#include "../../../common/WConditionOneShot.h"
#include "../../../common/WFlag.h"
#include "../../../common/WLogger.h"
#include "../../../graphicsEngine/WGE2DManipulator.h"
#include "../../../graphicsEngine/WGEViewer.h"
#include "../../../graphicsEngine/WGEZoomTrackballManipulator.h"
#include "../../../kernel/WKernel.h"
#ifndef _MSC_VER
#include <osgViewer/api/X11/GraphicsWindowX11>
typedef osgViewer::GraphicsWindowX11::WindowData WindowData;
#else
#include <osgViewer/api/Win32/GraphicsWindowWin32>
typedef osgViewer::GraphicsWindowWin32::WindowData WindowData;
#endif
WQtGLWidgetWin::WQtGLWidgetWin( std::string nameOfViewer, QWidget* parent, WGECamera::ProjectionMode projectionMode, const QGLWidget * shareWidget )
: QWidget( parent ),
m_nameOfViewer( nameOfViewer ),
m_recommendedSize()
{
m_recommendedSize.setWidth( 200 );
m_recommendedSize.setHeight( 200 );
m_initialProjectionMode = projectionMode;
// required
setAttribute( Qt::WA_PaintOnScreen );
setAttribute( Qt::WA_NoSystemBackground );
setFocusPolicy( Qt::ClickFocus );
// initialize OpenGL context and OpenSceneGraph
osg::ref_ptr<osg::Referenced> wdata = new WindowData( winId() );
// create viewer
m_Viewer = WKernel::getRunningKernel()->getGraphicsEngine()->createViewer(
m_nameOfViewer, wdata, x(), y(), width(), height(), m_initialProjectionMode );
}
WQtGLWidgetWin::~WQtGLWidgetWin()
{
WKernel::getRunningKernel()->getGraphicsEngine()->closeViewer( m_nameOfViewer );
m_Viewer.reset();
}
QSize WQtGLWidgetWin::sizeHint() const
{
return m_recommendedSize;
}
void WQtGLWidgetWin::setCameraManipulator( WQtGLWidgetWin::CameraManipulators manipulator )
{
m_CurrentManipulator = manipulator;
switch ( manipulator )
{
case TWO_D:
WLogger::getLogger()->addLogMessage( "Switched to OSG manipulator \"WGE2D\".",
"WQtGLWidgetAll(" + m_Viewer->getName() + ")",
LL_DEBUG );
m_Viewer->setCameraManipulator( new( WGE2DManipulator ) );
break;
case TRACKBALL:
default:
WLogger::getLogger()->addLogMessage( "Switched to OSG manipulator \"WGETrackball\".",
"WQtGLWidgetAll(" + m_Viewer->getName() + ")",
LL_DEBUG );
m_Viewer->setCameraManipulator( new( WGEZoomTrackballManipulator ) );
break;
}
}
void WQtGLWidgetWin::setBgColor( WColor bgColor )
{
m_Viewer->setBgColor( bgColor );
}
WQtGLWidgetWin::CameraManipulators WQtGLWidgetWin::getCameraManipulators()
{
return m_CurrentManipulator;
}
boost::shared_ptr< WGEViewer > WQtGLWidgetWin::getViewer() const
{
return m_Viewer;
}
void WQtGLWidgetWin::paintEvent( QPaintEvent* /*event*/ )
{
// maybe this helps finding the startup segfaults. This will be removed after the problem has been found.
if ( !m_firstPaint )
{
WLogger::getLogger()->addLogMessage( "Painted the first time.",
"WQtGLWidget(" + m_Viewer->getName() + ")",
LL_DEBUG );
m_firstPaint = true;
}
// m_Viewer->paint();
}
void WQtGLWidgetWin::resizeEvent( QResizeEvent* event )
{
m_Viewer->resize( event->size().width(), event->size().height() );
}
int WQtGLWidgetWin::translateButton( QMouseEvent* event )
{
switch( event->button() )
{
case( Qt::LeftButton ):
return 1;
case( Qt::MidButton ):
return 2;
case( Qt::RightButton ):
return 3;
default:
return 0;
}
}
void WQtGLWidgetWin::keyPressEvent( QKeyEvent* event )
{
if( event->text() != "" )
{
m_Viewer->keyEvent( WGEViewer::KEYPRESS, *event->text().toAscii().data() );
}
else
{
switch( event->modifiers() )
{
case Qt::ShiftModifier :
m_Viewer->keyEvent( WGEViewer::KEYPRESS, osgGA::GUIEventAdapter::KEY_Shift_L );
break;
case Qt::ControlModifier :
m_Viewer->keyEvent( WGEViewer::KEYPRESS, osgGA::GUIEventAdapter::KEY_Control_L );
break;
default :
break;
}
}
}
void WQtGLWidgetWin::keyReleaseEvent( QKeyEvent* event )
{
switch( event->key() )
{
case Qt::Key_Period:
WGraphicsEngine::getGraphicsEngine()->requestShaderReload();
break;
case Qt::Key_1:
setCameraManipulator( TRACKBALL );
break;
case Qt::Key_2:
setCameraManipulator( TWO_D );
break;
}
switch( event->modifiers() )
{
case Qt::ShiftModifier :
m_Viewer->keyEvent( WGEViewer::KEYRELEASE, osgGA::GUIEventAdapter::KEY_Shift_L );
break;
case Qt::ControlModifier :
m_Viewer->keyEvent( WGEViewer::KEYRELEASE, osgGA::GUIEventAdapter::KEY_Control_L );
break;
}
m_Viewer->keyEvent( WGEViewer::KEYRELEASE, *event->text().toAscii().data() );
}
void WQtGLWidgetWin::mousePressEvent( QMouseEvent* event )
{
m_Viewer->mouseEvent( WGEViewer::MOUSEPRESS, event->x(), event->y(), translateButton( event ) );
}
void WQtGLWidgetWin::mouseDoubleClickEvent( QMouseEvent* event )
{
m_Viewer->mouseEvent( WGEViewer::MOUSEDOUBLECLICK, event->x(), event->y(), translateButton( event ) );
}
void WQtGLWidgetWin::mouseReleaseEvent( QMouseEvent* event )
{
m_Viewer->mouseEvent( WGEViewer::MOUSERELEASE, event->x(), event->y(), translateButton( event ) );
}
void WQtGLWidgetWin::mouseMoveEvent( QMouseEvent* event )
{
m_Viewer->mouseEvent( WGEViewer::MOUSEMOVE, event->x(), event->y(), 0 );
}
void WQtGLWidgetWin::wheelEvent( QWheelEvent* event )
{
int x, y;
if( event->orientation() == Qt::Vertical )
{
x = 0;
y = event->delta();
}
else
{
x = event->delta();
y = 0;
}
m_Viewer->mouseEvent( WGEViewer::MOUSESCROLL, x, y, 0 );
}
void WQtGLWidgetWin::reset()
{
m_Viewer->reset();
}
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WQTGLWIDGETALL_H
#define WQTGLWIDGETALL_H
#include <string>
#include <QtCore/QTimer>
#include <QtGui/QWidget>
#include <QtOpenGL/QGLWidget>
#include <boost/shared_ptr.hpp>
#include <boost/signals2/signal.hpp>
#include "../../../graphicsEngine/WGECamera.h"
#include "../../../graphicsEngine/WGEViewer.h"
class WColor;
/**
* A widget containing an open gl display area. This initializes OpenGL context and adds a view to the
* engine.
* \ingroup gui
*/
// Note (ledig) this has to be in an extra file because mocing has problems with #ifdefs
class WQtGLWidgetWin
: public QWidget
{
Q_OBJECT
public:
/**
* Default constructor.
*
* \param nameOfViewer Name of the Viewer
* \param parent Parent widget.
* \param projectionMode decides whether the widget uses perspective or othographic projection
* \param shareWidget this widget will share OpenGL display lists and texture objects with shareWidget
*
* \return
*/
explicit WQtGLWidgetWin( std::string nameOfViewer, QWidget* parent = 0,
WGECamera::ProjectionMode projectionMode = WGECamera::ORTHOGRAPHIC, const QGLWidget * shareWidget = 0 );
/**
* Destructor.
*/
virtual ~WQtGLWidgetWin();
/**
* returns the recommended size for the widget to allow
* parent widgets to give it a proper initial layout
*/
QSize sizeHint() const;
/**
* List of currently possible camera manipulators.
*/
enum CameraManipulators
{
TRACKBALL, TWO_D
};
/**
* Sets the camera manipulator to use.
*
* \param manipulator the manipulator.
*/
void setCameraManipulator( CameraManipulators manipulator );
/**
* Sets the background color of the widget.
* \param bgColor the new backgorund color
*/
void setBgColor( WColor bgColor );
/**
* Returns the actually set camera manipulator.
*
* \return the manipulator.
*/
CameraManipulators getCameraManipulators();
/**
* Get the included viewer.
*
* \return a shared pointer to the viewer
*/
boost::shared_ptr< WGEViewer > getViewer() const;
public slots:
/**
* Resets the contained view using the installed manipulator.
*/
void reset();
protected:
/**
* The viewer to the scene.
*/
boost::shared_ptr<WGEViewer> m_Viewer;
/**
* The name of the viewer.
*/
std::string m_nameOfViewer;
/**
* Event handler for double clicks.
*
* \param event the event description.
*/
virtual void mouseDoubleClickEvent( QMouseEvent* event );
/**
* Event handler for resize events.
*
* \param event the event description.
*/
virtual void resizeEvent( QResizeEvent* event );
/**
* Event handler for key press.
*
* \param event the event description.
*/
virtual void keyPressEvent( QKeyEvent* event );
/**
* Event handler for key release.
*
* \param event the event description.
*/
virtual void keyReleaseEvent( QKeyEvent* event );
/**
* Event handler for mouse button press.
*
* \param event the event description.
*/
virtual void mousePressEvent( QMouseEvent* event );
/**
* Event handler for mouse button release.
*
* \param event the event description.
*/
virtual void mouseReleaseEvent( QMouseEvent* event );
/**
* Event handler for mouse moves.
*
* \param event the event description.
*/
virtual void mouseMoveEvent( QMouseEvent* event );
/**
* Event handler for the mouse wheel.
*
* \param event the event description.
*/
virtual void wheelEvent( QWheelEvent* event );
/**
* QT Callback for handling repaints.
*
* \param event event descriptor.
*/
virtual void paintEvent( QPaintEvent* event );
/**
* Simply translate the mouse button from an event to an int.
*
* \param event the QT Event.
*
* \return the translated button number.
*/
int translateButton( QMouseEvent* event );
/**
* Stores the current manipulator.
*/
CameraManipulators m_CurrentManipulator;
/**
* Camera projection mode used to initialize widget. May not be the actual one!
*/
WGECamera::ProjectionMode m_initialProjectionMode;
private:
/**
* Holds the recommended size for the widget
*/
QSize m_recommendedSize;
/**
* True when the widget got drawn the very first time.
*/
bool m_firstPaint;
};
#endif // WQTGLWIDGETALL_H
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