X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=appli%2FcpPipelineEditor%2FQNodesEditor.cxx;h=46508ca6fb92cbfe69c34430d3e1e9260126e8d4;hb=c06908465eb6da50572779f423d1e2c9e03b68dd;hp=051adde37951d18bb0b5294b46574e29f233f554;hpb=e3dc1dcc5279b279f0ed7e39ed87b902bab7778c;p=cpPlugins.git diff --git a/appli/cpPipelineEditor/QNodesEditor.cxx b/appli/cpPipelineEditor/QNodesEditor.cxx index 051adde..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 ) @@ -177,6 +191,7 @@ _CreateBlock( TFilter* f, const QPointF& pnt ) } // ------------------------------------------------------------------------- +/* TODO void PipelineEditor::QNodesEditor:: _DoubleClick( QGraphicsSceneMouseEvent* evt, QGraphicsItem* item ) { @@ -227,7 +242,6 @@ _DoubleClick( QGraphicsSceneMouseEvent* evt, QGraphicsItem* item ) } // fi } break; - /* TODO: case Qt::RightButton: { } @@ -236,11 +250,11 @@ _DoubleClick( QGraphicsSceneMouseEvent* evt, QGraphicsItem* item ) { } break; - */ default: break; } // hctiws } + */ // ------------------------------------------------------------------------- bool PipelineEditor::QNodesEditor:: @@ -249,370 +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; - case Qt::RightButton: + + } // fi + } + else if( port != NULL ) + { + if( evt->modifiers( ) == Qt::ControlModifier ) { - QNEInputPort* in_port = - dynamic_cast< QNEInputPort* >( this->itemAt( evt->scenePos( ) ) ); - QNEOutputPort* out_port = - dynamic_cast< QNEOutputPort* >( this->itemAt( evt->scenePos( ) ) ); - if( in_port != 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->connection( ) == NULL ) + 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 ) { - 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 ) - { - 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->updatePath( ); - return( true ); - - } // fi - } - break; - default: - break; - - } // hctiws - - } // fi - } - break; - case QEvent::GraphicsSceneMouseRelease: - { - QGraphicsSceneMouseEvent* evt = - dynamic_cast< QGraphicsSceneMouseEvent* >( e ); - if( evt != NULL ) - { - if( this->m_Conn != NULL && evt->button( ) == Qt::LeftButton ) - { - QNEInputPort* port2 = - dynamic_cast< QNEInputPort* >( this->itemAt( evt->scenePos( ) ) ); - if( port2 != NULL ) + else { - QNEOutputPort* port1 = - dynamic_cast< QNEOutputPort* >( this->m_Conn->port1( ) ); - if( port1 != NULL ) + if( in_port != NULL ) + { + } + else if( out_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( ).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 - ); - - this->m_Conn = NULL; - return( true ); - - } // fi - } // fi } // fi - delete this->m_Conn; - this->m_Conn = NULL; - return( true ); + this->m_Scene->update( ); } - else if( this->m_Conn != NULL && evt->button( ) == Qt::RightButton ) + else if( evt->modifiers( ) == Qt::NoModifier ) { - QNEOutputPort* port1 = this->m_Conn->port1( ); - QNEInputPort* port2 = this->m_Conn->port2( ); - - if( port1 != NULL && port2 == NULL ) + if( port->isExtended( ) ) { - if( - dynamic_cast< QNEInputPort* >( - this->itemAt( evt->scenePos( ) ) - ) == NULL - ) + 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 ) { - 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 - /*&& - port2->connection( ) == 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 ); + // 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 } // 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$