]> Creatis software - cpPlugins.git/commitdiff
More on graph editor
authorLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Sat, 2 Jan 2016 18:56:31 +0000 (13:56 -0500)
committerLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Sat, 2 Jan 2016 18:56:31 +0000 (13:56 -0500)
15 files changed:
appli/cpPipelineEditor/QNEBlock.cxx
appli/cpPipelineEditor/QNEBlock.h
appli/cpPipelineEditor/QNEConnection.cxx
appli/cpPipelineEditor/QNEConnection.h
appli/cpPipelineEditor/QNEPort.cxx
appli/cpPipelineEditor/QNEPort.h
appli/cpPipelineEditor/QNodesEditor.cxx
appli/cpPipelineEditor/QNodesEditor.h
appli/cpPipelineEditor/QNodesEditorCanvas.cxx
appli/cpPipelineEditor/QNodesEditorCanvas.h
appli/cpPipelineEditor/cpPipelineEditor.cxx
appli/cpPipelineEditor/cpPipelineEditor.h
lib/cpPlugins/Interface/Parameters.cxx
lib/cpPlugins/Interface/Parameters.h
lib/cpPlugins/Interface/WorkspaceIO.cxx

index 0c6900d559cff82ee176e4898e11624841379eeb..071effc1077bf48a23f420f4514a9987938b043d 100644 (file)
@@ -39,15 +39,19 @@ PipelineEditor::QNEBlock::
 QNEBlock( QGraphicsItem* parent, QGraphicsScene* scene )\r
   : Superclass( parent, scene ),\r
     m_HorzMargin( 20 ),\r
-    m_VertMargin( 5 )\r
+    m_VertMargin( 5 ),\r
+    m_NamePort( NULL ),\r
+    m_TypePort( NULL )\r
 {\r
   QPainterPath p;\r
   p.addRoundedRect( -50, -15, 100, 30, 5, 5 );\r
+\r
   this->setPath( p );\r
   this->setPen( QPen( Qt::darkGreen ) );\r
   this->setBrush( Qt::green );\r
   this->setFlag( QGraphicsItem::ItemIsMovable );\r
   this->setFlag( QGraphicsItem::ItemIsSelectable );\r
+\r
   this->m_Width = this->m_HorzMargin;\r
   this->m_Height = this->m_VertMargin;\r
 }\r
@@ -59,77 +63,85 @@ PipelineEditor::QNEBlock::
 }\r
 \r
 // -------------------------------------------------------------------------\r
-PipelineEditor::QNEPort* PipelineEditor::QNEBlock::\r
-addPort( const QString& name, bool isOutput, int flags, int ptr )\r
+void PipelineEditor::QNEBlock::\r
+setNamePort( const QString& txt )\r
 {\r
-  QNEPort* port = new QNEPort( this );\r
-  port->setName( name );\r
-  port->setIsOutput( isOutput );\r
-  port->setNEBlock( this );\r
-  port->setPortFlags( flags );\r
-  port->setPtr( ptr );\r
-\r
-  QFontMetrics fm( this->scene( )->font( ) );\r
-  int w = fm.width( name );\r
-  int h = fm.height( );\r
-  if( w > this->m_Width - this->m_HorzMargin )\r
-    this->m_Width = w + this->m_HorzMargin;\r
-  this->m_Height += h;\r
-\r
-  QPainterPath p;\r
-  p.addRoundedRect(\r
-    -this->m_Width / 2,\r
-    -this->m_Height / 2,\r
-    this->m_Width,\r
-    this->m_Height, 5, 5\r
-    );\r
-  this->setPath( p );\r
-\r
-  int y = -this->m_Height / 2 + this->m_VertMargin + port->radius( );\r
-  foreach( QGraphicsItem* port_, children( ) )\r
-  {\r
-    if( port_->type( ) != QNEPort::Type )\r
-      continue;\r
-\r
-    QNEPort* port = ( QNEPort* ) port_;\r
-    if( port->isOutput( ) )\r
-      port->setPos( this->m_Width/2 + port->radius( ), y );\r
-    else\r
-      port->setPos( -this->m_Width/2 - port->radius( ), y );\r
-    y += h;\r
-\r
-  } // rof\r
-  return( port );\r
+  if( this->m_NamePort == NULL )\r
+    this->m_NamePort = new QNENamePort( this );\r
+  this->m_NamePort->setName( txt );\r
+  this->_configPort( this->m_NamePort );\r
 }\r
 \r
 // -------------------------------------------------------------------------\r
-PipelineEditor::QNEPort* PipelineEditor::QNEBlock::\r
-addInputPort( const QString& name )\r
+void PipelineEditor::QNEBlock::\r
+setTypePort( const QString& txt )\r
 {\r
-  return( this->addPort( name, false ) );\r
+  if( this->m_TypePort == NULL )\r
+    this->m_TypePort = new QNETypePort( this );\r
+  this->m_TypePort->setName( txt );\r
+  this->_configPort( this->m_TypePort );\r
 }\r
 \r
 // -------------------------------------------------------------------------\r
-PipelineEditor::QNEPort* PipelineEditor::QNEBlock::\r
-addOutputPort( const QString& name )\r
+void PipelineEditor::QNEBlock::\r
+addInputPort( const QString& txt )\r
 {\r
-  return( this->addPort( name, true ) );\r
+  QNEInputPort* ip = new QNEInputPort( this );\r
+  ip->setName( txt );\r
+  this->m_InputPorts.push_back( ip );\r
+  this->_configPort( ip );\r
 }\r
 \r
 // -------------------------------------------------------------------------\r
 void PipelineEditor::QNEBlock::\r
-addInputPorts( const QStringList& names )\r
+addOutputPort( const QString& txt )\r
 {\r
-  foreach( QString n, names )\r
-    this->addInputPort( n );\r
+  QNEOutputPort* op = new QNEOutputPort( this );\r
+  op->setName( txt );\r
+  this->m_OutputPorts.push_back( op );\r
+  this->_configPort( op );\r
 }\r
 \r
 // -------------------------------------------------------------------------\r
-void PipelineEditor::QNEBlock::\r
-addOutputPorts( const QStringList& names )\r
+QVector< PipelineEditor::QNEPort* > PipelineEditor::QNEBlock::\r
+ports( )\r
 {\r
-  foreach( QString n, names )\r
-    this->addOutputPort( n );\r
+  QVector< QNEPort* > res;\r
+  foreach( QGraphicsItem* i, this->childItems( ) )\r
+  {\r
+    QNEPort* p = dynamic_cast< QNEPort* >( i );\r
+    if( p != NULL )\r
+      res.append( p );\r
+\r
+  } // rof\r
+  return( res );\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+PipelineEditor::QNEBlock* PipelineEditor::QNEBlock::\r
+clone( )\r
+{\r
+  QNEBlock* b = new QNEBlock( 0, this->scene( ) );\r
+  foreach( QGraphicsItem* i, this->childItems( ) )\r
+  {\r
+    QNENamePort* np = dynamic_cast< QNENamePort* >( i );\r
+    if( np != NULL )\r
+      b->setNamePort( np->name( ) );\r
+\r
+    QNETypePort* tp = dynamic_cast< QNETypePort* >( i );\r
+    if( tp != NULL )\r
+      b->setTypePort( tp->name( ) );\r
+\r
+    QNEInputPort* ip = dynamic_cast< QNEInputPort* >( i );\r
+    if( ip != NULL )\r
+      b->addInputPort( ip->name( ) );\r
+\r
+    QNEOutputPort* op = dynamic_cast< QNEOutputPort* >( i );\r
+    if( op != NULL )\r
+      b->addOutputPort( op->name( ) );\r
+\r
+  } // rof\r
+  return( b );\r
 }\r
 \r
 // -------------------------------------------------------------------------\r
@@ -156,48 +168,48 @@ paint(
 }\r
 \r
 // -------------------------------------------------------------------------\r
-PipelineEditor::QNEBlock* PipelineEditor::QNEBlock::\r
-clone( )\r
+QVariant PipelineEditor::QNEBlock::\r
+itemChange( GraphicsItemChange change, const QVariant& value )\r
 {\r
-  QNEBlock* b = new QNEBlock( 0, this->scene( ) );\r
-\r
-  foreach( QGraphicsItem* port_, childItems( ) )\r
-  {\r
-    if( port_->type( ) == QNEPort::Type )\r
-    {\r
-      QNEPort* port = ( QNEPort* ) port_;\r
-      b->addPort(\r
-        port->portName( ),\r
-        port->isOutput( ),\r
-        port->portFlags( ),\r
-        port->ptr( )\r
-        );\r
-\r
-    } // fi\r
-\r
-  } // rof\r
-  return( b );\r
+  return( value );\r
 }\r
 \r
 // -------------------------------------------------------------------------\r
-QVector< PipelineEditor::QNEPort* > PipelineEditor::QNEBlock::\r
-ports( )\r
+void PipelineEditor::QNEBlock::\r
+_configPort( QNEPort* port )\r
 {\r
-  QVector< PipelineEditor::QNEPort* > res;\r
-  foreach( QGraphicsItem* port_, childItems( ) )\r
+  port->setBlock( this );\r
+\r
+  QFontMetrics fm( this->scene( )->font( ) );\r
+  int w = fm.width( port->name( ) );\r
+  int h = fm.height( );\r
+  if( w > this->m_Width - this->m_HorzMargin )\r
+    this->m_Width = w + this->m_HorzMargin;\r
+  this->m_Height += h;\r
+\r
+  QPainterPath pth;\r
+  pth.addRoundedRect(\r
+    -this->m_Width / 2,\r
+    -this->m_Height / 2,\r
+    this->m_Width,\r
+    this->m_Height, 5, 5\r
+    );\r
+  this->setPath( pth );\r
+\r
+  int y = -this->m_Height / 2 + this->m_VertMargin + port->radius( );\r
+  foreach( QGraphicsItem* i, this->children( ) )\r
   {\r
-    if( port_->type( ) == QNEPort::Type )\r
-      res.append( ( QNEPort* ) port_ );\r
+    QNEPort* p = dynamic_cast< QNEPort* >( i );\r
+    if( p == NULL )\r
+      continue;\r
 \r
-  } // rof\r
-  return( res );\r
-}\r
+    if( dynamic_cast< QNEOutputPort* >( p ) != NULL )\r
+      p->setPos( this->m_Width / 2 + port->radius( ), y );\r
+    else\r
+      p->setPos( -this->m_Width / 2 - port->radius( ), y );\r
+    y += h;\r
 \r
-// -------------------------------------------------------------------------\r
-QVariant PipelineEditor::QNEBlock::\r
-itemChange( GraphicsItemChange change, const QVariant& value )\r
-{\r
-  return( value );\r
+  } // rof\r
 }\r
 \r
 // eof - $RCSfile$\r
index 524988aab73cb106c5e0cced727b0eb2f7a648d8..6b591ac726c15b8cae1016398d936289ff762bf6 100644 (file)
 namespace PipelineEditor\r
 {\r
   class QNEPort;\r
+  class QNENamePort;\r
+  class QNETypePort;\r
+  class QNEInputPort;\r
+  class QNEOutputPort;\r
 \r
   class QNEBlock\r
     : public QGraphicsPathItem\r
@@ -41,37 +45,59 @@ namespace PipelineEditor
     typedef QGraphicsPathItem Superclass;\r
   \r
   public:\r
-    enum { Type = QGraphicsItem::UserType + 3 };\r
+    enum { Type = QGraphicsItem::UserType + 6 };\r
 \r
     QNEBlock( QGraphicsItem* parent = NULL, QGraphicsScene* scene = NULL );\r
     virtual ~QNEBlock( );\r
 \r
-    QNEPort* addPort(\r
-      const QString& name, bool isOutput, int flags = 0, int ptr = 0\r
-      );\r
-    QNEPort* addInputPort( const QString& name );\r
-    QNEPort* addOutputPort( const QString& name );\r
-    void addInputPorts( const QStringList& names );\r
-    void addOutputPorts( const QStringList& names );\r
+    void setNamePort( const QString& txt );\r
+    void setTypePort( const QString& txt );\r
+    void addInputPort( const QString& txt );\r
+    void addOutputPort( const QString& txt );\r
+    QVector< QNEPort* > ports( );\r
+\r
+    inline QNENamePort* namePort( )\r
+      { return( this->m_NamePort ); }\r
+    inline QNETypePort* typePort( )\r
+      { return( this->m_TypePort ); }\r
+    inline QVector< QNEInputPort* >& inputPorts( )\r
+      { return( this->m_InputPorts ); }\r
+    inline QVector< QNEOutputPort* >& outputPorts( )\r
+      { return( this->m_OutputPorts ); }\r
+\r
+    inline const QNENamePort* namePort( ) const\r
+      { return( this->m_NamePort ); }\r
+    inline const QNETypePort* typePort( ) const\r
+      { return( this->m_TypePort ); }\r
+    inline const QVector< QNEInputPort* >& inputPorts( ) const\r
+      { return( this->m_InputPorts ); }\r
+    inline const QVector< QNEOutputPort* >& outputPorts( ) const\r
+      { return( this->m_OutputPorts ); }\r
+\r
+    QNEBlock* clone( );\r
+    inline int type( ) const\r
+      { return( this->Type ); }\r
+\r
     void paint(\r
       QPainter* painter,\r
       const QStyleOptionGraphicsItem* option,\r
       QWidget* widget\r
       );\r
-    QNEBlock* clone( );\r
-    QVector< QNEPort* > ports( );\r
-\r
-    int type( ) const\r
-      { return( this->Type ); }\r
-\r
+    \r
   protected:\r
     QVariant itemChange( GraphicsItemChange change, const QVariant& value );\r
+    void _configPort( QNEPort* port );\r
 \r
   private:\r
     int m_HorzMargin;\r
     int m_VertMargin;\r
     int m_Width;\r
     int m_Height;\r
+\r
+    QNENamePort* m_NamePort;\r
+    QNETypePort* m_TypePort;\r
+    QVector< QNEInputPort* >  m_InputPorts;\r
+    QVector< QNEOutputPort* > m_OutputPorts;\r
   };\r
 \r
 } // ecapseman\r
index 42199fd0d0ef891934ea81501fbca10919cad8bc..eb0f3bb36691cfd2c6f3598282d6b149f723438d 100644 (file)
@@ -25,7 +25,6 @@
 */\r
 \r
 #include "QNEConnection.h"\r
-\r
 #include "QNEPort.h"\r
 \r
 #include <QBrush>\r
@@ -40,22 +39,21 @@ QNEConnection( QGraphicsItem* parent, QGraphicsScene* scene )
   this->setPen( QPen( Qt::black, 2 ) );\r
   this->setBrush( Qt::NoBrush );\r
   this->setZValue( -1 );\r
-  this->m_Port1 = 0;\r
-  this->m_Port2 = 0;\r
+  this->m_Port1 = NULL;\r
+  this->m_Port2 = NULL;\r
 }\r
 \r
 // -------------------------------------------------------------------------\r
 PipelineEditor::QNEConnection::\r
 ~QNEConnection( )\r
 {\r
-  if ( this->m_Port1 )\r
-    this->m_Port1->connections( ).remove(\r
-      this->m_Port1->connections( ).indexOf( this )\r
-      );\r
-  if ( this->m_Port2 )\r
-    this->m_Port2->connections( ).remove(\r
-      this->m_Port2->connections( ).indexOf( this )\r
-      );\r
+  QNEOutputPort* op = dynamic_cast< QNEOutputPort* >( this->m_Port1 );\r
+  if( op != NULL )\r
+    op->connections( ).remove( op->connections( ).indexOf( this ) );\r
+\r
+  QNEInputPort* ip = dynamic_cast< QNEInputPort* >( this->m_Port2 );\r
+  if( ip != NULL )\r
+    ip->setConnection( NULL );\r
 }\r
 \r
 // -------------------------------------------------------------------------\r
@@ -76,16 +74,30 @@ setPos2( const QPointF& p )
 void PipelineEditor::QNEConnection::\r
 setPort1( QNEPort* p )\r
 {\r
-  this->m_Port1 = p;\r
-  this->m_Port1->connections( ).append( this );\r
+  QNEOutputPort* op = dynamic_cast< QNEOutputPort* >( p );\r
+  if( op != NULL )\r
+  {\r
+    op->connections( ).append( this );\r
+    this->m_Port1 = op;\r
+\r
+  } // fi\r
 }\r
 \r
 // -------------------------------------------------------------------------\r
 void PipelineEditor::QNEConnection::\r
 setPort2( QNEPort* p )\r
 {\r
-  this->m_Port2 = p;\r
-  this->m_Port2->connections( ).append( this );\r
+  QNEInputPort* ip = dynamic_cast< QNEInputPort* >( p );\r
+  if( ip != NULL )\r
+  {\r
+    if( ip->connection( ) == NULL )\r
+    {\r
+      ip->setConnection( this );\r
+      this->m_Port2 = ip;\r
+\r
+    } // fi\r
+\r
+  } // fi\r
 }\r
 \r
 // -------------------------------------------------------------------------\r
@@ -101,16 +113,13 @@ void PipelineEditor::QNEConnection::
 updatePath( )\r
 {\r
   QPainterPath p;\r
-\r
   p.moveTo( this->m_Pos1 );\r
 \r
   qreal dx = this->m_Pos2.x( ) - this->m_Pos1.x( );\r
   qreal dy = this->m_Pos2.y( ) - this->m_Pos1.y( );\r
-\r
-  QPointF ctr1( this->m_Pos1.x( ) + dx * 0.25, this->m_Pos1.y( ) + dy * 0.1 );\r
-  QPointF ctr2( this->m_Pos1.x( ) + dx * 0.75, this->m_Pos1.y( ) + dy * 0.9 );\r
-\r
-  p.cubicTo( ctr1, ctr2, this->m_Pos2 );\r
+  QPointF c1( this->m_Pos1.x( ) + dx * 0.25, this->m_Pos1.y( ) + dy * 0.1 );\r
+  QPointF c2( this->m_Pos1.x( ) + dx * 0.75, this->m_Pos1.y( ) + dy * 0.9 );\r
+  p.cubicTo( c1, c2, this->m_Pos2 );\r
 \r
   this->setPath( p );\r
 }\r
index 54cdf84115644539f82967c55a748a9d64ad3590..7e5a12e41a2a9415f8f6f8001e6ae05809e61556 100644 (file)
@@ -43,7 +43,7 @@ namespace PipelineEditor
     typedef QGraphicsPathItem Superclass;\r
 \r
   public:\r
-    enum { Type = QGraphicsItem::UserType + 2 };\r
+    enum { Type = QGraphicsItem::UserType + 5 };\r
 \r
     QNEConnection( QGraphicsItem* parent = 0, QGraphicsScene* scene = 0 );\r
     virtual ~QNEConnection( );\r
@@ -57,7 +57,8 @@ namespace PipelineEditor
     QNEPort* port1( ) const;\r
     QNEPort* port2( ) const;\r
 \r
-    int type( ) const { return Type; }\r
+    inline int type( ) const\r
+      { return( this->Type ); }\r
 \r
   private:\r
     QPointF m_Pos1;\r
index dbf43463be32b9ed1367dc1f0a3dad565c979bf4..6aa653b1a1987f14f1b8efcabd5397e3ae5a8445 100644 (file)
@@ -41,7 +41,7 @@ QNEPort( QGraphicsItem* parent, QGraphicsScene* scene )
   this->m_Label = new QGraphicsTextItem( this );\r
 \r
   QPainterPath p;\r
-  p.addEllipse( \r
+  p.addEllipse(\r
     -this->m_Radius, -this->m_Radius,\r
     2 * this->m_Radius, 2 * this->m_Radius\r
     );\r
@@ -50,27 +50,24 @@ QNEPort( QGraphicsItem* parent, QGraphicsScene* scene )
   this->setPen( QPen( Qt::darkRed ) );\r
   this->setBrush( Qt::red );\r
   this->setFlag( QGraphicsItem::ItemSendsScenePositionChanges );\r
-  this->m_PortFlags = 0;\r
 }\r
 \r
 // -------------------------------------------------------------------------\r
 PipelineEditor::QNEPort::\r
 ~QNEPort( )\r
 {\r
-  foreach( QNEConnection* conn, this->m_Connections )\r
-    delete conn;\r
 }\r
 \r
 // -------------------------------------------------------------------------\r
 void PipelineEditor::QNEPort::\r
-setNEBlock( QNEBlock *b )\r
+setBlock( QNEBlock* b )\r
 {\r
   this->m_Block = b;\r
 }\r
 \r
 // -------------------------------------------------------------------------\r
 void PipelineEditor::QNEPort::\r
-setName( const QString &n )\r
+setName( const QStringn )\r
 {\r
   this->m_Name = n;\r
   this->m_Label->setPlainText( n );\r
@@ -78,100 +75,184 @@ setName( const QString &n )
 \r
 // -------------------------------------------------------------------------\r
 void PipelineEditor::QNEPort::\r
-setIsOutput( bool o )\r
+setPtr( quint64 p )\r
 {\r
-  this->m_IsOutput = o;\r
+  this->m_Ptr = p;\r
+}\r
 \r
-  QFontMetrics fm( this->scene( )->font( ) );\r
-  QRect r = fm.boundingRect( this->m_Name );\r
+// -------------------------------------------------------------------------\r
+PipelineEditor::QNENamePort::\r
+QNENamePort( QGraphicsItem* parent, QGraphicsScene* scene )\r
+  : Superclass( parent, scene )\r
+{\r
+}\r
 \r
-  int rm = this->m_Radius + this->m_Margin;\r
-  int h = -this->m_Label->boundingRect( ).height( ) / 2;\r
-  if( this->m_IsOutput )\r
-    this->m_Label->setPos(\r
-      -rm - this->m_Label->boundingRect( ).width( ), h\r
-      );\r
-  else\r
-    this->m_Label->setPos( rm, h );\r
+// -------------------------------------------------------------------------\r
+PipelineEditor::QNENamePort::\r
+~QNENamePort( )\r
+{\r
 }\r
 \r
 // -------------------------------------------------------------------------\r
-int PipelineEditor::QNEPort::\r
-radius( )\r
+void PipelineEditor::QNENamePort::\r
+setName( const QString& n )\r
 {\r
-  return( this->m_Radius );\r
+  this->Superclass::setName( n );\r
+\r
+  QFont font( this->scene( )->font( ) );\r
+  font.setBold( true );\r
+  this->m_Label->setFont( font );\r
+  this->setPath( QPainterPath( ) );\r
 }\r
 \r
 // -------------------------------------------------------------------------\r
-bool PipelineEditor::QNEPort::\r
-isOutput( )\r
+bool PipelineEditor::QNENamePort::\r
+isConnected( QNEPort* other )\r
 {\r
-  return( this->m_IsOutput );\r
+  return( false );\r
 }\r
 \r
 // -------------------------------------------------------------------------\r
-QVector< PipelineEditor::QNEConnection* >& PipelineEditor::QNEPort::\r
-connections( )\r
+PipelineEditor::QNETypePort::\r
+QNETypePort( QGraphicsItem* parent, QGraphicsScene* scene )\r
+  : Superclass( parent, scene )\r
 {\r
-  return( this->m_Connections );\r
 }\r
 \r
 // -------------------------------------------------------------------------\r
-void PipelineEditor::QNEPort::\r
-setPortFlags( int f )\r
+PipelineEditor::QNETypePort::\r
+~QNETypePort( )\r
 {\r
-  this->m_PortFlags = f;\r
+}\r
 \r
-  if( this->m_PortFlags & Self::TypePort )\r
-  {\r
-    QFont font( this->scene( )->font( ) );\r
-    font.setItalic( true );\r
-    this->m_Label->setFont( font );\r
-    this->setPath( QPainterPath( ) );\r
-  }\r
-  else if( this->m_PortFlags & Self::NamePort )\r
+// -------------------------------------------------------------------------\r
+void PipelineEditor::QNETypePort::\r
+setName( const QString& n )\r
+{\r
+  this->Superclass::setName( n );\r
+\r
+  QFont font( this->scene( )->font( ) );\r
+  font.setItalic( true );\r
+  this->m_Label->setFont( font );\r
+  this->setPath( QPainterPath( ) );\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+bool PipelineEditor::QNETypePort::\r
+isConnected( QNEPort* other )\r
+{\r
+  return( false );\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+PipelineEditor::QNEInputPort::\r
+QNEInputPort( QGraphicsItem* parent, QGraphicsScene* scene )\r
+  : Superclass( parent, scene ),\r
+    m_Connection( NULL )\r
+{\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+PipelineEditor::QNEInputPort::\r
+~QNEInputPort( )\r
+{\r
+  if( this->m_Connection != NULL )\r
+    delete this->m_Connection;\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+void PipelineEditor::QNEInputPort::\r
+setName( const QString& n )\r
+{\r
+  this->Superclass::setName( n );\r
+\r
+  QFontMetrics fm( this->scene( )->font( ) );\r
+  QRect r = fm.boundingRect( this->m_Name );\r
+  int rm = this->m_Radius + this->m_Margin;\r
+  int h = -this->m_Label->boundingRect( ).height( ) / 2;\r
+  this->m_Label->setPos( rm, h );\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+bool PipelineEditor::QNEInputPort::\r
+isConnected( QNEPort* other )\r
+{\r
+  if( this->m_Connection != NULL )\r
+    return(\r
+      this->m_Connection->port1( ) == other &&\r
+      this->m_Connection->port2( ) == this\r
+      );\r
+  else\r
+    return( false );\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+void PipelineEditor::QNEInputPort::\r
+setConnection( QNEConnection* c )\r
+{\r
+  this->m_Connection = c;\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+QVariant PipelineEditor::QNEInputPort::\r
+itemChange( GraphicsItemChange change, const QVariant& value )\r
+{\r
+  if( change == ItemScenePositionHasChanged )\r
   {\r
-    QFont font( this->scene( )->font( ) );\r
-    font.setBold( true );\r
-    this->m_Label->setFont( font );\r
-    this->setPath( QPainterPath( ) );\r
+    if( this->m_Connection != NULL )\r
+    {\r
+      this->m_Connection->updatePosFromPorts( );\r
+      this->m_Connection->updatePath( );\r
+\r
+    } // fi\r
 \r
   } // fi\r
+  return( value );\r
 }\r
 \r
 // -------------------------------------------------------------------------\r
-PipelineEditor::QNEBlock* PipelineEditor::QNEPort::\r
-block( ) const\r
+PipelineEditor::QNEOutputPort::\r
+QNEOutputPort( QGraphicsItem* parent, QGraphicsScene* scene )\r
+  : Superclass( parent, scene )\r
 {\r
-  return( this->m_Block );\r
 }\r
 \r
 // -------------------------------------------------------------------------\r
-quint64 PipelineEditor::QNEPort::\r
-ptr( )\r
+PipelineEditor::QNEOutputPort::\r
+~QNEOutputPort( )\r
 {\r
-  return( this->m_Ptr );\r
+  foreach( QNEConnection* conn, this->m_Connections )\r
+    delete conn;\r
 }\r
 \r
 // -------------------------------------------------------------------------\r
-void PipelineEditor::QNEPort::\r
-setPtr( quint64 p )\r
+void PipelineEditor::QNEOutputPort::\r
+setName( const QString& n )\r
 {\r
-  this->m_Ptr = p;\r
+  this->Superclass::setName( n );\r
+\r
+  QFontMetrics fm( this->scene( )->font( ) );\r
+  QRect r = fm.boundingRect( this->m_Name );\r
+  int rm = this->m_Radius + this->m_Margin;\r
+  int h = -this->m_Label->boundingRect( ).height( ) / 2;\r
+  this->m_Label->setPos(\r
+    -rm - this->m_Label->boundingRect( ).width( ), h\r
+    );\r
 }\r
 \r
 // -------------------------------------------------------------------------\r
-bool PipelineEditor::QNEPort::\r
+bool PipelineEditor::QNEOutputPort::\r
 isConnected( QNEPort* other )\r
 {\r
-  foreach( QNEConnection* conn, this->m_Connections )\r
-    if( conn->port1( ) == other || conn->port2( ) == other )\r
-      return( true );\r
-  return( false );\r
+  auto i = this->m_Connections.begin( );\r
+  bool conn = false;\r
+  for( ; i != this->m_Connections.end( ) && !conn; ++i )\r
+    conn |= ( ( *i )->port1( ) == this && ( *i )->port2( ) == other );\r
+  return( conn );\r
 }\r
 \r
 // -------------------------------------------------------------------------\r
-QVariant PipelineEditor::QNEPort::\r
+QVariant PipelineEditor::QNEOutputPort::\r
 itemChange( GraphicsItemChange change, const QVariant& value )\r
 {\r
   if( change == ItemScenePositionHasChanged )\r
index 1f445d003c0aa1587eba25044172284451741246..383167b9bfcc39d977b4024b612afa43fafaafda 100644 (file)
@@ -44,45 +44,151 @@ namespace PipelineEditor
     typedef QGraphicsPathItem Superclass;\r
 \r
     enum { Type = QGraphicsItem::UserType + 1 };\r
-    enum { NamePort = 1, TypePort = 2 };\r
 \r
   public:\r
-    QNEPort( QGraphicsItem* parent = 0, QGraphicsScene* scene = NULL );\r
+    QNEPort( QGraphicsItem* parent = NULL, QGraphicsScene* scene = NULL );\r
     virtual ~QNEPort( );\r
 \r
-    void setNEBlock( QNEBlock* b );\r
-    void setName( const QString& n );\r
-    void setIsOutput( bool o );\r
-    int radius( );\r
-    bool isOutput( );\r
-    QVector< QNEConnection* >& connections( );\r
-    void setPortFlags( int f );\r
+    void setBlock( QNEBlock* b );\r
+    inline QNEBlock* block( ) const\r
+      { return( this->m_Block ); }\r
+\r
+    virtual void setName( const QString& n );\r
+    inline const QString& name( ) const\r
+      { return( this->m_Name ); }\r
 \r
-    QNEBlock* block( ) const;\r
-    quint64 ptr( );\r
     void setPtr( quint64 p );\r
-    bool isConnected( QNEPort* other );\r
+    inline quint64 ptr( )\r
+      { return( this->m_Ptr ); }\r
 \r
-    inline const QString& portName( ) const\r
-      { return( this->m_Name ); }\r
-    inline int portFlags( ) const\r
-      { return( this->m_PortFlags ); }\r
-    int type( ) const\r
+    inline int radius( ) const\r
+      { return( this->m_Radius ); }\r
+\r
+    virtual bool isConnected( QNEPort* other ) = 0;\r
+    inline int type( ) const\r
       { return( this->Type ); }\r
 \r
   protected:\r
-    QVariant itemChange( GraphicsItemChange change, const QVariant& value );\r
-\r
-  private:\r
     QNEBlock* m_Block;\r
-    QString m_Name;\r
-    bool m_IsOutput;\r
+\r
+    QString            m_Name;\r
     QGraphicsTextItem* m_Label;\r
-    int m_Radius;\r
-    int m_Margin;\r
+    int                m_Radius;\r
+    int                m_Margin;\r
+    quint64            m_Ptr;\r
+  };\r
+\r
+  /**\r
+   */\r
+  class QNENamePort\r
+    : public QNEPort\r
+  {\r
+  public:\r
+    typedef QNENamePort Self;\r
+    typedef QNEPort     Superclass;\r
+\r
+    enum { Type = Superclass::Type + 1 };\r
+\r
+  public:\r
+    QNENamePort( QGraphicsItem* parent = NULL, QGraphicsScene* scene = NULL );\r
+    virtual ~QNENamePort( );\r
+\r
+    virtual void setName( const QString& n );\r
+\r
+    virtual bool isConnected( QNEPort* other );\r
+    inline int type( ) const\r
+      { return( this->Type ); }\r
+  };\r
+\r
+  /**\r
+   */\r
+  class QNETypePort\r
+    : public QNEPort\r
+  {\r
+  public:\r
+    typedef QNETypePort Self;\r
+    typedef QNEPort     Superclass;\r
+\r
+    enum { Type = Superclass::Type + 2 };\r
+\r
+  public:\r
+    QNETypePort( QGraphicsItem* parent = NULL, QGraphicsScene* scene = NULL );\r
+    virtual ~QNETypePort( );\r
+\r
+    virtual void setName( const QString& n );\r
+\r
+    virtual bool isConnected( QNEPort* other );\r
+    inline int type( ) const\r
+      { return( this->Type ); }\r
+  };\r
+\r
+  /**\r
+   */\r
+  class QNEInputPort\r
+    : public QNEPort\r
+  {\r
+  public:\r
+    typedef QNEInputPort Self;\r
+    typedef QNEPort      Superclass;\r
+\r
+    enum { Type = Superclass::Type + 3 };\r
+\r
+  public:\r
+    QNEInputPort( QGraphicsItem* parent = NULL, QGraphicsScene* scene = NULL );\r
+    virtual ~QNEInputPort( );\r
+\r
+    virtual void setName( const QString& n );\r
+\r
+    virtual bool isConnected( QNEPort* other );\r
+    inline int type( ) const\r
+      { return( this->Type ); }\r
+\r
+    void setConnection( QNEConnection* c );\r
+    inline QNEConnection* connection( )\r
+      { return( this->m_Connection ); }\r
+    inline const QNEConnection* connection( ) const\r
+      { return( this->m_Connection ); }\r
+    inline bool hasConnection( ) const\r
+      { return( this->m_Connection != NULL ); }\r
+\r
+  protected:\r
+    QVariant itemChange( GraphicsItemChange change, const QVariant& value );\r
+\r
+  protected:\r
+    QNEConnection* m_Connection;\r
+  };\r
+\r
+  /**\r
+   */\r
+  class QNEOutputPort\r
+    : public QNEPort\r
+  {\r
+  public:\r
+    typedef QNEOutputPort Self;\r
+    typedef QNEPort       Superclass;\r
+\r
+    enum { Type = Superclass::Type + 4 };\r
+\r
+  public:\r
+    QNEOutputPort( QGraphicsItem* parent = NULL, QGraphicsScene* scene = NULL );\r
+    virtual ~QNEOutputPort( );\r
+\r
+    virtual void setName( const QString& n );\r
+\r
+    virtual bool isConnected( QNEPort* other );\r
+    inline int type( ) const\r
+      { return( this->Type ); }\r
+\r
+    inline QVector< QNEConnection* >& connections( )\r
+      { return( this->m_Connections ); }\r
+    inline const QVector< QNEConnection* >& connections( ) const\r
+      { return( this->m_Connections ); }\r
+\r
+  protected:\r
+    QVariant itemChange( GraphicsItemChange change, const QVariant& value );\r
+\r
+  protected:\r
     QVector< QNEConnection* > m_Connections;\r
-    int m_PortFlags;\r
-    quint64 m_Ptr;\r
   };\r
 \r
 } // ecapseman\r
index 590f8df610c632c2b77b5369aed1916246b74a0a..039b45ebc1a01cdeaf4eadf896e0ac30ffd8acbe 100644 (file)
 \r
 #include <QGraphicsScene>\r
 #include <QEvent>\r
+#include <QGraphicsSceneContextMenuEvent>\r
+#include <QGraphicsSceneDragDropEvent>\r
+#include <QGraphicsSceneHelpEvent>\r
+#include <QGraphicsSceneHoverEvent>\r
 #include <QGraphicsSceneMouseEvent>\r
+#include <QGraphicsSceneMoveEvent>\r
+#include <QGraphicsSceneResizeEvent>\r
+#include <QGraphicsSceneWheelEvent>\r
 \r
 #include "QNEPort.h"\r
 #include "QNEConnection.h"\r
 // -------------------------------------------------------------------------\r
 PipelineEditor::QNodesEditor::\r
 QNodesEditor( QObject* parent )\r
- : Superclass( parent )\r
+ : Superclass( parent ),\r
+   m_Conn( NULL ),\r
+   m_Workspace( NULL )\r
 {\r
-  this->m_Conn = NULL;\r
 }\r
 \r
 // -------------------------------------------------------------------------\r
@@ -48,6 +56,92 @@ PipelineEditor::QNodesEditor::
 {\r
 }\r
 \r
+// -------------------------------------------------------------------------\r
+PipelineEditor::QNodesEditor::\r
+TWorkspace* PipelineEditor::QNodesEditor::\r
+workspace( )\r
+{\r
+  return( this->m_Workspace );\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+const PipelineEditor::QNodesEditor::\r
+TWorkspace* PipelineEditor::QNodesEditor::\r
+workspace( ) const\r
+{\r
+  return( this->m_Workspace );\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+void PipelineEditor::QNodesEditor::\r
+setWorkspace( TWorkspace* ws )\r
+{\r
+  if( this->m_Workspace == ws )\r
+    return;\r
+  this->m_Workspace = ws;\r
+  this->m_Graph = TGraph::New( );\r
+\r
+  /* TODO\r
+     QGraphicsScene* scene = this->scene( );\r
+     // Add vertices and keep track of ports\r
+     std::map< std::string, std::map< std::string, QNEPort* > >\r
+     in_ports, out_ports;\r
+     auto vIt = this->m_Workspace->GetGraph( )->BeginVertices( );\r
+     auto vIt_end = this->m_Workspace->GetGraph( )->EndVertices( );\r
+     for( ; vIt != vIt_end; ++vIt )\r
+     {\r
+     this->_createBlock( dynamic_cast< TFilter* >( vIt->second.GetPointer( ) ) );\r
+\r
+     } // rof\r
+  */\r
+\r
+  // Add edges\r
+  /* TODO\r
+     auto rIt = this->m_Workspace->GetGraph( )->BeginEdgesRows( );\r
+     auto rIt_end = this->m_Workspace->GetGraph( )->EndEdgesRows( );\r
+     for( ; rIt != rIt_end; ++rIt )\r
+     {\r
+     auto cIt = rIt->second.begin( );\r
+     for( ; cIt != rIt->second.end( ); ++cIt )\r
+     {\r
+     auto eIt = cIt->second.begin( );\r
+     for( ; eIt != cIt->second.end( ); ++eIt )\r
+     {\r
+     QNEPort* p1 = out_ports[ rIt->first ][ eIt->first ];\r
+     QNEPort* p2 = in_ports[ cIt->first ][ eIt->second ];\r
+     if( p1 != NULL && p2 != NULL )\r
+     {\r
+     QNEConnection* conn = new QNEConnection( 0, scene );\r
+     conn->setPort1( p1 );\r
+     conn->setPort2( p2 );\r
+     this->m_Graph->AddConnection( rIt->first, cIt->first, conn );\r
+\r
+     } // fi\r
+\r
+     } // rof\r
+\r
+     } // rof\r
+\r
+     } // rof\r
+  */\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+std::string PipelineEditor::QNodesEditor::\r
+createFilter( const std::string& filter, const QPointF& pnt )\r
+{\r
+  std::string name = filter;\r
+  while( this->m_Workspace->HasFilter( name ) )\r
+    name += std::string( "_" );\r
+  if( this->m_Workspace->CreateFilter( filter, name ) )\r
+  {\r
+    this->_CreateBlock( this->m_Workspace->GetFilter( name ), pnt );\r
+    return( name );\r
+  }\r
+  else\r
+    return( "" );\r
+}\r
+\r
 // -------------------------------------------------------------------------\r
 void PipelineEditor::QNodesEditor::\r
 install( QGraphicsScene* s )\r
@@ -69,88 +163,384 @@ itemAt( const QPointF& pos )
   return( NULL );\r
 }\r
 \r
+#include <iostream>\r
+\r
+// -------------------------------------------------------------------------\r
+void PipelineEditor::QNodesEditor::\r
+_CreateBlock( TFilter* f, const QPointF& pnt )\r
+{\r
+  if( f == NULL )\r
+    return;\r
+\r
+  // Add block\r
+  QNEBlock* b = new QNEBlock( 0, this->m_Scene );\r
+  b->setNamePort( f->GetName( ) );\r
+  b->setTypePort( f->GetClassName( ).c_str( ) );\r
+  // TODO: b->setScenePos( pnt );\r
+\r
+  // Add input ports\r
+  std::set< std::string > inputs;\r
+  f->GetInputsNames( inputs );\r
+  for( auto iIt = inputs.begin( ); iIt != inputs.end( ); ++iIt )\r
+    b->addInputPort( iIt->c_str( ) );\r
+\r
+  // Add output ports\r
+  std::set< std::string > outputs;\r
+  f->GetOutputsNames( outputs );\r
+  for( auto oIt = outputs.begin( ); oIt != outputs.end( ); ++oIt )\r
+    b->addOutputPort( oIt->c_str( ) );\r
+\r
+  // Keep a trace of this visual graph\r
+  this->m_Graph->InsertVertex( f->GetName( ), b );\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+void PipelineEditor::QNodesEditor::\r
+_DoubleClick( QGraphicsSceneMouseEvent* evt, QGraphicsItem* item )\r
+{\r
+  switch( evt->button( ) )\r
+  {\r
+  case Qt::LeftButton:\r
+  {\r
+    QNEBlock* block = dynamic_cast< QNEBlock* >( item );\r
+    QNEPort* port = dynamic_cast< QNEPort* >( item );\r
+    QNEConnection* conn = dynamic_cast< QNEConnection* >( item );\r
+\r
+    if( block != NULL )\r
+    {\r
+      /* TODO\r
+         auto ports = block->ports( );\r
+         std::string name = "";\r
+         for(\r
+         auto pIt = ports.begin( );\r
+         pIt != ports.end( ) && name == "";\r
+         ++pIt\r
+         )\r
+         if(\r
+         ( *pIt )->portFlags( ) && QNEPort::NamePort == QNEPort::NamePort\r
+         )\r
+         name = ( *pIt )->portName( ).toStdString( );\r
+         if( name == "" )\r
+         return;\r
+         TFilter* filter = this->m_Workspace->GetFilter( name );\r
+         if( filter != NULL )\r
+         {\r
+         } // fi\r
+      */\r
+    }\r
+    else if( port != NULL )\r
+    {\r
+    }\r
+    else if( conn != NULL )\r
+    {\r
+    } // fi\r
+  }\r
+  break;\r
+  /* TODO:\r
+     case Qt::RightButton:\r
+     {\r
+     }\r
+     break;\r
+     case Qt::MiddleButton:\r
+     {\r
+     }\r
+     break;\r
+  */\r
+  default:\r
+    break;\r
+  } // hctiws\r
+}\r
+\r
 // -------------------------------------------------------------------------\r
 bool PipelineEditor::QNodesEditor::\r
 eventFilter( QObject* o, QEvent* e )\r
 {\r
-  QGraphicsSceneMouseEvent* me = ( QGraphicsSceneMouseEvent* ) e;\r
-\r
-  switch ( ( int ) e->type( ) )\r
+  // Event type\r
+  switch( int( e->type( ) ) )\r
   {\r
-  case QEvent::GraphicsSceneMousePress:\r
+  case QEvent::GraphicsSceneContextMenu:\r
   {\r
-    switch ( ( int ) me->button( ) )\r
+    QGraphicsSceneContextMenuEvent* evt =\r
+      dynamic_cast< QGraphicsSceneContextMenuEvent* >( e );\r
+    if( evt != NULL )\r
     {\r
-    case Qt::LeftButton:\r
+    } // fi\r
+  }\r
+  break;\r
+  case QEvent::GraphicsSceneDragEnter:\r
+  {\r
+    QGraphicsSceneDragDropEvent* evt =\r
+      dynamic_cast< QGraphicsSceneDragDropEvent* >( e );\r
+    if( evt != NULL )\r
     {\r
-      QGraphicsItem* item = this->itemAt( me->scenePos( ) );\r
-      if( item && item->type( ) == QNEPort::Type )\r
+    } // fi\r
+  }\r
+  break;\r
+  case QEvent::GraphicsSceneDragLeave:\r
+  {\r
+    QGraphicsSceneDragDropEvent* evt =\r
+      dynamic_cast< QGraphicsSceneDragDropEvent* >( e );\r
+    if( evt != NULL )\r
+    {\r
+    } // fi\r
+  }\r
+  break;\r
+  case QEvent::GraphicsSceneDragMove:\r
+  {\r
+    QGraphicsSceneDragDropEvent* evt =\r
+      dynamic_cast< QGraphicsSceneDragDropEvent* >( e );\r
+    if( evt != NULL )\r
+    {\r
+    } // fi\r
+  }\r
+  break;\r
+  case QEvent::GraphicsSceneDrop:\r
+  {\r
+    QGraphicsSceneDragDropEvent* evt =\r
+      dynamic_cast< QGraphicsSceneDragDropEvent* >( e );\r
+    if( evt != NULL )\r
+    {\r
+    } // fi\r
+  }\r
+  break;\r
+  case QEvent::GraphicsSceneHelp:\r
+  {\r
+    QGraphicsSceneHelpEvent* evt =\r
+      dynamic_cast< QGraphicsSceneHelpEvent* >( e );\r
+    if( evt != NULL )\r
+    {\r
+    } // fi\r
+  }\r
+  break;\r
+  case QEvent::GraphicsSceneHoverEnter:\r
+  {\r
+    QGraphicsSceneHoverEvent* evt =\r
+      dynamic_cast< QGraphicsSceneHoverEvent* >( e );\r
+    if( evt != NULL )\r
+    {\r
+    } // fi\r
+  }\r
+  break;\r
+  case QEvent::GraphicsSceneHoverLeave:\r
+  {\r
+    QGraphicsSceneHoverEvent* evt =\r
+      dynamic_cast< QGraphicsSceneHoverEvent* >( e );\r
+    if( evt != NULL )\r
+    {\r
+    } // fi\r
+  }\r
+  break;\r
+  case QEvent::GraphicsSceneHoverMove:\r
+  {\r
+    QGraphicsSceneHoverEvent* evt =\r
+      dynamic_cast< QGraphicsSceneHoverEvent* >( e );\r
+    if( evt != NULL )\r
+    {\r
+    } // fi\r
+  }\r
+  break;\r
+  case QEvent::GraphicsSceneMouseDoubleClick:\r
+  {\r
+    QGraphicsSceneMouseEvent* evt =\r
+      dynamic_cast< QGraphicsSceneMouseEvent* >( e );\r
+    if( evt != NULL )\r
+    {\r
+      QGraphicsItem* item = this->itemAt( evt->scenePos( ) );\r
+      if( item != NULL )\r
       {\r
-        this->m_Conn = new QNEConnection( 0, this->m_Scene );\r
-        this->m_Conn->setPort1( ( QNEPort* ) item );\r
-        this->m_Conn->setPos1( item->scenePos( ) );\r
-        this->m_Conn->setPos2( me->scenePos( ) );\r
-        this->m_Conn->updatePath( );\r
-\r
+        this->_DoubleClick( evt, item );\r
         return( true );\r
-      }\r
-      else if( item && item->type( ) == QNEBlock::Type )\r
-      {\r
-        /* if( selBlock )\r
-           selBlock->setSelected( ); */\r
-        // selBlock = ( QNEBlock* ) item;\r
 \r
       } // fi\r
-      break;\r
-    }\r
-    case Qt::RightButton:\r
-    {\r
-      QGraphicsItem* item = itemAt( me->scenePos( ) );\r
-      if( item && ( item->type( ) == QNEConnection::Type || item->type( ) == QNEBlock::Type ) )\r
-        delete item;\r
-      // if( selBlock == ( QNEBlock* ) item )\r
-      // selBlock = 0;\r
-      break;\r
-    }\r
-    }\r
+\r
+    } // fi\r
   }\r
+  break;\r
   case QEvent::GraphicsSceneMouseMove:\r
   {\r
-    if( this->m_Conn )\r
+    QGraphicsSceneMouseEvent* evt =\r
+      dynamic_cast< QGraphicsSceneMouseEvent* >( e );\r
+    if( evt != NULL )\r
     {\r
-      this->m_Conn->setPos2( me->scenePos( ) );\r
-      this->m_Conn->updatePath( );\r
-      return( true );\r
-    }\r
-    break;\r
+      if( this->m_Conn )\r
+      {\r
+        this->m_Conn->setPos2( evt->scenePos( ) );\r
+        this->m_Conn->updatePath( );\r
+        return( true );\r
+\r
+      } // fi\r
+\r
+    } // fi\r
   }\r
-  case QEvent::GraphicsSceneMouseRelease:\r
+  break;\r
+  case QEvent::GraphicsSceneMousePress:\r
   {\r
-    if( this->m_Conn && me->button( ) == Qt::LeftButton )\r
+    QGraphicsSceneMouseEvent* evt =\r
+      dynamic_cast< QGraphicsSceneMouseEvent* >( e );\r
+    if( evt != NULL )\r
     {\r
-      QGraphicsItem* item = itemAt( me->scenePos( ) );\r
-      if( item && item->type( ) == QNEPort::Type )\r
+      switch( evt->button( ) )\r
       {\r
-        QNEPort* port1 = this->m_Conn->port1( );\r
-        QNEPort* port2 = ( QNEPort* ) item;\r
-\r
-        if( port1->block( ) != port2->block( ) && port1->isOutput( ) != port2->isOutput( ) && !port1->isConnected( port2 ) )\r
+      case Qt::LeftButton:\r
+      {\r
+        QNEOutputPort* port =\r
+          dynamic_cast< QNEOutputPort* >( this->itemAt( evt->scenePos( ) ) );\r
+        if( port != NULL )\r
         {\r
-          this->m_Conn->setPos2( port2->scenePos( ) );\r
-          this->m_Conn->setPort2( port2 );\r
+          this->m_Conn = new QNEConnection( 0, this->m_Scene );\r
+          this->m_Conn->setPort1( port );\r
+          this->m_Conn->setPos1( port->scenePos( ) );\r
+          this->m_Conn->setPos2( evt->scenePos( ) );\r
           this->m_Conn->updatePath( );\r
-          this->m_Conn = NULL;\r
           return( true );\r
-        }\r
+\r
+        } // fi\r
       }\r
+      break;\r
+      default:\r
+        break;\r
 \r
-      delete this->m_Conn;\r
-      this->m_Conn = NULL;\r
-      return( true );\r
-    }\r
-    break;\r
+      } // hctiws\r
+\r
+    } // fi\r
+  }\r
+  break;\r
+  case QEvent::GraphicsSceneMouseRelease:\r
+  {\r
+    QGraphicsSceneMouseEvent* evt =\r
+      dynamic_cast< QGraphicsSceneMouseEvent* >( e );\r
+    if( evt != NULL )\r
+    {\r
+      if( this->m_Conn != NULL && evt->button( ) == Qt::LeftButton )\r
+      {\r
+        QNEInputPort* port2 =\r
+          dynamic_cast< QNEInputPort* >( this->itemAt( evt->scenePos( ) ) );\r
+        if( port2 != NULL )\r
+        {\r
+          QNEOutputPort* port1 =\r
+            dynamic_cast< QNEOutputPort* >( this->m_Conn->port1( ) );\r
+          if( port1 != NULL )\r
+          {\r
+            if(\r
+              port1->block( ) != port2->block( ) &&\r
+              !port2->hasConnection( ) &&\r
+              !port1->isConnected( port2 )\r
+              )\r
+            {\r
+              this->m_Conn->setPos2( port2->scenePos( ) );\r
+              this->m_Conn->setPort2( port2 );\r
+              this->m_Conn->updatePath( );\r
+\r
+              this->m_Workspace->Connect(\r
+                port1->block( )->namePort( )->name( ).toStdString( ),\r
+                port2->block( )->namePort( )->name( ).toStdString( ),\r
+                port1->name( ).toStdString( ),\r
+                port2->name( ).toStdString( )\r
+                );\r
+              this->m_Graph->AddConnection(\r
+                port1->block( )->namePort( )->name( ).toStdString( ),\r
+                port2->block( )->namePort( )->name( ).toStdString( ),\r
+                this->m_Conn\r
+                );\r
+\r
+              this->m_Conn = NULL;\r
+              return( true );\r
+\r
+            } // fi\r
+\r
+          } // fi\r
+\r
+        } // fi\r
+        delete this->m_Conn;\r
+        this->m_Conn = NULL;\r
+        return( true );\r
+\r
+      } // fi\r
+\r
+    } // fi\r
+  }\r
+  break;\r
+  case QEvent::GraphicsSceneMove:\r
+  {\r
+    QGraphicsSceneMoveEvent* evt =\r
+      dynamic_cast< QGraphicsSceneMoveEvent* >( e );\r
+    if( evt != NULL )\r
+    {\r
+    } // fi\r
   }\r
+  break;\r
+  case QEvent::GraphicsSceneResize:\r
+  {\r
+    QGraphicsSceneResizeEvent* evt =\r
+      dynamic_cast< QGraphicsSceneResizeEvent* >( e );\r
+    if( evt != NULL )\r
+    {\r
+    } // fi\r
+  }\r
+  break;\r
+  case QEvent::GraphicsSceneWheel:\r
+  {\r
+    QGraphicsSceneWheelEvent* evt =\r
+      dynamic_cast< QGraphicsSceneWheelEvent* >( e );\r
+    if( evt != NULL )\r
+    {\r
+    } // fi\r
+  }\r
+  break;\r
+  default:\r
+    break;\r
   } // hctiws\r
+\r
+  // Mouse event\r
+  /*\r
+    QGraphicsSceneMouseEvent* me =\r
+    dynamic_cast< QGraphicsSceneMouseEvent* >( e );\r
+    if( me != NULL )\r
+    {\r
+    } // fi\r
+  */\r
+\r
+  /* TODO\r
+     switch( ( int ) e->type( ) )\r
+     {\r
+     case QEvent::GraphicsSceneMouseMove:\r
+     {\r
+     if( this->m_Conn )\r
+     {\r
+     this->m_Conn->setPos2( me->scenePos( ) );\r
+     this->m_Conn->updatePath( );\r
+     return( true );\r
+     }\r
+     break;\r
+     }\r
+     case QEvent::GraphicsSceneMouseRelease:\r
+     {\r
+     if( this->m_Conn && me->button( ) == Qt::LeftButton )\r
+     {\r
+     QGraphicsItem* item = itemAt( me->scenePos( ) );\r
+     if( item && item->type( ) == QNEPort::Type )\r
+     {\r
+     QNEPort* port1 = this->m_Conn->port1( );\r
+     QNEPort* port2 = ( QNEPort* ) item;\r
+     if( port1->block( ) != port2->block( ) && port1->isOutput( ) != port2->isOutput( ) && !port1->isConnected( port2 ) )\r
+     {\r
+     this->m_Conn->setPos2( port2->scenePos( ) );\r
+     this->m_Conn->setPort2( port2 );\r
+     this->m_Conn->updatePath( );\r
+     this->m_Conn = NULL;\r
+     return( true );\r
+     }\r
+     }\r
+\r
+     delete this->m_Conn;\r
+     this->m_Conn = NULL;\r
+     return( true );\r
+     }\r
+     break;\r
+     }\r
+     } // hctiws\r
+  */\r
+\r
   return( this->Superclass::eventFilter( o, e ) );\r
 }\r
 \r
index c2db807d2d82f111e472fa547e50ae226ed9a8e3..e2dc37c7f7fc6718234a15ee455c3350a45ed955 100644 (file)
 #define __PIPELINEEDITOR__QNODESEDITOR__H__\r
 \r
 #include <QObject>\r
+#include <QPointF>\r
+#include <cpExtensions/DataStructures/Graph.h>\r
+#include <cpPlugins/Interface/Workspace.h>\r
 \r
 class QGraphicsScene;\r
+class QGraphicsSceneMouseEvent;\r
 class QGraphicsItem;\r
-class QPointF;\r
 \r
 namespace PipelineEditor\r
 {\r
@@ -49,20 +52,40 @@ namespace PipelineEditor
     typedef QNodesEditor Self;\r
     typedef QObject      Superclass;\r
 \r
+    typedef cpPlugins::Interface::Workspace TWorkspace;\r
+    typedef TWorkspace::TFilter             TFilter;\r
+    typedef\r
+      cpExtensions::DataStructures::\r
+      Graph< QNEBlock*, QNEConnection*, std::string > TGraph;\r
+\r
   public:\r
     explicit QNodesEditor( QObject* parent = 0 );\r
     virtual ~QNodesEditor( );\r
 \r
-    void install( QGraphicsScene* s );\r
+    TWorkspace* workspace( );\r
+    const TWorkspace* workspace( ) const;\r
+    void setWorkspace( TWorkspace* ws );\r
+\r
+    std::string createFilter(\r
+      const std::string& filter,\r
+      const QPointF& pnt = QPointF( )\r
+      );\r
 \r
+    void install( QGraphicsScene* s );\r
     bool eventFilter( QObject* o, QEvent* e );\r
 \r
   private:\r
     QGraphicsItem* itemAt( const QPointF& pos );\r
 \r
+    inline void _CreateBlock( TFilter* f, const QPointF& pnt );\r
+    inline void _DoubleClick( QGraphicsSceneMouseEvent* evt, QGraphicsItem* item );\r
+\r
   private:\r
     QGraphicsScene* m_Scene;\r
     QNEConnection* m_Conn;\r
+\r
+    TWorkspace* m_Workspace;\r
+    TGraph::Pointer m_Graph;\r
   };\r
 \r
 } // ecapseman\r
index afb5b62bd653ec6ce5e61993ee4a07191aa954eb..d253f78f8e9288cf7c7a14bf98c4ceec40d5f494 100644 (file)
@@ -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$
 
index 03380d128efedbd677f2942edc11cece1d83248d..2fec183e666a96782206c75dfcb26864bd36dc3f 100644 (file)
@@ -2,8 +2,6 @@
 #define __PIPELINEEDITOR__QNODESEDITORCANVAS__H__
 
 #include <QtGui/QGraphicsView>
-#include <cpExtensions/DataStructures/Graph.h>
-#include <cpPlugins/Interface/Workspace.h>
 
 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
index 8d838b829e821b299014d71d70624a51b01ed203..872b4f4a33907f9f2cbf2539f16a4c07439b5fdb 100644 (file)
@@ -1,6 +1,8 @@
 #include "cpPipelineEditor.h"
 #include "ui_cpPipelineEditor.h"
 
+#include "QNodesEditor.h"
+
 #include <QFileDialog>
 #include <QMessageBox>
 #include <cpPlugins/Interface/Workspace.h>
@@ -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$
index 5180dd12da81473efb070dc26985f6a28b7ae9fb..7192268911e3dbd816a59cd3a976aa812bab3a4d 100644 (file)
@@ -40,6 +40,7 @@ protected slots:
   void _ButtonLoadPluginsFile( );
   void _ButtonLoadPluginsPath( );
   void _ActionOpenWorkspace( );
+  void _ActionSaveWorkspace( );
 
 private:
   Ui::cpPipelineEditor* m_UI;
index 4a05b4fb4763654783d4318d78233306fb739069..e584b5e5d36cbd5d7f2719fe46f9ffb481f77302 100644 (file)
@@ -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( );
index 56cb5fdc51719922754a33913b8ce5df630bb90a..9c97639e11fce640eb199cea2ba942d0f20312d0 100644 (file)
@@ -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 );
index e14a44ef7e4c94ee1e286128dcd9c8dd37ebd614..b623ad9a025e44118c0ab0b56de645f151169025 100644 (file)
@@ -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 )
     {