\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
-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
-void PipelineEditor::QNEBlock::\r
+PipelineEditor::QNEInputPort* PipelineEditor::QNEBlock::\r
addInputPort( const QString& txt )\r
{\r
QNEInputPort* ip = new QNEInputPort( this );\r
ip->setName( txt );\r
- this->m_InputPorts.push_back( ip );\r
+ this->m_InputPorts[ txt.toStdString( ) ] = ip;\r
this->_configPort( ip );\r
+ return( ip );\r
}\r
\r
// -------------------------------------------------------------------------\r
-void PipelineEditor::QNEBlock::\r
+PipelineEditor::QNEOutputPort* PipelineEditor::QNEBlock::\r
addOutputPort( const QString& txt )\r
{\r
QNEOutputPort* op = new QNEOutputPort( this );\r
op->setName( txt );\r
- this->m_OutputPorts.push_back( op );\r
+ this->m_OutputPorts[ txt.toStdString( ) ] = op;\r
this->_configPort( op );\r
+ return( op );\r
}\r
\r
// -------------------------------------------------------------------------\r
-QVector< PipelineEditor::QNEPort* > PipelineEditor::QNEBlock::\r
-ports( )\r
+PipelineEditor::QNEInputPort* PipelineEditor::QNEBlock::\r
+inputPort( const QString& txt )\r
{\r
- QVector< QNEPort* > res;\r
- foreach( QGraphicsItem* i, this->childItems( ) )\r
- {\r
- QNEPort* p = dynamic_cast< QNEPort* >( i );\r
- if( p != NULL )\r
- res.append( p );\r
-\r
- } // rof\r
- return( res );\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
-PipelineEditor::QNEBlock* PipelineEditor::QNEBlock::\r
-clone( )\r
+PipelineEditor::QNEOutputPort* PipelineEditor::QNEBlock::\r
+outputPort( const QString& txt )\r
{\r
- QNEBlock* b = new QNEBlock( this->m_Filter, 0, this->scene( ) );\r
- foreach( QGraphicsItem* i, this->childItems( ) )\r
- {\r
- QNENamePort* np = dynamic_cast< QNENamePort* >( i );\r
- if( np != NULL )\r
- b->setNamePort( np->name( ) );\r
-\r
- QNETypePort* tp = dynamic_cast< QNETypePort* >( i );\r
- if( tp != NULL )\r
- b->setTypePort( tp->name( ) );\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
- QNEInputPort* ip = dynamic_cast< QNEInputPort* >( i );\r
- if( ip != NULL )\r
- b->addInputPort( ip->name( ) );\r
+// -------------------------------------------------------------------------\r
+const PipelineEditor::QNEInputPort* PipelineEditor::QNEBlock::\r
+inputPort( const QString& txt ) const\r
+{\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
- QNEOutputPort* op = dynamic_cast< QNEOutputPort* >( i );\r
- if( op != NULL )\r
- b->addOutputPort( op->name( ) );\r
+// -------------------------------------------------------------------------\r
+const PipelineEditor::QNEOutputPort* PipelineEditor::QNEBlock::\r
+outputPort( const QString& txt ) const\r
+{\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
- } // rof\r
- return( b );\r
+// -------------------------------------------------------------------------\r
+const QString& PipelineEditor::QNEBlock::\r
+namePort( ) const\r
+{\r
+ return( this->m_NamePort->name( ) );\r
}\r
\r
// -------------------------------------------------------------------------\r
return( value );\r
}\r
\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
void PipelineEditor::QNEBlock::\r
_configPort( QNEPort* port )\r
} // rof\r
}\r
\r
+// -------------------------------------------------------------------------\r
+void PipelineEditor::QNEBlock::\r
+mouseReleaseEvent( QGraphicsSceneMouseEvent* evt )\r
+{\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
virtual ~QNEBlock( );\r
\r
void setNamePort( const QString& txt );\r
- void setTypePort( const QString& txt );\r
- void addInputPort( const QString& txt );\r
- void addOutputPort( const QString& txt );\r
- QVector< QNEPort* > ports( );\r
-\r
- inline QNENamePort* namePort( )\r
- { return( this->m_NamePort ); }\r
- inline QNETypePort* typePort( )\r
- { return( this->m_TypePort ); }\r
- inline QVector< QNEInputPort* >& inputPorts( )\r
- { return( this->m_InputPorts ); }\r
- inline QVector< QNEOutputPort* >& outputPorts( )\r
- { return( this->m_OutputPorts ); }\r
-\r
- inline const QNENamePort* namePort( ) const\r
- { return( this->m_NamePort ); }\r
- inline const QNETypePort* typePort( ) const\r
- { return( this->m_TypePort ); }\r
- inline const QVector< QNEInputPort* >& inputPorts( ) const\r
- { return( this->m_InputPorts ); }\r
- inline const QVector< QNEOutputPort* >& outputPorts( ) const\r
- { return( this->m_OutputPorts ); }\r
-\r
- QNEBlock* clone( );\r
+ QNEInputPort* addInputPort( const QString& txt );\r
+ QNEOutputPort* addOutputPort( const QString& txt );\r
+ QNEInputPort* inputPort( const QString& txt );\r
+ QNEOutputPort* outputPort( const QString& txt );\r
+\r
+ const QString& namePort( ) const;\r
+ const QNEInputPort* inputPort( const QString& txt ) const;\r
+ const QNEOutputPort* outputPort( const QString& txt ) const;\r
+\r
inline int type( ) const\r
{ return( this->Type ); }\r
\r
\r
protected:\r
QVariant itemChange( GraphicsItemChange change, const QVariant& value );\r
+ void _setTypePort( const QString& txt );\r
void _configPort( QNEPort* port );\r
\r
+ virtual void mouseReleaseEvent( QGraphicsSceneMouseEvent* evt );\r
+\r
private:\r
int m_HorzMargin;\r
int m_VertMargin;\r
\r
QNENamePort* m_NamePort;\r
QNETypePort* m_TypePort;\r
- QVector< QNEInputPort* > m_InputPorts;\r
- QVector< QNEOutputPort* > m_OutputPorts;\r
+ std::map< std::string, QNEInputPort* > m_InputPorts;\r
+ std::map< std::string, QNEOutputPort* > m_OutputPorts;\r
\r
TFilter::Pointer m_Filter;\r
};\r
PipelineEditor::QNEConnection::\r
~QNEConnection( )\r
{\r
- QNEOutputPort* op = dynamic_cast< QNEOutputPort* >( this->m_Port1 );\r
- if( op != NULL )\r
- op->connections( ).remove( op->connections( ).indexOf( this ) );\r
+ if( this->m_Port1 != NULL )\r
+ this->m_Port1->connections( ).\r
+ remove( this->m_Port1->connections( ).indexOf( this ) );\r
\r
- QNEInputPort* ip = dynamic_cast< QNEInputPort* >( this->m_Port2 );\r
- if( ip != NULL )\r
- ip->setConnection( NULL );\r
+ if( this->m_Port2 != NULL )\r
+ this->m_Port2->setConnection( NULL );\r
}\r
\r
// -------------------------------------------------------------------------\r
\r
// -------------------------------------------------------------------------\r
void PipelineEditor::QNEConnection::\r
-setPort1( QNEPort* p )\r
+setPort1( QNEOutputPort* p )\r
{\r
- QNEOutputPort* op = dynamic_cast< QNEOutputPort* >( p );\r
- if( op != NULL )\r
+ if( p != NULL )\r
{\r
- op->connections( ).append( this );\r
- this->m_Port1 = op;\r
+ p->connections( ).append( this );\r
+ this->m_Port1 = p;\r
\r
} // fi\r
}\r
\r
// -------------------------------------------------------------------------\r
void PipelineEditor::QNEConnection::\r
-setPort2( QNEPort* p )\r
+setPort2( QNEInputPort* p )\r
{\r
- QNEInputPort* ip = dynamic_cast< QNEInputPort* >( p );\r
- if( ip != NULL )\r
+ if( p != NULL )\r
{\r
- if( ip->connection( ) == NULL )\r
+ if( p->connection( ) == NULL )\r
{\r
- ip->setConnection( this );\r
- this->m_Port2 = ip;\r
+ p->setConnection( this );\r
+ this->m_Port2 = p;\r
\r
} // fi\r
\r
}\r
\r
// -------------------------------------------------------------------------\r
-PipelineEditor::QNEPort* PipelineEditor::QNEConnection::\r
+PipelineEditor::QNEOutputPort* PipelineEditor::QNEConnection::\r
port1( ) const\r
{\r
return( this->m_Port1 );\r
}\r
\r
// -------------------------------------------------------------------------\r
-PipelineEditor::QNEPort* PipelineEditor::QNEConnection::\r
+PipelineEditor::QNEInputPort* PipelineEditor::QNEConnection::\r
port2( ) const\r
{\r
return( this->m_Port2 );\r
\r
namespace PipelineEditor\r
{\r
- class QNEPort;\r
+ class QNEInputPort;\r
+ class QNEOutputPort;\r
\r
/**\r
*/\r
\r
void setPos1( const QPointF& p );\r
void setPos2( const QPointF& p );\r
- void setPort1( QNEPort* p );\r
- void setPort2( QNEPort* p );\r
+ void setPort1( QNEOutputPort* p );\r
+ void setPort2( QNEInputPort* p );\r
void updatePosFromPorts( );\r
void updatePath( );\r
- QNEPort* port1( ) const;\r
- QNEPort* port2( ) const;\r
+ QNEOutputPort* port1( ) const;\r
+ QNEInputPort* port2( ) const;\r
\r
inline int type( ) const\r
{ return( this->Type ); }\r
private:\r
QPointF m_Pos1;\r
QPointF m_Pos2;\r
- QNEPort* m_Port1;\r
- QNEPort* m_Port2;\r
+ QNEOutputPort* m_Port1;\r
+ QNEInputPort* m_Port2;\r
};\r
\r
} // ecapseman\r
auto rIt_end = this->m_Workspace->GetGraph( )->EndEdgesRows( );\r
for( ; rIt != rIt_end; ++rIt )\r
{\r
- if( !this->m_Graph->HasVertexIndex( rIt->first ) )\r
- continue;\r
QNEBlock* orig = this->m_Graph->GetVertex( rIt->first );\r
- if( orig == NULL )\r
- continue;\r
- QVector< QNEOutputPort* >& oPorts = orig->outputPorts( );\r
-\r
auto cIt = rIt->second.begin( );\r
for( ; cIt != rIt->second.end( ); ++cIt )\r
{\r
- if( !this->m_Graph->HasVertexIndex( cIt->first ) )\r
- continue;\r
QNEBlock* dest = this->m_Graph->GetVertex( cIt->first );\r
- if( dest == NULL )\r
- continue;\r
- QVector< QNEInputPort* >& iPorts = dest->inputPorts( );\r
-\r
auto eIt = cIt->second.begin( );\r
for( ; eIt != cIt->second.end( ); ++eIt )\r
{\r
- QNEOutputPort* op = NULL;\r
- auto opIt = oPorts.begin( );\r
- for( ; opIt != oPorts.end( ) && op == NULL; ++opIt )\r
- if( ( *opIt )->name( ).toStdString( ) == eIt->first )\r
- op = *opIt;\r
-\r
- QNEInputPort* ip = NULL;\r
- auto ipIt = iPorts.begin( );\r
- for( ; ipIt != iPorts.end( ) && ip == NULL; ++ipIt )\r
- if( ( *ipIt )->name( ).toStdString( ) == eIt->second )\r
- ip = *ipIt;\r
-\r
+ QNEOutputPort* op = orig->outputPort( eIt->first.c_str( ) );\r
+ QNEInputPort* ip = dest->inputPort( eIt->second.c_str( ) );\r
if( op == NULL || ip == NULL )\r
continue;\r
\r
- QNEConnection* conn = new QNEConnection( 0, this->m_Scene );\r
- conn->setPort1( op );\r
- conn->setPort2( ip );\r
- conn->updatePosFromPorts( );\r
- conn->updatePath( );\r
- this->m_Graph->AddConnection( rIt->first, cIt->first, conn );\r
+ QNEConnection* c = new QNEConnection( 0, this->m_Scene );\r
+ c->setPort1( op );\r
+ c->setPort2( ip );\r
+ c->updatePosFromPorts( );\r
+ c->updatePath( );\r
+ this->m_Graph->AddConnection( rIt->first, cIt->first, c );\r
\r
} // rof\r
\r
return( "" );\r
}\r
\r
-// -------------------------------------------------------------------------\r
-void PipelineEditor::QNodesEditor::\r
-synchronizeBlockPositions( )\r
-{\r
- auto bIt = this->m_Graph->BeginVertices( );\r
- auto fIt = this->m_Workspace->GetGraph( )->BeginVertices( );\r
- while(\r
- bIt != this->m_Graph->EndVertices( ) &&\r
- fIt != this->m_Workspace->GetGraph( )->EndVertices( )\r
- )\r
- {\r
- auto pos = bIt->second->scenePos( );\r
- fIt->second->SetViewCoords( pos.x( ), pos.y( ) );\r
- bIt++;\r
- fIt++;\r
-\r
- } // elihw\r
-}\r
-\r
// -------------------------------------------------------------------------\r
void PipelineEditor::QNodesEditor::\r
install( QGraphicsScene* s )\r
\r
// Add block\r
QNEBlock* b = new QNEBlock( f, 0, this->m_Scene );\r
- b->setNamePort( f->GetName( ) );\r
- b->setTypePort( f->GetClassName( ) );\r
b->setPos( pnt );\r
\r
- // Add input ports\r
- std::set< std::string > inputs;\r
- f->GetInputsNames( inputs );\r
- for( auto iIt = inputs.begin( ); iIt != inputs.end( ); ++iIt )\r
- b->addInputPort( iIt->c_str( ) );\r
-\r
- // Add output ports\r
- std::set< std::string > outputs;\r
- f->GetOutputsNames( outputs );\r
- for( auto oIt = outputs.begin( ); oIt != outputs.end( ); ++oIt )\r
- b->addOutputPort( oIt->c_str( ) );\r
-\r
// Keep a trace of this visual graph\r
this->m_Graph->SetVertex( f->GetName( ), b );\r
}\r
\r
if( block != NULL )\r
{\r
- QString old_name = block->namePort( )->name( );\r
+ QString old_name = block->namePort( );\r
bool ok;\r
QString new_name =\r
QInputDialog::getText(\r
} // fi\r
\r
} // fi\r
-\r
- /* TODO\r
- auto ports = block->ports( );\r
- std::string name = "";\r
- for(\r
- auto pIt = ports.begin( );\r
- pIt != ports.end( ) && name == "";\r
- ++pIt\r
- )\r
- if(\r
- ( *pIt )->portFlags( ) && QNEPort::NamePort == QNEPort::NamePort\r
- )\r
- name = ( *pIt )->portName( ).toStdString( );\r
- if( name == "" )\r
- return;\r
- TFilter* filter = this->m_Workspace->GetFilter( name );\r
- if( filter != NULL )\r
- {\r
- } // fi\r
- */\r
}\r
else if( port != NULL )\r
{\r
} // fi\r
}\r
break;\r
+ case Qt::RightButton:\r
+ {\r
+ QNEInputPort* in_port =\r
+ dynamic_cast< QNEInputPort* >( this->itemAt( evt->scenePos( ) ) );\r
+ QNEOutputPort* out_port =\r
+ dynamic_cast< QNEOutputPort* >( this->itemAt( evt->scenePos( ) ) );\r
+ if( in_port != NULL )\r
+ {\r
+ if( in_port->connection( ) == NULL )\r
+ {\r
+ this->m_Conn = new QNEConnection( 0, this->m_Scene );\r
+ this->m_Conn->setPort2( in_port );\r
+ this->m_Conn->setPos1( evt->scenePos( ) );\r
+ this->m_Conn->setPos2( in_port->scenePos( ) );\r
+ this->m_Conn->updatePath( );\r
+ return( true );\r
+\r
+ } // fi\r
+ }\r
+ else if( out_port != NULL )\r
+ {\r
+ this->m_Conn = new QNEConnection( 0, this->m_Scene );\r
+ this->m_Conn->setPort1( out_port );\r
+ this->m_Conn->setPos1( out_port->scenePos( ) );\r
+ this->m_Conn->setPos2( evt->scenePos( ) );\r
+ this->m_Conn->updatePath( );\r
+ return( true );\r
+\r
+ } // fi\r
+ }\r
+ break;\r
default:\r
break;\r
\r
this->m_Conn->updatePath( );\r
\r
this->m_Workspace->Connect(\r
- port1->block( )->namePort( )->name( ).toStdString( ),\r
- port2->block( )->namePort( )->name( ).toStdString( ),\r
+ port1->block( )->namePort( ).toStdString( ),\r
+ port2->block( )->namePort( ).toStdString( ),\r
port1->name( ).toStdString( ),\r
port2->name( ).toStdString( )\r
);\r
this->m_Graph->AddConnection(\r
- port1->block( )->namePort( )->name( ).toStdString( ),\r
- port2->block( )->namePort( )->name( ).toStdString( ),\r
+ port1->block( )->namePort( ).toStdString( ),\r
+ port2->block( )->namePort( ).toStdString( ),\r
this->m_Conn\r
);\r
\r
delete this->m_Conn;\r
this->m_Conn = NULL;\r
return( true );\r
+ }\r
+ else if( this->m_Conn != NULL && evt->button( ) == Qt::RightButton )\r
+ {\r
+ QNEOutputPort* port1 = this->m_Conn->port1( );\r
+ QNEInputPort* port2 = this->m_Conn->port2( );\r
+\r
+ if( port1 != NULL && port2 == NULL )\r
+ {\r
+ if(\r
+ dynamic_cast< QNEInputPort* >(\r
+ this->itemAt( evt->scenePos( ) )\r
+ ) == NULL\r
+ )\r
+ {\r
+ port2 = new QNEInputPort( NULL, this->m_Scene );\r
+ port2->setName( port1->name( ) );\r
+ port2->setPos( evt->scenePos( ) );\r
+ this->m_Conn->setPos2( evt->scenePos( ) );\r
+ this->m_Conn->setPort2( port2 );\r
+ this->m_Conn->updatePath( );\r
+ }\r
+ else\r
+ delete this->m_Conn;\r
+ this->m_Conn = NULL;\r
+ return( true );\r
+ }\r
+ else if( port1 == NULL && port2 != NULL )\r
+ {\r
+ if(\r
+ dynamic_cast< QNEOutputPort* >(\r
+ this->itemAt( evt->scenePos( ) )\r
+ ) == NULL\r
+ /*&&\r
+ port2->connection( ) == NULL*/\r
+ )\r
+ {\r
+ port1 = new QNEOutputPort( NULL, this->m_Scene );\r
+ port1->setName( port2->name( ) );\r
+ port1->setPos( evt->scenePos( ) );\r
+ this->m_Conn->setPos1( evt->scenePos( ) );\r
+ this->m_Conn->setPort1( port1 );\r
+ this->m_Conn->updatePath( );\r
+ }\r
+ else\r
+ delete this->m_Conn;\r
+ this->m_Conn = NULL;\r
+ return( true );\r
+\r
+ } // fi\r
\r
} // fi\r
\r
\r
std::string createFilter(\r
const std::string& filter,\r
- const QPointF& pnt = QPointF( )\r
+ const QPointF& pnt = QPointF( qreal( 0 ), qreal( 0 ) )\r
);\r
- void synchronizeBlockPositions( );\r
\r
void install( QGraphicsScene* s );\r
bool eventFilter( QObject* o, QEvent* e );\r
QList< QTreeWidgetItem* > items = tree->selectedItems( );
for( auto iIt = items.begin( ); iIt != items.end( ); ++iIt )
this->m_Editor->createFilter(
- ( *iIt )->text( 0 ).toStdString( ), event->pos( )
+ ( *iIt )->text( 0 ).toStdString( ), this->mapToScene( event->pos( ) )
);
}
return;
std::string fname = dlg.selectedFiles( ).at( 0 ).toStdString( );
- this->m_UI->Canvas->editor( )->synchronizeBlockPositions( );
std::string err = this->m_Workspace->SaveWorkspace( fname );
if( err != "" )
QMessageBox::critical(
{
const char* class_value = filter->Attribute( "class" );
const char* name_value = filter->Attribute( "name" );
- float viewX = float( 0 );
- float viewY = float( 0 );
+ float viewX = float( 0 ), viewY = float( 0 );
filter->QueryFloatAttribute( "ViewX", &viewX );
filter->QueryFloatAttribute( "ViewY", &viewY );
if( class_value != NULL && name_value != NULL )