+++ /dev/null
-#include "Edge.h"
-#include "Node.h"
-
-#include <QPainter>
-
-// -------------------------------------------------------------------------
-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$
+++ /dev/null
-#ifndef __PIPELINEEDITOR__EDGE__H__
-#define __PIPELINEEDITOR__EDGE__H__
-
-#include <QGraphicsItem>
-
-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$
+++ /dev/null
-#include "Node.h"
-#include "Edge.h"
-#include "GraphCanvas.h"
-
-#include <QFontMetricsF>
-#include <QGraphicsWidget>
-#include <QGraphicsSceneHoverEvent>
-
-#include <cpPlugins/Interface/Object.h>
-#include <cpPlugins/Interface/DataObject.h>
-#include <cpPlugins/Interface/ProcessObject.h>
-
-#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$
+++ /dev/null
-#ifndef __PIPELINEEDITOR__NODE__H__
-#define __PIPELINEEDITOR__NODE__H__
-
-#include <map>
-#include <set>
-
-#include <QGraphicsItem>
-#include <QList>
-
-
-#include <iostream>
-
-
-// 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$
this->addOutputPort( n );\r
}\r
\r
-// -------------------------------------------------------------------------\r
-void PipelineEditor::QNEBlock::\r
-save( QDataStream& ds )\r
-{\r
- ds << pos( );\r
-\r
- int count( 0 );\r
-\r
- foreach( QGraphicsItem* port_, children( ) )\r
- {\r
- if( port_->type( ) != QNEPort::Type )\r
- continue;\r
- count++;\r
-\r
- } // rof\r
-\r
- ds << count;\r
-\r
- foreach( QGraphicsItem* port_, children( ) )\r
- {\r
- if( port_->type( ) != QNEPort::Type )\r
- continue;\r
-\r
- QNEPort* port = ( QNEPort* ) port_;\r
- ds << ( quint64 ) port;\r
- ds << port->portName( );\r
- ds << port->isOutput( );\r
- ds << port->portFlags( );\r
-\r
- } // rof\r
-}\r
-\r
-// -------------------------------------------------------------------------\r
-void PipelineEditor::QNEBlock::\r
-load( QDataStream& ds, QMap<quint64, QNEPort*>& portMap )\r
-{\r
- QPointF p;\r
- ds >> p;\r
- this->setPos( p );\r
- int count;\r
- ds >> count;\r
- for( int i = 0; i < count; i++ )\r
- {\r
- QString name;\r
- bool output;\r
- int flags;\r
- quint64 ptr;\r
-\r
- ds >> ptr;\r
- ds >> name;\r
- ds >> output;\r
- ds >> flags;\r
- portMap[ptr] = this->addPort( name, output, flags, ptr );\r
-\r
- } // rof\r
-}\r
-\r
// -------------------------------------------------------------------------\r
void PipelineEditor::QNEBlock::\r
paint(\r
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND\r
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */\r
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+*/\r
\r
#ifndef __PIPELINEEDITOR__QNEBLOCK__H__\r
#define __PIPELINEEDITOR__QNEBLOCK__H__\r
QNEPort* addOutputPort( const QString& name );\r
void addInputPorts( const QStringList& names );\r
void addOutputPorts( const QStringList& names );\r
- void save( QDataStream& ds );\r
- void load( QDataStream& ds, QMap< quint64, QNEPort* >& portMap );\r
void paint(\r
QPainter* painter,\r
const QStyleOptionGraphicsItem* option,\r
return( this->m_Port2 );\r
}\r
\r
-// -------------------------------------------------------------------------\r
-void PipelineEditor::QNEConnection::\r
-save( QDataStream& ds )\r
-{\r
- ds << ( quint64 ) this->m_Port1;\r
- ds << ( quint64 ) this->m_Port2;\r
-}\r
-\r
-// -------------------------------------------------------------------------\r
-void PipelineEditor::QNEConnection::\r
-load( QDataStream& ds, const QMap< quint64, QNEPort* >& portMap )\r
-{\r
- quint64 ptr1;\r
- quint64 ptr2;\r
- ds >> ptr1;\r
- ds >> ptr2;\r
-\r
- this->setPort1( portMap[ ptr1 ] );\r
- this->setPort2( portMap[ ptr2 ] );\r
- this->updatePosFromPorts( );\r
- this->updatePath( );\r
-}\r
-\r
// eof - $RCSfile$\r
QNEPort* port1( ) const;\r
QNEPort* port2( ) const;\r
\r
- void save( QDataStream& ds );\r
- void load( QDataStream& ds, const QMap< quint64, QNEPort* >& portMap );\r
-\r
int type( ) const { return Type; }\r
\r
private:\r
+++ /dev/null
-/* Copyright (c) 2012, STANISLAW ADASZEWSKI\r
-All rights reserved.\r
-\r
-Redistribution and use in source and binary forms, with or without\r
-modification, are permitted provided that the following conditions are met:\r
- * Redistributions of source code must retain the above copyright\r
- notice, this list of conditions and the following disclaimer.\r
- * Redistributions in binary form must reproduce the above copyright\r
- notice, this list of conditions and the following disclaimer in the\r
- documentation and/or other materials provided with the distribution.\r
- * Neither the name of STANISLAW ADASZEWSKI nor the\r
- names of its contributors may be used to endorse or promote products\r
- derived from this software without specific prior written permission.\r
-\r
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND\r
-ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r
-DISCLAIMED. IN NO EVENT SHALL STANISLAW ADASZEWSKI BE LIABLE FOR ANY\r
-DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
-(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
-LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND\r
-ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */\r
-\r
-#include "QNEMainWindow.h"\r
-#include "ui_QNEMainWindow.h"\r
-\r
-#include "QNEBlock.h"\r
-#include "QNodesEditor.h"\r
-\r
-#include <QGraphicsScene>\r
-#include <QFileDialog>\r
-\r
-#include "QNEPort.h"\r
-\r
-QNEMainWindow::QNEMainWindow(QWidget *parent) :\r
- QMainWindow(parent),\r
- ui(new Ui::QNEMainWindow)\r
-{\r
- ui->setupUi(this);\r
-\r
- QGraphicsScene *s = new QGraphicsScene();\r
- ui->graphicsView->setScene(s);\r
- ui->graphicsView->setRenderHint(QPainter::Antialiasing);\r
- // ui->graphicsView->setDragMode(QGraphicsView::ScrollHandDrag);\r
-\r
- QNEBlock *b = new QNEBlock(0, s);\r
- b->addPort("test", 0, QNEPort::NamePort);\r
- b->addPort("TestBlock", 0, QNEPort::TypePort);\r
- b->addInputPort("in1");\r
- b->addInputPort("in2");\r
- b->addInputPort("in3");\r
- b->addOutputPort("out1");\r
- b->addOutputPort("out2");\r
- b->addOutputPort("out3");\r
-\r
- b = b->clone();\r
- b->setPos(150, 0);\r
-\r
- b = b->clone();\r
- b->setPos(150, 150);\r
-\r
- nodesEditor = new QNodesEditor(this);\r
- nodesEditor->install(s);\r
-\r
- connect(ui->action_Save, SIGNAL(triggered()), this, SLOT(saveFile()));\r
- connect(ui->action_Load, SIGNAL(triggered()), this, SLOT(loadFile()));\r
- connect(ui->action_Quit, SIGNAL(triggered()), qApp, SLOT(quit()));\r
-\r
- ui->toolBar->addAction("Add block", this, SLOT(addBlock()));\r
-}\r
-\r
-QNEMainWindow::~QNEMainWindow()\r
-{\r
- delete ui;\r
-}\r
-\r
-void QNEMainWindow::saveFile()\r
-{\r
- QString fname = QFileDialog::getSaveFileName();\r
- if (fname.isEmpty())\r
- return;\r
-\r
- QFile f(fname);\r
- f.open(QFile::WriteOnly);\r
- QDataStream ds(&f);\r
- nodesEditor->save(ds);\r
-}\r
-\r
-void QNEMainWindow::loadFile()\r
-{\r
- QString fname = QFileDialog::getOpenFileName();\r
- if (fname.isEmpty())\r
- return;\r
-\r
- QFile f(fname);\r
- f.open(QFile::ReadOnly);\r
- QDataStream ds(&f);\r
- nodesEditor->load(ds);\r
-}\r
-\r
-void QNEMainWindow::addBlock()\r
-{\r
- QNEBlock *b = new QNEBlock(0, ui->graphicsView->scene());\r
- static const char* names[] = {"Vin", "Voutsadfasdf", "Imin", "Imax", "mul", "add", "sub", "div", "Conv", "FFT"};\r
- for (int i = 0; i < 4 + rand() % 3; i++)\r
- {\r
- b->addPort(names[rand() % 10], rand() % 2, 0, 0);\r
- b->setPos(ui->graphicsView->sceneRect().center().toPoint());\r
- }\r
-}\r
+++ /dev/null
-/* Copyright (c) 2012, STANISLAW ADASZEWSKI\r
-All rights reserved.\r
-\r
-Redistribution and use in source and binary forms, with or without\r
-modification, are permitted provided that the following conditions are met:\r
- * Redistributions of source code must retain the above copyright\r
- notice, this list of conditions and the following disclaimer.\r
- * Redistributions in binary form must reproduce the above copyright\r
- notice, this list of conditions and the following disclaimer in the\r
- documentation and/or other materials provided with the distribution.\r
- * Neither the name of STANISLAW ADASZEWSKI nor the\r
- names of its contributors may be used to endorse or promote products\r
- derived from this software without specific prior written permission.\r
-\r
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND\r
-ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r
-DISCLAIMED. IN NO EVENT SHALL STANISLAW ADASZEWSKI BE LIABLE FOR ANY\r
-DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
-(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
-LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND\r
-ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */\r
-\r
-#ifndef QNEMAINWINDOW_H\r
-#define QNEMAINWINDOW_H\r
-\r
-#include <QMainWindow>\r
-\r
-namespace Ui {\r
- class QNEMainWindow;\r
-}\r
-\r
-class QNodesEditor;\r
-\r
-class QNEMainWindow : public QMainWindow\r
-{\r
- Q_OBJECT\r
-\r
-public:\r
- explicit QNEMainWindow(QWidget *parent = 0);\r
- ~QNEMainWindow();\r
-\r
-private slots:\r
- void saveFile();\r
- void loadFile();\r
- void addBlock();\r
-\r
-private:\r
- Ui::QNEMainWindow *ui;\r
- QNodesEditor *nodesEditor;\r
-};\r
-\r
-#endif // QNEMAINWINDOW_H\r
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>\r
-<ui version="4.0">\r
- <class>QNEMainWindow</class>\r
- <widget class="QMainWindow" name="QNEMainWindow">\r
- <property name="geometry">\r
- <rect>\r
- <x>0</x>\r
- <y>0</y>\r
- <width>540</width>\r
- <height>389</height>\r
- </rect>\r
- </property>\r
- <property name="windowTitle">\r
- <string>QNodesEditor Demo (c) 2012 STANISLAW ADASZEWSKI, http://algoholic.eu</string>\r
- </property>\r
- <widget class="QWidget" name="centralWidget">\r
- <layout class="QVBoxLayout" name="verticalLayout">\r
- <item>\r
- <widget class="QGraphicsView" name="graphicsView"/>\r
- </item>\r
- </layout>\r
- </widget>\r
- <widget class="QMenuBar" name="menuBar">\r
- <property name="geometry">\r
- <rect>\r
- <x>0</x>\r
- <y>0</y>\r
- <width>540</width>\r
- <height>20</height>\r
- </rect>\r
- </property>\r
- <widget class="QMenu" name="menu_File">\r
- <property name="title">\r
- <string>&File</string>\r
- </property>\r
- <addaction name="action_Save"/>\r
- <addaction name="action_Load"/>\r
- <addaction name="separator"/>\r
- <addaction name="action_Quit"/>\r
- </widget>\r
- <addaction name="menu_File"/>\r
- </widget>\r
- <widget class="QToolBar" name="toolBar">\r
- <property name="windowTitle">\r
- <string>toolBar</string>\r
- </property>\r
- <attribute name="toolBarArea">\r
- <enum>TopToolBarArea</enum>\r
- </attribute>\r
- <attribute name="toolBarBreak">\r
- <bool>false</bool>\r
- </attribute>\r
- </widget>\r
- <action name="action_Save">\r
- <property name="text">\r
- <string>&Save</string>\r
- </property>\r
- </action>\r
- <action name="action_Load">\r
- <property name="text">\r
- <string>&Load</string>\r
- </property>\r
- </action>\r
- <action name="action_Quit">\r
- <property name="text">\r
- <string>&Quit</string>\r
- </property>\r
- </action>\r
- </widget>\r
- <layoutdefault spacing="6" margin="11"/>\r
- <resources/>\r
- <connections/>\r
-</ui>\r
*/\r
\r
#include "QNEPort.h"\r
+#include "QNEConnection.h"\r
\r
#include <QGraphicsScene>\r
#include <QFontMetrics>\r
#include <QPen>\r
\r
-#include "QNEConnection.h"\r
-\r
// -------------------------------------------------------------------------\r
PipelineEditor::QNEPort::\r
QNEPort( QGraphicsItem* parent, QGraphicsScene* scene )\r
typedef QNEPort Self;\r
typedef QGraphicsPathItem Superclass;\r
\r
- public:\r
enum { Type = QGraphicsItem::UserType + 1 };\r
enum { NamePort = 1, TypePort = 2 };\r
\r
+ public:\r
QNEPort( QGraphicsItem* parent = 0, QGraphicsScene* scene = NULL );\r
virtual ~QNEPort( );\r
\r
QVector< QNEConnection* >& connections( );\r
void setPortFlags( int f );\r
\r
+ QNEBlock* block( ) const;\r
+ quint64 ptr( );\r
+ void setPtr( quint64 p );\r
+ bool isConnected( QNEPort* other );\r
+\r
inline const QString& portName( ) const\r
{ return( this->m_Name ); }\r
inline int portFlags( ) const\r
int type( ) const\r
{ return( this->Type ); }\r
\r
- QNEBlock* block( ) const;\r
- quint64 ptr( );\r
- void setPtr( quint64 p );\r
- bool isConnected( QNEPort* other );\r
-\r
protected:\r
QVariant itemChange( GraphicsItemChange change, const QVariant& value );\r
\r
}\r
break;\r
}\r
- }\r
+ } // hctiws\r
return( this->Superclass::eventFilter( o, e ) );\r
}\r
\r
-// -------------------------------------------------------------------------\r
-void PipelineEditor::QNodesEditor::\r
-save( QDataStream& ds )\r
-{\r
- foreach( QGraphicsItem* item, this->m_Scene->items( ) )\r
- if( item->type( ) == QNEBlock::Type )\r
- {\r
- ds << item->type( );\r
- ( ( QNEBlock* ) item )->save( ds );\r
- }\r
-\r
- foreach( QGraphicsItem* item, this->m_Scene->items( ) )\r
- if( item->type( ) == QNEConnection::Type )\r
- {\r
- ds << item->type( );\r
- ( ( QNEConnection* ) item )->save( ds );\r
- }\r
-}\r
-\r
-// -------------------------------------------------------------------------\r
-void PipelineEditor::QNodesEditor::\r
-load( QDataStream& ds )\r
-{\r
- this->m_Scene->clear( );\r
-\r
- QMap<quint64, QNEPort*> portMap;\r
-\r
- while ( !ds.atEnd( ) )\r
- {\r
- int type;\r
- ds >> type;\r
- if( type == QNEBlock::Type )\r
- {\r
- QNEBlock* block = new QNEBlock( 0, this->m_Scene );\r
- block->load( ds, portMap );\r
- }\r
- else if( type == QNEConnection::Type )\r
- {\r
- this->m_Conn = new QNEConnection( 0, this->m_Scene );\r
- this->m_Conn->load( ds, portMap );\r
- }\r
- }\r
-}\r
-\r
// eof - $RCSfile$\r
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND\r
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */\r
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+*/\r
\r
#ifndef __PIPELINEEDITOR__QNODESEDITOR__H__\r
#define __PIPELINEEDITOR__QNODESEDITOR__H__\r
\r
bool eventFilter( QObject* o, QEvent* e );\r
\r
- void save( QDataStream& ds );\r
- void load( QDataStream& ds );\r
-\r
private:\r
QGraphicsItem* itemAt( const QPointF& pos );\r
\r
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( );
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
}
void PipelineEditor::QNodesEditorCanvas::
_createBlock( TFilter* f )
{
- std::cout << "ptr: " << f << std::endl;
-
if( f == NULL )
return;
V& cpExtensions::DataStructures::Graph< V, C, I >::
GetVertex( const I& index )
{
- static V zero;
return( this->m_Vertices[ index ] );
}
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 );
}
return( false );
}
else
- {
- std::cout << "wno" << std::endl;
return( true );
- }
}
// -------------------------------------------------------------------------
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 )
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 );