X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;ds=sidebyside;f=appli%2FcpPipelineEditor%2FQNEBlock.cxx;fp=appli%2FcpPipelineEditor%2FQNEBlock.cxx;h=d1e01094d1bb535845c708d0cfe498c9c4abbc55;hb=ef8b6e12859181d3faa8019ce7319c539c0f86ec;hp=0000000000000000000000000000000000000000;hpb=49ccd98bd1a735c6cf787853addb4ff2a2bfd2e1;p=cpPlugins.git diff --git a/appli/cpPipelineEditor/QNEBlock.cxx b/appli/cpPipelineEditor/QNEBlock.cxx new file mode 100644 index 0000000..d1e0109 --- /dev/null +++ b/appli/cpPipelineEditor/QNEBlock.cxx @@ -0,0 +1,260 @@ +/* Copyright (c) 2012, STANISLAW ADASZEWSKI + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of STANISLAW ADASZEWSKI nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL STANISLAW ADASZEWSKI BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "QNEBlock.h" + +#include +#include +#include +#include +#include + +#include "QNEPort.h" + +// ------------------------------------------------------------------------- +PipelineEditor::QNEBlock:: +QNEBlock( QGraphicsItem* parent, QGraphicsScene* scene ) + : Superclass( parent, scene ), + m_HorzMargin( 20 ), + m_VertMargin( 5 ) +{ + 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; +} + +// ------------------------------------------------------------------------- +PipelineEditor::QNEBlock:: +~QNEBlock( ) +{ +} + +// ------------------------------------------------------------------------- +PipelineEditor::QNEPort* PipelineEditor::QNEBlock:: +addPort( const QString& name, bool isOutput, int flags, int ptr ) +{ + 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 ); +} + +// ------------------------------------------------------------------------- +void PipelineEditor::QNEBlock:: +addInputPort( const QString& name ) +{ + this->addPort( name, false ); +} + +// ------------------------------------------------------------------------- +void PipelineEditor::QNEBlock:: +addOutputPort( const QString& name ) +{ + this->addPort( name, true ); +} + +// ------------------------------------------------------------------------- +void PipelineEditor::QNEBlock:: +addInputPorts( const QStringList& names ) +{ + foreach( QString n, names ) + this->addInputPort( n ); +} + +// ------------------------------------------------------------------------- +void PipelineEditor::QNEBlock:: +addOutputPorts( const QStringList& names ) +{ + foreach( QString n, names ) + this->addOutputPort( n ); +} + +// ------------------------------------------------------------------------- +void PipelineEditor::QNEBlock:: +save( QDataStream& ds ) +{ + ds << pos( ); + + int count( 0 ); + + foreach( QGraphicsItem* port_, children( ) ) + { + if( port_->type( ) != QNEPort::Type ) + continue; + count++; + + } // rof + + ds << count; + + foreach( QGraphicsItem* port_, children( ) ) + { + if( port_->type( ) != QNEPort::Type ) + continue; + + QNEPort* port = ( QNEPort* ) port_; + ds << ( quint64 ) port; + ds << port->portName( ); + ds << port->isOutput( ); + ds << port->portFlags( ); + + } // rof +} + +// ------------------------------------------------------------------------- +void PipelineEditor::QNEBlock:: +load( QDataStream& ds, QMap& portMap ) +{ + QPointF p; + ds >> p; + this->setPos( p ); + int count; + ds >> count; + for( int i = 0; i < count; i++ ) + { + QString name; + bool output; + int flags; + quint64 ptr; + + ds >> ptr; + ds >> name; + ds >> output; + ds >> flags; + portMap[ptr] = this->addPort( name, output, flags, ptr ); + + } // rof +} + +// ------------------------------------------------------------------------- +void PipelineEditor::QNEBlock:: +paint( + QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget + ) +{ + Q_UNUSED( option ); + Q_UNUSED( widget ); + + if( this->isSelected( ) ) + { + painter->setPen( QPen( Qt::darkYellow ) ); + painter->setBrush( Qt::yellow ); + } + else + { + painter->setPen( QPen( Qt::darkGreen ) ); + painter->setBrush( Qt::green ); + + } // fi + painter->drawPath( this->path( ) ); +} + +// ------------------------------------------------------------------------- +PipelineEditor::QNEBlock* PipelineEditor::QNEBlock:: +clone( ) +{ + 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 ); +} + +// ------------------------------------------------------------------------- +QVector< PipelineEditor::QNEPort* > PipelineEditor::QNEBlock:: +ports( ) +{ + QVector< PipelineEditor::QNEPort* > res; + foreach( QGraphicsItem* port_, childItems( ) ) + { + if( port_->type( ) == QNEPort::Type ) + res.append( ( QNEPort* ) port_ ); + + } // rof + return( res ); +} + +// ------------------------------------------------------------------------- +QVariant PipelineEditor::QNEBlock:: +itemChange( GraphicsItemChange change, const QVariant& value ) +{ + return( value ); +} + +// eof - $RCSfile$