]> Creatis software - cpPlugins.git/commitdiff
...
authorLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Wed, 16 Dec 2015 23:43:20 +0000 (18:43 -0500)
committerLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Wed, 16 Dec 2015 23:43:20 +0000 (18:43 -0500)
13 files changed:
appli/cpPipelineEditor/CMakeLists.txt
appli/cpPipelineEditor/GraphCanvas.cxx [deleted file]
appli/cpPipelineEditor/GraphCanvas.h [deleted file]
appli/cpPipelineEditor/QNEBlock.cxx
appli/cpPipelineEditor/QNEBlock.h
appli/cpPipelineEditor/QNodesEditor.cxx
appli/cpPipelineEditor/QNodesEditor.h
appli/cpPipelineEditor/QNodesEditorCanvas.cxx [new file with mode: 0644]
appli/cpPipelineEditor/QNodesEditorCanvas.h [new file with mode: 0644]
appli/cpPipelineEditor/cpPipelineEditor.cxx
appli/cpPipelineEditor/cpPipelineEditor.h
appli/cpPipelineEditor/cpPipelineEditor.ui
appli/cpPipelineEditor/main.cxx

index b978bcd11b97c581008c59943078cf1ad651b70a..14874c5f12b19d111dd1b1d13c92d121063e2880 100644 (file)
@@ -14,11 +14,12 @@ IF(USE_QT4)
     QNEConnection.cxx
     QNEPort.cxx
     QNodesEditor.cxx
-    QNEMainWindow.cxx
+    QNodesEditorCanvas.cxx
+    #QNEMainWindow.cxx
     #Edge.cxx
     #GraphCanvas.cxx
     #Node.cxx
-    #cpPipelineEditor.cxx
+    cpPipelineEditor.cxx
     )
   SET(
     App_SOURCES
@@ -27,9 +28,10 @@ IF(USE_QT4)
   SET(
     App_QT_HEADERS
     QNodesEditor.h
-    QNEMainWindow.h
+    QNodesEditorCanvas.h
+    #QNEMainWindow.h
     #GraphCanvas.h
-    #cpPipelineEditor.h
+    cpPipelineEditor.h
     )
   SET(
     App_HEADERS
diff --git a/appli/cpPipelineEditor/GraphCanvas.cxx b/appli/cpPipelineEditor/GraphCanvas.cxx
deleted file mode 100644 (file)
index 3b3041c..0000000
+++ /dev/null
@@ -1,318 +0,0 @@
-#include "GraphCanvas.h"
-#include "Edge.h"
-#include "Node.h"
-
-#include <QWheelEvent>
-
-#include <cpPlugins/Interface/Workspace.h>
-
-// -------------------------------------------------------------------------
-PipelineEditor::GraphCanvas::
-GraphCanvas( QWidget* parent )
-  : QGraphicsView( parent ),
-    m_Workspace( NULL )
-{
-  QGraphicsScene* scene = new QGraphicsScene( this );
-  scene->setItemIndexMethod( QGraphicsScene::NoIndex );
-  this->setScene( scene );
-}
-
-// -------------------------------------------------------------------------
-PipelineEditor::GraphCanvas::
-~GraphCanvas( )
-{
-}
-
-// -------------------------------------------------------------------------
-cpPlugins::Interface::Workspace* PipelineEditor::GraphCanvas::
-workspace( )
-{
-  return( this->m_Workspace );
-}
-
-// -------------------------------------------------------------------------
-const cpPlugins::Interface::Workspace* PipelineEditor::GraphCanvas::
-workspace( ) const
-{
-  return( this->m_Workspace );
-}
-
-// -------------------------------------------------------------------------
-void PipelineEditor::GraphCanvas::
-setWorkspace( cpPlugins::Interface::Workspace* ws )
-{
-  if( this->m_Workspace == ws )
-    return;
-  this->m_Workspace = ws;
-  QGraphicsScene* scene = this->scene( );
-
-  // Create graph
-  this->m_Graph = TGraph::New( );
-
-  // Add vertices
-  auto vIt = this->m_Workspace->GetGraph( )->BeginVertices( );
-  auto vIt_end = this->m_Workspace->GetGraph( )->EndVertices( );
-  for( ; vIt != vIt_end; ++vIt )
-  {
-    std::string label = vIt->second->GetName( ) + std::string( "\n" );
-    label += vIt->second->GetClassName( );
-
-    Node* node = new Node( this, vIt->second.GetPointer( ) );
-    this->m_Graph->InsertVertex( vIt->first, node );
-    scene->addItem( node );
-
-  } // rof
-
-  /* TODO
-     // Add edges
-     auto rIt = this->m_Workspace->GetGraph( )->BeginEdgesRows( );
-     auto rIt_end = this->m_Workspace->GetGraph( )->EndEdgesRows( );
-     for( ; rIt != rIt_end; ++rIt )
-     {
-     Node* a = this->m_Graph->GetVertex( rIt->first );
-     if( a == NULL )
-     continue;
-     auto cIt = rIt->second.begin( );
-     for( ; cIt != rIt->second.end( ); ++cIt )
-     {
-     Node* b = this->m_Graph->GetVertex( cIt->first );
-     if( b == NULL )
-     continue;
-     Edge* e = new Edge( a, b );
-     this->m_Graph->AddConnection( rIt->first, cIt->first, e );
-     scene->addItem( e );
-
-     } // rof
-
-     } // rof
-  */
-}
-
-// -------------------------------------------------------------------------
-void PipelineEditor::GraphCanvas::
-draw( )
-{
-  if( this->m_Workspace == NULL )
-    return;
-}
-
-// -------------------------------------------------------------------------
-void PipelineEditor::GraphCanvas::
-itemMoved( )
-{
-}
-
-// -------------------------------------------------------------------------
-void PipelineEditor::GraphCanvas::
-shuffle( )
-{
-}
-
-// -------------------------------------------------------------------------
-void PipelineEditor::GraphCanvas::
-zoomIn( )
-{
-}
-
-// -------------------------------------------------------------------------
-void PipelineEditor::GraphCanvas::
-zoomOut( )
-{
-}
-
-// -------------------------------------------------------------------------
-void PipelineEditor::GraphCanvas::
-keyPressEvent( QKeyEvent* event )
-{
-}
-
-// -------------------------------------------------------------------------
-void PipelineEditor::GraphCanvas::
-timerEvent( QTimerEvent* event )
-{
-}
-
-// -------------------------------------------------------------------------
-void PipelineEditor::GraphCanvas::
-wheelEvent( QWheelEvent* event )
-{
-  this->scaleView(
-    std::pow( double( 2 ), -event->delta( ) / double( 240 ) )
-    );
-}
-
-// -------------------------------------------------------------------------
-void PipelineEditor::GraphCanvas::
-drawBackground( QPainter* painter, const QRectF& rect )
-{
-  this->QGraphicsView::drawBackground( painter, rect );
-}
-
-// -------------------------------------------------------------------------
-void PipelineEditor::GraphCanvas::
-scaleView( qreal scaleFactor )
-{
-  qreal factor = this->transform( ).
-    scale( scaleFactor, scaleFactor ).
-    mapRect( QRectF( 0, 0, 1, 1 ) ).
-    width( );
-  if( factor < qreal( 0.07 ) || factor > qreal( 100 ) )
-    return;
-  this->scale( scaleFactor, scaleFactor );
-}
-
-/*
-  protected:
-    cpPlugins::Interface::Workspace* m_Workspace;
-    TGraph::Pointer m_Graph;
-  };
-*/
-
-// eof - $RCSfile$
-
-
-/*
-
-// -------------------------------------------------------------------------
-void GraphWidget::
-draw( )
-{
-  if( this->m_Workspace == NULL )
-    return;
-}
-
-// -------------------------------------------------------------------------
-void GraphWidget::itemMoved()
-{
-  if (!timerId)
-    timerId = startTimer(1000 / 25);
-}
-
-void GraphWidget::keyPressEvent(QKeyEvent *event)
-{
-  switch (event->key()) {
-  case Qt::Key_Up:
-    centerNode->moveBy(0, -20);
-    break;
-  case Qt::Key_Down:
-    centerNode->moveBy(0, 20);
-    break;
-  case Qt::Key_Left:
-    centerNode->moveBy(-20, 0);
-    break;
-  case Qt::Key_Right:
-    centerNode->moveBy(20, 0);
-    break;
-  case Qt::Key_Plus:
-    zoomIn();
-    break;
-  case Qt::Key_Minus:
-    zoomOut();
-    break;
-  case Qt::Key_Space:
-  case Qt::Key_Enter:
-    shuffle();
-    break;
-  default:
-    QGraphicsView::keyPressEvent(event);
-  }
-}
-
-void GraphWidget::timerEvent(QTimerEvent *event)
-{
-  Q_UNUSED(event);
-
-  QList<Node *> nodes;
-  foreach (QGraphicsItem *item, scene()->items()) {
-    if (Node *node = qgraphicsitem_cast<Node *>(item))
-      nodes << node;
-  }
-
-  foreach (Node *node, nodes)
-    node->calculateForces();
-
-  bool itemsMoved = false;
-  foreach (Node *node, nodes) {
-    if (node->advance())
-      itemsMoved = true;
-  }
-
-  if (!itemsMoved) {
-    killTimer(timerId);
-    timerId = 0;
-  }
-}
-
-void GraphWidget::wheelEvent(QWheelEvent *event)
-{
-  scaleView(pow((double)2, -event->delta() / 240.0));
-}
-
-void GraphWidget::drawBackground(QPainter *painter, const QRectF &rect)
-{
-  //Q_UNUSED(rect);
-
-  // Shadow
-  QRectF sceneRect = rect;//this->sceneRect();
-  QRectF rightShadow(sceneRect.right(), sceneRect.top() + 5, 5, sceneRect.height());
-  QRectF bottomShadow(sceneRect.left() + 5, sceneRect.bottom(), sceneRect.width(), 5);
-  if (rightShadow.intersects(rect) || rightShadow.contains(rect))
-    painter->fillRect(rightShadow, Qt::darkGray);
-  if (bottomShadow.intersects(rect) || bottomShadow.contains(rect))
-    painter->fillRect(bottomShadow, Qt::darkGray);
-
-  // Fill
-  QLinearGradient gradient(sceneRect.topLeft(), sceneRect.bottomRight());
-  gradient.setColorAt(0, Qt::white);
-  gradient.setColorAt(1, Qt::lightGray);
-  painter->fillRect(rect.intersect(sceneRect), gradient);
-  painter->setBrush(Qt::NoBrush);
-  painter->drawRect(sceneRect);
-
-#if !defined(Q_OS_SYMBIAN) && !defined(Q_WS_MAEMO_5)
-  // Text
-  QRectF textRect(sceneRect.left() + 4, sceneRect.top() + 4,
-                  sceneRect.width() - 4, sceneRect.height() - 4);
-  QString message(tr("Click and drag the nodes around, and zoom with the mouse "
-                     "wheel or the '+' and '-' keys"));
-
-  QFont font = painter->font();
-  font.setBold(true);
-  font.setPointSize(14);
-  painter->setFont(font);
-  painter->setPen(Qt::lightGray);
-  painter->drawText(textRect.translated(2, 2), message);
-  painter->setPen(Qt::black);
-  painter->drawText(textRect, message);
-#endif
-}
-
-void GraphWidget::scaleView(qreal scaleFactor)
-{
-  qreal factor = transform().scale(scaleFactor, scaleFactor).mapRect(QRectF(0, 0, 1, 1)).width();
-  if (factor < 0.07 || factor > 100)
-    return;
-
-  scale(scaleFactor, scaleFactor);
-}
-
-void GraphWidget::shuffle()
-{
-  foreach (QGraphicsItem *item, scene()->items()) {
-    if (qgraphicsitem_cast<Node *>(item))
-      item->setPos(-150 + qrand() % 300, -150 + qrand() % 300);
-  }
-}
-
-void GraphWidget::zoomIn()
-{
-  scaleView(qreal(1.2));
-}
-
-void GraphWidget::zoomOut()
-{
-  scaleView(1 / qreal(1.2));
-}
-
-
-*/
diff --git a/appli/cpPipelineEditor/GraphCanvas.h b/appli/cpPipelineEditor/GraphCanvas.h
deleted file mode 100644 (file)
index 3a4a9d0..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-#ifndef __PIPELINEEDITOR__GRAPHCANVAS__H__
-#define __PIPELINEEDITOR__GRAPHCANVAS__H__
-
-#include <QtGui/QGraphicsView>
-#include <cpExtensions/DataStructures/Graph.h>
-
-// Some forward declarations
-namespace cpPlugins
-{
-  namespace Interface
-  {
-    class Workspace;
-  }
-}
-
-namespace PipelineEditor
-{
-  // Some other forward declarations
-  class Node;
-  class Edge;
-
-  /**
-   */
-  class GraphCanvas
-    : public QGraphicsView
-  {
-    Q_OBJECT;
-
-  public:
-    typedef
-    cpExtensions::DataStructures::Graph< Node*, Edge*, std::string > TGraph;
-
-  public:
-    GraphCanvas( QWidget* parent = 0 );
-    virtual ~GraphCanvas( );
-
-    cpPlugins::Interface::Workspace* workspace( );
-    const cpPlugins::Interface::Workspace* workspace( ) const;
-    void setWorkspace( cpPlugins::Interface::Workspace* ws );
-
-    void draw( );
-
-    void itemMoved( );
-
-  public slots:
-    void shuffle( );
-    void zoomIn( );
-    void zoomOut( );
-
-  protected:
-    void keyPressEvent( QKeyEvent* event );
-    void timerEvent( QTimerEvent* event );
-    void wheelEvent( QWheelEvent* event );
-    void drawBackground( QPainter* painter, const QRectF& rect );
-    void scaleView( qreal scaleFactor );
-
-  protected:
-    cpPlugins::Interface::Workspace* m_Workspace;
-    TGraph::Pointer m_Graph;
-  };
-
-} // ecapseman
-
-#endif // __PIPELINEEDITOR__GRAPHCANVAS__H__
-
-// eof - $RCSfile$
index d1e01094d1bb535845c708d0cfe498c9c4abbc55..7ccb166cd3d6e70f29f03aa077eefba29d70cdbe 100644 (file)
@@ -103,17 +103,17 @@ addPort( const QString& name, bool isOutput, int flags, int ptr )
 }\r
 \r
 // -------------------------------------------------------------------------\r
-void PipelineEditor::QNEBlock::\r
+PipelineEditor::QNEPort* PipelineEditor::QNEBlock::\r
 addInputPort( const QString& name )\r
 {\r
-  this->addPort( name, false );\r
+  return( this->addPort( name, false ) );\r
 }\r
 \r
 // -------------------------------------------------------------------------\r
-void PipelineEditor::QNEBlock::\r
+PipelineEditor::QNEPort* PipelineEditor::QNEBlock::\r
 addOutputPort( const QString& name )\r
 {\r
-  this->addPort( name, true );\r
+  return( this->addPort( name, true ) );\r
 }\r
 \r
 // -------------------------------------------------------------------------\r
index 516e871c71ca2b9dde5b5ac993665ce036567024..1f3d6514d931398ca4d902921222e684af603e82 100644 (file)
@@ -48,8 +48,8 @@ namespace PipelineEditor
     QNEPort* addPort(\r
       const QString& name, bool isOutput, int flags = 0, int ptr = 0\r
       );\r
-    void addInputPort( const QString& name );\r
-    void addOutputPort( const QString& name );\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 save( QDataStream& ds );\r
index 9669eea49704045325fb3dddb2dcdfa9f49b86fb..91a5914b8248ad5115c96a394a868b395ce6c5fb 100644 (file)
@@ -77,19 +77,19 @@ eventFilter( QObject* o, QEvent* e )
 \r
   switch ( ( int ) e->type( ) )\r
   {\r
-  case QEvent::GraphicsThis->M_SceneMousePress:\r
+  case QEvent::GraphicsSceneMousePress:\r
   {\r
     switch ( ( int ) me->button( ) )\r
     {\r
     case Qt::LeftButton:\r
     {\r
-      QGraphicsItem* item = this->itemAt( me->this->m_ScenePos( ) );\r
+      QGraphicsItem* item = this->itemAt( me->scenePos( ) );\r
       if( item && item->type( ) == QNEPort::Type )\r
       {\r
         this->m_Conn = new QNEConnection( 0, this->m_Scene );\r
         this->m_Conn->setPort1( ( QNEPort* ) item );\r
-        this->m_Conn->setPos1( item->this->m_ScenePos( ) );\r
-        this->m_Conn->setPos2( me->this->m_ScenePos( ) );\r
+        this->m_Conn->setPos1( item->scenePos( ) );\r
+        this->m_Conn->setPos2( me->scenePos( ) );\r
         this->m_Conn->updatePath( );\r
 \r
         return( true );\r
@@ -105,7 +105,7 @@ eventFilter( QObject* o, QEvent* e )
     }\r
     case Qt::RightButton:\r
     {\r
-      QGraphicsItem* item = itemAt( me->this->m_ScenePos( ) );\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
@@ -114,29 +114,29 @@ eventFilter( QObject* o, QEvent* e )
     }\r
     }\r
   }\r
-  case QEvent::GraphicsThis->M_SceneMouseMove:\r
+  case QEvent::GraphicsSceneMouseMove:\r
   {\r
     if( this->m_Conn )\r
     {\r
-      this->m_Conn->setPos2( me->this->m_ScenePos( ) );\r
+      this->m_Conn->setPos2( me->scenePos( ) );\r
       this->m_Conn->updatePath( );\r
       return( true );\r
     }\r
     break;\r
   }\r
-  case QEvent::GraphicsThis->M_SceneMouseRelease:\r
+  case QEvent::GraphicsSceneMouseRelease:\r
   {\r
     if( this->m_Conn && me->button( ) == Qt::LeftButton )\r
     {\r
-      QGraphicsItem* item = itemAt( me->this->m_ScenePos( ) );\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
 \r
-        if( port1->block( ) != port2->block( ) && port1->isOutput( ) != port2->isOutput( ) && !port1->isThis->M_Connected( port2 ) )\r
+        if( port1->block( ) != port2->block( ) && port1->isOutput( ) != port2->isOutput( ) && !port1->isConnected( port2 ) )\r
         {\r
-          this->m_Conn->setPos2( port2->this->m_ScenePos( ) );\r
+          this->m_Conn->setPos2( port2->scenePos( ) );\r
           this->m_Conn->setPort2( port2 );\r
           this->m_Conn->updatePath( );\r
           this->m_Conn = NULL;\r
@@ -189,9 +189,10 @@ load( QDataStream& ds )
     {\r
       QNEBlock* block = new QNEBlock( 0, this->m_Scene );\r
       block->load( ds, portMap );\r
-    } else if( type == QNEConnection::Type )\r
+    }\r
+    else if( type == QNEConnection::Type )\r
     {\r
-      QNEConnection* this->m_Conn = new QNEConnection( 0, this->m_Scene );\r
+      this->m_Conn = new QNEConnection( 0, this->m_Scene );\r
       this->m_Conn->load( ds, portMap );\r
     }\r
   }\r
index 3e90b502d3e4b937ec629f8af66a10cee625366c..87c5a20c5d38b19a0195d4144268ee56c440ff0e 100644 (file)
 \r
 #include <QObject>\r
 \r
+class QGraphicsScene;\r
+class QGraphicsItem;\r
+class QPointF;\r
+\r
 namespace PipelineEditor\r
 {\r
-  class QGraphicsScene;\r
   class QNEConnection;\r
-  class QGraphicsItem;\r
-  class QPointF;\r
   class QNEBlock;\r
 \r
   /**\r
diff --git a/appli/cpPipelineEditor/QNodesEditorCanvas.cxx b/appli/cpPipelineEditor/QNodesEditorCanvas.cxx
new file mode 100644 (file)
index 0000000..6d970ad
--- /dev/null
@@ -0,0 +1,425 @@
+#include "QNodesEditorCanvas.h"
+#include "QNodesEditor.h"
+#include "QNEBlock.h"
+#include "QNEConnection.h"
+#include "QNEPort.h"
+
+#include <QDragEnterEvent>
+#include <QWheelEvent>
+#include <QTreeWidget>
+
+// -------------------------------------------------------------------------
+PipelineEditor::QNodesEditorCanvas::
+QNodesEditorCanvas( QWidget* parent )
+  : QGraphicsView( parent ),
+    m_Workspace( NULL )
+{
+  QGraphicsScene* scene = new QGraphicsScene( this );
+  this->setScene( scene );
+  this->setRenderHint( QPainter::Antialiasing );
+  this->setAcceptDrops( true );
+
+  this->m_Editor = new QNodesEditor( this );
+  this->m_Editor->install( scene );
+}
+
+// -------------------------------------------------------------------------
+PipelineEditor::QNodesEditorCanvas::
+~QNodesEditorCanvas( )
+{
+}
+
+// -------------------------------------------------------------------------
+PipelineEditor::QNodesEditorCanvas::
+TWorkspace* PipelineEditor::QNodesEditorCanvas::
+workspace( )
+{
+  return( this->m_Workspace );
+}
+
+// -------------------------------------------------------------------------
+const PipelineEditor::QNodesEditorCanvas::
+TWorkspace* PipelineEditor::QNodesEditorCanvas::
+workspace( ) const
+{
+  return( this->m_Workspace );
+}
+
+// -------------------------------------------------------------------------
+void PipelineEditor::QNodesEditorCanvas::
+setWorkspace( TWorkspace* ws )
+{
+  if( this->m_Workspace == ws )
+    return;
+  this->m_Workspace = ws;
+  QGraphicsScene* scene = this->scene( );
+
+  // Create graph
+  this->m_Graph = TGraph::New( );
+
+  // 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( ) ) );
+#error ACA VOY
+    // Add block
+    QNEBlock* b = new QNEBlock( 0, scene );
+    b->addPort( vIt->second->GetName( ), 0, QNEPort::NamePort );
+    b->addPort( vIt->second->GetClassName( ).c_str( ), 0, QNEPort::TypePort );
+
+    // Get filter
+    if( f == NULL )
+      continue;
+
+    // Add input ports
+    std::set< std::string > inputs;
+    f->GetInputsNames( inputs );
+    for( auto iIt = inputs.begin( ); iIt != inputs.end( ); ++iIt )
+      in_ports[ vIt->first ][ *iIt ] = b->addInputPort( iIt->c_str( ) );
+
+    // Add output ports
+    std::set< std::string > outputs;
+    f->GetOutputsNames( outputs );
+    for( auto oIt = outputs.begin( ); oIt != outputs.end( ); ++oIt )
+      out_ports[ vIt->first ][ *oIt ] = b->addOutputPort( oIt->c_str( ) );
+
+    // Keep a trace of this visual graph
+    this->m_Graph->InsertVertex( vIt->first, b );
+
+  } // 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
+  */
+}
+
+// -------------------------------------------------------------------------
+/* TODO
+   void PipelineEditor::QNodesEditorCanvas::
+   keyPressEvent( QKeyEvent* event )
+   {
+   }
+
+   // -------------------------------------------------------------------------
+   void PipelineEditor::QNodesEditorCanvas::
+   timerEvent( QTimerEvent* event )
+   {
+   }
+*/
+
+// -------------------------------------------------------------------------
+void PipelineEditor::QNodesEditorCanvas::
+wheelEvent( QWheelEvent* event )
+{
+  this->_scaleView(
+    std::pow( double( 2 ), event->delta( ) / double( 240 ) )
+    );
+}
+
+// -------------------------------------------------------------------------
+void PipelineEditor::QNodesEditorCanvas::
+dragEnterEvent( QDragEnterEvent* event )
+{
+  const QMimeData* mime = event->mimeData( );
+  if( mime->hasFormat( "application/x-qabstractitemmodeldatalist" ) )
+    event->acceptProposedAction( );
+}
+
+// -------------------------------------------------------------------------
+void PipelineEditor::QNodesEditorCanvas::
+dragLeaveEvent( QDragLeaveEvent* event )
+{
+}
+
+// -------------------------------------------------------------------------
+void PipelineEditor::QNodesEditorCanvas::
+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;
+
+  event->acceptProposedAction( );
+  auto tree = dynamic_cast< QTreeWidget* >( event->source( ) );
+  if( tree == NULL )
+    return;
+
+  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;
+    if( this->m_Workspace->GetFilter( name ) != NULL )
+      name += std::string( "_" );
+    if( this->m_Workspace->CreateFilter( filter, name ) )
+    {
+    } // fi
+
+  } // rof
+}
+
+// -------------------------------------------------------------------------
+void PipelineEditor::QNodesEditorCanvas::
+_scaleView( qreal scaleFactor )
+{
+  qreal factor = this->transform( ).
+    scale( scaleFactor, scaleFactor ).
+    mapRect( QRectF( 0, 0, 1, 1 ) ).
+    width( );
+  if( factor < qreal( 0.07 ) || factor > qreal( 100 ) )
+    return;
+  this->scale( scaleFactor, scaleFactor );
+}
+
+// -------------------------------------------------------------------------
+void PipelineEditor::QNodesEditorCanvas::
+_createBlock( TFilter* f )
+{
+  if( f == NULL )
+    return;
+
+  // Add block
+  QNEBlock* b = new QNEBlock( 0, this->scene( ) );
+  b->addPort( f->GetName( ), 0, QNEPort::NamePort );
+  b->addPort( f->GetClassName( ).c_str( ), 0, QNEPort::TypePort );
+
+  // Add input ports
+  std::set< std::string > inputs;
+  f->GetInputsNames( inputs );
+  for( auto iIt = inputs.begin( ); iIt != inputs.end( ); ++iIt )
+    b->addInputPort( iIt->c_str( ) );
+  //in_ports[ vIt->first ][ *iIt ] = b->addInputPort( iIt->c_str( ) );
+
+  // Add output ports
+  std::set< std::string > outputs;
+  f->GetOutputsNames( outputs );
+  for( auto oIt = outputs.begin( ); oIt != outputs.end( ); ++oIt )
+    b->addOutputPort( oIt->c_str( ) );
+  // out_ports[ vIt->first ][ *oIt ] = b->addOutputPort( oIt->c_str( ) );
+
+  // Keep a trace of this visual graph
+  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( );
+    auto vIt_end = this->m_Workspace->GetGraph( )->EndVertices( );
+    for( ; vIt != vIt_end; ++vIt )
+    {
+    // Add block
+    QNEBlock* b = new QNEBlock( 0, scene );
+    b->addPort( vIt->second->GetName( ), 0, QNEPort::NamePort );
+    b->addPort( vIt->second->GetClassName( ).c_str( ), 0, QNEPort::TypePort );
+
+    // Get filter
+    auto f = dynamic_cast< TFilter* >( vIt->second.GetPointer( ) );
+    if( f == NULL )
+    continue;
+
+    // Add input ports
+    std::set< std::string > inputs;
+    f->GetInputsNames( inputs );
+    for( auto iIt = inputs.begin( ); iIt != inputs.end( ); ++iIt )
+    in_ports[ vIt->first ][ *iIt ] = b->addInputPort( iIt->c_str( ) );
+
+    // Add output ports
+    std::set< std::string > outputs;
+    f->GetOutputsNames( outputs );
+    for( auto oIt = outputs.begin( ); oIt != outputs.end( ); ++oIt )
+    out_ports[ vIt->first ][ *oIt ] = b->addOutputPort( oIt->c_str( ) );
+
+    // Keep a trace of this visual graph
+    this->m_Graph->InsertVertex( vIt->first, b );
+
+    } // rof
+  */
+}
+
+// eof - $RCSfile$
+
+
+/*
+
+// -------------------------------------------------------------------------
+void GraphWidget::
+draw( )
+{
+  if( this->m_Workspace == NULL )
+    return;
+}
+
+// -------------------------------------------------------------------------
+void GraphWidget::itemMoved()
+{
+  if (!timerId)
+    timerId = startTimer(1000 / 25);
+}
+
+void GraphWidget::keyPressEvent(QKeyEvent *event)
+{
+  switch (event->key()) {
+  case Qt::Key_Up:
+    centerNode->moveBy(0, -20);
+    break;
+  case Qt::Key_Down:
+    centerNode->moveBy(0, 20);
+    break;
+  case Qt::Key_Left:
+    centerNode->moveBy(-20, 0);
+    break;
+  case Qt::Key_Right:
+    centerNode->moveBy(20, 0);
+    break;
+  case Qt::Key_Plus:
+    zoomIn();
+    break;
+  case Qt::Key_Minus:
+    zoomOut();
+    break;
+  case Qt::Key_Space:
+  case Qt::Key_Enter:
+    shuffle();
+    break;
+  default:
+    QGraphicsView::keyPressEvent(event);
+  }
+}
+
+void GraphWidget::timerEvent(QTimerEvent *event)
+{
+  Q_UNUSED(event);
+
+  QList<Node *> nodes;
+  foreach (QGraphicsItem *item, scene()->items()) {
+    if (Node *node = qgraphicsitem_cast<Node *>(item))
+      nodes << node;
+  }
+
+  foreach (Node *node, nodes)
+    node->calculateForces();
+
+  bool itemsMoved = false;
+  foreach (Node *node, nodes) {
+    if (node->advance())
+      itemsMoved = true;
+  }
+
+  if (!itemsMoved) {
+    killTimer(timerId);
+    timerId = 0;
+  }
+}
+
+void GraphWidget::wheelEvent(QWheelEvent *event)
+{
+  scaleView(pow((double)2, -event->delta() / 240.0));
+}
+
+void GraphWidget::drawBackground(QPainter *painter, const QRectF &rect)
+{
+  //Q_UNUSED(rect);
+
+  // Shadow
+  QRectF sceneRect = rect;//this->sceneRect();
+  QRectF rightShadow(sceneRect.right(), sceneRect.top() + 5, 5, sceneRect.height());
+  QRectF bottomShadow(sceneRect.left() + 5, sceneRect.bottom(), sceneRect.width(), 5);
+  if (rightShadow.intersects(rect) || rightShadow.contains(rect))
+    painter->fillRect(rightShadow, Qt::darkGray);
+  if (bottomShadow.intersects(rect) || bottomShadow.contains(rect))
+    painter->fillRect(bottomShadow, Qt::darkGray);
+
+  // Fill
+  QLinearGradient gradient(sceneRect.topLeft(), sceneRect.bottomRight());
+  gradient.setColorAt(0, Qt::white);
+  gradient.setColorAt(1, Qt::lightGray);
+  painter->fillRect(rect.intersect(sceneRect), gradient);
+  painter->setBrush(Qt::NoBrush);
+  painter->drawRect(sceneRect);
+
+#if !defined(Q_OS_SYMBIAN) && !defined(Q_WS_MAEMO_5)
+  // Text
+  QRectF textRect(sceneRect.left() + 4, sceneRect.top() + 4,
+                  sceneRect.width() - 4, sceneRect.height() - 4);
+  QString message(tr("Click and drag the nodes around, and zoom with the mouse "
+                     "wheel or the '+' and '-' keys"));
+
+  QFont font = painter->font();
+  font.setBold(true);
+  font.setPointSize(14);
+  painter->setFont(font);
+  painter->setPen(Qt::lightGray);
+  painter->drawText(textRect.translated(2, 2), message);
+  painter->setPen(Qt::black);
+  painter->drawText(textRect, message);
+#endif
+}
+
+void GraphWidget::scaleView(qreal scaleFactor)
+{
+  qreal factor = transform().scale(scaleFactor, scaleFactor).mapRect(QRectF(0, 0, 1, 1)).width();
+  if (factor < 0.07 || factor > 100)
+    return;
+
+  scale(scaleFactor, scaleFactor);
+}
+
+void GraphWidget::shuffle()
+{
+  foreach (QGraphicsItem *item, scene()->items()) {
+    if (qgraphicsitem_cast<Node *>(item))
+      item->setPos(-150 + qrand() % 300, -150 + qrand() % 300);
+  }
+}
+
+void GraphWidget::zoomIn()
+{
+  scaleView(qreal(1.2));
+}
+
+void GraphWidget::zoomOut()
+{
+  scaleView(1 / qreal(1.2));
+}
+
+
+*/
diff --git a/appli/cpPipelineEditor/QNodesEditorCanvas.h b/appli/cpPipelineEditor/QNodesEditorCanvas.h
new file mode 100644 (file)
index 0000000..03380d1
--- /dev/null
@@ -0,0 +1,62 @@
+#ifndef __PIPELINEEDITOR__QNODESEDITORCANVAS__H__
+#define __PIPELINEEDITOR__QNODESEDITORCANVAS__H__
+
+#include <QtGui/QGraphicsView>
+#include <cpExtensions/DataStructures/Graph.h>
+#include <cpPlugins/Interface/Workspace.h>
+
+namespace PipelineEditor
+{
+  // Some other forward declarations
+  class QNEBlock;
+  class QNEConnection;
+  class QNodesEditor;
+
+  /**
+   */
+  class QNodesEditorCanvas
+    : public QGraphicsView
+  {
+    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 );
+
+  protected:
+    /* TODO
+       void keyPressEvent( QKeyEvent* event );
+       void timerEvent( QTimerEvent* event );
+    */
+    void wheelEvent( QWheelEvent* event );
+
+    void dragEnterEvent( QDragEnterEvent* event );
+    void dragLeaveEvent( QDragLeaveEvent* event );
+    void dragMoveEvent( QDragMoveEvent* event );
+    void dropEvent( QDropEvent* event );
+
+    void _scaleView( qreal scaleFactor );
+    void _createBlock( TFilter* f );
+
+  protected:
+    TWorkspace* m_Workspace;
+    QNodesEditor* m_Editor;
+    TGraph::Pointer m_Graph;
+  };
+
+} // ecapseman
+
+#endif // __PIPELINEEDITOR__QNODESEDITORCANVAS__H__
+
+// eof - $RCSfile$
index 87fd6c86e65984f7c81926d1aeac700462407da9..9abdd013aabdffb41f5125e2bbd66efba3172f3e 100644 (file)
     this, SLOT( _Action##ACTION( ) )                    \
     )
 
+// -------------------------------------------------------------------------
+#define cpPipelineEditor_ConnectButton( BUTTON )        \
+  QObject::connect(                                     \
+    this->m_UI->Button##BUTTON, SIGNAL( clicked( ) ),   \
+    this, SLOT( _Button##BUTTON( ) )                    \
+    )
+
 // -------------------------------------------------------------------------
 cpPipelineEditor::
 cpPipelineEditor( QWidget* parent )
@@ -22,6 +29,8 @@ cpPipelineEditor( QWidget* parent )
   this->m_UI->setupUi( this );
 
   // Connect actions to slots
+  cpPipelineEditor_ConnectButton( LoadPluginsFile );
+  cpPipelineEditor_ConnectButton( LoadPluginsPath );
   cpPipelineEditor_ConnectAction( OpenWorkspace );
 }
 
@@ -34,6 +43,129 @@ cpPipelineEditor::
     delete this->m_Workspace;
 }
 
+// -------------------------------------------------------------------------
+void cpPipelineEditor::
+_UpdateLoadedPlugins( )
+{
+  typedef cpPlugins::Interface::Workspace::TStringContainer _TStrings;
+
+  if( this->m_Workspace == NULL )
+    return;
+
+  _TStrings categories;
+  this->m_Workspace->GetLoadedPluginCategories( categories );
+  for( auto cIt = categories.begin( ); cIt != categories.end( ); ++cIt )
+  {
+    // Create or get category
+    QList< QTreeWidgetItem* > cat_items =
+      this->m_UI->LoadedPlugins->findItems(
+        cIt->c_str( ), Qt::MatchExactly | Qt::MatchRecursive
+        );
+    QTreeWidgetItem* cat = NULL;
+    if( cat_items.size( ) == 0 )
+    {
+      cat = new QTreeWidgetItem(
+        ( QTreeWidgetItem* )( NULL ), QStringList( cIt->c_str( ) )
+        );
+      this->m_UI->LoadedPlugins->addTopLevelItem( cat );
+    }
+    else
+      cat = cat_items[ 0 ];
+
+    // Add filters
+    _TStrings filters = this->m_Workspace->GetLoadedPluginFilters( *cIt );
+    for( auto fIt = filters.begin( ); fIt != filters.end( ); ++fIt )
+    {
+      // Find filter
+      QList< QTreeWidgetItem* > filter_items =
+        this->m_UI->LoadedPlugins->findItems(
+          fIt->c_str( ), Qt::MatchExactly | Qt::MatchRecursive
+          );
+      auto fiIt = filter_items.begin( );
+      auto found_fiIt = filter_items.end( );
+      for( ; fiIt != filter_items.end( ); ++fiIt )
+        if( ( *fiIt )->parent( ) == cat )
+          found_fiIt = fiIt;
+
+      // Add filter
+      if( found_fiIt == filter_items.end( ) )
+        QTreeWidgetItem* filter = new QTreeWidgetItem(
+          cat, QStringList( fIt->c_str( ) )
+          );
+
+    } // rof
+
+  } // rof
+}
+
+// -------------------------------------------------------------------------
+void cpPipelineEditor::
+_ButtonLoadPluginsFile( )
+{
+  QFileDialog dlg( this );
+  dlg.setFileMode( QFileDialog::ExistingFiles );
+  dlg.setDirectory( "." );
+#ifdef _WIN32
+  dlg.setNameFilter( "Plugins file (*.dll);;All files (*)" );
+  dlg.setDefaultSuffix( "dll" );
+#else // _WIN32
+  dlg.setNameFilter( "Plugins file (*.so);;All files (*)" );
+  dlg.setDefaultSuffix( "so" );
+#endif // _WIN32
+  if( !( dlg.exec( ) ) )
+    return;
+
+  // Create a new workspace, if not ready
+  if( this->m_Workspace == NULL )
+    this->m_Workspace = new cpPlugins::Interface::Workspace( );
+
+  // Read
+  QStringList names = dlg.selectedFiles( );
+  std::stringstream err_str;
+  for( auto qIt = names.begin( ); qIt != names.end( ); ++qIt )
+    if( !( this->m_Workspace->LoadPlugins( qIt->toStdString( ) ) ) )
+      err_str << qIt->toStdString( ) << std::endl;
+
+  // Show an error message
+  std::string err = err_str.str( );
+  if( err.size( ) > 0 )
+    QMessageBox::critical(
+      this,
+      "Error loading plugins",
+      err.c_str( )
+      );
+
+  // Update view
+  this->_UpdateLoadedPlugins( );
+}
+
+// -------------------------------------------------------------------------
+void cpPipelineEditor::
+_ButtonLoadPluginsPath( )
+{
+  QFileDialog dlg( this );
+  dlg.setFileMode( QFileDialog::DirectoryOnly );
+  dlg.setDirectory( "." );
+  if( !( dlg.exec( ) ) )
+    return;
+
+  // Create a new workspace, if not ready
+  if( this->m_Workspace == NULL )
+    this->m_Workspace = new cpPlugins::Interface::Workspace( );
+
+  // Read
+  std::string dir = dlg.selectedFiles( ).begin( )->toStdString( );
+  if( !( this->m_Workspace->LoadPluginsPath( dir, false ) ) )
+    QMessageBox::critical(
+      this,
+      "Error loading plugins directory",
+      dir.c_str( )
+      );
+
+  // Update view
+  this->_UpdateLoadedPlugins( );
+}
+
 // -------------------------------------------------------------------------
 void cpPipelineEditor::
 _ActionOpenWorkspace( )
index 29700934256b7fb5b54afc00b5b4b5ad18832e49..5180dd12da81473efb070dc26985f6a28b7ae9fb 100644 (file)
@@ -33,7 +33,12 @@ public:
   explicit cpPipelineEditor( QWidget* parent = 0 );
   virtual ~cpPipelineEditor( );
 
+protected:
+  void _UpdateLoadedPlugins( );
+
 protected slots:
+  void _ButtonLoadPluginsFile( );
+  void _ButtonLoadPluginsPath( );
   void _ActionOpenWorkspace( );
 
 private:
index f35e6366ea34b0dce1f93f78463894783d8e9570..5fa8eb0e1ed2383fe109720037438ddd59dd9358 100644 (file)
     <height>600</height>
    </rect>
   </property>
+  <property name="minimumSize">
+   <size>
+    <width>800</width>
+    <height>600</height>
+   </size>
+  </property>
   <property name="windowTitle">
    <string>MainWindow</string>
   </property>
   <widget class="QWidget" name="MainWidget">
    <layout class="QGridLayout" name="gridLayout">
     <item row="0" column="0">
-     <widget class="PipelineEditor::GraphCanvas" name="Canvas" native="true"/>
+     <widget class="QSplitter" name="splitter">
+      <property name="orientation">
+       <enum>Qt::Horizontal</enum>
+      </property>
+      <widget class="QFrame" name="frame">
+       <property name="minimumSize">
+        <size>
+         <width>251</width>
+         <height>331</height>
+        </size>
+       </property>
+       <property name="frameShape">
+        <enum>QFrame::StyledPanel</enum>
+       </property>
+       <property name="frameShadow">
+        <enum>QFrame::Raised</enum>
+       </property>
+       <layout class="QVBoxLayout" name="verticalLayout">
+        <item>
+         <widget class="QGroupBox" name="groupBox">
+          <property name="minimumSize">
+           <size>
+            <width>202</width>
+            <height>67</height>
+           </size>
+          </property>
+          <property name="maximumSize">
+           <size>
+            <width>202</width>
+            <height>67</height>
+           </size>
+          </property>
+          <property name="title">
+           <string>Plugins</string>
+          </property>
+          <layout class="QHBoxLayout" name="horizontalLayout">
+           <item>
+            <widget class="QPushButton" name="ButtonLoadPluginsFile">
+             <property name="minimumSize">
+              <size>
+               <width>85</width>
+               <height>31</height>
+              </size>
+             </property>
+             <property name="maximumSize">
+              <size>
+               <width>85</width>
+               <height>31</height>
+              </size>
+             </property>
+             <property name="text">
+              <string>File</string>
+             </property>
+            </widget>
+           </item>
+           <item>
+            <widget class="QPushButton" name="ButtonLoadPluginsPath">
+             <property name="minimumSize">
+              <size>
+               <width>85</width>
+               <height>31</height>
+              </size>
+             </property>
+             <property name="maximumSize">
+              <size>
+               <width>85</width>
+               <height>31</height>
+              </size>
+             </property>
+             <property name="text">
+              <string>Path</string>
+             </property>
+            </widget>
+           </item>
+          </layout>
+         </widget>
+        </item>
+        <item>
+         <widget class="QTreeWidget" name="LoadedPlugins">
+          <property name="minimumSize">
+           <size>
+            <width>229</width>
+            <height>0</height>
+           </size>
+          </property>
+          <property name="dragEnabled">
+           <bool>true</bool>
+          </property>
+          <property name="dragDropMode">
+           <enum>QAbstractItemView::DragOnly</enum>
+          </property>
+          <column>
+           <property name="text">
+            <string>Loaded plugins</string>
+           </property>
+          </column>
+         </widget>
+        </item>
+       </layout>
+      </widget>
+      <widget class="PipelineEditor::QNodesEditorCanvas" name="Canvas" native="true">
+       <property name="minimumSize">
+        <size>
+         <width>500</width>
+         <height>0</height>
+        </size>
+       </property>
+       <property name="acceptDrops">
+        <bool>true</bool>
+       </property>
+      </widget>
+     </widget>
     </item>
    </layout>
   </widget>
      <addaction name="ActionSaveWorkspace"/>
     </widget>
     <addaction name="MenuWorkspace"/>
+    <addaction name="separator"/>
+    <addaction name="ActionExit"/>
    </widget>
    <addaction name="MenuFile"/>
   </widget>
     <string>Save</string>
    </property>
   </action>
+  <action name="ActionExit">
+   <property name="text">
+    <string>E&amp;xit</string>
+   </property>
+  </action>
  </widget>
  <customwidgets>
   <customwidget>
-   <class>PipelineEditor::GraphCanvas</class>
+   <class>PipelineEditor::QNodesEditorCanvas</class>
    <extends>QWidget</extends>
-   <header>GraphCanvas.h</header>
+   <header>QNodesEditorCanvas.h</header>
    <container>1</container>
   </customwidget>
  </customwidgets>
  <resources/>
- <connections/>
+ <connections>
+  <connection>
+   <sender>ActionExit</sender>
+   <signal>triggered()</signal>
+   <receiver>cpPipelineEditor</receiver>
+   <slot>close()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>-1</x>
+     <y>-1</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>399</x>
+     <y>299</y>
+    </hint>
+   </hints>
+  </connection>
+ </connections>
 </ui>
index 531d13e2a5c596c2783eaf186f5769c7a8a5804b..7154469095791cce503aae713bad7940473805a0 100644 (file)
@@ -1,4 +1,4 @@
-#include "QNEMainWindow.h"
+#include "cpPipelineEditor.h"
 #include <cstdlib>
 #include <QApplication>
 
@@ -6,7 +6,7 @@
 int main( int argc, char* argv[] )
 {
   QApplication a( argc, argv );
-  QNEMainWindow w;
+  cpPipelineEditor w;
   w.show( );
 
   return( a.exec( ) );