Commit 3f26bd45 authored by Mathias Goldau's avatar Mathias Goldau
Browse files

[MERGE]

parents 1fb78ba0 7b24407f
......@@ -32,7 +32,7 @@ ENDIF( CMAKE_BUILD_TYPE STREQUAL "Static" )
# To see which boost libs we currently use, you may run the following command
# in the trunk/src directory on a linux box to make some investigations:
# grep -i include `find . -type f` | grep boost | awk '{print $2}' | sort | uniq
FIND_PACKAGE( Boost REQUIRED program_options thread filesystem date_time )
FIND_PACKAGE( Boost REQUIRED program_options thread system filesystem date_time )
ASSERT_GE_VERSION( "Boost" "${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}" 1.36.0 )
INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIR} )
......@@ -98,7 +98,7 @@ IF( NOT CMAKE_BUILD_TYPE STREQUAL "Static" )
ADD_SUBDIRECTORY( kernel )
ADD_SUBDIRECTORY( common )
ADD_EXECUTABLE( walnut OpenWalnut.cpp utils/WOptionHandler.cpp )
TARGET_LINK_LIBRARIES( walnut kernel dataHandler guiqt4 common ${Boost_LIBRARIES} )
TARGET_LINK_LIBRARIES( walnut kernel dataHandler gui guiqt4 common ${Boost_LIBRARIES} )
ELSE( NOT CMAKE_BUILD_TYPE STREQUAL "Static" )
FILE( GLOB_RECURSE ALL_SRC ${PROJECT_SOURCE_DIR}/*.cpp )
......
......@@ -26,6 +26,10 @@
#include "common/WException.h"
#include "common/WSegmentationFault.h"
#include "common/WLogger.h"
#include "gui/WGUI.h"
#include "gui/qt4/WMainApplication.h"
#include "kernel/WKernel.h"
......@@ -51,8 +55,16 @@ int main( int argc, char* argv[] )
// install signal handler as early as possible
WSegmentationFault::installSignalHandler();
// initialize GUI
boost::shared_ptr< WGUI > gui = boost::shared_ptr< WGUI >( new WMainApplication() );
// init logger
WLogger logger;
logger.run();
// init the kernel
WKernel kernel = WKernel( argc, argv );
WKernel kernel = WKernel( argc, argv, gui );
int code = kernel.run();
return code;
}
......@@ -30,6 +30,10 @@
#include "WLogger.h"
/**
* Used for program wide access to the logger.
*/
WLogger* logger = NULL;
WLogger::WLogger( std::string fileName, LogLevel level ):
WThreadedRunner(),
......@@ -39,8 +43,10 @@ WLogger::WLogger( std::string fileName, LogLevel level ):
m_STDERRLevel( LL_ERROR ),
m_LogFileLevel( level ),
m_LogFileName( fileName ),
m_FinishRequested( false )
m_QueueMutex()
{
logger = this;
addLogMessage( "Initalizing Logger", "Logger", LL_DEBUG );
addLogMessage( "===============================================================================", "Logger", LL_INFO );
addLogMessage( "= Starting Log Session =", "Logger", LL_INFO );
......@@ -51,6 +57,11 @@ WLogger::~WLogger()
{
}
WLogger* WLogger::getLogger()
{
return logger;
}
void WLogger::setLogLevel( LogLevel level )
{
......@@ -87,7 +98,7 @@ void WLogger::setLogFileName( std::string fileName )
void WLogger::addLogMessage( std::string message, std::string source, LogLevel level )
{
if ( m_LogLevel > level )
if ( m_LogLevel > level || m_FinishRequested )
{
return;
}
......@@ -98,9 +109,6 @@ void WLogger::addLogMessage( std::string message, std::string source, LogLevel l
boost::mutex::scoped_lock l( m_QueueMutex );
m_LogQueue.push( entry );
// TODO(schurade): this must be called from the kernel
// processQueue();
}
......
......@@ -53,6 +53,13 @@ public:
*/
virtual ~WLogger();
/**
* Returns pointer to the currently running logger.
*
* \return pointer to logger instance.
*/
static WLogger* getLogger();
/**
*
*/
......@@ -98,6 +105,14 @@ public:
protected:
private:
/**
* We do not want a copy constructor, so we define it private.
*/
WLogger( const WLogger& )
{
};
/**
*
*/
......@@ -138,11 +153,6 @@ private:
*
*/
boost::mutex m_QueueMutex;
/**
*
*/
bool m_FinishRequested;
};
#endif // WLOGGER_H
......@@ -28,21 +28,21 @@
#include <osg/Group>
#include <osg/Geode>
#include "../kernel/WKernel.h"
#include "../common/WLogger.h"
#include "WGEScene.h"
WGEScene::WGEScene():
osg::Group()
{
WKernel::getRunningKernel()->getLogger()->addLogMessage( "Initializing OpenSceneGraph Root Node", "GE", LL_DEBUG );
WLogger::getLogger()->addLogMessage( "Initializing OpenSceneGraph Root Node", "GE", LL_DEBUG );
// initialize members
}
WGEScene::~WGEScene()
{
WKernel::getRunningKernel()->getLogger()->addLogMessage( "Shutting down OpenSceneGraph Root Node", "GE", LL_DEBUG );
WLogger::getLogger()->addLogMessage( "Shutting down OpenSceneGraph Root Node", "GE", LL_DEBUG );
// cleanup
}
......
......@@ -25,19 +25,21 @@
#include <iostream>
#include <list>
#include <string>
#include <boost/shared_ptr.hpp>
#include <boost/thread/locks.hpp>
#include "exceptions/WGEInitFailed.h"
#include "../kernel/WKernel.h"
#include "../common/WLogger.h"
#include "WGraphicsEngine.h"
#include "WGEViewer.h"
WGraphicsEngine::WGraphicsEngine():
WThreadedRunner()
WGraphicsEngine::WGraphicsEngine( std::string shaderPath ):
WThreadedRunner(),
m_shaderPath( shaderPath )
{
WKernel::getRunningKernel()->getLogger()->addLogMessage( "Initializing Graphics Engine", "GE", LL_DEBUG );
WLogger::getLogger()->addLogMessage( "Initializing Graphics Engine", "GE", LL_DEBUG );
// initialize members
m_RootNode = new WGEScene();
......@@ -46,7 +48,7 @@ WGraphicsEngine::WGraphicsEngine():
WGraphicsEngine::~WGraphicsEngine()
{
// cleanup
WKernel::getRunningKernel()->getLogger()->addLogMessage( "Shutting down Graphics Engine", "GE", LL_DEBUG );
WLogger::getLogger()->addLogMessage( "Shutting down Graphics Engine", "GE", LL_DEBUG );
}
osg::ref_ptr<WGEScene> WGraphicsEngine::getScene()
......@@ -54,6 +56,11 @@ osg::ref_ptr<WGEScene> WGraphicsEngine::getScene()
return m_RootNode;
}
std::string WGraphicsEngine::getShaderPath()
{
return m_shaderPath;
}
void WGraphicsEngine::threadMain()
{
// TODO(ebaum): is this thread actually needed since each viewer runs in separate thread
......@@ -67,7 +74,7 @@ void WGraphicsEngine::threadMain()
boost::shared_ptr<WGEViewer> WGraphicsEngine::createViewer( osg::ref_ptr<WindowData> wdata, int x, int y, int width, int height )
{
boost::shared_ptr<WGEViewer> viewer = boost::shared_ptr<WGEViewer>( new WGEViewer( wdata, x, y, width, height ) );
viewer->setScene( WKernel::getRunningKernel()->getGraphicsEngine()->getScene() );
viewer->setScene( this->getScene() );
// start rendering
viewer->run();
......
......@@ -26,6 +26,8 @@
#define WGRAPHICSENGINE_H
#include <list>
#include <string>
#include <boost/shared_ptr.hpp>
#include <boost/thread/thread.hpp>
......@@ -52,7 +54,7 @@ public:
/**
* Default constructor.
*/
WGraphicsEngine();
explicit WGraphicsEngine( std::string shaderPath );
/**
* Destructor.
......@@ -66,6 +68,13 @@ public:
*/
osg::ref_ptr<WGEScene> getScene();
/**
* Return the path where the shaders are expected to be located.
*
* \return shader path
*/
std::string getShaderPath();
/**
* Creates a new viewer. Does basic initialization and sets the default scene.
*
......@@ -102,6 +111,7 @@ protected:
boost::mutex m_ViewerLock;
private:
std::string m_shaderPath;
};
/**
......
......@@ -31,16 +31,14 @@
#include "boost/lexical_cast.hpp"
#include <boost/tokenizer.hpp>
#include "../kernel/WKernel.h"
#include "WShader.h"
WShader::WShader()
{
}
WShader::WShader( std::string fileName )
WShader::WShader( std::string fileName, std::string shaderPath ):
m_shaderPath( shaderPath )
{
m_VertexObject = readShaderFromFile( fileName + ".vs", osg::Shader::VERTEX );
m_FragmentObject = readShaderFromFile( fileName + ".fs", osg::Shader::FRAGMENT );
......@@ -80,7 +78,7 @@ std::string WShader::readTextFile( std::string fileName )
{
std::string fileText;
std::ifstream ifs( ( WKernel::getRunningKernel()->getShaderPath() + fileName ).c_str() );
std::ifstream ifs( ( m_shaderPath + fileName ).c_str() );
std::string line;
std::map< std::string, float >::const_iterator mi = m_defines.begin();
......
......@@ -43,7 +43,7 @@ public:
/**
*
*/
explicit WShader( std::string fileName );
explicit WShader( std::string fileName, std::string shaderPath );
/**
* destructor
......@@ -88,6 +88,7 @@ private:
*/
std::string getIncludeFileName( std::string line );
std::string m_shaderPath;
/**
*
*/
......
......@@ -24,15 +24,15 @@
#include <iostream>
#include <QtGui/QApplication>
#include "WMainApplication.h"
#include "WMainWindow.h"
#include <QtGui/QApplication>
#include "../../kernel/WKernel.h"
WMainApplication::WMainApplication():
WThreadedRunner()
WGUI()
{
}
......@@ -43,8 +43,14 @@ WMainApplication::~WMainApplication()
void WMainApplication::threadMain()
{
// TODO(ebaum): currently removed argument stuff. will be done later in conjunction with a better
// option handler.
// option handler.+
#ifdef __APPLE__
char * dummy = "";
int dummyInt = 0;
QApplication appl( dummyInt, &dummy, 0 );
#else
QApplication appl( 0, NULL );
#endif
QMainWindow* widget = new QMainWindow;
WMainWindow gui;
gui.setupGUI( widget );
......
......@@ -25,29 +25,30 @@
#ifndef WMAINAPPLICATION_H
#define WMAINAPPLICATION_H
#include "../../common/WThreadedRunner.h"
#include "../WGUI.h"
/**
* Starts up the QT GUI.
* \ingroup gui
*/
class WMainApplication: public WThreadedRunner
class WMainApplication : public WGUI
{
public:
/**
/**
* Default Constructor.
*/
WMainApplication();
/**
/**
* Default destructor.
*/
virtual ~WMainApplication();
protected:
/**
/**
* Execution loop.
*/
virtual void threadMain();
......
......@@ -45,9 +45,11 @@ WQtGLWidget::WQtGLWidget( QWidget* parent )
// Extract a WindowPtr from the HIViewRef that QWidget::winId() returns.
// Without this change, the peer tries to call GetWindowPort on the HIViewRef
// which returns 0 and we only render white.
osg::ref_ptr<WindowData> wdata = osg::ref_ptr<WindowData>(
new WindowData( HIViewGetWindow( static_cast<HIViewRef>winId() ) )
);
osg::ref_ptr<WindowData> wdata;
#warning This must be commented back in soon
// wdata = osg::ref_ptr<WindowData>(
// new WindowData( HIViewGetWindow( static_cast<HIViewRef>winId() ) )
// );
#else // all others
osg::ref_ptr<WindowData> wdata = osg::ref_ptr<WindowData>( new WindowData( winId() ) );
#endif
......
......@@ -41,7 +41,8 @@
*/
WKernel* kernel = NULL;
WKernel::WKernel( int argc, char* argv[] )
WKernel::WKernel( int argc, char* argv[], boost::shared_ptr< WGUI > gui )
: m_Gui( gui )
{
std::cout << "Initializing Kernel" << std::endl;
......@@ -62,7 +63,12 @@ WKernel::WKernel( int argc, char* argv[] )
WKernel::~WKernel()
{
// cleanup
m_Logger->addLogMessage( "Shutting down Kernel", "Kernel", LL_DEBUG );
WLogger::getLogger()->addLogMessage( "Shutting down Kernel", "Kernel", LL_DEBUG );
// finish running thread
WLogger::getLogger()->wait( true );
// write remaining log messages
WLogger::getLogger()->processQueue();
}
WKernel::WKernel( const WKernel& other )
......@@ -85,11 +91,15 @@ boost::shared_ptr<WDataHandler> WKernel::getDataHandler() const
return m_DataHandler;
}
boost::shared_ptr<WMainApplication> WKernel::getGui()
boost::shared_ptr< WGUI > WKernel::getGui()
{
return m_Gui;
}
void WKernel::setGui( boost::shared_ptr< WGUI > gui )
{
m_Gui = gui;
}
int WKernel::getArgumentCount() const
{
......@@ -103,7 +113,7 @@ char** WKernel::getArguments() const
int WKernel::run()
{
m_Logger->addLogMessage( "Starting Kernel", "Kernel", LL_DEBUG );
WLogger::getLogger()->addLogMessage( "Starting Kernel", "Kernel", LL_DEBUG );
// TODO(ebaum): add separate graphics thread here
m_GraphicsEngine->run();
......@@ -117,11 +127,11 @@ int WKernel::run()
// run module execution threads
// TODO(ebaum): after having modules loaded they should be started here.
// currently this is just the test module
m_Logger->addLogMessage( "*** Starting modules:", "Kernel", LL_DEBUG );
WLogger::getLogger()->addLogMessage( "*** Starting modules:", "Kernel", LL_DEBUG );
for( std::list<WModule*>::iterator list_iter = m_modules.begin(); list_iter != m_modules.end();
++list_iter )
{
m_Logger->addLogMessage( "Starting module: " + ( *list_iter )->getName(), "Kernel", LL_DEBUG );
WLogger::getLogger()->addLogMessage( "Starting module: " + ( *list_iter )->getName(), "Kernel", LL_DEBUG );
( *list_iter )->run();
}
......@@ -146,11 +156,11 @@ int WKernel::run()
void WKernel::loadModules()
{
// TODO(ebaum): add dynamic loading here
m_Logger->addLogMessage( "*** Loading Modules: ", "Kernel", LL_DEBUG );
WLogger::getLogger()->addLogMessage( "*** Loading Modules: ", "Kernel", LL_DEBUG );
m_modules.clear();
WModule* m = new WNavigationSliceModule();
m_Logger->addLogMessage( "Loading module: " + m->getName(), "Kernel", LL_DEBUG );
WLogger::getLogger()->addLogMessage( "Loading module: " + m->getName(), "Kernel", LL_DEBUG );
m_modules.push_back( m );
......@@ -161,16 +171,11 @@ void WKernel::init()
// initialize
findAppPath();
// initalize Logger
m_Logger = boost::shared_ptr<WLogger>( new WLogger() );
// initialize graphics engine
// this also includes initialization of WGEScene and OpenSceneGraph
m_GraphicsEngine = boost::shared_ptr<WGraphicsEngine>( new WGraphicsEngine );
m_GraphicsEngine = boost::shared_ptr<WGraphicsEngine>( new WGraphicsEngine( m_shaderPath ) );
// initialize GUI
// TODO(all): clean up this option handler mess
m_Gui = boost::shared_ptr<WMainApplication>( new WMainApplication() );
// initialize Datahandler
m_DataHandler = boost::shared_ptr<WDataHandler>( new WDataHandler() );
......@@ -211,7 +216,7 @@ bool WKernel::findAppPath()
m_AppPath = appPath;
std::string shaderPath( appPath );
m_ShaderPath = shaderPath + "shaders/";
m_shaderPath = shaderPath + "shaders/";
return true;
}
......@@ -238,10 +243,5 @@ std::string WKernel::getAppPath()
std::string WKernel::getShaderPath()
{
return m_ShaderPath;
}
boost::shared_ptr<WLogger> WKernel::getLogger()
{
return m_Logger;
return m_shaderPath;
}
......@@ -33,9 +33,9 @@
#include "WModule.h"
#include "../graphicsEngine/WGraphicsEngine.h"
#include "../gui/qt4/WMainApplication.h"
#include "../dataHandler/WDataHandler.h"
#include "../common/WLogger.h"
#include "../gui/WGUI.h"
/**
* OpenWalnut kernel, managing modules and interaction between
......@@ -51,8 +51,9 @@ public:
*
* \param argc number of arguments
* \param argv arguments
* \param gui pointer to the gui interface
*/
WKernel( int argc, char* argv[] );
WKernel( int argc, char* argv[], boost::shared_ptr< WGUI > gui );
/**
* Destructor.
......@@ -127,12 +128,12 @@ public:
/**
*
*/
boost::shared_ptr<WMainApplication> getGui();
boost::shared_ptr<WGUI> getGui();
/**
*
*/
boost::shared_ptr<WLogger> getLogger();
void setGui( boost::shared_ptr< WGUI > gui );
/**
*
......@@ -159,18 +160,13 @@ protected:
/**
* The Gui.
*/
boost::shared_ptr<WMainApplication> m_Gui;
boost::shared_ptr<WGUI> m_Gui;
/**
* The Datahandler.
*/
boost::shared_ptr<WDataHandler> m_DataHandler;
/**
* The logging device
*/
boost::shared_ptr<WLogger> m_Logger;
private:
/**
* Loads all the modules it can find.
......@@ -210,7 +206,7 @@ private:
/**
* the location of the openwalnut executable
*/
std::string m_ShaderPath;
std::string m_shaderPath;
};
/**
......
......@@ -46,7 +46,8 @@ WNavigationSliceModule::WNavigationSliceModule():
WModule()
{
// initialize members
m_shader = boost::shared_ptr< WShader > ( new WShader( "slice" ) );
std::string shaderPath = WKernel::getRunningKernel()->getGraphicsEngine()->getShaderPath();
m_shader = boost::shared_ptr< WShader > ( new WShader( "slice", shaderPath ) );
m_textureAssigned = false;
}
......
......@@ -27,7 +27,8 @@
#include <boost/program_options.hpp>
#include "../gui/qt4/WMainApplication.h"
// TODO(all): why is that include here?
// #include "../gui/qt4/WMainApplication.h"
// since the namespace is far to big we use a shortcut here:
namespace po = boost::program_options;
......
#!/bin/bash
#otool -l bin/walnut |grep osg
#otool -l bin/walnut |grep OpenThreads
###### OpenWalnut Libs #####
install_name_tool \
-change libosgDB.55.dylib /opt/local/lib/libosgDB.55.dylib \
-change libosgText.55.dylib /opt/local/lib/libosgText.55.dylib \
-change libosgGA.55.dylib /opt/local/lib/libosgGA.55.dylib \
-change libosgUtil.55.dylib /opt/local/lib/libosgUtil.55.dylib \
-change libosgViewer.55.dylib /opt/local/lib/libosgViewer.55.dylib \
-change libOpenThreads.11.dylib /opt/local/lib/libOpenThreads.11.dylib \
-change libosg.55.dylib /opt/local/lib/libosg.55.dylib \
bin/walnut
for i in lib/*; do \
install_name_tool \
-change libosgDB.55.dylib /opt/local/lib/libosgDB.55.dylib \
-change libosgText.55.dylib /opt/local/lib/libosgText.55.dylib \
-change libosgGA.55.dylib /opt/local/lib/libosgGA.55.dylib \
-change libosgUtil.55.dylib /opt/local/lib/libosgUtil.55.dylib \
-change libosgViewer.55.dylib /opt/local/lib/libosgViewer.55.dylib \
-change libOpenThreads.11.dylib /opt/local/lib/libOpenThreads.11.dylib \
-change libosg.55.dylib /opt/local/lib/libosg.55.dylib \
$i; done
###### OSG Libs ######
install_name_tool \
-change libosg.55.dylib /opt/local/lib/libosg.55.dylib \
-change libOpenThreads.11.dylib /opt/local/lib/libOpenThreads.11.dylib \
/opt/local/lib/libosgDB.55.dylib
install_name_tool \
-change libOpenThreads.11.dylib /opt/local/lib/libOpenThreads.11.dylib \
/opt/local/lib/libosg.55.dylib