#include <QStyleOptionGraphicsItem>\r
\r
#include "QNEPort.h"\r
+#include "QNEConnection.h"\r
\r
// -------------------------------------------------------------------------\r
PipelineEditor::QNEBlock::\r
-QNEBlock( QGraphicsItem* parent, QGraphicsScene* scene )\r
+QNEBlock( TFilter* filter, QGraphicsItem* parent, QGraphicsScene* scene )\r
: Superclass( parent, scene ),\r
m_HorzMargin( 20 ),\r
- m_VertMargin( 5 )\r
+ m_VertMargin( 5 ),\r
+ m_NamePort( NULL ),\r
+ m_TypePort( NULL ),\r
+ m_Filter( filter )\r
{\r
QPainterPath p;\r
p.addRoundedRect( -50, -15, 100, 30, 5, 5 );\r
+\r
this->setPath( p );\r
this->setPen( QPen( Qt::darkGreen ) );\r
this->setBrush( Qt::green );\r
this->setFlag( QGraphicsItem::ItemIsMovable );\r
this->setFlag( QGraphicsItem::ItemIsSelectable );\r
+\r
this->m_Width = this->m_HorzMargin;\r
this->m_Height = this->m_VertMargin;\r
+\r
+ // Configure names\r
+ this->setNamePort( this->m_Filter->GetName( ) );\r
+ this->_setTypePort( this->m_Filter->GetClassName( ) );\r
+\r
+ // Add input ports\r
+ std::set< std::string > inputs;\r
+ this->m_Filter->GetInputsNames( inputs );\r
+ for( auto iIt = inputs.begin( ); iIt != inputs.end( ); ++iIt )\r
+ this->addInputPort( iIt->c_str( ) );\r
+\r
+ // Add output ports\r
+ std::set< std::string > outputs;\r
+ this->m_Filter->GetOutputsNames( outputs );\r
+ for( auto oIt = outputs.begin( ); oIt != outputs.end( ); ++oIt )\r
+ this->addOutputPort( oIt->c_str( ) );\r
}\r
\r
// -------------------------------------------------------------------------\r
}\r
\r
// -------------------------------------------------------------------------\r
-PipelineEditor::QNEPort* PipelineEditor::QNEBlock::\r
-addPort( const QString& name, bool isOutput, int flags, int ptr )\r
+void PipelineEditor::QNEBlock::\r
+setNamePort( const QString& txt )\r
{\r
- QNEPort* port = new QNEPort( this );\r
- port->setName( name );\r
- port->setIsOutput( isOutput );\r
- port->setNEBlock( this );\r
- port->setPortFlags( flags );\r
- port->setPtr( ptr );\r
+ if( this->m_NamePort == NULL )\r
+ this->m_NamePort = new QNENamePort( this );\r
+ this->m_NamePort->setName( txt );\r
+ this->m_Filter->SetName( txt.toStdString( ) );\r
+ this->_configPort( this->m_NamePort );\r
+}\r
\r
- QFontMetrics fm( this->scene( )->font( ) );\r
- int w = fm.width( name );\r
- int h = fm.height( );\r
- if( w > this->m_Width - this->m_HorzMargin )\r
- this->m_Width = w + this->m_HorzMargin;\r
- this->m_Height += h;\r
+// -------------------------------------------------------------------------\r
+PipelineEditor::QNEInputPort* PipelineEditor::QNEBlock::\r
+addInputPort( const QString& txt )\r
+{\r
+ QNEInputPort* ip = new QNEInputPort( this );\r
+ ip->setExtendedName(\r
+ (\r
+ txt.toStdString( ) +\r
+ std::string( "@" ) +\r
+ this->namePort( ).toStdString( )\r
+ ).c_str( )\r
+ );\r
+ ip->setName( txt );\r
+ this->m_InputPorts[ txt.toStdString( ) ] = ip;\r
+ this->_configPort( ip );\r
+ return( ip );\r
+}\r
\r
- QPainterPath p;\r
- p.addRoundedRect(\r
- -this->m_Width / 2,\r
- -this->m_Height / 2,\r
- this->m_Width,\r
- this->m_Height, 5, 5\r
+// -------------------------------------------------------------------------\r
+PipelineEditor::QNEOutputPort* PipelineEditor::QNEBlock::\r
+addOutputPort( const QString& txt )\r
+{\r
+ QNEOutputPort* op = new QNEOutputPort( this );\r
+ op->setExtendedName(\r
+ (\r
+ txt.toStdString( ) +\r
+ std::string( "@" ) +\r
+ this->namePort( ).toStdString( )\r
+ ).c_str( )\r
);\r
- this->setPath( p );\r
+ op->setName( txt );\r
+ this->m_OutputPorts[ txt.toStdString( ) ] = op;\r
+ this->_configPort( op );\r
+ return( op );\r
+}\r
\r
- int y = -this->m_Height / 2 + this->m_VertMargin + port->radius( );\r
- foreach( QGraphicsItem* port_, children( ) )\r
+// -------------------------------------------------------------------------\r
+bool PipelineEditor::QNEBlock::\r
+extendInputPort( const QString& txt, QNEConnection* conn )\r
+{\r
+ auto p = this->m_InputPorts.find( txt.toStdString( ) );\r
+ auto i = this->m_ExtInputPorts.find( txt.toStdString( ) );\r
+ if( p != this->m_InputPorts.end( ) && i == this->m_ExtInputPorts.end( ) )\r
{\r
- if( port_->type( ) != QNEPort::Type )\r
- continue;\r
-\r
- QNEPort* port = ( QNEPort* ) port_;\r
- if( port->isOutput( ) )\r
- port->setPos( this->m_Width/2 + port->radius( ), y );\r
- else\r
- port->setPos( -this->m_Width/2 - port->radius( ), y );\r
- y += h;\r
-\r
- } // rof\r
- return( port );\r
+ this->m_ExtInputPorts[ txt.toStdString( ) ] = conn;\r
+ return( true );\r
+ }\r
+ else\r
+ return( false );\r
}\r
\r
// -------------------------------------------------------------------------\r
-PipelineEditor::QNEPort* PipelineEditor::QNEBlock::\r
-addInputPort( const QString& name )\r
+bool PipelineEditor::QNEBlock::\r
+extendOutputPort( const QString& txt, QNEConnection* conn )\r
{\r
- return( this->addPort( name, false ) );\r
+ auto p = this->m_OutputPorts.find( txt.toStdString( ) );\r
+ auto i = this->m_ExtOutputPorts.find( txt.toStdString( ) );\r
+ if( p != this->m_OutputPorts.end( ) && i == this->m_ExtOutputPorts.end( ) )\r
+ {\r
+ this->m_ExtOutputPorts[ txt.toStdString( ) ] = conn;\r
+ return( true );\r
+ }\r
+ else\r
+ return( false );\r
}\r
\r
// -------------------------------------------------------------------------\r
-PipelineEditor::QNEPort* PipelineEditor::QNEBlock::\r
-addOutputPort( const QString& name )\r
+PipelineEditor::QNEInputPort* PipelineEditor::QNEBlock::\r
+inputPort( const QString& txt )\r
{\r
- return( this->addPort( name, true ) );\r
+ auto i = this->m_InputPorts.find( txt.toStdString( ) );\r
+ if( i != this->m_InputPorts.end( ) )\r
+ return( i->second );\r
+ else\r
+ return( NULL );\r
}\r
\r
// -------------------------------------------------------------------------\r
-void PipelineEditor::QNEBlock::\r
-addInputPorts( const QStringList& names )\r
+PipelineEditor::QNEOutputPort* PipelineEditor::QNEBlock::\r
+outputPort( const QString& txt )\r
{\r
- foreach( QString n, names )\r
- this->addInputPort( n );\r
+ auto o = this->m_OutputPorts.find( txt.toStdString( ) );\r
+ if( o != this->m_OutputPorts.end( ) )\r
+ return( o->second );\r
+ else\r
+ return( NULL );\r
}\r
\r
// -------------------------------------------------------------------------\r
-void PipelineEditor::QNEBlock::\r
-addOutputPorts( const QStringList& names )\r
+QString PipelineEditor::QNEBlock::\r
+namePort( ) const\r
{\r
- foreach( QString n, names )\r
- this->addOutputPort( n );\r
+ return( this->m_NamePort->name( ) );\r
}\r
\r
// -------------------------------------------------------------------------\r
-void PipelineEditor::QNEBlock::\r
-save( QDataStream& ds )\r
+const PipelineEditor::QNEInputPort* PipelineEditor::QNEBlock::\r
+inputPort( const QString& txt ) const\r
{\r
- ds << pos( );\r
-\r
- int count( 0 );\r
-\r
- foreach( QGraphicsItem* port_, children( ) )\r
- {\r
- if( port_->type( ) != QNEPort::Type )\r
- continue;\r
- count++;\r
-\r
- } // rof\r
-\r
- ds << count;\r
-\r
- foreach( QGraphicsItem* port_, children( ) )\r
- {\r
- if( port_->type( ) != QNEPort::Type )\r
- continue;\r
-\r
- QNEPort* port = ( QNEPort* ) port_;\r
- ds << ( quint64 ) port;\r
- ds << port->portName( );\r
- ds << port->isOutput( );\r
- ds << port->portFlags( );\r
-\r
- } // rof\r
+ auto i = this->m_InputPorts.find( txt.toStdString( ) );\r
+ if( i != this->m_InputPorts.end( ) )\r
+ return( i->second );\r
+ else\r
+ return( NULL );\r
}\r
\r
// -------------------------------------------------------------------------\r
-void PipelineEditor::QNEBlock::\r
-load( QDataStream& ds, QMap<quint64, QNEPort*>& portMap )\r
+const PipelineEditor::QNEOutputPort* PipelineEditor::QNEBlock::\r
+outputPort( const QString& txt ) const\r
{\r
- QPointF p;\r
- ds >> p;\r
- this->setPos( p );\r
- int count;\r
- ds >> count;\r
- for( int i = 0; i < count; i++ )\r
- {\r
- QString name;\r
- bool output;\r
- int flags;\r
- quint64 ptr;\r
+ auto o = this->m_OutputPorts.find( txt.toStdString( ) );\r
+ if( o != this->m_OutputPorts.end( ) )\r
+ return( o->second );\r
+ else\r
+ return( NULL );\r
+}\r
\r
- ds >> ptr;\r
- ds >> name;\r
- ds >> output;\r
- ds >> flags;\r
- portMap[ptr] = this->addPort( name, output, flags, ptr );\r
+// -------------------------------------------------------------------------\r
+const PipelineEditor::QNEConnection* PipelineEditor::QNEBlock::\r
+extendedInputPort( const QString& txt ) const\r
+{\r
+ auto i = this->m_ExtInputPorts.find( txt.toStdString( ) );\r
+ if( i != this->m_ExtInputPorts.end( ) )\r
+ return( i->second );\r
+ else\r
+ return( NULL );\r
+}\r
\r
- } // rof\r
+// -------------------------------------------------------------------------\r
+const PipelineEditor::QNEConnection* PipelineEditor::QNEBlock::\r
+extendedOutputPort( const QString& txt ) const\r
+{\r
+ auto i = this->m_ExtOutputPorts.find( txt.toStdString( ) );\r
+ if( i != this->m_ExtOutputPorts.end( ) )\r
+ return( i->second );\r
+ else\r
+ return( NULL );\r
}\r
\r
// -------------------------------------------------------------------------\r
}\r
\r
// -------------------------------------------------------------------------\r
-PipelineEditor::QNEBlock* PipelineEditor::QNEBlock::\r
-clone( )\r
+QVariant PipelineEditor::QNEBlock::\r
+itemChange( GraphicsItemChange change, const QVariant& value )\r
{\r
- QNEBlock* b = new QNEBlock( 0, this->scene( ) );\r
-\r
- foreach( QGraphicsItem* port_, childItems( ) )\r
- {\r
- if( port_->type( ) == QNEPort::Type )\r
- {\r
- QNEPort* port = ( QNEPort* ) port_;\r
- b->addPort(\r
- port->portName( ),\r
- port->isOutput( ),\r
- port->portFlags( ),\r
- port->ptr( )\r
- );\r
-\r
- } // fi\r
+ return( value );\r
+}\r
\r
- } // rof\r
- return( b );\r
+// -------------------------------------------------------------------------\r
+void PipelineEditor::QNEBlock::\r
+_setTypePort( const QString& txt )\r
+{\r
+ if( this->m_TypePort == NULL )\r
+ this->m_TypePort = new QNETypePort( this );\r
+ this->m_TypePort->setName( txt );\r
+ this->_configPort( this->m_TypePort );\r
}\r
\r
// -------------------------------------------------------------------------\r
-QVector< PipelineEditor::QNEPort* > PipelineEditor::QNEBlock::\r
-ports( )\r
+void PipelineEditor::QNEBlock::\r
+_configPort( QNEPort* port )\r
{\r
- QVector< PipelineEditor::QNEPort* > res;\r
- foreach( QGraphicsItem* port_, childItems( ) )\r
+ port->setBlock( this );\r
+\r
+ QFontMetrics fm( this->scene( )->font( ) );\r
+ int w = fm.width( port->name( ) ) + ( 4 * port->radius( ) );\r
+ int h = fm.height( );\r
+ if( w > this->m_Width - this->m_HorzMargin )\r
+ this->m_Width = w + this->m_HorzMargin;\r
+ this->m_Height = this->m_InputPorts.size( ) + this->m_OutputPorts.size( );\r
+ this->m_Height += 4;\r
+ this->m_Height *= h;\r
+\r
+ QPainterPath pth;\r
+ pth.addRoundedRect(\r
+ -this->m_Width / 2,\r
+ -this->m_Height / 2,\r
+ this->m_Width,\r
+ this->m_Height, 5, 5\r
+ );\r
+ this->setPath( pth );\r
+\r
+ int y = -this->m_Height / 2 + this->m_VertMargin + port->radius( );\r
+ foreach( QGraphicsItem* i, this->children( ) )\r
{\r
- if( port_->type( ) == QNEPort::Type )\r
- res.append( ( QNEPort* ) port_ );\r
+ QNEPort* p = dynamic_cast< QNEPort* >( i );\r
+ if( p == NULL )\r
+ continue;\r
+\r
+ if( dynamic_cast< QNENamePort* >( i ) != NULL )\r
+ i->setPos( -this->m_Width / 2 + port->radius( ), y );\r
+ else if( dynamic_cast< QNETypePort* >( i ) != NULL )\r
+ {\r
+ i->setPos( -this->m_Width / 2 + port->radius( ), y );\r
+ y += h;\r
+ }\r
+ else if( dynamic_cast< QNEInputPort* >( i ) != NULL )\r
+ i->setPos( -this->m_Width / 2 - 2 * port->radius( ), y );\r
+ else if( dynamic_cast< QNEOutputPort* >( i ) != NULL )\r
+ i->setPos( this->m_Width / 2, y );\r
+\r
+ /* TODO\r
+ QNEPort* p = dynamic_cast< QNEPort* >( i );\r
+ if( p == NULL )\r
+ continue;\r
+\r
+ if( dynamic_cast< QNEOutputPort* >( p ) != NULL )\r
+ p->setPos( this->m_Width / 2 + port->radius( ), y );\r
+ else\r
+ p->setPos( -this->m_Width / 2 - port->radius( ), y );\r
+ */\r
+ y += h;\r
\r
} // rof\r
- return( res );\r
}\r
\r
// -------------------------------------------------------------------------\r
-QVariant PipelineEditor::QNEBlock::\r
-itemChange( GraphicsItemChange change, const QVariant& value )\r
+void PipelineEditor::QNEBlock::\r
+mouseReleaseEvent( QGraphicsSceneMouseEvent* evt )\r
{\r
- return( value );\r
+ if( this->m_Filter.IsNotNull( ) )\r
+ this->m_Filter->SetViewCoords(\r
+ this->scenePos( ).x( ), this->scenePos( ).y( )\r
+ );\r
+ this->Superclass::mouseReleaseEvent( evt );\r
}\r
\r
// eof - $RCSfile$\r