#include <QGraphicsSceneMoveEvent>\r
#include <QGraphicsSceneResizeEvent>\r
#include <QGraphicsSceneWheelEvent>\r
+#include <QInputDialog>\r
\r
#include "QNEPort.h"\r
#include "QNEConnection.h"\r
void PipelineEditor::QNodesEditor::\r
setWorkspace( TWorkspace* ws )\r
{\r
- if( this->m_Workspace == ws )\r
- return;\r
this->m_Workspace = ws;\r
this->m_Graph = TGraph::New( );\r
\r
{\r
this->_CreateBlock(\r
dynamic_cast< TFilter* >( vIt->second.GetPointer( ) ),\r
- QPointF( )\r
+ QPointF( vIt->second->GetViewX( ), vIt->second->GetViewY( ) )\r
);\r
\r
} // rof\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( NULL );\r
}\r
\r
-#include <iostream>\r
-\r
// -------------------------------------------------------------------------\r
void PipelineEditor::QNodesEditor::\r
_CreateBlock( TFilter* f, const QPointF& pnt )\r
return;\r
\r
// Add block\r
- QNEBlock* b = new QNEBlock( 0, this->m_Scene );\r
- b->setNamePort( f->GetName( ) );\r
- b->setTypePort( f->GetClassName( ).c_str( ) );\r
- // TODO: b->setScenePos( 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
+ QNEBlock* b = new QNEBlock( f, 0, this->m_Scene );\r
+ b->setPos( pnt );\r
\r
// Keep a trace of this visual graph\r
- this->m_Graph->InsertVertex( f->GetName( ), b );\r
+ this->m_Graph->SetVertex( f->GetName( ), b );\r
}\r
\r
// -------------------------------------------------------------------------\r
\r
if( block != NULL )\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
+ QString old_name = block->namePort( );\r
+ bool ok;\r
+ QString new_name =\r
+ QInputDialog::getText(\r
+ dynamic_cast< QWidget* >( this->parent( ) ),\r
+ "Change filter name",\r
+ "Filter name:",\r
+ QLineEdit::Normal,\r
+ old_name,\r
+ &ok\r
+ );\r
+ if( ok && !new_name.isEmpty( ) && old_name != new_name )\r
+ {\r
+ ok = this->m_Graph->RenameVertex(\r
+ old_name.toStdString( ),\r
+ new_name.toStdString( )\r
+ );\r
+ if( ok )\r
+ {\r
+ block->setNamePort( new_name );\r
+ this->m_Workspace->GetGraph( )->RenameVertex(\r
+ old_name.toStdString( ),\r
+ new_name.toStdString( )\r
+ );\r
+\r
+ } // fi\r
+\r
+ } // fi\r
}\r
else if( port != NULL )\r
{\r
{\r
if( this->m_Conn )\r
{\r
- this->m_Conn->setPos2( evt->scenePos( ) );\r
+ if( this->m_Conn->port1( ) == NULL )\r
+ this->m_Conn->setPos1( evt->scenePos( ) );\r
+ else if( this->m_Conn->port2( ) == NULL )\r
+ this->m_Conn->setPos2( evt->scenePos( ) );\r
this->m_Conn->updatePath( );\r
return( true );\r
\r
QNEOutputPort* port =\r
dynamic_cast< QNEOutputPort* >( this->itemAt( evt->scenePos( ) ) );\r
if( port != NULL )\r
+ {\r
+ if( port->block( ) != NULL )\r
+ {\r
+ this->m_Conn = new QNEConnection( 0, this->m_Scene );\r
+ this->m_Conn->setPort1( port );\r
+ this->m_Conn->setPos1( port->scenePos( ) );\r
+ this->m_Conn->setPos2( evt->scenePos( ) );\r
+ this->m_Conn->updatePath( );\r
+ return( true );\r
+\r
+ } // fi\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 && in_port->block( ) != 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 && out_port->block( ) != NULL )\r
{\r
this->m_Conn = new QNEConnection( 0, this->m_Scene );\r
- this->m_Conn->setPort1( port );\r
- this->m_Conn->setPos1( port->scenePos( ) );\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
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
+ {\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