X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=appli%2FcpPipelineEditor%2FQNodesEditor.cxx;h=99db8a6becab35b054a29b09592da756009c1df6;hb=f8c546490b7168b5c75d877bf66d27f83aa9412c;hp=e026dda9d12f683e1cf9c495dbe9662ace367fd6;hpb=3f6669acc6485e724c4ff79620e4de0f8c26734c;p=cpPlugins.git diff --git a/appli/cpPipelineEditor/QNodesEditor.cxx b/appli/cpPipelineEditor/QNodesEditor.cxx index e026dda..99db8a6 100644 --- a/appli/cpPipelineEditor/QNodesEditor.cxx +++ b/appli/cpPipelineEditor/QNodesEditor.cxx @@ -97,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 @@ -162,25 +140,6 @@ createFilter( const std::string& filter, const QPointF& pnt ) return( "" ); } -// ------------------------------------------------------------------------- -void PipelineEditor::QNodesEditor:: -synchronizeBlockPositions( ) -{ - auto bIt = this->m_Graph->BeginVertices( ); - auto fIt = this->m_Workspace->GetGraph( )->BeginVertices( ); - while( - bIt != this->m_Graph->EndVertices( ) && - fIt != this->m_Workspace->GetGraph( )->EndVertices( ) - ) - { - auto pos = bIt->second->scenePos( ); - fIt->second->SetViewCoords( pos.x( ), pos.y( ) ); - bIt++; - fIt++; - - } // elihw -} - // ------------------------------------------------------------------------- void PipelineEditor::QNodesEditor:: install( QGraphicsScene* s ) @@ -210,23 +169,9 @@ _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( ) ); + QNEBlock* b = new QNEBlock( f, 0, this->m_Scene ); b->setPos( 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( ) ); - // Keep a trace of this visual graph this->m_Graph->SetVertex( f->GetName( ), b ); } @@ -245,7 +190,7 @@ _DoubleClick( QGraphicsSceneMouseEvent* evt, QGraphicsItem* item ) if( block != NULL ) { - QString old_name = block->namePort( )->name( ); + QString old_name = block->namePort( ); bool ok; QString new_name = QInputDialog::getText( @@ -264,7 +209,7 @@ _DoubleClick( QGraphicsSceneMouseEvent* evt, QGraphicsItem* item ) ); if( ok ) { - block->namePort( )->setName( new_name ); + block->setNamePort( new_name ); this->m_Workspace->GetGraph( )->RenameVertex( old_name.toStdString( ), new_name.toStdString( ) @@ -273,26 +218,6 @@ _DoubleClick( QGraphicsSceneMouseEvent* evt, QGraphicsItem* item ) } // fi } // fi - - /* 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 - */ } else if( port != NULL ) { @@ -430,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 ); @@ -452,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 ); @@ -498,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 ); @@ -520,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