From: Leonardo Florez-Valencia Date: Sat, 2 Jan 2016 18:56:31 +0000 (-0500) Subject: More on graph editor X-Git-Tag: v0.1~279 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=f4aeff15ebb41183d4b89f41b29ec26043848722;p=cpPlugins.git More on graph editor --- diff --git a/appli/cpPipelineEditor/QNEBlock.cxx b/appli/cpPipelineEditor/QNEBlock.cxx index 0c6900d..071effc 100644 --- a/appli/cpPipelineEditor/QNEBlock.cxx +++ b/appli/cpPipelineEditor/QNEBlock.cxx @@ -39,15 +39,19 @@ PipelineEditor::QNEBlock:: QNEBlock( QGraphicsItem* parent, QGraphicsScene* scene ) : Superclass( parent, scene ), m_HorzMargin( 20 ), - m_VertMargin( 5 ) + m_VertMargin( 5 ), + m_NamePort( NULL ), + m_TypePort( NULL ) { QPainterPath p; p.addRoundedRect( -50, -15, 100, 30, 5, 5 ); + this->setPath( p ); this->setPen( QPen( Qt::darkGreen ) ); this->setBrush( Qt::green ); this->setFlag( QGraphicsItem::ItemIsMovable ); this->setFlag( QGraphicsItem::ItemIsSelectable ); + this->m_Width = this->m_HorzMargin; this->m_Height = this->m_VertMargin; } @@ -59,77 +63,85 @@ PipelineEditor::QNEBlock:: } // ------------------------------------------------------------------------- -PipelineEditor::QNEPort* PipelineEditor::QNEBlock:: -addPort( const QString& name, bool isOutput, int flags, int ptr ) +void PipelineEditor::QNEBlock:: +setNamePort( const QString& txt ) { - QNEPort* port = new QNEPort( this ); - port->setName( name ); - port->setIsOutput( isOutput ); - port->setNEBlock( this ); - port->setPortFlags( flags ); - port->setPtr( ptr ); - - QFontMetrics fm( this->scene( )->font( ) ); - int w = fm.width( name ); - int h = fm.height( ); - if( w > this->m_Width - this->m_HorzMargin ) - this->m_Width = w + this->m_HorzMargin; - this->m_Height += h; - - QPainterPath p; - p.addRoundedRect( - -this->m_Width / 2, - -this->m_Height / 2, - this->m_Width, - this->m_Height, 5, 5 - ); - this->setPath( p ); - - int y = -this->m_Height / 2 + this->m_VertMargin + port->radius( ); - foreach( QGraphicsItem* port_, children( ) ) - { - if( port_->type( ) != QNEPort::Type ) - continue; - - QNEPort* port = ( QNEPort* ) port_; - if( port->isOutput( ) ) - port->setPos( this->m_Width/2 + port->radius( ), y ); - else - port->setPos( -this->m_Width/2 - port->radius( ), y ); - y += h; - - } // rof - return( port ); + if( this->m_NamePort == NULL ) + this->m_NamePort = new QNENamePort( this ); + this->m_NamePort->setName( txt ); + this->_configPort( this->m_NamePort ); } // ------------------------------------------------------------------------- -PipelineEditor::QNEPort* PipelineEditor::QNEBlock:: -addInputPort( const QString& name ) +void PipelineEditor::QNEBlock:: +setTypePort( const QString& txt ) { - return( this->addPort( name, false ) ); + if( this->m_TypePort == NULL ) + this->m_TypePort = new QNETypePort( this ); + this->m_TypePort->setName( txt ); + this->_configPort( this->m_TypePort ); } // ------------------------------------------------------------------------- -PipelineEditor::QNEPort* PipelineEditor::QNEBlock:: -addOutputPort( const QString& name ) +void PipelineEditor::QNEBlock:: +addInputPort( const QString& txt ) { - return( this->addPort( name, true ) ); + QNEInputPort* ip = new QNEInputPort( this ); + ip->setName( txt ); + this->m_InputPorts.push_back( ip ); + this->_configPort( ip ); } // ------------------------------------------------------------------------- void PipelineEditor::QNEBlock:: -addInputPorts( const QStringList& names ) +addOutputPort( const QString& txt ) { - foreach( QString n, names ) - this->addInputPort( n ); + QNEOutputPort* op = new QNEOutputPort( this ); + op->setName( txt ); + this->m_OutputPorts.push_back( op ); + this->_configPort( op ); } // ------------------------------------------------------------------------- -void PipelineEditor::QNEBlock:: -addOutputPorts( const QStringList& names ) +QVector< PipelineEditor::QNEPort* > PipelineEditor::QNEBlock:: +ports( ) { - foreach( QString n, names ) - this->addOutputPort( n ); + QVector< QNEPort* > res; + foreach( QGraphicsItem* i, this->childItems( ) ) + { + QNEPort* p = dynamic_cast< QNEPort* >( i ); + if( p != NULL ) + res.append( p ); + + } // rof + return( res ); +} + +// ------------------------------------------------------------------------- +PipelineEditor::QNEBlock* PipelineEditor::QNEBlock:: +clone( ) +{ + QNEBlock* b = new QNEBlock( 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( ) ); + + QNEInputPort* ip = dynamic_cast< QNEInputPort* >( i ); + if( ip != NULL ) + b->addInputPort( ip->name( ) ); + + QNEOutputPort* op = dynamic_cast< QNEOutputPort* >( i ); + if( op != NULL ) + b->addOutputPort( op->name( ) ); + + } // rof + return( b ); } // ------------------------------------------------------------------------- @@ -156,48 +168,48 @@ paint( } // ------------------------------------------------------------------------- -PipelineEditor::QNEBlock* PipelineEditor::QNEBlock:: -clone( ) +QVariant PipelineEditor::QNEBlock:: +itemChange( GraphicsItemChange change, const QVariant& value ) { - QNEBlock* b = new QNEBlock( 0, this->scene( ) ); - - foreach( QGraphicsItem* port_, childItems( ) ) - { - if( port_->type( ) == QNEPort::Type ) - { - QNEPort* port = ( QNEPort* ) port_; - b->addPort( - port->portName( ), - port->isOutput( ), - port->portFlags( ), - port->ptr( ) - ); - - } // fi - - } // rof - return( b ); + return( value ); } // ------------------------------------------------------------------------- -QVector< PipelineEditor::QNEPort* > PipelineEditor::QNEBlock:: -ports( ) +void PipelineEditor::QNEBlock:: +_configPort( QNEPort* port ) { - QVector< PipelineEditor::QNEPort* > res; - foreach( QGraphicsItem* port_, childItems( ) ) + port->setBlock( this ); + + QFontMetrics fm( this->scene( )->font( ) ); + int w = fm.width( port->name( ) ); + int h = fm.height( ); + if( w > this->m_Width - this->m_HorzMargin ) + this->m_Width = w + this->m_HorzMargin; + this->m_Height += h; + + QPainterPath pth; + pth.addRoundedRect( + -this->m_Width / 2, + -this->m_Height / 2, + this->m_Width, + this->m_Height, 5, 5 + ); + this->setPath( pth ); + + int y = -this->m_Height / 2 + this->m_VertMargin + port->radius( ); + foreach( QGraphicsItem* i, this->children( ) ) { - if( port_->type( ) == QNEPort::Type ) - res.append( ( QNEPort* ) port_ ); + QNEPort* p = dynamic_cast< QNEPort* >( i ); + if( p == NULL ) + continue; - } // rof - return( res ); -} + if( dynamic_cast< QNEOutputPort* >( p ) != NULL ) + p->setPos( this->m_Width / 2 + port->radius( ), y ); + else + p->setPos( -this->m_Width / 2 - port->radius( ), y ); + y += h; -// ------------------------------------------------------------------------- -QVariant PipelineEditor::QNEBlock:: -itemChange( GraphicsItemChange change, const QVariant& value ) -{ - return( value ); + } // rof } // eof - $RCSfile$ diff --git a/appli/cpPipelineEditor/QNEBlock.h b/appli/cpPipelineEditor/QNEBlock.h index 524988a..6b591ac 100644 --- a/appli/cpPipelineEditor/QNEBlock.h +++ b/appli/cpPipelineEditor/QNEBlock.h @@ -32,6 +32,10 @@ namespace PipelineEditor { class QNEPort; + class QNENamePort; + class QNETypePort; + class QNEInputPort; + class QNEOutputPort; class QNEBlock : public QGraphicsPathItem @@ -41,37 +45,59 @@ namespace PipelineEditor typedef QGraphicsPathItem Superclass; public: - enum { Type = QGraphicsItem::UserType + 3 }; + enum { Type = QGraphicsItem::UserType + 6 }; QNEBlock( QGraphicsItem* parent = NULL, QGraphicsScene* scene = NULL ); virtual ~QNEBlock( ); - QNEPort* addPort( - const QString& name, bool isOutput, int flags = 0, int ptr = 0 - ); - QNEPort* addInputPort( const QString& name ); - QNEPort* addOutputPort( const QString& name ); - void addInputPorts( const QStringList& names ); - void addOutputPorts( const QStringList& names ); + 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( ); + inline int type( ) const + { return( this->Type ); } + void paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget ); - QNEBlock* clone( ); - QVector< QNEPort* > ports( ); - - int type( ) const - { return( this->Type ); } - + protected: QVariant itemChange( GraphicsItemChange change, const QVariant& value ); + void _configPort( QNEPort* port ); private: int m_HorzMargin; int m_VertMargin; int m_Width; int m_Height; + + QNENamePort* m_NamePort; + QNETypePort* m_TypePort; + QVector< QNEInputPort* > m_InputPorts; + QVector< QNEOutputPort* > m_OutputPorts; }; } // ecapseman diff --git a/appli/cpPipelineEditor/QNEConnection.cxx b/appli/cpPipelineEditor/QNEConnection.cxx index 42199fd..eb0f3bb 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,21 @@ 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 ) - ); + QNEOutputPort* op = dynamic_cast< QNEOutputPort* >( this->m_Port1 ); + if( op != NULL ) + op->connections( ).remove( op->connections( ).indexOf( this ) ); + + QNEInputPort* ip = dynamic_cast< QNEInputPort* >( this->m_Port2 ); + if( ip != NULL ) + ip->setConnection( NULL ); } // ------------------------------------------------------------------------- @@ -76,16 +74,30 @@ setPos2( const QPointF& p ) void PipelineEditor::QNEConnection:: setPort1( QNEPort* p ) { - this->m_Port1 = p; - this->m_Port1->connections( ).append( this ); + QNEOutputPort* op = dynamic_cast< QNEOutputPort* >( p ); + if( op != NULL ) + { + op->connections( ).append( this ); + this->m_Port1 = op; + + } // fi } // ------------------------------------------------------------------------- void PipelineEditor::QNEConnection:: setPort2( QNEPort* p ) { - this->m_Port2 = p; - this->m_Port2->connections( ).append( this ); + QNEInputPort* ip = dynamic_cast< QNEInputPort* >( p ); + if( ip != NULL ) + { + if( ip->connection( ) == NULL ) + { + ip->setConnection( this ); + this->m_Port2 = ip; + + } // fi + + } // fi } // ------------------------------------------------------------------------- @@ -101,16 +113,13 @@ 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 ); } diff --git a/appli/cpPipelineEditor/QNEConnection.h b/appli/cpPipelineEditor/QNEConnection.h index 54cdf84..7e5a12e 100644 --- a/appli/cpPipelineEditor/QNEConnection.h +++ b/appli/cpPipelineEditor/QNEConnection.h @@ -43,7 +43,7 @@ namespace PipelineEditor typedef QGraphicsPathItem Superclass; public: - enum { Type = QGraphicsItem::UserType + 2 }; + enum { Type = QGraphicsItem::UserType + 5 }; QNEConnection( QGraphicsItem* parent = 0, QGraphicsScene* scene = 0 ); virtual ~QNEConnection( ); @@ -57,7 +57,8 @@ namespace PipelineEditor QNEPort* port1( ) const; QNEPort* port2( ) const; - int type( ) const { return Type; } + inline int type( ) const + { return( this->Type ); } private: QPointF m_Pos1; diff --git a/appli/cpPipelineEditor/QNEPort.cxx b/appli/cpPipelineEditor/QNEPort.cxx index dbf4346..6aa653b 100644 --- a/appli/cpPipelineEditor/QNEPort.cxx +++ b/appli/cpPipelineEditor/QNEPort.cxx @@ -41,7 +41,7 @@ QNEPort( QGraphicsItem* parent, QGraphicsScene* scene ) this->m_Label = new QGraphicsTextItem( this ); QPainterPath p; - p.addEllipse( + p.addEllipse( -this->m_Radius, -this->m_Radius, 2 * this->m_Radius, 2 * this->m_Radius ); @@ -50,27 +50,24 @@ QNEPort( QGraphicsItem* parent, QGraphicsScene* scene ) this->setPen( QPen( Qt::darkRed ) ); this->setBrush( Qt::red ); this->setFlag( QGraphicsItem::ItemSendsScenePositionChanges ); - this->m_PortFlags = 0; } // ------------------------------------------------------------------------- PipelineEditor::QNEPort:: ~QNEPort( ) { - foreach( QNEConnection* conn, this->m_Connections ) - delete conn; } // ------------------------------------------------------------------------- void PipelineEditor::QNEPort:: -setNEBlock( QNEBlock *b ) +setBlock( QNEBlock* b ) { this->m_Block = b; } // ------------------------------------------------------------------------- void PipelineEditor::QNEPort:: -setName( const QString &n ) +setName( const QString& n ) { this->m_Name = n; this->m_Label->setPlainText( n ); @@ -78,100 +75,184 @@ setName( const QString &n ) // ------------------------------------------------------------------------- void PipelineEditor::QNEPort:: -setIsOutput( bool o ) +setPtr( quint64 p ) { - this->m_IsOutput = o; + this->m_Ptr = p; +} - QFontMetrics fm( this->scene( )->font( ) ); - QRect r = fm.boundingRect( this->m_Name ); +// ------------------------------------------------------------------------- +PipelineEditor::QNENamePort:: +QNENamePort( QGraphicsItem* parent, QGraphicsScene* scene ) + : Superclass( parent, scene ) +{ +} - int rm = this->m_Radius + this->m_Margin; - int h = -this->m_Label->boundingRect( ).height( ) / 2; - if( this->m_IsOutput ) - this->m_Label->setPos( - -rm - this->m_Label->boundingRect( ).width( ), h - ); - else - this->m_Label->setPos( rm, h ); +// ------------------------------------------------------------------------- +PipelineEditor::QNENamePort:: +~QNENamePort( ) +{ } // ------------------------------------------------------------------------- -int PipelineEditor::QNEPort:: -radius( ) +void PipelineEditor::QNENamePort:: +setName( const QString& n ) { - return( this->m_Radius ); + this->Superclass::setName( n ); + + QFont font( this->scene( )->font( ) ); + font.setBold( true ); + this->m_Label->setFont( font ); + this->setPath( QPainterPath( ) ); } // ------------------------------------------------------------------------- -bool PipelineEditor::QNEPort:: -isOutput( ) +bool PipelineEditor::QNENamePort:: +isConnected( QNEPort* other ) { - return( this->m_IsOutput ); + return( false ); } // ------------------------------------------------------------------------- -QVector< PipelineEditor::QNEConnection* >& PipelineEditor::QNEPort:: -connections( ) +PipelineEditor::QNETypePort:: +QNETypePort( QGraphicsItem* parent, QGraphicsScene* scene ) + : Superclass( parent, scene ) { - return( this->m_Connections ); } // ------------------------------------------------------------------------- -void PipelineEditor::QNEPort:: -setPortFlags( int f ) +PipelineEditor::QNETypePort:: +~QNETypePort( ) { - this->m_PortFlags = f; +} - if( this->m_PortFlags & Self::TypePort ) - { - QFont font( this->scene( )->font( ) ); - font.setItalic( true ); - this->m_Label->setFont( font ); - this->setPath( QPainterPath( ) ); - } - else if( this->m_PortFlags & Self::NamePort ) +// ------------------------------------------------------------------------- +void PipelineEditor::QNETypePort:: +setName( const QString& n ) +{ + this->Superclass::setName( n ); + + QFont font( this->scene( )->font( ) ); + font.setItalic( true ); + this->m_Label->setFont( font ); + this->setPath( QPainterPath( ) ); +} + +// ------------------------------------------------------------------------- +bool PipelineEditor::QNETypePort:: +isConnected( QNEPort* other ) +{ + return( false ); +} + +// ------------------------------------------------------------------------- +PipelineEditor::QNEInputPort:: +QNEInputPort( QGraphicsItem* parent, QGraphicsScene* scene ) + : Superclass( parent, scene ), + m_Connection( NULL ) +{ +} + +// ------------------------------------------------------------------------- +PipelineEditor::QNEInputPort:: +~QNEInputPort( ) +{ + if( this->m_Connection != NULL ) + delete this->m_Connection; +} + +// ------------------------------------------------------------------------- +void PipelineEditor::QNEInputPort:: +setName( const QString& n ) +{ + this->Superclass::setName( n ); + + QFontMetrics fm( this->scene( )->font( ) ); + QRect r = fm.boundingRect( this->m_Name ); + int rm = this->m_Radius + this->m_Margin; + int h = -this->m_Label->boundingRect( ).height( ) / 2; + this->m_Label->setPos( rm, h ); +} + +// ------------------------------------------------------------------------- +bool PipelineEditor::QNEInputPort:: +isConnected( QNEPort* other ) +{ + if( this->m_Connection != NULL ) + return( + this->m_Connection->port1( ) == other && + this->m_Connection->port2( ) == this + ); + else + return( false ); +} + +// ------------------------------------------------------------------------- +void PipelineEditor::QNEInputPort:: +setConnection( QNEConnection* c ) +{ + this->m_Connection = c; +} + +// ------------------------------------------------------------------------- +QVariant PipelineEditor::QNEInputPort:: +itemChange( GraphicsItemChange change, const QVariant& value ) +{ + if( change == ItemScenePositionHasChanged ) { - QFont font( this->scene( )->font( ) ); - font.setBold( true ); - this->m_Label->setFont( font ); - this->setPath( QPainterPath( ) ); + if( this->m_Connection != NULL ) + { + this->m_Connection->updatePosFromPorts( ); + this->m_Connection->updatePath( ); + + } // fi } // fi + return( value ); } // ------------------------------------------------------------------------- -PipelineEditor::QNEBlock* PipelineEditor::QNEPort:: -block( ) const +PipelineEditor::QNEOutputPort:: +QNEOutputPort( QGraphicsItem* parent, QGraphicsScene* scene ) + : Superclass( parent, scene ) { - return( this->m_Block ); } // ------------------------------------------------------------------------- -quint64 PipelineEditor::QNEPort:: -ptr( ) +PipelineEditor::QNEOutputPort:: +~QNEOutputPort( ) { - return( this->m_Ptr ); + foreach( QNEConnection* conn, this->m_Connections ) + delete conn; } // ------------------------------------------------------------------------- -void PipelineEditor::QNEPort:: -setPtr( quint64 p ) +void PipelineEditor::QNEOutputPort:: +setName( const QString& n ) { - this->m_Ptr = p; + this->Superclass::setName( n ); + + QFontMetrics fm( this->scene( )->font( ) ); + QRect r = fm.boundingRect( this->m_Name ); + int rm = this->m_Radius + this->m_Margin; + int h = -this->m_Label->boundingRect( ).height( ) / 2; + this->m_Label->setPos( + -rm - this->m_Label->boundingRect( ).width( ), h + ); } // ------------------------------------------------------------------------- -bool PipelineEditor::QNEPort:: +bool PipelineEditor::QNEOutputPort:: isConnected( QNEPort* other ) { - foreach( QNEConnection* conn, this->m_Connections ) - if( conn->port1( ) == other || conn->port2( ) == other ) - return( true ); - return( false ); + auto i = this->m_Connections.begin( ); + bool conn = false; + for( ; i != this->m_Connections.end( ) && !conn; ++i ) + conn |= ( ( *i )->port1( ) == this && ( *i )->port2( ) == other ); + return( conn ); } // ------------------------------------------------------------------------- -QVariant PipelineEditor::QNEPort:: +QVariant PipelineEditor::QNEOutputPort:: itemChange( GraphicsItemChange change, const QVariant& value ) { if( change == ItemScenePositionHasChanged ) diff --git a/appli/cpPipelineEditor/QNEPort.h b/appli/cpPipelineEditor/QNEPort.h index 1f445d0..383167b 100644 --- a/appli/cpPipelineEditor/QNEPort.h +++ b/appli/cpPipelineEditor/QNEPort.h @@ -44,45 +44,151 @@ namespace PipelineEditor typedef QGraphicsPathItem Superclass; enum { Type = QGraphicsItem::UserType + 1 }; - enum { NamePort = 1, TypePort = 2 }; public: - QNEPort( QGraphicsItem* parent = 0, QGraphicsScene* scene = NULL ); + QNEPort( QGraphicsItem* parent = NULL, QGraphicsScene* scene = NULL ); virtual ~QNEPort( ); - void setNEBlock( QNEBlock* b ); - void setName( const QString& n ); - void setIsOutput( bool o ); - int radius( ); - bool isOutput( ); - QVector< QNEConnection* >& connections( ); - void setPortFlags( int f ); + void setBlock( QNEBlock* b ); + inline QNEBlock* block( ) const + { return( this->m_Block ); } + + virtual void setName( const QString& n ); + inline const QString& name( ) const + { return( this->m_Name ); } - QNEBlock* block( ) const; - quint64 ptr( ); void setPtr( quint64 p ); - bool isConnected( QNEPort* other ); + inline quint64 ptr( ) + { return( this->m_Ptr ); } - inline const QString& portName( ) const - { return( this->m_Name ); } - inline int portFlags( ) const - { return( this->m_PortFlags ); } - int type( ) const + inline int radius( ) const + { return( this->m_Radius ); } + + virtual bool isConnected( QNEPort* other ) = 0; + inline int type( ) const { return( this->Type ); } protected: - QVariant itemChange( GraphicsItemChange change, const QVariant& value ); - - private: QNEBlock* m_Block; - QString m_Name; - bool m_IsOutput; + + QString m_Name; QGraphicsTextItem* m_Label; - int m_Radius; - int m_Margin; + int m_Radius; + int m_Margin; + quint64 m_Ptr; + }; + + /** + */ + class QNENamePort + : public QNEPort + { + public: + typedef QNENamePort Self; + typedef QNEPort Superclass; + + enum { Type = Superclass::Type + 1 }; + + public: + QNENamePort( QGraphicsItem* parent = NULL, QGraphicsScene* scene = NULL ); + virtual ~QNENamePort( ); + + virtual void setName( const QString& n ); + + virtual bool isConnected( QNEPort* other ); + inline int type( ) const + { return( this->Type ); } + }; + + /** + */ + class QNETypePort + : public QNEPort + { + public: + typedef QNETypePort Self; + typedef QNEPort Superclass; + + enum { Type = Superclass::Type + 2 }; + + public: + QNETypePort( QGraphicsItem* parent = NULL, QGraphicsScene* scene = NULL ); + virtual ~QNETypePort( ); + + virtual void setName( const QString& n ); + + virtual bool isConnected( QNEPort* other ); + inline int type( ) const + { return( this->Type ); } + }; + + /** + */ + class QNEInputPort + : public QNEPort + { + public: + typedef QNEInputPort Self; + typedef QNEPort Superclass; + + enum { Type = Superclass::Type + 3 }; + + public: + QNEInputPort( QGraphicsItem* parent = NULL, QGraphicsScene* scene = NULL ); + virtual ~QNEInputPort( ); + + virtual void setName( const QString& n ); + + virtual bool isConnected( QNEPort* other ); + inline int type( ) const + { return( this->Type ); } + + void setConnection( QNEConnection* c ); + inline QNEConnection* connection( ) + { return( this->m_Connection ); } + inline const QNEConnection* connection( ) const + { return( this->m_Connection ); } + inline bool hasConnection( ) const + { return( this->m_Connection != NULL ); } + + protected: + QVariant itemChange( GraphicsItemChange change, const QVariant& value ); + + protected: + QNEConnection* m_Connection; + }; + + /** + */ + class QNEOutputPort + : public QNEPort + { + public: + typedef QNEOutputPort Self; + typedef QNEPort Superclass; + + enum { Type = Superclass::Type + 4 }; + + public: + QNEOutputPort( QGraphicsItem* parent = NULL, QGraphicsScene* scene = NULL ); + virtual ~QNEOutputPort( ); + + virtual void setName( const QString& n ); + + virtual bool isConnected( QNEPort* other ); + inline int type( ) const + { return( this->Type ); } + + inline QVector< QNEConnection* >& connections( ) + { return( this->m_Connections ); } + inline const QVector< QNEConnection* >& connections( ) const + { return( this->m_Connections ); } + + protected: + QVariant itemChange( GraphicsItemChange change, const QVariant& value ); + + protected: QVector< QNEConnection* > m_Connections; - int m_PortFlags; - quint64 m_Ptr; }; } // ecapseman diff --git a/appli/cpPipelineEditor/QNodesEditor.cxx b/appli/cpPipelineEditor/QNodesEditor.cxx index 590f8df..039b45e 100644 --- a/appli/cpPipelineEditor/QNodesEditor.cxx +++ b/appli/cpPipelineEditor/QNodesEditor.cxx @@ -28,7 +28,14 @@ #include #include +#include +#include +#include +#include #include +#include +#include +#include #include "QNEPort.h" #include "QNEConnection.h" @@ -37,9 +44,10 @@ // ------------------------------------------------------------------------- PipelineEditor::QNodesEditor:: QNodesEditor( QObject* parent ) - : Superclass( parent ) + : Superclass( parent ), + m_Conn( NULL ), + m_Workspace( NULL ) { - this->m_Conn = NULL; } // ------------------------------------------------------------------------- @@ -48,6 +56,92 @@ PipelineEditor::QNodesEditor:: { } +// ------------------------------------------------------------------------- +PipelineEditor::QNodesEditor:: +TWorkspace* PipelineEditor::QNodesEditor:: +workspace( ) +{ + return( this->m_Workspace ); +} + +// ------------------------------------------------------------------------- +const PipelineEditor::QNodesEditor:: +TWorkspace* PipelineEditor::QNodesEditor:: +workspace( ) const +{ + return( this->m_Workspace ); +} + +// ------------------------------------------------------------------------- +void PipelineEditor::QNodesEditor:: +setWorkspace( TWorkspace* ws ) +{ + if( this->m_Workspace == ws ) + return; + this->m_Workspace = ws; + this->m_Graph = TGraph::New( ); + + /* TODO + QGraphicsScene* scene = this->scene( ); + // Add vertices and keep track of ports + std::map< std::string, std::map< std::string, QNEPort* > > + in_ports, out_ports; + auto vIt = this->m_Workspace->GetGraph( )->BeginVertices( ); + auto vIt_end = this->m_Workspace->GetGraph( )->EndVertices( ); + for( ; vIt != vIt_end; ++vIt ) + { + this->_createBlock( dynamic_cast< TFilter* >( vIt->second.GetPointer( ) ) ); + + } // rof + */ + + // Add edges + /* TODO + auto rIt = this->m_Workspace->GetGraph( )->BeginEdgesRows( ); + auto rIt_end = this->m_Workspace->GetGraph( )->EndEdgesRows( ); + for( ; rIt != rIt_end; ++rIt ) + { + auto cIt = rIt->second.begin( ); + for( ; cIt != rIt->second.end( ); ++cIt ) + { + auto eIt = cIt->second.begin( ); + for( ; eIt != cIt->second.end( ); ++eIt ) + { + QNEPort* p1 = out_ports[ rIt->first ][ eIt->first ]; + QNEPort* p2 = in_ports[ cIt->first ][ eIt->second ]; + if( p1 != NULL && p2 != NULL ) + { + QNEConnection* conn = new QNEConnection( 0, scene ); + conn->setPort1( p1 ); + conn->setPort2( p2 ); + this->m_Graph->AddConnection( rIt->first, cIt->first, conn ); + + } // fi + + } // rof + + } // rof + + } // rof + */ +} + +// ------------------------------------------------------------------------- +std::string PipelineEditor::QNodesEditor:: +createFilter( const std::string& filter, const QPointF& pnt ) +{ + std::string name = filter; + while( this->m_Workspace->HasFilter( name ) ) + name += std::string( "_" ); + if( this->m_Workspace->CreateFilter( filter, name ) ) + { + this->_CreateBlock( this->m_Workspace->GetFilter( name ), pnt ); + return( name ); + } + else + return( "" ); +} + // ------------------------------------------------------------------------- void PipelineEditor::QNodesEditor:: install( QGraphicsScene* s ) @@ -69,88 +163,384 @@ itemAt( const QPointF& pos ) return( NULL ); } +#include + +// ------------------------------------------------------------------------- +void PipelineEditor::QNodesEditor:: +_CreateBlock( TFilter* f, const QPointF& pnt ) +{ + if( f == NULL ) + return; + + // Add block + QNEBlock* b = new QNEBlock( 0, this->m_Scene ); + b->setNamePort( f->GetName( ) ); + b->setTypePort( f->GetClassName( ).c_str( ) ); + // TODO: b->setScenePos( 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->InsertVertex( f->GetName( ), b ); +} + +// ------------------------------------------------------------------------- +void PipelineEditor::QNodesEditor:: +_DoubleClick( QGraphicsSceneMouseEvent* evt, QGraphicsItem* item ) +{ + switch( evt->button( ) ) + { + case Qt::LeftButton: + { + QNEBlock* block = dynamic_cast< QNEBlock* >( item ); + QNEPort* port = dynamic_cast< QNEPort* >( item ); + QNEConnection* conn = dynamic_cast< QNEConnection* >( item ); + + if( block != NULL ) + { + /* 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 ) + { + } + else if( conn != NULL ) + { + } // fi + } + break; + /* TODO: + case Qt::RightButton: + { + } + break; + case Qt::MiddleButton: + { + } + break; + */ + default: + break; + } // hctiws +} + // ------------------------------------------------------------------------- bool PipelineEditor::QNodesEditor:: eventFilter( QObject* o, QEvent* e ) { - QGraphicsSceneMouseEvent* me = ( QGraphicsSceneMouseEvent* ) e; - - switch ( ( int ) e->type( ) ) + // Event type + switch( int( e->type( ) ) ) { - case QEvent::GraphicsSceneMousePress: + case QEvent::GraphicsSceneContextMenu: { - switch ( ( int ) me->button( ) ) + QGraphicsSceneContextMenuEvent* evt = + dynamic_cast< QGraphicsSceneContextMenuEvent* >( e ); + if( evt != NULL ) { - case Qt::LeftButton: + } // fi + } + break; + case QEvent::GraphicsSceneDragEnter: + { + QGraphicsSceneDragDropEvent* evt = + dynamic_cast< QGraphicsSceneDragDropEvent* >( e ); + if( evt != NULL ) { - QGraphicsItem* item = this->itemAt( me->scenePos( ) ); - if( item && item->type( ) == QNEPort::Type ) + } // 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->m_Conn = new QNEConnection( 0, this->m_Scene ); - this->m_Conn->setPort1( ( QNEPort* ) item ); - this->m_Conn->setPos1( item->scenePos( ) ); - this->m_Conn->setPos2( me->scenePos( ) ); - this->m_Conn->updatePath( ); - + this->_DoubleClick( evt, item ); return( true ); - } - else if( item && item->type( ) == QNEBlock::Type ) - { - /* if( selBlock ) - selBlock->setSelected( ); */ - // selBlock = ( QNEBlock* ) item; } // fi - break; - } - case Qt::RightButton: - { - QGraphicsItem* item = itemAt( me->scenePos( ) ); - if( item && ( item->type( ) == QNEConnection::Type || item->type( ) == QNEBlock::Type ) ) - delete item; - // if( selBlock == ( QNEBlock* ) item ) - // selBlock = 0; - break; - } - } + + } // fi } + break; case QEvent::GraphicsSceneMouseMove: { - if( this->m_Conn ) + QGraphicsSceneMouseEvent* evt = + dynamic_cast< QGraphicsSceneMouseEvent* >( e ); + if( evt != NULL ) { - this->m_Conn->setPos2( me->scenePos( ) ); - this->m_Conn->updatePath( ); - return( true ); - } - break; + if( this->m_Conn ) + { + this->m_Conn->setPos2( evt->scenePos( ) ); + this->m_Conn->updatePath( ); + return( true ); + + } // fi + + } // fi } - case QEvent::GraphicsSceneMouseRelease: + break; + case QEvent::GraphicsSceneMousePress: { - if( this->m_Conn && me->button( ) == Qt::LeftButton ) + QGraphicsSceneMouseEvent* evt = + dynamic_cast< QGraphicsSceneMouseEvent* >( e ); + if( evt != NULL ) { - QGraphicsItem* item = itemAt( me->scenePos( ) ); - if( item && item->type( ) == QNEPort::Type ) + switch( evt->button( ) ) { - QNEPort* port1 = this->m_Conn->port1( ); - QNEPort* port2 = ( QNEPort* ) item; - - if( port1->block( ) != port2->block( ) && port1->isOutput( ) != port2->isOutput( ) && !port1->isConnected( port2 ) ) + case Qt::LeftButton: + { + QNEOutputPort* port = + dynamic_cast< QNEOutputPort* >( this->itemAt( evt->scenePos( ) ) ); + if( port != NULL ) { - this->m_Conn->setPos2( port2->scenePos( ) ); - this->m_Conn->setPort2( port2 ); + 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( ); - this->m_Conn = NULL; return( true ); - } + + } // fi } + break; + default: + break; - delete this->m_Conn; - this->m_Conn = NULL; - return( true ); - } - 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 ) + { + QNEOutputPort* port1 = + dynamic_cast< QNEOutputPort* >( this->m_Conn->port1( ) ); + if( port1 != 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 + + } // 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 ) + { + } // fi } + break; + case QEvent::GraphicsSceneResize: + { + QGraphicsSceneResizeEvent* evt = + dynamic_cast< QGraphicsSceneResizeEvent* >( e ); + if( evt != NULL ) + { + } // fi + } + break; + case QEvent::GraphicsSceneWheel: + { + QGraphicsSceneWheelEvent* evt = + dynamic_cast< QGraphicsSceneWheelEvent* >( e ); + if( evt != NULL ) + { + } // fi + } + break; + default: + break; } // hctiws + + // Mouse event + /* + QGraphicsSceneMouseEvent* me = + dynamic_cast< QGraphicsSceneMouseEvent* >( e ); + if( me != NULL ) + { + } // fi + */ + + /* 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 ); + } + } + + delete this->m_Conn; + this->m_Conn = NULL; + return( true ); + } + break; + } + } // hctiws + */ + return( this->Superclass::eventFilter( o, e ) ); } diff --git a/appli/cpPipelineEditor/QNodesEditor.h b/appli/cpPipelineEditor/QNodesEditor.h index c2db807..e2dc37c 100644 --- a/appli/cpPipelineEditor/QNodesEditor.h +++ b/appli/cpPipelineEditor/QNodesEditor.h @@ -28,10 +28,13 @@ #define __PIPELINEEDITOR__QNODESEDITOR__H__ #include +#include +#include +#include class QGraphicsScene; +class QGraphicsSceneMouseEvent; class QGraphicsItem; -class QPointF; namespace PipelineEditor { @@ -49,20 +52,40 @@ namespace PipelineEditor typedef QNodesEditor Self; typedef QObject Superclass; + typedef cpPlugins::Interface::Workspace TWorkspace; + typedef TWorkspace::TFilter TFilter; + typedef + cpExtensions::DataStructures:: + Graph< QNEBlock*, QNEConnection*, std::string > TGraph; + public: explicit QNodesEditor( QObject* parent = 0 ); virtual ~QNodesEditor( ); - void install( QGraphicsScene* s ); + TWorkspace* workspace( ); + const TWorkspace* workspace( ) const; + void setWorkspace( TWorkspace* ws ); + + std::string createFilter( + const std::string& filter, + const QPointF& pnt = QPointF( ) + ); + void install( QGraphicsScene* s ); bool eventFilter( QObject* o, QEvent* e ); private: QGraphicsItem* itemAt( const QPointF& pos ); + inline void _CreateBlock( TFilter* f, const QPointF& pnt ); + inline void _DoubleClick( QGraphicsSceneMouseEvent* evt, QGraphicsItem* item ); + private: QGraphicsScene* m_Scene; QNEConnection* m_Conn; + + TWorkspace* m_Workspace; + TGraph::Pointer m_Graph; }; } // ecapseman diff --git a/appli/cpPipelineEditor/QNodesEditorCanvas.cxx b/appli/cpPipelineEditor/QNodesEditorCanvas.cxx index afb5b62..d253f78 100644 --- a/appli/cpPipelineEditor/QNodesEditorCanvas.cxx +++ b/appli/cpPipelineEditor/QNodesEditorCanvas.cxx @@ -11,8 +11,7 @@ // ------------------------------------------------------------------------- PipelineEditor::QNodesEditorCanvas:: QNodesEditorCanvas( QWidget* parent ) - : QGraphicsView( parent ), - m_Workspace( NULL ) + : QGraphicsView( parent ) { QGraphicsScene* scene = new QGraphicsScene( this ); this->setScene( scene ); @@ -30,73 +29,19 @@ PipelineEditor::QNodesEditorCanvas:: } // ------------------------------------------------------------------------- -PipelineEditor::QNodesEditorCanvas:: -TWorkspace* PipelineEditor::QNodesEditorCanvas:: -workspace( ) -{ - return( this->m_Workspace ); -} - -// ------------------------------------------------------------------------- -const PipelineEditor::QNodesEditorCanvas:: -TWorkspace* PipelineEditor::QNodesEditorCanvas:: -workspace( ) const +PipelineEditor:: +QNodesEditor* PipelineEditor::QNodesEditorCanvas:: +editor( ) { - return( this->m_Workspace ); + return( this->m_Editor ); } // ------------------------------------------------------------------------- -void PipelineEditor::QNodesEditorCanvas:: -setWorkspace( TWorkspace* ws ) +const PipelineEditor:: +QNodesEditor* PipelineEditor::QNodesEditorCanvas:: +editor( ) const { - if( this->m_Workspace == ws ) - return; - this->m_Workspace = ws; - this->m_Graph = TGraph::New( ); - - /* TODO - QGraphicsScene* scene = this->scene( ); - // Add vertices and keep track of ports - std::map< std::string, std::map< std::string, QNEPort* > > - in_ports, out_ports; - auto vIt = this->m_Workspace->GetGraph( )->BeginVertices( ); - auto vIt_end = this->m_Workspace->GetGraph( )->EndVertices( ); - for( ; vIt != vIt_end; ++vIt ) - { - this->_createBlock( dynamic_cast< TFilter* >( vIt->second.GetPointer( ) ) ); - - } // rof - */ - - // Add edges - /* TODO - auto rIt = this->m_Workspace->GetGraph( )->BeginEdgesRows( ); - auto rIt_end = this->m_Workspace->GetGraph( )->EndEdgesRows( ); - for( ; rIt != rIt_end; ++rIt ) - { - auto cIt = rIt->second.begin( ); - for( ; cIt != rIt->second.end( ); ++cIt ) - { - auto eIt = cIt->second.begin( ); - for( ; eIt != cIt->second.end( ); ++eIt ) - { - QNEPort* p1 = out_ports[ rIt->first ][ eIt->first ]; - QNEPort* p2 = in_ports[ cIt->first ][ eIt->second ]; - if( p1 != NULL && p2 != NULL ) - { - QNEConnection* conn = new QNEConnection( 0, scene ); - conn->setPort1( p1 ); - conn->setPort2( p2 ); - this->m_Graph->AddConnection( rIt->first, cIt->first, conn ); - - } // fi - - } // rof - - } // rof - - } // rof - */ + return( this->m_Editor ); } // ------------------------------------------------------------------------- @@ -147,8 +92,6 @@ dragMoveEvent( QDragMoveEvent* event ) void PipelineEditor::QNodesEditorCanvas:: dropEvent( QDropEvent* event ) { - if( this->m_Workspace == NULL ) - return; const QMimeData* mime = event->mimeData( ); if( !( mime->hasFormat( "application/x-qabstractitemmodeldatalist" ) ) ) return; @@ -160,15 +103,9 @@ dropEvent( QDropEvent* event ) QList< QTreeWidgetItem* > items = tree->selectedItems( ); for( auto iIt = items.begin( ); iIt != items.end( ); ++iIt ) - { - std::string filter = ( *iIt )->text( 0 ).toStdString( ); - std::string name = filter; - while( this->m_Workspace->HasFilter( name ) ) - name += std::string( "_" ); - if( this->m_Workspace->CreateFilter( filter, name ) ) - this->_createBlock( this->m_Workspace->GetFilter( name ) ); - - } // rof + this->m_Editor->createFilter( + ( *iIt )->text( 0 ).toStdString( ), event->pos( ) + ); } // ------------------------------------------------------------------------- @@ -185,6 +122,7 @@ _scaleView( qreal scaleFactor ) } // ------------------------------------------------------------------------- + /* void PipelineEditor::QNodesEditorCanvas:: _createBlock( TFilter* f ) { @@ -214,7 +152,6 @@ _createBlock( TFilter* f ) this->m_Graph->InsertVertex( f->GetName( ), b ); // Add vertices and keep track of ports - /* std::map< std::string, std::map< std::string, QNEPort* > > in_ports, out_ports; auto vIt = this->m_Workspace->GetGraph( )->BeginVertices( ); @@ -247,8 +184,8 @@ _createBlock( TFilter* f ) this->m_Graph->InsertVertex( vIt->first, b ); } // rof - */ } + */ // eof - $RCSfile$ diff --git a/appli/cpPipelineEditor/QNodesEditorCanvas.h b/appli/cpPipelineEditor/QNodesEditorCanvas.h index 03380d1..2fec183 100644 --- a/appli/cpPipelineEditor/QNodesEditorCanvas.h +++ b/appli/cpPipelineEditor/QNodesEditorCanvas.h @@ -2,8 +2,6 @@ #define __PIPELINEEDITOR__QNODESEDITORCANVAS__H__ #include -#include -#include namespace PipelineEditor { @@ -19,20 +17,12 @@ namespace PipelineEditor { Q_OBJECT; - public: - typedef cpPlugins::Interface::Workspace TWorkspace; - typedef TWorkspace::TFilter TFilter; - typedef - cpExtensions::DataStructures:: - Graph< QNEBlock*, QNEConnection*, std::string > TGraph; - public: QNodesEditorCanvas( QWidget* parent = 0 ); virtual ~QNodesEditorCanvas( ); - TWorkspace* workspace( ); - const TWorkspace* workspace( ) const; - void setWorkspace( TWorkspace* ws ); + QNodesEditor* editor( ); + const QNodesEditor* editor( ) const; protected: /* TODO @@ -47,12 +37,9 @@ namespace PipelineEditor void dropEvent( QDropEvent* event ); void _scaleView( qreal scaleFactor ); - void _createBlock( TFilter* f ); protected: - TWorkspace* m_Workspace; QNodesEditor* m_Editor; - TGraph::Pointer m_Graph; }; } // ecapseman diff --git a/appli/cpPipelineEditor/cpPipelineEditor.cxx b/appli/cpPipelineEditor/cpPipelineEditor.cxx index 8d838b8..872b4f4 100644 --- a/appli/cpPipelineEditor/cpPipelineEditor.cxx +++ b/appli/cpPipelineEditor/cpPipelineEditor.cxx @@ -1,6 +1,8 @@ #include "cpPipelineEditor.h" #include "ui_cpPipelineEditor.h" +#include "QNodesEditor.h" + #include #include #include @@ -32,6 +34,7 @@ cpPipelineEditor( QWidget* parent ) cpPipelineEditor_ConnectButton( LoadPluginsFile ); cpPipelineEditor_ConnectButton( LoadPluginsPath ); cpPipelineEditor_ConnectAction( OpenWorkspace ); + cpPipelineEditor_ConnectAction( SaveWorkspace ); } // ------------------------------------------------------------------------- @@ -136,7 +139,7 @@ _ButtonLoadPluginsFile( ) ); // Update view - this->m_UI->Canvas->setWorkspace( this->m_Workspace ); + this->m_UI->Canvas->editor( )->setWorkspace( this->m_Workspace ); this->_UpdateLoadedPlugins( ); } @@ -164,7 +167,7 @@ _ButtonLoadPluginsPath( ) ); // Update view - this->m_UI->Canvas->setWorkspace( this->m_Workspace ); + this->m_UI->Canvas->editor( )->setWorkspace( this->m_Workspace ); this->_UpdateLoadedPlugins( ); } @@ -189,7 +192,7 @@ _ActionOpenWorkspace( ) std::string err = this->m_Workspace->LoadWorkspace( fname ); if( err == "" ) { - this->m_UI->Canvas->setWorkspace( this->m_Workspace ); + this->m_UI->Canvas->editor( )->setWorkspace( this->m_Workspace ); } else { @@ -204,4 +207,32 @@ _ActionOpenWorkspace( ) } // fi } +// ------------------------------------------------------------------------- +void cpPipelineEditor:: +_ActionSaveWorkspace( ) +{ + if( this->m_Workspace == NULL ) + return; + + QFileDialog dlg( this ); + dlg.setFileMode( QFileDialog::AnyFile ); + dlg.setDirectory( "." ); + dlg.setAcceptMode( QFileDialog::AcceptSave ); + dlg.setNameFilter( + QFileDialog::tr( "Workspace file (*.xml);;All files (*)" ) + ); + dlg.setDefaultSuffix( QFileDialog::tr( "xml" ) ); + if( !( dlg.exec( ) ) ) + return; + std::string fname = dlg.selectedFiles( ).at( 0 ).toStdString( ); + + std::string err = this->m_Workspace->SaveWorkspace( fname ); + if( err != "" ) + QMessageBox::critical( + this, + QMessageBox::tr( "Error saving workspace" ), + QMessageBox::tr( err.c_str( ) ) + ); +} + // eof - $RCSfile$ diff --git a/appli/cpPipelineEditor/cpPipelineEditor.h b/appli/cpPipelineEditor/cpPipelineEditor.h index 5180dd1..7192268 100644 --- a/appli/cpPipelineEditor/cpPipelineEditor.h +++ b/appli/cpPipelineEditor/cpPipelineEditor.h @@ -40,6 +40,7 @@ protected slots: void _ButtonLoadPluginsFile( ); void _ButtonLoadPluginsPath( ); void _ActionOpenWorkspace( ); + void _ActionSaveWorkspace( ); private: Ui::cpPipelineEditor* m_UI; diff --git a/lib/cpPlugins/Interface/Parameters.cxx b/lib/cpPlugins/Interface/Parameters.cxx index 4a05b4f..e584b5e 100644 --- a/lib/cpPlugins/Interface/Parameters.cxx +++ b/lib/cpPlugins/Interface/Parameters.cxx @@ -163,12 +163,12 @@ cpPlugins_Parameters_Has( Choices ); // ------------------------------------------------------------------------- cpPlugins::Interface::Parameters:: TString cpPlugins::Interface::Parameters:: -GetString( const TString& name ) const +GetString( const TString& name, bool force ) const { TParameters::const_iterator i = this->m_Parameters.find( name ); if( i != this->m_Parameters.end( ) ) { - if( i->second.first == Self::String ) + if( i->second.first == Self::String || !force ) return( i->second.second.second ); } // fi @@ -364,12 +364,12 @@ GetSelectedChoice( const TString& name ) const // ------------------------------------------------------------------------- void cpPlugins::Interface::Parameters:: -SetString( const TString& name, const TString& v ) +SetString( const TString& name, const TString& v, bool force ) { TParameters::iterator i = this->m_Parameters.find( name ); if( i == this->m_Parameters.end( ) ) return; - if( i->second.first != Self::String ) + if( i->second.first != Self::String && force ) return; i->second.second.second = v; this->Modified( ); diff --git a/lib/cpPlugins/Interface/Parameters.h b/lib/cpPlugins/Interface/Parameters.h index 56cb5fd..9c97639 100644 --- a/lib/cpPlugins/Interface/Parameters.h +++ b/lib/cpPlugins/Interface/Parameters.h @@ -117,7 +117,7 @@ namespace cpPlugins bool HasVectorList( const TString& name ) const; bool HasChoices( const TString& name ) const; - TString GetString( const TString& name ) const; + TString GetString( const TString& name, bool force = true ) const; TBool GetBool( const TString& name ) const; TInt GetInt( const TString& name ) const; TUint GetUint( const TString& name ) const; @@ -165,7 +165,9 @@ namespace cpPlugins ) const; // Set methods - void SetString( const TString& name, const TString& v ); + void SetString( + const TString& name, const TString& v, bool force = true + ); void SetBool( const TString& name, const TBool& v ); void SetInt( const TString& name, const TInt& v ); void SetUint( const TString& name, const TUint& v ); diff --git a/lib/cpPlugins/Interface/WorkspaceIO.cxx b/lib/cpPlugins/Interface/WorkspaceIO.cxx index e14a44e..b623ad9 100644 --- a/lib/cpPlugins/Interface/WorkspaceIO.cxx +++ b/lib/cpPlugins/Interface/WorkspaceIO.cxx @@ -260,6 +260,57 @@ SaveWorkspace( const std::string& fname ) const auto data = dynamic_cast< TData* >( vIt->second.GetPointer( ) ); if( filter != NULL ) { + TiXmlElement* e = new TiXmlElement( "filter" ); + e->SetAttribute( "class", filter->GetClassName( ).c_str( ) ); + e->SetAttribute( "name", filter->GetName( ) ); + + const TParameters* params = filter->GetParameters( ); + std::vector< std::string > names; + params->GetNames( names ); + for( auto nIt = names.begin( ); nIt != names.end( ); ++nIt ) + { + TiXmlElement* p = new TiXmlElement( "parameter" ); + p->SetAttribute( "name", nIt->c_str( ) ); + //const char* param_type = param->Attribute( "type" ); + if( params->HasString( *nIt ) ) + p->SetAttribute( "type", "String" ); + else if( params->HasBool( *nIt ) ) + p->SetAttribute( "type", "Bool" ); + else if( params->HasInt( *nIt ) ) + p->SetAttribute( "type", "Int" ); + else if( params->HasUint( *nIt ) ) + p->SetAttribute( "type", "Uint" ); + else if( params->HasReal( *nIt ) ) + p->SetAttribute( "type", "Real" ); + else if( params->HasIndex( *nIt ) ) + p->SetAttribute( "type", "Index" ); + else if( params->HasPoint( *nIt ) ) + p->SetAttribute( "type", "Point" ); + else if( params->HasVector( *nIt ) ) + p->SetAttribute( "type", "Vector" ); + else if( params->HasStringList( *nIt ) ) + p->SetAttribute( "type", "StringList" ); + else if( params->HasBoolList( *nIt ) ) + p->SetAttribute( "type", "BoolList" ); + else if( params->HasIntList( *nIt ) ) + p->SetAttribute( "type", "IntList" ); + else if( params->HasUintList( *nIt ) ) + p->SetAttribute( "type", "UintList" ); + else if( params->HasRealList( *nIt ) ) + p->SetAttribute( "type", "RealList" ); + else if( params->HasIndexList( *nIt ) ) + p->SetAttribute( "type", "IndexList" ); + else if( params->HasPointList( *nIt ) ) + p->SetAttribute( "type", "PointList" ); + else if( params->HasVectorList( *nIt ) ) + p->SetAttribute( "type", "VectorList" ); + else if( params->HasChoices( *nIt ) ) + p->SetAttribute( "type", "Choices" ); + p->SetAttribute( "value", params->GetString( *nIt, false ).c_str( ) ); + e->LinkEndChild( p ); + + } // rof + root->LinkEndChild( e ); } else if( data != NULL ) {