Commit b1eab5cc authored by schurade's avatar schurade
Browse files

[ADD] more work on fiber selection

parent 164c5b25
......@@ -34,3 +34,13 @@ boost::signals2::signal0< void >* WROI::getSignalIsModified()
{
return &m_signalIsModified;
}
void WROI::setNot( bool isNot )
{
m_isNot = isNot;
}
bool WROI::isNot()
{
return m_isNot;
}
......@@ -54,6 +54,10 @@ public:
*/
boost::signals2::signal0< void >* getSignalIsModified();
void setNot( bool isNot = true );
bool isNot();
protected:
osg::ref_ptr< WPickHandler > m_pickHandler; //!< A pointer to the pick handler used to get gui events for moving the box.
osg::Geode* m_geode; //!< The graphical representation of the ROI.
......@@ -64,11 +68,13 @@ protected:
*/
boost::signals2::signal0< void >m_signalIsModified;
private:
bool m_isNot; //!< Indivated whether the region of interest is inside the WROI (false) oroutside (true).
WColor m_color; //!< The selected onject (Fibers, region on surface, ...) will have this color if m_useColor.
bool m_useColor; //!< Indicated whether m_color should be used for display.
private:
/**
* updates the graphics
* \param text text info from pick
......
......@@ -166,14 +166,13 @@ WROIBox::WROIBox( wmath::WPosition minPos, wmath::WPosition maxPos ) :
lightModel->setTwoSided( true );
state->setAttributeAndModes( lightModel.get(), osg::StateAttribute::ON );
state->setMode( GL_BLEND, osg::StateAttribute::ON );
<<<<<<< /SCR/schurade/workspace/walnut-hg/src/graphicsEngine/WROIBox.cpp
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->addChild( m_geode );
m_isModified = true;
=======
m_isNot = false;
assert( WGraphicsEngine::getGraphicsEngine() );
WGraphicsEngine::getGraphicsEngine()->getScene()->addChild( m_geode );
>>>>>>> /tmp/WROIBox.cpp~other.0y8ftg
}
wmath::WPosition WROIBox::getMinPos() const
......
......@@ -46,6 +46,8 @@
#include "../../common/WPreferences.h"
#include "../../kernel/WKernel.h"
#include "../../graphicsEngine/WROIBox.h"
#include "../icons/WIcons.h"
WMainWindow::WMainWindow() :
......@@ -141,6 +143,7 @@ void WMainWindow::setupRibbonMenu()
m_ribbonMenu->addPushButton( QString( "buttonLoad" ), QString( "File" ), m_iconManager.getIcon( "load" ), QString( "Load" ) );
m_ribbonMenu->addPushButton( QString( "buttonSave" ), QString( "File" ), m_iconManager.getIcon( "save" ), QString( "Save" ) );
m_ribbonMenu->addPushButton( QString( "buttonQuit" ), QString( "File" ), m_iconManager.getIcon( "quit" ), QString( "Exit" ) );
m_ribbonMenu->addPushButton( QString( "buttonRoi" ), QString( "File" ), m_iconManager.getIcon( "quit" ), QString( "ROI" ) );
// the parent (this) will take care for deleting the shortcut
QShortcut* shortcut = new QShortcut( QKeySequence( tr( "Ctrl+Q", "File|Exit" ) ), this );
......@@ -148,6 +151,7 @@ void WMainWindow::setupRibbonMenu()
connect( m_ribbonMenu->getButton( QString( "buttonQuit" ) ), SIGNAL( pressed() ), this, SLOT( close() ) );
connect( m_ribbonMenu->getButton( QString( "buttonLoad" ) ), SIGNAL( pressed() ), this, SLOT( openLoadDialog() ) );
connect( m_ribbonMenu->getButton( QString( "buttonRoi" ) ), SIGNAL( pressed() ), this, SLOT( newRoi() ) );
m_ribbonMenu->addTab( QString( "Modules" ) );
m_ribbonMenu->addTab( QString( "Help" ) );
......@@ -379,3 +383,16 @@ void WMainWindow::slotActivateModule( QString module )
m_moduleButtonSignal( getDatasetBrowser()->getSelectedModule(), WModuleFactory::getModuleFactory()->getPrototypeByName( module.toStdString() ) );
}
void WMainWindow::newRoi()
{
if ( m_datasetBrowser->getSelectedRoi().get() == NULL )
{
boost::shared_ptr< WROIBox > newRoi = boost::shared_ptr< WROIBox >( new WROIBox( wmath::WPosition( 60., 60., 60.), wmath::WPosition( 80., 80., 80. ) ) );
WKernel::getRunningKernel()->getRoiManager()->addRoi( newRoi );
}
else
{
boost::shared_ptr< WROIBox > newRoi = boost::shared_ptr< WROIBox >( new WROIBox( wmath::WPosition( 60., 60., 60.), wmath::WPosition( 80., 80., 80. ) ) );
WKernel::getRunningKernel()->getRoiManager()->addRoi( newRoi, m_datasetBrowser->getSelectedRoi()->getROI() );
}
}
......@@ -165,6 +165,11 @@ public slots:
*/
void slotActivateModule( QString module );
/**
* gets called when the button new roi is pressed
*/
void newRoi();
private:
/**
* Sets up the initial state of the ribbon menu
......
......@@ -42,6 +42,7 @@
#include "WOpenCustomDockWidgetEvent.h"
#include "WQt4Gui.h"
#include "events/WModuleAssocEvent.h"
#include "events/WRoiAssocEvent.h"
#include "events/WModuleReadyEvent.h"
WQt4Gui::WQt4Gui( int argc, char** argv )
......@@ -139,6 +140,8 @@ int WQt4Gui::run()
m_kernel->getRootContainer()->addDefaultNotifier( WM_ASSOCIATED, assocSignal );
t_ModuleGenericSignalHandlerType readySignal = boost::bind( &WQt4Gui::slotActivateDatasetOrModuleInBrowser, this, _1 );
m_kernel->getRootContainer()->addDefaultNotifier( WM_READY, readySignal );
boost::function< void ( boost::shared_ptr< WRMROIRepresentation > ) > assocRoiSignal = boost::bind( &WQt4Gui::slotAddRoiToBrowser, this, _1 );
m_kernel->getRoiManager()->addDefaultNotifier( assocRoiSignal );
// now we are initialized
m_isInitialized( true );
......@@ -168,6 +171,11 @@ void WQt4Gui::slotAddDatasetOrModuleToBrowser( boost::shared_ptr< WModule > modu
QCoreApplication::postEvent( m_mainWindow->getDatasetBrowser(), new WModuleAssocEvent( module ) );
}
void WQt4Gui::slotAddRoiToBrowser( boost::shared_ptr< WRMROIRepresentation > roi )
{
QCoreApplication::postEvent( m_mainWindow->getDatasetBrowser(), new WRoiAssocEvent( roi ) );
}
void WQt4Gui::slotActivateDatasetOrModuleInBrowser( boost::shared_ptr< WModule > module )
{
// create a new event for this and insert it into event queue
......
......@@ -32,6 +32,7 @@
#include "../WGUI.h"
#include "../../kernel/WModule.h"
#include "../../modules/fiberDisplay2/WRMROIRepresentation.h"
class WMainWindow;
class WGraphicsEngine;
......@@ -91,6 +92,14 @@ public:
*/
virtual void slotAddDatasetOrModuleToBrowser( boost::shared_ptr< WModule > module );
/**
* Slot gets called whenever a new roi is added.
*
* \param roi the roi to be added
*/
virtual void slotAddRoiToBrowser( boost::shared_ptr< WRMROIRepresentation > roi );
/**
* Slot gets called whenever a module switches its state to "ready".
*
......
......@@ -36,12 +36,12 @@
#include "WQtDatasetBrowser.h"
#include "../events/WModuleAssocEvent.h"
#include "../events/WRoiAssocEvent.h"
#include "../events/WModuleReadyEvent.h"
#include "../events/WEventTypes.h"
#include "WQtNumberEdit.h"
#include "WQtNumberEditDouble.h"
#include "WQtCheckBox.h"
#include "WQtModuleHeaderTreeItem.h"
#include "../../../kernel/WModuleFactory.h"
#include "../WMainWindow.h"
......@@ -85,8 +85,10 @@ WQtDatasetBrowser::WQtDatasetBrowser( WMainWindow* parent )
this->setFeatures( QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable );
this->setWidget( m_panel );
WQtModuleHeaderTreeItem* tiModules = new WQtModuleHeaderTreeItem( m_treeWidget );
tiModules->setText( 0, QString( "Modules" ) );
m_tiModules = new WQtModuleHeaderTreeItem( m_treeWidget );
m_tiModules->setText( 0, QString( "Modules" ) );
m_tiRois = new WQtRoiHeaderTreeItem( m_treeWidget );
m_tiRois->setText( 0, QString( "rois" ) );
connectSlots();
}
......@@ -119,26 +121,32 @@ bool WQtDatasetBrowser::event( QEvent* event )
if ( event->type() == WQT_ASSOC_EVENT )
{
// convert event to assoc event
WModuleAssocEvent* e = dynamic_cast< WModuleAssocEvent* >( event ); // NOLINT
if ( !e )
WModuleAssocEvent* e1 = dynamic_cast< WModuleAssocEvent* >( event ); // NOLINT
if ( e1 )
{
// this should never happen, since the type is set to WQT_ASSOC_EVENT.
WLogger::getLogger()->addLogMessage( "Event is not an WModueAssocEvent although its type claims it. Ignoring event.",
"DatasetBrowser", LL_WARNING );
}
WLogger::getLogger()->addLogMessage( "Inserting module " + e1->getModule()->getName() + " to dataset browser.",
"DatasetBrowser", LL_DEBUG );
WLogger::getLogger()->addLogMessage( "Inserting module " + e->getModule()->getName() + " to dataset browser.",
"DatasetBrowser", LL_DEBUG );
// finally add the module
// TODO(schurade): is this differentiation between data and "normal" modules really needed?
if ( boost::shared_dynamic_cast< WMData >( e->getModule() ).get() )
{
addDataset( e->getModule(), 0 );
// finally add the module
// TODO(schurade): is this differentiation between data and "normal" modules really needed?
if ( boost::shared_dynamic_cast< WMData >( e1->getModule() ).get() )
{
addDataset( e1->getModule(), 0 );
}
else
{
addModule( e1->getModule() );
}
}
else
return true;
}
if ( event->type() == WQT_ROI_ASSOC_EVENT)
{
WRoiAssocEvent* e2 = dynamic_cast< WRoiAssocEvent* >( event ); // NOLINT
if ( e2 )
{
addModule( e->getModule() );
addRoi( e2->getRoi() );
WLogger::getLogger()->addLogMessage( "Inserting roi to dataset browser.", "DatasetBrowser", LL_DEBUG );
}
return true;
......@@ -198,9 +206,27 @@ bool WQtDatasetBrowser::event( QEvent* event )
return QDockWidget::event( event );
}
void WQtDatasetBrowser::addModule2( boost::shared_ptr< WModule > module, int subjectId )
{
if ( boost::shared_dynamic_cast< WMData >( module ) )
{
WQtSubjectTreeItem* subject = ( WQtSubjectTreeItem* )m_treeWidget->topLevelItem( subjectId + 1 );
subject->setExpanded( true );
WQtDatasetTreeItem* item = subject->addDatasetItem( module );
item->setDisabled( true );
}
else
{
m_tiModules->setExpanded( true );
WQtModuleTreeItem* item = m_tiModules->addModuleItem( module );
item->setDisabled( true );
}
}
WQtDatasetTreeItem* WQtDatasetBrowser::addDataset( boost::shared_ptr< WModule > module, int subjectId )
{
WQtSubjectTreeItem* subject = ( WQtSubjectTreeItem* )m_treeWidget->topLevelItem( subjectId + 1 );
int c = getFirstSubject();
WQtSubjectTreeItem* subject = ( WQtSubjectTreeItem* )m_treeWidget->topLevelItem( subjectId + c );
subject->setExpanded( true );
WQtDatasetTreeItem* item = subject->addDatasetItem( module );
item->setDisabled( true );
......@@ -209,13 +235,53 @@ WQtDatasetTreeItem* WQtDatasetBrowser::addDataset( boost::shared_ptr< WModule >
WQtModuleTreeItem* WQtDatasetBrowser::addModule( boost::shared_ptr< WModule > module )
{
WQtModuleHeaderTreeItem* tiModules = ( WQtModuleHeaderTreeItem* )m_treeWidget->topLevelItem( 0 );
tiModules->setExpanded( true );
WQtModuleTreeItem* item = tiModules->addModuleItem( module );
m_tiModules->setExpanded( true );
WQtModuleTreeItem* item = m_tiModules->addModuleItem( module );
item->setDisabled( true );
return item;
}
void WQtDatasetBrowser::addRoi( boost::shared_ptr< WRMROIRepresentation > roi )
{
if ( m_treeWidget->selectedItems().count() != 0 )
{
switch ( m_treeWidget->selectedItems().at( 0 )->type() )
{
case 5 :
{
WQtRoiTreeItem* roiItem =( ( WQtRoiTreeItem* ) m_treeWidget->selectedItems().at( 0 ) );
m_tiRois->setExpanded( true );
roiItem->setExpanded( true );
WQtRoiTreeItem* item = roiItem->addRoiItem( roi );
item->setDisabled( false );
break;
}
case 6 :
{
WQtRoiTreeItem* roiItem =( ( WQtRoiTreeItem* ) m_treeWidget->selectedItems().at( 0 )->parent() );
m_tiRois->setExpanded( true );
roiItem->setExpanded( true );
WQtRoiTreeItem* item = roiItem->addRoiItem( roi );
item->setDisabled( false );
break;
}
default:
{
m_tiRois->setExpanded( true );
WQtRoiTreeItem* item = m_tiRois->addRoiItem( roi );
item->setDisabled( false );
break;
}
}
}
else
{
m_tiRois->setExpanded( true );
WQtRoiTreeItem* item = m_tiRois->addRoiItem( roi );
item->setDisabled( false );
}
}
boost::shared_ptr< WModule > WQtDatasetBrowser::getSelectedModule()
{
if ( m_treeWidget->selectedItems().at( 0 )->type() == 1 )
......@@ -234,41 +300,35 @@ void WQtDatasetBrowser::selectTreeItem()
{
// TODO(schurade): qt doc says clear() doesn't delete tabs so this is possibly a memory leak
m_tabWidget->clear();
if ( m_treeWidget->selectedItems().size() == 0 || m_treeWidget->selectedItems().at( 0 )->type() == 0 ||
m_treeWidget->selectedItems().at( 0 )->type() == 2 )
{
return;
}
boost::shared_ptr< WModule >module;
m_mainWindow->getCompatiblesToolBar()->clearNonPersistentTabs();
if ( m_treeWidget->selectedItems().at( 0 )->type() == 1 )
{
module = ( ( WQtDatasetTreeItem* ) m_treeWidget->selectedItems().at( 0 ) )->getModule();
}
else
{
module = ( ( WQtModuleTreeItem* ) m_treeWidget->selectedItems().at( 0 ) )->getModule();
}
boost::shared_ptr< WModule >module;
std::vector < WProperty* >props;
// every module may have compatibles: create ribbon menu entry
m_mainWindow->getCompatiblesToolBar()->addTab( QString( "Compatible Modules" ), false );
std::set< boost::shared_ptr< WModule > > comps = WModuleFactory::getModuleFactory()->getCompatiblePrototypes( module );
for ( std::set< boost::shared_ptr< WModule > >::iterator iter = comps.begin(); iter != comps.end(); ++iter )
if ( m_treeWidget->selectedItems().size() != 0 )
{
WQtPushButton* button = m_mainWindow->getCompatiblesToolBar()->addPushButton( QString( ( *iter )->getName().c_str() ),
QString( "Compatible Modules" ),
m_mainWindow->getIconManager()->getIcon( "o" ),
QString( ( *iter )->getName().c_str() ) );
connect( button, SIGNAL( pushButtonPressed( QString ) ), m_mainWindow, SLOT( slotActivateModule( QString ) ) );
switch ( m_treeWidget->selectedItems().at( 0 )->type() )
{
case 0:
break;
case 1:
case 3:
module = ( ( WQtModuleTreeItem* ) m_treeWidget->selectedItems().at( 0 ) )->getModule();
props = module->getProperties()->getPropertyVector();
createCompatibleButtons( module );
break;
case 2:
break;
case 4:
break;
case 5:
case 6:
props = ( ( WQtRoiTreeItem* ) m_treeWidget->selectedItems().at( 0 ) )->getRoi()->getProperties()->getPropertyVector();
break;
default:
break;
}
}
// create properties
std::vector < WProperty* >props = module->getProperties()->getPropertyVector();
WQtDSBWidget* tab1 = new WQtDSBWidget( "Settings" );
for ( size_t i = 0; i < props.size(); ++i )
......@@ -326,6 +386,22 @@ void WQtDatasetBrowser::selectTreeItem()
}
void WQtDatasetBrowser::createCompatibleButtons( boost::shared_ptr< WModule >module )
{
// every module may have compatibles: create ribbon menu entry
m_mainWindow->getCompatiblesToolBar()->addTab( QString( "Compatible Modules" ), false );
std::set< boost::shared_ptr< WModule > > comps = WModuleFactory::getModuleFactory()->getCompatiblePrototypes( module );
for ( std::set< boost::shared_ptr< WModule > >::iterator iter = comps.begin(); iter != comps.end(); ++iter )
{
WQtPushButton* button = m_mainWindow->getCompatiblesToolBar()->addPushButton( QString( ( *iter )->getName().c_str() ),
QString( "Compatible Modules" ),
m_mainWindow->getIconManager()->getIcon( "o" ),
QString( ( *iter )->getName().c_str() ) );
connect( button, SIGNAL( pushButtonPressed( QString ) ), m_mainWindow, SLOT( slotActivateModule( QString ) ) );
}
}
void WQtDatasetBrowser::changeTreeItem()
{
if ( m_treeWidget->selectedItems().size() == 1 && m_treeWidget->selectedItems().at( 0 )->type() == 1 )
......@@ -362,32 +438,28 @@ void WQtDatasetBrowser::addTabWidgetContent( WQtDSBWidget* content )
void WQtDatasetBrowser::slotSetIntProperty( QString name, int value )
{
boost::shared_ptr< WModule >module =( ( WQtDatasetTreeItem* ) m_treeWidget->selectedItems().at( 0 ) )->getModule();
module->getProperties()->setValue<int>( name.toStdString(), value );
getPropOfSelected()->setValue<int>( name.toStdString(), value );
emit dataSetBrowserEvent( QString( "textureChanged" ), true );
}
void WQtDatasetBrowser::slotSetDoubleProperty( QString name, double value )
{
boost::shared_ptr< WModule >module =( ( WQtDatasetTreeItem* ) m_treeWidget->selectedItems().at( 0 ) )->getModule();
module->getProperties()->setValue<double>( name.toStdString(), value );
getPropOfSelected()->setValue<double>( name.toStdString(), value );
emit dataSetBrowserEvent( QString( "textureChanged" ), true );
}
void WQtDatasetBrowser::slotSetBoolProperty( QString name, bool value )
{
boost::shared_ptr< WModule >module =( ( WQtDatasetTreeItem* ) m_treeWidget->selectedItems().at( 0 ) )->getModule();
module->getProperties()->setValue<bool>( name.toStdString(), value );
getPropOfSelected()->setValue<bool>( name.toStdString(), value );
emit dataSetBrowserEvent( QString( "textureChanged" ), true );
}
void WQtDatasetBrowser::slotSetStringProperty( QString name, QString value )
{
boost::shared_ptr< WModule >module =( ( WQtDatasetTreeItem* ) m_treeWidget->selectedItems().at( 0 ) )->getModule();
module->getProperties()->setValue<std::string>( name.toStdString(), value.toStdString() );
getPropOfSelected()->setValue<std::string>( name.toStdString(), value.toStdString() );
if ( name == "Name")
{
......@@ -395,20 +467,51 @@ void WQtDatasetBrowser::slotSetStringProperty( QString name, QString value )
}
}
boost::shared_ptr< WProperties > WQtDatasetBrowser::getPropOfSelected()
{
boost::shared_ptr< WModule > module;
boost::shared_ptr< WProperties > props;
if ( m_treeWidget->selectedItems().size() != 0 )
{
switch ( m_treeWidget->selectedItems().at( 0 )->type() )
{
case 0:
break;
case 1:
case 3:
module = ( ( WQtModuleTreeItem* ) m_treeWidget->selectedItems().at( 0 ) )->getModule();
props = module->getProperties();
break;
case 2:
break;
case 4:
break;
case 5:
case 6:
props = ( ( WQtRoiTreeItem* ) m_treeWidget->selectedItems().at( 0 ) )->getRoi()->getProperties();
break;
default:
break;
}
}
return props;
}
std::vector< boost::shared_ptr< WDataSet > > WQtDatasetBrowser::getDataSetList( int subjectId, bool onlyTextures )
{
int c = getFirstSubject();
std::vector< boost::shared_ptr< WDataSet > >moduleList;
if ( m_treeWidget->invisibleRootItem()->childCount() < subjectId + 1)
if ( m_treeWidget->invisibleRootItem()->childCount() < subjectId + c)
{
return moduleList;
}
int count = m_treeWidget->invisibleRootItem()->child( subjectId + 1 )->childCount();
int count = m_treeWidget->invisibleRootItem()->child( subjectId + c )->childCount();
for ( int i = 0 ; i < count ; ++i )
{
boost::shared_ptr< WMData > dm = boost::shared_dynamic_cast< WMData >( ( ( WQtDatasetTreeItem* )m_treeWidget->invisibleRootItem()->child(
subjectId + 1 )->child( i ) )->getModule() );
subjectId + c )->child( i ) )->getModule() );
if ( dm->isReady()() && ( !onlyTextures || dm->getDataSet()->isTexture() ) )
{
......@@ -433,3 +536,36 @@ void WQtDatasetBrowser::moveTreeItemUp()
emit dataSetBrowserEvent( QString( "textureChanged" ), true );
}
int WQtDatasetBrowser::getFirstSubject()
{
int c = 0;
for ( int i = 0; i < m_treeWidget->topLevelItemCount() ; ++i )
{
if ( m_treeWidget->topLevelItem( i )->type() == 0 )
{
break;
}
++c;
}
return c;
}
boost::shared_ptr< WRMROIRepresentation > WQtDatasetBrowser::getSelectedRoi()
{
boost::shared_ptr< WRMROIRepresentation >roi;
if ( m_treeWidget->selectedItems().count() == 0 )
{
return roi;
}
if ( m_treeWidget->selectedItems().at( 0 )->type() == 5 )
{
roi =( ( WQtRoiTreeItem* ) m_treeWidget->selectedItems().at( 0 ) )->getRoi();
std::cout << "return this" << std::endl;
}
if ( m_treeWidget->selectedItems().at( 0 )->type() == 6 )
{
roi =( ( WQtRoiTreeItem* ) m_treeWidget->selectedItems().at( 0 )->parent() )->getRoi();
std::cout << "return parent" << std::endl;
}
return roi;
}
......@@ -36,8 +36,13 @@
#include "WQtDSBWidget.h"
#include "WQtSubjectTreeItem.h"
#include "WQtModuleTreeItem.h"
#include "WQtModuleHeaderTreeItem.h"
#include "WQtRoiHeaderTreeItem.h"
#include "WQtTreeWidget.h"
#include "../../../graphicsEngine/WROI.h"
#include "../../../modules/fiberDisplay2/WRMROIRepresentation.h"
#include "../../../dataHandler/WDataSet.h"
class WMainWindow;
......@@ -98,6 +103,11 @@ public:
*/
WQtModuleTreeItem* addModule( boost::shared_ptr< WModule > module );
void addRoi( boost::shared_ptr< WRMROIRepresentation > roi );
void addModule2( boost::shared_ptr< WModule > module, int subjectId = 0 );
/**
* Returns a vector of pointers to the loaded datasets for a given subject.
*
......@@ -120,6 +130,11 @@ public:
*/
boost::shared_ptr< WModule > getSelectedModule();
/**
*
*/
boost::shared_ptr< WRMROIRepresentation > getSelectedRoi();
public slots:
/**
* slot to connect dynamically created controls
......@@ -153,7 +168,6 @@ public slots:
*/
void slotSetStringProperty( QString name, QString value );
protected:
/**
......@@ -166,6 +180,21 @@ protected:
*/
virtual bool event( QEvent* event );
/**