Commit f0054591 authored by cornimueller's avatar cornimueller
Browse files

[MERGE]

parents ad466a38 1750bb0d
# This is a sample configuration file for OpenWalnut.
# Uncomment the options you are interested in.
## This is a sample configuration file for OpenWalnut.
## Uncomment the options you are interested in.
[modules]
# use this to specify the default module to add during load.
# It is a comma seperated list. If this is not specified the default is assumed:
# "Coordinate System Module,HUD"
default="Coordinate System Module,HUD"
## use this to specify the default module to add during load.
## It is a comma seperated list. If this is not specified the default empty is assumed.
## An example could be
# default="HUD"
# MC.isoValue = 110 # set standard isovalue for marching cubes module (isosurface)
[qt4gui]
......@@ -16,7 +16,7 @@ default="Coordinate System Module,HUD"
# useToolBarBreak = no # put compatibles toolbar in separate row
# useAutoDisplay = no # automatically add a standard module after loading a data module.
[ge] # Settings for the graphics engine
[ge] ## Settings for the graphics engine
# bgColor.r = .9 # background color (red part)
# bgColor.g = .9 # background color (green part)
# bgColor.b = .9 # background color (blue part)
......
......@@ -8,7 +8,9 @@ ADD_SUBDIRECTORY( constraints )
ADD_SUBDIRECTORY( math )
ADD_LIBRARY( common ${COMMON_SRC} ${COMMON_DATASTRUCTURES_SRC} ${COMMON_EXCEPTIONS_SRC} ${MATH_SRC} ${FIBERSIMILARITY_SRC} )
TARGET_LINK_LIBRARIES( common ${Boost_LIBRARIES} )
# The OSG Libs are needed for common as the unit tests will fail to compile
TARGET_LINK_LIBRARIES( common ${Boost_LIBRARIES} ${OPENSCENEGRAPH_LIBRARIES} )
# Unit tests
IF( OW_COMPILE_TESTS )
......
......@@ -24,4 +24,4 @@
#include "WPreferences.h"
WProperties WPreferences::m_preferences;
WProperties2 WPreferences::m_preferences;
......@@ -32,7 +32,7 @@
#include <boost/program_options.hpp>
#include "../common/WIOTools.h"
#include "WProperties.h"
#include "WProperties2.h"
#include "WLogger.h"
/**
......@@ -50,7 +50,7 @@ public:
template< typename T> static bool getPreference( std::string prefName, T* retVal );
protected:
private:
static WProperties m_preferences; //!< Structure for caching the preferences.
static WProperties2 m_preferences; //!< Structure for caching the preferences.
};
template< typename T > bool WPreferences::getPreference( std::string prefName, T* retVal )
......@@ -59,9 +59,11 @@ template< typename T > bool WPreferences::getPreference( std::string prefName, T
{
return false;
}
if( m_preferences.existsProp( prefName ) )
boost::shared_ptr< WPropertyBase > pref = m_preferences.findProperty( prefName );
if( pref )
{
*retVal = m_preferences.getValue< T >( prefName );
*retVal = pref->toPropertyVariable< T >()->get();
return true;
}
......@@ -103,7 +105,7 @@ template< typename T > bool WPreferences::getPreference( std::string prefName, T
if( configuration.count( prefName ) )
{
*retVal = configuration[ prefName ].as< T >();
m_preferences.addProperty( prefName, *retVal, true );
m_preferences.addProperty( prefName, "Preference cache.", *retVal );
return true;
}
else
......
//---------------------------------------------------------------------------
//
// 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 <iostream>
#include <map>
#include <string>
#include <vector>
#include "../common/WLogger.h"
#include "WProperties.h"
WProperties::WProperties()
{
}
WProperties::~WProperties()
{
}
boost::signals2::signal1< void, std::string >* WProperties::addBool( std::string name, bool value, bool hidden,
std::string shortDesc, std::string longDesc )
{
WLogger::getLogger()->addLogMessage( "[DEPRECATED] WProperty is deprecated. Use WPropertyVariable instead.", "WProperties", LL_WARNING );
WProperty* prop = new WProperty( name, value, hidden, shortDesc, longDesc );
m_propertyList[name] = prop;
m_propertyVector.push_back( prop );
return prop->getSignalValueChanged();
}
boost::signals2::signal1< void, std::string >* WProperties::addChar( std::string name, char value, bool hidden,
std::string shortDesc, std::string longDesc )
{
WLogger::getLogger()->addLogMessage( "[DEPRECATED] WProperty is deprecated. Use WPropertyVariable instead.", "WProperties", LL_WARNING );
WProperty* prop = new WProperty( name, value, hidden, shortDesc, longDesc );
m_propertyList[name] = prop;
m_propertyVector.push_back( prop );
return prop->getSignalValueChanged();
}
boost::signals2::signal1< void, std::string >* WProperties::addInt( std::string name, int value, bool hidden,
std::string shortDesc, std::string longDesc )
{
WLogger::getLogger()->addLogMessage( "[DEPRECATED] WProperty is deprecated. Use WPropertyVariable instead.", "WProperties", LL_WARNING );
WProperty* prop = new WProperty( name, value, hidden, shortDesc, longDesc );
m_propertyList[name] = prop;
m_propertyVector.push_back( prop );
return prop->getSignalValueChanged();
}
boost::signals2::signal1< void, std::string >* WProperties::addFloat( std::string name, float value, bool hidden,
std::string shortDesc, std::string longDesc )
{
WLogger::getLogger()->addLogMessage( "[DEPRECATED] WProperty is deprecated. Use WPropertyVariable instead.", "WProperties", LL_WARNING );
WProperty* prop = new WProperty( name, value, hidden, shortDesc, longDesc );
m_propertyList[name] = prop;
m_propertyVector.push_back( prop );
return prop->getSignalValueChanged();
}
boost::signals2::signal1< void, std::string >* WProperties::addDouble( std::string name, double value, bool hidden,
std::string shortDesc, std::string longDesc )
{
WLogger::getLogger()->addLogMessage( "[DEPRECATED] WProperty is deprecated. Use WPropertyVariable instead.", "WProperties", LL_WARNING );
WProperty* prop = new WProperty( name, value, hidden, shortDesc, longDesc );
m_propertyList[name] = prop;
m_propertyVector.push_back( prop );
return prop->getSignalValueChanged();
}
boost::signals2::signal1< void, std::string >*
WProperties::addString( std::string name, std::string value, bool hidden, std::string shortDesc, std::string longDesc )
{
WLogger::getLogger()->addLogMessage( "[DEPRECATED] WProperty is deprecated. Use WPropertyVariable instead.", "WProperties", LL_WARNING );
WProperty* prop = new WProperty( name, value, hidden, shortDesc, longDesc );
m_propertyList[name] = prop;
m_propertyVector.push_back( prop );
return prop->getSignalValueChanged();
}
boost::signals2::signal1< void, std::string >* WProperties::addColor( std::string name, WColor value, bool hidden,
std::string shortDesc, std::string longDesc )
{
WLogger::getLogger()->addLogMessage( "[DEPRECATED] WProperty is deprecated. Use WPropertyVariable instead.", "WProperties", LL_WARNING );
WProperty* prop = new WProperty( name, value, hidden, shortDesc, longDesc );
m_propertyList[name] = prop;
m_propertyVector.push_back( prop );
return prop->getSignalValueChanged();
}
void WProperties::addProperty( WProperty* prop )
{
WLogger::getLogger()->addLogMessage( "[DEPRECATED] WProperty is deprecated. Use WPropertyVariable instead.", "WProperties", LL_WARNING );
m_propertyList[prop->getName()] = prop;
m_propertyVector.push_back( prop );
}
bool WProperties::existsProp( std::string name )
{
return ( findProp( name ) != 0 );
}
WProperty* WProperties::findProp( std::string name )
{
if( m_propertyList.count( name ) != 0 )
{
return m_propertyList[name];
}
else
{
// TODO(schurade): since the gui tries to set properties over all connected modules, the error
// message here can be misleading, removing it for now
// std::string msg( "Property doesn't exist: " + name );
// WLogger::getLogger()->addLogMessage( msg, "Properties", LL_ERROR );
return 0;
}
}
std::string WProperties::getValueString( const std::string prop )
{
if( findProp( prop ) )
{
return findProp( prop )->getValueString();
}
return "";
}
std::vector< WProperty* >& WProperties::getPropertyVector()
{
return m_propertyVector;
}
void WProperties::hideProperty( std::string name )
{
if ( findProp( name ) )
{
findProp( name )->hide();
}
}
void WProperties::unhideProperty( std::string name )
{
if ( findProp( name ) )
{
findProp( name )->unhide();
}
}
void WProperties::reemitChangedValueSignals()
{
std::vector< WProperty* >::iterator iter;
for( iter = m_propertyVector.begin(); iter != m_propertyVector.end(); ++iter )
{
WProperty* property = *iter;
if( property->isDirty() )
{
property->dirty( false );
// Refire but don't change the value.
property->signalValueChanged();
}
}
}
bool WProperties::isDirty() const
{
std::vector< WProperty* >::const_iterator cit;
for( cit = m_propertyVector.begin(); cit != m_propertyVector.end(); ++cit )
{
if( ( *cit )->isDirty() )
{
return true;
}
}
return false;
}
//---------------------------------------------------------------------------
//
// 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 WPROPERTIES_H
#define WPROPERTIES_H
#include <map>
#include <string>
#include <vector>
#include <boost/thread/thread.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/locks.hpp>
#include <boost/thread.hpp>
#include "WProperty.h"
/**
* class to manage properties of an object and to provide convinience methods for easy access and manipulation
*/
class WProperties
{
public:
/**
* standard constructor
*/
WProperties();
/**
* destructor
*/
virtual ~WProperties();
/**
* sets a flag hidden, which can be used by the datasetbrowser for instance
*
* \param name of the property to hide
*/
void hideProperty( std::string name );
/**
* sets a flag hidden, which can be used by the datasetbrowser for instance
*
* \param name name of the property to unhide
*/
void unhideProperty( std::string name );
/**
* returns a vector to the properties sorted by their insertion order
*/
std::vector< WProperty* >& getPropertyVector();
/**
* adds a boolean property to the list of properties
*
* \param name of the property
* \param value of the property
* \param hidden true if hidden from automatic widget generation
* \param shortDesc short description
* \param longDesc long description
*
* \return pointer to boost signal object that is fired whern a property changes
*/
boost::signals2::signal1< void, std::string >*
addBool( std::string name, bool value = false, bool hidden = false, std::string shortDesc = "", std::string longDesc = "" );
/**
* adds a char property to the list of properties
*
* \param name of the property
* \param value of the property
* \param hidden true if hidden from automatic widget generation
* \param shortDesc short description
* \param longDesc long description
*
* \return pointer to boost signal object that is fired whern a property changes
*/
boost::signals2::signal1< void, std::string >*
addChar( std::string name, char value = 0, bool hidden = false, std::string shortDesc = "", std::string longDesc = "" );
/**
* adds an integer property to the list of properties
*
* \param name of the property
* \param value of the property
* \param hidden true if hidden from automatic widget generation
* \param shortDesc short description
* \param longDesc long description
*
* \return pointer to boost signal object that is fired whern a property changes
*/
boost::signals2::signal1< void, std::string >*
addInt( std::string name, int value = 0, bool hidden = false, std::string shortDesc = "", std::string longDesc = "" );
/**
* adds a float property to the list of properties
*
* \param name of the property
* \param value of the property
* \param hidden true if hidden from automatic widget generation
* \param shortDesc short description
* \param longDesc long description
*
* \return pointer to boost signal object that is fired whern a property changes
*/
boost::signals2::signal1< void, std::string >*
addFloat( std::string name, float value = 0.0, bool hidden = false, std::string shortDesc = "", std::string longDesc = "" );
/**
* adds a double property to the list of properties
*
* \param name of the property
* \param value of the property
* \param hidden true if hidden from automatic widget generation
* \param shortDesc short description
* \param longDesc long description
*
* \return pointer to boost signal object that is fired whern a property changes
*/
boost::signals2::signal1< void, std::string >*
addDouble( std::string name, double value = 0.0, bool hidden = false, std::string shortDesc = "", std::string longDesc = "" );
/**
* adds a string property to the list of properties
*
* \param name of the property
* \param value of the property
* \param hidden true if hidden from automatic widget generation
* \param shortDesc short description
* \param longDesc long description
*
* \return pointer to boost signal object that is fired whern a property changes
*/
boost::signals2::signal1< void, std::string >*
addString( std::string name, std::string value = "", bool hidden = false, std::string shortDesc = "", std::string longDesc = "" );
/**
* adds a color property to the list of properties
*
* \param name of the property
* \param value of the property
* \param hidden true if hidden from automatic widget generation
* \param shortDesc short description
* \param longDesc long description
*
* \return pointer to boost signal object that is fired whern a property changes
*/
boost::signals2::signal1< void, std::string >*
addColor( std::string name, WColor value, bool hidden = false, std::string shortDesc = "", std::string longDesc = "" );
/**
* adds a color property to the list of properties
*
* \param name of the property
* \param value of the property
* \param hidden true if hidden from automatic widget generation
* \param shortDesc short description
* \param longDesc long description
*
* \return pointer to boost signal object that is fired whern a property changes
*/
template< typename T> boost::signals2::signal1< void, std::string >*
addProperty( std::string name, T value, bool hidden = false, std::string shortDesc = "", std::string longDesc = "" );
/**
* Simply insert the specified property to the list.
*
* \param prop the property to add
*/
void addProperty( WProperty* prop );
/**
* getter for the value of a property as std string
*
* \param prop the name of the property
* \return string of property
*/
std::string getValueString( const std::string prop );
/**
* sets the value of an existing property
*
* \param prop string with name of property
* \param arg value
*/
template < typename T > void setValue( std::string prop, const T& arg )
{
boost::shared_lock< boost::shared_mutex > slock;
slock = boost::shared_lock< boost::shared_mutex >( m_updateLock );
if( findProp( prop ) )
{
findProp( prop )->setValue( arg );
}
slock.unlock();
}
/**
* sets the minimum value of an existing property
*
* \param prop string with name of property
* \param arg value
*/
template < typename T > void setMin( std::string prop, const T& arg )
{
if( findProp( prop ) )
{
findProp( prop )->setMin( arg );
}
}
/**
* sets the maximum value of an existing property
*
* \param prop string with name of property
* \param arg value
*/
template < typename T > void setMax( std::string prop, const T& arg )
{
if( findProp( prop ) )
{
findProp( prop )->setMax( arg );
}
}
/**
* returns the value of an existing property
*
* \param prop name of the property
* \return the value
*/
template < typename T > T getValue( std::string prop )
{
if( findProp( prop ) )
{
return findProp( prop )->getValue< T >();
}
// TODO(schurade): do not use NULL as return value in this case. Throw exception instead.
return 0;
}
/**
* returns the minimum value of an existing property
*
* \param prop name of the property
* \return the minimum value
*/
template < typename T > T getMin( std::string prop )
{
if( findProp( prop ) )
{
return findProp( prop )->getMin< T >();
}
// TODO(schurade): do not use NULL as return value in this case. Throw exception instead.
return 0;
}
/**
* returns the maximum value of an existing property
*
* \param prop name of the property
* \return the maximum value
*/
template < typename T > T getMax( std::string prop )
{
if( findProp( prop ) )
{
return findProp( prop )->getMax< T >();
}
// TODO(schurade): do not use NULL as return value in this case. Throw exception instead.
return 0;
}
/**
* helper function that finds a property by its name
*
* \param name name of searched property.
*/
bool existsProp( std::string name );
/**
* If there are WProperty objects which are marked as dirty, then their
* signals are reemitted.
*/
void reemitChangedValueSignals();
/**
* Indicates if at least one WProperty is dirty or all are clean.
*
* \return True if at least one property is dirty, false otherwise
*/
bool isDirty() const;
/**
* helper function that finds a property by its name
*
* \param name the name of the property