X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpBaseQtApplication%2FPipeline%2FBlock.cxx;fp=lib%2FcpBaseQtApplication%2FPipeline%2FBlock.cxx;h=0000000000000000000000000000000000000000;hb=2e142df11d6f312a2a2b5097b8da73571ed523e8;hp=3d235aa49595764f892bbd66842c052f47c17aa9;hpb=61b3659afe961ed248f30e26f9ca8f28fcfafddc;p=cpPlugins.git diff --git a/lib/cpBaseQtApplication/Pipeline/Block.cxx b/lib/cpBaseQtApplication/Pipeline/Block.cxx deleted file mode 100644 index 3d235aa..0000000 --- a/lib/cpBaseQtApplication/Pipeline/Block.cxx +++ /dev/null @@ -1,418 +0,0 @@ -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -// ------------------------------------------------------------------------- -QColor cpBaseQtApplication::Pipeline::Block:: -SelectedAndUpdated = Qt::green; -QColor cpBaseQtApplication::Pipeline::Block:: -NotSelectedAndUpdated = Qt::blue; -QColor cpBaseQtApplication::Pipeline::Block:: -SelectedAndNotUpdated = Qt::yellow; -QColor cpBaseQtApplication::Pipeline::Block:: -NotSelectedAndNotUpdated = Qt::lightGray; - -// ------------------------------------------------------------------------- -void cpBaseQtApplication::Pipeline::Block::_TFilterObserver:: -Execute( const itk::Object* c, const itk::EventObject& e ) -{ - typedef cpPlugins::Pipeline::Events::Modified _TModified; - const _TModified* mod_evt = dynamic_cast< const _TModified* >( &e ); - if( mod_evt != NULL ) - { - std::stringstream str; - str - << "(" << mod_evt->Time << "/" - << double( mod_evt->Span ) / double( 1000 ) << "s)"; - this->ObservedBlock->setInfoPort( str.str( ).c_str( ) ); - - } // fi -} - -// ------------------------------------------------------------------------- -cpBaseQtApplication::Pipeline::Block:: -Block( - TFilter* filter, - QGraphicsItem* parent, QGraphicsScene* scene - ) - : Superclass( parent, scene ), - m_HorzMargin( 20 ), - m_VertMargin( 5 ), - m_NamePort( NULL ), - m_InfoPort( NULL ), - m_Filter( filter ) -{ - QPainterPath p; - p.addRoundedRect( -50, -15, 100, 30, 5, 5 ); - - this->setPath( p ); - this->setPen( QPen( Qt::darkGreen ) ); - this->setBrush( Qt::green ); - this->setFlag( QGraphicsItem::ItemIsMovable ); - this->setFlag( QGraphicsItem::ItemIsSelectable ); - - this->m_Width = this->m_HorzMargin; - this->m_Height = this->m_VertMargin; - - // Configure names - this->setNamePort( filter->GetName( ) ); - this->setInfoPort( "(-/-)" ); - this->_setTypeInfo( - ( - std::string( this->m_Filter->GetClassCategory( ) ) + - std::string( "::" ) + - std::string( this->m_Filter->GetClassName( ) ) - ).c_str( ) - ); - - // Add input ports - auto inputs = this->m_Filter->GetInputsNames( ); - for( auto iIt = inputs.begin( ); iIt != inputs.end( ); ++iIt ) - { - this->addInputPort( - iIt->c_str( ), - this->m_Filter->IsInputMultiple( iIt->c_str( ) ) - ); - - } // rof - - // Add output ports - auto outputs = this->m_Filter->GetOutputsNames( ); - for( auto oIt = outputs.begin( ); oIt != outputs.end( ); ++oIt ) - this->addOutputPort( oIt->c_str( ) ); - - // Add obvserver - this->m_FilterObserver = _TFilterObserver::New( ); - this->m_FilterObserver->ObservedBlock = this; - this->m_FilterObserverId = - this->m_Filter->AddObserver( - cpPlugins::Pipeline::Events::Modified( ), this->m_FilterObserver - ); -} - -// ------------------------------------------------------------------------- -cpBaseQtApplication::Pipeline::Block:: -~Block( ) -{ - this->m_Filter->RemoveObserver( this->m_FilterObserverId ); -} - -// ------------------------------------------------------------------------- -cpBaseQtApplication::Pipeline::Block:: -TFilter* cpBaseQtApplication::Pipeline::Block:: -filter( ) -{ - return( this->m_Filter ); -} - -// ------------------------------------------------------------------------- -const cpBaseQtApplication::Pipeline::Block:: -TFilter* cpBaseQtApplication::Pipeline::Block:: -filter( ) const -{ - return( this->m_Filter ); -} - -// ------------------------------------------------------------------------- -void cpBaseQtApplication::Pipeline::Block:: -setNamePort( const QString& txt ) -{ - if( this->m_NamePort == NULL ) - this->m_NamePort = new NamePort( this ); - this->m_NamePort->setName( txt ); - this->_configPort( this->m_NamePort ); -} - -// ------------------------------------------------------------------------- -void cpBaseQtApplication::Pipeline::Block:: -setInfoPort( const QString& txt ) -{ - if( this->m_InfoPort == NULL ) - this->m_InfoPort = new InfoPort( this ); - this->m_InfoPort->setName( txt ); - this->_configPort( this->m_InfoPort ); -} - -// ------------------------------------------------------------------------- -cpBaseQtApplication::Pipeline::InputPort* -cpBaseQtApplication::Pipeline::Block:: -addInputPort( const QString& txt, bool multiple ) -{ - InputPort* ip = new InputPort( this, multiple ); - ip->setExtendedName( "" ); - ip->setName( txt ); - this->m_InputPorts[ txt.toStdString( ) ] = ip; - this->_configPort( ip ); - return( ip ); -} - -// ------------------------------------------------------------------------- -cpBaseQtApplication::Pipeline::OutputPort* -cpBaseQtApplication::Pipeline::Block:: -addOutputPort( const QString& txt ) -{ - OutputPort* op = new OutputPort( this ); - op->setExtendedName( "" ); - op->setName( txt ); - this->m_OutputPorts[ txt.toStdString( ) ] = op; - this->_configPort( op ); - return( op ); -} - -// ------------------------------------------------------------------------- -cpBaseQtApplication::Pipeline::InputPort* -cpBaseQtApplication::Pipeline::Block:: -inputPort( const QString& txt ) -{ - auto i = this->m_InputPorts.find( txt.toStdString( ) ); - if( i != this->m_InputPorts.end( ) ) - return( i->second ); - else - return( NULL ); -} - -// ------------------------------------------------------------------------- -cpBaseQtApplication::Pipeline::OutputPort* -cpBaseQtApplication::Pipeline::Block:: -outputPort( const QString& txt ) -{ - auto o = this->m_OutputPorts.find( txt.toStdString( ) ); - if( o != this->m_OutputPorts.end( ) ) - return( o->second ); - else - return( NULL ); -} - -// ------------------------------------------------------------------------- -QString cpBaseQtApplication::Pipeline::Block:: -namePort( ) const -{ - return( this->m_NamePort->name( ) ); -} - -// ------------------------------------------------------------------------- -const cpBaseQtApplication::Pipeline::InputPort* -cpBaseQtApplication::Pipeline::Block:: -inputPort( const QString& txt ) const -{ - auto i = this->m_InputPorts.find( txt.toStdString( ) ); - if( i != this->m_InputPorts.end( ) ) - return( i->second ); - else - return( NULL ); -} - -// ------------------------------------------------------------------------- -const cpBaseQtApplication::Pipeline::OutputPort* -cpBaseQtApplication::Pipeline::Block:: -outputPort( const QString& txt ) const -{ - auto o = this->m_OutputPorts.find( txt.toStdString( ) ); - if( o != this->m_OutputPorts.end( ) ) - return( o->second ); - else - return( NULL ); -} - - -// ------------------------------------------------------------------------- -bool cpBaseQtApplication::Pipeline::Block:: -connectOutputPortSlot( QObject* receiver, const char* slot ) -{ - bool ok = true; - for( auto p : this->m_OutputPorts ) - ok &= QObject::connect( - p.second, SIGNAL( viewData( const std::string&, bool ) ), - receiver, slot - ); - return( ok ); -} - -// ------------------------------------------------------------------------- -void cpBaseQtApplication::Pipeline::Block:: -setPos( const QPointF& pos ) -{ - this->m_Filter->SetViewCoords( pos.x( ), pos.y( ) ); - this->Superclass::setPos( pos ); -} - -// ------------------------------------------------------------------------- -void cpBaseQtApplication::Pipeline::Block:: -setPos( qreal x, qreal y ) -{ - this->m_Filter->SetViewCoords( x, y ); - this->Superclass::setPos( x, y ); -} - -// ------------------------------------------------------------------------- -void cpBaseQtApplication::Pipeline::Block:: -paint( - QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget - ) -{ - Q_UNUSED( option ); - Q_UNUSED( widget ); - - if( this->isSelected( ) ) - { - painter->setPen( QPen( Qt::darkYellow ) ); - painter->setBrush( Qt::yellow ); - } - else - { - painter->setPen( QPen( Qt::darkGreen ) ); - painter->setBrush( Qt::green ); - - } // fi - painter->drawPath( this->path( ) ); -} - -// ------------------------------------------------------------------------- -QVariant cpBaseQtApplication::Pipeline::Block:: -itemChange( GraphicsItemChange change, const QVariant& value ) -{ - return( value ); -} - -// ------------------------------------------------------------------------- -void cpBaseQtApplication::Pipeline::Block:: -_setTypeInfo( const QString& txt ) -{ - this->setToolTip( txt ); -} - -// ------------------------------------------------------------------------- -void cpBaseQtApplication::Pipeline::Block:: -_configPort( Port* port ) -{ - port->setBlock( this ); - - QFontMetrics fm( this->scene( )->font( ) ); - this->m_Width = 0; - foreach( QGraphicsItem* i, this->children( ) ) - { - Port* p = dynamic_cast< Port* >( i ); - if( p == NULL ) - continue; - int w = fm.width( p->name( ) ) + ( 4 * p->radius( ) ); - if( w > this->m_Width - this->m_HorzMargin ) - this->m_Width = w + this->m_HorzMargin; - - } // rof - int h = fm.height( ); - this->m_Height = this->m_InputPorts.size( ) + this->m_OutputPorts.size( ); - this->m_Height += 4; - this->m_Height *= h; - - QPainterPath pth; - pth.addRoundedRect( - -this->m_Width / 2, - -this->m_Height / 2, - this->m_Width, - this->m_Height, 5, 5 - ); - this->setPath( pth ); - - int y = -this->m_Height / 2 + this->m_VertMargin + port->radius( ); - foreach( QGraphicsItem* i, this->children( ) ) - { - Port* p = dynamic_cast< Port* >( i ); - if( p == NULL ) - continue; - - if( - dynamic_cast< NamePort* >( i ) != NULL || - dynamic_cast< InfoPort* >( i ) != NULL - ) - { - i->setPos( -this->m_Width / 2 + port->radius( ), y ); - y += h >> 1; - } - else if( dynamic_cast< InputPort* >( i ) != NULL ) - i->setPos( -this->m_Width / 2 - 2 * port->radius( ), y ); - else if( dynamic_cast< OutputPort* >( i ) != NULL ) - i->setPos( this->m_Width / 2, y ); - y += h; - - } // rof -} - -// ------------------------------------------------------------------------- -void cpBaseQtApplication::Pipeline::Block:: -mouseReleaseEvent( QGraphicsSceneMouseEvent* evt ) -{ - if( this->m_Filter.IsNotNull( ) ) - this->m_Filter->SetViewCoords( - this->scenePos( ).x( ), - this->scenePos( ).y( ) - ); - this->Superclass::mouseReleaseEvent( evt ); -} - -// ------------------------------------------------------------------------- -void cpBaseQtApplication::Pipeline::Block:: -contextMenuEvent( QGraphicsSceneContextMenuEvent* evt ) -{ - QMenu menu; - QAction* configureAction = menu.addAction( "Configure" ); - QAction* updateAction = menu.addAction( "Update" ); - auto widget = - dynamic_cast< cpPlugins::Pipeline::Widget* >( - this->m_Filter.GetPointer( ) - ); - QAction* enableAction = NULL; - if( widget != NULL ) - enableAction = - menu.addAction( ( widget->GetEnabled( ) )? "Disable": "Enable" ); - - QAction* selectedAction = menu.exec( evt->screenPos( ) ); - if( selectedAction == configureAction ) - { - auto dlg = this->m_Filter->CreateQDialog( ); - if( dlg != NULL ) - dlg->exec( ); - } - else if( selectedAction == enableAction ) - { - if( widget != NULL ) - widget->SetEnabled( !( widget->GetEnabled( ) ) ); - } - else if( selectedAction == updateAction ) - { - cpBaseQtApplication::Blocker blocker; - blocker.block( ); - try - { - this->m_Filter->Update( ); - blocker.unblock( ); - } - catch( std::exception& err ) - { - blocker.unblock( ); - QMessageBox::critical( - NULL, - QMessageBox::tr( "Error updating filter" ), - QMessageBox::tr( err.what( ) ) - ); - - } // yrt - - } // fi -} - -// eof - $RCSfile$