Commit 72a46c16 authored by Alexander Wiebel's avatar Alexander Wiebel
Browse files

[ADD] Implemented config file mechanism. By now it is capable to preset the

backgriudn color of our viewers.
parent e200f864
......@@ -135,6 +135,11 @@ osg::ref_ptr<osg::Node> WGEViewer::getNode()
return m_View->getSceneData();
}
void WGEViewer::setBgColor( WColor bgColor )
{
m_View->getCamera()->setClearColor( osg::Vec4( bgColor.getRed(), bgColor.getGreen(), bgColor.getBlue(), 1. ) );
}
void WGEViewer::resize( int width, int height )
{
WGEGraphicsWindow::resize( width, height );
......
......@@ -46,6 +46,9 @@
#include "WGECamera.h"
#include "WGEZoomTrackballManipulator.h"
class WColor;
/**
* Class for managing one viewer to the scene. This includes viewport, camera and graphics context.
* It is, besides WGraphicsEngine, the ONLY entry point for each widget for accessing the graphics engine.
......@@ -83,7 +86,7 @@ public:
*/
virtual void resize( int width, int height );
/**
/**
* Close the viewer, but wait for the rendering thread to finish.
*/
virtual void close();
......@@ -145,6 +148,11 @@ public:
return m_name;
}
/**
* Determine the color of the viewer's background.
*/
void setBgColor( WColor bgColor );
protected:
/**
......
......@@ -36,6 +36,7 @@
#include "exceptions/WGEInitFailed.h"
#include "../common/WLogger.h"
#include "../common/WColor.h"
#include "WGraphicsEngine.h"
#include "WGEViewer.h"
......@@ -87,7 +88,8 @@ void WGraphicsEngine::setShaderPath( std::string path )
}
boost::shared_ptr<WGEViewer> WGraphicsEngine::createViewer( std::string name, osg::ref_ptr<WindowData> wdata, int x, int y,
int width, int height, WGECamera::ProjectionMode projectionMode )
int width, int height, WGECamera::ProjectionMode projectionMode,
WColor bgColor )
{
// init the composite viewer if not already done
if ( m_Viewer == osg::ref_ptr< osgViewer::CompositeViewer >() )
......@@ -96,6 +98,7 @@ boost::shared_ptr<WGEViewer> WGraphicsEngine::createViewer( std::string name, os
boost::shared_ptr<WGEViewer> viewer = boost::shared_ptr<WGEViewer>(
new WGEViewer( name, wdata, x, y, width, height, projectionMode ) );
viewer->setBgColor( bgColor );
viewer->setScene( getScene() );
// finally add view
......
......@@ -80,7 +80,7 @@ public:
/**
* Sets the shader path.
*
*
* \param path path to shaders.
*/
void setShaderPath( std::string path );
......@@ -95,11 +95,13 @@ public:
* \param width Width of the widget.
* \param height Height of the Widget.
* \param projectionMode Projection mode of the viewer.
* \param bgColor background color shown in the viewer.
* \return the new instance, ready to be used.
* \exception WGEInitFailed thrown if initialization of graphics context or graphics window has failed.
*/
boost::shared_ptr<WGEViewer> createViewer( std::string name, osg::ref_ptr<WindowData> wdata, int x, int y,
int width, int height, WGECamera::ProjectionMode projectionMode = WGECamera::ORTHOGRAPHIC );
int width, int height, WGECamera::ProjectionMode projectionMode = WGECamera::ORTHOGRAPHIC,
WColor bgColor = WColor( .9, .9, .9 ) );
/**
* Searchs for a viewer with a given name and returns it, if found.
......
......@@ -44,12 +44,12 @@
#include "../icons/WIcons.h"
WMainWindow::WMainWindow() :
WMainWindow::WMainWindow( boost::program_options::variables_map guiConfiguration ) :
QMainWindow(),
m_iconManager(),
m_propertyManager()
{
setupGUI();
setupGUI( guiConfiguration );
}
WMainWindow::~WMainWindow()
......@@ -57,7 +57,7 @@ WMainWindow::~WMainWindow()
}
void WMainWindow::setupGUI()
void WMainWindow::setupGUI( boost::program_options::variables_map guiConfiguration )
{
m_iconManager.addIcon( std::string( "logo" ), logoIcon_xpm );
......@@ -77,6 +77,14 @@ void WMainWindow::setupGUI()
m_mainGLWidget->initialize();
setCentralWidget( m_mainGLWidget.get() );
if( guiConfiguration.count( "ge.bgColor.r" ) && guiConfiguration.count( "ge.bgColor.g" ) && guiConfiguration.count( "ge.bgColor.b" ) )
{
WColor bgColor( guiConfiguration["ge.bgColor.r"].as< float >(),
guiConfiguration["ge.bgColor.g"].as< float >(),
guiConfiguration["ge.bgColor.b"].as< float >() );
m_mainGLWidget->setBgColor( bgColor );
}
//TODO(all): this is commented out
// initially 3 views
// m_navAxial = boost::shared_ptr< WQtNavGLWidget >( new WQtNavGLWidget( "axial", 160, "axialPos" ) );
......
......@@ -30,6 +30,7 @@
#include <vector>
#include <boost/shared_ptr.hpp>
#include <boost/program_options.hpp>
#include <QtGui/QIcon>
#include <QtGui/QMainWindow>
......@@ -57,12 +58,12 @@ class WMainWindow : public QMainWindow
Q_OBJECT
public:
explicit WMainWindow();
explicit WMainWindow( boost::program_options::variables_map guiConfiguration );
/**
* Set up all widgets menus an buttons in the main window.
*/
void setupGUI();
void setupGUI( boost::program_options::variables_map guiConfiguration );
/**
* Destructor.
......@@ -99,7 +100,7 @@ protected:
/**
* We want to react on close events.
*
*
* \param e the close event.
*/
void closeEvent( QCloseEvent* e );
......
......@@ -23,6 +23,7 @@
//---------------------------------------------------------------------------
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
......@@ -46,19 +47,11 @@ WQt4Gui::~WQt4Gui()
{
}
/**
* This function defines and parses the valid command line options.
* This might once be put in a separate class like WOptionHandler.
* At the moment it seems reasonable that differnet GUIs might have
* different command line options, thus we implement their parsing
* in the GUI implemntation itself, i.e. here.
*/
boost::program_options::variables_map parseOptions( int argc, char** argv )
bool WQt4Gui::parseOptions( int argc, char** argv )
{
// since the namespace is far to big we use a shortcut here
namespace po = boost::program_options;
po::variables_map optionsMap;
po::options_description desc( "Allowed options" );
desc.add_options()
( "help,h", "Prints this help message" )
......@@ -67,31 +60,63 @@ boost::program_options::variables_map parseOptions( int argc, char** argv )
po::positional_options_description p;
p.add( "input", -1 );
po::store( po::command_line_parser( argc, argv ).options( desc ).positional( p ).run(), optionsMap );
po::notify( optionsMap );
// print usage information if command line asks for help.
if( optionsMap.count( "help" ) )
{
std::cout << desc << std::endl;
}
return optionsMap;
}
int WQt4Gui::run()
{
try
{
m_optionsMap = parseOptions( argc, argv );
po::store( po::command_line_parser( argc, argv ).options( desc ).positional( p ).run(), m_optionsMap );
}
catch( boost::program_options::unknown_option e )
{
std::cout << e.what() << std::endl;
return 1;
return false;
}
catch( boost::program_options::invalid_command_line_syntax e )
{
std::cout << e.what() << std::endl;
return false;
}
po::notify( m_optionsMap );
//=====================
// CONFIGURATION FILE
po::options_description guiConfigurationDescription( "GUI configuration" );
guiConfigurationDescription.add_options()
( "ge.bgColor.r", po::value< float >() )
( "ge.bgColor.g", po::value< float >() )
( "ge.bgColor.b", po::value< float >() );
std::ifstream ifs;
ifs.open( "walnut.cfg", std::ifstream::in );
po::variables_map guiConfiguration;
try
{
po::store( po::parse_config_file( ifs, guiConfigurationDescription ), m_guiConfiguration );
}
catch( boost::program_options::unknown_option e )
{
std::cout << "Syntax error in configuration file \"walnut.cfg\"." << std::endl;
return false;
}
po::notify( m_guiConfiguration );
// print usage information if command line asks for help.
if( m_optionsMap.count( "help" ) )
{
std::cout << desc << std::endl;
}
return true;
}
int WQt4Gui::run()
{
bool parsingSuccessful = false;
parsingSuccessful = parseOptions( argc, argv );
if( !parsingSuccessful )
{
return 1;
}
......@@ -113,7 +138,7 @@ int WQt4Gui::run()
m_kernel = boost::shared_ptr< WKernel >( new WKernel( m_ge, shared_from_this() ) );
m_kernel->run();
// create the window
m_gui = new WMainWindow;
m_gui = new WMainWindow( m_guiConfiguration );
m_gui->show();
// connect out loader signal with krnel
......
......@@ -46,7 +46,7 @@ public:
/**
* Constructor.
*
*
* \param argc number of arguments given on command line.
* \param argv arguments given on command line.
*/
......@@ -66,7 +66,7 @@ public:
/**
* TODO(schurade): write something
*
*
* \param module
* \param subjectId
*/
......@@ -107,6 +107,16 @@ private:
boost::shared_ptr< WKernel > m_kernel;
boost::program_options::variables_map m_optionsMap; //!< Map storing the program options.
boost::program_options::variables_map m_guiConfiguration; //!< Map storing the configuration of the GUI
/**
* This function defines and parses the valid command line options.
* This might once be put in a separate class like WOptionHandler.
* At the moment it seems reasonable that different GUIs might have
* different command line options, thus we implement their parsing
* in the GUI implemntation itself, i.e. here.
*/
bool parseOptions( int argc, char** argv );
};
#endif // WQT4GUI_H
......
......@@ -132,6 +132,12 @@ void WQtGLWidget::setCameraManipulator( WQtGLWidget::CameraManipulators manipula
}
}
void WQtGLWidget::setBgColor( WColor bgColor )
{
assert( m_Viewer );
m_Viewer->setBgColor( bgColor );
}
WQtGLWidget::CameraManipulators WQtGLWidget::getCameraManipulators()
{
return m_CurrentManipulator;
......
......@@ -36,6 +36,7 @@
#include "../../common/WFlag.hpp"
class WGEViewer;
class WColor;
/**
* A widget containing an open gl display area. This initializes OpenGL context and adds a view to the
......@@ -88,6 +89,11 @@ public:
*/
void setCameraManipulator( CameraManipulators manipulator );
/**
* Sets the background color of the widget.
*/
void setBgColor( WColor bgColor );
/**
* Returns the actually set camera manipulator.
*
......@@ -97,7 +103,7 @@ public:
/**
* Determines whether the widget is properly initialized.
*
*
* \return flag - initialized.
*/
const WBoolFlag& isInitialized() const;
......
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