Commit 6cd356ed authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum

[ADD] - added trigger property. How to use? See template module.

parent 36b399b0
......@@ -244,6 +244,11 @@ WPropColor WProperties::addProperty( std::string name, std::string description,
return addProperty< WPVBaseTypes::PV_COLOR >( name, description, initial, hide );
}
WPropTrigger WProperties::addProperty( std::string name, std::string description, const WPVBaseTypes::PV_TRIGGER& initial, bool hide )
{
return addProperty< WPVBaseTypes::PV_TRIGGER >( name, description, initial, hide );
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// convenience methods for
// template< typename T>
......@@ -307,6 +312,12 @@ WPropColor WProperties::addProperty( std::string name, std::string description,
return addProperty< WPVBaseTypes::PV_COLOR >( name, description, initial, condition, hide );
}
WPropTrigger WProperties::addProperty( std::string name, std::string description, const WPVBaseTypes::PV_TRIGGER& initial,
boost::shared_ptr< WCondition > condition, bool hide )
{
return addProperty< WPVBaseTypes::PV_TRIGGER >( name, description, initial, condition, hide );
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// convenience methods for
// template< typename T>
......@@ -370,6 +381,11 @@ WPropColor WProperties::addProperty( std::string name, std::string description,
return addProperty< WPVBaseTypes::PV_COLOR >( name, description, initial, notifier, hide );
}
WPropTrigger WProperties::addProperty( std::string name, std::string description, const WPVBaseTypes::PV_TRIGGER& initial,
WPropertyBase::PropertyChangeNotifierType notifier, bool hide )
{
return addProperty< WPVBaseTypes::PV_TRIGGER >( name, description, initial, notifier, hide );
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// convenience methods for
......@@ -443,3 +459,10 @@ WPropColor WProperties::addProperty( std::string name, std::string description,
return addProperty< WPVBaseTypes::PV_COLOR >( name, description, initial, condition, notifier, hide );
}
WPropTrigger WProperties::addProperty( std::string name, std::string description, const WPVBaseTypes::PV_TRIGGER& initial,
boost::shared_ptr< WCondition > condition,
WPropertyBase::PropertyChangeNotifierType notifier, bool hide )
{
return addProperty< WPVBaseTypes::PV_TRIGGER >( name, description, initial, condition, notifier, hide );
}
......@@ -364,6 +364,19 @@ public:
*/
WPropColor addProperty( std::string name, std::string description, const WPVBaseTypes::PV_COLOR& initial, bool hide = false );
/**
* Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
*
* \see WPropertyVariable
*
* \param name the property name
* \param description the property description
* \param initial the initial value
* \param hide set to true to set the hide flag directly.
*
* \return the newly created property variable instance.
*/
WPropTrigger addProperty( std::string name, std::string description, const WPVBaseTypes::PV_TRIGGER& initial, bool hide = false );
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// convenience methods for
......@@ -502,6 +515,22 @@ public:
WPropColor addProperty( std::string name, std::string description, const WPVBaseTypes::PV_COLOR& initial,
boost::shared_ptr< WCondition > condition, bool hide = false );
/**
* Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
*
* \see WPropertyVariable
*
* \param name the property name
* \param description the property description
* \param initial the initial value
* \param condition use this external condition for notification.
* \param hide set to true to set the hide flag directly.
*
* \return the newly created property variable instance.
*/
WPropTrigger addProperty( std::string name, std::string description, const WPVBaseTypes::PV_TRIGGER& initial,
boost::shared_ptr< WCondition > condition, bool hide = false );
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// convenience methods for
// template< typename T>
......@@ -638,6 +667,23 @@ public:
*/
WPropColor addProperty( std::string name, std::string description, const WPVBaseTypes::PV_COLOR& initial,
WPropertyBase::PropertyChangeNotifierType notifier, bool hide = false );
/**
* Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
*
* \see WPropertyVariable
*
* \param name the property name
* \param description the property description
* \param initial the initial value
* \param notifier use this notifier for change callbacks.
* \param hide set to true to set the hide flag directly.
*
* \return the newly created property variable instance.
*/
WPropTrigger addProperty( std::string name, std::string description, const WPVBaseTypes::PV_TRIGGER& initial,
WPropertyBase::PropertyChangeNotifierType notifier, bool hide = false );
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// convenience methods for
// template< typename T>
......@@ -793,6 +839,24 @@ public:
boost::shared_ptr< WCondition > condition,
WPropertyBase::PropertyChangeNotifierType notifier, bool hide = false );
/**
* Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
*
* \see WPropertyVariable
*
* \param name the property name
* \param description the property description
* \param initial the initial value
* \param notifier use this notifier for change callbacks.
* \param condition use this external condition for notification
* \param hide set to true to set the hide flag directly.
*
* \return the newly created property variable instance.
*/
WPropTrigger addProperty( std::string name, std::string description, const WPVBaseTypes::PV_TRIGGER& initial,
boost::shared_ptr< WCondition > condition,
WPropertyBase::PropertyChangeNotifierType notifier, bool hide = false );
protected:
/**
......
......@@ -131,6 +131,11 @@ WPropGroup WPropertyBase::toPropGroup()
return boost::shared_static_cast< WPVGroup >( shared_from_this() );
}
WPropTrigger WPropertyBase::toPropTrigger()
{
return boost::shared_static_cast< WPVTrigger >( shared_from_this() );
}
boost::shared_ptr< WCondition > WPropertyBase::getUpdateCondition() const
{
return m_updateCondition;
......
......@@ -186,6 +186,13 @@ public:
*/
WPropPosition toPropPosition();
/**
* Helper converts this instance to its native type.
*
* \return the property as trigger property
*/
WPropTrigger toPropTrigger();
/**
* Helper converts this instance to its native type.
*
......
//---------------------------------------------------------------------------
//
// 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 "WPropertyTypes.h"
std::ostream& WPVBaseTypes::operator<<( std::ostream& out, const WPVBaseTypes::PV_TRIGGER& c )
{
out << c;
return out;
}
std::istream& WPVBaseTypes::operator>>( std::istream& in, WPVBaseTypes::PV_TRIGGER& c )
{
in >> c;
return in;
}
......@@ -62,13 +62,14 @@ typedef enum
PV_PATH, // a Boost Path object denoting a filename/path
PV_SELECTION, // a list of strings, selectable
PV_POSITION, // a position property
PV_COLOR // a color property
PV_COLOR, // a color property
PV_TRIGGER // for triggering an event
}
PROPERTY_TYPE;
/**
* Namespace containing all base types of the WPropertyVariables. Use these types instead of issuing int32_t, double, bool, ...
* directly.
* directly. It also contains some user defined types including the needed operators.
*
* \note You can use only types which overwrite the << and >> operators!
*/
......@@ -83,6 +84,21 @@ namespace WPVBaseTypes
// typedef std::list< std::pair< std::string, bool > > PV_SELECTION; //!< base type used for every WPVSelection
typedef wmath::WPosition PV_POSITION; //!< base type used for every WPVPosition
typedef WColor PV_COLOR; //!< base type used for every WPVColor
typedef enum
{
PV_TRIGGER_READY = 0, //!< Trigger property: is ready to be triggered (again)
PV_TRIGGER_TRIGGERED //!< Trigger property: got triggered
} PV_TRIGGER; //!< base type used for every WPVTrigger
/**
* Write a PV_TRIGGER in string representation to the given output stream.
*/
std::ostream& operator<<( std::ostream& out, const PV_TRIGGER& c );
/**
* Write a PV_TRIGGER in string representation to the given input stream.
*/
std::istream& operator>>( std::istream& in, PV_TRIGGER& c );
}
/**
......@@ -136,6 +152,11 @@ typedef WPropertyVariable< WPVBaseTypes::PV_POSITION > WPVPosition;
*/
typedef WPropertyVariable< WPVBaseTypes::PV_COLOR > WPVColor;
/**
* Trigger properties
*/
typedef WPropertyVariable< WPVBaseTypes::PV_TRIGGER > WPVTrigger;
/**
* Some convenience type alias for a even more easy usage of WPropertyVariable.
* These typdefs define some pointer alias.
......@@ -186,6 +207,11 @@ typedef boost::shared_ptr< WPVColor > WPropColor;
*/
typedef boost::shared_ptr< WPVGroup > WPropGroup;
/**
* Alias for the trigger properties.
*/
typedef boost::shared_ptr< WPVTrigger > WPropTrigger;
/**
* This namespace contains several helper classes which translate their template type to an enum.
*/
......@@ -352,6 +378,24 @@ namespace PROPERTY_TYPE_HELPER
return PV_COLOR;
}
};
/**
* Class helping to adapt types specified as template parameter into an enum.
*/
template<>
class WTypeIdentifier< WPVBaseTypes::PV_TRIGGER >
{
public:
/**
* Get type identifier of the template type T.
*
* \return type identifier-
*/
PROPERTY_TYPE getType()
{
return PV_TRIGGER;
}
};
}
#endif // WPROPERTYTYPES_H
......@@ -22,6 +22,7 @@ SET(GUI_QT4_MOC_HDRS
datasetbrowser/WPropertyStringWidget.h
datasetbrowser/WPropertyColorWidget.h
datasetbrowser/WPropertyFilenameWidget.h
datasetbrowser/WPropertyTriggerWidget.h
datasetbrowser/WQtDatasetBrowser.h
datasetbrowser/WQtDSBWidget.h
datasetbrowser/WQtLineEdit.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 "WPropertyTriggerWidget.h"
#include "../../../common/WPropertyVariable.h"
WPropertyTriggerWidget::WPropertyTriggerWidget( WPropTrigger property, QGridLayout* propertyGrid, QWidget* parent ):
WPropertyWidget( property, propertyGrid, parent ),
m_triggerProperty( property ),
m_button( this ),
m_layout()
{
// initialize members
m_button.setCheckable( true );
update();
// layout both against each other
m_layout.addWidget( &m_button );
m_button.setText( QString::fromStdString( property->getDescription() ) );
m_layout.setContentsMargins( 1, 1, 1, 1 );
setLayout( &m_layout );
// connect the modification signal of m_checkbox with our callback
connect( &m_button, SIGNAL( toggled( bool ) ), this, SLOT( changed() ) );
}
WPropertyTriggerWidget::~WPropertyTriggerWidget()
{
// cleanup
}
void WPropertyTriggerWidget::update()
{
// simply set the new state
m_button.setChecked( m_triggerProperty->get() == WPVBaseTypes::PV_TRIGGER_TRIGGERED );
m_button.setEnabled( m_triggerProperty->get() == WPVBaseTypes::PV_TRIGGER_READY );
}
QPushButton* WPropertyTriggerWidget::getButton()
{
return &m_button;
}
void WPropertyTriggerWidget::changed()
{
// set the value
invalidate( !m_triggerProperty->set( m_button.isChecked() ? WPVBaseTypes::PV_TRIGGER_TRIGGERED : WPVBaseTypes::PV_TRIGGER_READY ) );
}
//---------------------------------------------------------------------------
//
// 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 WPROPERTYTRIGGERWIDGET_H
#define WPROPERTYTRIGGERWIDGET_H
#include <string>
#include <QtGui/QCheckBox>
#include <QtGui/QPushButton>
#include <QtGui/QHBoxLayout>
#include "WPropertyWidget.h"
/**
* Implements a property widget for WPropTrigger.
*/
class WPropertyTriggerWidget: public WPropertyWidget
{
Q_OBJECT
public:
/**
* Constructor. Creates a new widget appropriate for the specified property.
*
* \param property the property to handle
* \param parent the parent widget.
* \param propertyGrid the grid used to layout the labels and property widgets
*/
WPropertyTriggerWidget( WPropTrigger property, QGridLayout* propertyGrid, QWidget* parent = 0 );
/**
* Destructor.
*/
virtual ~WPropertyTriggerWidget();
/**
* Returns the QT PushButton widget used. It always returns a valid pointer.
*
* \return the button
*/
virtual QPushButton* getButton();
protected:
/**
* Called whenever the widget should update.
*/
virtual void update();
/**
* The boolean property represented by this widget.
*/
WPropTrigger m_triggerProperty;
/**
* If asButton is set to true: use this button instead of the m_checkbox
*/
QPushButton m_button;
/**
* Layout used to position the label and the checkbox
*/
QHBoxLayout m_layout;
private:
public slots:
/**
* called whenever the user modifies the widget
*/
void changed();
};
#endif // WPROPERTYTRIGGERWIDGET_H
......@@ -71,6 +71,11 @@ WPropertyFilenameWidget* WQtDSBWidget::addProp( WPropFilename property )
return new WPropertyFilenameWidget( property, &m_controlLayout, this );
}
WPropertyTriggerWidget* WQtDSBWidget::addProp( WPropTrigger property )
{
return new WPropertyTriggerWidget( property, &m_controlLayout, this );
}
void WQtDSBWidget::addGroup( WQtDSBWidget* widget )
{
// TODO(ebaum): extend it to collapse the group
......
......@@ -36,6 +36,7 @@
#include "WPropertyDoubleWidget.h"
#include "WPropertyColorWidget.h"
#include "WPropertyFilenameWidget.h"
#include "WPropertyTriggerWidget.h"
#include "../../../common/WPropertyVariable.h"
......@@ -137,6 +138,15 @@ public:
*/
WPropertyColorWidget* addProp( WPropColor property );
/**
* Adds a new trigger property to the DSB.
*
* \param property the property to add.
*
* \return the widget that has been added.
*/
WPropertyTriggerWidget* addProp( WPropTrigger property );
/**
* Adds an widget containing another property group to this widget. It encloses it with a GroupBox.
*
......
......@@ -429,6 +429,9 @@ WQtDSBWidget* WQtDatasetBrowser::buildPropWidget( boost::shared_ptr< WPropertie
WLogger::getLogger()->addLogMessage( "This property type \"PV_POSITION\" is not yet supported by the GUI.", "DatasetBrowser",
LL_WARNING );
break;
case PV_TRIGGER:
tab->addProp( ( *iter )->toPropTrigger() );
break;
case PV_GROUP:
tab->addGroup( buildPropWidget( ( *iter )->toPropGroup() ) );
break;
......
......@@ -160,6 +160,8 @@ 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",
......@@ -174,7 +176,11 @@ void WMTemplate::properties()
// properties of this group and must not contain any slashes (/). The second argument is a description. A nice feature is the possibility
// to specify an own condition, which gets fired when the property gets modified. This is especially useful to wake up the module's thread
// on property changes. So, the property m_anInteger will wake the module thread on changes. m_enableFeature and m_aColor should not wake up
// the module thread. They get read by the update callback of this modules OSG node, to update the color.
// the module thread. They get read by the update callback of this modules OSG node, to update the color. m_aTrigger is a property which can
// be used to trigger costly operations. The GUI shows them as buttons with the description as button text. The user can then press them and
// the WPropTrigger will change its state to PV_TRIGGER_TRIGGERED. In the moduleMain documentation, you'll find a more detailed description
// of how to use trigger properties. Be aware, that these kind of properties should be used carefully. They somehow inhibit the update flow
// through the module graph.
//
// m_anIntegerClone has a special purpose in this example. It shows that you can simply update properties from within your module whilst the
// GUI updates itself. You can, for example, set constraints or simply modify values depending on input data, most probably useful to set
......
......@@ -181,6 +181,11 @@ private:
*/
WPropColor m_aColor;
/**
* A trigger which can be used to trigger some kind of operation.
*/
WPropTrigger m_aTrigger;
/**
* Node callback to change the color of the shapes inside the root node. For more details on this class, refer to the documentation in
* moduleMain().
......
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