X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=appli%2FcpPipelineEditor%2FQNEConnection.cxx;h=c79bb7ed27e02d6b7c5d1af662d3a7671665ab71;hb=c06908465eb6da50572779f423d1e2c9e03b68dd;hp=42199fd0d0ef891934ea81501fbca10919cad8bc;hpb=9c75dcecf566cc567583caf4687ce523a2af586d;p=cpPlugins.git diff --git a/appli/cpPipelineEditor/QNEConnection.cxx b/appli/cpPipelineEditor/QNEConnection.cxx index 42199fd..c79bb7e 100644 --- a/appli/cpPipelineEditor/QNEConnection.cxx +++ b/appli/cpPipelineEditor/QNEConnection.cxx @@ -25,7 +25,6 @@ */ #include "QNEConnection.h" - #include "QNEPort.h" #include @@ -40,22 +39,20 @@ QNEConnection( QGraphicsItem* parent, QGraphicsScene* scene ) this->setPen( QPen( Qt::black, 2 ) ); this->setBrush( Qt::NoBrush ); this->setZValue( -1 ); - this->m_Port1 = 0; - this->m_Port2 = 0; + this->m_Port1 = NULL; + this->m_Port2 = NULL; } // ------------------------------------------------------------------------- PipelineEditor::QNEConnection:: ~QNEConnection( ) { - if ( this->m_Port1 ) - this->m_Port1->connections( ).remove( - this->m_Port1->connections( ).indexOf( this ) - ); - if ( this->m_Port2 ) - this->m_Port2->connections( ).remove( - this->m_Port2->connections( ).indexOf( this ) - ); + if( this->m_Port1 != NULL ) + this->m_Port1->connections( ). + remove( this->m_Port1->connections( ).indexOf( this ) ); + + if( this->m_Port2 != NULL ) + this->m_Port2->setConnection( NULL ); } // ------------------------------------------------------------------------- @@ -74,26 +71,44 @@ setPos2( const QPointF& p ) // ------------------------------------------------------------------------- void PipelineEditor::QNEConnection:: -setPort1( QNEPort* p ) +setPort1( QNEOutputPort* p ) { - this->m_Port1 = p; - this->m_Port1->connections( ).append( this ); + if( p != NULL ) + { + p->connections( ).append( this ); + this->m_Port1 = p; + + } // fi } // ------------------------------------------------------------------------- void PipelineEditor::QNEConnection:: -setPort2( QNEPort* p ) +setPort2( QNEInputPort* p ) { - this->m_Port2 = p; - this->m_Port2->connections( ).append( this ); + if( p != NULL ) + { + if( p->connection( ) == NULL ) + { + p->setConnection( this ); + this->m_Port2 = p; + + } // fi + + } // fi } // ------------------------------------------------------------------------- void PipelineEditor::QNEConnection:: updatePosFromPorts( ) { - this->m_Pos1 = this->m_Port1->scenePos( ); - this->m_Pos2 = this->m_Port2->scenePos( ); + if( this->m_Port1 != NULL ) + this->m_Pos1 = + this->m_Port1->scenePos( ) + + QPointF( this->m_Port1->radius( ), this->m_Port1->radius( ) ); + if( this->m_Port2 != NULL ) + this->m_Pos2 = + this->m_Port2->scenePos( ) + + QPointF( this->m_Port2->radius( ), this->m_Port2->radius( ) ); } // ------------------------------------------------------------------------- @@ -101,29 +116,26 @@ void PipelineEditor::QNEConnection:: updatePath( ) { QPainterPath p; - p.moveTo( this->m_Pos1 ); qreal dx = this->m_Pos2.x( ) - this->m_Pos1.x( ); qreal dy = this->m_Pos2.y( ) - this->m_Pos1.y( ); - - QPointF ctr1( this->m_Pos1.x( ) + dx * 0.25, this->m_Pos1.y( ) + dy * 0.1 ); - QPointF ctr2( this->m_Pos1.x( ) + dx * 0.75, this->m_Pos1.y( ) + dy * 0.9 ); - - p.cubicTo( ctr1, ctr2, this->m_Pos2 ); + QPointF c1( this->m_Pos1.x( ) + dx * 0.25, this->m_Pos1.y( ) + dy * 0.1 ); + QPointF c2( this->m_Pos1.x( ) + dx * 0.75, this->m_Pos1.y( ) + dy * 0.9 ); + p.cubicTo( c1, c2, this->m_Pos2 ); this->setPath( p ); } // ------------------------------------------------------------------------- -PipelineEditor::QNEPort* PipelineEditor::QNEConnection:: +PipelineEditor::QNEOutputPort* PipelineEditor::QNEConnection:: port1( ) const { return( this->m_Port1 ); } // ------------------------------------------------------------------------- -PipelineEditor::QNEPort* PipelineEditor::QNEConnection:: +PipelineEditor::QNEInputPort* PipelineEditor::QNEConnection:: port2( ) const { return( this->m_Port2 );