X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=appli%2FcpPipelineEditor%2FQNodesEditor.cxx;h=99db8a6becab35b054a29b09592da756009c1df6;hb=f8c546490b7168b5c75d877bf66d27f83aa9412c;hp=6417636e44ff256c6d30cbee0ce3786b5814e228;hpb=94411ee4209d15d6d1cf25bb817675f76f7ea5c0;p=cpPlugins.git diff --git a/appli/cpPipelineEditor/QNodesEditor.cxx b/appli/cpPipelineEditor/QNodesEditor.cxx index 6417636..99db8a6 100644 --- a/appli/cpPipelineEditor/QNodesEditor.cxx +++ b/appli/cpPipelineEditor/QNodesEditor.cxx @@ -36,6 +36,7 @@ #include #include #include +#include #include "QNEPort.h" #include "QNEConnection.h" @@ -86,7 +87,7 @@ setWorkspace( TWorkspace* ws ) { this->_CreateBlock( dynamic_cast< TFilter* >( vIt->second.GetPointer( ) ), - QPointF( ) + QPointF( vIt->second->GetViewX( ), vIt->second->GetViewY( ) ) ); } // rof @@ -96,47 +97,25 @@ setWorkspace( TWorkspace* ws ) auto rIt_end = this->m_Workspace->GetGraph( )->EndEdgesRows( ); for( ; rIt != rIt_end; ++rIt ) { - if( !this->m_Graph->HasVertexIndex( rIt->first ) ) - continue; QNEBlock* orig = this->m_Graph->GetVertex( rIt->first ); - if( orig == NULL ) - continue; - QVector< QNEOutputPort* >& oPorts = orig->outputPorts( ); - auto cIt = rIt->second.begin( ); for( ; cIt != rIt->second.end( ); ++cIt ) { - if( !this->m_Graph->HasVertexIndex( cIt->first ) ) - continue; QNEBlock* dest = this->m_Graph->GetVertex( cIt->first ); - if( dest == NULL ) - continue; - QVector< QNEInputPort* >& iPorts = dest->inputPorts( ); - auto eIt = cIt->second.begin( ); for( ; eIt != cIt->second.end( ); ++eIt ) { - QNEOutputPort* op = NULL; - auto opIt = oPorts.begin( ); - for( ; opIt != oPorts.end( ) && op == NULL; ++opIt ) - if( ( *opIt )->name( ).toStdString( ) == eIt->first ) - op = *opIt; - - QNEInputPort* ip = NULL; - auto ipIt = iPorts.begin( ); - for( ; ipIt != iPorts.end( ) && ip == NULL; ++ipIt ) - if( ( *ipIt )->name( ).toStdString( ) == eIt->second ) - ip = *ipIt; - + QNEOutputPort* op = orig->outputPort( eIt->first.c_str( ) ); + QNEInputPort* ip = dest->inputPort( eIt->second.c_str( ) ); if( op == NULL || ip == NULL ) continue; - QNEConnection* conn = new QNEConnection( 0, this->m_Scene ); - conn->setPort1( op ); - conn->setPort2( ip ); - conn->updatePosFromPorts( ); - conn->updatePath( ); - this->m_Graph->AddConnection( rIt->first, cIt->first, conn ); + QNEConnection* c = new QNEConnection( 0, this->m_Scene ); + c->setPort1( op ); + c->setPort2( ip ); + c->updatePosFromPorts( ); + c->updatePath( ); + this->m_Graph->AddConnection( rIt->first, cIt->first, c ); } // rof @@ -190,22 +169,8 @@ _CreateBlock( TFilter* f, const QPointF& pnt ) return; // Add block - QNEBlock* b = new QNEBlock( 0, this->m_Scene ); - b->setNamePort( f->GetName( ) ); - b->setTypePort( f->GetClassName( ) ); - // TODO: b->setScenePos( pnt ); - - // Add input ports - std::set< std::string > inputs; - f->GetInputsNames( inputs ); - for( auto iIt = inputs.begin( ); iIt != inputs.end( ); ++iIt ) - b->addInputPort( iIt->c_str( ) ); - - // Add output ports - std::set< std::string > outputs; - f->GetOutputsNames( outputs ); - for( auto oIt = outputs.begin( ); oIt != outputs.end( ); ++oIt ) - b->addOutputPort( oIt->c_str( ) ); + QNEBlock* b = new QNEBlock( f, 0, this->m_Scene ); + b->setPos( pnt ); // Keep a trace of this visual graph this->m_Graph->SetVertex( f->GetName( ), b ); @@ -225,25 +190,34 @@ _DoubleClick( QGraphicsSceneMouseEvent* evt, QGraphicsItem* item ) if( block != NULL ) { - /* TODO - auto ports = block->ports( ); - std::string name = ""; - for( - auto pIt = ports.begin( ); - pIt != ports.end( ) && name == ""; - ++pIt - ) - if( - ( *pIt )->portFlags( ) && QNEPort::NamePort == QNEPort::NamePort - ) - name = ( *pIt )->portName( ).toStdString( ); - if( name == "" ) - return; - TFilter* filter = this->m_Workspace->GetFilter( name ); - if( filter != NULL ) - { - } // fi - */ + QString old_name = block->namePort( ); + bool ok; + QString new_name = + QInputDialog::getText( + dynamic_cast< QWidget* >( this->parent( ) ), + "Change filter name", + "Filter name:", + QLineEdit::Normal, + old_name, + &ok + ); + if( ok && !new_name.isEmpty( ) && old_name != new_name ) + { + ok = this->m_Graph->RenameVertex( + old_name.toStdString( ), + new_name.toStdString( ) + ); + if( ok ) + { + block->setNamePort( new_name ); + this->m_Workspace->GetGraph( )->RenameVertex( + old_name.toStdString( ), + new_name.toStdString( ) + ); + + } // fi + + } // fi } else if( port != NULL ) { @@ -381,7 +355,10 @@ eventFilter( QObject* o, QEvent* e ) { if( this->m_Conn ) { - this->m_Conn->setPos2( evt->scenePos( ) ); + if( this->m_Conn->port1( ) == NULL ) + this->m_Conn->setPos1( evt->scenePos( ) ); + else if( this->m_Conn->port2( ) == NULL ) + this->m_Conn->setPos2( evt->scenePos( ) ); this->m_Conn->updatePath( ); return( true ); @@ -403,10 +380,45 @@ eventFilter( QObject* o, QEvent* e ) QNEOutputPort* port = dynamic_cast< QNEOutputPort* >( this->itemAt( evt->scenePos( ) ) ); if( port != NULL ) + { + if( port->block( ) != NULL ) + { + this->m_Conn = new QNEConnection( 0, this->m_Scene ); + this->m_Conn->setPort1( port ); + this->m_Conn->setPos1( port->scenePos( ) ); + this->m_Conn->setPos2( evt->scenePos( ) ); + this->m_Conn->updatePath( ); + return( true ); + + } // fi + + } // fi + } + break; + case Qt::RightButton: + { + QNEInputPort* in_port = + dynamic_cast< QNEInputPort* >( this->itemAt( evt->scenePos( ) ) ); + QNEOutputPort* out_port = + dynamic_cast< QNEOutputPort* >( this->itemAt( evt->scenePos( ) ) ); + if( in_port != NULL ) + { + if( in_port->connection( ) == NULL && in_port->block( ) != NULL ) + { + this->m_Conn = new QNEConnection( 0, this->m_Scene ); + this->m_Conn->setPort2( in_port ); + this->m_Conn->setPos1( evt->scenePos( ) ); + this->m_Conn->setPos2( in_port->scenePos( ) ); + this->m_Conn->updatePath( ); + return( true ); + + } // fi + } + else if( out_port != NULL && out_port->block( ) != NULL ) { this->m_Conn = new QNEConnection( 0, this->m_Scene ); - this->m_Conn->setPort1( port ); - this->m_Conn->setPos1( port->scenePos( ) ); + this->m_Conn->setPort1( out_port ); + this->m_Conn->setPos1( out_port->scenePos( ) ); this->m_Conn->setPos2( evt->scenePos( ) ); this->m_Conn->updatePath( ); return( true ); @@ -449,14 +461,14 @@ eventFilter( QObject* o, QEvent* e ) this->m_Conn->updatePath( ); this->m_Workspace->Connect( - port1->block( )->namePort( )->name( ).toStdString( ), - port2->block( )->namePort( )->name( ).toStdString( ), + port1->block( )->namePort( ).toStdString( ), + port2->block( )->namePort( ).toStdString( ), port1->name( ).toStdString( ), port2->name( ).toStdString( ) ); this->m_Graph->AddConnection( - port1->block( )->namePort( )->name( ).toStdString( ), - port2->block( )->namePort( )->name( ).toStdString( ), + port1->block( )->namePort( ).toStdString( ), + port2->block( )->namePort( ).toStdString( ), this->m_Conn ); @@ -471,6 +483,53 @@ eventFilter( QObject* o, QEvent* e ) delete this->m_Conn; this->m_Conn = NULL; return( true ); + } + else if( this->m_Conn != NULL && evt->button( ) == Qt::RightButton ) + { + QNEOutputPort* port1 = this->m_Conn->port1( ); + QNEInputPort* port2 = this->m_Conn->port2( ); + + if( port1 != NULL && port2 == NULL ) + { + if( + dynamic_cast< QNEInputPort* >( + this->itemAt( evt->scenePos( ) ) + ) == NULL + ) + { + port2 = new QNEInputPort( NULL, this->m_Scene ); + port2->setName( port1->name( ) ); + port2->setPos( evt->scenePos( ) ); + this->m_Conn->setPos2( evt->scenePos( ) ); + this->m_Conn->setPort2( port2 ); + this->m_Conn->updatePath( ); + } + else + delete this->m_Conn; + this->m_Conn = NULL; + return( true ); + } + else if( port1 == NULL && port2 != NULL ) + { + if( + dynamic_cast< QNEOutputPort* >( + this->itemAt( evt->scenePos( ) ) + ) == NULL + ) + { + port1 = new QNEOutputPort( NULL, this->m_Scene ); + port1->setName( port2->name( ) ); + port1->setPos( evt->scenePos( ) ); + this->m_Conn->setPos1( evt->scenePos( ) ); + this->m_Conn->setPort1( port1 ); + this->m_Conn->updatePath( ); + } + else + delete this->m_Conn; + this->m_Conn = NULL; + return( true ); + + } // fi } // fi