X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=appli%2FcpPipelineEditor%2FQNEBlock.cxx;h=2b7ed51f6bc52f5580e4f9d6145f5086d0af1773;hb=f8c546490b7168b5c75d877bf66d27f83aa9412c;hp=d1e01094d1bb535845c708d0cfe498c9c4abbc55;hpb=ef8b6e12859181d3faa8019ce7319c539c0f86ec;p=cpPlugins.git diff --git a/appli/cpPipelineEditor/QNEBlock.cxx b/appli/cpPipelineEditor/QNEBlock.cxx index d1e0109..2b7ed51 100644 --- a/appli/cpPipelineEditor/QNEBlock.cxx +++ b/appli/cpPipelineEditor/QNEBlock.cxx @@ -36,20 +36,41 @@ // ------------------------------------------------------------------------- PipelineEditor::QNEBlock:: -QNEBlock( QGraphicsItem* parent, QGraphicsScene* scene ) +QNEBlock( TFilter* filter, QGraphicsItem* parent, QGraphicsScene* scene ) : Superclass( parent, scene ), m_HorzMargin( 20 ), - m_VertMargin( 5 ) + m_VertMargin( 5 ), + m_NamePort( NULL ), + m_TypePort( 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( this->m_Filter->GetName( ) ); + this->_setTypePort( this->m_Filter->GetClassName( ) ); + + // Add input ports + std::set< std::string > inputs; + this->m_Filter->GetInputsNames( inputs ); + for( auto iIt = inputs.begin( ); iIt != inputs.end( ); ++iIt ) + this->addInputPort( iIt->c_str( ) ); + + // Add output ports + std::set< std::string > outputs; + this->m_Filter->GetOutputsNames( outputs ); + for( auto oIt = outputs.begin( ); oIt != outputs.end( ); ++oIt ) + this->addOutputPort( oIt->c_str( ) ); } // ------------------------------------------------------------------------- @@ -59,134 +80,87 @@ PipelineEditor::QNEBlock:: } // ------------------------------------------------------------------------- -PipelineEditor::QNEPort* PipelineEditor::QNEBlock:: -addPort( const QString& name, bool isOutput, int flags, int ptr ) +void PipelineEditor::QNEBlock:: +setNamePort( const QString& txt ) { - QNEPort* port = new QNEPort( this ); - port->setName( name ); - port->setIsOutput( isOutput ); - port->setNEBlock( this ); - port->setPortFlags( flags ); - port->setPtr( ptr ); - - QFontMetrics fm( this->scene( )->font( ) ); - int w = fm.width( name ); - int h = fm.height( ); - if( w > this->m_Width - this->m_HorzMargin ) - this->m_Width = w + this->m_HorzMargin; - this->m_Height += h; - - QPainterPath p; - p.addRoundedRect( - -this->m_Width / 2, - -this->m_Height / 2, - this->m_Width, - this->m_Height, 5, 5 - ); - this->setPath( p ); - - int y = -this->m_Height / 2 + this->m_VertMargin + port->radius( ); - foreach( QGraphicsItem* port_, children( ) ) - { - if( port_->type( ) != QNEPort::Type ) - continue; - - QNEPort* port = ( QNEPort* ) port_; - if( port->isOutput( ) ) - port->setPos( this->m_Width/2 + port->radius( ), y ); - else - port->setPos( -this->m_Width/2 - port->radius( ), y ); - y += h; - - } // rof - return( port ); + if( this->m_NamePort == NULL ) + this->m_NamePort = new QNENamePort( this ); + this->m_NamePort->setName( txt ); + this->m_Filter->SetName( txt.toStdString( ) ); + this->_configPort( this->m_NamePort ); } // ------------------------------------------------------------------------- -void PipelineEditor::QNEBlock:: -addInputPort( const QString& name ) +PipelineEditor::QNEInputPort* PipelineEditor::QNEBlock:: +addInputPort( const QString& txt ) { - this->addPort( name, false ); + QNEInputPort* ip = new QNEInputPort( this ); + ip->setName( txt ); + this->m_InputPorts[ txt.toStdString( ) ] = ip; + this->_configPort( ip ); + return( ip ); } // ------------------------------------------------------------------------- -void PipelineEditor::QNEBlock:: -addOutputPort( const QString& name ) +PipelineEditor::QNEOutputPort* PipelineEditor::QNEBlock:: +addOutputPort( const QString& txt ) { - this->addPort( name, true ); + QNEOutputPort* op = new QNEOutputPort( this ); + op->setName( txt ); + this->m_OutputPorts[ txt.toStdString( ) ] = op; + this->_configPort( op ); + return( op ); } // ------------------------------------------------------------------------- -void PipelineEditor::QNEBlock:: -addInputPorts( const QStringList& names ) +PipelineEditor::QNEInputPort* PipelineEditor::QNEBlock:: +inputPort( const QString& txt ) { - foreach( QString n, names ) - this->addInputPort( n ); + auto i = this->m_InputPorts.find( txt.toStdString( ) ); + if( i != this->m_InputPorts.end( ) ) + return( i->second ); + else + return( NULL ); } // ------------------------------------------------------------------------- -void PipelineEditor::QNEBlock:: -addOutputPorts( const QStringList& names ) +PipelineEditor::QNEOutputPort* PipelineEditor::QNEBlock:: +outputPort( const QString& txt ) { - foreach( QString n, names ) - this->addOutputPort( n ); + auto o = this->m_OutputPorts.find( txt.toStdString( ) ); + if( o != this->m_OutputPorts.end( ) ) + return( o->second ); + else + return( NULL ); } // ------------------------------------------------------------------------- -void PipelineEditor::QNEBlock:: -save( QDataStream& ds ) +const PipelineEditor::QNEInputPort* PipelineEditor::QNEBlock:: +inputPort( const QString& txt ) const { - ds << pos( ); - - int count( 0 ); - - foreach( QGraphicsItem* port_, children( ) ) - { - if( port_->type( ) != QNEPort::Type ) - continue; - count++; - - } // rof - - ds << count; - - foreach( QGraphicsItem* port_, children( ) ) - { - if( port_->type( ) != QNEPort::Type ) - continue; - - QNEPort* port = ( QNEPort* ) port_; - ds << ( quint64 ) port; - ds << port->portName( ); - ds << port->isOutput( ); - ds << port->portFlags( ); - - } // rof + auto i = this->m_InputPorts.find( txt.toStdString( ) ); + if( i != this->m_InputPorts.end( ) ) + return( i->second ); + else + return( NULL ); } // ------------------------------------------------------------------------- -void PipelineEditor::QNEBlock:: -load( QDataStream& ds, QMap& portMap ) +const PipelineEditor::QNEOutputPort* PipelineEditor::QNEBlock:: +outputPort( const QString& txt ) const { - QPointF p; - ds >> p; - this->setPos( p ); - int count; - ds >> count; - for( int i = 0; i < count; i++ ) - { - QString name; - bool output; - int flags; - quint64 ptr; - - ds >> ptr; - ds >> name; - ds >> output; - ds >> flags; - portMap[ptr] = this->addPort( name, output, flags, ptr ); + auto o = this->m_OutputPorts.find( txt.toStdString( ) ); + if( o != this->m_OutputPorts.end( ) ) + return( o->second ); + else + return( NULL ); +} - } // rof +// ------------------------------------------------------------------------- +const QString& PipelineEditor::QNEBlock:: +namePort( ) const +{ + return( this->m_NamePort->name( ) ); } // ------------------------------------------------------------------------- @@ -213,48 +187,69 @@ paint( } // ------------------------------------------------------------------------- -PipelineEditor::QNEBlock* PipelineEditor::QNEBlock:: -clone( ) +QVariant PipelineEditor::QNEBlock:: +itemChange( GraphicsItemChange change, const QVariant& value ) { - QNEBlock* b = new QNEBlock( 0, this->scene( ) ); - - foreach( QGraphicsItem* port_, childItems( ) ) - { - if( port_->type( ) == QNEPort::Type ) - { - QNEPort* port = ( QNEPort* ) port_; - b->addPort( - port->portName( ), - port->isOutput( ), - port->portFlags( ), - port->ptr( ) - ); - - } // fi + return( value ); +} - } // rof - return( b ); +// ------------------------------------------------------------------------- +void PipelineEditor::QNEBlock:: +_setTypePort( const QString& txt ) +{ + if( this->m_TypePort == NULL ) + this->m_TypePort = new QNETypePort( this ); + this->m_TypePort->setName( txt ); + this->_configPort( this->m_TypePort ); } // ------------------------------------------------------------------------- -QVector< PipelineEditor::QNEPort* > PipelineEditor::QNEBlock:: -ports( ) +void PipelineEditor::QNEBlock:: +_configPort( QNEPort* port ) { - QVector< PipelineEditor::QNEPort* > res; - foreach( QGraphicsItem* port_, childItems( ) ) + port->setBlock( this ); + + QFontMetrics fm( this->scene( )->font( ) ); + int w = fm.width( port->name( ) ); + int h = fm.height( ); + if( w > this->m_Width - this->m_HorzMargin ) + this->m_Width = w + this->m_HorzMargin; + 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( ) ) { - if( port_->type( ) == QNEPort::Type ) - res.append( ( QNEPort* ) port_ ); + QNEPort* p = dynamic_cast< QNEPort* >( i ); + if( p == NULL ) + continue; + + if( dynamic_cast< QNEOutputPort* >( p ) != NULL ) + p->setPos( this->m_Width / 2 + port->radius( ), y ); + else + p->setPos( -this->m_Width / 2 - port->radius( ), y ); + y += h; } // rof - return( res ); } // ------------------------------------------------------------------------- -QVariant PipelineEditor::QNEBlock:: -itemChange( GraphicsItemChange change, const QVariant& value ) +void PipelineEditor::QNEBlock:: +mouseReleaseEvent( QGraphicsSceneMouseEvent* evt ) { - return( value ); + if( this->m_Filter.IsNotNull( ) ) + this->m_Filter->SetViewCoords( + this->scenePos( ).x( ), this->scenePos( ).y( ) + ); + this->Superclass::mouseReleaseEvent( evt ); } // eof - $RCSfile$