Commit d4f0f97e authored by Mathias Goldau's avatar Mathias Goldau
Browse files

[MERGE]

parents 08be00ea 1055e1be
......@@ -94,7 +94,7 @@ void WLogger::setLogFileName( std::string fileName )
void WLogger::addLogMessage( std::string message, std::string source, LogLevel level )
{
if ( m_LogLevel > level || m_FinishRequested )
if ( m_LogLevel > level || m_shutdownFlag() )
{
return;
}
......@@ -158,7 +158,7 @@ void WLogger::threadMain()
// NOTE: in DEBUG mode, we do not use the process queue, since it prints messages delayed and is, therefore, not very usable during debugging.
#ifndef DEBUG
// Since the modules run in a separate thread: such loops are possible
while ( !m_FinishRequested )
while ( !m_shutdownFlag() )
{
processQueue();
// do fancy stuff
......
......@@ -86,6 +86,14 @@ void WProgressCombiner::addSubProgress( boost::shared_ptr< WProgress > progress
lock.unlock();
}
void WProgressCombiner::removeSubProgress( boost::shared_ptr< WProgress > progress )
{
boost::unique_lock<boost::shared_mutex> lock = boost::unique_lock<boost::shared_mutex>( m_updateLock );
// add the progress to the children list
m_children.erase( progress );
lock.unlock();
}
void WProgressCombiner::finish()
{
// combiner just propagate the finish request down to all children
......
......@@ -85,6 +85,13 @@ public:
*/
virtual void addSubProgress( boost::shared_ptr< WProgress > progress );
/**
* Removes the specified sub progress from this combiner.
*
* \param progress the progress to remove.
*/
virtual void removeSubProgress( boost::shared_ptr< WProgress > progress );
/**
* Function updating the internal state. This needs to be called before any get function to ensure the getter return the right
* values.
......
......@@ -25,15 +25,15 @@
#include <iostream>
#include "WConditionOneShot.h"
#include "WCondition.h"
#include "WLogger.h"
#include "WThreadedRunner.h"
WThreadedRunner::WThreadedRunner():
m_shutdownFlag( new WConditionOneShot, false )
m_shutdownFlag( new WConditionOneShot(), false )
{
// initialize members
m_FinishRequested = false;
}
WThreadedRunner::~WThreadedRunner()
......@@ -62,14 +62,12 @@ void WThreadedRunner::wait( bool requestFinish )
m_thread.join();
}
void WThreadedRunner::requestStop()
{
// first notify
notifyStop();
// then signal it
m_FinishRequested = true;
m_shutdownFlag( true );
}
......
......@@ -75,6 +75,11 @@ public:
*/
void wait( bool requestFinish = false );
/**
* This method's purpose is to request a stop without waiting for it.
*/
virtual void requestStop();
protected:
/**
......@@ -88,21 +93,11 @@ protected:
*/
virtual void notifyStop();
/**
* This method's purpose is to request a stop without waiting for it.
*/
virtual void requestStop();
/**
* Thread instance.
*/
boost::thread m_thread;
/**
* True if thread should end execution. NOTE: do not use this. Use m_shutdownFlag instead.
*/
bool m_FinishRequested;
/**
* Give remaining execution timeslice to another thread.
*/
......
......@@ -157,6 +157,12 @@ public:
*/
WMatrix operator*( const WMatrix& rhs ) const;
/**
* Multiplication with a vector.
* \param rhs The right hand side of the multiplication
*/
WValue< T > operator*( const WValue< T >& rhs ) const;
protected:
private:
size_t m_nbCols; //!< Number of columns of the matrix. The number of rows will be computed by (size/m_nbCols).
......@@ -181,5 +187,20 @@ template< typename T > WMatrix< T > WMatrix< T >::operator*( const WMatrix< T >&
return result;
}
template< typename T > WValue< T > WMatrix< T >::operator*( const WValue< T >& rhs ) const
{
assert( rhs.size() == getNbCols() );
WValue< T > result( getNbRows() );
for( size_t r = 0; r < getNbRows(); ++r)
{
for( size_t i = 0; i < getNbCols(); ++i )
{
result[r] += ( *this )( r, i ) * rhs[i];
}
}
return result;
}
} // End of namespace
#endif // WMATRIX_H
......@@ -31,7 +31,7 @@
#include "../WThreadedRunner.h"
/**
/**
* Class implementing a simple worker thread, since proper testing of WThreadedRunner itself is not usable.
*/
class WThreadedRunnerImpl: public WThreadedRunner
......@@ -45,7 +45,7 @@ protected:
virtual void threadMain()
{
// Since the modules run in a separate thread: such loops are possible
while ( !m_FinishRequested )
while ( !m_shutdownFlag() )
{
// do fancy stuff
sleep( 1 );
......
......@@ -151,9 +151,28 @@ double WDataSetScalar::interpolate( const wmath::WPosition& pos, bool* success )
double result = 0;
for( size_t i = 0; i < 8; ++i )
{
result += h[i] * getValueAt( vertexIds[i] );
result += h[i] * WDataSetSingle::getValueAt( vertexIds[i] );
}
*success = true;
return result;
}
template< typename T > T WDataSetScalar::getValueAt( int x, int y, int z )
{
boost::shared_ptr< WValueSet< T > > vs = boost::shared_dynamic_cast< WValueSet< T > >( m_valueSet );
boost::shared_ptr< WGridRegular3D > grid = boost::shared_dynamic_cast< WGridRegular3D >( m_grid );
size_t id = x + y * grid->getNbCoordsX() + z * grid->getNbCoordsX() * grid->getNbCoordsY();
T v = vs->getScalar( id );
return v;
}
double WDataSetScalar::getValueAt( int x, int y, int z )
{
boost::shared_ptr< WGridRegular3D > grid = boost::shared_dynamic_cast< WGridRegular3D >( m_grid );
size_t id = x + y * grid->getNbCoordsX() + z * grid->getNbCoordsX() * grid->getNbCoordsY();
return WDataSetSingle::getValueAt( id );
}
......@@ -91,6 +91,25 @@ public:
*/
double interpolate( const wmath::WPosition& pos, bool* success );
/**
* Get the value stored at a certain grid position of the data set
* \param x index in x direction
* \param y index in y direction
* \param z index in z direction
*/
template< typename T > T getValueAt( int x, int y, int z );
/**
* Get the value stored at a certain grid position of the data set
* \param x index in x direction
* \param y index in y direction
* \param z index in z direction
*
* \return the double value at the given cell.
*/
double getValueAt( int x, int y, int z );
/**
* Returns a prototype instantiated with the true type of the deriving class.
*
......
......@@ -134,13 +134,5 @@ double WDataSetSingle::getValueAt( size_t id )
WAssert( false, "Unknow data type in dataset." );
}
return 0.0;
}
double WDataSetSingle::getValueAt( int x, int y, int z )
{
boost::shared_ptr< WGridRegular3D > grid = boost::shared_dynamic_cast< WGridRegular3D >( m_grid );
size_t id = x + y * grid->getNbCoordsX() + z * grid->getNbCoordsX() * grid->getNbCoordsY();
return getValueAt( id );
return 0.0; // should not be reached. Just there to quiet compiler.
}
......@@ -75,25 +75,7 @@ public:
boost::shared_ptr< WGrid > getGrid() const;
/**
* Get the value stored at a certain grid position of the data set
* \param x index in x direction
* \param y index in y direction
* \param z index in z direction
*/
template< typename T > T getValueAt( int x, int y, int z );
/**
* Get the value stored at a certain grid position of the data set
* \param x index in x direction
* \param y index in y direction
* \param z index in z direction
*
* \return the double value at the given cell.
*/
double getValueAt( int x, int y, int z );
/**
* Get the value stored at a certain grid position of the data set
* Get the value stored at position of the value set. This is the grid position only for scalar data sets.
*
* \param id The id'th value in the data set
*
......@@ -102,7 +84,7 @@ public:
template< typename T > T getValueAt( size_t id );
/**
* Get the value stored at a certain grid position of the data set in type double.
* Get the value stored at position of the value set. This is the grid position only for scalar data sets.
*
* \param id The id'th value in the data set
*
......@@ -169,17 +151,6 @@ private:
boost::shared_ptr< WDataTexture3D > m_texture3D;
};
template< typename T > T WDataSetSingle::getValueAt( int x, int y, int z )
{
boost::shared_ptr< WValueSet< T > > vs = boost::shared_dynamic_cast< WValueSet< T > >( m_valueSet );
boost::shared_ptr< WGridRegular3D > grid = boost::shared_dynamic_cast< WGridRegular3D >( m_grid );
size_t id = x + y * grid->getNbCoordsX() + z * grid->getNbCoordsX() * grid->getNbCoordsY();
T v = vs->getScalar( id );
return v;
}
template< typename T > T WDataSetSingle::getValueAt( size_t id )
{
boost::shared_ptr< WValueSet< T > > vs = boost::shared_dynamic_cast< WValueSet< T > >( m_valueSet );
......
......@@ -89,7 +89,7 @@ void WMainWindow::setupGUI()
setWindowIcon( m_iconManager.getIcon( "logo" ) );
setWindowTitle( QApplication::translate( "MainWindow", "OpenWalnut", 0, QApplication::UnicodeUTF8 ) );
m_menuBar = new QMenuBar( 0 );
m_menuBar = new QMenuBar( this );
QMenu* fileMenu = m_menuBar->addMenu( "File" );
fileMenu->addAction( m_iconManager.getIcon( "load" ), "Load", this, SLOT( openLoadDialog() ), QKeySequence( "Ctrl+L" ) );
fileMenu->addAction( m_iconManager.getIcon( "quit" ), "Quit", this, SLOT( close() ), QKeySequence( "Ctrl+Q" ) );
......@@ -371,6 +371,10 @@ void WMainWindow::setupCompatiblesToolBar()
WPreferences::getPreference( "qt4gui.useToolBarBreak", &useToolBarBreak );
if( useToolBarBreak )
{
// Blank toolbar for nicer layout in case of toolbar break
// This can be done nicer very probably.
WQtToolBar* blankToolBar = new WQtToolBar( "Blank Toolbar", this );
addToolBar( Qt::TopToolBarArea, blankToolBar );
addToolBarBreak( Qt::TopToolBarArea );
}
}
......
......@@ -51,6 +51,8 @@
#include "events/WModuleCrashEvent.h"
#include "events/WUpdateTextureSorterEvent.h"
WMainWindow* WQt4Gui::m_mainWindow = NULL;
WQt4Gui::WQt4Gui( int argc, char** argv )
: WGUI( argc, argv )
{
......@@ -104,6 +106,11 @@ void WQt4Gui::moduleError( boost::shared_ptr< WModule > module, const WException
QCoreApplication::postEvent( m_mainWindow, new WModuleCrashEvent( module, exception.what() ) );
}
WMainWindow* WQt4Gui::getMainWindow()
{
return m_mainWindow;
}
int WQt4Gui::run()
{
bool parsingSuccessful = parseOptions();
......
......@@ -131,6 +131,13 @@ public:
*/
virtual void closeCustomWidget( std::string title );
/**
* Returns the current main window instance or NULL if not existent.
*
* \return the main window instance.
*/
static WMainWindow* getMainWindow();
protected:
/**
......@@ -146,7 +153,7 @@ private:
/**
* Main window containing all needed widgets.
*/
WMainWindow* m_mainWindow;
static WMainWindow* m_mainWindow;
/**
* Graphics Engine instance.
......
......@@ -54,7 +54,7 @@ WQtNavGLWidget::WQtNavGLWidget( QString title, QWidget* parent, std::string slid
m_glWidget->setFixedSize( 150, 150 );
m_glWidget->initialize();
setMinimumSize( 160, 200 );
setMinimumSize( 160, 240 );
setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
m_scene = new WGEScene();
......
......@@ -22,8 +22,9 @@
//
//---------------------------------------------------------------------------
#include "WQtToolBar.h"
#include <list>
#include "WQtToolBar.h"
WQtToolBar::WQtToolBar( const QString & title, QWidget* parent )
: QToolBar( title, parent )
......@@ -51,10 +52,25 @@ WQtPushButton* WQtToolBar::addPushButton( QString name, QIcon icon, QString labe
return button;
}
QAction* WQtToolBar::addWidget( QWidget* widget )
{
m_widgets.push_back( widget );
return QToolBar::addWidget( widget );
}
void WQtToolBar::clearButtons()
{
clear();
// iterate all items and delete them
for ( std::list< QWidget* >::iterator it = m_widgets.begin(); it != m_widgets.end(); ++it )
{
delete ( *it );
}
// clear the lists
m_widgets.clear();
// The following prevents the bar from changing size when it has no real buttons.
QPushButton* dummyButton = new QPushButton;
dummyButton->setFixedWidth( 0 );
......
......@@ -25,6 +25,8 @@
#ifndef WQTTOOLBAR_H
#define WQTTOOLBAR_H
#include <list>
#include <QtGui/QToolBar>
#include "guiElements/WQtPushButton.h"
......@@ -55,12 +57,27 @@ public:
*/
WQtPushButton* addPushButton( QString name, QIcon icon, QString label = 0 );
/**
* Add a widget to the toolbar. This also stores the reference and removes it if clearButtons is called.
*
* \param widget the widget to add
*
* \return the corresponding action object
*/
QAction* addWidget( QWidget* widget );
/**
* Removes all buttons,
*/
void clearButtons();
protected:
/**
* The list of widgets in this toolbar.
*/
std::list< QWidget* > m_widgets;
private:
};
......
......@@ -41,7 +41,7 @@ WPropertyDoubleWidget::WPropertyDoubleWidget( WPropDouble property, QGridLayout*
m_layout( &m_parameterWidgets )
{
// initialize members
m_edit.resize( m_edit.minimumSizeHint().width() , m_edit.size().height() );
m_edit.resize( m_edit.minimumSizeHint().width() *.8 , m_edit.size().height() );
m_edit.setMaximumWidth( m_edit.minimumSizeHint().width() );
// layout both against each other
......@@ -128,8 +128,8 @@ void WPropertyDoubleWidget::update()
// resize the text widget
//m_edit.setMaxLength( length );
m_edit.setMaximumWidth( m_edit.minimumSizeHint().width() * length / 2 );
m_edit.setMinimumWidth( m_edit.minimumSizeHint().width() * length / 2 );
m_edit.resize( m_edit.minimumSizeHint().width() * length / 2, m_edit.size().height() );
// m_edit.setMinimumWidth( m_edit.minimumSizeHint().width() * length / 4 );
// m_edit.resize( m_edit.minimumSizeHint().width() * length / 2, m_edit.size().height() );
// set the initial values
m_edit.setText( QString( toString( m_doubleProperty->get() ).c_str() ) );
......
......@@ -42,7 +42,7 @@ WPropertyIntWidget::WPropertyIntWidget( WPropInt property, QGridLayout* property
m_layout( &m_parameterWidgets )
{
// initialize members
m_edit.resize( m_edit.minimumSizeHint().width() , m_edit.size().height() );
m_edit.resize( m_edit.minimumSizeHint().width(), m_edit.size().height() );
m_edit.setMaximumWidth( m_edit.minimumSizeHint().width() );
// layout both against each other
......@@ -112,10 +112,11 @@ void WPropertyIntWidget::update()
int length = 6; // use fixed length to have a uniform look among several widgets
// resize the text widget
m_edit.setMaxLength( length );
// m_edit.setMaxLength( length );
m_edit.setMaximumWidth( m_edit.minimumSizeHint().width() * length / 2 );
m_edit.setMinimumWidth( m_edit.minimumSizeHint().width() * length / 2 );
m_edit.resize( m_edit.minimumSizeHint().width() * length / 2, m_edit.size().height() );
// m_edit.setMinimumWidth( m_edit.minimumSizeHint().width() * length / 4 );
// m_edit.resize( m_edit.minimumSizeHint().width() * length / 4, m_edit.size().height() );
// set the initial values
m_edit.setText( QString( boost::lexical_cast< std::string >( m_intProperty->get() ).c_str() ) );
......
......@@ -37,23 +37,23 @@
#include "../../../dataHandler/WDataSet.h"
#include "WQtDatasetBrowser.h"
#include "../../../kernel/WModuleFactory.h"
#include "../../../kernel/WKernel.h"
#include "../../../modules/data/WMData.h"
#include "../events/WModuleAssocEvent.h"
#include "../events/WRoiAssocEvent.h"
#include "../events/WRoiRemoveEvent.h"
#include "../events/WModuleReadyEvent.h"
#include "../events/WModuleDeleteEvent.h"
#include "../events/WEventTypes.h"
#include "../guiElements/WQtApplyModulePushButton.h"
#include "../WMainWindow.h"
#include "WQtNumberEdit.h"
#include "WQtNumberEditDouble.h"
#include "WQtTextureSorter.h"
#include "WQtBranchTreeItem.h"
#include "../../../kernel/WModuleFactory.h"
#include "../WMainWindow.h"
#include "../../../modules/data/WMData.h"
#include "WQtDatasetBrowser.h"
WQtDatasetBrowser::WQtDatasetBrowser( WMainWindow* parent )
: QDockWidget( "Dataset Browser", parent )
......@@ -61,14 +61,14 @@ WQtDatasetBrowser::WQtDatasetBrowser( WMainWindow* parent )
m_mainWindow = parent;
m_panel = new QWidget( this );
m_treeWidget = new WQtTreeWidget( m_panel );
m_moduleTreeWidget = new WQtTreeWidget( m_panel );
m_treeWidget->setHeaderLabel( QString( "Dataset Browser" ) );
m_treeWidget->setDragEnabled( true );
m_treeWidget->viewport()->setAcceptDrops( true );
m_treeWidget->setDropIndicatorShown( true );
m_treeWidget->setDragDropMode( QAbstractItemView::InternalMove );
m_treeWidget->setMinimumHeight( 250 );
m_moduleTreeWidget->setHeaderLabel( QString( "Dataset Browser" ) );
m_moduleTreeWidget->setDragEnabled( true );
m_moduleTreeWidget->viewport()->setAcceptDrops( true );
m_moduleTreeWidget->setDropIndicatorShown( true );
m_moduleTreeWidget->setDragDropMode( QAbstractItemView::InternalMove );
m_moduleTreeWidget->setMinimumHeight( 250 );
m_textureSorter = new WQtTextureSorter( m_panel );
m_textureSorter->setToolTip( "Reorder the textures." );
......@@ -78,7 +78,7 @@ WQtDatasetBrowser::WQtDatasetBrowser( WMainWindow* parent )
m_tabWidget->setMinimumHeight( 220 );
m_layout = new QVBoxLayout();
m_layout->addWidget( m_treeWidget );
m_layout->addWidget( m_moduleTreeWidget );
m_layout->addWidget( m_tabWidget2 );
......@@ -102,7 +102,7 @@ WQtDatasetBrowser::WQtDatasetBrowser( WMainWindow* parent )
this->setFeatures( QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable );
this->setWidget( m_panel );
m_tiModules = new WQtModuleHeaderTreeItem( m_treeWidget );
m_tiModules = new WQtModuleHeaderTreeItem( m_moduleTreeWidget );
m_tiModules->setText( 0, QString( "Modules" ) );
m_tiRois = new WQtRoiHeaderTreeItem( m_roiTreeWidget );
m_tiRois->setText( 0, QString( "ROIs" ) );
......@@ -118,9 +118,10 @@ WQtDatasetBrowser::WQtDatasetBrowser( WMainWindow* parent )
WPreferences::getPreference( "modules.whiteList", &moduleWhiteList );
m_moduleWhiteList = string_utils::tokenize( moduleWhiteList, "," );
QShortcut* shortcut = new QShortcut( QKeySequence( Qt::Key_Delete ), m_roiTreeWidget );
connect( shortcut, SIGNAL( activated() ), this, SLOT( deleteTreeItem() ) );
connect( shortcut, SIGNAL( activated() ), this, SLOT( deleteROITreeItem() ) );
QShortcut* shortcutDeleteModules = new QShortcut( QKeySequence( Qt::Key_Backspace ), m_moduleTreeWidget );
connect( shortcutDeleteModules, SIGNAL( activated() ), this, SLOT( deleteModuleTreeItem() ) );
}
WQtDatasetBrowser::~WQtDatasetBrowser()
......@@ -130,8 +131,8 @@ WQtDatasetBrowser::~WQtDatasetBrowser()
void WQtDatasetBrowser::connectSlots()
{
connect( m_treeWidget, SIGNAL( itemSelectionChanged() ), this, SLOT( selectTreeItem() ) );
connect( m_treeWidget, SIGNAL( itemClicked( QTreeWidgetItem*, int ) ), this, SLOT( changeTreeItem() ) );
connect( m_moduleTreeWidget, SIGNAL( itemSelectionChanged() ), this, SLOT( selectTreeItem() ) );
connect( m_moduleTreeWidget, SIGNAL( itemClicked( QTreeWidgetItem*, int ) ), this, SLOT( changeTreeItem() ) );
connect( m_roiTreeWidget, SIGNAL( itemSelectionChanged() ), this, SLOT( selectRoiTreeItem() ) );
connect( m_roiTreeWidget, SIGNAL( itemClicked( QTreeWidgetItem*, int ) ), this, SLOT( changeRoiTreeItem() ) );
}
......@@ -139,7 +140,7 @@ void WQtDatasetBrowser::connectSlots()
WQtSubjectTreeItem* WQtDatasetBrowser::addSubject( std::string name )
{
WQtSubjectTreeItem* subject = new WQtSubjectTreeItem( m_treeWidget );
WQtSubjectTreeItem* subject = new WQtSubjectTreeItem( m_moduleTreeWidget );
subject->setText( 0, QString( name.c_str() ) );
return subject;
......@@ -199,6 +200,35 @@ bool WQtDatasetBrowser::event( QEvent* event )
return true;
}
// a module tree item should be deleted
if ( event->type() == WQT_MODULE_REMOVE_EVENT )
{
WModuleDeleteEvent* e = dynamic_cast< WModuleDeleteEvent* >( event ); // NOLINT
if ( !e )
{
// this should never happen, since the type is set to WQT_Ready_EVENT.
WLogger::getLogger()->addLogMessage( "Event is not an WModuleRemoveEvent although its type claims it. Ignoring event.",
"DatasetBrowser", LL_WARNING );
return true;
}
// grab the module reference and print some info
boost::shared_ptr< WModule > module = e->getTreeItem()->getModule();
WLogger::getLogger()->addLogMessage( "Removing module \"" + module->getName() + "\" from Tree.", "DatasetBrowser", LL_DEBUG );
// remove it from the tree and free last ref count