Commit 0750d9a3 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[ADD] - added gui cmake file and cleaned up the platform dependend mess

parent 0d587efd
......@@ -25,7 +25,7 @@ syntax: regexp
^src/cscope.out
# files geneterated by build system
^src/version.h
^src/qt4gui/version.h
# local vim rc
^lvimrc
......
......@@ -98,7 +98,7 @@ IF( CMAKE_GENERATOR MATCHES "Visual Studio" )
ELSE()
# Unfortunately libstdc++'s header files don't work with mingw in ansi mode (basically libstdc++'s fault)
IF( CMAKE_HOST_SYSTEM MATCHES "Windows" )
SET( CMAKE_CXX_FLAGS "-frtti -pedantic -Wall -Wno-long-long -Wextra -Wold-style-cast" CACHE STRING "" FORCE )
SET( CMAKE_CXX_FLAGS "-frtti -pedantic -Wall -Wno-long-long -Wextra " CACHE STRING "" FORCE )
ELSE()
# SET( CMAKE_CXX_FLAGS "-frtti -pedantic -ansi -Wall -Wno-long-long -Wextra -Wold-style-cast" CACHE STRING "" FORCE )
SET( CMAKE_CXX_FLAGS "-frtti -pedantic -ansi -Wall -Wno-long-long -Wextra " CACHE STRING "" FORCE )
......@@ -377,6 +377,8 @@ ADD_SUBDIRECTORY( core )
# -----------------------------------------------------------------------------------------------------------------------------------------------
# QT4 Walnut binary
SET( OWQt4GuiName "walnut" )
# build core
# ADD_SUBDIRECTORY( qt4gui )
ADD_SUBDIRECTORY( qt4gui )
#---------------------------------------------------------------------------
#
# 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/>.
#
#---------------------------------------------------------------------------
# ---------------------------------------------------------------------------------------------------------------------------------------------------
# Some common setup
# ---------------------------------------------------------------------------------------------------------------------------------------------------
SET( LibName ${OWQt4GuiName} )
# ---------------------------------------------------------------------------------------------------------------------------------------------------
# Setup QT4
# ---------------------------------------------------------------------------------------------------------------------------------------------------
# Package dependencies:
FIND_PACKAGE( Qt4 REQUIRED )
# Includes:
INCLUDE_DIRECTORIES( ${QT_INCLUDE_DIR} )
# Libraries for linking:
SET( QT_LIBS ${QT_QTCORE_LIBRARY}
${QT_QTGUI_LIBRARY}
${QT_QTOPENGL_LIBRARY}
${QT_QTWEBKIT_LIBRARY} )
# ---------------------------------------------------------------------------------------------------------------------------------------------------
# The walnut executable should print the revision/tag
# ---------------------------------------------------------------------------------------------------------------------------------------------------
# We use mercurial to get current version information. This is stored in version.h, included by OpenWalnut.cpp
IF( NOT CMAKE_GENERATOR MATCHES "Visual Studio" )
add_custom_command( OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/version.h
MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/../../.hg/dirstate
COMMAND hg parents --template '\#define W_VERSION \"{node|short} {rev} {branches} {tags}\" //' > ${CMAKE_CURRENT_SOURCE_DIR}/version.h
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Creating version.h"
)
ELSE()
add_custom_command( OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/version.h
MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/../../.hg/dirstate
COMMAND hg parents --template "\"#define W_VERSION \"\"{node|short} {rev} {branches} {tags}\"\"\"" > ${CMAKE_CURRENT_SOURCE_DIR}/version.h
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
COMMENT "Creating version.h"
)
ENDIF()
# ---------------------------------------------------------------------------------------------------------------------------------------------------
# Add sources as target
# ---------------------------------------------------------------------------------------------------------------------------------------------------
# Collect the compile-files for this target
COLLECT_COMPILE_FILES( "${CMAKE_CURRENT_SOURCE_DIR}" TARGET_CPP_FILES TARGET_H_FILES TARGET_TEST_FILES )
# Qt4 Requires all classes with a QWidget stuff inside to be put into the MOC mechanism. We add all of them. Moc only does something if needed.
SET( GUI_QT4_MOC_HDRS ${TARGET_H_FILES} )
QT4_WRAP_CPP( GUI_QT4_MOC_SRCS ${GUI_QT4_MOC_HDRS} )
# Setup the target
ADD_EXECUTABLE( ${LibName} ${TARGET_CPP_FILES} ${TARGET_H_FILES} ${GUI_QT4_MOC_SRCS} "version.h" )
TARGET_LINK_LIBRARIES( ${LibName} ${OWCoreName} ${QT_LIBS} ${Boost_LIBRARIES} )
# TODO(all): comment this stuff. I do not know what the purpose is
IF( MSVC_IDE )
SET_TARGET_PROPERTIES( ${LibName} PROPERTIES DEBUG_POSTFIX "d")
SET_TARGET_PROPERTIES( ${LibName} PROPERTIES PREFIX "../")
ENDIF( MSVC_IDE )
# ---------------------------------------------------------------------------------------------------------------------------------------------------
# Test Setup
# ---------------------------------------------------------------------------------------------------------------------------------------------------
# Setup tests of this target
SETUP_TESTS( "${TARGET_TEST_FILES}" "${LibName}" "" )
# ---------------------------------------------------------------------------------------------------------------------------------------------------
# Copy the documentation
# ---------------------------------------------------------------------------------------------------------------------------------------------------
# ---------------------------------------------------------------------------------------------------------------------------------------------------
# Style Checker
# ---------------------------------------------------------------------------------------------------------------------------------------------------
# setup the stylechecker. Ignore the platform specific stuff.
SETUP_STYLECHECKER( "${LibName}"
"${TARGET_CPP_FILES};${TARGET_H_FILES};${TARGET_TEST_FILES};${TARGET_GLSL_FILES}" # add all these files to the stylechecker
"" ) # exlude some ugly files
......@@ -63,7 +63,7 @@
#include "core/kernel/WProjectFile.h"
#include "core/kernel/WROIManager.h"
#include "core/kernel/WSelectionManager.h"
#include "../icons/WIcons.h"
#include "../icons/WIcons.xpm"
#include "controlPanel/WPropertyBoolWidget.h"
#include "controlPanel/WQtControlPanel.h"
#include "events/WEventTypes.h"
......
......@@ -22,4 +22,271 @@
//
//---------------------------------------------------------------------------
#include <string>
#include <iostream>
#include <QtGui/QKeyEvent>
#include "WQtGLWidget.h"
#include "core/common/WConditionOneShot.h"
#include "core/common/WFlag.h"
#include "core/common/WLogger.h"
#include "core/graphicsEngine/WGE2DManipulator.h"
#include "core/graphicsEngine/WGEViewer.h"
#include "core/graphicsEngine/WGEZoomTrackballManipulator.h"
#include "core/graphicsEngine/WGraphicsEngine.h"
#include "core/kernel/WKernel.h"
#ifndef __APPLE__
#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
#endif
WQtGLWidget::WQtGLWidget( std::string nameOfViewer, QWidget* parent, WGECamera::ProjectionMode projectionMode, const QGLWidget * shareWidget ):
#ifndef _MSC_VER
QGLWidget( getDefaultFormat(), parent, shareWidget ),
#else
QWidget( parent ),
#endif
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
#ifndef __APPLE__
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 );
// connect( &m_Timer, SIGNAL( timeout() ), this, SLOT( updateGL() ) );
// m_Timer.start( 10 );
#else
// create viewer
m_Viewer = WKernel::getRunningKernel()->getGraphicsEngine()->createViewer(
m_nameOfViewer, x(), y(), width(), height(), m_initialProjectionMode );
connect( &m_Timer, SIGNAL( timeout() ), this, SLOT( updateGL() ) );
m_Timer.start( 10 );
#endif
}
WQtGLWidget::~WQtGLWidget()
{
WKernel::getRunningKernel()->getGraphicsEngine()->closeViewer( m_nameOfViewer );
m_Viewer.reset();
}
QSize WQtGLWidget::sizeHint() const
{
return m_recommendedSize;
}
void WQtGLWidget::setCameraManipulator( WQtGLWidget::CameraManipulators manipulator )
{
m_CurrentManipulator = manipulator;
switch ( manipulator )
{
case TWO_D:
WLogger::getLogger()->addLogMessage( "Switched to OSG manipulator \"WGE2D\".",
"WQtGLWidget(" + m_Viewer->getName() + ")",
LL_DEBUG );
m_Viewer->setCameraManipulator( new( WGE2DManipulator ) );
break;
case TRACKBALL:
default:
WLogger::getLogger()->addLogMessage( "Switched to OSG manipulator \"WGETrackball\".",
"WQtGLWidget(" + m_Viewer->getName() + ")",
LL_DEBUG );
m_Viewer->setCameraManipulator( new( WGEZoomTrackballManipulator ) );
break;
}
}
void WQtGLWidget::setBgColor( const WColor& bgColor )
{
m_Viewer->setBgColor( bgColor );
}
WQtGLWidget::CameraManipulators WQtGLWidget::getCameraManipulators()
{
return m_CurrentManipulator;
}
boost::shared_ptr< WGEViewer > WQtGLWidget::getViewer() const
{
return m_Viewer;
}
void WQtGLWidget::paintEvent( QPaintEvent* /*event*/ )
{
// m_Viewer->paint();
}
#ifdef __APPLE__
void WQtGLWidget::paintGL()
{
m_Viewer->paint();
}
void WQtGLWidget::resizeEvent( QResizeEvent* /* event */ )
{
// m_Viewer->resize( event->size().width(), event->size().height() );
}
void WQtGLWidget::resizeGL( int width, int height )
{
m_Viewer->resize( width, height );
}
#else
void WQtGLWidget::paintGL()
{
// m_Viewer->paint();
}
void WQtGLWidget::resizeEvent( QResizeEvent* event )
{
m_Viewer->resize( event->size().width(), event->size().height() );
}
void WQtGLWidget::resizeGL( int /* width */, int /* height */ )
{
// m_Viewer->resize( width, height );
}
#endif
int WQtGLWidget::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 WQtGLWidget::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 WQtGLWidget::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 WQtGLWidget::mousePressEvent( QMouseEvent* event )
{
m_Viewer->mouseEvent( WGEViewer::MOUSEPRESS, event->x(), event->y(), translateButton( event ) );
}
void WQtGLWidget::mouseDoubleClickEvent( QMouseEvent* event )
{
m_Viewer->mouseEvent( WGEViewer::MOUSEDOUBLECLICK, event->x(), event->y(), translateButton( event ) );
}
void WQtGLWidget::mouseReleaseEvent( QMouseEvent* event )
{
m_Viewer->mouseEvent( WGEViewer::MOUSERELEASE, event->x(), event->y(), translateButton( event ) );
}
void WQtGLWidget::mouseMoveEvent( QMouseEvent* event )
{
m_Viewer->mouseEvent( WGEViewer::MOUSEMOVE, event->x(), event->y(), 0 );
}
void WQtGLWidget::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 WQtGLWidget::reset()
{
m_Viewer->reset();
}
const QGLFormat WQtGLWidget::getDefaultFormat()
{
QGLFormat format;
format.setSwapInterval( 1 ); // according to Qt Doc, this should enable VSync. But it doesn't.
return format;
}
......@@ -25,17 +25,225 @@
#ifndef WQTGLWIDGET_H
#define WQTGLWIDGET_H
#if defined( __APPLE__ )
#include "platformDependent/WQtGLWidgetMac.h"
typedef WQtGLWidgetMac WQtGLWidget;
#include <string>
#include <boost/shared_ptr.hpp>
#include <boost/signals2/signal.hpp>
#include <QtCore/QTimer>
#include <QtGui/QWidget>
#include <QtOpenGL/QGLWidget>
#include <QtOpenGL/QGLFormat>
#include "core/common/WColor.h" // not forwarded due to duplicated typedef
#include "core/graphicsEngine/WGECamera.h"
#include "core/graphicsEngine/WGEViewer.h"
/**
* A widget containing an open gl display area. This initializes OpenGL context and adds a view to the
* engine.
* \ingroup gui
*/
// NOTE: to make this work with MOC, the defines must be set before MOC runs (ensured in Build system)
class WQtGLWidget: public
#ifndef _MSC_VER
QGLWidget
#else
#ifdef _MSC_VER
#include "platformDependent/WQtGLWidgetWin.h"
typedef WQtGLWidgetWin WQtGLWidget;
#else
#include "platformDependent/WQtGLWidgetAll.h"
typedef WQtGLWidgetAll WQtGLWidget;
#endif
QWidget
#endif
{
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 WQtGLWidget( std::string nameOfViewer, QWidget* parent = 0,
WGECamera::ProjectionMode projectionMode = WGECamera::ORTHOGRAPHIC, const QGLWidget * shareWidget = 0 );
/**
* Destructor.
*/
virtual ~WQtGLWidget();
/**
* 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( const 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;
/**
* Creates and returns a default OpenGL format description with vertical sync enabled.
*
* \return the format descriptor
*/
static const QGLFormat getDefaultFormat();
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 resize events.
*
* \param width the new width.
* \param height the new height.
*/
virtual void resizeGL( int width, int height );
/**
* 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 );
/**
* QT Callback for handling repaints.
*/
virtual void paintGL();