Commit 6b924ae8 authored by schurade's avatar schurade
Browse files

[ADD] made WColor lexical_castable to be able to be used in Properties

parent 6f6d7b93
......@@ -24,3 +24,46 @@
#include "WColor.hpp"
std::ostream& operator<<( std::ostream& out, const WColor& c )
{
float r = c.getRed();
float g = c.getGreen();
float b = c.getBlue();
float a = c.getAlpha();
out << r << ";" << g << ";" << b << ";" << a;
return out;
}
std::istream& operator>>( std::istream& in, WColor& c )
{
std::vector<std::string> tokens;
std::string str;
in >> str;
c.tokenize(str, tokens, ";");
c.setRed( boost::lexical_cast<float>( tokens[0] ) );
c.setGreen( boost::lexical_cast<float>( tokens[1] ) );
c.setBlue( boost::lexical_cast<float>( tokens[2] ) );
return in;
}
void WColor::tokenize(const std::string& str, std::vector<std::string>& tokens, const std::string& delimiters )
{
// Skip delimiters at beginning.
std::string::size_type lastPos = str.find_first_not_of( delimiters, 0 );
// Find first "non-delimiter".
std::string::size_type pos = str.find_first_of( delimiters, lastPos );
while ( std::string::npos != pos || std::string::npos != lastPos )
{
// Found a token, add it to the vector.
tokens.push_back( str.substr( lastPos, pos - lastPos ) );
// Skip delimiters. Note the "not_of"
lastPos = str.find_first_not_of( delimiters, pos );
// Find next "non-delimiter"
pos = str.find_first_of( delimiters, lastPos );
}
}
......@@ -26,6 +26,12 @@
#define WCOLOR_HPP
#include <cassert>
#include <istream>
#include <ostream>
#include <string>
#include <vector>
#include <boost/lexical_cast.hpp>
#include <osg/Vec4>
......@@ -35,6 +41,9 @@
class WColor
{
public:
friend std::ostream& operator<<( std::ostream& out, const WColor& c );
friend std::istream& operator>>( std::istream& in, WColor& c );
/**
* Standard way of constructing colors, alpha is optional, and black is default
*/
......@@ -73,6 +82,15 @@ public:
m_red = red;
}
/**
* Sets the alpha channel for this color
*/
void setAlpha( float alpha )
{
assert( alpha <= 1.0 && alpha >= 0.0 );
m_alpha = alpha;
}
/**
* \return red channel for this color
*/
......@@ -112,6 +130,10 @@ public:
{
return osg::Vec4( m_red, m_green, m_blue, m_alpha );
}
void tokenize( const std::string& str, std::vector<std::string>& tokens, const std::string& delimiters = " " );
protected:
private:
float m_red;
......
......@@ -92,6 +92,14 @@ boost::signal1< void, std::string >* WProperties::addString( std::string name, s
return prop->getSignalValueChanged();
}
boost::signal1< void, std::string >* WProperties::addColor( std::string name, WColor value, std::string shortDesc, std::string longDesc )
{
WProperty* prop = new WProperty( name, value, shortDesc, longDesc );
m_propertyList[name] = prop;
m_propertyVector.push_back( prop );
return prop->getSignalValueChanged();
}
WProperty* WProperties::findProp( std::string name )
{
if ( m_propertyList.count( name) != 0 )
......
......@@ -72,6 +72,7 @@ public:
boost::signal1< void, std::string >* addFloat( std::string name, float value = 0.0, std::string shortDesc = "", std::string longDesc = "" );
boost::signal1< void, std::string >* addDouble( std::string name, double value = 0.0, std::string shortDesc = "", std::string longDesc = "" );
boost::signal1< void, std::string >* addString( std::string name, std::string value = "", std::string shortDesc = "", std::string longDesc = "" );
boost::signal1< void, std::string >* addColor( std::string name, WColor value, std::string shortDesc = "", std::string longDesc = "" );
std::string getValueString( const std::string prop );
......
......@@ -94,6 +94,17 @@ WProperty::WProperty( std::string name, double value, std::string shortDesc, std
setValue( value );
}
WProperty::WProperty( std::string name, WColor value, std::string shortDesc, std::string longDesc )
: m_type( P_DOUBLE ),
m_name( name ),
m_shortDesc( shortDesc ),
m_longDesc( longDesc ),
m_isHidden( false )
{
setValue( value );
}
WProperty::~WProperty()
{
......
......@@ -30,6 +30,8 @@
#include <boost/lexical_cast.hpp>
#include "../gui/qt4/signalslib.hpp"
#include "WColor.hpp"
typedef enum
{
P_UNDEFINED,
......@@ -59,6 +61,7 @@ public:
WProperty( std::string name, int value, std::string shortDesc = "", std::string longDesc = "" );
WProperty( std::string name, float value, std::string shortDesc = "", std::string longDesc = "" );
WProperty( std::string name, double value, std::string shortDesc = "", std::string longDesc = "" );
WProperty( std::string name, WColor value, std::string shortDesc = "", std::string longDesc = "" );
/**
* destructor
......
......@@ -106,64 +106,62 @@ WQtDatasetTreeItem* WQtDatasetBrowser::addDataset( boost::shared_ptr< WModule >
void WQtDatasetBrowser::selectTreeItem()
{
if ( m_treeWidget->selectedItems().size() == 0 || m_treeWidget->selectedItems().at( 0 )->type() != 1 )
{
m_tabWidget->clear();
return;
}
// TODO(schurade): qt doc says clear() doesn't delete tabs so this is possibly a memory leak
m_tabWidget->clear();
boost::shared_ptr< WModule >module =( ( WQtDatasetTreeItem* ) m_treeWidget->selectedItems().at( 0 ) )->getModule();
std::vector < WProperty* >props = module->getProperties()->getPropertyVector();
if ( m_treeWidget->selectedItems().size() > 0 || m_treeWidget->selectedItems().at( 0 )->type() == 1 )
{
boost::shared_ptr< WModule >module =( ( WQtDatasetTreeItem* ) m_treeWidget->selectedItems().at( 0 ) )->getModule();
std::vector < WProperty* >props = module->getProperties()->getPropertyVector();
WQtDSBWidget* tab1 = new WQtDSBWidget( "settings" );
WQtDSBWidget* tab1 = new WQtDSBWidget( "settings" );
for ( size_t i = 0; i < props.size(); ++i )
{
if ( !props.at(i)->isHidden() )
for ( size_t i = 0; i < props.size(); ++i )
{
switch ( props.at(i)->getType() )
if ( !props.at(i)->isHidden() )
{
case P_BOOL:
{
QString name = QString( props.at( i )->getName().c_str() );
WQtCheckBox* box = tab1->addCheckBox( name, props.at( i )->getValue<bool>() );
connect( box, SIGNAL( checkBoxStateChanged( QString, bool ) ), this, SLOT( slotSetBoolProperty( QString, bool ) ) );
break;
}
case P_CHAR:
break;
case P_UNSIGNED_CHAR:
break;
case P_INT:
switch ( props.at(i)->getType() )
{
QString name = QString( props.at( i )->getName().c_str() );
WQtSliderWithEdit* slider = tab1->addSliderInt( name, props.at( i )->getValue<int>(),
props.at( i )->getMin<int>(), props.at( i )->getMax<int>() );
connect( slider, SIGNAL( signalNumberWithName( QString, int ) ), this, SLOT( slotSetIntProperty( QString, int ) ) );
break;
case P_BOOL:
{
QString name = QString( props.at( i )->getName().c_str() );
WQtCheckBox* box = tab1->addCheckBox( name, props.at( i )->getValue<bool>() );
connect( box, SIGNAL( checkBoxStateChanged( QString, bool ) ), this, SLOT( slotSetBoolProperty( QString, bool ) ) );
break;
}
case P_CHAR:
break;
case P_UNSIGNED_CHAR:
break;
case P_INT:
{
QString name = QString( props.at( i )->getName().c_str() );
WQtSliderWithEdit* slider = tab1->addSliderInt( name, props.at( i )->getValue<int>(),
props.at( i )->getMin<int>(), props.at( i )->getMax<int>() );
connect( slider, SIGNAL( signalNumberWithName( QString, int ) ), this, SLOT( slotSetIntProperty( QString, int ) ) );
break;
}
case P_UNSIGNED_INT:
break;
case P_FLOAT:
break;
case P_DOUBLE:
break;
case P_STRING:
{
QString name = QString( props.at( i )->getName().c_str() );
QString text = QString( props.at( i )->getValue<std::string>().c_str() );
WQtLineEdit* edit = tab1->addLineEdit( name, text );
connect( edit, SIGNAL( lineEditStateChanged( QString, QString ) ), this, SLOT( slotSetStringProperty( QString, QString ) ) );
break;
}
default:
break;
}
case P_UNSIGNED_INT:
break;
case P_FLOAT:
break;
case P_DOUBLE:
break;
case P_STRING:
{
QString name = QString( props.at( i )->getName().c_str() );
QString text = QString( props.at( i )->getValue<std::string>().c_str() );
WQtLineEdit* edit = tab1->addLineEdit( name, text );
connect( edit, SIGNAL( lineEditStateChanged( QString, QString ) ), this, SLOT( slotSetStringProperty( QString, QString ) ) );
break;
}
default:
break;
}
}
addTabWidgetContent( tab1 );
}
// TODO(schurade): qt doc says clear() doesn't delete tabs so this is possibly a memory leak
m_tabWidget->clear();
addTabWidgetContent( tab1 );
}
void WQtDatasetBrowser::changeTreeItem()
......@@ -184,7 +182,6 @@ void WQtDatasetBrowser::changeTreeItem()
module->getProperties()->setValue<bool>( "active", false );
}
emit dataSetBrowserEvent( QString( "textureChanged" ), true );
// selectTreeItem();
}
void WQtDatasetBrowser::addTabWidgetContent( WQtDSBWidget* content )
......
......@@ -50,6 +50,8 @@
#include "../../graphicsEngine/WShader.h"
#include "../../common/WColor.hpp"
WNavigationSliceModule::WNavigationSliceModule():
WModule()
{
......@@ -98,19 +100,21 @@ void WNavigationSliceModule::connectors()
void WNavigationSliceModule::properties()
{
( m_properties->addBool( "textureChanged", false ) );
m_properties->addBool( "textureChanged", false );
( m_properties->addInt( "axialPos", 80 ) );
( m_properties->addInt( "coronalPos", 100 ) );
( m_properties->addInt( "sagittalPos", 80 ) );
m_properties->addInt( "axialPos", 80 );
m_properties->addInt( "coronalPos", 100 );
m_properties->addInt( "sagittalPos", 80 );
m_properties->addInt( "maxAxial", 160 );
m_properties->addInt( "maxCoronal", 200 );
m_properties->addInt( "maxSagittal", 160 );
( m_properties->addBool( "showAxial", true ) );
( m_properties->addBool( "showCoronal", true ) );
( m_properties->addBool( "showSagittal", true ) );
m_properties->addBool( "showAxial", true );
m_properties->addBool( "showCoronal", true );
m_properties->addBool( "showSagittal", true );
m_properties->addColor( "testColor", WColor(0.3, 0.3, 0.5, 1.0) );
}
void WNavigationSliceModule::notifyDataChange( boost::shared_ptr<WModuleConnector> input,
......@@ -125,6 +129,9 @@ void WNavigationSliceModule::threadMain()
{
createGeometry();
WColor c = m_properties->getValue<WColor>( "testColor" );
std::cout << c << std::endl;
// Since the modules run in a separate thread: such loops are possible
while ( !m_FinishRequested )
{
......
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