X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=appli%2FcpPipelineEditor%2FQNEBlock.cxx;fp=appli%2FcpPipelineEditor%2FQNEBlock.cxx;h=2b7ed51f6bc52f5580e4f9d6145f5086d0af1773;hb=e3dc1dcc5279b279f0ed7e39ed87b902bab7778c;hp=5d6f16c4e6b1e674ae0c49e8ab7c6608de89cbe2;hpb=6885cd42cb7981803efb5c27c0a1a761084dc31c;p=cpPlugins.git diff --git a/appli/cpPipelineEditor/QNEBlock.cxx b/appli/cpPipelineEditor/QNEBlock.cxx index 5d6f16c..2b7ed51 100644 --- a/appli/cpPipelineEditor/QNEBlock.cxx +++ b/appli/cpPipelineEditor/QNEBlock.cxx @@ -55,6 +55,22 @@ QNEBlock( TFilter* filter, QGraphicsItem* parent, QGraphicsScene* scene ) 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( ) ); } // ------------------------------------------------------------------------- @@ -75,75 +91,76 @@ setNamePort( const QString& txt ) } // ------------------------------------------------------------------------- -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 ); -} - -// ------------------------------------------------------------------------- -void PipelineEditor::QNEBlock:: +PipelineEditor::QNEInputPort* PipelineEditor::QNEBlock:: addInputPort( const QString& txt ) { QNEInputPort* ip = new QNEInputPort( this ); ip->setName( txt ); - this->m_InputPorts.push_back( ip ); + this->m_InputPorts[ txt.toStdString( ) ] = ip; this->_configPort( ip ); + return( ip ); } // ------------------------------------------------------------------------- -void PipelineEditor::QNEBlock:: +PipelineEditor::QNEOutputPort* PipelineEditor::QNEBlock:: addOutputPort( const QString& txt ) { QNEOutputPort* op = new QNEOutputPort( this ); op->setName( txt ); - this->m_OutputPorts.push_back( op ); + this->m_OutputPorts[ txt.toStdString( ) ] = op; this->_configPort( op ); + return( op ); } // ------------------------------------------------------------------------- -QVector< PipelineEditor::QNEPort* > PipelineEditor::QNEBlock:: -ports( ) +PipelineEditor::QNEInputPort* PipelineEditor::QNEBlock:: +inputPort( const QString& txt ) { - QVector< QNEPort* > res; - foreach( QGraphicsItem* i, this->childItems( ) ) - { - QNEPort* p = dynamic_cast< QNEPort* >( i ); - if( p != NULL ) - res.append( p ); - - } // rof - return( res ); + auto i = this->m_InputPorts.find( txt.toStdString( ) ); + if( i != this->m_InputPorts.end( ) ) + return( i->second ); + else + return( NULL ); } // ------------------------------------------------------------------------- -PipelineEditor::QNEBlock* PipelineEditor::QNEBlock:: -clone( ) +PipelineEditor::QNEOutputPort* PipelineEditor::QNEBlock:: +outputPort( const QString& txt ) { - QNEBlock* b = new QNEBlock( this->m_Filter, 0, this->scene( ) ); - foreach( QGraphicsItem* i, this->childItems( ) ) - { - QNENamePort* np = dynamic_cast< QNENamePort* >( i ); - if( np != NULL ) - b->setNamePort( np->name( ) ); - - QNETypePort* tp = dynamic_cast< QNETypePort* >( i ); - if( tp != NULL ) - b->setTypePort( tp->name( ) ); + auto o = this->m_OutputPorts.find( txt.toStdString( ) ); + if( o != this->m_OutputPorts.end( ) ) + return( o->second ); + else + return( NULL ); +} - QNEInputPort* ip = dynamic_cast< QNEInputPort* >( i ); - if( ip != NULL ) - b->addInputPort( ip->name( ) ); +// ------------------------------------------------------------------------- +const PipelineEditor::QNEInputPort* PipelineEditor::QNEBlock:: +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 ); +} - QNEOutputPort* op = dynamic_cast< QNEOutputPort* >( i ); - if( op != NULL ) - b->addOutputPort( op->name( ) ); +// ------------------------------------------------------------------------- +const PipelineEditor::QNEOutputPort* PipelineEditor::QNEBlock:: +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 ); +} - } // rof - return( b ); +// ------------------------------------------------------------------------- +const QString& PipelineEditor::QNEBlock:: +namePort( ) const +{ + return( this->m_NamePort->name( ) ); } // ------------------------------------------------------------------------- @@ -176,6 +193,16 @@ itemChange( GraphicsItemChange change, const QVariant& value ) return( value ); } +// ------------------------------------------------------------------------- +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 ); +} + // ------------------------------------------------------------------------- void PipelineEditor::QNEBlock:: _configPort( QNEPort* port ) @@ -214,4 +241,15 @@ _configPort( QNEPort* port ) } // rof } +// ------------------------------------------------------------------------- +void PipelineEditor::QNEBlock:: +mouseReleaseEvent( QGraphicsSceneMouseEvent* evt ) +{ + if( this->m_Filter.IsNotNull( ) ) + this->m_Filter->SetViewCoords( + this->scenePos( ).x( ), this->scenePos( ).y( ) + ); + this->Superclass::mouseReleaseEvent( evt ); +} + // eof - $RCSfile$