Commit f1ab77c5 authored by schurade's avatar schurade
Browse files

[Merge] with 06de740ebeab42d1bd8157d2202553bf4b5c0645

parents 069f3492 c56cd6a7
......@@ -107,6 +107,12 @@ boost::signals2::signal1< void, std::string >* WProperties::addColor( std::strin
return prop->getSignalValueChanged();
}
void WProperties::addProperty( WProperty* prop )
{
m_propertyList[prop->getName()] = prop;
m_propertyVector.push_back( prop );
}
bool WProperties::existsProp( std::string name )
{
return ( findProp( name ) != 0 );
......@@ -159,3 +165,30 @@ void WProperties::unhideProperty( std::string name )
}
}
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;
}
......@@ -183,6 +183,13 @@ public:
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
*
......@@ -296,7 +303,19 @@ public:
*/
bool existsProp( std::string name );
private:
/**
* 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
*
......@@ -305,6 +324,7 @@ private:
*/
WProperty* findProp( std::string name );
private:
/**
* map of properties for easy access with name string
*/
......
......@@ -28,84 +28,61 @@
WProperty::WProperty( std::string name, std::string value, bool hidden, std::string shortDesc, std::string longDesc )
: m_type( P_STRING ),
m_name( name ),
m_value( value ),
m_shortDesc( shortDesc ),
m_longDesc( longDesc ),
m_isHidden( hidden )
m_value( value )
{
initMembers( name, shortDesc, longDesc, hidden );
}
WProperty::WProperty( std::string name, bool value, bool hidden, std::string shortDesc, std::string longDesc )
: m_type( P_BOOL ),
m_name( name ),
m_shortDesc( shortDesc ),
m_longDesc( longDesc ),
m_isHidden( hidden )
: m_type( P_BOOL )
{
setValue( value );
initMembers( name, shortDesc, longDesc, hidden );
}
WProperty::WProperty( std::string name, char value, bool hidden, std::string shortDesc, std::string longDesc )
: m_type( P_CHAR ),
m_name( name ),
m_shortDesc( shortDesc ),
m_longDesc( longDesc ),
m_isHidden( hidden )
: m_type( P_CHAR )
{
setMin( -128 );
setMax( 127 );
setValue( value );
initMembers( name, shortDesc, longDesc, hidden );
}
WProperty::WProperty( std::string name, int value, bool hidden, std::string shortDesc, std::string longDesc )
: m_type( P_INT ),
m_name( name ),
m_shortDesc( shortDesc ),
m_longDesc( longDesc ),
m_isHidden( hidden )
: m_type( P_INT )
{
setMin( 0 );
setMax( 255 );
setValue( value );
initMembers( name, shortDesc, longDesc, hidden );
}
WProperty::WProperty( std::string name, float value, bool hidden, std::string shortDesc, std::string longDesc )
: m_type( P_FLOAT ),
m_name( name ),
m_shortDesc( shortDesc ),
m_longDesc( longDesc ),
m_isHidden( hidden )
: m_type( P_FLOAT )
{
setMin( 0.0 );
setMax( 100.0 );
setValue( value );
initMembers( name, shortDesc, longDesc, hidden );
}
WProperty::WProperty( std::string name, double value, bool hidden, std::string shortDesc, std::string longDesc )
: m_type( P_DOUBLE ),
m_name( name ),
m_shortDesc( shortDesc ),
m_longDesc( longDesc ),
m_isHidden( hidden )
: m_type( P_DOUBLE )
{
setMin( 0.0 );
setMax( 100.0 );
setValue( value );
initMembers( name, shortDesc, longDesc, hidden );
}
WProperty::WProperty( std::string name, WColor value, bool hidden, std::string shortDesc, std::string longDesc )
: m_type( P_DOUBLE ),
m_name( name ),
m_shortDesc( shortDesc ),
m_longDesc( longDesc ),
m_isHidden( hidden )
: m_type( P_DOUBLE )
{
setValue( value );
initMembers( name, shortDesc, longDesc, hidden );
}
WProperty::~WProperty()
{
}
......@@ -165,6 +142,30 @@ bool WProperty::isHidden()
return m_isHidden;
}
bool WProperty::isDirty() const
{
return m_isDirty;
}
void WProperty::dirty( bool isDirty )
{
m_isDirty = isDirty;
}
void WProperty::initMembers( const std::string& name, const std::string& shortDesc, const std::string& longDesc, const bool hidden )
{
m_name = name;
m_shortDesc = shortDesc;
m_longDesc = longDesc;
m_isHidden = hidden;
m_isDirty = false;
}
void WProperty::signalValueChanged()
{
m_signalValueChanged( m_name );
}
boost::signals2::signal1< void, std::string >* WProperty::getSignalValueChanged()
{
return &m_signalValueChanged;
......
......@@ -210,7 +210,7 @@ public:
{
m_value = "";
}
m_signalValueChanged( m_name );
signalValueChanged();
}
/**
......@@ -284,7 +284,44 @@ public:
*/
std::string getValueString();
/**
* Determines if this property is considered to be dirty. A Property can be
* dirty if its value changes but its change cannot be applied in the
* module. This can have several reasons: e.g. module is busy and is
* working with current values of the properties. So it recognizes the
* change and mark those properties as dirty for later update.
*
* \return True if this property has unhandled change events and needs a
* fresh update handling
*/
bool isDirty() const;
/**
* Marks a property as dirty. For more details on the dirtyness \see isDirty().
*
* \param isDirty True if it is dirty, false if appropriate actions took
* place so it is not dirty anymore.
*/
void dirty( bool isDirty );
/**
* Fires the signal
*/
void signalValueChanged();
private:
/**
* Use this only in constructors to initialize the members. The only reason
* why this member function exists is not to repeat your self. This makes
* it easy to add new member variabels.
*
* \param name
* \param shortDesc
* \param longDesc
* \param hidden
*/
void initMembers( const std::string& name, const std::string& shortDesc, const std::string& longDesc, const bool hidden );
/**
* type of property
*/
......@@ -325,10 +362,12 @@ private:
*/
bool m_isHidden;
bool m_isDirty; //!< True if the property has changed but its changed weren't consumed
/**
* boost signal object to indicate property changes
*/
boost::signals2::signal1< void, std::string >m_signalValueChanged;
boost::signals2::signal1< void, std::string > m_signalValueChanged;
};
#endif // WPROPERTY_H
//---------------------------------------------------------------------------
//
// 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 "WProperty2.h"
WProperty2::WProperty2( std::string name, std::string description ):
m_name( name ),
m_description( description )
{
// initialize members
}
WProperty2::~WProperty2()
{
// clean up
}
std::string WProperty2::getName() const
{
return m_name;
}
std::string WProperty2::getDescription() const
{
return m_description;
}
//---------------------------------------------------------------------------
//
// 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 WPROPERTY2_H
#define WPROPERTY2_H
#include <string>
#include "WPropertyTypes.h"
/**
* Class managing a single named property.
*/
class WProperty2
{
public:
/**
* Create an empty instance just containing a name.
*
* \param name the property name
* \param description the property description
*/
WProperty2( std::string name, std::string description );
/**
* Destructor.
*/
virtual ~WProperty2();
/**
* Get the name of the property.
*
* \return the name.
*/
std::string getName() const;
/**
* Get the description of the property.
*
* \return the description.
*/
std::string getDescription() const;
/**
* Returns the actual type of the property. This is needed to identify all subclassed types.
*
* \return the type.
*/
virtual PROPERTY_TYPE getType() const = 0;
protected:
/**
* Name of the property.
*/
std::string m_name;
/**
* Description of the property.
*/
std::string m_description;
private:
};
#endif // WPROPERTY2_H
//---------------------------------------------------------------------------
//
// 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 WPROPERTYTYPES_H
#define WPROPERTYTYPES_H
/**
* Enum of all possible types, that can be used with WProperty.
*/
typedef enum
{
UNKNOWN, // type not know
INT, // integer value
DOUBLE, // floating point value
BOOL, // boolean
STRING // a string
}
PROPERTY_TYPE;
#endif // WPROPERTYTYPES_H
//---------------------------------------------------------------------------
//
// 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 "WPropertyVariable.h"
void hallo()
{
WPropertyVariable< bool > p( "ich", "du", 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 WPROPERTYVARIABLE_H
#define WPROPERTYVARIABLE_H
#include <stdint.h>
#include <string>
#include <typeinfo>
#include "WProperty2.h"
/**
* A named property class with a concrete type.
*/
template< typename T >
class WPropertyVariable: public WProperty2
{
public:
/**
* Create an empty instance just containing a name.
*
* \param name the property name
* \param description the property description
* \param initial the initial value
*/
WPropertyVariable( std::string name, std::string description, const T& initial ):
WProperty2( name, description )
{
// initialize everything
}
/**
* Destructor.
*/
virtual ~WPropertyVariable()
{
// clean up
}
T& get() const
{
return m_value;
}
void set( T& val )
{
m_value = val;
}
virtual PROPERTY_TYPE getType() const
{
if ( typeid( T ) == typeid( int ) )
return INT;
else
return INT;
}
protected:
/**
* The actual variable handled by this property.
*/
T m_value;
private:
};
#endif // WPROPERTYVARIABLE_H
......@@ -14,5 +14,13 @@ TARGET_LINK_LIBRARIES( ge common ${OPENGL_gl_LIBRARY} ${OPENSCENEGRAPH_LIBRARIES
# Unit tests
IF( OW_COMPILE_TESTS )
CXXTEST_ADD_TESTS_FROM_LIST( "${GE_SRC}" "ge;math" )
ENDIF( OW_COMPILE_TESTS )
\ No newline at end of file
CXXTEST_ADD_TESTS_FROM_LIST( "${GE_SRC}" "ge;math"
"WGESignals.cpp"
"WGraphicsEngine.cpp"
"WGEScene.cpp"
"WGEResourceManager.cpp"
"WGEViewer.cpp"
"WGEGraphicsWindow.cpp"
"WGEGroupNode.cpp"
)
ENDIF( OW_COMPILE_TESTS )
//---------------------------------------------------------------------------
//
// 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.