Commit d4f0f97e by Mathias Goldau

[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
......
......@@ -86,6 +86,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:
/**
......@@ -89,21 +94,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.
*/
void yield() const;
......
......@@ -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 );
}
......@@ -92,6 +92,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.
*
* \return the prototype.
......
......@@ -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"
......@@ -56,11 +58,26 @@ 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() ) );
......
......@@ -176,7 +176,7 @@ protected:
WMainWindow* m_mainWindow;
private:
WQtTreeWidget* m_treeWidget; //!< pointer to the tree widget
WQtTreeWidget* m_moduleTreeWidget; //!< pointer to the tree widget
WQtTreeWidget* m_roiTreeWidget; //!< pointer to the tree widget
......@@ -248,10 +248,14 @@ private slots:
void moveTreeItemUp();
/**
* delete a tree item
* delete a ROI tree item
*/
void deleteTreeItem();
void deleteROITreeItem();
/**
* delete a module tree item
*/
void deleteModuleTreeItem();
signals:
/**
......
......@@ -25,17 +25,27 @@
#include <set>
#include <string>
#include <QtGui/QApplication>
#include "../../../kernel/WKernel.h"
#include "../../../common/WProgressCombiner.h"
#include "../../../common/WProgress.h"
#include "../../../kernel/WModuleInputConnector.h"
#include "../../../kernel/WModuleOutputConnector.h"
#include "../events/WModuleDeleteEvent.h"
#include "../WQt4Gui.h"
#include "../WMainWindow.h"
#include "WTreeItemTypes.h"
#include "WQtTreeItem.h"
WQtTreeItem::WQtTreeItem( QTreeWidgetItem * parent, WTreeItemType type, boost::shared_ptr< WModule > module ) :
QTreeWidgetItem( parent, type )
QTreeWidgetItem( parent, type ),
m_deleteInProgress( false ),
m_needPostDeleteEvent( true )
{
m_module = module;
m_name = module->getName();
......@@ -148,7 +158,33 @@ void WQtTreeItem::updateState()
setText( 0, m_name.c_str() );
}
// if the user requested it to be deleted: disable and color it
if ( m_deleteInProgress )
{
setForeground( 0, QBrush( QColor::fromRgb( 255, 0, 0 ) ) );
setDisabled( true );
}
// is finished?
if ( m_deleteInProgress && !m_module->isRunning().get() && m_needPostDeleteEvent )
{
m_needPostDeleteEvent = false; // this ensures the event is only posted once
QCoreApplication::postEvent( WQt4Gui::getMainWindow()->getDatasetBrowser(), new WModuleDeleteEvent( this ) );
}
// update tooltip
updateTooltip( progress );
}
void WQtTreeItem::deleteSelf()
{
// instruct the kernel to remove module
WKernel::getRunningKernel()->getRootContainer()->remove( m_module );
// update tree item state
m_deleteInProgress = true;
// instruct the module to finish
m_module->requestStop();
}
......@@ -50,7 +50,7 @@ public:
* \param module The represented module
* \param type the type used for the treeitem. Used to identify the items.
*/
WQtTreeItem( QTreeWidgetItem * parent, WTreeItemType type, boost::shared_ptr< WModule > module );
WQtTreeItem( QTreeWidgetItem* parent, WTreeItemType type, boost::shared_ptr< WModule > module );
/**
* Destructor.
......@@ -62,7 +62,7 @@ public:
*
* \return the pointer to the module associated with this item.
*/
boost::shared_ptr< WModule >getModule();
boost::shared_ptr< WModule > getModule();
/**
* Returns the name used for this tree item.
......@@ -71,6 +71,11 @@ public:
*/
std::string getName();
/**
* Initiates the item to delete itself from the tree. It also removes the underlying module to be deleted from the module graph.
*/
virtual void deleteSelf();
public slots:
/**
......@@ -102,6 +107,16 @@ protected:
*/
void updateTooltip( std::string progress );
/**
* True if the treeitem and the module gets deleted currently.
*/
bool m_deleteInProgress;
/**
* True if no delete event has been posted yet.
*/
bool m_needPostDeleteEvent;
private:
/**
......
......@@ -38,6 +38,12 @@ WQtTreeWidget::~WQtTreeWidget()
{
}
void WQtTreeWidget::deleteItem( QTreeWidgetItem* item )
{
// takeTopLevelItem ( indexOfTopLevelItem( item ) );
delete item;
}
void WQtTreeWidget::moveTreeItemDown()
{
QTreeWidgetItem *parent = currentItem()->parent();
......
......@@ -46,6 +46,12 @@ public:
*/
virtual ~WQtTreeWidget();
/**
* Deletes an entry from the tree
* \param item The given item will be removed from the tree
*/
void deleteItem( QTreeWidgetItem* item );
public slots:
/**
* change order of items, move currently selected item down
......@@ -59,7 +65,6 @@ public slots:
//void keyPressEvent(QKeyEvent *e);
protected:
private:
};
......
......@@ -54,4 +54,7 @@
// when a roi got removed
#define WQT_ROI_REMOVE_EVENT QEvent::User + 7
// when a module got deleted
#define WQT_MODULE_REMOVE_EVENT QEvent::User + 8
#endif // WEVENTTYPES_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 "WEventTypes.h"
#include "WModuleDeleteEvent.h"
WModuleDeleteEvent::WModuleDeleteEvent( WQtTreeItem* treeItem )
: QEvent( static_cast< QEvent::Type >( WQT_MODULE_REMOVE_EVENT ) ),
m_item( treeItem )
{
// initialize members
}
WModuleDeleteEvent::~WModuleDeleteEvent()
{
// cleanup
}
WQtTreeItem* WModuleDeleteEvent::getTreeItem()
{
return m_item;
}
//---------------------------------------------------------------------------
//
// 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 WMODULEDELETEEVENT_H
#define WMODULEDELETEEVENT_H
#include <QtCore/QEvent>
#include "../datasetbrowser/WQtTreeItem.h"
/**
* Event signalling a module item should be deleted.
*/
class WModuleDeleteEvent: public QEvent