X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=appli%2FcpPipelineEditor%2FQNodesEditor.cxx;h=46508ca6fb92cbfe69c34430d3e1e9260126e8d4;hb=c06908465eb6da50572779f423d1e2c9e03b68dd;hp=e026dda9d12f683e1cf9c495dbe9662ace367fd6;hpb=3f6669acc6485e724c4ff79620e4de0f8c26734c;p=cpPlugins.git diff --git a/appli/cpPipelineEditor/QNodesEditor.cxx b/appli/cpPipelineEditor/QNodesEditor.cxx index e026dda..46508ca 100644 --- a/appli/cpPipelineEditor/QNodesEditor.cxx +++ b/appli/cpPipelineEditor/QNodesEditor.cxx @@ -42,6 +42,20 @@ #include "QNEConnection.h" #include "QNEBlock.h" +// ------------------------------------------------------------------------- +#define PipelineEditor_QNodesEditor_Callback_SWITCH( E, e ) \ + case QEvent::E: \ + { \ + Q##E##Event* evt = dynamic_cast< Q##E##Event* >( e ); \ + if( evt != NULL ) \ + this->_##E##_cbk( evt ); \ + } \ + break + +// ------------------------------------------------------------------------- +#define PipelineEditor_QNodesEditor_Callback_CODE( E ) \ + void PipelineEditor::QNodesEditor::_##E##_cbk( Q##E##Event* evt ) + // ------------------------------------------------------------------------- PipelineEditor::QNodesEditor:: QNodesEditor( QObject* parent ) @@ -97,47 +111,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 +154,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,28 +183,15 @@ _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 ); } // ------------------------------------------------------------------------- +/* TODO void PipelineEditor::QNodesEditor:: _DoubleClick( QGraphicsSceneMouseEvent* evt, QGraphicsItem* item ) { @@ -245,7 +205,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 +224,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 +233,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 ) { @@ -302,7 +242,6 @@ _DoubleClick( QGraphicsSceneMouseEvent* evt, QGraphicsItem* item ) } // fi } break; - /* TODO: case Qt::RightButton: { } @@ -311,11 +250,11 @@ _DoubleClick( QGraphicsSceneMouseEvent* evt, QGraphicsItem* item ) { } break; - */ default: break; } // hctiws } + */ // ------------------------------------------------------------------------- bool PipelineEditor::QNodesEditor:: @@ -324,290 +263,334 @@ eventFilter( QObject* o, QEvent* e ) // Event type switch( int( e->type( ) ) ) { - case QEvent::GraphicsSceneContextMenu: - { - QGraphicsSceneContextMenuEvent* evt = - dynamic_cast< QGraphicsSceneContextMenuEvent* >( e ); - if( evt != NULL ) - { - } // fi - } - break; - case QEvent::GraphicsSceneDragEnter: - { - QGraphicsSceneDragDropEvent* evt = - dynamic_cast< QGraphicsSceneDragDropEvent* >( e ); - if( evt != NULL ) - { - } // fi - } - break; - case QEvent::GraphicsSceneDragLeave: - { - QGraphicsSceneDragDropEvent* evt = - dynamic_cast< QGraphicsSceneDragDropEvent* >( e ); - if( evt != NULL ) - { - } // fi - } - break; - case QEvent::GraphicsSceneDragMove: - { - QGraphicsSceneDragDropEvent* evt = - dynamic_cast< QGraphicsSceneDragDropEvent* >( e ); - if( evt != NULL ) - { - } // fi - } - break; - case QEvent::GraphicsSceneDrop: - { - QGraphicsSceneDragDropEvent* evt = - dynamic_cast< QGraphicsSceneDragDropEvent* >( e ); - if( evt != NULL ) - { - } // fi - } - break; - case QEvent::GraphicsSceneHelp: - { - QGraphicsSceneHelpEvent* evt = - dynamic_cast< QGraphicsSceneHelpEvent* >( e ); - if( evt != NULL ) - { - } // fi - } - break; - case QEvent::GraphicsSceneHoverEnter: - { - QGraphicsSceneHoverEvent* evt = - dynamic_cast< QGraphicsSceneHoverEvent* >( e ); - if( evt != NULL ) - { - } // fi - } - break; - case QEvent::GraphicsSceneHoverLeave: - { - QGraphicsSceneHoverEvent* evt = - dynamic_cast< QGraphicsSceneHoverEvent* >( e ); - if( evt != NULL ) - { - } // fi - } - break; - case QEvent::GraphicsSceneHoverMove: - { - QGraphicsSceneHoverEvent* evt = - dynamic_cast< QGraphicsSceneHoverEvent* >( e ); - if( evt != NULL ) - { - } // fi - } - break; - case QEvent::GraphicsSceneMouseDoubleClick: - { - QGraphicsSceneMouseEvent* evt = - dynamic_cast< QGraphicsSceneMouseEvent* >( e ); - if( evt != NULL ) - { - QGraphicsItem* item = this->itemAt( evt->scenePos( ) ); - if( item != NULL ) - { - this->_DoubleClick( evt, item ); - return( true ); + PipelineEditor_QNodesEditor_Callback_SWITCH( GraphicsSceneContextMenu, e ); + PipelineEditor_QNodesEditor_Callback_SWITCH( GraphicsSceneDragEnter, e ); + PipelineEditor_QNodesEditor_Callback_SWITCH( GraphicsSceneDragLeave, e ); + PipelineEditor_QNodesEditor_Callback_SWITCH( GraphicsSceneDragMove, e ); + PipelineEditor_QNodesEditor_Callback_SWITCH( GraphicsSceneDrop, e ); + PipelineEditor_QNodesEditor_Callback_SWITCH( GraphicsSceneHelp, e ); + PipelineEditor_QNodesEditor_Callback_SWITCH( GraphicsSceneHoverEnter, e ); + PipelineEditor_QNodesEditor_Callback_SWITCH( GraphicsSceneHoverLeave, e ); + PipelineEditor_QNodesEditor_Callback_SWITCH( GraphicsSceneHoverMove, e ); + PipelineEditor_QNodesEditor_Callback_SWITCH( GraphicsSceneMouseDoubleClick, e ); + PipelineEditor_QNodesEditor_Callback_SWITCH( GraphicsSceneMouseMove, e ); + PipelineEditor_QNodesEditor_Callback_SWITCH( GraphicsSceneMousePress, e ); + PipelineEditor_QNodesEditor_Callback_SWITCH( GraphicsSceneMouseRelease, e ); + PipelineEditor_QNodesEditor_Callback_SWITCH( GraphicsSceneMove, e ); + PipelineEditor_QNodesEditor_Callback_SWITCH( GraphicsSceneResize, e ); + PipelineEditor_QNodesEditor_Callback_SWITCH( GraphicsSceneWheel, e ); + default: + break; + } // hctiws - } // fi + return( this->Superclass::eventFilter( o, e ) ); +} - } // fi - } - break; - case QEvent::GraphicsSceneMouseMove: - { - QGraphicsSceneMouseEvent* evt = - dynamic_cast< QGraphicsSceneMouseEvent* >( e ); - if( evt != NULL ) - { - if( this->m_Conn ) - { - this->m_Conn->setPos2( evt->scenePos( ) ); - this->m_Conn->updatePath( ); - return( true ); +// ------------------------------------------------------------------------- +PipelineEditor_QNodesEditor_Callback_CODE( GraphicsSceneContextMenu ) +{ +} - } // fi +// ------------------------------------------------------------------------- +PipelineEditor_QNodesEditor_Callback_CODE( GraphicsSceneDragEnter ) +{ +} - } // fi - } - break; - case QEvent::GraphicsSceneMousePress: +// ------------------------------------------------------------------------- +PipelineEditor_QNodesEditor_Callback_CODE( GraphicsSceneDragLeave ) +{ +} + +// ------------------------------------------------------------------------- +PipelineEditor_QNodesEditor_Callback_CODE( GraphicsSceneDragMove ) +{ +} + +// ------------------------------------------------------------------------- +PipelineEditor_QNodesEditor_Callback_CODE( GraphicsSceneDrop ) +{ +} + +// ------------------------------------------------------------------------- +PipelineEditor_QNodesEditor_Callback_CODE( GraphicsSceneHelp ) +{ +} + +// ------------------------------------------------------------------------- +PipelineEditor_QNodesEditor_Callback_CODE( GraphicsSceneHoverEnter ) +{ +} + +// ------------------------------------------------------------------------- +PipelineEditor_QNodesEditor_Callback_CODE( GraphicsSceneHoverLeave ) +{ +} + +// ------------------------------------------------------------------------- +PipelineEditor_QNodesEditor_Callback_CODE( GraphicsSceneHoverMove ) +{ +} + +// ------------------------------------------------------------------------- +PipelineEditor_QNodesEditor_Callback_CODE( GraphicsSceneMouseDoubleClick ) +{ + QGraphicsItem* item = this->itemAt( evt->scenePos( ) ); + if( item == NULL ) + return; + + switch( evt->button( ) ) + { + case Qt::LeftButton: { - QGraphicsSceneMouseEvent* evt = - dynamic_cast< QGraphicsSceneMouseEvent* >( e ); - if( evt != NULL ) + QNEBlock* block = dynamic_cast< QNEBlock* >( item ); + QNEPort* port = dynamic_cast< QNEPort* >( item ); + QNEConnection* conn = dynamic_cast< QNEConnection* >( item ); + + if( block != NULL ) { - switch( evt->button( ) ) - { - case Qt::LeftButton: + 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 ) { - QNEOutputPort* port = - dynamic_cast< QNEOutputPort* >( this->itemAt( evt->scenePos( ) ) ); - if( port != NULL ) + ok = this->m_Graph->RenameVertex( + old_name.toStdString( ), + new_name.toStdString( ) + ); + if( ok ) { - 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 ); + block->setNamePort( new_name ); + this->m_Workspace->GetGraph( )->RenameVertex( + old_name.toStdString( ), + new_name.toStdString( ) + ); } // fi - } - break; - default: - break; - } // hctiws - - } // fi - } - break; - case QEvent::GraphicsSceneMouseRelease: - { - QGraphicsSceneMouseEvent* evt = - dynamic_cast< QGraphicsSceneMouseEvent* >( e ); - if( evt != NULL ) + } // fi + } + else if( port != NULL ) { - if( this->m_Conn != NULL && evt->button( ) == Qt::LeftButton ) + if( evt->modifiers( ) == Qt::ControlModifier ) { - QNEInputPort* port2 = - dynamic_cast< QNEInputPort* >( this->itemAt( evt->scenePos( ) ) ); - if( port2 != NULL ) + port->setExtend( !( port->isExtended( ) ) ); + QNEInputPort* in_port = dynamic_cast< QNEInputPort* >( port ); + QNEOutputPort* out_port = dynamic_cast< QNEOutputPort* >( port ); + if( port->isExtended( ) ) + { + if( in_port != NULL ) + { + this->m_Workspace->AddInputPort( + in_port->extendedName( ).toStdString( ), + in_port->block( )->namePort( ).toStdString( ), + in_port->name( ).toStdString( ) + ); + } + else if( out_port != NULL ) + { + } // fi + } + else { - QNEOutputPort* port1 = - dynamic_cast< QNEOutputPort* >( this->m_Conn->port1( ) ); - if( port1 != NULL ) + if( in_port != NULL ) { - if( - port1->block( ) != port2->block( ) && - !port2->hasConnection( ) && - !port1->isConnected( port2 ) - ) - { - this->m_Conn->setPos2( port2->scenePos( ) ); - this->m_Conn->setPort2( port2 ); - this->m_Conn->updatePath( ); - - this->m_Workspace->Connect( - port1->block( )->namePort( )->name( ).toStdString( ), - port2->block( )->namePort( )->name( ).toStdString( ), - port1->name( ).toStdString( ), - port2->name( ).toStdString( ) - ); - this->m_Graph->AddConnection( - port1->block( )->namePort( )->name( ).toStdString( ), - port2->block( )->namePort( )->name( ).toStdString( ), - this->m_Conn - ); - - this->m_Conn = NULL; - return( true ); - - } // fi + } + else if( out_port != NULL ) + { + } // fi + } // fi + this->m_Scene->update( ); + } + else if( evt->modifiers( ) == Qt::NoModifier ) + { + if( port->isExtended( ) ) + { + QString old_name = port->extendedName( ); + 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 ) + { + // TODO: port->setExtendedName( new_name ); + /* TODO + 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 } // fi - delete this->m_Conn; - this->m_Conn = NULL; - return( true ); } // fi - - } // fi - } - break; - case QEvent::GraphicsSceneMove: - { - QGraphicsSceneMoveEvent* evt = - dynamic_cast< QGraphicsSceneMoveEvent* >( e ); - if( evt != NULL ) + } + else if( conn != NULL ) { } // fi } break; - case QEvent::GraphicsSceneResize: + /* TODO: + case Qt::RightButton: + { + } + break; + case Qt::MiddleButton: + { + } + break; + */ + default: + break; + } // hctiws +} + +// ------------------------------------------------------------------------- +PipelineEditor_QNodesEditor_Callback_CODE( GraphicsSceneMouseMove ) +{ + if( this->m_Conn != NULL ) { - QGraphicsSceneResizeEvent* evt = - dynamic_cast< QGraphicsSceneResizeEvent* >( e ); - if( evt != NULL ) - { - } // fi - } - break; - case QEvent::GraphicsSceneWheel: + 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( ); + + } // fi +} + +// ------------------------------------------------------------------------- +PipelineEditor_QNodesEditor_Callback_CODE( GraphicsSceneMousePress ) +{ + QNEInputPort* in_port = + dynamic_cast< QNEInputPort* >( this->itemAt( evt->scenePos( ) ) ); + QNEOutputPort* out_port = + dynamic_cast< QNEOutputPort* >( this->itemAt( evt->scenePos( ) ) ); + if( in_port == NULL && out_port == NULL ) + return; + + switch( evt->button( ) ) { - QGraphicsSceneWheelEvent* evt = - dynamic_cast< QGraphicsSceneWheelEvent* >( e ); - if( evt != NULL ) + case Qt::LeftButton: + { + if( out_port != NULL ) { + if( out_port->block( ) != NULL ) + { + // Start new connection + this->m_Conn = new QNEConnection( 0, this->m_Scene ); + this->m_Conn->setPort1( out_port ); + this->m_Conn->setPos1( out_port->scenePos( ) ); + this->m_Conn->setPos2( evt->scenePos( ) ); + this->m_Conn->updatePosFromPorts( ); + this->m_Conn->updatePath( ); + + } // fi + } // fi } break; default: break; + } // hctiws +} + +// ------------------------------------------------------------------------- +PipelineEditor_QNodesEditor_Callback_CODE( GraphicsSceneMouseRelease ) +{ + if( this->m_Conn == NULL ) + return; - // Mouse event - /* - QGraphicsSceneMouseEvent* me = - dynamic_cast< QGraphicsSceneMouseEvent* >( e ); - if( me != NULL ) + switch( evt->button( ) ) + { + case Qt::LeftButton: + { + QNEInputPort* port2 = + dynamic_cast< QNEInputPort* >( this->itemAt( evt->scenePos( ) ) ); + if( port2 != NULL ) { - } // fi - */ + QNEOutputPort* port1 = + dynamic_cast< QNEOutputPort* >( this->m_Conn->port1( ) ); + if( port1 != NULL ) + { + if( + port1->block( ) != port2->block( ) && + !port2->hasConnection( ) && + !port1->isConnected( port2 ) && + !port2->isExtended( ) + ) + { + this->m_Conn->setPos2( port2->scenePos( ) ); + this->m_Conn->setPort2( port2 ); + this->m_Conn->updatePosFromPorts( ); + this->m_Conn->updatePath( ); - /* TODO - switch( ( int ) e->type( ) ) - { - case QEvent::GraphicsSceneMouseMove: - { - if( this->m_Conn ) - { - this->m_Conn->setPos2( me->scenePos( ) ); - this->m_Conn->updatePath( ); - return( true ); - } - break; - } - case QEvent::GraphicsSceneMouseRelease: - { - if( this->m_Conn && me->button( ) == Qt::LeftButton ) - { - QGraphicsItem* item = itemAt( me->scenePos( ) ); - if( item && item->type( ) == QNEPort::Type ) - { - QNEPort* port1 = this->m_Conn->port1( ); - QNEPort* port2 = ( QNEPort* ) item; - if( port1->block( ) != port2->block( ) && port1->isOutput( ) != port2->isOutput( ) && !port1->isConnected( port2 ) ) - { - this->m_Conn->setPos2( port2->scenePos( ) ); - this->m_Conn->setPort2( port2 ); - this->m_Conn->updatePath( ); - this->m_Conn = NULL; - return( true ); - } - } + this->m_Workspace->Connect( + port1->block( )->namePort( ).toStdString( ), + port2->block( )->namePort( ).toStdString( ), + port1->name( ).toStdString( ), + port2->name( ).toStdString( ) + ); + this->m_Graph->AddConnection( + port1->block( )->namePort( ).toStdString( ), + port2->block( )->namePort( ).toStdString( ), + this->m_Conn + ); + } + else + delete this->m_Conn; + } + else + delete this->m_Conn; + } + else + delete this->m_Conn; + this->m_Conn = NULL; + } + break; + default: + break; + } // hctisw +} - delete this->m_Conn; - this->m_Conn = NULL; - return( true ); - } - break; - } - } // hctiws - */ +// ------------------------------------------------------------------------- +PipelineEditor_QNodesEditor_Callback_CODE( GraphicsSceneMove ) +{ +} - return( this->Superclass::eventFilter( o, e ) ); +// ------------------------------------------------------------------------- +PipelineEditor_QNodesEditor_Callback_CODE( GraphicsSceneResize ) +{ +} + +// ------------------------------------------------------------------------- +PipelineEditor_QNodesEditor_Callback_CODE( GraphicsSceneWheel ) +{ } // eof - $RCSfile$