Commit 06d449f3 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum

[CHANGE] - selection properties now work, some constraints added....

[CHANGE] - selection properties now work, some constraints added. WPropertyVariable updated to meet requirements
parent 8e1d30a5
......@@ -63,7 +63,7 @@ WItemSelector WItemSelector::newSelector( const std::string asString ) const
return newSelector( l );
}
std::ostream& WItemSelector::operator<<( std::ostream& out )
std::ostream& WItemSelector::operator<<( std::ostream& out ) const
{
for ( WItemSelector::IndexList::const_iterator iter = m_selected.begin(); iter != m_selected.end(); ++iter )
{
......@@ -78,8 +78,7 @@ std::ostream& WItemSelector::operator<<( std::ostream& out )
std::ostream& operator<<( std::ostream& out, const WItemSelector& other )
{
out << other;
return out;
return other.operator<<( out );
}
bool WItemSelector::operator==( const WItemSelector& other ) const
......@@ -107,3 +106,8 @@ WItemSelection::Item WItemSelector::at( size_t index ) const
return m_selection->at( m_selected.at( index ) );
}
bool WItemSelector::empty() const
{
return ( size() == 0 );
}
......@@ -97,7 +97,7 @@ public:
*
* \return the output stream extended by the information of this selector
*/
std::ostream& operator<<( std::ostream& out );
std::ostream& operator<<( std::ostream& out ) const;
/**
* Gives the count of elements in the set of selectable items. This is \ref size + number of unselected items.
......@@ -113,6 +113,13 @@ public:
*/
virtual size_t size() const;
/**
* True if the selection is empty.
*
* \return true if nothing is selected.
*/
virtual bool empty() const;
/**
* Gets the item with the given index from the WItemSelection. This index does not equal the index of the same item for \ref at. This method
* is useful to go through the list of ALL items (not only the selected).
......
......@@ -34,6 +34,8 @@
#include "exceptions/WPropertyUnknown.h"
#include "exceptions/WPropertyNotUnique.h"
#include "WPropertyHelper.h"
#include "WProperties.h"
WProperties::WProperties( std::string name, std::string description ):
......@@ -239,7 +241,7 @@ WPropString WProperties::addProperty( std::string name, std::string description,
WPropFilename WProperties::addProperty( std::string name, std::string description, const WPVBaseTypes::PV_PATH& initial, bool hide )
{
WPropFilename p = addProperty< WPVBaseTypes::PV_PATH >( name, description, initial, hide );
p->addConstraint( WPVFilename::PropertyConstraint::create( PC_NOTEMPTY ) );
WPropertyHelper::PC_NOTEMPTY::addTo( p );
return p;
}
......@@ -304,7 +306,7 @@ WPropFilename WProperties::addProperty( std::string name, std::string descriptio
boost::shared_ptr< WCondition > condition, bool hide )
{
WPropFilename p = addProperty< WPVBaseTypes::PV_PATH >( name, description, initial, condition, hide );
p->addConstraint( WPVFilename::PropertyConstraint::create( PC_NOTEMPTY ) );
WPropertyHelper::PC_NOTEMPTY::addTo( p );
return p;
}
......@@ -373,7 +375,7 @@ WPropFilename WProperties::addProperty( std::string name, std::string descriptio
WPropertyBase::PropertyChangeNotifierType notifier, bool hide )
{
WPropFilename p = addProperty< WPVBaseTypes::PV_PATH >( name, description, initial, notifier, hide );
p->addConstraint( WPVFilename::PropertyConstraint::create( PC_NOTEMPTY ) );
WPropertyHelper::PC_NOTEMPTY::addTo( p );
return p;
}
......@@ -448,7 +450,7 @@ WPropFilename WProperties::addProperty( std::string name, std::string descriptio
WPropertyBase::PropertyChangeNotifierType notifier, bool hide )
{
WPropFilename p = addProperty< WPVBaseTypes::PV_PATH >( name, description, initial, condition, notifier, hide );
p->addConstraint( WPVFilename::PropertyConstraint::create( PC_NOTEMPTY ) );
WPropertyHelper::PC_NOTEMPTY::addTo( p );
return p;
}
......
//---------------------------------------------------------------------------
//
// 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 "WPropertyHelper.h"
namespace WPropertyHelper
{
namespace PC_SELECTONLYONE
{
void addTo( WPropSelection prop )
{
prop->addConstraint( boost::shared_ptr< WPropertyConstraintSelectOnlyOne< WPVBaseTypes::PV_SELECTION > >(
new WPropertyConstraintSelectOnlyOne< WPVBaseTypes::PV_SELECTION >
) );
}
}
namespace PC_NOTEMPTY
{
void addTo( WPropSelection prop )
{
prop->addConstraint( boost::shared_ptr< WPropertyConstraintNotEmpty< WPVBaseTypes::PV_SELECTION > >(
new WPropertyConstraintNotEmpty< WPVBaseTypes::PV_SELECTION >
) );
}
void addTo( WPropString prop )
{
prop->addConstraint( boost::shared_ptr< WPropertyConstraintNotEmpty< WPVBaseTypes::PV_STRING > >(
new WPropertyConstraintNotEmpty< WPVBaseTypes::PV_STRING >
) );
}
void addTo( WPropFilename prop )
{
prop->addConstraint( boost::shared_ptr< WPropertyConstraintNotEmpty< WPVBaseTypes::PV_PATH > >(
new WPropertyConstraintNotEmpty< WPVBaseTypes::PV_PATH >
) );
}
}
namespace PC_PATHEXISTS
{
void addTo( WPropFilename prop )
{
prop->addConstraint( boost::shared_ptr< WPropertyConstraintPathExists< WPVBaseTypes::PV_PATH > >(
new WPropertyConstraintPathExists< WPVBaseTypes::PV_PATH >()
) );
}
}
namespace PC_ISDIRECTORY
{
void addTo( WPropFilename prop )
{
prop->addConstraint( boost::shared_ptr< WPropertyConstraintIsDirectory< WPVBaseTypes::PV_PATH > >(
new WPropertyConstraintIsDirectory< WPVBaseTypes::PV_PATH >()
) );
}
}
}
//---------------------------------------------------------------------------
//
// 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 WPROPERTYHELPER_H
#define WPROPERTYHELPER_H
#include <boost/shared_ptr.hpp>
#include "WPropertyVariable.h"
#include "constraints/WPropertyConstraintNotEmpty.h"
#include "constraints/WPropertyConstraintPathExists.h"
#include "constraints/WPropertyConstraintIsDirectory.h"
#include "constraints/WPropertyConstraintSelectOnlyOne.h"
/**
* This namespace contains several utility functions to handle properties. Especially constraint helper to easily create constraints.
*/
namespace WPropertyHelper
{
/**
* Contains functions for easily adding constraints of type PC_SELECTONLYONE to properties compatible with this constraint.
*/
namespace PC_SELECTONLYONE
{
/**
* Add the PC_SELECTONLYONE constraint to the property.
*
* \param prop the property where to add the constraint.
*/
void addTo( WPropSelection prop );
}
/**
* Contains functions for easily adding constraints of type PC_NOTEMPTY to properties compatible with this constraint.
*/
namespace PC_NOTEMPTY
{
/**
* Add the PC_NOTEMPTY constraint to the property.
*
* \param prop the property where to add the constraint.
*/
void addTo( WPropSelection prop );
/**
* Add the PC_NOTEMPTY constraint to the property.
*
* \param prop the property where to add the constraint.
*/
void addTo( WPropString prop );
/**
* Add the PC_NOTEMPTY constraint to the property.
*
* \param prop the property where to add the constraint.
*/
void addTo( WPropFilename prop );
}
/**
* Contains functions for easily adding constraints of type PC_PATHEXISTS to properties compatible with this constraint.
*/
namespace PC_PATHEXISTS
{
/**
* Add the PC_PATHEXISTS constraint to the property.
*
* \param prop the property where to add the constraint.
*/
void addTo( WPropFilename prop );
}
/**
* Contains functions for easily adding constraints of type PC_ISDIRECTORY to properties compatible with this constraint.
*/
namespace PC_ISDIRECTORY
{
/**
* Add the PC_PATHEXISTS constraint to the property.
*
* \param prop the property where to add the constraint.
*/
void addTo( WPropFilename prop );
}
}
#endif // WPROPERTYHELPER_H
......@@ -22,5 +22,12 @@
//
//---------------------------------------------------------------------------
#include "constraints/WPropertyConstraintMin.h"
#include "constraints/WPropertyConstraintMax.h"
#include "constraints/WPropertyConstraintNotEmpty.h"
#include "constraints/WPropertyConstraintPathExists.h"
#include "constraints/WPropertyConstraintIsDirectory.h"
#include "constraints/WPropertyConstraintSelectOnlyOne.h"
#include "WPropertyVariable.h"
......@@ -42,6 +42,7 @@
#include "WFlag.h"
#include "WPropertyBase.h"
#include "WCondition.h"
#include "WSharedAssociativeContainer.h"
#include "constraints/WPropertyConstraintTypes.h"
......@@ -50,8 +51,8 @@
#include "constraints/WPropertyConstraintNotEmpty.h"
#include "constraints/WPropertyConstraintPathExists.h"
#include "constraints/WPropertyConstraintIsDirectory.h"
#include "constraints/WPropertyConstraintSelectOnlyOne.h"
#include "WCondition.h"
/**
* A named property class with a concrete type.
......@@ -230,19 +231,10 @@ public:
void addConstraint( boost::shared_ptr< PropertyConstraint > constraint );
/**
* Add a new constraint. It creates one for your with the specified type.
*
* \param constraint the type of constraint.
* Returns all the current constraints of a WPropertyVariable. They can be iterated using the provided access object.
*
* \return the constraint created and added.
* \return the constraint access object
*/
boost::shared_ptr< PropertyConstraint > addConstraint( PROPERTYCONSTRAINT_TYPE constraint );
/**
* Returns all the current constraints of a WPropertyVariable. They can be iterated using the provided access object.
*
* \return the constraint access object
*/
ConstraintAccess getConstraints();
/**
......@@ -558,15 +550,6 @@ void WPropertyVariable< T >::addConstraint( boost::shared_ptr< PropertyConstrain
m_constraintsChanged->notify();
}
template < typename T >
boost::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint >
WPropertyVariable< T >::addConstraint( PROPERTYCONSTRAINT_TYPE constraint )
{
boost::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint > c = PropertyConstraint::create( constraint );
addConstraint( c );
return c;
}
template < typename T >
boost::shared_ptr< WCondition > WPropertyVariable< T >::getContraintsChangedCondition()
{
......@@ -748,38 +731,5 @@ PROPERTYCONSTRAINT_TYPE WPropertyVariable< T >::PropertyConstraint::getType()
return PC_UNKNOWN;
}
template < typename T >
boost::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint >
WPropertyVariable< T >::PropertyConstraint::create( PROPERTYCONSTRAINT_TYPE type )
{
typename WPropertyVariable< T >::PropertyConstraint* c = NULL;
// simply create a new instance for all those constraints.
switch( type )
{
case PC_MIN: // min and max constraints can't be created this way since they need a construction parameter
WLogger::getLogger()->addLogMessage( "Minimum property constraints can't be created this way. Use setMin() instead.",
"PropertyConstraint::create", LL_WARNING );
break;
case PC_MAX:
WLogger::getLogger()->addLogMessage( "Maximum property constraints can't be created this way. Use setMax() instead.",
"PropertyConstraint::create", LL_WARNING );
break;
case PC_NOTEMPTY:
c = new WPropertyConstraintNotEmpty< T >();
break;
case PC_PATHEXISTS:
c = new WPropertyConstraintPathExists< T >();
break;
case PC_ISDIRECTORY:
c = new WPropertyConstraintIsDirectory< T >();
break;
default:
WLogger::getLogger()->addLogMessage( "The property constraint is unknown.", "PropertyConstraint::create", LL_WARNING );
break;
}
return boost::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint >( c );
}
#endif // WPROPERTYVARIABLE_H
......@@ -28,7 +28,7 @@
#include "../WPropertyTypes.h"
#include "WPropertyConstraintTypes.h"
template< typename T >
template < typename T >
class WPropertyVariable;
/**
......
//---------------------------------------------------------------------------
//
// 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 "WPropertyConstraintSelectOnlyOne.h"
#include "../WPropertyVariable.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 WPROPERTYCONSTRAINTSELECTONLYONE_H
#define WPROPERTYCONSTRAINTSELECTONLYONE_H
#include "../WPropertyTypes.h"
#include "WPropertyConstraintTypes.h"
template< typename T >
class WPropertyVariable;
/**
* This class allows constraining selection properties to not allow selection of multiple items.
*/
template < typename T >
class WPropertyConstraintSelectOnlyOne: public WPropertyVariable< T >::PropertyConstraint
{
public:
/**
* Constructor.
*/
explicit WPropertyConstraintSelectOnlyOne();
/**
* Destructor.
*/
virtual ~WPropertyConstraintSelectOnlyOne();
/**
* Checks whether the specified value is a directory or not.
*
* \param property the property whose new value should be set.
* \param value the new value to check
*
* \return true if the file/path is a directory
*/
virtual bool accept( boost::shared_ptr< WPropertyVariable< T > > property, T value );
/**
* Allows simple identification of the real constraint type.
*
* \return the type
*/
virtual PROPERTYCONSTRAINT_TYPE getType();
private:
};
template < typename T >
WPropertyConstraintSelectOnlyOne< T >::WPropertyConstraintSelectOnlyOne()
{
}
template < typename T >
WPropertyConstraintSelectOnlyOne< T >::~WPropertyConstraintSelectOnlyOne()
{
}
template < typename T >
bool WPropertyConstraintSelectOnlyOne< T >::accept( boost::shared_ptr< WPropertyVariable< T > > /* property */, T value )
{
return ( value.size() <= 1 );
}
template < typename T >
PROPERTYCONSTRAINT_TYPE WPropertyConstraintSelectOnlyOne< T >::getType()
{
return PC_SELECTONLYONE;
}
#endif // WPROPERTYCONSTRAINTSELECTONLYONE_H
......@@ -31,12 +31,14 @@
*/
typedef enum
{
PC_UNKNOWN, // type ID for arbitrary WPropertyConstraint
PC_MIN, // type ID for WPropertyConstraintMin
PC_MAX, // type ID for WPropertyConstraintMax
PC_NOTEMPTY, // type ID for WPropertyConstraintNotEmpty
PC_PATHEXISTS, // type ID for WPropertyConstraintPathExists
PC_ISDIRECTORY // type ID for WPropertyConstraintIsDirectory
PC_UNKNOWN, // type ID for arbitrary WPropertyConstraint
PC_MIN, // type ID for WPropertyConstraintMin
PC_MAX, // type ID for WPropertyConstraintMax
PC_NOTEMPTY, // type ID for WPropertyConstraintNotEmpty
PC_PATHEXISTS, // type ID for WPropertyConstraintPathExists
PC_ISDIRECTORY, // type ID for WPropertyConstraintIsDirectory
PC_SELECTONLYONE, // type ID for WPropertyConstraintSelectOnlyOne
PC_SELECTATLEASTONE // type ID for WPropertyConstraintSelectAtLeastOne
}
PROPERTYCONSTRAINT_TYPE;
......
......@@ -32,6 +32,7 @@
#include "../../common/WColor.h"
#include "../../common/WLogger.h"
#include "../../common/WProgress.h"
#include "../../common/WPropertyHelper.h"
#include "../../common/datastructures/WFiber.h"
#include "../../dataHandler/WDataSetFiberVector.h"
#include "../../dataHandler/WSubject.h"
......@@ -132,7 +133,7 @@ void WMFiberCulling::properties()
m_savePath = m_properties->addProperty( "Save path", "Where to save the result", boost::filesystem::path( "/no/such/file" ) );
m_run = m_properties->addProperty( "Run", "Go go go with those parameters", false, m_recompute );
m_run->get( true ); // reset so no initial run occurs
m_savePath->addConstraint( PC_NOTEMPTY );
WPropertyHelper::PC_PATHEXISTS::addTo( m_savePath );
}
void WMFiberCulling::cullOutFibers()
......
......@@ -31,6 +31,7 @@
#include "../../common/WCondition.h"
#include "../../common/WProgress.h"
#include "../../common/WPropertyTypes.h"
#include "../../common/WPropertyHelper.h"
#include "../../dataHandler/WDataSetFiberVector.h"
#include "../../dataHandler/WDataSetFibers.h"
#include "../../dataHandler/io/WWriterFiberVTK.h"
......@@ -39,7 +40,6 @@
#include "../../kernel/WModuleOutputData.h"
#include "WMFiberTransform.h"
WMFiberTransform::WMFiberTransform()
: WModule(),
m_recompute( new WCondition() ),
......@@ -76,7 +76,7 @@ void WMFiberTransform::properties()
m_savePath = m_properties->addProperty( "Save path", "Where to save the result", boost::filesystem::path( "/no/such/file" ) );
m_run = m_properties->addProperty( "Run", "Do the transformation", WPVBaseTypes::PV_TRIGGER_READY, m_recompute );
m_run->get( true ); // reset so no initial run occurs
m_savePath->addConstraint( PC_NOTEMPTY );
WPropertyHelper::PC_PATHEXISTS::addTo( m_savePath );
}
void WMFiberTransform::moduleMain()
......
......@@ -60,6 +60,7 @@
#include "../../kernel/WKernel.h"
#include "../../common/WColor.h"
#include "../../common/WPropertyHelper.h"
#include "template.xpm"
#include "WMTemplate.h"
......@@ -188,16 +189,16 @@ void WMTemplate::properties()
// world. As with connectors, a property which not has been added to m_properties is not visible for others. Now, how to add a new property?
m_propCondition = boost::shared_ptr< WCondition >( new WCondition() );
m_aTrigger = m_properties->addProperty( "Do It Now!", "Trigger Button Text.",
WPVBaseTypes::PV_TRIGGER_READY, m_propCondition );
m_enableFeature = m_properties->addProperty( "Enable Feature", "Description.", true );
m_anInteger = m_properties->addProperty( "Number of Shape Rows", "Number of shape rows.", 10, m_propCondition );
m_anIntegerClone = m_properties->addProperty( "CLONE!Number of Shape Rows",
"A property which gets modified if \"Number of shape rows\" gets modified.", 10 );
m_aDouble = m_properties->addProperty( "Shape Radii", "Shape radii.", 20.0, m_propCondition );
m_aString = m_properties->addProperty( "A String", "Something.", std::string( "hello" ), m_propCondition );
m_aFile = m_properties->addProperty( "A Filenname", "Description.", WKernel::getAppPathObject(), m_propCondition );
m_aColor = m_properties->addProperty( "A Color", "Description.", WColor( 1.0, 0.0, 0.0, 1.0 ) );
m_aTrigger = m_properties->addProperty( "Do It Now!", "Trigger Button Text.", WPVBaseTypes::PV_TRIGGER_READY,
m_propCondition );
m_enableFeature = m_properties->addProperty( "Enable Feature", "Description.", true );
m_anInteger = m_properties->addProperty( "Number of Shape Rows", "Number of shape rows.", 10, m_propCondition );
m_anIntegerClone = m_properties->addProperty( "CLONE!Number of Shape Rows",
"A property which gets modified if \"Number of shape rows\" gets modified.", 10 );
m_aDouble = m_properties->addProperty( "Shape Radii", "Shape radii.", 20.0, m_propCondition );
m_aString = m_properties->addProperty( "A String", "Something.", std::string( "hello" ), m_propCondition );
m_aFile = m_properties->addProperty( "A Filenname", "Description.", WKernel::getAppPathObject(), m_propCondition );
m_aColor = m_properties->addProperty( "A Color", "Description.", WColor( 1.0, 0.0, 0.0, 1.0 ) );
// These lines create some new properties and add them to the property list of this module. The specific type to create is determined by the
// initial value specified in the third argument. The first argument is the name of the property, which needs to be unique among all
......@@ -214,6 +215,21 @@ void WMTemplate::properties()
// GUI updates itself. You can, for example, set constraints or simply modify values depending on input data, most probably useful to set
// nice default values or min/max constraints.
// All these above properties are not that usable for selections. Assume the following situation. Your module allows two different kinds of
// algorithms to run on some data and you want the user to select which one should do the work. This might be done integer properties but it
// is simply ugly. Therefore, properties of type WPropSelection are available. First you need to define a list of alternatives:
m_possibleSelections = boost::shared_ptr< WItemSelection >( new WItemSelection() );
m_possibleSelections->addItem( "Select", "Description" );
m_possibleSelections->addItem( "Me", "Description" );
m_possibleSelections->addItem( "Please", "Description" );
// This list of alternatives is NOT the actual property value. It is the list on which so called "WItemSelector" instances work. These
// selectors are the actual property. After you created the first selector instance from the list, it can't be modified anymore. This ensures
// that it is consistent among multiple threads and selection instances. The following two lines create two selectors as initial value and