Commit 2bdf0436 authored by Dirk Albrecht's avatar Dirk Albrecht

[MERGE]with 2966 from default branch

parents 20aca258 c6e6e38b
......@@ -76,9 +76,10 @@ IF( NOT CMAKE_GENERATOR MATCHES "Visual Studio" )
FIND_PACKAGE( osgText ${MIN_OSG_VERSION} REQUIRED )
FIND_PACKAGE( osgGA ${MIN_OSG_VERSION} REQUIRED )
FIND_PACKAGE( osgSim ${MIN_OSG_VERSION} REQUIRED )
FIND_PACKAGE( osgWidget ${MIN_OSG_VERSION} REQUIRED )
FIND_PACKAGE( OpenThreads ${MIN_OSG_VERSION} REQUIRED )
SET( OPENSCENEGRAPH_LIBRARIES ${OSGDB_LIBRARY} ${OSGTEXT_LIBRARY} ${OSGGA_LIBRARY} ${OSGUTIL_LIBRARY} ${OSGVIEWER_LIBRARY} ${OSG_LIBRARY} ${OSGSIM_LIBRARY} ${OPENTHREADS_LIBRARY} )
SET( OPENSCENEGRAPH_INCLUDE_DIRS ${OSG_INCLUDE_DIR} ${OSGDB_INCLUDE_DIR} ${OSGTEXT_INCLUDE_DIR} ${OSGGA_INCLUDE_DIR} ${OSGVIEWER_INCLUDE_DIR} ${OSGUTIL_INCLUDE_DIR} ${OSGSIM_INCLUDE_DIR} ${OPENTHREADS_INCLUDE_DIR} )
SET( OPENSCENEGRAPH_LIBRARIES ${OSGDB_LIBRARY} ${OSGTEXT_LIBRARY} ${OSGGA_LIBRARY} ${OSGUTIL_LIBRARY} ${OSGVIEWER_LIBRARY} ${OSG_LIBRARY} ${OSGSIM_LIBRARY} ${OSGWIDGET_LIBRARY} ${OPENTHREADS_LIBRARY} )
SET( OPENSCENEGRAPH_INCLUDE_DIRS ${OSG_INCLUDE_DIR} ${OSGDB_INCLUDE_DIR} ${OSGTEXT_INCLUDE_DIR} ${OSGGA_INCLUDE_DIR} ${OSGVIEWER_INCLUDE_DIR} ${OSGUTIL_INCLUDE_DIR} ${OSGSIM_INCLUDE_DIR} ${OSGWIDGET_INCLUDE_DIR} ${OPENTHREADS_INCLUDE_DIR} )
# When new cmake version available >=2.6.4 we may use this the line below instead the stuff above
# FIND_PACKAGE( OpenSceneGraph 2.8.0 REQUIRED osgDB osgUtil osgGA osgViewer osgSim OpenThreads )
INCLUDE_DIRECTORIES( ${OPENSCENEGRAPH_INCLUDE_DIRS} )
......@@ -98,6 +99,20 @@ IF( Teem_FOUND ) # we need to add the include path and lib path to allow the
LINK_DIRECTORIES( ${LINK_DIRECTORIES} ${Teem_LIBRARY_DIRS} )
ENDIF()
### OSSIM ###
FIND_PACKAGE( OSSIM QUIET )
IF( OSSIM_FOUND )
MESSAGE( STATUS "Found OSSIM." )
ADD_DEFINITIONS( -DUSEOSSIM )
INCLUDE_DIRECTORIES( ${OSSIM_INCLUDE_DIR} )
LINK_LIBRARIES( ${OSSIM_LIBRARY} )
# TODO(math): is an entry in link directories necessary?
# LINK_DIRECTORIES( ${OSSIM_LIBDIR} )
MARK_AS_ADVANCED( OSSIM_INCLUDEDIR )
MARK_AS_ADVANCED( OSSIM_LIBRARIES )
# MARK_AS_ADVANCED( OSSIM_LIBDIR )
ENDIF()
# other options:
#---------------
# Set default build type
......
......@@ -47,7 +47,7 @@ int main( int argc, char** argv )
{
std::cout << "OpenWalnut ( http://www.openwalnut.org )" << std::endl <<
"Build from: " << W_VERSION << std::endl << std::endl <<
"Copyright (C) 2009-2010 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS\n"
"Copyright 2009-2010 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS\n"
"For more information see http://www.openwalnut.org/copying\n"
"This program comes with ABSOLUTELY NO WARRANTY.\n"
"This is free software, and you are welcome to redistribute it\n"
......
......@@ -29,12 +29,13 @@
#include <vector>
#include "WHistogram.h"
#include "WExportCommon.h"
/**
* Container which associate values with (uniform width) bins (aka intervals or buckets). This class implements a very simple and easy to use
* generic histogram with uniform bucket sizes.
*/
class WHistogramBasic: public WHistogram
class OWCOMMON_EXPORT WHistogramBasic: public WHistogram
{
public:
/**
......
......@@ -23,16 +23,18 @@
//---------------------------------------------------------------------------
#include <string>
#include <vector>
#include "WLogger.h"
#include "exceptions/WOutOfBounds.h"
#include "exceptions/WNameNotUnique.h"
#include "WItemSelector.h"
#include "WItemSelection.h"
WItemSelection::WItemSelection():
m_modifyable( true )
WSharedSequenceContainer< std::vector< boost::shared_ptr< WItemSelectionItem > > >()
{
// initialize members
}
......@@ -42,27 +44,12 @@ WItemSelection::~WItemSelection()
// cleanup
}
void WItemSelection::addItem( std::string name, std::string description, const char** icon )
{
if ( m_modifyable )
{
Item* i = new Item; // NOLINT <-- initialize the struct this way is far more comfortable
i->name = name;
i->description = description;
i->icon = icon;
m_items.push_back( i );
}
else
{
wlog::warn( "WItemSelection " ) << "You can not modify the selection list after a selector has been created.";
}
}
WItemSelector WItemSelection::getSelectorAll()
{
m_modifyable = false;
WItemSelector::IndexList l;
for ( size_t i = 0; i < m_items.size(); ++i )
ReadTicket r = getReadTicket();
for ( size_t i = 0; i < r->get().size(); ++i )
{
l.push_back( i );
}
......@@ -71,16 +58,17 @@ WItemSelector WItemSelection::getSelectorAll()
WItemSelector WItemSelection::getSelectorNone()
{
m_modifyable = false;
WItemSelector::IndexList l;
ReadTicket r = getReadTicket();
return WItemSelector( shared_from_this(), l );
}
WItemSelector WItemSelection::getSelectorFirst()
{
m_modifyable = false;
WItemSelector::IndexList l;
if ( m_items.size() >= 1 )
ReadTicket r = getReadTicket();
if ( r->get().size() >= 1 )
{
l.push_back( 0 );
}
......@@ -89,9 +77,10 @@ WItemSelector WItemSelection::getSelectorFirst()
WItemSelector WItemSelection::getSelector( size_t item )
{
m_modifyable = false;
WItemSelector::IndexList l;
if ( m_items.size() <= item )
ReadTicket r = getReadTicket();
if ( r->get().size() <= item )
{
throw WOutOfBounds( "The specified item does not exist." );
}
......@@ -99,13 +88,8 @@ WItemSelector WItemSelection::getSelector( size_t item )
return WItemSelector( shared_from_this(), l );
}
size_t WItemSelection::size() const
{
return m_items.size();
}
WItemSelection::Item& WItemSelection::at( size_t index ) const
void WItemSelection::addItem( std::string name, std::string description, const char** icon )
{
return *m_items.at( index );
push_back( boost::shared_ptr< WItemSelectionItem >( new WItemSelectionItem( name, description, icon ) ) );
}
......@@ -31,8 +31,11 @@
#include <boost/tuple/tuple.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/signals2/signal.hpp>
#include <boost/enable_shared_from_this.hpp>
#include "WSharedSequenceContainer.h"
#include "WItemSelectionItem.h"
#include "WExportCommon.h"
class WItemSelector;
......@@ -41,34 +44,14 @@ class WItemSelector;
* A class containing a list of named items. It is mainly a container for an std::vector but with the difference that there can be so called
* Selectors which are able to select some subset of the item set. This is especially useful in properties where item selection is needed. The
* class is kept very restrictive to keep the interface clean and sleek and to keep the item set consistent among several threads. So please do
* not implement any function that might change the item list. The would cause odd behaviour of all the WItemSelector instances. Items can only
* be added until the first Selector instance is created.
* not implement any function that might change the item list, use the provided ones. If the item list changes, existing selectors get invalid
* automatically using the change condition of the inherited WSharedSequenceContainer.
*/
class OWCOMMON_EXPORT WItemSelection: public boost::enable_shared_from_this< WItemSelection >
class OWCOMMON_EXPORT WItemSelection: public boost::enable_shared_from_this< WItemSelection >,
public WSharedSequenceContainer< std::vector< boost::shared_ptr< WItemSelectionItem > > >
{
friend class WItemSelector; // for proper locking and unlocking
public:
/**
* For shortening, it is the type of an item.
*/
typedef struct
{
/**
* Name
*/
std::string name;
/**
* Description, can be empty.
*/
std::string description;
/**
* Icon shown in the item selection box. Can be NULL.
*/
const char** icon;
}
Item;
/**
* Default constructor.
*/
......@@ -80,39 +63,28 @@ public:
virtual ~WItemSelection();
/**
* Adds an item to the list of selectable items.
*
* \param name the name
* \param description the description
* \param icon an icon to show together with this item. Useful to illustrate the selection options.
*/
virtual void addItem( std::string name, std::string description, const char** icon = NULL );
/**
* Creates an default selection (all items selected). After the first call of this function, no more items can be added using \ref addItem.
* Creates an default selection (all items selected). The selector gets invalid if another item is added.
*
* \return an selector.
*/
virtual WItemSelector getSelectorAll();
/**
* Creates an default selection (no items selected). After the first call of this function, no more items can be added using \ref addItem.
* Creates an default selection (no items selected). The selector gets invalid if another item is added.
*
* \return an selector.
*/
virtual WItemSelector getSelectorNone();
/**
* Creates an default selection (first item selected). After the first call of this function, no more items can be added using \ref addItem.
* If no item is in the selection, nothing is selected.
* Creates an default selection (first item selected). The selector gets invalid if another item is added.
*
* \return an selector.
*/
virtual WItemSelector getSelectorFirst();
/**
* Creates an default selection (a specified items selected). After the first call of this function, no more items can be added
* using \ref addItem.
* Creates an default selection (a specified items selected). The selector gets invalid if another item is added.
*
* \param item the item to select.
*
......@@ -121,33 +93,28 @@ public:
virtual WItemSelector getSelector( size_t item );
/**
* The number of selectable items.
* Convenience method to create a new item.
*
* \param name name of the item
* \param description the description, can be empty
* \param icon the icon, can be NULL
*
* \return the number of items.
* \return the Item.
*/
virtual size_t size() const;
static boost::shared_ptr< WItemSelectionItem > Item( std::string name, std::string description = "", const char** icon = NULL )
{
return boost::shared_ptr< WItemSelectionItem >( new WItemSelectionItem( name, description, icon ) );
}
/**
* Gets the item with the given index. This is not the same index as the element has in the corresponding WItemSelector!
* This method is especially useful to iterate the through all items.
* Convenience method to add a new item.
*
* \param index the index
* \param name name of the item
* \param description the description, can be empty
* \param icon the icon, can be NULL
*
* \return the item
*/
virtual Item& at( size_t index ) const;
protected:
/**
* List of items.
*/
std::vector< Item* > m_items;
/**
* True if the selection can be modified.
*/
bool m_modifyable;
void addItem( std::string name, std::string description = "", const char** icon = NULL );
private:
};
......
......@@ -24,42 +24,37 @@
#include <string>
#include "WQtNumberEditDouble.h"
#include "WItemSelectionItem.h"
WQtNumberEditDouble::WQtNumberEditDouble( QString name, QWidget* parent )
: QLineEdit( parent ),
m_name( name )
WItemSelectionItem::WItemSelectionItem( std::string name, std::string description, const char** icon ):
m_name( name ),
m_description( description ),
m_icon( icon )
{
connect( this, SIGNAL( returnPressed() ), this, SLOT( numberChanged() ) );
// initialize members
}
WQtNumberEditDouble::~WQtNumberEditDouble()
WItemSelectionItem::~WItemSelectionItem()
{
// cleanup
}
void WQtNumberEditDouble::setName( QString name )
std::string WItemSelectionItem::getName() const
{
m_name = name;
return m_name;
}
std::string WItemSelectionItem::getDescription() const
{
return m_description;
}
void WQtNumberEditDouble::setDouble( double number )
const char** WItemSelectionItem::getIcon() const
{
setText( QString::number( number ) );
emit signalNumberWithName( m_name, number );
return m_icon;
}
void WQtNumberEditDouble::numberChanged()
bool WItemSelectionItem::operator==( const WItemSelectionItem& other ) const
{
bool ok;
double number = text().toDouble( &ok );
if ( ok )
{
emit signalNumberWithName( m_name, number );
}
else
{
setText( QString::number( 0 ) );
emit signalNumberWithName( m_name, 0 );
}
return ( m_name == other.m_name );
}
......@@ -22,71 +22,83 @@
//
//---------------------------------------------------------------------------
#ifndef WQTNUMBEREDITDOUBLE_H
#define WQTNUMBEREDITDOUBLE_H
#ifndef WITEMSELECTIONITEM_H
#define WITEMSELECTIONITEM_H
#include <string>
#include <QtGui/QLineEdit>
#include "WExportCommon.h"
/**
* a QLineEdit modified to deal only with double numbers
* Class for keeping a single named item in a WItemSelection.
*/
class WQtNumberEditDouble : public QLineEdit
class OWCOMMON_EXPORT WItemSelectionItem // NOLINT
{
Q_OBJECT
public:
/**
* Default constructor, that connects the slot of the edit.
* Constructs a new item with the specified values.
*
* \param name The name of teh widget
* \param parent The widget managing this widget
* \param name Name of item.
* \param description Description, can be empty.
* \param icon Icon, can be NULL.
*/
explicit WQtNumberEditDouble( QString name, QWidget* parent = 0 );
WItemSelectionItem( std::string name, std::string description = "", const char** icon = NULL );
/**
* setter for name.
*
* \param name The new name for the widget
* Destruction. Does NOT delete the icon!
*/
void setName( QString name );
virtual ~WItemSelectionItem();
/**
* destructor
* Returns the name of the item.
*
* \return the name
*/
virtual ~WQtNumberEditDouble();
public slots:
std::string getName() const;
/**
* Sets the edit field to a certain number.
* The description of the item.
*
* \param number The double to be put into the field.
* \return the description
*/
void setDouble( double number );
std::string getDescription() const;
/**
* Updated the number in the lineEdit if the number has changed.
* The icon associated with this item. Can be NULL.
*
* \return the icon, might be NULL.
*/
void numberChanged();
signals:
const char** getIcon() const;
/**
* Signal to distribute the number set in the lineEdit.
* Compares this and another item using their names only.
*
* \param other the second to compare the this one with
*
* \param name name of the edit field.
* \param number new value of the edit field.
* \return true if the names are equal.
*/
void signalNumberWithName( QString name, double number );
bool operator==( const WItemSelectionItem& other ) const;
protected:
private:
/**
* Name if the value.
* Item name.
*/
QString m_name;
std::string m_name;
/**
* Item description.
*/
std::string m_description;
/**
* Item icon.
*/
const char** m_icon;
private:
};
#endif // WQTNUMBEREDITDOUBLE_H
#endif // WITEMSELECTIONITEM_H
......@@ -34,19 +34,53 @@
WItemSelector::WItemSelector( boost::shared_ptr< WItemSelection > selection, IndexList selected ):
m_selection( selection ),
m_selected( selected )
m_selected( selected ),
m_invalidateSignalConnection(),
m_valid( true )
{
// initialize members
m_invalidateSignalConnection = m_selection->getChangeCondition()->subscribeSignal( boost::bind( &WItemSelector::invalidate, this ) );
}
WItemSelector::WItemSelector( const WItemSelector& other ):
m_selection( other.m_selection ),
m_selected( other.m_selected ),
m_valid( other.m_valid )
{
m_invalidateSignalConnection = m_selection->getChangeCondition()->subscribeSignal( boost::bind( &WItemSelector::invalidate, this ) );
}
WItemSelector& WItemSelector::operator=( const WItemSelector & other )
{
if ( this != &other ) // protect against invalid self-assignment
{
m_selection = other.m_selection;
m_selected = other.m_selected;
m_valid = other.m_valid;
m_invalidateSignalConnection = m_selection->getChangeCondition()->subscribeSignal( boost::bind( &WItemSelector::invalidate, this ) );
}
// by convention, always return *this
return *this;
}
WItemSelector::~WItemSelector()
{
// cleanup
m_invalidateSignalConnection.disconnect();
}
WItemSelector WItemSelector::newSelector( IndexList selected ) const
{
return WItemSelector( m_selection, selected );
return createSelector( selected );
}
WItemSelector WItemSelector::newSelector( size_t selected ) const
{
IndexList n = m_selected;
n.push_back( selected );
return createSelector( n );
}
WItemSelector WItemSelector::newSelector( const std::string asString ) const
......@@ -60,7 +94,22 @@ WItemSelector WItemSelector::newSelector( const std::string asString ) const
l.push_back( boost::lexical_cast< size_t >( tokens[i] ) );
}
return newSelector( l );
return createSelector( l );
}
WItemSelector WItemSelector::newSelector() const
{
WItemSelector s( *this );
s.m_valid = true;
// iterate selected items to remove items with invalid index
for ( IndexList::iterator i = s.m_selected.begin(); i != s.m_selected.end(); ++i )
{
if ( ( *i ) >= m_selection->size() )
{
s.m_selected.erase( i );
}
}
return s;
}
std::ostream& WItemSelector::operator<<( std::ostream& out ) const
......@@ -83,7 +132,7 @@ std::ostream& operator<<( std::ostream& out, const WItemSelector& other )
bool WItemSelector::operator==( const WItemSelector& other ) const
{
return ( ( m_selection == other.m_selection ) && ( m_selected == other.m_selected ) );
return ( ( m_selection == other.m_selection ) && ( m_selected == other.m_selected ) && ( m_valid == other.m_valid ) );
}
size_t WItemSelector::sizeAll() const
......@@ -96,12 +145,12 @@ size_t WItemSelector::size() const
return m_selected.size();
}
const WItemSelection::Item& WItemSelector::atAll( size_t index ) const