From: Leonardo Florez-Valencia Date: Tue, 12 Jan 2016 23:52:46 +0000 (-0500) Subject: ... X-Git-Tag: v0.1~273 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=e3dc1dcc5279b279f0ed7e39ed87b902bab7778c;p=cpPlugins.git ... --- diff --git a/appli/cpPipelineEditor/QNEBlock.cxx b/appli/cpPipelineEditor/QNEBlock.cxx index 5d6f16c..2b7ed51 100644 --- a/appli/cpPipelineEditor/QNEBlock.cxx +++ b/appli/cpPipelineEditor/QNEBlock.cxx @@ -55,6 +55,22 @@ QNEBlock( TFilter* filter, QGraphicsItem* parent, QGraphicsScene* scene ) this->m_Width = this->m_HorzMargin; this->m_Height = this->m_VertMargin; + + // Configure names + this->setNamePort( this->m_Filter->GetName( ) ); + this->_setTypePort( this->m_Filter->GetClassName( ) ); + + // Add input ports + std::set< std::string > inputs; + this->m_Filter->GetInputsNames( inputs ); + for( auto iIt = inputs.begin( ); iIt != inputs.end( ); ++iIt ) + this->addInputPort( iIt->c_str( ) ); + + // Add output ports + std::set< std::string > outputs; + this->m_Filter->GetOutputsNames( outputs ); + for( auto oIt = outputs.begin( ); oIt != outputs.end( ); ++oIt ) + this->addOutputPort( oIt->c_str( ) ); } // ------------------------------------------------------------------------- @@ -75,75 +91,76 @@ setNamePort( const QString& txt ) } // ------------------------------------------------------------------------- -void PipelineEditor::QNEBlock:: -setTypePort( const QString& txt ) -{ - if( this->m_TypePort == NULL ) - this->m_TypePort = new QNETypePort( this ); - this->m_TypePort->setName( txt ); - this->_configPort( this->m_TypePort ); -} - -// ------------------------------------------------------------------------- -void PipelineEditor::QNEBlock:: +PipelineEditor::QNEInputPort* PipelineEditor::QNEBlock:: addInputPort( const QString& txt ) { QNEInputPort* ip = new QNEInputPort( this ); ip->setName( txt ); - this->m_InputPorts.push_back( ip ); + this->m_InputPorts[ txt.toStdString( ) ] = ip; this->_configPort( ip ); + return( ip ); } // ------------------------------------------------------------------------- -void PipelineEditor::QNEBlock:: +PipelineEditor::QNEOutputPort* PipelineEditor::QNEBlock:: addOutputPort( const QString& txt ) { QNEOutputPort* op = new QNEOutputPort( this ); op->setName( txt ); - this->m_OutputPorts.push_back( op ); + this->m_OutputPorts[ txt.toStdString( ) ] = op; this->_configPort( op ); + return( op ); } // ------------------------------------------------------------------------- -QVector< PipelineEditor::QNEPort* > PipelineEditor::QNEBlock:: -ports( ) +PipelineEditor::QNEInputPort* PipelineEditor::QNEBlock:: +inputPort( const QString& txt ) { - QVector< QNEPort* > res; - foreach( QGraphicsItem* i, this->childItems( ) ) - { - QNEPort* p = dynamic_cast< QNEPort* >( i ); - if( p != NULL ) - res.append( p ); - - } // rof - return( res ); + auto i = this->m_InputPorts.find( txt.toStdString( ) ); + if( i != this->m_InputPorts.end( ) ) + return( i->second ); + else + return( NULL ); } // ------------------------------------------------------------------------- -PipelineEditor::QNEBlock* PipelineEditor::QNEBlock:: -clone( ) +PipelineEditor::QNEOutputPort* PipelineEditor::QNEBlock:: +outputPort( const QString& txt ) { - QNEBlock* b = new QNEBlock( this->m_Filter, 0, this->scene( ) ); - foreach( QGraphicsItem* i, this->childItems( ) ) - { - QNENamePort* np = dynamic_cast< QNENamePort* >( i ); - if( np != NULL ) - b->setNamePort( np->name( ) ); - - QNETypePort* tp = dynamic_cast< QNETypePort* >( i ); - if( tp != NULL ) - b->setTypePort( tp->name( ) ); + auto o = this->m_OutputPorts.find( txt.toStdString( ) ); + if( o != this->m_OutputPorts.end( ) ) + return( o->second ); + else + return( NULL ); +} - QNEInputPort* ip = dynamic_cast< QNEInputPort* >( i ); - if( ip != NULL ) - b->addInputPort( ip->name( ) ); +// ------------------------------------------------------------------------- +const PipelineEditor::QNEInputPort* PipelineEditor::QNEBlock:: +inputPort( const QString& txt ) const +{ + auto i = this->m_InputPorts.find( txt.toStdString( ) ); + if( i != this->m_InputPorts.end( ) ) + return( i->second ); + else + return( NULL ); +} - QNEOutputPort* op = dynamic_cast< QNEOutputPort* >( i ); - if( op != NULL ) - b->addOutputPort( op->name( ) ); +// ------------------------------------------------------------------------- +const PipelineEditor::QNEOutputPort* PipelineEditor::QNEBlock:: +outputPort( const QString& txt ) const +{ + auto o = this->m_OutputPorts.find( txt.toStdString( ) ); + if( o != this->m_OutputPorts.end( ) ) + return( o->second ); + else + return( NULL ); +} - } // rof - return( b ); +// ------------------------------------------------------------------------- +const QString& PipelineEditor::QNEBlock:: +namePort( ) const +{ + return( this->m_NamePort->name( ) ); } // ------------------------------------------------------------------------- @@ -176,6 +193,16 @@ itemChange( GraphicsItemChange change, const QVariant& value ) return( value ); } +// ------------------------------------------------------------------------- +void PipelineEditor::QNEBlock:: +_setTypePort( const QString& txt ) +{ + if( this->m_TypePort == NULL ) + this->m_TypePort = new QNETypePort( this ); + this->m_TypePort->setName( txt ); + this->_configPort( this->m_TypePort ); +} + // ------------------------------------------------------------------------- void PipelineEditor::QNEBlock:: _configPort( QNEPort* port ) @@ -214,4 +241,15 @@ _configPort( QNEPort* port ) } // rof } +// ------------------------------------------------------------------------- +void PipelineEditor::QNEBlock:: +mouseReleaseEvent( QGraphicsSceneMouseEvent* evt ) +{ + if( this->m_Filter.IsNotNull( ) ) + this->m_Filter->SetViewCoords( + this->scenePos( ).x( ), this->scenePos( ).y( ) + ); + this->Superclass::mouseReleaseEvent( evt ); +} + // eof - $RCSfile$ diff --git a/appli/cpPipelineEditor/QNEBlock.h b/appli/cpPipelineEditor/QNEBlock.h index dfe5199..d1a398e 100644 --- a/appli/cpPipelineEditor/QNEBlock.h +++ b/appli/cpPipelineEditor/QNEBlock.h @@ -56,30 +56,15 @@ namespace PipelineEditor virtual ~QNEBlock( ); void setNamePort( const QString& txt ); - void setTypePort( const QString& txt ); - void addInputPort( const QString& txt ); - void addOutputPort( const QString& txt ); - QVector< QNEPort* > ports( ); - - inline QNENamePort* namePort( ) - { return( this->m_NamePort ); } - inline QNETypePort* typePort( ) - { return( this->m_TypePort ); } - inline QVector< QNEInputPort* >& inputPorts( ) - { return( this->m_InputPorts ); } - inline QVector< QNEOutputPort* >& outputPorts( ) - { return( this->m_OutputPorts ); } - - inline const QNENamePort* namePort( ) const - { return( this->m_NamePort ); } - inline const QNETypePort* typePort( ) const - { return( this->m_TypePort ); } - inline const QVector< QNEInputPort* >& inputPorts( ) const - { return( this->m_InputPorts ); } - inline const QVector< QNEOutputPort* >& outputPorts( ) const - { return( this->m_OutputPorts ); } - - QNEBlock* clone( ); + QNEInputPort* addInputPort( const QString& txt ); + QNEOutputPort* addOutputPort( const QString& txt ); + QNEInputPort* inputPort( const QString& txt ); + QNEOutputPort* outputPort( const QString& txt ); + + const QString& namePort( ) const; + const QNEInputPort* inputPort( const QString& txt ) const; + const QNEOutputPort* outputPort( const QString& txt ) const; + inline int type( ) const { return( this->Type ); } @@ -91,8 +76,11 @@ namespace PipelineEditor protected: QVariant itemChange( GraphicsItemChange change, const QVariant& value ); + void _setTypePort( const QString& txt ); void _configPort( QNEPort* port ); + virtual void mouseReleaseEvent( QGraphicsSceneMouseEvent* evt ); + private: int m_HorzMargin; int m_VertMargin; @@ -101,8 +89,8 @@ namespace PipelineEditor QNENamePort* m_NamePort; QNETypePort* m_TypePort; - QVector< QNEInputPort* > m_InputPorts; - QVector< QNEOutputPort* > m_OutputPorts; + std::map< std::string, QNEInputPort* > m_InputPorts; + std::map< std::string, QNEOutputPort* > m_OutputPorts; TFilter::Pointer m_Filter; }; diff --git a/appli/cpPipelineEditor/QNEConnection.cxx b/appli/cpPipelineEditor/QNEConnection.cxx index eb0f3bb..df84c81 100644 --- a/appli/cpPipelineEditor/QNEConnection.cxx +++ b/appli/cpPipelineEditor/QNEConnection.cxx @@ -47,13 +47,12 @@ QNEConnection( QGraphicsItem* parent, QGraphicsScene* scene ) PipelineEditor::QNEConnection:: ~QNEConnection( ) { - QNEOutputPort* op = dynamic_cast< QNEOutputPort* >( this->m_Port1 ); - if( op != NULL ) - op->connections( ).remove( op->connections( ).indexOf( this ) ); + if( this->m_Port1 != NULL ) + this->m_Port1->connections( ). + remove( this->m_Port1->connections( ).indexOf( this ) ); - QNEInputPort* ip = dynamic_cast< QNEInputPort* >( this->m_Port2 ); - if( ip != NULL ) - ip->setConnection( NULL ); + if( this->m_Port2 != NULL ) + this->m_Port2->setConnection( NULL ); } // ------------------------------------------------------------------------- @@ -72,28 +71,26 @@ setPos2( const QPointF& p ) // ------------------------------------------------------------------------- void PipelineEditor::QNEConnection:: -setPort1( QNEPort* p ) +setPort1( QNEOutputPort* p ) { - QNEOutputPort* op = dynamic_cast< QNEOutputPort* >( p ); - if( op != NULL ) + if( p != NULL ) { - op->connections( ).append( this ); - this->m_Port1 = op; + p->connections( ).append( this ); + this->m_Port1 = p; } // fi } // ------------------------------------------------------------------------- void PipelineEditor::QNEConnection:: -setPort2( QNEPort* p ) +setPort2( QNEInputPort* p ) { - QNEInputPort* ip = dynamic_cast< QNEInputPort* >( p ); - if( ip != NULL ) + if( p != NULL ) { - if( ip->connection( ) == NULL ) + if( p->connection( ) == NULL ) { - ip->setConnection( this ); - this->m_Port2 = ip; + p->setConnection( this ); + this->m_Port2 = p; } // fi @@ -125,14 +122,14 @@ updatePath( ) } // ------------------------------------------------------------------------- -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 ); diff --git a/appli/cpPipelineEditor/QNEConnection.h b/appli/cpPipelineEditor/QNEConnection.h index 7e5a12e..bbed7dd 100644 --- a/appli/cpPipelineEditor/QNEConnection.h +++ b/appli/cpPipelineEditor/QNEConnection.h @@ -31,7 +31,8 @@ namespace PipelineEditor { - class QNEPort; + class QNEInputPort; + class QNEOutputPort; /** */ @@ -50,12 +51,12 @@ namespace PipelineEditor void setPos1( const QPointF& p ); void setPos2( const QPointF& p ); - void setPort1( QNEPort* p ); - void setPort2( QNEPort* p ); + void setPort1( QNEOutputPort* p ); + void setPort2( QNEInputPort* p ); void updatePosFromPorts( ); void updatePath( ); - QNEPort* port1( ) const; - QNEPort* port2( ) const; + QNEOutputPort* port1( ) const; + QNEInputPort* port2( ) const; inline int type( ) const { return( this->Type ); } @@ -63,8 +64,8 @@ namespace PipelineEditor private: QPointF m_Pos1; QPointF m_Pos2; - QNEPort* m_Port1; - QNEPort* m_Port2; + QNEOutputPort* m_Port1; + QNEInputPort* m_Port2; }; } // ecapseman diff --git a/appli/cpPipelineEditor/QNodesEditor.cxx b/appli/cpPipelineEditor/QNodesEditor.cxx index 21008db..051adde 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 ) @@ -211,22 +170,8 @@ _CreateBlock( TFilter* f, const QPointF& pnt ) // Add block QNEBlock* b = new QNEBlock( f, 0, this->m_Scene ); - b->setNamePort( f->GetName( ) ); - b->setTypePort( f->GetClassName( ) ); 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( @@ -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 ) { @@ -463,6 +388,37 @@ eventFilter( QObject* o, QEvent* e ) } // 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 ) + { + 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; @@ -498,14 +454,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 +476,55 @@ 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 + /*&& + 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 ); + + } // fi } // fi diff --git a/appli/cpPipelineEditor/QNodesEditor.h b/appli/cpPipelineEditor/QNodesEditor.h index a47b6bf..f338d91 100644 --- a/appli/cpPipelineEditor/QNodesEditor.h +++ b/appli/cpPipelineEditor/QNodesEditor.h @@ -68,9 +68,8 @@ namespace PipelineEditor std::string createFilter( const std::string& filter, - const QPointF& pnt = QPointF( ) + const QPointF& pnt = QPointF( qreal( 0 ), qreal( 0 ) ) ); - void synchronizeBlockPositions( ); void install( QGraphicsScene* s ); bool eventFilter( QObject* o, QEvent* e ); diff --git a/appli/cpPipelineEditor/QNodesEditorCanvas.cxx b/appli/cpPipelineEditor/QNodesEditorCanvas.cxx index d253f78..e5d914f 100644 --- a/appli/cpPipelineEditor/QNodesEditorCanvas.cxx +++ b/appli/cpPipelineEditor/QNodesEditorCanvas.cxx @@ -104,7 +104,7 @@ dropEvent( QDropEvent* event ) QList< QTreeWidgetItem* > items = tree->selectedItems( ); for( auto iIt = items.begin( ); iIt != items.end( ); ++iIt ) this->m_Editor->createFilter( - ( *iIt )->text( 0 ).toStdString( ), event->pos( ) + ( *iIt )->text( 0 ).toStdString( ), this->mapToScene( event->pos( ) ) ); } diff --git a/appli/cpPipelineEditor/cpPipelineEditor.cxx b/appli/cpPipelineEditor/cpPipelineEditor.cxx index 088edbc..6bda2a7 100644 --- a/appli/cpPipelineEditor/cpPipelineEditor.cxx +++ b/appli/cpPipelineEditor/cpPipelineEditor.cxx @@ -243,7 +243,6 @@ _ActionSaveWorkspace( ) return; std::string fname = dlg.selectedFiles( ).at( 0 ).toStdString( ); - this->m_UI->Canvas->editor( )->synchronizeBlockPositions( ); std::string err = this->m_Workspace->SaveWorkspace( fname ); if( err != "" ) QMessageBox::critical( diff --git a/lib/cpPlugins/Interface/WorkspaceIO.cxx b/lib/cpPlugins/Interface/WorkspaceIO.cxx index ce81b86..7e7a2bd 100644 --- a/lib/cpPlugins/Interface/WorkspaceIO.cxx +++ b/lib/cpPlugins/Interface/WorkspaceIO.cxx @@ -20,8 +20,7 @@ LoadWorkspace( const std::string& fname ) { const char* class_value = filter->Attribute( "class" ); const char* name_value = filter->Attribute( "name" ); - float viewX = float( 0 ); - float viewY = float( 0 ); + float viewX = float( 0 ), viewY = float( 0 ); filter->QueryFloatAttribute( "ViewX", &viewX ); filter->QueryFloatAttribute( "ViewY", &viewY ); if( class_value != NULL && name_value != NULL )