From: Leonardo Florez-Valencia Date: Fri, 18 Dec 2015 18:55:19 +0000 (-0500) Subject: ... X-Git-Tag: v0.1~280 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=9c75dcecf566cc567583caf4687ce523a2af586d;p=cpPlugins.git ... --- diff --git a/appli/cpPipelineEditor/Edge.cxx b/appli/cpPipelineEditor/Edge.cxx deleted file mode 100644 index 5fb9c7c..0000000 --- a/appli/cpPipelineEditor/Edge.cxx +++ /dev/null @@ -1,143 +0,0 @@ -#include "Edge.h" -#include "Node.h" - -#include - -// ------------------------------------------------------------------------- -PipelineEditor::Edge:: -Edge( - const Node* nsrc, const Node* ndes, - const QRectF* rsrc, const QRectF* rdes - ) - : QGraphicsItem( NULL ) -{ - this->setAcceptedMouseButtons( 0 ); - this->m_SrcNode = nsrc; - this->m_DesNode = ndes; - this->m_SrcRect = rsrc; - this->m_DesRect = rdes; - this->adjust( ); -} - -// ------------------------------------------------------------------------- -PipelineEditor::Edge:: -~Edge( ) -{ -} - -// ------------------------------------------------------------------------- -const QRectF* PipelineEditor::Edge:: -source( ) const -{ - return( this->m_SrcRect ); -} - -// ------------------------------------------------------------------------- -const QRectF* PipelineEditor::Edge:: -destination( ) const -{ - return( this->m_DesRect ); -} - -// ------------------------------------------------------------------------- -void PipelineEditor::Edge:: -adjust( ) -{ - - /* TODO - if( this->m_Src == NULL || this->m_Des == NULL ) - return; - - QLineF line( - this->mapFromParent( this->m_Src->center( ) ), - this->mapFromParent( this->m_Des->center( ) ) - ); - // TODO: qreal length = line.length( ); - this->prepareGeometryChange( ); - if( length > qreal( 20 ) ) - { - QPointF edgeOffset( - ( line.dx( ) * qreal( 10 ) ) / length, - ( line.dy( ) * qreal( 10 ) ) / length - ); - this->m_SrcPoint = line.p1( ) + edgeOffset; - this->m_DesPoint = line.p2( ) - edgeOffset; - } - else - this->m_SrcPoint = this->m_DesPoint = line.p1( ); - */ -} - -// ------------------------------------------------------------------------- -QRectF PipelineEditor::Edge:: -boundingRect( ) const -{ - if( this->m_SrcRect == NULL || this->m_DesRect == NULL ) - return( QRectF( ) ); - - /* - qreal penWidth = 1; - qreal extra = ( penWidth + this->m_ArrowSize ) / qreal( 2 ); - */ - qreal extra = qreal( 1 ); - return( - QRectF( - this->m_SrcRect->center( ), - QSizeF( - this->m_DesRect->center( ).x( ) - this->m_SrcRect->center( ).x( ), - this->m_DesRect->center( ).y( ) - this->m_SrcRect->center( ).y( ) - ) - ).normalized( ).adjusted( -extra, -extra, extra, extra ) - ); -} - -// ------------------------------------------------------------------------- -void PipelineEditor::Edge:: -paint( - QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget - ) -{ - /* TODO - if( this->m_Src == NULL || this->m_Des == NULL ) - return; - */ - - // TODO: QLineF line( this->m_Src->center( ), this->m_Des->center( ) ); - QLineF line( - this->m_SrcNode->mapToScene( this->m_SrcRect->center( ) ), - this->m_DesNode->mapToScene( this->m_DesRect->center( ) ) - ); - - if( qFuzzyCompare( line.length(), qreal( 0 ) ) ) - return; - - // Draw the line itself - painter->setPen( - QPen( Qt::black, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) - ); - painter->drawLine( line ); - - /* TODO - // Draw the arrows - double angle = ::acos(line.dx() / line.length()); - if (line.dy() >= 0) - angle = TwoPi - angle; - - QPointF destArrowP1 = destPoint + QPointF( - sin(angle - Pi / 3) * arrowSize, - cos(angle - Pi / 3) * arrowSize - ); - QPointF destArrowP2 = destPoint + QPointF( - sin(angle - Pi + Pi / 3) * arrowSize, - cos(angle - Pi + Pi / 3) * arrowSize - ); - QPointF center = sourcePoint + destPoint; - center /= 2; - - painter->setBrush(Qt::black); - painter->drawPolygon(QPolygonF() << line.p2() << destArrowP1 << destArrowP2); - painter->drawText( center, "Edge!!!" ); - */ -} - -// eof - $RCSfile$ diff --git a/appli/cpPipelineEditor/Edge.h b/appli/cpPipelineEditor/Edge.h deleted file mode 100644 index bbaeb1e..0000000 --- a/appli/cpPipelineEditor/Edge.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef __PIPELINEEDITOR__EDGE__H__ -#define __PIPELINEEDITOR__EDGE__H__ - -#include - -namespace PipelineEditor -{ - // Some forward declarations - class Node; - - /** - */ - class Edge - : public QGraphicsItem - { - public: - Edge( - const Node* nsrc, const Node* ndes, - const QRectF* rsrc, const QRectF* rdes - ); - virtual ~Edge( ); - - const QRectF* source( ) const; - const QRectF* destination( ) const; - void adjust( ); - QRectF boundingRect( ) const; - void paint( - QPainter* painter, - const QStyleOptionGraphicsItem* option, - QWidget* widget - ); - - private: - const Node* m_SrcNode; - const Node* m_DesNode; - const QRectF* m_SrcRect; - const QRectF* m_DesRect; - }; - -} // ecapseman - -#endif // __PIPELINEEDITOR__EDGE__H__ - -// eof - $RCSfile$ diff --git a/appli/cpPipelineEditor/Node.cxx b/appli/cpPipelineEditor/Node.cxx deleted file mode 100644 index 34c4d96..0000000 --- a/appli/cpPipelineEditor/Node.cxx +++ /dev/null @@ -1,391 +0,0 @@ -#include "Node.h" -#include "Edge.h" -#include "GraphCanvas.h" - -#include -#include -#include - -#include -#include -#include - -#define PORT_SIZE 15 - -// ------------------------------------------------------------------------- -PipelineEditor::Node:: -Node( GraphCanvas* canvas, cpPlugins::Interface::Object* object ) - : QGraphicsItem( NULL ), - m_Canvas( canvas ), - m_Object( object ), - m_SelectedPort( NULL ), - m_DraggingPort( false ) -{ - this->setFlag( QGraphicsItem::ItemIsMovable, true ); - this->setFlag( QGraphicsItem::ItemSendsGeometryChanges, true ); - this->setCacheMode( QGraphicsItem::DeviceCoordinateCache ); - this->setAcceptHoverEvents( true ); - this->setAcceptDrops( true ); - this->setZValue( -1 ); - this->updateRepresentation( ); -} - -// ------------------------------------------------------------------------- -PipelineEditor::Node:: -~Node( ) -{ -} - -// ------------------------------------------------------------------------- -void PipelineEditor::Node:: -addEdge( PipelineEditor::Edge* edge ) -{ - this->m_Edges << edge; - edge->adjust( ); -} - -// ------------------------------------------------------------------------- -QList< PipelineEditor::Edge* > PipelineEditor::Node:: -edges( ) const -{ - return( this->m_Edges ); -} - -// ------------------------------------------------------------------------- -void PipelineEditor::Node:: -updateRepresentation( ) -{ - typedef cpPlugins::Interface::DataObject _TData; - typedef cpPlugins::Interface::ProcessObject _TFilter; - - if( this->m_Object == NULL ) - return; - - // Try to infere type - _TData* d = dynamic_cast< _TData* >( this->m_Object ); - _TFilter* f = dynamic_cast< _TFilter* >( this->m_Object ); - if( d == NULL && f == NULL ) - return; - - // Label and its bounds - QFontMetricsF fm( this->m_Canvas->font( ) ); - this->m_Label = this->m_Object->GetName( ); - this->m_Label += "\n"; - this->m_Label += this->m_Object->GetClassName( ).c_str( ); - this->m_Bounds = fm.boundingRect( this->m_Label ); - - // Create ports representation - this->m_Inputs.clear( ); - this->m_Outputs.clear( ); - this->m_InputPorts.clear( ); - this->m_OutputPorts.clear( ); - if( f != NULL ) - { - // Get filter's inputs and outputs - f->GetInputsNames( this->m_Inputs ); - f->GetOutputsNames( this->m_Outputs ); - - // Correct height - unsigned int nIn = this->m_Inputs.size( ); - unsigned int nOut = this->m_Outputs.size( ); - qreal n = - qreal( ( ( ( ( nIn > nOut )? nIn: nOut ) << 1 ) + 1 ) * PORT_SIZE ); - qreal h = this->m_Bounds.height( ); - if( n > h ) - this->m_Bounds.setHeight( n ); - - // Get bounds values - qreal rt = this->m_Bounds.top( ) - qreal( PORT_SIZE ); - qreal rb = this->m_Bounds.bottom( ) + qreal( PORT_SIZE ); - qreal rl = this->m_Bounds.left( ) - qreal( PORT_SIZE ); - qreal rr = this->m_Bounds.right( ) + qreal( PORT_SIZE ); - - // Add some space to the geometry - this->m_Bounds.setTop( rt ); - this->m_Bounds.setBottom( rb ); - this->m_Bounds.setLeft( rl ); - this->m_Bounds.setRight( rr ); - qreal rh = this->m_Bounds.height( ); - - // Create ports - QSizeF ps( qreal( PORT_SIZE ), qreal( PORT_SIZE ) ); - std::set< std::string >* ports[] = - { &( this->m_Inputs ), &( this->m_Outputs ) }; - for( unsigned int pId = 0; pId < 2; ++pId ) - { - qreal h = qreal( ( ( ports[ pId ]->size( ) << 1 ) + 1 ) * PORT_SIZE ); - qreal off = qreal( PORT_SIZE ); - if( rh > h ) - off += ( rh - h ) / qreal( 2 ); - for( auto i = ports[ pId ]->begin( ); i != ports[ pId ]->end( ); ++i ) - { - if( pId == 0 ) - this->m_InputPorts[ *i ] = - QRectF( QPointF( rl, rt + off ), ps ); - else - this->m_OutputPorts[ *i ] = - QRectF( QPointF( rr - qreal( PORT_SIZE ), rt + off ), ps ); - off += qreal( PORT_SIZE < 1 ); - - } // rof - - } // rof - - } // fi - - // Some other initializations - this->m_SelectedPort = NULL; -} - -// ------------------------------------------------------------------------- -QRectF PipelineEditor::Node:: -boundingRect( ) const -{ - return( this->m_Bounds ); -} - -// ------------------------------------------------------------------------- -QPainterPath PipelineEditor::Node:: -shape( ) const -{ - QPainterPath path; - path.addRect( this->m_Bounds ); - return( path ); -} - -// ------------------------------------------------------------------------- -void PipelineEditor::Node:: -paint( - QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget - ) -{ - // Draw main box - QRectF rect = this->boundingRect( ); - painter->drawRect( rect ); - painter->drawText( rect, Qt::AlignCenter, this->m_Label ); - - // Draw ports - std::map< std::string, QRectF >* ports[] = - { &( this->m_InputPorts ), &( this->m_OutputPorts ) }; - for( unsigned int pId = 0; pId < 2; ++pId ) - for( auto i = ports[ pId ]->begin( ); i != ports[ pId ]->end( ); ++i ) - painter->drawRect( i->second ); - - // Draw clicked port - if( this->m_SelectedPort != NULL ) - { - painter->setBrush( Qt::green ); - painter->drawEllipse( *( this->m_SelectedPort ) ); - - } // fi -} - -// ------------------------------------------------------------------------- -QVariant PipelineEditor::Node:: -itemChange( GraphicsItemChange change, const QVariant& value ) -{ - switch( change ) - { - case QGraphicsItem::ItemPositionHasChanged: - foreach( Edge* edge, this->m_Edges ) - edge->update( ); - this->m_Canvas->itemMoved( ); - break; - default: - break; - } // hctiws - return( this->QGraphicsItem::itemChange( change, value ) ); -} - -// ------------------------------------------------------------------------- -void PipelineEditor::Node:: -mousePressEvent( QGraphicsSceneMouseEvent* event ) -{ - if( this->m_SelectedPort != NULL && this->m_Canvas != NULL ) - { - if( event->button( ) == Qt::LeftButton ) - { - QDrag* drag = new QDrag( this->m_Canvas ); - QMimeData* mimeData = new QMimeData( ); - - // mimeData->setText( "drag_data" ); - qulonglong address = reinterpret_cast< qulonglong >( this ); - QByteArray ba; - ba.setNum( address ); - mimeData->setData( "source_node", ba ); - drag->setMimeData( mimeData ); - // TODO: drag->setPixmap( iconPixmap ); - - this->m_DraggingPort = true; - Qt::DropAction dropAction = drag->exec( ); - this->m_DraggingPort = false; - - } // fi - } - else - { - } // fi - - /* TODO - Qt::MouseButton btn = event->button( ); - if( btn == Qt::LeftButton ) - { - std::string name = this->toolTip( ).toStdString( ); - if( name != this->m_Object->GetName( ) ) - { - // Get clicked port, if any - QPointF pos = event->buttonDownPos( btn ); - auto iIt = this->m_InputPorts.find( name ); - auto oIt = this->m_OutputPorts.find( name ); - this->m_SelectedPort = NULL; - if( iIt != this->m_InputPorts.end( ) ) - if( iIt->second.contains( pos ) ) - this->m_SelectedPort = &( iIt->second ); - if( this->m_SelectedPort == NULL && oIt != this->m_OutputPorts.end( ) ) - if( oIt->second.contains( pos ) ) - this->m_SelectedPort = &( oIt->second ); - - } // fi - - } // fi - */ - this->update( ); - this->QGraphicsItem::mousePressEvent( event ); -} - -// ------------------------------------------------------------------------- -void PipelineEditor::Node:: -mouseReleaseEvent( QGraphicsSceneMouseEvent* event ) -{ - this->update( ); - this->QGraphicsItem::mouseReleaseEvent( event ); -} - -// ------------------------------------------------------------------------- -void PipelineEditor::Node:: -mouseDoubleClickEvent( QGraphicsSceneMouseEvent* event ) -{ -} - -// ------------------------------------------------------------------------- -void PipelineEditor::Node:: -hoverMoveEvent( QGraphicsSceneHoverEvent* event ) -{ - this->_selectPort( event->pos( ) ); -} - -// ------------------------------------------------------------------------- -void PipelineEditor::Node:: -hoverLeaveEvent( QGraphicsSceneHoverEvent* event ) -{ - this->_deselectPort( ); -} - -// ------------------------------------------------------------------------- -void PipelineEditor::Node:: -dragMoveEvent( QGraphicsSceneDragDropEvent* event ) -{ - this->_selectPort( event->pos( ) ); -} - -// ------------------------------------------------------------------------- -void PipelineEditor::Node:: -dragLeaveEvent( QGraphicsSceneDragDropEvent* event ) -{ - this->_deselectPort( ); -} - -// ------------------------------------------------------------------------- -void PipelineEditor::Node:: -dropEvent( QGraphicsSceneDragDropEvent* event ) -{ - // Get vertices and directionality - bool ok; - qulonglong address = - event->mimeData( )->data( "source_node" ).toULongLong( &ok ); - Node* src = reinterpret_cast< Node* >( address ); - if( src == NULL ) - return; - Node* des = this; - if( src->m_SelectedPortIsInput ) - { - des = src; - src = this; - - } // fi - - // Discard if a loop is detected - if( src == des ) - return; - - // Get edge data - const QRectF* srcPort = src->m_SelectedPort; - const QRectF* desPort = des->m_SelectedPort; - std::string srcName = src->m_Object->GetName( ); - std::string desName = des->m_Object->GetName( ); - std::string srcPortName = src->toolTip( ).toStdString( ); - std::string desPortName = des->toolTip( ).toStdString( ); - - Edge* e = new Edge( src, des, srcPort, desPort ); - src->addEdge( e ); - des->addEdge( e ); - if( this->m_Canvas != NULL ) - this->m_Canvas->scene( )->addItem( e ); -} - -// ------------------------------------------------------------------------- -void PipelineEditor::Node:: -_selectPort( const QPointF& pos ) -{ - if( this->m_DraggingPort ) - return; - - const QRectF* prevPort = this->m_SelectedPort; - - // Check ports - std::map< std::string, QRectF >* ports[] = - { &( this->m_InputPorts ), &( this->m_OutputPorts ) }; - bool found = false; - for( unsigned int pId = 0; pId < 2 && !found; ++pId ) - { - for( - auto i = ports[ pId ]->begin( ); - i != ports[ pId ]->end( ) && !found; - ++i - ) - { - if( i->second.contains( pos ) ) - { - this->setToolTip( i->first.c_str( ) ); - this->m_SelectedPort = &( i->second ); - this->m_SelectedPortIsInput = ( pId == 0 ); - found = true; - - } // fi - - } // rof - - } // rof - if( !found ) - { - this->setToolTip( this->m_Object->GetName( ) ); - this->m_SelectedPort = NULL; - - } // fi - if( prevPort != this->m_SelectedPort ) - this->update( ); -} - -// ------------------------------------------------------------------------- -void PipelineEditor::Node:: -_deselectPort( ) -{ - if( !( this->m_DraggingPort ) ) - { - this->m_SelectedPort = NULL; - this->update( ); - - } // fi -} - -// eof - $RCSfile$ diff --git a/appli/cpPipelineEditor/Node.h b/appli/cpPipelineEditor/Node.h deleted file mode 100644 index 41a68c3..0000000 --- a/appli/cpPipelineEditor/Node.h +++ /dev/null @@ -1,98 +0,0 @@ -#ifndef __PIPELINEEDITOR__NODE__H__ -#define __PIPELINEEDITOR__NODE__H__ - -#include -#include - -#include -#include - - -#include - - -// Some forward declarations -class QGraphicsSceneMouseEvent; -class QGraphicsSceneHoverEvent; - -// Some forward declarations -namespace cpPlugins -{ - namespace Interface - { - class Object; - } -} - -namespace PipelineEditor -{ - // Some other forward declarations - class Edge; - class GraphCanvas; - - /** - */ - class Node - : public QGraphicsItem - { - public: - Node( GraphCanvas* canvas, cpPlugins::Interface::Object* object ); - virtual ~Node( ); - - void addEdge( Edge* edge ); - QList< Edge* > edges( ) const; - - void updateRepresentation( ); - - QRectF boundingRect( ) const; - QPainterPath shape( ) const; - void paint( - QPainter* painter, - const QStyleOptionGraphicsItem* option, - QWidget* widget - ); - void moveBy(qreal dx, qreal dy) - { - std::cout << "move: " << dx << " " << dy << std::endl; - this->QGraphicsItem::moveBy( dx, dy ); - } - - protected: - QVariant itemChange( GraphicsItemChange change, const QVariant& value ); - - void mousePressEvent( QGraphicsSceneMouseEvent* event ); - void mouseReleaseEvent( QGraphicsSceneMouseEvent* event ); - void mouseDoubleClickEvent( QGraphicsSceneMouseEvent* event ); - void hoverMoveEvent( QGraphicsSceneHoverEvent* event ); - void hoverLeaveEvent( QGraphicsSceneHoverEvent* event ); - void dragMoveEvent( QGraphicsSceneDragDropEvent* event ); - void dragLeaveEvent( QGraphicsSceneDragDropEvent* event ); - void dropEvent( QGraphicsSceneDragDropEvent* event ); - - void _selectPort( const QPointF& pos ); - void _deselectPort( ); - - private: - GraphCanvas* m_Canvas; - QList< Edge* > m_Edges; - cpPlugins::Interface::Object* m_Object; - - // Graphical objects - QString m_Label; - QRectF m_Bounds; - std::set< std::string > m_Inputs; - std::set< std::string > m_Outputs; - std::map< std::string, QRectF > m_InputPorts; - std::map< std::string, QRectF > m_OutputPorts; - - // Interaction objects - const QRectF* m_SelectedPort; - bool m_SelectedPortIsInput; - bool m_DraggingPort; - }; - -} // ecapseman - -#endif // __PIPELINEEDITOR__NODE__H__ - -// eof - $RCSfile$ diff --git a/appli/cpPipelineEditor/QNEBlock.cxx b/appli/cpPipelineEditor/QNEBlock.cxx index 7ccb166..0c6900d 100644 --- a/appli/cpPipelineEditor/QNEBlock.cxx +++ b/appli/cpPipelineEditor/QNEBlock.cxx @@ -132,63 +132,6 @@ addOutputPorts( const QStringList& 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( diff --git a/appli/cpPipelineEditor/QNEBlock.h b/appli/cpPipelineEditor/QNEBlock.h index 1f3d651..524988a 100644 --- a/appli/cpPipelineEditor/QNEBlock.h +++ b/appli/cpPipelineEditor/QNEBlock.h @@ -21,7 +21,8 @@ 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. */ + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ #ifndef __PIPELINEEDITOR__QNEBLOCK__H__ #define __PIPELINEEDITOR__QNEBLOCK__H__ @@ -52,8 +53,6 @@ namespace PipelineEditor QNEPort* addOutputPort( const QString& name ); void addInputPorts( const QStringList& names ); void addOutputPorts( const QStringList& names ); - void save( QDataStream& ds ); - void load( QDataStream& ds, QMap< quint64, QNEPort* >& portMap ); void paint( QPainter* painter, const QStyleOptionGraphicsItem* option, diff --git a/appli/cpPipelineEditor/QNEConnection.cxx b/appli/cpPipelineEditor/QNEConnection.cxx index e038c5f..42199fd 100644 --- a/appli/cpPipelineEditor/QNEConnection.cxx +++ b/appli/cpPipelineEditor/QNEConnection.cxx @@ -129,27 +129,4 @@ port2( ) const return( this->m_Port2 ); } -// ------------------------------------------------------------------------- -void PipelineEditor::QNEConnection:: -save( QDataStream& ds ) -{ - ds << ( quint64 ) this->m_Port1; - ds << ( quint64 ) this->m_Port2; -} - -// ------------------------------------------------------------------------- -void PipelineEditor::QNEConnection:: -load( QDataStream& ds, const QMap< quint64, QNEPort* >& portMap ) -{ - quint64 ptr1; - quint64 ptr2; - ds >> ptr1; - ds >> ptr2; - - this->setPort1( portMap[ ptr1 ] ); - this->setPort2( portMap[ ptr2 ] ); - this->updatePosFromPorts( ); - this->updatePath( ); -} - // eof - $RCSfile$ diff --git a/appli/cpPipelineEditor/QNEConnection.h b/appli/cpPipelineEditor/QNEConnection.h index 869e283..54cdf84 100644 --- a/appli/cpPipelineEditor/QNEConnection.h +++ b/appli/cpPipelineEditor/QNEConnection.h @@ -57,9 +57,6 @@ namespace PipelineEditor QNEPort* port1( ) const; QNEPort* port2( ) const; - void save( QDataStream& ds ); - void load( QDataStream& ds, const QMap< quint64, QNEPort* >& portMap ); - int type( ) const { return Type; } private: diff --git a/appli/cpPipelineEditor/QNEMainWindow.cxx b/appli/cpPipelineEditor/QNEMainWindow.cxx deleted file mode 100644 index 5d7f7fe..0000000 --- a/appli/cpPipelineEditor/QNEMainWindow.cxx +++ /dev/null @@ -1,112 +0,0 @@ -/* 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 "QNEMainWindow.h" -#include "ui_QNEMainWindow.h" - -#include "QNEBlock.h" -#include "QNodesEditor.h" - -#include -#include - -#include "QNEPort.h" - -QNEMainWindow::QNEMainWindow(QWidget *parent) : - QMainWindow(parent), - ui(new Ui::QNEMainWindow) -{ - ui->setupUi(this); - - QGraphicsScene *s = new QGraphicsScene(); - ui->graphicsView->setScene(s); - ui->graphicsView->setRenderHint(QPainter::Antialiasing); - // ui->graphicsView->setDragMode(QGraphicsView::ScrollHandDrag); - - QNEBlock *b = new QNEBlock(0, s); - b->addPort("test", 0, QNEPort::NamePort); - b->addPort("TestBlock", 0, QNEPort::TypePort); - b->addInputPort("in1"); - b->addInputPort("in2"); - b->addInputPort("in3"); - b->addOutputPort("out1"); - b->addOutputPort("out2"); - b->addOutputPort("out3"); - - b = b->clone(); - b->setPos(150, 0); - - b = b->clone(); - b->setPos(150, 150); - - nodesEditor = new QNodesEditor(this); - nodesEditor->install(s); - - connect(ui->action_Save, SIGNAL(triggered()), this, SLOT(saveFile())); - connect(ui->action_Load, SIGNAL(triggered()), this, SLOT(loadFile())); - connect(ui->action_Quit, SIGNAL(triggered()), qApp, SLOT(quit())); - - ui->toolBar->addAction("Add block", this, SLOT(addBlock())); -} - -QNEMainWindow::~QNEMainWindow() -{ - delete ui; -} - -void QNEMainWindow::saveFile() -{ - QString fname = QFileDialog::getSaveFileName(); - if (fname.isEmpty()) - return; - - QFile f(fname); - f.open(QFile::WriteOnly); - QDataStream ds(&f); - nodesEditor->save(ds); -} - -void QNEMainWindow::loadFile() -{ - QString fname = QFileDialog::getOpenFileName(); - if (fname.isEmpty()) - return; - - QFile f(fname); - f.open(QFile::ReadOnly); - QDataStream ds(&f); - nodesEditor->load(ds); -} - -void QNEMainWindow::addBlock() -{ - QNEBlock *b = new QNEBlock(0, ui->graphicsView->scene()); - static const char* names[] = {"Vin", "Voutsadfasdf", "Imin", "Imax", "mul", "add", "sub", "div", "Conv", "FFT"}; - for (int i = 0; i < 4 + rand() % 3; i++) - { - b->addPort(names[rand() % 10], rand() % 2, 0, 0); - b->setPos(ui->graphicsView->sceneRect().center().toPoint()); - } -} diff --git a/appli/cpPipelineEditor/QNEMainWindow.h b/appli/cpPipelineEditor/QNEMainWindow.h deleted file mode 100644 index 4ee1100..0000000 --- a/appli/cpPipelineEditor/QNEMainWindow.h +++ /dev/null @@ -1,55 +0,0 @@ -/* 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. */ - -#ifndef QNEMAINWINDOW_H -#define QNEMAINWINDOW_H - -#include - -namespace Ui { - class QNEMainWindow; -} - -class QNodesEditor; - -class QNEMainWindow : public QMainWindow -{ - Q_OBJECT - -public: - explicit QNEMainWindow(QWidget *parent = 0); - ~QNEMainWindow(); - -private slots: - void saveFile(); - void loadFile(); - void addBlock(); - -private: - Ui::QNEMainWindow *ui; - QNodesEditor *nodesEditor; -}; - -#endif // QNEMAINWINDOW_H diff --git a/appli/cpPipelineEditor/QNEMainWindow.ui b/appli/cpPipelineEditor/QNEMainWindow.ui deleted file mode 100644 index 29f3f8c..0000000 --- a/appli/cpPipelineEditor/QNEMainWindow.ui +++ /dev/null @@ -1,73 +0,0 @@ - - - QNEMainWindow - - - - 0 - 0 - 540 - 389 - - - - QNodesEditor Demo (c) 2012 STANISLAW ADASZEWSKI, http://algoholic.eu - - - - - - - - - - - - 0 - 0 - 540 - 20 - - - - - &File - - - - - - - - - - - toolBar - - - TopToolBarArea - - - false - - - - - &Save - - - - - &Load - - - - - &Quit - - - - - - - diff --git a/appli/cpPipelineEditor/QNEPort.cxx b/appli/cpPipelineEditor/QNEPort.cxx index 7c140bb..dbf4346 100644 --- a/appli/cpPipelineEditor/QNEPort.cxx +++ b/appli/cpPipelineEditor/QNEPort.cxx @@ -25,13 +25,12 @@ */ #include "QNEPort.h" +#include "QNEConnection.h" #include #include #include -#include "QNEConnection.h" - // ------------------------------------------------------------------------- PipelineEditor::QNEPort:: QNEPort( QGraphicsItem* parent, QGraphicsScene* scene ) diff --git a/appli/cpPipelineEditor/QNEPort.h b/appli/cpPipelineEditor/QNEPort.h index 638e413..1f445d0 100644 --- a/appli/cpPipelineEditor/QNEPort.h +++ b/appli/cpPipelineEditor/QNEPort.h @@ -43,10 +43,10 @@ namespace PipelineEditor typedef QNEPort Self; typedef QGraphicsPathItem Superclass; - public: enum { Type = QGraphicsItem::UserType + 1 }; enum { NamePort = 1, TypePort = 2 }; + public: QNEPort( QGraphicsItem* parent = 0, QGraphicsScene* scene = NULL ); virtual ~QNEPort( ); @@ -58,6 +58,11 @@ namespace PipelineEditor QVector< QNEConnection* >& connections( ); void setPortFlags( int f ); + QNEBlock* block( ) const; + quint64 ptr( ); + void setPtr( quint64 p ); + bool isConnected( QNEPort* other ); + inline const QString& portName( ) const { return( this->m_Name ); } inline int portFlags( ) const @@ -65,11 +70,6 @@ namespace PipelineEditor int type( ) const { return( this->Type ); } - QNEBlock* block( ) const; - quint64 ptr( ); - void setPtr( quint64 p ); - bool isConnected( QNEPort* other ); - protected: QVariant itemChange( GraphicsItemChange change, const QVariant& value ); diff --git a/appli/cpPipelineEditor/QNodesEditor.cxx b/appli/cpPipelineEditor/QNodesEditor.cxx index 91a5914..590f8df 100644 --- a/appli/cpPipelineEditor/QNodesEditor.cxx +++ b/appli/cpPipelineEditor/QNodesEditor.cxx @@ -150,52 +150,8 @@ eventFilter( QObject* o, QEvent* e ) } break; } - } + } // hctiws return( this->Superclass::eventFilter( o, e ) ); } -// ------------------------------------------------------------------------- -void PipelineEditor::QNodesEditor:: -save( QDataStream& ds ) -{ - foreach( QGraphicsItem* item, this->m_Scene->items( ) ) - if( item->type( ) == QNEBlock::Type ) - { - ds << item->type( ); - ( ( QNEBlock* ) item )->save( ds ); - } - - foreach( QGraphicsItem* item, this->m_Scene->items( ) ) - if( item->type( ) == QNEConnection::Type ) - { - ds << item->type( ); - ( ( QNEConnection* ) item )->save( ds ); - } -} - -// ------------------------------------------------------------------------- -void PipelineEditor::QNodesEditor:: -load( QDataStream& ds ) -{ - this->m_Scene->clear( ); - - QMap portMap; - - while ( !ds.atEnd( ) ) - { - int type; - ds >> type; - if( type == QNEBlock::Type ) - { - QNEBlock* block = new QNEBlock( 0, this->m_Scene ); - block->load( ds, portMap ); - } - else if( type == QNEConnection::Type ) - { - this->m_Conn = new QNEConnection( 0, this->m_Scene ); - this->m_Conn->load( ds, portMap ); - } - } -} - // eof - $RCSfile$ diff --git a/appli/cpPipelineEditor/QNodesEditor.h b/appli/cpPipelineEditor/QNodesEditor.h index 87c5a20..c2db807 100644 --- a/appli/cpPipelineEditor/QNodesEditor.h +++ b/appli/cpPipelineEditor/QNodesEditor.h @@ -21,7 +21,8 @@ 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. */ + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ #ifndef __PIPELINEEDITOR__QNODESEDITOR__H__ #define __PIPELINEEDITOR__QNODESEDITOR__H__ @@ -56,9 +57,6 @@ namespace PipelineEditor bool eventFilter( QObject* o, QEvent* e ); - void save( QDataStream& ds ); - void load( QDataStream& ds ); - private: QGraphicsItem* itemAt( const QPointF& pos ); diff --git a/appli/cpPipelineEditor/QNodesEditorCanvas.cxx b/appli/cpPipelineEditor/QNodesEditorCanvas.cxx index b320930..afb5b62 100644 --- a/appli/cpPipelineEditor/QNodesEditorCanvas.cxx +++ b/appli/cpPipelineEditor/QNodesEditorCanvas.cxx @@ -147,7 +147,6 @@ dragMoveEvent( QDragMoveEvent* event ) void PipelineEditor::QNodesEditorCanvas:: dropEvent( QDropEvent* event ) { - std::cout << event << " " << this->m_Workspace << std::endl; if( this->m_Workspace == NULL ) return; const QMimeData* mime = event->mimeData( ); @@ -163,26 +162,11 @@ dropEvent( QDropEvent* event ) for( auto iIt = items.begin( ); iIt != items.end( ); ++iIt ) { std::string filter = ( *iIt )->text( 0 ).toStdString( ); - std::string name = "filtro"; //filter; - if( this->m_Workspace->GetFilter( name ) != NULL ) + std::string name = filter; + while( this->m_Workspace->HasFilter( name ) ) name += std::string( "_" ); - std::cout << name << std::endl; if( this->m_Workspace->CreateFilter( filter, name ) ) - { - auto vIt = this->m_Workspace->GetGraph( )->BeginVertices( ); - auto vIt_end = this->m_Workspace->GetGraph( )->EndVertices( ); - for( ; vIt != vIt_end; ++vIt ) - { - std::cout << "NAME: " << vIt->first << " " << vIt->second.GetPointer( ) << std::endl; - vIt->second->Print( std::cout ); - } - - - std::cout << "ok" << std::endl; this->_createBlock( this->m_Workspace->GetFilter( name ) ); - } - else - std::cout << "no" << std::endl; } // rof } @@ -204,8 +188,6 @@ _scaleView( qreal scaleFactor ) void PipelineEditor::QNodesEditorCanvas:: _createBlock( TFilter* f ) { - std::cout << "ptr: " << f << std::endl; - if( f == NULL ) return; diff --git a/lib/cpExtensions/DataStructures/Graph.hxx b/lib/cpExtensions/DataStructures/Graph.hxx index 800bb8e..c567f39 100644 --- a/lib/cpExtensions/DataStructures/Graph.hxx +++ b/lib/cpExtensions/DataStructures/Graph.hxx @@ -103,7 +103,6 @@ template< class V, class C, class I > V& cpExtensions::DataStructures::Graph< V, C, I >:: GetVertex( const I& index ) { - static V zero; return( this->m_Vertices[ index ] ); } diff --git a/lib/cpPlugins/Interface/Workspace.cxx b/lib/cpPlugins/Interface/Workspace.cxx index 97c3854..fb8f91e 100644 --- a/lib/cpPlugins/Interface/Workspace.cxx +++ b/lib/cpPlugins/Interface/Workspace.cxx @@ -133,27 +133,14 @@ GetGraph( ) const bool cpPlugins::Interface::Workspace:: CreateFilter( const std::string& filter, const std::string& name ) { - std::cout << "wNAME: " << filter << " " << name << std::endl; - - for( - auto i = this->m_Graph->BeginVertices( ); - i != this->m_Graph->EndVertices( ); - ++i - ) - std::cout << "wOBJ: " << i->first << std::endl; - - // Get or create new filter from name if( !( this->m_Graph->HasVertexIndex( name ) ) ) { - std::cout << "wok" << std::endl; - TFilter::Pointer f = this->m_Interface.CreateObject( filter ); if( f.IsNotNull( ) ) { f->SetName( name ); TObject::Pointer o = f.GetPointer( ); - o->Print( std::cout ); this->m_Graph->InsertVertex( name, o ); return( true ); } @@ -161,10 +148,7 @@ CreateFilter( const std::string& filter, const std::string& name ) return( false ); } else - { - std::cout << "wno" << std::endl; return( true ); - } } // ------------------------------------------------------------------------- @@ -249,6 +233,16 @@ GetFilter( const std::string& name ) const return( f ); } +// ------------------------------------------------------------------------- +bool cpPlugins::Interface::Workspace:: +HasFilter( const std::string& name ) const +{ + if( this->m_Graph->HasVertexIndex( name ) ) + return( this->GetFilter( name ) != NULL ); + else + return( false ); +} + // ------------------------------------------------------------------------- bool cpPlugins::Interface::Workspace:: Reduce( const std::string& name ) diff --git a/lib/cpPlugins/Interface/Workspace.h b/lib/cpPlugins/Interface/Workspace.h index 6cf157d..6618644 100644 --- a/lib/cpPlugins/Interface/Workspace.h +++ b/lib/cpPlugins/Interface/Workspace.h @@ -68,6 +68,7 @@ namespace cpPlugins const TParameters* GetParameters( const std::string& name ) const; TFilter* GetFilter( const std::string& name ); const TFilter* GetFilter( const std::string& name ) const; + bool HasFilter( const std::string& name ) const; // Graph reduction bool Reduce( const std::string& name );